From 6b517ddc63683a75b740f3ee2af134fe27e8056b Mon Sep 17 00:00:00 2001 From: maziggy Date: Sun, 21 Jun 2026 10:35:53 +0200 Subject: [PATCH] fix(printers): hide chamber fan badge on open-frame Bambu models MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Printers page rendered three fan widgets (part / aux / chamber) for every printer unconditionally. Open-frame models (A1, A1 Mini, A2L, P1P) have no chamber fan — the firmware reports big_fan2_speed as 0, so the badge always rendered greyed-out and let users "set" a fan speed on hardware that doesn't exist. Adds MODELS_WITH_CHAMBER_FAN allowlist (X1C / X1 / X1E / X2D / P1S / P2S / H2D / H2D Pro / H2C / H2S) near mapModelCode, and the chamber entry is spread into fanItems only when the printer's model is in the set. Open-frame printers now show two badges (part + aux), which matches their actual hardware. Allowlist not denylist: mirrors the file's existing classification pattern (the enclosure-door badge gate uses the same shape), and the failure mode is preferable — a missing badge on a real chambered printer is obvious; a phantom badge on a future open-frame model would look correct and silently lie. --- CHANGELOG.md | 2 + .../src/__tests__/pages/PrintersPage.test.tsx | 67 ++++++++++++++ frontend/src/pages/PrintersPage.tsx | 41 +++++++-- .../{index-Ckvy6dRm.js => index-BsijWO1C.js} | 92 +++++++++---------- static/index.html | 2 +- 5 files changed, 150 insertions(+), 54 deletions(-) rename static/assets/{index-Ckvy6dRm.js => index-BsijWO1C.js} (97%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e9c81ea8..3bc98da5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,8 @@ All notable changes to Bambuddy will be documented in this file. - **Push notification for "Printer offline" now actually fires (#1752, reported by @saint-hh)** — The notification provider's `on_printer_offline` toggle has shipped since the notifications feature landed: schema field, DB column, `notification_template.py` entry, and the dispatcher `NotificationService.on_printer_offline(printer_id, printer_name, db)` are all in place. What was missing was the caller — nothing in the codebase actually invoked the dispatcher when a printer went offline. The reporter (P2S, smart-plug-cuts-power scenario) confirmed turning the toggle on did nothing; only the print-failure notification fired when power was restored, via the firmware's `gcode_state=FAILED` report on MQTT reconnect. **Why the toggle was orphan:** every other provider event (`on_print_start`, `on_print_complete`, `on_print_progress`, `on_printer_error`, etc.) has a clear call site under `main.py::on_printer_status_change` or alongside the print-lifecycle hooks. The offline event was the only edge-triggered toggle without one — the dispatcher and template predated the wiring step and were silently shipped. Both upstream offline-trigger paths (`smart_plug_manager` → `printer_manager.mark_printer_offline()` and `bambu_mqtt.py::check_staleness` after the 30s STALE_RECONNECT_COOLDOWN) route through `_on_status_change` already and reach `on_printer_status_change`; the handler just didn't act on the disconnect edge. **Fix:** edge detection in `on_printer_status_change` watches `state.connected` against the previous observation per printer (`_printer_last_connected: dict[int, bool]`). On the True → False transition it schedules `_maybe_notify_printer_offline(printer_id)` as a background asyncio task; on the next True observation it cancels any pending task. The helper sleeps `_PRINTER_OFFLINE_NOTIFY_DEBOUNCE_SECONDS = 60.0` then re-checks `printer_manager.is_connected(printer_id)` — only fires the notification if the printer is still offline. **Why 60s debounce:** sized against `bambu_mqtt.py::STALE_RECONNECT_COOLDOWN = 30s` — a single stale-trigger + reconnect cycle isn't enough to fire, only a real outage that survives one full cooldown notifies. Transient MQTT blips (WiFi roam, broker reload, brief packet loss) recover within the window and the cancellation path kicks in. **Edge-case handling:** initial observation with no prior connected state doesn't fire (covers Bambuddy startup with an already-offline printer); a False → False repeat doesn't reschedule (the in-flight task stays in place rather than resetting the clock on every status callback, which would otherwise mean the notification never fires); the task entry pops from `_printer_offline_notify_tasks` in the finally block whether the notification fired, the printer reconnected, or the task was cancelled mid-await. **No symmetric `on_printer_online` event:** the reporter explicitly noted the "printer lost power and interrupted the print" notification already fires when power is restored — that's the print-failure notification, triggered by the firmware reporting `gcode_state=FAILED` for the interrupted print on MQTT reconnect. That covers the "printer is back" channel without a new toggle. If the user then resumes the print, no print_start notification fires (Bambuddy's `bambu_mqtt.py:3039` explicitly suppresses `is_new_print` for PAUSE → RUNNING to prevent duplicates when resuming from pause), but that's a separate scope from offline-detection. **Tests:** 9 new cases in `test_printer_offline_notification.py` split across two classes. `TestMaybeNotifyPrinterOffline` pins the debounced helper: fires notification when still offline at end of window, doesn't fire when printer reconnected during debounce, doesn't fire when the printer disappeared from the DB (uninstall mid-window), clears `_printer_offline_notify_tasks[printer_id]` after run. `TestOfflineEdgeDetection` pins the edge logic inside `on_printer_status_change`: first observation (connected) doesn't schedule, first observation (disconnected) doesn't schedule (the no-prior-True case — important for startup), True → False schedules a task, reconnect cancels the pending task, repeated False observations don't replace the in-flight task. Full backend suite still green; ruff clean. +- **Chamber-fan badge shown on open-frame Bambu printers that have no chamber fan (reported off-list, screenshot of an A1)** — The Printers page rendered three fan widgets (part cooling / auxiliary / chamber) for every printer unconditionally at `PrintersPage.tsx::fanItems` (around line 3579), reading `cooling_fan_speed` / `big_fan1_speed` / `big_fan2_speed` off the status payload. Open-frame Bambu models (A1, A1 Mini, A2L, P1P) physically have no chamber fan — the firmware reports `big_fan2_speed` as 0 there, so the badge always rendered greyed-out and clicking it would let the user "set" a speed on a fan that doesn't exist. Closed-frame models (X1C / X1 / X1E / X2D / P1S / P2S / H2D / H2D Pro / H2C / H2S) are unaffected. **Fix:** new module-scope `MODELS_WITH_CHAMBER_FAN: ReadonlySet` allowlist near `mapModelCode`; the chamber entry is now spread into `fanItems` only when `MODELS_WITH_CHAMBER_FAN.has(printer.model ?? '')`. Open-frame printers drop to a 2-badge row (part + aux), which is what their hardware actually has. **Why an allowlist (not a denylist):** the existing enclosure-door-badge gate at `PrintersPage.tsx:3314` uses an explicit model list pattern; mirroring it keeps the file's classification convention consistent and means a new Bambu model added to the codebase has to be deliberately added to the chamber-fan set rather than silently inheriting (failure mode: missing widget on a real chambered printer, noticed immediately and trivially fixed) — better than the denylist's failure mode (phantom widget on a new open-frame model, looks correct, silently lies). The set deliberately excludes P1P: open-frame, no chamber fan, even though the door-badge list includes it (separate pre-existing inconsistency, not in scope to fix here). **Tests:** 5 new cases in `PrintersPage.test.tsx::'fan badges'` — hides on A1 Mini, hides on A1, hides on P1P, shows on X1C, shows on P1S. Each constructs a single-printer mock with the model under test plus a status payload that has all three fan speeds populated (53 / 53 / 53), then asserts the `title='Chamber Fan'` element is/isn't in the DOM and that the part-cooling / auxiliary badges still render unchanged so we're not over-filtering. Existing 51 PrintersPage cases still green; `npm run build` clean; ESLint clean. **Scope clarification — what this does NOT change.** The `/api/v1/printers/{id}/fan` backend route still accepts `fan=chamber` requests for all models (the dispatch surface stays uniform, so external automations / MQTT relays don't need a model-aware gate); the chamber-fan icon's behaviour and the `printers.fans.chamber` i18n string are unchanged on chambered models; the chamber-*temperature* widget is not affected (open-frame models' status payload doesn't include a chamber temp field, so it was already absent there). + - **In-app "Install Update" on Windows installer installs failed with "Could not find git executable"** — Reported off-list by a Windows user running the `.exe` installer. Root cause has two layers, and the surfaced error only described the first. **Layer 1 — git not findable on Windows.** `backend/app/api/routes/updates.py::_find_executable("git")` falls through `shutil.which("git")` (the installer doesn't bundle git, fresh Windows installs have no git on PATH) into a fallback list of *Unix-only* paths (`/usr/bin/git`, `/opt/homebrew/bin/git`, `~/.local/bin/git` etc) — none exist on Windows, so the helper returns `None` and the route reports "Could not find git executable. Please ensure git is installed." **Layer 2 — no `.git` directory in the installer payload anyway.** `installers/windows/build.py::stage_backend` copies `backend/` via `shutil.copytree` rather than `git clone`, so even if Git for Windows were installed separately, the next `git fetch` would die on `fatal: not a git repository`. Adding Windows paths to `_find_executable` would only have changed which error message users saw. **Fix — distinct `update_method=windows_installer` instead of stretching the git path.** Same shape as the existing `docker` / `ha_addon` branches: detect the installer install, surface a download link to the release `.exe`, let the user run the installer like every other Windows app (Discord/Spotify model). New `_is_windows_installer_install()` helper returns True iff `sys.platform == "win32"` AND `settings.app_dir / ".git"` is absent — so a Windows developer with a real `git clone` keeps the git path, only installer users hit the new branch. New `_find_windows_installer_asset(release_data)` picks the matching asset out of the release's `assets[]` (prefer the versioned `bambuddy--windows-x64-setup.exe` because daily prereleases only publish that form; fall back to the unversioned `bambuddy-windows-x64-setup.exe` alias when present). `/updates/check` now includes `is_windows_installer: bool`, `update_method: "windows_installer"`, and `installer_download_url` on Windows-installer installs. `/updates/apply` short-circuits with `success: false, is_windows_installer: true` after the existing HA / Docker guards — defense in depth, since the frontend swaps the button so the POST shouldn't even fire on Windows. **Frontend.** `UpdateCheckResult` extended with `is_windows_installer`, `installer_download_url`, and `'windows_installer'` in the `update_method` union. `SettingsPage.tsx` inserts a new branch between the Docker snippet and the "Install Update" button: renders the same Bambu-green primary-button style as an `` pointing at `installer_download_url` (falls back to `release_url` then to the tag page so the link is never broken even if the release uploader is mid-publish). Hardcoded `data, settings and printers are preserved` reassurance in the body text — the installer preserves DATA_DIR by design, but Windows users who hit this UI mid-print would otherwise reasonably hesitate. `applyUpdateMutation.onSuccess` toast guard extended to treat `is_windows_installer` the same as HA / Docker, so a direct API call still surfaces the message instead of swallowing it. **i18n.** Two new keys — `settings.updateViaWindowsInstaller` (body copy) and `settings.downloadWindowsInstaller` (button label, takes `{{version}}`) — translated across all 11 locales (de / en / es / fr / it / ja / ko / pt-BR / tr / zh-CN / zh-TW). Parity check 5216 leaves per locale, no English fallback. **Tests.** Backend: 8 new cases in `test_updates_api.py` — `_is_windows_installer_install` (× 3: true on `.git`-less Windows tmp_path, false when `.git` exists, false off-Windows), `_find_windows_installer_asset` (× 3: prefers versioned, falls back to alias, None when missing), `/updates/apply` rejection for installer installs, `/updates/check` returns `update_method="windows_installer"` + the asset URL. Frontend: 1 new case in `SettingsPage.test.tsx::'shows the installer-download link for Windows installer installs'` asserting the `` is rendered with the correct `href` / `target=_blank` / `rel*=noopener` AND the in-app Update button is suppressed AND the Docker/HA messages don't leak across. All 29 backend updates tests + all 44 SettingsPage frontend tests green; `npm run build` clean; ESLint clean; ruff clean. **Scope — what this does NOT change.** No installer change (no git.exe bundled, no `.git` seeded — those would be heavier fixes that still wouldn't match the user mental model of "double-click installer = update"); no behaviour change for Docker / HA / Linux / macOS / Windows-git-clone installs (the existing `update_method` selection prioritises HA → Docker → Windows-installer → git in that order; only `.git`-less Windows installs reach the new branch); no auto-download or in-app installer launch (UAC + NSSM service stop/start ordering would need a separate elevated helper — out of scope for this fix). - **PrintModal printer picker no longer offers a printer between dispatch-accept and PRINT_START (reported off-list by a corporate user running multi-operator farm shifts)** — Operator picks a printer in the reprint modal, hits Send, Bambuddy accepts the dispatch and begins FTP upload + sending the print command. The printer hasn't reported `gcode_state=RUNNING` yet — it's still IDLE on its own MQTT status. A second operator opening the modal during this window sees the same printer as available and submits a second job. The backend correctly rejects the second submit with HTTP 409 (`background_dispatch._dispatch` rejects when `_queued_jobs` or `_active_jobs` already holds the printer_id), so no double-print is possible, but the operator only finds out after they click Send — wasted minutes per attempt on a busy floor. **Root cause:** `PrinterSelector.tsx::isPrinterBusy` consulted only `PrinterStatus.state` against `AVAILABLE_STATES = {IDLE, FINISH, FAILED}`. PRINT_START is the only signal that flips the printer out of IDLE, and there's a real wall-clock window (upload time + print command + firmware ack) between dispatch acceptance and that flip. The dispatch-queue state — already broadcast as a WebSocket `background_dispatch` push including `dispatched_jobs[].printer_id` and `active_jobs[].printer_id` — was being consumed by `ToastContext` for the progress overlay but never read by the picker. **Fix:** new `frontend/src/hooks/useDispatchedPrinterIds.ts` exposes `Set` of printer_ids with a queued or active dispatch, populated from the same `background-dispatch` window event the ToastContext listens for. Module-level singleton + `useSyncExternalStore` so every `PrinterSelector` instance sees the same snapshot and a modal opened mid-batch picks up the latest state without a refetch. Reference-stable snapshot (size + membership check) keeps `useSyncExternalStore`'s Object.is comparison from re-rendering on every WS push that doesn't change the set. `PrinterSelector.tsx::isPrinterBusy` ORs the set into the existing connected/state check — printer disabled the instant dispatch is accepted, re-enabled when the dispatch finishes (or fails) and disappears from the next state payload. `getPrinterStateLabel` returns `"Dispatching..."` for the badge so operators see the in-flight state instead of a misleading "Idle" on a now-disabled card. Hardcoded English label is consistent with the existing labels in that function (`"Idle"`, `"Printing"`, `"Paused"` are all hardcoded, no i18n key). **What this is NOT:** a backend change (the reservation Mike asked about already exists at `background_dispatch.py:283-290`); a behaviour change for `add-to-queue` / `edit-queue-item` modes (those don't set `disableBusy=true`, so the busy-OR remains dormant for the card click handler — the badge label still flips, which is informative); a guarantee against the WS-not-yet-connected race (a fresh page load that opens the modal before the WS initial-state push lands still sees an empty set for ~1 frame; same race as today, much shorter window). **Tests:** 8 new cases in `useDispatchedPrinterIds.test.ts` pin the contract — empty initial set, picks up `dispatched_jobs` printer_ids, picks up `active_jobs` printer_ids, unions both lists, clears when subsequent event reports zero jobs, ignores non-numeric `printer_id` (defensive against payload drift), reference-stable snapshot when content doesn't change, shared state across hook instances. Existing 84 PrintModal + PrinterSelector cases still green — the new code path is dormant until a `background-dispatch` window event fires, which existing tests don't trigger. `npm run build` clean, ESLint clean. diff --git a/frontend/src/__tests__/pages/PrintersPage.test.tsx b/frontend/src/__tests__/pages/PrintersPage.test.tsx index c5d883f05..bd332aa03 100644 --- a/frontend/src/__tests__/pages/PrintersPage.test.tsx +++ b/frontend/src/__tests__/pages/PrintersPage.test.tsx @@ -243,6 +243,73 @@ describe('PrintersPage', () => { }); }); + describe('fan badges', () => { + // Chamber fan only exists on enclosed Bambu models. Open-frame printers + // (A1, A1 Mini, A2L, P1P) have no chamber fan — the firmware reports + // big_fan2_speed as 0 there and the widget would be dead UI. + const statusWithFans = { + ...mockPrinterStatus, + cooling_fan_speed: 53, + big_fan1_speed: 53, + big_fan2_speed: 53, + }; + + const renderWithPrinter = (printer: typeof mockPrinters[number]) => { + server.use( + http.get('/api/v1/printers/', () => HttpResponse.json([printer])), + http.get('/api/v1/printers/:id/status', () => HttpResponse.json(statusWithFans)), + ); + render(); + }; + + it('hides chamber fan badge on A1 Mini (open-frame, no chamber fan)', async () => { + renderWithPrinter({ ...mockPrinters[0], model: 'A1 Mini' }); + + await waitFor(() => { + // Part-cooling badge confirms the fan row rendered. + expect(screen.getByTitle('Part Cooling Fan')).toBeInTheDocument(); + }); + expect(screen.getByTitle('Auxiliary Fan')).toBeInTheDocument(); + expect(screen.queryByTitle('Chamber Fan')).not.toBeInTheDocument(); + }); + + it('hides chamber fan badge on A1 (open-frame)', async () => { + renderWithPrinter({ ...mockPrinters[0], model: 'A1' }); + + await waitFor(() => { + expect(screen.getByTitle('Part Cooling Fan')).toBeInTheDocument(); + }); + expect(screen.queryByTitle('Chamber Fan')).not.toBeInTheDocument(); + }); + + it('hides chamber fan badge on P1P (open-frame)', async () => { + renderWithPrinter({ ...mockPrinters[0], model: 'P1P' }); + + await waitFor(() => { + expect(screen.getByTitle('Part Cooling Fan')).toBeInTheDocument(); + }); + expect(screen.queryByTitle('Chamber Fan')).not.toBeInTheDocument(); + }); + + it('shows chamber fan badge on X1C (enclosed)', async () => { + renderWithPrinter({ ...mockPrinters[0], model: 'X1C' }); + + await waitFor(() => { + expect(screen.getByTitle('Chamber Fan')).toBeInTheDocument(); + }); + expect(screen.getByTitle('Part Cooling Fan')).toBeInTheDocument(); + expect(screen.getByTitle('Auxiliary Fan')).toBeInTheDocument(); + }); + + it('shows chamber fan badge on P1S (enclosed)', async () => { + renderWithPrinter({ ...mockPrinters[0], model: 'P1S' }); + + await waitFor(() => { + expect(screen.getByTitle('Chamber Fan')).toBeInTheDocument(); + }); + }); + }); + describe('empty state', () => { it('shows empty state when no printers', async () => { server.use( diff --git a/frontend/src/pages/PrintersPage.tsx b/frontend/src/pages/PrintersPage.tsx index 97b765bcd..ff3645303 100644 --- a/frontend/src/pages/PrintersPage.tsx +++ b/frontend/src/pages/PrintersPage.tsx @@ -1465,6 +1465,23 @@ function getStatusDisplay(state: string | null | undefined, stg_cur_name: string } } +// Bambu models that ship with an enclosure chamber fan (firmware field +// `big_fan2_speed`). Open-frame models (A1 / A1 Mini / A2L / P1P) have no +// chamber fan — `big_fan2_speed` is meaningless / always 0 there, so the +// widget is hidden in fanItems instead of rendered greyed-out. +const MODELS_WITH_CHAMBER_FAN: ReadonlySet = new Set([ + 'X1C', + 'X1', + 'X1E', + 'X2D', + 'P1S', + 'P2S', + 'H2D', + 'H2D Pro', + 'H2C', + 'H2S', +]); + // Map SSDP model codes to display names function mapModelCode(ssdpModel: string | null): string { if (!ssdpModel) return ''; @@ -3576,6 +3593,12 @@ function PrinterCard({ const statusControlClass = `relative text-center px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 flex flex-col justify-center items-center transition-colors ${ canUseStatusControls ? 'cursor-pointer hover:bg-bambu-dark-tertiary' : 'cursor-default opacity-80' }`; + // Chamber fan only exists on enclosed Bambu models. Open-frame + // printers (A1, A1 Mini, A2L, P1P) have no chamber fan — showing + // the widget there is at best dead UI and at worst suggests a + // control that does nothing. Mirrors the enclosure-door badge + // gate above. + const hasChamberFan = MODELS_WITH_CHAMBER_FAN.has(printer.model ?? ''); const fanItems = [ { key: 'part', @@ -3591,13 +3614,17 @@ function PrinterCard({ Icon: Wind, activeClass: 'text-blue-400', }, - { - key: 'chamber', - label: t('printers.fans.chamber'), - value: status.big_fan2_speed ?? 0, - Icon: AirVent, - activeClass: 'text-green-400', - }, + ...(hasChamberFan + ? [ + { + key: 'chamber', + label: t('printers.fans.chamber'), + value: status.big_fan2_speed ?? 0, + Icon: AirVent, + activeClass: 'text-green-400', + }, + ] + : []), ]; return ( diff --git a/static/assets/index-Ckvy6dRm.js b/static/assets/index-BsijWO1C.js similarity index 97% rename from static/assets/index-Ckvy6dRm.js rename to static/assets/index-BsijWO1C.js index d0561261e..ea1ca5d3b 100644 --- a/static/assets/index-Ckvy6dRm.js +++ b/static/assets/index-BsijWO1C.js @@ -3884,7 +3884,7 @@ void main() { gl_Position = vec4( position, 1.0 ); } - `}function _ne(e){let t=new WeakMap,n=null;function r(r){if(r&&r.isTexture){let o=r.mapping,s=o===303||o===304,c=o===301||o===302;if(s||c){let o=t.get(r),l=o===void 0?0:o.texture.pmremVersion;if(r.isRenderTargetTexture&&r.pmremVersion!==l)return n===null&&(n=new $_(e)),o=s?n.fromEquirectangular(r,o):n.fromCubemap(r,o),o.texture.pmremVersion=r.pmremVersion,t.set(r,o),o.texture;if(o!==void 0)return o.texture;{let l=r.image;return s&&l&&l.height>0||c&&l&&i(l)?(n===null&&(n=new $_(e)),o=s?n.fromEquirectangular(r):n.fromCubemap(r),o.texture.pmremVersion=r.pmremVersion,t.set(r,o),r.addEventListener(`dispose`,a),o.texture):null}}}return r}function i(e){let t=0;for(let n=0;n<6;n++)e[n]!==void 0&&t++;return t===6}function a(e){let n=e.target;n.removeEventListener(`dispose`,a);let r=t.get(n);r!==void 0&&(t.delete(n),r.dispose())}function o(){t=new WeakMap,n!==null&&(n.dispose(),n=null)}return{get:r,dispose:o}}function vne(e){let t={};function n(n){if(t[n]!==void 0)return t[n];let r=e.getExtension(n);return t[n]=r,r}return{has:function(e){return n(e)!==null},init:function(){n(`EXT_color_buffer_float`),n(`WEBGL_clip_cull_distance`),n(`OES_texture_float_linear`),n(`EXT_color_buffer_half_float`),n(`WEBGL_multisampled_render_to_texture`),n(`WEBGL_render_shared_exponent`)},get:function(e){let t=n(e);return t===null&&mm(`WebGLRenderer: `+e+` extension not supported.`),t}}}function yne(e,t,n,r){let i={},a=new WeakMap;function o(e){let s=e.target;s.index!==null&&t.remove(s.index);for(let e in s.attributes)t.remove(s.attributes[e]);s.removeEventListener(`dispose`,o),delete i[s.id];let c=a.get(s);c&&(t.remove(c),a.delete(s)),r.releaseStatesOfGeometry(s),s.isInstancedBufferGeometry===!0&&delete s._maxInstanceCount,n.memory.geometries--}function s(e,t){return i[t.id]===!0?t:(t.addEventListener(`dispose`,o),i[t.id]=!0,n.memory.geometries++,t)}function c(n){let r=n.attributes;for(let n in r)t.update(r[n],e.ARRAY_BUFFER)}function l(e){let n=[],r=e.index,i=e.attributes.position,o=0;if(r!==null){let e=r.array;o=r.version;for(let t=0,r=e.length;tt.maxTextureSize&&(m=Math.ceil(p/t.maxTextureSize),p=t.maxTextureSize);let h=new Float32Array(p*m*4*u),g=new Ym(h,p,m,u);g.type=Np,g.needsUpdate=!0;let _=f*4;for(let t=0;t0)return e;let i=t*n,a=dv[i];if(a===void 0&&(a=new Float32Array(i),dv[i]=a),t!==0){r.toArray(a,0);for(let r=1,i=0;r!==t;++r)i+=n,e[r].toArray(a,i)}return a}function _v(e,t){if(e.length!==t.length)return!1;for(let n=0,r=e.length;n0||c&&l&&i(l)?(n===null&&(n=new $_(e)),o=s?n.fromEquirectangular(r):n.fromCubemap(r),o.texture.pmremVersion=r.pmremVersion,t.set(r,o),r.addEventListener(`dispose`,a),o.texture):null}}}return r}function i(e){let t=0;for(let n=0;n<6;n++)e[n]!==void 0&&t++;return t===6}function a(e){let n=e.target;n.removeEventListener(`dispose`,a);let r=t.get(n);r!==void 0&&(t.delete(n),r.dispose())}function o(){t=new WeakMap,n!==null&&(n.dispose(),n=null)}return{get:r,dispose:o}}function vne(e){let t={};function n(n){if(t[n]!==void 0)return t[n];let r=e.getExtension(n);return t[n]=r,r}return{has:function(e){return n(e)!==null},init:function(){n(`EXT_color_buffer_float`),n(`WEBGL_clip_cull_distance`),n(`OES_texture_float_linear`),n(`EXT_color_buffer_half_float`),n(`WEBGL_multisampled_render_to_texture`),n(`WEBGL_render_shared_exponent`)},get:function(e){let t=n(e);return t===null&&mm(`WebGLRenderer: `+e+` extension not supported.`),t}}}function yne(e,t,n,r){let i={},a=new WeakMap;function o(e){let s=e.target;s.index!==null&&t.remove(s.index);for(let e in s.attributes)t.remove(s.attributes[e]);s.removeEventListener(`dispose`,o),delete i[s.id];let c=a.get(s);c&&(t.remove(c),a.delete(s)),r.releaseStatesOfGeometry(s),s.isInstancedBufferGeometry===!0&&delete s._maxInstanceCount,n.memory.geometries--}function s(e,t){return i[t.id]===!0?t:(t.addEventListener(`dispose`,o),i[t.id]=!0,n.memory.geometries++,t)}function c(n){let r=n.attributes;for(let n in r)t.update(r[n],e.ARRAY_BUFFER)}function l(e){let n=[],r=e.index,i=e.attributes.position,o=0;if(r!==null){let e=r.array;o=r.version;for(let t=0,r=e.length;tt.maxTextureSize&&(m=Math.ceil(p/t.maxTextureSize),p=t.maxTextureSize);let h=new Float32Array(p*m*4*u),g=new Ym(h,p,m,u);g.type=Np,g.needsUpdate=!0;let _=f*4;for(let t=0;t0)return e;let i=t*n,a=uv[i];if(a===void 0&&(a=new Float32Array(i),uv[i]=a),t!==0){r.toArray(a,0);for(let r=1,i=0;r!==t;++r)i+=n,e[r].toArray(a,i)}return a}function gv(e,t){if(e.length!==t.length)return!1;for(let n=0,r=e.length;n`:` `} ${i}: ${n[e]}`)}return r.join(` `)}var wv=new Fm;function gre(e){zm._getMatrix(wv,zm.workingColorSpace,e);let t=`mat3( ${wv.elements.map(e=>e.toFixed(4))} )`;switch(zm.getTransfer(e)){case nm:return[t,`LinearTransferOETF`];case rm:return[t,`sRGBTransferOETF`];default:return fm(`WebGLProgram: Unsupported color space: `,e),[t,`LinearTransferOETF`]}}function Tv(e,t,n){let r=e.getShaderParameter(t,e.COMPILE_STATUS),i=(e.getShaderInfoLog(t)||``).trim();if(r&&i===``)return``;let a=/ERROR: 0:(\d+)/.exec(i);if(a){let r=parseInt(a[1]);return n.toUpperCase()+` @@ -3987,7 +3987,7 @@ void main() { } -}`,nie=class{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(e,t){if(this.texture===null){let n=new g_(e.texture);(e.depthNear!==t.depthNear||e.depthFar!==t.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=n}}getMesh(e){if(this.texture!==null&&this.mesh===null){let t=e.cameras[0].viewport,n=new Hg({vertexShader:eie,fragmentShader:tie,uniforms:{depthColor:{value:this.texture},depthWidth:{value:t.z},depthHeight:{value:t.w}}});this.mesh=new Ig(new __(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}},rie=class extends hm{constructor(e,t){super();let n=this,r=null,i=1,a=null,o=`local-floor`,s=1,c=null,l=null,u=null,d=null,f=null,p=null,m=typeof XRWebGLBinding<`u`,h=new nie,g={},_=t.getContextAttributes(),v=null,y=null,b=[],x=[],S=new Am,C=null,w=new qg;w.viewport=new qm;let T=new qg;T.viewport=new qm;let E=[w,T],D=new Wte,O=null,k=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(e){let t=b[e];return t===void 0&&(t=new Qg,b[e]=t),t.getTargetRaySpace()},this.getControllerGrip=function(e){let t=b[e];return t===void 0&&(t=new Qg,b[e]=t),t.getGripSpace()},this.getHand=function(e){let t=b[e];return t===void 0&&(t=new Qg,b[e]=t),t.getHandSpace()};function A(e){let t=x.indexOf(e.inputSource);if(t===-1)return;let n=b[t];n!==void 0&&(n.update(e.inputSource,e.frame,c||a),n.dispatchEvent({type:e.type,data:e.inputSource}))}function j(){r.removeEventListener(`select`,A),r.removeEventListener(`selectstart`,A),r.removeEventListener(`selectend`,A),r.removeEventListener(`squeeze`,A),r.removeEventListener(`squeezestart`,A),r.removeEventListener(`squeezeend`,A),r.removeEventListener(`end`,j),r.removeEventListener(`inputsourceschange`,M);for(let e=0;e=0&&(x[r]=null,b[r].disconnect(n))}for(let t=0;t=x.length){x.push(n),r=e;break}else if(x[e]===null){x[e]=n,r=e;break}if(r===-1)break}let i=b[r];i&&i.connect(n)}}let N=new Mm,P=new Mm;function F(e,t,n){N.setFromMatrixPosition(t.matrixWorld),P.setFromMatrixPosition(n.matrixWorld);let r=N.distanceTo(P),i=t.projectionMatrix.elements,a=n.projectionMatrix.elements,o=i[14]/(i[10]-1),s=i[14]/(i[10]+1),c=(i[9]+1)/i[5],l=(i[9]-1)/i[5],u=(i[8]-1)/i[0],d=(a[8]+1)/a[0],f=o*u,p=o*d,m=r/(-u+d),h=m*-u;if(t.matrixWorld.decompose(e.position,e.quaternion,e.scale),e.translateX(h),e.translateZ(m),e.matrixWorld.compose(e.position,e.quaternion,e.scale),e.matrixWorldInverse.copy(e.matrixWorld).invert(),i[10]===-1)e.projectionMatrix.copy(t.projectionMatrix),e.projectionMatrixInverse.copy(t.projectionMatrixInverse);else{let t=o+m,n=s+m,i=f-h,a=p+(r-h),u=c*s/n*t,d=l*s/n*t;e.projectionMatrix.makePerspective(i,a,u,d,t,n),e.projectionMatrixInverse.copy(e.projectionMatrix).invert()}}function I(e,t){t===null?e.matrixWorld.copy(e.matrix):e.matrixWorld.multiplyMatrices(t.matrixWorld,e.matrix),e.matrixWorldInverse.copy(e.matrixWorld).invert()}this.updateCamera=function(e){if(r===null)return;let t=e.near,n=e.far;h.texture!==null&&(h.depthNear>0&&(t=h.depthNear),h.depthFar>0&&(n=h.depthFar)),D.near=T.near=w.near=t,D.far=T.far=w.far=n,(O!==D.near||k!==D.far)&&(r.updateRenderState({depthNear:D.near,depthFar:D.far}),O=D.near,k=D.far),D.layers.mask=e.layers.mask|6,w.layers.mask=D.layers.mask&3,T.layers.mask=D.layers.mask&5;let i=e.parent,a=D.cameras;I(D,i);for(let e=0;e0&&(e.alphaTest.value=r.alphaTest);let i=t.get(r),a=i.envMap,o=i.envMapRotation;a&&(e.envMap.value=a,Iv.copy(o),Iv.x*=-1,Iv.y*=-1,Iv.z*=-1,a.isCubeTexture&&a.isRenderTargetTexture===!1&&(Iv.y*=-1,Iv.z*=-1),e.envMapRotation.value.setFromMatrix4(iie.makeRotationFromEuler(Iv)),e.flipEnvMap.value=a.isCubeTexture&&a.isRenderTargetTexture===!1?-1:1,e.reflectivity.value=r.reflectivity,e.ior.value=r.ior,e.refractionRatio.value=r.refractionRatio),r.lightMap&&(e.lightMap.value=r.lightMap,e.lightMapIntensity.value=r.lightMapIntensity,n(r.lightMap,e.lightMapTransform)),r.aoMap&&(e.aoMap.value=r.aoMap,e.aoMapIntensity.value=r.aoMapIntensity,n(r.aoMap,e.aoMapTransform))}function o(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,t.map&&(e.map.value=t.map,n(t.map,e.mapTransform))}function s(e,t){e.dashSize.value=t.dashSize,e.totalSize.value=t.dashSize+t.gapSize,e.scale.value=t.scale}function c(e,t,r,i){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.size.value=t.size*r,e.scale.value=i*.5,t.map&&(e.map.value=t.map,n(t.map,e.uvTransform)),t.alphaMap&&(e.alphaMap.value=t.alphaMap,n(t.alphaMap,e.alphaMapTransform)),t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}function l(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.rotation.value=t.rotation,t.map&&(e.map.value=t.map,n(t.map,e.mapTransform)),t.alphaMap&&(e.alphaMap.value=t.alphaMap,n(t.alphaMap,e.alphaMapTransform)),t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}function u(e,t){e.specular.value.copy(t.specular),e.shininess.value=Math.max(t.shininess,1e-4)}function d(e,t){t.gradientMap&&(e.gradientMap.value=t.gradientMap)}function f(e,t){e.metalness.value=t.metalness,t.metalnessMap&&(e.metalnessMap.value=t.metalnessMap,n(t.metalnessMap,e.metalnessMapTransform)),e.roughness.value=t.roughness,t.roughnessMap&&(e.roughnessMap.value=t.roughnessMap,n(t.roughnessMap,e.roughnessMapTransform)),t.envMap&&(e.envMapIntensity.value=t.envMapIntensity)}function p(e,t,r){e.ior.value=t.ior,t.sheen>0&&(e.sheenColor.value.copy(t.sheenColor).multiplyScalar(t.sheen),e.sheenRoughness.value=t.sheenRoughness,t.sheenColorMap&&(e.sheenColorMap.value=t.sheenColorMap,n(t.sheenColorMap,e.sheenColorMapTransform)),t.sheenRoughnessMap&&(e.sheenRoughnessMap.value=t.sheenRoughnessMap,n(t.sheenRoughnessMap,e.sheenRoughnessMapTransform))),t.clearcoat>0&&(e.clearcoat.value=t.clearcoat,e.clearcoatRoughness.value=t.clearcoatRoughness,t.clearcoatMap&&(e.clearcoatMap.value=t.clearcoatMap,n(t.clearcoatMap,e.clearcoatMapTransform)),t.clearcoatRoughnessMap&&(e.clearcoatRoughnessMap.value=t.clearcoatRoughnessMap,n(t.clearcoatRoughnessMap,e.clearcoatRoughnessMapTransform)),t.clearcoatNormalMap&&(e.clearcoatNormalMap.value=t.clearcoatNormalMap,n(t.clearcoatNormalMap,e.clearcoatNormalMapTransform),e.clearcoatNormalScale.value.copy(t.clearcoatNormalScale),t.side===1&&e.clearcoatNormalScale.value.negate())),t.dispersion>0&&(e.dispersion.value=t.dispersion),t.iridescence>0&&(e.iridescence.value=t.iridescence,e.iridescenceIOR.value=t.iridescenceIOR,e.iridescenceThicknessMinimum.value=t.iridescenceThicknessRange[0],e.iridescenceThicknessMaximum.value=t.iridescenceThicknessRange[1],t.iridescenceMap&&(e.iridescenceMap.value=t.iridescenceMap,n(t.iridescenceMap,e.iridescenceMapTransform)),t.iridescenceThicknessMap&&(e.iridescenceThicknessMap.value=t.iridescenceThicknessMap,n(t.iridescenceThicknessMap,e.iridescenceThicknessMapTransform))),t.transmission>0&&(e.transmission.value=t.transmission,e.transmissionSamplerMap.value=r.texture,e.transmissionSamplerSize.value.set(r.width,r.height),t.transmissionMap&&(e.transmissionMap.value=t.transmissionMap,n(t.transmissionMap,e.transmissionMapTransform)),e.thickness.value=t.thickness,t.thicknessMap&&(e.thicknessMap.value=t.thicknessMap,n(t.thicknessMap,e.thicknessMapTransform)),e.attenuationDistance.value=t.attenuationDistance,e.attenuationColor.value.copy(t.attenuationColor)),t.anisotropy>0&&(e.anisotropyVector.value.set(t.anisotropy*Math.cos(t.anisotropyRotation),t.anisotropy*Math.sin(t.anisotropyRotation)),t.anisotropyMap&&(e.anisotropyMap.value=t.anisotropyMap,n(t.anisotropyMap,e.anisotropyMapTransform))),e.specularIntensity.value=t.specularIntensity,e.specularColor.value.copy(t.specularColor),t.specularColorMap&&(e.specularColorMap.value=t.specularColorMap,n(t.specularColorMap,e.specularColorMapTransform)),t.specularIntensityMap&&(e.specularIntensityMap.value=t.specularIntensityMap,n(t.specularIntensityMap,e.specularIntensityMapTransform))}function m(e,t){t.matcap&&(e.matcap.value=t.matcap)}function h(e,n){let r=t.get(n).light;e.referencePosition.value.setFromMatrixPosition(r.matrixWorld),e.nearDistance.value=r.shadow.camera.near,e.farDistance.value=r.shadow.camera.far}return{refreshFogUniforms:r,refreshMaterialUniforms:i}}function oie(e,t,n,r){let i={},a={},o=[],s=e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS);function c(e,t){let n=t.program;r.uniformBlockBinding(e,n)}function l(e,n){let o=i[e.id];o===void 0&&(m(e),o=u(e),i[e.id]=o,e.addEventListener(`dispose`,g));let s=n.program;r.updateUBOMapping(e,s);let c=t.render.frame;a[e.id]!==c&&(f(e),a[e.id]=c)}function u(t){let n=d();t.__bindingPointIndex=n;let r=e.createBuffer(),i=t.__size,a=t.usage;return e.bindBuffer(e.UNIFORM_BUFFER,r),e.bufferData(e.UNIFORM_BUFFER,i,a),e.bindBuffer(e.UNIFORM_BUFFER,null),e.bindBufferBase(e.UNIFORM_BUFFER,n,r),r}function d(){for(let e=0;e0&&(n+=16-r),e.__size=n,e.__cache={},this}function h(e){let t={boundary:0,storage:0};return typeof e==`number`||typeof e==`boolean`?(t.boundary=4,t.storage=4):e.isVector2?(t.boundary=8,t.storage=8):e.isVector3||e.isColor?(t.boundary=16,t.storage=12):e.isVector4?(t.boundary=16,t.storage=16):e.isMatrix3?(t.boundary=48,t.storage=48):e.isMatrix4?(t.boundary=64,t.storage=64):e.isTexture?fm(`WebGLRenderer: Texture samplers can not be part of an uniforms group.`):fm(`WebGLRenderer: Unsupported uniform value type.`,e),t}function g(t){let n=t.target;n.removeEventListener(`dispose`,g);let r=o.indexOf(n.__bindingPointIndex);o.splice(r,1),e.deleteBuffer(i[n.id]),delete i[n.id],delete a[n.id]}function _(){for(let t in i)e.deleteBuffer(i[t]);o=[],i={},a={}}return{bind:c,update:l,dispose:_}}var sie=new Uint16Array([11481,15204,11534,15171,11808,15015,12385,14843,12894,14716,13396,14600,13693,14483,13976,14366,14237,14171,14405,13961,14511,13770,14605,13598,14687,13444,14760,13305,14822,13066,14876,12857,14923,12675,14963,12517,14997,12379,15025,12230,15049,12023,15070,11843,15086,11687,15100,11551,15111,11433,15120,11330,15127,11217,15132,11060,15135,10922,15138,10801,15139,10695,15139,10600,13012,14923,13020,14917,13064,14886,13176,14800,13349,14666,13513,14526,13724,14398,13960,14230,14200,14020,14383,13827,14488,13651,14583,13491,14667,13348,14740,13132,14803,12908,14856,12713,14901,12542,14938,12394,14968,12241,14992,12017,15010,11822,15024,11654,15034,11507,15041,11380,15044,11269,15044,11081,15042,10913,15037,10764,15031,10635,15023,10520,15014,10419,15003,10330,13657,14676,13658,14673,13670,14660,13698,14622,13750,14547,13834,14442,13956,14317,14112,14093,14291,13889,14407,13704,14499,13538,14586,13389,14664,13201,14733,12966,14792,12758,14842,12577,14882,12418,14915,12272,14940,12033,14959,11826,14972,11646,14980,11490,14983,11355,14983,11212,14979,11008,14971,10830,14961,10675,14950,10540,14936,10420,14923,10315,14909,10204,14894,10041,14089,14460,14090,14459,14096,14452,14112,14431,14141,14388,14186,14305,14252,14130,14341,13941,14399,13756,14467,13585,14539,13430,14610,13272,14677,13026,14737,12808,14790,12617,14833,12449,14869,12303,14896,12065,14916,11845,14929,11655,14937,11490,14939,11347,14936,11184,14930,10970,14921,10783,14912,10621,14900,10480,14885,10356,14867,10247,14848,10062,14827,9894,14805,9745,14400,14208,14400,14206,14402,14198,14406,14174,14415,14122,14427,14035,14444,13913,14469,13767,14504,13613,14548,13463,14598,13324,14651,13082,14704,12858,14752,12658,14795,12483,14831,12330,14860,12106,14881,11875,14895,11675,14903,11501,14905,11351,14903,11178,14900,10953,14892,10757,14880,10589,14865,10442,14847,10313,14827,10162,14805,9965,14782,9792,14757,9642,14731,9507,14562,13883,14562,13883,14563,13877,14566,13862,14570,13830,14576,13773,14584,13689,14595,13582,14613,13461,14637,13336,14668,13120,14704,12897,14741,12695,14776,12516,14808,12358,14835,12150,14856,11910,14870,11701,14878,11519,14882,11361,14884,11187,14880,10951,14871,10748,14858,10572,14842,10418,14823,10286,14801,10099,14777,9897,14751,9722,14725,9567,14696,9430,14666,9309,14702,13604,14702,13604,14702,13600,14703,13591,14705,13570,14707,13533,14709,13477,14712,13400,14718,13305,14727,13106,14743,12907,14762,12716,14784,12539,14807,12380,14827,12190,14844,11943,14855,11727,14863,11539,14870,11376,14871,11204,14868,10960,14858,10748,14845,10565,14829,10406,14809,10269,14786,10058,14761,9852,14734,9671,14705,9512,14674,9374,14641,9253,14608,9076,14821,13366,14821,13365,14821,13364,14821,13358,14821,13344,14821,13320,14819,13252,14817,13145,14815,13011,14814,12858,14817,12698,14823,12539,14832,12389,14841,12214,14850,11968,14856,11750,14861,11558,14866,11390,14867,11226,14862,10972,14853,10754,14840,10565,14823,10401,14803,10259,14780,10032,14754,9820,14725,9635,14694,9473,14661,9333,14627,9203,14593,8988,14557,8798,14923,13014,14922,13014,14922,13012,14922,13004,14920,12987,14919,12957,14915,12907,14909,12834,14902,12738,14894,12623,14888,12498,14883,12370,14880,12203,14878,11970,14875,11759,14873,11569,14874,11401,14872,11243,14865,10986,14855,10762,14842,10568,14825,10401,14804,10255,14781,10017,14754,9799,14725,9611,14692,9445,14658,9301,14623,9139,14587,8920,14548,8729,14509,8562,15008,12672,15008,12672,15008,12671,15007,12667,15005,12656,15001,12637,14997,12605,14989,12556,14978,12490,14966,12407,14953,12313,14940,12136,14927,11934,14914,11742,14903,11563,14896,11401,14889,11247,14879,10992,14866,10767,14851,10570,14833,10400,14812,10252,14789,10007,14761,9784,14731,9592,14698,9424,14663,9279,14627,9088,14588,8868,14548,8676,14508,8508,14467,8360,15080,12386,15080,12386,15079,12385,15078,12383,15076,12378,15072,12367,15066,12347,15057,12315,15045,12253,15030,12138,15012,11998,14993,11845,14972,11685,14951,11530,14935,11383,14920,11228,14904,10981,14887,10762,14870,10567,14850,10397,14827,10248,14803,9997,14774,9771,14743,9578,14710,9407,14674,9259,14637,9048,14596,8826,14555,8632,14514,8464,14471,8317,14427,8182,15139,12008,15139,12008,15138,12008,15137,12007,15135,12003,15130,11990,15124,11969,15115,11929,15102,11872,15086,11794,15064,11693,15041,11581,15013,11459,14987,11336,14966,11170,14944,10944,14921,10738,14898,10552,14875,10387,14850,10239,14824,9983,14794,9758,14762,9563,14728,9392,14692,9244,14653,9014,14611,8791,14569,8597,14526,8427,14481,8281,14436,8110,14391,7885,15188,11617,15188,11617,15187,11617,15186,11618,15183,11617,15179,11612,15173,11601,15163,11581,15150,11546,15133,11495,15110,11427,15083,11346,15051,11246,15024,11057,14996,10868,14967,10687,14938,10517,14911,10362,14882,10206,14853,9956,14821,9737,14787,9543,14752,9375,14715,9228,14675,8980,14632,8760,14589,8565,14544,8395,14498,8248,14451,8049,14404,7824,14357,7630,15228,11298,15228,11298,15227,11299,15226,11301,15223,11303,15219,11302,15213,11299,15204,11290,15191,11271,15174,11217,15150,11129,15119,11015,15087,10886,15057,10744,15024,10599,14990,10455,14957,10318,14924,10143,14891,9911,14856,9701,14820,9516,14782,9352,14744,9200,14703,8946,14659,8725,14615,8533,14568,8366,14521,8220,14472,7992,14423,7770,14374,7578,14315,7408,15260,10819,15260,10819,15259,10822,15258,10826,15256,10832,15251,10836,15246,10841,15237,10838,15225,10821,15207,10788,15183,10734,15151,10660,15120,10571,15087,10469,15049,10359,15012,10249,14974,10041,14937,9837,14900,9647,14860,9475,14820,9320,14779,9147,14736,8902,14691,8688,14646,8499,14598,8335,14549,8189,14499,7940,14448,7720,14397,7529,14347,7363,14256,7218,15285,10410,15285,10411,15285,10413,15284,10418,15282,10425,15278,10434,15272,10442,15264,10449,15252,10445,15235,10433,15210,10403,15179,10358,15149,10301,15113,10218,15073,10059,15033,9894,14991,9726,14951,9565,14909,9413,14865,9273,14822,9073,14777,8845,14730,8641,14682,8459,14633,8300,14583,8129,14531,7883,14479,7670,14426,7482,14373,7321,14305,7176,14201,6939,15305,9939,15305,9940,15305,9945,15304,9955,15302,9967,15298,9989,15293,10010,15286,10033,15274,10044,15258,10045,15233,10022,15205,9975,15174,9903,15136,9808,15095,9697,15053,9578,15009,9451,14965,9327,14918,9198,14871,8973,14825,8766,14775,8579,14725,8408,14675,8259,14622,8058,14569,7821,14515,7615,14460,7435,14405,7276,14350,7108,14256,6866,14149,6653,15321,9444,15321,9445,15321,9448,15320,9458,15317,9470,15314,9490,15310,9515,15302,9540,15292,9562,15276,9579,15251,9577,15226,9559,15195,9519,15156,9463,15116,9389,15071,9304,15025,9208,14978,9023,14927,8838,14878,8661,14827,8496,14774,8344,14722,8206,14667,7973,14612,7749,14556,7555,14499,7382,14443,7229,14385,7025,14322,6791,14210,6588,14100,6409,15333,8920,15333,8921,15332,8927,15332,8943,15329,8965,15326,9002,15322,9048,15316,9106,15307,9162,15291,9204,15267,9221,15244,9221,15212,9196,15175,9134,15133,9043,15088,8930,15040,8801,14990,8665,14938,8526,14886,8391,14830,8261,14775,8087,14719,7866,14661,7664,14603,7482,14544,7322,14485,7178,14426,6936,14367,6713,14281,6517,14166,6348,14054,6198,15341,8360,15341,8361,15341,8366,15341,8379,15339,8399,15336,8431,15332,8473,15326,8527,15318,8585,15302,8632,15281,8670,15258,8690,15227,8690,15191,8664,15149,8612,15104,8543,15055,8456,15001,8360,14948,8259,14892,8122,14834,7923,14776,7734,14716,7558,14656,7397,14595,7250,14534,7070,14472,6835,14410,6628,14350,6443,14243,6283,14125,6135,14010,5889,15348,7715,15348,7717,15348,7725,15347,7745,15345,7780,15343,7836,15339,7905,15334,8e3,15326,8103,15310,8193,15293,8239,15270,8270,15240,8287,15204,8283,15163,8260,15118,8223,15067,8143,15014,8014,14958,7873,14899,7723,14839,7573,14778,7430,14715,7293,14652,7164,14588,6931,14524,6720,14460,6531,14396,6362,14330,6210,14207,6015,14086,5781,13969,5576,15352,7114,15352,7116,15352,7128,15352,7159,15350,7195,15348,7237,15345,7299,15340,7374,15332,7457,15317,7544,15301,7633,15280,7703,15251,7754,15216,7775,15176,7767,15131,7733,15079,7670,15026,7588,14967,7492,14906,7387,14844,7278,14779,7171,14714,6965,14648,6770,14581,6587,14515,6420,14448,6269,14382,6123,14299,5881,14172,5665,14049,5477,13929,5310,15355,6329,15355,6330,15355,6339,15355,6362,15353,6410,15351,6472,15349,6572,15344,6688,15337,6835,15323,6985,15309,7142,15287,7220,15260,7277,15226,7310,15188,7326,15142,7318,15090,7285,15036,7239,14976,7177,14914,7045,14849,6892,14782,6736,14714,6581,14645,6433,14576,6293,14506,6164,14438,5946,14369,5733,14270,5540,14140,5369,14014,5216,13892,5043,15357,5483,15357,5484,15357,5496,15357,5528,15356,5597,15354,5692,15351,5835,15347,6011,15339,6195,15328,6317,15314,6446,15293,6566,15268,6668,15235,6746,15197,6796,15152,6811,15101,6790,15046,6748,14985,6673,14921,6583,14854,6479,14785,6371,14714,6259,14643,6149,14571,5946,14499,5750,14428,5567,14358,5401,14242,5250,14109,5111,13980,4870,13856,4657,15359,4555,15359,4557,15358,4573,15358,4633,15357,4715,15355,4841,15353,5061,15349,5216,15342,5391,15331,5577,15318,5770,15299,5967,15274,6150,15243,6223,15206,6280,15161,6310,15111,6317,15055,6300,14994,6262,14928,6208,14860,6141,14788,5994,14715,5838,14641,5684,14566,5529,14492,5384,14418,5247,14346,5121,14216,4892,14079,4682,13948,4496,13822,4330,15359,3498,15359,3501,15359,3520,15359,3598,15358,3719,15356,3860,15355,4137,15351,4305,15344,4563,15334,4809,15321,5116,15303,5273,15280,5418,15250,5547,15214,5653,15170,5722,15120,5761,15064,5763,15002,5733,14935,5673,14865,5597,14792,5504,14716,5400,14640,5294,14563,5185,14486,5041,14410,4841,14335,4655,14191,4482,14051,4325,13918,4183,13790,4012,15360,2282,15360,2285,15360,2306,15360,2401,15359,2547,15357,2748,15355,3103,15352,3349,15345,3675,15336,4020,15324,4272,15307,4496,15285,4716,15255,4908,15220,5086,15178,5170,15128,5214,15072,5234,15010,5231,14943,5206,14871,5166,14796,5102,14718,4971,14639,4833,14559,4687,14480,4541,14402,4401,14315,4268,14167,4142,14025,3958,13888,3747,13759,3556,15360,923,15360,925,15360,946,15360,1052,15359,1214,15357,1494,15356,1892,15352,2274,15346,2663,15338,3099,15326,3393,15309,3679,15288,3980,15260,4183,15226,4325,15185,4437,15136,4517,15080,4570,15018,4591,14950,4581,14877,4545,14800,4485,14720,4411,14638,4325,14556,4231,14475,4136,14395,3988,14297,3803,14145,3628,13999,3465,13861,3314,13729,3177,15360,263,15360,264,15360,272,15360,325,15359,407,15358,548,15356,780,15352,1144,15347,1580,15339,2099,15328,2425,15312,2795,15292,3133,15264,3329,15232,3517,15191,3689,15143,3819,15088,3923,15025,3978,14956,3999,14882,3979,14804,3931,14722,3855,14639,3756,14554,3645,14470,3529,14388,3409,14279,3289,14124,3173,13975,3055,13834,2848,13701,2658,15360,49,15360,49,15360,52,15360,75,15359,111,15358,201,15356,283,15353,519,15348,726,15340,1045,15329,1415,15314,1795,15295,2173,15269,2410,15237,2649,15197,2866,15150,3054,15095,3140,15032,3196,14963,3228,14888,3236,14808,3224,14725,3191,14639,3146,14553,3088,14466,2976,14382,2836,14262,2692,14103,2549,13952,2409,13808,2278,13674,2154,15360,4,15360,4,15360,4,15360,13,15359,33,15358,59,15357,112,15353,199,15348,302,15341,456,15331,628,15316,827,15297,1082,15272,1332,15241,1601,15202,1851,15156,2069,15101,2172,15039,2256,14970,2314,14894,2348,14813,2358,14728,2344,14640,2311,14551,2263,14463,2203,14376,2133,14247,2059,14084,1915,13930,1761,13784,1609,13648,1464,15360,0,15360,0,15360,0,15360,3,15359,18,15358,26,15357,53,15354,80,15348,97,15341,165,15332,238,15318,326,15299,427,15275,529,15245,654,15207,771,15161,885,15108,994,15046,1089,14976,1170,14900,1229,14817,1266,14731,1284,14641,1282,14550,1260,14460,1223,14370,1174,14232,1116,14066,1050,13909,981,13761,910,13623,839]),Lv=null;function cie(){return Lv===null&&(Lv=new Ste(sie,32,32,Gp,Pp),Lv.minFilter=wp,Lv.magFilter=wp,Lv.wrapS=yp,Lv.wrapT=yp,Lv.generateMipmaps=!1,Lv.needsUpdate=!0),Lv}var lie=class{constructor(e={}){let{canvas:t=Iee(),context:n=null,depth:r=!0,stencil:i=!1,alpha:a=!1,antialias:o=!1,premultipliedAlpha:s=!0,preserveDrawingBuffer:c=!1,powerPreference:l=`default`,failIfMajorPerformanceCaveat:u=!1,reversedDepthBuffer:d=!1}=e;this.isWebGLRenderer=!0;let f;if(n!==null){if(typeof WebGLRenderingContext<`u`&&n instanceof WebGLRenderingContext)throw Error(`THREE.WebGLRenderer: WebGL 1 is not supported since r163.`);f=n.getContextAttributes().alpha}else f=a;let p=new Set([qp,Kp,Wp]),m=new Set([Dp,Mp,Ap,Lp,Fp,Ip]),h=new Uint32Array(4),g=new Int32Array(4),_=null,v=null,y=[],b=[];this.domElement=t,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=0,this.toneMappingExposure=1,this.transmissionResolutionScale=1;let x=this,S=!1;this._outputColorSpace=em;let C=0,w=0,T=null,E=-1,D=null,O=new qm,k=new qm,A=null,j=new cg(0),M=0,N=t.width,P=t.height,F=1,I=null,L=null,R=new qm(0,0,N,P),z=new qm(0,0,N,P),B=!1,V=new r_,ee=!1,H=!1,te=new Sh,ne=new Mm,re=new qm,U={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0},ie=!1;function ae(){return T===null?F:1}let W=n;function oe(e,n){return t.getContext(e,n)}try{let e={alpha:!0,depth:r,stencil:i,antialias:o,premultipliedAlpha:s,preserveDrawingBuffer:c,powerPreference:l,failIfMajorPerformanceCaveat:u};if(`setAttribute`in t&&t.setAttribute(`data-engine`,`three.js r181`),t.addEventListener(`webglcontextlost`,Ne,!1),t.addEventListener(`webglcontextrestored`,Pe,!1),t.addEventListener(`webglcontextcreationerror`,Fe,!1),W===null){let t=`webgl2`;if(W=oe(t,e),W===null)throw oe(t)?Error(`Error creating WebGL context with your selected attributes.`):Error(`Error creating WebGL context.`)}}catch(e){throw e(`WebGLRenderer: `+e.message),e}let se,ce,le,ue,de,fe,pe,me,he,ge,_e,ve,ye,be,xe,Se,Ce,we,Te,Ee,De,Oe,ke,Ae;function je(){se=new vne(W),se.init(),Oe=new $re(W,se),ce=new lne(W,se,e,Oe),le=new Zre(W,se),ce.reversedDepthBuffer&&d&&le.buffers.depth.setReversed(!0),ue=new xne(W),de=new Rre,fe=new Qre(W,se,le,de,ce,Oe,ue),pe=new dne(x),me=new _ne(x),he=new ine(W),ke=new sne(W,he),ge=new yne(W,he,ue,ke),_e=new Sne(W,ge,he,ue),Te=new av(W,ce,fe),Se=new une(de),ve=new Lre(x,pe,me,se,ce,ke,Se),ye=new aie(x,de),be=new Bre,xe=new Kre(se),we=new one(x,pe,me,le,_e,f,s),Ce=new Yre(x,_e,ce),Ae=new oie(W,ue,ce,le),Ee=new cne(W,se,ue),De=new bne(W,se,ue),ue.programs=ve.programs,x.capabilities=ce,x.extensions=se,x.properties=de,x.renderLists=be,x.shadowMap=Ce,x.state=le,x.info=ue}je();let Me=new rie(x,W);this.xr=Me,this.getContext=function(){return W},this.getContextAttributes=function(){return W.getContextAttributes()},this.forceContextLoss=function(){let e=se.get(`WEBGL_lose_context`);e&&e.loseContext()},this.forceContextRestore=function(){let e=se.get(`WEBGL_lose_context`);e&&e.restoreContext()},this.getPixelRatio=function(){return F},this.setPixelRatio=function(e){e!==void 0&&(F=e,this.setSize(N,P,!1))},this.getSize=function(e){return e.set(N,P)},this.setSize=function(e,n,r=!0){if(Me.isPresenting){fm(`WebGLRenderer: Can't change size while VR device is presenting.`);return}N=e,P=n,t.width=Math.floor(e*F),t.height=Math.floor(n*F),r===!0&&(t.style.width=e+`px`,t.style.height=n+`px`),this.setViewport(0,0,e,n)},this.getDrawingBufferSize=function(e){return e.set(N*F,P*F).floor()},this.setDrawingBufferSize=function(e,n,r){N=e,P=n,F=r,t.width=Math.floor(e*r),t.height=Math.floor(n*r),this.setViewport(0,0,e,n)},this.getCurrentViewport=function(e){return e.copy(O)},this.getViewport=function(e){return e.copy(R)},this.setViewport=function(e,t,n,r){e.isVector4?R.set(e.x,e.y,e.z,e.w):R.set(e,t,n,r),le.viewport(O.copy(R).multiplyScalar(F).round())},this.getScissor=function(e){return e.copy(z)},this.setScissor=function(e,t,n,r){e.isVector4?z.set(e.x,e.y,e.z,e.w):z.set(e,t,n,r),le.scissor(k.copy(z).multiplyScalar(F).round())},this.getScissorTest=function(){return B},this.setScissorTest=function(e){le.setScissorTest(B=e)},this.setOpaqueSort=function(e){I=e},this.setTransparentSort=function(e){L=e},this.getClearColor=function(e){return e.copy(we.getClearColor())},this.setClearColor=function(){we.setClearColor(...arguments)},this.getClearAlpha=function(){return we.getClearAlpha()},this.setClearAlpha=function(){we.setClearAlpha(...arguments)},this.clear=function(e=!0,t=!0,n=!0){let r=0;if(e){let e=!1;if(T!==null){let t=T.texture.format;e=p.has(t)}if(e){let e=T.texture.type,t=m.has(e),n=we.getClearColor(),r=we.getClearAlpha(),i=n.r,a=n.g,o=n.b;t?(h[0]=i,h[1]=a,h[2]=o,h[3]=r,W.clearBufferuiv(W.COLOR,0,h)):(g[0]=i,g[1]=a,g[2]=o,g[3]=r,W.clearBufferiv(W.COLOR,0,g))}else r|=W.COLOR_BUFFER_BIT}t&&(r|=W.DEPTH_BUFFER_BIT),n&&(r|=W.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),W.clear(r)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.dispose=function(){t.removeEventListener(`webglcontextlost`,Ne,!1),t.removeEventListener(`webglcontextrestored`,Pe,!1),t.removeEventListener(`webglcontextcreationerror`,Fe,!1),we.dispose(),be.dispose(),xe.dispose(),de.dispose(),pe.dispose(),me.dispose(),_e.dispose(),ke.dispose(),Ae.dispose(),ve.dispose(),Me.dispose(),Me.removeEventListener(`sessionstart`,He),Me.removeEventListener(`sessionend`,Ue),We.stop()};function Ne(e){e.preventDefault(),dm(`WebGLRenderer: Context Lost.`),S=!0}function Pe(){dm(`WebGLRenderer: Context Restored.`),S=!1;let e=ue.autoReset,t=Ce.enabled,n=Ce.autoUpdate,r=Ce.needsUpdate,i=Ce.type;je(),ue.autoReset=e,Ce.enabled=t,Ce.autoUpdate=n,Ce.needsUpdate=r,Ce.type=i}function Fe(e){pm(`WebGLRenderer: A WebGL context could not be created. Reason: `,e.statusMessage)}function Ie(e){let t=e.target;t.removeEventListener(`dispose`,Ie),Le(t)}function Le(e){Re(e),de.remove(e)}function Re(e){let t=de.get(e).programs;t!==void 0&&(t.forEach(function(e){ve.releaseProgram(e)}),e.isShaderMaterial&&ve.releaseShaderCache(e))}this.renderBufferDirect=function(e,t,n,r,i,a){t===null&&(t=U);let o=i.isMesh&&i.matrixWorld.determinant()<0,s=G(e,t,n,r,i);le.setMaterial(r,o);let c=n.index,l=1;if(r.wireframe===!0){if(c=ge.getWireframeAttribute(n),c===void 0)return;l=2}let u=n.drawRange,d=n.attributes.position,f=u.start*l,p=(u.start+u.count)*l;a!==null&&(f=Math.max(f,a.start*l),p=Math.min(p,(a.start+a.count)*l)),c===null?d!=null&&(f=Math.max(f,0),p=Math.min(p,d.count)):(f=Math.max(f,0),p=Math.min(p,c.count));let m=p-f;if(m<0||m===1/0)return;ke.setup(i,r,s,n,c);let h,g=Ee;if(c!==null&&(h=he.get(c),g=De,g.setIndex(h)),i.isMesh)r.wireframe===!0?(le.setLineWidth(r.wireframeLinewidth*ae()),g.setMode(W.LINES)):g.setMode(W.TRIANGLES);else if(i.isLine){let e=r.linewidth;e===void 0&&(e=1),le.setLineWidth(e*ae()),i.isLineSegments?g.setMode(W.LINES):i.isLineLoop?g.setMode(W.LINE_LOOP):g.setMode(W.LINE_STRIP)}else i.isPoints?g.setMode(W.POINTS):i.isSprite&&g.setMode(W.TRIANGLES);if(i.isBatchedMesh)if(i._multiDrawInstances!==null)mm(`WebGLRenderer: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection.`),g.renderMultiDrawInstances(i._multiDrawStarts,i._multiDrawCounts,i._multiDrawCount,i._multiDrawInstances);else if(se.get(`WEBGL_multi_draw`))g.renderMultiDraw(i._multiDrawStarts,i._multiDrawCounts,i._multiDrawCount);else{let e=i._multiDrawStarts,t=i._multiDrawCounts,n=i._multiDrawCount,a=c?he.get(c).bytesPerElement:1,o=de.get(r).currentProgram.getUniforms();for(let r=0;r{function n(){if(r.forEach(function(e){de.get(e).currentProgram.isReady()&&r.delete(e)}),r.size===0){t(e);return}setTimeout(n,10)}se.get(`KHR_parallel_shader_compile`)===null?setTimeout(n,10):n()})};let Be=null;function Ve(e){Be&&Be(e)}function He(){We.stop()}function Ue(){We.start()}let We=new R_;We.setAnimationLoop(Ve),typeof self<`u`&&We.setContext(self),this.setAnimationLoop=function(e){Be=e,Me.setAnimationLoop(e),e===null?We.stop():We.start()},Me.addEventListener(`sessionstart`,He),Me.addEventListener(`sessionend`,Ue),this.render=function(e,t){if(t!==void 0&&t.isCamera!==!0){pm(`WebGLRenderer.render: camera is not an instance of THREE.Camera.`);return}if(S===!0)return;if(e.matrixWorldAutoUpdate===!0&&e.updateMatrixWorld(),t.parent===null&&t.matrixWorldAutoUpdate===!0&&t.updateMatrixWorld(),Me.enabled===!0&&Me.isPresenting===!0&&(Me.cameraAutoUpdate===!0&&Me.updateCamera(t),t=Me.getCamera()),e.isScene===!0&&e.onBeforeRender(x,e,t,T),v=xe.get(e,b.length),v.init(t),b.push(v),te.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),V.setFromProjectionMatrix(te,om,t.reversedDepth),H=this.localClippingEnabled,ee=Se.init(this.clippingPlanes,H),_=be.get(e,y.length),_.init(),y.push(_),Me.enabled===!0&&Me.isPresenting===!0){let e=x.xr.getDepthSensingMesh();e!==null&&Ge(e,t,-1/0,x.sortObjects)}Ge(e,t,0,x.sortObjects),_.finish(),x.sortObjects===!0&&_.sort(I,L),ie=Me.enabled===!1||Me.isPresenting===!1||Me.hasDepthSensing()===!1,ie&&we.addToRenderList(_,e),this.info.render.frame++,ee===!0&&Se.beginShadows();let n=v.state.shadowsArray;Ce.render(n,e,t),ee===!0&&Se.endShadows(),this.info.autoReset===!0&&this.info.reset();let r=_.opaque,i=_.transmissive;if(v.setupLights(),t.isArrayCamera){let n=t.cameras;if(i.length>0)for(let t=0,a=n.length;t0&&qe(r,i,e,t),ie&&we.render(e),Ke(_,e,t);T!==null&&w===0&&(fe.updateMultisampleRenderTarget(T),fe.updateRenderTargetMipmap(T)),e.isScene===!0&&e.onAfterRender(x,e,t),ke.resetDefaultState(),E=-1,D=null,b.pop(),b.length>0?(v=b[b.length-1],ee===!0&&Se.setGlobalState(x.clippingPlanes,v.state.camera)):v=null,y.pop(),_=y.length>0?y[y.length-1]:null};function Ge(e,t,n,r){if(e.visible===!1)return;if(e.layers.test(t.layers)){if(e.isGroup)n=e.renderOrder;else if(e.isLOD)e.autoUpdate===!0&&e.update(t);else if(e.isLight)v.pushLight(e),e.castShadow&&v.pushShadow(e);else if(e.isSprite){if(!e.frustumCulled||V.intersectsSprite(e)){r&&re.setFromMatrixPosition(e.matrixWorld).applyMatrix4(te);let t=_e.update(e),i=e.material;i.visible&&_.push(e,t,i,n,re.z,null)}}else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||V.intersectsObject(e))){let t=_e.update(e),i=e.material;if(r&&(e.boundingSphere===void 0?(t.boundingSphere===null&&t.computeBoundingSphere(),re.copy(t.boundingSphere.center)):(e.boundingSphere===null&&e.computeBoundingSphere(),re.copy(e.boundingSphere.center)),re.applyMatrix4(e.matrixWorld).applyMatrix4(te)),Array.isArray(i)){let r=t.groups;for(let a=0,o=r.length;a0&&Je(i,t,n),a.length>0&&Je(a,t,n),o.length>0&&Je(o,t,n),le.buffers.depth.setTest(!0),le.buffers.depth.setMask(!0),le.buffers.color.setMask(!0),le.setPolygonOffset(!1)}function qe(e,t,n,r){if((n.isScene===!0?n.overrideMaterial:null)!==null)return;v.state.transmissionRenderTarget[r.id]===void 0&&(v.state.transmissionRenderTarget[r.id]=new Jm(1,1,{generateMipmaps:!0,type:se.has(`EXT_color_buffer_half_float`)||se.has(`EXT_color_buffer_float`)?Pp:Dp,minFilter:Ep,samples:4,stencilBuffer:i,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:zm.workingColorSpace}));let a=v.state.transmissionRenderTarget[r.id],o=r.viewport||O;a.setSize(o.z*x.transmissionResolutionScale,o.w*x.transmissionResolutionScale);let s=x.getRenderTarget(),c=x.getActiveCubeFace(),l=x.getActiveMipmapLevel();x.setRenderTarget(a),x.getClearColor(j),M=x.getClearAlpha(),M<1&&x.setClearColor(16777215,.5),x.clear(),ie&&we.render(n);let u=x.toneMapping;x.toneMapping=0;let d=r.viewport;if(r.viewport!==void 0&&(r.viewport=void 0),v.setupLightsView(r),ee===!0&&Se.setGlobalState(x.clippingPlanes,r),Je(e,n,r),fe.updateMultisampleRenderTarget(a),fe.updateRenderTargetMipmap(a),se.has(`WEBGL_multisampled_render_to_texture`)===!1){let e=!1;for(let i=0,a=t.length;i0),d=!!n.morphAttributes.position,f=!!n.morphAttributes.normal,p=!!n.morphAttributes.color,m=0;r.toneMapped&&(T===null||T.isXRRenderTarget===!0)&&(m=x.toneMapping);let h=n.morphAttributes.position||n.morphAttributes.normal||n.morphAttributes.color,g=h===void 0?0:h.length,_=de.get(r),y=v.state.lights;if(ee===!0&&(H===!0||e!==D)){let t=e===D&&r.id===E;Se.setState(r,e,t)}let b=!1;r.version===_.__version?_.needsLights&&_.lightsStateVersion!==y.state.version?b=!0:_.outputColorSpace===s?i.isBatchedMesh&&_.batching===!1||!i.isBatchedMesh&&_.batching===!0||i.isBatchedMesh&&_.batchingColor===!0&&i.colorTexture===null||i.isBatchedMesh&&_.batchingColor===!1&&i.colorTexture!==null||i.isInstancedMesh&&_.instancing===!1||!i.isInstancedMesh&&_.instancing===!0||i.isSkinnedMesh&&_.skinning===!1||!i.isSkinnedMesh&&_.skinning===!0||i.isInstancedMesh&&_.instancingColor===!0&&i.instanceColor===null||i.isInstancedMesh&&_.instancingColor===!1&&i.instanceColor!==null||i.isInstancedMesh&&_.instancingMorph===!0&&i.morphTexture===null||i.isInstancedMesh&&_.instancingMorph===!1&&i.morphTexture!==null?b=!0:_.envMap===c?r.fog===!0&&_.fog!==a||_.numClippingPlanes!==void 0&&(_.numClippingPlanes!==Se.numPlanes||_.numIntersection!==Se.numIntersection)?b=!0:_.vertexAlphas===l&&_.vertexTangents===u&&_.morphTargets===d&&_.morphNormals===f&&_.morphColors===p&&_.toneMapping===m?_.morphTargetsCount!==g&&(b=!0):b=!0:b=!0:b=!0:(b=!0,_.__version=r.version);let S=_.currentProgram;b===!0&&(S=Xe(r,t,i));let C=!1,w=!1,O=!1,k=S.getUniforms(),A=_.uniforms;if(le.useProgram(S.program)&&(C=!0,w=!0,O=!0),r.id!==E&&(E=r.id,w=!0),C||D!==e){le.buffers.depth.getReversed()&&e.reversedDepth!==!0&&(e._reversedDepth=!0,e.updateProjectionMatrix()),k.setValue(W,`projectionMatrix`,e.projectionMatrix),k.setValue(W,`viewMatrix`,e.matrixWorldInverse);let t=k.map.cameraPosition;t!==void 0&&t.setValue(W,ne.setFromMatrixPosition(e.matrixWorld)),ce.logarithmicDepthBuffer&&k.setValue(W,`logDepthBufFC`,2/(Math.log(e.far+1)/Math.LN2)),(r.isMeshPhongMaterial||r.isMeshToonMaterial||r.isMeshLambertMaterial||r.isMeshBasicMaterial||r.isMeshStandardMaterial||r.isShaderMaterial)&&k.setValue(W,`isOrthographic`,e.isOrthographicCamera===!0),D!==e&&(D=e,w=!0,O=!0)}if(i.isSkinnedMesh){k.setOptional(W,i,`bindMatrix`),k.setOptional(W,i,`bindMatrixInverse`);let e=i.skeleton;e&&(e.boneTexture===null&&e.computeBoneTexture(),k.setValue(W,`boneTexture`,e.boneTexture,fe))}i.isBatchedMesh&&(k.setOptional(W,i,`batchingTexture`),k.setValue(W,`batchingTexture`,i._matricesTexture,fe),k.setOptional(W,i,`batchingIdTexture`),k.setValue(W,`batchingIdTexture`,i._indirectTexture,fe),k.setOptional(W,i,`batchingColorTexture`),i._colorsTexture!==null&&k.setValue(W,`batchingColorTexture`,i._colorsTexture,fe));let j=n.morphAttributes;if((j.position!==void 0||j.normal!==void 0||j.color!==void 0)&&Te.update(i,n,S),(w||_.receiveShadow!==i.receiveShadow)&&(_.receiveShadow=i.receiveShadow,k.setValue(W,`receiveShadow`,i.receiveShadow)),r.isMeshGouraudMaterial&&r.envMap!==null&&(A.envMap.value=c,A.flipEnvMap.value=c.isCubeTexture&&c.isRenderTargetTexture===!1?-1:1),r.isMeshStandardMaterial&&r.envMap===null&&t.environment!==null&&(A.envMapIntensity.value=t.environmentIntensity),A.dfgLUT!==void 0&&(A.dfgLUT.value=cie()),w&&(k.setValue(W,`toneMappingExposure`,x.toneMappingExposure),_.needsLights&&$e(A,O),a&&r.fog===!0&&ye.refreshFogUniforms(A,a),ye.refreshMaterialUniforms(A,r,F,P,v.state.transmissionRenderTarget[e.id]),Sv.upload(W,Ze(_),A,fe)),r.isShaderMaterial&&r.uniformsNeedUpdate===!0&&(Sv.upload(W,Ze(_),A,fe),r.uniformsNeedUpdate=!1),r.isSpriteMaterial&&k.setValue(W,`center`,i.center),k.setValue(W,`modelViewMatrix`,i.modelViewMatrix),k.setValue(W,`normalMatrix`,i.normalMatrix),k.setValue(W,`modelMatrix`,i.matrixWorld),r.isShaderMaterial||r.isRawShaderMaterial){let e=r.uniformsGroups;for(let t=0,n=e.length;t0&&fe.useMultisampledRTT(e)===!1?de.get(e).__webglMultisampledFramebuffer:Array.isArray(l)?l[n]:l,O.copy(e.viewport),k.copy(e.scissor),A=e.scissorTest}else O.copy(R).multiplyScalar(F).floor(),k.copy(z).multiplyScalar(F).floor(),A=B;if(n!==0&&(i=tt),le.bindFramebuffer(W.FRAMEBUFFER,i)&&r&&le.drawBuffers(e,i),le.viewport(O),le.scissor(k),le.setScissorTest(A),a){let r=de.get(e.texture);W.framebufferTexture2D(W.FRAMEBUFFER,W.COLOR_ATTACHMENT0,W.TEXTURE_CUBE_MAP_POSITIVE_X+t,r.__webglTexture,n)}else if(o){let r=t;for(let t=0;t=0&&t<=e.width-r&&n>=0&&n<=e.height-i&&(e.textures.length>1&&W.readBuffer(W.COLOR_ATTACHMENT0+s),W.readPixels(t,n,r,i,Oe.convert(c),Oe.convert(l),a))}finally{let e=T===null?null:de.get(T).__webglFramebuffer;le.bindFramebuffer(W.FRAMEBUFFER,e)}}},this.readRenderTargetPixelsAsync=async function(e,t,n,r,i,a,o,s=0){if(!(e&&e.isWebGLRenderTarget))throw Error(`THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.`);let c=de.get(e).__webglFramebuffer;if(e.isWebGLCubeRenderTarget&&o!==void 0&&(c=c[o]),c)if(t>=0&&t<=e.width-r&&n>=0&&n<=e.height-i){le.bindFramebuffer(W.FRAMEBUFFER,c);let o=e.textures[s],l=o.format,u=o.type;if(!ce.textureFormatReadable(l))throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.`);if(!ce.textureTypeReadable(u))throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.`);let d=W.createBuffer();W.bindBuffer(W.PIXEL_PACK_BUFFER,d),W.bufferData(W.PIXEL_PACK_BUFFER,a.byteLength,W.STREAM_READ),e.textures.length>1&&W.readBuffer(W.COLOR_ATTACHMENT0+s),W.readPixels(t,n,r,i,Oe.convert(l),Oe.convert(u),0);let f=T===null?null:de.get(T).__webglFramebuffer;le.bindFramebuffer(W.FRAMEBUFFER,f);let p=W.fenceSync(W.SYNC_GPU_COMMANDS_COMPLETE,0);return W.flush(),await Lee(W,p,4),W.bindBuffer(W.PIXEL_PACK_BUFFER,d),W.getBufferSubData(W.PIXEL_PACK_BUFFER,0,a),W.deleteBuffer(d),W.deleteSync(p),a}else throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.`)},this.copyFramebufferToTexture=function(e,t=null,n=0){let r=2**-n,i=Math.floor(e.image.width*r),a=Math.floor(e.image.height*r),o=t===null?0:t.x,s=t===null?0:t.y;fe.setTexture2D(e,0),W.copyTexSubImage2D(W.TEXTURE_2D,n,0,0,o,s,i,a),le.unbindTexture()};let nt=W.createFramebuffer(),rt=W.createFramebuffer();this.copyTextureToTexture=function(e,t,n=null,r=null,i=0,a=null){a===null&&(i===0?a=0:(mm(`WebGLRenderer: copyTextureToTexture function signature has changed to support src and dst mipmap levels.`),a=i,i=0));let o,s,c,l,u,d,f,p,m,h=e.isCompressedTexture?e.mipmaps[a]:e.image;if(n!==null)o=n.max.x-n.min.x,s=n.max.y-n.min.y,c=n.isBox3?n.max.z-n.min.z:1,l=n.min.x,u=n.min.y,d=n.isBox3?n.min.z:0;else{let t=2**-i;o=Math.floor(h.width*t),s=Math.floor(h.height*t),c=e.isDataArrayTexture?h.depth:e.isData3DTexture?Math.floor(h.depth*t):1,l=0,u=0,d=0}r===null?(f=0,p=0,m=0):(f=r.x,p=r.y,m=r.z);let g=Oe.convert(t.format),_=Oe.convert(t.type),v;t.isData3DTexture?(fe.setTexture3D(t,0),v=W.TEXTURE_3D):t.isDataArrayTexture||t.isCompressedArrayTexture?(fe.setTexture2DArray(t,0),v=W.TEXTURE_2D_ARRAY):(fe.setTexture2D(t,0),v=W.TEXTURE_2D),W.pixelStorei(W.UNPACK_FLIP_Y_WEBGL,t.flipY),W.pixelStorei(W.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),W.pixelStorei(W.UNPACK_ALIGNMENT,t.unpackAlignment);let y=W.getParameter(W.UNPACK_ROW_LENGTH),b=W.getParameter(W.UNPACK_IMAGE_HEIGHT),x=W.getParameter(W.UNPACK_SKIP_PIXELS),S=W.getParameter(W.UNPACK_SKIP_ROWS),C=W.getParameter(W.UNPACK_SKIP_IMAGES);W.pixelStorei(W.UNPACK_ROW_LENGTH,h.width),W.pixelStorei(W.UNPACK_IMAGE_HEIGHT,h.height),W.pixelStorei(W.UNPACK_SKIP_PIXELS,l),W.pixelStorei(W.UNPACK_SKIP_ROWS,u),W.pixelStorei(W.UNPACK_SKIP_IMAGES,d);let w=e.isDataArrayTexture||e.isData3DTexture,T=t.isDataArrayTexture||t.isData3DTexture;if(e.isDepthTexture){let n=de.get(e),r=de.get(t),h=de.get(n.__renderTarget),g=de.get(r.__renderTarget);le.bindFramebuffer(W.READ_FRAMEBUFFER,h.__webglFramebuffer),le.bindFramebuffer(W.DRAW_FRAMEBUFFER,g.__webglFramebuffer);for(let n=0;nMath.PI&&(n-=Wv),r<-Math.PI?r+=Wv:r>Math.PI&&(r-=Wv),n<=r?this._spherical.theta=Math.max(n,Math.min(r,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(n+r)/2?Math.max(n,this._spherical.theta):Math.min(r,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let i=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{let e=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),i=e!=this._spherical.radius}if(Uv.setFromSpherical(this._spherical),Uv.applyQuaternion(this._quatInverse),t.copy(this.target).add(Uv),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let e=null;if(this.object.isPerspectiveCamera){let t=Uv.length();e=this._clampDistance(t*this._scale);let n=t-e;this.object.position.addScaledVector(this._dollyDirection,n),this.object.updateMatrixWorld(),i=!!n}else if(this.object.isOrthographicCamera){let t=new Mm(this._mouse.x,this._mouse.y,0);t.unproject(this.object);let n=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),i=n!==this.object.zoom;let r=new Mm(this._mouse.x,this._mouse.y,0);r.unproject(this.object),this.object.position.sub(r).add(t),this.object.updateMatrixWorld(),e=Uv.length()}else console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.`),this.zoomToCursor=!1;e!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(e).add(this.object.position):(Vv.origin.copy(this.object.position),Vv.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(Vv.direction))Kv||8*(1-this._lastQuaternion.dot(this.object.quaternion))>Kv||this._lastTargetPosition.distanceToSquared(this.target)>Kv?(this.dispatchEvent(Rv),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e===null?Wv/60/60*this.autoRotateSpeed:Wv/60*this.autoRotateSpeed*e}_getZoomScale(e){let t=Math.abs(e*.01);return .95**(this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){Uv.setFromMatrixColumn(t,0),Uv.multiplyScalar(-e),this._panOffset.add(Uv)}_panUp(e,t){this.screenSpacePanning===!0?Uv.setFromMatrixColumn(t,1):(Uv.setFromMatrixColumn(t,0),Uv.crossVectors(this.object.up,Uv)),Uv.multiplyScalar(e),this._panOffset.add(Uv)}_pan(e,t){let n=this.domElement;if(this.object.isPerspectiveCamera){let r=this.object.position;Uv.copy(r).sub(this.target);let i=Uv.length();i*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*i/n.clientHeight,this.object.matrix),this._panUp(2*t*i/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.`),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.`),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.`),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;let n=this.domElement.getBoundingClientRect(),r=e-n.left,i=t-n.top,a=n.width,o=n.height;this._mouse.x=r/a*2-1,this._mouse.y=-(i/o)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);let t=this.domElement;this._rotateLeft(Wv*this._rotateDelta.x/t.clientHeight),this._rotateUp(Wv*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(Wv*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-Wv*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(Wv*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-Wv*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._rotateStart.set(n,r)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._panStart.set(n,r)}}_handleTouchStartDolly(e){let t=this._getSecondPointerPosition(e),n=e.pageX-t.x,r=e.pageY-t.y,i=Math.sqrt(n*n+r*r);this._dollyStart.set(0,i)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._rotateEnd.set(n,r)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);let t=this.domElement;this._rotateLeft(Wv*this._rotateDelta.x/t.clientHeight),this._rotateUp(Wv*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._panEnd.set(n,r)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){let t=this._getSecondPointerPosition(e),n=e.pageX-t.x,r=e.pageY-t.y,i=Math.sqrt(n*n+r*r);this._dollyEnd.set(0,i),this._dollyDelta.set(0,(this._dollyEnd.y/this._dollyStart.y)**+this.zoomSpeed),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);let a=(e.pageX+t.x)*.5,o=(e.pageY+t.y)*.5;this._updateZoomParameters(a,o)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t>5&31)/31,a=(e>>10&31)/31)}for(let c=1;c<=3;c++){let l=n+c*12,u=e*3*3+(c-1)*3;p[u]=t.getFloat32(l,!0),p[u+1]=t.getFloat32(l+4,!0),p[u+2]=t.getFloat32(l+8,!0),m[u]=d,m[u+1]=f,m[u+2]=g,o&&(h.setRGB(r,i,a,em),s[u]=h.r,s[u+1]=h.g,s[u+2]=h.b)}}return f.setAttribute(`position`,new mg(p,3)),f.setAttribute(`normal`,new mg(m,3)),o&&(f.setAttribute(`color`,new mg(s,3)),f.hasColors=!0,f.alpha=d),f}function i(e){let t=new wg,n=/solid([\s\S]*?)endsolid/g,r=/facet([\s\S]*?)endfacet/g,i=/solid\s(.+)/,a=0,o=RegExp(`vertex[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)`,`g`),s=RegExp(`normal[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)`,`g`),c=[],l=[],u=[],d=new Mm,f,p=0,m=0,h=0;for(;(f=n.exec(e))!==null;){m=h;let e=f[0],n=(f=i.exec(e))===null?``:f[1];for(u.push(n);(f=r.exec(e))!==null;){let e=0,t=0,n=f[0];for(;(f=s.exec(n))!==null;)d.x=parseFloat(f[1]),d.y=parseFloat(f[2]),d.z=parseFloat(f[3]),t++;for(;(f=o.exec(n))!==null;)c.push(parseFloat(f[1]),parseFloat(f[2]),parseFloat(f[3])),l.push(d.x,d.y,d.z),e++,h++;t!==1&&console.error(`THREE.STLLoader: Something isn't right with the normal of face number `+a),e!==3&&console.error(`THREE.STLLoader: Something isn't right with the vertices of face number `+a),a++}let g=m,_=h-m;t.userData.groupNames=u,t.addGroup(g,_,p),p++}return t.setAttribute(`position`,new _g(c,3)),t.setAttribute(`normal`,new _g(l,3)),t}function a(e){return typeof e==`string`?e:new TextDecoder().decode(e)}function o(e){if(typeof e==`string`){let t=new Uint8Array(e.length);for(let n=0;n{(function(n){typeof e==`object`&&t!==void 0?t.exports=n():typeof define==`function`&&define.amd?define([],n):(typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:this).JSZip=n()})(function(){return function e(t,n,r){function i(o,s){if(!n[o]){if(!t[o]){var c=typeof u==`function`&&u;if(!s&&c)return c(o,!0);if(a)return a(o,!0);var l=Error(`Cannot find module '`+o+`'`);throw l.code=`MODULE_NOT_FOUND`,l}var d=n[o]={exports:{}};t[o][0].call(d.exports,function(e){var n=t[o][1][e];return i(n||e)},d,d.exports,e,t,n,r)}return n[o].exports}for(var a=typeof u==`function`&&u,o=0;o>2,s=(3&t)<<4|n>>4,c=1>6:64,l=2>4,n=(15&o)<<4|(s=a.indexOf(e.charAt(l++)))>>2,r=(3&s)<<6|(c=a.indexOf(e.charAt(l++))),f[u++]=t,s!==64&&(f[u++]=n),c!==64&&(f[u++]=r);return f}},{"./support":30,"./utils":32}],2:[function(e,t,n){var r=e(`./external`),i=e(`./stream/DataWorker`),a=e(`./stream/Crc32Probe`),o=e(`./stream/DataLengthProbe`);function s(e,t,n,r,i){this.compressedSize=e,this.uncompressedSize=t,this.crc32=n,this.compression=r,this.compressedContent=i}s.prototype={getContentWorker:function(){var e=new i(r.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new o(`data_length`)),t=this;return e.on(`end`,function(){if(this.streamInfo.data_length!==t.uncompressedSize)throw Error(`Bug : uncompressed data size mismatch`)}),e},getCompressedWorker:function(){return new i(r.Promise.resolve(this.compressedContent)).withStreamInfo(`compressedSize`,this.compressedSize).withStreamInfo(`uncompressedSize`,this.uncompressedSize).withStreamInfo(`crc32`,this.crc32).withStreamInfo(`compression`,this.compression)}},s.createWorkerFrom=function(e,t,n){return e.pipe(new a).pipe(new o(`uncompressedSize`)).pipe(t.compressWorker(n)).pipe(new o(`compressedSize`)).withStreamInfo(`compression`,t)},t.exports=s},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(e,t,n){var r=e(`./stream/GenericWorker`);n.STORE={magic:`\0\0`,compressWorker:function(){return new r(`STORE compression`)},uncompressWorker:function(){return new r(`STORE decompression`)}},n.DEFLATE=e(`./flate`)},{"./flate":7,"./stream/GenericWorker":28}],4:[function(e,t,n){var r=e(`./utils`),i=function(){for(var e,t=[],n=0;n<256;n++){e=n;for(var r=0;r<8;r++)e=1&e?3988292384^e>>>1:e>>>1;t[n]=e}return t}();t.exports=function(e,t){return e!==void 0&&e.length?r.getTypeOf(e)===`string`?function(e,t,n,r){var a=i,o=r+n;e^=-1;for(var s=r;s>>8^a[255&(e^t.charCodeAt(s))];return-1^e}(0|t,e,e.length,0):function(e,t,n,r){var a=i,o=r+n;e^=-1;for(var s=r;s>>8^a[255&(e^t[s])];return-1^e}(0|t,e,e.length,0):0}},{"./utils":32}],5:[function(e,t,n){n.base64=!1,n.binary=!1,n.dir=!1,n.createFolders=!0,n.date=null,n.compression=null,n.compressionOptions=null,n.comment=null,n.unixPermissions=null,n.dosPermissions=null},{}],6:[function(e,t,n){var r=null;r=typeof Promise<`u`?Promise:e(`lie`),t.exports={Promise:r}},{lie:37}],7:[function(e,t,n){var r=typeof Uint8Array<`u`&&typeof Uint16Array<`u`&&typeof Uint32Array<`u`,i=e(`pako`),a=e(`./utils`),o=e(`./stream/GenericWorker`),s=r?`uint8array`:`array`;function c(e,t){o.call(this,`FlateWorker/`+e),this._pako=null,this._pakoAction=e,this._pakoOptions=t,this.meta={}}n.magic=`\b\0`,a.inherits(c,o),c.prototype.processChunk=function(e){this.meta=e.meta,this._pako===null&&this._createPako(),this._pako.push(a.transformTo(s,e.data),!1)},c.prototype.flush=function(){o.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},c.prototype.cleanUp=function(){o.prototype.cleanUp.call(this),this._pako=null},c.prototype._createPako=function(){this._pako=new i[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var e=this;this._pako.onData=function(t){e.push({data:t,meta:e.meta})}},n.compressWorker=function(e){return new c(`Deflate`,e)},n.uncompressWorker=function(){return new c(`Inflate`,{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(e,t,n){function r(e,t){var n,r=``;for(n=0;n>>=8;return r}function i(e,t,n,i,o,u){var d,f,p=e.file,m=e.compression,h=u!==s.utf8encode,g=a.transformTo(`string`,u(p.name)),_=a.transformTo(`string`,s.utf8encode(p.name)),v=p.comment,y=a.transformTo(`string`,u(v)),b=a.transformTo(`string`,s.utf8encode(v)),x=_.length!==p.name.length,S=b.length!==v.length,C=``,w=``,T=``,E=p.dir,D=p.date,O={crc32:0,compressedSize:0,uncompressedSize:0};t&&!n||(O.crc32=e.crc32,O.compressedSize=e.compressedSize,O.uncompressedSize=e.uncompressedSize);var k=0;t&&(k|=8),h||!x&&!S||(k|=2048);var A=0,j=0;E&&(A|=16),o===`UNIX`?(j=798,A|=function(e,t){var n=e;return e||(n=t?16893:33204),(65535&n)<<16}(p.unixPermissions,E)):(j=20,A|=function(e){return 63&(e||0)}(p.dosPermissions)),d=D.getUTCHours(),d<<=6,d|=D.getUTCMinutes(),d<<=5,d|=D.getUTCSeconds()/2,f=D.getUTCFullYear()-1980,f<<=4,f|=D.getUTCMonth()+1,f<<=5,f|=D.getUTCDate(),x&&(w=r(1,1)+r(c(g),4)+_,C+=`up`+r(w.length,2)+w),S&&(T=r(1,1)+r(c(y),4)+b,C+=`uc`+r(T.length,2)+T);var M=``;return M+=` +}`,nie=class{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(e,t){if(this.texture===null){let n=new g_(e.texture);(e.depthNear!==t.depthNear||e.depthFar!==t.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=n}}getMesh(e){if(this.texture!==null&&this.mesh===null){let t=e.cameras[0].viewport,n=new Hg({vertexShader:eie,fragmentShader:tie,uniforms:{depthColor:{value:this.texture},depthWidth:{value:t.z},depthHeight:{value:t.w}}});this.mesh=new Ig(new __(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}},rie=class extends hm{constructor(e,t){super();let n=this,r=null,i=1,a=null,o=`local-floor`,s=1,c=null,l=null,u=null,d=null,f=null,p=null,m=typeof XRWebGLBinding<`u`,h=new nie,g={},_=t.getContextAttributes(),v=null,y=null,b=[],x=[],S=new Am,C=null,w=new qg;w.viewport=new qm;let T=new qg;T.viewport=new qm;let E=[w,T],D=new Wte,O=null,k=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(e){let t=b[e];return t===void 0&&(t=new Qg,b[e]=t),t.getTargetRaySpace()},this.getControllerGrip=function(e){let t=b[e];return t===void 0&&(t=new Qg,b[e]=t),t.getGripSpace()},this.getHand=function(e){let t=b[e];return t===void 0&&(t=new Qg,b[e]=t),t.getHandSpace()};function A(e){let t=x.indexOf(e.inputSource);if(t===-1)return;let n=b[t];n!==void 0&&(n.update(e.inputSource,e.frame,c||a),n.dispatchEvent({type:e.type,data:e.inputSource}))}function j(){r.removeEventListener(`select`,A),r.removeEventListener(`selectstart`,A),r.removeEventListener(`selectend`,A),r.removeEventListener(`squeeze`,A),r.removeEventListener(`squeezestart`,A),r.removeEventListener(`squeezeend`,A),r.removeEventListener(`end`,j),r.removeEventListener(`inputsourceschange`,M);for(let e=0;e=0&&(x[r]=null,b[r].disconnect(n))}for(let t=0;t=x.length){x.push(n),r=e;break}else if(x[e]===null){x[e]=n,r=e;break}if(r===-1)break}let i=b[r];i&&i.connect(n)}}let N=new Mm,P=new Mm;function F(e,t,n){N.setFromMatrixPosition(t.matrixWorld),P.setFromMatrixPosition(n.matrixWorld);let r=N.distanceTo(P),i=t.projectionMatrix.elements,a=n.projectionMatrix.elements,o=i[14]/(i[10]-1),s=i[14]/(i[10]+1),c=(i[9]+1)/i[5],l=(i[9]-1)/i[5],u=(i[8]-1)/i[0],d=(a[8]+1)/a[0],f=o*u,p=o*d,m=r/(-u+d),h=m*-u;if(t.matrixWorld.decompose(e.position,e.quaternion,e.scale),e.translateX(h),e.translateZ(m),e.matrixWorld.compose(e.position,e.quaternion,e.scale),e.matrixWorldInverse.copy(e.matrixWorld).invert(),i[10]===-1)e.projectionMatrix.copy(t.projectionMatrix),e.projectionMatrixInverse.copy(t.projectionMatrixInverse);else{let t=o+m,n=s+m,i=f-h,a=p+(r-h),u=c*s/n*t,d=l*s/n*t;e.projectionMatrix.makePerspective(i,a,u,d,t,n),e.projectionMatrixInverse.copy(e.projectionMatrix).invert()}}function I(e,t){t===null?e.matrixWorld.copy(e.matrix):e.matrixWorld.multiplyMatrices(t.matrixWorld,e.matrix),e.matrixWorldInverse.copy(e.matrixWorld).invert()}this.updateCamera=function(e){if(r===null)return;let t=e.near,n=e.far;h.texture!==null&&(h.depthNear>0&&(t=h.depthNear),h.depthFar>0&&(n=h.depthFar)),D.near=T.near=w.near=t,D.far=T.far=w.far=n,(O!==D.near||k!==D.far)&&(r.updateRenderState({depthNear:D.near,depthFar:D.far}),O=D.near,k=D.far),D.layers.mask=e.layers.mask|6,w.layers.mask=D.layers.mask&3,T.layers.mask=D.layers.mask&5;let i=e.parent,a=D.cameras;I(D,i);for(let e=0;e0&&(e.alphaTest.value=r.alphaTest);let i=t.get(r),a=i.envMap,o=i.envMapRotation;a&&(e.envMap.value=a,Iv.copy(o),Iv.x*=-1,Iv.y*=-1,Iv.z*=-1,a.isCubeTexture&&a.isRenderTargetTexture===!1&&(Iv.y*=-1,Iv.z*=-1),e.envMapRotation.value.setFromMatrix4(iie.makeRotationFromEuler(Iv)),e.flipEnvMap.value=a.isCubeTexture&&a.isRenderTargetTexture===!1?-1:1,e.reflectivity.value=r.reflectivity,e.ior.value=r.ior,e.refractionRatio.value=r.refractionRatio),r.lightMap&&(e.lightMap.value=r.lightMap,e.lightMapIntensity.value=r.lightMapIntensity,n(r.lightMap,e.lightMapTransform)),r.aoMap&&(e.aoMap.value=r.aoMap,e.aoMapIntensity.value=r.aoMapIntensity,n(r.aoMap,e.aoMapTransform))}function o(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,t.map&&(e.map.value=t.map,n(t.map,e.mapTransform))}function s(e,t){e.dashSize.value=t.dashSize,e.totalSize.value=t.dashSize+t.gapSize,e.scale.value=t.scale}function c(e,t,r,i){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.size.value=t.size*r,e.scale.value=i*.5,t.map&&(e.map.value=t.map,n(t.map,e.uvTransform)),t.alphaMap&&(e.alphaMap.value=t.alphaMap,n(t.alphaMap,e.alphaMapTransform)),t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}function l(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.rotation.value=t.rotation,t.map&&(e.map.value=t.map,n(t.map,e.mapTransform)),t.alphaMap&&(e.alphaMap.value=t.alphaMap,n(t.alphaMap,e.alphaMapTransform)),t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}function u(e,t){e.specular.value.copy(t.specular),e.shininess.value=Math.max(t.shininess,1e-4)}function d(e,t){t.gradientMap&&(e.gradientMap.value=t.gradientMap)}function f(e,t){e.metalness.value=t.metalness,t.metalnessMap&&(e.metalnessMap.value=t.metalnessMap,n(t.metalnessMap,e.metalnessMapTransform)),e.roughness.value=t.roughness,t.roughnessMap&&(e.roughnessMap.value=t.roughnessMap,n(t.roughnessMap,e.roughnessMapTransform)),t.envMap&&(e.envMapIntensity.value=t.envMapIntensity)}function p(e,t,r){e.ior.value=t.ior,t.sheen>0&&(e.sheenColor.value.copy(t.sheenColor).multiplyScalar(t.sheen),e.sheenRoughness.value=t.sheenRoughness,t.sheenColorMap&&(e.sheenColorMap.value=t.sheenColorMap,n(t.sheenColorMap,e.sheenColorMapTransform)),t.sheenRoughnessMap&&(e.sheenRoughnessMap.value=t.sheenRoughnessMap,n(t.sheenRoughnessMap,e.sheenRoughnessMapTransform))),t.clearcoat>0&&(e.clearcoat.value=t.clearcoat,e.clearcoatRoughness.value=t.clearcoatRoughness,t.clearcoatMap&&(e.clearcoatMap.value=t.clearcoatMap,n(t.clearcoatMap,e.clearcoatMapTransform)),t.clearcoatRoughnessMap&&(e.clearcoatRoughnessMap.value=t.clearcoatRoughnessMap,n(t.clearcoatRoughnessMap,e.clearcoatRoughnessMapTransform)),t.clearcoatNormalMap&&(e.clearcoatNormalMap.value=t.clearcoatNormalMap,n(t.clearcoatNormalMap,e.clearcoatNormalMapTransform),e.clearcoatNormalScale.value.copy(t.clearcoatNormalScale),t.side===1&&e.clearcoatNormalScale.value.negate())),t.dispersion>0&&(e.dispersion.value=t.dispersion),t.iridescence>0&&(e.iridescence.value=t.iridescence,e.iridescenceIOR.value=t.iridescenceIOR,e.iridescenceThicknessMinimum.value=t.iridescenceThicknessRange[0],e.iridescenceThicknessMaximum.value=t.iridescenceThicknessRange[1],t.iridescenceMap&&(e.iridescenceMap.value=t.iridescenceMap,n(t.iridescenceMap,e.iridescenceMapTransform)),t.iridescenceThicknessMap&&(e.iridescenceThicknessMap.value=t.iridescenceThicknessMap,n(t.iridescenceThicknessMap,e.iridescenceThicknessMapTransform))),t.transmission>0&&(e.transmission.value=t.transmission,e.transmissionSamplerMap.value=r.texture,e.transmissionSamplerSize.value.set(r.width,r.height),t.transmissionMap&&(e.transmissionMap.value=t.transmissionMap,n(t.transmissionMap,e.transmissionMapTransform)),e.thickness.value=t.thickness,t.thicknessMap&&(e.thicknessMap.value=t.thicknessMap,n(t.thicknessMap,e.thicknessMapTransform)),e.attenuationDistance.value=t.attenuationDistance,e.attenuationColor.value.copy(t.attenuationColor)),t.anisotropy>0&&(e.anisotropyVector.value.set(t.anisotropy*Math.cos(t.anisotropyRotation),t.anisotropy*Math.sin(t.anisotropyRotation)),t.anisotropyMap&&(e.anisotropyMap.value=t.anisotropyMap,n(t.anisotropyMap,e.anisotropyMapTransform))),e.specularIntensity.value=t.specularIntensity,e.specularColor.value.copy(t.specularColor),t.specularColorMap&&(e.specularColorMap.value=t.specularColorMap,n(t.specularColorMap,e.specularColorMapTransform)),t.specularIntensityMap&&(e.specularIntensityMap.value=t.specularIntensityMap,n(t.specularIntensityMap,e.specularIntensityMapTransform))}function m(e,t){t.matcap&&(e.matcap.value=t.matcap)}function h(e,n){let r=t.get(n).light;e.referencePosition.value.setFromMatrixPosition(r.matrixWorld),e.nearDistance.value=r.shadow.camera.near,e.farDistance.value=r.shadow.camera.far}return{refreshFogUniforms:r,refreshMaterialUniforms:i}}function oie(e,t,n,r){let i={},a={},o=[],s=e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS);function c(e,t){let n=t.program;r.uniformBlockBinding(e,n)}function l(e,n){let o=i[e.id];o===void 0&&(m(e),o=u(e),i[e.id]=o,e.addEventListener(`dispose`,g));let s=n.program;r.updateUBOMapping(e,s);let c=t.render.frame;a[e.id]!==c&&(f(e),a[e.id]=c)}function u(t){let n=d();t.__bindingPointIndex=n;let r=e.createBuffer(),i=t.__size,a=t.usage;return e.bindBuffer(e.UNIFORM_BUFFER,r),e.bufferData(e.UNIFORM_BUFFER,i,a),e.bindBuffer(e.UNIFORM_BUFFER,null),e.bindBufferBase(e.UNIFORM_BUFFER,n,r),r}function d(){for(let e=0;e0&&(n+=16-r),e.__size=n,e.__cache={},this}function h(e){let t={boundary:0,storage:0};return typeof e==`number`||typeof e==`boolean`?(t.boundary=4,t.storage=4):e.isVector2?(t.boundary=8,t.storage=8):e.isVector3||e.isColor?(t.boundary=16,t.storage=12):e.isVector4?(t.boundary=16,t.storage=16):e.isMatrix3?(t.boundary=48,t.storage=48):e.isMatrix4?(t.boundary=64,t.storage=64):e.isTexture?fm(`WebGLRenderer: Texture samplers can not be part of an uniforms group.`):fm(`WebGLRenderer: Unsupported uniform value type.`,e),t}function g(t){let n=t.target;n.removeEventListener(`dispose`,g);let r=o.indexOf(n.__bindingPointIndex);o.splice(r,1),e.deleteBuffer(i[n.id]),delete i[n.id],delete a[n.id]}function _(){for(let t in i)e.deleteBuffer(i[t]);o=[],i={},a={}}return{bind:c,update:l,dispose:_}}var sie=new Uint16Array([11481,15204,11534,15171,11808,15015,12385,14843,12894,14716,13396,14600,13693,14483,13976,14366,14237,14171,14405,13961,14511,13770,14605,13598,14687,13444,14760,13305,14822,13066,14876,12857,14923,12675,14963,12517,14997,12379,15025,12230,15049,12023,15070,11843,15086,11687,15100,11551,15111,11433,15120,11330,15127,11217,15132,11060,15135,10922,15138,10801,15139,10695,15139,10600,13012,14923,13020,14917,13064,14886,13176,14800,13349,14666,13513,14526,13724,14398,13960,14230,14200,14020,14383,13827,14488,13651,14583,13491,14667,13348,14740,13132,14803,12908,14856,12713,14901,12542,14938,12394,14968,12241,14992,12017,15010,11822,15024,11654,15034,11507,15041,11380,15044,11269,15044,11081,15042,10913,15037,10764,15031,10635,15023,10520,15014,10419,15003,10330,13657,14676,13658,14673,13670,14660,13698,14622,13750,14547,13834,14442,13956,14317,14112,14093,14291,13889,14407,13704,14499,13538,14586,13389,14664,13201,14733,12966,14792,12758,14842,12577,14882,12418,14915,12272,14940,12033,14959,11826,14972,11646,14980,11490,14983,11355,14983,11212,14979,11008,14971,10830,14961,10675,14950,10540,14936,10420,14923,10315,14909,10204,14894,10041,14089,14460,14090,14459,14096,14452,14112,14431,14141,14388,14186,14305,14252,14130,14341,13941,14399,13756,14467,13585,14539,13430,14610,13272,14677,13026,14737,12808,14790,12617,14833,12449,14869,12303,14896,12065,14916,11845,14929,11655,14937,11490,14939,11347,14936,11184,14930,10970,14921,10783,14912,10621,14900,10480,14885,10356,14867,10247,14848,10062,14827,9894,14805,9745,14400,14208,14400,14206,14402,14198,14406,14174,14415,14122,14427,14035,14444,13913,14469,13767,14504,13613,14548,13463,14598,13324,14651,13082,14704,12858,14752,12658,14795,12483,14831,12330,14860,12106,14881,11875,14895,11675,14903,11501,14905,11351,14903,11178,14900,10953,14892,10757,14880,10589,14865,10442,14847,10313,14827,10162,14805,9965,14782,9792,14757,9642,14731,9507,14562,13883,14562,13883,14563,13877,14566,13862,14570,13830,14576,13773,14584,13689,14595,13582,14613,13461,14637,13336,14668,13120,14704,12897,14741,12695,14776,12516,14808,12358,14835,12150,14856,11910,14870,11701,14878,11519,14882,11361,14884,11187,14880,10951,14871,10748,14858,10572,14842,10418,14823,10286,14801,10099,14777,9897,14751,9722,14725,9567,14696,9430,14666,9309,14702,13604,14702,13604,14702,13600,14703,13591,14705,13570,14707,13533,14709,13477,14712,13400,14718,13305,14727,13106,14743,12907,14762,12716,14784,12539,14807,12380,14827,12190,14844,11943,14855,11727,14863,11539,14870,11376,14871,11204,14868,10960,14858,10748,14845,10565,14829,10406,14809,10269,14786,10058,14761,9852,14734,9671,14705,9512,14674,9374,14641,9253,14608,9076,14821,13366,14821,13365,14821,13364,14821,13358,14821,13344,14821,13320,14819,13252,14817,13145,14815,13011,14814,12858,14817,12698,14823,12539,14832,12389,14841,12214,14850,11968,14856,11750,14861,11558,14866,11390,14867,11226,14862,10972,14853,10754,14840,10565,14823,10401,14803,10259,14780,10032,14754,9820,14725,9635,14694,9473,14661,9333,14627,9203,14593,8988,14557,8798,14923,13014,14922,13014,14922,13012,14922,13004,14920,12987,14919,12957,14915,12907,14909,12834,14902,12738,14894,12623,14888,12498,14883,12370,14880,12203,14878,11970,14875,11759,14873,11569,14874,11401,14872,11243,14865,10986,14855,10762,14842,10568,14825,10401,14804,10255,14781,10017,14754,9799,14725,9611,14692,9445,14658,9301,14623,9139,14587,8920,14548,8729,14509,8562,15008,12672,15008,12672,15008,12671,15007,12667,15005,12656,15001,12637,14997,12605,14989,12556,14978,12490,14966,12407,14953,12313,14940,12136,14927,11934,14914,11742,14903,11563,14896,11401,14889,11247,14879,10992,14866,10767,14851,10570,14833,10400,14812,10252,14789,10007,14761,9784,14731,9592,14698,9424,14663,9279,14627,9088,14588,8868,14548,8676,14508,8508,14467,8360,15080,12386,15080,12386,15079,12385,15078,12383,15076,12378,15072,12367,15066,12347,15057,12315,15045,12253,15030,12138,15012,11998,14993,11845,14972,11685,14951,11530,14935,11383,14920,11228,14904,10981,14887,10762,14870,10567,14850,10397,14827,10248,14803,9997,14774,9771,14743,9578,14710,9407,14674,9259,14637,9048,14596,8826,14555,8632,14514,8464,14471,8317,14427,8182,15139,12008,15139,12008,15138,12008,15137,12007,15135,12003,15130,11990,15124,11969,15115,11929,15102,11872,15086,11794,15064,11693,15041,11581,15013,11459,14987,11336,14966,11170,14944,10944,14921,10738,14898,10552,14875,10387,14850,10239,14824,9983,14794,9758,14762,9563,14728,9392,14692,9244,14653,9014,14611,8791,14569,8597,14526,8427,14481,8281,14436,8110,14391,7885,15188,11617,15188,11617,15187,11617,15186,11618,15183,11617,15179,11612,15173,11601,15163,11581,15150,11546,15133,11495,15110,11427,15083,11346,15051,11246,15024,11057,14996,10868,14967,10687,14938,10517,14911,10362,14882,10206,14853,9956,14821,9737,14787,9543,14752,9375,14715,9228,14675,8980,14632,8760,14589,8565,14544,8395,14498,8248,14451,8049,14404,7824,14357,7630,15228,11298,15228,11298,15227,11299,15226,11301,15223,11303,15219,11302,15213,11299,15204,11290,15191,11271,15174,11217,15150,11129,15119,11015,15087,10886,15057,10744,15024,10599,14990,10455,14957,10318,14924,10143,14891,9911,14856,9701,14820,9516,14782,9352,14744,9200,14703,8946,14659,8725,14615,8533,14568,8366,14521,8220,14472,7992,14423,7770,14374,7578,14315,7408,15260,10819,15260,10819,15259,10822,15258,10826,15256,10832,15251,10836,15246,10841,15237,10838,15225,10821,15207,10788,15183,10734,15151,10660,15120,10571,15087,10469,15049,10359,15012,10249,14974,10041,14937,9837,14900,9647,14860,9475,14820,9320,14779,9147,14736,8902,14691,8688,14646,8499,14598,8335,14549,8189,14499,7940,14448,7720,14397,7529,14347,7363,14256,7218,15285,10410,15285,10411,15285,10413,15284,10418,15282,10425,15278,10434,15272,10442,15264,10449,15252,10445,15235,10433,15210,10403,15179,10358,15149,10301,15113,10218,15073,10059,15033,9894,14991,9726,14951,9565,14909,9413,14865,9273,14822,9073,14777,8845,14730,8641,14682,8459,14633,8300,14583,8129,14531,7883,14479,7670,14426,7482,14373,7321,14305,7176,14201,6939,15305,9939,15305,9940,15305,9945,15304,9955,15302,9967,15298,9989,15293,10010,15286,10033,15274,10044,15258,10045,15233,10022,15205,9975,15174,9903,15136,9808,15095,9697,15053,9578,15009,9451,14965,9327,14918,9198,14871,8973,14825,8766,14775,8579,14725,8408,14675,8259,14622,8058,14569,7821,14515,7615,14460,7435,14405,7276,14350,7108,14256,6866,14149,6653,15321,9444,15321,9445,15321,9448,15320,9458,15317,9470,15314,9490,15310,9515,15302,9540,15292,9562,15276,9579,15251,9577,15226,9559,15195,9519,15156,9463,15116,9389,15071,9304,15025,9208,14978,9023,14927,8838,14878,8661,14827,8496,14774,8344,14722,8206,14667,7973,14612,7749,14556,7555,14499,7382,14443,7229,14385,7025,14322,6791,14210,6588,14100,6409,15333,8920,15333,8921,15332,8927,15332,8943,15329,8965,15326,9002,15322,9048,15316,9106,15307,9162,15291,9204,15267,9221,15244,9221,15212,9196,15175,9134,15133,9043,15088,8930,15040,8801,14990,8665,14938,8526,14886,8391,14830,8261,14775,8087,14719,7866,14661,7664,14603,7482,14544,7322,14485,7178,14426,6936,14367,6713,14281,6517,14166,6348,14054,6198,15341,8360,15341,8361,15341,8366,15341,8379,15339,8399,15336,8431,15332,8473,15326,8527,15318,8585,15302,8632,15281,8670,15258,8690,15227,8690,15191,8664,15149,8612,15104,8543,15055,8456,15001,8360,14948,8259,14892,8122,14834,7923,14776,7734,14716,7558,14656,7397,14595,7250,14534,7070,14472,6835,14410,6628,14350,6443,14243,6283,14125,6135,14010,5889,15348,7715,15348,7717,15348,7725,15347,7745,15345,7780,15343,7836,15339,7905,15334,8e3,15326,8103,15310,8193,15293,8239,15270,8270,15240,8287,15204,8283,15163,8260,15118,8223,15067,8143,15014,8014,14958,7873,14899,7723,14839,7573,14778,7430,14715,7293,14652,7164,14588,6931,14524,6720,14460,6531,14396,6362,14330,6210,14207,6015,14086,5781,13969,5576,15352,7114,15352,7116,15352,7128,15352,7159,15350,7195,15348,7237,15345,7299,15340,7374,15332,7457,15317,7544,15301,7633,15280,7703,15251,7754,15216,7775,15176,7767,15131,7733,15079,7670,15026,7588,14967,7492,14906,7387,14844,7278,14779,7171,14714,6965,14648,6770,14581,6587,14515,6420,14448,6269,14382,6123,14299,5881,14172,5665,14049,5477,13929,5310,15355,6329,15355,6330,15355,6339,15355,6362,15353,6410,15351,6472,15349,6572,15344,6688,15337,6835,15323,6985,15309,7142,15287,7220,15260,7277,15226,7310,15188,7326,15142,7318,15090,7285,15036,7239,14976,7177,14914,7045,14849,6892,14782,6736,14714,6581,14645,6433,14576,6293,14506,6164,14438,5946,14369,5733,14270,5540,14140,5369,14014,5216,13892,5043,15357,5483,15357,5484,15357,5496,15357,5528,15356,5597,15354,5692,15351,5835,15347,6011,15339,6195,15328,6317,15314,6446,15293,6566,15268,6668,15235,6746,15197,6796,15152,6811,15101,6790,15046,6748,14985,6673,14921,6583,14854,6479,14785,6371,14714,6259,14643,6149,14571,5946,14499,5750,14428,5567,14358,5401,14242,5250,14109,5111,13980,4870,13856,4657,15359,4555,15359,4557,15358,4573,15358,4633,15357,4715,15355,4841,15353,5061,15349,5216,15342,5391,15331,5577,15318,5770,15299,5967,15274,6150,15243,6223,15206,6280,15161,6310,15111,6317,15055,6300,14994,6262,14928,6208,14860,6141,14788,5994,14715,5838,14641,5684,14566,5529,14492,5384,14418,5247,14346,5121,14216,4892,14079,4682,13948,4496,13822,4330,15359,3498,15359,3501,15359,3520,15359,3598,15358,3719,15356,3860,15355,4137,15351,4305,15344,4563,15334,4809,15321,5116,15303,5273,15280,5418,15250,5547,15214,5653,15170,5722,15120,5761,15064,5763,15002,5733,14935,5673,14865,5597,14792,5504,14716,5400,14640,5294,14563,5185,14486,5041,14410,4841,14335,4655,14191,4482,14051,4325,13918,4183,13790,4012,15360,2282,15360,2285,15360,2306,15360,2401,15359,2547,15357,2748,15355,3103,15352,3349,15345,3675,15336,4020,15324,4272,15307,4496,15285,4716,15255,4908,15220,5086,15178,5170,15128,5214,15072,5234,15010,5231,14943,5206,14871,5166,14796,5102,14718,4971,14639,4833,14559,4687,14480,4541,14402,4401,14315,4268,14167,4142,14025,3958,13888,3747,13759,3556,15360,923,15360,925,15360,946,15360,1052,15359,1214,15357,1494,15356,1892,15352,2274,15346,2663,15338,3099,15326,3393,15309,3679,15288,3980,15260,4183,15226,4325,15185,4437,15136,4517,15080,4570,15018,4591,14950,4581,14877,4545,14800,4485,14720,4411,14638,4325,14556,4231,14475,4136,14395,3988,14297,3803,14145,3628,13999,3465,13861,3314,13729,3177,15360,263,15360,264,15360,272,15360,325,15359,407,15358,548,15356,780,15352,1144,15347,1580,15339,2099,15328,2425,15312,2795,15292,3133,15264,3329,15232,3517,15191,3689,15143,3819,15088,3923,15025,3978,14956,3999,14882,3979,14804,3931,14722,3855,14639,3756,14554,3645,14470,3529,14388,3409,14279,3289,14124,3173,13975,3055,13834,2848,13701,2658,15360,49,15360,49,15360,52,15360,75,15359,111,15358,201,15356,283,15353,519,15348,726,15340,1045,15329,1415,15314,1795,15295,2173,15269,2410,15237,2649,15197,2866,15150,3054,15095,3140,15032,3196,14963,3228,14888,3236,14808,3224,14725,3191,14639,3146,14553,3088,14466,2976,14382,2836,14262,2692,14103,2549,13952,2409,13808,2278,13674,2154,15360,4,15360,4,15360,4,15360,13,15359,33,15358,59,15357,112,15353,199,15348,302,15341,456,15331,628,15316,827,15297,1082,15272,1332,15241,1601,15202,1851,15156,2069,15101,2172,15039,2256,14970,2314,14894,2348,14813,2358,14728,2344,14640,2311,14551,2263,14463,2203,14376,2133,14247,2059,14084,1915,13930,1761,13784,1609,13648,1464,15360,0,15360,0,15360,0,15360,3,15359,18,15358,26,15357,53,15354,80,15348,97,15341,165,15332,238,15318,326,15299,427,15275,529,15245,654,15207,771,15161,885,15108,994,15046,1089,14976,1170,14900,1229,14817,1266,14731,1284,14641,1282,14550,1260,14460,1223,14370,1174,14232,1116,14066,1050,13909,981,13761,910,13623,839]),Lv=null;function cie(){return Lv===null&&(Lv=new Ste(sie,32,32,Gp,Pp),Lv.minFilter=wp,Lv.magFilter=wp,Lv.wrapS=yp,Lv.wrapT=yp,Lv.generateMipmaps=!1,Lv.needsUpdate=!0),Lv}var lie=class{constructor(e={}){let{canvas:t=Iee(),context:n=null,depth:r=!0,stencil:i=!1,alpha:a=!1,antialias:o=!1,premultipliedAlpha:s=!0,preserveDrawingBuffer:c=!1,powerPreference:l=`default`,failIfMajorPerformanceCaveat:u=!1,reversedDepthBuffer:d=!1}=e;this.isWebGLRenderer=!0;let f;if(n!==null){if(typeof WebGLRenderingContext<`u`&&n instanceof WebGLRenderingContext)throw Error(`THREE.WebGLRenderer: WebGL 1 is not supported since r163.`);f=n.getContextAttributes().alpha}else f=a;let p=new Set([qp,Kp,Wp]),m=new Set([Dp,Mp,Ap,Lp,Fp,Ip]),h=new Uint32Array(4),g=new Int32Array(4),_=null,v=null,y=[],b=[];this.domElement=t,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=0,this.toneMappingExposure=1,this.transmissionResolutionScale=1;let x=this,S=!1;this._outputColorSpace=em;let C=0,w=0,T=null,E=-1,D=null,O=new qm,k=new qm,A=null,j=new cg(0),M=0,N=t.width,P=t.height,F=1,I=null,L=null,R=new qm(0,0,N,P),z=new qm(0,0,N,P),B=!1,V=new r_,ee=!1,H=!1,te=new Sh,ne=new Mm,re=new qm,U={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0},ie=!1;function ae(){return T===null?F:1}let W=n;function oe(e,n){return t.getContext(e,n)}try{let e={alpha:!0,depth:r,stencil:i,antialias:o,premultipliedAlpha:s,preserveDrawingBuffer:c,powerPreference:l,failIfMajorPerformanceCaveat:u};if(`setAttribute`in t&&t.setAttribute(`data-engine`,`three.js r181`),t.addEventListener(`webglcontextlost`,Ne,!1),t.addEventListener(`webglcontextrestored`,Pe,!1),t.addEventListener(`webglcontextcreationerror`,Fe,!1),W===null){let t=`webgl2`;if(W=oe(t,e),W===null)throw oe(t)?Error(`Error creating WebGL context with your selected attributes.`):Error(`Error creating WebGL context.`)}}catch(e){throw e(`WebGLRenderer: `+e.message),e}let se,ce,le,ue,de,fe,pe,me,he,ge,_e,ve,ye,be,xe,Se,Ce,we,Te,Ee,De,Oe,ke,Ae;function je(){se=new vne(W),se.init(),Oe=new $re(W,se),ce=new lne(W,se,e,Oe),le=new Zre(W,se),ce.reversedDepthBuffer&&d&&le.buffers.depth.setReversed(!0),ue=new xne(W),de=new Rre,fe=new Qre(W,se,le,de,ce,Oe,ue),pe=new dne(x),me=new _ne(x),he=new ine(W),ke=new sne(W,he),ge=new yne(W,he,ue,ke),_e=new Cne(W,ge,he,ue),Te=new Sne(W,ce,fe),Se=new une(de),ve=new Lre(x,pe,me,se,ce,ke,Se),ye=new aie(x,de),be=new Bre,xe=new Kre(se),we=new one(x,pe,me,le,_e,f,s),Ce=new Yre(x,_e,ce),Ae=new oie(W,ue,ce,le),Ee=new cne(W,se,ue),De=new bne(W,se,ue),ue.programs=ve.programs,x.capabilities=ce,x.extensions=se,x.properties=de,x.renderLists=be,x.shadowMap=Ce,x.state=le,x.info=ue}je();let Me=new rie(x,W);this.xr=Me,this.getContext=function(){return W},this.getContextAttributes=function(){return W.getContextAttributes()},this.forceContextLoss=function(){let e=se.get(`WEBGL_lose_context`);e&&e.loseContext()},this.forceContextRestore=function(){let e=se.get(`WEBGL_lose_context`);e&&e.restoreContext()},this.getPixelRatio=function(){return F},this.setPixelRatio=function(e){e!==void 0&&(F=e,this.setSize(N,P,!1))},this.getSize=function(e){return e.set(N,P)},this.setSize=function(e,n,r=!0){if(Me.isPresenting){fm(`WebGLRenderer: Can't change size while VR device is presenting.`);return}N=e,P=n,t.width=Math.floor(e*F),t.height=Math.floor(n*F),r===!0&&(t.style.width=e+`px`,t.style.height=n+`px`),this.setViewport(0,0,e,n)},this.getDrawingBufferSize=function(e){return e.set(N*F,P*F).floor()},this.setDrawingBufferSize=function(e,n,r){N=e,P=n,F=r,t.width=Math.floor(e*r),t.height=Math.floor(n*r),this.setViewport(0,0,e,n)},this.getCurrentViewport=function(e){return e.copy(O)},this.getViewport=function(e){return e.copy(R)},this.setViewport=function(e,t,n,r){e.isVector4?R.set(e.x,e.y,e.z,e.w):R.set(e,t,n,r),le.viewport(O.copy(R).multiplyScalar(F).round())},this.getScissor=function(e){return e.copy(z)},this.setScissor=function(e,t,n,r){e.isVector4?z.set(e.x,e.y,e.z,e.w):z.set(e,t,n,r),le.scissor(k.copy(z).multiplyScalar(F).round())},this.getScissorTest=function(){return B},this.setScissorTest=function(e){le.setScissorTest(B=e)},this.setOpaqueSort=function(e){I=e},this.setTransparentSort=function(e){L=e},this.getClearColor=function(e){return e.copy(we.getClearColor())},this.setClearColor=function(){we.setClearColor(...arguments)},this.getClearAlpha=function(){return we.getClearAlpha()},this.setClearAlpha=function(){we.setClearAlpha(...arguments)},this.clear=function(e=!0,t=!0,n=!0){let r=0;if(e){let e=!1;if(T!==null){let t=T.texture.format;e=p.has(t)}if(e){let e=T.texture.type,t=m.has(e),n=we.getClearColor(),r=we.getClearAlpha(),i=n.r,a=n.g,o=n.b;t?(h[0]=i,h[1]=a,h[2]=o,h[3]=r,W.clearBufferuiv(W.COLOR,0,h)):(g[0]=i,g[1]=a,g[2]=o,g[3]=r,W.clearBufferiv(W.COLOR,0,g))}else r|=W.COLOR_BUFFER_BIT}t&&(r|=W.DEPTH_BUFFER_BIT),n&&(r|=W.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),W.clear(r)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.dispose=function(){t.removeEventListener(`webglcontextlost`,Ne,!1),t.removeEventListener(`webglcontextrestored`,Pe,!1),t.removeEventListener(`webglcontextcreationerror`,Fe,!1),we.dispose(),be.dispose(),xe.dispose(),de.dispose(),pe.dispose(),me.dispose(),_e.dispose(),ke.dispose(),Ae.dispose(),ve.dispose(),Me.dispose(),Me.removeEventListener(`sessionstart`,He),Me.removeEventListener(`sessionend`,Ue),We.stop()};function Ne(e){e.preventDefault(),dm(`WebGLRenderer: Context Lost.`),S=!0}function Pe(){dm(`WebGLRenderer: Context Restored.`),S=!1;let e=ue.autoReset,t=Ce.enabled,n=Ce.autoUpdate,r=Ce.needsUpdate,i=Ce.type;je(),ue.autoReset=e,Ce.enabled=t,Ce.autoUpdate=n,Ce.needsUpdate=r,Ce.type=i}function Fe(e){pm(`WebGLRenderer: A WebGL context could not be created. Reason: `,e.statusMessage)}function Ie(e){let t=e.target;t.removeEventListener(`dispose`,Ie),Le(t)}function Le(e){Re(e),de.remove(e)}function Re(e){let t=de.get(e).programs;t!==void 0&&(t.forEach(function(e){ve.releaseProgram(e)}),e.isShaderMaterial&&ve.releaseShaderCache(e))}this.renderBufferDirect=function(e,t,n,r,i,a){t===null&&(t=U);let o=i.isMesh&&i.matrixWorld.determinant()<0,s=G(e,t,n,r,i);le.setMaterial(r,o);let c=n.index,l=1;if(r.wireframe===!0){if(c=ge.getWireframeAttribute(n),c===void 0)return;l=2}let u=n.drawRange,d=n.attributes.position,f=u.start*l,p=(u.start+u.count)*l;a!==null&&(f=Math.max(f,a.start*l),p=Math.min(p,(a.start+a.count)*l)),c===null?d!=null&&(f=Math.max(f,0),p=Math.min(p,d.count)):(f=Math.max(f,0),p=Math.min(p,c.count));let m=p-f;if(m<0||m===1/0)return;ke.setup(i,r,s,n,c);let h,g=Ee;if(c!==null&&(h=he.get(c),g=De,g.setIndex(h)),i.isMesh)r.wireframe===!0?(le.setLineWidth(r.wireframeLinewidth*ae()),g.setMode(W.LINES)):g.setMode(W.TRIANGLES);else if(i.isLine){let e=r.linewidth;e===void 0&&(e=1),le.setLineWidth(e*ae()),i.isLineSegments?g.setMode(W.LINES):i.isLineLoop?g.setMode(W.LINE_LOOP):g.setMode(W.LINE_STRIP)}else i.isPoints?g.setMode(W.POINTS):i.isSprite&&g.setMode(W.TRIANGLES);if(i.isBatchedMesh)if(i._multiDrawInstances!==null)mm(`WebGLRenderer: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection.`),g.renderMultiDrawInstances(i._multiDrawStarts,i._multiDrawCounts,i._multiDrawCount,i._multiDrawInstances);else if(se.get(`WEBGL_multi_draw`))g.renderMultiDraw(i._multiDrawStarts,i._multiDrawCounts,i._multiDrawCount);else{let e=i._multiDrawStarts,t=i._multiDrawCounts,n=i._multiDrawCount,a=c?he.get(c).bytesPerElement:1,o=de.get(r).currentProgram.getUniforms();for(let r=0;r{function n(){if(r.forEach(function(e){de.get(e).currentProgram.isReady()&&r.delete(e)}),r.size===0){t(e);return}setTimeout(n,10)}se.get(`KHR_parallel_shader_compile`)===null?setTimeout(n,10):n()})};let Be=null;function Ve(e){Be&&Be(e)}function He(){We.stop()}function Ue(){We.start()}let We=new R_;We.setAnimationLoop(Ve),typeof self<`u`&&We.setContext(self),this.setAnimationLoop=function(e){Be=e,Me.setAnimationLoop(e),e===null?We.stop():We.start()},Me.addEventListener(`sessionstart`,He),Me.addEventListener(`sessionend`,Ue),this.render=function(e,t){if(t!==void 0&&t.isCamera!==!0){pm(`WebGLRenderer.render: camera is not an instance of THREE.Camera.`);return}if(S===!0)return;if(e.matrixWorldAutoUpdate===!0&&e.updateMatrixWorld(),t.parent===null&&t.matrixWorldAutoUpdate===!0&&t.updateMatrixWorld(),Me.enabled===!0&&Me.isPresenting===!0&&(Me.cameraAutoUpdate===!0&&Me.updateCamera(t),t=Me.getCamera()),e.isScene===!0&&e.onBeforeRender(x,e,t,T),v=xe.get(e,b.length),v.init(t),b.push(v),te.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),V.setFromProjectionMatrix(te,om,t.reversedDepth),H=this.localClippingEnabled,ee=Se.init(this.clippingPlanes,H),_=be.get(e,y.length),_.init(),y.push(_),Me.enabled===!0&&Me.isPresenting===!0){let e=x.xr.getDepthSensingMesh();e!==null&&Ge(e,t,-1/0,x.sortObjects)}Ge(e,t,0,x.sortObjects),_.finish(),x.sortObjects===!0&&_.sort(I,L),ie=Me.enabled===!1||Me.isPresenting===!1||Me.hasDepthSensing()===!1,ie&&we.addToRenderList(_,e),this.info.render.frame++,ee===!0&&Se.beginShadows();let n=v.state.shadowsArray;Ce.render(n,e,t),ee===!0&&Se.endShadows(),this.info.autoReset===!0&&this.info.reset();let r=_.opaque,i=_.transmissive;if(v.setupLights(),t.isArrayCamera){let n=t.cameras;if(i.length>0)for(let t=0,a=n.length;t0&&qe(r,i,e,t),ie&&we.render(e),Ke(_,e,t);T!==null&&w===0&&(fe.updateMultisampleRenderTarget(T),fe.updateRenderTargetMipmap(T)),e.isScene===!0&&e.onAfterRender(x,e,t),ke.resetDefaultState(),E=-1,D=null,b.pop(),b.length>0?(v=b[b.length-1],ee===!0&&Se.setGlobalState(x.clippingPlanes,v.state.camera)):v=null,y.pop(),_=y.length>0?y[y.length-1]:null};function Ge(e,t,n,r){if(e.visible===!1)return;if(e.layers.test(t.layers)){if(e.isGroup)n=e.renderOrder;else if(e.isLOD)e.autoUpdate===!0&&e.update(t);else if(e.isLight)v.pushLight(e),e.castShadow&&v.pushShadow(e);else if(e.isSprite){if(!e.frustumCulled||V.intersectsSprite(e)){r&&re.setFromMatrixPosition(e.matrixWorld).applyMatrix4(te);let t=_e.update(e),i=e.material;i.visible&&_.push(e,t,i,n,re.z,null)}}else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||V.intersectsObject(e))){let t=_e.update(e),i=e.material;if(r&&(e.boundingSphere===void 0?(t.boundingSphere===null&&t.computeBoundingSphere(),re.copy(t.boundingSphere.center)):(e.boundingSphere===null&&e.computeBoundingSphere(),re.copy(e.boundingSphere.center)),re.applyMatrix4(e.matrixWorld).applyMatrix4(te)),Array.isArray(i)){let r=t.groups;for(let a=0,o=r.length;a0&&Je(i,t,n),a.length>0&&Je(a,t,n),o.length>0&&Je(o,t,n),le.buffers.depth.setTest(!0),le.buffers.depth.setMask(!0),le.buffers.color.setMask(!0),le.setPolygonOffset(!1)}function qe(e,t,n,r){if((n.isScene===!0?n.overrideMaterial:null)!==null)return;v.state.transmissionRenderTarget[r.id]===void 0&&(v.state.transmissionRenderTarget[r.id]=new Jm(1,1,{generateMipmaps:!0,type:se.has(`EXT_color_buffer_half_float`)||se.has(`EXT_color_buffer_float`)?Pp:Dp,minFilter:Ep,samples:4,stencilBuffer:i,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:zm.workingColorSpace}));let a=v.state.transmissionRenderTarget[r.id],o=r.viewport||O;a.setSize(o.z*x.transmissionResolutionScale,o.w*x.transmissionResolutionScale);let s=x.getRenderTarget(),c=x.getActiveCubeFace(),l=x.getActiveMipmapLevel();x.setRenderTarget(a),x.getClearColor(j),M=x.getClearAlpha(),M<1&&x.setClearColor(16777215,.5),x.clear(),ie&&we.render(n);let u=x.toneMapping;x.toneMapping=0;let d=r.viewport;if(r.viewport!==void 0&&(r.viewport=void 0),v.setupLightsView(r),ee===!0&&Se.setGlobalState(x.clippingPlanes,r),Je(e,n,r),fe.updateMultisampleRenderTarget(a),fe.updateRenderTargetMipmap(a),se.has(`WEBGL_multisampled_render_to_texture`)===!1){let e=!1;for(let i=0,a=t.length;i0),d=!!n.morphAttributes.position,f=!!n.morphAttributes.normal,p=!!n.morphAttributes.color,m=0;r.toneMapped&&(T===null||T.isXRRenderTarget===!0)&&(m=x.toneMapping);let h=n.morphAttributes.position||n.morphAttributes.normal||n.morphAttributes.color,g=h===void 0?0:h.length,_=de.get(r),y=v.state.lights;if(ee===!0&&(H===!0||e!==D)){let t=e===D&&r.id===E;Se.setState(r,e,t)}let b=!1;r.version===_.__version?_.needsLights&&_.lightsStateVersion!==y.state.version?b=!0:_.outputColorSpace===s?i.isBatchedMesh&&_.batching===!1||!i.isBatchedMesh&&_.batching===!0||i.isBatchedMesh&&_.batchingColor===!0&&i.colorTexture===null||i.isBatchedMesh&&_.batchingColor===!1&&i.colorTexture!==null||i.isInstancedMesh&&_.instancing===!1||!i.isInstancedMesh&&_.instancing===!0||i.isSkinnedMesh&&_.skinning===!1||!i.isSkinnedMesh&&_.skinning===!0||i.isInstancedMesh&&_.instancingColor===!0&&i.instanceColor===null||i.isInstancedMesh&&_.instancingColor===!1&&i.instanceColor!==null||i.isInstancedMesh&&_.instancingMorph===!0&&i.morphTexture===null||i.isInstancedMesh&&_.instancingMorph===!1&&i.morphTexture!==null?b=!0:_.envMap===c?r.fog===!0&&_.fog!==a||_.numClippingPlanes!==void 0&&(_.numClippingPlanes!==Se.numPlanes||_.numIntersection!==Se.numIntersection)?b=!0:_.vertexAlphas===l&&_.vertexTangents===u&&_.morphTargets===d&&_.morphNormals===f&&_.morphColors===p&&_.toneMapping===m?_.morphTargetsCount!==g&&(b=!0):b=!0:b=!0:b=!0:(b=!0,_.__version=r.version);let S=_.currentProgram;b===!0&&(S=Xe(r,t,i));let C=!1,w=!1,O=!1,k=S.getUniforms(),A=_.uniforms;if(le.useProgram(S.program)&&(C=!0,w=!0,O=!0),r.id!==E&&(E=r.id,w=!0),C||D!==e){le.buffers.depth.getReversed()&&e.reversedDepth!==!0&&(e._reversedDepth=!0,e.updateProjectionMatrix()),k.setValue(W,`projectionMatrix`,e.projectionMatrix),k.setValue(W,`viewMatrix`,e.matrixWorldInverse);let t=k.map.cameraPosition;t!==void 0&&t.setValue(W,ne.setFromMatrixPosition(e.matrixWorld)),ce.logarithmicDepthBuffer&&k.setValue(W,`logDepthBufFC`,2/(Math.log(e.far+1)/Math.LN2)),(r.isMeshPhongMaterial||r.isMeshToonMaterial||r.isMeshLambertMaterial||r.isMeshBasicMaterial||r.isMeshStandardMaterial||r.isShaderMaterial)&&k.setValue(W,`isOrthographic`,e.isOrthographicCamera===!0),D!==e&&(D=e,w=!0,O=!0)}if(i.isSkinnedMesh){k.setOptional(W,i,`bindMatrix`),k.setOptional(W,i,`bindMatrixInverse`);let e=i.skeleton;e&&(e.boneTexture===null&&e.computeBoneTexture(),k.setValue(W,`boneTexture`,e.boneTexture,fe))}i.isBatchedMesh&&(k.setOptional(W,i,`batchingTexture`),k.setValue(W,`batchingTexture`,i._matricesTexture,fe),k.setOptional(W,i,`batchingIdTexture`),k.setValue(W,`batchingIdTexture`,i._indirectTexture,fe),k.setOptional(W,i,`batchingColorTexture`),i._colorsTexture!==null&&k.setValue(W,`batchingColorTexture`,i._colorsTexture,fe));let j=n.morphAttributes;if((j.position!==void 0||j.normal!==void 0||j.color!==void 0)&&Te.update(i,n,S),(w||_.receiveShadow!==i.receiveShadow)&&(_.receiveShadow=i.receiveShadow,k.setValue(W,`receiveShadow`,i.receiveShadow)),r.isMeshGouraudMaterial&&r.envMap!==null&&(A.envMap.value=c,A.flipEnvMap.value=c.isCubeTexture&&c.isRenderTargetTexture===!1?-1:1),r.isMeshStandardMaterial&&r.envMap===null&&t.environment!==null&&(A.envMapIntensity.value=t.environmentIntensity),A.dfgLUT!==void 0&&(A.dfgLUT.value=cie()),w&&(k.setValue(W,`toneMappingExposure`,x.toneMappingExposure),_.needsLights&&$e(A,O),a&&r.fog===!0&&ye.refreshFogUniforms(A,a),ye.refreshMaterialUniforms(A,r,F,P,v.state.transmissionRenderTarget[e.id]),Sv.upload(W,Ze(_),A,fe)),r.isShaderMaterial&&r.uniformsNeedUpdate===!0&&(Sv.upload(W,Ze(_),A,fe),r.uniformsNeedUpdate=!1),r.isSpriteMaterial&&k.setValue(W,`center`,i.center),k.setValue(W,`modelViewMatrix`,i.modelViewMatrix),k.setValue(W,`normalMatrix`,i.normalMatrix),k.setValue(W,`modelMatrix`,i.matrixWorld),r.isShaderMaterial||r.isRawShaderMaterial){let e=r.uniformsGroups;for(let t=0,n=e.length;t0&&fe.useMultisampledRTT(e)===!1?de.get(e).__webglMultisampledFramebuffer:Array.isArray(l)?l[n]:l,O.copy(e.viewport),k.copy(e.scissor),A=e.scissorTest}else O.copy(R).multiplyScalar(F).floor(),k.copy(z).multiplyScalar(F).floor(),A=B;if(n!==0&&(i=tt),le.bindFramebuffer(W.FRAMEBUFFER,i)&&r&&le.drawBuffers(e,i),le.viewport(O),le.scissor(k),le.setScissorTest(A),a){let r=de.get(e.texture);W.framebufferTexture2D(W.FRAMEBUFFER,W.COLOR_ATTACHMENT0,W.TEXTURE_CUBE_MAP_POSITIVE_X+t,r.__webglTexture,n)}else if(o){let r=t;for(let t=0;t=0&&t<=e.width-r&&n>=0&&n<=e.height-i&&(e.textures.length>1&&W.readBuffer(W.COLOR_ATTACHMENT0+s),W.readPixels(t,n,r,i,Oe.convert(c),Oe.convert(l),a))}finally{let e=T===null?null:de.get(T).__webglFramebuffer;le.bindFramebuffer(W.FRAMEBUFFER,e)}}},this.readRenderTargetPixelsAsync=async function(e,t,n,r,i,a,o,s=0){if(!(e&&e.isWebGLRenderTarget))throw Error(`THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.`);let c=de.get(e).__webglFramebuffer;if(e.isWebGLCubeRenderTarget&&o!==void 0&&(c=c[o]),c)if(t>=0&&t<=e.width-r&&n>=0&&n<=e.height-i){le.bindFramebuffer(W.FRAMEBUFFER,c);let o=e.textures[s],l=o.format,u=o.type;if(!ce.textureFormatReadable(l))throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.`);if(!ce.textureTypeReadable(u))throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.`);let d=W.createBuffer();W.bindBuffer(W.PIXEL_PACK_BUFFER,d),W.bufferData(W.PIXEL_PACK_BUFFER,a.byteLength,W.STREAM_READ),e.textures.length>1&&W.readBuffer(W.COLOR_ATTACHMENT0+s),W.readPixels(t,n,r,i,Oe.convert(l),Oe.convert(u),0);let f=T===null?null:de.get(T).__webglFramebuffer;le.bindFramebuffer(W.FRAMEBUFFER,f);let p=W.fenceSync(W.SYNC_GPU_COMMANDS_COMPLETE,0);return W.flush(),await Lee(W,p,4),W.bindBuffer(W.PIXEL_PACK_BUFFER,d),W.getBufferSubData(W.PIXEL_PACK_BUFFER,0,a),W.deleteBuffer(d),W.deleteSync(p),a}else throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.`)},this.copyFramebufferToTexture=function(e,t=null,n=0){let r=2**-n,i=Math.floor(e.image.width*r),a=Math.floor(e.image.height*r),o=t===null?0:t.x,s=t===null?0:t.y;fe.setTexture2D(e,0),W.copyTexSubImage2D(W.TEXTURE_2D,n,0,0,o,s,i,a),le.unbindTexture()};let nt=W.createFramebuffer(),rt=W.createFramebuffer();this.copyTextureToTexture=function(e,t,n=null,r=null,i=0,a=null){a===null&&(i===0?a=0:(mm(`WebGLRenderer: copyTextureToTexture function signature has changed to support src and dst mipmap levels.`),a=i,i=0));let o,s,c,l,u,d,f,p,m,h=e.isCompressedTexture?e.mipmaps[a]:e.image;if(n!==null)o=n.max.x-n.min.x,s=n.max.y-n.min.y,c=n.isBox3?n.max.z-n.min.z:1,l=n.min.x,u=n.min.y,d=n.isBox3?n.min.z:0;else{let t=2**-i;o=Math.floor(h.width*t),s=Math.floor(h.height*t),c=e.isDataArrayTexture?h.depth:e.isData3DTexture?Math.floor(h.depth*t):1,l=0,u=0,d=0}r===null?(f=0,p=0,m=0):(f=r.x,p=r.y,m=r.z);let g=Oe.convert(t.format),_=Oe.convert(t.type),v;t.isData3DTexture?(fe.setTexture3D(t,0),v=W.TEXTURE_3D):t.isDataArrayTexture||t.isCompressedArrayTexture?(fe.setTexture2DArray(t,0),v=W.TEXTURE_2D_ARRAY):(fe.setTexture2D(t,0),v=W.TEXTURE_2D),W.pixelStorei(W.UNPACK_FLIP_Y_WEBGL,t.flipY),W.pixelStorei(W.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),W.pixelStorei(W.UNPACK_ALIGNMENT,t.unpackAlignment);let y=W.getParameter(W.UNPACK_ROW_LENGTH),b=W.getParameter(W.UNPACK_IMAGE_HEIGHT),x=W.getParameter(W.UNPACK_SKIP_PIXELS),S=W.getParameter(W.UNPACK_SKIP_ROWS),C=W.getParameter(W.UNPACK_SKIP_IMAGES);W.pixelStorei(W.UNPACK_ROW_LENGTH,h.width),W.pixelStorei(W.UNPACK_IMAGE_HEIGHT,h.height),W.pixelStorei(W.UNPACK_SKIP_PIXELS,l),W.pixelStorei(W.UNPACK_SKIP_ROWS,u),W.pixelStorei(W.UNPACK_SKIP_IMAGES,d);let w=e.isDataArrayTexture||e.isData3DTexture,T=t.isDataArrayTexture||t.isData3DTexture;if(e.isDepthTexture){let n=de.get(e),r=de.get(t),h=de.get(n.__renderTarget),g=de.get(r.__renderTarget);le.bindFramebuffer(W.READ_FRAMEBUFFER,h.__webglFramebuffer),le.bindFramebuffer(W.DRAW_FRAMEBUFFER,g.__webglFramebuffer);for(let n=0;nMath.PI&&(n-=Wv),r<-Math.PI?r+=Wv:r>Math.PI&&(r-=Wv),n<=r?this._spherical.theta=Math.max(n,Math.min(r,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(n+r)/2?Math.max(n,this._spherical.theta):Math.min(r,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let i=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{let e=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),i=e!=this._spherical.radius}if(Uv.setFromSpherical(this._spherical),Uv.applyQuaternion(this._quatInverse),t.copy(this.target).add(Uv),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let e=null;if(this.object.isPerspectiveCamera){let t=Uv.length();e=this._clampDistance(t*this._scale);let n=t-e;this.object.position.addScaledVector(this._dollyDirection,n),this.object.updateMatrixWorld(),i=!!n}else if(this.object.isOrthographicCamera){let t=new Mm(this._mouse.x,this._mouse.y,0);t.unproject(this.object);let n=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),i=n!==this.object.zoom;let r=new Mm(this._mouse.x,this._mouse.y,0);r.unproject(this.object),this.object.position.sub(r).add(t),this.object.updateMatrixWorld(),e=Uv.length()}else console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.`),this.zoomToCursor=!1;e!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(e).add(this.object.position):(Vv.origin.copy(this.object.position),Vv.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(Vv.direction))Kv||8*(1-this._lastQuaternion.dot(this.object.quaternion))>Kv||this._lastTargetPosition.distanceToSquared(this.target)>Kv?(this.dispatchEvent(Rv),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e===null?Wv/60/60*this.autoRotateSpeed:Wv/60*this.autoRotateSpeed*e}_getZoomScale(e){let t=Math.abs(e*.01);return .95**(this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){Uv.setFromMatrixColumn(t,0),Uv.multiplyScalar(-e),this._panOffset.add(Uv)}_panUp(e,t){this.screenSpacePanning===!0?Uv.setFromMatrixColumn(t,1):(Uv.setFromMatrixColumn(t,0),Uv.crossVectors(this.object.up,Uv)),Uv.multiplyScalar(e),this._panOffset.add(Uv)}_pan(e,t){let n=this.domElement;if(this.object.isPerspectiveCamera){let r=this.object.position;Uv.copy(r).sub(this.target);let i=Uv.length();i*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*i/n.clientHeight,this.object.matrix),this._panUp(2*t*i/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.`),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.`),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.`),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;let n=this.domElement.getBoundingClientRect(),r=e-n.left,i=t-n.top,a=n.width,o=n.height;this._mouse.x=r/a*2-1,this._mouse.y=-(i/o)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);let t=this.domElement;this._rotateLeft(Wv*this._rotateDelta.x/t.clientHeight),this._rotateUp(Wv*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(Wv*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-Wv*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(Wv*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-Wv*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._rotateStart.set(n,r)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._panStart.set(n,r)}}_handleTouchStartDolly(e){let t=this._getSecondPointerPosition(e),n=e.pageX-t.x,r=e.pageY-t.y,i=Math.sqrt(n*n+r*r);this._dollyStart.set(0,i)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._rotateEnd.set(n,r)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);let t=this.domElement;this._rotateLeft(Wv*this._rotateDelta.x/t.clientHeight),this._rotateUp(Wv*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._panEnd.set(n,r)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){let t=this._getSecondPointerPosition(e),n=e.pageX-t.x,r=e.pageY-t.y,i=Math.sqrt(n*n+r*r);this._dollyEnd.set(0,i),this._dollyDelta.set(0,(this._dollyEnd.y/this._dollyStart.y)**+this.zoomSpeed),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);let a=(e.pageX+t.x)*.5,o=(e.pageY+t.y)*.5;this._updateZoomParameters(a,o)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t>5&31)/31,a=(e>>10&31)/31)}for(let c=1;c<=3;c++){let l=n+c*12,u=e*3*3+(c-1)*3;p[u]=t.getFloat32(l,!0),p[u+1]=t.getFloat32(l+4,!0),p[u+2]=t.getFloat32(l+8,!0),m[u]=d,m[u+1]=f,m[u+2]=g,o&&(h.setRGB(r,i,a,em),s[u]=h.r,s[u+1]=h.g,s[u+2]=h.b)}}return f.setAttribute(`position`,new mg(p,3)),f.setAttribute(`normal`,new mg(m,3)),o&&(f.setAttribute(`color`,new mg(s,3)),f.hasColors=!0,f.alpha=d),f}function i(e){let t=new wg,n=/solid([\s\S]*?)endsolid/g,r=/facet([\s\S]*?)endfacet/g,i=/solid\s(.+)/,a=0,o=RegExp(`vertex[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)`,`g`),s=RegExp(`normal[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)`,`g`),c=[],l=[],u=[],d=new Mm,f,p=0,m=0,h=0;for(;(f=n.exec(e))!==null;){m=h;let e=f[0],n=(f=i.exec(e))===null?``:f[1];for(u.push(n);(f=r.exec(e))!==null;){let e=0,t=0,n=f[0];for(;(f=s.exec(n))!==null;)d.x=parseFloat(f[1]),d.y=parseFloat(f[2]),d.z=parseFloat(f[3]),t++;for(;(f=o.exec(n))!==null;)c.push(parseFloat(f[1]),parseFloat(f[2]),parseFloat(f[3])),l.push(d.x,d.y,d.z),e++,h++;t!==1&&console.error(`THREE.STLLoader: Something isn't right with the normal of face number `+a),e!==3&&console.error(`THREE.STLLoader: Something isn't right with the vertices of face number `+a),a++}let g=m,_=h-m;t.userData.groupNames=u,t.addGroup(g,_,p),p++}return t.setAttribute(`position`,new _g(c,3)),t.setAttribute(`normal`,new _g(l,3)),t}function a(e){return typeof e==`string`?e:new TextDecoder().decode(e)}function o(e){if(typeof e==`string`){let t=new Uint8Array(e.length);for(let n=0;n{(function(n){typeof e==`object`&&t!==void 0?t.exports=n():typeof define==`function`&&define.amd?define([],n):(typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:this).JSZip=n()})(function(){return function e(t,n,r){function i(o,s){if(!n[o]){if(!t[o]){var c=typeof u==`function`&&u;if(!s&&c)return c(o,!0);if(a)return a(o,!0);var l=Error(`Cannot find module '`+o+`'`);throw l.code=`MODULE_NOT_FOUND`,l}var d=n[o]={exports:{}};t[o][0].call(d.exports,function(e){var n=t[o][1][e];return i(n||e)},d,d.exports,e,t,n,r)}return n[o].exports}for(var a=typeof u==`function`&&u,o=0;o>2,s=(3&t)<<4|n>>4,c=1>6:64,l=2>4,n=(15&o)<<4|(s=a.indexOf(e.charAt(l++)))>>2,r=(3&s)<<6|(c=a.indexOf(e.charAt(l++))),f[u++]=t,s!==64&&(f[u++]=n),c!==64&&(f[u++]=r);return f}},{"./support":30,"./utils":32}],2:[function(e,t,n){var r=e(`./external`),i=e(`./stream/DataWorker`),a=e(`./stream/Crc32Probe`),o=e(`./stream/DataLengthProbe`);function s(e,t,n,r,i){this.compressedSize=e,this.uncompressedSize=t,this.crc32=n,this.compression=r,this.compressedContent=i}s.prototype={getContentWorker:function(){var e=new i(r.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new o(`data_length`)),t=this;return e.on(`end`,function(){if(this.streamInfo.data_length!==t.uncompressedSize)throw Error(`Bug : uncompressed data size mismatch`)}),e},getCompressedWorker:function(){return new i(r.Promise.resolve(this.compressedContent)).withStreamInfo(`compressedSize`,this.compressedSize).withStreamInfo(`uncompressedSize`,this.uncompressedSize).withStreamInfo(`crc32`,this.crc32).withStreamInfo(`compression`,this.compression)}},s.createWorkerFrom=function(e,t,n){return e.pipe(new a).pipe(new o(`uncompressedSize`)).pipe(t.compressWorker(n)).pipe(new o(`compressedSize`)).withStreamInfo(`compression`,t)},t.exports=s},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(e,t,n){var r=e(`./stream/GenericWorker`);n.STORE={magic:`\0\0`,compressWorker:function(){return new r(`STORE compression`)},uncompressWorker:function(){return new r(`STORE decompression`)}},n.DEFLATE=e(`./flate`)},{"./flate":7,"./stream/GenericWorker":28}],4:[function(e,t,n){var r=e(`./utils`),i=function(){for(var e,t=[],n=0;n<256;n++){e=n;for(var r=0;r<8;r++)e=1&e?3988292384^e>>>1:e>>>1;t[n]=e}return t}();t.exports=function(e,t){return e!==void 0&&e.length?r.getTypeOf(e)===`string`?function(e,t,n,r){var a=i,o=r+n;e^=-1;for(var s=r;s>>8^a[255&(e^t.charCodeAt(s))];return-1^e}(0|t,e,e.length,0):function(e,t,n,r){var a=i,o=r+n;e^=-1;for(var s=r;s>>8^a[255&(e^t[s])];return-1^e}(0|t,e,e.length,0):0}},{"./utils":32}],5:[function(e,t,n){n.base64=!1,n.binary=!1,n.dir=!1,n.createFolders=!0,n.date=null,n.compression=null,n.compressionOptions=null,n.comment=null,n.unixPermissions=null,n.dosPermissions=null},{}],6:[function(e,t,n){var r=null;r=typeof Promise<`u`?Promise:e(`lie`),t.exports={Promise:r}},{lie:37}],7:[function(e,t,n){var r=typeof Uint8Array<`u`&&typeof Uint16Array<`u`&&typeof Uint32Array<`u`,i=e(`pako`),a=e(`./utils`),o=e(`./stream/GenericWorker`),s=r?`uint8array`:`array`;function c(e,t){o.call(this,`FlateWorker/`+e),this._pako=null,this._pakoAction=e,this._pakoOptions=t,this.meta={}}n.magic=`\b\0`,a.inherits(c,o),c.prototype.processChunk=function(e){this.meta=e.meta,this._pako===null&&this._createPako(),this._pako.push(a.transformTo(s,e.data),!1)},c.prototype.flush=function(){o.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},c.prototype.cleanUp=function(){o.prototype.cleanUp.call(this),this._pako=null},c.prototype._createPako=function(){this._pako=new i[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var e=this;this._pako.onData=function(t){e.push({data:t,meta:e.meta})}},n.compressWorker=function(e){return new c(`Deflate`,e)},n.uncompressWorker=function(){return new c(`Inflate`,{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(e,t,n){function r(e,t){var n,r=``;for(n=0;n>>=8;return r}function i(e,t,n,i,o,u){var d,f,p=e.file,m=e.compression,h=u!==s.utf8encode,g=a.transformTo(`string`,u(p.name)),_=a.transformTo(`string`,s.utf8encode(p.name)),v=p.comment,y=a.transformTo(`string`,u(v)),b=a.transformTo(`string`,s.utf8encode(v)),x=_.length!==p.name.length,S=b.length!==v.length,C=``,w=``,T=``,E=p.dir,D=p.date,O={crc32:0,compressedSize:0,uncompressedSize:0};t&&!n||(O.crc32=e.crc32,O.compressedSize=e.compressedSize,O.uncompressedSize=e.uncompressedSize);var k=0;t&&(k|=8),h||!x&&!S||(k|=2048);var A=0,j=0;E&&(A|=16),o===`UNIX`?(j=798,A|=function(e,t){var n=e;return e||(n=t?16893:33204),(65535&n)<<16}(p.unixPermissions,E)):(j=20,A|=function(e){return 63&(e||0)}(p.dosPermissions)),d=D.getUTCHours(),d<<=6,d|=D.getUTCMinutes(),d<<=5,d|=D.getUTCSeconds()/2,f=D.getUTCFullYear()-1980,f<<=4,f|=D.getUTCMonth()+1,f<<=5,f|=D.getUTCDate(),x&&(w=r(1,1)+r(c(g),4)+_,C+=`up`+r(w.length,2)+w),S&&(T=r(1,1)+r(c(y),4)+b,C+=`uc`+r(T.length,2)+T);var M=``;return M+=` \0`,M+=r(k,2),M+=m.magic,M+=r(d,2),M+=r(f,2),M+=r(O.crc32,4),M+=r(O.compressedSize,4),M+=r(O.uncompressedSize,4),M+=r(g.length,2),M+=r(C.length,2),{fileRecord:l.LOCAL_FILE_HEADER+M+g+C,dirRecord:l.CENTRAL_FILE_HEADER+r(j,2)+M+r(y.length,2)+`\0\0\0\0`+r(A,4)+r(i,4)+g+C+y}}var a=e(`../utils`),o=e(`../stream/GenericWorker`),s=e(`../utf8`),c=e(`../crc32`),l=e(`../signature`);function u(e,t,n,r){o.call(this,`ZipFileWorker`),this.bytesWritten=0,this.zipComment=t,this.zipPlatform=n,this.encodeFileName=r,this.streamFiles=e,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}a.inherits(u,o),u.prototype.push=function(e){var t=e.meta.percent||0,n=this.entriesCount,r=this._sources.length;this.accumulate?this.contentBuffer.push(e):(this.bytesWritten+=e.data.length,o.prototype.push.call(this,{data:e.data,meta:{currentFile:this.currentFile,percent:n?(t+100*(n-r-1))/n:100}}))},u.prototype.openedSource=function(e){this.currentSourceOffset=this.bytesWritten,this.currentFile=e.file.name;var t=this.streamFiles&&!e.file.dir;if(t){var n=i(e,t,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:n.fileRecord,meta:{percent:0}})}else this.accumulate=!0},u.prototype.closedSource=function(e){this.accumulate=!1;var t=this.streamFiles&&!e.file.dir,n=i(e,t,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(n.dirRecord),t)this.push({data:function(e){return l.DATA_DESCRIPTOR+r(e.crc32,4)+r(e.compressedSize,4)+r(e.uncompressedSize,4)}(e),meta:{percent:100}});else for(this.push({data:n.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},u.prototype.flush=function(){for(var e=this.bytesWritten,t=0;t=this.index;t--)n=(n<<8)+this.byteAt(t);return this.index+=e,n},readString:function(e){return r.transformTo(`string`,this.readData(e))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var e=this.readInt(4);return new Date(Date.UTC(1980+(e>>25&127),(e>>21&15)-1,e>>16&31,e>>11&31,e>>5&63,(31&e)<<1))}},t.exports=i},{"../utils":32}],19:[function(e,t,n){var r=e(`./Uint8ArrayReader`);function i(e){r.call(this,e)}e(`../utils`).inherits(i,r),i.prototype.readData=function(e){this.checkOffset(e);var t=this.data.slice(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(e,t,n){var r=e(`./DataReader`);function i(e){r.call(this,e)}e(`../utils`).inherits(i,r),i.prototype.byteAt=function(e){return this.data.charCodeAt(this.zero+e)},i.prototype.lastIndexOfSignature=function(e){return this.data.lastIndexOf(e)-this.zero},i.prototype.readAndCheckSignature=function(e){return e===this.readData(4)},i.prototype.readData=function(e){this.checkOffset(e);var t=this.data.slice(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./DataReader":18}],21:[function(e,t,n){var r=e(`./ArrayReader`);function i(e){r.call(this,e)}e(`../utils`).inherits(i,r),i.prototype.readData=function(e){if(this.checkOffset(e),e===0)return new Uint8Array;var t=this.data.subarray(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./ArrayReader":17}],22:[function(e,t,n){var r=e(`../utils`),i=e(`../support`),a=e(`./ArrayReader`),o=e(`./StringReader`),s=e(`./NodeBufferReader`),c=e(`./Uint8ArrayReader`);t.exports=function(e){var t=r.getTypeOf(e);return r.checkSupport(t),t!==`string`||i.uint8array?t===`nodebuffer`?new s(e):i.uint8array?new c(r.transformTo(`uint8array`,e)):new a(r.transformTo(`array`,e)):new o(e)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(e,t,n){n.LOCAL_FILE_HEADER=`PK`,n.CENTRAL_FILE_HEADER=`PK`,n.CENTRAL_DIRECTORY_END=`PK`,n.ZIP64_CENTRAL_DIRECTORY_LOCATOR=`PK\x07`,n.ZIP64_CENTRAL_DIRECTORY_END=`PK`,n.DATA_DESCRIPTOR=`PK\x07\b`},{}],24:[function(e,t,n){var r=e(`./GenericWorker`),i=e(`../utils`);function a(e){r.call(this,`ConvertWorker to `+e),this.destType=e}i.inherits(a,r),a.prototype.processChunk=function(e){this.push({data:i.transformTo(this.destType,e.data),meta:e.meta})},t.exports=a},{"../utils":32,"./GenericWorker":28}],25:[function(e,t,n){var r=e(`./GenericWorker`),i=e(`../crc32`);function a(){r.call(this,`Crc32Probe`),this.withStreamInfo(`crc32`,0)}e(`../utils`).inherits(a,r),a.prototype.processChunk=function(e){this.streamInfo.crc32=i(e.data,this.streamInfo.crc32||0),this.push(e)},t.exports=a},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(e,t,n){var r=e(`../utils`),i=e(`./GenericWorker`);function a(e){i.call(this,`DataLengthProbe for `+e),this.propName=e,this.withStreamInfo(e,0)}r.inherits(a,i),a.prototype.processChunk=function(e){if(e){var t=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=t+e.data.length}i.prototype.processChunk.call(this,e)},t.exports=a},{"../utils":32,"./GenericWorker":28}],27:[function(e,t,n){var r=e(`../utils`),i=e(`./GenericWorker`);function a(e){i.call(this,`DataWorker`);var t=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type=``,this._tickScheduled=!1,e.then(function(e){t.dataIsReady=!0,t.data=e,t.max=e&&e.length||0,t.type=r.getTypeOf(e),t.isPaused||t._tickAndRepeat()},function(e){t.error(e)})}r.inherits(a,i),a.prototype.cleanUp=function(){i.prototype.cleanUp.call(this),this.data=null},a.prototype.resume=function(){return!!i.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,r.delay(this._tickAndRepeat,[],this)),!0)},a.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(r.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},a.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var e=null,t=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case`string`:e=this.data.substring(this.index,t);break;case`uint8array`:e=this.data.subarray(this.index,t);break;case`array`:case`nodebuffer`:e=this.data.slice(this.index,t)}return this.index=t,this.push({data:e,meta:{percent:this.max?this.index/this.max*100:0}})},t.exports=a},{"../utils":32,"./GenericWorker":28}],28:[function(e,t,n){function r(e){this.name=e||`default`,this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}r.prototype={push:function(e){this.emit(`data`,e)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit(`end`),this.cleanUp(),this.isFinished=!0}catch(e){this.emit(`error`,e)}return!0},error:function(e){return!this.isFinished&&(this.isPaused?this.generatedError=e:(this.isFinished=!0,this.emit(`error`,e),this.previous&&this.previous.error(e),this.cleanUp()),!0)},on:function(e,t){return this._listeners[e].push(t),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(e,t){if(this._listeners[e])for(var n=0;n `+e:e}},t.exports=r},{}],29:[function(e,t,n){var r=e(`../utils`),i=e(`./ConvertWorker`),a=e(`./GenericWorker`),o=e(`../base64`),s=e(`../support`),c=e(`../external`),l=null;if(s.nodestream)try{l=e(`../nodejs/NodejsStreamOutputAdapter`)}catch{}function u(e,t){return new c.Promise(function(n,i){var a=[],s=e._internalType,c=e._outputType,l=e._mimeType;e.on(`data`,function(e,n){a.push(e),t&&t(n)}).on(`error`,function(e){a=[],i(e)}).on(`end`,function(){try{n(function(e,t,n){switch(e){case`blob`:return r.newBlob(r.transformTo(`arraybuffer`,t),n);case`base64`:return o.encode(t);default:return r.transformTo(e,t)}}(c,function(e,t){var n,r=0,i=null,a=0;for(n=0;n`u`)n.blob=!1;else{var r=new ArrayBuffer(0);try{n.blob=new Blob([r],{type:`application/zip`}).size===0}catch{try{var i=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);i.append(r),n.blob=i.getBlob(`application/zip`).size===0}catch{n.blob=!1}}}try{n.nodestream=!!e(`readable-stream`).Readable}catch{n.nodestream=!1}},{"readable-stream":16}],31:[function(e,t,n){for(var r=e(`./utils`),i=e(`./support`),a=e(`./nodejsUtils`),o=e(`./stream/GenericWorker`),s=Array(256),c=0;c<256;c++)s[c]=252<=c?6:248<=c?5:240<=c?4:224<=c?3:192<=c?2:1;s[254]=s[254]=1;function l(){o.call(this,`utf-8 decode`),this.leftOver=null}function u(){o.call(this,`utf-8 encode`)}n.utf8encode=function(e){return i.nodebuffer?a.newBufferFrom(e,`utf-8`):function(e){var t,n,r,a,o,s=e.length,c=0;for(a=0;a>>6:(n<65536?t[o++]=224|n>>>12:(t[o++]=240|n>>>18,t[o++]=128|n>>>12&63),t[o++]=128|n>>>6&63),t[o++]=128|63&n);return t}(e)},n.utf8decode=function(e){return i.nodebuffer?r.transformTo(`nodebuffer`,e).toString(`utf-8`):function(e){var t,n,i,a,o=e.length,c=Array(2*o);for(t=n=0;t>10&1023,c[n++]=56320|1023&i)}return c.length!==n&&(c.subarray?c=c.subarray(0,n):c.length=n),r.applyFromCharCode(c)}(e=r.transformTo(i.uint8array?`uint8array`:`array`,e))},r.inherits(l,o),l.prototype.processChunk=function(e){var t=r.transformTo(i.uint8array?`uint8array`:`array`,e.data);if(this.leftOver&&this.leftOver.length){if(i.uint8array){var a=t;(t=new Uint8Array(a.length+this.leftOver.length)).set(this.leftOver,0),t.set(a,this.leftOver.length)}else t=this.leftOver.concat(t);this.leftOver=null}var o=function(e,t){var n;for((t||=e.length)>e.length&&(t=e.length),n=t-1;0<=n&&(192&e[n])==128;)n--;return n<0||n===0?t:n+s[e[n]]>t?n:t}(t),c=t;o!==t.length&&(i.uint8array?(c=t.subarray(0,o),this.leftOver=t.subarray(o,t.length)):(c=t.slice(0,o),this.leftOver=t.slice(o,t.length))),this.push({data:n.utf8decode(c),meta:e.meta})},l.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:n.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},n.Utf8DecodeWorker=l,r.inherits(u,o),u.prototype.processChunk=function(e){this.push({data:n.utf8encode(e.data),meta:e.meta})},n.Utf8EncodeWorker=u},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(e,t,n){var r=e(`./support`),i=e(`./base64`),a=e(`./nodejsUtils`),o=e(`./external`);function s(e){return e}function c(e,t){for(var n=0;n>8;this.dir=!!(16&this.externalFileAttributes),e==0&&(this.dosPermissions=63&this.externalFileAttributes),e==3&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||this.fileNameStr.slice(-1)!==`/`||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var e=r(this.extraFields[1].value);this.uncompressedSize===i.MAX_VALUE_32BITS&&(this.uncompressedSize=e.readInt(8)),this.compressedSize===i.MAX_VALUE_32BITS&&(this.compressedSize=e.readInt(8)),this.localHeaderOffset===i.MAX_VALUE_32BITS&&(this.localHeaderOffset=e.readInt(8)),this.diskNumberStart===i.MAX_VALUE_32BITS&&(this.diskNumberStart=e.readInt(4))}},readExtraFields:function(e){var t,n,r,i=e.index+this.extraFieldsLength;for(this.extraFields||={};e.index+4>>6:(n<65536?t[o++]=224|n>>>12:(t[o++]=240|n>>>18,t[o++]=128|n>>>12&63),t[o++]=128|n>>>6&63),t[o++]=128|63&n);return t},n.buf2binstring=function(e){return c(e,e.length)},n.binstring2buf=function(e){for(var t=new r.Buf8(e.length),n=0,i=t.length;n>10&1023,l[r++]=56320|1023&i)}return c(l,r)},n.utf8border=function(e,t){var n;for((t||=e.length)>e.length&&(t=e.length),n=t-1;0<=n&&(192&e[n])==128;)n--;return n<0||n===0?t:n+o[e[n]]>t?n:t}},{"./common":41}],43:[function(e,t,n){t.exports=function(e,t,n,r){for(var i=65535&e|0,a=e>>>16&65535|0,o=0;n!==0;){for(n-=o=2e3>>1:e>>>1;t[n]=e}return t}();t.exports=function(e,t,n,i){var a=r,o=i+n;e^=-1;for(var s=i;s>>8^a[255&(e^t[s])];return-1^e}},{}],46:[function(e,t,n){var r,i=e(`../utils/common`),a=e(`./trees`),o=e(`./adler32`),s=e(`./crc32`),c=e(`./messages`),l=0,u=4,d=0,f=-2,p=-1,m=4,h=2,g=8,_=9,v=286,y=30,b=19,x=2*v+1,S=15,C=3,w=258,T=w+C+1,E=42,D=113,O=1,k=2,A=3,j=4;function M(e,t){return e.msg=c[t],t}function N(e){return(e<<1)-(4e.avail_out&&(n=e.avail_out),n!==0&&(i.arraySet(e.output,t.pending_buf,t.pending_out,n,e.next_out),e.next_out+=n,t.pending_out+=n,e.total_out+=n,e.avail_out-=n,t.pending-=n,t.pending===0&&(t.pending_out=0))}function I(e,t){a._tr_flush_block(e,0<=e.block_start?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,F(e.strm)}function L(e,t){e.pending_buf[e.pending++]=t}function R(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t}function z(e,t){var n,r,i=e.max_chain_length,a=e.strstart,o=e.prev_length,s=e.nice_match,c=e.strstart>e.w_size-T?e.strstart-(e.w_size-T):0,l=e.window,u=e.w_mask,d=e.prev,f=e.strstart+w,p=l[a+o-1],m=l[a+o];e.prev_length>=e.good_match&&(i>>=2),s>e.lookahead&&(s=e.lookahead);do if(l[(n=t)+o]===m&&l[n+o-1]===p&&l[n]===l[a]&&l[++n]===l[a+1]){a+=2,n++;do;while(l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&ac&&--i!=0);return o<=e.lookahead?o:e.lookahead}function B(e){var t,n,r,a,c,l,u,d,f,p,m=e.w_size;do{if(a=e.window_size-e.lookahead-e.strstart,e.strstart>=m+(m-T)){for(i.arraySet(e.window,e.window,m,m,0),e.match_start-=m,e.strstart-=m,e.block_start-=m,t=n=e.hash_size;r=e.head[--t],e.head[t]=m<=r?r-m:0,--n;);for(t=n=m;r=e.prev[--t],e.prev[t]=m<=r?r-m:0,--n;);a+=m}if(e.strm.avail_in===0)break;if(l=e.strm,u=e.window,d=e.strstart+e.lookahead,f=a,p=void 0,p=l.avail_in,f=C)for(c=e.strstart-e.insert,e.ins_h=e.window[c],e.ins_h=(e.ins_h<=C&&(e.ins_h=(e.ins_h<=C)if(r=a._tr_tally(e,e.strstart-e.match_start,e.match_length-C),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=C){for(e.match_length--;e.strstart++,e.ins_h=(e.ins_h<=C&&(e.ins_h=(e.ins_h<=C&&e.match_length<=e.prev_length){for(i=e.strstart+e.lookahead-C,r=a._tr_tally(e,e.strstart-1-e.prev_match,e.prev_length-C),e.lookahead-=e.prev_length-1,e.prev_length-=2;++e.strstart<=i&&(e.ins_h=(e.ins_h<e.pending_buf_size-5&&(n=e.pending_buf_size-5);;){if(e.lookahead<=1){if(B(e),e.lookahead===0&&t===l)return O;if(e.lookahead===0)break}e.strstart+=e.lookahead,e.lookahead=0;var r=e.block_start+n;if((e.strstart===0||e.strstart>=r)&&(e.lookahead=e.strstart-r,e.strstart=r,I(e,!1),e.strm.avail_out===0)||e.strstart-e.block_start>=e.w_size-T&&(I(e,!1),e.strm.avail_out===0))return O}return e.insert=0,t===u?(I(e,!0),e.strm.avail_out===0?A:j):(e.strstart>e.block_start&&(I(e,!1),e.strm.avail_out),O)}),new H(4,4,8,4,V),new H(4,5,16,8,V),new H(4,6,32,32,V),new H(4,4,16,16,ee),new H(8,16,32,32,ee),new H(8,16,128,128,ee),new H(8,32,128,256,ee),new H(32,128,258,1024,ee),new H(32,258,258,4096,ee)],n.deflateInit=function(e,t){return U(e,t,g,15,8,0)},n.deflateInit2=U,n.deflateReset=re,n.deflateResetKeep=ne,n.deflateSetHeader=function(e,t){return e&&e.state&&e.state.wrap===2?(e.state.gzhead=t,d):f},n.deflate=function(e,t){var n,i,o,c;if(!e||!e.state||5>8&255),L(i,i.gzhead.time>>16&255),L(i,i.gzhead.time>>24&255),L(i,i.level===9?2:2<=i.strategy||i.level<2?4:0),L(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(L(i,255&i.gzhead.extra.length),L(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(e.adler=s(e.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(L(i,0),L(i,0),L(i,0),L(i,0),L(i,0),L(i,i.level===9?2:2<=i.strategy||i.level<2?4:0),L(i,3),i.status=D);else{var p=g+(i.w_bits-8<<4)<<8;p|=(2<=i.strategy||i.level<2?0:i.level<6?1:i.level===6?2:3)<<6,i.strstart!==0&&(p|=32),p+=31-p%31,i.status=D,R(i,p),i.strstart!==0&&(R(i,e.adler>>>16),R(i,65535&e.adler)),e.adler=1}if(i.status===69)if(i.gzhead.extra){for(o=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>o&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),F(e),o=i.pending,i.pending!==i.pending_buf_size));)L(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>o&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(i.status===73)if(i.gzhead.name){o=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>o&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),F(e),o=i.pending,i.pending===i.pending_buf_size)){c=1;break}c=i.gzindexo&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),c===0&&(i.gzindex=0,i.status=91)}else i.status=91;if(i.status===91)if(i.gzhead.comment){o=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>o&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),F(e),o=i.pending,i.pending===i.pending_buf_size)){c=1;break}c=i.gzindexo&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),c===0&&(i.status=103)}else i.status=103;if(i.status===103&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&F(e),i.pending+2<=i.pending_buf_size&&(L(i,255&e.adler),L(i,e.adler>>8&255),e.adler=0,i.status=D)):i.status=D),i.pending!==0){if(F(e),e.avail_out===0)return i.last_flush=-1,d}else if(e.avail_in===0&&N(t)<=N(n)&&t!==u)return M(e,-5);if(i.status===666&&e.avail_in!==0)return M(e,-5);if(e.avail_in!==0||i.lookahead!==0||t!==l&&i.status!==666){var m=i.strategy===2?function(e,t){for(var n;;){if(e.lookahead===0&&(B(e),e.lookahead===0)){if(t===l)return O;break}if(e.match_length=0,n=a._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,n&&(I(e,!1),e.strm.avail_out===0))return O}return e.insert=0,t===u?(I(e,!0),e.strm.avail_out===0?A:j):e.last_lit&&(I(e,!1),e.strm.avail_out===0)?O:k}(i,t):i.strategy===3?function(e,t){for(var n,r,i,o,s=e.window;;){if(e.lookahead<=w){if(B(e),e.lookahead<=w&&t===l)return O;if(e.lookahead===0)break}if(e.match_length=0,e.lookahead>=C&&0e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=C?(n=a._tr_tally(e,1,e.match_length-C),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(n=a._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),n&&(I(e,!1),e.strm.avail_out===0))return O}return e.insert=0,t===u?(I(e,!0),e.strm.avail_out===0?A:j):e.last_lit&&(I(e,!1),e.strm.avail_out===0)?O:k}(i,t):r[i.level].func(i,t);if(m!==A&&m!==j||(i.status=666),m===O||m===A)return e.avail_out===0&&(i.last_flush=-1),d;if(m===k&&(t===1?a._tr_align(i):t!==5&&(a._tr_stored_block(i,0,0,!1),t===3&&(P(i.head),i.lookahead===0&&(i.strstart=0,i.block_start=0,i.insert=0))),F(e),e.avail_out===0))return i.last_flush=-1,d}return t===u?i.wrap<=0?1:(i.wrap===2?(L(i,255&e.adler),L(i,e.adler>>8&255),L(i,e.adler>>16&255),L(i,e.adler>>24&255),L(i,255&e.total_in),L(i,e.total_in>>8&255),L(i,e.total_in>>16&255),L(i,e.total_in>>24&255)):(R(i,e.adler>>>16),R(i,65535&e.adler)),F(e),0=n.w_size&&(s===0&&(P(n.head),n.strstart=0,n.block_start=0,n.insert=0),p=new i.Buf8(n.w_size),i.arraySet(p,t,m-n.w_size,n.w_size,0),t=p,m=n.w_size),c=e.avail_in,l=e.next_in,u=e.input,e.avail_in=m,e.next_in=0,e.input=t,B(n);n.lookahead>=C;){for(r=n.strstart,a=n.lookahead-(C-1);n.ins_h=(n.ins_h<>>=b=y>>>24,m-=b,(b=y>>>16&255)==0)E[a++]=65535&y;else{if(!(16&b)){if(!(64&b)){y=h[(65535&y)+(p&(1<>>=b,m-=b),m<15&&(p+=T[r++]<>>=b=y>>>24,m-=b,!(16&(b=y>>>16&255))){if(!(64&b)){y=g[(65535&y)+(p&(1<>>=b,m-=b,(b=a-o)>3,p&=(1<<(m-=x<<3))-1,e.next_in=r,e.next_out=a,e.avail_in=r>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)}function g(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new r.Buf16(320),this.work=new r.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function _(e){var t;return e&&e.state?(t=e.state,e.total_in=e.total_out=t.total=0,e.msg=``,t.wrap&&(e.adler=1&t.wrap),t.mode=f,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new r.Buf32(p),t.distcode=t.distdyn=new r.Buf32(m),t.sane=1,t.back=-1,u):d}function v(e){var t;return e&&e.state?((t=e.state).wsize=0,t.whave=0,t.wnext=0,_(e)):d}function y(e,t){var n,r;return e&&e.state?(r=e.state,t<0?(n=0,t=-t):(n=1+(t>>4),t<48&&(t&=15)),t&&(t<8||15=o.wsize?(r.arraySet(o.window,t,n-o.wsize,o.wsize,0),o.wnext=0,o.whave=o.wsize):(i<(a=o.wsize-o.wnext)&&(a=i),r.arraySet(o.window,t,n-i,a,o.wnext),(i-=a)?(r.arraySet(o.window,t,n-i,i,0),o.wnext=i,o.whave=o.wsize):(o.wnext+=a,o.wnext===o.wsize&&(o.wnext=0),o.whave>>8&255,n.check=a(n.check,B,2,0),x=b=0,n.mode=2;break}if(n.flags=0,n.head&&(n.head.done=!1),!(1&n.wrap)||(((255&b)<<8)+(b>>8))%31){e.msg=`incorrect header check`,n.mode=30;break}if((15&b)!=8){e.msg=`unknown compression method`,n.mode=30;break}if(x-=4,F=8+(15&(b>>>=4)),n.wbits===0)n.wbits=F;else if(F>n.wbits){e.msg=`invalid window size`,n.mode=30;break}n.dmax=1<>8&1),512&n.flags&&(B[0]=255&b,B[1]=b>>>8&255,n.check=a(n.check,B,2,0)),x=b=0,n.mode=3;case 3:for(;x<32;){if(v===0)break e;v--,b+=p[g++]<>>8&255,B[2]=b>>>16&255,B[3]=b>>>24&255,n.check=a(n.check,B,4,0)),x=b=0,n.mode=4;case 4:for(;x<16;){if(v===0)break e;v--,b+=p[g++]<>8),512&n.flags&&(B[0]=255&b,B[1]=b>>>8&255,n.check=a(n.check,B,2,0)),x=b=0,n.mode=5;case 5:if(1024&n.flags){for(;x<16;){if(v===0)break e;v--,b+=p[g++]<>>8&255,n.check=a(n.check,B,2,0)),x=b=0}else n.head&&(n.head.extra=null);n.mode=6;case 6:if(1024&n.flags&&(v<(E=n.length)&&(E=v),E&&(n.head&&(F=n.head.extra_len-n.length,n.head.extra||(n.head.extra=Array(n.head.extra_len)),r.arraySet(n.head.extra,p,g,E,F)),512&n.flags&&(n.check=a(n.check,p,E,g)),v-=E,g+=E,n.length-=E),n.length))break e;n.length=0,n.mode=7;case 7:if(2048&n.flags){if(v===0)break e;for(E=0;F=p[g+ E++],n.head&&F&&n.length<65536&&(n.head.name+=String.fromCharCode(F)),F&&E>9&1,n.head.done=!0),e.adler=n.check=0,n.mode=12;break;case 10:for(;x<32;){if(v===0)break e;v--,b+=p[g++]<>>=7&x,x-=7&x,n.mode=27;break}for(;x<3;){if(v===0)break e;v--,b+=p[g++]<>>=1)){case 0:n.mode=14;break;case 1:if(w(n),n.mode=20,t!==6)break;b>>>=2,x-=2;break e;case 2:n.mode=17;break;case 3:e.msg=`invalid block type`,n.mode=30}b>>>=2,x-=2;break;case 14:for(b>>>=7&x,x-=7&x;x<32;){if(v===0)break e;v--,b+=p[g++]<>>16^65535)){e.msg=`invalid stored block lengths`,n.mode=30;break}if(n.length=65535&b,x=b=0,n.mode=15,t===6)break e;case 15:n.mode=16;case 16:if(E=n.length){if(v>>=5,x-=5,n.ndist=1+(31&b),b>>>=5,x-=5,n.ncode=4+(15&b),b>>>=4,x-=4,286>>=3,x-=3}for(;n.have<19;)n.lens[V[n.have++]]=0;if(n.lencode=n.lendyn,n.lenbits=7,L={bits:n.lenbits},I=s(0,n.lens,0,19,n.lencode,0,n.work,L),n.lenbits=L.bits,I){e.msg=`invalid code lengths set`,n.mode=30;break}n.have=0,n.mode=19;case 19:for(;n.have>>16&255,j=65535&z,!((k=z>>>24)<=x);){if(v===0)break e;v--,b+=p[g++]<>>=k,x-=k,n.lens[n.have++]=j;else{if(j===16){for(R=k+2;x>>=k,x-=k,n.have===0){e.msg=`invalid bit length repeat`,n.mode=30;break}F=n.lens[n.have-1],E=3+(3&b),b>>>=2,x-=2}else if(j===17){for(R=k+3;x>>=k)),b>>>=3,x-=3}else{for(R=k+7;x>>=k)),b>>>=7,x-=7}if(n.have+E>n.nlen+n.ndist){e.msg=`invalid bit length repeat`,n.mode=30;break}for(;E--;)n.lens[n.have++]=F}}if(n.mode===30)break;if(n.lens[256]===0){e.msg=`invalid code -- missing end-of-block`,n.mode=30;break}if(n.lenbits=9,L={bits:n.lenbits},I=s(c,n.lens,0,n.nlen,n.lencode,0,n.work,L),n.lenbits=L.bits,I){e.msg=`invalid literal/lengths set`,n.mode=30;break}if(n.distbits=6,n.distcode=n.distdyn,L={bits:n.distbits},I=s(l,n.lens,n.nlen,n.ndist,n.distcode,0,n.work,L),n.distbits=L.bits,I){e.msg=`invalid distances set`,n.mode=30;break}if(n.mode=20,t===6)break e;case 20:n.mode=21;case 21:if(6<=v&&258<=y){e.next_out=_,e.avail_out=y,e.next_in=g,e.avail_in=v,n.hold=b,n.bits=x,o(e,C),_=e.next_out,m=e.output,y=e.avail_out,g=e.next_in,p=e.input,v=e.avail_in,b=n.hold,x=n.bits,n.mode===12&&(n.back=-1);break}for(n.back=0;A=(z=n.lencode[b&(1<>>16&255,j=65535&z,!((k=z>>>24)<=x);){if(v===0)break e;v--,b+=p[g++]<>M)])>>>16&255,j=65535&z,!(M+(k=z>>>24)<=x);){if(v===0)break e;v--,b+=p[g++]<>>=M,x-=M,n.back+=M}if(b>>>=k,x-=k,n.back+=k,n.length=j,A===0){n.mode=26;break}if(32&A){n.back=-1,n.mode=12;break}if(64&A){e.msg=`invalid literal/length code`,n.mode=30;break}n.extra=15&A,n.mode=22;case 22:if(n.extra){for(R=n.extra;x>>=n.extra,x-=n.extra,n.back+=n.extra}n.was=n.length,n.mode=23;case 23:for(;A=(z=n.distcode[b&(1<>>16&255,j=65535&z,!((k=z>>>24)<=x);){if(v===0)break e;v--,b+=p[g++]<>M)])>>>16&255,j=65535&z,!(M+(k=z>>>24)<=x);){if(v===0)break e;v--,b+=p[g++]<>>=M,x-=M,n.back+=M}if(b>>>=k,x-=k,n.back+=k,64&A){e.msg=`invalid distance code`,n.mode=30;break}n.offset=j,n.extra=15&A,n.mode=24;case 24:if(n.extra){for(R=n.extra;x>>=n.extra,x-=n.extra,n.back+=n.extra}if(n.offset>n.dmax){e.msg=`invalid distance too far back`,n.mode=30;break}n.mode=25;case 25:if(y===0)break e;if(E=C-y,n.offset>E){if((E=n.offset-E)>n.whave&&n.sane){e.msg=`invalid distance too far back`,n.mode=30;break}D=E>n.wnext?(E-=n.wnext,n.wsize-E):n.wnext-E,E>n.length&&(E=n.length),O=n.window}else O=m,D=_-n.offset,E=n.length;for(yv?(b=L[R+d[w]],N[P+d[w]]):(b=96,0),p=1<>k)+(m-=p)]=y<<24|b<<16|x|0,m!==0;);for(p=1<>=1;if(p===0?M=0:(M&=p-1,M+=p),w++,--F[C]==0){if(C===E)break;C=t[n+d[w]]}if(D>>7)]}function L(e,t){e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255}function R(e,t,n){e.bi_valid>h-n?(e.bi_buf|=t<>h-e.bi_valid,e.bi_valid+=n-h):(e.bi_buf|=t<>>=1,n<<=1,0<--t;);return n>>>1}function V(e,t,n){var r,i,a=Array(m+1),o=0;for(r=1;r<=m;r++)a[r]=o=o+n[r-1]<<1;for(i=0;i<=t;i++){var s=e[2*i+1];s!==0&&(e[2*i]=B(a[s]++,s))}}function ee(e){var t;for(t=0;t>1;1<=n;n--)ne(e,a,n);for(i=c;n=e.heap[1],e.heap[1]=e.heap[e.heap_len--],ne(e,a,1),r=e.heap[1],e.heap[--e.heap_max]=n,e.heap[--e.heap_max]=r,a[2*i]=a[2*n]+a[2*r],e.depth[i]=(e.depth[n]>=e.depth[r]?e.depth[n]:e.depth[r])+1,a[2*n+1]=a[2*r+1]=i,e.heap[1]=i++,ne(e,a,1),2<=e.heap_len;);e.heap[--e.heap_max]=e.heap[1],function(e,t){var n,r,i,a,o,s,c=t.dyn_tree,l=t.max_code,u=t.stat_desc.static_tree,d=t.stat_desc.has_stree,f=t.stat_desc.extra_bits,h=t.stat_desc.extra_base,g=t.stat_desc.max_length,_=0;for(a=0;a<=m;a++)e.bl_count[a]=0;for(c[2*e.heap[e.heap_max]+1]=0,n=e.heap_max+1;n>=7;r>>=1)if(1&n&&e.dyn_ltree[2*t]!==0)return i;if(e.dyn_ltree[18]!==0||e.dyn_ltree[20]!==0||e.dyn_ltree[26]!==0)return a;for(t=32;t>>3,(s=e.static_len+3+7>>>3)<=o&&(o=s)):o=s=n+5,n+4<=o&&t!==-1?oe(e,t,n,r):e.strategy===4||s===o?(R(e,2+ +!!r,3),re(e,T,E)):(R(e,4+ +!!r,3),function(e,t,n,r){var i;for(R(e,t-257,5),R(e,n-1,5),R(e,r-4,4),i=0;i>>8&255,e.pending_buf[e.d_buf+2*e.last_lit+1]=255&t,e.pending_buf[e.l_buf+e.last_lit]=255&n,e.last_lit++,t===0?e.dyn_ltree[2*n]++:(e.matches++,t--,e.dyn_ltree[2*(O[n]+l+1)]++,e.dyn_dtree[2*I(t)]++),e.last_lit===e.lit_bufsize-1},n._tr_align=function(e){R(e,2,3),z(e,_,T),function(e){e.bi_valid===16?(L(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):8<=e.bi_valid&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)}(e)}},{"../utils/common":41}],53:[function(e,t,n){t.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg=``,this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(e,t,n){(function(e){(function(e,t){if(!e.setImmediate){var n,r,i,a,o=1,s={},c=!1,l=e.document,u=Object.getPrototypeOf&&Object.getPrototypeOf(e);u=u&&u.setTimeout?u:e,n={}.toString.call(e.process)===`[object process]`?function(e){process.nextTick(function(){f(e)})}:function(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage(``,`*`),e.onmessage=n,t}}()?(a=`setImmediate$`+Math.random()+`$`,e.addEventListener?e.addEventListener(`message`,p,!1):e.attachEvent(`onmessage`,p),function(t){e.postMessage(a+t,`*`)}):e.MessageChannel?((i=new MessageChannel).port1.onmessage=function(e){f(e.data)},function(e){i.port2.postMessage(e)}):l&&`onreadystatechange`in l.createElement(`script`)?(r=l.documentElement,function(e){var t=l.createElement(`script`);t.onreadystatechange=function(){f(e),t.onreadystatechange=null,r.removeChild(t),t=null},r.appendChild(t)}):function(e){setTimeout(f,0,e)},u.setImmediate=function(e){typeof e!=`function`&&(e=Function(``+e));for(var t=Array(arguments.length-1),r=0;r`u`?e===void 0?this:e:self)}).call(this,typeof global<`u`?global:typeof self<`u`?self:typeof window<`u`?window:{})},{}]},{},[10])(10)})}))(),1);function Yv(){return new Promise(e=>setTimeout(e,0))}var Xv=2e4,Zv=2e4;function Eie(e){let t=new Sh;if(!e)return t;let n=e.trim().split(/\s+/).map(parseFloat);return n.length>=12&&t.set(n[0],n[1],n[2],n[9],n[3],n[4],n[5],n[10],n[6],n[7],n[8],n[11],0,0,0,1),t}var Qv=Eie;async function $v(e,t=0){let n=[],r=e.getElementsByTagName(`mesh`);for(let e=0;e0&&e%Xv===0&&await Yv()}let c=i.getElementsByTagName(`triangle`);for(let e=0;e0&&e%Zv===0&&await Yv()}a.length>0&&o.length>0&&n.push({vertices:a,triangles:o,extruder:t})}return n}function ey(e){let t=Array.from(e.attributes).find(e=>{let t=e.name.toLowerCase();return t===`plate_id`||t===`plater_id`||t===`plateid`||t===`platerid`||t.endsWith(`:plate_id`)||t.endsWith(`:plater_id`)});if(!t?.value)return null;let n=Number.parseInt(t.value,10);return Number.isFinite(n)?n:null}async function Die(e){let t;try{t=await Tie.default.loadAsync(e)}catch{throw Error(`Unsupported file format`)}let n=new Map,r=[],i=new Map,a=new Map,o=new DOMParser;async function s(e){let n=e.startsWith(`/`)?e.slice(1):e,r=t.files[n];if(!r)return null;let i=await r.async(`string`);return o.parseFromString(i,`application/xml`)}let c=new Map,l=new Map,u=new Map,d=new Map,f=t.files[`Metadata/model_settings.config`];if(f)try{let e=await f.async(`string`),t=o.parseFromString(e,`application/xml`),n=t.getElementsByTagName(`object`);for(let e=0;ee.tagName===`metadata`&&e.getAttribute(`key`)===`extruder`);if(i.length>0){let e=i[0].getAttribute(`value`);e&&c.set(r,Math.max(0,parseInt(e,10)-1))}let a=Array.from(t.children).find(e=>e.tagName===`metadata`&&e.getAttribute(`key`)===`name`)?.getAttribute(`value`);a&&u.set(r,a);let o=t.getElementsByTagName(`part`);for(let e=0;ee.tagName===`metadata`&&e.getAttribute(`key`)===`extruder`);if(i.length>0){let e=i[0].getAttribute(`value`);e&&l.set(`${r}:${n}`,Math.max(0,parseInt(e,10)-1))}}}let r=t.getElementsByTagName(`plate`);for(let e=0;ee.startsWith(`Metadata/plate_`)&&e.endsWith(`.json`));for(let e of m){let n=e.match(/^Metadata\/plate_(\d+)\.json$/);if(!n)continue;let r=Number.parseInt(n[1],10);if(Number.isFinite(r))try{let n=await t.files[e].async(`string`),a=JSON.parse(n),o=a.bbox_objects??[];for(let e of o)e?.name&&p.set(e.name,r);if(Array.isArray(a.bbox_all)&&a.bbox_all.length>=4){let[e,t,n,o]=a.bbox_all;[e,t,n,o].every(e=>Number.isFinite(e))&&i.set(r,{minX:e,minY:t,maxX:n,maxY:o})}}catch{}}let h=Object.keys(t.files).find(e=>e===`3D/3dmodel.model`||e.endsWith(`/3dmodel.model`));if(!h){let e=Object.keys(t.files).find(e=>e.endsWith(`.model`));if(e){let t=await s(e);if(t){let e=await $v(t,0);e.length>0&&n.set(`1`,{id:`1`,meshes:e,defaultExtruder:0})}}return{objects:n,buildItems:r,plateBounds:i,plateOffsets:a}}let g=await s(h);if(!g)return{objects:n,buildItems:r,plateBounds:i,plateOffsets:a};let _=g.getElementsByTagName(`object`);for(let e=0;e<_.length;e++){e>0&&await Yv();let t=_[e],r=t.getAttribute(`id`);if(!r)continue;let i=ey(t)??d.get(r)??null,a=c.get(r)??-1;if(a<0){let e=t.getAttribute(`p:extruder`)||t.getAttributeNS(`http://schemas.microsoft.com/3dmanufacturing/production/2015/06`,`extruder`)||`1`;a=Math.max(0,parseInt(e,10)-1)}let o=[],u=t.getElementsByTagName(`mesh`);for(let e=0;e0&&e%Xv===0&&await Yv()}let s=t.getElementsByTagName(`triangle`);for(let e=0;e0&&e%Zv===0&&await Yv()}n.length>0&&r.length>0&&o.push({vertices:n,triangles:r,extruder:a})}let f=t.getElementsByTagName(`component`);for(let e=0;e0&&n.set(r,{id:r,meshes:o,defaultExtruder:a,plateId:i})}let v=g.getElementsByTagName(`build`);if(v.length>0){let e=v[0].getElementsByTagName(`item`);for(let t=0;t{if(e instanceof Ig)if(e.geometry.dispose(),Array.isArray(e.material))for(let t of e.material)t.dispose();else e.material.dispose()})}function kie(e,t,n){let{objects:r,buildItems:i}=e,a=new Zg,o=e=>new v_({color:new cg(n?.[e]||`#00ae42`),shininess:30,flatShading:!1}),s=new Map,c=i.some(e=>e.plateId!=null),l=t==null||!c?i:i.filter(e=>e.plateId===t),u=l.length>0?l:i;if(u.length>0)for(let e of u){let t=r.get(e.objectId);if(t)for(let n of t.meshes){let t=e.extruder??n.extruder,r=[];for(let t=0;t1)for(let e of t)e.dispose()}return a}function ny({url:e,fileType:t,buildVolume:n={x:256,y:256,z:256},filamentColors:r,selectedPlateId:i=null,className:a=``}){let{t:o}=G(),s=(0,y.useRef)(null),c=(0,y.useRef)(null),l=(0,y.useRef)(null),u=(0,y.useRef)(null),d=(0,y.useRef)(null),f=(0,y.useRef)(null),p=(0,y.useRef)(null),m=(0,y.useRef)(null),[h,g]=(0,y.useState)(!0),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(null),[S,C]=(0,y.useState)(null);(0,y.useEffect)(()=>{if(!s.current)return;let r=s.current,i=r.clientWidth,a=r.clientHeight,h=new xte;h.background=new cg(1710618),l.current=h;let _=new qg(45,i/a,.1,1e4);_.position.set(150,150,150),u.current=_;let y=new lie({antialias:!0});y.setSize(i,a),y.setPixelRatio(window.devicePixelRatio),r.appendChild(y.domElement),c.current=y;let b=new die(_,y.domElement);b.enableDamping=!0,b.dampingFactor=.05,d.current=b;let S=new Ute(16777215,.6);h.add(S);let w=new N_(16777215,.8);w.position.set(100,100,100),h.add(w);let T=new N_(16777215,.4);T.position.set(-100,50,-100),h.add(T);let E=Math.max(n.x,n.y),D=new tne(E,Math.ceil(E/16),4473924,3355443);h.add(D),m.current=D;let O=new Ig(new __(n.x,n.y),new dg({color:44610,transparent:!0,opacity:.15,side:2}));O.rotation.x=-Math.PI/2,O.position.y=-.5,h.add(O),p.current=O;let k,A=()=>{k=requestAnimationFrame(A),b.update(),y.render(h,_)};A(),g(!0),v(null),x(null),C(null);let j=(t||e.split(`?`)[0].split(`.`).pop()||``).toLowerCase(),M={},N=Hu();N&&(M.Authorization=`Bearer ${N}`),j===`stl`?fetch(e,{headers:M}).then(e=>{if(!e.ok)throw Error(o(`modelViewer.errors.failedToLoad`));return e.arrayBuffer()}).then(e=>{let t=new wie().parse(e);t.computeVertexNormals(),t.rotateX(-Math.PI/2),C(t)}).catch(e=>{v(e.message),g(!1)}):j===`3mf`?fetch(e,{headers:M}).then(e=>{if(!e.ok)throw Error(o(`modelViewer.errors.failedToLoad`));return e.arrayBuffer()}).then(Die).then(e=>{if(e.objects.size===0)throw Error(o(`modelViewer.errors.noMeshes`));x(e)}).catch(e=>{v(e.message),g(!1)}):(v(o(`modelViewer.errors.unsupportedFormat`)),g(!1));let P=()=>{if(!r)return;let e=r.clientWidth,t=r.clientHeight;e===0||t===0||(_.aspect=e/t,_.updateProjectionMatrix(),y.setSize(e,t))};window.addEventListener(`resize`,P);let F=new ResizeObserver(()=>{P()});return F.observe(r),()=>{window.removeEventListener(`resize`,P),F.disconnect(),cancelAnimationFrame(k),b.dispose(),y.dispose(),r.removeChild(y.domElement),f.current=null,p.current=null,m.current=null}},[e,n,t,o]),(0,y.useEffect)(()=>{if(!l.current||!u.current||!d.current||!b&&!S)return;f.current&&(l.current.remove(f.current),Oie(f.current));let e=!!S,t=e?(()=>{let e=new Ig(S,new v_({color:new cg(r?.[0]||`#00ae42`),shininess:30})),t=new Zg;return t.add(e),t})():kie(b,i??null,r);f.current=t,l.current.add(t);let a=new Xm().setFromObject(t),o=a.getCenter(new Mm);t.position.y=-a.min.y;let s=!e&&i!=null&&b.buildItems.length>0?b.plateBounds.get(i):void 0,c=!e&&i!=null?b.plateOffsets.get(i):void 0,h=e||b.buildItems.length===0||i!=null&&!s&&!c,_=h?-o.x:0,v=h?-o.z:0,y=0,x=0;if(!e&&i!=null&&b.buildItems.length>0&&s){let e=new Xm().setFromObject(t);y=e.min.x-s.minX,x=e.min.z-s.minY}let C=n.x/2,w=n.y/2;!e&&i!=null&&b.buildItems.length>0&&s?(t.position.x=_-y,t.position.z=v-x):!e&&i!=null&&c?(t.position.x=_+(C-c.offsetX),t.position.z=v+(w-c.offsetY)):h?(t.position.x=_+C,t.position.z=v+w):(t.position.x=_,t.position.z=v),p.current&&(p.current.position.x=C,p.current.position.z=w),m.current&&(m.current.position.x=C,m.current.position.z=w);let T=new Xm().setFromObject(t),E=T.getCenter(new Mm),D=T.getSize(new Mm),O=Math.max(D.x,D.y,D.z)*1.8;u.current.position.set(E.x+O*.7,E.y+O*.5,E.z+O*.7),d.current.target.copy(E),d.current.update(),g(!1)},[b,S,i,r,n]);let w=()=>{u.current&&d.current&&(u.current.position.set(150,150,150),d.current.target.set(0,50,0),d.current.update())},T=e=>{u.current&&u.current.position.multiplyScalar(e)};return(0,K.jsxs)(`div`,{className:`relative ${a}`,children:[(0,K.jsx)(`div`,{ref:s,className:`w-full h-full min-h-[400px]`}),h&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-bambu-dark/80`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}),_&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-bambu-dark/80`,children:(0,K.jsx)(`p`,{className:`text-red-400`,children:_})}),!h&&!_&&(0,K.jsxs)(`div`,{className:`absolute bottom-4 right-4 flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>T(.8),children:(0,K.jsx)(Fu,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>T(1.25),children:(0,K.jsx)(Lu,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:w,children:(0,K.jsx)(Tl,{className:`w-4 h-4`})})]})]})}var ry={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},iy={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},ay=1e3,oy=1001,sy=1002,cy=1003,Aie=1004,jie=1005,ly=1006,Mie=1007,uy=1008,dy=1009,fy=1014,py=1015,my=1016,hy=1020,gy=1023,_y=1026,Nie=1027,vy=2300,yy=2301,by=2302,xy=2400,Sy=2401,Cy=2402,wy=3e3,Ty=3001,Pie=3200,Fie=3201,Ey=`srgb`,Dy=`srgb-linear`,Oy=`display-p3`,ky=`display-p3-linear`,Ay=`linear`,jy=`srgb`,My=`rec709`,Ny=7680,Py=35044,Iie=1035,Fy=2e3,Lie=2001,Iy=class{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});let n=this._listeners;n[e]===void 0&&(n[e]=[]),n[e].indexOf(t)===-1&&n[e].push(t)}hasEventListener(e,t){if(this._listeners===void 0)return!1;let n=this._listeners;return n[e]!==void 0&&n[e].indexOf(t)!==-1}removeEventListener(e,t){if(this._listeners===void 0)return;let n=this._listeners[e];if(n!==void 0){let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}dispatchEvent(e){if(this._listeners===void 0)return;let t=this._listeners[e.type];if(t!==void 0){e.target=this;let n=t.slice(0);for(let t=0,r=n.length;t>8&255]+Ly[e>>16&255]+Ly[e>>24&255]+`-`+Ly[t&255]+Ly[t>>8&255]+`-`+Ly[t>>16&15|64]+Ly[t>>24&255]+`-`+Ly[n&63|128]+Ly[n>>8&255]+`-`+Ly[n>>16&255]+Ly[n>>24&255]+Ly[r&255]+Ly[r>>8&255]+Ly[r>>16&255]+Ly[r>>24&255]).toLowerCase()}function Hy(e,t,n){return Math.max(t,Math.min(n,e))}function Uy(e,t){return(e%t+t)%t}function Rie(e,t,n,r,i){return r+(e-t)*(i-r)/(n-t)}function zie(e,t,n){return e===t?0:(n-e)/(t-e)}function Wy(e,t,n){return(1-n)*e+n*t}function Bie(e,t,n,r){return Wy(e,t,1-Math.exp(-n*r))}function Vie(e,t=1){return t-Math.abs(Uy(e,t*2)-t)}function Hie(e,t,n){return e<=t?0:e>=n?1:(e=(e-t)/(n-t),e*e*(3-2*e))}function Uie(e,t,n){return e<=t?0:e>=n?1:(e=(e-t)/(n-t),e*e*e*(e*(e*6-15)+10))}function Wie(e,t){return e+Math.floor(Math.random()*(t-e+1))}function Gie(e,t){return e+Math.random()*(t-e)}function Kie(e){return e*(.5-Math.random())}function qie(e){e!==void 0&&(Ry=e);let t=Ry+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function Jie(e){return e*zy}function Yie(e){return e*By}function Gy(e){return(e&e-1)==0&&e!==0}function Xie(e){return 2**Math.ceil(Math.log(e)/Math.LN2)}function Ky(e){return 2**Math.floor(Math.log(e)/Math.LN2)}function Zie(e,t,n,r,i){let a=Math.cos,o=Math.sin,s=a(n/2),c=o(n/2),l=a((t+r)/2),u=o((t+r)/2),d=a((t-r)/2),f=o((t-r)/2),p=a((r-t)/2),m=o((r-t)/2);switch(i){case`XYX`:e.set(s*u,c*d,c*f,s*l);break;case`YZY`:e.set(c*f,s*u,c*d,s*l);break;case`ZXZ`:e.set(c*d,c*f,s*u,s*l);break;case`XZX`:e.set(s*u,c*m,c*p,s*l);break;case`YXY`:e.set(c*p,s*u,c*m,s*l);break;case`ZYZ`:e.set(c*m,c*p,s*u,s*l);break;default:console.warn(`THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: `+i)}}function qy(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return e/4294967295;case Uint16Array:return e/65535;case Uint8Array:return e/255;case Int32Array:return Math.max(e/2147483647,-1);case Int16Array:return Math.max(e/32767,-1);case Int8Array:return Math.max(e/127,-1);default:throw Error(`Invalid component type.`)}}function Jy(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return Math.round(e*4294967295);case Uint16Array:return Math.round(e*65535);case Uint8Array:return Math.round(e*255);case Int32Array:return Math.round(e*2147483647);case Int16Array:return Math.round(e*32767);case Int8Array:return Math.round(e*127);default:throw Error(`Invalid component type.`)}}var Yy={DEG2RAD:zy,RAD2DEG:By,generateUUID:Vy,clamp:Hy,euclideanModulo:Uy,mapLinear:Rie,inverseLerp:zie,lerp:Wy,damp:Bie,pingpong:Vie,smoothstep:Hie,smootherstep:Uie,randInt:Wie,randFloat:Gie,randFloatSpread:Kie,seededRandom:qie,degToRad:Jie,radToDeg:Yie,isPowerOfTwo:Gy,ceilPowerOfTwo:Xie,floorPowerOfTwo:Ky,setQuaternionFromProperEuler:Zie,normalize:Jy,denormalize:qy},Xy=class e{constructor(t=0,n=0){e.prototype.isVector2=!0,this.x=t,this.y=n}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw Error(`index is out of range: `+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw Error(`index is out of range: `+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){let t=this.x,n=this.y,r=e.elements;return this.x=r[0]*t+r[3]*n+r[6],this.y=r[1]*t+r[4]*n+r[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let n=this.dot(e)/t;return Math.acos(Hy(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,n=this.y-e.y;return t*t+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){let n=Math.cos(t),r=Math.sin(t),i=this.x-e.x,a=this.y-e.y;return this.x=i*n-a*r+e.x,this.y=i*r+a*n+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}},Zy=class e{constructor(t,n,r,i,a,o,s,c,l){e.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,n,r,i,a,o,s,c,l)}set(e,t,n,r,i,a,o,s,c){let l=this.elements;return l[0]=e,l[1]=r,l[2]=o,l[3]=t,l[4]=i,l[5]=s,l[6]=n,l[7]=a,l[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){let t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],this}extractBasis(e,t,n){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(e){let t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let n=e.elements,r=t.elements,i=this.elements,a=n[0],o=n[3],s=n[6],c=n[1],l=n[4],u=n[7],d=n[2],f=n[5],p=n[8],m=r[0],h=r[3],g=r[6],_=r[1],v=r[4],y=r[7],b=r[2],x=r[5],S=r[8];return i[0]=a*m+o*_+s*b,i[3]=a*h+o*v+s*x,i[6]=a*g+o*y+s*S,i[1]=c*m+l*_+u*b,i[4]=c*h+l*v+u*x,i[7]=c*g+l*y+u*S,i[2]=d*m+f*_+p*b,i[5]=d*h+f*v+p*x,i[8]=d*g+f*y+p*S,this}multiplyScalar(e){let t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){let e=this.elements,t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],o=e[5],s=e[6],c=e[7],l=e[8];return t*a*l-t*o*c-n*i*l+n*o*s+r*i*c-r*a*s}invert(){let e=this.elements,t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],o=e[5],s=e[6],c=e[7],l=e[8],u=l*a-o*c,d=o*s-l*i,f=c*i-a*s,p=t*u+n*d+r*f;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);let m=1/p;return e[0]=u*m,e[1]=(r*c-l*n)*m,e[2]=(o*n-r*a)*m,e[3]=d*m,e[4]=(l*t-r*s)*m,e[5]=(r*i-o*t)*m,e[6]=f*m,e[7]=(n*s-c*t)*m,e[8]=(a*t-n*i)*m,this}transpose(){let e,t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){let t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,n,r,i,a,o){let s=Math.cos(i),c=Math.sin(i);return this.set(n*s,n*c,-n*(s*a+c*o)+a+e,-r*c,r*s,-r*(-c*a+s*o)+o+t,0,0,1),this}scale(e,t){return this.premultiply(Qy.makeScale(e,t)),this}rotate(e){return this.premultiply(Qy.makeRotation(-e)),this}translate(e,t){return this.premultiply(Qy.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,n,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){let t=this.elements,n=e.elements;for(let e=0;e<9;e++)if(t[e]!==n[e])return!1;return!0}fromArray(e,t=0){for(let n=0;n<9;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){let n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e}clone(){return new this.constructor().fromArray(this.elements)}},Qy=new Zy;function $y(e){for(let t=e.length-1;t>=0;--t)if(e[t]>=65535)return!0;return!1}function eb(e){return document.createElementNS(`http://www.w3.org/1999/xhtml`,e)}function Qie(){let e=eb(`canvas`);return e.style.display=`block`,e}var tb={};function nb(e){e in tb||(tb[e]=!0,console.warn(e))}var rb=new Zy().set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),ib=new Zy().set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),ab={[Dy]:{transfer:Ay,primaries:My,toReference:e=>e,fromReference:e=>e},[Ey]:{transfer:jy,primaries:My,toReference:e=>e.convertSRGBToLinear(),fromReference:e=>e.convertLinearToSRGB()},[ky]:{transfer:Ay,primaries:`p3`,toReference:e=>e.applyMatrix3(ib),fromReference:e=>e.applyMatrix3(rb)},[Oy]:{transfer:jy,primaries:`p3`,toReference:e=>e.convertSRGBToLinear().applyMatrix3(ib),fromReference:e=>e.applyMatrix3(rb).convertLinearToSRGB()}},$ie=new Set([Dy,ky]),ob={enabled:!0,_workingColorSpace:Dy,get legacyMode(){return console.warn(`THREE.ColorManagement: .legacyMode=false renamed to .enabled=true in r150.`),!this.enabled},set legacyMode(e){console.warn(`THREE.ColorManagement: .legacyMode=false renamed to .enabled=true in r150.`),this.enabled=!e},get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(e){if(!$ie.has(e))throw Error(`Unsupported working color space, "${e}".`);this._workingColorSpace=e},convert:function(e,t,n){if(this.enabled===!1||t===n||!t||!n)return e;let r=ab[t].toReference,i=ab[n].fromReference;return i(r(e))},fromWorkingColorSpace:function(e,t){return this.convert(e,this._workingColorSpace,t)},toWorkingColorSpace:function(e,t){return this.convert(e,t,this._workingColorSpace)},getPrimaries:function(e){return ab[e].primaries},getTransfer:function(e){return e===``?Ay:ab[e].transfer}};function sb(e){return e<.04045?e*.0773993808:(e*.9478672986+.0521327014)**2.4}function cb(e){return e<.0031308?e*12.92:1.055*e**.41666-.055}var lb,ub=class{static getDataURL(e){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>`u`)return e.src;let t;if(e instanceof HTMLCanvasElement)t=e;else{lb===void 0&&(lb=eb(`canvas`)),lb.width=e.width,lb.height=e.height;let n=lb.getContext(`2d`);e instanceof ImageData?n.putImageData(e,0,0):n.drawImage(e,0,0,e.width,e.height),t=lb}return t.width>2048||t.height>2048?(console.warn(`THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons`,e),t.toDataURL(`image/jpeg`,.6)):t.toDataURL(`image/png`)}static sRGBToLinear(e){if(typeof HTMLImageElement<`u`&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof ImageBitmap<`u`&&e instanceof ImageBitmap){let t=eb(`canvas`);t.width=e.width,t.height=e.height;let n=t.getContext(`2d`);n.drawImage(e,0,0,e.width,e.height);let r=n.getImageData(0,0,e.width,e.height),i=r.data;for(let e=0;e0&&(n.userData=this.userData),t||(e.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:`dispose`})}transformUv(e){if(this.mapping!==300)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case ay:e.x-=Math.floor(e.x);break;case oy:e.x=e.x<0?0:1;break;case sy:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x-=Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case ay:e.y-=Math.floor(e.y);break;case oy:e.y=e.y<0?0:1;break;case sy:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y-=Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}get encoding(){return nb(`THREE.Texture: Property .encoding has been replaced by .colorSpace.`),this.colorSpace===`srgb`?Ty:wy}set encoding(e){nb(`THREE.Texture: Property .encoding has been replaced by .colorSpace.`),this.colorSpace=e===3001?Ey:``}};pb.DEFAULT_IMAGE=null,pb.DEFAULT_MAPPING=300,pb.DEFAULT_ANISOTROPY=1;var mb=class e{constructor(t=0,n=0,r=0,i=1){e.prototype.isVector4=!0,this.x=t,this.y=n,this.z=r,this.w=i}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,n,r){return this.x=e,this.y=t,this.z=n,this.w=r,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw Error(`index is out of range: `+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw Error(`index is out of range: `+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w===void 0?1:e.w,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){let t=this.x,n=this.y,r=this.z,i=this.w,a=e.elements;return this.x=a[0]*t+a[4]*n+a[8]*r+a[12]*i,this.y=a[1]*t+a[5]*n+a[9]*r+a[13]*i,this.z=a[2]*t+a[6]*n+a[10]*r+a[14]*i,this.w=a[3]*t+a[7]*n+a[11]*r+a[15]*i,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);let t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,n,r,i,a=.01,o=.1,s=e.elements,c=s[0],l=s[4],u=s[8],d=s[1],f=s[5],p=s[9],m=s[2],h=s[6],g=s[10];if(Math.abs(l-d)s&&e>_?e_?s=0?1:-1,r=1-t*t;if(r>2**-52){let i=Math.sqrt(r),a=Math.atan2(i,t*n);e=Math.sin(e*a)/i,o=Math.sin(o*a)/i}let i=o*n;if(s=s*e+d*i,c=c*e+f*i,l=l*e+p*i,u=u*e+m*i,e===1-o){let e=1/Math.sqrt(s*s+c*c+l*l+u*u);s*=e,c*=e,l*=e,u*=e}}e[t]=s,e[t+1]=c,e[t+2]=l,e[t+3]=u}static multiplyQuaternionsFlat(e,t,n,r,i,a){let o=n[r],s=n[r+1],c=n[r+2],l=n[r+3],u=i[a],d=i[a+1],f=i[a+2],p=i[a+3];return e[t]=o*p+l*u+s*f-c*d,e[t+1]=s*p+l*d+c*u-o*f,e[t+2]=c*p+l*f+o*d-s*u,e[t+3]=l*p-o*u-s*d-c*f,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,n,r){return this._x=e,this._y=t,this._z=n,this._w=r,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t){let n=e._x,r=e._y,i=e._z,a=e._order,o=Math.cos,s=Math.sin,c=o(n/2),l=o(r/2),u=o(i/2),d=s(n/2),f=s(r/2),p=s(i/2);switch(a){case`XYZ`:this._x=d*l*u+c*f*p,this._y=c*f*u-d*l*p,this._z=c*l*p+d*f*u,this._w=c*l*u-d*f*p;break;case`YXZ`:this._x=d*l*u+c*f*p,this._y=c*f*u-d*l*p,this._z=c*l*p-d*f*u,this._w=c*l*u+d*f*p;break;case`ZXY`:this._x=d*l*u-c*f*p,this._y=c*f*u+d*l*p,this._z=c*l*p+d*f*u,this._w=c*l*u-d*f*p;break;case`ZYX`:this._x=d*l*u-c*f*p,this._y=c*f*u+d*l*p,this._z=c*l*p-d*f*u,this._w=c*l*u+d*f*p;break;case`YZX`:this._x=d*l*u+c*f*p,this._y=c*f*u+d*l*p,this._z=c*l*p-d*f*u,this._w=c*l*u-d*f*p;break;case`XZY`:this._x=d*l*u-c*f*p,this._y=c*f*u-d*l*p,this._z=c*l*p+d*f*u,this._w=c*l*u+d*f*p;break;default:console.warn(`THREE.Quaternion: .setFromEuler() encountered an unknown order: `+a)}return t!==!1&&this._onChangeCallback(),this}setFromAxisAngle(e,t){let n=t/2,r=Math.sin(n);return this._x=e.x*r,this._y=e.y*r,this._z=e.z*r,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(e){let t=e.elements,n=t[0],r=t[4],i=t[8],a=t[1],o=t[5],s=t[9],c=t[2],l=t[6],u=t[10],d=n+o+u;if(d>0){let e=.5/Math.sqrt(d+1);this._w=.25/e,this._x=(l-s)*e,this._y=(i-c)*e,this._z=(a-r)*e}else if(n>o&&n>u){let e=2*Math.sqrt(1+n-o-u);this._w=(l-s)/e,this._x=.25*e,this._y=(r+a)/e,this._z=(i+c)/e}else if(o>u){let e=2*Math.sqrt(1+o-n-u);this._w=(i-c)/e,this._x=(r+a)/e,this._y=.25*e,this._z=(s+l)/e}else{let e=2*Math.sqrt(1+u-n-o);this._w=(a-r)/e,this._x=(i+c)/e,this._y=(s+l)/e,this._z=.25*e}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let n=e.dot(t)+1;return n<2**-52?(n=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=n):(this._x=0,this._y=-e.z,this._z=e.y,this._w=n)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=n),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(Hy(this.dot(e),-1,1)))}rotateTowards(e,t){let n=this.angleTo(e);if(n===0)return this;let r=Math.min(1,t/n);return this.slerp(e,r),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x*=e,this._y*=e,this._z*=e,this._w*=e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){let n=e._x,r=e._y,i=e._z,a=e._w,o=t._x,s=t._y,c=t._z,l=t._w;return this._x=n*l+a*o+r*c-i*s,this._y=r*l+a*s+i*o-n*c,this._z=i*l+a*c+n*s-r*o,this._w=a*l-n*o-r*s-i*c,this._onChangeCallback(),this}slerp(e,t){if(t===0)return this;if(t===1)return this.copy(e);let n=this._x,r=this._y,i=this._z,a=this._w,o=a*e._w+n*e._x+r*e._y+i*e._z;if(o<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,o=-o):this.copy(e),o>=1)return this._w=a,this._x=n,this._y=r,this._z=i,this;let s=1-o*o;if(s<=2**-52){let e=1-t;return this._w=e*a+t*this._w,this._x=e*n+t*this._x,this._y=e*r+t*this._y,this._z=e*i+t*this._z,this.normalize(),this._onChangeCallback(),this}let c=Math.sqrt(s),l=Math.atan2(c,o),u=Math.sin((1-t)*l)/c,d=Math.sin(t*l)/c;return this._w=a*u+this._w*d,this._x=n*u+this._x*d,this._y=r*u+this._y*d,this._z=i*u+this._z*d,this._onChangeCallback(),this}slerpQuaternions(e,t,n){return this.copy(e).slerp(t,n)}random(){let e=Math.random(),t=Math.sqrt(1-e),n=Math.sqrt(e),r=2*Math.PI*Math.random(),i=2*Math.PI*Math.random();return this.set(t*Math.cos(r),n*Math.sin(i),n*Math.cos(i),t*Math.sin(r))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}},vb=class e{constructor(t=0,n=0,r=0){e.prototype.isVector3=!0,this.x=t,this.y=n,this.z=r}set(e,t,n){return n===void 0&&(n=this.z),this.x=e,this.y=t,this.z=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw Error(`index is out of range: `+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw Error(`index is out of range: `+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(bb.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(bb.setFromAxisAngle(e,t))}applyMatrix3(e){let t=this.x,n=this.y,r=this.z,i=e.elements;return this.x=i[0]*t+i[3]*n+i[6]*r,this.y=i[1]*t+i[4]*n+i[7]*r,this.z=i[2]*t+i[5]*n+i[8]*r,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){let t=this.x,n=this.y,r=this.z,i=e.elements,a=1/(i[3]*t+i[7]*n+i[11]*r+i[15]);return this.x=(i[0]*t+i[4]*n+i[8]*r+i[12])*a,this.y=(i[1]*t+i[5]*n+i[9]*r+i[13])*a,this.z=(i[2]*t+i[6]*n+i[10]*r+i[14])*a,this}applyQuaternion(e){let t=this.x,n=this.y,r=this.z,i=e.x,a=e.y,o=e.z,s=e.w,c=2*(a*r-o*n),l=2*(o*t-i*r),u=2*(i*n-a*t);return this.x=t+s*c+a*u-o*l,this.y=n+s*l+o*c-i*u,this.z=r+s*u+i*l-a*c,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){let t=this.x,n=this.y,r=this.z,i=e.elements;return this.x=i[0]*t+i[4]*n+i[8]*r,this.y=i[1]*t+i[5]*n+i[9]*r,this.z=i[2]*t+i[6]*n+i[10]*r,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){let n=e.x,r=e.y,i=e.z,a=t.x,o=t.y,s=t.z;return this.x=r*s-i*o,this.y=i*a-n*s,this.z=n*o-r*a,this}projectOnVector(e){let t=e.lengthSq();if(t===0)return this.set(0,0,0);let n=e.dot(this)/t;return this.copy(e).multiplyScalar(n)}projectOnPlane(e){return yb.copy(this).projectOnVector(e),this.sub(yb)}reflect(e){return this.sub(yb.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let n=this.dot(e)/t;return Math.acos(Hy(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,n=this.y-e.y,r=this.z-e.z;return t*t+n*n+r*r}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,n){let r=Math.sin(t)*e;return this.x=r*Math.sin(n),this.y=Math.cos(t)*e,this.z=r*Math.cos(n),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,n){return this.x=e*Math.sin(t),this.y=n,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){let t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){let t=this.setFromMatrixColumn(e,0).length(),n=this.setFromMatrixColumn(e,1).length(),r=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=n,this.z=r,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){let e=(Math.random()-.5)*2,t=Math.random()*Math.PI*2,n=Math.sqrt(1-e**2);return this.x=n*Math.cos(t),this.y=n*Math.sin(t),this.z=e,this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}},yb=new vb,bb=new _b,xb=class{constructor(e=new vb(1/0,1/0,1/0),t=new vb(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,n=e.length;tthis.max.x||e.ythis.max.y||e.zthis.max.z)}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return!(e.max.xthis.max.x||e.max.ythis.max.y||e.max.zthis.max.z)}intersectsSphere(e){return this.clampPoint(e.center,Cb),Cb.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,n;return e.normal.x>0?(t=e.normal.x*this.min.x,n=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,n=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,n+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,n+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,n+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,n+=e.normal.z*this.min.z),t<=-e.constant&&n>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(jb),Mb.subVectors(this.max,jb),Tb.subVectors(e.a,jb),Eb.subVectors(e.b,jb),Db.subVectors(e.c,jb),Ob.subVectors(Eb,Tb),kb.subVectors(Db,Eb),Ab.subVectors(Tb,Db);let t=[0,-Ob.z,Ob.y,0,-kb.z,kb.y,0,-Ab.z,Ab.y,Ob.z,0,-Ob.x,kb.z,0,-kb.x,Ab.z,0,-Ab.x,-Ob.y,Ob.x,0,-kb.y,kb.x,0,-Ab.y,Ab.x,0];return!Fb(t,Tb,Eb,Db,Mb)||(t=[1,0,0,0,1,0,0,0,1],!Fb(t,Tb,Eb,Db,Mb))?!1:(Nb.crossVectors(Ob,kb),t=[Nb.x,Nb.y,Nb.z],Fb(t,Tb,Eb,Db,Mb))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,Cb).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(Cb).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(Sb[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),Sb[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),Sb[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),Sb[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),Sb[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),Sb[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),Sb[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),Sb[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(Sb),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}},Sb=[new vb,new vb,new vb,new vb,new vb,new vb,new vb,new vb],Cb=new vb,wb=new xb,Tb=new vb,Eb=new vb,Db=new vb,Ob=new vb,kb=new vb,Ab=new vb,jb=new vb,Mb=new vb,Nb=new vb,Pb=new vb;function Fb(e,t,n,r,i){for(let a=0,o=e.length-3;a<=o;a+=3){Pb.fromArray(e,a);let o=i.x*Math.abs(Pb.x)+i.y*Math.abs(Pb.y)+i.z*Math.abs(Pb.z),s=t.dot(Pb),c=n.dot(Pb),l=r.dot(Pb);if(Math.max(-Math.max(s,c,l),Math.min(s,c,l))>o)return!1}return!0}var iae=new xb,Ib=new vb,Lb=new vb,Rb=class{constructor(e=new vb,t=-1){this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){let n=this.center;t===void 0?iae.setFromPoints(e).getCenter(n):n.copy(t);let r=0;for(let t=0,i=e.length;tthis.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius*=e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;Ib.subVectors(e,this.center);let t=Ib.lengthSq();if(t>this.radius*this.radius){let e=Math.sqrt(t),n=(e-this.radius)*.5;this.center.addScaledVector(Ib,n/e),this.radius+=n}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(Lb.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(Ib.copy(e.center).add(Lb)),this.expandByPoint(Ib.copy(e.center).sub(Lb))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}},zb=new vb,Bb=new vb,Vb=new vb,Hb=new vb,Ub=new vb,Wb=new vb,Gb=new vb,Kb=class{constructor(e=new vb,t=new vb(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,zb)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);let n=t.dot(this.direction);return n<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){let t=zb.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(zb.copy(this.origin).addScaledVector(this.direction,t),zb.distanceToSquared(e))}distanceSqToSegment(e,t,n,r){Bb.copy(e).add(t).multiplyScalar(.5),Vb.copy(t).sub(e).normalize(),Hb.copy(this.origin).sub(Bb);let i=e.distanceTo(t)*.5,a=-this.direction.dot(Vb),o=Hb.dot(this.direction),s=-Hb.dot(Vb),c=Hb.lengthSq(),l=Math.abs(1-a*a),u,d,f,p;if(l>0)if(u=a*s-o,d=a*o-s,p=i*l,u>=0)if(d>=-p)if(d<=p){let e=1/l;u*=e,d*=e,f=u*(u+a*d+2*o)+d*(a*u+d+2*s)+c}else d=i,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*s)+c;else d=-i,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*s)+c;else d<=-p?(u=Math.max(0,-(-a*i+o)),d=u>0?-i:Math.min(Math.max(-i,-s),i),f=-u*u+d*(d+2*s)+c):d<=p?(u=0,d=Math.min(Math.max(-i,-s),i),f=d*(d+2*s)+c):(u=Math.max(0,-(a*i+o)),d=u>0?i:Math.min(Math.max(-i,-s),i),f=-u*u+d*(d+2*s)+c);else d=a>0?-i:i,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*s)+c;return n&&n.copy(this.origin).addScaledVector(this.direction,u),r&&r.copy(Bb).addScaledVector(Vb,d),f}intersectSphere(e,t){zb.subVectors(e.center,this.origin);let n=zb.dot(this.direction),r=zb.dot(zb)-n*n,i=e.radius*e.radius;if(r>i)return null;let a=Math.sqrt(i-r),o=n-a,s=n+a;return s<0?null:o<0?this.at(s,t):this.at(o,t)}intersectsSphere(e){return this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){let t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;let n=-(this.origin.dot(e.normal)+e.constant)/t;return n>=0?n:null}intersectPlane(e,t){let n=this.distanceToPlane(e);return n===null?null:this.at(n,t)}intersectsPlane(e){let t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let n,r,i,a,o,s,c=1/this.direction.x,l=1/this.direction.y,u=1/this.direction.z,d=this.origin;return c>=0?(n=(e.min.x-d.x)*c,r=(e.max.x-d.x)*c):(n=(e.max.x-d.x)*c,r=(e.min.x-d.x)*c),l>=0?(i=(e.min.y-d.y)*l,a=(e.max.y-d.y)*l):(i=(e.max.y-d.y)*l,a=(e.min.y-d.y)*l),n>a||i>r||((i>n||isNaN(n))&&(n=i),(a=0?(o=(e.min.z-d.z)*u,s=(e.max.z-d.z)*u):(o=(e.max.z-d.z)*u,s=(e.min.z-d.z)*u),n>s||o>r)||((o>n||n!==n)&&(n=o),(s=0?n:r,t)}intersectsBox(e){return this.intersectBox(e,zb)!==null}intersectTriangle(e,t,n,r,i){Ub.subVectors(t,e),Wb.subVectors(n,e),Gb.crossVectors(Ub,Wb);let a=this.direction.dot(Gb),o;if(a>0){if(r)return null;o=1}else if(a<0)o=-1,a=-a;else return null;Hb.subVectors(this.origin,e);let s=o*this.direction.dot(Wb.crossVectors(Hb,Wb));if(s<0)return null;let c=o*this.direction.dot(Ub.cross(Hb));if(c<0||s+c>a)return null;let l=-o*Hb.dot(Gb);return l<0?null:this.at(l/a,i)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}},qb=class e{constructor(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g){e.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g)}set(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){let g=this.elements;return g[0]=e,g[4]=t,g[8]=n,g[12]=r,g[1]=i,g[5]=a,g[9]=o,g[13]=s,g[2]=c,g[6]=l,g[10]=u,g[14]=d,g[3]=f,g[7]=p,g[11]=m,g[15]=h,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new e().fromArray(this.elements)}copy(e){let t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=n[11],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15],this}copyPosition(e){let t=this.elements,n=e.elements;return t[12]=n[12],t[13]=n[13],t[14]=n[14],this}setFromMatrix3(e){let t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,n){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(e,t,n){return this.set(e.x,t.x,n.x,0,e.y,t.y,n.y,0,e.z,t.z,n.z,0,0,0,0,1),this}extractRotation(e){let t=this.elements,n=e.elements,r=1/Jb.setFromMatrixColumn(e,0).length(),i=1/Jb.setFromMatrixColumn(e,1).length(),a=1/Jb.setFromMatrixColumn(e,2).length();return t[0]=n[0]*r,t[1]=n[1]*r,t[2]=n[2]*r,t[3]=0,t[4]=n[4]*i,t[5]=n[5]*i,t[6]=n[6]*i,t[7]=0,t[8]=n[8]*a,t[9]=n[9]*a,t[10]=n[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){let t=this.elements,n=e.x,r=e.y,i=e.z,a=Math.cos(n),o=Math.sin(n),s=Math.cos(r),c=Math.sin(r),l=Math.cos(i),u=Math.sin(i);if(e.order===`XYZ`){let e=a*l,n=a*u,r=o*l,i=o*u;t[0]=s*l,t[4]=-s*u,t[8]=c,t[1]=n+r*c,t[5]=e-i*c,t[9]=-o*s,t[2]=i-e*c,t[6]=r+n*c,t[10]=a*s}else if(e.order===`YXZ`){let e=s*l,n=s*u,r=c*l,i=c*u;t[0]=e+i*o,t[4]=r*o-n,t[8]=a*c,t[1]=a*u,t[5]=a*l,t[9]=-o,t[2]=n*o-r,t[6]=i+e*o,t[10]=a*s}else if(e.order===`ZXY`){let e=s*l,n=s*u,r=c*l,i=c*u;t[0]=e-i*o,t[4]=-a*u,t[8]=r+n*o,t[1]=n+r*o,t[5]=a*l,t[9]=i-e*o,t[2]=-a*c,t[6]=o,t[10]=a*s}else if(e.order===`ZYX`){let e=a*l,n=a*u,r=o*l,i=o*u;t[0]=s*l,t[4]=r*c-n,t[8]=e*c+i,t[1]=s*u,t[5]=i*c+e,t[9]=n*c-r,t[2]=-c,t[6]=o*s,t[10]=a*s}else if(e.order===`YZX`){let e=a*s,n=a*c,r=o*s,i=o*c;t[0]=s*l,t[4]=i-e*u,t[8]=r*u+n,t[1]=u,t[5]=a*l,t[9]=-o*l,t[2]=-c*l,t[6]=n*u+r,t[10]=e-i*u}else if(e.order===`XZY`){let e=a*s,n=a*c,r=o*s,i=o*c;t[0]=s*l,t[4]=-u,t[8]=c*l,t[1]=e*u+i,t[5]=a*l,t[9]=n*u-r,t[2]=r*u-n,t[6]=o*l,t[10]=i*u+e}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(aae,e,oae)}lookAt(e,t,n){let r=this.elements;return Qb.subVectors(e,t),Qb.lengthSq()===0&&(Qb.z=1),Qb.normalize(),Xb.crossVectors(n,Qb),Xb.lengthSq()===0&&(Math.abs(n.z)===1?Qb.x+=1e-4:Qb.z+=1e-4,Qb.normalize(),Xb.crossVectors(n,Qb)),Xb.normalize(),Zb.crossVectors(Qb,Xb),r[0]=Xb.x,r[4]=Zb.x,r[8]=Qb.x,r[1]=Xb.y,r[5]=Zb.y,r[9]=Qb.y,r[2]=Xb.z,r[6]=Zb.z,r[10]=Qb.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let n=e.elements,r=t.elements,i=this.elements,a=n[0],o=n[4],s=n[8],c=n[12],l=n[1],u=n[5],d=n[9],f=n[13],p=n[2],m=n[6],h=n[10],g=n[14],_=n[3],v=n[7],y=n[11],b=n[15],x=r[0],S=r[4],C=r[8],w=r[12],T=r[1],E=r[5],D=r[9],O=r[13],k=r[2],A=r[6],j=r[10],M=r[14],N=r[3],P=r[7],F=r[11],I=r[15];return i[0]=a*x+o*T+s*k+c*N,i[4]=a*S+o*E+s*A+c*P,i[8]=a*C+o*D+s*j+c*F,i[12]=a*w+o*O+s*M+c*I,i[1]=l*x+u*T+d*k+f*N,i[5]=l*S+u*E+d*A+f*P,i[9]=l*C+u*D+d*j+f*F,i[13]=l*w+u*O+d*M+f*I,i[2]=p*x+m*T+h*k+g*N,i[6]=p*S+m*E+h*A+g*P,i[10]=p*C+m*D+h*j+g*F,i[14]=p*w+m*O+h*M+g*I,i[3]=_*x+v*T+y*k+b*N,i[7]=_*S+v*E+y*A+b*P,i[11]=_*C+v*D+y*j+b*F,i[15]=_*w+v*O+y*M+b*I,this}multiplyScalar(e){let t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){let e=this.elements,t=e[0],n=e[4],r=e[8],i=e[12],a=e[1],o=e[5],s=e[9],c=e[13],l=e[2],u=e[6],d=e[10],f=e[14],p=e[3],m=e[7],h=e[11],g=e[15];return p*(+i*s*u-r*c*u-i*o*d+n*c*d+r*o*f-n*s*f)+m*(+t*s*f-t*c*d+i*a*d-r*a*f+r*c*l-i*s*l)+h*(+t*c*u-t*o*f-i*a*u+n*a*f+i*o*l-n*c*l)+g*(-r*o*l-t*s*u+t*o*d+r*a*u-n*a*d+n*s*l)}transpose(){let e=this.elements,t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,n){let r=this.elements;return e.isVector3?(r[12]=e.x,r[13]=e.y,r[14]=e.z):(r[12]=e,r[13]=t,r[14]=n),this}invert(){let e=this.elements,t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],o=e[5],s=e[6],c=e[7],l=e[8],u=e[9],d=e[10],f=e[11],p=e[12],m=e[13],h=e[14],g=e[15],_=u*h*c-m*d*c+m*s*f-o*h*f-u*s*g+o*d*g,v=p*d*c-l*h*c-p*s*f+a*h*f+l*s*g-a*d*g,y=l*m*c-p*u*c+p*o*f-a*m*f-l*o*g+a*u*g,b=p*u*s-l*m*s-p*o*d+a*m*d+l*o*h-a*u*h,x=t*_+n*v+r*y+i*b;if(x===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);let S=1/x;return e[0]=_*S,e[1]=(m*d*i-u*h*i-m*r*f+n*h*f+u*r*g-n*d*g)*S,e[2]=(o*h*i-m*s*i+m*r*c-n*h*c-o*r*g+n*s*g)*S,e[3]=(u*s*i-o*d*i-u*r*c+n*d*c+o*r*f-n*s*f)*S,e[4]=v*S,e[5]=(l*h*i-p*d*i+p*r*f-t*h*f-l*r*g+t*d*g)*S,e[6]=(p*s*i-a*h*i-p*r*c+t*h*c+a*r*g-t*s*g)*S,e[7]=(a*d*i-l*s*i+l*r*c-t*d*c-a*r*f+t*s*f)*S,e[8]=y*S,e[9]=(p*u*i-l*m*i-p*n*f+t*m*f+l*n*g-t*u*g)*S,e[10]=(a*m*i-p*o*i+p*n*c-t*m*c-a*n*g+t*o*g)*S,e[11]=(l*o*i-a*u*i-l*n*c+t*u*c+a*n*f-t*o*f)*S,e[12]=b*S,e[13]=(l*m*r-p*u*r+p*n*d-t*m*d-l*n*h+t*u*h)*S,e[14]=(p*o*r-a*m*r-p*n*s+t*m*s+a*n*h-t*o*h)*S,e[15]=(a*u*r-l*o*r+l*n*s-t*u*s-a*n*d+t*o*d)*S,this}scale(e){let t=this.elements,n=e.x,r=e.y,i=e.z;return t[0]*=n,t[4]*=r,t[8]*=i,t[1]*=n,t[5]*=r,t[9]*=i,t[2]*=n,t[6]*=r,t[10]*=i,t[3]*=n,t[7]*=r,t[11]*=i,this}getMaxScaleOnAxis(){let e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],n=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],r=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,n,r))}makeTranslation(e,t,n){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,n,0,0,0,1),this}makeRotationX(e){let t=Math.cos(e),n=Math.sin(e);return this.set(1,0,0,0,0,t,-n,0,0,n,t,0,0,0,0,1),this}makeRotationY(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,0,n,0,0,1,0,0,-n,0,t,0,0,0,0,1),this}makeRotationZ(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,0,n,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){let n=Math.cos(t),r=Math.sin(t),i=1-n,a=e.x,o=e.y,s=e.z,c=i*a,l=i*o;return this.set(c*a+n,c*o-r*s,c*s+r*o,0,c*o+r*s,l*o+n,l*s-r*a,0,c*s-r*o,l*s+r*a,i*s*s+n,0,0,0,0,1),this}makeScale(e,t,n){return this.set(e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1),this}makeShear(e,t,n,r,i,a){return this.set(1,n,i,0,e,1,a,0,t,r,1,0,0,0,0,1),this}compose(e,t,n){let r=this.elements,i=t._x,a=t._y,o=t._z,s=t._w,c=i+i,l=a+a,u=o+o,d=i*c,f=i*l,p=i*u,m=a*l,h=a*u,g=o*u,_=s*c,v=s*l,y=s*u,b=n.x,x=n.y,S=n.z;return r[0]=(1-(m+g))*b,r[1]=(f+y)*b,r[2]=(p-v)*b,r[3]=0,r[4]=(f-y)*x,r[5]=(1-(d+g))*x,r[6]=(h+_)*x,r[7]=0,r[8]=(p+v)*S,r[9]=(h-_)*S,r[10]=(1-(d+m))*S,r[11]=0,r[12]=e.x,r[13]=e.y,r[14]=e.z,r[15]=1,this}decompose(e,t,n){let r=this.elements,i=Jb.set(r[0],r[1],r[2]).length(),a=Jb.set(r[4],r[5],r[6]).length(),o=Jb.set(r[8],r[9],r[10]).length();this.determinant()<0&&(i=-i),e.x=r[12],e.y=r[13],e.z=r[14],Yb.copy(this);let s=1/i,c=1/a,l=1/o;return Yb.elements[0]*=s,Yb.elements[1]*=s,Yb.elements[2]*=s,Yb.elements[4]*=c,Yb.elements[5]*=c,Yb.elements[6]*=c,Yb.elements[8]*=l,Yb.elements[9]*=l,Yb.elements[10]*=l,t.setFromRotationMatrix(Yb),n.x=i,n.y=a,n.z=o,this}makePerspective(e,t,n,r,i,a,o=Fy){let s=this.elements,c=2*i/(t-e),l=2*i/(n-r),u=(t+e)/(t-e),d=(n+r)/(n-r),f,p;if(o===2e3)f=-(a+i)/(a-i),p=-2*a*i/(a-i);else if(o===2001)f=-a/(a-i),p=-a*i/(a-i);else throw Error(`THREE.Matrix4.makePerspective(): Invalid coordinate system: `+o);return s[0]=c,s[4]=0,s[8]=u,s[12]=0,s[1]=0,s[5]=l,s[9]=d,s[13]=0,s[2]=0,s[6]=0,s[10]=f,s[14]=p,s[3]=0,s[7]=0,s[11]=-1,s[15]=0,this}makeOrthographic(e,t,n,r,i,a,o=Fy){let s=this.elements,c=1/(t-e),l=1/(n-r),u=1/(a-i),d=(t+e)*c,f=(n+r)*l,p,m;if(o===2e3)p=(a+i)*u,m=-2*u;else if(o===2001)p=i*u,m=-1*u;else throw Error(`THREE.Matrix4.makeOrthographic(): Invalid coordinate system: `+o);return s[0]=2*c,s[4]=0,s[8]=0,s[12]=-d,s[1]=0,s[5]=2*l,s[9]=0,s[13]=-f,s[2]=0,s[6]=0,s[10]=m,s[14]=-p,s[3]=0,s[7]=0,s[11]=0,s[15]=1,this}equals(e){let t=this.elements,n=e.elements;for(let e=0;e<16;e++)if(t[e]!==n[e])return!1;return!0}fromArray(e,t=0){for(let n=0;n<16;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){let n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e[t+9]=n[9],e[t+10]=n[10],e[t+11]=n[11],e[t+12]=n[12],e[t+13]=n[13],e[t+14]=n[14],e[t+15]=n[15],e}},Jb=new vb,Yb=new qb,aae=new vb(0,0,0),oae=new vb(1,1,1),Xb=new vb,Zb=new vb,Qb=new vb,$b=new qb,ex=new _b,tx=class e{constructor(t=0,n=0,r=0,i=e.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=n,this._z=r,this._order=i}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,n,r=this._order){return this._x=e,this._y=t,this._z=n,this._order=r,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,n=!0){let r=e.elements,i=r[0],a=r[4],o=r[8],s=r[1],c=r[5],l=r[9],u=r[2],d=r[6],f=r[10];switch(t){case`XYZ`:this._y=Math.asin(Hy(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-l,f),this._z=Math.atan2(-a,i)):(this._x=Math.atan2(d,c),this._z=0);break;case`YXZ`:this._x=Math.asin(-Hy(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(o,f),this._z=Math.atan2(s,c)):(this._y=Math.atan2(-u,i),this._z=0);break;case`ZXY`:this._x=Math.asin(Hy(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,f),this._z=Math.atan2(-a,c)):(this._y=0,this._z=Math.atan2(s,i));break;case`ZYX`:this._y=Math.asin(-Hy(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,f),this._z=Math.atan2(s,i)):(this._x=0,this._z=Math.atan2(-a,c));break;case`YZX`:this._z=Math.asin(Hy(s,-1,1)),Math.abs(s)<.9999999?(this._x=Math.atan2(-l,c),this._y=Math.atan2(-u,i)):(this._x=0,this._y=Math.atan2(o,f));break;case`XZY`:this._z=Math.asin(-Hy(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(d,c),this._y=Math.atan2(o,i)):(this._x=Math.atan2(-l,f),this._y=0);break;default:console.warn(`THREE.Euler: .setFromRotationMatrix() encountered an unknown order: `+t)}return this._order=t,n===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,n){return $b.makeRotationFromQuaternion(e),this.setFromRotationMatrix($b,t,n)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return ex.setFromEuler(this),this.setFromQuaternion(ex,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}};tx.DEFAULT_ORDER=`XYZ`;var nx=class{constructor(){this.mask=1}set(e){this.mask=(1<>>0}enable(e){this.mask|=1<1){for(let e=0;e1){for(let e=0;e0&&(r.userData=this.userData),r.layers=this.layers.mask,r.matrix=this.matrix.toArray(),r.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(r.matrixAutoUpdate=!1),this.isInstancedMesh&&(r.type=`InstancedMesh`,r.count=this.count,r.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(r.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(r.type=`BatchedMesh`,r.perObjectFrustumCulled=this.perObjectFrustumCulled,r.sortObjects=this.sortObjects,r.drawRanges=this._drawRanges,r.reservedRanges=this._reservedRanges,r.visibility=this._visibility,r.active=this._active,r.bounds=this._bounds.map(e=>({boxInitialized:e.boxInitialized,boxMin:e.box.min.toArray(),boxMax:e.box.max.toArray(),sphereInitialized:e.sphereInitialized,sphereRadius:e.sphere.radius,sphereCenter:e.sphere.center.toArray()})),r.maxGeometryCount=this._maxGeometryCount,r.maxVertexCount=this._maxVertexCount,r.maxIndexCount=this._maxIndexCount,r.geometryInitialized=this._geometryInitialized,r.geometryCount=this._geometryCount,r.matricesTexture=this._matricesTexture.toJSON(e),this.boundingSphere!==null&&(r.boundingSphere={center:r.boundingSphere.center.toArray(),radius:r.boundingSphere.radius}),this.boundingBox!==null&&(r.boundingBox={min:r.boundingBox.min.toArray(),max:r.boundingBox.max.toArray()}));function i(t,n){return t[n.uuid]===void 0&&(t[n.uuid]=n.toJSON(e)),n.uuid}if(this.isScene)this.background&&(this.background.isColor?r.background=this.background.toJSON():this.background.isTexture&&(r.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(r.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){r.geometry=i(e.geometries,this.geometry);let t=this.geometry.parameters;if(t!==void 0&&t.shapes!==void 0){let n=t.shapes;if(Array.isArray(n))for(let t=0,r=n.length;t0){r.children=[];for(let t=0;t0){r.animations=[];for(let t=0;t0&&(n.geometries=t),r.length>0&&(n.materials=r),i.length>0&&(n.textures=i),o.length>0&&(n.images=o),s.length>0&&(n.shapes=s),c.length>0&&(n.skeletons=c),l.length>0&&(n.animations=l),u.length>0&&(n.nodes=u)}return n.object=r,n;function a(e){let t=[];for(let n in e){let r=e[n];delete r.metadata,t.push(r)}return t}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let t=0;t0?r.multiplyScalar(1/Math.sqrt(i)):r.set(0,0,0)}static getBarycoord(e,t,n,r,i){fx.subVectors(r,t),px.subVectors(n,t),mx.subVectors(e,t);let a=fx.dot(fx),o=fx.dot(px),s=fx.dot(mx),c=px.dot(px),l=px.dot(mx),u=a*c-o*o;if(u===0)return i.set(-2,-1,-1);let d=1/u,f=(c*s-o*l)*d,p=(a*l-o*s)*d;return i.set(1-f-p,p,f)}static containsPoint(e,t,n,r){return this.getBarycoord(e,t,n,r,hx),hx.x>=0&&hx.y>=0&&hx.x+hx.y<=1}static getUV(e,t,n,r,i,a,o,s){return Sx===!1&&(console.warn(`THREE.Triangle.getUV() has been renamed to THREE.Triangle.getInterpolation().`),Sx=!0),this.getInterpolation(e,t,n,r,i,a,o,s)}static getInterpolation(e,t,n,r,i,a,o,s){return this.getBarycoord(e,t,n,r,hx),s.setScalar(0),s.addScaledVector(i,hx.x),s.addScaledVector(a,hx.y),s.addScaledVector(o,hx.z),s}static isFrontFacing(e,t,n,r){return fx.subVectors(n,t),px.subVectors(e,t),fx.cross(px).dot(r)<0}set(e,t,n){return this.a.copy(e),this.b.copy(t),this.c.copy(n),this}setFromPointsAndIndices(e,t,n,r){return this.a.copy(e[t]),this.b.copy(e[n]),this.c.copy(e[r]),this}setFromAttributeAndIndices(e,t,n,r){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,n),this.c.fromBufferAttribute(e,r),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return fx.subVectors(this.c,this.b),px.subVectors(this.a,this.b),fx.cross(px).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return e.getNormal(this.a,this.b,this.c,t)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,n){return e.getBarycoord(t,this.a,this.b,this.c,n)}getUV(t,n,r,i,a){return Sx===!1&&(console.warn(`THREE.Triangle.getUV() has been renamed to THREE.Triangle.getInterpolation().`),Sx=!0),e.getInterpolation(t,this.a,this.b,this.c,n,r,i,a)}getInterpolation(t,n,r,i,a){return e.getInterpolation(t,this.a,this.b,this.c,n,r,i,a)}containsPoint(t){return e.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return e.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){let n=this.a,r=this.b,i=this.c,a,o;gx.subVectors(r,n),_x.subVectors(i,n),yx.subVectors(e,n);let s=gx.dot(yx),c=_x.dot(yx);if(s<=0&&c<=0)return t.copy(n);bx.subVectors(e,r);let l=gx.dot(bx),u=_x.dot(bx);if(l>=0&&u<=l)return t.copy(r);let d=s*u-l*c;if(d<=0&&s>=0&&l<=0)return a=s/(s-l),t.copy(n).addScaledVector(gx,a);xx.subVectors(e,i);let f=gx.dot(xx),p=_x.dot(xx);if(p>=0&&f<=p)return t.copy(i);let m=f*c-s*p;if(m<=0&&c>=0&&p<=0)return o=c/(c-p),t.copy(n).addScaledVector(_x,o);let h=l*p-f*u;if(h<=0&&u-l>=0&&f-p>=0)return vx.subVectors(i,r),o=(u-l)/(u-l+(f-p)),t.copy(r).addScaledVector(vx,o);let g=1/(h+m+d);return a=m*g,o=d*g,t.copy(n).addScaledVector(gx,a).addScaledVector(_x,o)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}},wx={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},Tx={h:0,s:0,l:0},Ex={h:0,s:0,l:0};function Dx(e,t,n){return n<0&&(n+=1),n>1&&--n,n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*6*(2/3-n):e}var Ox=class{constructor(e,t,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,n)}set(e,t,n){if(t===void 0&&n===void 0){let t=e;t&&t.isColor?this.copy(t):typeof t==`number`?this.setHex(t):typeof t==`string`&&this.setStyle(t)}else this.setRGB(e,t,n);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=Ey){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,ob.toWorkingColorSpace(this,t),this}setRGB(e,t,n,r=ob.workingColorSpace){return this.r=e,this.g=t,this.b=n,ob.toWorkingColorSpace(this,r),this}setHSL(e,t,n,r=ob.workingColorSpace){if(e=Uy(e,1),t=Hy(t,0,1),n=Hy(n,0,1),t===0)this.r=this.g=this.b=n;else{let r=n<=.5?n*(1+t):n+t-n*t,i=2*n-r;this.r=Dx(i,r,e+1/3),this.g=Dx(i,r,e),this.b=Dx(i,r,e-1/3)}return ob.toWorkingColorSpace(this,r),this}setStyle(e,t=Ey){function n(t){t!==void 0&&parseFloat(t)<1&&console.warn(`THREE.Color: Alpha component of `+e+` will be ignored.`)}let r;if(r=/^(\w+)\(([^\)]*)\)/.exec(e)){let i,a=r[1],o=r[2];switch(a){case`rgb`:case`rgba`:if(i=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(i[4]),this.setRGB(Math.min(255,parseInt(i[1],10))/255,Math.min(255,parseInt(i[2],10))/255,Math.min(255,parseInt(i[3],10))/255,t);if(i=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(i[4]),this.setRGB(Math.min(100,parseInt(i[1],10))/100,Math.min(100,parseInt(i[2],10))/100,Math.min(100,parseInt(i[3],10))/100,t);break;case`hsl`:case`hsla`:if(i=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(i[4]),this.setHSL(parseFloat(i[1])/360,parseFloat(i[2])/100,parseFloat(i[3])/100,t);break;default:console.warn(`THREE.Color: Unknown color model `+e)}}else if(r=/^\#([A-Fa-f\d]+)$/.exec(e)){let n=r[1],i=n.length;if(i===3)return this.setRGB(parseInt(n.charAt(0),16)/15,parseInt(n.charAt(1),16)/15,parseInt(n.charAt(2),16)/15,t);if(i===6)return this.setHex(parseInt(n,16),t);console.warn(`THREE.Color: Invalid hex color `+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=Ey){let n=wx[e.toLowerCase()];return n===void 0?console.warn(`THREE.Color: Unknown color `+e):this.setHex(n,t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=sb(e.r),this.g=sb(e.g),this.b=sb(e.b),this}copyLinearToSRGB(e){return this.r=cb(e.r),this.g=cb(e.g),this.b=cb(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=Ey){return ob.fromWorkingColorSpace(kx.copy(this),e),Math.round(Hy(kx.r*255,0,255))*65536+Math.round(Hy(kx.g*255,0,255))*256+Math.round(Hy(kx.b*255,0,255))}getHexString(e=Ey){return(`000000`+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=ob.workingColorSpace){ob.fromWorkingColorSpace(kx.copy(this),t);let n=kx.r,r=kx.g,i=kx.b,a=Math.max(n,r,i),o=Math.min(n,r,i),s,c,l=(o+a)/2;if(o===a)s=0,c=0;else{let e=a-o;switch(c=l<=.5?e/(a+o):e/(2-a-o),a){case n:s=(r-i)/e+(r0!=e>0&&this.version++,this._alphaTest=e}onBuild(){}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(let t in e){let n=e[t];if(n===void 0){console.warn(`THREE.Material: parameter '${t}' has value of undefined.`);continue}let r=this[t];if(r===void 0){console.warn(`THREE.Material: '${t}' is not a property of THREE.${this.type}.`);continue}r&&r.isColor?r.set(n):r&&r.isVector3&&n&&n.isVector3?r.copy(n):this[t]=n}}toJSON(e){let t=e===void 0||typeof e==`string`;t&&(e={textures:{},images:{}});let n={metadata:{version:4.6,type:`Material`,generator:`Material.toJSON`}};n.uuid=this.uuid,n.type=this.type,this.name!==``&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),this.roughness!==void 0&&(n.roughness=this.roughness),this.metalness!==void 0&&(n.metalness=this.metalness),this.sheen!==void 0&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),this.emissiveIntensity&&this.emissiveIntensity!==1&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(n.shininess=this.shininess),this.clearcoat!==void 0&&(n.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.iridescence!==void 0&&(n.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(n.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(n.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(e).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(e).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(e).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(e).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(e).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(n.combine=this.combine)),this.envMapIntensity!==void 0&&(n.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(n.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(n.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(n.size=this.size),this.shadowSide!==null&&(n.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(n.sizeAttenuation=this.sizeAttenuation),this.blending!==1&&(n.blending=this.blending),this.side!==0&&(n.side=this.side),this.vertexColors===!0&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),this.transparent===!0&&(n.transparent=!0),this.blendSrc!==204&&(n.blendSrc=this.blendSrc),this.blendDst!==205&&(n.blendDst=this.blendDst),this.blendEquation!==100&&(n.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(n.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(n.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(n.blendAlpha=this.blendAlpha),this.depthFunc!==3&&(n.depthFunc=this.depthFunc),this.depthTest===!1&&(n.depthTest=this.depthTest),this.depthWrite===!1&&(n.depthWrite=this.depthWrite),this.colorWrite===!1&&(n.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(n.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==519&&(n.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(n.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==7680&&(n.stencilFail=this.stencilFail),this.stencilZFail!==7680&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==7680&&(n.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(n.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(n.rotation=this.rotation),this.polygonOffset===!0&&(n.polygonOffset=!0),this.polygonOffsetFactor!==0&&(n.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(n.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(n.linewidth=this.linewidth),this.dashSize!==void 0&&(n.dashSize=this.dashSize),this.gapSize!==void 0&&(n.gapSize=this.gapSize),this.scale!==void 0&&(n.scale=this.scale),this.dithering===!0&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),this.alphaHash===!0&&(n.alphaHash=!0),this.alphaToCoverage===!0&&(n.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(n.premultipliedAlpha=!0),this.forceSinglePass===!0&&(n.forceSinglePass=!0),this.wireframe===!0&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!==`round`&&(n.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!==`round`&&(n.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(n.flatShading=!0),this.visible===!1&&(n.visible=!1),this.toneMapped===!1&&(n.toneMapped=!1),this.fog===!1&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData);function r(e){let t=[];for(let n in e){let r=e[n];delete r.metadata,t.push(r)}return t}if(t){let t=r(e.textures),i=r(e.images);t.length>0&&(n.textures=t),i.length>0&&(n.images=i)}return n}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;let t=e.clippingPlanes,n=null;if(t!==null){let e=t.length;n=Array(e);for(let r=0;r!==e;++r)n[r]=t[r].clone()}return this.clippingPlanes=n,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:`dispose`})}set needsUpdate(e){e===!0&&this.version++}},jx=class extends Ax{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type=`MeshBasicMaterial`,this.color=new Ox(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap=`round`,this.wireframeLinejoin=`round`,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}},Mx=new vb,Nx=new Xy,Px=class{constructor(e,t,n=!1){if(Array.isArray(e))throw TypeError(`THREE.BufferAttribute: array should be a Typed Array.`);this.isBufferAttribute=!0,this.name=``,this.array=e,this.itemSize=t,this.count=e===void 0?0:e.length/t,this.normalized=n,this.usage=Py,this._updateRange={offset:0,count:-1},this.updateRanges=[],this.gpuType=py,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}get updateRange(){return console.warn(`THREE.BufferAttribute: "updateRange" is deprecated and removed in r169. Use "addUpdateRange()" instead.`),this._updateRange}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,n){e*=this.itemSize,n*=t.itemSize;for(let r=0,i=this.itemSize;r0&&(e.userData=this.userData),this.parameters!==void 0){let t=this.parameters;for(let n in t)t[n]!==void 0&&(e[n]=t[n]);return e}e.data={attributes:{}};let t=this.index;t!==null&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});let n=this.attributes;for(let t in n){let r=n[t];e.data.attributes[t]=r.toJSON(e.data)}let r={},i=!1;for(let t in this.morphAttributes){let n=this.morphAttributes[t],a=[];for(let t=0,r=n.length;t0&&(r[t]=a,i=!0)}i&&(e.data.morphAttributes=r,e.data.morphTargetsRelative=this.morphTargetsRelative);let a=this.groups;a.length>0&&(e.data.groups=JSON.parse(JSON.stringify(a)));let o=this.boundingSphere;return o!==null&&(e.data.boundingSphere={center:o.center.toArray(),radius:o.radius}),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;let t={};this.name=e.name;let n=e.index;n!==null&&this.setIndex(n.clone(t));let r=e.attributes;for(let e in r){let n=r[e];this.setAttribute(e,n.clone(t))}let i=e.morphAttributes;for(let e in i){let n=[],r=i[e];for(let e=0,i=r.length;e0){let n=e[t[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,t=n.length;e(e.far-e.near)**2))&&(Gx.copy(i).invert(),Kx.copy(e.ray).applyMatrix4(Gx),!(n.boundingBox!==null&&Kx.intersectsBox(n.boundingBox)===!1)&&this._computeIntersections(e,t,Kx)))}_computeIntersections(e,t,n){let r,i=this.geometry,a=this.material,o=i.index,s=i.attributes.position,c=i.attributes.uv,l=i.attributes.uv1,u=i.attributes.normal,d=i.groups,f=i.drawRange;if(o!==null)if(Array.isArray(a))for(let i=0,s=d.length;in.far?null:{distance:l,point:sS.clone(),object:e}}function lS(e,t,n,r,i,a,o,s,c,l){e.getVertexPosition(s,Yx),e.getVertexPosition(c,Xx),e.getVertexPosition(l,Zx);let u=mae(e,t,n,r,Yx,Xx,Zx,oS);if(u){i&&(eS.fromBufferAttribute(i,s),tS.fromBufferAttribute(i,c),nS.fromBufferAttribute(i,l),u.uv=Cx.getInterpolation(oS,Yx,Xx,Zx,eS,tS,nS,new Xy)),a&&(eS.fromBufferAttribute(a,s),tS.fromBufferAttribute(a,c),nS.fromBufferAttribute(a,l),u.uv1=Cx.getInterpolation(oS,Yx,Xx,Zx,eS,tS,nS,new Xy),u.uv2=u.uv1),o&&(rS.fromBufferAttribute(o,s),iS.fromBufferAttribute(o,c),aS.fromBufferAttribute(o,l),u.normal=Cx.getInterpolation(oS,Yx,Xx,Zx,rS,iS,aS,new vb),u.normal.dot(r.direction)>0&&u.normal.multiplyScalar(-1));let e={a:s,b:c,c:l,normal:new vb,materialIndex:0};Cx.getNormal(Yx,Xx,Zx,e.normal),u.face=e}return u}var uS=class e extends Wx{constructor(e=1,t=1,n=1,r=1,i=1,a=1){super(),this.type=`BoxGeometry`,this.parameters={width:e,height:t,depth:n,widthSegments:r,heightSegments:i,depthSegments:a};let o=this;r=Math.floor(r),i=Math.floor(i),a=Math.floor(a);let s=[],c=[],l=[],u=[],d=0,f=0;p(`z`,`y`,`x`,-1,-1,n,t,e,a,i,0),p(`z`,`y`,`x`,1,-1,n,t,-e,a,i,1),p(`x`,`z`,`y`,1,1,e,n,t,r,a,2),p(`x`,`z`,`y`,1,-1,e,n,-t,r,a,3),p(`x`,`y`,`z`,1,-1,e,t,n,r,i,4),p(`x`,`y`,`z`,-1,-1,e,t,-n,r,i,5),this.setIndex(s),this.setAttribute(`position`,new Lx(c,3)),this.setAttribute(`normal`,new Lx(l,3)),this.setAttribute(`uv`,new Lx(u,2));function p(e,t,n,r,i,a,p,m,h,g,_){let v=a/h,y=p/g,b=a/2,x=p/2,S=m/2,C=h+1,w=g+1,T=0,E=0,D=new vb;for(let a=0;a0?1:-1,l.push(D.x,D.y,D.z),u.push(s/h),u.push(1-a/g),T+=1}for(let e=0;ee.id>=2),i=Array.from({length:6},(e,t)=>r.find(e=>e.id===16+t)??{id:-(t+1),nozzle_type:``,nozzle_diameter:``,wear:null,stat:null,max_temp:0,serial_number:``,filament_color:``,filament_id:``,filament_type:``});return(0,K.jsxs)(`div`,{className:`text-center px-2.5 py-1.5 bg-bambu-dark rounded-lg flex-[2_1_190px] flex flex-col justify-center`,children:[(0,K.jsx)(`p`,{className:`text-[9px] text-bambu-gray mb-1`,children:n(`printers.nozzleRack`)}),(0,K.jsx)(`div`,{className:`flex gap-[3px] justify-center`,children:i.map((e,n)=>{let r=!e.nozzle_diameter&&!e.nozzle_type,i=r?null:Gd(e.filament_color),a=i?Kd(e.filament_color):!1;return(0,K.jsx)(gq,{slot:e,index:n,filamentName:e.filament_id?t?.[e.filament_id]?.name:void 0,children:(0,K.jsx)(`div`,{className:`w-7 h-7 rounded flex items-center justify-center cursor-default transition-colors border-b-2 ${r?`bg-bambu-dark-tertiary/20 border-bambu-dark-tertiary/20`:`bg-bambu-dark-tertiary/40 border-bambu-dark-tertiary/40`}`,style:i?{backgroundColor:i}:void 0,children:(0,K.jsx)(`span`,{className:`text-[10px] font-semibold ${r?`text-bambu-gray/30`:a?`text-black/80`:`text-white`}`,style:i&&!a?{textShadow:`0 1px 3px rgba(0,0,0,0.9)`}:void 0,children:r?`—`:e.nozzle_diameter||`?`})})},e.id>=0?e.id:`empty-${n}`)})})]})}function uEe({className:e}){return(0,K.jsx)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,K.jsx)(`path`,{d:`M17.8131 0.00538C18.4463 -0.15091 20.3648 3.14642 20.8264 3.84781C25.4187 10.816 35.3089 26.9368 35.9383 34.8694C37.4182 53.5822 11.882 61.3357 2.53721 45.3789C-1.73471 38.0791 0.016 32.2049 3.178 25.0232C6.99221 16.3662 12.6411 7.90372 17.8131 0.00538ZM18.3738 7.24807L17.5881 7.48441C14.4452 12.9431 10.917 18.2341 8.19369 23.9368C4.6808 31.29 1.18317 38.5479 7.69403 45.5657C17.3058 55.9228 34.9847 46.8808 31.4604 32.8681C29.2558 24.0969 22.4207 15.2913 18.3776 7.24807H18.3738Z`,fill:`#C3C2C1`})})}function dEe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 35 53`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`path`,{d:`M17.3165 0.0038C17.932 -0.14959 19.7971 3.08645 20.2458 3.77481C24.7103 10.6135 34.3251 26.4346 34.937 34.2198C36.3757 52.5848 11.5505 60.1942 2.46584 44.534C-1.68714 37.3735 0.0148 31.6085 3.08879 24.5603C6.79681 16.0605 12.2884 7.75907 17.3165 0.0038ZM17.8615 7.11561L17.0977 7.34755C14.0423 12.7048 10.6124 17.8974 7.96483 23.4941C4.54975 30.7107 1.14949 37.8337 7.47908 44.721C16.8233 54.8856 34.01 46.0117 30.5838 32.2595C28.4405 23.6512 21.7957 15.0093 17.8652 7.11561H17.8615Z`,fill:`#C3C2C1`}),(0,K.jsx)(`path`,{d:`M5.03547 30.112C9.64453 30.4936 11.632 35.7985 16.4154 35.791C19.6339 35.7873 20.2161 33.2283 22.3853 31.6197C31.6776 24.7286 33.5835 37.4894 27.9881 44.4254C18.1878 56.5653 -1.16063 44.6013 5.03917 30.1158L5.03547 30.112Z`,fill:`#1F8FEB`})]})}function fEe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`path`,{d:`M17.9625 4.48059L4.77216 26.3154L2.08228 40.2175L10.0224 50.8414H23.1594L33.3246 42.1693V30.2455L17.9625 4.48059Z`,fill:`#1F8FEB`}),(0,K.jsx)(`path`,{d:`M17.7948 0.00538C18.4273 -0.15091 20.3438 3.14642 20.8048 3.84781C25.3921 10.816 35.2715 26.9368 35.9001 34.8694C37.3784 53.5822 11.8702 61.3357 2.53562 45.3789C-1.73163 38.0829 0.0134 32.2087 3.1757 25.027C6.98574 16.3662 12.6284 7.90372 17.7948 0.00538ZM18.3549 7.24807L17.57 7.48441C14.4306 12.9431 10.9063 18.2341 8.1859 23.9368C4.67686 31.29 1.18305 38.5479 7.68679 45.5657C17.2881 55.9228 34.9476 46.8808 31.4271 32.8681C29.2249 24.0969 22.3974 15.2913 18.3587 7.24807H18.3549Z`,fill:`#C3C2C1`})]})}function pEe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`}),(0,K.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2.5`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function mEe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`rect`,{x:`4.5`,y:`8`,width:`3`,height:`4.5`,fill:`#d4a017`,rx:`0.5`}),(0,K.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#d4a017`}),(0,K.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function hEe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`rect`,{x:`4.5`,y:`3`,width:`3`,height:`9.5`,fill:`#c62828`,rx:`0.5`}),(0,K.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#c62828`}),(0,K.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function gEe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,K.jsx)(`rect`,{x:`9.2`,y:`3.4`,width:`5.6`,height:`8.1`}),(0,K.jsx)(`rect`,{x:`6`,y:`11.5`,width:`12.1`,height:`3.7`}),(0,K.jsx)(`path`,{d:`M 7.3 15.2 L 12.1 19.6 L 16.7 15.2`})]})}function _q({className:e,color:t,isHeating:n}){let r={"text-orange-400":`#fb923c`,"text-blue-400":`#60a5fa`,"text-green-400":`#4ade80`}[t]||`#888`,i=n?{filter:`drop-shadow(0 0 4px ${r}) drop-shadow(0 0 8px ${r})`}:{};return n?(0,K.jsxs)(`svg`,{className:e,style:i,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`rect`,{x:`4.5`,y:`3`,width:`3`,height:`9.5`,fill:r,rx:`0.5`}),(0,K.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:r}),(0,K.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:r,strokeWidth:`1`,fill:`none`})]}):(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:r,strokeWidth:`1`,fill:`none`}),(0,K.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2.5`,stroke:r,strokeWidth:`1`,fill:`none`})]})}function _Ee({state:e,canToggle:t,pending:n,onToggle:r}){let{t:i}=G(),a=e!==null,o=t&&a&&!n,s=`flex items-center justify-center w-[18px] h-[18px] rounded text-[10px] transition-colors `,c;return e===!0?(s+=o?`bg-blue-500/20 text-blue-400 hover:bg-blue-500/30 cursor-pointer`:`bg-blue-500/20 text-blue-400 cursor-default`,c=i(`printers.amsBackup.titleOn`)):e===!1?(s+=o?`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark/80 cursor-pointer`:`bg-bambu-dark text-bambu-gray cursor-default`,c=i(`printers.amsBackup.titleOff`)):(s+=`bg-bambu-dark text-bambu-gray/50 cursor-default`,c=i(`printers.amsBackup.titleUnknown`)),(0,K.jsx)(`button`,{type:`button`,disabled:!o,onClick:()=>o&&r(!e),className:s,title:c,"aria-label":c,children:a?(0,K.jsx)(wl,{className:`w-3 h-3`}):(0,K.jsx)(`span`,{children:`?`})})}function vq({humidity:e,goodThreshold:t=40,fairThreshold:n=60,onClick:r,compact:i}){let a=typeof e==`string`?parseInt(e,10):e,o=typeof t==`number`?t:40,s=typeof n==`number`?n:60,c,l;isNaN(a)?(c=`#C3C2C1`,l=`Unknown`):a<=o?(c=`#22a352`,l=`Good`):a<=s?(c=`#d4a017`,l=`Fair`):(c=`#c62828`,l=`Bad`);let u;return u=isNaN(a)||a<=o?uEe:a<=s?dEe:fEe,(0,K.jsxs)(`button`,{type:`button`,onClick:r,className:`flex items-center gap-1 ${r?`cursor-pointer hover:opacity-80 transition-opacity`:``}`,title:`Humidity: ${a}% - ${l}${r?` (click for history)`:``}`,children:[(0,K.jsx)(u,{className:i?`w-2.5 h-3`:`w-3 h-4`}),(0,K.jsxs)(`span`,{className:`font-medium tabular-nums ${i?`text-[10px]`:`text-xs`}`,style:{color:c},children:[a,`%`]})]})}function yq({temp:e,goodThreshold:t=28,fairThreshold:n=35,onClick:r,compact:i}){let a=typeof t==`number`?t:28,o=typeof n==`number`?n:35,s,c,l;return e<=a?(s=`#22a352`,c=`Good`,l=pEe):e<=o?(s=`#d4a017`,c=`Fair`,l=mEe):(s=`#c62828`,c=`Bad`,l=hEe),(0,K.jsxs)(`button`,{type:`button`,onClick:r,className:`flex items-center gap-1 ${r?`cursor-pointer hover:opacity-80 transition-opacity`:``}`,title:`Temperature: ${e}°C - ${c}${r?` (click for history)`:``}`,children:[(0,K.jsx)(l,{className:i?`w-2.5 h-3`:`w-3 h-4`}),(0,K.jsxs)(`span`,{className:`tabular-nums text-right ${i?`text-[10px] w-8`:`w-12`}`,style:{color:s},children:[e,`°C`]})]})}function bq(e,t){let n=typeof e==`string`?parseInt(e,10):e,r=isNaN(n)?0:n,i=t===1,a=r>=128?r-128:r,o=String.fromCharCode(65+a);return i?`HT-${o}`:`AMS-${o}`}function xq(e){return e?.tray_type?null:e?.state===9||e?.state===10?`physical`:`reset`}function vEe({url:e,printName:t,className:n=`w-20 h-20`,radiusClass:r=`rounded-lg`}){let{t:i}=G(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),d=(0,y.useMemo)(()=>e?Ku(`${e}${e.includes(`?`)?`&`:`?`}v=${encodeURIComponent(t||Date.now().toString())}`):null,[e,t]);return(0,y.useEffect)(()=>{o(!1),c(!1)},[d]),(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`${n} flex-shrink-0 ${r} overflow-hidden bg-bambu-dark-tertiary flex items-center justify-center ${d&&a?`cursor-pointer`:``}`,onClick:()=>d&&a&&u(!0),children:d&&!s?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`img`,{src:d,alt:i(`printers.printPreview`),className:`w-full h-full object-cover ${a?`block`:`hidden`}`,onLoad:()=>o(!0),onError:()=>c(!0)}),!a&&(0,K.jsx)(Bo,{className:`w-8 h-8 text-bambu-gray`})]}):(0,K.jsx)(Bo,{className:`w-8 h-8 text-bambu-gray`})}),l&&d&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-8`,onClick:()=>u(!1),children:(0,K.jsxs)(`div`,{className:`relative max-w-2xl max-h-full`,children:[(0,K.jsx)(`img`,{src:d,alt:i(`printers.printPreview`),className:`max-w-full max-h-[80vh] rounded-lg shadow-2xl`}),t&&(0,K.jsx)(`p`,{className:`text-white text-center mt-4 text-lg`,children:t})]})})]})}function yEe({printers:e}){let{t}=G(),n=Qa(),[r,i]=(0,y.useState)(0);(0,y.useEffect)(()=>{let e=!1,t=n.getQueryCache().subscribe(()=>{e||(e=!0,requestAnimationFrame(()=>{i(e=>e+1),e=!1}))});return()=>t()},[n]);let{counts:a,nextFinish:o}=(0,y.useMemo)(()=>{let t=0,r=0,i=0,a=0,o=0,s=0,c=0,l=null,u=null,d=0;return e?.forEach(e=>{let f=n.getQueryData([`printerStatus`,e.id]);if(f===void 0)s++;else if(!f.connected)o++;else{let n=f.hms_errors?dp(f.hms_errors).length:0;switch(n>0&&c++,f.state){case`RUNNING`:t++,f.remaining_time!=null&&f.remaining_time>0&&(u===null||f.remaining_time0||i++;break;default:a++;break}}}),{counts:{printing:t,paused:r,finished:i,idle:a,offline:o,loading:s,error:c,total:e?.length||0},nextFinish:l&&u?{name:l,remainingMin:u,progress:d}:null}},[e,n,r]);return e?.length?(0,K.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-4 gap-y-2 text-bambu-gray`,children:[[{count:a.printing,dot:`bg-bambu-green animate-pulse`,label:t(`printers.status.printing`).toLowerCase()},{count:a.paused,dot:`bg-status-warning`,label:t(`printers.status.paused`,`paused`).toLowerCase()},{count:a.finished,dot:`bg-blue-400`,label:t(`printers.status.finished`,`finished`).toLowerCase()},{count:a.idle,dot:a.idle>0?`bg-bambu-green`:`bg-gray-500`,label:t(`printers.status.available`).toLowerCase()},{count:a.error,dot:`bg-status-error`,label:t(`printers.status.problem`).toLowerCase()},{count:a.offline,dot:`bg-gray-400`,label:t(`printers.status.offline`).toLowerCase()}].map(({count:e,dot:t,label:n})=>e>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full ${t}`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`text-white font-medium`,children:e}),` `,n]})]},n)),o&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`w-px h-4 bg-bambu-dark-tertiary`}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-1 sm:flex-row sm:items-center sm:gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-green font-medium`,children:[t(`printers.nextAvailable`),`:`]}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:o.name})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 w-full sm:w-auto`,children:[(0,K.jsx)(`div`,{className:`w-full sm:w-16 bg-bambu-dark-tertiary rounded-full h-1.5`,children:(0,K.jsx)(`div`,{className:`bg-bambu-green h-1.5 rounded-full transition-all`,style:{width:`${o.progress}%`}})}),(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[Math.round(o.progress),`%`]}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,yf(o.remainingMin*60),`)`]})]})]})]})]}):null}function Sq({value:e,options:t,onChange:n,fullWidth:r=!1}){let[i,a]=(0,y.useState)(!1),o=t.find(t=>t.value===e)??t[0];return(0,K.jsxs)(`div`,{className:`relative ${r?`w-full min-w-0`:``}`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`h-8 px-2 rounded-lg border bg-bambu-dark border-bambu-dark-tertiary text-white text-sm font-medium transition-colors hover:bg-bambu-dark-tertiary focus:outline-none focus:border-bambu-green flex items-center justify-between gap-2 ${r?`w-full`:`min-w-28`}`,children:[(0,K.jsx)(`span`,{className:`truncate`,children:o?.label}),(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?`rotate-180`:``}`})]}),i&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>a(!1)}),(0,K.jsx)(`div`,{className:`absolute left-0 top-full z-20 mt-1 min-w-full rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary py-1 shadow-xl`,children:t.map(t=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>{n(t.value),a(!1)},className:`w-full px-3 py-2 text-left text-sm transition-colors hover:bg-bambu-dark-tertiary ${t.value===e?`text-bambu-green`:`text-white`}`,children:t.label},t.value))})]})]})}function Cq({label:e,icon:t,children:n}){let[r,i]=(0,y.useState)(!1);return(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`h-8 w-8 rounded-lg border bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center justify-center`,"aria-label":e,title:e,children:t}),r&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>i(!1)}),(0,K.jsx)(`div`,{className:`absolute right-0 top-full z-20 mt-1 min-w-40 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary p-2 shadow-xl`,children:n})]})]})}function wq({title:e,options:t=[],unit:n,customMin:r,customMax:i,customStep:a=1,widthClass:o=`w-[240px]`,popoverWidth:s=240,popoverHeight:c=280,isPending:l,onClose:u,onSubmit:d,children:f}){let p=(0,y.useRef)(null),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(``);(0,y.useLayoutEffect)(()=>{let e=p.current?.parentElement;if(!e)return;let t=()=>{h(ep({triggerRect:e.getBoundingClientRect(),popoverWidth:s,estimatedHeight:c,horizontalAlign:`center`}))};return t(),window.addEventListener(`resize`,t),window.addEventListener(`scroll`,t,!0),()=>{window.removeEventListener(`resize`,t),window.removeEventListener(`scroll`,t,!0)}},[s,c]);let v=n!==void 0,b=()=>{let e=Number(g);Number.isFinite(e)&&d?.(Math.round(Math.min(i??e,Math.max(r??e,e))))};return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{ref:p,className:`hidden`,"aria-hidden":`true`}),(0,Zf.createPortal)((0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-[1000]`,onClick:u}),(0,K.jsxs)(`div`,{className:`fixed z-[1001] flex ${o} flex-col overflow-hidden rounded-xl border border-bambu-dark-tertiary bg-bambu-dark-secondary shadow-2xl`,style:{top:m?.top??-9999,left:m?.left??-9999,visibility:m?`visible`:`hidden`},onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`shrink-0 px-3 py-2.5 text-center text-sm font-medium text-white`,children:e}),(0,K.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),t.length>0&&(0,K.jsx)(`div`,{className:`px-3 py-2.5`,children:(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:t.map(e=>(0,K.jsx)(`button`,{type:`button`,disabled:l,onClick:()=>d?.(e.value),className:`h-8 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 disabled:cursor-not-allowed disabled:opacity-50`,children:e.label},`${e.label}-${e.value}`))})}),f,v&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),(0,K.jsxs)(`form`,{className:`flex gap-1.5 px-3 pt-2.5 pb-3`,onSubmit:e=>{e.preventDefault(),b()},children:[(0,K.jsx)(`input`,{type:`number`,min:r,max:i,step:a,value:g,onChange:e=>_(e.target.value),placeholder:`Custom`,className:`h-8 min-w-0 flex-1 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark px-2 text-xs text-white placeholder:text-bambu-gray/60 focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`button`,{type:`submit`,disabled:l||g.trim()===``,className:`h-8 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 disabled:cursor-not-allowed disabled:opacity-50`,children:`Set`})]})]})]})]}),document.body)]})}var bEe=sp(tp,`C`);function Tq({label:e,current:t,target:n,isActive:r,isPending:i,onSubmit:a,options:o=bEe}){let[s,c]=(0,y.useState)(``),l=()=>{let e=Number(s);Number.isFinite(e)&&a(Math.min(320,Math.max(0,Math.round(e))))};return(0,K.jsxs)(`div`,{className:`rounded-lg border p-2 ${r?`border-amber-400/60 bg-amber-400/10`:`border-bambu-dark-tertiary bg-bambu-dark`}`,children:[(0,K.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium ${r?`text-amber-300`:`text-white`}`,children:e}),(0,K.jsxs)(`span`,{className:`text-[10px] text-bambu-gray`,children:[Math.round(t??0),`°C`,n===void 0?``:` / ${Math.round(n)}°`]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-1`,children:o.map(t=>(0,K.jsx)(`button`,{type:`button`,disabled:i,onClick:()=>a(t.value),className:`h-7 rounded-md border border-bambu-dark-tertiary bg-bambu-dark-secondary px-1.5 text-[11px] font-medium text-white transition-colors hover:bg-bambu-dark-tertiary disabled:cursor-not-allowed disabled:opacity-50`,children:t.label},`${e}-${t.value}`))}),(0,K.jsxs)(`form`,{className:`mt-1.5 flex gap-1`,onSubmit:e=>{e.preventDefault(),l()},children:[(0,K.jsx)(`input`,{type:`number`,min:0,max:320,step:1,value:s,onChange:e=>c(e.target.value),placeholder:`Custom`,className:`h-7 min-w-0 flex-1 rounded-md border border-bambu-dark-tertiary bg-bambu-dark-secondary px-1.5 text-[11px] text-white placeholder:text-bambu-gray/60 focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`button`,{type:`submit`,disabled:i||s.trim()===``,className:`h-7 rounded-md border border-bambu-dark-tertiary bg-bambu-dark-secondary px-2 text-[11px] font-medium text-white transition-colors hover:bg-bambu-dark-tertiary disabled:cursor-not-allowed disabled:opacity-50`,children:`Set`})]})]})}var xEe=[`error`,`printing`,`paused`,`finished`,`idle`,`offline`],Eq={error:{labelKey:`printers.status.problem`,dot:`bg-status-error`},printing:{labelKey:`printers.status.printing`,dot:`bg-bambu-green animate-pulse`},paused:{labelKey:`printers.status.paused`,dot:`bg-status-warning`},finished:{labelKey:`printers.status.finished`,dot:`bg-blue-400`},idle:{labelKey:`printers.status.idle`,dot:`bg-bambu-green`},offline:{labelKey:`printers.status.offline`,dot:`bg-gray-400`}};function Dq(e){if(!e?.connected)return`offline`;if((e.hms_errors?dp(e.hms_errors):[]).length>0)return`error`;switch(e.state){case`RUNNING`:return`printing`;case`PAUSE`:return`paused`;case`FINISH`:return`finished`;case`FAILED`:return`finished`;default:return`idle`}}function SEe(e,t){if(t)return t;switch(e){case`RUNNING`:return`Printing`;case`PAUSE`:return`Paused`;case`FINISH`:return`Finished`;case`FAILED`:return`Failed`;case`IDLE`:return`Idle`;default:return e?e.charAt(0)+e.slice(1).toLowerCase():`Idle`}}function Oq(e){return e?{O1D:`H2D`,O1E:`H2D Pro`,O2D:`H2D Pro`,O1C:`H2C`,O1C2:`H2C`,O1S:`H2S`,"BL-P001":`X1C`,"BL-P002":`X1`,"BL-P003":`X1E`,N6:`X2D`,N9:`A2L`,C11:`P1S`,C12:`P1P`,C13:`P2S`,N2S:`A1`,N1:`A1 Mini`,X1C:`X1C`,X1:`X1`,X1E:`X1E`,X2D:`X2D`,P1S:`P1S`,P1P:`P1P`,P2S:`P2S`,A1:`A1`,"A1 Mini":`A1 Mini`,A2L:`A2L`,H2D:`H2D`,"H2D Pro":`H2D Pro`,H2C:`H2C`,H2S:`H2S`}[e]||e:``}function kq({ams:e,printerId:t,label:n,amsLabels:r,canEdit:i,onSaved:a,children:o}){let{t:s}=G(),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(`top`),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(!1),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(!1),x=(0,y.useRef)(null),S=(0,y.useRef)(null),C=(0,y.useRef)(null);(0,y.useEffect)(()=>{c&&(p(r?.[e.id]??``),_(null),requestAnimationFrame(()=>{if(x.current&&S.current){let e=x.current.getBoundingClientRect(),t=e.top-56,n=window.innerHeight-e.bottom;d(tt?`bottom`:`top`)}}))},[c,r,e.id]);let w=()=>{C.current&&clearTimeout(C.current),C.current=setTimeout(()=>l(!0),80)},T=()=>{C.current&&clearTimeout(C.current),v||(C.current=setTimeout(()=>l(!1),200))};(0,y.useEffect)(()=>()=>{C.current&&clearTimeout(C.current)},[]);let E=async()=>{if(i){h(!0),_(null);try{let n=f.trim();n?await Q.saveAmsLabel(t,e.id,n,e.serial_number):await Q.deleteAmsLabel(t,e.id,e.serial_number),a(),l(!1)}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!1)}}};return(0,K.jsxs)(`div`,{ref:x,className:`relative inline-block`,onMouseEnter:w,onMouseLeave:T,children:[o,c&&(0,K.jsx)(`div`,{ref:S,className:` + `})]})]})}function lEe({slots:e,filamentInfo:t}){let{t:n}=G(),r=e.filter(e=>e.id>=2),i=Array.from({length:6},(e,t)=>r.find(e=>e.id===16+t)??{id:-(t+1),nozzle_type:``,nozzle_diameter:``,wear:null,stat:null,max_temp:0,serial_number:``,filament_color:``,filament_id:``,filament_type:``});return(0,K.jsxs)(`div`,{className:`text-center px-2.5 py-1.5 bg-bambu-dark rounded-lg flex-[2_1_190px] flex flex-col justify-center`,children:[(0,K.jsx)(`p`,{className:`text-[9px] text-bambu-gray mb-1`,children:n(`printers.nozzleRack`)}),(0,K.jsx)(`div`,{className:`flex gap-[3px] justify-center`,children:i.map((e,n)=>{let r=!e.nozzle_diameter&&!e.nozzle_type,i=r?null:Gd(e.filament_color),a=i?Kd(e.filament_color):!1;return(0,K.jsx)(gq,{slot:e,index:n,filamentName:e.filament_id?t?.[e.filament_id]?.name:void 0,children:(0,K.jsx)(`div`,{className:`w-7 h-7 rounded flex items-center justify-center cursor-default transition-colors border-b-2 ${r?`bg-bambu-dark-tertiary/20 border-bambu-dark-tertiary/20`:`bg-bambu-dark-tertiary/40 border-bambu-dark-tertiary/40`}`,style:i?{backgroundColor:i}:void 0,children:(0,K.jsx)(`span`,{className:`text-[10px] font-semibold ${r?`text-bambu-gray/30`:a?`text-black/80`:`text-white`}`,style:i&&!a?{textShadow:`0 1px 3px rgba(0,0,0,0.9)`}:void 0,children:r?`—`:e.nozzle_diameter||`?`})})},e.id>=0?e.id:`empty-${n}`)})})]})}function uEe({className:e}){return(0,K.jsx)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,K.jsx)(`path`,{d:`M17.8131 0.00538C18.4463 -0.15091 20.3648 3.14642 20.8264 3.84781C25.4187 10.816 35.3089 26.9368 35.9383 34.8694C37.4182 53.5822 11.882 61.3357 2.53721 45.3789C-1.73471 38.0791 0.016 32.2049 3.178 25.0232C6.99221 16.3662 12.6411 7.90372 17.8131 0.00538ZM18.3738 7.24807L17.5881 7.48441C14.4452 12.9431 10.917 18.2341 8.19369 23.9368C4.6808 31.29 1.18317 38.5479 7.69403 45.5657C17.3058 55.9228 34.9847 46.8808 31.4604 32.8681C29.2558 24.0969 22.4207 15.2913 18.3776 7.24807H18.3738Z`,fill:`#C3C2C1`})})}function dEe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 35 53`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`path`,{d:`M17.3165 0.0038C17.932 -0.14959 19.7971 3.08645 20.2458 3.77481C24.7103 10.6135 34.3251 26.4346 34.937 34.2198C36.3757 52.5848 11.5505 60.1942 2.46584 44.534C-1.68714 37.3735 0.0148 31.6085 3.08879 24.5603C6.79681 16.0605 12.2884 7.75907 17.3165 0.0038ZM17.8615 7.11561L17.0977 7.34755C14.0423 12.7048 10.6124 17.8974 7.96483 23.4941C4.54975 30.7107 1.14949 37.8337 7.47908 44.721C16.8233 54.8856 34.01 46.0117 30.5838 32.2595C28.4405 23.6512 21.7957 15.0093 17.8652 7.11561H17.8615Z`,fill:`#C3C2C1`}),(0,K.jsx)(`path`,{d:`M5.03547 30.112C9.64453 30.4936 11.632 35.7985 16.4154 35.791C19.6339 35.7873 20.2161 33.2283 22.3853 31.6197C31.6776 24.7286 33.5835 37.4894 27.9881 44.4254C18.1878 56.5653 -1.16063 44.6013 5.03917 30.1158L5.03547 30.112Z`,fill:`#1F8FEB`})]})}function fEe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`path`,{d:`M17.9625 4.48059L4.77216 26.3154L2.08228 40.2175L10.0224 50.8414H23.1594L33.3246 42.1693V30.2455L17.9625 4.48059Z`,fill:`#1F8FEB`}),(0,K.jsx)(`path`,{d:`M17.7948 0.00538C18.4273 -0.15091 20.3438 3.14642 20.8048 3.84781C25.3921 10.816 35.2715 26.9368 35.9001 34.8694C37.3784 53.5822 11.8702 61.3357 2.53562 45.3789C-1.73163 38.0829 0.0134 32.2087 3.1757 25.027C6.98574 16.3662 12.6284 7.90372 17.7948 0.00538ZM18.3549 7.24807L17.57 7.48441C14.4306 12.9431 10.9063 18.2341 8.1859 23.9368C4.67686 31.29 1.18305 38.5479 7.68679 45.5657C17.2881 55.9228 34.9476 46.8808 31.4271 32.8681C29.2249 24.0969 22.3974 15.2913 18.3587 7.24807H18.3549Z`,fill:`#C3C2C1`})]})}function pEe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`}),(0,K.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2.5`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function mEe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`rect`,{x:`4.5`,y:`8`,width:`3`,height:`4.5`,fill:`#d4a017`,rx:`0.5`}),(0,K.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#d4a017`}),(0,K.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function hEe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`rect`,{x:`4.5`,y:`3`,width:`3`,height:`9.5`,fill:`#c62828`,rx:`0.5`}),(0,K.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#c62828`}),(0,K.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function gEe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,K.jsx)(`rect`,{x:`9.2`,y:`3.4`,width:`5.6`,height:`8.1`}),(0,K.jsx)(`rect`,{x:`6`,y:`11.5`,width:`12.1`,height:`3.7`}),(0,K.jsx)(`path`,{d:`M 7.3 15.2 L 12.1 19.6 L 16.7 15.2`})]})}function _q({className:e,color:t,isHeating:n}){let r={"text-orange-400":`#fb923c`,"text-blue-400":`#60a5fa`,"text-green-400":`#4ade80`}[t]||`#888`,i=n?{filter:`drop-shadow(0 0 4px ${r}) drop-shadow(0 0 8px ${r})`}:{};return n?(0,K.jsxs)(`svg`,{className:e,style:i,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`rect`,{x:`4.5`,y:`3`,width:`3`,height:`9.5`,fill:r,rx:`0.5`}),(0,K.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:r}),(0,K.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:r,strokeWidth:`1`,fill:`none`})]}):(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:r,strokeWidth:`1`,fill:`none`}),(0,K.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2.5`,stroke:r,strokeWidth:`1`,fill:`none`})]})}function _Ee({state:e,canToggle:t,pending:n,onToggle:r}){let{t:i}=G(),a=e!==null,o=t&&a&&!n,s=`flex items-center justify-center w-[18px] h-[18px] rounded text-[10px] transition-colors `,c;return e===!0?(s+=o?`bg-blue-500/20 text-blue-400 hover:bg-blue-500/30 cursor-pointer`:`bg-blue-500/20 text-blue-400 cursor-default`,c=i(`printers.amsBackup.titleOn`)):e===!1?(s+=o?`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark/80 cursor-pointer`:`bg-bambu-dark text-bambu-gray cursor-default`,c=i(`printers.amsBackup.titleOff`)):(s+=`bg-bambu-dark text-bambu-gray/50 cursor-default`,c=i(`printers.amsBackup.titleUnknown`)),(0,K.jsx)(`button`,{type:`button`,disabled:!o,onClick:()=>o&&r(!e),className:s,title:c,"aria-label":c,children:a?(0,K.jsx)(wl,{className:`w-3 h-3`}):(0,K.jsx)(`span`,{children:`?`})})}function vq({humidity:e,goodThreshold:t=40,fairThreshold:n=60,onClick:r,compact:i}){let a=typeof e==`string`?parseInt(e,10):e,o=typeof t==`number`?t:40,s=typeof n==`number`?n:60,c,l;isNaN(a)?(c=`#C3C2C1`,l=`Unknown`):a<=o?(c=`#22a352`,l=`Good`):a<=s?(c=`#d4a017`,l=`Fair`):(c=`#c62828`,l=`Bad`);let u;return u=isNaN(a)||a<=o?uEe:a<=s?dEe:fEe,(0,K.jsxs)(`button`,{type:`button`,onClick:r,className:`flex items-center gap-1 ${r?`cursor-pointer hover:opacity-80 transition-opacity`:``}`,title:`Humidity: ${a}% - ${l}${r?` (click for history)`:``}`,children:[(0,K.jsx)(u,{className:i?`w-2.5 h-3`:`w-3 h-4`}),(0,K.jsxs)(`span`,{className:`font-medium tabular-nums ${i?`text-[10px]`:`text-xs`}`,style:{color:c},children:[a,`%`]})]})}function yq({temp:e,goodThreshold:t=28,fairThreshold:n=35,onClick:r,compact:i}){let a=typeof t==`number`?t:28,o=typeof n==`number`?n:35,s,c,l;return e<=a?(s=`#22a352`,c=`Good`,l=pEe):e<=o?(s=`#d4a017`,c=`Fair`,l=mEe):(s=`#c62828`,c=`Bad`,l=hEe),(0,K.jsxs)(`button`,{type:`button`,onClick:r,className:`flex items-center gap-1 ${r?`cursor-pointer hover:opacity-80 transition-opacity`:``}`,title:`Temperature: ${e}°C - ${c}${r?` (click for history)`:``}`,children:[(0,K.jsx)(l,{className:i?`w-2.5 h-3`:`w-3 h-4`}),(0,K.jsxs)(`span`,{className:`tabular-nums text-right ${i?`text-[10px] w-8`:`w-12`}`,style:{color:s},children:[e,`°C`]})]})}function bq(e,t){let n=typeof e==`string`?parseInt(e,10):e,r=isNaN(n)?0:n,i=t===1,a=r>=128?r-128:r,o=String.fromCharCode(65+a);return i?`HT-${o}`:`AMS-${o}`}function xq(e){return e?.tray_type?null:e?.state===9||e?.state===10?`physical`:`reset`}function vEe({url:e,printName:t,className:n=`w-20 h-20`,radiusClass:r=`rounded-lg`}){let{t:i}=G(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),d=(0,y.useMemo)(()=>e?Ku(`${e}${e.includes(`?`)?`&`:`?`}v=${encodeURIComponent(t||Date.now().toString())}`):null,[e,t]);return(0,y.useEffect)(()=>{o(!1),c(!1)},[d]),(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`${n} flex-shrink-0 ${r} overflow-hidden bg-bambu-dark-tertiary flex items-center justify-center ${d&&a?`cursor-pointer`:``}`,onClick:()=>d&&a&&u(!0),children:d&&!s?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`img`,{src:d,alt:i(`printers.printPreview`),className:`w-full h-full object-cover ${a?`block`:`hidden`}`,onLoad:()=>o(!0),onError:()=>c(!0)}),!a&&(0,K.jsx)(Bo,{className:`w-8 h-8 text-bambu-gray`})]}):(0,K.jsx)(Bo,{className:`w-8 h-8 text-bambu-gray`})}),l&&d&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-8`,onClick:()=>u(!1),children:(0,K.jsxs)(`div`,{className:`relative max-w-2xl max-h-full`,children:[(0,K.jsx)(`img`,{src:d,alt:i(`printers.printPreview`),className:`max-w-full max-h-[80vh] rounded-lg shadow-2xl`}),t&&(0,K.jsx)(`p`,{className:`text-white text-center mt-4 text-lg`,children:t})]})})]})}function yEe({printers:e}){let{t}=G(),n=Qa(),[r,i]=(0,y.useState)(0);(0,y.useEffect)(()=>{let e=!1,t=n.getQueryCache().subscribe(()=>{e||(e=!0,requestAnimationFrame(()=>{i(e=>e+1),e=!1}))});return()=>t()},[n]);let{counts:a,nextFinish:o}=(0,y.useMemo)(()=>{let t=0,r=0,i=0,a=0,o=0,s=0,c=0,l=null,u=null,d=0;return e?.forEach(e=>{let f=n.getQueryData([`printerStatus`,e.id]);if(f===void 0)s++;else if(!f.connected)o++;else{let n=f.hms_errors?dp(f.hms_errors).length:0;switch(n>0&&c++,f.state){case`RUNNING`:t++,f.remaining_time!=null&&f.remaining_time>0&&(u===null||f.remaining_time0||i++;break;default:a++;break}}}),{counts:{printing:t,paused:r,finished:i,idle:a,offline:o,loading:s,error:c,total:e?.length||0},nextFinish:l&&u?{name:l,remainingMin:u,progress:d}:null}},[e,n,r]);return e?.length?(0,K.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-4 gap-y-2 text-bambu-gray`,children:[[{count:a.printing,dot:`bg-bambu-green animate-pulse`,label:t(`printers.status.printing`).toLowerCase()},{count:a.paused,dot:`bg-status-warning`,label:t(`printers.status.paused`,`paused`).toLowerCase()},{count:a.finished,dot:`bg-blue-400`,label:t(`printers.status.finished`,`finished`).toLowerCase()},{count:a.idle,dot:a.idle>0?`bg-bambu-green`:`bg-gray-500`,label:t(`printers.status.available`).toLowerCase()},{count:a.error,dot:`bg-status-error`,label:t(`printers.status.problem`).toLowerCase()},{count:a.offline,dot:`bg-gray-400`,label:t(`printers.status.offline`).toLowerCase()}].map(({count:e,dot:t,label:n})=>e>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full ${t}`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`text-white font-medium`,children:e}),` `,n]})]},n)),o&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`w-px h-4 bg-bambu-dark-tertiary`}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-1 sm:flex-row sm:items-center sm:gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-green font-medium`,children:[t(`printers.nextAvailable`),`:`]}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:o.name})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 w-full sm:w-auto`,children:[(0,K.jsx)(`div`,{className:`w-full sm:w-16 bg-bambu-dark-tertiary rounded-full h-1.5`,children:(0,K.jsx)(`div`,{className:`bg-bambu-green h-1.5 rounded-full transition-all`,style:{width:`${o.progress}%`}})}),(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[Math.round(o.progress),`%`]}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,yf(o.remainingMin*60),`)`]})]})]})]})]}):null}function Sq({value:e,options:t,onChange:n,fullWidth:r=!1}){let[i,a]=(0,y.useState)(!1),o=t.find(t=>t.value===e)??t[0];return(0,K.jsxs)(`div`,{className:`relative ${r?`w-full min-w-0`:``}`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`h-8 px-2 rounded-lg border bg-bambu-dark border-bambu-dark-tertiary text-white text-sm font-medium transition-colors hover:bg-bambu-dark-tertiary focus:outline-none focus:border-bambu-green flex items-center justify-between gap-2 ${r?`w-full`:`min-w-28`}`,children:[(0,K.jsx)(`span`,{className:`truncate`,children:o?.label}),(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?`rotate-180`:``}`})]}),i&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>a(!1)}),(0,K.jsx)(`div`,{className:`absolute left-0 top-full z-20 mt-1 min-w-full rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary py-1 shadow-xl`,children:t.map(t=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>{n(t.value),a(!1)},className:`w-full px-3 py-2 text-left text-sm transition-colors hover:bg-bambu-dark-tertiary ${t.value===e?`text-bambu-green`:`text-white`}`,children:t.label},t.value))})]})]})}function Cq({label:e,icon:t,children:n}){let[r,i]=(0,y.useState)(!1);return(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`h-8 w-8 rounded-lg border bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center justify-center`,"aria-label":e,title:e,children:t}),r&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>i(!1)}),(0,K.jsx)(`div`,{className:`absolute right-0 top-full z-20 mt-1 min-w-40 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary p-2 shadow-xl`,children:n})]})]})}function wq({title:e,options:t=[],unit:n,customMin:r,customMax:i,customStep:a=1,widthClass:o=`w-[240px]`,popoverWidth:s=240,popoverHeight:c=280,isPending:l,onClose:u,onSubmit:d,children:f}){let p=(0,y.useRef)(null),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(``);(0,y.useLayoutEffect)(()=>{let e=p.current?.parentElement;if(!e)return;let t=()=>{h(ep({triggerRect:e.getBoundingClientRect(),popoverWidth:s,estimatedHeight:c,horizontalAlign:`center`}))};return t(),window.addEventListener(`resize`,t),window.addEventListener(`scroll`,t,!0),()=>{window.removeEventListener(`resize`,t),window.removeEventListener(`scroll`,t,!0)}},[s,c]);let v=n!==void 0,b=()=>{let e=Number(g);Number.isFinite(e)&&d?.(Math.round(Math.min(i??e,Math.max(r??e,e))))};return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{ref:p,className:`hidden`,"aria-hidden":`true`}),(0,Zf.createPortal)((0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-[1000]`,onClick:u}),(0,K.jsxs)(`div`,{className:`fixed z-[1001] flex ${o} flex-col overflow-hidden rounded-xl border border-bambu-dark-tertiary bg-bambu-dark-secondary shadow-2xl`,style:{top:m?.top??-9999,left:m?.left??-9999,visibility:m?`visible`:`hidden`},onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`shrink-0 px-3 py-2.5 text-center text-sm font-medium text-white`,children:e}),(0,K.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),t.length>0&&(0,K.jsx)(`div`,{className:`px-3 py-2.5`,children:(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:t.map(e=>(0,K.jsx)(`button`,{type:`button`,disabled:l,onClick:()=>d?.(e.value),className:`h-8 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 disabled:cursor-not-allowed disabled:opacity-50`,children:e.label},`${e.label}-${e.value}`))})}),f,v&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),(0,K.jsxs)(`form`,{className:`flex gap-1.5 px-3 pt-2.5 pb-3`,onSubmit:e=>{e.preventDefault(),b()},children:[(0,K.jsx)(`input`,{type:`number`,min:r,max:i,step:a,value:g,onChange:e=>_(e.target.value),placeholder:`Custom`,className:`h-8 min-w-0 flex-1 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark px-2 text-xs text-white placeholder:text-bambu-gray/60 focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`button`,{type:`submit`,disabled:l||g.trim()===``,className:`h-8 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 disabled:cursor-not-allowed disabled:opacity-50`,children:`Set`})]})]})]})]}),document.body)]})}var bEe=sp(tp,`C`);function Tq({label:e,current:t,target:n,isActive:r,isPending:i,onSubmit:a,options:o=bEe}){let[s,c]=(0,y.useState)(``),l=()=>{let e=Number(s);Number.isFinite(e)&&a(Math.min(320,Math.max(0,Math.round(e))))};return(0,K.jsxs)(`div`,{className:`rounded-lg border p-2 ${r?`border-amber-400/60 bg-amber-400/10`:`border-bambu-dark-tertiary bg-bambu-dark`}`,children:[(0,K.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium ${r?`text-amber-300`:`text-white`}`,children:e}),(0,K.jsxs)(`span`,{className:`text-[10px] text-bambu-gray`,children:[Math.round(t??0),`°C`,n===void 0?``:` / ${Math.round(n)}°`]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-1`,children:o.map(t=>(0,K.jsx)(`button`,{type:`button`,disabled:i,onClick:()=>a(t.value),className:`h-7 rounded-md border border-bambu-dark-tertiary bg-bambu-dark-secondary px-1.5 text-[11px] font-medium text-white transition-colors hover:bg-bambu-dark-tertiary disabled:cursor-not-allowed disabled:opacity-50`,children:t.label},`${e}-${t.value}`))}),(0,K.jsxs)(`form`,{className:`mt-1.5 flex gap-1`,onSubmit:e=>{e.preventDefault(),l()},children:[(0,K.jsx)(`input`,{type:`number`,min:0,max:320,step:1,value:s,onChange:e=>c(e.target.value),placeholder:`Custom`,className:`h-7 min-w-0 flex-1 rounded-md border border-bambu-dark-tertiary bg-bambu-dark-secondary px-1.5 text-[11px] text-white placeholder:text-bambu-gray/60 focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`button`,{type:`submit`,disabled:i||s.trim()===``,className:`h-7 rounded-md border border-bambu-dark-tertiary bg-bambu-dark-secondary px-2 text-[11px] font-medium text-white transition-colors hover:bg-bambu-dark-tertiary disabled:cursor-not-allowed disabled:opacity-50`,children:`Set`})]})]})}var xEe=[`error`,`printing`,`paused`,`finished`,`idle`,`offline`],Eq={error:{labelKey:`printers.status.problem`,dot:`bg-status-error`},printing:{labelKey:`printers.status.printing`,dot:`bg-bambu-green animate-pulse`},paused:{labelKey:`printers.status.paused`,dot:`bg-status-warning`},finished:{labelKey:`printers.status.finished`,dot:`bg-blue-400`},idle:{labelKey:`printers.status.idle`,dot:`bg-bambu-green`},offline:{labelKey:`printers.status.offline`,dot:`bg-gray-400`}};function Dq(e){if(!e?.connected)return`offline`;if((e.hms_errors?dp(e.hms_errors):[]).length>0)return`error`;switch(e.state){case`RUNNING`:return`printing`;case`PAUSE`:return`paused`;case`FINISH`:return`finished`;case`FAILED`:return`finished`;default:return`idle`}}function SEe(e,t){if(t)return t;switch(e){case`RUNNING`:return`Printing`;case`PAUSE`:return`Paused`;case`FINISH`:return`Finished`;case`FAILED`:return`Failed`;case`IDLE`:return`Idle`;default:return e?e.charAt(0)+e.slice(1).toLowerCase():`Idle`}}var CEe=new Set([`X1C`,`X1`,`X1E`,`X2D`,`P1S`,`P2S`,`H2D`,`H2D Pro`,`H2C`,`H2S`]);function Oq(e){return e?{O1D:`H2D`,O1E:`H2D Pro`,O2D:`H2D Pro`,O1C:`H2C`,O1C2:`H2C`,O1S:`H2S`,"BL-P001":`X1C`,"BL-P002":`X1`,"BL-P003":`X1E`,N6:`X2D`,N9:`A2L`,C11:`P1S`,C12:`P1P`,C13:`P2S`,N2S:`A1`,N1:`A1 Mini`,X1C:`X1C`,X1:`X1`,X1E:`X1E`,X2D:`X2D`,P1S:`P1S`,P1P:`P1P`,P2S:`P2S`,A1:`A1`,"A1 Mini":`A1 Mini`,A2L:`A2L`,H2D:`H2D`,"H2D Pro":`H2D Pro`,H2C:`H2C`,H2S:`H2S`}[e]||e:``}function kq({ams:e,printerId:t,label:n,amsLabels:r,canEdit:i,onSaved:a,children:o}){let{t:s}=G(),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(`top`),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(!1),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(!1),x=(0,y.useRef)(null),S=(0,y.useRef)(null),C=(0,y.useRef)(null);(0,y.useEffect)(()=>{c&&(p(r?.[e.id]??``),_(null),requestAnimationFrame(()=>{if(x.current&&S.current){let e=x.current.getBoundingClientRect(),t=e.top-56,n=window.innerHeight-e.bottom;d(tt?`bottom`:`top`)}}))},[c,r,e.id]);let w=()=>{C.current&&clearTimeout(C.current),C.current=setTimeout(()=>l(!0),80)},T=()=>{C.current&&clearTimeout(C.current),v||(C.current=setTimeout(()=>l(!1),200))};(0,y.useEffect)(()=>()=>{C.current&&clearTimeout(C.current)},[]);let E=async()=>{if(i){h(!0),_(null);try{let n=f.trim();n?await Q.saveAmsLabel(t,e.id,n,e.serial_number):await Q.deleteAmsLabel(t,e.id,e.serial_number),a(),l(!1)}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!1)}}};return(0,K.jsxs)(`div`,{ref:x,className:`relative inline-block`,onMouseEnter:w,onMouseLeave:T,children:[o,c&&(0,K.jsx)(`div`,{ref:S,className:` 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-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 Aq={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 jq({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=Aq,requirePlateClear:S=!1,selectionMode:C=!1,isSelected:w=!1,onToggleSelect:T,onOpenCompactCard:E,nozzleTempPresets:D=tp,bedTempPresets:O=np,chamberTempPresets:k=rp,fanSpeedPresets:A=ip}){let{t:j}=G(),M=Qa(),N=Yn(),{showToast:P}=xd(),{hasPermission:F}=sd(),[I,L]=(0,y.useState)(!1),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(!0),[ee,H]=(0,y.useState)(!1),[te,ne]=(0,y.useState)(!1),[re,U]=(0,y.useState)(!1),[ie,ae]=(0,y.useState)(!1),[W,oe]=(0,y.useState)(!1),[se,ce]=(0,y.useState)(null),[le,ue]=(0,y.useState)(!1),[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(!1),[he,ge]=(0,y.useState)(null),[_e,ve]=(0,y.useState)(null),[ye,be]=(0,y.useState)(null),[xe,Se]=(0,y.useState)(null),[Ce,we]=(0,y.useState)(10),[Te,Ee]=(0,y.useState)(null),[De,Oe]=(0,y.useState)(!1),[ke,Ae]=(0,y.useState)(!1),[je,Me]=(0,y.useState)(!1),[Ne,Pe]=(0,y.useState)(!1),[Fe,Ie]=(0,y.useState)(!1),Le=(0,y.useCallback)(()=>Pe(!1),[]),[Re,ze]=(0,y.useState)(null),[Be,Ve]=(0,y.useState)(null),[He,Ue]=(0,y.useState)(`n3f`),[We,Ge]=(0,y.useState)(`PLA`),[Ke,qe]=(0,y.useState)(50),[Je,Ye]=(0,y.useState)(4),[Xe,Ze]=(0,y.useState)(!1),[Qe,$e]=(0,y.useState)(null),[et,tt]=(0,y.useState)(!1),[nt,rt]=(0,y.useState)(!1),it=(0,y.useRef)(null),at=(0,y.useRef)(0),[ot,st]=(0,y.useState)(null),[ct,lt]=(0,y.useState)(null),[ut,dt]=(0,y.useState)(null),[ft,pt]=(0,y.useState)(null),[mt,ht]=(0,y.useState)(null),[gt,_t]=(0,y.useState)(!1),[vt,yt]=(0,y.useState)(null),[bt,xt]=(0,y.useState)(!1),[St,Ct]=(0,y.useState)(!1),[wt,Tt]=(0,y.useState)(null),[Et,Dt]=(0,y.useState)(!1),[Ot,kt]=(0,y.useState)(!1),{data:At}=q({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),refetchInterval:3e4}),{data:jt}=q({queryKey:[`firmwareUpdate`,e.id],queryFn:()=>ed.checkPrinterUpdate(e.id),staleTime:300*1e3,refetchInterval:300*1e3,enabled:b&&F(`firmware:read`)}),Mt=(0,y.useMemo)(()=>{let e=new Set;if(At?.ams)for(let t of At.ams)for(let n of t.tray||[])n.tray_info_idx&&e.add(n.tray_info_idx);for(let t of At?.vt_tray??[])t.tray_info_idx&&e.add(t.tray_info_idx);if(At?.nozzle_rack)for(let t of At.nozzle_rack)t.filament_id&&e.add(t.filament_id);return Array.from(e)},[At?.ams,At?.vt_tray,At?.nozzle_rack]),Nt=(0,y.useMemo)(()=>{let e=new Set;if(At?.ams)for(let t of At.ams)for(let n of t.tray||[])n.tray_type&&e.add(n.tray_type.toUpperCase());for(let t of At?.vt_tray??[])t.tray_type&&e.add(t.tray_type.toUpperCase());return e},[At?.ams,At?.vt_tray]),Pt=(0,y.useMemo)(()=>{let e=new Set;if(At?.ams){for(let t of At.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 At?.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},[At?.ams,At?.vt_tray]),{data:Ft}=q({queryKey:[`filamentInfo`,Mt],queryFn:()=>Q.getFilamentInfo(Mt),enabled:Mt.length>0,staleTime:300*1e3}),{data:It}=q({queryKey:[`slotPresets`,e.id],queryFn:()=>Q.getSlotPresets(e.id),staleTime:120*1e3}),Lt=At?.state===`RUNNING`||At?.state===`PAUSE`?At?.current_archive_id??null:null,{data:Rt}=q({queryKey:[`archive-plates`,Lt],queryFn:()=>Q.getArchivePlates(Lt),enabled:Lt!=null,staleTime:300*1e3}),zt=!Rt?.is_multi_plate||At?.current_plate_id==null?null:Rt.plates.find(e=>e.index===At.current_plate_id)?.name||j(`printers.plateNumber`,`Plate {{number}}`,{number:At.current_plate_id}),{data:Bt,refetch:Vt}=q({queryKey:[`amsLabels`,e.id],queryFn:()=>Q.getAmsLabels(e.id),staleTime:300*1e3}),[Ht,Ut]=(0,y.useState)(null);(0,y.useEffect)(()=>{At?.wifi_signal!=null&&Ut(At.wifi_signal)},[At?.wifi_signal]);let Wt=At?.wifi_signal??Ht,Gt=(0,y.useRef)(void 0);(0,y.useEffect)(()=>{At?.connected!==void 0&&(Gt.current=At.connected)},[At?.connected]);let Kt=At?.connected??Gt.current,qt=(0,y.useRef)({});(0,y.useEffect)(()=>{At?.ams_extruder_map&&Object.keys(At.ams_extruder_map).length>0&&(qt.current=At.ams_extruder_map)},[At?.ams_extruder_map]);let Jt=At?.ams_extruder_map&&Object.keys(At.ams_extruder_map).length>0?At.ams_extruder_map:qt.current,Yt=(0,y.useRef)([]);(0,y.useEffect)(()=>{At?.ams&&At.ams.length>0&&(Yt.current=At.ams)},[At?.ams]);let Xt=At?.ams&&At.ams.length>0?At.ams:Yt.current,Zt=(0,y.useRef)(void 0),Qt=At?.tray_now;Qt!==void 0&&Qt!==255?Zt.current=Qt:Qt===255&&(Zt.current=void 0);let $t=Qt!==void 0&&Qt!==255?Qt:Zt.current,{data:en}=q({queryKey:[`smartPlugByPrinter`,e.id],queryFn:()=>Q.getSmartPlugByPrinter(e.id)}),{data:tn}=q({queryKey:[`scriptPlugsByPrinter`,e.id],queryFn:()=>Q.getScriptPlugsByPrinter(e.id)}),{data:nn}=q({queryKey:[`smartPlugStatus`,en?.id],queryFn:()=>en?Q.getSmartPlugStatus(en.id):null,enabled:!!en,refetchInterval:1e4}),{data:rn}=q({queryKey:[`queue`,e.id,`pending`],queryFn:()=>Q.getQueue(e.id,`pending`)}),an=(0,y.useMemo)(()=>rn?.length?IT(rn,Nt,Pt).length:0,[rn,Nt,Pt]),{data:on}=q({queryKey:[`queue`,e.id,`printing`],queryFn:()=>Q.getQueue(e.id,`printing`),enabled:At?.state===`RUNNING`}),{data:sn}=q({queryKey:[`currentPrintUser`,e.id],queryFn:()=>Q.getCurrentPrintUser(e.id),enabled:At?.state===`RUNNING`}),cn=on?.[0]?.created_by_username||sn?.username,{data:ln}=q({queryKey:[`archives`,e.id,`last`],queryFn:()=>Q.getArchives(e.id,1,0),enabled:At?.connected&&At?.state!==`RUNNING`}),un=ln?.[0],dn=At?.state===`RUNNING`||At?.state===`PAUSE`,fn=S&&At?.awaiting_plate_clear===!0,pn=At?.connected&&fn&&!dn,mn=At?.current_print&&dn?$f(At.subtask_name||At.current_print||null,At.gcode_file,j,zt):null,[hn,gn]=(0,y.useState)(null);(0,y.useEffect)(()=>{mn?gn({name:mn,coverUrl:At?.cover_url??null}):fn||gn(null)},[mn,fn,At?.cover_url]);let _n=!S||!At?.connected?null:dn?{label:j(`printers.plateStatus.inUse`),className:`bg-blue-500/20 text-blue-400`}:At.awaiting_plate_clear?{label:j(`printers.plateStatus.notCleared`),className:`bg-yellow-500/20 text-yellow-400`}:{label:j(`printers.plateStatus.cleared`),className:`bg-status-ok/20 text-status-ok`},vn=_n?(0,K.jsx)(`span`,{className:`inline-flex flex-shrink-0 items-center rounded-full px-2 py-0.5 text-[10px] font-medium ${_n.className}`,children:_n.label}):null,yn=t&&Kt===!1,bn=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`)}),xn=J({mutationFn:()=>Q.connectPrinter(e.id),onSuccess:()=>{M.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),Sn=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`)}),Cn=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`)}}),wn=J({mutationFn:({amsId:t,temp:n,duration:r,filament:i,rotateTray:a})=>Q.startDrying(e.id,t,n,r,i,a),onSuccess:()=>{Ve(null),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Tn=J({mutationFn:t=>Q.stopDrying(e.id,t),onSuccess:()=>{M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),En=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`)}),Dn=J({mutationFn:e=>en?Q.controlSmartPlug(en.id,e):Promise.reject(`No plug`),onSuccess:()=>{M.invalidateQueries({queryKey:[`smartPlugStatus`,en?.id]})}}),On=J({mutationFn:e=>en?Q.updateSmartPlug(en.id,{auto_off:e}):Promise.reject(`No plug`),onSuccess:()=>{M.invalidateQueries({queryKey:[`smartPlugByPrinter`,e.id]}),M.invalidateQueries({queryKey:[`smart-plugs`]})}}),kn=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`)}),An=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`)}),jn=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`)}),Mn=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`)}),Nn=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`)}),Pn=J({mutationFn:({target:t,nozzle:n})=>Q.setNozzleTemperature(e.id,t,n),onSuccess:t=>{Se(null),P(t.message),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Fn=J({mutationFn:t=>Q.setBedTemperature(e.id,t),onSuccess:t=>{Se(null),P(t.message),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),In=J({mutationFn:t=>Q.setChamberTemperature(e.id,t),onSuccess:t=>{Se(null),P(t.message),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Ln=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=>{Se(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`)}}),Rn=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=>{Se(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`)}}),zn=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`)}}),Bn=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`)}}),Vn=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`)}}),Hn=J({mutationFn:({distance:t,force:n})=>Q.bedJog(e.id,t,n??!1),onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Un=J({mutationFn:({x:t,y:n})=>Q.xyJog(e.id,t,n),onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Wn=J({mutationFn:t=>Q.extruderJog(e.id,t),onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Gn=J({mutationFn:t=>Q.homeAxes(e.id,t),onSuccess:()=>{try{sessionStorage.setItem(`bambuddy.bedJog.warned.${e.id}`,`1`)}catch{}P(j(`printers.bedJog.homingStarted`))},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Kn=J({mutationFn:t=>Q.updatePrinter(e.id,{plate_detection_enabled:t}),onSuccess:()=>{M.invalidateQueries({queryKey:[`printers`]}),P(Kn.variables?j(`printers.toast.plateCheckEnabled`):j(`printers.toast.plateCheckDisabled`))},onError:e=>P(e.message||j(`printers.toast.failedToUpdateSetting`),`error`)}),qn=(At?.state===`RUNNING`||At?.state===`PAUSE`)&&(At?.printable_objects_count??0)>=2,{data:Jn}=q({queryKey:[`printableObjects`,e.id],queryFn:()=>Q.getPrintableObjects(e.id),enabled:ke||qn,refetchInterval:ke?5e3:qn?3e4:!1}),[Xn,Zn]=(0,y.useState)(null),Qn=(0,y.useRef)(!1),$n=(0,y.useRef)(null),er=(0,y.useRef)(!1),tr=J({mutationFn:({amsId:t,slotId:n})=>Q.refreshAmsSlot(e.id,t,n),onMutate:({amsId:e,slotId:t})=>{$n.current&&clearTimeout($n.current),Qn.current=!1,er.current=!1,Zn({amsId:e,slotId:t}),setTimeout(()=>{er.current=!0},2e3),$n.current=setTimeout(()=>{Zn(null)},3e4)},onSuccess:e=>{P(e.message||j(`printers.toast.rfidRereadInitiated`))},onError:e=>{P(e.message||j(`printers.toast.failedToRereadRfid`),`error`),$n.current&&clearTimeout($n.current),Zn(null)}}),nr=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`)}}),rr=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`)}}),[ir,ar]=(0,y.useState)(null),[or,sr]=(0,y.useState)(null),cr=async()=>{try{ar(await Q.getPlateReferences(e.id))}catch{}},lr=()=>{Kn.mutate(!e.plate_detection_enabled)},ur=async()=>{xt(!0),yt(null);let t=At?.chamber_light===!1;kt(t),t&&(await Q.setChamberLight(e.id,!0),await new Promise(e=>setTimeout(e,2500)));try{yt(await Q.checkPlateEmpty(e.id,{includeDebugImage:!0})),cr()}catch(n){P(n instanceof Error?n.message:j(`printers.toast.failedToCheckPlate`),`error`),t&&(await Q.setChamberLight(e.id,!1),kt(!1))}finally{xt(!1)}},dr=(0,y.useCallback)(async()=>{yt(null),Ot&&(await Q.setChamberLight(e.id,!1),kt(!1))},[Ot,e.id]),fr=async t=>{Ct(!0);try{let n=await Q.calibratePlateDetection(e.id,{label:t});n.success?(P(n.message||j(`printers.toast.calibrationSaved`),`success`),cr(),yt(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{Ct(!1)}},pr=async(t,n)=>{try{await Q.updatePlateReferenceLabel(e.id,t,n),sr(null),cr()}catch(e){P(e instanceof Error?e.message:j(`printers.toast.failedToUpdateLabel`),`error`)}},mr=async t=>{try{await Q.deletePlateReference(e.id,t),P(j(`printers.toast.referenceDeleted`),`success`),cr(),yt(await Q.checkPlateEmpty(e.id,{includeDebugImage:!0}))}catch(e){P(e instanceof Error?e.message:j(`printers.toast.failedToDeleteReference`),`error`)}},hr=async()=>{if(wt){Dt(!0);try{await Q.updatePrinter(e.id,{plate_detection_roi:wt}),P(j(`printers.toast.detectionAreaSaved`),`success`),Tt(null),yt(await Q.checkPlateEmpty(e.id,{includeDebugImage:!0}))}catch(e){P(e instanceof Error?e.message:j(`printers.toast.failedToSaveDetectionArea`),`error`)}finally{Dt(!1)}}};(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&vt&&dr()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[vt,dr]);let gr=(0,y.useRef)(null);if((0,y.useEffect)(()=>{if(!Xn)return;let e=At?.ams_status_main??0;return e!==0&&(Qn.current=!0,gr.current&&=(clearTimeout(gr.current),null)),Qn.current&&e===0&&(er.current?($n.current&&clearTimeout($n.current),Zn(null)):gr.current||=setTimeout(()=>{$n.current&&clearTimeout($n.current),Zn(null)},2e3)),()=>{gr.current&&clearTimeout(gr.current)}},[At?.ams_status_main,Xn]),(0,y.useEffect)(()=>{if(!I)return;let e=e=>{let t=e.target;it.current?.contains(t)||L(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[I]),yn)return null;let _r=()=>{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`}},vr=()=>{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`}},yr=()=>{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`}},br=Kt&&At?.state!==`RUNNING`&&At?.state!==`PAUSE`&&F(`printers:control`),xr=e=>{e.preventDefault(),at.current++,at.current===1&&tt(!0)},Sr=e=>{e.preventDefault(),e.dataTransfer.dropEffect=br?`copy`:`none`},Cr=e=>{e.preventDefault(),at.current--,at.current===0&&tt(!1)},wr=async t=>{if(t.preventDefault(),at.current=0,tt(!1),!br)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}rt(!0);try{let t=await Q.uploadLibraryFile(n,null),r=t.metadata?.sliced_for_model,i=Oq(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}ze({id:t.id,filename:t.filename})}catch{P(j(`common.uploadFailed`,`Upload failed`),`error`)}finally{rt(!1)}},Tr=t=>{r!==`compact`||C||t.target.closest(`button, a, input, select, textarea, [role="button"]`)||E?.(e.id)},Er=`!h-8 !min-h-8 !w-8 !px-0 !py-0`,Dr=({amsId:e,slotId:t,loadTrayId:n,isRefreshing:r,includeRfid:i=!0})=>{let a=At?.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`))&&tr.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)(Cl,{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`))&&nr.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)(Uc,{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`))&&rr.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)(Wc,{className:`w-3 h-3`}),j(`printers.ams.unload`)]})]})},Or=(0,K.jsxs)(`div`,{ref:it,className:`relative flex-shrink-0`,children:[(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>L(!I),title:j(`common.more`,`More`),className:Er,children:(0,K.jsx)(zs,{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`)&&(H(!0),L(!1))},title:F(`printers:update`)?void 0:j(`printers.permission.noEdit`),children:[(0,K.jsx)(pl,{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:()=>{Pe(!0),L(!1)},children:[(0,K.jsx)(kc,{className:`w-4 h-4`}),j(`printers.printerInformation`)]}),(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:()=>{xn.mutate(),L(!1)},children:[(0,K.jsx)(Cl,{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:Sn.isPending,onClick:()=>{Sn.mutate(),L(!1)},children:[(0,K.jsx)(El,{className:`w-4 h-4 ${Sn.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:()=>{U(!0),L(!1)},children:[(0,K.jsx)(lu,{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:()=>{Ie(!0),L(!1)},children:[(0,K.jsx)(ru,{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-400 hover:bg-bambu-dark-tertiary`:`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)(hu,{className:`w-4 h-4`}),j(`common.delete`)]})]})]});return(0,K.jsxs)(pd,{id:`printer-card-${e.id}`,className:`relative flex h-full flex-col ${w?`ring-2 ring-bambu-green`:``} ${C||r===`compact`?`cursor-pointer`:``}`,onClick:Tr,onDragEnter:xr,onDragOver:Sr,onDragLeave:Cr,onDrop:wr,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)($l,{className:`w-5 h-5 text-bambu-green`}):(0,K.jsx)(tu,{className:`w-5 h-5 text-bambu-gray`})}),(et||nt)&&(0,K.jsx)(`div`,{className:`absolute inset-0 z-10 rounded-xl border-2 border-dashed flex items-center justify-center transition-colors ${nt?`bg-bambu-green/10 border-bambu-green/50`:br?`bg-bambu-green/10 border-bambu-green`:`bg-red-500/10 border-red-500/50`}`,children:(0,K.jsx)(`div`,{className:`text-center`,children:nt?(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...`)})]}):br?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(bl,{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)(Pu,{className:`w-8 h-8 mx-auto mb-2 text-red-400`}),(0,K.jsx)(`p`,{className:`text-sm font-medium text-red-400`,children:j(`printers.cannotPrint`,`Printer busy`)})]})})}),(0,K.jsxs)(hd,{className:`${i>=3?`p-5`:``} flex flex-1 flex-col`,children:[(0,K.jsxs)(`div`,{className:yr(),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:PT(e.model),alt:e.model||j(`common.printer`),className:`object-contain rounded-lg flex-shrink-0 ${_r()}`}),(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 ${vr()}`,children:e.name}),r===`compact`&&(()=>{let e=At?.connected&&At.hms_errors?dp(At.hms_errors):[],t=e.some(e=>e.severity<=2),n=e.length>0,r=At?.connected?t?`bg-status-error`:n?`bg-status-warning`:`bg-status-ok`:`bg-status-error`,i=At?.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`&&pn&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>Nn.mutate(),disabled:Nn.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-500/20 border border-yellow-400/40 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:Nn.isPending?(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}):(0,K.jsx)(OK,{className:`w-3 h-3`})})]}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[e.model||`Unknown Model`,r===`expanded`&&At?.nozzles&&At.nozzles[0]?.nozzle_diameter&&(0,K.jsxs)(`span`,{className:`ml-1.5 text-bambu-gray`,title:At.nozzles[0].nozzle_type||`Nozzle`,children:[`• `,At.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)(_s,{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:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 rounded-full text-xs ${At?.connected?`bg-status-ok/20 text-status-ok`:`bg-status-error/20 text-status-error`}`,children:[At?.connected?(0,K.jsx)(Lc,{className:`w-3 h-3`}):(0,K.jsx)(xu,{className:`w-3 h-3`}),At?.connected?j(`printers.connection.connected`):j(`printers.connection.offline`)]}),!At?.connected&&(0,K.jsxs)(`button`,{onClick:()=>Ie(!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)(ru,{className:`w-3 h-3`}),j(`diagnostic.runButton`)]}),At?.connected&&At?.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)(Uo,{className:`w-3 h-3`}),j(`printers.connection.ethernet`,`Ethernet`)]}),At?.connected&&!At?.wired_network&&Wt!=null&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs ${Wt>=-50||Wt>=-60?`bg-status-ok/20 text-status-ok`:Wt>=-70?`bg-status-warning/20 text-status-warning`:Wt>=-80?`bg-orange-500/20 text-orange-600`:`bg-status-error/20 text-status-error`}`,title:`WiFi: ${Wt} dBm - ${j(FT(Wt).labelKey)}`,children:[(0,K.jsx)(Wl,{className:`w-3 h-3`}),Wt,`dBm`]}),At?.connected&&(()=>{let e=At.hms_errors?dp(At.hms_errors):[];return(0,K.jsxs)(`button`,{onClick:()=>ue(!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)(vu,{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)(Nu,{className:`w-3 h-3`}),n.due_count>0||n.warning_count>0?n.due_count+n.warning_count:`OK`]}),an>0&&(0,K.jsxs)(`button`,{onClick:()=>N(`/queue`),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-indigo-500/20 text-indigo-400 hover:opacity-80 transition-opacity`,title:j(`printers.queue.inQueue`,{count:an}),children:[(0,K.jsx)(Nc,{className:`w-3 h-3`}),an]}),b&&jt?.current_version&&jt?.latest_version?(0,K.jsxs)(`button`,{onClick:()=>_t(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs hover:opacity-80 transition-opacity ${jt.update_available?`bg-orange-500/20 text-orange-400`:`bg-status-ok/20 text-status-ok`}`,title:jt.update_available?j(`printers.firmwareUpdateAvailable`,{current:jt.current_version,latest:jt.latest_version}):j(`printers.firmwareUpToDate`,{version:jt.current_version}),children:[jt.update_available?(0,K.jsx)(Is,{className:`w-3 h-3`}):(0,K.jsx)(ls,{className:`w-3 h-3`}),jt.current_version]}):At?.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:At.firmware_version}):null,At?.connected&&[`X1C`,`X1`,`X1E`,`X2D`,`P1S`,`P1P`,`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 ${At.door_open?`bg-yellow-500/20 text-yellow-400`:`bg-status-ok/20 text-status-ok`}`,title:At.door_open?j(`printers.door.open`):j(`printers.door.closed`),children:At.door_open?(0,K.jsx)(Fs,{className:`w-3 h-3`}):(0,K.jsx)(Ps,{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)(pd,{className:`w-full max-w-md mx-4`,children:(0,K.jsxs)(hd,{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-500/20`,children:(0,K.jsx)(vu,{className:`w-5 h-5 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:()=>{bn.mutate({deleteArchives:B}),z(!1),V(!0)},children:`Delete`})]})]})})}),At?.connected&&(0,K.jsxs)(K.Fragment,{children:[r===`compact`?(()=>{let e=At.hms_errors?dp(At.hms_errors):[],t=At.state===`FAILED`||e.length>0,n=At.state===`RUNNING`||At.state===`PAUSE`?Math.max(0,Math.min(100,At.progress||0)):pn||t?100:0,r=At.state===`RUNNING`||At.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`:At.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=!!(At.current_print&&(At.state===`RUNNING`||At.state===`PAUSE`)),n=!t&&fn&&hn,r=t?mn:n?hn.name:null,i=t?At.cover_url:n?hn.coverUrl:null,a=t?At.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:()=>Ae(!0),disabled:!t||(At.printable_objects_count??0)<2||!F(`printers:control`),className:`absolute top-2 right-2 p-1.5 rounded transition-colors z-10 ${t&&(At.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?(At.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)(kT,{className:`w-4 h-4`}),Jn&&Jn.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:Jn.skipped_count})]}),(0,K.jsxs)(`div`,{className:`flex items-stretch gap-2`,children:[(0,K.jsx)(vEe,{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:SEe(At.state,At.stg_cur_name)}),vn]}),(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?At.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:[At.remaining_time!=null&&At.remaining_time>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),yf(At.remaining_time*60)]}),(0,K.jsxs)(`span`,{className:`text-bambu-green font-medium`,title:j(`printers.estimatedCompletion`),children:[`ETA `,vf(At.remaining_time,g,j)]})]}),At.layer_num!=null&&At.total_layers!=null&&At.total_layers>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(Nc,{className:`w-3 h-3`}),At.layer_num,`/`,At.total_layers]}),cn&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,title:`Started by ${cn}`,children:[(0,K.jsx)(Cu,{className:`w-3 h-3`}),cn]})]}):un?(0,K.jsxs)(`p`,{className:`truncate`,title:un.print_name||un.filename,children:[`Last: `,un.print_name||un.filename,un.completed_at&&(0,K.jsxs)(`span`,{className:`ml-1 text-bambu-gray/60`,children:[`• `,hf(un.completed_at,{month:`short`,day:`numeric`})]})]}):(0,K.jsx)(`span`,{children:j(`printers.readyToPrint`)})})]})]}),(0,K.jsx)(gce,{printerId:e.id,printerModel:e.model,loadedFilamentTypes:Nt,loadedFilaments:Pt,variant:`panelExtension`})]})})()]}),At.temperatures&&r===`expanded`&&(()=>{let t=At.temperatures.nozzle_heating||At.temperatures.nozzle_2_heating||!1,n=At.temperatures.bed_heating||!1,r=At.temperatures.chamber_heating||!1,i=e.nozzle_count===2||At.temperatures.nozzle_2!==void 0,a=(()=>{let e=[`nozzle`];return At.temperatures.nozzle_2!==void 0&&e.push(`nozzle_2`),e.push(`bed`),At.temperatures.chamber!==void 0&&e.push(`chamber`),e})(),o=At.active_extruder===1?`L`:`R`,s=At.nozzle_rack?.find(e=>e.id===1),c=At.nozzle_rack?.find(e=>e.id===0),l=c||s,u=At.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=[{key:`part`,label:j(`printers.fans.partCooling`),value:At.cooling_fan_speed??0,Icon:Ks,activeClass:`text-cyan-400`},{key:`aux`,label:j(`printers.fans.auxiliary`),value:At.big_fan1_speed??0,Icon:Mu,activeClass:`text-blue-400`},{key:`chamber`,label:j(`printers.fans.chamber`),value:At.big_fan2_speed??0,Icon:Co,activeClass:`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&&Se(xe===`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(),lt({initialKind:`nozzle`,availableKinds:a})},children:(0,K.jsx)(Xo,{className:`w-2.5 h-2.5`})}),(0,K.jsx)(_q,{className:`w-3.5 h-3.5 mb-0.5`,color:`text-orange-400`,isHeating:t}),At.temperatures.nozzle_2===void 0?l?(0,K.jsx)(gq,{slot:l,index:0,activeStatus:!0,filamentName:l.filament_id?Ft?.[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(At.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(At.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(At.temperatures.nozzle||0),`° / `,Math.round(At.temperatures.nozzle_2||0),`°`]})]}),xe===`nozzle-temp`&&(i?(0,K.jsx)(wq,{title:`Set Nozzle Temperatures`,widthClass:`w-[300px]`,popoverWidth:300,popoverHeight:260,isPending:Pn.isPending,onClose:()=>Se(null),children:(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 px-3 py-2.5`,children:[(0,K.jsx)(Tq,{label:`Left Temp`,current:At.temperatures.nozzle,target:At.temperatures.nozzle_target,isActive:o===`L`,isPending:Pn.isPending,onSubmit:e=>Pn.mutate({target:e,nozzle:1}),options:sp(D,`C`)}),(0,K.jsx)(Tq,{label:`Right Temp`,current:At.temperatures.nozzle_2,target:At.temperatures.nozzle_2_target,isActive:o===`R`,isPending:Pn.isPending,onSubmit:e=>Pn.mutate({target:e,nozzle:0}),options:sp(D,`C`)})]})}):(0,K.jsx)(wq,{title:`Set Nozzle Temperature`,unit:`°C`,customMin:0,customMax:320,isPending:Pn.isPending,options:sp(D,`C`),onClose:()=>Se(null),onSubmit:e=>Pn.mutate({target:e,nozzle:At.active_extruder??0})}))]}),(0,K.jsxs)(`div`,{className:f,title:d,onClick:()=>u&&Se(xe===`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(),lt({initialKind:`bed`,availableKinds:a})},children:(0,K.jsx)(Xo,{className:`w-2.5 h-2.5`})}),(0,K.jsx)(_q,{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(At.temperatures.bed||0),`°C`]}),xe===`bed-temp`&&(0,K.jsx)(wq,{title:`Set Bed Temperature`,unit:`°C`,customMin:0,customMax:140,isPending:Fn.isPending,options:sp(O,`C`),onClose:()=>Se(null),onSubmit:e=>Fn.mutate(e)})]}),At.temperatures.chamber!==void 0&&(()=>{let e=At.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&&Se(xe===`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(),lt({initialKind:`chamber`,availableKinds:a})},children:(0,K.jsx)(Xo,{className:`w-2.5 h-2.5`})}),(0,K.jsx)(_q,{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(At.temperatures.chamber||0),`°C`]}),e&&xe===`chamber-temp`&&(0,K.jsx)(wq,{title:`Set Chamber Temperature`,unit:`°C`,customMin:0,customMax:60,isPending:In.isPending,options:sp(k,`C`),onClose:()=>Se(null),onSubmit:e=>In.mutate(e)})]})})(),i&&(0,K.jsx)(cEe,{leftSlot:s,rightSlot:c,activeNozzle:o,filamentInfo:Ft,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&&Se(xe===`nozzle-select`?null:`nozzle-select`),children:[(0,K.jsx)(gEe,{className:`w-3.5 h-3.5 mb-0.5 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-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-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`)}),xe===`nozzle-select`&&(0,K.jsx)(wq,{title:`Set Nozzle Selection`,widthClass:`w-[300px]`,popoverWidth:300,popoverHeight:140,isPending:Rn.isPending,options:[{label:`Left`,value:1},{label:`Right`,value:0}],onClose:()=>Se(null),onSubmit:e=>Rn.mutate(e)})]})}),At.nozzle_rack&&At.nozzle_rack.some(e=>e.id>=2)&&(0,K.jsx)(lEe,{slots:At.nozzle_rack,filamentInfo:Ft})]}),(0,K.jsx)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:p.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&&Se(xe===`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,`%`]}),xe===`fan-${e}`&&(0,K.jsx)(wq,{title:`Set ${t} Speed`,unit:`%`,customMin:0,customMax:100,isPending:Ln.isPending,options:sp(A,`%`),onClose:()=>Se(null),onSubmit:t=>Ln.mutate({fan:e,speed:t})})]},e)})})]})})(),r===`expanded`&&pn&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>Nn.mutate(),disabled:Nn.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-500/20 border border-yellow-400/40 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:[Nn.isPending?(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}):(0,K.jsx)(OK,{className:`w-4 h-4`}),j(`printers.plateStatus.markCleared`)]}),r===`expanded`&&(()=>{let t=At.state===`RUNNING`,n=At.state===`PAUSE`,r=t||n,i=An.isPending||jn.isPending||Mn.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:()=>zn.mutate(!At.chamber_light),disabled:!At.connected||zn.isPending||!F(`printers:control`),className:`${o} ${At.chamber_light?`bg-yellow-500/10 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`)?At.chamber_light?j(`printers.chamberLightOff`):j(`printers.chamberLightOn`):j(`printers.permission.noControl`),children:(0,K.jsx)(OT,{on:At.chamber_light??!1,className:`w-4 h-4`})}),[`P2S`,`X2D`,`H2D`,`H2C`,`H2S`].includes(e.model??``)&&(()=>{let t=At.airduct_mode===1,n=t?ec:Zl,r=t?`text-orange-400`:`text-sky-400`,i=t?`bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:`bg-sky-500/10 text-sky-400 hover:bg-sky-500/20`;return(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{onClick:()=>ve(_e===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}`})}),_e===e.id&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>ve(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:()=>{Vn.mutate(e),ve(null)},className:`w-full text-left px-3 py-1.5 text-xs transition-colors flex items-center gap-2 ${At.airduct_mode===n?`text-bambu-green bg-bambu-green/10`:`text-white hover:bg-bambu-dark-tertiary`}`,children:[e===`heating`?(0,K.jsx)(ec,{className:`w-3 h-3`}):(0,K.jsx)(Zl,{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-500/15 text-indigo-300 transition-colors hover:bg-indigo-500/30 disabled:cursor-not-allowed disabled:opacity-50`,a=t=>{let n=t*Ce*1,r=`bambuddy.bedJog.warned.${e.id}`;(()=>{try{return sessionStorage.getItem(r)===`1`}catch{return!1}})()?Hn.mutate({distance:n,force:!0}):Ee({distance:n})},s=(e,t)=>{Un.mutate({x:e,y:t})},c=e=>{Wn.mutate(e)};return(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{onClick:()=>be(ye===e.id?null:e.id),disabled:n,className:`${o} ${n?`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`:`bg-indigo-500/10 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)(il,{className:`w-4 h-4`})}),ye===e.id&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>be(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.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,Ce),disabled:Un.isPending,className:i,"aria-label":`Move Y forward`,children:(0,K.jsx)(Mo,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{}),(0,K.jsx)(`button`,{onClick:()=>s(-Ce,0),disabled:Un.isPending,className:i,"aria-label":`Move X left`,children:(0,K.jsx)(Do,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{be(null),Gn.mutate(`all`)},disabled:Gn.isPending,className:i,"aria-label":j(`printers.bedJog.homeZ`),children:(0,K.jsx)(Tc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>s(Ce,0),disabled:Un.isPending,className:i,"aria-label":`Move X right`,children:(0,K.jsx)(ko,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{}),(0,K.jsx)(`button`,{onClick:()=>s(0,-Ce),disabled:Un.isPending,className:i,"aria-label":`Move Y back`,children:(0,K.jsx)(Eo,{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:Hn.isPending,className:i,"aria-label":j(`printers.bedJog.up`),children:(0,K.jsx)(Mo,{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)(Nc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(1),disabled:Hn.isPending,className:i,"aria-label":j(`printers.bedJog.down`),children:(0,K.jsx)(Eo,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>c(-Ce),disabled:Wn.isPending,className:i,"aria-label":`Retract filament`,children:(0,K.jsx)(Mo,{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(Ce),disabled:Wn.isPending,className:i,"aria-label":`Extrude filament`,children:(0,K.jsx)(Eo,{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:()=>we(e),className:`flex-1 px-1 py-1 rounded text-[10px] transition-colors ${Ce===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:lr,disabled:!At.connected||Kn.isPending||!F(`printers:update`),className:`${o} rounded-r-none ${e.plate_detection_enabled?`bg-green-500/10 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:Kn.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(jl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:ur,disabled:!At.connected||bt||!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-500/10 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:bt?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(es,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{"data-testid":`speed-control`,onClick:()=>ge(he===e.id?null:e.id),disabled:!r||!F(`printers:control`),className:`${o} ${r?`bg-amber-500/10 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)(uc,{className:`w-4 h-4`})}),he===e.id&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>ge(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:()=>{Bn.mutate(e),ge(null)},className:`w-full text-left px-3 py-1.5 text-xs transition-colors ${At.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?Oe(!0):me(!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-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 Aq={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 jq({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=Aq,requirePlateClear:S=!1,selectionMode:C=!1,isSelected:w=!1,onToggleSelect:T,onOpenCompactCard:E,nozzleTempPresets:D=tp,bedTempPresets:O=np,chamberTempPresets:k=rp,fanSpeedPresets:A=ip}){let{t:j}=G(),M=Qa(),N=Yn(),{showToast:P}=xd(),{hasPermission:F}=sd(),[I,L]=(0,y.useState)(!1),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(!0),[ee,H]=(0,y.useState)(!1),[te,ne]=(0,y.useState)(!1),[re,U]=(0,y.useState)(!1),[ie,ae]=(0,y.useState)(!1),[W,oe]=(0,y.useState)(!1),[se,ce]=(0,y.useState)(null),[le,ue]=(0,y.useState)(!1),[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(!1),[he,ge]=(0,y.useState)(null),[_e,ve]=(0,y.useState)(null),[ye,be]=(0,y.useState)(null),[xe,Se]=(0,y.useState)(null),[Ce,we]=(0,y.useState)(10),[Te,Ee]=(0,y.useState)(null),[De,Oe]=(0,y.useState)(!1),[ke,Ae]=(0,y.useState)(!1),[je,Me]=(0,y.useState)(!1),[Ne,Pe]=(0,y.useState)(!1),[Fe,Ie]=(0,y.useState)(!1),Le=(0,y.useCallback)(()=>Pe(!1),[]),[Re,ze]=(0,y.useState)(null),[Be,Ve]=(0,y.useState)(null),[He,Ue]=(0,y.useState)(`n3f`),[We,Ge]=(0,y.useState)(`PLA`),[Ke,qe]=(0,y.useState)(50),[Je,Ye]=(0,y.useState)(4),[Xe,Ze]=(0,y.useState)(!1),[Qe,$e]=(0,y.useState)(null),[et,tt]=(0,y.useState)(!1),[nt,rt]=(0,y.useState)(!1),it=(0,y.useRef)(null),at=(0,y.useRef)(0),[ot,st]=(0,y.useState)(null),[ct,lt]=(0,y.useState)(null),[ut,dt]=(0,y.useState)(null),[ft,pt]=(0,y.useState)(null),[mt,ht]=(0,y.useState)(null),[gt,_t]=(0,y.useState)(!1),[vt,yt]=(0,y.useState)(null),[bt,xt]=(0,y.useState)(!1),[St,Ct]=(0,y.useState)(!1),[wt,Tt]=(0,y.useState)(null),[Et,Dt]=(0,y.useState)(!1),[Ot,kt]=(0,y.useState)(!1),{data:At}=q({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),refetchInterval:3e4}),{data:jt}=q({queryKey:[`firmwareUpdate`,e.id],queryFn:()=>ed.checkPrinterUpdate(e.id),staleTime:300*1e3,refetchInterval:300*1e3,enabled:b&&F(`firmware:read`)}),Mt=(0,y.useMemo)(()=>{let e=new Set;if(At?.ams)for(let t of At.ams)for(let n of t.tray||[])n.tray_info_idx&&e.add(n.tray_info_idx);for(let t of At?.vt_tray??[])t.tray_info_idx&&e.add(t.tray_info_idx);if(At?.nozzle_rack)for(let t of At.nozzle_rack)t.filament_id&&e.add(t.filament_id);return Array.from(e)},[At?.ams,At?.vt_tray,At?.nozzle_rack]),Nt=(0,y.useMemo)(()=>{let e=new Set;if(At?.ams)for(let t of At.ams)for(let n of t.tray||[])n.tray_type&&e.add(n.tray_type.toUpperCase());for(let t of At?.vt_tray??[])t.tray_type&&e.add(t.tray_type.toUpperCase());return e},[At?.ams,At?.vt_tray]),Pt=(0,y.useMemo)(()=>{let e=new Set;if(At?.ams){for(let t of At.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 At?.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},[At?.ams,At?.vt_tray]),{data:Ft}=q({queryKey:[`filamentInfo`,Mt],queryFn:()=>Q.getFilamentInfo(Mt),enabled:Mt.length>0,staleTime:300*1e3}),{data:It}=q({queryKey:[`slotPresets`,e.id],queryFn:()=>Q.getSlotPresets(e.id),staleTime:120*1e3}),Lt=At?.state===`RUNNING`||At?.state===`PAUSE`?At?.current_archive_id??null:null,{data:Rt}=q({queryKey:[`archive-plates`,Lt],queryFn:()=>Q.getArchivePlates(Lt),enabled:Lt!=null,staleTime:300*1e3}),zt=!Rt?.is_multi_plate||At?.current_plate_id==null?null:Rt.plates.find(e=>e.index===At.current_plate_id)?.name||j(`printers.plateNumber`,`Plate {{number}}`,{number:At.current_plate_id}),{data:Bt,refetch:Vt}=q({queryKey:[`amsLabels`,e.id],queryFn:()=>Q.getAmsLabels(e.id),staleTime:300*1e3}),[Ht,Ut]=(0,y.useState)(null);(0,y.useEffect)(()=>{At?.wifi_signal!=null&&Ut(At.wifi_signal)},[At?.wifi_signal]);let Wt=At?.wifi_signal??Ht,Gt=(0,y.useRef)(void 0);(0,y.useEffect)(()=>{At?.connected!==void 0&&(Gt.current=At.connected)},[At?.connected]);let Kt=At?.connected??Gt.current,qt=(0,y.useRef)({});(0,y.useEffect)(()=>{At?.ams_extruder_map&&Object.keys(At.ams_extruder_map).length>0&&(qt.current=At.ams_extruder_map)},[At?.ams_extruder_map]);let Jt=At?.ams_extruder_map&&Object.keys(At.ams_extruder_map).length>0?At.ams_extruder_map:qt.current,Yt=(0,y.useRef)([]);(0,y.useEffect)(()=>{At?.ams&&At.ams.length>0&&(Yt.current=At.ams)},[At?.ams]);let Xt=At?.ams&&At.ams.length>0?At.ams:Yt.current,Zt=(0,y.useRef)(void 0),Qt=At?.tray_now;Qt!==void 0&&Qt!==255?Zt.current=Qt:Qt===255&&(Zt.current=void 0);let $t=Qt!==void 0&&Qt!==255?Qt:Zt.current,{data:en}=q({queryKey:[`smartPlugByPrinter`,e.id],queryFn:()=>Q.getSmartPlugByPrinter(e.id)}),{data:tn}=q({queryKey:[`scriptPlugsByPrinter`,e.id],queryFn:()=>Q.getScriptPlugsByPrinter(e.id)}),{data:nn}=q({queryKey:[`smartPlugStatus`,en?.id],queryFn:()=>en?Q.getSmartPlugStatus(en.id):null,enabled:!!en,refetchInterval:1e4}),{data:rn}=q({queryKey:[`queue`,e.id,`pending`],queryFn:()=>Q.getQueue(e.id,`pending`)}),an=(0,y.useMemo)(()=>rn?.length?IT(rn,Nt,Pt).length:0,[rn,Nt,Pt]),{data:on}=q({queryKey:[`queue`,e.id,`printing`],queryFn:()=>Q.getQueue(e.id,`printing`),enabled:At?.state===`RUNNING`}),{data:sn}=q({queryKey:[`currentPrintUser`,e.id],queryFn:()=>Q.getCurrentPrintUser(e.id),enabled:At?.state===`RUNNING`}),cn=on?.[0]?.created_by_username||sn?.username,{data:ln}=q({queryKey:[`archives`,e.id,`last`],queryFn:()=>Q.getArchives(e.id,1,0),enabled:At?.connected&&At?.state!==`RUNNING`}),un=ln?.[0],dn=At?.state===`RUNNING`||At?.state===`PAUSE`,fn=S&&At?.awaiting_plate_clear===!0,pn=At?.connected&&fn&&!dn,mn=At?.current_print&&dn?$f(At.subtask_name||At.current_print||null,At.gcode_file,j,zt):null,[hn,gn]=(0,y.useState)(null);(0,y.useEffect)(()=>{mn?gn({name:mn,coverUrl:At?.cover_url??null}):fn||gn(null)},[mn,fn,At?.cover_url]);let _n=!S||!At?.connected?null:dn?{label:j(`printers.plateStatus.inUse`),className:`bg-blue-500/20 text-blue-400`}:At.awaiting_plate_clear?{label:j(`printers.plateStatus.notCleared`),className:`bg-yellow-500/20 text-yellow-400`}:{label:j(`printers.plateStatus.cleared`),className:`bg-status-ok/20 text-status-ok`},vn=_n?(0,K.jsx)(`span`,{className:`inline-flex flex-shrink-0 items-center rounded-full px-2 py-0.5 text-[10px] font-medium ${_n.className}`,children:_n.label}):null,yn=t&&Kt===!1,bn=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`)}),xn=J({mutationFn:()=>Q.connectPrinter(e.id),onSuccess:()=>{M.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),Sn=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`)}),Cn=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`)}}),wn=J({mutationFn:({amsId:t,temp:n,duration:r,filament:i,rotateTray:a})=>Q.startDrying(e.id,t,n,r,i,a),onSuccess:()=>{Ve(null),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Tn=J({mutationFn:t=>Q.stopDrying(e.id,t),onSuccess:()=>{M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),En=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`)}),Dn=J({mutationFn:e=>en?Q.controlSmartPlug(en.id,e):Promise.reject(`No plug`),onSuccess:()=>{M.invalidateQueries({queryKey:[`smartPlugStatus`,en?.id]})}}),On=J({mutationFn:e=>en?Q.updateSmartPlug(en.id,{auto_off:e}):Promise.reject(`No plug`),onSuccess:()=>{M.invalidateQueries({queryKey:[`smartPlugByPrinter`,e.id]}),M.invalidateQueries({queryKey:[`smart-plugs`]})}}),kn=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`)}),An=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`)}),jn=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`)}),Mn=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`)}),Nn=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`)}),Pn=J({mutationFn:({target:t,nozzle:n})=>Q.setNozzleTemperature(e.id,t,n),onSuccess:t=>{Se(null),P(t.message),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Fn=J({mutationFn:t=>Q.setBedTemperature(e.id,t),onSuccess:t=>{Se(null),P(t.message),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),In=J({mutationFn:t=>Q.setChamberTemperature(e.id,t),onSuccess:t=>{Se(null),P(t.message),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Ln=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=>{Se(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`)}}),Rn=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=>{Se(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`)}}),zn=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`)}}),Bn=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`)}}),Vn=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`)}}),Hn=J({mutationFn:({distance:t,force:n})=>Q.bedJog(e.id,t,n??!1),onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Un=J({mutationFn:({x:t,y:n})=>Q.xyJog(e.id,t,n),onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Wn=J({mutationFn:t=>Q.extruderJog(e.id,t),onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Gn=J({mutationFn:t=>Q.homeAxes(e.id,t),onSuccess:()=>{try{sessionStorage.setItem(`bambuddy.bedJog.warned.${e.id}`,`1`)}catch{}P(j(`printers.bedJog.homingStarted`))},onError:e=>P(e.message||j(`printers.toast.failedToSendCommand`),`error`)}),Kn=J({mutationFn:t=>Q.updatePrinter(e.id,{plate_detection_enabled:t}),onSuccess:()=>{M.invalidateQueries({queryKey:[`printers`]}),P(Kn.variables?j(`printers.toast.plateCheckEnabled`):j(`printers.toast.plateCheckDisabled`))},onError:e=>P(e.message||j(`printers.toast.failedToUpdateSetting`),`error`)}),qn=(At?.state===`RUNNING`||At?.state===`PAUSE`)&&(At?.printable_objects_count??0)>=2,{data:Jn}=q({queryKey:[`printableObjects`,e.id],queryFn:()=>Q.getPrintableObjects(e.id),enabled:ke||qn,refetchInterval:ke?5e3:qn?3e4:!1}),[Xn,Zn]=(0,y.useState)(null),Qn=(0,y.useRef)(!1),$n=(0,y.useRef)(null),er=(0,y.useRef)(!1),tr=J({mutationFn:({amsId:t,slotId:n})=>Q.refreshAmsSlot(e.id,t,n),onMutate:({amsId:e,slotId:t})=>{$n.current&&clearTimeout($n.current),Qn.current=!1,er.current=!1,Zn({amsId:e,slotId:t}),setTimeout(()=>{er.current=!0},2e3),$n.current=setTimeout(()=>{Zn(null)},3e4)},onSuccess:e=>{P(e.message||j(`printers.toast.rfidRereadInitiated`))},onError:e=>{P(e.message||j(`printers.toast.failedToRereadRfid`),`error`),$n.current&&clearTimeout($n.current),Zn(null)}}),nr=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`)}}),rr=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`)}}),[ir,ar]=(0,y.useState)(null),[or,sr]=(0,y.useState)(null),cr=async()=>{try{ar(await Q.getPlateReferences(e.id))}catch{}},lr=()=>{Kn.mutate(!e.plate_detection_enabled)},ur=async()=>{xt(!0),yt(null);let t=At?.chamber_light===!1;kt(t),t&&(await Q.setChamberLight(e.id,!0),await new Promise(e=>setTimeout(e,2500)));try{yt(await Q.checkPlateEmpty(e.id,{includeDebugImage:!0})),cr()}catch(n){P(n instanceof Error?n.message:j(`printers.toast.failedToCheckPlate`),`error`),t&&(await Q.setChamberLight(e.id,!1),kt(!1))}finally{xt(!1)}},dr=(0,y.useCallback)(async()=>{yt(null),Ot&&(await Q.setChamberLight(e.id,!1),kt(!1))},[Ot,e.id]),fr=async t=>{Ct(!0);try{let n=await Q.calibratePlateDetection(e.id,{label:t});n.success?(P(n.message||j(`printers.toast.calibrationSaved`),`success`),cr(),yt(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{Ct(!1)}},pr=async(t,n)=>{try{await Q.updatePlateReferenceLabel(e.id,t,n),sr(null),cr()}catch(e){P(e instanceof Error?e.message:j(`printers.toast.failedToUpdateLabel`),`error`)}},mr=async t=>{try{await Q.deletePlateReference(e.id,t),P(j(`printers.toast.referenceDeleted`),`success`),cr(),yt(await Q.checkPlateEmpty(e.id,{includeDebugImage:!0}))}catch(e){P(e instanceof Error?e.message:j(`printers.toast.failedToDeleteReference`),`error`)}},hr=async()=>{if(wt){Dt(!0);try{await Q.updatePrinter(e.id,{plate_detection_roi:wt}),P(j(`printers.toast.detectionAreaSaved`),`success`),Tt(null),yt(await Q.checkPlateEmpty(e.id,{includeDebugImage:!0}))}catch(e){P(e instanceof Error?e.message:j(`printers.toast.failedToSaveDetectionArea`),`error`)}finally{Dt(!1)}}};(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&vt&&dr()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[vt,dr]);let gr=(0,y.useRef)(null);if((0,y.useEffect)(()=>{if(!Xn)return;let e=At?.ams_status_main??0;return e!==0&&(Qn.current=!0,gr.current&&=(clearTimeout(gr.current),null)),Qn.current&&e===0&&(er.current?($n.current&&clearTimeout($n.current),Zn(null)):gr.current||=setTimeout(()=>{$n.current&&clearTimeout($n.current),Zn(null)},2e3)),()=>{gr.current&&clearTimeout(gr.current)}},[At?.ams_status_main,Xn]),(0,y.useEffect)(()=>{if(!I)return;let e=e=>{let t=e.target;it.current?.contains(t)||L(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[I]),yn)return null;let _r=()=>{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`}},vr=()=>{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`}},yr=()=>{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`}},br=Kt&&At?.state!==`RUNNING`&&At?.state!==`PAUSE`&&F(`printers:control`),xr=e=>{e.preventDefault(),at.current++,at.current===1&&tt(!0)},Sr=e=>{e.preventDefault(),e.dataTransfer.dropEffect=br?`copy`:`none`},Cr=e=>{e.preventDefault(),at.current--,at.current===0&&tt(!1)},wr=async t=>{if(t.preventDefault(),at.current=0,tt(!1),!br)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}rt(!0);try{let t=await Q.uploadLibraryFile(n,null),r=t.metadata?.sliced_for_model,i=Oq(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}ze({id:t.id,filename:t.filename})}catch{P(j(`common.uploadFailed`,`Upload failed`),`error`)}finally{rt(!1)}},Tr=t=>{r!==`compact`||C||t.target.closest(`button, a, input, select, textarea, [role="button"]`)||E?.(e.id)},Er=`!h-8 !min-h-8 !w-8 !px-0 !py-0`,Dr=({amsId:e,slotId:t,loadTrayId:n,isRefreshing:r,includeRfid:i=!0})=>{let a=At?.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`))&&tr.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)(Cl,{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`))&&nr.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)(Uc,{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`))&&rr.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)(Wc,{className:`w-3 h-3`}),j(`printers.ams.unload`)]})]})},Or=(0,K.jsxs)(`div`,{ref:it,className:`relative flex-shrink-0`,children:[(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>L(!I),title:j(`common.more`,`More`),className:Er,children:(0,K.jsx)(zs,{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`)&&(H(!0),L(!1))},title:F(`printers:update`)?void 0:j(`printers.permission.noEdit`),children:[(0,K.jsx)(pl,{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:()=>{Pe(!0),L(!1)},children:[(0,K.jsx)(kc,{className:`w-4 h-4`}),j(`printers.printerInformation`)]}),(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:()=>{xn.mutate(),L(!1)},children:[(0,K.jsx)(Cl,{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:Sn.isPending,onClick:()=>{Sn.mutate(),L(!1)},children:[(0,K.jsx)(El,{className:`w-4 h-4 ${Sn.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:()=>{U(!0),L(!1)},children:[(0,K.jsx)(lu,{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:()=>{Ie(!0),L(!1)},children:[(0,K.jsx)(ru,{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-400 hover:bg-bambu-dark-tertiary`:`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)(hu,{className:`w-4 h-4`}),j(`common.delete`)]})]})]});return(0,K.jsxs)(pd,{id:`printer-card-${e.id}`,className:`relative flex h-full flex-col ${w?`ring-2 ring-bambu-green`:``} ${C||r===`compact`?`cursor-pointer`:``}`,onClick:Tr,onDragEnter:xr,onDragOver:Sr,onDragLeave:Cr,onDrop:wr,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)($l,{className:`w-5 h-5 text-bambu-green`}):(0,K.jsx)(tu,{className:`w-5 h-5 text-bambu-gray`})}),(et||nt)&&(0,K.jsx)(`div`,{className:`absolute inset-0 z-10 rounded-xl border-2 border-dashed flex items-center justify-center transition-colors ${nt?`bg-bambu-green/10 border-bambu-green/50`:br?`bg-bambu-green/10 border-bambu-green`:`bg-red-500/10 border-red-500/50`}`,children:(0,K.jsx)(`div`,{className:`text-center`,children:nt?(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...`)})]}):br?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(bl,{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)(Pu,{className:`w-8 h-8 mx-auto mb-2 text-red-400`}),(0,K.jsx)(`p`,{className:`text-sm font-medium text-red-400`,children:j(`printers.cannotPrint`,`Printer busy`)})]})})}),(0,K.jsxs)(hd,{className:`${i>=3?`p-5`:``} flex flex-1 flex-col`,children:[(0,K.jsxs)(`div`,{className:yr(),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:PT(e.model),alt:e.model||j(`common.printer`),className:`object-contain rounded-lg flex-shrink-0 ${_r()}`}),(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 ${vr()}`,children:e.name}),r===`compact`&&(()=>{let e=At?.connected&&At.hms_errors?dp(At.hms_errors):[],t=e.some(e=>e.severity<=2),n=e.length>0,r=At?.connected?t?`bg-status-error`:n?`bg-status-warning`:`bg-status-ok`:`bg-status-error`,i=At?.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`&&pn&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>Nn.mutate(),disabled:Nn.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-500/20 border border-yellow-400/40 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:Nn.isPending?(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}):(0,K.jsx)(OK,{className:`w-3 h-3`})})]}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[e.model||`Unknown Model`,r===`expanded`&&At?.nozzles&&At.nozzles[0]?.nozzle_diameter&&(0,K.jsxs)(`span`,{className:`ml-1.5 text-bambu-gray`,title:At.nozzles[0].nozzle_type||`Nozzle`,children:[`• `,At.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)(_s,{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:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 rounded-full text-xs ${At?.connected?`bg-status-ok/20 text-status-ok`:`bg-status-error/20 text-status-error`}`,children:[At?.connected?(0,K.jsx)(Lc,{className:`w-3 h-3`}):(0,K.jsx)(xu,{className:`w-3 h-3`}),At?.connected?j(`printers.connection.connected`):j(`printers.connection.offline`)]}),!At?.connected&&(0,K.jsxs)(`button`,{onClick:()=>Ie(!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)(ru,{className:`w-3 h-3`}),j(`diagnostic.runButton`)]}),At?.connected&&At?.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)(Uo,{className:`w-3 h-3`}),j(`printers.connection.ethernet`,`Ethernet`)]}),At?.connected&&!At?.wired_network&&Wt!=null&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs ${Wt>=-50||Wt>=-60?`bg-status-ok/20 text-status-ok`:Wt>=-70?`bg-status-warning/20 text-status-warning`:Wt>=-80?`bg-orange-500/20 text-orange-600`:`bg-status-error/20 text-status-error`}`,title:`WiFi: ${Wt} dBm - ${j(FT(Wt).labelKey)}`,children:[(0,K.jsx)(Wl,{className:`w-3 h-3`}),Wt,`dBm`]}),At?.connected&&(()=>{let e=At.hms_errors?dp(At.hms_errors):[];return(0,K.jsxs)(`button`,{onClick:()=>ue(!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)(vu,{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)(Nu,{className:`w-3 h-3`}),n.due_count>0||n.warning_count>0?n.due_count+n.warning_count:`OK`]}),an>0&&(0,K.jsxs)(`button`,{onClick:()=>N(`/queue`),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-indigo-500/20 text-indigo-400 hover:opacity-80 transition-opacity`,title:j(`printers.queue.inQueue`,{count:an}),children:[(0,K.jsx)(Nc,{className:`w-3 h-3`}),an]}),b&&jt?.current_version&&jt?.latest_version?(0,K.jsxs)(`button`,{onClick:()=>_t(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs hover:opacity-80 transition-opacity ${jt.update_available?`bg-orange-500/20 text-orange-400`:`bg-status-ok/20 text-status-ok`}`,title:jt.update_available?j(`printers.firmwareUpdateAvailable`,{current:jt.current_version,latest:jt.latest_version}):j(`printers.firmwareUpToDate`,{version:jt.current_version}),children:[jt.update_available?(0,K.jsx)(Is,{className:`w-3 h-3`}):(0,K.jsx)(ls,{className:`w-3 h-3`}),jt.current_version]}):At?.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:At.firmware_version}):null,At?.connected&&[`X1C`,`X1`,`X1E`,`X2D`,`P1S`,`P1P`,`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 ${At.door_open?`bg-yellow-500/20 text-yellow-400`:`bg-status-ok/20 text-status-ok`}`,title:At.door_open?j(`printers.door.open`):j(`printers.door.closed`),children:At.door_open?(0,K.jsx)(Fs,{className:`w-3 h-3`}):(0,K.jsx)(Ps,{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)(pd,{className:`w-full max-w-md mx-4`,children:(0,K.jsxs)(hd,{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-500/20`,children:(0,K.jsx)(vu,{className:`w-5 h-5 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:()=>{bn.mutate({deleteArchives:B}),z(!1),V(!0)},children:`Delete`})]})]})})}),At?.connected&&(0,K.jsxs)(K.Fragment,{children:[r===`compact`?(()=>{let e=At.hms_errors?dp(At.hms_errors):[],t=At.state===`FAILED`||e.length>0,n=At.state===`RUNNING`||At.state===`PAUSE`?Math.max(0,Math.min(100,At.progress||0)):pn||t?100:0,r=At.state===`RUNNING`||At.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`:At.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=!!(At.current_print&&(At.state===`RUNNING`||At.state===`PAUSE`)),n=!t&&fn&&hn,r=t?mn:n?hn.name:null,i=t?At.cover_url:n?hn.coverUrl:null,a=t?At.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:()=>Ae(!0),disabled:!t||(At.printable_objects_count??0)<2||!F(`printers:control`),className:`absolute top-2 right-2 p-1.5 rounded transition-colors z-10 ${t&&(At.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?(At.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)(kT,{className:`w-4 h-4`}),Jn&&Jn.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:Jn.skipped_count})]}),(0,K.jsxs)(`div`,{className:`flex items-stretch gap-2`,children:[(0,K.jsx)(vEe,{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:SEe(At.state,At.stg_cur_name)}),vn]}),(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?At.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:[At.remaining_time!=null&&At.remaining_time>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),yf(At.remaining_time*60)]}),(0,K.jsxs)(`span`,{className:`text-bambu-green font-medium`,title:j(`printers.estimatedCompletion`),children:[`ETA `,vf(At.remaining_time,g,j)]})]}),At.layer_num!=null&&At.total_layers!=null&&At.total_layers>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(Nc,{className:`w-3 h-3`}),At.layer_num,`/`,At.total_layers]}),cn&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,title:`Started by ${cn}`,children:[(0,K.jsx)(Cu,{className:`w-3 h-3`}),cn]})]}):un?(0,K.jsxs)(`p`,{className:`truncate`,title:un.print_name||un.filename,children:[`Last: `,un.print_name||un.filename,un.completed_at&&(0,K.jsxs)(`span`,{className:`ml-1 text-bambu-gray/60`,children:[`• `,hf(un.completed_at,{month:`short`,day:`numeric`})]})]}):(0,K.jsx)(`span`,{children:j(`printers.readyToPrint`)})})]})]}),(0,K.jsx)(gce,{printerId:e.id,printerModel:e.model,loadedFilamentTypes:Nt,loadedFilaments:Pt,variant:`panelExtension`})]})})()]}),At.temperatures&&r===`expanded`&&(()=>{let t=At.temperatures.nozzle_heating||At.temperatures.nozzle_2_heating||!1,n=At.temperatures.bed_heating||!1,r=At.temperatures.chamber_heating||!1,i=e.nozzle_count===2||At.temperatures.nozzle_2!==void 0,a=(()=>{let e=[`nozzle`];return At.temperatures.nozzle_2!==void 0&&e.push(`nozzle_2`),e.push(`bed`),At.temperatures.chamber!==void 0&&e.push(`chamber`),e})(),o=At.active_extruder===1?`L`:`R`,s=At.nozzle_rack?.find(e=>e.id===1),c=At.nozzle_rack?.find(e=>e.id===0),l=c||s,u=At.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=CEe.has(e.model??``),m=[{key:`part`,label:j(`printers.fans.partCooling`),value:At.cooling_fan_speed??0,Icon:Ks,activeClass:`text-cyan-400`},{key:`aux`,label:j(`printers.fans.auxiliary`),value:At.big_fan1_speed??0,Icon:Mu,activeClass:`text-blue-400`},...p?[{key:`chamber`,label:j(`printers.fans.chamber`),value:At.big_fan2_speed??0,Icon:Co,activeClass:`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&&Se(xe===`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(),lt({initialKind:`nozzle`,availableKinds:a})},children:(0,K.jsx)(Xo,{className:`w-2.5 h-2.5`})}),(0,K.jsx)(_q,{className:`w-3.5 h-3.5 mb-0.5`,color:`text-orange-400`,isHeating:t}),At.temperatures.nozzle_2===void 0?l?(0,K.jsx)(gq,{slot:l,index:0,activeStatus:!0,filamentName:l.filament_id?Ft?.[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(At.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(At.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(At.temperatures.nozzle||0),`° / `,Math.round(At.temperatures.nozzle_2||0),`°`]})]}),xe===`nozzle-temp`&&(i?(0,K.jsx)(wq,{title:`Set Nozzle Temperatures`,widthClass:`w-[300px]`,popoverWidth:300,popoverHeight:260,isPending:Pn.isPending,onClose:()=>Se(null),children:(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 px-3 py-2.5`,children:[(0,K.jsx)(Tq,{label:`Left Temp`,current:At.temperatures.nozzle,target:At.temperatures.nozzle_target,isActive:o===`L`,isPending:Pn.isPending,onSubmit:e=>Pn.mutate({target:e,nozzle:1}),options:sp(D,`C`)}),(0,K.jsx)(Tq,{label:`Right Temp`,current:At.temperatures.nozzle_2,target:At.temperatures.nozzle_2_target,isActive:o===`R`,isPending:Pn.isPending,onSubmit:e=>Pn.mutate({target:e,nozzle:0}),options:sp(D,`C`)})]})}):(0,K.jsx)(wq,{title:`Set Nozzle Temperature`,unit:`°C`,customMin:0,customMax:320,isPending:Pn.isPending,options:sp(D,`C`),onClose:()=>Se(null),onSubmit:e=>Pn.mutate({target:e,nozzle:At.active_extruder??0})}))]}),(0,K.jsxs)(`div`,{className:f,title:d,onClick:()=>u&&Se(xe===`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(),lt({initialKind:`bed`,availableKinds:a})},children:(0,K.jsx)(Xo,{className:`w-2.5 h-2.5`})}),(0,K.jsx)(_q,{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(At.temperatures.bed||0),`°C`]}),xe===`bed-temp`&&(0,K.jsx)(wq,{title:`Set Bed Temperature`,unit:`°C`,customMin:0,customMax:140,isPending:Fn.isPending,options:sp(O,`C`),onClose:()=>Se(null),onSubmit:e=>Fn.mutate(e)})]}),At.temperatures.chamber!==void 0&&(()=>{let e=At.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&&Se(xe===`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(),lt({initialKind:`chamber`,availableKinds:a})},children:(0,K.jsx)(Xo,{className:`w-2.5 h-2.5`})}),(0,K.jsx)(_q,{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(At.temperatures.chamber||0),`°C`]}),e&&xe===`chamber-temp`&&(0,K.jsx)(wq,{title:`Set Chamber Temperature`,unit:`°C`,customMin:0,customMax:60,isPending:In.isPending,options:sp(k,`C`),onClose:()=>Se(null),onSubmit:e=>In.mutate(e)})]})})(),i&&(0,K.jsx)(cEe,{leftSlot:s,rightSlot:c,activeNozzle:o,filamentInfo:Ft,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&&Se(xe===`nozzle-select`?null:`nozzle-select`),children:[(0,K.jsx)(gEe,{className:`w-3.5 h-3.5 mb-0.5 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-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-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`)}),xe===`nozzle-select`&&(0,K.jsx)(wq,{title:`Set Nozzle Selection`,widthClass:`w-[300px]`,popoverWidth:300,popoverHeight:140,isPending:Rn.isPending,options:[{label:`Left`,value:1},{label:`Right`,value:0}],onClose:()=>Se(null),onSubmit:e=>Rn.mutate(e)})]})}),At.nozzle_rack&&At.nozzle_rack.some(e=>e.id>=2)&&(0,K.jsx)(lEe,{slots:At.nozzle_rack,filamentInfo:Ft})]}),(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&&Se(xe===`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,`%`]}),xe===`fan-${e}`&&(0,K.jsx)(wq,{title:`Set ${t} Speed`,unit:`%`,customMin:0,customMax:100,isPending:Ln.isPending,options:sp(A,`%`),onClose:()=>Se(null),onSubmit:t=>Ln.mutate({fan:e,speed:t})})]},e)})})]})})(),r===`expanded`&&pn&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>Nn.mutate(),disabled:Nn.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-500/20 border border-yellow-400/40 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:[Nn.isPending?(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}):(0,K.jsx)(OK,{className:`w-4 h-4`}),j(`printers.plateStatus.markCleared`)]}),r===`expanded`&&(()=>{let t=At.state===`RUNNING`,n=At.state===`PAUSE`,r=t||n,i=An.isPending||jn.isPending||Mn.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:()=>zn.mutate(!At.chamber_light),disabled:!At.connected||zn.isPending||!F(`printers:control`),className:`${o} ${At.chamber_light?`bg-yellow-500/10 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`)?At.chamber_light?j(`printers.chamberLightOff`):j(`printers.chamberLightOn`):j(`printers.permission.noControl`),children:(0,K.jsx)(OT,{on:At.chamber_light??!1,className:`w-4 h-4`})}),[`P2S`,`X2D`,`H2D`,`H2C`,`H2S`].includes(e.model??``)&&(()=>{let t=At.airduct_mode===1,n=t?ec:Zl,r=t?`text-orange-400`:`text-sky-400`,i=t?`bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:`bg-sky-500/10 text-sky-400 hover:bg-sky-500/20`;return(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{onClick:()=>ve(_e===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}`})}),_e===e.id&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>ve(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:()=>{Vn.mutate(e),ve(null)},className:`w-full text-left px-3 py-1.5 text-xs transition-colors flex items-center gap-2 ${At.airduct_mode===n?`text-bambu-green bg-bambu-green/10`:`text-white hover:bg-bambu-dark-tertiary`}`,children:[e===`heating`?(0,K.jsx)(ec,{className:`w-3 h-3`}):(0,K.jsx)(Zl,{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-500/15 text-indigo-300 transition-colors hover:bg-indigo-500/30 disabled:cursor-not-allowed disabled:opacity-50`,a=t=>{let n=t*Ce*1,r=`bambuddy.bedJog.warned.${e.id}`;(()=>{try{return sessionStorage.getItem(r)===`1`}catch{return!1}})()?Hn.mutate({distance:n,force:!0}):Ee({distance:n})},s=(e,t)=>{Un.mutate({x:e,y:t})},c=e=>{Wn.mutate(e)};return(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{onClick:()=>be(ye===e.id?null:e.id),disabled:n,className:`${o} ${n?`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`:`bg-indigo-500/10 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)(il,{className:`w-4 h-4`})}),ye===e.id&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>be(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.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,Ce),disabled:Un.isPending,className:i,"aria-label":`Move Y forward`,children:(0,K.jsx)(Mo,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{}),(0,K.jsx)(`button`,{onClick:()=>s(-Ce,0),disabled:Un.isPending,className:i,"aria-label":`Move X left`,children:(0,K.jsx)(Do,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{be(null),Gn.mutate(`all`)},disabled:Gn.isPending,className:i,"aria-label":j(`printers.bedJog.homeZ`),children:(0,K.jsx)(Tc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>s(Ce,0),disabled:Un.isPending,className:i,"aria-label":`Move X right`,children:(0,K.jsx)(ko,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{}),(0,K.jsx)(`button`,{onClick:()=>s(0,-Ce),disabled:Un.isPending,className:i,"aria-label":`Move Y back`,children:(0,K.jsx)(Eo,{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:Hn.isPending,className:i,"aria-label":j(`printers.bedJog.up`),children:(0,K.jsx)(Mo,{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)(Nc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(1),disabled:Hn.isPending,className:i,"aria-label":j(`printers.bedJog.down`),children:(0,K.jsx)(Eo,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>c(-Ce),disabled:Wn.isPending,className:i,"aria-label":`Retract filament`,children:(0,K.jsx)(Mo,{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(Ce),disabled:Wn.isPending,className:i,"aria-label":`Extrude filament`,children:(0,K.jsx)(Eo,{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:()=>we(e),className:`flex-1 px-1 py-1 rounded text-[10px] transition-colors ${Ce===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:lr,disabled:!At.connected||Kn.isPending||!F(`printers:update`),className:`${o} rounded-r-none ${e.plate_detection_enabled?`bg-green-500/10 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:Kn.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(jl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:ur,disabled:!At.connected||bt||!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-500/10 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:bt?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(es,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{"data-testid":`speed-control`,onClick:()=>ge(he===e.id?null:e.id),disabled:!r||!F(`printers:control`),className:`${o} ${r?`bg-amber-500/10 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)(uc,{className:`w-4 h-4`})}),he===e.id&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>ge(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:()=>{Bn.mutate(e),ge(null)},className:`w-full text-left px-3 py-1.5 text-xs transition-colors ${At.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?Oe(!0):me(!0),disabled:e,className:` ${s} ${e?a:n?`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`:`bg-yellow-500/20 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)(hl,{className:`w-3 h-3`}):(0,K.jsx)(ul,{className:`w-3 h-3`}),j(n?`printers.resume`:`printers.pause`)]})})(),(()=>{let e=!r||i||!F(`printers:control`);return(0,K.jsxs)(`button`,{onClick:()=>fe(!0),disabled:e,className:` ${s} ${e?a:`bg-red-500/20 text-red-400 hover:bg-red-500/30`} - `,title:F(`printers:control`)?j(`printers.stop`):j(`printers.permission.noControl`),children:[(0,K.jsx)(tu,{className:`w-3 h-3`}),j(`printers.stop`)]})})()]})]})]})})(),(Xt?.length>0||At.vt_tray.length>0)&&r===`expanded`&&(()=>{let t=Xt.filter(e=>e.tray.length>1),n=Xt.filter(e=>e.tray.length===1),r=e.nozzle_count===2||At?.temperatures?.nozzle_2!==void 0,i=`min-w-14`,g=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)(_Ee,{state:At.ams_filament_backup,canToggle:F(`printers:control`),pending:En.isPending,onToggle:e=>En.mutate(e)}),(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=Jt[String(t.id)],_=t.id>=128?t.id-128:t.id,v=n===void 0?_:n,y=v===1,b=v===0;return(0,K.jsxs)(`div`,{style:g(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)(kq,{ams:t,printerId:e.id,label:bq(t.id,t.tray.length),amsLabels:Bt,canEdit:F(`printers:update`),onSaved:Vt,children:(0,K.jsx)(`span`,{className:`block truncate text-[10px] text-white font-medium cursor-default select-none`,children:Bt?.[t.id]||bq(t.id,t.tray.length)})}),r&&(y||b)&&(0,K.jsx)(pq,{side:y?`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)(vq,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>st({amsId:t.id,amsLabel:bq(t.id,t.tray.length),mode:`humidity`}),compact:!0}),t.temp!=null&&(0,K.jsx)(`div`,{className:`mr-1`,children:(0,K.jsx)(yq,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>st({amsId:t.id,amsLabel:bq(t.id,t.tray.length),mode:`temperature`}),compact:!0})}),At.supports_drying&&(t.module_type===`n3f`||t.module_type===`n3s`)&&F(`printers:control`)&&(0,K.jsx)(`button`,{disabled:!!(t.dry_sf_reason?.length&&t.dry_time===0),onClick:e=>{if(t.dry_time>0)Tn.mutate(t.id);else if(Be===t.id)Ve(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;Ge(n),qe(r[i]||r.n3f),Ye(i===`n3s`?r.n3s_hours:r.n3f_hours),Ze(!1),Ue(t.module_type),Ve(t.id),$e(ep({triggerRect:e.currentTarget.getBoundingClientRect(),popoverWidth:uq,estimatedHeight:dq,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-500/20 text-amber-400`: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: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)(ec,{className:`w-3 h-3`})})]})]}),t.dry_time>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-amber-500/10 px-2 py-1 text-[9px]`,children:[(0,K.jsx)(ec,{className:`w-3 h-3 text-amber-400 shrink-0`}),(0,K.jsx)(`span`,{className:`text-amber-400 font-medium`,children:j(`printers.drying.active`)}),(0,K.jsx)(`span`,{className:`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`})}),(0,K.jsx)(`button`,{onClick:()=>Tn.mutate(t.id),disabled:Tn.isPending,className:`ml-auto text-amber-400 hover:text-amber-300 transition-colors disabled:opacity-50`,title:j(`printers.drying.stop`),children:(0,K.jsx)(Pu,{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),g=a?.tray_type&&a.remain>=0,_=!a?.tray_type,v=xq(a),y=t.id*4+r,b=$t===y,x=a?.tray_info_idx?Ft?.[a.tray_info_idx]:null,S=It?.[y],C=(a?.tray_uuid||a?.tag_uid||VK(e.serial_number,t.id,r))?.toUpperCase(),w=C?s?.[C]:void 0,T=zK(w),E=o&&!m?p?.find(n=>n.printer_id===e.id&&n.ams_id===t.id&&n.tray_id===r):void 0,D=E?f?.find(e=>e.id===E.spoolman_spool_id):void 0,O=D&&(D.label_weight??0)>0?Math.round(Math.max(0,(D.label_weight??0)-D.weight_used)/(D.label_weight??1)*100):null,k=u?.(e.id,t.id,r),A=(()=>{let e=k?.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})(),M=A===0&&g&&a.remain>0?null:A,N=T??O??M??(g?a.remain:null),P=T!==null||O!==null?`spoolman`:M===null?g?`ams`:void 0:`inventory`,I=a?.tray_type?{vendor:qK(a)?`Bambu Lab`:`Generic`,profile:S?.preset_name||(D?[D.brand,D.slicer_filament_name?.split(`@`)[0].trim()||D.material].filter(Boolean).join(` `).trim():null)||k?.spool?.slicer_filament_name||x?.name||a.tray_sub_brands||a.tray_type,colorName:Vd(a.tray_color||``),colorHex:a.tray_color||null,kFactor:fq(a.k),fillLevel:N,trayUuid:a.tray_uuid||null,tagUid:a.tag_uid||null,fillSource:P}:null,L=Xn?.amsId===t.id&&Xn?.slotId===r,R=(0,K.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${_?`opacity-50`:``} ${b?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[(0,K.jsx)(lq,{trayColor:a?.tray_color,trayType:a?.tray_type,isEmpty:_,emptyKind:v,slotNumber:r+1}),(0,K.jsx)(`div`,{className:`text-[9px] text-white font-bold truncate`,children:a?.tray_type||j(v===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,K.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:N!==null&&N>=0&&!_&&a&&(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${N}%`,backgroundColor:RK(N)}})})]});return(0,K.jsxs)(`div`,{className:`relative group w-full ${i}`,children:[L&&(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)(Cl,{className:`w-4 h-4 text-bambu-green animate-spin`})}),I?(0,K.jsx)(JG,{data:I,actions:Dr({amsId:t.id,slotId:r,loadTrayId:t.id*4+r,isRefreshing:L}),spoolman:{enabled:o,linkedSpoolId:E?.spoolman_spool_id??(C?s?.[C]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!E&&!k?()=>{let n=(I.trayUuid||I.tagUid||VK(e.serial_number,t.id,r)).toUpperCase();dt({tagUid:I.tagUid||n,trayUuid:I.trayUuid||``,printerId:e.id,amsId:t.id,trayId:r})}:void 0,onUnlinkSpool:w?.id?()=>Cn.mutate(w.id):void 0},inventory:(()=>{if(o){if(m)return;let n=E,i=D;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:()=>pt({printerId:e.id,amsId:t.id,trayId:r,trayInfo:{type:a?.tray_type||I.profile,material:a?.tray_type??void 0,profile:I.profile,color:I.colorHex||``,location:`${bq(t.id,t.tray.length)} Slot ${r+1}`}}),onUnassignSpool:i&&!qK(a)?()=>h?.(i.id):void 0,isAssigned:!!n||qK(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:()=>pt({printerId:e.id,amsId:t.id,trayId:r,trayInfo:{type:a?.tray_type||I.profile,material:a?.tray_type??void 0,profile:I.profile,color:I.colorHex||``,location:`${bq(t.id,t.tray.length)} Slot ${r+1}`}}),onUnassignSpool:n&&!qK(a)?()=>d?.(e.id,t.id,r):void 0,isAssigned:!!n||qK(a)}})(),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({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:S?.preset_id})},children:R}):(0,K.jsx)(YG,{kind:v??void 0,actions:Dr({amsId:t.id,slotId:r,loadTrayId:t.id*4+r,isRefreshing:L}),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({amsId:t.id,trayId:r,trayCount:t.tray.length,extruderId:n})},onAssignSpool:()=>pt({printerId:e.id,amsId:t.id,trayId:r,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`${bq(t.id,t.tray.length)} Slot ${r+1}`}}),children:R})]},r)})})]},t.id)}),n.map(t=>{let n=Jt[String(t.id)],i=t.id>=128?t.id-128:t.id,g=n===void 0?i:n,_=g===1,v=g===0,y=t.tray[0],b=y?.tray_type&&y.remain>=0,S=!y?.tray_type,C=xq(y),w=LK(t.id,y?.id??0,!1),T=$t===w,E=y?.tray_info_idx?Ft?.[y.tray_info_idx]:null,D=It?.[w],O=y?.id??0,k=(y?.tray_uuid||y?.tag_uid||VK(e.serial_number,t.id,O))?.toUpperCase(),A=k?s?.[k]:void 0,M=zK(A),N=u?.(e.id,t.id,O),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&&b&&y.remain>0?null:P,L=o&&!m?p?.find(n=>n.printer_id===e.id&&n.ams_id===t.id&&n.tray_id===O):void 0,R=L?f?.find(e=>e.id===L.spoolman_spool_id):void 0,z=R&&(R.label_weight??0)>0?Math.round(Math.max(0,(R.label_weight??0)-R.weight_used)/(R.label_weight??1)*100):null,B=M??z??I??(b?y.remain:null),V=M!==null||z!==null?`spoolman`:I===null?b?`ams`:void 0:`inventory`,ee=y?.tray_type?{vendor:qK(y)?`Bambu Lab`:`Generic`,profile:D?.preset_name||(R?[R.brand,R.slicer_filament_name?.split(`@`)[0].trim()||R.material].filter(Boolean).join(` `).trim():null)||N?.spool?.slicer_filament_name||E?.name||y.tray_sub_brands||y.tray_type,colorName:Vd(y.tray_color||``),colorHex:y.tray_color||null,kFactor:fq(y.k),fillLevel:B,trayUuid:y.tray_uuid||null,tagUid:y.tag_uid||null,fillSource:V}:null,H=Xn?.amsId===t.id&&Xn?.slotId===O,te=(0,K.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${S?`opacity-50`:``} ${T?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[(0,K.jsx)(lq,{trayColor:y?.tray_color,trayType:y?.tray_type,isEmpty:S,emptyKind:C,slotNumber:1}),(0,K.jsx)(`div`,{className:`text-[9px] text-white font-bold truncate`,children:y?.tray_type||j(C===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,K.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:B!==null&&B>=0&&!S&&(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${B}%`,backgroundColor:RK(B)}})})]});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)(kq,{ams:t,printerId:e.id,label:bq(t.id,t.tray.length),amsLabels:Bt,canEdit:F(`printers:update`),onSaved:Vt,children:(0,K.jsx)(`span`,{className:`block truncate text-[10px] text-white font-medium cursor-default select-none`,children:Bt?.[t.id]||bq(t.id,t.tray.length)})}),r&&(_||v)&&(0,K.jsx)(pq,{side:_?`L`:`R`})]}),At.supports_drying&&(t.module_type===`n3f`||t.module_type===`n3s`)&&F(`printers:control`)&&(0,K.jsx)(`div`,{className:`relative ml-auto`,children:(0,K.jsx)(`button`,{onClick:e=>{if(t.dry_time>0)Tn.mutate(t.id);else if(Be===t.id)Ve(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;Ge(n),qe(r[i]||r.n3f),Ye(i===`n3s`?r.n3s_hours:r.n3f_hours),Ze(!1),Ue(t.module_type),Ve(t.id),$e(ep({triggerRect:e.currentTarget.getBoundingClientRect(),popoverWidth:uq,estimatedHeight:dq,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-500/20 text-amber-400`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark/80`}`,title:t.dry_time>0?j(`printers.drying.stop`):j(`printers.drying.start`),children:(0,K.jsx)(ec,{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-500/10 px-2 py-1 text-[9px]`,children:[(0,K.jsx)(ec,{className:`w-3 h-3 text-amber-400 shrink-0`}),(0,K.jsx)(`span`,{className:`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`}),(0,K.jsx)(`button`,{onClick:()=>Tn.mutate(t.id),disabled:Tn.isPending,className:`ml-auto text-amber-400 hover:text-amber-300 transition-colors disabled:opacity-50 shrink-0`,title:j(`printers.drying.stop`),children:(0,K.jsx)(Pu,{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:[H&&(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)(Cl,{className:`w-4 h-4 text-bambu-green animate-spin`})}),ee?(0,K.jsx)(JG,{data:ee,actions:Dr({amsId:t.id,slotId:O,loadTrayId:t.id*4+O,isRefreshing:H}),spoolman:{enabled:o,linkedSpoolId:L?.spoolman_spool_id??(k?s?.[k]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!L&&!N?()=>{let n=(ee.trayUuid||ee.tagUid||VK(e.serial_number,t.id,O)).toUpperCase();dt({tagUid:ee.tagUid||n,trayUuid:ee.trayUuid||``,printerId:e.id,amsId:t.id,trayId:O})}:void 0,onUnlinkSpool:A?.id?()=>Cn.mutate(A.id):void 0},inventory:(()=>{if(o){if(m)return;let n=L,r=R;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:()=>pt({printerId:e.id,amsId:t.id,trayId:O,trayInfo:{type:y?.tray_type||ee.profile,material:y?.tray_type??void 0,profile:ee.profile,color:ee.colorHex||``,location:bq(t.id,t.tray.length)}}),onUnassignSpool:r&&!qK(y)?()=>h?.(r.id):void 0,isAssigned:!!n||qK(y)}}let n=u?.(e.id,t.id,O);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:()=>pt({printerId:e.id,amsId:t.id,trayId:O,trayInfo:{type:y?.tray_type||ee.profile,material:y?.tray_type??void 0,profile:ee.profile,color:ee.colorHex||``,location:bq(t.id,t.tray.length)}}),onUnassignSpool:n&&!qK(y)?()=>d?.(e.id,t.id,O):void 0,isAssigned:!!n||qK(y)}})(),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({amsId:t.id,trayId:O,trayCount:t.tray.length,trayType:y?.tray_type||void 0,trayColor:y?.tray_color||void 0,traySubBrands:y?.tray_sub_brands||void 0,trayInfoIdx:y?.tray_info_idx||void 0,extruderId:n,caliIdx:y?.cali_idx,savedPresetId:D?.preset_id})},children:te}):(0,K.jsx)(YG,{kind:C??void 0,actions:Dr({amsId:t.id,slotId:O,loadTrayId:t.id*4+O,isRefreshing:H}),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({amsId:t.id,trayId:O,trayCount:t.tray.length,extruderId:n})},onAssignSpool:()=>pt({printerId:e.id,amsId:t.id,trayId:O,trayInfo:{type:``,material:void 0,profile:``,color:``,location:bq(t.id,t.tray.length)}}),children:te})]}),(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)(yq,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>st({amsId:t.id,amsLabel:bq(t.id,t.tray.length),mode:`temperature`}),compact:!0}),t.humidity!=null&&(0,K.jsx)(vq,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>st({amsId:t.id,amsLabel:bq(t.id,t.tray.length),mode:`humidity`}),compact:!0})]})]})]},t.id)}),At.vt_tray.length>0&&(0,K.jsxs)(`div`,{style:g(At.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 ${At.vt_tray.length>1?`grid-cols-[repeat(2,minmax(3.5rem,1fr))]`:`grid-cols-[minmax(3.5rem,1fr)]`} gap-1`,children:[...At.vt_tray].sort((e,t)=>(e.id??254)-(t.id??254)).map(t=>{let n=t.id??254,a=r&&$t===254?n===254&&At.active_extruder===1||n===255&&At.active_extruder===0:$t===n,g=n-254,_=r?j(n===254?`printers.extL`:`printers.extR`):``,v=t.tray_info_idx?Ft?.[t.tray_info_idx]:null,y=It?.[1020+g],b=(t.tray_uuid||t.tag_uid||VK(e.serial_number,255,g))?.toUpperCase(),x=b?s?.[b]:void 0,S=zK(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:qK(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:Vd(t.tray_color||``),colorHex:t.tray_color||null,kFactor:fq(t.k),fillLevel:A,trayUuid:t.tray_uuid||null,tagUid:t.tag_uid||null,fillSource:M},P=!t.tray_type,I=xq(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)(lq,{trayColor:t.tray_color,trayType:t.tray_type,isEmpty:P,emptyKind:I,slotNumber: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:RK(A)}})}),_&&(0,K.jsx)(`div`,{className:`text-[7px] text-white/40 mt-0.5 truncate`,children:_})]});return(0,K.jsx)(`div`,{className:`relative group w-full ${i}`,children:P?(0,K.jsx)(YG,{kind:I??void 0,actions:Dr({amsId:255,slotId:g,loadTrayId:n,includeRfid:!1}),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({amsId:255,trayId:g,trayCount:1,extruderId:r?+(n===254):void 0})},onAssignSpool:()=>pt({printerId:e.id,amsId:255,trayId:g,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`External Slot ${g+1}`}}),children:L}):(0,K.jsx)(JG,{data:N,actions:Dr({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||VK(e.serial_number,255,g)).toUpperCase();dt({tagUid:N.tagUid||t,trayUuid:N.trayUuid||``,printerId:e.id,amsId:255,trayId:g})}:void 0,onUnlinkSpool:x?.id?()=>Cn.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:()=>pt({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&&!qK(t)?()=>h?.(r.id):void 0,isAssigned:!!n||qK(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:()=>pt({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&&!qK(t)?()=>d?.(e.id,255,g):void 0,isAssigned:!!n||qK(t)}})(),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({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:[en&&(0,K.jsxs)(`div`,{className:`pt-4`,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)(Iu,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm text-white truncate`,children:en.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:nn?.energy?.power!==null&&nn?.energy?.power!==void 0?`${Math.round(nn.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:()=>On.mutate(!en.auto_off),disabled:On.isPending||en.auto_off_executed||!F(`smart_plugs:control`),title:F(`smart_plugs:control`)?en.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`)?en.auto_off||en.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)(_s,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{nn?.state===`ON`?oe(!0):ae(!0)},disabled:Dn.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`)?nn?.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`)?nn?.state===`ON`?`Turn off`:`Turn on`:j(`printers.permission.noSmartPlugControl`),children:(0,K.jsx)(Iu,{className:`w-4 h-4`})})]})]}),tn&&tn.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,K.jsx)(Tc,{className:`w-3.5 h-3.5 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:tn.map(e=>{let t=e.ha_entity_id?.startsWith(`script.`);return(0,K.jsxs)(`button`,{onClick:()=>{t?kn.mutate({id:e.id,action:`on`}):ce(e)},disabled:kn.isPending,title:`${t?`Run`:`Toggle`} ${e.ha_entity_id}`,className:`px-2 py-0.5 text-xs bg-blue-500/20 text-blue-400 hover:bg-blue-500/30 rounded transition-colors flex items-center gap-1`,children:[(0,K.jsx)(hl,{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:[Or,(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:!At?.connected||!F(`camera:view`),title:F(`camera:view`)?j(_===`embedded`?`printers.openCameraOverlay`:`printers.openCameraWindow`):j(`printers.permission.noCamera`),className:Er,children:(0,K.jsx)(Tu,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>ne(!0),disabled:!Kt||!F(`printers:files`),title:F(`printers:files`)?j(`printers.browseFiles`):j(`printers.permission.noFiles`),className:Er,children:(0,K.jsx)(yc,{className:`w-4 h-4`})}),Kt&&At?.state!==`RUNNING`&&At?.state!==`PAUSE`&&(0,K.jsxs)($,{size:`sm`,onClick:()=>Me(!0),disabled:!F(`printers:control`),title:F(`printers:control`)?j(`common.print`):j(`printers.permission.noControl`),className:`!h-8 !min-h-8 !px-2 !py-0 !bg-bambu-green hover:!bg-bambu-green/80 !text-white`,children:[(0,K.jsx)(bl,{className:`w-4 h-4`}),j(`common.print`)]})]})]})]})]})]}),te&&(0,K.jsx)(cce,{printerId:e.id,printerName:e.name,onClose:()=>ne(!1)}),je&&(0,K.jsx)(kK,{folderId:null,onClose:()=>Me(!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=Oq(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});ze({id:t.id,filename:t.filename})}}),Re&&(0,K.jsx)(sq,{mode:`reprint`,libraryFileId:Re.id,archiveName:Re.filename,initialSelectedPrinterIds:[e.id],onClose:()=>ze(null),onSuccess:()=>ze(null),cleanupLibraryAfterDispatch:!0}),re&&(0,K.jsx)(hce,{printerId:e.id,printerName:e.name,onClose:()=>U(!1)}),Fe&&(0,K.jsx)(Df,{printerId:e.id,printerName:e.name,onClose:()=>Ie(!1)}),Ne&&(0,K.jsx)(oEe,{printer:e,status:At,totalPrintHours:n?.total_print_hours,onClose:Le}),vt&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>dr(),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:[vt.needs_calibration?(0,K.jsx)(jl,{className:`w-5 h-5 text-blue-500`}):vt.is_empty?(0,K.jsx)(ls,{className:`w-5 h-5 text-green-500`}):(0,K.jsx)(ms,{className:`w-5 h-5 text-yellow-500`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:`Build Plate Check`}),vt.reference_count!==void 0&&vt.max_references&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[vt.reference_count,`/`,vt.max_references,` refs`]})]}),(0,K.jsx)(`button`,{onClick:()=>dr(),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[vt.needs_calibration?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`p-3 rounded-lg bg-blue-500/20 border border-blue-500/50`,children:[(0,K.jsx)(`p`,{className:`font-medium 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 ${vt.is_empty?`bg-green-500/20 border border-green-500/50`:`bg-yellow-500/20 border border-yellow-500/50`}`,children:[(0,K.jsx)(`p`,{className:`font-medium ${vt.is_empty?`text-green-400`:`text-yellow-400`}`,children:vt.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(vt.confidence*100),`% | `,j(`printers.plateDetection.difference`),`: `,vt.difference_percent.toFixed(1),`%`]})]}),vt.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:vt.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:vt.message})]}),ir&&ir.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:ir.references.length,max:ir.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:ir.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:()=>mr(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)(Pu,{className:`w-3 h-3 text-white`})}),or?.index===t.index?(0,K.jsx)(`input`,{type:`text`,value:or.label,onChange:e=>sr({...or,label:e.target.value}),onBlur:()=>pr(t.index,or.label),onKeyDown:e=>{e.key===`Enter`&&pr(t.index,or.label),e.key===`Escape`&&sr(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:()=>sr({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?mf(t.timestamp)?.toLocaleDateString()??``:``})]},t.index))})]}),!vt.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`})]}),wt?(0,K.jsxs)(`div`,{className:`flex gap-1`,children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>Tt(null),disabled:Et,children:j(`common.cancel`)}),(0,K.jsx)($,{size:`sm`,onClick:hr,disabled:Et,children:Et?(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}):j(`common.save`)})]}):(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>Tt(vt.roi||{x:.15,y:.35,w:.7,h:.55}),children:[(0,K.jsx)(pl,{className:`w-3 h-3 mr-1`}),j(`common.edit`)]})]}),wt?(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:wt.x,onChange:e=>Tt({...wt,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(wt.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:wt.y,onChange:e=>Tt({...wt,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(wt.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:wt.w,onChange:e=>Tt({...wt,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(wt.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:wt.h,onChange:e=>Tt({...wt,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(wt.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((vt.roi?.x||.15)*100),`%, Y=`,Math.round((vt.roi?.y||.35)*100),`%, W=`,Math.round((vt.roi?.w||.7)*100),`%, H=`,Math.round((vt.roi?.h||.55)*100),`%`]})]})]}),(0,K.jsx)(`div`,{className:`flex justify-end gap-2 p-4`,children:vt.needs_calibration?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)($,{variant:`ghost`,onClick:()=>dr(),children:j(`common.cancel`)}),(0,K.jsx)($,{onClick:()=>fr(),disabled:St,children:St?(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:()=>fr(),disabled:St,children:St?`Adding...`:`Add Reference (${ir?.references.length||0}/${ir?.max_references||5})`}),(0,K.jsx)($,{onClick:()=>dr(),children:`Close`})]})})]})}),ie&&en&&(0,K.jsx)(Ed,{title:j(`printers.confirm.powerOnTitle`),message:j(`printers.confirm.powerOnMessage`,{name:e.name}),confirmText:j(`printers.confirm.powerOnButton`),variant:`default`,onConfirm:()=>{Dn.mutate(`on`),ae(!1)},onCancel:()=>ae(!1)}),W&&en&&(0,K.jsx)(Ed,{title:j(`printers.confirm.powerOffTitle`),message:At?.state===`RUNNING`?j(`printers.confirm.powerOffWarning`,{name:e.name}):j(`printers.confirm.powerOffMessage`,{name:e.name}),confirmText:j(`printers.confirm.powerOffButton`),variant:`danger`,onConfirm:()=>{Dn.mutate(`off`),oe(!1)},onCancel:()=>oe(!1)}),se&&(0,K.jsx)(Ed,{title:j(`printers.confirm.haToggleTitle`,{name:se.name}),message:At?.state===`RUNNING`?j(`printers.confirm.haToggleWarning`,{name:e.name,entity:se.ha_entity_id||se.name}):j(`printers.confirm.haToggleMessage`,{entity:se.ha_entity_id||se.name}),confirmText:j(`printers.confirm.haToggleButton`),variant:At?.state===`RUNNING`?`danger`:`default`,onConfirm:()=>{kn.mutate({id:se.id,action:`toggle`}),ce(null)},onCancel:()=>ce(null)}),de&&(0,K.jsx)(Ed,{title:j(`printers.confirm.stopTitle`),message:j(`printers.confirm.stopMessage`,{name:e.name}),confirmText:j(`printers.confirm.stopButton`),variant:`danger`,onConfirm:()=>{An.mutate(),fe(!1)},onCancel:()=>fe(!1)}),pe&&(0,K.jsx)(Ed,{title:j(`printers.confirm.pauseTitle`),message:j(`printers.confirm.pauseMessage`,{name:e.name}),confirmText:j(`printers.confirm.pauseButton`),variant:`default`,onConfirm:()=>{jn.mutate(),me(!1)},onCancel:()=>me(!1)}),De&&(0,K.jsx)(Ed,{title:j(`printers.confirm.resumeTitle`),message:j(`printers.confirm.resumeMessage`,{name:e.name}),confirmText:j(`printers.confirm.resumeButton`),variant:`default`,onConfirm:()=>{Mn.mutate(),Oe(!1)},onCancel:()=>Oe(!1)}),Te&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl w-full max-w-sm p-5`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,K.jsx)(vu,{className:`w-5 h-5 text-yellow-400 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-white mb-1`,children:j(`printers.bedJog.notHomedTitle`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray leading-relaxed`,children:j(`printers.bedJog.notHomedMessage`)})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>{Gn.mutate(`all`),Ee(null)},className:`w-full px-3 py-2 rounded-lg text-xs font-medium bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 transition-colors`,children:j(`printers.bedJog.homeZ`)}),(0,K.jsx)(`button`,{onClick:()=>{let t=Te.distance;try{sessionStorage.setItem(`bambuddy.bedJog.warned.${e.id}`,`1`)}catch{}Hn.mutate({distance:t,force:!0}),Ee(null)},className:`w-full px-3 py-2 rounded-lg text-xs font-medium bg-yellow-500/20 text-yellow-400 hover:bg-yellow-500/30 transition-colors`,children:j(`printers.bedJog.moveAnyway`)}),(0,K.jsx)(`button`,{onClick:()=>Ee(null),className:`w-full px-3 py-2 rounded-lg text-xs font-medium bg-bambu-dark text-bambu-gray hover:bg-bambu-dark-tertiary transition-colors`,children:j(`common.cancel`)})]})]})}),(0,K.jsx)(AT,{printerId:e.id,isOpen:ke,onClose:()=>Ae(!1)}),le&&(0,K.jsx)(pp,{printerName:e.name,errors:At?.hms_errors||[],onClose:()=>ue(!1),printerId:e.id,hasPermission:F}),ot&&(0,K.jsx)(bTe,{isOpen:!!ot,onClose:()=>st(null),printerId:e.id,printerName:e.name,amsId:ot.amsId,amsLabel:ot.amsLabel,initialMode:ot.mode,thresholds:a}),ct&&(0,K.jsx)(STe,{isOpen:!!ct,onClose:()=>lt(null),printerId:e.id,printerName:e.name,initialKind:ct.initialKind,availableKinds:ct.availableKinds}),ut&&(0,K.jsx)(XG,{isOpen:!!ut,onClose:()=>dt(null),tagUid:ut.tagUid,trayUuid:ut.trayUuid,printerId:ut.printerId,amsId:ut.amsId,trayId:ut.trayId}),ft&&(0,K.jsx)(QG,{isOpen:!!ft,onClose:()=>pt(null),printerId:ft.printerId,amsId:ft.amsId,trayId:ft.trayId,trayInfo:ft.trayInfo,spoolmanEnabled:!!o}),mt&&(0,K.jsx)(DK,{isOpen:!!mt,onClose:()=>ht(null),printerId:e.id,slotInfo:mt,printerModel:Oq(e.model)||void 0,onSuccess:()=>{M.invalidateQueries({queryKey:[`slotPresets`,e.id]}),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),ee&&(0,K.jsx)(TEe,{printer:e,onClose:()=>H(!1)}),gt&&jt&&(0,K.jsx)(wEe,{printer:e,firmwareInfo:jt,onClose:()=>_t(!1)}),Be!==null&&Qe&&(()=>{let e=He===`n3s`?85:65,t=e+10;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-[100]`,onClick:()=>Ve(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:Qe.top,left:Qe.left,maxHeight:`calc(100dvh - ${Qe.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)(ec,{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)(Sq,{value:We,options:Object.keys(x).map(e=>({value:e,label:e})),onChange:e=>{Ge(e);let t=x[e];t&&(qe(t[He===`n3s`?`n3s`:`n3f`]),Ye(He===`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:Ke,onChange:t=>qe(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:Ke,onChange:t=>qe(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:Je,onChange:e=>Ye(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:Je,onChange:e=>Ye(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`})]})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>Ze(e=>!e),"aria-pressed":Xe,className:`h-8 w-full rounded-lg border px-2 text-sm font-medium transition-colors ${Xe?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,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:()=>{Be!==null&&wn.mutate({amsId:Be,temp:Ke,duration:Je,filament:We,rotateTray:Xe})},disabled:wn.isPending,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:wn.isPending?j(`printers.drying.startingDrying`):j(`printers.drying.start`)})})]})]})})()]})}function CEe({onClose:e,onAdd:t,existingSerials:n}){let{t:r}=G(),[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)(()=>{Xu.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 Xu.startSubnetScan(e);let t=setInterval(async()=>{try{let e=await Xu.getScanStatus();E({scanned:e.scanned,total:e.total}),l(await Xu.getDiscoveredPrinters()),e.running||(clearInterval(t),s(!1),p(!0))}catch(e){console.error(`Failed to get scan status:`,e)}},500)}else{await Xu.startDiscovery(10);let e=setInterval(async()=>{try{l(await Xu.getDiscoveredPrinters())}catch(e){console.error(`Failed to get discovered printers:`,e)}},1e3);setTimeout(async()=>{clearInterval(e);try{await Xu.stopDiscovery()}catch{}s(!1),p(!0);try{l(await Xu.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:Oq(e.model)}),l([])};return(0,y.useEffect)(()=>()=>{Xu.stopDiscovery().catch(()=>{}),Xu.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)(pd,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(hd,{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)(Nl,{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-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:[Oq(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)(es,{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)(ru,{className:`w-4 h-4`}),r(`diagnostic.runButton`)]}),j?(0,K.jsxs)(`div`,{className:`rounded-lg bg-amber-500/10 border border-amber-500/30 p-3 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-400`}),(0,K.jsx)(`p`,{className:`text-sm text-amber-300`,children:r(`printers.addPreflight.warning`)})]}),(0,K.jsx)(Tf,{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)(Df,{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 wEe({printer:e,firmwareInfo:t,onClose:n}){let{t:r}=G(),i=Qa(),{showToast:a}=xd(),{hasPermission:o}=sd(),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:()=>ed.prepareUpload(e.id,m??void 0),staleTime:3e4,enabled:!!m&&s&&!u}),v=J({mutationFn:()=>ed.startUpload(e.id,m??void 0),onSuccess:()=>{d(!0);let t=setInterval(async()=>{try{let n=await ed.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)(pd,{className:`w-full max-w-md mx-4`,children:(0,K.jsxs)(hd,{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-500/20`:`bg-status-ok/20`}`,children:t.update_available?(0,K.jsx)(Is,{className:`w-5 h-5 text-orange-400`}):(0,K.jsx)(ls,{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-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-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?Qf(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-400`:`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-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-500/15 text-blue-400 border 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)(Bo,{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-400 text-sm`,children:[(0,K.jsx)(ss,{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-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)(Is,{className:`w-4 h-4 mr-2`}),r(`printers.firmwareModal.uploadFirmware`)]})})]})]})})})}function TEe({printer:e,onClose:t}){let{t:n}=G(),r=Qa(),{showToast:i}=xd(),[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}),[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};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)(pd,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(hd,{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`)})]}),l?(0,K.jsxs)(`div`,{className:`rounded-lg bg-amber-500/10 border border-amber-500/30 p-3 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-400`}),(0,K.jsx)(`p`,{className:`text-sm text-amber-300`,children:n(`printers.addPreflight.warning`)})]}),(0,K.jsx)(Tf,{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 EEe(e){let{data:t}=q({queryKey:[`printerStatus`,e],queryFn:()=>Q.getPrinterStatus(e),refetchInterval:3e4});return!t?.connected}function DEe({printer:e,plug:t,onPowerOn:n,isPowering:r}){let i=EEe(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-gray-900 dark: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-500/20 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)(yl,{className:`w-3 h-3`}),r?`...`:`On`]})]}):null}function OEe(){let{t:e}=G(),{resolvedMode:t,darkAccent:n,lightAccent:r}=ud(),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=_===1?`compact`:`expanded`,[x,S]=(0,y.useState)(null),C=(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`})})})},[]),w=(0,y.useCallback)(e=>{S(e),v(2),localStorage.setItem(`printerCardSize`,`2`),C(e)},[C]),T=(0,y.useCallback)(()=>{let e=x;S(null),v(1),localStorage.setItem(`printerCardSize`,`1`),e!=null&&C(e)},[x,C]),[E,D]=(0,y.useState)(``),[O,k]=(0,y.useState)(`all`),[A,j]=(0,y.useState)(`all`),[M,N]=(0,y.useState)(0),[P,F]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`printerCollapsedSections`);return e?JSON.parse(e):{}}catch{return{}}}),I=Qa(),{showToast:L}=xd(),{hasPermission:R}=sd(),[z,B]=(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(z.values());e.length>0?localStorage.setItem(`openEmbeddedCameras`,JSON.stringify(e)):localStorage.removeItem(`openEmbeddedCameras`)},[z]);let{data:V,isLoading:ee}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:H}=q({queryKey:[`ui-preferences`],queryFn:Q.getUiPreferences}),te=(0,y.useMemo)(()=>op(H?.nozzle_temp_presets,tp,0,320),[H?.nozzle_temp_presets]),ne=(0,y.useMemo)(()=>op(H?.bed_temp_presets,np,0,140),[H?.bed_temp_presets]),re=(0,y.useMemo)(()=>op(H?.chamber_temp_presets,rp,0,60),[H?.chamber_temp_presets]),U=(0,y.useMemo)(()=>op(H?.fan_speed_presets,ip,0,100),[H?.fan_speed_presets]),ie=(0,y.useMemo)(()=>{if(H?.drying_presets)try{let e=JSON.parse(H.drying_presets);if(typeof e==`object`&&e&&Object.keys(e).length>0)return{...Aq,...e}}catch{}return Aq},[H?.drying_presets]);(0,y.useEffect)(()=>{H?.camera_view_mode===`window`&&z.size>0&&B(new Map)},[H?.camera_view_mode,z.size]);let{data:ae}=q({queryKey:[`smart-plugs`],queryFn:Q.getSmartPlugs}),{data:W}=q({queryKey:[`maintenanceOverview`],queryFn:Q.getMaintenanceOverview,staleTime:60*1e3}),{data:oe}=q({queryKey:[`spoolman-status`],queryFn:Q.getSpoolmanStatus,staleTime:60*1e3}),se=oe?.enabled&&oe?.connected,{data:ce}=q({queryKey:[`spoolman-settings`],queryFn:Q.getSpoolmanSettings,enabled:!!se,staleTime:60*1e3}),le=ce?.spoolman_sync_mode,{data:ue}=q({queryKey:[`unlinked-spools`],queryFn:Q.getUnlinkedSpools,enabled:!!se,staleTime:30*1e3}),de=ue&&ue.length>0,{data:fe}=q({queryKey:[`linked-spools`],queryFn:Q.getLinkedSpools,enabled:!!se,staleTime:30*1e3}),pe=fe?.linked,{data:me}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),enabled:R(`inventory:view_assignments`),staleTime:30*1e3}),he=J({mutationFn:({printerId:e,amsId:t,trayId:n})=>Q.unassignSpool(e,t,n),onSuccess:()=>{I.invalidateQueries({queryKey:[`spool-assignments`]})}}),{data:ge,isLoading:_e}=q({queryKey:[`spoolman-inventory-spools`],queryFn:()=>Q.getSpoolmanInventorySpools(!1),enabled:!!se,staleTime:30*1e3}),{data:ve,isLoading:ye}=q({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:!!se,staleTime:30*1e3}),be=J({mutationFn:e=>Q.unassignSpoolmanSlot(e),onSuccess:()=>{I.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),I.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})}}),xe=(e,t,n)=>me?.find(r=>r.printer_id===e&&r.ams_id===Number(t)&&r.tray_id===Number(n)),Se=W?.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),{})||{},Ce=ae?.reduce((e,t)=>(t.printer_id&&(e[t.printer_id]=t),e),{})||{},we=J({mutationFn:Q.createPrinter,onSuccess:()=>{I.invalidateQueries({queryKey:[`printers`]}),I.invalidateQueries({queryKey:[`maintenanceOverview`]}),o(!1)},onError:t=>{if(t instanceof zu&&t.code===`printer_connection_failed`){L(e(`printers.toast.connectionFailedNotAdded`),`error`);return}L(t.message||e(`printers.toast.failedToAdd`),`error`)}}),Te=J({mutationFn:e=>Q.controlSmartPlug(e,`on`),onSuccess:()=>{I.invalidateQueries({queryKey:[`smart-plugs`]}),f(null)},onError:()=>{f(null)}}),[Ee,De]=(0,y.useState)(new Set),[Oe,ke]=(0,y.useState)(!1),[Ae,je]=(0,y.useState)(null),[Me,Ne]=(0,y.useState)(!1),Pe=Oe||Ee.size>0,Fe=(0,y.useCallback)(e=>{De(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Ie=(0,y.useCallback)(()=>{De(new Set),ke(!1)},[]);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Pe&&Ie()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Pe,Ie]);let Le=(0,y.useCallback)(async t=>{Ne(!0);let n=Array.from(Ee).filter(e=>{let n=I.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&&dp(n.hms_errors).length>0;default:return!1}});if(n.length===0){L(e(`printers.bulk.noneApplicable`),`error`),Ne(!1),je(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?L(e(`printers.bulk.success`,{action:e(`printers.bulk.actions.${t}`),count:a})):L(e(`printers.bulk.partial`,{succeeded:a,failed:o}),`error`),n.forEach(e=>{I.invalidateQueries({queryKey:[`printerStatus`,e]})}),Ne(!1),je(null)},[Ee,I,L,e]),Re=(0,y.useCallback)(e=>{e===`stop`||e===`pause`||e===`clearPlate`?je(e):Le(e)},[Le]),ze=()=>{let e=!s;c(e),localStorage.setItem(`hideDisconnectedPrinters`,String(e))},Be=e=>{m(e),localStorage.setItem(`printerSortBy`,e)},Ve=()=>{let e=!h;g(e),localStorage.setItem(`printerSortAsc`,String(e))},He=()=>{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`}},Ue=[`S`,`M`,`L`,`XL`];(0,y.useEffect)(()=>I.getQueryCache().subscribe(e=>{e.type===`updated`&&Array.isArray(e.query.queryKey)&&e.query.queryKey[0]===`printerStatus`&&N(e=>e+1)}),[I]);let We=(0,y.useMemo)(()=>{if(!V)return[];let e=V;if(E.trim()){let t=E.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 A!==`all`&&(e=e.filter(e=>(e.location||``)===A)),O!==`all`&&(e=e.filter(e=>{let t=I.getQueryData([`printerStatus`,e.id]);if(!t?.connected)return O===`offline`;let n=t.hms_errors?dp(t.hms_errors):[];switch(O){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},[V,E,O,A,I,M]),Ge=(0,y.useMemo)(()=>V?[...new Set(V.map(e=>e.location||``).filter(Boolean))].sort():[],[V]),Ke=(0,y.useMemo)(()=>{let e=[...We];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=I.getQueryData([`printerStatus`,e.id]),r=I.getQueryData([`printerStatus`,t.id]),i=e=>e?.connected?(e.hms_errors?dp(e.hms_errors):[]).length>0?0:e.state===`RUNNING`?1:2:3;return i(n)-i(r)});break}return h||e.reverse(),e},[We,p,h,I]),qe=(0,y.useCallback)(()=>{De(new Set(Ke.map(e=>e.id))),ke(!0)},[Ke]),Je=(0,y.useCallback)(e=>{De(t=>{let n=new Set(t);return Ke.forEach(t=>{Dq(I.getQueryData([`printerStatus`,t.id]))===e&&n.add(t.id)}),n}),ke(!0)},[Ke,I]),Ye=(0,y.useCallback)(e=>{De(t=>{let n=new Set(t);return Ke.filter(t=>(t.location||``)===e).forEach(e=>n.add(e.id)),n}),ke(!0)},[Ke]),Xe=(0,y.useCallback)(e=>{De(t=>{let n=new Set(t);return Ke.filter(t=>(t.model||`Unknown`)===e).forEach(e=>n.add(e.id)),n}),ke(!0)},[Ke]),Ze=(0,y.useCallback)(e=>{F(t=>{let n={...t,[e]:!t[e]};try{localStorage.setItem(`printerCollapsedSections`,JSON.stringify(n))}catch{}return n})},[]),Qe=(0,y.useMemo)(()=>{if(p===`name`)return null;let e={};return p===`location`?Ke.forEach(t=>{let n=t.location||`Ungrouped`;e[n]||(e[n]=[]),e[n].push(t)}):p===`model`?Ke.forEach(t=>{let n=t.model||`Unknown`;e[n]||(e[n]=[]),e[n].push(t)}):p===`status`&&Ke.forEach(t=>{let n=Dq(I.getQueryData([`printerStatus`,t.id]));e[n]||(e[n]=[]),e[n].push(t)}),e},[p,Ke,I,M]),$e=(0,y.useRef)(null),et=(0,y.useRef)(null),tt=(0,y.useRef)(0),[nt,rt]=(0,y.useState)(!1),it=(0,y.useCallback)(()=>{let e=$e.current;if(!e)return;let t=et.current?.offsetWidth;t&&(tt.current=t);let n=tt.current>0&&e.clientWidthe===n?e:n)},[]),at=Object.keys(Ce).length;(0,y.useLayoutEffect)(()=>{it();let e=$e.current;if(!e)return;if(typeof ResizeObserver>`u`)return window.addEventListener(`resize`,it),()=>window.removeEventListener(`resize`,it);let t=new ResizeObserver(()=>it());return t.observe(e),window.addEventListener(`resize`,it),()=>{t.disconnect(),window.removeEventListener(`resize`,it)}},[it,V?.length,Ge.length,s,at]);let ot=(t=!1)=>(0,K.jsxs)(K.Fragment,{children:[V&&V.length>0&&(0,K.jsx)(Sq,{value:O,onChange:k,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`)}]}),V&&V.length>0&&Ge.length>0&&(0,K.jsx)(Sq,{value:A,onChange:j,fullWidth:t,options:[{value:`all`,label:e(`printers.filter.allLocations`)},...Ge.map(e=>({value:e,label:e}))]}),(0,K.jsx)(`button`,{type:`button`,onClick:ze,"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`)})]}),st=(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)(Sq,{value:p,onChange:Be,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`)}]}),(0,K.jsx)(`button`,{onClick:Ve,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)(Mo,{className:`w-4 h-4 text-white`}):(0,K.jsx)(Eo,{className:`w-4 h-4 text-white`})})]}),(0,K.jsx)(`div`,{className:`flex h-8 items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary ${t?`w-full`:``}`,children:Ue.map((n,r)=>{let i=r+1,a=_===i;return(0,K.jsx)(`button`,{onClick:()=>{S(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===Ue.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)})})]}),ct=(t=!1)=>(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`button`,{onClick:()=>{Pe?Ie():ke(!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`:``} ${Pe?`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:!R(`printers:control`),children:[(0,K.jsx)($l,{className:`w-4 h-4`}),t&&(0,K.jsx)(`span`,{children:e(`printers.bulk.select`)})]}),s&&Object.keys(Ce).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)(yl,{className:`w-4 h-4`}),e(`printers.powerOn`)]}),(0,K.jsx)(es,{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`)}),V?.filter(e=>Ce[e.id]).map(e=>(0,K.jsx)(DEe,{printer:e,plug:Ce[e.id],onPowerOn:e=>{f(e),Te.mutate(e)},isPowering:d===Ce[e.id]?.id},e.id)),V?.filter(e=>Ce[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:!R(`printers:create`),title:R(`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)(_l,{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)(bl,{className:`w-7 h-7 text-bambu-green`}),e(`printers.title`)]}),(0,K.jsx)(yEe,{printers:V})]}),(0,K.jsxs)(`div`,{ref:$e,className:`relative flex items-center gap-2`,children:[V&&V.length>0&&(0,K.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,K.jsx)(Nl,{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:E,onChange:e=>D(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`}),E&&(0,K.jsx)(`button`,{type:`button`,"aria-label":e(`common.clear`),onClick:()=>D(``),className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{ref:et,"aria-hidden":nt,inert:nt,className:`${nt?`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:ot()}),(0,K.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:st()}),(0,K.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:ct()})]}),nt&&(0,K.jsxs)(`div`,{className:`ml-auto flex items-center justify-end gap-1`,children:[(0,K.jsx)(Cq,{label:e(`printers.toolbar.filters`,`Filters`),icon:(0,K.jsx)(lc,{className:`w-4 h-4`}),children:(0,K.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:ot(!0)})}),(0,K.jsx)(Cq,{label:e(`printers.toolbar.view`,`View`),icon:(0,K.jsx)(ql,{className:`w-4 h-4`}),children:(0,K.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:st(!0)})}),(0,K.jsx)(Cq,{label:e(`printers.toolbar.actions`,`Actions`),icon:(0,K.jsx)(Bs,{className:`w-4 h-4`}),children:(0,K.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:ct(!0)})})]})]})]}),ee?(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`common.loading`)}):V?.length===0?(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{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:!R(`printers:create`),title:R(`printers:create`)?void 0:e(`printers.permission.noAdd`),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]})}):Ke.length===0&&(E.trim()||O!==`all`||A!==`all`)?(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`text-center py-12`,children:(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`printers.noSearchResults`)})})}):Qe?(0,K.jsx)(`div`,{className:`space-y-6`,children:(()=>{let e=p===`status`?xEe.filter(e=>Qe[e]?.length>0):Object.keys(Qe);return h?e:[...e].reverse()})().map(t=>{let n=Qe[t],r=`${p}:${t}`,i=!P[r],a=p===`status`&&Eq[t]?.dot||`bg-bambu-green`,o=p===`status`?e(Eq[t]?.labelKey||t):t;return(0,K.jsx)(Mf,{open:i,onToggle:()=>Ze(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,`)`]}),Pe&&(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p===`location`?Ye(t===`Ungrouped`?``:t):p===`status`?Je(t):p===`model`&&Xe(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`:``} ${He()}`,children:n.map(e=>(0,K.jsx)(jq,{printer:e,hideIfDisconnected:s,maintenanceInfo:Se[e.id],viewMode:b,cardSize:_,amsThresholds:H?{humidityGood:Number(H.ams_humidity_good)||40,humidityFair:Number(H.ams_humidity_fair)||60,tempGood:Number(H.ams_temp_good)||28,tempFair:Number(H.ams_temp_fair)||35}:void 0,spoolmanEnabled:se,hasUnlinkedSpools:de,linkedSpools:pe,spoolmanUrl:oe?.url,spoolmanSyncMode:le,onGetAssignment:xe,onUnassignSpool:(e,t,n)=>he.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:ge,spoolmanSlotAssignments:ve,spoolmanLoading:_e||ye,onUnassignSpoolmanSpool:e=>be.mutate(e),timeFormat:H?.time_format||`system`,cameraViewMode:H?.camera_view_mode||`window`,onOpenEmbeddedCamera:(e,t)=>B(n=>new Map(n).set(e,{id:e,name:t})),checkPrinterFirmware:H?.check_printer_firmware!==!1,dryingPresets:ie,nozzleTempPresets:te,bedTempPresets:ne,chamberTempPresets:re,fanSpeedPresets:U,requirePlateClear:H?.require_plate_clear===!0,selectionMode:Pe,isSelected:Ee.has(e.id),onToggleSelect:Fe,onOpenCompactCard:w},e.id))})},t)})}):(0,K.jsx)(`div`,{className:`grid gap-4 ${_>=3?`gap-6`:``} ${He()}`,children:Ke.map(e=>(0,K.jsx)(jq,{printer:e,hideIfDisconnected:s,maintenanceInfo:Se[e.id],viewMode:b,cardSize:_,spoolmanEnabled:se,hasUnlinkedSpools:de,linkedSpools:pe,spoolmanUrl:oe?.url,spoolmanSyncMode:le,onGetAssignment:xe,onUnassignSpool:(e,t,n)=>he.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:ge,spoolmanSlotAssignments:ve,spoolmanLoading:_e||ye,onUnassignSpoolmanSpool:e=>be.mutate(e),amsThresholds:H?{humidityGood:Number(H.ams_humidity_good)||40,humidityFair:Number(H.ams_humidity_fair)||60,tempGood:Number(H.ams_temp_good)||28,tempFair:Number(H.ams_temp_fair)||35}:void 0,timeFormat:H?.time_format||`system`,cameraViewMode:H?.camera_view_mode||`window`,onOpenEmbeddedCamera:(e,t)=>B(n=>new Map(n).set(e,{id:e,name:t})),checkPrinterFirmware:H?.check_printer_firmware!==!1,dryingPresets:ie,nozzleTempPresets:te,bedTempPresets:ne,chamberTempPresets:re,fanSpeedPresets:U,requirePlateClear:H?.require_plate_clear===!0,selectionMode:Pe,isSelected:Ee.has(e.id),onToggleSelect:Fe,onOpenCompactCard:w},e.id))}),_===2&&x!=null&&(0,K.jsxs)(`button`,{type:`button`,onClick:T,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)(Do,{className:`w-4 h-4`}),e(`common.back`,`Back`)]}),a&&(0,K.jsx)(CEe,{onClose:()=>o(!1),onAdd:e=>we.mutate(e),existingSerials:V?.map(e=>e.serial_number)||[]}),Pe&&V&&(0,K.jsx)(hp,{selectedIds:Ee,printers:V,onClose:Ie,onSelectAll:qe,onSelectByLocation:Ye,onSelectByState:Je,onAction:Re,actionPending:Me}),Ae===`stop`&&(0,K.jsx)(Ed,{title:e(`printers.bulk.confirm.stopTitle`,{count:Ee.size}),message:e(`printers.bulk.confirm.stopMessage`,{count:Ee.size}),confirmText:e(`printers.bulk.confirm.stopButton`),variant:`danger`,isLoading:Me,onConfirm:()=>Le(`stop`),onCancel:()=>je(null)}),Ae===`pause`&&(0,K.jsx)(Ed,{title:e(`printers.bulk.confirm.pauseTitle`,{count:Ee.size}),message:e(`printers.bulk.confirm.pauseMessage`,{count:Ee.size}),confirmText:e(`printers.bulk.confirm.pauseButton`),isLoading:Me,onConfirm:()=>Le(`pause`),onCancel:()=>je(null)}),Ae===`clearPlate`&&(0,K.jsx)(Ed,{title:e(`printers.bulk.confirm.clearPlateTitle`,{count:Ee.size}),message:e(`printers.bulk.confirm.clearPlateMessage`,{count:Ee.size}),confirmText:e(`printers.bulk.confirm.clearPlateButton`),isLoading:Me,onConfirm:()=>Le(`clearPlate`),onCancel:()=>je(null)}),Array.from(z.values()).map((e,t)=>(0,K.jsx)(mce,{printerId:e.id,printerName:e.name,viewerIndex:t,onClose:()=>B(t=>{let n=new Map(t);return n.delete(e.id),n})},e.id))]})}function kEe({title:e,message:t,subtitle:n,closeText:r,variant:i=`error`,onClose:a}){let{t:o}=G(),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)(pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(hd,{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-400`:`text-red-400`}`,children:(0,K.jsx)(vu,{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 Mq=(0,y.createContext)(null),AEe=1500,jEe=1e3,Nq=e=>`slice-job-${e}`;function Pq(e){try{return decodeURIComponent(e)}catch{return e}}function MEe(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 NEe({children:e}){let{t}=G(),{showToast:n,showPersistentToast:r,dismissToast:i}=xd(),a=Qa(),[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=MEe(i),s=p.current.get(e.id)??null,c=s&&s.stage&&s.total_percent>0;if(a===`running`&&c){let n=Pq(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(Nq(e.id),c,`loading`);return}let l=a===`pending`?`slice.queuedToast`:`slice.runningToast`,u=a===`pending`?`Queued: {{name}} — {{elapsed}}`:`Slicing {{name}} — {{elapsed}}`;r(Nq(e.id),t(l,u,{name:Pq(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(Nq(e.id)),r.status===`completed`?n(t(`slice.completedToast`,`Sliced {{name}}`,{name:Pq(e.sourceName)}),`success`):r.status===`failed`&&l({name:Pq(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{}},AEe);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)},jEe);return()=>clearInterval(e)},[o.length,m]),(0,K.jsxs)(Mq.Provider,{value:{trackJob:h,activeJobs:o},children:[e,c&&(0,K.jsx)(kEe,{title:t(`slice.failedTitle`),subtitle:c.name,message:c.detail,onClose:()=>l(null)})]})}function PEe(){let e=(0,y.useContext)(Mq);if(!e)throw Error(`useSliceJobTracker must be used inside SliceJobTrackerProvider`);return e}function Fq({plates:e,onSelect:t,onClose:n}){let{t:r}=G();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)(Pu,{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:Ku(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)(Nc,{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?``:` • ${yf(e.print_time_seconds)}`]})]})]},e.index))})})]})})}var Iq=[`local`,`orca_cloud`,`cloud`,`standard`];function Lq(e,t){for(let n of Iq){let r=e[n][t];if(r.length>0)return{source:r[0].source,id:r[0].id}}return null}function Rq(e,t,n){return t?e[t.source][n].find(e=>e.id===t.id)??null:null}function zq(e,t,n){if(!n)return null;for(let r of Iq){let i=e[r][t].find(e=>e.name===n);if(i)return{source:i.source,id:i.id}}return null}function FEe(e,t,n,r){let i=zq(e,`process`,r);if(i){let r=Rq(e,i,`process`);if(r&&iK(r,`process`,t,n)!==`mismatch`)return i}for(let r of[`match`,`unknown`])for(let i of Iq)for(let a of e[i].process)if(iK(a,`process`,t,n)===r)return{source:a.source,id:a.id};return Lq(e,`process`)}var IEe={local:1.75,orca_cloud:1.5,cloud:1,standard:.5};function LEe(e,t,n,r){let i=t.type.trim().toUpperCase(),a=jK(t.color),o=null;for(let s of Iq)for(let c of e[s].filament){let e=0,l=(c.filament_type??``).trim().toUpperCase(),u=jK(c.filament_colour??``);i&&l&&i===l&&(e+=10),a&&u&&(u===a?e+=5:FK(c.filament_colour??``,t.color)&&(e+=2)),e+=IEe[s],iK(c,`filament`,n,r)===`mismatch`&&(e-=100),(o==null||e>o.score)&&(o={ref:{source:c.source,id:c.id},score:e})}return o==null?Lq(e,`filament`):o.ref}function REe(e){return e?`${e.source}:${e.id}`:``}function zEe(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 BEe({requestId:e,sourceName:t}){let{t:n}=G(),{showPersistentToast:r,dismissToast:i}=xd(),[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=VEe(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 VEe(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 Bq({source:e,onClose:t}){let{t:n}=G(),{trackJob:r}=PEe(),i=Qa(),[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=q({queryKey:[`slicePlates`,e.kind,e.id],queryFn:async()=>e.kind===`libraryFile`?Q.getLibraryFilePlates(e.id):Q.getArchivePlates(e.id),staleTime:6e4}),x=!!b.data?.is_multi_plate&&(b.data?.plates?.length??0)>1,S=x&&p==null,C=p??1,w=(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${C}-${t}`},[e.kind,e.id,C]),T=q({queryKey:[`sliceFilamentReqs`,e.kind,e.id,C],queryFn:async()=>e.kind===`libraryFile`?Q.getLibraryFileFilamentRequirements(e.id,C,w):Q.getArchiveFilamentRequirements(e.id,C,w),enabled:!S,staleTime:6e4}),E=(0,y.useMemo)(()=>{let e=T.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,T.data]),D=q({queryKey:[`slicerPresets`],queryFn:()=>Q.getSlicerPresets(),staleTime:6e4,enabled:!b.isLoading&&!S}),[O,k]=(0,y.useState)(!1),A=async()=>{if(!O){k(!0);try{let e=await Q.getSlicerPresets({refresh:!0});i.setQueryData([`slicerPresets`],e)}catch{i.invalidateQueries({queryKey:[`slicerPresets`]})}finally{k(!1)}}},j=q({queryKey:[`slicerPrinterModels`],queryFn:Q.getSlicerPrinterModels,staleTime:1/0}),M=(0,y.useMemo)(()=>!D.data||!a?null:Rq(D.data,a,`printer`)?.name??null,[D.data,a]),N=(0,y.useMemo)(()=>tK(j.data??{}),[j.data]),P=b.data?.embedded_printer??null,F=b.data?.embedded_process??null;(0,y.useEffect)(()=>{let e=D.data;e&&(a??o(zq(e,`printer`,P)??Lq(e,`printer`)))},[D.data,P]),(0,y.useEffect)(()=>{let e=D.data;e&&c(t=>{if(t){let n=Rq(e,t,`process`);if(n&&iK(n,`process`,M,N)!==`mismatch`)return t}return FEe(e,M,N,F)})},[D.data,M,N,F]),(0,y.useEffect)(()=>{let e=D.data;e&&u(t=>E.map((n,r)=>{let i=t[r]??null;if(i){let t=Rq(e,i,`filament`);if(t&&iK(t,`filament`,M,N)!==`mismatch`)return i}return LEe(e,{type:n.type,color:n.color},M,N)}))},[D.data,E,M,N]);let I=J({mutationFn:async t=>{let n=L(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 L(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:_}}}let R=a!=null&&s!=null&&T.isSuccess&&l.length>0&&l.every(e=>e!=null),z=I.isPending,B=b.data?.plates?.length??0,V=x&&B>1&&!S;return S&&b.data?(0,K.jsx)(Fq,{plates:b.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:()=>{z||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)(ws,{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:z,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors disabled:opacity-50`,"aria-label":n(`common.close`),children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(b.isLoading||D.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`)]}),D.isError&&(0,K.jsx)(`div`,{className:`text-sm 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.`)}),D.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)(Vq,{status:D.data.cloud_status,cloudName:`bambu`}),(0,K.jsx)(Vq,{status:D.data.orca_cloud_status,cloudName:`orca`})]}),(0,K.jsxs)(`button`,{type:`button`,onClick:A,disabled:O||z,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)(Cl,{className:`w-3.5 h-3.5 ${O?`animate-spin`:``}`}),n(`slice.refreshPresets`)]})]}),(0,K.jsx)(Hq,{label:n(`slice.printer`),slot:`printer`,data:D.data,value:a,onChange:o,disabled:z}),(0,K.jsx)(Hq,{label:n(`slice.process`),slot:`process`,data:D.data,value:s,onChange:c,disabled:z,selectedPrinterName:M,compatIndex:N}),(0,K.jsx)(UEe,{value:_,onChange:v,disabled:z}),T.isLoading?(0,K.jsx)(BEe,{requestId:w,sourceName:e.filename}):E.map((e,t)=>{let r=e.used_in_plate!==!1,i=E.length>1?n(`slice.filamentSlot`,{index:t+1,type:e.type}):n(`slice.filament`);return(0,K.jsx)(Hq,{label:r?i:`${i} ${n(`slice.notUsedByPlate`)}`,slot:`filament`,data:D.data,value:l[t]??null,onChange:e=>u(n=>{let r=n.length===E.length?[...n]:E.map((e,t)=>n[t]??null);return r[t]=e,r}),disabled:z||!r,swatchColor:E.length>1?e.color:void 0,selectedPrinterName:M,compatIndex:N},`filament-${t}`)})]}),d&&(0,K.jsx)(`div`,{className:`text-sm 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:z,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`)}),V&&(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:B}),children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),disabled:z,className:`cursor-pointer`}),n(`slice.allPlatesToggle`,{count:B})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{f(null);let e=h?0:p;I.mutate(e)},disabled:!R||z,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:z?(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:B}):n(`slice.action`)})]})]})})}function Vq({status:e,cloudName:t=`bambu`}){let{t:n}=G();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-700/40 bg-amber-900/20 text-amber-200`,icon:vs},unreachable:{tone:`border-bambu-dark-tertiary/40 bg-bambu-dark text-bambu-gray`,icon:vs}}[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 HEe=[{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 UEe({value:e,onChange:t,disabled:n}){let{t:r}=G();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`)}),HEe.map(e=>(0,K.jsx)(`option`,{value:e.value,children:r(e.labelKey,e.fallback)},e.value))]})]})}function Hq({label:e,slot:t,data:n,value:r,onChange:i,disabled:a,swatchColor:o,selectedPrinterName:s,compatIndex:c}){let{t:l}=G(),{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)iK(n,t,s??null,c??wTe)===`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:REe(r),onChange:e=>i(zEe(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 WEe(){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 Uq(e,t=`bambu_studio`){let n,r=encodeURIComponent(e);n=t===`orcaslicer`?`orcaslicer://open?file=${r}`:WEe()===`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 Wq=768;function Gq(){let[e,t]=(0,y.useState)(()=>typeof window<`u`?window.innerWidth{let e=window.matchMedia(`(max-width: ${Wq-1}px)`),n=e=>{t(e.matches)};return t(e.matches),e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}function GEe({onClose:e,initialFiles:t}){let{t:n}=G(),r=Qa(),{showToast:i}=xd(),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)(pd,{className:`w-full max-w-2xl max-h-[90vh] flex flex-col`,children:(0,K.jsxs)(hd,{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)(Pu,{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)(Su,{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)(Qs,{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-400 transition-colors`,disabled:x,children:(0,K.jsx)(Pu,{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)(ls,{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-400`,children:e.error}),(0,K.jsx)(ss,{className:`w-4 h-4 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-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)(Su,{className:`w-4 h-4`}),n(`uploadModal.upload`),` `,b>0&&`(${b})`]})})]})]})})})}var KEe=365;function qEe({onClose:e,initialDays:t}){let{t:n}=G(),r=Qa(),{showToast:i}=xd(),[a,o]=(0,y.useState)(t??KEe),[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)(hu,{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)(Pu,{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:yd(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)(vu,{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 JEe(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 YEe(e){if(!e)return`—`;let t=mf(e);return t?t.toLocaleString():`—`}function Kq({archiveId:e}){let{t}=G(),{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-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:YEe(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:JEe(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 qq=[`adhesionFailure`,`spaghettiDetached`,`layerShift`,`cloggedNozzle`,`filamentRunout`,`warping`,`stringing`,`underExtrusion`,`powerFailure`,`userCancelled`,`other`],XEe=[`completed`,`failed`,`aborted`,`printing`];function Jq({archive:e,onClose:t,existingTags:n=[]}){let{t:r}=G();(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let i=Qa(),[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?qq.includes(t)?t:qq.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()}}),H=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=``)}}},te=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)(Pu,{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)(Kq,{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)(nc,{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)(bc,{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)(Lc,{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)(su,{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)(Pu,{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:XEe.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`)}),qq.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)(Jo,{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:()=>te(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)(hu,{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:H,className:`hidden`,disabled:E}),E?(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,K.jsx)(_l,{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)(Ol,{className:`w-4 h-4`}),ee.isPending?r(`common.saving`):r(`common.save`)]})]})]})]})})}function Yq({archiveId:e,archiveName:t,onClose:n}){let{t:r}=G();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)(wc,{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)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`p-6 overflow-y-auto flex-1`,children:(0,K.jsx)(Kq,{archiveId:e})})]})})}function ZEe({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)(Nl,{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-400 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 Xq({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-400 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)(ts,{className:`w-4 h-4 text-bambu-gray`})]}),n&&a===t&&(0,K.jsx)(ZEe,{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 QEe({selectedIds:e,existingTags:t,onClose:n}){let r=Qa(),{showToast:i}=xd(),[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)(pd,{className:`w-full max-w-md`,children:(0,K.jsxs)(hd,{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)(su,{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)(Pu,{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)(_l,{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-500/20 text-green-400`:`bg-red-500/20 text-red-400`}`,children:[e,(0,K.jsx)(`button`,{onClick:()=>f(e),className:`hover:opacity-70`,children:(0,K.jsx)(Pu,{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)(su,{className:`w-4 h-4`}),l===`add`?`Add Tags`:`Remove Tags`]})})]})]})})})}function $Ee({selectedIds:e,onClose:t}){let{t:n}=G(),r=Qa(),{showToast:i}=xd(),[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)(pd,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,children:(0,K.jsxs)(hd,{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)(nc,{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)(Pu,{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)(ms,{className:`w-4 h-4 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)(Nl,{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)(nc,{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 eDe(e,t){return new Date(e,t+1,0).getDate()}function tDe(e,t){return new Date(e,t,1).getDay()}var nDe=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],rDe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function iDe({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=mf(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=eDe(o,i),m=tDe(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)(ns,{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:[nDe[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)(ts,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-7 gap-1 mb-1`,children:rDe.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=mf(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-400`,children:e.filter(e=>{let t=mf(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-400`,children:e.filter(e=>{let t=mf(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-400`:`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 Zq({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)(Pu,{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)(Is,{className:`w-4 h-4`}),`Download QR Code`]})]})]})})}function Qq({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)(Is,{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)(hu,{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)(Pu,{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)(ns,{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)(ts,{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)(Ed,{title:`Delete Photo`,message:`Delete this photo? This cannot be undone.`,confirmText:`Delete`,variant:`danger`,onConfirm:()=>{i?.(l),c(!1)},onCancel:()=>c(!1)})]})}function $q(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n`u`?null:CJ(BigInt.prototype.toString),vJ=typeof Symbol>`u`?null:CJ(Symbol.prototype.toString),yJ=CJ(Object.prototype.hasOwnProperty),bJ=CJ(Object.prototype.toString),xJ=CJ(RegExp.prototype.test),SJ=vDe(TypeError);function CJ(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return oJ(e,t,n)}}function vDe(e){return function(){return sJ(e,[...arguments])}}function wJ(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:fJ;if(tJ&&tJ(e,null),!dJ(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(uDe(t)||(t[r]=e),i=e)}e[i]=!0}return e}function yDe(e){for(let t=0;t/g),EDe=rJ(/\${[\w\W]*/g),DDe=rJ(/^data-[\-\w.\u00B7-\uFFFF]+$/),ODe=rJ(/^aria-[\-\w]+$/),IJ=rJ(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),kDe=rJ(/^(?:\w+script|data):/i),ADe=rJ(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),jDe=rJ(/^html$/i),MDe=rJ(/^[a-z][.\w]*(-[.\w]+)+$/i),LJ=rJ(/<[/\w!]/g),NDe=rJ(/<[/\w]/g),PDe=rJ(/<\/no(script|embed|frames)/i),FDe=rJ(/\/>/i),RJ={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},IDe=function(){return typeof window>`u`?null:window},LDe=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}},zJ=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},BJ=function(e,t,n,r){return yJ(e,t)&&dJ(e[t])?wJ(r.base?TJ(r.base):{},e[t],r.transform):n};function VJ(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:IDe(),t=e=>VJ(e);if(t.version=`3.4.11`,t.removed=[],!e||!e.document||e.document.nodeType!==RJ.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=EJ(d,`cloneNode`),p=EJ(d,`remove`),m=EJ(d,`nextSibling`),h=EJ(d,`childNodes`),g=EJ(d,`parentNode`),_=EJ(d,`shadowRoot`),v=EJ(d,`attributes`),y=o&&o.prototype?EJ(o.prototype,`nodeType`):null,b=o&&o.prototype?EJ(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 SJ(`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=LDe(u,i),!0),C},A=n,j=A.implementation,M=A.createNodeIterator,N=A.createDocumentFragment,P=A.getElementsByTagName,F=r.importNode,I=zJ();t.isSupported=typeof eJ==`function`&&typeof g==`function`&&j&&j.createHTMLDocument!==void 0;let L=wDe,R=TDe,z=EDe,B=DDe,V=ODe,ee=kDe,H=ADe,te=MDe,ne=IJ,re=null,U=wJ({},[...DJ,...OJ,...kJ,...AJ,...jJ]),ie=null,ae=wJ({},[...MJ,...NJ,...PJ,...FJ]),W=Object.seal(iJ(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}})),oe=null,se=null,ce=Object.seal(iJ(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),le=!0,ue=!0,de=!1,fe=!0,pe=!1,me=!0,he=!1,ge=!1,_e=null,ve=null,ye=!1,be=!1,xe=!1,Se=!1,Ce=!0,we=!1,Te=`user-content-`,Ee=!0,De=!1,Oe={},ke=null,Ae=wJ({},`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(`.`)),je=null,Me=wJ({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Ne=null,Pe=wJ({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Fe=`http://www.w3.org/1998/Math/MathML`,Ie=`http://www.w3.org/2000/svg`,Le=`http://www.w3.org/1999/xhtml`,Re=Le,ze=!1,Be=null,Ve=wJ({},[Fe,Ie,Le],pJ),He=nJ([`mi`,`mo`,`mn`,`ms`,`mtext`]),Ue=wJ({},He),We=nJ([`annotation-xml`]),Ge=wJ({},We),Ke=wJ({},[`title`,`style`,`font`,`a`,`script`]),qe=null,Je=[`application/xhtml+xml`,`text/html`],Ye=null,Xe=null,Ze=n.createElement(`form`),Qe=function(e){return e instanceof RegExp||e instanceof Function},G=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(Xe&&Xe===e)return;(!e||typeof e!=`object`)&&(e={}),e=TJ(e),qe=Je.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,Ye=qe===`application/xhtml+xml`?pJ:fJ,re=BJ(e,`ALLOWED_TAGS`,U,{transform:Ye}),ie=BJ(e,`ALLOWED_ATTR`,ae,{transform:Ye}),Be=BJ(e,`ALLOWED_NAMESPACES`,Ve,{transform:pJ}),Ne=BJ(e,`ADD_URI_SAFE_ATTR`,Pe,{transform:Ye,base:Pe}),je=BJ(e,`ADD_DATA_URI_TAGS`,Me,{transform:Ye,base:Me}),ke=BJ(e,`FORBID_CONTENTS`,Ae,{transform:Ye}),oe=BJ(e,`FORBID_TAGS`,TJ({}),{transform:Ye}),se=BJ(e,`FORBID_ATTR`,TJ({}),{transform:Ye}),Oe=yJ(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?TJ(e.USE_PROFILES):e.USE_PROFILES:!1,le=e.ALLOW_ARIA_ATTR!==!1,ue=e.ALLOW_DATA_ATTR!==!1,de=e.ALLOW_UNKNOWN_PROTOCOLS||!1,fe=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,pe=e.SAFE_FOR_TEMPLATES||!1,me=e.SAFE_FOR_XML!==!1,he=e.WHOLE_DOCUMENT||!1,be=e.RETURN_DOM||!1,xe=e.RETURN_DOM_FRAGMENT||!1,Se=e.RETURN_TRUSTED_TYPE||!1,ye=e.FORCE_BODY||!1,Ce=e.SANITIZE_DOM!==!1,we=e.SANITIZE_NAMED_PROPS||!1,Ee=e.KEEP_CONTENT!==!1,De=e.IN_PLACE||!1,ne=xDe(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:IJ,Re=typeof e.NAMESPACE==`string`?e.NAMESPACE:Le,Ue=yJ(e,`MATHML_TEXT_INTEGRATION_POINTS`)&&e.MATHML_TEXT_INTEGRATION_POINTS&&typeof e.MATHML_TEXT_INTEGRATION_POINTS==`object`?TJ(e.MATHML_TEXT_INTEGRATION_POINTS):wJ({},He),Ge=yJ(e,`HTML_INTEGRATION_POINTS`)&&e.HTML_INTEGRATION_POINTS&&typeof e.HTML_INTEGRATION_POINTS==`object`?TJ(e.HTML_INTEGRATION_POINTS):wJ({},We);let t=yJ(e,`CUSTOM_ELEMENT_HANDLING`)&&e.CUSTOM_ELEMENT_HANDLING&&typeof e.CUSTOM_ELEMENT_HANDLING==`object`?TJ(e.CUSTOM_ELEMENT_HANDLING):iJ(null);if(W=iJ(null),yJ(t,`tagNameCheck`)&&Qe(t.tagNameCheck)&&(W.tagNameCheck=t.tagNameCheck),yJ(t,`attributeNameCheck`)&&Qe(t.attributeNameCheck)&&(W.attributeNameCheck=t.attributeNameCheck),yJ(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(W.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),rJ(W),pe&&(ue=!1),xe&&(be=!0),Oe&&(re=wJ({},jJ),ie=iJ(null),Oe.html===!0&&(wJ(re,DJ),wJ(ie,MJ)),Oe.svg===!0&&(wJ(re,OJ),wJ(ie,NJ),wJ(ie,FJ)),Oe.svgFilters===!0&&(wJ(re,kJ),wJ(ie,NJ),wJ(ie,FJ)),Oe.mathMl===!0&&(wJ(re,AJ),wJ(ie,PJ),wJ(ie,FJ))),ce.tagCheck=null,ce.attributeCheck=null,yJ(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?ce.tagCheck=e.ADD_TAGS:dJ(e.ADD_TAGS)&&(re===U&&(re=TJ(re)),wJ(re,e.ADD_TAGS,Ye))),yJ(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?ce.attributeCheck=e.ADD_ATTR:dJ(e.ADD_ATTR)&&(ie===ae&&(ie=TJ(ie)),wJ(ie,e.ADD_ATTR,Ye))),yJ(e,`ADD_URI_SAFE_ATTR`)&&dJ(e.ADD_URI_SAFE_ATTR)&&wJ(Ne,e.ADD_URI_SAFE_ATTR,Ye),yJ(e,`FORBID_CONTENTS`)&&dJ(e.FORBID_CONTENTS)&&(ke===Ae&&(ke=TJ(ke)),wJ(ke,e.FORBID_CONTENTS,Ye)),yJ(e,`ADD_FORBID_CONTENTS`)&&dJ(e.ADD_FORBID_CONTENTS)&&(ke===Ae&&(ke=TJ(ke)),wJ(ke,e.ADD_FORBID_CONTENTS,Ye)),Ee&&(re[`#text`]=!0),he&&wJ(re,[`html`,`head`,`body`]),re.table&&(wJ(re,[`tbody`]),delete oe.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw SJ(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw SJ(`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(``)));nJ&&nJ(e),Xe=e},$e=wJ({},[...OJ,...kJ,...SDe]),et=wJ({},[...AJ,...CDe]),tt=function(e,t,n){return t.namespaceURI===Le?e===`svg`:t.namespaceURI===Fe?e===`svg`&&(n===`annotation-xml`||Ue[n]):!!$e[e]},nt=function(e,t,n){return t.namespaceURI===Le?e===`math`:t.namespaceURI===Ie?e===`math`&&Ge[n]:!!et[e]},rt=function(e,t,n){return t.namespaceURI===Ie&&!Ge[n]||t.namespaceURI===Fe&&!Ue[n]?!1:!et[e]&&(Ke[e]||!$e[e])},it=function(e){let t=g(e);(!t||!t.tagName)&&(t={namespaceURI:Re,tagName:`template`});let n=fJ(e.tagName),r=fJ(t.tagName);return Be[e.namespaceURI]?e.namespaceURI===Ie?tt(n,t,r):e.namespaceURI===Fe?nt(n,t,r):e.namespaceURI===Le?rt(n,t,r):!!(qe===`application/xhtml+xml`&&Be[e.namespaceURI]):!1},at=function(e){uJ(t.removed,{element:e});try{g(e).removeChild(e)}catch{if(p(e),!g(e))throw SJ(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},ot=function(e){let t=h(e);if(t){let e=[];cJ(t,t=>{uJ(e,t)}),cJ(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{}}},st=function(e,n){try{uJ(t.removed,{attribute:n.getAttributeNode(e),from:n})}catch{uJ(t.removed,{attribute:null,from:n})}if(n.removeAttribute(e),e===`is`)if(be||xe)try{at(n)}catch{}else try{n.setAttribute(e,``)}catch{}},ct=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`||ie[Ye(i)]))try{e.removeAttribute(i)}catch{}}},lt=function(e){let t=[e];for(;t.length>0;){let e=t.pop();(y?y(e):e.nodeType)===RJ.element&&ct(e);let n=h(e);if(n)for(let e=n.length-1;e>=0;--e)t.push(n[e])}},ut=function(e){let t=null,r=null;if(ye)e=``+e;else{let t=mJ(e,/^[\r\n\t ]+/);r=t&&t[0]}qe===`application/xhtml+xml`&&Re===Le&&(e=``+e+``);let i=x?D(e):e;if(Re===Le)try{t=new l().parseFromString(i,qe)}catch{}if(!t||!t.documentElement){t=j.createDocument(Re,`template`,null);try{t.documentElement.innerHTML=ze?S:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),Re===Le?P.call(t,he?`html`:`body`)[0]:he?t.documentElement:a},dt=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)},ft=function(e){return e=hJ(e,L,` `),e=hJ(e,R,` `),e=hJ(e,z,` `),e},pt=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=ft(n.data),n=t.nextNode();let r=e.querySelectorAll?.call(e,`template`);r&&cJ(r,e=>{ht(e.content)&&pt(e.content)})},mt=function(e){let t=b?b(e):null;return typeof t!=`string`||Ye(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)},ht=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return y(e)===RJ.documentFragment}catch{return!1}},gt=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return typeof y(e)==`number`}catch{return!1}};function _t(e,n,r){e.length!==0&&cJ(e,e=>{e.call(t,n,r,Xe)})}let vt=function(e,t){return!!(me&&e.hasChildNodes()&&!gt(e.firstElementChild)&&xJ(LJ,e.textContent)&&xJ(LJ,e.innerHTML)||me&&e.namespaceURI===Le&&t===`style`&>(e.firstElementChild)||e.nodeType===RJ.processingInstruction||me&&e.nodeType===RJ.comment&&xJ(NDe,e.data))},yt=function(e,t){if(!oe[t]&&Ct(t)&&(W.tagNameCheck instanceof RegExp&&xJ(W.tagNameCheck,t)||W.tagNameCheck instanceof Function&&W.tagNameCheck(t)))return!1;if(Ee&&!ke[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=De?n[i]:f(n[i],!0);t.insertBefore(r,m(e))}}}return at(e),!0},bt=function(e){if(_t(I.beforeSanitizeElements,e,null),mt(e))return at(e),!0;let n=Ye(b?b(e):e.nodeName);if(_t(I.uponSanitizeElement,e,{tagName:n,allowedTags:re}),vt(e,n))return at(e),!0;if(oe[n]||!(ce.tagCheck instanceof Function&&ce.tagCheck(n))&&!re[n])return yt(e,n);if((y?y(e):e.nodeType)===RJ.element&&!it(e)||(n===`noscript`||n===`noembed`||n===`noframes`)&&xJ(PDe,e.innerHTML))return at(e),!0;if(pe&&e.nodeType===RJ.text){let n=ft(e.textContent);e.textContent!==n&&(uJ(t.removed,{element:e.cloneNode()}),e.textContent=n)}return _t(I.afterSanitizeElements,e,null),!1},xt=function(e,t,r){if(se[t]||Ce&&(t===`id`||t===`name`)&&(r in n||r in Ze))return!1;let i=ie[t]||ce.attributeCheck instanceof Function&&ce.attributeCheck(t,e);if(!(ue&&xJ(B,t))&&!(le&&xJ(V,t))){if(!i){if(!(Ct(e)&&(W.tagNameCheck instanceof RegExp&&xJ(W.tagNameCheck,e)||W.tagNameCheck instanceof Function&&W.tagNameCheck(e))&&(W.attributeNameCheck instanceof RegExp&&xJ(W.attributeNameCheck,t)||W.attributeNameCheck instanceof Function&&W.attributeNameCheck(t,e))||t===`is`&&W.allowCustomizedBuiltInElements&&(W.tagNameCheck instanceof RegExp&&xJ(W.tagNameCheck,r)||W.tagNameCheck instanceof Function&&W.tagNameCheck(r))))return!1}else if(!Ne[t]&&!xJ(ne,hJ(r,H,``))&&!((t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&gJ(r,`data:`)===0&&je[e])&&!(de&&!xJ(ee,hJ(r,H,``)))&&r)return!1}return!0},St=wJ({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),Ct=function(e){return!St[fJ(e)]&&xJ(te,e)},wt=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},Tt=function(e,n,r,i){try{r?e.setAttributeNS(r,n,i):e.setAttribute(n,i),mt(e)?at(e):lJ(t.removed)}catch{st(n,e)}},Et=function(e){_t(I.beforeSanitizeAttributes,e,null);let t=e.attributes;if(!t||mt(e))return;let n={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:ie,forceKeepAttr:void 0},r=t.length,i=Ye(e.nodeName);for(;r--;){let a=t[r],o=a.name,s=a.namespaceURI,c=a.value,l=Ye(o),u=c,d=o===`value`?u:hDe(u);if(n.attrName=l,n.attrValue=d,n.keepAttr=!0,n.forceKeepAttr=void 0,_t(I.uponSanitizeAttribute,e,n),d=n.attrValue,we&&(l===`id`||l===`name`)&&gJ(d,Te)!==0&&(st(o,e),d=Te+d),me&&xJ(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)){st(o,e);continue}if(l===`attributename`&&mJ(d,`href`)){st(o,e);continue}if(!n.forceKeepAttr){if(!n.keepAttr){st(o,e);continue}if(!fe&&xJ(FDe,d)){st(o,e);continue}if(pe&&(d=ft(d)),!xt(i,l,d)){st(o,e);continue}d=wt(i,l,s,d),d!==u&&Tt(e,o,s,d)}}_t(I.afterSanitizeAttributes,e,null)},Dt=function(e){let t=null,n=dt(e);for(_t(I.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(_t(I.uponSanitizeShadowNode,t,null),bt(t),Et(t),ht(t.content)&&Dt(t.content),(y?y(t):t.nodeType)===RJ.element){let e=_(t);ht(e)&&(Ot(e),Dt(e))}_t(I.afterSanitizeShadowDOM,e,null)},Ot=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){Dt(e.shadow);continue}let n=e.node,r=(y?y(n):n.nodeType)===RJ.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`&&Ye(e)===`template`){let e=n.content;ht(e)&&t.push({node:e,shadow:null})}}if(r){let e=_(n);ht(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(ze=!e,ze&&(e=``),typeof e!=`string`&&!gt(e)&&(e=bDe(e),typeof e!=`string`))throw SJ(`dirty is not a string, aborting`);if(!t.isSupported)return e;ge?(re=_e,ie=ve):G(n),(I.uponSanitizeElement.length>0||I.uponSanitizeAttribute.length>0)&&(re=TJ(re)),I.uponSanitizeAttribute.length>0&&(ie=TJ(ie)),t.removed=[];let c=De&&typeof e!=`string`&>(e);if(c){let t=b?b(e):e.nodeName;if(typeof t==`string`){let e=Ye(t);if(!re[e]||oe[e])throw SJ(`root node is forbidden and cannot be sanitized in-place`)}if(mt(e))throw SJ(`root node is clobbered and cannot be sanitized in-place`);try{Ot(e)}catch(t){throw ot(e),t}}else if(gt(e))i=ut(``),a=i.ownerDocument.importNode(e,!0),a.nodeType===RJ.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),Ot(a);else{if(!be&&!pe&&!he&&e.indexOf(`<`)===-1)return x&&Se?D(e):e;if(i=ut(e),!i)return be?null:Se?S:``}i&&ye&&at(i.firstChild);let l=dt(c?e:i);try{for(;o=l.nextNode();)bt(o),Et(o),ht(o.content)&&Dt(o.content)}catch(t){throw c&&ot(e),t}if(c)return cJ(t.removed,e=>{e.element&<(e.element)}),pe&&pt(e),e;if(be){if(pe&&pt(i),xe)for(s=N.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(ie.shadowroot||ie.shadowrootmode)&&(s=F.call(r,s,!0)),s}let u=he?i.outerHTML:i.innerHTML;return he&&re[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&xJ(jDe,i.ownerDocument.doctype.name)&&(u=` -`+u),pe&&(u=ft(u)),x&&Se?D(u):u},t.setConfig=function(){G(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}),ge=!0,_e=re,ve=ie},t.clearConfig=function(){Xe=null,ge=!1,_e=null,ve=null,x=C,S=``},t.isValidAttribute=function(e,t,n){return Xe||G({}),xt(Ye(e),Ye(t),n)},t.addHook=function(e,t){typeof t==`function`&&yJ(I,e)&&uJ(I[e],t)},t.removeHook=function(e,t){if(yJ(I,e)){if(t!==void 0){let n=pDe(I[e],t);return n===-1?void 0:mDe(I[e],n,1)[0]}return lJ(I[e])}},t.removeHooks=function(e){yJ(I,e)&&(I[e]=[])},t.removeAllHooks=function(){I=zJ()},t}var HJ=VJ();function UJ(e){this.content=e}UJ.prototype={constructor:UJ,find:function(e){for(var t=0;t>1}},UJ.from=function(e){if(e instanceof UJ)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new UJ(t)};function WJ(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=WJ(i.content,a.content,n+1);if(e!=null)return e}n+=i.nodeSize}}function GJ(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?JJ(t+1,i):JJ(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}};XJ.none=[];var ZJ=class extends Error{},QJ=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=eY(this.content,t+this.openStart,n);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e($J(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(KJ.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)}};QJ.empty=new QJ(KJ.empty,0,0);function $J(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($J(a.content,t-i-1,n-i-1)))}function eY(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=eY(o.content,t-a-1,n,o);return s&&e.replaceChild(i,o.copy(s))}function RDe(e,t,n){if(n.openStart>e.depth)throw new ZJ(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new ZJ(`Inconsistent open depths`);return tY(e,t,n,0)}function tY(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 aY(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&&(iY(e.nodeAfter,r),a++));for(let e=a;ei&&rY(e,t,i+1),o=r.depth>i&&rY(n,r,i+1),s=[];return aY(null,e,i,s),a&&o&&t.index(i)==n.index(i)?(nY(a,o),iY(oY(a,sY(e,t,n,r,i+1)),s)):(a&&iY(oY(a,cY(e,t,i+1)),s),aY(t,n,i,s),o&&iY(oY(o,cY(n,r,i+1)),s)),aY(r,null,i,s),new KJ(s)}function cY(e,t,n){let r=[];return aY(null,e,n,r),e.depth>n&&iY(oY(rY(e,t,n+1),cY(e,t,n+1)),r),aY(t,null,n,r),new KJ(r)}function zDe(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(KJ.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var lY=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 dY(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=uY.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()+`)`),pY(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=KJ.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=KJ.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}};fY.prototype.text=void 0;var UDe=class e extends fY{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):pY(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 pY(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var mY=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new WDe(t,n);if(r.next==null)return e.empty;let i=hY(r);r.next&&r.err(`Unexpected trailing text`);let a=ZDe(XDe(i));return QDe(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(` -`)}};mY.empty=new mY(!0);var WDe=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 hY(e){let t=[];do t.push(GDe(e));while(e.eat(`|`));return t.length==1?t[0]:{type:`choice`,exprs:t}}function GDe(e){let t=[];do t.push(KDe(e));while(e.next&&e.next!=`)`&&e.next!=`|`);return t.length==1?t[0]:{type:`seq`,exprs:t}}function KDe(e){let t=YDe(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=qDe(e,t);else break;return t}function gY(e){/\D/.test(e.next)&&e.err(`Expected number, got '`+e.next+`'`);let t=Number(e.next);return e.pos++,t}function qDe(e,t){let n=gY(e),r=n;return e.eat(`,`)&&(r=e.next==`}`?-1:gY(e)),e.eat(`}`)||e.err(`Unclosed braced range`),{type:`range`,min:n,max:r,expr:t}}function JDe(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 YDe(e){if(e.eat(`(`)){let t=hY(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=JDe(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 XDe(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 mY(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:bY(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error(`NodeType.create can't construct text nodes`);return new fY(this,this.computeAttrs(e),KJ.from(t),XJ.setFrom(n))}createChecked(e=null,t,n){return t=KJ.from(t),this.checkContent(t),new fY(this,this.computeAttrs(e),t,XJ.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=KJ.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(KJ.empty,!0);return i?new fY(this,e,t.append(i),XJ.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 $De(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 eOe=class{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,`default`),this.default=n.default,this.validate=typeof n.validate==`string`?$De(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}},wY=class e{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=SY(e,r.attrs),this.excluded=null;let i=yY(this.attrs);this.instance=i?new XJ(this,i):null}create(e=null){return!e&&this.instance?this.instance:new XJ(this,bY(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}},TY=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=UJ.from(e.nodes),t.marks=UJ.from(e.marks||{}),this.nodes=CY.compile(this.spec.nodes,this),this.marks=wY.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]=mY.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?EY(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==``?[]:EY(this,n.split(` `))}this.nodeFromJSON=e=>fY.fromJSON(this,e),this.markFromJSON=e=>XJ.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 CY))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 UDe(n,n.defaultAttrs,e,XJ.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 EY(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 tOe(e){return e.tag!=null}function nOe(e){return e.style!=null}var DY=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(tOe(e))this.tags.push(e);else if(nOe(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 FY(this,t,!1);return n.addAll(e,XJ.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new FY(this,t,!0);return n.addAll(e,XJ.none,t.from,t.to),QJ.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=IY(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=IY(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)))}},OY={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},rOe={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},kY={ol:!0,ul:!0},AY=1,jY=2,MY=4;function NY(e,t,n){return t==null?e&&e.whitespace==`pre`?3:n&-5:(t?AY:0)|(t===`full`?jY:0)}var PY=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=XJ.none,this.match=i||(a&MY?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(KJ.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&AY)){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=KJ.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(KJ.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&&!OY.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},FY=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=NY(null,t.preserveWhitespace,0)|(n?MY:0);i=r?new PY(r.type,r.attrs,XJ.none,!0,t.topMatch||r.type.contentMatch,a):n?new PY(null,null,XJ.none,!0,null,a):new PY(e.schema.topNodeType,null,XJ.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&jY?`full`:this.localPreserveWS||(r.options&AY)>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,` -`);else if(a.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(a.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),n.consuming===!1)e=n;else break}}return t}addElementByRule(e,t,n,r){let i,a;if(t.node)if(a=this.parser.schema.nodes[t.node],a.isLeaf)this.insertNode(a.create(t.attrs),n,e.nodeName==`BR`)||this.leafFallback(e,n);else{let e=this.enter(a,t.attrs||null,n,t.preserveWhitespace);e&&(i=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let o=this.top;if(a&&a.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;typeof t.contentElement==`string`?r=e.querySelector(t.contentElement):typeof t.contentElement==`function`?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}i&&this.sync(o)&&this.open--}addAll(e,t,n,r){let i=n||0;for(let a=n?e.childNodes[n]:e.firstChild,o=r==null?null:e.childNodes[r];a!=o;a=a.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(a,t);this.findAtPoint(e,i)}findPlace(e,t,n){let r,i;for(let t=this.open,a=0;t>=0;t--){let o=this.nodes[t],s=o.findWrapping(e);if(s&&(!r||r.length>s.length+a)&&(r=s,i=o,!s.length))break;if(o.solid){if(n)break;a+=2}}if(!r)return null;this.sync(i);for(let e=0;e(a.type?a.type.allowsMarkType(t.type):LY(t.type,e))?(s=t.addToSet(s),!1):!0),this.nodes.push(new PY(e,t,s,r,null,o)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;else this.localPreserveWS&&(this.nodes[t].options|=AY);return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split(`/`),n=this.options.context,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),i=-(n?n.depth+1:0)+ +!r,a=(e,o)=>{for(;e>=0;e--){let s=t[e];if(s==``){if(e==t.length-1||e==0)continue;for(;o>=i;o--)if(a(e-1,o))return!0;return!1}else{let e=o>0||o==0&&r?this.nodes[o].type:n&&o>=i?n.node(o-i).type:null;if(!e||e.name!=s&&!e.isInGroup(s))return!1;o--}}return!0};return a(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}};function iOe(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=t.nodeType==1?t.nodeName.toLowerCase():null;e&&kY.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):e==`li`?n=t:e&&(n=null)}}function aOe(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function IY(e){let t={};for(let n in e)t[n]=e[n];return t}function LY(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let a=[],o=e=>{a.push(e);for(let n=0;n{if(i.length||e.marks.length){let n=0,a=0;for(;n=0;r--){let i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&HY(BY(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return HY(e,t,n,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new e(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(e){let t=zY(e.nodes);return t.text||=e=>e.text,t}static marksFromSchema(e){return zY(e.marks)}};function zY(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function BY(e){return e.document||window.document}var VY=new WeakMap;function oOe(e){let t=VY.get(e);return t===void 0&&VY.set(e,t=sOe(e)),t}function sOe(e){let t=null;function n(e){if(e&&typeof e==`object`)if(Array.isArray(e))if(typeof e[0]==`string`)t||=[],t.push(e);else for(let t=0;t-1)throw RangeError(`Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.`);let o=i.indexOf(` `);o>0&&(n=i.slice(0,o),i=i.slice(o+1));let s,c=n?e.createElementNS(n,i):e.createElement(i),l=t[1],u=1;if(l&&typeof l==`object`&&l.nodeType==null&&!Array.isArray(l)){u=2;for(let e in l)if(l[e]!=null){let t=e.indexOf(` `);t>0?c.setAttributeNS(e.slice(0,t),e.slice(t+1),l[e]):e==`style`&&c.style?c.style.cssText=l[e]:c.setAttribute(e,l[e])}}for(let i=u;iu)throw RangeError(`Content hole must be the only child of its parent node`);return{dom:c,contentDOM:c}}else{let{dom:t,contentDOM:i}=HY(e,a,n,r);if(c.appendChild(t),i){if(s)throw RangeError(`Multiple content holes`);s=i}}}return{dom:c,contentDOM:s}}var UY=65535,WY=2**16;function cOe(e,t){return e+t*WY}function GY(e){return e&UY}function lOe(e){return(e-(e&UY))/WY}var uOe=1,dOe=2,KY=4,qY=8,JY=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&qY)>0}get deletedBefore(){return(this.delInfo&5)>0}get deletedAfter(){return(this.delInfo&6)>0}get deletedAcross(){return(this.delInfo&KY)>0}},YY=class e{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&e.empty)return e.empty}recover(e){let t=0,n=GY(e);if(!this.inverted)for(let e=0;ee)break;let c=this.ranges[o+i],l=this.ranges[o+a],u=s+c;if(e<=u){let i=c?e==s?-1:e==u?1:t:t,a=s+r+(i<0?0:l);if(n)return a;let d=e==(t<0?s:u)?null:cOe(o/3,e-s),f=e==s?dOe:e==u?uOe:KY;return(t<0?e!=s:e!=u)&&(f|=qY),new JY(a,f,d)}r+=l-c}return n?e+r:new JY(e+r,0,null)}touches(e,t){let n=0,r=GY(t),i=this.inverted?2:1,a=this.inverted?1:2;for(let t=0;te)break;let s=this.ranges[t+i];if(e<=o+s&&t==r*3)return!0;n+=this.ranges[t+a]-s}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?n-r-1:void 0)}}invert(){let t=new e;return t.appendMappingInverted(this),t}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;nn&&t!e.isAtom||!t.type.allowsMarkType(this.mark.type)?e:e.mark(this.mark.addToSet(e.marks)),r),t.openStart,t.openEnd);return $Y.fromReplace(e,this.from,this.to,i)}invert(){return new nX(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`addMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for AddMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};QY.jsonID(`addMark`,tX);var nX=class e extends QY{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new QJ(eX(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return $Y.fromReplace(e,this.from,this.to,n)}invert(){return new tX(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`removeMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for RemoveMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};QY.jsonID(`removeMark`,nX);var rX=class e extends QY{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return $Y.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return $Y.fromReplace(e,this.pos,this.pos+1,new QJ(KJ.from(n),0,+!t.isLeaf))}invert(t){let n=t.nodeAt(this.pos);if(n){let t=this.mark.addToSet(n.marks);if(t.length==n.marks.length){for(let r=0;rr.pos?null:new e(n.pos,r.pos,i,a,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:`replaceAround`,from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`||typeof n.gapFrom!=`number`||typeof n.gapTo!=`number`||typeof n.insert!=`number`)throw RangeError(`Invalid input for ReplaceAroundStep.fromJSON`);return new e(n.from,n.to,n.gapFrom,n.gapTo,QJ.fromJSON(t,n.slice),n.insert,!!n.structure)}};QY.jsonID(`replaceAround`,oX);function sX(e,t,n){let r=e.resolve(t),i=n-t,a=r.depth;for(;i>0&&a>0&&r.indexAfter(a)==r.node(a).childCount;)a--,i--;if(i>0){let e=r.node(a).maybeChild(r.indexAfter(a));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function fOe(e,t,n,r){let i=[],a=[],o,s;e.doc.nodesBetween(t,n,(e,c,l)=>{if(!e.isInline)return;let u=e.marks;if(!r.isInSet(u)&&l.type.allowsMarkType(r.type)){let l=Math.max(c,t),d=Math.min(c+e.nodeSize,n),f=r.addToSet(u);for(let e=0;ee.step(t)),a.forEach(t=>e.step(t))}function pOe(e,t,n,r){let i=[],a=0;e.doc.nodesBetween(t,n,(e,o)=>{if(!e.isInline)return;a++;let s=null;if(r instanceof wY){let t=e.marks,n;for(;n=r.isInSet(t);)(s||=[]).push(n),t=n.removeFromSet(t)}else r?r.isInSet(e.marks)&&(s=[r]):s=e.marks;if(s&&s.length){let r=Math.min(o+e.nodeSize,n);for(let e=0;ee.step(new nX(t.from,t.to,t.style)))}function cX(e,t,n,r=n.contentMatch,i=!0){let a=e.doc.nodeAt(t),o=[],s=t+1;for(let t=0;t=0;t--)e.step(o[t])}function mOe(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function lX(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth,r=0,i=0;;--n){let a=e.$from.node(n),o=e.$from.index(n)+r,s=e.$to.indexAfter(n)-i;if(nn;e--)t||r.index(e)>0?(t=!0,u=KJ.from(r.node(e).copy(u)),d++):c--;let f=KJ.empty,p=0;for(let e=a,t=!1;e>n;e--)t||i.after(e+1)=0;e--){if(r.size){let t=n[e].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw RangeError(`Wrapper type given to Transform.wrap does not form valid content of its parent wrapper`)}r=KJ.from(n[e].type.create(n[e].attrs,r))}let i=t.start,a=t.end;e.step(new oX(i,a,i,a,new QJ(r,0,0),n.length,!0))}function yOe(e,t,n,r,i){if(!r.isTextblock)throw RangeError(`Type given to setBlockType should be a textblock`);let a=e.steps.length;e.doc.nodesBetween(t,n,(t,n)=>{let o=typeof i==`function`?i(t):i;if(t.isTextblock&&!t.hasMarkup(r,o)&&bOe(e.doc,e.mapping.slice(a).map(n),r)){let i=null;if(r.schema.linebreakReplacement){let e=r.whitespace==`pre`,t=!!r.contentMatch.matchType(r.schema.linebreakReplacement);e&&!t?i=!1:!e&&t&&(i=!0)}i===!1&&pX(e,t,n,a),cX(e,e.mapping.slice(a).map(n,1),r,void 0,i===null);let s=e.mapping.slice(a),c=s.map(n,1),l=s.map(n+t.nodeSize,1);return e.step(new oX(c,l,c+1,l-1,new QJ(KJ.from(r.create(o,null,t.marks)),0,0),1,!0)),i===!0&&fX(e,t,n,a),!1}})}function fX(e,t,n,r){t.forEach((i,a)=>{if(i.isText){let o,s=/\r?\n|\r/g;for(;o=s.exec(i.text);){let i=e.mapping.slice(r).map(n+1+a+o.index);e.replaceWith(i,i+1,t.type.schema.linebreakReplacement.create())}}})}function pX(e,t,n,r){t.forEach((i,a)=>{if(i.type==i.type.schema.linebreakReplacement){let i=e.mapping.slice(r).map(n+1+a);e.replaceWith(i,i+1,t.type.schema.text(` -`))}})}function bOe(e,t,n){let r=e.resolve(t),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function xOe(e,t,n,r,i){let a=e.doc.nodeAt(t);if(!a)throw RangeError(`No node at given position`);n||=a.type;let o=n.create(r,null,i||a.marks);if(a.isLeaf)return e.replaceWith(t,t+a.nodeSize,o);if(!n.validContent(a.content))throw RangeError(`Invalid content for node type `+n.name);e.step(new oX(t,t+a.nodeSize,t+1,t+a.nodeSize-1,new QJ(KJ.from(o),0,0),1,!0))}function mX(e,t,n=1,r){let i=e.resolve(t),a=i.depth-n,o=r&&r[r.length-1]||i.parent;if(a<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let e=i.depth-1,t=n-2;e>a;e--,t--){let n=i.node(e),a=i.index(e);if(n.type.spec.isolating)return!1;let o=n.content.cutByIndex(a,n.childCount),s=r&&r[t+1];s&&(o=o.replaceChild(0,s.type.create(s.attrs)));let c=r&&r[t]||n;if(!n.canReplace(a+1,n.childCount)||!c.type.validContent(o))return!1}let s=i.indexAfter(a),c=r&&r[0];return i.node(a).canReplaceWith(s,s,c?c.type:i.node(a+1).type)}function SOe(e,t,n=1,r){let i=e.doc.resolve(t),a=KJ.empty,o=KJ.empty;for(let e=i.depth,t=i.depth-n,s=n-1;e>t;e--,s--){a=KJ.from(i.node(e).copy(a));let t=r&&r[s];o=KJ.from(t?t.type.create(t.attrs,o):i.node(e).copy(o))}e.step(new aX(t,t,new QJ(a.append(o),n,n),!0))}function hX(e,t){let n=e.resolve(t),r=n.index();return gX(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function COe(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:r}=e.type.schema;for(let i=0;i0?(i=r.node(e+1),o++,a=r.node(e).maybeChild(o)):(i=r.node(e).maybeChild(o-1),a=r.node(e+1)),i&&!i.isTextblock&&gX(i,a)&&r.node(e).canReplace(o,o+1))return t;if(e==0)break;t=n<0?r.before(e):r.after(e)}}function wOe(e,t,n){let r=null,{linebreakReplacement:i}=e.doc.type.schema,a=e.doc.resolve(t-n),o=a.node().type;if(i&&o.inlineContent){let e=o.whitespace==`pre`,t=!!o.contentMatch.matchType(i);e&&!t?r=!1:!e&&t&&(r=!0)}let s=e.steps.length;if(r===!1){let r=e.doc.resolve(t+n);pX(e,r.node(),r.before(),s)}o.inlineContent&&cX(e,t+n-1,o,a.node().contentMatchAt(a.index()),r==null);let c=e.mapping.slice(s),l=c.map(t-n);if(e.step(new aX(l,c.map(t+n,-1),QJ.empty,!0)),r===!0){let t=e.doc.resolve(l);fX(e,t.node(),t.before(),e.steps.length)}return e}function TOe(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(r.parentOffset==0)for(let e=r.depth-1;e>=0;e--){let t=r.index(e);if(r.node(e).canReplaceWith(t,t,n))return r.before(e+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let e=r.depth-1;e>=0;e--){let t=r.indexAfter(e);if(r.node(e).canReplaceWith(t,t,n))return r.after(e+1);if(t=0;t--){let n=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1,a=r.index(t)+ +(n>0),o=r.node(t),s=!1;if(e==1)s=o.canReplace(a,a,i);else{let e=o.contentMatchAt(a).findWrapping(i.firstChild.type);s=e&&o.canReplaceWith(a,a,e[0])}if(s)return n==0?r.pos:n<0?r.before(t+1):r.after(t+1)}return null}function yX(e,t,n=t,r=QJ.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),a=e.resolve(n);return bX(i,a,r)?new aX(t,n,r):new EOe(i,a,r).fit()}function bX(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}var EOe=class{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=KJ.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=KJ.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let i=this.placed,a=n.depth,o=r.depth;for(;a&&o&&i.childCount==1;)i=i.firstChild.content,a--,o--;let s=new QJ(i,a,o);return e>-1?new oX(n.pos,e,this.$to.pos,this.$to.end(),s,t):s.size||n.pos!=this.$to.pos?new aX(n.pos,r.pos,s):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n1&&(r=0),i.type.spec.isolating&&r<=n){e=n;break}t=i.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let e,r=null;n?(r=CX(this.unplaced.content,n-1).firstChild,e=r.content):e=this.unplaced.content;let i=e.firstChild;for(let e=this.depth;e>=0;e--){let{type:a,match:o}=this.frontier[e],s,c=null;if(t==1&&(i?o.matchType(i.type)||(c=o.fillBefore(KJ.from(i),!1)):r&&a.compatibleContent(r.type)))return{sliceDepth:n,frontierDepth:e,parent:r,inject:c};if(t==2&&i&&(s=o.findWrapping(i.type)))return{sliceDepth:n,frontierDepth:e,parent:r,wrap:s};if(r&&o.matchType(r.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=CX(e,t);return!r.childCount||r.firstChild.isLeaf?!1:(this.unplaced=new QJ(e,t+1,Math.max(n,r.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=CX(e,t);if(r.childCount<=1&&t>0){let i=e.size-t<=t+r.size;this.unplaced=new QJ(xX(e,t-1,1),t-1,i?t-1:n)}else this.unplaced=new QJ(xX(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:i}){for(;this.depth>t;)this.closeFrontierNode();if(i)for(let e=0;e1||s==0||e.content.size)&&(u=t,l.push(wX(e.mark(d.allowedMarks(e.marks)),c==1?s:0,c==o.childCount?f:-1)))}let p=c==o.childCount;p||(f=-1),this.placed=SX(this.placed,t,KJ.from(l)),this.frontier[t].match=u,p&&f<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=o;e1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){scan:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],i=t=0;n--){let{match:t,type:r}=this.frontier[n],i=TX(e,n,r,t,!0);if(!i||i.childCount)continue scan}return{depth:t,fit:a,move:i?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=SX(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=SX(this.placed,this.depth,KJ.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(KJ.empty,!0);e.childCount&&(this.placed=SX(this.placed,this.frontier.length,e))}};function xX(e,t,n){return t==0?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(xX(e.firstChild.content,t-1,n)))}function SX(e,t,n){return t==0?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(SX(e.lastChild.content,t-1,n)))}function CX(e,t){for(let n=0;n1&&(r=r.replaceChild(0,wX(r.firstChild,t-1,r.childCount==1?n-1:0))),t>0&&(r=e.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(e.type.contentMatch.matchFragment(r).fillBefore(KJ.empty,!0)))),e.copy(r)}function TX(e,t,n,r,i){let a=e.node(t),o=i?e.indexAfter(t):e.index(t);if(o==a.childCount&&!n.compatibleContent(a.type))return null;let s=r.fillBefore(a.content,!0,o);return s&&!DOe(n,a.content,o)?s:null}function DOe(e,t,n){for(let r=n;r0;e--,t--){let n=i.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;o.indexOf(e)>-1?s=e:i.before(e)==t&&o.splice(1,0,-e)}let c=o.indexOf(s),l=[],u=r.openStart;for(let e=r.content,t=0;;t++){let n=e.firstChild;if(l.push(n),t==r.openStart)break;e=n.content}for(let e=u-1;e>=0;e--){let t=l[e],n=OOe(t.type);if(n&&!t.sameMarkup(i.node(Math.abs(s)-1)))u=e;else if(n||!t.type.isTextblock)break}for(let t=r.openStart;t>=0;t--){let s=(t+u+1)%(r.openStart+1),d=l[s];if(d)for(let t=0;t=0&&(e.replace(t,n,r),!(e.steps.length>d));s--){let e=o[s];e<0||(t=i.before(e),n=a.after(e))}}function EX(e,t,n,r,i){if(tr){let t=i.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(KJ.empty,!0))}return e}function AOe(e,t,n,r){if(!r.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let i=TOe(e.doc,t,r.type);i!=null&&(t=n=i)}e.replaceRange(t,n,new QJ(KJ.from(r),0,0))}function jOe(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n),a=DX(r,i);for(let t=0;t0&&(o||r.node(n-1).canReplace(r.index(n-1),i.indexAfter(n-1))))return e.delete(r.before(n),i.after(n))}for(let a=1;a<=r.depth&&a<=i.depth;a++)if(t-r.start(a)==r.depth-a&&n>r.end(a)&&i.end(a)-n!=i.depth-a&&r.start(a-1)==i.start(a-1)&&r.node(a-1).canReplace(r.index(a-1),i.index(a-1)))return e.delete(r.before(a),n);e.delete(t,n)}function DX(e,t){let n=[],r=Math.min(e.depth,t.depth);for(let i=r;i>=0;i--){let r=e.start(i);if(rt.pos+(t.depth-i)||e.node(i).type.spec.isolating||t.node(i).type.spec.isolating)break;(r==t.start(i)||i==e.depth&&i==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&i&&t.start(i-1)==r-1)&&n.push(i)}return n}var OX=class e extends QY{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return $Y.fail(`No node at attribute step's position`);let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return $Y.fromReplace(e,this.pos,this.pos+1,new QJ(KJ.from(r),0,+!t.isLeaf))}getMap(){return YY.empty}invert(t){return new e(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.attr,this.value)}toJSON(){return{stepType:`attr`,pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!=`number`||typeof n.attr!=`string`)throw RangeError(`Invalid input for AttrStep.fromJSON`);return new e(n.pos,n.attr,n.value)}};QY.jsonID(`attr`,OX);var kX=class e extends QY{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return $Y.ok(n)}getMap(){return YY.empty}invert(t){return new e(this.attr,t.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:`docAttr`,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.attr!=`string`)throw RangeError(`Invalid input for DocAttrStep.fromJSON`);return new e(n.attr,n.value)}};QY.jsonID(`docAttr`,kX);var AX=class extends Error{};AX=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},AX.prototype=Object.create(Error.prototype),AX.prototype.constructor=AX,AX.prototype.name=`TransformError`;var jX=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new XY}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new AX(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let n=0;n{e=Math.min(e,i),t=Math.max(t,a)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=QJ.empty){let r=yX(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new QJ(KJ.from(n),0,0))}delete(e,t){return this.replace(e,t,QJ.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return kOe(this,e,t,n),this}replaceRangeWith(e,t,n){return AOe(this,e,t,n),this}deleteRange(e,t){return jOe(this,e,t),this}lift(e,t){return hOe(this,e,t),this}join(e,t=1){return wOe(this,e,t),this}wrap(e,t){return vOe(this,e,t),this}setBlockType(e,t=e,n,r=null){return yOe(this,e,t,n,r),this}setNodeMarkup(e,t,n=null,r){return xOe(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new OX(e,t,n)),this}setDocAttribute(e,t){return this.step(new kX(e,t)),this}addNodeMark(e,t){return this.step(new rX(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw RangeError(`No node at position `+e);if(t instanceof XJ)t.isInSet(n.marks)&&this.step(new iX(e,t));else{let r=n.marks,i,a=[];for(;i=t.isInSet(r);)a.push(new iX(e,i)),r=i.removeFromSet(r);for(let e=a.length-1;e>=0;e--)this.step(a[e])}return this}split(e,t=1,n){return SOe(this,e,t,n),this}addMark(e,t,n){return fOe(this,e,t,n),this}removeMark(e,t,n){return pOe(this,e,t,n),this}clearIncompatible(e,t,n){return cX(this,e,t,n),this}},MX=Object.create(null),NX=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new MOe(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;r--){let i=t<0?BX(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):BX(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new zX(e.node(0))}static atStart(e){return BX(e,e,0,0,1)||new zX(e)}static atEnd(e){return BX(e,e,e.content.size,e.childCount,-1)||new zX(e)}static fromJSON(e,t){if(!t||!t.type)throw RangeError(`Invalid input for Selection.fromJSON`);let n=MX[t.type];if(!n)throw RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in MX)throw RangeError(`Duplicate use of selection JSON ID `+e);return MX[e]=t,t.prototype.jsonID=e,t}getBookmark(){return IX.between(this.$anchor,this.$head).getBookmark()}};NX.prototype.visible=!0;var MOe=class{constructor(e,t){this.$from=e,this.$to=t}},PX=!1;function FX(e){!PX&&!e.parent.inlineContent&&(PX=!0,console.warn(`TextSelection endpoint not pointing into a node with inline content (`+e.parent.type.name+`)`))}var IX=class e extends NX{constructor(e,t=e){FX(e),FX(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return NX.near(r);let i=t.resolve(n.map(this.anchor));return new e(i.parent.inlineContent?i:r,r)}replace(e,t=QJ.empty){if(super.replace(e,t),t==QJ.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(t){return t instanceof e&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new LX(this.anchor,this.head)}toJSON(){return{type:`text`,anchor:this.anchor,head:this.head}}static fromJSON(t,n){if(typeof n.anchor!=`number`||typeof n.head!=`number`)throw RangeError(`Invalid input for TextSelection.fromJSON`);return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(t,n,r){let i=t.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let e=NX.findFrom(n,r,!0)||NX.findFrom(n,-r,!0);if(e)n=e.$head;else return NX.near(n,r)}return t.parent.inlineContent||(i==0?t=n:(t=(NX.findFrom(t,-r,!0)||NX.findFrom(t,r,!0)).$anchor,t.pos0?0:1);i>0?o=0;o+=i){let r=t.child(o);if(!r.isAtom){let t=BX(e,r,n+i,i<0?r.childCount:0,i,a);if(t)return t}else if(!a&&RX.isSelectable(r))return RX.create(e,n-(i<0?r.nodeSize:0));n+=r.nodeSize*i}return null}function VX(e,t,n){let r=e.steps.length-1;if(r{o??=r}),e.setSelection(NX.near(e.doc.resolve(o),n))}var HX=1,UX=2,WX=4,FOe=class extends jX{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=UX,this}ensureMarks(e){return XJ.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&UX)>0}addStep(e,t){super.addStep(e,t),this.updated&=-3,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||XJ.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(n??=t,!e)return this.deleteRange(t,n);let i=this.storedMarks;if(!i){let e=this.doc.resolve(t);i=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,i)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(NX.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e==`string`?e:e.key]=t,this}getMeta(e){return this.meta[typeof e==`string`?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=WX,this}get scrolledIntoView(){return(this.updated&WX)>0}};function GX(e,t){return!t||!e?e:e.bind(t)}var KX=class{constructor(e,t,n){this.name=e,this.init=GX(t.init,n),this.apply=GX(t.apply,n)}},IOe=[new KX(`doc`,{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new KX(`selection`,{init(e,t){return e.selection||NX.atStart(t.doc)},apply(e){return e.selection}}),new KX(`storedMarks`,{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new KX(`scrollToSelection`,{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}})],qX=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=IOe.slice(),t&&t.forEach(e=>{if(this.pluginsByKey[e.key])throw RangeError(`Adding different instances of a keyed plugin (`+e.key+`)`);this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new KX(e.key,e.spec.state,e))})}},LOe=class e{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;ne.toJSON())),e&&typeof e==`object`)for(let n in e){if(n==`doc`||n==`selection`)throw RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],i=r.spec.state;i&&i.toJSON&&(t[n]=i.toJSON.call(r,this[r.key]))}return t}static fromJSON(t,n,r){if(!n)throw RangeError(`Invalid input for EditorState.fromJSON`);if(!t.schema)throw RangeError(`Required config field 'schema' missing`);let i=new qX(t.schema,t.plugins),a=new e(i);return i.fields.forEach(e=>{if(e.name==`doc`)a.doc=fY.fromJSON(t.schema,n.doc);else if(e.name==`selection`)a.selection=NX.fromJSON(a.doc,n.selection);else if(e.name==`storedMarks`)n.storedMarks&&(a.storedMarks=n.storedMarks.map(t.schema.markFromJSON));else{if(r)for(let i in r){let o=r[i],s=o.spec.state;if(o.key==e.name&&s&&s.fromJSON&&Object.prototype.hasOwnProperty.call(n,i)){a[e.name]=s.fromJSON.call(o,t,n[i],a);return}}a[e.name]=e.init(t,a)}}),a}};function JX(e,t,n){for(let r in e){let i=e[r];i instanceof Function?i=i.bind(t):r==`handleDOMEvents`&&(i=JX(i,t,{})),n[r]=i}return n}var YX=class{constructor(e){this.spec=e,this.props={},e.props&&JX(e.props,this,this.props),this.key=e.key?e.key.key:ZX(`plugin`)}getState(e){return e[this.key]}},XX=Object.create(null);function ZX(e){return e in XX?e+`$`+ ++XX[e]:(XX[e]=0,e+`$`)}var QX=class{constructor(e=`key`){this.key=ZX(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}},$X=(e,t)=>e.selection.empty?!1:(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function eZ(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`backward`,e):n.parentOffset>0)?null:n}var tZ=(e,t,n)=>{let r=eZ(e,n);if(!r)return!1;let i=aZ(r);if(!i){let n=r.blockRange(),i=n&&lX(n);return i==null?!1:(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let a=i.nodeBefore;if(hZ(e,i,t,-1))return!0;if(r.parent.content.size==0&&(rZ(a,`end`)||RX.isSelectable(a)))for(let n=r.depth;;n--){let o=yX(e.doc,r.before(n),r.after(n),QJ.empty);if(o&&o.slice.size1)break}return a.isAtom&&i.depth==r.depth-1?(t&&t(e.tr.delete(i.pos-a.nodeSize,i.pos).scrollIntoView()),!0):!1},ROe=(e,t,n)=>{let r=eZ(e,n);if(!r)return!1;let i=aZ(r);return i?nZ(e,i,t):!1},zOe=(e,t,n)=>{let r=oZ(e,n);if(!r)return!1;let i=lZ(r);return i?nZ(e,i,t):!1};function nZ(e,t,n){let r=t.nodeBefore,i=t.pos-1;for(;!r.isTextblock;i--){if(r.type.spec.isolating)return!1;let e=r.lastChild;if(!e)return!1;r=e}let a=t.nodeAfter,o=t.pos+1;for(;!a.isTextblock;o++){if(a.type.spec.isolating)return!1;let e=a.firstChild;if(!e)return!1;a=e}let s=yX(e.doc,i,o,QJ.empty);if(!s||s.from!=i||s instanceof aX&&s.slice.size>=o-i)return!1;if(n){let t=e.tr.step(s);t.setSelection(IX.create(t.doc,i)),n(t.scrollIntoView())}return!0}function rZ(e,t,n=!1){for(let r=e;r;r=t==`start`?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}var iZ=(e,t,n)=>{let{$head:r,empty:i}=e.selection,a=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`backward`,e):r.parentOffset>0)return!1;a=aZ(r)}let o=a&&a.nodeBefore;return!o||!RX.isSelectable(o)?!1:(t&&t(e.tr.setSelection(RX.create(e.doc,a.pos-o.nodeSize)).scrollIntoView()),!0)};function aZ(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function oZ(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`forward`,e):n.parentOffset{let r=oZ(e,n);if(!r)return!1;let i=lZ(r);if(!i)return!1;let a=i.nodeAfter;if(hZ(e,i,t,1))return!0;if(r.parent.content.size==0&&(rZ(a,`start`)||RX.isSelectable(a))){let n=yX(e.doc,r.before(),r.after(),QJ.empty);if(n&&n.slice.size{let{$head:r,empty:i}=e.selection,a=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`forward`,e):r.parentOffset=0;t--){let n=e.node(t);if(e.index(t)+1{let n=e.selection,r=n instanceof RX,i;if(r){if(n.node.isTextblock||!hX(e.doc,n.from))return!1;i=n.from}else if(i=_X(e.doc,n.from,-1),i==null)return!1;if(t){let n=e.tr.join(i);r&&n.setSelection(RX.create(n.doc,i-e.doc.resolve(i).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0},VOe=(e,t)=>{let n=e.selection,r;if(n instanceof RX){if(n.node.isTextblock||!hX(e.doc,n.to))return!1;r=n.to}else if(r=_X(e.doc,n.to,1),r==null)return!1;return t&&t(e.tr.join(r).scrollIntoView()),!0},HOe=(e,t)=>{let{$from:n,$to:r}=e.selection,i=n.blockRange(r),a=i&&lX(i);return a==null?!1:(t&&t(e.tr.lift(i,a).scrollIntoView()),!0)},uZ=(e,t)=>{let{$head:n,$anchor:r}=e.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(t&&t(e.tr.insertText(` -`).scrollIntoView()),!0)};function dZ(e){for(let t=0;t{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),a=n.indexAfter(-1),o=dZ(i.contentMatchAt(a));if(!o||!i.canReplaceWith(a,a,o))return!1;if(t){let r=n.after(),i=e.tr.replaceWith(r,r,o.createAndFill());i.setSelection(NX.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0},pZ=(e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof zX||r.parent.inlineContent||i.parent.inlineContent)return!1;let a=dZ(i.parent.contentMatchAt(i.indexAfter()));if(!a||!a.isTextblock)return!1;if(t){let n=(!r.parentOffset&&i.index(){let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(mX(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),i=r&&lX(r);return i==null?!1:(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)};function UOe(e){return(t,n)=>{let{$from:r,$to:i}=t.selection;if(t.selection instanceof RX&&t.selection.node.isBlock)return!r.parentOffset||!mX(t.doc,r.pos)?!1:(n&&n(t.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let a=[],o,s,c=!1,l=!1;for(let t=r.depth;;t--)if(r.node(t).isBlock){c=r.end(t)==r.pos+(r.depth-t),l=r.start(t)==r.pos-(r.depth-t),s=dZ(r.node(t-1).contentMatchAt(r.indexAfter(t-1)));let n=e&&e(i.parent,c,r);a.unshift(n||(c&&s?{type:s}:null)),o=t;break}else{if(t==1)return!1;a.unshift(null)}let u=t.tr;(t.selection instanceof IX||t.selection instanceof zX)&&u.deleteSelection();let d=u.mapping.map(r.pos),f=mX(u.doc,d,a.length,a);if(f||=(a[0]=s?{type:s}:null,mX(u.doc,d,a.length,a)),!f)return!1;if(u.split(d,a.length,a),!c&&l&&r.node(o).type!=s){let e=u.mapping.map(r.before(o)),t=u.doc.resolve(e);s&&r.node(o-1).canReplaceWith(t.index(),t.index()+1,s)&&u.setNodeMarkup(u.mapping.map(r.before(o)),s)}return n&&n(u.scrollIntoView()),!0}}var WOe=UOe(),GOe=(e,t)=>{let{$from:n,to:r}=e.selection,i,a=n.sharedDepth(r);return a==0?!1:(i=n.before(a),t&&t(e.tr.setSelection(RX.create(e.doc,i))),!0)},KOe=(e,t)=>(t&&t(e.tr.setSelection(new zX(e.doc))),!0);function qOe(e,t,n){let r=t.nodeBefore,i=t.nodeAfter,a=t.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&t.parent.canReplace(a-1,a)?(n&&n(e.tr.delete(t.pos-r.nodeSize,t.pos).scrollIntoView()),!0):!t.parent.canReplace(a,a+1)||!(i.isTextblock||hX(e.doc,t.pos))?!1:(n&&n(e.tr.join(t.pos).scrollIntoView()),!0)}function hZ(e,t,n,r){let i=t.nodeBefore,a=t.nodeAfter,o,s,c=i.type.spec.isolating||a.type.spec.isolating;if(!c&&qOe(e,t,n))return!0;let l=!c&&t.parent.canReplace(t.index(),t.index()+1);if(l&&(o=(s=i.contentMatchAt(i.childCount)).findWrapping(a.type))&&s.matchType(o[0]||a.type).validEnd){if(n){let r=t.pos+a.nodeSize,s=KJ.empty;for(let e=o.length-1;e>=0;e--)s=KJ.from(o[e].create(null,s));s=KJ.from(i.copy(s));let c=e.tr.step(new oX(t.pos-1,r,t.pos,r,new QJ(s,1,0),o.length,!0)),l=c.doc.resolve(r+2*o.length);l.nodeAfter&&l.nodeAfter.type==i.type&&hX(c.doc,l.pos)&&c.join(l.pos),n(c.scrollIntoView())}return!0}let u=a.type.spec.isolating||r>0&&c?null:NX.findFrom(t,1),d=u&&u.$from.blockRange(u.$to),f=d&&lX(d);if(f!=null&&f>=t.depth)return n&&n(e.tr.lift(d,f).scrollIntoView()),!0;if(l&&rZ(a,`start`,!0)&&rZ(i,`end`)){let r=i,o=[];for(;o.push(r),!r.isTextblock;)r=r.lastChild;let s=a,c=1;for(;!s.isTextblock;s=s.firstChild)c++;if(r.canReplace(r.childCount,r.childCount,s.content)){if(n){let r=KJ.empty;for(let e=o.length-1;e>=0;e--)r=KJ.from(o[e].copy(r));n(e.tr.step(new oX(t.pos-o.length,t.pos+a.nodeSize,t.pos+c,t.pos+a.nodeSize-c,new QJ(r,o.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function gZ(e){return function(t,n){let r=t.selection,i=e<0?r.$from:r.$to,a=i.depth;for(;i.node(a).isInline;){if(!a)return!1;a--}return i.node(a).isTextblock?(n&&n(t.tr.setSelection(IX.create(t.doc,e<0?i.start(a):i.end(a)))),!0):!1}}var _Z=gZ(-1),vZ=gZ(1);function JOe(e,t=null){return function(n,r){let{$from:i,$to:a}=n.selection,o=i.blockRange(a),s=o&&uX(o,e,t);return s?(r&&r(n.tr.wrap(o,s).scrollIntoView()),!0):!1}}function yZ(e,t=null){return function(n,r){let i=!1;for(let r=0;r{if(i)return!1;if(!(!r.isTextblock||r.hasMarkup(e,t)))if(r.type==e)i=!0;else{let t=n.doc.resolve(a),r=t.index();i=t.parent.canReplaceWith(r,r+1,e)}})}if(!i)return!1;if(r){let i=n.tr;for(let r=0;r=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&t.startIndex==0){if(t.$from.index(t.depth-1)==0)return!1;let e=o.resolve(t.start-2);a=new dY(e,e,t.depth),t.endIndex=0;e--)a=KJ.from(n[e].type.create(n[e].attrs,a));e.step(new oX(t.start-(r?2:0),t.end,t.start,t.end,new QJ(a,0,0),n.length,!0));let o=0;for(let e=0;et.childCount>0&&t.firstChild.type==e);return a?n?r.node(a.depth-1).type==e?eke(t,n,e,a):tke(t,n,a):!0:!1}}function eke(e,t,n,r){let i=e.tr,a=r.end,o=r.$to.end(r.depth);aa;t--)e-=i.child(t).nodeSize,r.delete(e-1,e+1);let a=r.doc.resolve(n.start),o=a.nodeAfter;if(r.mapping.map(n.end)!=n.start+a.nodeAfter.nodeSize)return!1;let s=n.startIndex==0,c=n.endIndex==i.childCount,l=a.node(-1),u=a.index(-1);if(!l.canReplace(u+ +!s,u+1,o.content.append(c?KJ.empty:KJ.from(i))))return!1;let d=a.pos,f=d+o.nodeSize;return r.step(new oX(d-+!!s,f+ +!!c,d+1,f-1,new QJ((s?KJ.empty:KJ.from(i.copy(KJ.empty))).append(c?KJ.empty:KJ.from(i.copy(KJ.empty))),+!s,+!c),+!s)),t(r.scrollIntoView()),!0}function nke(e){return function(t,n){let{$from:r,$to:i}=t.selection,a=r.blockRange(i,t=>t.childCount>0&&t.firstChild.type==e);if(!a)return!1;let o=a.startIndex;if(o==0)return!1;let s=a.parent,c=s.child(o-1);if(c.type!=e)return!1;if(n){let r=c.lastChild&&c.lastChild.type==s.type,i=KJ.from(r?e.create():null),o=new QJ(KJ.from(e.create(null,KJ.from(s.type.create(null,i)))),r?3:1,0),l=a.start,u=a.end;n(t.tr.step(new oX(l-(r?3:1),u,l,u,o,1,!0)).scrollIntoView())}return!0}}var wZ=function(e){for(var t=0;;t++)if(e=e.previousSibling,!e)return t},TZ=function(e){let t=e.assignedSlot||e.parentNode;return t&&t.nodeType==11?t.host:t},EZ=null,DZ=function(e,t,n){let r=EZ||=document.createRange();return r.setEnd(e,n??e.nodeValue.length),r.setStart(e,t||0),r},rke=function(){EZ=null},OZ=function(e,t,n,r){return n&&(kZ(e,t,n,r,-1)||kZ(e,t,n,r,1))},ike=/^(img|br|input|textarea|hr)$/i;function kZ(e,t,n,r,i){for(;;){if(e==n&&t==r)return!0;if(t==(i<0?0:AZ(e))){let n=e.parentNode;if(!n||n.nodeType!=1||jZ(e)||ike.test(e.nodeName)||e.contentEditable==`false`)return!1;t=wZ(e)+(i<0?0:1),e=n}else if(e.nodeType==1){let n=e.childNodes[t+(i<0?-1:0)];if(n.nodeType==1&&n.contentEditable==`false`)if(n.pmViewDesc?.ignoreForSelection)t+=i;else return!1;else e=n,t=i<0?AZ(e):0}else return!1}}function AZ(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function ake(e,t){for(;;){if(e.nodeType==3&&t)return e;if(e.nodeType==1&&t>0){if(e.contentEditable==`false`)return null;e=e.childNodes[t-1],t=AZ(e)}else if(e.parentNode&&!jZ(e))t=wZ(e),e=e.parentNode;else return null}}function oke(e,t){for(;;){if(e.nodeType==3&&t2),JZ=qZ||(PZ?/Mac/.test(PZ.platform):!1),YZ=PZ?/Win/.test(PZ.platform):!1,XZ=/Android \d/.test(IZ),ZZ=!!FZ&&`webkitFontSmoothing`in FZ.documentElement.style,uke=ZZ?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function dke(e){let t=e.defaultView&&e.defaultView.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function QZ(e,t){return typeof e==`number`?e:e[t]}function fke(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}function $Z(e,t,n){let r=e.someProp(`scrollThreshold`)||0,i=e.someProp(`scrollMargin`)||5,a=e.dom.ownerDocument;for(let o=n||e.dom;o;){if(o.nodeType!=1){o=TZ(o);continue}let e=o,n=e==a.body,s=n?dke(a):fke(e),c=0,l=0;if(t.tops.bottom-QZ(r,`bottom`)&&(l=t.bottom-t.top>s.bottom-s.top?t.top+QZ(i,`top`)-s.top:t.bottom-s.bottom+QZ(i,`bottom`)),t.lefts.right-QZ(r,`right`)&&(c=t.right-s.right+QZ(i,`right`)),c||l)if(n)a.defaultView.scrollBy(c,l);else{let n=e.scrollLeft,r=e.scrollTop;l&&(e.scrollTop+=l),c&&(e.scrollLeft+=c);let i=e.scrollLeft-n,a=e.scrollTop-r;t={left:t.left-i,top:t.top-a,right:t.right-i,bottom:t.bottom-a}}let u=n?`fixed`:getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(u))break;o=u==`absolute`?o.offsetParent:TZ(o)}}function pke(e){let t=e.dom.getBoundingClientRect(),n=Math.max(0,t.top),r,i;for(let a=(t.left+t.right)/2,o=n+1;o=n-20){r=t,i=s.top;break}}return{refDOM:r,refTop:i,stack:eQ(e.dom)}}function eQ(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=TZ(r));return t}function mke({refDOM:e,refTop:t,stack:n}){let r=e?e.getBoundingClientRect().top:0;tQ(n,r==0?0:r-t)}function tQ(e,t){for(let n=0;n=s){o=Math.max(p.bottom,o),s=Math.min(p.top,s);let e=p.left>t.left?p.left-t.left:p.right=(p.left+p.right)/2));continue}}else p.top>t.top&&!c&&p.left<=t.left&&p.right>=t.left&&(c=u,l={left:Math.max(p.left,Math.min(p.right,t.left)),top:p.top});!n&&(t.left>=p.right&&t.top>=p.top||t.left>=p.left&&t.top>=p.bottom)&&(a=d+1)}}return!n&&c&&(n=c,i=l,r=0),n&&n.nodeType==3?gke(n,i):!n||r&&n.nodeType==1?{node:e,offset:a}:rQ(n,i)}function gke(e,t){let n=e.nodeValue.length,r=document.createRange(),i;for(let a=0;a=(n.left+n.right)/2)};break}}return r.detach(),i||{node:e,offset:0}}function iQ(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function _ke(e,t){let n=e.parentNode;return n&&/^li$/i.test(n.nodeName)&&t.left(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(r,i,a)}function yke(e,t,n,r){let i=-1;for(let n=t,a=!1;n!=e.dom;){let t=e.docView.nearestDesc(n,!0),o;if(!t)return null;if(t.dom.nodeType==1&&(t.node.isBlock&&t.parent||!t.contentDOM)&&((o=t.dom.getBoundingClientRect()).width||o.height)&&(t.node.isBlock&&t.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(t.dom.nodeName)&&(!a&&o.left>r.left||o.top>r.top?i=t.posBefore:(!a&&o.right-1?i:e.docView.posFromDOM(t,n,-1)}function aQ(e,t,n){let r=e.childNodes.length;if(r&&n.topt.top&&i++}let n;ZZ&&i&&r.nodeType==1&&(n=r.childNodes[i-1]).nodeType==1&&n.contentEditable==`false`&&n.getBoundingClientRect().top>=t.top&&i--,r==e.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&t.top>r.lastChild.getBoundingClientRect().bottom?s=e.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!=`BR`)&&(s=yke(e,r,i,t))}s??=vke(e,o,t);let c=e.docView.nearestDesc(o,!0);return{pos:s,inside:c?c.posAtStart-c.border:-1}}function oQ(e){return e.top=0&&i==r.nodeValue.length?(e--,a=1):n<0?e--:t++,lQ(sQ(DZ(r,e,t),a),a<0)}if(!e.state.doc.resolve(t-(a||0)).parent.inlineContent){if(a==null&&i&&(n<0||i==AZ(r))){let e=r.childNodes[i-1];if(e.nodeType==1)return uQ(e.getBoundingClientRect(),!1)}if(a==null&&i=0)}if(a==null&&i&&(n<0||i==AZ(r))){let e=r.childNodes[i-1],t=e.nodeType==3?DZ(e,AZ(e)-+!o):e.nodeType==1&&(e.nodeName!=`BR`||!e.nextSibling)?e:null;if(t)return lQ(sQ(t,1),!1)}if(a==null&&i=0)}function lQ(e,t){if(e.width==0)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function uQ(e,t){if(e.height==0)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function dQ(e,t,n){let r=e.state,i=e.root.activeElement;r!=t&&e.updateState(t),i!=e.dom&&e.focus();try{return n()}finally{r!=t&&e.updateState(r),i!=e.dom&&i&&i.focus()}}function Ske(e,t,n){let r=t.selection,i=n==`up`?r.$from:r.$to;return dQ(e,t,()=>{let{node:t}=e.docView.domFromPos(i.pos,n==`up`?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.contentDOM||n.dom;break}t=n.dom.parentNode}let r=cQ(e,i.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(e.nodeType==1)t=e.getClientRects();else if(e.nodeType==3)t=DZ(e,0,e.nodeValue.length).getClientRects();else continue;for(let e=0;ei.top+1&&(n==`up`?r.top-i.top>(i.bottom-r.top)*2:i.bottom-r.bottom>(r.bottom-i.top)*2))return!1}}return!0})}var Cke=/[\u0590-\u08ac]/;function wke(e,t,n){let{$head:r}=t.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,a=!i,o=i==r.parent.content.size,s=e.domSelection();return s?!Cke.test(r.parent.textContent)||!s.modify?n==`left`||n==`backward`?a:o:dQ(e,t,()=>{let{focusNode:t,focusOffset:i,anchorNode:a,anchorOffset:o}=e.domSelectionRange(),c=s.caretBidiLevel;s.modify(`move`,n,`character`);let l=r.depth?e.docView.domAfterPos(r.before()):e.dom,{focusNode:u,focusOffset:d}=e.domSelectionRange(),f=u&&!l.contains(u.nodeType==1?u:u.parentNode)||t==u&&i==d;try{s.collapse(a,o),t&&(t!=a||i!=o)&&s.extend&&s.extend(t,i)}catch{}return c!=null&&(s.caretBidiLevel=c),f}):r.pos==r.start()||r.pos==r.end()}var fQ=null,pQ=null,mQ=!1;function Tke(e,t,n){return fQ==t&&pQ==n?mQ:(fQ=t,pQ=n,mQ=n==`up`||n==`down`?Ske(e,t,n):wke(e,t,n))}var hQ=0,gQ=1,_Q=2,vQ=3,yQ=class{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=hQ,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;twZ(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!1;break}if(t.previousSibling)break}if(r==null&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!0;break}if(t.nextSibling)break}}return r??n>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let i=this.getDesc(r),a;if(i&&(!t||i.node))if(n&&(a=i.nodeDOM)&&!(a.nodeType==1?a.contains(e.nodeType==1?e:e.parentNode):a==e))n=!1;else return i}}getDesc(e){let t=e.pmViewDesc;for(let e=t;e;e=e.parent)if(e==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let i=this.getDesc(r);if(i)return i.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;te||i instanceof TQ){r=e-t;break}t=a}if(r)return this.children[n].domFromPos(r-this.children[n].border,t);for(let e;n&&!(e=this.children[n-1]).size&&e instanceof bQ&&e.side>=0;n--);if(t<=0){let e,r=!0;for(;e=n?this.children[n-1]:null,!(!e||e.dom.parentNode==this.contentDOM);n--,r=!1);return e&&t&&r&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?wZ(e.dom)+1:0}}else{let e,r=!0;for(;e=n=i&&t<=s-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,i);e=a;for(let t=o;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=wZ(n.dom)+1;break}e-=n.size}r==-1&&(r=0)}if(r>-1&&(s>t||o==this.children.length-1)){t=s;for(let e=o+1;es&&at){let e=o;o=s,s=e}let n=document.createRange();n.setEnd(s.node,s.offset),n.setStart(o.node,o.offset),c.removeAllRanges(),c.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&e.type!=`selection`}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,r=0;r=n:en){let r=n+i.border,o=a-i.border;if(e>=r&&t<=o){this.dirty=e==n||t==a?_Q:gQ,e==r&&t==o&&(i.contentLost||i.dom.parentNode!=this.contentDOM)?i.dirty=vQ:i.markDirty(e-r,t-r);return}else i.dirty=i.dom==i.contentDOM&&i.dom.parentNode==this.contentDOM&&!i.children.length?_Q:vQ}n=a}this.dirty=_Q}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?_Q:gQ;t.dirty{if(!i)return r;if(i.parent)return i.parent.posBeforeChild(i)})),!t.type.spec.raw){if(a.nodeType!=1){let e=document.createElement(`span`);e.appendChild(a),a=e}a.contentEditable=`false`,a.classList.add(`ProseMirror-widget`)}super(e,[],a,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return this.dirty==hQ&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!=`selection`||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}},Eke=class extends yQ{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e==this.textDOM?this.posAtStart+t:this.posAtStart+(t?this.size:0)}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type===`characterData`&&e.target.nodeValue==e.oldValue}},xQ=class e extends yQ{constructor(e,t,n,r,i){super(e,[],n,r),this.mark=t,this.spec=i}static create(t,n,r,i){let a=i.nodeViews[n.type.name],o=a&&a(n,i,r);return(!o||!o.dom)&&(o=RY.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new e(t,n,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&vQ||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=vQ&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=hQ){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty0&&(a=PQ(a,0,t,r));for(let e=0;e{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),u=l&&l.dom,d=l&&l.contentDOM;if(n.isText){if(!u)u=document.createTextNode(n.text);else if(u.nodeType!=3)throw RangeError(`Text must be rendered as a DOM text node`)}else if(!u){let e=RY.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs);({dom:u,contentDOM:d}=e)}!d&&!n.isText&&u.nodeName!=`BR`&&(u.hasAttribute(`contenteditable`)||(u.contentEditable=`false`),n.type.spec.draggable&&(u.draggable=!0));let f=u;return u=jQ(u,r,n),l?c=new Dke(t,n,r,i,u,d||null,f,l,a,o+1):n.isText?new wQ(t,n,r,i,u,f,a):new e(t,n,r,i,u,d||null,f,a,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace==`pre`&&(e.preserveWhitespace=`full`),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>KJ.empty)}return e}matchesNode(e,t,n){return this.dirty==hQ&&e.eq(this.node)&&MQ(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return+!this.node.isLeaf}updateChildren(e,t){let n=this.node.inlineContent,r=t,i=e.composing?this.localCompositionInfo(e,t):null,a=i&&i.pos>-1?i:null,o=i&&i.pos<0,s=new kke(this,a&&a.node,e);Mke(this.node,this.innerDeco,(t,i,a)=>{t.spec.marks?s.syncToMarks(t.spec.marks,n,e,i):t.type.side>=0&&!a&&s.syncToMarks(i==this.node.childCount?XJ.none:this.node.child(i).marks,n,e,i),s.placeWidget(t,e,r)},(t,a,c,l)=>{s.syncToMarks(t.marks,n,e,l);let u;s.findNodeMatch(t,a,c,l)||o&&e.state.selection.from>r&&e.state.selection.to-1&&s.updateNodeAt(t,a,c,u,e)||s.updateNextNode(t,a,c,e,l,r)||s.addNode(t,a,c,e,r),r+=t.nodeSize}),s.syncToMarks([],n,e,0),this.node.isTextblock&&s.addTextblockHacks(),s.destroyRest(),(s.changed||this.dirty==_Q)&&(a&&this.protectLocalComposition(e,a),EQ(this.contentDOM,this.children,e),qZ&&Nke(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof IX)||nt+this.node.content.size)return null;let i=e.input.compositionNode;if(!i||!this.dom.contains(i.parentNode))return null;if(this.node.inlineContent){let e=i.nodeValue,a=Pke(this.node.content,e,n-t,r-t);return a<0?null:{node:i,pos:a,text:e}}else return{node:i,pos:-1,text:``}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&=void 0}let a=new Eke(this,i,t,r);e.input.compositionNodes.push(a),this.children=PQ(this.children,n,n+r.length,e,a)}update(e,t,n,r){return this.dirty==vQ||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=hQ}updateOuterDeco(e){if(MQ(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,n=this.dom;this.dom=AQ(this.dom,this.nodeDOM,kQ(this.outerDeco,this.node,t),kQ(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute(`draggable`))}get domAtom(){return this.node.isAtom}};function CQ(e,t,n,r,i){jQ(r,t,e);let a=new SQ(void 0,e,t,n,r,r,r,i,0);return a.contentDOM&&a.updateChildren(i,0),a}var wQ=class e extends SQ{constructor(e,t,n,r,i,a,o){super(e,t,n,r,i,null,a,o,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return this.dirty==vQ||this.dirty!=hQ&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=hQ||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=hQ,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!=`characterData`&&e.type!=`selection`}slice(t,n,r){let i=this.node.cut(t,n),a=document.createTextNode(i.text);return new e(this.parent,i,this.outerDeco,this.innerDeco,a,a,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=vQ)}get domAtom(){return!1}isText(e){return this.node.text==e}},TQ=class extends yQ{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==hQ&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName==`IMG`}},Dke=class extends SQ{constructor(e,t,n,r,i,a,o,s,c,l){super(e,t,n,r,i,a,o,c,l),this.spec=s}update(e,t,n,r){if(this.dirty==vQ)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let i=this.spec.update(e,t,n);return i&&this.updateInner(e,t,n,r),i}else if(!this.contentDOM&&!e.isLeaf)return!1;else return super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function EQ(e,t,n){let r=e.firstChild,i=!1;for(let a=0;a>1,o=Math.min(a,e.length);for(;i-1)i>this.index&&(this.changed=!0,this.destroyBetween(this.index,i)),this.top=this.top.children[this.index];else{let r=xQ.create(this.top,e[a],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,a++}}findNodeMatch(e,t,n,r){let i=-1,a;if(r>=this.preMatch.index&&(a=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&a.matchesNode(e,t,n))i=this.top.children.indexOf(a,this.index);else for(let r=this.index,a=Math.min(this.top.children.length,r+5);r0;){let s;for(;;)if(r){let e=n.children[r-1];if(e instanceof xQ)n=e,r=e.children.length;else{s=e,r--;break}}else if(n==t)break outer;else r=n.parent.children.indexOf(n),n=n.parent;let c=s.node;if(c){if(c!=e.child(i-1))break;--i,a.set(s,i),o.push(s)}}return{index:i,matched:a,matches:o.reverse()}}function jke(e,t){return e.type.side-t.type.side}function Mke(e,t,n,r){let i=t.locals(e),a=0;if(i.length==0){for(let n=0;na;)s.push(i[o++]);let m=a+f.nodeSize;if(f.isText){let e=m;o!e.inline):s.slice();r(f,h,t.forChild(a,f),p),a=m}}function Nke(e){if(e.nodeName==`UL`||e.nodeName==`OL`){let t=e.style.cssText;e.style.cssText=t+`; list-style: square !important`,window.getComputedStyle(e).listStyle,e.style.cssText=t}}function Pke(e,t,n,r){for(let i=0,a=0;i=n){if(a>=r&&c.slice(r-t.length-s,r-s)==t)return r-t.length;let e=s=0&&e+t.length+s>=n)return s+e;if(n==r&&c.length>=r+t.length-s&&c.slice(r-s,r-s+t.length)==t)return r}}return-1}function PQ(e,t,n,r,i){let a=[];for(let o=0,s=0;o=n||u<=t?a.push(c):(ln&&a.push(c.slice(n-l,c.size,r)))}return a}function FQ(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let i=e.docView.nearestDesc(n.focusNode),a=i&&i.size==0,o=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let s=r.resolve(o),c,l;if(MZ(n)){for(c=o;i&&!i.node;)i=i.parent;let e=i.node;if(i&&e.isAtom&&RX.isSelectable(e)&&i.parent&&!(e.isInline&&ske(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;l=new RX(o==e?s:r.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=o,i=o;for(let r=0;r{(n.anchorNode!=r||n.anchorOffset!=i)&&(t.removeEventListener(`selectionchange`,e.input.hideSelectionGuard),setTimeout(()=>{(!IQ(e)||e.state.selection.visible)&&e.dom.classList.remove(`ProseMirror-hideselection`)},20))})}function Ike(e){let t=e.domSelection();if(!t)return;let n=e.cursorWrapper.dom,r=n.nodeName==`IMG`;r?t.collapse(n.parentNode,wZ(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&BZ&&VZ<=11&&(n.disabled=!0,n.disabled=!1)}function HQ(e,t){if(t instanceof RX){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(UQ(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else UQ(e)}function UQ(e){e.lastSelectedViewDesc&&=(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),void 0)}function WQ(e,t,n,r){return e.someProp(`createSelectionBetween`,r=>r(e,t,n))||IX.between(t,n,r)}function GQ(e){return e.editable&&!e.hasFocus()?!1:KQ(e)}function KQ(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return e.dom.contains(t.anchorNode.nodeType==3?t.anchorNode.parentNode:t.anchorNode)&&(e.editable||e.dom.contains(t.focusNode.nodeType==3?t.focusNode.parentNode:t.focusNode))}catch{return!1}}function Lke(e){let t=e.docView.domFromPos(e.state.selection.anchor,0),n=e.domSelectionRange();return OZ(t.node,t.offset,n.anchorNode,n.anchorOffset)}function qQ(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),a=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):null:i;return a&&NX.findFrom(a,t)}function JQ(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function YQ(e,t,n){let r=e.state.selection;if(r instanceof IX){if(n.indexOf(`s`)>-1){let{$head:n}=r,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let a=e.state.doc.resolve(n.pos+i.nodeSize*(t<0?-1:1));return JQ(e,new IX(r.$anchor,a))}else if(!r.empty)return!1;else if(e.endOfTextblock(t>0?`forward`:`backward`)){let n=qQ(e.state,t);return n&&n instanceof RX?JQ(e,n):!1}else if(!(JZ&&n.indexOf(`m`)>-1)){let n=r.$head,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter,a;if(!i||i.isText)return!1;let o=t<0?n.pos-i.nodeSize:n.pos;return i.isAtom||(a=e.docView.descAt(o))&&!a.contentDOM?RX.isSelectable(i)?JQ(e,new RX(t<0?e.state.doc.resolve(n.pos-i.nodeSize):n)):ZZ?JQ(e,new IX(e.state.doc.resolve(t<0?o:o+i.nodeSize))):!1:!1}}else if(r instanceof RX&&r.node.isInline)return JQ(e,new IX(t>0?r.$to:r.$from));else{let n=qQ(e.state,t);return n?JQ(e,n):!1}}function XQ(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function ZQ(e,t){let n=e.pmViewDesc;return n&&n.size==0&&(t<0||e.nextSibling||e.nodeName!=`BR`)}function QQ(e,t){return t<0?Rke(e):zke(e)}function Rke(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,a,o=!1;for(HZ&&n.nodeType==1&&r0){if(n.nodeType!=1)break;{let e=n.childNodes[r-1];if(ZQ(e,-1))i=n,a=--r;else if(e.nodeType==3)n=e,r=n.nodeValue.length;else break}}else if($Q(n))break;else{let t=n.previousSibling;for(;t&&ZQ(t,-1);)i=n.parentNode,a=wZ(t),t=t.previousSibling;if(t)n=t,r=XQ(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}o?e$(e,n,r):i&&e$(e,i,a)}function zke(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i=XQ(n),a,o;for(;;)if(r{e.state==i&&LQ(e)},50)}function t$(e,t){let n=e.state.doc.resolve(t);if(!(WZ||YZ)&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),i=(n.top+n.bottom)/2;if(i>r.top&&i1)return n.leftr.top&&i1)return n.left>r.left?`ltr`:`rtl`}}return getComputedStyle(e.dom).direction==`rtl`?`rtl`:`ltr`}function n$(e,t,n){let r=e.state.selection;if(r instanceof IX&&!r.empty||n.indexOf(`s`)>-1||JZ&&n.indexOf(`m`)>-1)return!1;let{$from:i,$to:a}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?`up`:`down`)){let n=qQ(e.state,t);if(n&&n instanceof RX)return JQ(e,n)}if(!i.parent.inlineContent){let n=t<0?i:a,o=r instanceof zX?NX.near(n,t):NX.findFrom(n,t);return o?JQ(e,o):!1}return!1}function r$(e,t){if(!(e.state.selection instanceof IX))return!0;let{$head:n,$anchor:r,empty:i}=e.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(e.endOfTextblock(t>0?`forward`:`backward`))return!0;let a=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(a&&!a.isText){let r=e.state.tr;return t<0?r.delete(n.pos-a.nodeSize,n.pos):r.delete(n.pos,n.pos+a.nodeSize),e.dispatch(r),!0}return!1}function i$(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function Hke(e){if(!KZ||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&t.nodeType==1&&n==0&&t.firstChild&&t.firstChild.contentEditable==`false`){let n=t.firstChild;i$(e,n,`true`),setTimeout(()=>i$(e,n,`false`),20)}return!1}function Uke(e){let t=``;return e.ctrlKey&&(t+=`c`),e.metaKey&&(t+=`m`),e.altKey&&(t+=`a`),e.shiftKey&&(t+=`s`),t}function Wke(e,t){let n=t.keyCode,r=Uke(t);if(n==8||JZ&&n==72&&r==`c`)return r$(e,-1)||QQ(e,-1);if(n==46&&!t.shiftKey||JZ&&n==68&&r==`c`)return r$(e,1)||QQ(e,1);if(n==13||n==27)return!0;if(n==37||JZ&&n==66&&r==`c`){let t=n==37?t$(e,e.state.selection.from)==`ltr`?-1:1:-1;return YQ(e,t,r)||QQ(e,t)}else if(n==39||JZ&&n==70&&r==`c`){let t=n==39?t$(e,e.state.selection.from)==`ltr`?1:-1:1;return YQ(e,t,r)||QQ(e,t)}else if(n==38||JZ&&n==80&&r==`c`)return n$(e,-1,r)||QQ(e,-1);else if(n==40||JZ&&n==78&&r==`c`)return Hke(e)||n$(e,1,r)||QQ(e,1);else if(r==(JZ?`m`:`c`)&&(n==66||n==73||n==89||n==90))return!0;return!1}function a$(e,t){e.someProp(`transformCopied`,n=>{t=n(t,e)});let n=[],{content:r,openStart:i,openEnd:a}=t;for(;i>1&&a>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,a--;let e=r.firstChild;n.push(e.type.name,e.attrs==e.type.defaultAttrs?null:e.attrs),r=e.content}let o=e.someProp(`clipboardSerializer`)||RY.fromSchema(e.state.schema),s=p$(),c=s.createElement(`div`);c.appendChild(o.serializeFragment(r,{document:s}));let l=c.firstChild,u,d=0;for(;l&&l.nodeType==1&&(u=f$[l.nodeName.toLowerCase()]);){for(let e=u.length-1;e>=0;e--){let t=s.createElement(u[e]);for(;c.firstChild;)t.appendChild(c.firstChild);c.appendChild(t),d++}l=c.firstChild}return l&&l.nodeType==1&&l.setAttribute(`data-pm-slice`,`${i} ${a}${d?` -${d}`:``} ${JSON.stringify(n)}`),{dom:c,text:e.someProp(`clipboardTextSerializer`,n=>n(t,e))||t.content.textBetween(0,t.content.size,` + `,title:F(`printers:control`)?j(`printers.stop`):j(`printers.permission.noControl`),children:[(0,K.jsx)(tu,{className:`w-3 h-3`}),j(`printers.stop`)]})})()]})]})]})})(),(Xt?.length>0||At.vt_tray.length>0)&&r===`expanded`&&(()=>{let t=Xt.filter(e=>e.tray.length>1),n=Xt.filter(e=>e.tray.length===1),r=e.nozzle_count===2||At?.temperatures?.nozzle_2!==void 0,i=`min-w-14`,g=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)(_Ee,{state:At.ams_filament_backup,canToggle:F(`printers:control`),pending:En.isPending,onToggle:e=>En.mutate(e)}),(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=Jt[String(t.id)],_=t.id>=128?t.id-128:t.id,v=n===void 0?_:n,y=v===1,b=v===0;return(0,K.jsxs)(`div`,{style:g(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)(kq,{ams:t,printerId:e.id,label:bq(t.id,t.tray.length),amsLabels:Bt,canEdit:F(`printers:update`),onSaved:Vt,children:(0,K.jsx)(`span`,{className:`block truncate text-[10px] text-white font-medium cursor-default select-none`,children:Bt?.[t.id]||bq(t.id,t.tray.length)})}),r&&(y||b)&&(0,K.jsx)(pq,{side:y?`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)(vq,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>st({amsId:t.id,amsLabel:bq(t.id,t.tray.length),mode:`humidity`}),compact:!0}),t.temp!=null&&(0,K.jsx)(`div`,{className:`mr-1`,children:(0,K.jsx)(yq,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>st({amsId:t.id,amsLabel:bq(t.id,t.tray.length),mode:`temperature`}),compact:!0})}),At.supports_drying&&(t.module_type===`n3f`||t.module_type===`n3s`)&&F(`printers:control`)&&(0,K.jsx)(`button`,{disabled:!!(t.dry_sf_reason?.length&&t.dry_time===0),onClick:e=>{if(t.dry_time>0)Tn.mutate(t.id);else if(Be===t.id)Ve(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;Ge(n),qe(r[i]||r.n3f),Ye(i===`n3s`?r.n3s_hours:r.n3f_hours),Ze(!1),Ue(t.module_type),Ve(t.id),$e(ep({triggerRect:e.currentTarget.getBoundingClientRect(),popoverWidth:uq,estimatedHeight:dq,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-500/20 text-amber-400`: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: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)(ec,{className:`w-3 h-3`})})]})]}),t.dry_time>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-amber-500/10 px-2 py-1 text-[9px]`,children:[(0,K.jsx)(ec,{className:`w-3 h-3 text-amber-400 shrink-0`}),(0,K.jsx)(`span`,{className:`text-amber-400 font-medium`,children:j(`printers.drying.active`)}),(0,K.jsx)(`span`,{className:`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`})}),(0,K.jsx)(`button`,{onClick:()=>Tn.mutate(t.id),disabled:Tn.isPending,className:`ml-auto text-amber-400 hover:text-amber-300 transition-colors disabled:opacity-50`,title:j(`printers.drying.stop`),children:(0,K.jsx)(Pu,{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),g=a?.tray_type&&a.remain>=0,_=!a?.tray_type,v=xq(a),y=t.id*4+r,b=$t===y,x=a?.tray_info_idx?Ft?.[a.tray_info_idx]:null,S=It?.[y],C=(a?.tray_uuid||a?.tag_uid||VK(e.serial_number,t.id,r))?.toUpperCase(),w=C?s?.[C]:void 0,T=zK(w),E=o&&!m?p?.find(n=>n.printer_id===e.id&&n.ams_id===t.id&&n.tray_id===r):void 0,D=E?f?.find(e=>e.id===E.spoolman_spool_id):void 0,O=D&&(D.label_weight??0)>0?Math.round(Math.max(0,(D.label_weight??0)-D.weight_used)/(D.label_weight??1)*100):null,k=u?.(e.id,t.id,r),A=(()=>{let e=k?.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})(),M=A===0&&g&&a.remain>0?null:A,N=T??O??M??(g?a.remain:null),P=T!==null||O!==null?`spoolman`:M===null?g?`ams`:void 0:`inventory`,I=a?.tray_type?{vendor:qK(a)?`Bambu Lab`:`Generic`,profile:S?.preset_name||(D?[D.brand,D.slicer_filament_name?.split(`@`)[0].trim()||D.material].filter(Boolean).join(` `).trim():null)||k?.spool?.slicer_filament_name||x?.name||a.tray_sub_brands||a.tray_type,colorName:Vd(a.tray_color||``),colorHex:a.tray_color||null,kFactor:fq(a.k),fillLevel:N,trayUuid:a.tray_uuid||null,tagUid:a.tag_uid||null,fillSource:P}:null,L=Xn?.amsId===t.id&&Xn?.slotId===r,R=(0,K.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${_?`opacity-50`:``} ${b?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[(0,K.jsx)(lq,{trayColor:a?.tray_color,trayType:a?.tray_type,isEmpty:_,emptyKind:v,slotNumber:r+1}),(0,K.jsx)(`div`,{className:`text-[9px] text-white font-bold truncate`,children:a?.tray_type||j(v===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,K.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:N!==null&&N>=0&&!_&&a&&(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${N}%`,backgroundColor:RK(N)}})})]});return(0,K.jsxs)(`div`,{className:`relative group w-full ${i}`,children:[L&&(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)(Cl,{className:`w-4 h-4 text-bambu-green animate-spin`})}),I?(0,K.jsx)(JG,{data:I,actions:Dr({amsId:t.id,slotId:r,loadTrayId:t.id*4+r,isRefreshing:L}),spoolman:{enabled:o,linkedSpoolId:E?.spoolman_spool_id??(C?s?.[C]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!E&&!k?()=>{let n=(I.trayUuid||I.tagUid||VK(e.serial_number,t.id,r)).toUpperCase();dt({tagUid:I.tagUid||n,trayUuid:I.trayUuid||``,printerId:e.id,amsId:t.id,trayId:r})}:void 0,onUnlinkSpool:w?.id?()=>Cn.mutate(w.id):void 0},inventory:(()=>{if(o){if(m)return;let n=E,i=D;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:()=>pt({printerId:e.id,amsId:t.id,trayId:r,trayInfo:{type:a?.tray_type||I.profile,material:a?.tray_type??void 0,profile:I.profile,color:I.colorHex||``,location:`${bq(t.id,t.tray.length)} Slot ${r+1}`}}),onUnassignSpool:i&&!qK(a)?()=>h?.(i.id):void 0,isAssigned:!!n||qK(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:()=>pt({printerId:e.id,amsId:t.id,trayId:r,trayInfo:{type:a?.tray_type||I.profile,material:a?.tray_type??void 0,profile:I.profile,color:I.colorHex||``,location:`${bq(t.id,t.tray.length)} Slot ${r+1}`}}),onUnassignSpool:n&&!qK(a)?()=>d?.(e.id,t.id,r):void 0,isAssigned:!!n||qK(a)}})(),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({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:S?.preset_id})},children:R}):(0,K.jsx)(YG,{kind:v??void 0,actions:Dr({amsId:t.id,slotId:r,loadTrayId:t.id*4+r,isRefreshing:L}),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({amsId:t.id,trayId:r,trayCount:t.tray.length,extruderId:n})},onAssignSpool:()=>pt({printerId:e.id,amsId:t.id,trayId:r,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`${bq(t.id,t.tray.length)} Slot ${r+1}`}}),children:R})]},r)})})]},t.id)}),n.map(t=>{let n=Jt[String(t.id)],i=t.id>=128?t.id-128:t.id,g=n===void 0?i:n,_=g===1,v=g===0,y=t.tray[0],b=y?.tray_type&&y.remain>=0,S=!y?.tray_type,C=xq(y),w=LK(t.id,y?.id??0,!1),T=$t===w,E=y?.tray_info_idx?Ft?.[y.tray_info_idx]:null,D=It?.[w],O=y?.id??0,k=(y?.tray_uuid||y?.tag_uid||VK(e.serial_number,t.id,O))?.toUpperCase(),A=k?s?.[k]:void 0,M=zK(A),N=u?.(e.id,t.id,O),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&&b&&y.remain>0?null:P,L=o&&!m?p?.find(n=>n.printer_id===e.id&&n.ams_id===t.id&&n.tray_id===O):void 0,R=L?f?.find(e=>e.id===L.spoolman_spool_id):void 0,z=R&&(R.label_weight??0)>0?Math.round(Math.max(0,(R.label_weight??0)-R.weight_used)/(R.label_weight??1)*100):null,B=M??z??I??(b?y.remain:null),V=M!==null||z!==null?`spoolman`:I===null?b?`ams`:void 0:`inventory`,ee=y?.tray_type?{vendor:qK(y)?`Bambu Lab`:`Generic`,profile:D?.preset_name||(R?[R.brand,R.slicer_filament_name?.split(`@`)[0].trim()||R.material].filter(Boolean).join(` `).trim():null)||N?.spool?.slicer_filament_name||E?.name||y.tray_sub_brands||y.tray_type,colorName:Vd(y.tray_color||``),colorHex:y.tray_color||null,kFactor:fq(y.k),fillLevel:B,trayUuid:y.tray_uuid||null,tagUid:y.tag_uid||null,fillSource:V}:null,H=Xn?.amsId===t.id&&Xn?.slotId===O,te=(0,K.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${S?`opacity-50`:``} ${T?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[(0,K.jsx)(lq,{trayColor:y?.tray_color,trayType:y?.tray_type,isEmpty:S,emptyKind:C,slotNumber:1}),(0,K.jsx)(`div`,{className:`text-[9px] text-white font-bold truncate`,children:y?.tray_type||j(C===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,K.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:B!==null&&B>=0&&!S&&(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${B}%`,backgroundColor:RK(B)}})})]});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)(kq,{ams:t,printerId:e.id,label:bq(t.id,t.tray.length),amsLabels:Bt,canEdit:F(`printers:update`),onSaved:Vt,children:(0,K.jsx)(`span`,{className:`block truncate text-[10px] text-white font-medium cursor-default select-none`,children:Bt?.[t.id]||bq(t.id,t.tray.length)})}),r&&(_||v)&&(0,K.jsx)(pq,{side:_?`L`:`R`})]}),At.supports_drying&&(t.module_type===`n3f`||t.module_type===`n3s`)&&F(`printers:control`)&&(0,K.jsx)(`div`,{className:`relative ml-auto`,children:(0,K.jsx)(`button`,{onClick:e=>{if(t.dry_time>0)Tn.mutate(t.id);else if(Be===t.id)Ve(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;Ge(n),qe(r[i]||r.n3f),Ye(i===`n3s`?r.n3s_hours:r.n3f_hours),Ze(!1),Ue(t.module_type),Ve(t.id),$e(ep({triggerRect:e.currentTarget.getBoundingClientRect(),popoverWidth:uq,estimatedHeight:dq,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-500/20 text-amber-400`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark/80`}`,title:t.dry_time>0?j(`printers.drying.stop`):j(`printers.drying.start`),children:(0,K.jsx)(ec,{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-500/10 px-2 py-1 text-[9px]`,children:[(0,K.jsx)(ec,{className:`w-3 h-3 text-amber-400 shrink-0`}),(0,K.jsx)(`span`,{className:`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`}),(0,K.jsx)(`button`,{onClick:()=>Tn.mutate(t.id),disabled:Tn.isPending,className:`ml-auto text-amber-400 hover:text-amber-300 transition-colors disabled:opacity-50 shrink-0`,title:j(`printers.drying.stop`),children:(0,K.jsx)(Pu,{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:[H&&(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)(Cl,{className:`w-4 h-4 text-bambu-green animate-spin`})}),ee?(0,K.jsx)(JG,{data:ee,actions:Dr({amsId:t.id,slotId:O,loadTrayId:t.id*4+O,isRefreshing:H}),spoolman:{enabled:o,linkedSpoolId:L?.spoolman_spool_id??(k?s?.[k]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!L&&!N?()=>{let n=(ee.trayUuid||ee.tagUid||VK(e.serial_number,t.id,O)).toUpperCase();dt({tagUid:ee.tagUid||n,trayUuid:ee.trayUuid||``,printerId:e.id,amsId:t.id,trayId:O})}:void 0,onUnlinkSpool:A?.id?()=>Cn.mutate(A.id):void 0},inventory:(()=>{if(o){if(m)return;let n=L,r=R;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:()=>pt({printerId:e.id,amsId:t.id,trayId:O,trayInfo:{type:y?.tray_type||ee.profile,material:y?.tray_type??void 0,profile:ee.profile,color:ee.colorHex||``,location:bq(t.id,t.tray.length)}}),onUnassignSpool:r&&!qK(y)?()=>h?.(r.id):void 0,isAssigned:!!n||qK(y)}}let n=u?.(e.id,t.id,O);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:()=>pt({printerId:e.id,amsId:t.id,trayId:O,trayInfo:{type:y?.tray_type||ee.profile,material:y?.tray_type??void 0,profile:ee.profile,color:ee.colorHex||``,location:bq(t.id,t.tray.length)}}),onUnassignSpool:n&&!qK(y)?()=>d?.(e.id,t.id,O):void 0,isAssigned:!!n||qK(y)}})(),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({amsId:t.id,trayId:O,trayCount:t.tray.length,trayType:y?.tray_type||void 0,trayColor:y?.tray_color||void 0,traySubBrands:y?.tray_sub_brands||void 0,trayInfoIdx:y?.tray_info_idx||void 0,extruderId:n,caliIdx:y?.cali_idx,savedPresetId:D?.preset_id})},children:te}):(0,K.jsx)(YG,{kind:C??void 0,actions:Dr({amsId:t.id,slotId:O,loadTrayId:t.id*4+O,isRefreshing:H}),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({amsId:t.id,trayId:O,trayCount:t.tray.length,extruderId:n})},onAssignSpool:()=>pt({printerId:e.id,amsId:t.id,trayId:O,trayInfo:{type:``,material:void 0,profile:``,color:``,location:bq(t.id,t.tray.length)}}),children:te})]}),(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)(yq,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>st({amsId:t.id,amsLabel:bq(t.id,t.tray.length),mode:`temperature`}),compact:!0}),t.humidity!=null&&(0,K.jsx)(vq,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>st({amsId:t.id,amsLabel:bq(t.id,t.tray.length),mode:`humidity`}),compact:!0})]})]})]},t.id)}),At.vt_tray.length>0&&(0,K.jsxs)(`div`,{style:g(At.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 ${At.vt_tray.length>1?`grid-cols-[repeat(2,minmax(3.5rem,1fr))]`:`grid-cols-[minmax(3.5rem,1fr)]`} gap-1`,children:[...At.vt_tray].sort((e,t)=>(e.id??254)-(t.id??254)).map(t=>{let n=t.id??254,a=r&&$t===254?n===254&&At.active_extruder===1||n===255&&At.active_extruder===0:$t===n,g=n-254,_=r?j(n===254?`printers.extL`:`printers.extR`):``,v=t.tray_info_idx?Ft?.[t.tray_info_idx]:null,y=It?.[1020+g],b=(t.tray_uuid||t.tag_uid||VK(e.serial_number,255,g))?.toUpperCase(),x=b?s?.[b]:void 0,S=zK(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:qK(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:Vd(t.tray_color||``),colorHex:t.tray_color||null,kFactor:fq(t.k),fillLevel:A,trayUuid:t.tray_uuid||null,tagUid:t.tag_uid||null,fillSource:M},P=!t.tray_type,I=xq(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)(lq,{trayColor:t.tray_color,trayType:t.tray_type,isEmpty:P,emptyKind:I,slotNumber: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:RK(A)}})}),_&&(0,K.jsx)(`div`,{className:`text-[7px] text-white/40 mt-0.5 truncate`,children:_})]});return(0,K.jsx)(`div`,{className:`relative group w-full ${i}`,children:P?(0,K.jsx)(YG,{kind:I??void 0,actions:Dr({amsId:255,slotId:g,loadTrayId:n,includeRfid:!1}),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({amsId:255,trayId:g,trayCount:1,extruderId:r?+(n===254):void 0})},onAssignSpool:()=>pt({printerId:e.id,amsId:255,trayId:g,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`External Slot ${g+1}`}}),children:L}):(0,K.jsx)(JG,{data:N,actions:Dr({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||VK(e.serial_number,255,g)).toUpperCase();dt({tagUid:N.tagUid||t,trayUuid:N.trayUuid||``,printerId:e.id,amsId:255,trayId:g})}:void 0,onUnlinkSpool:x?.id?()=>Cn.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:()=>pt({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&&!qK(t)?()=>h?.(r.id):void 0,isAssigned:!!n||qK(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:()=>pt({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&&!qK(t)?()=>d?.(e.id,255,g):void 0,isAssigned:!!n||qK(t)}})(),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({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:[en&&(0,K.jsxs)(`div`,{className:`pt-4`,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)(Iu,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm text-white truncate`,children:en.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:nn?.energy?.power!==null&&nn?.energy?.power!==void 0?`${Math.round(nn.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:()=>On.mutate(!en.auto_off),disabled:On.isPending||en.auto_off_executed||!F(`smart_plugs:control`),title:F(`smart_plugs:control`)?en.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`)?en.auto_off||en.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)(_s,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{nn?.state===`ON`?oe(!0):ae(!0)},disabled:Dn.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`)?nn?.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`)?nn?.state===`ON`?`Turn off`:`Turn on`:j(`printers.permission.noSmartPlugControl`),children:(0,K.jsx)(Iu,{className:`w-4 h-4`})})]})]}),tn&&tn.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,K.jsx)(Tc,{className:`w-3.5 h-3.5 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:tn.map(e=>{let t=e.ha_entity_id?.startsWith(`script.`);return(0,K.jsxs)(`button`,{onClick:()=>{t?kn.mutate({id:e.id,action:`on`}):ce(e)},disabled:kn.isPending,title:`${t?`Run`:`Toggle`} ${e.ha_entity_id}`,className:`px-2 py-0.5 text-xs bg-blue-500/20 text-blue-400 hover:bg-blue-500/30 rounded transition-colors flex items-center gap-1`,children:[(0,K.jsx)(hl,{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:[Or,(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:!At?.connected||!F(`camera:view`),title:F(`camera:view`)?j(_===`embedded`?`printers.openCameraOverlay`:`printers.openCameraWindow`):j(`printers.permission.noCamera`),className:Er,children:(0,K.jsx)(Tu,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>ne(!0),disabled:!Kt||!F(`printers:files`),title:F(`printers:files`)?j(`printers.browseFiles`):j(`printers.permission.noFiles`),className:Er,children:(0,K.jsx)(yc,{className:`w-4 h-4`})}),Kt&&At?.state!==`RUNNING`&&At?.state!==`PAUSE`&&(0,K.jsxs)($,{size:`sm`,onClick:()=>Me(!0),disabled:!F(`printers:control`),title:F(`printers:control`)?j(`common.print`):j(`printers.permission.noControl`),className:`!h-8 !min-h-8 !px-2 !py-0 !bg-bambu-green hover:!bg-bambu-green/80 !text-white`,children:[(0,K.jsx)(bl,{className:`w-4 h-4`}),j(`common.print`)]})]})]})]})]})]}),te&&(0,K.jsx)(cce,{printerId:e.id,printerName:e.name,onClose:()=>ne(!1)}),je&&(0,K.jsx)(kK,{folderId:null,onClose:()=>Me(!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=Oq(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});ze({id:t.id,filename:t.filename})}}),Re&&(0,K.jsx)(sq,{mode:`reprint`,libraryFileId:Re.id,archiveName:Re.filename,initialSelectedPrinterIds:[e.id],onClose:()=>ze(null),onSuccess:()=>ze(null),cleanupLibraryAfterDispatch:!0}),re&&(0,K.jsx)(hce,{printerId:e.id,printerName:e.name,onClose:()=>U(!1)}),Fe&&(0,K.jsx)(Df,{printerId:e.id,printerName:e.name,onClose:()=>Ie(!1)}),Ne&&(0,K.jsx)(oEe,{printer:e,status:At,totalPrintHours:n?.total_print_hours,onClose:Le}),vt&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>dr(),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:[vt.needs_calibration?(0,K.jsx)(jl,{className:`w-5 h-5 text-blue-500`}):vt.is_empty?(0,K.jsx)(ls,{className:`w-5 h-5 text-green-500`}):(0,K.jsx)(ms,{className:`w-5 h-5 text-yellow-500`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:`Build Plate Check`}),vt.reference_count!==void 0&&vt.max_references&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[vt.reference_count,`/`,vt.max_references,` refs`]})]}),(0,K.jsx)(`button`,{onClick:()=>dr(),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[vt.needs_calibration?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`p-3 rounded-lg bg-blue-500/20 border border-blue-500/50`,children:[(0,K.jsx)(`p`,{className:`font-medium 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 ${vt.is_empty?`bg-green-500/20 border border-green-500/50`:`bg-yellow-500/20 border border-yellow-500/50`}`,children:[(0,K.jsx)(`p`,{className:`font-medium ${vt.is_empty?`text-green-400`:`text-yellow-400`}`,children:vt.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(vt.confidence*100),`% | `,j(`printers.plateDetection.difference`),`: `,vt.difference_percent.toFixed(1),`%`]})]}),vt.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:vt.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:vt.message})]}),ir&&ir.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:ir.references.length,max:ir.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:ir.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:()=>mr(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)(Pu,{className:`w-3 h-3 text-white`})}),or?.index===t.index?(0,K.jsx)(`input`,{type:`text`,value:or.label,onChange:e=>sr({...or,label:e.target.value}),onBlur:()=>pr(t.index,or.label),onKeyDown:e=>{e.key===`Enter`&&pr(t.index,or.label),e.key===`Escape`&&sr(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:()=>sr({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?mf(t.timestamp)?.toLocaleDateString()??``:``})]},t.index))})]}),!vt.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`})]}),wt?(0,K.jsxs)(`div`,{className:`flex gap-1`,children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>Tt(null),disabled:Et,children:j(`common.cancel`)}),(0,K.jsx)($,{size:`sm`,onClick:hr,disabled:Et,children:Et?(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}):j(`common.save`)})]}):(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>Tt(vt.roi||{x:.15,y:.35,w:.7,h:.55}),children:[(0,K.jsx)(pl,{className:`w-3 h-3 mr-1`}),j(`common.edit`)]})]}),wt?(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:wt.x,onChange:e=>Tt({...wt,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(wt.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:wt.y,onChange:e=>Tt({...wt,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(wt.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:wt.w,onChange:e=>Tt({...wt,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(wt.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:wt.h,onChange:e=>Tt({...wt,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(wt.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((vt.roi?.x||.15)*100),`%, Y=`,Math.round((vt.roi?.y||.35)*100),`%, W=`,Math.round((vt.roi?.w||.7)*100),`%, H=`,Math.round((vt.roi?.h||.55)*100),`%`]})]})]}),(0,K.jsx)(`div`,{className:`flex justify-end gap-2 p-4`,children:vt.needs_calibration?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)($,{variant:`ghost`,onClick:()=>dr(),children:j(`common.cancel`)}),(0,K.jsx)($,{onClick:()=>fr(),disabled:St,children:St?(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:()=>fr(),disabled:St,children:St?`Adding...`:`Add Reference (${ir?.references.length||0}/${ir?.max_references||5})`}),(0,K.jsx)($,{onClick:()=>dr(),children:`Close`})]})})]})}),ie&&en&&(0,K.jsx)(Ed,{title:j(`printers.confirm.powerOnTitle`),message:j(`printers.confirm.powerOnMessage`,{name:e.name}),confirmText:j(`printers.confirm.powerOnButton`),variant:`default`,onConfirm:()=>{Dn.mutate(`on`),ae(!1)},onCancel:()=>ae(!1)}),W&&en&&(0,K.jsx)(Ed,{title:j(`printers.confirm.powerOffTitle`),message:At?.state===`RUNNING`?j(`printers.confirm.powerOffWarning`,{name:e.name}):j(`printers.confirm.powerOffMessage`,{name:e.name}),confirmText:j(`printers.confirm.powerOffButton`),variant:`danger`,onConfirm:()=>{Dn.mutate(`off`),oe(!1)},onCancel:()=>oe(!1)}),se&&(0,K.jsx)(Ed,{title:j(`printers.confirm.haToggleTitle`,{name:se.name}),message:At?.state===`RUNNING`?j(`printers.confirm.haToggleWarning`,{name:e.name,entity:se.ha_entity_id||se.name}):j(`printers.confirm.haToggleMessage`,{entity:se.ha_entity_id||se.name}),confirmText:j(`printers.confirm.haToggleButton`),variant:At?.state===`RUNNING`?`danger`:`default`,onConfirm:()=>{kn.mutate({id:se.id,action:`toggle`}),ce(null)},onCancel:()=>ce(null)}),de&&(0,K.jsx)(Ed,{title:j(`printers.confirm.stopTitle`),message:j(`printers.confirm.stopMessage`,{name:e.name}),confirmText:j(`printers.confirm.stopButton`),variant:`danger`,onConfirm:()=>{An.mutate(),fe(!1)},onCancel:()=>fe(!1)}),pe&&(0,K.jsx)(Ed,{title:j(`printers.confirm.pauseTitle`),message:j(`printers.confirm.pauseMessage`,{name:e.name}),confirmText:j(`printers.confirm.pauseButton`),variant:`default`,onConfirm:()=>{jn.mutate(),me(!1)},onCancel:()=>me(!1)}),De&&(0,K.jsx)(Ed,{title:j(`printers.confirm.resumeTitle`),message:j(`printers.confirm.resumeMessage`,{name:e.name}),confirmText:j(`printers.confirm.resumeButton`),variant:`default`,onConfirm:()=>{Mn.mutate(),Oe(!1)},onCancel:()=>Oe(!1)}),Te&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl w-full max-w-sm p-5`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,K.jsx)(vu,{className:`w-5 h-5 text-yellow-400 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-white mb-1`,children:j(`printers.bedJog.notHomedTitle`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray leading-relaxed`,children:j(`printers.bedJog.notHomedMessage`)})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>{Gn.mutate(`all`),Ee(null)},className:`w-full px-3 py-2 rounded-lg text-xs font-medium bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 transition-colors`,children:j(`printers.bedJog.homeZ`)}),(0,K.jsx)(`button`,{onClick:()=>{let t=Te.distance;try{sessionStorage.setItem(`bambuddy.bedJog.warned.${e.id}`,`1`)}catch{}Hn.mutate({distance:t,force:!0}),Ee(null)},className:`w-full px-3 py-2 rounded-lg text-xs font-medium bg-yellow-500/20 text-yellow-400 hover:bg-yellow-500/30 transition-colors`,children:j(`printers.bedJog.moveAnyway`)}),(0,K.jsx)(`button`,{onClick:()=>Ee(null),className:`w-full px-3 py-2 rounded-lg text-xs font-medium bg-bambu-dark text-bambu-gray hover:bg-bambu-dark-tertiary transition-colors`,children:j(`common.cancel`)})]})]})}),(0,K.jsx)(AT,{printerId:e.id,isOpen:ke,onClose:()=>Ae(!1)}),le&&(0,K.jsx)(pp,{printerName:e.name,errors:At?.hms_errors||[],onClose:()=>ue(!1),printerId:e.id,hasPermission:F}),ot&&(0,K.jsx)(bTe,{isOpen:!!ot,onClose:()=>st(null),printerId:e.id,printerName:e.name,amsId:ot.amsId,amsLabel:ot.amsLabel,initialMode:ot.mode,thresholds:a}),ct&&(0,K.jsx)(STe,{isOpen:!!ct,onClose:()=>lt(null),printerId:e.id,printerName:e.name,initialKind:ct.initialKind,availableKinds:ct.availableKinds}),ut&&(0,K.jsx)(XG,{isOpen:!!ut,onClose:()=>dt(null),tagUid:ut.tagUid,trayUuid:ut.trayUuid,printerId:ut.printerId,amsId:ut.amsId,trayId:ut.trayId}),ft&&(0,K.jsx)(QG,{isOpen:!!ft,onClose:()=>pt(null),printerId:ft.printerId,amsId:ft.amsId,trayId:ft.trayId,trayInfo:ft.trayInfo,spoolmanEnabled:!!o}),mt&&(0,K.jsx)(DK,{isOpen:!!mt,onClose:()=>ht(null),printerId:e.id,slotInfo:mt,printerModel:Oq(e.model)||void 0,onSuccess:()=>{M.invalidateQueries({queryKey:[`slotPresets`,e.id]}),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),ee&&(0,K.jsx)(EEe,{printer:e,onClose:()=>H(!1)}),gt&&jt&&(0,K.jsx)(TEe,{printer:e,firmwareInfo:jt,onClose:()=>_t(!1)}),Be!==null&&Qe&&(()=>{let e=He===`n3s`?85:65,t=e+10;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-[100]`,onClick:()=>Ve(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:Qe.top,left:Qe.left,maxHeight:`calc(100dvh - ${Qe.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)(ec,{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)(Sq,{value:We,options:Object.keys(x).map(e=>({value:e,label:e})),onChange:e=>{Ge(e);let t=x[e];t&&(qe(t[He===`n3s`?`n3s`:`n3f`]),Ye(He===`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:Ke,onChange:t=>qe(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:Ke,onChange:t=>qe(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:Je,onChange:e=>Ye(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:Je,onChange:e=>Ye(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`})]})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>Ze(e=>!e),"aria-pressed":Xe,className:`h-8 w-full rounded-lg border px-2 text-sm font-medium transition-colors ${Xe?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,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:()=>{Be!==null&&wn.mutate({amsId:Be,temp:Ke,duration:Je,filament:We,rotateTray:Xe})},disabled:wn.isPending,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:wn.isPending?j(`printers.drying.startingDrying`):j(`printers.drying.start`)})})]})]})})()]})}function wEe({onClose:e,onAdd:t,existingSerials:n}){let{t:r}=G(),[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)(()=>{Xu.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 Xu.startSubnetScan(e);let t=setInterval(async()=>{try{let e=await Xu.getScanStatus();E({scanned:e.scanned,total:e.total}),l(await Xu.getDiscoveredPrinters()),e.running||(clearInterval(t),s(!1),p(!0))}catch(e){console.error(`Failed to get scan status:`,e)}},500)}else{await Xu.startDiscovery(10);let e=setInterval(async()=>{try{l(await Xu.getDiscoveredPrinters())}catch(e){console.error(`Failed to get discovered printers:`,e)}},1e3);setTimeout(async()=>{clearInterval(e);try{await Xu.stopDiscovery()}catch{}s(!1),p(!0);try{l(await Xu.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:Oq(e.model)}),l([])};return(0,y.useEffect)(()=>()=>{Xu.stopDiscovery().catch(()=>{}),Xu.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)(pd,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(hd,{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)(Nl,{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-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:[Oq(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)(es,{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)(ru,{className:`w-4 h-4`}),r(`diagnostic.runButton`)]}),j?(0,K.jsxs)(`div`,{className:`rounded-lg bg-amber-500/10 border border-amber-500/30 p-3 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-400`}),(0,K.jsx)(`p`,{className:`text-sm text-amber-300`,children:r(`printers.addPreflight.warning`)})]}),(0,K.jsx)(Tf,{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)(Df,{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 TEe({printer:e,firmwareInfo:t,onClose:n}){let{t:r}=G(),i=Qa(),{showToast:a}=xd(),{hasPermission:o}=sd(),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:()=>ed.prepareUpload(e.id,m??void 0),staleTime:3e4,enabled:!!m&&s&&!u}),v=J({mutationFn:()=>ed.startUpload(e.id,m??void 0),onSuccess:()=>{d(!0);let t=setInterval(async()=>{try{let n=await ed.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)(pd,{className:`w-full max-w-md mx-4`,children:(0,K.jsxs)(hd,{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-500/20`:`bg-status-ok/20`}`,children:t.update_available?(0,K.jsx)(Is,{className:`w-5 h-5 text-orange-400`}):(0,K.jsx)(ls,{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-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-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?Qf(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-400`:`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-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-500/15 text-blue-400 border 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)(Bo,{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-400 text-sm`,children:[(0,K.jsx)(ss,{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-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)(Is,{className:`w-4 h-4 mr-2`}),r(`printers.firmwareModal.uploadFirmware`)]})})]})]})})})}function EEe({printer:e,onClose:t}){let{t:n}=G(),r=Qa(),{showToast:i}=xd(),[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}),[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};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)(pd,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(hd,{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`)})]}),l?(0,K.jsxs)(`div`,{className:`rounded-lg bg-amber-500/10 border border-amber-500/30 p-3 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-400`}),(0,K.jsx)(`p`,{className:`text-sm text-amber-300`,children:n(`printers.addPreflight.warning`)})]}),(0,K.jsx)(Tf,{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 DEe(e){let{data:t}=q({queryKey:[`printerStatus`,e],queryFn:()=>Q.getPrinterStatus(e),refetchInterval:3e4});return!t?.connected}function OEe({printer:e,plug:t,onPowerOn:n,isPowering:r}){let i=DEe(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-gray-900 dark: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-500/20 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)(yl,{className:`w-3 h-3`}),r?`...`:`On`]})]}):null}function kEe(){let{t:e}=G(),{resolvedMode:t,darkAccent:n,lightAccent:r}=ud(),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=_===1?`compact`:`expanded`,[x,S]=(0,y.useState)(null),C=(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`})})})},[]),w=(0,y.useCallback)(e=>{S(e),v(2),localStorage.setItem(`printerCardSize`,`2`),C(e)},[C]),T=(0,y.useCallback)(()=>{let e=x;S(null),v(1),localStorage.setItem(`printerCardSize`,`1`),e!=null&&C(e)},[x,C]),[E,D]=(0,y.useState)(``),[O,k]=(0,y.useState)(`all`),[A,j]=(0,y.useState)(`all`),[M,N]=(0,y.useState)(0),[P,F]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`printerCollapsedSections`);return e?JSON.parse(e):{}}catch{return{}}}),I=Qa(),{showToast:L}=xd(),{hasPermission:R}=sd(),[z,B]=(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(z.values());e.length>0?localStorage.setItem(`openEmbeddedCameras`,JSON.stringify(e)):localStorage.removeItem(`openEmbeddedCameras`)},[z]);let{data:V,isLoading:ee}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:H}=q({queryKey:[`ui-preferences`],queryFn:Q.getUiPreferences}),te=(0,y.useMemo)(()=>op(H?.nozzle_temp_presets,tp,0,320),[H?.nozzle_temp_presets]),ne=(0,y.useMemo)(()=>op(H?.bed_temp_presets,np,0,140),[H?.bed_temp_presets]),re=(0,y.useMemo)(()=>op(H?.chamber_temp_presets,rp,0,60),[H?.chamber_temp_presets]),U=(0,y.useMemo)(()=>op(H?.fan_speed_presets,ip,0,100),[H?.fan_speed_presets]),ie=(0,y.useMemo)(()=>{if(H?.drying_presets)try{let e=JSON.parse(H.drying_presets);if(typeof e==`object`&&e&&Object.keys(e).length>0)return{...Aq,...e}}catch{}return Aq},[H?.drying_presets]);(0,y.useEffect)(()=>{H?.camera_view_mode===`window`&&z.size>0&&B(new Map)},[H?.camera_view_mode,z.size]);let{data:ae}=q({queryKey:[`smart-plugs`],queryFn:Q.getSmartPlugs}),{data:W}=q({queryKey:[`maintenanceOverview`],queryFn:Q.getMaintenanceOverview,staleTime:60*1e3}),{data:oe}=q({queryKey:[`spoolman-status`],queryFn:Q.getSpoolmanStatus,staleTime:60*1e3}),se=oe?.enabled&&oe?.connected,{data:ce}=q({queryKey:[`spoolman-settings`],queryFn:Q.getSpoolmanSettings,enabled:!!se,staleTime:60*1e3}),le=ce?.spoolman_sync_mode,{data:ue}=q({queryKey:[`unlinked-spools`],queryFn:Q.getUnlinkedSpools,enabled:!!se,staleTime:30*1e3}),de=ue&&ue.length>0,{data:fe}=q({queryKey:[`linked-spools`],queryFn:Q.getLinkedSpools,enabled:!!se,staleTime:30*1e3}),pe=fe?.linked,{data:me}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),enabled:R(`inventory:view_assignments`),staleTime:30*1e3}),he=J({mutationFn:({printerId:e,amsId:t,trayId:n})=>Q.unassignSpool(e,t,n),onSuccess:()=>{I.invalidateQueries({queryKey:[`spool-assignments`]})}}),{data:ge,isLoading:_e}=q({queryKey:[`spoolman-inventory-spools`],queryFn:()=>Q.getSpoolmanInventorySpools(!1),enabled:!!se,staleTime:30*1e3}),{data:ve,isLoading:ye}=q({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:!!se,staleTime:30*1e3}),be=J({mutationFn:e=>Q.unassignSpoolmanSlot(e),onSuccess:()=>{I.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),I.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})}}),xe=(e,t,n)=>me?.find(r=>r.printer_id===e&&r.ams_id===Number(t)&&r.tray_id===Number(n)),Se=W?.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),{})||{},Ce=ae?.reduce((e,t)=>(t.printer_id&&(e[t.printer_id]=t),e),{})||{},we=J({mutationFn:Q.createPrinter,onSuccess:()=>{I.invalidateQueries({queryKey:[`printers`]}),I.invalidateQueries({queryKey:[`maintenanceOverview`]}),o(!1)},onError:t=>{if(t instanceof zu&&t.code===`printer_connection_failed`){L(e(`printers.toast.connectionFailedNotAdded`),`error`);return}L(t.message||e(`printers.toast.failedToAdd`),`error`)}}),Te=J({mutationFn:e=>Q.controlSmartPlug(e,`on`),onSuccess:()=>{I.invalidateQueries({queryKey:[`smart-plugs`]}),f(null)},onError:()=>{f(null)}}),[Ee,De]=(0,y.useState)(new Set),[Oe,ke]=(0,y.useState)(!1),[Ae,je]=(0,y.useState)(null),[Me,Ne]=(0,y.useState)(!1),Pe=Oe||Ee.size>0,Fe=(0,y.useCallback)(e=>{De(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Ie=(0,y.useCallback)(()=>{De(new Set),ke(!1)},[]);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Pe&&Ie()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Pe,Ie]);let Le=(0,y.useCallback)(async t=>{Ne(!0);let n=Array.from(Ee).filter(e=>{let n=I.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&&dp(n.hms_errors).length>0;default:return!1}});if(n.length===0){L(e(`printers.bulk.noneApplicable`),`error`),Ne(!1),je(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?L(e(`printers.bulk.success`,{action:e(`printers.bulk.actions.${t}`),count:a})):L(e(`printers.bulk.partial`,{succeeded:a,failed:o}),`error`),n.forEach(e=>{I.invalidateQueries({queryKey:[`printerStatus`,e]})}),Ne(!1),je(null)},[Ee,I,L,e]),Re=(0,y.useCallback)(e=>{e===`stop`||e===`pause`||e===`clearPlate`?je(e):Le(e)},[Le]),ze=()=>{let e=!s;c(e),localStorage.setItem(`hideDisconnectedPrinters`,String(e))},Be=e=>{m(e),localStorage.setItem(`printerSortBy`,e)},Ve=()=>{let e=!h;g(e),localStorage.setItem(`printerSortAsc`,String(e))},He=()=>{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`}},Ue=[`S`,`M`,`L`,`XL`];(0,y.useEffect)(()=>I.getQueryCache().subscribe(e=>{e.type===`updated`&&Array.isArray(e.query.queryKey)&&e.query.queryKey[0]===`printerStatus`&&N(e=>e+1)}),[I]);let We=(0,y.useMemo)(()=>{if(!V)return[];let e=V;if(E.trim()){let t=E.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 A!==`all`&&(e=e.filter(e=>(e.location||``)===A)),O!==`all`&&(e=e.filter(e=>{let t=I.getQueryData([`printerStatus`,e.id]);if(!t?.connected)return O===`offline`;let n=t.hms_errors?dp(t.hms_errors):[];switch(O){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},[V,E,O,A,I,M]),Ge=(0,y.useMemo)(()=>V?[...new Set(V.map(e=>e.location||``).filter(Boolean))].sort():[],[V]),Ke=(0,y.useMemo)(()=>{let e=[...We];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=I.getQueryData([`printerStatus`,e.id]),r=I.getQueryData([`printerStatus`,t.id]),i=e=>e?.connected?(e.hms_errors?dp(e.hms_errors):[]).length>0?0:e.state===`RUNNING`?1:2:3;return i(n)-i(r)});break}return h||e.reverse(),e},[We,p,h,I]),qe=(0,y.useCallback)(()=>{De(new Set(Ke.map(e=>e.id))),ke(!0)},[Ke]),Je=(0,y.useCallback)(e=>{De(t=>{let n=new Set(t);return Ke.forEach(t=>{Dq(I.getQueryData([`printerStatus`,t.id]))===e&&n.add(t.id)}),n}),ke(!0)},[Ke,I]),Ye=(0,y.useCallback)(e=>{De(t=>{let n=new Set(t);return Ke.filter(t=>(t.location||``)===e).forEach(e=>n.add(e.id)),n}),ke(!0)},[Ke]),Xe=(0,y.useCallback)(e=>{De(t=>{let n=new Set(t);return Ke.filter(t=>(t.model||`Unknown`)===e).forEach(e=>n.add(e.id)),n}),ke(!0)},[Ke]),Ze=(0,y.useCallback)(e=>{F(t=>{let n={...t,[e]:!t[e]};try{localStorage.setItem(`printerCollapsedSections`,JSON.stringify(n))}catch{}return n})},[]),Qe=(0,y.useMemo)(()=>{if(p===`name`)return null;let e={};return p===`location`?Ke.forEach(t=>{let n=t.location||`Ungrouped`;e[n]||(e[n]=[]),e[n].push(t)}):p===`model`?Ke.forEach(t=>{let n=t.model||`Unknown`;e[n]||(e[n]=[]),e[n].push(t)}):p===`status`&&Ke.forEach(t=>{let n=Dq(I.getQueryData([`printerStatus`,t.id]));e[n]||(e[n]=[]),e[n].push(t)}),e},[p,Ke,I,M]),$e=(0,y.useRef)(null),et=(0,y.useRef)(null),tt=(0,y.useRef)(0),[nt,rt]=(0,y.useState)(!1),it=(0,y.useCallback)(()=>{let e=$e.current;if(!e)return;let t=et.current?.offsetWidth;t&&(tt.current=t);let n=tt.current>0&&e.clientWidthe===n?e:n)},[]),at=Object.keys(Ce).length;(0,y.useLayoutEffect)(()=>{it();let e=$e.current;if(!e)return;if(typeof ResizeObserver>`u`)return window.addEventListener(`resize`,it),()=>window.removeEventListener(`resize`,it);let t=new ResizeObserver(()=>it());return t.observe(e),window.addEventListener(`resize`,it),()=>{t.disconnect(),window.removeEventListener(`resize`,it)}},[it,V?.length,Ge.length,s,at]);let ot=(t=!1)=>(0,K.jsxs)(K.Fragment,{children:[V&&V.length>0&&(0,K.jsx)(Sq,{value:O,onChange:k,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`)}]}),V&&V.length>0&&Ge.length>0&&(0,K.jsx)(Sq,{value:A,onChange:j,fullWidth:t,options:[{value:`all`,label:e(`printers.filter.allLocations`)},...Ge.map(e=>({value:e,label:e}))]}),(0,K.jsx)(`button`,{type:`button`,onClick:ze,"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`)})]}),st=(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)(Sq,{value:p,onChange:Be,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`)}]}),(0,K.jsx)(`button`,{onClick:Ve,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)(Mo,{className:`w-4 h-4 text-white`}):(0,K.jsx)(Eo,{className:`w-4 h-4 text-white`})})]}),(0,K.jsx)(`div`,{className:`flex h-8 items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary ${t?`w-full`:``}`,children:Ue.map((n,r)=>{let i=r+1,a=_===i;return(0,K.jsx)(`button`,{onClick:()=>{S(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===Ue.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)})})]}),ct=(t=!1)=>(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`button`,{onClick:()=>{Pe?Ie():ke(!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`:``} ${Pe?`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:!R(`printers:control`),children:[(0,K.jsx)($l,{className:`w-4 h-4`}),t&&(0,K.jsx)(`span`,{children:e(`printers.bulk.select`)})]}),s&&Object.keys(Ce).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)(yl,{className:`w-4 h-4`}),e(`printers.powerOn`)]}),(0,K.jsx)(es,{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`)}),V?.filter(e=>Ce[e.id]).map(e=>(0,K.jsx)(OEe,{printer:e,plug:Ce[e.id],onPowerOn:e=>{f(e),Te.mutate(e)},isPowering:d===Ce[e.id]?.id},e.id)),V?.filter(e=>Ce[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:!R(`printers:create`),title:R(`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)(_l,{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)(bl,{className:`w-7 h-7 text-bambu-green`}),e(`printers.title`)]}),(0,K.jsx)(yEe,{printers:V})]}),(0,K.jsxs)(`div`,{ref:$e,className:`relative flex items-center gap-2`,children:[V&&V.length>0&&(0,K.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,K.jsx)(Nl,{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:E,onChange:e=>D(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`}),E&&(0,K.jsx)(`button`,{type:`button`,"aria-label":e(`common.clear`),onClick:()=>D(``),className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{ref:et,"aria-hidden":nt,inert:nt,className:`${nt?`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:ot()}),(0,K.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:st()}),(0,K.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:ct()})]}),nt&&(0,K.jsxs)(`div`,{className:`ml-auto flex items-center justify-end gap-1`,children:[(0,K.jsx)(Cq,{label:e(`printers.toolbar.filters`,`Filters`),icon:(0,K.jsx)(lc,{className:`w-4 h-4`}),children:(0,K.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:ot(!0)})}),(0,K.jsx)(Cq,{label:e(`printers.toolbar.view`,`View`),icon:(0,K.jsx)(ql,{className:`w-4 h-4`}),children:(0,K.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:st(!0)})}),(0,K.jsx)(Cq,{label:e(`printers.toolbar.actions`,`Actions`),icon:(0,K.jsx)(Bs,{className:`w-4 h-4`}),children:(0,K.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:ct(!0)})})]})]})]}),ee?(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`common.loading`)}):V?.length===0?(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{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:!R(`printers:create`),title:R(`printers:create`)?void 0:e(`printers.permission.noAdd`),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]})}):Ke.length===0&&(E.trim()||O!==`all`||A!==`all`)?(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`text-center py-12`,children:(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`printers.noSearchResults`)})})}):Qe?(0,K.jsx)(`div`,{className:`space-y-6`,children:(()=>{let e=p===`status`?xEe.filter(e=>Qe[e]?.length>0):Object.keys(Qe);return h?e:[...e].reverse()})().map(t=>{let n=Qe[t],r=`${p}:${t}`,i=!P[r],a=p===`status`&&Eq[t]?.dot||`bg-bambu-green`,o=p===`status`?e(Eq[t]?.labelKey||t):t;return(0,K.jsx)(Mf,{open:i,onToggle:()=>Ze(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,`)`]}),Pe&&(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p===`location`?Ye(t===`Ungrouped`?``:t):p===`status`?Je(t):p===`model`&&Xe(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`:``} ${He()}`,children:n.map(e=>(0,K.jsx)(jq,{printer:e,hideIfDisconnected:s,maintenanceInfo:Se[e.id],viewMode:b,cardSize:_,amsThresholds:H?{humidityGood:Number(H.ams_humidity_good)||40,humidityFair:Number(H.ams_humidity_fair)||60,tempGood:Number(H.ams_temp_good)||28,tempFair:Number(H.ams_temp_fair)||35}:void 0,spoolmanEnabled:se,hasUnlinkedSpools:de,linkedSpools:pe,spoolmanUrl:oe?.url,spoolmanSyncMode:le,onGetAssignment:xe,onUnassignSpool:(e,t,n)=>he.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:ge,spoolmanSlotAssignments:ve,spoolmanLoading:_e||ye,onUnassignSpoolmanSpool:e=>be.mutate(e),timeFormat:H?.time_format||`system`,cameraViewMode:H?.camera_view_mode||`window`,onOpenEmbeddedCamera:(e,t)=>B(n=>new Map(n).set(e,{id:e,name:t})),checkPrinterFirmware:H?.check_printer_firmware!==!1,dryingPresets:ie,nozzleTempPresets:te,bedTempPresets:ne,chamberTempPresets:re,fanSpeedPresets:U,requirePlateClear:H?.require_plate_clear===!0,selectionMode:Pe,isSelected:Ee.has(e.id),onToggleSelect:Fe,onOpenCompactCard:w},e.id))})},t)})}):(0,K.jsx)(`div`,{className:`grid gap-4 ${_>=3?`gap-6`:``} ${He()}`,children:Ke.map(e=>(0,K.jsx)(jq,{printer:e,hideIfDisconnected:s,maintenanceInfo:Se[e.id],viewMode:b,cardSize:_,spoolmanEnabled:se,hasUnlinkedSpools:de,linkedSpools:pe,spoolmanUrl:oe?.url,spoolmanSyncMode:le,onGetAssignment:xe,onUnassignSpool:(e,t,n)=>he.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:ge,spoolmanSlotAssignments:ve,spoolmanLoading:_e||ye,onUnassignSpoolmanSpool:e=>be.mutate(e),amsThresholds:H?{humidityGood:Number(H.ams_humidity_good)||40,humidityFair:Number(H.ams_humidity_fair)||60,tempGood:Number(H.ams_temp_good)||28,tempFair:Number(H.ams_temp_fair)||35}:void 0,timeFormat:H?.time_format||`system`,cameraViewMode:H?.camera_view_mode||`window`,onOpenEmbeddedCamera:(e,t)=>B(n=>new Map(n).set(e,{id:e,name:t})),checkPrinterFirmware:H?.check_printer_firmware!==!1,dryingPresets:ie,nozzleTempPresets:te,bedTempPresets:ne,chamberTempPresets:re,fanSpeedPresets:U,requirePlateClear:H?.require_plate_clear===!0,selectionMode:Pe,isSelected:Ee.has(e.id),onToggleSelect:Fe,onOpenCompactCard:w},e.id))}),_===2&&x!=null&&(0,K.jsxs)(`button`,{type:`button`,onClick:T,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)(Do,{className:`w-4 h-4`}),e(`common.back`,`Back`)]}),a&&(0,K.jsx)(wEe,{onClose:()=>o(!1),onAdd:e=>we.mutate(e),existingSerials:V?.map(e=>e.serial_number)||[]}),Pe&&V&&(0,K.jsx)(hp,{selectedIds:Ee,printers:V,onClose:Ie,onSelectAll:qe,onSelectByLocation:Ye,onSelectByState:Je,onAction:Re,actionPending:Me}),Ae===`stop`&&(0,K.jsx)(Ed,{title:e(`printers.bulk.confirm.stopTitle`,{count:Ee.size}),message:e(`printers.bulk.confirm.stopMessage`,{count:Ee.size}),confirmText:e(`printers.bulk.confirm.stopButton`),variant:`danger`,isLoading:Me,onConfirm:()=>Le(`stop`),onCancel:()=>je(null)}),Ae===`pause`&&(0,K.jsx)(Ed,{title:e(`printers.bulk.confirm.pauseTitle`,{count:Ee.size}),message:e(`printers.bulk.confirm.pauseMessage`,{count:Ee.size}),confirmText:e(`printers.bulk.confirm.pauseButton`),isLoading:Me,onConfirm:()=>Le(`pause`),onCancel:()=>je(null)}),Ae===`clearPlate`&&(0,K.jsx)(Ed,{title:e(`printers.bulk.confirm.clearPlateTitle`,{count:Ee.size}),message:e(`printers.bulk.confirm.clearPlateMessage`,{count:Ee.size}),confirmText:e(`printers.bulk.confirm.clearPlateButton`),isLoading:Me,onConfirm:()=>Le(`clearPlate`),onCancel:()=>je(null)}),Array.from(z.values()).map((e,t)=>(0,K.jsx)(mce,{printerId:e.id,printerName:e.name,viewerIndex:t,onClose:()=>B(t=>{let n=new Map(t);return n.delete(e.id),n})},e.id))]})}function AEe({title:e,message:t,subtitle:n,closeText:r,variant:i=`error`,onClose:a}){let{t:o}=G(),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)(pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(hd,{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-400`:`text-red-400`}`,children:(0,K.jsx)(vu,{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 Mq=(0,y.createContext)(null),jEe=1500,MEe=1e3,Nq=e=>`slice-job-${e}`;function Pq(e){try{return decodeURIComponent(e)}catch{return e}}function NEe(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 PEe({children:e}){let{t}=G(),{showToast:n,showPersistentToast:r,dismissToast:i}=xd(),a=Qa(),[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=NEe(i),s=p.current.get(e.id)??null,c=s&&s.stage&&s.total_percent>0;if(a===`running`&&c){let n=Pq(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(Nq(e.id),c,`loading`);return}let l=a===`pending`?`slice.queuedToast`:`slice.runningToast`,u=a===`pending`?`Queued: {{name}} — {{elapsed}}`:`Slicing {{name}} — {{elapsed}}`;r(Nq(e.id),t(l,u,{name:Pq(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(Nq(e.id)),r.status===`completed`?n(t(`slice.completedToast`,`Sliced {{name}}`,{name:Pq(e.sourceName)}),`success`):r.status===`failed`&&l({name:Pq(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{}},jEe);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)},MEe);return()=>clearInterval(e)},[o.length,m]),(0,K.jsxs)(Mq.Provider,{value:{trackJob:h,activeJobs:o},children:[e,c&&(0,K.jsx)(AEe,{title:t(`slice.failedTitle`),subtitle:c.name,message:c.detail,onClose:()=>l(null)})]})}function FEe(){let e=(0,y.useContext)(Mq);if(!e)throw Error(`useSliceJobTracker must be used inside SliceJobTrackerProvider`);return e}function Fq({plates:e,onSelect:t,onClose:n}){let{t:r}=G();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)(Pu,{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:Ku(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)(Nc,{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?``:` • ${yf(e.print_time_seconds)}`]})]})]},e.index))})})]})})}var Iq=[`local`,`orca_cloud`,`cloud`,`standard`];function Lq(e,t){for(let n of Iq){let r=e[n][t];if(r.length>0)return{source:r[0].source,id:r[0].id}}return null}function Rq(e,t,n){return t?e[t.source][n].find(e=>e.id===t.id)??null:null}function zq(e,t,n){if(!n)return null;for(let r of Iq){let i=e[r][t].find(e=>e.name===n);if(i)return{source:i.source,id:i.id}}return null}function IEe(e,t,n,r){let i=zq(e,`process`,r);if(i){let r=Rq(e,i,`process`);if(r&&iK(r,`process`,t,n)!==`mismatch`)return i}for(let r of[`match`,`unknown`])for(let i of Iq)for(let a of e[i].process)if(iK(a,`process`,t,n)===r)return{source:a.source,id:a.id};return Lq(e,`process`)}var LEe={local:1.75,orca_cloud:1.5,cloud:1,standard:.5};function REe(e,t,n,r){let i=t.type.trim().toUpperCase(),a=jK(t.color),o=null;for(let s of Iq)for(let c of e[s].filament){let e=0,l=(c.filament_type??``).trim().toUpperCase(),u=jK(c.filament_colour??``);i&&l&&i===l&&(e+=10),a&&u&&(u===a?e+=5:FK(c.filament_colour??``,t.color)&&(e+=2)),e+=LEe[s],iK(c,`filament`,n,r)===`mismatch`&&(e-=100),(o==null||e>o.score)&&(o={ref:{source:c.source,id:c.id},score:e})}return o==null?Lq(e,`filament`):o.ref}function zEe(e){return e?`${e.source}:${e.id}`:``}function BEe(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 VEe({requestId:e,sourceName:t}){let{t:n}=G(),{showPersistentToast:r,dismissToast:i}=xd(),[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=HEe(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 HEe(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 Bq({source:e,onClose:t}){let{t:n}=G(),{trackJob:r}=FEe(),i=Qa(),[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=q({queryKey:[`slicePlates`,e.kind,e.id],queryFn:async()=>e.kind===`libraryFile`?Q.getLibraryFilePlates(e.id):Q.getArchivePlates(e.id),staleTime:6e4}),x=!!b.data?.is_multi_plate&&(b.data?.plates?.length??0)>1,S=x&&p==null,C=p??1,w=(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${C}-${t}`},[e.kind,e.id,C]),T=q({queryKey:[`sliceFilamentReqs`,e.kind,e.id,C],queryFn:async()=>e.kind===`libraryFile`?Q.getLibraryFileFilamentRequirements(e.id,C,w):Q.getArchiveFilamentRequirements(e.id,C,w),enabled:!S,staleTime:6e4}),E=(0,y.useMemo)(()=>{let e=T.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,T.data]),D=q({queryKey:[`slicerPresets`],queryFn:()=>Q.getSlicerPresets(),staleTime:6e4,enabled:!b.isLoading&&!S}),[O,k]=(0,y.useState)(!1),A=async()=>{if(!O){k(!0);try{let e=await Q.getSlicerPresets({refresh:!0});i.setQueryData([`slicerPresets`],e)}catch{i.invalidateQueries({queryKey:[`slicerPresets`]})}finally{k(!1)}}},j=q({queryKey:[`slicerPrinterModels`],queryFn:Q.getSlicerPrinterModels,staleTime:1/0}),M=(0,y.useMemo)(()=>!D.data||!a?null:Rq(D.data,a,`printer`)?.name??null,[D.data,a]),N=(0,y.useMemo)(()=>tK(j.data??{}),[j.data]),P=b.data?.embedded_printer??null,F=b.data?.embedded_process??null;(0,y.useEffect)(()=>{let e=D.data;e&&(a??o(zq(e,`printer`,P)??Lq(e,`printer`)))},[D.data,P]),(0,y.useEffect)(()=>{let e=D.data;e&&c(t=>{if(t){let n=Rq(e,t,`process`);if(n&&iK(n,`process`,M,N)!==`mismatch`)return t}return IEe(e,M,N,F)})},[D.data,M,N,F]),(0,y.useEffect)(()=>{let e=D.data;e&&u(t=>E.map((n,r)=>{let i=t[r]??null;if(i){let t=Rq(e,i,`filament`);if(t&&iK(t,`filament`,M,N)!==`mismatch`)return i}return REe(e,{type:n.type,color:n.color},M,N)}))},[D.data,E,M,N]);let I=J({mutationFn:async t=>{let n=L(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 L(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:_}}}let R=a!=null&&s!=null&&T.isSuccess&&l.length>0&&l.every(e=>e!=null),z=I.isPending,B=b.data?.plates?.length??0,V=x&&B>1&&!S;return S&&b.data?(0,K.jsx)(Fq,{plates:b.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:()=>{z||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)(ws,{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:z,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors disabled:opacity-50`,"aria-label":n(`common.close`),children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(b.isLoading||D.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`)]}),D.isError&&(0,K.jsx)(`div`,{className:`text-sm 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.`)}),D.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)(Vq,{status:D.data.cloud_status,cloudName:`bambu`}),(0,K.jsx)(Vq,{status:D.data.orca_cloud_status,cloudName:`orca`})]}),(0,K.jsxs)(`button`,{type:`button`,onClick:A,disabled:O||z,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)(Cl,{className:`w-3.5 h-3.5 ${O?`animate-spin`:``}`}),n(`slice.refreshPresets`)]})]}),(0,K.jsx)(Hq,{label:n(`slice.printer`),slot:`printer`,data:D.data,value:a,onChange:o,disabled:z}),(0,K.jsx)(Hq,{label:n(`slice.process`),slot:`process`,data:D.data,value:s,onChange:c,disabled:z,selectedPrinterName:M,compatIndex:N}),(0,K.jsx)(WEe,{value:_,onChange:v,disabled:z}),T.isLoading?(0,K.jsx)(VEe,{requestId:w,sourceName:e.filename}):E.map((e,t)=>{let r=e.used_in_plate!==!1,i=E.length>1?n(`slice.filamentSlot`,{index:t+1,type:e.type}):n(`slice.filament`);return(0,K.jsx)(Hq,{label:r?i:`${i} ${n(`slice.notUsedByPlate`)}`,slot:`filament`,data:D.data,value:l[t]??null,onChange:e=>u(n=>{let r=n.length===E.length?[...n]:E.map((e,t)=>n[t]??null);return r[t]=e,r}),disabled:z||!r,swatchColor:E.length>1?e.color:void 0,selectedPrinterName:M,compatIndex:N},`filament-${t}`)})]}),d&&(0,K.jsx)(`div`,{className:`text-sm 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:z,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`)}),V&&(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:B}),children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),disabled:z,className:`cursor-pointer`}),n(`slice.allPlatesToggle`,{count:B})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{f(null);let e=h?0:p;I.mutate(e)},disabled:!R||z,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:z?(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:B}):n(`slice.action`)})]})]})})}function Vq({status:e,cloudName:t=`bambu`}){let{t:n}=G();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-700/40 bg-amber-900/20 text-amber-200`,icon:vs},unreachable:{tone:`border-bambu-dark-tertiary/40 bg-bambu-dark text-bambu-gray`,icon:vs}}[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 UEe=[{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 WEe({value:e,onChange:t,disabled:n}){let{t:r}=G();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`)}),UEe.map(e=>(0,K.jsx)(`option`,{value:e.value,children:r(e.labelKey,e.fallback)},e.value))]})]})}function Hq({label:e,slot:t,data:n,value:r,onChange:i,disabled:a,swatchColor:o,selectedPrinterName:s,compatIndex:c}){let{t:l}=G(),{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)iK(n,t,s??null,c??wTe)===`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:zEe(r),onChange:e=>i(BEe(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 GEe(){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 Uq(e,t=`bambu_studio`){let n,r=encodeURIComponent(e);n=t===`orcaslicer`?`orcaslicer://open?file=${r}`:GEe()===`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 Wq=768;function Gq(){let[e,t]=(0,y.useState)(()=>typeof window<`u`?window.innerWidth{let e=window.matchMedia(`(max-width: ${Wq-1}px)`),n=e=>{t(e.matches)};return t(e.matches),e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}function KEe({onClose:e,initialFiles:t}){let{t:n}=G(),r=Qa(),{showToast:i}=xd(),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)(pd,{className:`w-full max-w-2xl max-h-[90vh] flex flex-col`,children:(0,K.jsxs)(hd,{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)(Pu,{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)(Su,{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)(Qs,{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-400 transition-colors`,disabled:x,children:(0,K.jsx)(Pu,{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)(ls,{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-400`,children:e.error}),(0,K.jsx)(ss,{className:`w-4 h-4 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-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)(Su,{className:`w-4 h-4`}),n(`uploadModal.upload`),` `,b>0&&`(${b})`]})})]})]})})})}var qEe=365;function JEe({onClose:e,initialDays:t}){let{t:n}=G(),r=Qa(),{showToast:i}=xd(),[a,o]=(0,y.useState)(t??qEe),[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)(hu,{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)(Pu,{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:yd(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)(vu,{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 YEe(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 XEe(e){if(!e)return`—`;let t=mf(e);return t?t.toLocaleString():`—`}function Kq({archiveId:e}){let{t}=G(),{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-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:XEe(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:YEe(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 qq=[`adhesionFailure`,`spaghettiDetached`,`layerShift`,`cloggedNozzle`,`filamentRunout`,`warping`,`stringing`,`underExtrusion`,`powerFailure`,`userCancelled`,`other`],ZEe=[`completed`,`failed`,`aborted`,`printing`];function Jq({archive:e,onClose:t,existingTags:n=[]}){let{t:r}=G();(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let i=Qa(),[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?qq.includes(t)?t:qq.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()}}),H=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=``)}}},te=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)(Pu,{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)(Kq,{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)(nc,{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)(bc,{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)(Lc,{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)(su,{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)(Pu,{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:ZEe.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`)}),qq.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)(Jo,{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:()=>te(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)(hu,{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:H,className:`hidden`,disabled:E}),E?(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,K.jsx)(_l,{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)(Ol,{className:`w-4 h-4`}),ee.isPending?r(`common.saving`):r(`common.save`)]})]})]})]})})}function Yq({archiveId:e,archiveName:t,onClose:n}){let{t:r}=G();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)(wc,{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)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`p-6 overflow-y-auto flex-1`,children:(0,K.jsx)(Kq,{archiveId:e})})]})})}function QEe({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)(Nl,{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-400 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 Xq({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-400 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)(ts,{className:`w-4 h-4 text-bambu-gray`})]}),n&&a===t&&(0,K.jsx)(QEe,{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 $Ee({selectedIds:e,existingTags:t,onClose:n}){let r=Qa(),{showToast:i}=xd(),[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)(pd,{className:`w-full max-w-md`,children:(0,K.jsxs)(hd,{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)(su,{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)(Pu,{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)(_l,{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-500/20 text-green-400`:`bg-red-500/20 text-red-400`}`,children:[e,(0,K.jsx)(`button`,{onClick:()=>f(e),className:`hover:opacity-70`,children:(0,K.jsx)(Pu,{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)(su,{className:`w-4 h-4`}),l===`add`?`Add Tags`:`Remove Tags`]})})]})]})})})}function eDe({selectedIds:e,onClose:t}){let{t:n}=G(),r=Qa(),{showToast:i}=xd(),[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)(pd,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,children:(0,K.jsxs)(hd,{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)(nc,{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)(Pu,{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)(ms,{className:`w-4 h-4 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)(Nl,{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)(nc,{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 tDe(e,t){return new Date(e,t+1,0).getDate()}function nDe(e,t){return new Date(e,t,1).getDay()}var rDe=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],iDe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function aDe({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=mf(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=tDe(o,i),m=nDe(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)(ns,{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:[rDe[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)(ts,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-7 gap-1 mb-1`,children:iDe.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=mf(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-400`,children:e.filter(e=>{let t=mf(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-400`,children:e.filter(e=>{let t=mf(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-400`:`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 Zq({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)(Pu,{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)(Is,{className:`w-4 h-4`}),`Download QR Code`]})]})]})})}function Qq({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)(Is,{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)(hu,{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)(Pu,{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)(ns,{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)(ts,{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)(Ed,{title:`Delete Photo`,message:`Delete this photo? This cannot be undone.`,confirmText:`Delete`,variant:`danger`,onConfirm:()=>{i?.(l),c(!1)},onCancel:()=>c(!1)})]})}function $q(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n`u`?null:CJ(BigInt.prototype.toString),vJ=typeof Symbol>`u`?null:CJ(Symbol.prototype.toString),yJ=CJ(Object.prototype.hasOwnProperty),bJ=CJ(Object.prototype.toString),xJ=CJ(RegExp.prototype.test),SJ=yDe(TypeError);function CJ(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return oJ(e,t,n)}}function yDe(e){return function(){return sJ(e,[...arguments])}}function wJ(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:fJ;if(tJ&&tJ(e,null),!dJ(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(dDe(t)||(t[r]=e),i=e)}e[i]=!0}return e}function bDe(e){for(let t=0;t/g),DDe=rJ(/\${[\w\W]*/g),ODe=rJ(/^data-[\-\w.\u00B7-\uFFFF]+$/),kDe=rJ(/^aria-[\-\w]+$/),IJ=rJ(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),ADe=rJ(/^(?:\w+script|data):/i),jDe=rJ(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),MDe=rJ(/^html$/i),NDe=rJ(/^[a-z][.\w]*(-[.\w]+)+$/i),LJ=rJ(/<[/\w!]/g),PDe=rJ(/<[/\w]/g),FDe=rJ(/<\/no(script|embed|frames)/i),IDe=rJ(/\/>/i),RJ={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},LDe=function(){return typeof window>`u`?null:window},RDe=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}},zJ=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},BJ=function(e,t,n,r){return yJ(e,t)&&dJ(e[t])?wJ(r.base?TJ(r.base):{},e[t],r.transform):n};function VJ(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:LDe(),t=e=>VJ(e);if(t.version=`3.4.11`,t.removed=[],!e||!e.document||e.document.nodeType!==RJ.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=EJ(d,`cloneNode`),p=EJ(d,`remove`),m=EJ(d,`nextSibling`),h=EJ(d,`childNodes`),g=EJ(d,`parentNode`),_=EJ(d,`shadowRoot`),v=EJ(d,`attributes`),y=o&&o.prototype?EJ(o.prototype,`nodeType`):null,b=o&&o.prototype?EJ(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 SJ(`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=RDe(u,i),!0),C},A=n,j=A.implementation,M=A.createNodeIterator,N=A.createDocumentFragment,P=A.getElementsByTagName,F=r.importNode,I=zJ();t.isSupported=typeof eJ==`function`&&typeof g==`function`&&j&&j.createHTMLDocument!==void 0;let L=TDe,R=EDe,z=DDe,B=ODe,V=kDe,ee=ADe,H=jDe,te=NDe,ne=IJ,re=null,U=wJ({},[...DJ,...OJ,...kJ,...AJ,...jJ]),ie=null,ae=wJ({},[...MJ,...NJ,...PJ,...FJ]),W=Object.seal(iJ(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}})),oe=null,se=null,ce=Object.seal(iJ(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),le=!0,ue=!0,de=!1,fe=!0,pe=!1,me=!0,he=!1,ge=!1,_e=null,ve=null,ye=!1,be=!1,xe=!1,Se=!1,Ce=!0,we=!1,Te=`user-content-`,Ee=!0,De=!1,Oe={},ke=null,Ae=wJ({},`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(`.`)),je=null,Me=wJ({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Ne=null,Pe=wJ({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Fe=`http://www.w3.org/1998/Math/MathML`,Ie=`http://www.w3.org/2000/svg`,Le=`http://www.w3.org/1999/xhtml`,Re=Le,ze=!1,Be=null,Ve=wJ({},[Fe,Ie,Le],pJ),He=nJ([`mi`,`mo`,`mn`,`ms`,`mtext`]),Ue=wJ({},He),We=nJ([`annotation-xml`]),Ge=wJ({},We),Ke=wJ({},[`title`,`style`,`font`,`a`,`script`]),qe=null,Je=[`application/xhtml+xml`,`text/html`],Ye=null,Xe=null,Ze=n.createElement(`form`),Qe=function(e){return e instanceof RegExp||e instanceof Function},G=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(Xe&&Xe===e)return;(!e||typeof e!=`object`)&&(e={}),e=TJ(e),qe=Je.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,Ye=qe===`application/xhtml+xml`?pJ:fJ,re=BJ(e,`ALLOWED_TAGS`,U,{transform:Ye}),ie=BJ(e,`ALLOWED_ATTR`,ae,{transform:Ye}),Be=BJ(e,`ALLOWED_NAMESPACES`,Ve,{transform:pJ}),Ne=BJ(e,`ADD_URI_SAFE_ATTR`,Pe,{transform:Ye,base:Pe}),je=BJ(e,`ADD_DATA_URI_TAGS`,Me,{transform:Ye,base:Me}),ke=BJ(e,`FORBID_CONTENTS`,Ae,{transform:Ye}),oe=BJ(e,`FORBID_TAGS`,TJ({}),{transform:Ye}),se=BJ(e,`FORBID_ATTR`,TJ({}),{transform:Ye}),Oe=yJ(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?TJ(e.USE_PROFILES):e.USE_PROFILES:!1,le=e.ALLOW_ARIA_ATTR!==!1,ue=e.ALLOW_DATA_ATTR!==!1,de=e.ALLOW_UNKNOWN_PROTOCOLS||!1,fe=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,pe=e.SAFE_FOR_TEMPLATES||!1,me=e.SAFE_FOR_XML!==!1,he=e.WHOLE_DOCUMENT||!1,be=e.RETURN_DOM||!1,xe=e.RETURN_DOM_FRAGMENT||!1,Se=e.RETURN_TRUSTED_TYPE||!1,ye=e.FORCE_BODY||!1,Ce=e.SANITIZE_DOM!==!1,we=e.SANITIZE_NAMED_PROPS||!1,Ee=e.KEEP_CONTENT!==!1,De=e.IN_PLACE||!1,ne=SDe(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:IJ,Re=typeof e.NAMESPACE==`string`?e.NAMESPACE:Le,Ue=yJ(e,`MATHML_TEXT_INTEGRATION_POINTS`)&&e.MATHML_TEXT_INTEGRATION_POINTS&&typeof e.MATHML_TEXT_INTEGRATION_POINTS==`object`?TJ(e.MATHML_TEXT_INTEGRATION_POINTS):wJ({},He),Ge=yJ(e,`HTML_INTEGRATION_POINTS`)&&e.HTML_INTEGRATION_POINTS&&typeof e.HTML_INTEGRATION_POINTS==`object`?TJ(e.HTML_INTEGRATION_POINTS):wJ({},We);let t=yJ(e,`CUSTOM_ELEMENT_HANDLING`)&&e.CUSTOM_ELEMENT_HANDLING&&typeof e.CUSTOM_ELEMENT_HANDLING==`object`?TJ(e.CUSTOM_ELEMENT_HANDLING):iJ(null);if(W=iJ(null),yJ(t,`tagNameCheck`)&&Qe(t.tagNameCheck)&&(W.tagNameCheck=t.tagNameCheck),yJ(t,`attributeNameCheck`)&&Qe(t.attributeNameCheck)&&(W.attributeNameCheck=t.attributeNameCheck),yJ(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(W.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),rJ(W),pe&&(ue=!1),xe&&(be=!0),Oe&&(re=wJ({},jJ),ie=iJ(null),Oe.html===!0&&(wJ(re,DJ),wJ(ie,MJ)),Oe.svg===!0&&(wJ(re,OJ),wJ(ie,NJ),wJ(ie,FJ)),Oe.svgFilters===!0&&(wJ(re,kJ),wJ(ie,NJ),wJ(ie,FJ)),Oe.mathMl===!0&&(wJ(re,AJ),wJ(ie,PJ),wJ(ie,FJ))),ce.tagCheck=null,ce.attributeCheck=null,yJ(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?ce.tagCheck=e.ADD_TAGS:dJ(e.ADD_TAGS)&&(re===U&&(re=TJ(re)),wJ(re,e.ADD_TAGS,Ye))),yJ(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?ce.attributeCheck=e.ADD_ATTR:dJ(e.ADD_ATTR)&&(ie===ae&&(ie=TJ(ie)),wJ(ie,e.ADD_ATTR,Ye))),yJ(e,`ADD_URI_SAFE_ATTR`)&&dJ(e.ADD_URI_SAFE_ATTR)&&wJ(Ne,e.ADD_URI_SAFE_ATTR,Ye),yJ(e,`FORBID_CONTENTS`)&&dJ(e.FORBID_CONTENTS)&&(ke===Ae&&(ke=TJ(ke)),wJ(ke,e.FORBID_CONTENTS,Ye)),yJ(e,`ADD_FORBID_CONTENTS`)&&dJ(e.ADD_FORBID_CONTENTS)&&(ke===Ae&&(ke=TJ(ke)),wJ(ke,e.ADD_FORBID_CONTENTS,Ye)),Ee&&(re[`#text`]=!0),he&&wJ(re,[`html`,`head`,`body`]),re.table&&(wJ(re,[`tbody`]),delete oe.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw SJ(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw SJ(`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(``)));nJ&&nJ(e),Xe=e},$e=wJ({},[...OJ,...kJ,...CDe]),et=wJ({},[...AJ,...wDe]),tt=function(e,t,n){return t.namespaceURI===Le?e===`svg`:t.namespaceURI===Fe?e===`svg`&&(n===`annotation-xml`||Ue[n]):!!$e[e]},nt=function(e,t,n){return t.namespaceURI===Le?e===`math`:t.namespaceURI===Ie?e===`math`&&Ge[n]:!!et[e]},rt=function(e,t,n){return t.namespaceURI===Ie&&!Ge[n]||t.namespaceURI===Fe&&!Ue[n]?!1:!et[e]&&(Ke[e]||!$e[e])},it=function(e){let t=g(e);(!t||!t.tagName)&&(t={namespaceURI:Re,tagName:`template`});let n=fJ(e.tagName),r=fJ(t.tagName);return Be[e.namespaceURI]?e.namespaceURI===Ie?tt(n,t,r):e.namespaceURI===Fe?nt(n,t,r):e.namespaceURI===Le?rt(n,t,r):!!(qe===`application/xhtml+xml`&&Be[e.namespaceURI]):!1},at=function(e){uJ(t.removed,{element:e});try{g(e).removeChild(e)}catch{if(p(e),!g(e))throw SJ(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},ot=function(e){let t=h(e);if(t){let e=[];cJ(t,t=>{uJ(e,t)}),cJ(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{}}},st=function(e,n){try{uJ(t.removed,{attribute:n.getAttributeNode(e),from:n})}catch{uJ(t.removed,{attribute:null,from:n})}if(n.removeAttribute(e),e===`is`)if(be||xe)try{at(n)}catch{}else try{n.setAttribute(e,``)}catch{}},ct=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`||ie[Ye(i)]))try{e.removeAttribute(i)}catch{}}},lt=function(e){let t=[e];for(;t.length>0;){let e=t.pop();(y?y(e):e.nodeType)===RJ.element&&ct(e);let n=h(e);if(n)for(let e=n.length-1;e>=0;--e)t.push(n[e])}},ut=function(e){let t=null,r=null;if(ye)e=``+e;else{let t=mJ(e,/^[\r\n\t ]+/);r=t&&t[0]}qe===`application/xhtml+xml`&&Re===Le&&(e=``+e+``);let i=x?D(e):e;if(Re===Le)try{t=new l().parseFromString(i,qe)}catch{}if(!t||!t.documentElement){t=j.createDocument(Re,`template`,null);try{t.documentElement.innerHTML=ze?S:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),Re===Le?P.call(t,he?`html`:`body`)[0]:he?t.documentElement:a},dt=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)},ft=function(e){return e=hJ(e,L,` `),e=hJ(e,R,` `),e=hJ(e,z,` `),e},pt=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=ft(n.data),n=t.nextNode();let r=e.querySelectorAll?.call(e,`template`);r&&cJ(r,e=>{ht(e.content)&&pt(e.content)})},mt=function(e){let t=b?b(e):null;return typeof t!=`string`||Ye(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)},ht=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return y(e)===RJ.documentFragment}catch{return!1}},gt=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return typeof y(e)==`number`}catch{return!1}};function _t(e,n,r){e.length!==0&&cJ(e,e=>{e.call(t,n,r,Xe)})}let vt=function(e,t){return!!(me&&e.hasChildNodes()&&!gt(e.firstElementChild)&&xJ(LJ,e.textContent)&&xJ(LJ,e.innerHTML)||me&&e.namespaceURI===Le&&t===`style`&>(e.firstElementChild)||e.nodeType===RJ.processingInstruction||me&&e.nodeType===RJ.comment&&xJ(PDe,e.data))},yt=function(e,t){if(!oe[t]&&Ct(t)&&(W.tagNameCheck instanceof RegExp&&xJ(W.tagNameCheck,t)||W.tagNameCheck instanceof Function&&W.tagNameCheck(t)))return!1;if(Ee&&!ke[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=De?n[i]:f(n[i],!0);t.insertBefore(r,m(e))}}}return at(e),!0},bt=function(e){if(_t(I.beforeSanitizeElements,e,null),mt(e))return at(e),!0;let n=Ye(b?b(e):e.nodeName);if(_t(I.uponSanitizeElement,e,{tagName:n,allowedTags:re}),vt(e,n))return at(e),!0;if(oe[n]||!(ce.tagCheck instanceof Function&&ce.tagCheck(n))&&!re[n])return yt(e,n);if((y?y(e):e.nodeType)===RJ.element&&!it(e)||(n===`noscript`||n===`noembed`||n===`noframes`)&&xJ(FDe,e.innerHTML))return at(e),!0;if(pe&&e.nodeType===RJ.text){let n=ft(e.textContent);e.textContent!==n&&(uJ(t.removed,{element:e.cloneNode()}),e.textContent=n)}return _t(I.afterSanitizeElements,e,null),!1},xt=function(e,t,r){if(se[t]||Ce&&(t===`id`||t===`name`)&&(r in n||r in Ze))return!1;let i=ie[t]||ce.attributeCheck instanceof Function&&ce.attributeCheck(t,e);if(!(ue&&xJ(B,t))&&!(le&&xJ(V,t))){if(!i){if(!(Ct(e)&&(W.tagNameCheck instanceof RegExp&&xJ(W.tagNameCheck,e)||W.tagNameCheck instanceof Function&&W.tagNameCheck(e))&&(W.attributeNameCheck instanceof RegExp&&xJ(W.attributeNameCheck,t)||W.attributeNameCheck instanceof Function&&W.attributeNameCheck(t,e))||t===`is`&&W.allowCustomizedBuiltInElements&&(W.tagNameCheck instanceof RegExp&&xJ(W.tagNameCheck,r)||W.tagNameCheck instanceof Function&&W.tagNameCheck(r))))return!1}else if(!Ne[t]&&!xJ(ne,hJ(r,H,``))&&!((t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&gJ(r,`data:`)===0&&je[e])&&!(de&&!xJ(ee,hJ(r,H,``)))&&r)return!1}return!0},St=wJ({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),Ct=function(e){return!St[fJ(e)]&&xJ(te,e)},wt=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},Tt=function(e,n,r,i){try{r?e.setAttributeNS(r,n,i):e.setAttribute(n,i),mt(e)?at(e):lJ(t.removed)}catch{st(n,e)}},Et=function(e){_t(I.beforeSanitizeAttributes,e,null);let t=e.attributes;if(!t||mt(e))return;let n={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:ie,forceKeepAttr:void 0},r=t.length,i=Ye(e.nodeName);for(;r--;){let a=t[r],o=a.name,s=a.namespaceURI,c=a.value,l=Ye(o),u=c,d=o===`value`?u:gDe(u);if(n.attrName=l,n.attrValue=d,n.keepAttr=!0,n.forceKeepAttr=void 0,_t(I.uponSanitizeAttribute,e,n),d=n.attrValue,we&&(l===`id`||l===`name`)&&gJ(d,Te)!==0&&(st(o,e),d=Te+d),me&&xJ(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)){st(o,e);continue}if(l===`attributename`&&mJ(d,`href`)){st(o,e);continue}if(!n.forceKeepAttr){if(!n.keepAttr){st(o,e);continue}if(!fe&&xJ(IDe,d)){st(o,e);continue}if(pe&&(d=ft(d)),!xt(i,l,d)){st(o,e);continue}d=wt(i,l,s,d),d!==u&&Tt(e,o,s,d)}}_t(I.afterSanitizeAttributes,e,null)},Dt=function(e){let t=null,n=dt(e);for(_t(I.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(_t(I.uponSanitizeShadowNode,t,null),bt(t),Et(t),ht(t.content)&&Dt(t.content),(y?y(t):t.nodeType)===RJ.element){let e=_(t);ht(e)&&(Ot(e),Dt(e))}_t(I.afterSanitizeShadowDOM,e,null)},Ot=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){Dt(e.shadow);continue}let n=e.node,r=(y?y(n):n.nodeType)===RJ.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`&&Ye(e)===`template`){let e=n.content;ht(e)&&t.push({node:e,shadow:null})}}if(r){let e=_(n);ht(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(ze=!e,ze&&(e=``),typeof e!=`string`&&!gt(e)&&(e=xDe(e),typeof e!=`string`))throw SJ(`dirty is not a string, aborting`);if(!t.isSupported)return e;ge?(re=_e,ie=ve):G(n),(I.uponSanitizeElement.length>0||I.uponSanitizeAttribute.length>0)&&(re=TJ(re)),I.uponSanitizeAttribute.length>0&&(ie=TJ(ie)),t.removed=[];let c=De&&typeof e!=`string`&>(e);if(c){let t=b?b(e):e.nodeName;if(typeof t==`string`){let e=Ye(t);if(!re[e]||oe[e])throw SJ(`root node is forbidden and cannot be sanitized in-place`)}if(mt(e))throw SJ(`root node is clobbered and cannot be sanitized in-place`);try{Ot(e)}catch(t){throw ot(e),t}}else if(gt(e))i=ut(``),a=i.ownerDocument.importNode(e,!0),a.nodeType===RJ.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),Ot(a);else{if(!be&&!pe&&!he&&e.indexOf(`<`)===-1)return x&&Se?D(e):e;if(i=ut(e),!i)return be?null:Se?S:``}i&&ye&&at(i.firstChild);let l=dt(c?e:i);try{for(;o=l.nextNode();)bt(o),Et(o),ht(o.content)&&Dt(o.content)}catch(t){throw c&&ot(e),t}if(c)return cJ(t.removed,e=>{e.element&<(e.element)}),pe&&pt(e),e;if(be){if(pe&&pt(i),xe)for(s=N.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(ie.shadowroot||ie.shadowrootmode)&&(s=F.call(r,s,!0)),s}let u=he?i.outerHTML:i.innerHTML;return he&&re[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&xJ(MDe,i.ownerDocument.doctype.name)&&(u=` +`+u),pe&&(u=ft(u)),x&&Se?D(u):u},t.setConfig=function(){G(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}),ge=!0,_e=re,ve=ie},t.clearConfig=function(){Xe=null,ge=!1,_e=null,ve=null,x=C,S=``},t.isValidAttribute=function(e,t,n){return Xe||G({}),xt(Ye(e),Ye(t),n)},t.addHook=function(e,t){typeof t==`function`&&yJ(I,e)&&uJ(I[e],t)},t.removeHook=function(e,t){if(yJ(I,e)){if(t!==void 0){let n=mDe(I[e],t);return n===-1?void 0:hDe(I[e],n,1)[0]}return lJ(I[e])}},t.removeHooks=function(e){yJ(I,e)&&(I[e]=[])},t.removeAllHooks=function(){I=zJ()},t}var HJ=VJ();function UJ(e){this.content=e}UJ.prototype={constructor:UJ,find:function(e){for(var t=0;t>1}},UJ.from=function(e){if(e instanceof UJ)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new UJ(t)};function WJ(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=WJ(i.content,a.content,n+1);if(e!=null)return e}n+=i.nodeSize}}function GJ(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?JJ(t+1,i):JJ(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}};XJ.none=[];var ZJ=class extends Error{},QJ=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=eY(this.content,t+this.openStart,n);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e($J(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(KJ.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)}};QJ.empty=new QJ(KJ.empty,0,0);function $J(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($J(a.content,t-i-1,n-i-1)))}function eY(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=eY(o.content,t-a-1,n,o);return s&&e.replaceChild(i,o.copy(s))}function zDe(e,t,n){if(n.openStart>e.depth)throw new ZJ(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new ZJ(`Inconsistent open depths`);return tY(e,t,n,0)}function tY(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 aY(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&&(iY(e.nodeAfter,r),a++));for(let e=a;ei&&rY(e,t,i+1),o=r.depth>i&&rY(n,r,i+1),s=[];return aY(null,e,i,s),a&&o&&t.index(i)==n.index(i)?(nY(a,o),iY(oY(a,sY(e,t,n,r,i+1)),s)):(a&&iY(oY(a,cY(e,t,i+1)),s),aY(t,n,i,s),o&&iY(oY(o,cY(n,r,i+1)),s)),aY(r,null,i,s),new KJ(s)}function cY(e,t,n){let r=[];return aY(null,e,n,r),e.depth>n&&iY(oY(rY(e,t,n+1),cY(e,t,n+1)),r),aY(t,null,n,r),new KJ(r)}function BDe(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(KJ.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var lY=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 dY(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=uY.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()+`)`),pY(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=KJ.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=KJ.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}};fY.prototype.text=void 0;var WDe=class e extends fY{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):pY(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 pY(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var mY=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new GDe(t,n);if(r.next==null)return e.empty;let i=hY(r);r.next&&r.err(`Unexpected trailing text`);let a=QDe(ZDe(i));return $De(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(` +`)}};mY.empty=new mY(!0);var GDe=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 hY(e){let t=[];do t.push(KDe(e));while(e.eat(`|`));return t.length==1?t[0]:{type:`choice`,exprs:t}}function KDe(e){let t=[];do t.push(qDe(e));while(e.next&&e.next!=`)`&&e.next!=`|`);return t.length==1?t[0]:{type:`seq`,exprs:t}}function qDe(e){let t=XDe(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=JDe(e,t);else break;return t}function gY(e){/\D/.test(e.next)&&e.err(`Expected number, got '`+e.next+`'`);let t=Number(e.next);return e.pos++,t}function JDe(e,t){let n=gY(e),r=n;return e.eat(`,`)&&(r=e.next==`}`?-1:gY(e)),e.eat(`}`)||e.err(`Unclosed braced range`),{type:`range`,min:n,max:r,expr:t}}function YDe(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 XDe(e){if(e.eat(`(`)){let t=hY(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=YDe(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 ZDe(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 mY(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:bY(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error(`NodeType.create can't construct text nodes`);return new fY(this,this.computeAttrs(e),KJ.from(t),XJ.setFrom(n))}createChecked(e=null,t,n){return t=KJ.from(t),this.checkContent(t),new fY(this,this.computeAttrs(e),t,XJ.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=KJ.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(KJ.empty,!0);return i?new fY(this,e,t.append(i),XJ.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 eOe(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 tOe=class{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,`default`),this.default=n.default,this.validate=typeof n.validate==`string`?eOe(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}},wY=class e{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=SY(e,r.attrs),this.excluded=null;let i=yY(this.attrs);this.instance=i?new XJ(this,i):null}create(e=null){return!e&&this.instance?this.instance:new XJ(this,bY(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}},TY=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=UJ.from(e.nodes),t.marks=UJ.from(e.marks||{}),this.nodes=CY.compile(this.spec.nodes,this),this.marks=wY.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]=mY.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?EY(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==``?[]:EY(this,n.split(` `))}this.nodeFromJSON=e=>fY.fromJSON(this,e),this.markFromJSON=e=>XJ.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 CY))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 WDe(n,n.defaultAttrs,e,XJ.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 EY(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 nOe(e){return e.tag!=null}function rOe(e){return e.style!=null}var DY=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(nOe(e))this.tags.push(e);else if(rOe(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 FY(this,t,!1);return n.addAll(e,XJ.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new FY(this,t,!0);return n.addAll(e,XJ.none,t.from,t.to),QJ.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=IY(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=IY(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)))}},OY={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},iOe={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},kY={ol:!0,ul:!0},AY=1,jY=2,MY=4;function NY(e,t,n){return t==null?e&&e.whitespace==`pre`?3:n&-5:(t?AY:0)|(t===`full`?jY:0)}var PY=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=XJ.none,this.match=i||(a&MY?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(KJ.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&AY)){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=KJ.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(KJ.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&&!OY.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},FY=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=NY(null,t.preserveWhitespace,0)|(n?MY:0);i=r?new PY(r.type,r.attrs,XJ.none,!0,t.topMatch||r.type.contentMatch,a):n?new PY(null,null,XJ.none,!0,null,a):new PY(e.schema.topNodeType,null,XJ.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&jY?`full`:this.localPreserveWS||(r.options&AY)>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,` +`);else if(a.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(a.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),n.consuming===!1)e=n;else break}}return t}addElementByRule(e,t,n,r){let i,a;if(t.node)if(a=this.parser.schema.nodes[t.node],a.isLeaf)this.insertNode(a.create(t.attrs),n,e.nodeName==`BR`)||this.leafFallback(e,n);else{let e=this.enter(a,t.attrs||null,n,t.preserveWhitespace);e&&(i=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let o=this.top;if(a&&a.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;typeof t.contentElement==`string`?r=e.querySelector(t.contentElement):typeof t.contentElement==`function`?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}i&&this.sync(o)&&this.open--}addAll(e,t,n,r){let i=n||0;for(let a=n?e.childNodes[n]:e.firstChild,o=r==null?null:e.childNodes[r];a!=o;a=a.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(a,t);this.findAtPoint(e,i)}findPlace(e,t,n){let r,i;for(let t=this.open,a=0;t>=0;t--){let o=this.nodes[t],s=o.findWrapping(e);if(s&&(!r||r.length>s.length+a)&&(r=s,i=o,!s.length))break;if(o.solid){if(n)break;a+=2}}if(!r)return null;this.sync(i);for(let e=0;e(a.type?a.type.allowsMarkType(t.type):LY(t.type,e))?(s=t.addToSet(s),!1):!0),this.nodes.push(new PY(e,t,s,r,null,o)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;else this.localPreserveWS&&(this.nodes[t].options|=AY);return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split(`/`),n=this.options.context,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),i=-(n?n.depth+1:0)+ +!r,a=(e,o)=>{for(;e>=0;e--){let s=t[e];if(s==``){if(e==t.length-1||e==0)continue;for(;o>=i;o--)if(a(e-1,o))return!0;return!1}else{let e=o>0||o==0&&r?this.nodes[o].type:n&&o>=i?n.node(o-i).type:null;if(!e||e.name!=s&&!e.isInGroup(s))return!1;o--}}return!0};return a(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}};function aOe(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=t.nodeType==1?t.nodeName.toLowerCase():null;e&&kY.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):e==`li`?n=t:e&&(n=null)}}function oOe(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function IY(e){let t={};for(let n in e)t[n]=e[n];return t}function LY(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let a=[],o=e=>{a.push(e);for(let n=0;n{if(i.length||e.marks.length){let n=0,a=0;for(;n=0;r--){let i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&HY(BY(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return HY(e,t,n,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new e(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(e){let t=zY(e.nodes);return t.text||=e=>e.text,t}static marksFromSchema(e){return zY(e.marks)}};function zY(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function BY(e){return e.document||window.document}var VY=new WeakMap;function sOe(e){let t=VY.get(e);return t===void 0&&VY.set(e,t=cOe(e)),t}function cOe(e){let t=null;function n(e){if(e&&typeof e==`object`)if(Array.isArray(e))if(typeof e[0]==`string`)t||=[],t.push(e);else for(let t=0;t-1)throw RangeError(`Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.`);let o=i.indexOf(` `);o>0&&(n=i.slice(0,o),i=i.slice(o+1));let s,c=n?e.createElementNS(n,i):e.createElement(i),l=t[1],u=1;if(l&&typeof l==`object`&&l.nodeType==null&&!Array.isArray(l)){u=2;for(let e in l)if(l[e]!=null){let t=e.indexOf(` `);t>0?c.setAttributeNS(e.slice(0,t),e.slice(t+1),l[e]):e==`style`&&c.style?c.style.cssText=l[e]:c.setAttribute(e,l[e])}}for(let i=u;iu)throw RangeError(`Content hole must be the only child of its parent node`);return{dom:c,contentDOM:c}}else{let{dom:t,contentDOM:i}=HY(e,a,n,r);if(c.appendChild(t),i){if(s)throw RangeError(`Multiple content holes`);s=i}}}return{dom:c,contentDOM:s}}var UY=65535,WY=2**16;function lOe(e,t){return e+t*WY}function GY(e){return e&UY}function uOe(e){return(e-(e&UY))/WY}var dOe=1,fOe=2,KY=4,qY=8,JY=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&qY)>0}get deletedBefore(){return(this.delInfo&5)>0}get deletedAfter(){return(this.delInfo&6)>0}get deletedAcross(){return(this.delInfo&KY)>0}},YY=class e{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&e.empty)return e.empty}recover(e){let t=0,n=GY(e);if(!this.inverted)for(let e=0;ee)break;let c=this.ranges[o+i],l=this.ranges[o+a],u=s+c;if(e<=u){let i=c?e==s?-1:e==u?1:t:t,a=s+r+(i<0?0:l);if(n)return a;let d=e==(t<0?s:u)?null:lOe(o/3,e-s),f=e==s?fOe:e==u?dOe:KY;return(t<0?e!=s:e!=u)&&(f|=qY),new JY(a,f,d)}r+=l-c}return n?e+r:new JY(e+r,0,null)}touches(e,t){let n=0,r=GY(t),i=this.inverted?2:1,a=this.inverted?1:2;for(let t=0;te)break;let s=this.ranges[t+i];if(e<=o+s&&t==r*3)return!0;n+=this.ranges[t+a]-s}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?n-r-1:void 0)}}invert(){let t=new e;return t.appendMappingInverted(this),t}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;nn&&t!e.isAtom||!t.type.allowsMarkType(this.mark.type)?e:e.mark(this.mark.addToSet(e.marks)),r),t.openStart,t.openEnd);return $Y.fromReplace(e,this.from,this.to,i)}invert(){return new nX(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`addMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for AddMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};QY.jsonID(`addMark`,tX);var nX=class e extends QY{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new QJ(eX(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return $Y.fromReplace(e,this.from,this.to,n)}invert(){return new tX(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`removeMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for RemoveMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};QY.jsonID(`removeMark`,nX);var rX=class e extends QY{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return $Y.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return $Y.fromReplace(e,this.pos,this.pos+1,new QJ(KJ.from(n),0,+!t.isLeaf))}invert(t){let n=t.nodeAt(this.pos);if(n){let t=this.mark.addToSet(n.marks);if(t.length==n.marks.length){for(let r=0;rr.pos?null:new e(n.pos,r.pos,i,a,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:`replaceAround`,from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`||typeof n.gapFrom!=`number`||typeof n.gapTo!=`number`||typeof n.insert!=`number`)throw RangeError(`Invalid input for ReplaceAroundStep.fromJSON`);return new e(n.from,n.to,n.gapFrom,n.gapTo,QJ.fromJSON(t,n.slice),n.insert,!!n.structure)}};QY.jsonID(`replaceAround`,oX);function sX(e,t,n){let r=e.resolve(t),i=n-t,a=r.depth;for(;i>0&&a>0&&r.indexAfter(a)==r.node(a).childCount;)a--,i--;if(i>0){let e=r.node(a).maybeChild(r.indexAfter(a));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function pOe(e,t,n,r){let i=[],a=[],o,s;e.doc.nodesBetween(t,n,(e,c,l)=>{if(!e.isInline)return;let u=e.marks;if(!r.isInSet(u)&&l.type.allowsMarkType(r.type)){let l=Math.max(c,t),d=Math.min(c+e.nodeSize,n),f=r.addToSet(u);for(let e=0;ee.step(t)),a.forEach(t=>e.step(t))}function mOe(e,t,n,r){let i=[],a=0;e.doc.nodesBetween(t,n,(e,o)=>{if(!e.isInline)return;a++;let s=null;if(r instanceof wY){let t=e.marks,n;for(;n=r.isInSet(t);)(s||=[]).push(n),t=n.removeFromSet(t)}else r?r.isInSet(e.marks)&&(s=[r]):s=e.marks;if(s&&s.length){let r=Math.min(o+e.nodeSize,n);for(let e=0;ee.step(new nX(t.from,t.to,t.style)))}function cX(e,t,n,r=n.contentMatch,i=!0){let a=e.doc.nodeAt(t),o=[],s=t+1;for(let t=0;t=0;t--)e.step(o[t])}function hOe(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function lX(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth,r=0,i=0;;--n){let a=e.$from.node(n),o=e.$from.index(n)+r,s=e.$to.indexAfter(n)-i;if(nn;e--)t||r.index(e)>0?(t=!0,u=KJ.from(r.node(e).copy(u)),d++):c--;let f=KJ.empty,p=0;for(let e=a,t=!1;e>n;e--)t||i.after(e+1)=0;e--){if(r.size){let t=n[e].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw RangeError(`Wrapper type given to Transform.wrap does not form valid content of its parent wrapper`)}r=KJ.from(n[e].type.create(n[e].attrs,r))}let i=t.start,a=t.end;e.step(new oX(i,a,i,a,new QJ(r,0,0),n.length,!0))}function bOe(e,t,n,r,i){if(!r.isTextblock)throw RangeError(`Type given to setBlockType should be a textblock`);let a=e.steps.length;e.doc.nodesBetween(t,n,(t,n)=>{let o=typeof i==`function`?i(t):i;if(t.isTextblock&&!t.hasMarkup(r,o)&&xOe(e.doc,e.mapping.slice(a).map(n),r)){let i=null;if(r.schema.linebreakReplacement){let e=r.whitespace==`pre`,t=!!r.contentMatch.matchType(r.schema.linebreakReplacement);e&&!t?i=!1:!e&&t&&(i=!0)}i===!1&&pX(e,t,n,a),cX(e,e.mapping.slice(a).map(n,1),r,void 0,i===null);let s=e.mapping.slice(a),c=s.map(n,1),l=s.map(n+t.nodeSize,1);return e.step(new oX(c,l,c+1,l-1,new QJ(KJ.from(r.create(o,null,t.marks)),0,0),1,!0)),i===!0&&fX(e,t,n,a),!1}})}function fX(e,t,n,r){t.forEach((i,a)=>{if(i.isText){let o,s=/\r?\n|\r/g;for(;o=s.exec(i.text);){let i=e.mapping.slice(r).map(n+1+a+o.index);e.replaceWith(i,i+1,t.type.schema.linebreakReplacement.create())}}})}function pX(e,t,n,r){t.forEach((i,a)=>{if(i.type==i.type.schema.linebreakReplacement){let i=e.mapping.slice(r).map(n+1+a);e.replaceWith(i,i+1,t.type.schema.text(` +`))}})}function xOe(e,t,n){let r=e.resolve(t),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function SOe(e,t,n,r,i){let a=e.doc.nodeAt(t);if(!a)throw RangeError(`No node at given position`);n||=a.type;let o=n.create(r,null,i||a.marks);if(a.isLeaf)return e.replaceWith(t,t+a.nodeSize,o);if(!n.validContent(a.content))throw RangeError(`Invalid content for node type `+n.name);e.step(new oX(t,t+a.nodeSize,t+1,t+a.nodeSize-1,new QJ(KJ.from(o),0,0),1,!0))}function mX(e,t,n=1,r){let i=e.resolve(t),a=i.depth-n,o=r&&r[r.length-1]||i.parent;if(a<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let e=i.depth-1,t=n-2;e>a;e--,t--){let n=i.node(e),a=i.index(e);if(n.type.spec.isolating)return!1;let o=n.content.cutByIndex(a,n.childCount),s=r&&r[t+1];s&&(o=o.replaceChild(0,s.type.create(s.attrs)));let c=r&&r[t]||n;if(!n.canReplace(a+1,n.childCount)||!c.type.validContent(o))return!1}let s=i.indexAfter(a),c=r&&r[0];return i.node(a).canReplaceWith(s,s,c?c.type:i.node(a+1).type)}function COe(e,t,n=1,r){let i=e.doc.resolve(t),a=KJ.empty,o=KJ.empty;for(let e=i.depth,t=i.depth-n,s=n-1;e>t;e--,s--){a=KJ.from(i.node(e).copy(a));let t=r&&r[s];o=KJ.from(t?t.type.create(t.attrs,o):i.node(e).copy(o))}e.step(new aX(t,t,new QJ(a.append(o),n,n),!0))}function hX(e,t){let n=e.resolve(t),r=n.index();return gX(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function wOe(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:r}=e.type.schema;for(let i=0;i0?(i=r.node(e+1),o++,a=r.node(e).maybeChild(o)):(i=r.node(e).maybeChild(o-1),a=r.node(e+1)),i&&!i.isTextblock&&gX(i,a)&&r.node(e).canReplace(o,o+1))return t;if(e==0)break;t=n<0?r.before(e):r.after(e)}}function TOe(e,t,n){let r=null,{linebreakReplacement:i}=e.doc.type.schema,a=e.doc.resolve(t-n),o=a.node().type;if(i&&o.inlineContent){let e=o.whitespace==`pre`,t=!!o.contentMatch.matchType(i);e&&!t?r=!1:!e&&t&&(r=!0)}let s=e.steps.length;if(r===!1){let r=e.doc.resolve(t+n);pX(e,r.node(),r.before(),s)}o.inlineContent&&cX(e,t+n-1,o,a.node().contentMatchAt(a.index()),r==null);let c=e.mapping.slice(s),l=c.map(t-n);if(e.step(new aX(l,c.map(t+n,-1),QJ.empty,!0)),r===!0){let t=e.doc.resolve(l);fX(e,t.node(),t.before(),e.steps.length)}return e}function EOe(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(r.parentOffset==0)for(let e=r.depth-1;e>=0;e--){let t=r.index(e);if(r.node(e).canReplaceWith(t,t,n))return r.before(e+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let e=r.depth-1;e>=0;e--){let t=r.indexAfter(e);if(r.node(e).canReplaceWith(t,t,n))return r.after(e+1);if(t=0;t--){let n=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1,a=r.index(t)+ +(n>0),o=r.node(t),s=!1;if(e==1)s=o.canReplace(a,a,i);else{let e=o.contentMatchAt(a).findWrapping(i.firstChild.type);s=e&&o.canReplaceWith(a,a,e[0])}if(s)return n==0?r.pos:n<0?r.before(t+1):r.after(t+1)}return null}function yX(e,t,n=t,r=QJ.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),a=e.resolve(n);return bX(i,a,r)?new aX(t,n,r):new DOe(i,a,r).fit()}function bX(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}var DOe=class{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=KJ.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=KJ.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let i=this.placed,a=n.depth,o=r.depth;for(;a&&o&&i.childCount==1;)i=i.firstChild.content,a--,o--;let s=new QJ(i,a,o);return e>-1?new oX(n.pos,e,this.$to.pos,this.$to.end(),s,t):s.size||n.pos!=this.$to.pos?new aX(n.pos,r.pos,s):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n1&&(r=0),i.type.spec.isolating&&r<=n){e=n;break}t=i.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let e,r=null;n?(r=CX(this.unplaced.content,n-1).firstChild,e=r.content):e=this.unplaced.content;let i=e.firstChild;for(let e=this.depth;e>=0;e--){let{type:a,match:o}=this.frontier[e],s,c=null;if(t==1&&(i?o.matchType(i.type)||(c=o.fillBefore(KJ.from(i),!1)):r&&a.compatibleContent(r.type)))return{sliceDepth:n,frontierDepth:e,parent:r,inject:c};if(t==2&&i&&(s=o.findWrapping(i.type)))return{sliceDepth:n,frontierDepth:e,parent:r,wrap:s};if(r&&o.matchType(r.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=CX(e,t);return!r.childCount||r.firstChild.isLeaf?!1:(this.unplaced=new QJ(e,t+1,Math.max(n,r.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=CX(e,t);if(r.childCount<=1&&t>0){let i=e.size-t<=t+r.size;this.unplaced=new QJ(xX(e,t-1,1),t-1,i?t-1:n)}else this.unplaced=new QJ(xX(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:i}){for(;this.depth>t;)this.closeFrontierNode();if(i)for(let e=0;e1||s==0||e.content.size)&&(u=t,l.push(wX(e.mark(d.allowedMarks(e.marks)),c==1?s:0,c==o.childCount?f:-1)))}let p=c==o.childCount;p||(f=-1),this.placed=SX(this.placed,t,KJ.from(l)),this.frontier[t].match=u,p&&f<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=o;e1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){scan:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],i=t=0;n--){let{match:t,type:r}=this.frontier[n],i=TX(e,n,r,t,!0);if(!i||i.childCount)continue scan}return{depth:t,fit:a,move:i?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=SX(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=SX(this.placed,this.depth,KJ.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(KJ.empty,!0);e.childCount&&(this.placed=SX(this.placed,this.frontier.length,e))}};function xX(e,t,n){return t==0?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(xX(e.firstChild.content,t-1,n)))}function SX(e,t,n){return t==0?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(SX(e.lastChild.content,t-1,n)))}function CX(e,t){for(let n=0;n1&&(r=r.replaceChild(0,wX(r.firstChild,t-1,r.childCount==1?n-1:0))),t>0&&(r=e.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(e.type.contentMatch.matchFragment(r).fillBefore(KJ.empty,!0)))),e.copy(r)}function TX(e,t,n,r,i){let a=e.node(t),o=i?e.indexAfter(t):e.index(t);if(o==a.childCount&&!n.compatibleContent(a.type))return null;let s=r.fillBefore(a.content,!0,o);return s&&!OOe(n,a.content,o)?s:null}function OOe(e,t,n){for(let r=n;r0;e--,t--){let n=i.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;o.indexOf(e)>-1?s=e:i.before(e)==t&&o.splice(1,0,-e)}let c=o.indexOf(s),l=[],u=r.openStart;for(let e=r.content,t=0;;t++){let n=e.firstChild;if(l.push(n),t==r.openStart)break;e=n.content}for(let e=u-1;e>=0;e--){let t=l[e],n=kOe(t.type);if(n&&!t.sameMarkup(i.node(Math.abs(s)-1)))u=e;else if(n||!t.type.isTextblock)break}for(let t=r.openStart;t>=0;t--){let s=(t+u+1)%(r.openStart+1),d=l[s];if(d)for(let t=0;t=0&&(e.replace(t,n,r),!(e.steps.length>d));s--){let e=o[s];e<0||(t=i.before(e),n=a.after(e))}}function EX(e,t,n,r,i){if(tr){let t=i.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(KJ.empty,!0))}return e}function jOe(e,t,n,r){if(!r.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let i=EOe(e.doc,t,r.type);i!=null&&(t=n=i)}e.replaceRange(t,n,new QJ(KJ.from(r),0,0))}function MOe(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n),a=DX(r,i);for(let t=0;t0&&(o||r.node(n-1).canReplace(r.index(n-1),i.indexAfter(n-1))))return e.delete(r.before(n),i.after(n))}for(let a=1;a<=r.depth&&a<=i.depth;a++)if(t-r.start(a)==r.depth-a&&n>r.end(a)&&i.end(a)-n!=i.depth-a&&r.start(a-1)==i.start(a-1)&&r.node(a-1).canReplace(r.index(a-1),i.index(a-1)))return e.delete(r.before(a),n);e.delete(t,n)}function DX(e,t){let n=[],r=Math.min(e.depth,t.depth);for(let i=r;i>=0;i--){let r=e.start(i);if(rt.pos+(t.depth-i)||e.node(i).type.spec.isolating||t.node(i).type.spec.isolating)break;(r==t.start(i)||i==e.depth&&i==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&i&&t.start(i-1)==r-1)&&n.push(i)}return n}var OX=class e extends QY{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return $Y.fail(`No node at attribute step's position`);let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return $Y.fromReplace(e,this.pos,this.pos+1,new QJ(KJ.from(r),0,+!t.isLeaf))}getMap(){return YY.empty}invert(t){return new e(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.attr,this.value)}toJSON(){return{stepType:`attr`,pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!=`number`||typeof n.attr!=`string`)throw RangeError(`Invalid input for AttrStep.fromJSON`);return new e(n.pos,n.attr,n.value)}};QY.jsonID(`attr`,OX);var kX=class e extends QY{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return $Y.ok(n)}getMap(){return YY.empty}invert(t){return new e(this.attr,t.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:`docAttr`,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.attr!=`string`)throw RangeError(`Invalid input for DocAttrStep.fromJSON`);return new e(n.attr,n.value)}};QY.jsonID(`docAttr`,kX);var AX=class extends Error{};AX=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},AX.prototype=Object.create(Error.prototype),AX.prototype.constructor=AX,AX.prototype.name=`TransformError`;var jX=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new XY}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new AX(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let n=0;n{e=Math.min(e,i),t=Math.max(t,a)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=QJ.empty){let r=yX(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new QJ(KJ.from(n),0,0))}delete(e,t){return this.replace(e,t,QJ.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return AOe(this,e,t,n),this}replaceRangeWith(e,t,n){return jOe(this,e,t,n),this}deleteRange(e,t){return MOe(this,e,t),this}lift(e,t){return gOe(this,e,t),this}join(e,t=1){return TOe(this,e,t),this}wrap(e,t){return yOe(this,e,t),this}setBlockType(e,t=e,n,r=null){return bOe(this,e,t,n,r),this}setNodeMarkup(e,t,n=null,r){return SOe(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new OX(e,t,n)),this}setDocAttribute(e,t){return this.step(new kX(e,t)),this}addNodeMark(e,t){return this.step(new rX(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw RangeError(`No node at position `+e);if(t instanceof XJ)t.isInSet(n.marks)&&this.step(new iX(e,t));else{let r=n.marks,i,a=[];for(;i=t.isInSet(r);)a.push(new iX(e,i)),r=i.removeFromSet(r);for(let e=a.length-1;e>=0;e--)this.step(a[e])}return this}split(e,t=1,n){return COe(this,e,t,n),this}addMark(e,t,n){return pOe(this,e,t,n),this}removeMark(e,t,n){return mOe(this,e,t,n),this}clearIncompatible(e,t,n){return cX(this,e,t,n),this}},MX=Object.create(null),NX=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new NOe(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;r--){let i=t<0?BX(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):BX(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new zX(e.node(0))}static atStart(e){return BX(e,e,0,0,1)||new zX(e)}static atEnd(e){return BX(e,e,e.content.size,e.childCount,-1)||new zX(e)}static fromJSON(e,t){if(!t||!t.type)throw RangeError(`Invalid input for Selection.fromJSON`);let n=MX[t.type];if(!n)throw RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in MX)throw RangeError(`Duplicate use of selection JSON ID `+e);return MX[e]=t,t.prototype.jsonID=e,t}getBookmark(){return IX.between(this.$anchor,this.$head).getBookmark()}};NX.prototype.visible=!0;var NOe=class{constructor(e,t){this.$from=e,this.$to=t}},PX=!1;function FX(e){!PX&&!e.parent.inlineContent&&(PX=!0,console.warn(`TextSelection endpoint not pointing into a node with inline content (`+e.parent.type.name+`)`))}var IX=class e extends NX{constructor(e,t=e){FX(e),FX(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return NX.near(r);let i=t.resolve(n.map(this.anchor));return new e(i.parent.inlineContent?i:r,r)}replace(e,t=QJ.empty){if(super.replace(e,t),t==QJ.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(t){return t instanceof e&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new LX(this.anchor,this.head)}toJSON(){return{type:`text`,anchor:this.anchor,head:this.head}}static fromJSON(t,n){if(typeof n.anchor!=`number`||typeof n.head!=`number`)throw RangeError(`Invalid input for TextSelection.fromJSON`);return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(t,n,r){let i=t.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let e=NX.findFrom(n,r,!0)||NX.findFrom(n,-r,!0);if(e)n=e.$head;else return NX.near(n,r)}return t.parent.inlineContent||(i==0?t=n:(t=(NX.findFrom(t,-r,!0)||NX.findFrom(t,r,!0)).$anchor,t.pos0?0:1);i>0?o=0;o+=i){let r=t.child(o);if(!r.isAtom){let t=BX(e,r,n+i,i<0?r.childCount:0,i,a);if(t)return t}else if(!a&&RX.isSelectable(r))return RX.create(e,n-(i<0?r.nodeSize:0));n+=r.nodeSize*i}return null}function VX(e,t,n){let r=e.steps.length-1;if(r{o??=r}),e.setSelection(NX.near(e.doc.resolve(o),n))}var HX=1,UX=2,WX=4,IOe=class extends jX{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=UX,this}ensureMarks(e){return XJ.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&UX)>0}addStep(e,t){super.addStep(e,t),this.updated&=-3,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||XJ.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(n??=t,!e)return this.deleteRange(t,n);let i=this.storedMarks;if(!i){let e=this.doc.resolve(t);i=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,i)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(NX.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e==`string`?e:e.key]=t,this}getMeta(e){return this.meta[typeof e==`string`?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=WX,this}get scrolledIntoView(){return(this.updated&WX)>0}};function GX(e,t){return!t||!e?e:e.bind(t)}var KX=class{constructor(e,t,n){this.name=e,this.init=GX(t.init,n),this.apply=GX(t.apply,n)}},LOe=[new KX(`doc`,{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new KX(`selection`,{init(e,t){return e.selection||NX.atStart(t.doc)},apply(e){return e.selection}}),new KX(`storedMarks`,{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new KX(`scrollToSelection`,{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}})],qX=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=LOe.slice(),t&&t.forEach(e=>{if(this.pluginsByKey[e.key])throw RangeError(`Adding different instances of a keyed plugin (`+e.key+`)`);this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new KX(e.key,e.spec.state,e))})}},ROe=class e{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;ne.toJSON())),e&&typeof e==`object`)for(let n in e){if(n==`doc`||n==`selection`)throw RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],i=r.spec.state;i&&i.toJSON&&(t[n]=i.toJSON.call(r,this[r.key]))}return t}static fromJSON(t,n,r){if(!n)throw RangeError(`Invalid input for EditorState.fromJSON`);if(!t.schema)throw RangeError(`Required config field 'schema' missing`);let i=new qX(t.schema,t.plugins),a=new e(i);return i.fields.forEach(e=>{if(e.name==`doc`)a.doc=fY.fromJSON(t.schema,n.doc);else if(e.name==`selection`)a.selection=NX.fromJSON(a.doc,n.selection);else if(e.name==`storedMarks`)n.storedMarks&&(a.storedMarks=n.storedMarks.map(t.schema.markFromJSON));else{if(r)for(let i in r){let o=r[i],s=o.spec.state;if(o.key==e.name&&s&&s.fromJSON&&Object.prototype.hasOwnProperty.call(n,i)){a[e.name]=s.fromJSON.call(o,t,n[i],a);return}}a[e.name]=e.init(t,a)}}),a}};function JX(e,t,n){for(let r in e){let i=e[r];i instanceof Function?i=i.bind(t):r==`handleDOMEvents`&&(i=JX(i,t,{})),n[r]=i}return n}var YX=class{constructor(e){this.spec=e,this.props={},e.props&&JX(e.props,this,this.props),this.key=e.key?e.key.key:ZX(`plugin`)}getState(e){return e[this.key]}},XX=Object.create(null);function ZX(e){return e in XX?e+`$`+ ++XX[e]:(XX[e]=0,e+`$`)}var QX=class{constructor(e=`key`){this.key=ZX(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}},$X=(e,t)=>e.selection.empty?!1:(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function eZ(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`backward`,e):n.parentOffset>0)?null:n}var tZ=(e,t,n)=>{let r=eZ(e,n);if(!r)return!1;let i=aZ(r);if(!i){let n=r.blockRange(),i=n&&lX(n);return i==null?!1:(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let a=i.nodeBefore;if(hZ(e,i,t,-1))return!0;if(r.parent.content.size==0&&(rZ(a,`end`)||RX.isSelectable(a)))for(let n=r.depth;;n--){let o=yX(e.doc,r.before(n),r.after(n),QJ.empty);if(o&&o.slice.size1)break}return a.isAtom&&i.depth==r.depth-1?(t&&t(e.tr.delete(i.pos-a.nodeSize,i.pos).scrollIntoView()),!0):!1},zOe=(e,t,n)=>{let r=eZ(e,n);if(!r)return!1;let i=aZ(r);return i?nZ(e,i,t):!1},BOe=(e,t,n)=>{let r=oZ(e,n);if(!r)return!1;let i=lZ(r);return i?nZ(e,i,t):!1};function nZ(e,t,n){let r=t.nodeBefore,i=t.pos-1;for(;!r.isTextblock;i--){if(r.type.spec.isolating)return!1;let e=r.lastChild;if(!e)return!1;r=e}let a=t.nodeAfter,o=t.pos+1;for(;!a.isTextblock;o++){if(a.type.spec.isolating)return!1;let e=a.firstChild;if(!e)return!1;a=e}let s=yX(e.doc,i,o,QJ.empty);if(!s||s.from!=i||s instanceof aX&&s.slice.size>=o-i)return!1;if(n){let t=e.tr.step(s);t.setSelection(IX.create(t.doc,i)),n(t.scrollIntoView())}return!0}function rZ(e,t,n=!1){for(let r=e;r;r=t==`start`?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}var iZ=(e,t,n)=>{let{$head:r,empty:i}=e.selection,a=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`backward`,e):r.parentOffset>0)return!1;a=aZ(r)}let o=a&&a.nodeBefore;return!o||!RX.isSelectable(o)?!1:(t&&t(e.tr.setSelection(RX.create(e.doc,a.pos-o.nodeSize)).scrollIntoView()),!0)};function aZ(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function oZ(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`forward`,e):n.parentOffset{let r=oZ(e,n);if(!r)return!1;let i=lZ(r);if(!i)return!1;let a=i.nodeAfter;if(hZ(e,i,t,1))return!0;if(r.parent.content.size==0&&(rZ(a,`start`)||RX.isSelectable(a))){let n=yX(e.doc,r.before(),r.after(),QJ.empty);if(n&&n.slice.size{let{$head:r,empty:i}=e.selection,a=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`forward`,e):r.parentOffset=0;t--){let n=e.node(t);if(e.index(t)+1{let n=e.selection,r=n instanceof RX,i;if(r){if(n.node.isTextblock||!hX(e.doc,n.from))return!1;i=n.from}else if(i=_X(e.doc,n.from,-1),i==null)return!1;if(t){let n=e.tr.join(i);r&&n.setSelection(RX.create(n.doc,i-e.doc.resolve(i).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0},HOe=(e,t)=>{let n=e.selection,r;if(n instanceof RX){if(n.node.isTextblock||!hX(e.doc,n.to))return!1;r=n.to}else if(r=_X(e.doc,n.to,1),r==null)return!1;return t&&t(e.tr.join(r).scrollIntoView()),!0},UOe=(e,t)=>{let{$from:n,$to:r}=e.selection,i=n.blockRange(r),a=i&&lX(i);return a==null?!1:(t&&t(e.tr.lift(i,a).scrollIntoView()),!0)},uZ=(e,t)=>{let{$head:n,$anchor:r}=e.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(t&&t(e.tr.insertText(` +`).scrollIntoView()),!0)};function dZ(e){for(let t=0;t{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),a=n.indexAfter(-1),o=dZ(i.contentMatchAt(a));if(!o||!i.canReplaceWith(a,a,o))return!1;if(t){let r=n.after(),i=e.tr.replaceWith(r,r,o.createAndFill());i.setSelection(NX.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0},pZ=(e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof zX||r.parent.inlineContent||i.parent.inlineContent)return!1;let a=dZ(i.parent.contentMatchAt(i.indexAfter()));if(!a||!a.isTextblock)return!1;if(t){let n=(!r.parentOffset&&i.index(){let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(mX(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),i=r&&lX(r);return i==null?!1:(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)};function WOe(e){return(t,n)=>{let{$from:r,$to:i}=t.selection;if(t.selection instanceof RX&&t.selection.node.isBlock)return!r.parentOffset||!mX(t.doc,r.pos)?!1:(n&&n(t.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let a=[],o,s,c=!1,l=!1;for(let t=r.depth;;t--)if(r.node(t).isBlock){c=r.end(t)==r.pos+(r.depth-t),l=r.start(t)==r.pos-(r.depth-t),s=dZ(r.node(t-1).contentMatchAt(r.indexAfter(t-1)));let n=e&&e(i.parent,c,r);a.unshift(n||(c&&s?{type:s}:null)),o=t;break}else{if(t==1)return!1;a.unshift(null)}let u=t.tr;(t.selection instanceof IX||t.selection instanceof zX)&&u.deleteSelection();let d=u.mapping.map(r.pos),f=mX(u.doc,d,a.length,a);if(f||=(a[0]=s?{type:s}:null,mX(u.doc,d,a.length,a)),!f)return!1;if(u.split(d,a.length,a),!c&&l&&r.node(o).type!=s){let e=u.mapping.map(r.before(o)),t=u.doc.resolve(e);s&&r.node(o-1).canReplaceWith(t.index(),t.index()+1,s)&&u.setNodeMarkup(u.mapping.map(r.before(o)),s)}return n&&n(u.scrollIntoView()),!0}}var GOe=WOe(),KOe=(e,t)=>{let{$from:n,to:r}=e.selection,i,a=n.sharedDepth(r);return a==0?!1:(i=n.before(a),t&&t(e.tr.setSelection(RX.create(e.doc,i))),!0)},qOe=(e,t)=>(t&&t(e.tr.setSelection(new zX(e.doc))),!0);function JOe(e,t,n){let r=t.nodeBefore,i=t.nodeAfter,a=t.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&t.parent.canReplace(a-1,a)?(n&&n(e.tr.delete(t.pos-r.nodeSize,t.pos).scrollIntoView()),!0):!t.parent.canReplace(a,a+1)||!(i.isTextblock||hX(e.doc,t.pos))?!1:(n&&n(e.tr.join(t.pos).scrollIntoView()),!0)}function hZ(e,t,n,r){let i=t.nodeBefore,a=t.nodeAfter,o,s,c=i.type.spec.isolating||a.type.spec.isolating;if(!c&&JOe(e,t,n))return!0;let l=!c&&t.parent.canReplace(t.index(),t.index()+1);if(l&&(o=(s=i.contentMatchAt(i.childCount)).findWrapping(a.type))&&s.matchType(o[0]||a.type).validEnd){if(n){let r=t.pos+a.nodeSize,s=KJ.empty;for(let e=o.length-1;e>=0;e--)s=KJ.from(o[e].create(null,s));s=KJ.from(i.copy(s));let c=e.tr.step(new oX(t.pos-1,r,t.pos,r,new QJ(s,1,0),o.length,!0)),l=c.doc.resolve(r+2*o.length);l.nodeAfter&&l.nodeAfter.type==i.type&&hX(c.doc,l.pos)&&c.join(l.pos),n(c.scrollIntoView())}return!0}let u=a.type.spec.isolating||r>0&&c?null:NX.findFrom(t,1),d=u&&u.$from.blockRange(u.$to),f=d&&lX(d);if(f!=null&&f>=t.depth)return n&&n(e.tr.lift(d,f).scrollIntoView()),!0;if(l&&rZ(a,`start`,!0)&&rZ(i,`end`)){let r=i,o=[];for(;o.push(r),!r.isTextblock;)r=r.lastChild;let s=a,c=1;for(;!s.isTextblock;s=s.firstChild)c++;if(r.canReplace(r.childCount,r.childCount,s.content)){if(n){let r=KJ.empty;for(let e=o.length-1;e>=0;e--)r=KJ.from(o[e].copy(r));n(e.tr.step(new oX(t.pos-o.length,t.pos+a.nodeSize,t.pos+c,t.pos+a.nodeSize-c,new QJ(r,o.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function gZ(e){return function(t,n){let r=t.selection,i=e<0?r.$from:r.$to,a=i.depth;for(;i.node(a).isInline;){if(!a)return!1;a--}return i.node(a).isTextblock?(n&&n(t.tr.setSelection(IX.create(t.doc,e<0?i.start(a):i.end(a)))),!0):!1}}var _Z=gZ(-1),vZ=gZ(1);function YOe(e,t=null){return function(n,r){let{$from:i,$to:a}=n.selection,o=i.blockRange(a),s=o&&uX(o,e,t);return s?(r&&r(n.tr.wrap(o,s).scrollIntoView()),!0):!1}}function yZ(e,t=null){return function(n,r){let i=!1;for(let r=0;r{if(i)return!1;if(!(!r.isTextblock||r.hasMarkup(e,t)))if(r.type==e)i=!0;else{let t=n.doc.resolve(a),r=t.index();i=t.parent.canReplaceWith(r,r+1,e)}})}if(!i)return!1;if(r){let i=n.tr;for(let r=0;r=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&t.startIndex==0){if(t.$from.index(t.depth-1)==0)return!1;let e=o.resolve(t.start-2);a=new dY(e,e,t.depth),t.endIndex=0;e--)a=KJ.from(n[e].type.create(n[e].attrs,a));e.step(new oX(t.start-(r?2:0),t.end,t.start,t.end,new QJ(a,0,0),n.length,!0));let o=0;for(let e=0;et.childCount>0&&t.firstChild.type==e);return a?n?r.node(a.depth-1).type==e?tke(t,n,e,a):nke(t,n,a):!0:!1}}function tke(e,t,n,r){let i=e.tr,a=r.end,o=r.$to.end(r.depth);aa;t--)e-=i.child(t).nodeSize,r.delete(e-1,e+1);let a=r.doc.resolve(n.start),o=a.nodeAfter;if(r.mapping.map(n.end)!=n.start+a.nodeAfter.nodeSize)return!1;let s=n.startIndex==0,c=n.endIndex==i.childCount,l=a.node(-1),u=a.index(-1);if(!l.canReplace(u+ +!s,u+1,o.content.append(c?KJ.empty:KJ.from(i))))return!1;let d=a.pos,f=d+o.nodeSize;return r.step(new oX(d-+!!s,f+ +!!c,d+1,f-1,new QJ((s?KJ.empty:KJ.from(i.copy(KJ.empty))).append(c?KJ.empty:KJ.from(i.copy(KJ.empty))),+!s,+!c),+!s)),t(r.scrollIntoView()),!0}function rke(e){return function(t,n){let{$from:r,$to:i}=t.selection,a=r.blockRange(i,t=>t.childCount>0&&t.firstChild.type==e);if(!a)return!1;let o=a.startIndex;if(o==0)return!1;let s=a.parent,c=s.child(o-1);if(c.type!=e)return!1;if(n){let r=c.lastChild&&c.lastChild.type==s.type,i=KJ.from(r?e.create():null),o=new QJ(KJ.from(e.create(null,KJ.from(s.type.create(null,i)))),r?3:1,0),l=a.start,u=a.end;n(t.tr.step(new oX(l-(r?3:1),u,l,u,o,1,!0)).scrollIntoView())}return!0}}var wZ=function(e){for(var t=0;;t++)if(e=e.previousSibling,!e)return t},TZ=function(e){let t=e.assignedSlot||e.parentNode;return t&&t.nodeType==11?t.host:t},EZ=null,DZ=function(e,t,n){let r=EZ||=document.createRange();return r.setEnd(e,n??e.nodeValue.length),r.setStart(e,t||0),r},ike=function(){EZ=null},OZ=function(e,t,n,r){return n&&(kZ(e,t,n,r,-1)||kZ(e,t,n,r,1))},ake=/^(img|br|input|textarea|hr)$/i;function kZ(e,t,n,r,i){for(;;){if(e==n&&t==r)return!0;if(t==(i<0?0:AZ(e))){let n=e.parentNode;if(!n||n.nodeType!=1||jZ(e)||ake.test(e.nodeName)||e.contentEditable==`false`)return!1;t=wZ(e)+(i<0?0:1),e=n}else if(e.nodeType==1){let n=e.childNodes[t+(i<0?-1:0)];if(n.nodeType==1&&n.contentEditable==`false`)if(n.pmViewDesc?.ignoreForSelection)t+=i;else return!1;else e=n,t=i<0?AZ(e):0}else return!1}}function AZ(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function oke(e,t){for(;;){if(e.nodeType==3&&t)return e;if(e.nodeType==1&&t>0){if(e.contentEditable==`false`)return null;e=e.childNodes[t-1],t=AZ(e)}else if(e.parentNode&&!jZ(e))t=wZ(e),e=e.parentNode;else return null}}function ske(e,t){for(;;){if(e.nodeType==3&&t2),JZ=qZ||(PZ?/Mac/.test(PZ.platform):!1),YZ=PZ?/Win/.test(PZ.platform):!1,XZ=/Android \d/.test(IZ),ZZ=!!FZ&&`webkitFontSmoothing`in FZ.documentElement.style,dke=ZZ?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function fke(e){let t=e.defaultView&&e.defaultView.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function QZ(e,t){return typeof e==`number`?e:e[t]}function pke(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}function $Z(e,t,n){let r=e.someProp(`scrollThreshold`)||0,i=e.someProp(`scrollMargin`)||5,a=e.dom.ownerDocument;for(let o=n||e.dom;o;){if(o.nodeType!=1){o=TZ(o);continue}let e=o,n=e==a.body,s=n?fke(a):pke(e),c=0,l=0;if(t.tops.bottom-QZ(r,`bottom`)&&(l=t.bottom-t.top>s.bottom-s.top?t.top+QZ(i,`top`)-s.top:t.bottom-s.bottom+QZ(i,`bottom`)),t.lefts.right-QZ(r,`right`)&&(c=t.right-s.right+QZ(i,`right`)),c||l)if(n)a.defaultView.scrollBy(c,l);else{let n=e.scrollLeft,r=e.scrollTop;l&&(e.scrollTop+=l),c&&(e.scrollLeft+=c);let i=e.scrollLeft-n,a=e.scrollTop-r;t={left:t.left-i,top:t.top-a,right:t.right-i,bottom:t.bottom-a}}let u=n?`fixed`:getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(u))break;o=u==`absolute`?o.offsetParent:TZ(o)}}function mke(e){let t=e.dom.getBoundingClientRect(),n=Math.max(0,t.top),r,i;for(let a=(t.left+t.right)/2,o=n+1;o=n-20){r=t,i=s.top;break}}return{refDOM:r,refTop:i,stack:eQ(e.dom)}}function eQ(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=TZ(r));return t}function hke({refDOM:e,refTop:t,stack:n}){let r=e?e.getBoundingClientRect().top:0;tQ(n,r==0?0:r-t)}function tQ(e,t){for(let n=0;n=s){o=Math.max(p.bottom,o),s=Math.min(p.top,s);let e=p.left>t.left?p.left-t.left:p.right=(p.left+p.right)/2));continue}}else p.top>t.top&&!c&&p.left<=t.left&&p.right>=t.left&&(c=u,l={left:Math.max(p.left,Math.min(p.right,t.left)),top:p.top});!n&&(t.left>=p.right&&t.top>=p.top||t.left>=p.left&&t.top>=p.bottom)&&(a=d+1)}}return!n&&c&&(n=c,i=l,r=0),n&&n.nodeType==3?_ke(n,i):!n||r&&n.nodeType==1?{node:e,offset:a}:rQ(n,i)}function _ke(e,t){let n=e.nodeValue.length,r=document.createRange(),i;for(let a=0;a=(n.left+n.right)/2)};break}}return r.detach(),i||{node:e,offset:0}}function iQ(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function vke(e,t){let n=e.parentNode;return n&&/^li$/i.test(n.nodeName)&&t.left(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(r,i,a)}function bke(e,t,n,r){let i=-1;for(let n=t,a=!1;n!=e.dom;){let t=e.docView.nearestDesc(n,!0),o;if(!t)return null;if(t.dom.nodeType==1&&(t.node.isBlock&&t.parent||!t.contentDOM)&&((o=t.dom.getBoundingClientRect()).width||o.height)&&(t.node.isBlock&&t.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(t.dom.nodeName)&&(!a&&o.left>r.left||o.top>r.top?i=t.posBefore:(!a&&o.right-1?i:e.docView.posFromDOM(t,n,-1)}function aQ(e,t,n){let r=e.childNodes.length;if(r&&n.topt.top&&i++}let n;ZZ&&i&&r.nodeType==1&&(n=r.childNodes[i-1]).nodeType==1&&n.contentEditable==`false`&&n.getBoundingClientRect().top>=t.top&&i--,r==e.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&t.top>r.lastChild.getBoundingClientRect().bottom?s=e.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!=`BR`)&&(s=bke(e,r,i,t))}s??=yke(e,o,t);let c=e.docView.nearestDesc(o,!0);return{pos:s,inside:c?c.posAtStart-c.border:-1}}function oQ(e){return e.top=0&&i==r.nodeValue.length?(e--,a=1):n<0?e--:t++,lQ(sQ(DZ(r,e,t),a),a<0)}if(!e.state.doc.resolve(t-(a||0)).parent.inlineContent){if(a==null&&i&&(n<0||i==AZ(r))){let e=r.childNodes[i-1];if(e.nodeType==1)return uQ(e.getBoundingClientRect(),!1)}if(a==null&&i=0)}if(a==null&&i&&(n<0||i==AZ(r))){let e=r.childNodes[i-1],t=e.nodeType==3?DZ(e,AZ(e)-+!o):e.nodeType==1&&(e.nodeName!=`BR`||!e.nextSibling)?e:null;if(t)return lQ(sQ(t,1),!1)}if(a==null&&i=0)}function lQ(e,t){if(e.width==0)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function uQ(e,t){if(e.height==0)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function dQ(e,t,n){let r=e.state,i=e.root.activeElement;r!=t&&e.updateState(t),i!=e.dom&&e.focus();try{return n()}finally{r!=t&&e.updateState(r),i!=e.dom&&i&&i.focus()}}function Cke(e,t,n){let r=t.selection,i=n==`up`?r.$from:r.$to;return dQ(e,t,()=>{let{node:t}=e.docView.domFromPos(i.pos,n==`up`?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.contentDOM||n.dom;break}t=n.dom.parentNode}let r=cQ(e,i.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(e.nodeType==1)t=e.getClientRects();else if(e.nodeType==3)t=DZ(e,0,e.nodeValue.length).getClientRects();else continue;for(let e=0;ei.top+1&&(n==`up`?r.top-i.top>(i.bottom-r.top)*2:i.bottom-r.bottom>(r.bottom-i.top)*2))return!1}}return!0})}var wke=/[\u0590-\u08ac]/;function Tke(e,t,n){let{$head:r}=t.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,a=!i,o=i==r.parent.content.size,s=e.domSelection();return s?!wke.test(r.parent.textContent)||!s.modify?n==`left`||n==`backward`?a:o:dQ(e,t,()=>{let{focusNode:t,focusOffset:i,anchorNode:a,anchorOffset:o}=e.domSelectionRange(),c=s.caretBidiLevel;s.modify(`move`,n,`character`);let l=r.depth?e.docView.domAfterPos(r.before()):e.dom,{focusNode:u,focusOffset:d}=e.domSelectionRange(),f=u&&!l.contains(u.nodeType==1?u:u.parentNode)||t==u&&i==d;try{s.collapse(a,o),t&&(t!=a||i!=o)&&s.extend&&s.extend(t,i)}catch{}return c!=null&&(s.caretBidiLevel=c),f}):r.pos==r.start()||r.pos==r.end()}var fQ=null,pQ=null,mQ=!1;function Eke(e,t,n){return fQ==t&&pQ==n?mQ:(fQ=t,pQ=n,mQ=n==`up`||n==`down`?Cke(e,t,n):Tke(e,t,n))}var hQ=0,gQ=1,_Q=2,vQ=3,yQ=class{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=hQ,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;twZ(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!1;break}if(t.previousSibling)break}if(r==null&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!0;break}if(t.nextSibling)break}}return r??n>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let i=this.getDesc(r),a;if(i&&(!t||i.node))if(n&&(a=i.nodeDOM)&&!(a.nodeType==1?a.contains(e.nodeType==1?e:e.parentNode):a==e))n=!1;else return i}}getDesc(e){let t=e.pmViewDesc;for(let e=t;e;e=e.parent)if(e==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let i=this.getDesc(r);if(i)return i.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;te||i instanceof TQ){r=e-t;break}t=a}if(r)return this.children[n].domFromPos(r-this.children[n].border,t);for(let e;n&&!(e=this.children[n-1]).size&&e instanceof bQ&&e.side>=0;n--);if(t<=0){let e,r=!0;for(;e=n?this.children[n-1]:null,!(!e||e.dom.parentNode==this.contentDOM);n--,r=!1);return e&&t&&r&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?wZ(e.dom)+1:0}}else{let e,r=!0;for(;e=n=i&&t<=s-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,i);e=a;for(let t=o;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=wZ(n.dom)+1;break}e-=n.size}r==-1&&(r=0)}if(r>-1&&(s>t||o==this.children.length-1)){t=s;for(let e=o+1;es&&at){let e=o;o=s,s=e}let n=document.createRange();n.setEnd(s.node,s.offset),n.setStart(o.node,o.offset),c.removeAllRanges(),c.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&e.type!=`selection`}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,r=0;r=n:en){let r=n+i.border,o=a-i.border;if(e>=r&&t<=o){this.dirty=e==n||t==a?_Q:gQ,e==r&&t==o&&(i.contentLost||i.dom.parentNode!=this.contentDOM)?i.dirty=vQ:i.markDirty(e-r,t-r);return}else i.dirty=i.dom==i.contentDOM&&i.dom.parentNode==this.contentDOM&&!i.children.length?_Q:vQ}n=a}this.dirty=_Q}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?_Q:gQ;t.dirty{if(!i)return r;if(i.parent)return i.parent.posBeforeChild(i)})),!t.type.spec.raw){if(a.nodeType!=1){let e=document.createElement(`span`);e.appendChild(a),a=e}a.contentEditable=`false`,a.classList.add(`ProseMirror-widget`)}super(e,[],a,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return this.dirty==hQ&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!=`selection`||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}},Dke=class extends yQ{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e==this.textDOM?this.posAtStart+t:this.posAtStart+(t?this.size:0)}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type===`characterData`&&e.target.nodeValue==e.oldValue}},xQ=class e extends yQ{constructor(e,t,n,r,i){super(e,[],n,r),this.mark=t,this.spec=i}static create(t,n,r,i){let a=i.nodeViews[n.type.name],o=a&&a(n,i,r);return(!o||!o.dom)&&(o=RY.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new e(t,n,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&vQ||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=vQ&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=hQ){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty0&&(a=PQ(a,0,t,r));for(let e=0;e{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),u=l&&l.dom,d=l&&l.contentDOM;if(n.isText){if(!u)u=document.createTextNode(n.text);else if(u.nodeType!=3)throw RangeError(`Text must be rendered as a DOM text node`)}else if(!u){let e=RY.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs);({dom:u,contentDOM:d}=e)}!d&&!n.isText&&u.nodeName!=`BR`&&(u.hasAttribute(`contenteditable`)||(u.contentEditable=`false`),n.type.spec.draggable&&(u.draggable=!0));let f=u;return u=jQ(u,r,n),l?c=new Oke(t,n,r,i,u,d||null,f,l,a,o+1):n.isText?new wQ(t,n,r,i,u,f,a):new e(t,n,r,i,u,d||null,f,a,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace==`pre`&&(e.preserveWhitespace=`full`),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>KJ.empty)}return e}matchesNode(e,t,n){return this.dirty==hQ&&e.eq(this.node)&&MQ(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return+!this.node.isLeaf}updateChildren(e,t){let n=this.node.inlineContent,r=t,i=e.composing?this.localCompositionInfo(e,t):null,a=i&&i.pos>-1?i:null,o=i&&i.pos<0,s=new Ake(this,a&&a.node,e);Nke(this.node,this.innerDeco,(t,i,a)=>{t.spec.marks?s.syncToMarks(t.spec.marks,n,e,i):t.type.side>=0&&!a&&s.syncToMarks(i==this.node.childCount?XJ.none:this.node.child(i).marks,n,e,i),s.placeWidget(t,e,r)},(t,a,c,l)=>{s.syncToMarks(t.marks,n,e,l);let u;s.findNodeMatch(t,a,c,l)||o&&e.state.selection.from>r&&e.state.selection.to-1&&s.updateNodeAt(t,a,c,u,e)||s.updateNextNode(t,a,c,e,l,r)||s.addNode(t,a,c,e,r),r+=t.nodeSize}),s.syncToMarks([],n,e,0),this.node.isTextblock&&s.addTextblockHacks(),s.destroyRest(),(s.changed||this.dirty==_Q)&&(a&&this.protectLocalComposition(e,a),EQ(this.contentDOM,this.children,e),qZ&&Pke(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof IX)||nt+this.node.content.size)return null;let i=e.input.compositionNode;if(!i||!this.dom.contains(i.parentNode))return null;if(this.node.inlineContent){let e=i.nodeValue,a=Fke(this.node.content,e,n-t,r-t);return a<0?null:{node:i,pos:a,text:e}}else return{node:i,pos:-1,text:``}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&=void 0}let a=new Dke(this,i,t,r);e.input.compositionNodes.push(a),this.children=PQ(this.children,n,n+r.length,e,a)}update(e,t,n,r){return this.dirty==vQ||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=hQ}updateOuterDeco(e){if(MQ(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,n=this.dom;this.dom=AQ(this.dom,this.nodeDOM,kQ(this.outerDeco,this.node,t),kQ(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute(`draggable`))}get domAtom(){return this.node.isAtom}};function CQ(e,t,n,r,i){jQ(r,t,e);let a=new SQ(void 0,e,t,n,r,r,r,i,0);return a.contentDOM&&a.updateChildren(i,0),a}var wQ=class e extends SQ{constructor(e,t,n,r,i,a,o){super(e,t,n,r,i,null,a,o,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return this.dirty==vQ||this.dirty!=hQ&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=hQ||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=hQ,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!=`characterData`&&e.type!=`selection`}slice(t,n,r){let i=this.node.cut(t,n),a=document.createTextNode(i.text);return new e(this.parent,i,this.outerDeco,this.innerDeco,a,a,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=vQ)}get domAtom(){return!1}isText(e){return this.node.text==e}},TQ=class extends yQ{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==hQ&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName==`IMG`}},Oke=class extends SQ{constructor(e,t,n,r,i,a,o,s,c,l){super(e,t,n,r,i,a,o,c,l),this.spec=s}update(e,t,n,r){if(this.dirty==vQ)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let i=this.spec.update(e,t,n);return i&&this.updateInner(e,t,n,r),i}else if(!this.contentDOM&&!e.isLeaf)return!1;else return super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function EQ(e,t,n){let r=e.firstChild,i=!1;for(let a=0;a>1,o=Math.min(a,e.length);for(;i-1)i>this.index&&(this.changed=!0,this.destroyBetween(this.index,i)),this.top=this.top.children[this.index];else{let r=xQ.create(this.top,e[a],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,a++}}findNodeMatch(e,t,n,r){let i=-1,a;if(r>=this.preMatch.index&&(a=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&a.matchesNode(e,t,n))i=this.top.children.indexOf(a,this.index);else for(let r=this.index,a=Math.min(this.top.children.length,r+5);r0;){let s;for(;;)if(r){let e=n.children[r-1];if(e instanceof xQ)n=e,r=e.children.length;else{s=e,r--;break}}else if(n==t)break outer;else r=n.parent.children.indexOf(n),n=n.parent;let c=s.node;if(c){if(c!=e.child(i-1))break;--i,a.set(s,i),o.push(s)}}return{index:i,matched:a,matches:o.reverse()}}function Mke(e,t){return e.type.side-t.type.side}function Nke(e,t,n,r){let i=t.locals(e),a=0;if(i.length==0){for(let n=0;na;)s.push(i[o++]);let m=a+f.nodeSize;if(f.isText){let e=m;o!e.inline):s.slice();r(f,h,t.forChild(a,f),p),a=m}}function Pke(e){if(e.nodeName==`UL`||e.nodeName==`OL`){let t=e.style.cssText;e.style.cssText=t+`; list-style: square !important`,window.getComputedStyle(e).listStyle,e.style.cssText=t}}function Fke(e,t,n,r){for(let i=0,a=0;i=n){if(a>=r&&c.slice(r-t.length-s,r-s)==t)return r-t.length;let e=s=0&&e+t.length+s>=n)return s+e;if(n==r&&c.length>=r+t.length-s&&c.slice(r-s,r-s+t.length)==t)return r}}return-1}function PQ(e,t,n,r,i){let a=[];for(let o=0,s=0;o=n||u<=t?a.push(c):(ln&&a.push(c.slice(n-l,c.size,r)))}return a}function FQ(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let i=e.docView.nearestDesc(n.focusNode),a=i&&i.size==0,o=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let s=r.resolve(o),c,l;if(MZ(n)){for(c=o;i&&!i.node;)i=i.parent;let e=i.node;if(i&&e.isAtom&&RX.isSelectable(e)&&i.parent&&!(e.isInline&&cke(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;l=new RX(o==e?s:r.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=o,i=o;for(let r=0;r{(n.anchorNode!=r||n.anchorOffset!=i)&&(t.removeEventListener(`selectionchange`,e.input.hideSelectionGuard),setTimeout(()=>{(!IQ(e)||e.state.selection.visible)&&e.dom.classList.remove(`ProseMirror-hideselection`)},20))})}function Lke(e){let t=e.domSelection();if(!t)return;let n=e.cursorWrapper.dom,r=n.nodeName==`IMG`;r?t.collapse(n.parentNode,wZ(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&BZ&&VZ<=11&&(n.disabled=!0,n.disabled=!1)}function HQ(e,t){if(t instanceof RX){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(UQ(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else UQ(e)}function UQ(e){e.lastSelectedViewDesc&&=(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),void 0)}function WQ(e,t,n,r){return e.someProp(`createSelectionBetween`,r=>r(e,t,n))||IX.between(t,n,r)}function GQ(e){return e.editable&&!e.hasFocus()?!1:KQ(e)}function KQ(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return e.dom.contains(t.anchorNode.nodeType==3?t.anchorNode.parentNode:t.anchorNode)&&(e.editable||e.dom.contains(t.focusNode.nodeType==3?t.focusNode.parentNode:t.focusNode))}catch{return!1}}function Rke(e){let t=e.docView.domFromPos(e.state.selection.anchor,0),n=e.domSelectionRange();return OZ(t.node,t.offset,n.anchorNode,n.anchorOffset)}function qQ(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),a=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):null:i;return a&&NX.findFrom(a,t)}function JQ(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function YQ(e,t,n){let r=e.state.selection;if(r instanceof IX){if(n.indexOf(`s`)>-1){let{$head:n}=r,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let a=e.state.doc.resolve(n.pos+i.nodeSize*(t<0?-1:1));return JQ(e,new IX(r.$anchor,a))}else if(!r.empty)return!1;else if(e.endOfTextblock(t>0?`forward`:`backward`)){let n=qQ(e.state,t);return n&&n instanceof RX?JQ(e,n):!1}else if(!(JZ&&n.indexOf(`m`)>-1)){let n=r.$head,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter,a;if(!i||i.isText)return!1;let o=t<0?n.pos-i.nodeSize:n.pos;return i.isAtom||(a=e.docView.descAt(o))&&!a.contentDOM?RX.isSelectable(i)?JQ(e,new RX(t<0?e.state.doc.resolve(n.pos-i.nodeSize):n)):ZZ?JQ(e,new IX(e.state.doc.resolve(t<0?o:o+i.nodeSize))):!1:!1}}else if(r instanceof RX&&r.node.isInline)return JQ(e,new IX(t>0?r.$to:r.$from));else{let n=qQ(e.state,t);return n?JQ(e,n):!1}}function XQ(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function ZQ(e,t){let n=e.pmViewDesc;return n&&n.size==0&&(t<0||e.nextSibling||e.nodeName!=`BR`)}function QQ(e,t){return t<0?zke(e):Bke(e)}function zke(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,a,o=!1;for(HZ&&n.nodeType==1&&r0){if(n.nodeType!=1)break;{let e=n.childNodes[r-1];if(ZQ(e,-1))i=n,a=--r;else if(e.nodeType==3)n=e,r=n.nodeValue.length;else break}}else if($Q(n))break;else{let t=n.previousSibling;for(;t&&ZQ(t,-1);)i=n.parentNode,a=wZ(t),t=t.previousSibling;if(t)n=t,r=XQ(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}o?e$(e,n,r):i&&e$(e,i,a)}function Bke(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i=XQ(n),a,o;for(;;)if(r{e.state==i&&LQ(e)},50)}function t$(e,t){let n=e.state.doc.resolve(t);if(!(WZ||YZ)&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),i=(n.top+n.bottom)/2;if(i>r.top&&i1)return n.leftr.top&&i1)return n.left>r.left?`ltr`:`rtl`}}return getComputedStyle(e.dom).direction==`rtl`?`rtl`:`ltr`}function n$(e,t,n){let r=e.state.selection;if(r instanceof IX&&!r.empty||n.indexOf(`s`)>-1||JZ&&n.indexOf(`m`)>-1)return!1;let{$from:i,$to:a}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?`up`:`down`)){let n=qQ(e.state,t);if(n&&n instanceof RX)return JQ(e,n)}if(!i.parent.inlineContent){let n=t<0?i:a,o=r instanceof zX?NX.near(n,t):NX.findFrom(n,t);return o?JQ(e,o):!1}return!1}function r$(e,t){if(!(e.state.selection instanceof IX))return!0;let{$head:n,$anchor:r,empty:i}=e.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(e.endOfTextblock(t>0?`forward`:`backward`))return!0;let a=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(a&&!a.isText){let r=e.state.tr;return t<0?r.delete(n.pos-a.nodeSize,n.pos):r.delete(n.pos,n.pos+a.nodeSize),e.dispatch(r),!0}return!1}function i$(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function Uke(e){if(!KZ||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&t.nodeType==1&&n==0&&t.firstChild&&t.firstChild.contentEditable==`false`){let n=t.firstChild;i$(e,n,`true`),setTimeout(()=>i$(e,n,`false`),20)}return!1}function Wke(e){let t=``;return e.ctrlKey&&(t+=`c`),e.metaKey&&(t+=`m`),e.altKey&&(t+=`a`),e.shiftKey&&(t+=`s`),t}function Gke(e,t){let n=t.keyCode,r=Wke(t);if(n==8||JZ&&n==72&&r==`c`)return r$(e,-1)||QQ(e,-1);if(n==46&&!t.shiftKey||JZ&&n==68&&r==`c`)return r$(e,1)||QQ(e,1);if(n==13||n==27)return!0;if(n==37||JZ&&n==66&&r==`c`){let t=n==37?t$(e,e.state.selection.from)==`ltr`?-1:1:-1;return YQ(e,t,r)||QQ(e,t)}else if(n==39||JZ&&n==70&&r==`c`){let t=n==39?t$(e,e.state.selection.from)==`ltr`?1:-1:1;return YQ(e,t,r)||QQ(e,t)}else if(n==38||JZ&&n==80&&r==`c`)return n$(e,-1,r)||QQ(e,-1);else if(n==40||JZ&&n==78&&r==`c`)return Uke(e)||n$(e,1,r)||QQ(e,1);else if(r==(JZ?`m`:`c`)&&(n==66||n==73||n==89||n==90))return!0;return!1}function a$(e,t){e.someProp(`transformCopied`,n=>{t=n(t,e)});let n=[],{content:r,openStart:i,openEnd:a}=t;for(;i>1&&a>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,a--;let e=r.firstChild;n.push(e.type.name,e.attrs==e.type.defaultAttrs?null:e.attrs),r=e.content}let o=e.someProp(`clipboardSerializer`)||RY.fromSchema(e.state.schema),s=p$(),c=s.createElement(`div`);c.appendChild(o.serializeFragment(r,{document:s}));let l=c.firstChild,u,d=0;for(;l&&l.nodeType==1&&(u=f$[l.nodeName.toLowerCase()]);){for(let e=u.length-1;e>=0;e--){let t=s.createElement(u[e]);for(;c.firstChild;)t.appendChild(c.firstChild);c.appendChild(t),d++}l=c.firstChild}return l&&l.nodeType==1&&l.setAttribute(`data-pm-slice`,`${i} ${a}${d?` -${d}`:``} ${JSON.stringify(n)}`),{dom:c,text:e.someProp(`clipboardTextSerializer`,n=>n(t,e))||t.content.textBetween(0,t.content.size,` `),slice:t}}function o$(e,t,n,r,i){let a=i.parent.type.spec.code,o,s;if(!n&&!t)return null;let c=!!t&&(r||a||!n);if(c){if(e.someProp(`transformPastedText`,n=>{t=n(t,a||r,e)}),a)return s=new QJ(KJ.from(e.state.schema.text(t.replace(/\r\n?/g,` -`))),0,0),e.someProp(`transformPasted`,t=>{s=t(s,e,!0)}),s;let n=e.someProp(`clipboardTextParser`,n=>n(t,i,r,e));if(n)s=n;else{let n=i.marks(),{schema:r}=e.state,a=RY.fromSchema(r);o=document.createElement(`div`),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=o.appendChild(document.createElement(`p`));e&&t.appendChild(a.serializeNode(r.text(e,n)))})}}else e.someProp(`transformPastedHTML`,t=>{n=t(n,e)}),o=Yke(n),ZZ&&Xke(o);let l=o&&o.querySelector(`[data-pm-slice]`),u=l&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(l.getAttribute(`data-pm-slice`)||``);if(u&&u[3])for(let e=+u[3];e>0;e--){let e=o.firstChild;for(;e&&e.nodeType!=1;)e=e.nextSibling;if(!e)break;o=e}if(s||=(e.someProp(`clipboardParser`)||e.someProp(`domParser`)||DY.fromSchema(e.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||u),context:i,ruleFromNode(e){return e.nodeName==`BR`&&!e.nextSibling&&e.parentNode&&!Gke.test(e.parentNode.nodeName)?{ignore:!0}:null}}),u)s=Zke(d$(s,+u[1],+u[2]),u[4]);else if(s=QJ.maxOpen(Kke(s.content,i),!0),s.openStart||s.openEnd){let e=0,t=0;for(let t=s.content.firstChild;e{s=t(s,e,c)}),s}var Gke=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function Kke(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.index(n)),i,a=[];if(e.forEach(e=>{if(!a)return;let t=r.findWrapping(e.type),n;if(!t)return a=null;if(n=a.length&&i.length&&c$(t,i,e,a[a.length-1],0))a[a.length-1]=n;else{a.length&&(a[a.length-1]=l$(a[a.length-1],i.length));let n=s$(e,t);a.push(n),r=r.matchType(n.type),i=t}}),a)return KJ.from(a)}return e}function s$(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,KJ.from(e));return e}function c$(e,t,n,r,i){if(i1&&(a=0),i=n&&(s=t<0?o.contentMatchAt(0).fillBefore(s,a<=i).append(s):s.append(o.contentMatchAt(o.childCount).fillBefore(KJ.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(s))}function d$(e,t,n){return te}),m$.createHTML(e)):e}function Yke(e){let t=/^(\s*]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n=p$().createElement(`div`),r=/<([a-z][^>\s]+)/i.exec(e),i;if((i=r&&f$[r[1].toLowerCase()])&&(e=i.map(e=>`<`+e+`>`).join(``)+e+i.map(e=>``).reverse().join(``)),n.innerHTML=Jke(e),i)for(let e=0;e=0;e-=2){let t=n.nodes[r[e]];if(!t||t.hasRequiredAttrs())break;i=KJ.from(t.create(r[e+1],i)),a++,o++}return new QJ(i,a,o)}var h$={},g$={},Qke={touchstart:!0,touchmove:!0},$ke=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:``,button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function eAe(e){for(let t in h$){let n=h$[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{nAe(e,t)&&!y$(e,t)&&(e.editable||!(t.type in g$))&&n(e,t)},Qke[t]?{passive:!0}:void 0)}KZ&&e.dom.addEventListener(`input`,()=>null),v$(e)}function _$(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function tAe(e){e.domObserver.stop();for(let t in e.input.eventHandlers)e.dom.removeEventListener(t,e.input.eventHandlers[t]);clearTimeout(e.input.composingTimeout),clearTimeout(e.input.lastIOSEnterFallbackTimeout)}function v$(e){e.someProp(`handleDOMEvents`,t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>y$(e,t))})}function y$(e,t){return e.someProp(`handleDOMEvents`,n=>{let r=n[t.type];return r?r(e,t)||t.defaultPrevented:!1})}function nAe(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function rAe(e,t){!y$(e,t)&&h$[t.type]&&(e.editable||!(t.type in g$))&&h$[t.type](e,t)}g$.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=n.keyCode==16||n.shiftKey,!T$(e,n)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!(XZ&&WZ&&n.keyCode==13)))if(n.keyCode!=229&&e.domObserver.forceFlush(),qZ&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp(`handleKeyDown`,t=>t(e,NZ(13,`Enter`))),e.input.lastIOSEnter=0)},200)}else e.someProp(`handleKeyDown`,t=>t(e,n))||Wke(e,n)?n.preventDefault():_$(e,`key`)},g$.keyup=(e,t)=>{t.keyCode==16&&(e.input.shiftKey=!1)},g$.keypress=(e,t)=>{let n=t;if(T$(e,n)||!n.charCode||n.ctrlKey&&!n.altKey||JZ&&n.metaKey)return;if(e.someProp(`handleKeyPress`,t=>t(e,n))){n.preventDefault();return}let r=e.state.selection;if(!(r instanceof IX)||!r.$from.sameParent(r.$to)){let t=String.fromCharCode(n.charCode),i=()=>e.state.tr.insertText(t).scrollIntoView();!/[\r\n]/.test(t)&&!e.someProp(`handleTextInput`,n=>n(e,r.$from.pos,r.$to.pos,t,i))&&e.dispatch(i()),n.preventDefault()}};function b$(e){return{left:e.clientX,top:e.clientY}}function iAe(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}function x$(e,t,n,r,i){if(r==-1)return!1;let a=e.state.doc.resolve(r);for(let r=a.depth+1;r>0;r--)if(e.someProp(t,t=>r>a.depth?t(e,n,a.nodeAfter,a.before(r),i,!0):t(e,n,a.node(r),a.before(r),i,!1)))return!0;return!1}function S$(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let r=e.state.tr.setSelection(t);n==`pointer`&&r.setMeta(`pointer`,!0),e.dispatch(r)}function aAe(e,t){if(t==-1)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return r&&r.isAtom&&RX.isSelectable(r)?(S$(e,new RX(n),`pointer`),!0):!1}function oAe(e,t){if(t==-1)return!1;let n=e.state.selection,r,i;n instanceof RX&&(r=n.node);let a=e.state.doc.resolve(t);for(let e=a.depth+1;e>0;e--){let t=e>a.depth?a.nodeAfter:a.node(e);if(RX.isSelectable(t)){i=r&&n.$from.depth>0&&e>=n.$from.depth&&a.before(n.$from.depth+1)==n.$from.pos?a.before(n.$from.depth):a.before(e);break}}return i==null?!1:(S$(e,RX.create(e.state.doc,i),`pointer`),!0)}function sAe(e,t,n,r,i){return x$(e,`handleClickOn`,t,n,r)||e.someProp(`handleClick`,n=>n(e,t,r))||(i?oAe(e,n):aAe(e,n))}function cAe(e,t,n,r){return x$(e,`handleDoubleClickOn`,t,n,r)||e.someProp(`handleDoubleClick`,n=>n(e,t,r))}function lAe(e,t,n,r){return x$(e,`handleTripleClickOn`,t,n,r)||e.someProp(`handleTripleClick`,n=>n(e,t,r))||uAe(e,n,r)}function uAe(e,t,n){if(n.button!=0)return!1;let r=e.state.doc;if(t==-1)return r.inlineContent?(S$(e,IX.create(r,0,r.content.size),`pointer`),!0):!1;let i=r.resolve(t);for(let t=i.depth+1;t>0;t--){let n=t>i.depth?i.nodeAfter:i.node(t),a=i.before(t);if(n.inlineContent)S$(e,IX.create(r,a+1,a+1+n.content.size),`pointer`);else if(RX.isSelectable(n))S$(e,RX.create(r,a),`pointer`);else continue;return!0}}function C$(e){return O$(e)}var w$=JZ?`metaKey`:`ctrlKey`;h$.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=C$(e),i=Date.now(),a=`singleClick`;i-e.input.lastClick.time<500&&iAe(n,e.input.lastClick)&&!n[w$]&&e.input.lastClick.button==n.button&&(e.input.lastClick.type==`singleClick`?a=`doubleClick`:e.input.lastClick.type==`doubleClick`&&(a=`tripleClick`)),e.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:a,button:n.button};let o=e.posAtCoords(b$(n));o&&(a==`singleClick`?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new dAe(e,o,n,!!r)):(a==`doubleClick`?cAe:lAe)(e,o.pos,o.inside,n)?n.preventDefault():_$(e,`pointer`))};var dAe=class{constructor(e,t,n,r){this.view=e,this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[w$],this.allowDefault=n.shiftKey;let i,a;if(t.inside>-1)i=e.state.doc.nodeAt(t.inside),a=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,a=n.depth?n.before():0}let o=r?null:n.target,s=o?e.docView.nearestDesc(o,!0):null;this.target=s&&s.nodeDOM.nodeType==1?s.nodeDOM:null;let{selection:c}=e.state;(n.button==0&&i.type.spec.draggable&&i.type.spec.selectable!==!1||c instanceof RX&&c.from<=a&&c.to>a)&&(this.mightDrag={node:i,pos:a,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&HZ&&!this.target.hasAttribute(`contentEditable`))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute(`contentEditable`,`false`)},20),this.view.domObserver.start()),e.root.addEventListener(`mouseup`,this.up=this.up.bind(this)),e.root.addEventListener(`mousemove`,this.move=this.move.bind(this)),_$(e,`pointer`)}done(){this.view.root.removeEventListener(`mouseup`,this.up),this.view.root.removeEventListener(`mousemove`,this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute(`draggable`),this.mightDrag.setUneditable&&this.target.removeAttribute(`contentEditable`),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>LQ(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(b$(e))),this.updateAllowDefault(e),this.allowDefault||!t?_$(this.view,`pointer`):sAe(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||KZ&&this.mightDrag&&!this.mightDrag.node.isAtom||WZ&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(S$(this.view,NX.near(this.view.state.doc.resolve(t.pos)),`pointer`),e.preventDefault()):_$(this.view,`pointer`)}move(e){this.updateAllowDefault(e),_$(this.view,`pointer`),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}};h$.touchstart=e=>{e.input.lastTouch=Date.now(),C$(e),_$(e,`pointer`)},h$.touchmove=e=>{e.input.lastTouch=Date.now(),_$(e,`pointer`)},h$.contextmenu=e=>C$(e);function T$(e,t){return e.composing?!0:KZ&&Math.abs(t.timeStamp-e.input.compositionEndedAt)<500?(e.input.compositionEndedAt=-2e8,!0):!1}var fAe=XZ?5e3:-1;g$.compositionstart=g$.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof IX&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>e.type.spec.inclusive===!1)||WZ&&YZ&&pAe(e)))e.markCursor=e.state.storedMarks||n.marks(),O$(e,!0),e.markCursor=null;else if(O$(e,!t.selection.empty),HZ&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,r=t.focusOffset;n&&n.nodeType==1&&r!=0;){let t=r<0?n.lastChild:n.childNodes[r-1];if(!t)break;if(t.nodeType==3){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}else n=t,r=-1}}e.input.composing=!0}E$(e,fAe)};function pAe(e){let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(!t||t.nodeType!=1||n>=t.childNodes.length)return!1;let r=t.childNodes[n];return r.nodeType==1&&r.contentEditable==`false`}g$.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.badSafariComposition?e.domObserver.forceFlush():e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,E$(e,20))};function E$(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>O$(e),t))}function D$(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=hAe());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function mAe(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=ake(t.focusNode,t.focusOffset),r=oke(t.focusNode,t.focusOffset);if(n&&r&&n!=r){let t=r.pmViewDesc,i=e.domObserver.lastChangedTextNode;if(n==i||r==i)return i;if(!t||!t.isText(r.nodeValue))return r;if(e.input.compositionNode==r){let e=n.pmViewDesc;if(!(!e||!e.isText(n.nodeValue)))return r}}return n||r}function hAe(){let e=document.createEvent(`Event`);return e.initEvent(`event`,!0,!0),e.timeStamp}function O$(e,t=!1){if(!(XZ&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),D$(e),t||e.docView&&e.docView.dirty){let n=FQ(e),r=e.state.selection;return n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):(e.markCursor||t)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.dispatch(e.state.tr.deleteSelection()):e.updateState(e.state),!0}return!1}}function gAe(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement(`div`));n.appendChild(t),n.style.cssText=`position: fixed; left: -10000px; top: 10px`;let r=getSelection(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}var k$=BZ&&VZ<15||qZ&&uke<604;h$.copy=g$.cut=(e,t)=>{let n=t,r=e.state.selection,i=n.type==`cut`;if(r.empty)return;let a=k$?null:n.clipboardData,{dom:o,text:s}=a$(e,r.content());a?(n.preventDefault(),a.clearData(),a.setData(`text/html`,o.innerHTML),a.setData(`text/plain`,s)):gAe(e,o),i&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta(`uiEvent`,`cut`))};function _Ae(e){return e.openStart==0&&e.openEnd==0&&e.content.childCount==1?e.content.firstChild:null}function vAe(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?`textarea`:`div`));n||(r.contentEditable=`true`),r.style.cssText=`position: fixed; left: -10000px; top: 10px`,r.focus();let i=e.input.shiftKey&&e.input.lastKeyCode!=45;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?A$(e,r.value,null,i,t):A$(e,r.textContent,r.innerHTML,i,t)},50)}function A$(e,t,n,r,i){let a=o$(e,t,n,r,e.state.selection.$from);if(e.someProp(`handlePaste`,t=>t(e,i,a||QJ.empty)))return!0;if(!a)return!1;let o=_Ae(a),s=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(a);return e.dispatch(s.scrollIntoView().setMeta(`paste`,!0).setMeta(`uiEvent`,`paste`)),!0}function j$(e){let t=e.getData(`text/plain`)||e.getData(`Text`);if(t)return t;let n=e.getData(`text/uri-list`);return n?n.replace(/\r?\n/g,` `):``}g$.paste=(e,t)=>{let n=t;if(e.composing&&!XZ)return;let r=k$?null:n.clipboardData,i=e.input.shiftKey&&e.input.lastKeyCode!=45;r&&A$(e,j$(r),r.getData(`text/html`),i,n)?n.preventDefault():vAe(e,n)};var M$=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},yAe=JZ?`altKey`:`ctrlKey`;function N$(e,t){return e.someProp(`dragCopies`,e=>!e(t))??!t[yAe]}h$.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=e.state.selection,a=i.empty?null:e.posAtCoords(b$(n)),o;if(!(a&&a.pos>=i.from&&a.pos<=(i instanceof RX?i.to-1:i.to))){if(r&&r.mightDrag)o=RX.create(e.state.doc,r.mightDrag.pos);else if(n.target&&n.target.nodeType==1){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&(o=RX.create(e.state.doc,t.posBefore))}}let{dom:s,text:c,slice:l}=a$(e,(o||e.state.selection).content());(!n.dataTransfer.files.length||!WZ||GZ>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(k$?`Text`:`text/html`,s.innerHTML),n.dataTransfer.effectAllowed=`copyMove`,k$||n.dataTransfer.setData(`text/plain`,c),e.dragging=new M$(l,N$(e,n),o)},h$.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},g$.dragover=g$.dragenter=(e,t)=>t.preventDefault(),g$.drop=(e,t)=>{try{bAe(e,t,e.dragging)}finally{e.dragging=null}};function bAe(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(b$(t));if(!r)return;let i=e.state.doc.resolve(r.pos),a=n&&n.slice;a?e.someProp(`transformPasted`,t=>{a=t(a,e,!1)}):a=o$(e,j$(t.dataTransfer),k$?null:t.dataTransfer.getData(`text/html`),!1,i);let o=!!(n&&N$(e,t));if(e.someProp(`handleDrop`,n=>n(e,t,a||QJ.empty,o))){t.preventDefault();return}if(!a)return;t.preventDefault();let s=a?vX(e.state.doc,i.pos,a):i.pos;s??=i.pos;let c=e.state.tr;if(o){let{node:e}=n;e?e.replace(c):c.deleteSelection()}let l=c.mapping.map(s),u=a.openStart==0&&a.openEnd==0&&a.content.childCount==1,d=c.doc;if(u?c.replaceRangeWith(l,l,a.content.firstChild):c.replaceRange(l,l,a),c.doc.eq(d))return;let f=c.doc.resolve(l);if(u&&RX.isSelectable(a.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(a.content.firstChild))c.setSelection(new RX(f));else{let t=c.mapping.map(s);c.mapping.maps[c.mapping.maps.length-1].forEach((e,n,r,i)=>t=i),c.setSelection(WQ(e,f,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta(`uiEvent`,`drop`))}h$.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add(`ProseMirror-focused`),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&LQ(e)},20))},h$.blur=(e,t)=>{let n=t;e.focused&&=(e.domObserver.stop(),e.dom.classList.remove(`ProseMirror-focused`),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),!1)},h$.beforeinput=(e,t)=>{if(WZ&&XZ&&t.inputType==`deleteContentBackward`){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t||(e.dom.blur(),e.focus(),e.someProp(`handleKeyDown`,t=>t(e,NZ(8,`Backspace`)))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())},50)}};for(let e in g$)h$[e]=g$[e];function P$(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}var F$=class e{constructor(e,t){this.toDOM=e,this.spec=t||z$,this.side=this.spec.side||0}map(e,t,n,r){let{pos:i,deleted:a}=e.mapResult(t.from+r,this.side<0?-1:1);return a?null:new L$(i-n,i-n,this)}valid(){return!0}eq(t){return this==t||t instanceof e&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&P$(this.spec,t.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},I$=class e{constructor(e,t){this.attrs=e,this.spec=t||z$}map(e,t,n,r){let i=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,a=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return i>=a?null:new L$(i,a,this)}valid(e,t){return t.from=e&&(!i||i(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let a=0;ae){let o=this.children[a]+1;this.children[a+2].findInner(e-o,t-o,n,r+o,i)}}map(e,t,n){return this==V$||e.maps.length==0?this:this.mapInner(e,t,0,0,n||z$)}mapInner(t,n,r,i,a){let o;for(let e=0;e{let o=t+r,s;if(s=W$(n,e,o)){for(i||=this.children.slice();aa&&n.to=t){this.children[e]==t&&(r=this.children[e+2]);break}let a=t+1,o=a+n.content.size;for(let e=0;ea&&t.type instanceof I$){let e=Math.max(a,t.from)-a,n=Math.min(o,t.to)-a;ee.map(t,n,z$));return e.from(r)}forChild(t,n){if(n.isLeaf)return B$.empty;let r=[];for(let i=0;ie instanceof B$)?t:t.reduce((e,t)=>e.concat(t instanceof B$?t:t.members),[]))}}forEachSet(e){for(let t=0;t{let o=a-i-(n-e);for(let i=0;ia+t-r)continue;let c=s[i]+t-r;n>=c?s[i+1]=e<=c?-2:-1:e>=t&&o&&(s[i]+=o,s[i+1]+=o)}r+=o}),t=n.maps[e].map(t,-1)}let c=!1;for(let t=0;t=r.content.size){c=!0;continue}let d=n.map(e[t+1]+a,-1)-i,{index:f,offset:p}=r.content.findIndex(u),m=r.maybeChild(f);if(m&&p==u&&p+m.nodeSize==d){let r=s[t+2].mapInner(n,m,l+1,e[t]+a+1,o);r==V$?(s[t+1]=-2,c=!0):(s[t]=u,s[t+1]=d,s[t+2]=r)}else c=!0}if(c){let c=K$(CAe(s,e,t,n,i,a,o),r,0,o);t=c.local;for(let e=0;en&&a.to{let s=W$(e,t,o+n);if(s){a=!0;let e=K$(s,t,n+o+1,r);e!=V$&&i.push(o,o+t.nodeSize,e)}});let o=U$(a?G$(e):e,-n).sort(q$);for(let e=0;e0;)t++;e.splice(t,0,n)}function X$(e){let t=[];return e.someProp(`decorations`,n=>{let r=n(e.state);r&&r!=V$&&t.push(r)}),e.cursorWrapper&&t.push(B$.create(e.state.doc,[e.cursorWrapper.deco])),H$.from(t)}var wAe={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},TAe=BZ&&VZ<=11,EAe=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}},DAe=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new EAe,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(t=>{for(let e=0;ee.type==`childList`&&e.removedNodes.length||e.type==`characterData`&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():KZ&&e.composing&&t.some(e=>e.type==`childList`&&e.target.nodeName==`TR`)?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),TAe&&(this.onCharData=e=>{this.queue.push({target:e.target,type:`characterData`,oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,wAe)),this.onCharData&&this.view.dom.addEventListener(`DOMCharacterDataModified`,this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;tthis.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener(`DOMCharacterDataModified`,this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener(`selectionchange`,this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener(`selectionchange`,this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(GQ(this.view)){if(this.suppressingSelectionUpdates)return LQ(this.view);if(BZ&&VZ<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&OZ(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let n=e.focusNode;n;n=TZ(n))t.add(n);for(let r=e.anchorNode;r;r=TZ(r))if(t.has(r)){n=r;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:`selection`,target:n.nodeType==3?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&GQ(e)&&!this.ignoreSelectionChange(n),i=-1,a=-1,o=!1,s=[];if(e.editable)for(let e=0;ee.nodeName==`BR`)&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let e of s)if(e.nodeName==`BR`&&e.parentNode){let t=e.nextSibling;t&&t.nodeType==1&&t.contentEditable==`false`&&e.parentNode.removeChild(e)}}else if(HZ&&s.length){let t=s.filter(e=>e.nodeName==`BR`);if(t.length==2){let[e,n]=t;e.parentNode&&e.parentNode.parentNode==n.parentNode?n.remove():e.remove()}else{let{focusNode:n}=this.currentSelection;for(let r of t){let t=r.parentNode;t&&t.nodeName==`LI`&&(!n||AAe(e,n)!=t)&&r.remove()}}}let c=null;i<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||r)&&(i>-1&&(e.docView.markDirty(i,a),OAe(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,jAe(e,s)),this.handleDOMChange(i,a,o,s),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||LQ(e),this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type==`attributes`&&(n==this.view.docView||e.attributeName==`contenteditable`||e.attributeName==`style`&&!e.oldValue&&!e.target.getAttribute(`style`))||!n||n.ignoreMutation(e))return null;if(e.type==`childList`){for(let n=0;ni;e--){let t=r.childNodes[e-1],n=t.pmViewDesc;if(t.nodeName==`BR`&&!n){a=e;break}if(!n||n.size)break}let d=e.state.doc,f=e.someProp(`domParser`)||DY.fromSchema(e.state.schema),p=d.resolve(o),m=null,h=f.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:a,preserveWhitespace:p.parent.type.whitespace==`pre`?`full`:!0,findPositions:l,ruleFromNode:NAe,context:p});if(l&&l[0].pos!=null){let e=l[0].pos,t=l[1]&&l[1].pos;t??=e,m={anchor:e+o,head:t+o}}return{doc:h,sel:m,from:o,to:s}}function NAe(e){let t=e.pmViewDesc;if(t)return t.parseRule();if(e.nodeName==`BR`&&e.parentNode){if(KZ&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let e=document.createElement(`div`);return e.appendChild(document.createElement(`li`)),{skip:e}}else if(e.parentNode.lastChild==e||KZ&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if(e.nodeName==`IMG`&&e.getAttribute(`mark-placeholder`))return{ignore:!0};return null}var PAe=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function FAe(e,t,n,r,i){let a=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=FQ(e,t);if(n&&!e.state.selection.eq(n)){if(WZ&&XZ&&e.input.lastKeyCode===13&&Date.now()-100t(e,NZ(13,`Enter`))))return;let r=e.state.tr.setSelection(n);t==`pointer`?r.setMeta(`pointer`,!0):t==`key`&&r.scrollIntoView(),a&&r.setMeta(`composition`,a),e.dispatch(r)}return}let o=e.state.doc.resolve(t),s=o.sharedDepth(n);t=o.before(s+1),n=e.state.doc.resolve(n).after(s+1);let c=e.state.selection,l=MAe(e,t,n),u=e.state.doc,d=u.slice(l.from,l.to),f,p;e.input.lastKeyCode===8&&Date.now()-100Date.now()-225||XZ)&&i.some(e=>e.nodeType==1&&!PAe.test(e.nodeName))&&(!m||m.endA>=m.endB)&&e.someProp(`handleKeyDown`,t=>t(e,NZ(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(!m)if(r&&c instanceof IX&&!c.empty&&c.$head.sameParent(c.$anchor)&&!e.composing&&!(l.sel&&l.sel.anchor!=l.sel.head))m={start:c.from,endA:c.to,endB:c.to};else{if(l.sel){let t=e1(e,e.state.doc,l.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);a&&n.setMeta(`composition`,a),e.dispatch(n)}}return}e.state.selection.frome.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=l.from?m.start=e.state.selection.from:m.endA=e.state.selection.to-2&&e.state.selection.to<=l.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),BZ&&VZ<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>l.from&&l.doc.textBetween(m.start-l.from-1,m.start-l.from+1)==` \xA0`&&(m.start--,m.endA--,m.endB--);let h=l.doc.resolveNoCache(m.start-l.from),g=l.doc.resolveNoCache(m.endB-l.from),_=u.resolve(m.start),v=h.sameParent(g)&&h.parent.inlineContent&&_.end()>=m.endA;if((qZ&&e.input.lastIOSEnter>Date.now()-225&&(!v||i.some(e=>e.nodeName==`DIV`||e.nodeName==`P`))||!v&&h.post(e,NZ(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>m.start&&LAe(u,m.start,m.endA,h,g)&&e.someProp(`handleKeyDown`,t=>t(e,NZ(8,`Backspace`)))){XZ&&WZ&&e.domObserver.suppressSelectionUpdates();return}WZ&&m.endB==m.start&&(e.input.lastChromeDelete=Date.now()),XZ&&!v&&h.start()!=g.start()&&g.parentOffset==0&&h.depth==g.depth&&l.sel&&l.sel.anchor==l.sel.head&&l.sel.head==m.endA&&(m.endB-=2,g=l.doc.resolveNoCache(m.endB-l.from),setTimeout(()=>{e.someProp(`handleKeyDown`,function(t){return t(e,NZ(13,`Enter`))})},20));let y=m.start,b=m.endA,x=t=>{let n=t||e.state.tr.replace(y,b,l.doc.slice(m.start-l.from,m.endB-l.from));if(l.sel){let t=e1(e,n.doc,l.sel);t&&!(WZ&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastChromeDeleteLQ(e),20));let t=x(e.state.tr.delete(y,b)),n=u.resolve(m.start).marksAcross(u.resolve(m.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(m.endA==m.endB&&(S=IAe(h.parent.content.cut(h.parentOffset,g.parentOffset),_.parent.content.cut(_.parentOffset,m.endA-_.start())))){let t=x(e.state.tr);S.type==`add`?t.addMark(y,b,S.mark):t.removeMark(y,b,S.mark),e.dispatch(t)}else if(h.parent.child(h.index()).isText&&h.index()==g.index()-+!g.textOffset){let t=h.parent.textBetween(h.parentOffset,g.parentOffset),n=()=>x(e.state.tr.insertText(t,y,b));e.someProp(`handleTextInput`,r=>r(e,y,b,t,n))||e.dispatch(n())}else e.dispatch(x());else e.dispatch(x())}function e1(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:WQ(e,t.resolve(n.anchor),t.resolve(n.head))}function IAe(e,t){let n=e.firstChild.marks,r=t.firstChild.marks,i=n,a=r,o,s,c;for(let e=0;ee.mark(s.addToSet(e.marks));else if(i.length==0&&a.length==1)s=a[0],o=`remove`,c=e=>e.mark(s.removeFromSet(e.marks));else return null;let l=[];for(let e=0;en||t1(o,!0,!1)0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}function RAe(e,t,n,r,i){let a=e.findDiffStart(t,n);if(a==null)return null;let{a:o,b:s}=e.findDiffEnd(t,n+e.size,n+t.size);if(i==`end`){let e=Math.max(0,a-Math.min(o,s));r-=o+e-a}if(o=o?a-r:0;a-=e,a&&a=s?a-r:0;a-=t,a&&a=56320&&t<=57343&&n>=55296&&n<=56319}var r1=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new $ke,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(c1),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement(`div`),e&&(e.appendChild?e.appendChild(this.dom):typeof e==`function`?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=o1(this),a1(this),this.nodeViews=s1(this),this.docView=CQ(this.state.doc,i1(this),X$(this),this.dom,this),this.domObserver=new DAe(this,(e,t,n,r)=>FAe(this,e,t,n,r)),this.domObserver.start(),eAe(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&v$(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(c1),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){let n=this.state,r=!1,i=!1;e.storedMarks&&this.composing&&(D$(this),i=!0),this.state=e;let a=n.plugins!=e.plugins||this._props.plugins!=t.plugins;if(a||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=s1(this);BAe(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}(a||t.handleDOMEvents!=this._props.handleDOMEvents)&&v$(this),this.editable=o1(this),a1(this);let o=X$(this),s=i1(this),c=n.plugins!=e.plugins&&!n.doc.eq(e.doc)?`reset`:e.scrollToSelection>n.scrollToSelection?`to selection`:`preserve`,l=r||!this.docView.matchesNode(e.doc,s,o);(l||!e.selection.eq(n.selection))&&(i=!0);let u=c==`preserve`&&i&&this.dom.style.overflowAnchor==null&&pke(this);if(i){this.domObserver.stop();let t=l&&(BZ||WZ)&&!this.composing&&!n.selection.empty&&!e.selection.empty&&zAe(n.selection,e.selection);if(l){let n=WZ?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=mAe(this)),(r||!this.docView.update(e.doc,s,o,this))&&(this.docView.updateOuterDeco(s),this.docView.destroy(),this.docView=CQ(e.doc,s,o,this.dom,this)),n&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(t=!0)}t||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Lke(this))?LQ(this,t):(HQ(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(n),this.dragging?.node&&!n.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,n),c==`reset`?this.dom.scrollTop=0:c==`to selection`?this.scrollToSelection():u&&mke(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))&&!this.someProp(`handleScrollToSelection`,e=>e(this)))if(this.state.selection instanceof RX){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&$Z(this,t.getBoundingClientRect(),e)}else $Z(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let e=0;e0&&this.state.doc.nodeAt(e))==n.node&&(r=e)}this.dragging=new M$(e.slice,e.move,r<0?void 0:RX.create(this.state.doc,r))}someProp(e,t){let n=this._props&&this._props[e],r;if(n!=null&&(r=t?t(n):n))return r;for(let n=0;ne.ownerDocument.getSelection()),this._root=e}return e||document}updateRoot(){this._root=null}posAtCoords(e){return bke(this,e)}coordsAtPos(e,t=1){return cQ(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(r==null)throw RangeError(`DOM position not inside the editor`);return r}endOfTextblock(e,t){return Tke(this,t||this.state,e)}pasteHTML(e,t){return A$(this,``,e,!1,t||new ClipboardEvent(`paste`))}pasteText(e,t){return A$(this,e,null,!0,t||new ClipboardEvent(`paste`))}serializeForClipboard(e){return a$(this,e)}destroy(){this.docView&&(tAe(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],X$(this),this),this.dom.textContent=``):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,rke())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return rAe(this,e)}domSelectionRange(){let e=this.domSelection();return e?KZ&&this.root.nodeType===11&&cke(this.dom.ownerDocument)==this.dom&&kAe(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};r1.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};function i1(e){let t=Object.create(null);return t.class=`ProseMirror`,t.contenteditable=String(e.editable),e.someProp(`attributes`,n=>{if(typeof n==`function`&&(n=n(e.state)),n)for(let e in n)e==`class`?t.class+=` `+n[e]:e==`style`?t.style=(t.style?t.style+`;`:``)+n[e]:!t[e]&&e!=`contenteditable`&&e!=`nodeName`&&(t[e]=String(n[e]))}),t.translate||=`no`,[L$.node(0,e.state.doc.content.size,t)]}function a1(e){if(e.markCursor){let t=document.createElement(`img`);t.className=`ProseMirror-separator`,t.setAttribute(`mark-placeholder`,`true`),t.setAttribute(`alt`,``),e.cursorWrapper={dom:t,deco:L$.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function o1(e){return!e.someProp(`editable`,t=>t(e.state)===!1)}function zAe(e,t){let n=Math.min(e.$anchor.sharedDepth(e.head),t.$anchor.sharedDepth(t.head));return e.$anchor.start(n)!=t.$anchor.start(n)}function s1(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp(`nodeViews`,n),e.someProp(`markViews`,n),t}function BAe(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r}function c1(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError(`Plugins passed directly to the view must not have a state component`)}for(var l1={8:`Backspace`,9:`Tab`,10:`Enter`,12:`NumLock`,13:`Enter`,16:`Shift`,17:`Control`,18:`Alt`,20:`CapsLock`,27:`Escape`,32:` `,33:`PageUp`,34:`PageDown`,35:`End`,36:`Home`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`,44:`PrintScreen`,45:`Insert`,46:`Delete`,59:`;`,61:`=`,91:`Meta`,92:`Meta`,106:`*`,107:`+`,108:`,`,109:`-`,110:`.`,111:`/`,144:`NumLock`,145:`ScrollLock`,160:`Shift`,161:`Shift`,162:`Control`,163:`Control`,164:`Alt`,165:`Alt`,173:`-`,186:`;`,187:`=`,188:`,`,189:`-`,190:`.`,191:`/`,192:"`",219:`[`,220:`\\`,221:`]`,222:`'`},u1={48:`)`,49:`!`,50:`@`,51:`#`,52:`$`,53:`%`,54:`^`,55:`&`,56:`*`,57:`(`,59:`:`,61:`+`,173:`_`,186:`:`,187:`+`,188:`<`,189:`_`,190:`>`,191:`?`,192:`~`,219:`{`,220:`|`,221:`}`,222:`"`},VAe=typeof navigator<`u`&&/Mac/.test(navigator.platform),HAe=typeof navigator<`u`&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),d1=0;d1<10;d1++)l1[48+d1]=l1[96+d1]=String(d1);for(var d1=1;d1<=24;d1++)l1[d1+111]=`F`+d1;for(var d1=65;d1<=90;d1++)l1[d1]=String.fromCharCode(d1+32),u1[d1]=String.fromCharCode(d1);for(var f1 in l1)u1.hasOwnProperty(f1)||(u1[f1]=l1[f1]);function UAe(e){var t=!(VAe&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||HAe&&e.shiftKey&&e.key&&e.key.length==1||e.key==`Unidentified`)&&e.key||(e.shiftKey?u1:l1)[e.keyCode]||e.key||`Unidentified`;return t==`Esc`&&(t=`Escape`),t==`Del`&&(t=`Delete`),t==`Left`&&(t=`ArrowLeft`),t==`Up`&&(t=`ArrowUp`),t==`Right`&&(t=`ArrowRight`),t==`Down`&&(t=`ArrowDown`),t}var WAe=typeof navigator<`u`&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),GAe=typeof navigator<`u`&&/Win/.test(navigator.platform);function KAe(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n==`Space`&&(n=` `);let r,i,a,o;for(let e=0;e{for(var n in t)YAe(e,n,{get:t[n],enumerable:!0})};function g1(e){let{state:t,transaction:n}=e,{selection:r}=n,{doc:i}=n,{storedMarks:a}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return a},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,a=n.storedMarks,n}}}var _1=class{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){let{rawCommands:e,editor:t,state:n}=this,{view:r}=t,{tr:i}=n,a=this.buildProps(i);return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,(...e)=>{let n=t(...e)(a);return!i.getMeta(`preventDispatch`)&&!this.hasCustomState&&r.dispatch(i),n}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o=[],s=!!e,c=e||i.tr,l=()=>(!s&&t&&!c.getMeta(`preventDispatch`)&&!this.hasCustomState&&a.dispatch(c),o.every(e=>e===!0)),u={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{let r=this.buildProps(c,t),i=n(...e)(r);return o.push(i),u}])),run:l};return u}createCan(e){let{rawCommands:t,state:n}=this,r=e||n.tr,i=this.buildProps(r,!1);return{...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)({...i,dispatch:void 0})])),chain:()=>this.createChain(r,!1)}}buildProps(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o={tr:e,editor:r,view:a,state:g1({state:i,transaction:e}),dispatch:t?()=>void 0:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(...e)=>t(...e)(o)]))}};return o}},v1={};h1(v1,{blur:()=>XAe,clearContent:()=>ZAe,clearNodes:()=>QAe,command:()=>$Ae,createParagraphNear:()=>eje,cut:()=>tje,deleteCurrentNode:()=>nje,deleteNode:()=>rje,deleteRange:()=>ije,deleteSelection:()=>aje,enter:()=>oje,exitCode:()=>sje,extendMarkRange:()=>cje,first:()=>lje,focus:()=>dje,forEach:()=>fje,insertContent:()=>pje,insertContentAt:()=>gje,joinBackward:()=>yje,joinDown:()=>vje,joinForward:()=>bje,joinItemBackward:()=>xje,joinItemForward:()=>Sje,joinTextblockBackward:()=>Cje,joinTextblockForward:()=>wje,joinUp:()=>_je,keyboardShortcut:()=>Eje,lift:()=>Dje,liftEmptyBlock:()=>Oje,liftListItem:()=>kje,newlineInCode:()=>Aje,resetAttributes:()=>jje,scrollIntoView:()=>Mje,selectAll:()=>Nje,selectNodeBackward:()=>Pje,selectNodeForward:()=>Fje,selectParentNode:()=>Ije,selectTextblockEnd:()=>Lje,selectTextblockStart:()=>Rje,setContent:()=>zje,setMark:()=>aMe,setMeta:()=>oMe,setNode:()=>sMe,setNodeSelection:()=>cMe,setTextDirection:()=>lMe,setTextSelection:()=>uMe,sinkListItem:()=>dMe,splitBlock:()=>fMe,splitListItem:()=>pMe,toggleList:()=>mMe,toggleMark:()=>hMe,toggleNode:()=>gMe,toggleWrap:()=>_Me,undoInputRule:()=>vMe,unsetAllMarks:()=>yMe,unsetMark:()=>bMe,unsetTextDirection:()=>xMe,updateAttributes:()=>SMe,wrapIn:()=>CMe,wrapInList:()=>wMe});var XAe=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),(n=window==null?void 0:window.getSelection())==null||n.removeAllRanges())}),!0),ZAe=(e=!0)=>({commands:t})=>t.setContent(``,{emitUpdate:e}),QAe=()=>({state:e,tr:t,dispatch:n})=>{let{selection:r}=t,{ranges:i}=r;return n&&i.forEach(({$from:n,$to:r})=>{e.doc.nodesBetween(n.pos,r.pos,(e,n)=>{if(e.type.isText)return;let{doc:r,mapping:i}=t,a=r.resolve(i.map(n)),o=r.resolve(i.map(n+e.nodeSize)),s=a.blockRange(o);if(!s)return;let c=lX(s);if(e.type.isTextblock){let{defaultType:e}=a.parent.contentMatchAt(a.index());t.setNodeMarkup(s.start,e)}(c||c===0)&&t.lift(s,c)})}),!0},$Ae=e=>t=>e(t),eje=()=>({state:e,dispatch:t})=>pZ(e,t),tje=(e,t)=>({editor:n,tr:r})=>{let{state:i}=n,a=i.doc.slice(e.from,e.to);r.deleteRange(e.from,e.to);let o=r.mapping.map(t);return r.insert(o,a.content),r.setSelection(new IX(r.doc.resolve(Math.max(o-1,0)))),!0},nje=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;let i=e.selection.$anchor;for(let n=i.depth;n>0;--n)if(i.node(n).type===r.type){if(t){let t=i.before(n),r=i.after(n);e.delete(t,r).scrollIntoView()}return!0}return!1};function y1(e,t){if(typeof e==`string`){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}var rje=e=>({tr:t,state:n,dispatch:r})=>{let i=y1(e,n.schema),a=t.selection.$anchor;for(let e=a.depth;e>0;--e)if(a.node(e).type===i){if(r){let n=a.before(e),r=a.after(e);t.delete(n,r).scrollIntoView()}return!0}return!1},ije=e=>({tr:t,dispatch:n})=>{let{from:r,to:i}=e;return n&&t.delete(r,i),!0},aje=()=>({state:e,dispatch:t})=>$X(e,t),oje=()=>({commands:e})=>e.keyboardShortcut(`Enter`),sje=()=>({state:e,dispatch:t})=>fZ(e,t);function b1(e){return Object.prototype.toString.call(e)===`[object RegExp]`}function x1(e,t,n={strict:!0}){let r=Object.keys(t);return r.length?r.every(r=>n.strict?t[r]===e[r]:b1(t[r])?t[r].test(e[r]):t[r]===e[r]):!0}function S1(e,t,n={}){return e.find(e=>e.type===t&&x1(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function C1(e,t,n={}){return!!S1(e,t,n)}function w1(e,t,n){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if((!r.node||!r.node.marks.some(e=>e.type===t))&&(r=e.parent.childBefore(e.parentOffset)),!r.node||!r.node.marks.some(e=>e.type===t)||(n||=r.node.marks[0]?.attrs,!S1([...r.node.marks],t,n)))return;let i=r.index,a=e.start()+r.offset,o=i+1,s=a+r.node.nodeSize;for(;i>0&&C1([...e.parent.child(i-1).marks],t,n);)--i,a-=e.parent.child(i).nodeSize;for(;o({tr:n,state:r,dispatch:i})=>{let a=T1(e,r.schema),{doc:o,selection:s}=n,{$from:c,from:l,to:u}=s;if(i){let e=w1(c,a,t);if(e&&e.from<=l&&e.to>=u){let t=IX.create(o,e.from,e.to);n.setSelection(t)}}return!0},lje=e=>t=>{let n=typeof e==`function`?e(t):e;for(let e=0;e({editor:n,view:r,tr:i,dispatch:a})=>{t={scrollIntoView:!0,...t};let o=()=>{(A1()||k1())&&r.dom.focus(),uje()&&!A1()&&!k1()&&r.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),t?.scrollIntoView&&n.commands.scrollIntoView())})};try{if(r.hasFocus()&&e===null||e===!1)return!0}catch{return!1}if(a&&e===null&&!E1(n.state.selection))return o(),!0;let s=O1(i.doc,e)||n.state.selection,c=n.state.selection.eq(s);return a&&(c||i.setSelection(s),c&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},fje=(e,t)=>n=>e.every((e,r)=>t(e,{...n,index:r})),pje=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),j1=e=>{let t=e.childNodes;for(let n=t.length-1;n>=0;--n){let r=t[n];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?e.removeChild(r):r.nodeType===1&&j1(r)}return e};function M1(e){if(typeof window>`u`)throw Error(`[tiptap error]: there is no window object available, so this function cannot be used`);let t=`${e}`,n=new window.DOMParser().parseFromString(t,`text/html`).body;return j1(n)}function N1(e,t,n){if(e instanceof fY||e instanceof KJ)return e;n={slice:!0,parseOptions:{},...n};let r=typeof e==`object`&&!!e,i=typeof e==`string`;if(r)try{if(Array.isArray(e)&&e.length>0)return KJ.fromArray(e.map(e=>t.nodeFromJSON(e)));let r=t.nodeFromJSON(e);return n.errorOnInvalidContent&&r.check(),r}catch(r){if(n.errorOnInvalidContent)throw Error(`[tiptap error]: Invalid JSON content`,{cause:r});return console.warn(`[tiptap warn]: Invalid content.`,`Passed value:`,e,`Error:`,r),N1(``,t,n)}if(i){if(n.errorOnInvalidContent){let r=!1,i=``,a=new TY({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:`inline*`,group:`block`,parseDOM:[{tag:`*`,getAttrs:e=>(r=!0,i=typeof e==`string`?e:e.outerHTML,null)}]}})});if(n.slice?DY.fromSchema(a).parseSlice(M1(e),n.parseOptions):DY.fromSchema(a).parse(M1(e),n.parseOptions),n.errorOnInvalidContent&&r)throw Error(`[tiptap error]: Invalid HTML content`,{cause:Error(`Invalid element found: ${i}`)})}let r=DY.fromSchema(t);return n.slice?r.parseSlice(M1(e),n.parseOptions).content:r.parse(M1(e),n.parseOptions)}return N1(``,t,n)}function mje(e,t,n){let r=e.steps.length-1;if(r{o===0&&(o=r)}),e.setSelection(NX.near(e.doc.resolve(o),n))}var hje=e=>!(`type`in e),gje=(e,t,n)=>({tr:r,dispatch:i,editor:a})=>{if(i){n={parseOptions:a.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let i,o=e=>{a.emit(`contentError`,{editor:a,error:e,disableCollaboration:()=>{`collaboration`in a.storage&&typeof a.storage.collaboration==`object`&&a.storage.collaboration&&(a.storage.collaboration.isDisabled=!0)}})},s={preserveWhitespace:`full`,...n.parseOptions};if(!n.errorOnInvalidContent&&!a.options.enableContentCheck&&a.options.emitContentError)try{N1(t,a.schema,{parseOptions:s,errorOnInvalidContent:!0})}catch(e){o(e)}try{i=N1(t,a.schema,{parseOptions:s,errorOnInvalidContent:n.errorOnInvalidContent??a.options.enableContentCheck})}catch(e){return o(e),!1}let{from:c,to:l}=typeof e==`number`?{from:e,to:e}:{from:e.from,to:e.to},u=!0,d=!0;if((hje(i)?i:[i]).forEach(e=>{e.check(),u=u?e.isText&&e.marks.length===0:!1,d=d?e.isBlock:!1}),c===l&&d){let{parent:e}=r.doc.resolve(c);e.isTextblock&&!e.type.spec.code&&!e.childCount&&(--c,l+=1)}let f;if(u){if(Array.isArray(t))f=t.map(e=>e.text||``).join(``);else if(t instanceof KJ){let e=``;t.forEach(t=>{t.text&&(e+=t.text)}),f=e}else f=typeof t==`object`&&t&&t.text?t.text:t;r.insertText(f,c,l)}else{f=i;let e=r.doc.resolve(c),t=e.node(),n=e.parentOffset===0,a=t.isText||t.isTextblock,o=t.content.size>0;n&&a&&o&&(c=Math.max(0,c-1)),r.replaceWith(c,l,f)}n.updateSelection&&mje(r,r.steps.length-1,-1),n.applyInputRules&&r.setMeta(`applyInputRules`,{from:c,text:f}),n.applyPasteRules&&r.setMeta(`applyPasteRules`,{from:c,text:f})}return!0},_je=()=>({state:e,dispatch:t})=>BOe(e,t),vje=()=>({state:e,dispatch:t})=>VOe(e,t),yje=()=>({state:e,dispatch:t})=>tZ(e,t),bje=()=>({state:e,dispatch:t})=>sZ(e,t),xje=()=>({state:e,dispatch:t,tr:n})=>{try{let r=_X(e.doc,e.selection.$from.pos,-1);return r==null?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},Sje=()=>({state:e,dispatch:t,tr:n})=>{try{let r=_X(e.doc,e.selection.$from.pos,1);return r==null?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},Cje=()=>({state:e,dispatch:t})=>ROe(e,t),wje=()=>({state:e,dispatch:t})=>zOe(e,t);function P1(){return typeof navigator<`u`?/Mac/.test(navigator.platform):!1}function Tje(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n===`Space`&&(n=` `);let r,i,a,o;for(let e=0;e({editor:t,view:n,tr:r,dispatch:i})=>{let a=Tje(e).split(/-(?!$)/),o=a.find(e=>![`Alt`,`Ctrl`,`Meta`,`Shift`].includes(e)),s=new KeyboardEvent(`keydown`,{key:o===`Space`?` `:o,altKey:a.includes(`Alt`),ctrlKey:a.includes(`Ctrl`),metaKey:a.includes(`Meta`),shiftKey:a.includes(`Shift`),bubbles:!0,cancelable:!0});return t.captureTransaction(()=>{n.someProp(`handleKeyDown`,e=>e(n,s))})?.steps.forEach(e=>{let t=e.map(r.mapping);t&&i&&r.maybeStep(t)}),!0};function F1(e,t,n={}){let{from:r,to:i,empty:a}=e.selection,o=t?y1(t,e.schema):null,s=[];e.doc.nodesBetween(r,i,(e,t)=>{if(e.isText)return;let n=Math.max(r,t),a=Math.min(i,t+e.nodeSize);s.push({node:e,from:n,to:a})});let c=i-r,l=s.filter(e=>o?o.name===e.node.type.name:!0).filter(e=>x1(e.node.attrs,n,{strict:!1}));return a?!!l.length:l.reduce((e,t)=>e+t.to-t.from,0)>=c}var Dje=(e,t={})=>({state:n,dispatch:r})=>F1(n,y1(e,n.schema),t)?HOe(n,r):!1,Oje=()=>({state:e,dispatch:t})=>mZ(e,t),kje=e=>({state:t,dispatch:n})=>$Oe(y1(e,t.schema))(t,n),Aje=()=>({state:e,dispatch:t})=>uZ(e,t);function I1(e,t){return t.nodes[e]?`node`:t.marks[e]?`mark`:null}function L1(e,t){let n=typeof t==`string`?[t]:t;return Object.keys(e).reduce((t,r)=>(n.includes(r)||(t[r]=e[r]),t),{})}var jje=(e,t)=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=I1(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=y1(e,r.schema)),s===`mark`&&(o=T1(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{r.doc.nodesBetween(e.$from.pos,e.$to.pos,(e,r)=>{a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,L1(e.attrs,t))),o&&e.marks.length&&e.marks.forEach(a=>{o===a.type&&(c=!0,i&&n.addMark(r,r+e.nodeSize,o.create(L1(a.attrs,t))))})})}),c},Mje=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),Nje=()=>({tr:e,dispatch:t})=>{if(t){let t=new zX(e.doc);e.setSelection(t)}return!0},Pje=()=>({state:e,dispatch:t})=>iZ(e,t),Fje=()=>({state:e,dispatch:t})=>cZ(e,t),Ije=()=>({state:e,dispatch:t})=>GOe(e,t),Lje=()=>({state:e,dispatch:t})=>vZ(e,t),Rje=()=>({state:e,dispatch:t})=>_Z(e,t);function R1(e,t,n={},r={}){return N1(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var zje=(e,{errorOnInvalidContent:t,emitUpdate:n=!0,parseOptions:r={}}={})=>({editor:i,tr:a,dispatch:o,commands:s})=>{let{doc:c}=a;if(r.preserveWhitespace!==`full`){let s=R1(e,i.schema,r,{errorOnInvalidContent:t??i.options.enableContentCheck});return o&&a.replaceWith(0,c.content.size,s).setMeta(`preventUpdate`,!n),!0}return o&&a.setMeta(`preventUpdate`,!n),s.insertContentAt({from:0,to:c.content.size},e,{parseOptions:r,errorOnInvalidContent:t??i.options.enableContentCheck})};function z1(e,t){let n=T1(t,e.schema),{from:r,to:i,empty:a}=e.selection,o=[];a?(e.storedMarks&&o.push(...e.storedMarks),o.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,i,e=>{o.push(...e.marks)});let s=o.find(e=>e.type.name===n.name);return s?{...s.attrs}:{}}function B1(e,t){let n=new jX(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function Bje(e){for(let t=0;t{n(e)&&r.push({node:e,pos:t})}),r}function Hje(e,t){for(let n=e.depth;n>0;--n){let r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function V1(e){return t=>Hje(t.$from,e)}function H1(e,t,n){return e.config[t]===void 0&&e.parent?H1(e.parent,t,n):typeof e.config[t]==`function`?e.config[t].bind({...n,parent:e.parent?H1(e.parent,t,n):null}):e.config[t]}function U1(e){return e.map(e=>{let t=H1(e,`addExtensions`,{name:e.name,options:e.options,storage:e.storage});return t?[e,...U1(t())]:e}).flat(10)}function W1(e,t){let n=RY.fromSchema(t).serializeFragment(e),r=document.implementation.createHTMLDocument().createElement(`div`);return r.appendChild(n),r.innerHTML}function G1(e){return typeof e==`function`}function K1(e,t=void 0,...n){return G1(e)?t?e.bind(t)(...n):e(...n):e}function Uje(e={}){return Object.keys(e).length===0&&e.constructor===Object}function q1(e){return{baseExtensions:e.filter(e=>e.type===`extension`),nodeExtensions:e.filter(e=>e.type===`node`),markExtensions:e.filter(e=>e.type===`mark`)}}function J1(e){let t=[],{nodeExtensions:n,markExtensions:r}=q1(e),i=[...n,...r],a={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1};return e.forEach(e=>{let n=H1(e,`addGlobalAttributes`,{name:e.name,options:e.options,storage:e.storage,extensions:i});n&&n().forEach(e=>{e.types.forEach(n=>{Object.entries(e.attributes).forEach(([e,r])=>{t.push({type:n,name:e,attribute:{...a,...r}})})})})}),i.forEach(e=>{let n=H1(e,`addAttributes`,{name:e.name,options:e.options,storage:e.storage});if(!n)return;let r=n();Object.entries(r).forEach(([n,r])=>{let i={...a,...r};typeof i?.default==`function`&&(i.default=i.default()),i?.isRequired&&i?.default===void 0&&delete i.default,t.push({type:e.name,name:n,attribute:i})})}),t}function Y1(...e){return e.filter(e=>!!e).reduce((e,t)=>{let n={...e};return Object.entries(t).forEach(([e,t])=>{if(!n[e]){n[e]=t;return}if(e===`class`){let r=t?String(t).split(` `):[],i=n[e]?n[e].split(` `):[],a=r.filter(e=>!i.includes(e));n[e]=[...i,...a].join(` `)}else if(e===`style`){let r=t?t.split(`;`).map(e=>e.trim()).filter(Boolean):[],i=n[e]?n[e].split(`;`).map(e=>e.trim()).filter(Boolean):[],a=new Map;i.forEach(e=>{let[t,n]=e.split(`:`).map(e=>e.trim());a.set(t,n)}),r.forEach(e=>{let[t,n]=e.split(`:`).map(e=>e.trim());a.set(t,n)}),n[e]=Array.from(a.entries()).map(([e,t])=>`${e}: ${t}`).join(`; `)}else n[e]=t}),n},{})}function X1(e,t){return t.filter(t=>t.type===e.type.name).filter(e=>e.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(e.attrs)||{}:{[t.name]:e.attrs[t.name]}).reduce((e,t)=>Y1(e,t),{})}function Wje(e){return typeof e==`string`?e.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(e):e===`true`?!0:e===`false`?!1:e:e}function Z1(e,t){return`style`in e?e:{...e,getAttrs:n=>{let r=e.getAttrs?e.getAttrs(n):e.attrs;if(r===!1)return!1;let i=t.reduce((e,t)=>{let r=t.attribute.parseHTML?t.attribute.parseHTML(n):Wje(n.getAttribute(t.name));return r==null?e:{...e,[t.name]:r}},{});return{...r,...i}}}}function Q1(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>e===`attrs`&&Uje(t)?!1:t!=null))}function $1(e){let t={};return!e?.attribute?.isRequired&&`default`in(e?.attribute||{})&&(t.default=e.attribute.default),e?.attribute?.validate!==void 0&&(t.validate=e.attribute.validate),[e.name,t]}function Gje(e,t){let n=J1(e),{nodeExtensions:r,markExtensions:i}=q1(e);return new TY({topNode:r.find(e=>H1(e,`topNode`))?.name,nodes:Object.fromEntries(r.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=Q1({...e.reduce((e,t)=>{let n=H1(t,`extendNodeSchema`,a);return{...e,...n?n(r):{}}},{}),content:K1(H1(r,`content`,a)),marks:K1(H1(r,`marks`,a)),group:K1(H1(r,`group`,a)),inline:K1(H1(r,`inline`,a)),atom:K1(H1(r,`atom`,a)),selectable:K1(H1(r,`selectable`,a)),draggable:K1(H1(r,`draggable`,a)),code:K1(H1(r,`code`,a)),whitespace:K1(H1(r,`whitespace`,a)),linebreakReplacement:K1(H1(r,`linebreakReplacement`,a)),defining:K1(H1(r,`defining`,a)),isolating:K1(H1(r,`isolating`,a)),attrs:Object.fromEntries(i.map($1))}),s=K1(H1(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>Z1(e,i)));let c=H1(r,`renderHTML`,a);c&&(o.toDOM=e=>c({node:e,HTMLAttributes:X1(e,i)}));let l=H1(r,`renderText`,a);return l&&(o.toText=l),[r.name,o]})),marks:Object.fromEntries(i.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=Q1({...e.reduce((e,t)=>{let n=H1(t,`extendMarkSchema`,a);return{...e,...n?n(r):{}}},{}),inclusive:K1(H1(r,`inclusive`,a)),excludes:K1(H1(r,`excludes`,a)),group:K1(H1(r,`group`,a)),spanning:K1(H1(r,`spanning`,a)),code:K1(H1(r,`code`,a)),attrs:Object.fromEntries(i.map($1))}),s=K1(H1(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>Z1(e,i)));let c=H1(r,`renderHTML`,a);return c&&(o.toDOM=e=>c({mark:e,HTMLAttributes:X1(e,i)})),[r.name,o]}))})}function Kje(e){let t=e.filter((t,n)=>e.indexOf(t)!==n);return Array.from(new Set(t))}function e0(e){return e.sort((e,t)=>{let n=H1(e,`priority`)||100,r=H1(t,`priority`)||100;return n>r?-1:+(ne.name));return n.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${n.map(e=>`'${e}'`).join(`, `)}]. This can lead to issues.`),t}function n0(e,t,n){let{from:r,to:i}=t,{blockSeparator:a=` +`))),0,0),e.someProp(`transformPasted`,t=>{s=t(s,e,!0)}),s;let n=e.someProp(`clipboardTextParser`,n=>n(t,i,r,e));if(n)s=n;else{let n=i.marks(),{schema:r}=e.state,a=RY.fromSchema(r);o=document.createElement(`div`),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=o.appendChild(document.createElement(`p`));e&&t.appendChild(a.serializeNode(r.text(e,n)))})}}else e.someProp(`transformPastedHTML`,t=>{n=t(n,e)}),o=Xke(n),ZZ&&Zke(o);let l=o&&o.querySelector(`[data-pm-slice]`),u=l&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(l.getAttribute(`data-pm-slice`)||``);if(u&&u[3])for(let e=+u[3];e>0;e--){let e=o.firstChild;for(;e&&e.nodeType!=1;)e=e.nextSibling;if(!e)break;o=e}if(s||=(e.someProp(`clipboardParser`)||e.someProp(`domParser`)||DY.fromSchema(e.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||u),context:i,ruleFromNode(e){return e.nodeName==`BR`&&!e.nextSibling&&e.parentNode&&!Kke.test(e.parentNode.nodeName)?{ignore:!0}:null}}),u)s=Qke(d$(s,+u[1],+u[2]),u[4]);else if(s=QJ.maxOpen(qke(s.content,i),!0),s.openStart||s.openEnd){let e=0,t=0;for(let t=s.content.firstChild;e{s=t(s,e,c)}),s}var Kke=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function qke(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.index(n)),i,a=[];if(e.forEach(e=>{if(!a)return;let t=r.findWrapping(e.type),n;if(!t)return a=null;if(n=a.length&&i.length&&c$(t,i,e,a[a.length-1],0))a[a.length-1]=n;else{a.length&&(a[a.length-1]=l$(a[a.length-1],i.length));let n=s$(e,t);a.push(n),r=r.matchType(n.type),i=t}}),a)return KJ.from(a)}return e}function s$(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,KJ.from(e));return e}function c$(e,t,n,r,i){if(i1&&(a=0),i=n&&(s=t<0?o.contentMatchAt(0).fillBefore(s,a<=i).append(s):s.append(o.contentMatchAt(o.childCount).fillBefore(KJ.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(s))}function d$(e,t,n){return te}),m$.createHTML(e)):e}function Xke(e){let t=/^(\s*]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n=p$().createElement(`div`),r=/<([a-z][^>\s]+)/i.exec(e),i;if((i=r&&f$[r[1].toLowerCase()])&&(e=i.map(e=>`<`+e+`>`).join(``)+e+i.map(e=>``).reverse().join(``)),n.innerHTML=Yke(e),i)for(let e=0;e=0;e-=2){let t=n.nodes[r[e]];if(!t||t.hasRequiredAttrs())break;i=KJ.from(t.create(r[e+1],i)),a++,o++}return new QJ(i,a,o)}var h$={},g$={},$ke={touchstart:!0,touchmove:!0},eAe=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:``,button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function tAe(e){for(let t in h$){let n=h$[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{rAe(e,t)&&!y$(e,t)&&(e.editable||!(t.type in g$))&&n(e,t)},$ke[t]?{passive:!0}:void 0)}KZ&&e.dom.addEventListener(`input`,()=>null),v$(e)}function _$(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function nAe(e){e.domObserver.stop();for(let t in e.input.eventHandlers)e.dom.removeEventListener(t,e.input.eventHandlers[t]);clearTimeout(e.input.composingTimeout),clearTimeout(e.input.lastIOSEnterFallbackTimeout)}function v$(e){e.someProp(`handleDOMEvents`,t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>y$(e,t))})}function y$(e,t){return e.someProp(`handleDOMEvents`,n=>{let r=n[t.type];return r?r(e,t)||t.defaultPrevented:!1})}function rAe(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function iAe(e,t){!y$(e,t)&&h$[t.type]&&(e.editable||!(t.type in g$))&&h$[t.type](e,t)}g$.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=n.keyCode==16||n.shiftKey,!T$(e,n)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!(XZ&&WZ&&n.keyCode==13)))if(n.keyCode!=229&&e.domObserver.forceFlush(),qZ&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp(`handleKeyDown`,t=>t(e,NZ(13,`Enter`))),e.input.lastIOSEnter=0)},200)}else e.someProp(`handleKeyDown`,t=>t(e,n))||Gke(e,n)?n.preventDefault():_$(e,`key`)},g$.keyup=(e,t)=>{t.keyCode==16&&(e.input.shiftKey=!1)},g$.keypress=(e,t)=>{let n=t;if(T$(e,n)||!n.charCode||n.ctrlKey&&!n.altKey||JZ&&n.metaKey)return;if(e.someProp(`handleKeyPress`,t=>t(e,n))){n.preventDefault();return}let r=e.state.selection;if(!(r instanceof IX)||!r.$from.sameParent(r.$to)){let t=String.fromCharCode(n.charCode),i=()=>e.state.tr.insertText(t).scrollIntoView();!/[\r\n]/.test(t)&&!e.someProp(`handleTextInput`,n=>n(e,r.$from.pos,r.$to.pos,t,i))&&e.dispatch(i()),n.preventDefault()}};function b$(e){return{left:e.clientX,top:e.clientY}}function aAe(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}function x$(e,t,n,r,i){if(r==-1)return!1;let a=e.state.doc.resolve(r);for(let r=a.depth+1;r>0;r--)if(e.someProp(t,t=>r>a.depth?t(e,n,a.nodeAfter,a.before(r),i,!0):t(e,n,a.node(r),a.before(r),i,!1)))return!0;return!1}function S$(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let r=e.state.tr.setSelection(t);n==`pointer`&&r.setMeta(`pointer`,!0),e.dispatch(r)}function oAe(e,t){if(t==-1)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return r&&r.isAtom&&RX.isSelectable(r)?(S$(e,new RX(n),`pointer`),!0):!1}function sAe(e,t){if(t==-1)return!1;let n=e.state.selection,r,i;n instanceof RX&&(r=n.node);let a=e.state.doc.resolve(t);for(let e=a.depth+1;e>0;e--){let t=e>a.depth?a.nodeAfter:a.node(e);if(RX.isSelectable(t)){i=r&&n.$from.depth>0&&e>=n.$from.depth&&a.before(n.$from.depth+1)==n.$from.pos?a.before(n.$from.depth):a.before(e);break}}return i==null?!1:(S$(e,RX.create(e.state.doc,i),`pointer`),!0)}function cAe(e,t,n,r,i){return x$(e,`handleClickOn`,t,n,r)||e.someProp(`handleClick`,n=>n(e,t,r))||(i?sAe(e,n):oAe(e,n))}function lAe(e,t,n,r){return x$(e,`handleDoubleClickOn`,t,n,r)||e.someProp(`handleDoubleClick`,n=>n(e,t,r))}function uAe(e,t,n,r){return x$(e,`handleTripleClickOn`,t,n,r)||e.someProp(`handleTripleClick`,n=>n(e,t,r))||dAe(e,n,r)}function dAe(e,t,n){if(n.button!=0)return!1;let r=e.state.doc;if(t==-1)return r.inlineContent?(S$(e,IX.create(r,0,r.content.size),`pointer`),!0):!1;let i=r.resolve(t);for(let t=i.depth+1;t>0;t--){let n=t>i.depth?i.nodeAfter:i.node(t),a=i.before(t);if(n.inlineContent)S$(e,IX.create(r,a+1,a+1+n.content.size),`pointer`);else if(RX.isSelectable(n))S$(e,RX.create(r,a),`pointer`);else continue;return!0}}function C$(e){return O$(e)}var w$=JZ?`metaKey`:`ctrlKey`;h$.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=C$(e),i=Date.now(),a=`singleClick`;i-e.input.lastClick.time<500&&aAe(n,e.input.lastClick)&&!n[w$]&&e.input.lastClick.button==n.button&&(e.input.lastClick.type==`singleClick`?a=`doubleClick`:e.input.lastClick.type==`doubleClick`&&(a=`tripleClick`)),e.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:a,button:n.button};let o=e.posAtCoords(b$(n));o&&(a==`singleClick`?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new fAe(e,o,n,!!r)):(a==`doubleClick`?lAe:uAe)(e,o.pos,o.inside,n)?n.preventDefault():_$(e,`pointer`))};var fAe=class{constructor(e,t,n,r){this.view=e,this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[w$],this.allowDefault=n.shiftKey;let i,a;if(t.inside>-1)i=e.state.doc.nodeAt(t.inside),a=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,a=n.depth?n.before():0}let o=r?null:n.target,s=o?e.docView.nearestDesc(o,!0):null;this.target=s&&s.nodeDOM.nodeType==1?s.nodeDOM:null;let{selection:c}=e.state;(n.button==0&&i.type.spec.draggable&&i.type.spec.selectable!==!1||c instanceof RX&&c.from<=a&&c.to>a)&&(this.mightDrag={node:i,pos:a,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&HZ&&!this.target.hasAttribute(`contentEditable`))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute(`contentEditable`,`false`)},20),this.view.domObserver.start()),e.root.addEventListener(`mouseup`,this.up=this.up.bind(this)),e.root.addEventListener(`mousemove`,this.move=this.move.bind(this)),_$(e,`pointer`)}done(){this.view.root.removeEventListener(`mouseup`,this.up),this.view.root.removeEventListener(`mousemove`,this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute(`draggable`),this.mightDrag.setUneditable&&this.target.removeAttribute(`contentEditable`),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>LQ(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(b$(e))),this.updateAllowDefault(e),this.allowDefault||!t?_$(this.view,`pointer`):cAe(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||KZ&&this.mightDrag&&!this.mightDrag.node.isAtom||WZ&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(S$(this.view,NX.near(this.view.state.doc.resolve(t.pos)),`pointer`),e.preventDefault()):_$(this.view,`pointer`)}move(e){this.updateAllowDefault(e),_$(this.view,`pointer`),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}};h$.touchstart=e=>{e.input.lastTouch=Date.now(),C$(e),_$(e,`pointer`)},h$.touchmove=e=>{e.input.lastTouch=Date.now(),_$(e,`pointer`)},h$.contextmenu=e=>C$(e);function T$(e,t){return e.composing?!0:KZ&&Math.abs(t.timeStamp-e.input.compositionEndedAt)<500?(e.input.compositionEndedAt=-2e8,!0):!1}var pAe=XZ?5e3:-1;g$.compositionstart=g$.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof IX&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>e.type.spec.inclusive===!1)||WZ&&YZ&&mAe(e)))e.markCursor=e.state.storedMarks||n.marks(),O$(e,!0),e.markCursor=null;else if(O$(e,!t.selection.empty),HZ&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,r=t.focusOffset;n&&n.nodeType==1&&r!=0;){let t=r<0?n.lastChild:n.childNodes[r-1];if(!t)break;if(t.nodeType==3){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}else n=t,r=-1}}e.input.composing=!0}E$(e,pAe)};function mAe(e){let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(!t||t.nodeType!=1||n>=t.childNodes.length)return!1;let r=t.childNodes[n];return r.nodeType==1&&r.contentEditable==`false`}g$.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.badSafariComposition?e.domObserver.forceFlush():e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,E$(e,20))};function E$(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>O$(e),t))}function D$(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=gAe());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function hAe(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=oke(t.focusNode,t.focusOffset),r=ske(t.focusNode,t.focusOffset);if(n&&r&&n!=r){let t=r.pmViewDesc,i=e.domObserver.lastChangedTextNode;if(n==i||r==i)return i;if(!t||!t.isText(r.nodeValue))return r;if(e.input.compositionNode==r){let e=n.pmViewDesc;if(!(!e||!e.isText(n.nodeValue)))return r}}return n||r}function gAe(){let e=document.createEvent(`Event`);return e.initEvent(`event`,!0,!0),e.timeStamp}function O$(e,t=!1){if(!(XZ&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),D$(e),t||e.docView&&e.docView.dirty){let n=FQ(e),r=e.state.selection;return n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):(e.markCursor||t)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.dispatch(e.state.tr.deleteSelection()):e.updateState(e.state),!0}return!1}}function _Ae(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement(`div`));n.appendChild(t),n.style.cssText=`position: fixed; left: -10000px; top: 10px`;let r=getSelection(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}var k$=BZ&&VZ<15||qZ&&dke<604;h$.copy=g$.cut=(e,t)=>{let n=t,r=e.state.selection,i=n.type==`cut`;if(r.empty)return;let a=k$?null:n.clipboardData,{dom:o,text:s}=a$(e,r.content());a?(n.preventDefault(),a.clearData(),a.setData(`text/html`,o.innerHTML),a.setData(`text/plain`,s)):_Ae(e,o),i&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta(`uiEvent`,`cut`))};function vAe(e){return e.openStart==0&&e.openEnd==0&&e.content.childCount==1?e.content.firstChild:null}function yAe(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?`textarea`:`div`));n||(r.contentEditable=`true`),r.style.cssText=`position: fixed; left: -10000px; top: 10px`,r.focus();let i=e.input.shiftKey&&e.input.lastKeyCode!=45;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?A$(e,r.value,null,i,t):A$(e,r.textContent,r.innerHTML,i,t)},50)}function A$(e,t,n,r,i){let a=o$(e,t,n,r,e.state.selection.$from);if(e.someProp(`handlePaste`,t=>t(e,i,a||QJ.empty)))return!0;if(!a)return!1;let o=vAe(a),s=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(a);return e.dispatch(s.scrollIntoView().setMeta(`paste`,!0).setMeta(`uiEvent`,`paste`)),!0}function j$(e){let t=e.getData(`text/plain`)||e.getData(`Text`);if(t)return t;let n=e.getData(`text/uri-list`);return n?n.replace(/\r?\n/g,` `):``}g$.paste=(e,t)=>{let n=t;if(e.composing&&!XZ)return;let r=k$?null:n.clipboardData,i=e.input.shiftKey&&e.input.lastKeyCode!=45;r&&A$(e,j$(r),r.getData(`text/html`),i,n)?n.preventDefault():yAe(e,n)};var M$=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},bAe=JZ?`altKey`:`ctrlKey`;function N$(e,t){return e.someProp(`dragCopies`,e=>!e(t))??!t[bAe]}h$.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=e.state.selection,a=i.empty?null:e.posAtCoords(b$(n)),o;if(!(a&&a.pos>=i.from&&a.pos<=(i instanceof RX?i.to-1:i.to))){if(r&&r.mightDrag)o=RX.create(e.state.doc,r.mightDrag.pos);else if(n.target&&n.target.nodeType==1){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&(o=RX.create(e.state.doc,t.posBefore))}}let{dom:s,text:c,slice:l}=a$(e,(o||e.state.selection).content());(!n.dataTransfer.files.length||!WZ||GZ>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(k$?`Text`:`text/html`,s.innerHTML),n.dataTransfer.effectAllowed=`copyMove`,k$||n.dataTransfer.setData(`text/plain`,c),e.dragging=new M$(l,N$(e,n),o)},h$.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},g$.dragover=g$.dragenter=(e,t)=>t.preventDefault(),g$.drop=(e,t)=>{try{xAe(e,t,e.dragging)}finally{e.dragging=null}};function xAe(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(b$(t));if(!r)return;let i=e.state.doc.resolve(r.pos),a=n&&n.slice;a?e.someProp(`transformPasted`,t=>{a=t(a,e,!1)}):a=o$(e,j$(t.dataTransfer),k$?null:t.dataTransfer.getData(`text/html`),!1,i);let o=!!(n&&N$(e,t));if(e.someProp(`handleDrop`,n=>n(e,t,a||QJ.empty,o))){t.preventDefault();return}if(!a)return;t.preventDefault();let s=a?vX(e.state.doc,i.pos,a):i.pos;s??=i.pos;let c=e.state.tr;if(o){let{node:e}=n;e?e.replace(c):c.deleteSelection()}let l=c.mapping.map(s),u=a.openStart==0&&a.openEnd==0&&a.content.childCount==1,d=c.doc;if(u?c.replaceRangeWith(l,l,a.content.firstChild):c.replaceRange(l,l,a),c.doc.eq(d))return;let f=c.doc.resolve(l);if(u&&RX.isSelectable(a.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(a.content.firstChild))c.setSelection(new RX(f));else{let t=c.mapping.map(s);c.mapping.maps[c.mapping.maps.length-1].forEach((e,n,r,i)=>t=i),c.setSelection(WQ(e,f,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta(`uiEvent`,`drop`))}h$.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add(`ProseMirror-focused`),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&LQ(e)},20))},h$.blur=(e,t)=>{let n=t;e.focused&&=(e.domObserver.stop(),e.dom.classList.remove(`ProseMirror-focused`),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),!1)},h$.beforeinput=(e,t)=>{if(WZ&&XZ&&t.inputType==`deleteContentBackward`){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t||(e.dom.blur(),e.focus(),e.someProp(`handleKeyDown`,t=>t(e,NZ(8,`Backspace`)))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())},50)}};for(let e in g$)h$[e]=g$[e];function P$(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}var F$=class e{constructor(e,t){this.toDOM=e,this.spec=t||z$,this.side=this.spec.side||0}map(e,t,n,r){let{pos:i,deleted:a}=e.mapResult(t.from+r,this.side<0?-1:1);return a?null:new L$(i-n,i-n,this)}valid(){return!0}eq(t){return this==t||t instanceof e&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&P$(this.spec,t.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},I$=class e{constructor(e,t){this.attrs=e,this.spec=t||z$}map(e,t,n,r){let i=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,a=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return i>=a?null:new L$(i,a,this)}valid(e,t){return t.from=e&&(!i||i(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let a=0;ae){let o=this.children[a]+1;this.children[a+2].findInner(e-o,t-o,n,r+o,i)}}map(e,t,n){return this==V$||e.maps.length==0?this:this.mapInner(e,t,0,0,n||z$)}mapInner(t,n,r,i,a){let o;for(let e=0;e{let o=t+r,s;if(s=W$(n,e,o)){for(i||=this.children.slice();aa&&n.to=t){this.children[e]==t&&(r=this.children[e+2]);break}let a=t+1,o=a+n.content.size;for(let e=0;ea&&t.type instanceof I$){let e=Math.max(a,t.from)-a,n=Math.min(o,t.to)-a;ee.map(t,n,z$));return e.from(r)}forChild(t,n){if(n.isLeaf)return B$.empty;let r=[];for(let i=0;ie instanceof B$)?t:t.reduce((e,t)=>e.concat(t instanceof B$?t:t.members),[]))}}forEachSet(e){for(let t=0;t{let o=a-i-(n-e);for(let i=0;ia+t-r)continue;let c=s[i]+t-r;n>=c?s[i+1]=e<=c?-2:-1:e>=t&&o&&(s[i]+=o,s[i+1]+=o)}r+=o}),t=n.maps[e].map(t,-1)}let c=!1;for(let t=0;t=r.content.size){c=!0;continue}let d=n.map(e[t+1]+a,-1)-i,{index:f,offset:p}=r.content.findIndex(u),m=r.maybeChild(f);if(m&&p==u&&p+m.nodeSize==d){let r=s[t+2].mapInner(n,m,l+1,e[t]+a+1,o);r==V$?(s[t+1]=-2,c=!0):(s[t]=u,s[t+1]=d,s[t+2]=r)}else c=!0}if(c){let c=K$(wAe(s,e,t,n,i,a,o),r,0,o);t=c.local;for(let e=0;en&&a.to{let s=W$(e,t,o+n);if(s){a=!0;let e=K$(s,t,n+o+1,r);e!=V$&&i.push(o,o+t.nodeSize,e)}});let o=U$(a?G$(e):e,-n).sort(q$);for(let e=0;e0;)t++;e.splice(t,0,n)}function X$(e){let t=[];return e.someProp(`decorations`,n=>{let r=n(e.state);r&&r!=V$&&t.push(r)}),e.cursorWrapper&&t.push(B$.create(e.state.doc,[e.cursorWrapper.deco])),H$.from(t)}var TAe={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},EAe=BZ&&VZ<=11,DAe=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}},OAe=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new DAe,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(t=>{for(let e=0;ee.type==`childList`&&e.removedNodes.length||e.type==`characterData`&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():KZ&&e.composing&&t.some(e=>e.type==`childList`&&e.target.nodeName==`TR`)?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),EAe&&(this.onCharData=e=>{this.queue.push({target:e.target,type:`characterData`,oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,TAe)),this.onCharData&&this.view.dom.addEventListener(`DOMCharacterDataModified`,this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;tthis.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener(`DOMCharacterDataModified`,this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener(`selectionchange`,this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener(`selectionchange`,this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(GQ(this.view)){if(this.suppressingSelectionUpdates)return LQ(this.view);if(BZ&&VZ<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&OZ(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let n=e.focusNode;n;n=TZ(n))t.add(n);for(let r=e.anchorNode;r;r=TZ(r))if(t.has(r)){n=r;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:`selection`,target:n.nodeType==3?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&GQ(e)&&!this.ignoreSelectionChange(n),i=-1,a=-1,o=!1,s=[];if(e.editable)for(let e=0;ee.nodeName==`BR`)&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let e of s)if(e.nodeName==`BR`&&e.parentNode){let t=e.nextSibling;t&&t.nodeType==1&&t.contentEditable==`false`&&e.parentNode.removeChild(e)}}else if(HZ&&s.length){let t=s.filter(e=>e.nodeName==`BR`);if(t.length==2){let[e,n]=t;e.parentNode&&e.parentNode.parentNode==n.parentNode?n.remove():e.remove()}else{let{focusNode:n}=this.currentSelection;for(let r of t){let t=r.parentNode;t&&t.nodeName==`LI`&&(!n||jAe(e,n)!=t)&&r.remove()}}}let c=null;i<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||r)&&(i>-1&&(e.docView.markDirty(i,a),kAe(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,MAe(e,s)),this.handleDOMChange(i,a,o,s),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||LQ(e),this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type==`attributes`&&(n==this.view.docView||e.attributeName==`contenteditable`||e.attributeName==`style`&&!e.oldValue&&!e.target.getAttribute(`style`))||!n||n.ignoreMutation(e))return null;if(e.type==`childList`){for(let n=0;ni;e--){let t=r.childNodes[e-1],n=t.pmViewDesc;if(t.nodeName==`BR`&&!n){a=e;break}if(!n||n.size)break}let d=e.state.doc,f=e.someProp(`domParser`)||DY.fromSchema(e.state.schema),p=d.resolve(o),m=null,h=f.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:a,preserveWhitespace:p.parent.type.whitespace==`pre`?`full`:!0,findPositions:l,ruleFromNode:PAe,context:p});if(l&&l[0].pos!=null){let e=l[0].pos,t=l[1]&&l[1].pos;t??=e,m={anchor:e+o,head:t+o}}return{doc:h,sel:m,from:o,to:s}}function PAe(e){let t=e.pmViewDesc;if(t)return t.parseRule();if(e.nodeName==`BR`&&e.parentNode){if(KZ&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let e=document.createElement(`div`);return e.appendChild(document.createElement(`li`)),{skip:e}}else if(e.parentNode.lastChild==e||KZ&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if(e.nodeName==`IMG`&&e.getAttribute(`mark-placeholder`))return{ignore:!0};return null}var FAe=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function IAe(e,t,n,r,i){let a=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=FQ(e,t);if(n&&!e.state.selection.eq(n)){if(WZ&&XZ&&e.input.lastKeyCode===13&&Date.now()-100t(e,NZ(13,`Enter`))))return;let r=e.state.tr.setSelection(n);t==`pointer`?r.setMeta(`pointer`,!0):t==`key`&&r.scrollIntoView(),a&&r.setMeta(`composition`,a),e.dispatch(r)}return}let o=e.state.doc.resolve(t),s=o.sharedDepth(n);t=o.before(s+1),n=e.state.doc.resolve(n).after(s+1);let c=e.state.selection,l=NAe(e,t,n),u=e.state.doc,d=u.slice(l.from,l.to),f,p;e.input.lastKeyCode===8&&Date.now()-100Date.now()-225||XZ)&&i.some(e=>e.nodeType==1&&!FAe.test(e.nodeName))&&(!m||m.endA>=m.endB)&&e.someProp(`handleKeyDown`,t=>t(e,NZ(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(!m)if(r&&c instanceof IX&&!c.empty&&c.$head.sameParent(c.$anchor)&&!e.composing&&!(l.sel&&l.sel.anchor!=l.sel.head))m={start:c.from,endA:c.to,endB:c.to};else{if(l.sel){let t=e1(e,e.state.doc,l.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);a&&n.setMeta(`composition`,a),e.dispatch(n)}}return}e.state.selection.frome.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=l.from?m.start=e.state.selection.from:m.endA=e.state.selection.to-2&&e.state.selection.to<=l.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),BZ&&VZ<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>l.from&&l.doc.textBetween(m.start-l.from-1,m.start-l.from+1)==` \xA0`&&(m.start--,m.endA--,m.endB--);let h=l.doc.resolveNoCache(m.start-l.from),g=l.doc.resolveNoCache(m.endB-l.from),_=u.resolve(m.start),v=h.sameParent(g)&&h.parent.inlineContent&&_.end()>=m.endA;if((qZ&&e.input.lastIOSEnter>Date.now()-225&&(!v||i.some(e=>e.nodeName==`DIV`||e.nodeName==`P`))||!v&&h.post(e,NZ(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>m.start&&RAe(u,m.start,m.endA,h,g)&&e.someProp(`handleKeyDown`,t=>t(e,NZ(8,`Backspace`)))){XZ&&WZ&&e.domObserver.suppressSelectionUpdates();return}WZ&&m.endB==m.start&&(e.input.lastChromeDelete=Date.now()),XZ&&!v&&h.start()!=g.start()&&g.parentOffset==0&&h.depth==g.depth&&l.sel&&l.sel.anchor==l.sel.head&&l.sel.head==m.endA&&(m.endB-=2,g=l.doc.resolveNoCache(m.endB-l.from),setTimeout(()=>{e.someProp(`handleKeyDown`,function(t){return t(e,NZ(13,`Enter`))})},20));let y=m.start,b=m.endA,x=t=>{let n=t||e.state.tr.replace(y,b,l.doc.slice(m.start-l.from,m.endB-l.from));if(l.sel){let t=e1(e,n.doc,l.sel);t&&!(WZ&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastChromeDeleteLQ(e),20));let t=x(e.state.tr.delete(y,b)),n=u.resolve(m.start).marksAcross(u.resolve(m.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(m.endA==m.endB&&(S=LAe(h.parent.content.cut(h.parentOffset,g.parentOffset),_.parent.content.cut(_.parentOffset,m.endA-_.start())))){let t=x(e.state.tr);S.type==`add`?t.addMark(y,b,S.mark):t.removeMark(y,b,S.mark),e.dispatch(t)}else if(h.parent.child(h.index()).isText&&h.index()==g.index()-+!g.textOffset){let t=h.parent.textBetween(h.parentOffset,g.parentOffset),n=()=>x(e.state.tr.insertText(t,y,b));e.someProp(`handleTextInput`,r=>r(e,y,b,t,n))||e.dispatch(n())}else e.dispatch(x());else e.dispatch(x())}function e1(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:WQ(e,t.resolve(n.anchor),t.resolve(n.head))}function LAe(e,t){let n=e.firstChild.marks,r=t.firstChild.marks,i=n,a=r,o,s,c;for(let e=0;ee.mark(s.addToSet(e.marks));else if(i.length==0&&a.length==1)s=a[0],o=`remove`,c=e=>e.mark(s.removeFromSet(e.marks));else return null;let l=[];for(let e=0;en||t1(o,!0,!1)0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}function zAe(e,t,n,r,i){let a=e.findDiffStart(t,n);if(a==null)return null;let{a:o,b:s}=e.findDiffEnd(t,n+e.size,n+t.size);if(i==`end`){let e=Math.max(0,a-Math.min(o,s));r-=o+e-a}if(o=o?a-r:0;a-=e,a&&a=s?a-r:0;a-=t,a&&a=56320&&t<=57343&&n>=55296&&n<=56319}var r1=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new eAe,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(c1),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement(`div`),e&&(e.appendChild?e.appendChild(this.dom):typeof e==`function`?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=o1(this),a1(this),this.nodeViews=s1(this),this.docView=CQ(this.state.doc,i1(this),X$(this),this.dom,this),this.domObserver=new OAe(this,(e,t,n,r)=>IAe(this,e,t,n,r)),this.domObserver.start(),tAe(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&v$(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(c1),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){let n=this.state,r=!1,i=!1;e.storedMarks&&this.composing&&(D$(this),i=!0),this.state=e;let a=n.plugins!=e.plugins||this._props.plugins!=t.plugins;if(a||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=s1(this);VAe(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}(a||t.handleDOMEvents!=this._props.handleDOMEvents)&&v$(this),this.editable=o1(this),a1(this);let o=X$(this),s=i1(this),c=n.plugins!=e.plugins&&!n.doc.eq(e.doc)?`reset`:e.scrollToSelection>n.scrollToSelection?`to selection`:`preserve`,l=r||!this.docView.matchesNode(e.doc,s,o);(l||!e.selection.eq(n.selection))&&(i=!0);let u=c==`preserve`&&i&&this.dom.style.overflowAnchor==null&&mke(this);if(i){this.domObserver.stop();let t=l&&(BZ||WZ)&&!this.composing&&!n.selection.empty&&!e.selection.empty&&BAe(n.selection,e.selection);if(l){let n=WZ?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=hAe(this)),(r||!this.docView.update(e.doc,s,o,this))&&(this.docView.updateOuterDeco(s),this.docView.destroy(),this.docView=CQ(e.doc,s,o,this.dom,this)),n&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(t=!0)}t||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Rke(this))?LQ(this,t):(HQ(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(n),this.dragging?.node&&!n.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,n),c==`reset`?this.dom.scrollTop=0:c==`to selection`?this.scrollToSelection():u&&hke(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))&&!this.someProp(`handleScrollToSelection`,e=>e(this)))if(this.state.selection instanceof RX){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&$Z(this,t.getBoundingClientRect(),e)}else $Z(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let e=0;e0&&this.state.doc.nodeAt(e))==n.node&&(r=e)}this.dragging=new M$(e.slice,e.move,r<0?void 0:RX.create(this.state.doc,r))}someProp(e,t){let n=this._props&&this._props[e],r;if(n!=null&&(r=t?t(n):n))return r;for(let n=0;ne.ownerDocument.getSelection()),this._root=e}return e||document}updateRoot(){this._root=null}posAtCoords(e){return xke(this,e)}coordsAtPos(e,t=1){return cQ(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(r==null)throw RangeError(`DOM position not inside the editor`);return r}endOfTextblock(e,t){return Eke(this,t||this.state,e)}pasteHTML(e,t){return A$(this,``,e,!1,t||new ClipboardEvent(`paste`))}pasteText(e,t){return A$(this,e,null,!0,t||new ClipboardEvent(`paste`))}serializeForClipboard(e){return a$(this,e)}destroy(){this.docView&&(nAe(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],X$(this),this),this.dom.textContent=``):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,ike())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return iAe(this,e)}domSelectionRange(){let e=this.domSelection();return e?KZ&&this.root.nodeType===11&&lke(this.dom.ownerDocument)==this.dom&&AAe(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};r1.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};function i1(e){let t=Object.create(null);return t.class=`ProseMirror`,t.contenteditable=String(e.editable),e.someProp(`attributes`,n=>{if(typeof n==`function`&&(n=n(e.state)),n)for(let e in n)e==`class`?t.class+=` `+n[e]:e==`style`?t.style=(t.style?t.style+`;`:``)+n[e]:!t[e]&&e!=`contenteditable`&&e!=`nodeName`&&(t[e]=String(n[e]))}),t.translate||=`no`,[L$.node(0,e.state.doc.content.size,t)]}function a1(e){if(e.markCursor){let t=document.createElement(`img`);t.className=`ProseMirror-separator`,t.setAttribute(`mark-placeholder`,`true`),t.setAttribute(`alt`,``),e.cursorWrapper={dom:t,deco:L$.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function o1(e){return!e.someProp(`editable`,t=>t(e.state)===!1)}function BAe(e,t){let n=Math.min(e.$anchor.sharedDepth(e.head),t.$anchor.sharedDepth(t.head));return e.$anchor.start(n)!=t.$anchor.start(n)}function s1(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp(`nodeViews`,n),e.someProp(`markViews`,n),t}function VAe(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r}function c1(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError(`Plugins passed directly to the view must not have a state component`)}for(var l1={8:`Backspace`,9:`Tab`,10:`Enter`,12:`NumLock`,13:`Enter`,16:`Shift`,17:`Control`,18:`Alt`,20:`CapsLock`,27:`Escape`,32:` `,33:`PageUp`,34:`PageDown`,35:`End`,36:`Home`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`,44:`PrintScreen`,45:`Insert`,46:`Delete`,59:`;`,61:`=`,91:`Meta`,92:`Meta`,106:`*`,107:`+`,108:`,`,109:`-`,110:`.`,111:`/`,144:`NumLock`,145:`ScrollLock`,160:`Shift`,161:`Shift`,162:`Control`,163:`Control`,164:`Alt`,165:`Alt`,173:`-`,186:`;`,187:`=`,188:`,`,189:`-`,190:`.`,191:`/`,192:"`",219:`[`,220:`\\`,221:`]`,222:`'`},u1={48:`)`,49:`!`,50:`@`,51:`#`,52:`$`,53:`%`,54:`^`,55:`&`,56:`*`,57:`(`,59:`:`,61:`+`,173:`_`,186:`:`,187:`+`,188:`<`,189:`_`,190:`>`,191:`?`,192:`~`,219:`{`,220:`|`,221:`}`,222:`"`},HAe=typeof navigator<`u`&&/Mac/.test(navigator.platform),UAe=typeof navigator<`u`&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),d1=0;d1<10;d1++)l1[48+d1]=l1[96+d1]=String(d1);for(var d1=1;d1<=24;d1++)l1[d1+111]=`F`+d1;for(var d1=65;d1<=90;d1++)l1[d1]=String.fromCharCode(d1+32),u1[d1]=String.fromCharCode(d1);for(var f1 in l1)u1.hasOwnProperty(f1)||(u1[f1]=l1[f1]);function WAe(e){var t=!(HAe&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||UAe&&e.shiftKey&&e.key&&e.key.length==1||e.key==`Unidentified`)&&e.key||(e.shiftKey?u1:l1)[e.keyCode]||e.key||`Unidentified`;return t==`Esc`&&(t=`Escape`),t==`Del`&&(t=`Delete`),t==`Left`&&(t=`ArrowLeft`),t==`Up`&&(t=`ArrowUp`),t==`Right`&&(t=`ArrowRight`),t==`Down`&&(t=`ArrowDown`),t}var GAe=typeof navigator<`u`&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),KAe=typeof navigator<`u`&&/Win/.test(navigator.platform);function qAe(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n==`Space`&&(n=` `);let r,i,a,o;for(let e=0;e{for(var n in t)XAe(e,n,{get:t[n],enumerable:!0})};function g1(e){let{state:t,transaction:n}=e,{selection:r}=n,{doc:i}=n,{storedMarks:a}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return a},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,a=n.storedMarks,n}}}var _1=class{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){let{rawCommands:e,editor:t,state:n}=this,{view:r}=t,{tr:i}=n,a=this.buildProps(i);return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,(...e)=>{let n=t(...e)(a);return!i.getMeta(`preventDispatch`)&&!this.hasCustomState&&r.dispatch(i),n}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o=[],s=!!e,c=e||i.tr,l=()=>(!s&&t&&!c.getMeta(`preventDispatch`)&&!this.hasCustomState&&a.dispatch(c),o.every(e=>e===!0)),u={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{let r=this.buildProps(c,t),i=n(...e)(r);return o.push(i),u}])),run:l};return u}createCan(e){let{rawCommands:t,state:n}=this,r=e||n.tr,i=this.buildProps(r,!1);return{...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)({...i,dispatch:void 0})])),chain:()=>this.createChain(r,!1)}}buildProps(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o={tr:e,editor:r,view:a,state:g1({state:i,transaction:e}),dispatch:t?()=>void 0:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(...e)=>t(...e)(o)]))}};return o}},v1={};h1(v1,{blur:()=>ZAe,clearContent:()=>QAe,clearNodes:()=>$Ae,command:()=>eje,createParagraphNear:()=>tje,cut:()=>nje,deleteCurrentNode:()=>rje,deleteNode:()=>ije,deleteRange:()=>aje,deleteSelection:()=>oje,enter:()=>sje,exitCode:()=>cje,extendMarkRange:()=>lje,first:()=>uje,focus:()=>fje,forEach:()=>pje,insertContent:()=>mje,insertContentAt:()=>_je,joinBackward:()=>bje,joinDown:()=>yje,joinForward:()=>xje,joinItemBackward:()=>Sje,joinItemForward:()=>Cje,joinTextblockBackward:()=>wje,joinTextblockForward:()=>Tje,joinUp:()=>vje,keyboardShortcut:()=>Dje,lift:()=>Oje,liftEmptyBlock:()=>kje,liftListItem:()=>Aje,newlineInCode:()=>jje,resetAttributes:()=>Mje,scrollIntoView:()=>Nje,selectAll:()=>Pje,selectNodeBackward:()=>Fje,selectNodeForward:()=>Ije,selectParentNode:()=>Lje,selectTextblockEnd:()=>Rje,selectTextblockStart:()=>zje,setContent:()=>Bje,setMark:()=>oMe,setMeta:()=>sMe,setNode:()=>cMe,setNodeSelection:()=>lMe,setTextDirection:()=>uMe,setTextSelection:()=>dMe,sinkListItem:()=>fMe,splitBlock:()=>pMe,splitListItem:()=>mMe,toggleList:()=>hMe,toggleMark:()=>gMe,toggleNode:()=>_Me,toggleWrap:()=>vMe,undoInputRule:()=>yMe,unsetAllMarks:()=>bMe,unsetMark:()=>xMe,unsetTextDirection:()=>SMe,updateAttributes:()=>CMe,wrapIn:()=>wMe,wrapInList:()=>TMe});var ZAe=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),(n=window==null?void 0:window.getSelection())==null||n.removeAllRanges())}),!0),QAe=(e=!0)=>({commands:t})=>t.setContent(``,{emitUpdate:e}),$Ae=()=>({state:e,tr:t,dispatch:n})=>{let{selection:r}=t,{ranges:i}=r;return n&&i.forEach(({$from:n,$to:r})=>{e.doc.nodesBetween(n.pos,r.pos,(e,n)=>{if(e.type.isText)return;let{doc:r,mapping:i}=t,a=r.resolve(i.map(n)),o=r.resolve(i.map(n+e.nodeSize)),s=a.blockRange(o);if(!s)return;let c=lX(s);if(e.type.isTextblock){let{defaultType:e}=a.parent.contentMatchAt(a.index());t.setNodeMarkup(s.start,e)}(c||c===0)&&t.lift(s,c)})}),!0},eje=e=>t=>e(t),tje=()=>({state:e,dispatch:t})=>pZ(e,t),nje=(e,t)=>({editor:n,tr:r})=>{let{state:i}=n,a=i.doc.slice(e.from,e.to);r.deleteRange(e.from,e.to);let o=r.mapping.map(t);return r.insert(o,a.content),r.setSelection(new IX(r.doc.resolve(Math.max(o-1,0)))),!0},rje=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;let i=e.selection.$anchor;for(let n=i.depth;n>0;--n)if(i.node(n).type===r.type){if(t){let t=i.before(n),r=i.after(n);e.delete(t,r).scrollIntoView()}return!0}return!1};function y1(e,t){if(typeof e==`string`){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}var ije=e=>({tr:t,state:n,dispatch:r})=>{let i=y1(e,n.schema),a=t.selection.$anchor;for(let e=a.depth;e>0;--e)if(a.node(e).type===i){if(r){let n=a.before(e),r=a.after(e);t.delete(n,r).scrollIntoView()}return!0}return!1},aje=e=>({tr:t,dispatch:n})=>{let{from:r,to:i}=e;return n&&t.delete(r,i),!0},oje=()=>({state:e,dispatch:t})=>$X(e,t),sje=()=>({commands:e})=>e.keyboardShortcut(`Enter`),cje=()=>({state:e,dispatch:t})=>fZ(e,t);function b1(e){return Object.prototype.toString.call(e)===`[object RegExp]`}function x1(e,t,n={strict:!0}){let r=Object.keys(t);return r.length?r.every(r=>n.strict?t[r]===e[r]:b1(t[r])?t[r].test(e[r]):t[r]===e[r]):!0}function S1(e,t,n={}){return e.find(e=>e.type===t&&x1(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function C1(e,t,n={}){return!!S1(e,t,n)}function w1(e,t,n){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if((!r.node||!r.node.marks.some(e=>e.type===t))&&(r=e.parent.childBefore(e.parentOffset)),!r.node||!r.node.marks.some(e=>e.type===t)||(n||=r.node.marks[0]?.attrs,!S1([...r.node.marks],t,n)))return;let i=r.index,a=e.start()+r.offset,o=i+1,s=a+r.node.nodeSize;for(;i>0&&C1([...e.parent.child(i-1).marks],t,n);)--i,a-=e.parent.child(i).nodeSize;for(;o({tr:n,state:r,dispatch:i})=>{let a=T1(e,r.schema),{doc:o,selection:s}=n,{$from:c,from:l,to:u}=s;if(i){let e=w1(c,a,t);if(e&&e.from<=l&&e.to>=u){let t=IX.create(o,e.from,e.to);n.setSelection(t)}}return!0},uje=e=>t=>{let n=typeof e==`function`?e(t):e;for(let e=0;e({editor:n,view:r,tr:i,dispatch:a})=>{t={scrollIntoView:!0,...t};let o=()=>{(A1()||k1())&&r.dom.focus(),dje()&&!A1()&&!k1()&&r.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),t?.scrollIntoView&&n.commands.scrollIntoView())})};try{if(r.hasFocus()&&e===null||e===!1)return!0}catch{return!1}if(a&&e===null&&!E1(n.state.selection))return o(),!0;let s=O1(i.doc,e)||n.state.selection,c=n.state.selection.eq(s);return a&&(c||i.setSelection(s),c&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},pje=(e,t)=>n=>e.every((e,r)=>t(e,{...n,index:r})),mje=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),j1=e=>{let t=e.childNodes;for(let n=t.length-1;n>=0;--n){let r=t[n];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?e.removeChild(r):r.nodeType===1&&j1(r)}return e};function M1(e){if(typeof window>`u`)throw Error(`[tiptap error]: there is no window object available, so this function cannot be used`);let t=`${e}`,n=new window.DOMParser().parseFromString(t,`text/html`).body;return j1(n)}function N1(e,t,n){if(e instanceof fY||e instanceof KJ)return e;n={slice:!0,parseOptions:{},...n};let r=typeof e==`object`&&!!e,i=typeof e==`string`;if(r)try{if(Array.isArray(e)&&e.length>0)return KJ.fromArray(e.map(e=>t.nodeFromJSON(e)));let r=t.nodeFromJSON(e);return n.errorOnInvalidContent&&r.check(),r}catch(r){if(n.errorOnInvalidContent)throw Error(`[tiptap error]: Invalid JSON content`,{cause:r});return console.warn(`[tiptap warn]: Invalid content.`,`Passed value:`,e,`Error:`,r),N1(``,t,n)}if(i){if(n.errorOnInvalidContent){let r=!1,i=``,a=new TY({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:`inline*`,group:`block`,parseDOM:[{tag:`*`,getAttrs:e=>(r=!0,i=typeof e==`string`?e:e.outerHTML,null)}]}})});if(n.slice?DY.fromSchema(a).parseSlice(M1(e),n.parseOptions):DY.fromSchema(a).parse(M1(e),n.parseOptions),n.errorOnInvalidContent&&r)throw Error(`[tiptap error]: Invalid HTML content`,{cause:Error(`Invalid element found: ${i}`)})}let r=DY.fromSchema(t);return n.slice?r.parseSlice(M1(e),n.parseOptions).content:r.parse(M1(e),n.parseOptions)}return N1(``,t,n)}function hje(e,t,n){let r=e.steps.length-1;if(r{o===0&&(o=r)}),e.setSelection(NX.near(e.doc.resolve(o),n))}var gje=e=>!(`type`in e),_je=(e,t,n)=>({tr:r,dispatch:i,editor:a})=>{if(i){n={parseOptions:a.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let i,o=e=>{a.emit(`contentError`,{editor:a,error:e,disableCollaboration:()=>{`collaboration`in a.storage&&typeof a.storage.collaboration==`object`&&a.storage.collaboration&&(a.storage.collaboration.isDisabled=!0)}})},s={preserveWhitespace:`full`,...n.parseOptions};if(!n.errorOnInvalidContent&&!a.options.enableContentCheck&&a.options.emitContentError)try{N1(t,a.schema,{parseOptions:s,errorOnInvalidContent:!0})}catch(e){o(e)}try{i=N1(t,a.schema,{parseOptions:s,errorOnInvalidContent:n.errorOnInvalidContent??a.options.enableContentCheck})}catch(e){return o(e),!1}let{from:c,to:l}=typeof e==`number`?{from:e,to:e}:{from:e.from,to:e.to},u=!0,d=!0;if((gje(i)?i:[i]).forEach(e=>{e.check(),u=u?e.isText&&e.marks.length===0:!1,d=d?e.isBlock:!1}),c===l&&d){let{parent:e}=r.doc.resolve(c);e.isTextblock&&!e.type.spec.code&&!e.childCount&&(--c,l+=1)}let f;if(u){if(Array.isArray(t))f=t.map(e=>e.text||``).join(``);else if(t instanceof KJ){let e=``;t.forEach(t=>{t.text&&(e+=t.text)}),f=e}else f=typeof t==`object`&&t&&t.text?t.text:t;r.insertText(f,c,l)}else{f=i;let e=r.doc.resolve(c),t=e.node(),n=e.parentOffset===0,a=t.isText||t.isTextblock,o=t.content.size>0;n&&a&&o&&(c=Math.max(0,c-1)),r.replaceWith(c,l,f)}n.updateSelection&&hje(r,r.steps.length-1,-1),n.applyInputRules&&r.setMeta(`applyInputRules`,{from:c,text:f}),n.applyPasteRules&&r.setMeta(`applyPasteRules`,{from:c,text:f})}return!0},vje=()=>({state:e,dispatch:t})=>VOe(e,t),yje=()=>({state:e,dispatch:t})=>HOe(e,t),bje=()=>({state:e,dispatch:t})=>tZ(e,t),xje=()=>({state:e,dispatch:t})=>sZ(e,t),Sje=()=>({state:e,dispatch:t,tr:n})=>{try{let r=_X(e.doc,e.selection.$from.pos,-1);return r==null?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},Cje=()=>({state:e,dispatch:t,tr:n})=>{try{let r=_X(e.doc,e.selection.$from.pos,1);return r==null?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},wje=()=>({state:e,dispatch:t})=>zOe(e,t),Tje=()=>({state:e,dispatch:t})=>BOe(e,t);function P1(){return typeof navigator<`u`?/Mac/.test(navigator.platform):!1}function Eje(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n===`Space`&&(n=` `);let r,i,a,o;for(let e=0;e({editor:t,view:n,tr:r,dispatch:i})=>{let a=Eje(e).split(/-(?!$)/),o=a.find(e=>![`Alt`,`Ctrl`,`Meta`,`Shift`].includes(e)),s=new KeyboardEvent(`keydown`,{key:o===`Space`?` `:o,altKey:a.includes(`Alt`),ctrlKey:a.includes(`Ctrl`),metaKey:a.includes(`Meta`),shiftKey:a.includes(`Shift`),bubbles:!0,cancelable:!0});return t.captureTransaction(()=>{n.someProp(`handleKeyDown`,e=>e(n,s))})?.steps.forEach(e=>{let t=e.map(r.mapping);t&&i&&r.maybeStep(t)}),!0};function F1(e,t,n={}){let{from:r,to:i,empty:a}=e.selection,o=t?y1(t,e.schema):null,s=[];e.doc.nodesBetween(r,i,(e,t)=>{if(e.isText)return;let n=Math.max(r,t),a=Math.min(i,t+e.nodeSize);s.push({node:e,from:n,to:a})});let c=i-r,l=s.filter(e=>o?o.name===e.node.type.name:!0).filter(e=>x1(e.node.attrs,n,{strict:!1}));return a?!!l.length:l.reduce((e,t)=>e+t.to-t.from,0)>=c}var Oje=(e,t={})=>({state:n,dispatch:r})=>F1(n,y1(e,n.schema),t)?UOe(n,r):!1,kje=()=>({state:e,dispatch:t})=>mZ(e,t),Aje=e=>({state:t,dispatch:n})=>eke(y1(e,t.schema))(t,n),jje=()=>({state:e,dispatch:t})=>uZ(e,t);function I1(e,t){return t.nodes[e]?`node`:t.marks[e]?`mark`:null}function L1(e,t){let n=typeof t==`string`?[t]:t;return Object.keys(e).reduce((t,r)=>(n.includes(r)||(t[r]=e[r]),t),{})}var Mje=(e,t)=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=I1(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=y1(e,r.schema)),s===`mark`&&(o=T1(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{r.doc.nodesBetween(e.$from.pos,e.$to.pos,(e,r)=>{a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,L1(e.attrs,t))),o&&e.marks.length&&e.marks.forEach(a=>{o===a.type&&(c=!0,i&&n.addMark(r,r+e.nodeSize,o.create(L1(a.attrs,t))))})})}),c},Nje=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),Pje=()=>({tr:e,dispatch:t})=>{if(t){let t=new zX(e.doc);e.setSelection(t)}return!0},Fje=()=>({state:e,dispatch:t})=>iZ(e,t),Ije=()=>({state:e,dispatch:t})=>cZ(e,t),Lje=()=>({state:e,dispatch:t})=>KOe(e,t),Rje=()=>({state:e,dispatch:t})=>vZ(e,t),zje=()=>({state:e,dispatch:t})=>_Z(e,t);function R1(e,t,n={},r={}){return N1(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var Bje=(e,{errorOnInvalidContent:t,emitUpdate:n=!0,parseOptions:r={}}={})=>({editor:i,tr:a,dispatch:o,commands:s})=>{let{doc:c}=a;if(r.preserveWhitespace!==`full`){let s=R1(e,i.schema,r,{errorOnInvalidContent:t??i.options.enableContentCheck});return o&&a.replaceWith(0,c.content.size,s).setMeta(`preventUpdate`,!n),!0}return o&&a.setMeta(`preventUpdate`,!n),s.insertContentAt({from:0,to:c.content.size},e,{parseOptions:r,errorOnInvalidContent:t??i.options.enableContentCheck})};function z1(e,t){let n=T1(t,e.schema),{from:r,to:i,empty:a}=e.selection,o=[];a?(e.storedMarks&&o.push(...e.storedMarks),o.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,i,e=>{o.push(...e.marks)});let s=o.find(e=>e.type.name===n.name);return s?{...s.attrs}:{}}function B1(e,t){let n=new jX(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function Vje(e){for(let t=0;t{n(e)&&r.push({node:e,pos:t})}),r}function Uje(e,t){for(let n=e.depth;n>0;--n){let r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function V1(e){return t=>Uje(t.$from,e)}function H1(e,t,n){return e.config[t]===void 0&&e.parent?H1(e.parent,t,n):typeof e.config[t]==`function`?e.config[t].bind({...n,parent:e.parent?H1(e.parent,t,n):null}):e.config[t]}function U1(e){return e.map(e=>{let t=H1(e,`addExtensions`,{name:e.name,options:e.options,storage:e.storage});return t?[e,...U1(t())]:e}).flat(10)}function W1(e,t){let n=RY.fromSchema(t).serializeFragment(e),r=document.implementation.createHTMLDocument().createElement(`div`);return r.appendChild(n),r.innerHTML}function G1(e){return typeof e==`function`}function K1(e,t=void 0,...n){return G1(e)?t?e.bind(t)(...n):e(...n):e}function Wje(e={}){return Object.keys(e).length===0&&e.constructor===Object}function q1(e){return{baseExtensions:e.filter(e=>e.type===`extension`),nodeExtensions:e.filter(e=>e.type===`node`),markExtensions:e.filter(e=>e.type===`mark`)}}function J1(e){let t=[],{nodeExtensions:n,markExtensions:r}=q1(e),i=[...n,...r],a={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1};return e.forEach(e=>{let n=H1(e,`addGlobalAttributes`,{name:e.name,options:e.options,storage:e.storage,extensions:i});n&&n().forEach(e=>{e.types.forEach(n=>{Object.entries(e.attributes).forEach(([e,r])=>{t.push({type:n,name:e,attribute:{...a,...r}})})})})}),i.forEach(e=>{let n=H1(e,`addAttributes`,{name:e.name,options:e.options,storage:e.storage});if(!n)return;let r=n();Object.entries(r).forEach(([n,r])=>{let i={...a,...r};typeof i?.default==`function`&&(i.default=i.default()),i?.isRequired&&i?.default===void 0&&delete i.default,t.push({type:e.name,name:n,attribute:i})})}),t}function Y1(...e){return e.filter(e=>!!e).reduce((e,t)=>{let n={...e};return Object.entries(t).forEach(([e,t])=>{if(!n[e]){n[e]=t;return}if(e===`class`){let r=t?String(t).split(` `):[],i=n[e]?n[e].split(` `):[],a=r.filter(e=>!i.includes(e));n[e]=[...i,...a].join(` `)}else if(e===`style`){let r=t?t.split(`;`).map(e=>e.trim()).filter(Boolean):[],i=n[e]?n[e].split(`;`).map(e=>e.trim()).filter(Boolean):[],a=new Map;i.forEach(e=>{let[t,n]=e.split(`:`).map(e=>e.trim());a.set(t,n)}),r.forEach(e=>{let[t,n]=e.split(`:`).map(e=>e.trim());a.set(t,n)}),n[e]=Array.from(a.entries()).map(([e,t])=>`${e}: ${t}`).join(`; `)}else n[e]=t}),n},{})}function X1(e,t){return t.filter(t=>t.type===e.type.name).filter(e=>e.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(e.attrs)||{}:{[t.name]:e.attrs[t.name]}).reduce((e,t)=>Y1(e,t),{})}function Gje(e){return typeof e==`string`?e.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(e):e===`true`?!0:e===`false`?!1:e:e}function Z1(e,t){return`style`in e?e:{...e,getAttrs:n=>{let r=e.getAttrs?e.getAttrs(n):e.attrs;if(r===!1)return!1;let i=t.reduce((e,t)=>{let r=t.attribute.parseHTML?t.attribute.parseHTML(n):Gje(n.getAttribute(t.name));return r==null?e:{...e,[t.name]:r}},{});return{...r,...i}}}}function Q1(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>e===`attrs`&&Wje(t)?!1:t!=null))}function $1(e){let t={};return!e?.attribute?.isRequired&&`default`in(e?.attribute||{})&&(t.default=e.attribute.default),e?.attribute?.validate!==void 0&&(t.validate=e.attribute.validate),[e.name,t]}function Kje(e,t){let n=J1(e),{nodeExtensions:r,markExtensions:i}=q1(e);return new TY({topNode:r.find(e=>H1(e,`topNode`))?.name,nodes:Object.fromEntries(r.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=Q1({...e.reduce((e,t)=>{let n=H1(t,`extendNodeSchema`,a);return{...e,...n?n(r):{}}},{}),content:K1(H1(r,`content`,a)),marks:K1(H1(r,`marks`,a)),group:K1(H1(r,`group`,a)),inline:K1(H1(r,`inline`,a)),atom:K1(H1(r,`atom`,a)),selectable:K1(H1(r,`selectable`,a)),draggable:K1(H1(r,`draggable`,a)),code:K1(H1(r,`code`,a)),whitespace:K1(H1(r,`whitespace`,a)),linebreakReplacement:K1(H1(r,`linebreakReplacement`,a)),defining:K1(H1(r,`defining`,a)),isolating:K1(H1(r,`isolating`,a)),attrs:Object.fromEntries(i.map($1))}),s=K1(H1(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>Z1(e,i)));let c=H1(r,`renderHTML`,a);c&&(o.toDOM=e=>c({node:e,HTMLAttributes:X1(e,i)}));let l=H1(r,`renderText`,a);return l&&(o.toText=l),[r.name,o]})),marks:Object.fromEntries(i.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=Q1({...e.reduce((e,t)=>{let n=H1(t,`extendMarkSchema`,a);return{...e,...n?n(r):{}}},{}),inclusive:K1(H1(r,`inclusive`,a)),excludes:K1(H1(r,`excludes`,a)),group:K1(H1(r,`group`,a)),spanning:K1(H1(r,`spanning`,a)),code:K1(H1(r,`code`,a)),attrs:Object.fromEntries(i.map($1))}),s=K1(H1(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>Z1(e,i)));let c=H1(r,`renderHTML`,a);return c&&(o.toDOM=e=>c({mark:e,HTMLAttributes:X1(e,i)})),[r.name,o]}))})}function qje(e){let t=e.filter((t,n)=>e.indexOf(t)!==n);return Array.from(new Set(t))}function e0(e){return e.sort((e,t)=>{let n=H1(e,`priority`)||100,r=H1(t,`priority`)||100;return n>r?-1:+(ne.name));return n.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${n.map(e=>`'${e}'`).join(`, `)}]. This can lead to issues.`),t}function n0(e,t,n){let{from:r,to:i}=t,{blockSeparator:a=` -`,textSerializers:o={}}=n||{},s=``;return e.nodesBetween(r,i,(e,n,c,l)=>{e.isBlock&&n>r&&(s+=a);let u=o?.[e.type.name];if(u)return c&&(s+=u({node:e,pos:n,parent:c,index:l,range:t})),!1;e.isText&&(s+=(e?.text)?.slice(Math.max(r,n)-n,i-n))}),s}function qje(e,t){return n0(e,{from:0,to:e.content.size},t)}function r0(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function Jje(e,t){let n=y1(t,e.schema),{from:r,to:i}=e.selection,a=[];e.doc.nodesBetween(r,i,e=>{a.push(e)});let o=a.reverse().find(e=>e.type.name===n.name);return o?{...o.attrs}:{}}function i0(e,t){let n=I1(typeof t==`string`?t:t.name,e.schema);return n===`node`?Jje(e,t):n===`mark`?z1(e,t):{}}function Yje(e,t=JSON.stringify){let n={};return e.filter(e=>{let r=t(e);return Object.prototype.hasOwnProperty.call(n,r)?!1:n[r]=!0})}function Xje(e){let t=Yje(e);return t.length===1?t:t.filter((e,n)=>!t.filter((e,t)=>t!==n).some(t=>e.oldRange.from>=t.oldRange.from&&e.oldRange.to<=t.oldRange.to&&e.newRange.from>=t.newRange.from&&e.newRange.to<=t.newRange.to))}function a0(e){let{mapping:t,steps:n}=e,r=[];return t.maps.forEach((e,i)=>{let a=[];if(e.ranges.length)e.forEach((e,t)=>{a.push({from:e,to:t})});else{let{from:e,to:t}=n[i];if(e===void 0||t===void 0)return;a.push({from:e,to:t})}a.forEach(({from:e,to:n})=>{let a=t.slice(i).map(e,-1),o=t.slice(i).map(n),s=t.invert().map(a,-1),c=t.invert().map(o);r.push({oldRange:{from:s,to:c},newRange:{from:a,to:o}})})}),Xje(r)}function o0(e,t,n){let r=[];return e===t?n.resolve(e).marks().forEach(t=>{let i=w1(n.resolve(e),t.type);i&&r.push({mark:t,...i})}):n.nodesBetween(e,t,(e,t)=>{!e||e?.nodeSize===void 0||r.push(...e.marks.map(n=>({from:t,to:t+e.nodeSize,mark:n})))}),r}var Zje=(e,t,n,r=20)=>{let i=e.doc.resolve(n),a=r,o=null;for(;a>0&&o===null;){let e=i.node(a);e?.type.name===t?o=e:--a}return[o,a]};function s0(e,t){return t.nodes[e]||t.marks[e]||null}function c0(e,t,n){return Object.fromEntries(Object.entries(n).filter(([n])=>{let r=e.find(e=>e.type===t&&e.name===n);return r?r.attribute.keepOnSplit:!1}))}var Qje=(e,t=500)=>{let n=``,r=e.parentOffset;return e.parent.nodesBetween(Math.max(0,r-t),r,(e,t,i,a)=>{var o;let s=(o=e.type.spec).toText?.call(o,{node:e,pos:t,parent:i,index:a})||e.textContent||`%leaf%`;n+=e.isAtom&&!e.isText?s:s.slice(0,Math.max(0,r-t))}),n};function l0(e,t,n={}){let{empty:r,ranges:i}=e.selection,a=t?T1(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>a?a.name===e.type.name:!0).find(e=>x1(e.attrs,n,{strict:!1}));let o=0,s=[];if(i.forEach(({$from:t,$to:n})=>{let r=t.pos,i=n.pos;e.doc.nodesBetween(r,i,(e,t)=>{if(!e.isText&&!e.marks.length)return;let n=Math.max(r,t),a=Math.min(i,t+e.nodeSize),c=a-n;o+=c,s.push(...e.marks.map(e=>({mark:e,from:n,to:a})))})}),o===0)return!1;let c=s.filter(e=>a?a.name===e.mark.type.name:!0).filter(e=>x1(e.mark.attrs,n,{strict:!1})).reduce((e,t)=>e+t.to-t.from,0),l=s.filter(e=>a?e.mark.type!==a&&e.mark.type.excludes(a):!0).reduce((e,t)=>e+t.to-t.from,0);return(c>0?c+l:c)>=o}function $je(e,t,n={}){if(!t)return F1(e,null,n)||l0(e,null,n);let r=I1(t,e.schema);return r===`node`?F1(e,t,n):r===`mark`?l0(e,t,n):!1}var eMe=(e,t)=>{let{$from:n,$to:r,$anchor:i}=e.selection;if(t){let n=V1(e=>e.type.name===t)(e.selection);if(!n)return!1;let r=e.doc.resolve(n.pos+1);return i.pos+1===r.end()}return!(r.parentOffset{let{$from:t,$to:n}=e.selection;return!(t.parentOffset>0||t.pos!==n.pos)};function u0(e,t){return Array.isArray(t)?t.some(t=>(typeof t==`string`?t:t.name)===e.name):t}function d0(e,t){let{nodeExtensions:n}=q1(t),r=n.find(t=>t.name===e);if(!r)return!1;let i=K1(H1(r,`group`,{name:r.name,options:r.options,storage:r.storage}));return typeof i==`string`?i.split(` `).includes(`list`):!1}function f0(e,{checkChildren:t=!0,ignoreWhitespace:n=!1}={}){if(n){if(e.type.name===`hardBreak`)return!0;if(e.isText)return/^\s*$/m.test(e.text??``)}if(e.isText)return!e.text;if(e.isAtom||e.isLeaf)return!1;if(e.content.childCount===0)return!0;if(t){let r=!0;return e.content.forEach(e=>{r!==!1&&(f0(e,{ignoreWhitespace:n,checkChildren:t})||(r=!1))}),r}return!1}function p0(e){return e instanceof RX}var m0=class e{constructor(e){this.position=e}static fromJSON(t){return new e(t.position)}toJSON(){return{position:this.position}}};function nMe(e,t){let n=t.mapping.mapResult(e.position);return{position:new m0(n.pos),mapResult:n}}function rMe(e){return new m0(e)}function iMe(e,t,n){let{selection:r}=t,i=null;if(E1(r)&&(i=r.$cursor),i){let t=e.storedMarks??i.marks();return i.parent.type.allowsMarkType(n)&&(!!n.isInSet(t)||!t.some(e=>e.type.excludes(n)))}let{ranges:a}=r;return a.some(({$from:t,$to:r})=>{let i=t.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(n):!1;return e.doc.nodesBetween(t.pos,r.pos,(e,t,r)=>{if(i)return!1;if(e.isInline){let t=!r||r.type.allowsMarkType(n),a=!!n.isInSet(e.marks)||!e.marks.some(e=>e.type.excludes(n));i=t&&a}return!i}),i})}var aMe=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=n,{empty:o,ranges:s}=a,c=T1(e,r.schema);if(i)if(o){let e=z1(r,c);n.addStoredMark(c.create({...e,...t}))}else s.forEach(e=>{let i=e.$from.pos,a=e.$to.pos;r.doc.nodesBetween(i,a,(e,r)=>{let o=Math.max(r,i),s=Math.min(r+e.nodeSize,a);e.marks.find(e=>e.type===c)?e.marks.forEach(e=>{c===e.type&&n.addMark(o,s,c.create({...e.attrs,...t}))}):n.addMark(o,s,c.create(t))})});return iMe(r,n,c)},oMe=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),sMe=(e,t={})=>({state:n,dispatch:r,chain:i})=>{let a=y1(e,n.schema),o;return n.selection.$anchor.sameParent(n.selection.$head)&&(o=n.selection.$anchor.parent.attrs),a.isTextblock?i().command(({commands:e})=>yZ(a,{...o,...t})(n)?!0:e.clearNodes()).command(({state:e})=>yZ(a,{...o,...t})(e,r)).run():(console.warn(`[tiptap warn]: Currently "setNode()" only supports text block nodes.`),!1)},cMe=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,r=D1(e,0,n.content.size),i=RX.create(n,r);t.setSelection(i)}return!0},lMe=(e,t)=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=r,o,s;return typeof t==`number`?(o=t,s=t):t&&`from`in t&&`to`in t?(o=t.from,s=t.to):(o=a.from,s=a.to),i&&n.doc.nodesBetween(o,s,(t,r)=>{t.isText||n.setNodeMarkup(r,void 0,{...t.attrs,dir:e})}),!0},uMe=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,{from:r,to:i}=typeof e==`number`?{from:e,to:e}:e,a=IX.atStart(n).from,o=IX.atEnd(n).to,s=D1(r,a,o),c=D1(i,a,o),l=IX.create(n,s,c);t.setSelection(l)}return!0},dMe=e=>({state:t,dispatch:n})=>nke(y1(e,t.schema))(t,n);function h0(e,t){let n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){let r=n.filter(e=>t?.includes(e.type.name));e.tr.ensureMarks(r)}}var fMe=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{let{selection:a,doc:o}=t,{$from:s,$to:c}=a,l=i.extensionManager.attributes,u=c0(l,s.node().type.name,s.node().attrs);if(a instanceof RX&&a.node.isBlock)return!s.parentOffset||!mX(o,s.pos)?!1:(r&&(e&&h0(n,i.extensionManager.splittableMarks),t.split(s.pos).scrollIntoView()),!0);if(!s.parent.isBlock)return!1;let d=c.parentOffset===c.parent.content.size,f=s.depth===0?void 0:Bje(s.node(-1).contentMatchAt(s.indexAfter(-1))),p=d&&f?[{type:f,attrs:u}]:void 0,m=mX(t.doc,t.mapping.map(s.pos),1,p);if(!p&&!m&&mX(t.doc,t.mapping.map(s.pos),1,f?[{type:f}]:void 0)&&(m=!0,p=f?[{type:f,attrs:u}]:void 0),r){if(m&&(a instanceof IX&&t.deleteSelection(),t.split(t.mapping.map(s.pos),1,p),f&&!d&&!s.parentOffset&&s.parent.type!==f)){let e=t.mapping.map(s.before()),n=t.doc.resolve(e);s.node(-1).canReplaceWith(n.index(),n.index()+1,f)&&t.setNodeMarkup(t.mapping.map(s.before()),f)}e&&h0(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return m},pMe=(e,t={})=>({tr:n,state:r,dispatch:i,editor:a})=>{let o=y1(e,r.schema),{$from:s,$to:c}=r.selection,l=r.selection.node;if(l&&l.isBlock||s.depth<2||!s.sameParent(c))return!1;let u=s.node(-1);if(u.type!==o)return!1;let d=a.extensionManager.attributes;if(s.parent.content.size===0&&s.node(-1).childCount===s.indexAfter(-1)){if(s.depth===2||s.node(-3).type!==o||s.index(-2)!==s.node(-2).childCount-1)return!1;if(i){let e=KJ.empty,r=s.index(-1)?1:s.index(-2)?2:3;for(let t=s.depth-r;t>=s.depth-3;--t)e=KJ.from(s.node(t).copy(e));let i=s.indexAfter(-1){if(u>-1)return!1;e.isTextblock&&e.content.size===0&&(u=t+1)}),u>-1&&n.setSelection(IX.near(n.doc.resolve(u))),n.scrollIntoView()}return!0}let f=c.pos===s.end()?u.contentMatchAt(0).defaultType:null,p={...c0(d,u.type.name,u.attrs),...t},m={...c0(d,s.node().type.name,s.node().attrs),...t};n.delete(s.pos,c.pos);let h=f?[{type:o,attrs:p},{type:f,attrs:m}]:[{type:o,attrs:p}];if(!mX(n.doc,s.pos,2))return!1;if(i){let{selection:e,storedMarks:t}=r,{splittableMarks:o}=a.extensionManager,c=t||e.$to.parentOffset&&e.$from.marks();if(n.split(s.pos,2,h).scrollIntoView(),!c||!i)return!0;let l=c.filter(e=>o.includes(e.type.name));n.ensureMarks(l)}return!0},g0=(e,t)=>{let n=V1(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return n.node.type===i?.type&&hX(e.doc,n.pos)&&e.join(n.pos),!0},_0=(e,t)=>{let n=V1(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return n.node.type===i?.type&&hX(e.doc,r)&&e.join(r),!0},mMe=(e,t,n,r={})=>({editor:i,tr:a,state:o,dispatch:s,chain:c,commands:l,can:u})=>{let{extensions:d,splittableMarks:f}=i.extensionManager,p=y1(e,o.schema),m=y1(t,o.schema),{selection:h,storedMarks:g}=o,{$from:_,$to:v}=h,y=_.blockRange(v),b=g||h.$to.parentOffset&&h.$from.marks();if(!y)return!1;let x=V1(e=>d0(e.type.name,d))(h);if(y.depth>=1&&x&&y.depth-x.depth<=1){if(x.node.type===p)return l.liftListItem(m);if(d0(x.node.type.name,d)&&p.validContent(x.node.content)&&s)return c().command(()=>(a.setNodeMarkup(x.pos,p),!0)).command(()=>g0(a,p)).command(()=>_0(a,p)).run()}return!n||!b||!s?c().command(()=>u().wrapInList(p,r)?!0:l.clearNodes()).wrapInList(p,r).command(()=>g0(a,p)).command(()=>_0(a,p)).run():c().command(()=>{let e=u().wrapInList(p,r),t=b.filter(e=>f.includes(e.type.name));return a.ensureMarks(t),e?!0:l.clearNodes()}).wrapInList(p,r).command(()=>g0(a,p)).command(()=>_0(a,p)).run()},hMe=(e,t={},n={})=>({state:r,commands:i})=>{let{extendEmptyMarkRange:a=!1}=n,o=T1(e,r.schema);return l0(r,o,t)?i.unsetMark(o,{extendEmptyMarkRange:a}):i.setMark(o,t)},gMe=(e,t,n={})=>({state:r,commands:i})=>{let a=y1(e,r.schema),o=y1(t,r.schema),s=F1(r,a,n),c;return r.selection.$anchor.sameParent(r.selection.$head)&&(c=r.selection.$anchor.parent.attrs),s?i.setNode(o,c):i.setNode(a,{...c,...n})},_Me=(e,t={})=>({state:n,commands:r})=>{let i=y1(e,n.schema);return F1(n,i,t)?r.lift(i):r.wrapIn(i,t)},vMe=()=>({state:e,dispatch:t})=>{let n=e.plugins;for(let r=0;r=0;--e)t.step(n.steps[e].invert(n.docs[e]));if(a.text){let n=t.doc.resolve(a.from).marks();t.replaceWith(a.from,a.to,e.schema.text(a.text,n))}else t.delete(a.from,a.to)}return!0}}return!1},yMe=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,{empty:r,ranges:i}=n;return r||t&&i.forEach(t=>{e.removeMark(t.$from.pos,t.$to.pos)}),!0},bMe=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{extendEmptyMarkRange:a=!1}=t,{selection:o}=n,s=T1(e,r.schema),{$from:c,empty:l,ranges:u}=o;if(!i)return!0;if(l&&a){let{from:e,to:t}=o,r=w1(c,s,c.marks().find(e=>e.type===s)?.attrs);r&&(e=r.from,t=r.to),n.removeMark(e,t,s)}else u.forEach(e=>{n.removeMark(e.$from.pos,e.$to.pos,s)});return n.removeStoredMark(s),!0},xMe=e=>({tr:t,state:n,dispatch:r})=>{let{selection:i}=n,a,o;return typeof e==`number`?(a=e,o=e):e&&`from`in e&&`to`in e?(a=e.from,o=e.to):(a=i.from,o=i.to),r&&t.doc.nodesBetween(a,o,(e,n)=>{if(e.isText)return;let r={...e.attrs};delete r.dir,t.setNodeMarkup(n,void 0,r)}),!0},SMe=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=I1(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=y1(e,r.schema)),s===`mark`&&(o=T1(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{let s=e.$from.pos,l=e.$to.pos,u,d,f,p;n.selection.empty?r.doc.nodesBetween(s,l,(e,t)=>{a&&a===e.type&&(c=!0,f=Math.max(t,s),p=Math.min(t+e.nodeSize,l),u=t,d=e)}):r.doc.nodesBetween(s,l,(e,r)=>{r=s&&r<=l&&(a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,{...e.attrs,...t})),o&&e.marks.length&&e.marks.forEach(a=>{if(o===a.type&&(c=!0,i)){let i=Math.max(r,s),c=Math.min(r+e.nodeSize,l);n.addMark(i,c,o.create({...a.attrs,...t}))}}))}),d&&(u!==void 0&&i&&n.setNodeMarkup(u,void 0,{...d.attrs,...t}),o&&d.marks.length&&d.marks.forEach(e=>{o===e.type&&i&&n.addMark(f,p,o.create({...e.attrs,...t}))}))}),c},CMe=(e,t={})=>({state:n,dispatch:r})=>JOe(y1(e,n.schema),t)(n,r),wMe=(e,t={})=>({state:n,dispatch:r})=>XOe(y1(e,n.schema),t)(n,r),TMe=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){let n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}once(e,t){let n=(...r)=>{this.off(e,n),t.apply(this,r)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}},v0=class{constructor(e){this.find=e.find,this.handler=e.handler,this.undoable=e.undoable??!0}},EMe=(e,t)=>{if(b1(t))return t.exec(e);let n=t(e);if(!n)return null;let r=[n.text];return r.index=n.index,r.input=e,r.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn(`[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".`),r.push(n.replaceWith)),r};function y0(e){let{editor:t,from:n,to:r,text:i,rules:a,plugin:o}=e,{view:s}=t;if(s.composing)return!1;let c=s.state.doc.resolve(n);if(c.parent.type.spec.code||(c.nodeBefore||c.nodeAfter)?.marks.find(e=>e.type.spec.code))return!1;let l=!1,u=Qje(c)+i;return a.forEach(e=>{if(l)return;let a=EMe(u,e.find);if(!a)return;let c=s.state.tr,d=g1({state:s.state,transaction:c}),f={from:n-(a[0].length-i.length),to:r},{commands:p,chain:m,can:h}=new _1({editor:t,state:d});e.handler({state:d,range:f,match:a,commands:p,chain:m,can:h})===null||!c.steps.length||(e.undoable&&c.setMeta(o,{transform:c,from:n,to:r,text:i}),s.dispatch(c),l=!0)}),l}function DMe(e){let{editor:t,rules:n}=e,r=new YX({state:{init(){return null},apply(e,i,a){let o=e.getMeta(r);if(o)return o;let s=e.getMeta(`applyInputRules`);return s&&setTimeout(()=>{let{text:e}=s;e=typeof e==`string`?e:W1(KJ.from(e),a.schema);let{from:i}=s;y0({editor:t,from:i,to:i+e.length,text:e,rules:n,plugin:r})}),e.selectionSet||e.docChanged?null:i}},props:{handleTextInput(e,i,a,o){return y0({editor:t,from:i,to:a,text:o,rules:n,plugin:r})},handleDOMEvents:{compositionend:e=>(setTimeout(()=>{let{$cursor:i}=e.state.selection;i&&y0({editor:t,from:i.pos,to:i.pos,text:``,rules:n,plugin:r})}),!1)},handleKeyDown(e,i){if(i.key!==`Enter`)return!1;let{$cursor:a}=e.state.selection;return a?y0({editor:t,from:a.pos,to:a.pos,text:` -`,rules:n,plugin:r}):!1}},isInputRules:!0});return r}function OMe(e){return Object.prototype.toString.call(e).slice(8,-1)}function b0(e){return OMe(e)===`Object`?e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype:!1}function x0(e,t){let n={...e};return b0(e)&&b0(t)&&Object.keys(t).forEach(r=>{b0(t[r])&&b0(e[r])?n[r]=x0(e[r],t[r]):n[r]=t[r]}),n}var S0=class{constructor(e={}){this.type=`extendable`,this.parent=null,this.child=null,this.name=``,this.config={name:this.name},this.config={...this.config,...e},this.name=this.config.name}get options(){return{...K1(H1(this,`addOptions`,{name:this.name}))||{}}}get storage(){return{...K1(H1(this,`addStorage`,{name:this.name,options:this.options}))||{}}}configure(e={}){let t=this.extend({...this.config,addOptions:()=>x0(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){let t=new this.constructor({...this.config,...e});return t.parent=this,this.child=t,t.name=`name`in e?e.name:t.parent.name,t}},C0=class e extends S0{constructor(){super(...arguments),this.type=`mark`}static create(t={}){return new e(typeof t==`function`?t():t)}static handleExit({editor:e,mark:t}){let{tr:n}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){let i=r.marks();if(!i.find(e=>e?.type.name===t.name))return!1;let a=i.find(e=>e?.type.name===t.name);return a&&n.removeStoredMark(a),n.insertText(` `,r.pos),e.view.dispatch(n),!0}return!1}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}};function kMe(e){return typeof e==`number`}var AMe=class{constructor(e){this.find=e.find,this.handler=e.handler}},jMe=(e,t,n)=>{if(b1(t))return[...e.matchAll(t)];let r=t(e,n);return r?r.map(t=>{let n=[t.text];return n.index=t.index,n.input=e,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn(`[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".`),n.push(t.replaceWith)),n}):[]};function MMe(e){let{editor:t,state:n,from:r,to:i,rule:a,pasteEvent:o,dropEvent:s}=e,{commands:c,chain:l,can:u}=new _1({editor:t,state:n}),d=[];return n.doc.nodesBetween(r,i,(e,t)=>{if(e.type?.spec?.code||!(e.isText||e.isTextblock||e.isInline))return;let f=e.content?.size??e.nodeSize??0,p=Math.max(r,t),m=Math.min(i,t+f);p>=m||jMe(e.isText?e.text||``:e.textBetween(p-t,m-t,void 0,``),a.find,o).forEach(e=>{if(e.index===void 0)return;let t=p+e.index+1,r=t+e[0].length,i={from:n.tr.mapping.map(t),to:n.tr.mapping.map(r)},f=a.handler({state:n,range:i,match:e,commands:c,chain:l,can:u,pasteEvent:o,dropEvent:s});d.push(f)})}),d.every(e=>e!==null)}var w0=null,NMe=e=>{var t;let n=new ClipboardEvent(`paste`,{clipboardData:new DataTransfer});return(t=n.clipboardData)==null||t.setData(`text/html`,e),n};function PMe(e){let{editor:t,rules:n}=e,r=null,i=!1,a=!1,o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,s;try{s=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{s=null}let c=({state:e,from:n,to:r,rule:i,pasteEvt:a})=>{let c=e.tr;if(!(!MMe({editor:t,state:g1({state:e,transaction:c}),from:Math.max(n-1,0),to:r.b-1,rule:i,pasteEvent:a,dropEvent:s})||!c.steps.length)){try{s=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{s=null}return o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,c}};return n.map(e=>new YX({view(e){let n=n=>{r=e.dom.parentElement?.contains(n.target)?e.dom.parentElement:null,r&&(w0=t)},i=()=>{w0&&=null};return window.addEventListener(`dragstart`,n),window.addEventListener(`dragend`,i),{destroy(){window.removeEventListener(`dragstart`,n),window.removeEventListener(`dragend`,i)}}},props:{handleDOMEvents:{drop:(e,t)=>{if(a=r===e.dom.parentElement,s=t,!a){let e=w0;e?.isEditable&&setTimeout(()=>{let t=e.state.selection;t&&e.commands.deleteRange({from:t.from,to:t.to})},10)}return!1},paste:(e,t)=>{let n=t.clipboardData?.getData(`text/html`);return o=t,i=!!n?.includes(`data-pm-slice`),!1}}},appendTransaction:(t,n,r)=>{let s=t[0],l=s.getMeta(`uiEvent`)===`paste`&&!i,u=s.getMeta(`uiEvent`)===`drop`&&!a,d=s.getMeta(`applyPasteRules`),f=!!d;if(!l&&!u&&!f)return;if(f){let{text:t}=d;t=typeof t==`string`?t:W1(KJ.from(t),r.schema);let{from:n}=d,i=n+t.length,a=NMe(t);return c({rule:e,state:r,from:n,to:{b:i},pasteEvt:a})}let p=n.doc.content.findDiffStart(r.doc.content),m=n.doc.content.findDiffEnd(r.doc.content);if(!(!kMe(p)||!m||p===m.b))return c({rule:e,state:r,from:p,to:m,pasteEvt:o})}}))}var T0=class{constructor(e,t){this.splittableMarks=[],this.editor=t,this.baseExtensions=e,this.extensions=t0(e),this.schema=Gje(this.extensions,t),this.setupExtensions()}get commands(){return this.extensions.reduce((e,t)=>{let n=H1(t,`addCommands`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:this.editor,type:s0(t.name,this.schema)});return n?{...e,...n()}:e},{})}get plugins(){let{editor:e}=this;return e0([...this.extensions].reverse()).flatMap(t=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:s0(t.name,this.schema)},r=[],i=H1(t,`addKeyboardShortcuts`,n),a={};if(t.type===`mark`&&H1(t,`exitable`,n)&&(a.ArrowRight=()=>C0.handleExit({editor:e,mark:t})),i){let t=Object.fromEntries(Object.entries(i()).map(([t,n])=>[t,()=>n({editor:e})]));a={...a,...t}}let o=JAe(a);r.push(o);let s=H1(t,`addInputRules`,n);if(u0(t,e.options.enableInputRules)&&s){let t=s();if(t&&t.length){let n=DMe({editor:e,rules:t}),i=Array.isArray(n)?n:[n];r.push(...i)}}let c=H1(t,`addPasteRules`,n);if(u0(t,e.options.enablePasteRules)&&c){let t=c();if(t&&t.length){let n=PMe({editor:e,rules:t});r.push(...n)}}let l=H1(t,`addProseMirrorPlugins`,n);if(l){let e=l();r.push(...e)}return r})}get attributes(){return J1(this.extensions)}get nodeViews(){let{editor:e}=this,{nodeExtensions:t}=q1(this.extensions);return Object.fromEntries(t.filter(e=>!!H1(e,`addNodeView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=H1(t,`addNodeView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:y1(t.name,this.schema)});if(!r)return[];let i=r();return i?[t.name,(r,a,o,s,c)=>i({node:r,view:a,getPos:o,decorations:s,innerDecorations:c,editor:e,extension:t,HTMLAttributes:X1(r,n)})]:[]}))}dispatchTransaction(e){let{editor:t}=this;return e0([...this.extensions].reverse()).reduceRight((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:s0(n.name,this.schema)},i=H1(n,`dispatchTransaction`,r);return i?t=>{i.call(r,{transaction:t,next:e})}:e},e)}get markViews(){let{editor:e}=this,{markExtensions:t}=q1(this.extensions);return Object.fromEntries(t.filter(e=>!!H1(e,`addMarkView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=H1(t,`addMarkView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:T1(t.name,this.schema)});return r?[t.name,(i,a,o)=>{let s=X1(i,n);return r()({mark:i,view:a,inline:o,editor:e,extension:t,HTMLAttributes:s,updateAttributes:t=>{qMe(i,e,t)}})}]:[]}))}setupExtensions(){let e=this.extensions;this.editor.extensionStorage=Object.fromEntries(e.map(e=>[e.name,e.storage])),e.forEach(e=>{let t={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:s0(e.name,this.schema)};e.type===`mark`&&(K1(H1(e,`keepOnSplit`,t))??!0)&&this.splittableMarks.push(e.name);let n=H1(e,`onBeforeCreate`,t),r=H1(e,`onCreate`,t),i=H1(e,`onUpdate`,t),a=H1(e,`onSelectionUpdate`,t),o=H1(e,`onTransaction`,t),s=H1(e,`onFocus`,t),c=H1(e,`onBlur`,t),l=H1(e,`onDestroy`,t);n&&this.editor.on(`beforeCreate`,n),r&&this.editor.on(`create`,r),i&&this.editor.on(`update`,i),a&&this.editor.on(`selectionUpdate`,a),o&&this.editor.on(`transaction`,o),s&&this.editor.on(`focus`,s),c&&this.editor.on(`blur`,c),l&&this.editor.on(`destroy`,l)})}};T0.resolve=t0,T0.sort=e0,T0.flatten=U1,h1({},{ClipboardTextSerializer:()=>D0,Commands:()=>O0,Delete:()=>k0,Drop:()=>A0,Editable:()=>j0,FocusEvents:()=>N0,Keymap:()=>P0,Paste:()=>F0,Tabindex:()=>I0,TextDirection:()=>L0,focusEventsPluginKey:()=>M0});var E0=class e extends S0{constructor(){super(...arguments),this.type=`extension`}static create(t={}){return new e(typeof t==`function`?t():t)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}},D0=E0.create({name:`clipboardTextSerializer`,addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new YX({key:new QX(`clipboardTextSerializer`),props:{clipboardTextSerializer:()=>{let{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:i}=t,{ranges:a}=i,o=Math.min(...a.map(e=>e.$from.pos)),s=Math.max(...a.map(e=>e.$to.pos)),c=r0(n);return n0(r,{from:o,to:s},{...this.options.blockSeparator===void 0?{}:{blockSeparator:this.options.blockSeparator},textSerializers:c})}}})]}}),O0=E0.create({name:`commands`,addCommands(){return{...v1}}}),k0=E0.create({name:`delete`,onUpdate({transaction:e,appendedTransactions:t}){let n=()=>{var n;if(((n=this.editor.options.coreExtensionOptions?.delete)?.filterTransaction)?.call(n,e)??e.getMeta(`y-sync$`))return;let r=B1(e.before,[e,...t]);a0(r).forEach(t=>{r.mapping.mapResult(t.oldRange.from).deletedAfter&&r.mapping.mapResult(t.oldRange.to).deletedBefore&&r.before.nodesBetween(t.oldRange.from,t.oldRange.to,(n,i)=>{let a=i+n.nodeSize-2,o=t.oldRange.from<=i&&a<=t.oldRange.to;this.editor.emit(`delete`,{type:`node`,node:n,from:i,to:a,newFrom:r.mapping.map(i),newTo:r.mapping.map(a),deletedRange:t.oldRange,newRange:t.newRange,partial:!o,editor:this.editor,transaction:e,combinedTransform:r})})});let i=r.mapping;r.steps.forEach((t,n)=>{if(t instanceof nX){let a=i.slice(n).map(t.from,-1),o=i.slice(n).map(t.to),s=i.invert().map(a,-1),c=i.invert().map(o),l=r.doc.nodeAt(a-1)?.marks.some(e=>e.eq(t.mark)),u=r.doc.nodeAt(o)?.marks.some(e=>e.eq(t.mark));this.editor.emit(`delete`,{type:`mark`,mark:t.mark,from:t.from,to:t.to,deletedRange:{from:s,to:c},newRange:{from:a,to:o},partial:!!(u||l),editor:this.editor,transaction:e,combinedTransform:r})}})};this.editor.options.coreExtensionOptions?.delete?.async??!0?setTimeout(n,0):n()}}),A0=E0.create({name:`drop`,addProseMirrorPlugins(){return[new YX({key:new QX(`tiptapDrop`),props:{handleDrop:(e,t,n,r)=>{this.editor.emit(`drop`,{editor:this.editor,event:t,slice:n,moved:r})}}})]}}),j0=E0.create({name:`editable`,addProseMirrorPlugins(){return[new YX({key:new QX(`editable`),props:{editable:()=>this.editor.options.editable}})]}}),M0=new QX(`focusEvents`),N0=E0.create({name:`focusEvents`,addProseMirrorPlugins(){let{editor:e}=this;return[new YX({key:M0,props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;let r=e.state.tr.setMeta(`focus`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;let r=e.state.tr.setMeta(`blur`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1}}}})]}}),P0=E0.create({name:`keymap`,addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({commands:e})=>[()=>e.undoInputRule(),()=>e.command(({tr:t})=>{let{selection:n,doc:r}=t,{empty:i,$anchor:a}=n,{pos:o,parent:s}=a,c=a.parent.isTextblock&&o>0?t.doc.resolve(o-1):a,l=c.parent.type.spec.isolating,u=a.pos-a.parentOffset,d=l&&c.parent.childCount===1?u===a.pos:NX.atStart(r).from===o;return!i||!s.type.isTextblock||s.textContent.length||!d||d&&a.parent.type.name===`paragraph`?!1:e.clearNodes()}),()=>e.deleteSelection(),()=>e.joinBackward(),()=>e.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.deleteCurrentNode(),()=>e.joinForward(),()=>e.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:e})=>[()=>e.newlineInCode(),()=>e.createParagraphNear(),()=>e.liftEmptyBlock(),()=>e.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},r={...n},i={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return A1()||P1()?i:r},addProseMirrorPlugins(){return[new YX({key:new QX(`clearDocument`),appendTransaction:(e,t,n)=>{if(e.some(e=>e.getMeta(`composition`)))return;let r=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),i=e.some(e=>e.getMeta(`preventClearDocument`));if(!r||i)return;let{empty:a,from:o,to:s}=t.selection,c=NX.atStart(t.doc).from,l=NX.atEnd(t.doc).to;if(a||!(o===c&&s===l)||!f0(n.doc))return;let u=n.tr,d=g1({state:n,transaction:u}),{commands:f}=new _1({editor:this.editor,state:d});if(f.clearNodes(),u.steps.length)return u}})]}}),F0=E0.create({name:`paste`,addProseMirrorPlugins(){return[new YX({key:new QX(`tiptapPaste`),props:{handlePaste:(e,t,n)=>{this.editor.emit(`paste`,{editor:this.editor,event:t,slice:n})}}})]}}),I0=E0.create({name:`tabindex`,addProseMirrorPlugins(){return[new YX({key:new QX(`tabindex`),props:{attributes:()=>this.editor.isEditable?{tabindex:`0`}:{}}})]}}),L0=E0.create({name:`textDirection`,addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];let{nodeExtensions:e}=q1(this.extensions);return[{types:e.filter(e=>e.name!==`text`).map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{let t=e.getAttribute(`dir`);return t&&(t===`ltr`||t===`rtl`||t===`auto`)?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new YX({key:new QX(`textDirection`),props:{attributes:()=>{let e=this.options.direction;return e?{dir:e}:{}}}})]}}),FMe=class e{constructor(e,t,n=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=r}get name(){return this.node.type.name}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){return this.actualDepth??this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can\u2019t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+ +!this.node.isText}get parent(){if(this.depth===0)return null;let t=this.resolvedPos.start(this.resolvedPos.depth-1);return new e(this.resolvedPos.doc.resolve(t),this.editor)}get before(){let t=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.from-3)),new e(t,this.editor)}get after(){let t=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.to+3)),new e(t,this.editor)}get children(){let t=[];return this.node.content.forEach((n,r)=>{let i=n.isBlock&&!n.isTextblock,a=n.isAtom&&!n.isText,o=n.isInline,s=this.pos+r+ +!a;if(s<0||s>this.resolvedPos.doc.nodeSize-2)return;let c=this.resolvedPos.doc.resolve(s);if(!i&&!o&&c.depth<=this.depth)return;let l=new e(c,this.editor,i,i||o?n:null);i&&(l.actualDepth=this.depth+1),t.push(l)}),t}get firstChild(){return this.children[0]||null}get lastChild(){let e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,r=this.parent;for(;r&&!n;){if(r.node.type.name===e)if(Object.keys(t).length>0){let e=r.node.attrs,n=Object.keys(t);for(let r=0;r{n&&r.length>0||(a.node.type.name===e&&i.every(e=>t[e]===a.node.attrs[e])&&r.push(a),!(n&&r.length>0)&&(r=r.concat(a.querySelectorAll(e,t,n))))}),r}setAttribute(e){let{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},IMe=`.ProseMirror { +`,textSerializers:o={}}=n||{},s=``;return e.nodesBetween(r,i,(e,n,c,l)=>{e.isBlock&&n>r&&(s+=a);let u=o?.[e.type.name];if(u)return c&&(s+=u({node:e,pos:n,parent:c,index:l,range:t})),!1;e.isText&&(s+=(e?.text)?.slice(Math.max(r,n)-n,i-n))}),s}function Jje(e,t){return n0(e,{from:0,to:e.content.size},t)}function r0(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function Yje(e,t){let n=y1(t,e.schema),{from:r,to:i}=e.selection,a=[];e.doc.nodesBetween(r,i,e=>{a.push(e)});let o=a.reverse().find(e=>e.type.name===n.name);return o?{...o.attrs}:{}}function i0(e,t){let n=I1(typeof t==`string`?t:t.name,e.schema);return n===`node`?Yje(e,t):n===`mark`?z1(e,t):{}}function Xje(e,t=JSON.stringify){let n={};return e.filter(e=>{let r=t(e);return Object.prototype.hasOwnProperty.call(n,r)?!1:n[r]=!0})}function Zje(e){let t=Xje(e);return t.length===1?t:t.filter((e,n)=>!t.filter((e,t)=>t!==n).some(t=>e.oldRange.from>=t.oldRange.from&&e.oldRange.to<=t.oldRange.to&&e.newRange.from>=t.newRange.from&&e.newRange.to<=t.newRange.to))}function a0(e){let{mapping:t,steps:n}=e,r=[];return t.maps.forEach((e,i)=>{let a=[];if(e.ranges.length)e.forEach((e,t)=>{a.push({from:e,to:t})});else{let{from:e,to:t}=n[i];if(e===void 0||t===void 0)return;a.push({from:e,to:t})}a.forEach(({from:e,to:n})=>{let a=t.slice(i).map(e,-1),o=t.slice(i).map(n),s=t.invert().map(a,-1),c=t.invert().map(o);r.push({oldRange:{from:s,to:c},newRange:{from:a,to:o}})})}),Zje(r)}function o0(e,t,n){let r=[];return e===t?n.resolve(e).marks().forEach(t=>{let i=w1(n.resolve(e),t.type);i&&r.push({mark:t,...i})}):n.nodesBetween(e,t,(e,t)=>{!e||e?.nodeSize===void 0||r.push(...e.marks.map(n=>({from:t,to:t+e.nodeSize,mark:n})))}),r}var Qje=(e,t,n,r=20)=>{let i=e.doc.resolve(n),a=r,o=null;for(;a>0&&o===null;){let e=i.node(a);e?.type.name===t?o=e:--a}return[o,a]};function s0(e,t){return t.nodes[e]||t.marks[e]||null}function c0(e,t,n){return Object.fromEntries(Object.entries(n).filter(([n])=>{let r=e.find(e=>e.type===t&&e.name===n);return r?r.attribute.keepOnSplit:!1}))}var $je=(e,t=500)=>{let n=``,r=e.parentOffset;return e.parent.nodesBetween(Math.max(0,r-t),r,(e,t,i,a)=>{var o;let s=(o=e.type.spec).toText?.call(o,{node:e,pos:t,parent:i,index:a})||e.textContent||`%leaf%`;n+=e.isAtom&&!e.isText?s:s.slice(0,Math.max(0,r-t))}),n};function l0(e,t,n={}){let{empty:r,ranges:i}=e.selection,a=t?T1(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>a?a.name===e.type.name:!0).find(e=>x1(e.attrs,n,{strict:!1}));let o=0,s=[];if(i.forEach(({$from:t,$to:n})=>{let r=t.pos,i=n.pos;e.doc.nodesBetween(r,i,(e,t)=>{if(!e.isText&&!e.marks.length)return;let n=Math.max(r,t),a=Math.min(i,t+e.nodeSize),c=a-n;o+=c,s.push(...e.marks.map(e=>({mark:e,from:n,to:a})))})}),o===0)return!1;let c=s.filter(e=>a?a.name===e.mark.type.name:!0).filter(e=>x1(e.mark.attrs,n,{strict:!1})).reduce((e,t)=>e+t.to-t.from,0),l=s.filter(e=>a?e.mark.type!==a&&e.mark.type.excludes(a):!0).reduce((e,t)=>e+t.to-t.from,0);return(c>0?c+l:c)>=o}function eMe(e,t,n={}){if(!t)return F1(e,null,n)||l0(e,null,n);let r=I1(t,e.schema);return r===`node`?F1(e,t,n):r===`mark`?l0(e,t,n):!1}var tMe=(e,t)=>{let{$from:n,$to:r,$anchor:i}=e.selection;if(t){let n=V1(e=>e.type.name===t)(e.selection);if(!n)return!1;let r=e.doc.resolve(n.pos+1);return i.pos+1===r.end()}return!(r.parentOffset{let{$from:t,$to:n}=e.selection;return!(t.parentOffset>0||t.pos!==n.pos)};function u0(e,t){return Array.isArray(t)?t.some(t=>(typeof t==`string`?t:t.name)===e.name):t}function d0(e,t){let{nodeExtensions:n}=q1(t),r=n.find(t=>t.name===e);if(!r)return!1;let i=K1(H1(r,`group`,{name:r.name,options:r.options,storage:r.storage}));return typeof i==`string`?i.split(` `).includes(`list`):!1}function f0(e,{checkChildren:t=!0,ignoreWhitespace:n=!1}={}){if(n){if(e.type.name===`hardBreak`)return!0;if(e.isText)return/^\s*$/m.test(e.text??``)}if(e.isText)return!e.text;if(e.isAtom||e.isLeaf)return!1;if(e.content.childCount===0)return!0;if(t){let r=!0;return e.content.forEach(e=>{r!==!1&&(f0(e,{ignoreWhitespace:n,checkChildren:t})||(r=!1))}),r}return!1}function p0(e){return e instanceof RX}var m0=class e{constructor(e){this.position=e}static fromJSON(t){return new e(t.position)}toJSON(){return{position:this.position}}};function rMe(e,t){let n=t.mapping.mapResult(e.position);return{position:new m0(n.pos),mapResult:n}}function iMe(e){return new m0(e)}function aMe(e,t,n){let{selection:r}=t,i=null;if(E1(r)&&(i=r.$cursor),i){let t=e.storedMarks??i.marks();return i.parent.type.allowsMarkType(n)&&(!!n.isInSet(t)||!t.some(e=>e.type.excludes(n)))}let{ranges:a}=r;return a.some(({$from:t,$to:r})=>{let i=t.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(n):!1;return e.doc.nodesBetween(t.pos,r.pos,(e,t,r)=>{if(i)return!1;if(e.isInline){let t=!r||r.type.allowsMarkType(n),a=!!n.isInSet(e.marks)||!e.marks.some(e=>e.type.excludes(n));i=t&&a}return!i}),i})}var oMe=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=n,{empty:o,ranges:s}=a,c=T1(e,r.schema);if(i)if(o){let e=z1(r,c);n.addStoredMark(c.create({...e,...t}))}else s.forEach(e=>{let i=e.$from.pos,a=e.$to.pos;r.doc.nodesBetween(i,a,(e,r)=>{let o=Math.max(r,i),s=Math.min(r+e.nodeSize,a);e.marks.find(e=>e.type===c)?e.marks.forEach(e=>{c===e.type&&n.addMark(o,s,c.create({...e.attrs,...t}))}):n.addMark(o,s,c.create(t))})});return aMe(r,n,c)},sMe=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),cMe=(e,t={})=>({state:n,dispatch:r,chain:i})=>{let a=y1(e,n.schema),o;return n.selection.$anchor.sameParent(n.selection.$head)&&(o=n.selection.$anchor.parent.attrs),a.isTextblock?i().command(({commands:e})=>yZ(a,{...o,...t})(n)?!0:e.clearNodes()).command(({state:e})=>yZ(a,{...o,...t})(e,r)).run():(console.warn(`[tiptap warn]: Currently "setNode()" only supports text block nodes.`),!1)},lMe=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,r=D1(e,0,n.content.size),i=RX.create(n,r);t.setSelection(i)}return!0},uMe=(e,t)=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=r,o,s;return typeof t==`number`?(o=t,s=t):t&&`from`in t&&`to`in t?(o=t.from,s=t.to):(o=a.from,s=a.to),i&&n.doc.nodesBetween(o,s,(t,r)=>{t.isText||n.setNodeMarkup(r,void 0,{...t.attrs,dir:e})}),!0},dMe=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,{from:r,to:i}=typeof e==`number`?{from:e,to:e}:e,a=IX.atStart(n).from,o=IX.atEnd(n).to,s=D1(r,a,o),c=D1(i,a,o),l=IX.create(n,s,c);t.setSelection(l)}return!0},fMe=e=>({state:t,dispatch:n})=>rke(y1(e,t.schema))(t,n);function h0(e,t){let n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){let r=n.filter(e=>t?.includes(e.type.name));e.tr.ensureMarks(r)}}var pMe=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{let{selection:a,doc:o}=t,{$from:s,$to:c}=a,l=i.extensionManager.attributes,u=c0(l,s.node().type.name,s.node().attrs);if(a instanceof RX&&a.node.isBlock)return!s.parentOffset||!mX(o,s.pos)?!1:(r&&(e&&h0(n,i.extensionManager.splittableMarks),t.split(s.pos).scrollIntoView()),!0);if(!s.parent.isBlock)return!1;let d=c.parentOffset===c.parent.content.size,f=s.depth===0?void 0:Vje(s.node(-1).contentMatchAt(s.indexAfter(-1))),p=d&&f?[{type:f,attrs:u}]:void 0,m=mX(t.doc,t.mapping.map(s.pos),1,p);if(!p&&!m&&mX(t.doc,t.mapping.map(s.pos),1,f?[{type:f}]:void 0)&&(m=!0,p=f?[{type:f,attrs:u}]:void 0),r){if(m&&(a instanceof IX&&t.deleteSelection(),t.split(t.mapping.map(s.pos),1,p),f&&!d&&!s.parentOffset&&s.parent.type!==f)){let e=t.mapping.map(s.before()),n=t.doc.resolve(e);s.node(-1).canReplaceWith(n.index(),n.index()+1,f)&&t.setNodeMarkup(t.mapping.map(s.before()),f)}e&&h0(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return m},mMe=(e,t={})=>({tr:n,state:r,dispatch:i,editor:a})=>{let o=y1(e,r.schema),{$from:s,$to:c}=r.selection,l=r.selection.node;if(l&&l.isBlock||s.depth<2||!s.sameParent(c))return!1;let u=s.node(-1);if(u.type!==o)return!1;let d=a.extensionManager.attributes;if(s.parent.content.size===0&&s.node(-1).childCount===s.indexAfter(-1)){if(s.depth===2||s.node(-3).type!==o||s.index(-2)!==s.node(-2).childCount-1)return!1;if(i){let e=KJ.empty,r=s.index(-1)?1:s.index(-2)?2:3;for(let t=s.depth-r;t>=s.depth-3;--t)e=KJ.from(s.node(t).copy(e));let i=s.indexAfter(-1){if(u>-1)return!1;e.isTextblock&&e.content.size===0&&(u=t+1)}),u>-1&&n.setSelection(IX.near(n.doc.resolve(u))),n.scrollIntoView()}return!0}let f=c.pos===s.end()?u.contentMatchAt(0).defaultType:null,p={...c0(d,u.type.name,u.attrs),...t},m={...c0(d,s.node().type.name,s.node().attrs),...t};n.delete(s.pos,c.pos);let h=f?[{type:o,attrs:p},{type:f,attrs:m}]:[{type:o,attrs:p}];if(!mX(n.doc,s.pos,2))return!1;if(i){let{selection:e,storedMarks:t}=r,{splittableMarks:o}=a.extensionManager,c=t||e.$to.parentOffset&&e.$from.marks();if(n.split(s.pos,2,h).scrollIntoView(),!c||!i)return!0;let l=c.filter(e=>o.includes(e.type.name));n.ensureMarks(l)}return!0},g0=(e,t)=>{let n=V1(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return n.node.type===i?.type&&hX(e.doc,n.pos)&&e.join(n.pos),!0},_0=(e,t)=>{let n=V1(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return n.node.type===i?.type&&hX(e.doc,r)&&e.join(r),!0},hMe=(e,t,n,r={})=>({editor:i,tr:a,state:o,dispatch:s,chain:c,commands:l,can:u})=>{let{extensions:d,splittableMarks:f}=i.extensionManager,p=y1(e,o.schema),m=y1(t,o.schema),{selection:h,storedMarks:g}=o,{$from:_,$to:v}=h,y=_.blockRange(v),b=g||h.$to.parentOffset&&h.$from.marks();if(!y)return!1;let x=V1(e=>d0(e.type.name,d))(h);if(y.depth>=1&&x&&y.depth-x.depth<=1){if(x.node.type===p)return l.liftListItem(m);if(d0(x.node.type.name,d)&&p.validContent(x.node.content)&&s)return c().command(()=>(a.setNodeMarkup(x.pos,p),!0)).command(()=>g0(a,p)).command(()=>_0(a,p)).run()}return!n||!b||!s?c().command(()=>u().wrapInList(p,r)?!0:l.clearNodes()).wrapInList(p,r).command(()=>g0(a,p)).command(()=>_0(a,p)).run():c().command(()=>{let e=u().wrapInList(p,r),t=b.filter(e=>f.includes(e.type.name));return a.ensureMarks(t),e?!0:l.clearNodes()}).wrapInList(p,r).command(()=>g0(a,p)).command(()=>_0(a,p)).run()},gMe=(e,t={},n={})=>({state:r,commands:i})=>{let{extendEmptyMarkRange:a=!1}=n,o=T1(e,r.schema);return l0(r,o,t)?i.unsetMark(o,{extendEmptyMarkRange:a}):i.setMark(o,t)},_Me=(e,t,n={})=>({state:r,commands:i})=>{let a=y1(e,r.schema),o=y1(t,r.schema),s=F1(r,a,n),c;return r.selection.$anchor.sameParent(r.selection.$head)&&(c=r.selection.$anchor.parent.attrs),s?i.setNode(o,c):i.setNode(a,{...c,...n})},vMe=(e,t={})=>({state:n,commands:r})=>{let i=y1(e,n.schema);return F1(n,i,t)?r.lift(i):r.wrapIn(i,t)},yMe=()=>({state:e,dispatch:t})=>{let n=e.plugins;for(let r=0;r=0;--e)t.step(n.steps[e].invert(n.docs[e]));if(a.text){let n=t.doc.resolve(a.from).marks();t.replaceWith(a.from,a.to,e.schema.text(a.text,n))}else t.delete(a.from,a.to)}return!0}}return!1},bMe=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,{empty:r,ranges:i}=n;return r||t&&i.forEach(t=>{e.removeMark(t.$from.pos,t.$to.pos)}),!0},xMe=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{extendEmptyMarkRange:a=!1}=t,{selection:o}=n,s=T1(e,r.schema),{$from:c,empty:l,ranges:u}=o;if(!i)return!0;if(l&&a){let{from:e,to:t}=o,r=w1(c,s,c.marks().find(e=>e.type===s)?.attrs);r&&(e=r.from,t=r.to),n.removeMark(e,t,s)}else u.forEach(e=>{n.removeMark(e.$from.pos,e.$to.pos,s)});return n.removeStoredMark(s),!0},SMe=e=>({tr:t,state:n,dispatch:r})=>{let{selection:i}=n,a,o;return typeof e==`number`?(a=e,o=e):e&&`from`in e&&`to`in e?(a=e.from,o=e.to):(a=i.from,o=i.to),r&&t.doc.nodesBetween(a,o,(e,n)=>{if(e.isText)return;let r={...e.attrs};delete r.dir,t.setNodeMarkup(n,void 0,r)}),!0},CMe=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=I1(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=y1(e,r.schema)),s===`mark`&&(o=T1(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{let s=e.$from.pos,l=e.$to.pos,u,d,f,p;n.selection.empty?r.doc.nodesBetween(s,l,(e,t)=>{a&&a===e.type&&(c=!0,f=Math.max(t,s),p=Math.min(t+e.nodeSize,l),u=t,d=e)}):r.doc.nodesBetween(s,l,(e,r)=>{r=s&&r<=l&&(a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,{...e.attrs,...t})),o&&e.marks.length&&e.marks.forEach(a=>{if(o===a.type&&(c=!0,i)){let i=Math.max(r,s),c=Math.min(r+e.nodeSize,l);n.addMark(i,c,o.create({...a.attrs,...t}))}}))}),d&&(u!==void 0&&i&&n.setNodeMarkup(u,void 0,{...d.attrs,...t}),o&&d.marks.length&&d.marks.forEach(e=>{o===e.type&&i&&n.addMark(f,p,o.create({...e.attrs,...t}))}))}),c},wMe=(e,t={})=>({state:n,dispatch:r})=>YOe(y1(e,n.schema),t)(n,r),TMe=(e,t={})=>({state:n,dispatch:r})=>ZOe(y1(e,n.schema),t)(n,r),EMe=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){let n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}once(e,t){let n=(...r)=>{this.off(e,n),t.apply(this,r)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}},v0=class{constructor(e){this.find=e.find,this.handler=e.handler,this.undoable=e.undoable??!0}},DMe=(e,t)=>{if(b1(t))return t.exec(e);let n=t(e);if(!n)return null;let r=[n.text];return r.index=n.index,r.input=e,r.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn(`[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".`),r.push(n.replaceWith)),r};function y0(e){let{editor:t,from:n,to:r,text:i,rules:a,plugin:o}=e,{view:s}=t;if(s.composing)return!1;let c=s.state.doc.resolve(n);if(c.parent.type.spec.code||(c.nodeBefore||c.nodeAfter)?.marks.find(e=>e.type.spec.code))return!1;let l=!1,u=$je(c)+i;return a.forEach(e=>{if(l)return;let a=DMe(u,e.find);if(!a)return;let c=s.state.tr,d=g1({state:s.state,transaction:c}),f={from:n-(a[0].length-i.length),to:r},{commands:p,chain:m,can:h}=new _1({editor:t,state:d});e.handler({state:d,range:f,match:a,commands:p,chain:m,can:h})===null||!c.steps.length||(e.undoable&&c.setMeta(o,{transform:c,from:n,to:r,text:i}),s.dispatch(c),l=!0)}),l}function OMe(e){let{editor:t,rules:n}=e,r=new YX({state:{init(){return null},apply(e,i,a){let o=e.getMeta(r);if(o)return o;let s=e.getMeta(`applyInputRules`);return s&&setTimeout(()=>{let{text:e}=s;e=typeof e==`string`?e:W1(KJ.from(e),a.schema);let{from:i}=s;y0({editor:t,from:i,to:i+e.length,text:e,rules:n,plugin:r})}),e.selectionSet||e.docChanged?null:i}},props:{handleTextInput(e,i,a,o){return y0({editor:t,from:i,to:a,text:o,rules:n,plugin:r})},handleDOMEvents:{compositionend:e=>(setTimeout(()=>{let{$cursor:i}=e.state.selection;i&&y0({editor:t,from:i.pos,to:i.pos,text:``,rules:n,plugin:r})}),!1)},handleKeyDown(e,i){if(i.key!==`Enter`)return!1;let{$cursor:a}=e.state.selection;return a?y0({editor:t,from:a.pos,to:a.pos,text:` +`,rules:n,plugin:r}):!1}},isInputRules:!0});return r}function kMe(e){return Object.prototype.toString.call(e).slice(8,-1)}function b0(e){return kMe(e)===`Object`?e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype:!1}function x0(e,t){let n={...e};return b0(e)&&b0(t)&&Object.keys(t).forEach(r=>{b0(t[r])&&b0(e[r])?n[r]=x0(e[r],t[r]):n[r]=t[r]}),n}var S0=class{constructor(e={}){this.type=`extendable`,this.parent=null,this.child=null,this.name=``,this.config={name:this.name},this.config={...this.config,...e},this.name=this.config.name}get options(){return{...K1(H1(this,`addOptions`,{name:this.name}))||{}}}get storage(){return{...K1(H1(this,`addStorage`,{name:this.name,options:this.options}))||{}}}configure(e={}){let t=this.extend({...this.config,addOptions:()=>x0(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){let t=new this.constructor({...this.config,...e});return t.parent=this,this.child=t,t.name=`name`in e?e.name:t.parent.name,t}},C0=class e extends S0{constructor(){super(...arguments),this.type=`mark`}static create(t={}){return new e(typeof t==`function`?t():t)}static handleExit({editor:e,mark:t}){let{tr:n}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){let i=r.marks();if(!i.find(e=>e?.type.name===t.name))return!1;let a=i.find(e=>e?.type.name===t.name);return a&&n.removeStoredMark(a),n.insertText(` `,r.pos),e.view.dispatch(n),!0}return!1}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}};function AMe(e){return typeof e==`number`}var jMe=class{constructor(e){this.find=e.find,this.handler=e.handler}},MMe=(e,t,n)=>{if(b1(t))return[...e.matchAll(t)];let r=t(e,n);return r?r.map(t=>{let n=[t.text];return n.index=t.index,n.input=e,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn(`[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".`),n.push(t.replaceWith)),n}):[]};function NMe(e){let{editor:t,state:n,from:r,to:i,rule:a,pasteEvent:o,dropEvent:s}=e,{commands:c,chain:l,can:u}=new _1({editor:t,state:n}),d=[];return n.doc.nodesBetween(r,i,(e,t)=>{if(e.type?.spec?.code||!(e.isText||e.isTextblock||e.isInline))return;let f=e.content?.size??e.nodeSize??0,p=Math.max(r,t),m=Math.min(i,t+f);p>=m||MMe(e.isText?e.text||``:e.textBetween(p-t,m-t,void 0,``),a.find,o).forEach(e=>{if(e.index===void 0)return;let t=p+e.index+1,r=t+e[0].length,i={from:n.tr.mapping.map(t),to:n.tr.mapping.map(r)},f=a.handler({state:n,range:i,match:e,commands:c,chain:l,can:u,pasteEvent:o,dropEvent:s});d.push(f)})}),d.every(e=>e!==null)}var w0=null,PMe=e=>{var t;let n=new ClipboardEvent(`paste`,{clipboardData:new DataTransfer});return(t=n.clipboardData)==null||t.setData(`text/html`,e),n};function FMe(e){let{editor:t,rules:n}=e,r=null,i=!1,a=!1,o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,s;try{s=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{s=null}let c=({state:e,from:n,to:r,rule:i,pasteEvt:a})=>{let c=e.tr;if(!(!NMe({editor:t,state:g1({state:e,transaction:c}),from:Math.max(n-1,0),to:r.b-1,rule:i,pasteEvent:a,dropEvent:s})||!c.steps.length)){try{s=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{s=null}return o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,c}};return n.map(e=>new YX({view(e){let n=n=>{r=e.dom.parentElement?.contains(n.target)?e.dom.parentElement:null,r&&(w0=t)},i=()=>{w0&&=null};return window.addEventListener(`dragstart`,n),window.addEventListener(`dragend`,i),{destroy(){window.removeEventListener(`dragstart`,n),window.removeEventListener(`dragend`,i)}}},props:{handleDOMEvents:{drop:(e,t)=>{if(a=r===e.dom.parentElement,s=t,!a){let e=w0;e?.isEditable&&setTimeout(()=>{let t=e.state.selection;t&&e.commands.deleteRange({from:t.from,to:t.to})},10)}return!1},paste:(e,t)=>{let n=t.clipboardData?.getData(`text/html`);return o=t,i=!!n?.includes(`data-pm-slice`),!1}}},appendTransaction:(t,n,r)=>{let s=t[0],l=s.getMeta(`uiEvent`)===`paste`&&!i,u=s.getMeta(`uiEvent`)===`drop`&&!a,d=s.getMeta(`applyPasteRules`),f=!!d;if(!l&&!u&&!f)return;if(f){let{text:t}=d;t=typeof t==`string`?t:W1(KJ.from(t),r.schema);let{from:n}=d,i=n+t.length,a=PMe(t);return c({rule:e,state:r,from:n,to:{b:i},pasteEvt:a})}let p=n.doc.content.findDiffStart(r.doc.content),m=n.doc.content.findDiffEnd(r.doc.content);if(!(!AMe(p)||!m||p===m.b))return c({rule:e,state:r,from:p,to:m,pasteEvt:o})}}))}var T0=class{constructor(e,t){this.splittableMarks=[],this.editor=t,this.baseExtensions=e,this.extensions=t0(e),this.schema=Kje(this.extensions,t),this.setupExtensions()}get commands(){return this.extensions.reduce((e,t)=>{let n=H1(t,`addCommands`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:this.editor,type:s0(t.name,this.schema)});return n?{...e,...n()}:e},{})}get plugins(){let{editor:e}=this;return e0([...this.extensions].reverse()).flatMap(t=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:s0(t.name,this.schema)},r=[],i=H1(t,`addKeyboardShortcuts`,n),a={};if(t.type===`mark`&&H1(t,`exitable`,n)&&(a.ArrowRight=()=>C0.handleExit({editor:e,mark:t})),i){let t=Object.fromEntries(Object.entries(i()).map(([t,n])=>[t,()=>n({editor:e})]));a={...a,...t}}let o=YAe(a);r.push(o);let s=H1(t,`addInputRules`,n);if(u0(t,e.options.enableInputRules)&&s){let t=s();if(t&&t.length){let n=OMe({editor:e,rules:t}),i=Array.isArray(n)?n:[n];r.push(...i)}}let c=H1(t,`addPasteRules`,n);if(u0(t,e.options.enablePasteRules)&&c){let t=c();if(t&&t.length){let n=FMe({editor:e,rules:t});r.push(...n)}}let l=H1(t,`addProseMirrorPlugins`,n);if(l){let e=l();r.push(...e)}return r})}get attributes(){return J1(this.extensions)}get nodeViews(){let{editor:e}=this,{nodeExtensions:t}=q1(this.extensions);return Object.fromEntries(t.filter(e=>!!H1(e,`addNodeView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=H1(t,`addNodeView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:y1(t.name,this.schema)});if(!r)return[];let i=r();return i?[t.name,(r,a,o,s,c)=>i({node:r,view:a,getPos:o,decorations:s,innerDecorations:c,editor:e,extension:t,HTMLAttributes:X1(r,n)})]:[]}))}dispatchTransaction(e){let{editor:t}=this;return e0([...this.extensions].reverse()).reduceRight((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:s0(n.name,this.schema)},i=H1(n,`dispatchTransaction`,r);return i?t=>{i.call(r,{transaction:t,next:e})}:e},e)}get markViews(){let{editor:e}=this,{markExtensions:t}=q1(this.extensions);return Object.fromEntries(t.filter(e=>!!H1(e,`addMarkView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=H1(t,`addMarkView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:T1(t.name,this.schema)});return r?[t.name,(i,a,o)=>{let s=X1(i,n);return r()({mark:i,view:a,inline:o,editor:e,extension:t,HTMLAttributes:s,updateAttributes:t=>{JMe(i,e,t)}})}]:[]}))}setupExtensions(){let e=this.extensions;this.editor.extensionStorage=Object.fromEntries(e.map(e=>[e.name,e.storage])),e.forEach(e=>{let t={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:s0(e.name,this.schema)};e.type===`mark`&&(K1(H1(e,`keepOnSplit`,t))??!0)&&this.splittableMarks.push(e.name);let n=H1(e,`onBeforeCreate`,t),r=H1(e,`onCreate`,t),i=H1(e,`onUpdate`,t),a=H1(e,`onSelectionUpdate`,t),o=H1(e,`onTransaction`,t),s=H1(e,`onFocus`,t),c=H1(e,`onBlur`,t),l=H1(e,`onDestroy`,t);n&&this.editor.on(`beforeCreate`,n),r&&this.editor.on(`create`,r),i&&this.editor.on(`update`,i),a&&this.editor.on(`selectionUpdate`,a),o&&this.editor.on(`transaction`,o),s&&this.editor.on(`focus`,s),c&&this.editor.on(`blur`,c),l&&this.editor.on(`destroy`,l)})}};T0.resolve=t0,T0.sort=e0,T0.flatten=U1,h1({},{ClipboardTextSerializer:()=>D0,Commands:()=>O0,Delete:()=>k0,Drop:()=>A0,Editable:()=>j0,FocusEvents:()=>N0,Keymap:()=>P0,Paste:()=>F0,Tabindex:()=>I0,TextDirection:()=>L0,focusEventsPluginKey:()=>M0});var E0=class e extends S0{constructor(){super(...arguments),this.type=`extension`}static create(t={}){return new e(typeof t==`function`?t():t)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}},D0=E0.create({name:`clipboardTextSerializer`,addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new YX({key:new QX(`clipboardTextSerializer`),props:{clipboardTextSerializer:()=>{let{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:i}=t,{ranges:a}=i,o=Math.min(...a.map(e=>e.$from.pos)),s=Math.max(...a.map(e=>e.$to.pos)),c=r0(n);return n0(r,{from:o,to:s},{...this.options.blockSeparator===void 0?{}:{blockSeparator:this.options.blockSeparator},textSerializers:c})}}})]}}),O0=E0.create({name:`commands`,addCommands(){return{...v1}}}),k0=E0.create({name:`delete`,onUpdate({transaction:e,appendedTransactions:t}){let n=()=>{var n;if(((n=this.editor.options.coreExtensionOptions?.delete)?.filterTransaction)?.call(n,e)??e.getMeta(`y-sync$`))return;let r=B1(e.before,[e,...t]);a0(r).forEach(t=>{r.mapping.mapResult(t.oldRange.from).deletedAfter&&r.mapping.mapResult(t.oldRange.to).deletedBefore&&r.before.nodesBetween(t.oldRange.from,t.oldRange.to,(n,i)=>{let a=i+n.nodeSize-2,o=t.oldRange.from<=i&&a<=t.oldRange.to;this.editor.emit(`delete`,{type:`node`,node:n,from:i,to:a,newFrom:r.mapping.map(i),newTo:r.mapping.map(a),deletedRange:t.oldRange,newRange:t.newRange,partial:!o,editor:this.editor,transaction:e,combinedTransform:r})})});let i=r.mapping;r.steps.forEach((t,n)=>{if(t instanceof nX){let a=i.slice(n).map(t.from,-1),o=i.slice(n).map(t.to),s=i.invert().map(a,-1),c=i.invert().map(o),l=r.doc.nodeAt(a-1)?.marks.some(e=>e.eq(t.mark)),u=r.doc.nodeAt(o)?.marks.some(e=>e.eq(t.mark));this.editor.emit(`delete`,{type:`mark`,mark:t.mark,from:t.from,to:t.to,deletedRange:{from:s,to:c},newRange:{from:a,to:o},partial:!!(u||l),editor:this.editor,transaction:e,combinedTransform:r})}})};this.editor.options.coreExtensionOptions?.delete?.async??!0?setTimeout(n,0):n()}}),A0=E0.create({name:`drop`,addProseMirrorPlugins(){return[new YX({key:new QX(`tiptapDrop`),props:{handleDrop:(e,t,n,r)=>{this.editor.emit(`drop`,{editor:this.editor,event:t,slice:n,moved:r})}}})]}}),j0=E0.create({name:`editable`,addProseMirrorPlugins(){return[new YX({key:new QX(`editable`),props:{editable:()=>this.editor.options.editable}})]}}),M0=new QX(`focusEvents`),N0=E0.create({name:`focusEvents`,addProseMirrorPlugins(){let{editor:e}=this;return[new YX({key:M0,props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;let r=e.state.tr.setMeta(`focus`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;let r=e.state.tr.setMeta(`blur`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1}}}})]}}),P0=E0.create({name:`keymap`,addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({commands:e})=>[()=>e.undoInputRule(),()=>e.command(({tr:t})=>{let{selection:n,doc:r}=t,{empty:i,$anchor:a}=n,{pos:o,parent:s}=a,c=a.parent.isTextblock&&o>0?t.doc.resolve(o-1):a,l=c.parent.type.spec.isolating,u=a.pos-a.parentOffset,d=l&&c.parent.childCount===1?u===a.pos:NX.atStart(r).from===o;return!i||!s.type.isTextblock||s.textContent.length||!d||d&&a.parent.type.name===`paragraph`?!1:e.clearNodes()}),()=>e.deleteSelection(),()=>e.joinBackward(),()=>e.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.deleteCurrentNode(),()=>e.joinForward(),()=>e.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:e})=>[()=>e.newlineInCode(),()=>e.createParagraphNear(),()=>e.liftEmptyBlock(),()=>e.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},r={...n},i={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return A1()||P1()?i:r},addProseMirrorPlugins(){return[new YX({key:new QX(`clearDocument`),appendTransaction:(e,t,n)=>{if(e.some(e=>e.getMeta(`composition`)))return;let r=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),i=e.some(e=>e.getMeta(`preventClearDocument`));if(!r||i)return;let{empty:a,from:o,to:s}=t.selection,c=NX.atStart(t.doc).from,l=NX.atEnd(t.doc).to;if(a||!(o===c&&s===l)||!f0(n.doc))return;let u=n.tr,d=g1({state:n,transaction:u}),{commands:f}=new _1({editor:this.editor,state:d});if(f.clearNodes(),u.steps.length)return u}})]}}),F0=E0.create({name:`paste`,addProseMirrorPlugins(){return[new YX({key:new QX(`tiptapPaste`),props:{handlePaste:(e,t,n)=>{this.editor.emit(`paste`,{editor:this.editor,event:t,slice:n})}}})]}}),I0=E0.create({name:`tabindex`,addProseMirrorPlugins(){return[new YX({key:new QX(`tabindex`),props:{attributes:()=>this.editor.isEditable?{tabindex:`0`}:{}}})]}}),L0=E0.create({name:`textDirection`,addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];let{nodeExtensions:e}=q1(this.extensions);return[{types:e.filter(e=>e.name!==`text`).map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{let t=e.getAttribute(`dir`);return t&&(t===`ltr`||t===`rtl`||t===`auto`)?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new YX({key:new QX(`textDirection`),props:{attributes:()=>{let e=this.options.direction;return e?{dir:e}:{}}}})]}}),IMe=class e{constructor(e,t,n=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=r}get name(){return this.node.type.name}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){return this.actualDepth??this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can\u2019t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+ +!this.node.isText}get parent(){if(this.depth===0)return null;let t=this.resolvedPos.start(this.resolvedPos.depth-1);return new e(this.resolvedPos.doc.resolve(t),this.editor)}get before(){let t=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.from-3)),new e(t,this.editor)}get after(){let t=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.to+3)),new e(t,this.editor)}get children(){let t=[];return this.node.content.forEach((n,r)=>{let i=n.isBlock&&!n.isTextblock,a=n.isAtom&&!n.isText,o=n.isInline,s=this.pos+r+ +!a;if(s<0||s>this.resolvedPos.doc.nodeSize-2)return;let c=this.resolvedPos.doc.resolve(s);if(!i&&!o&&c.depth<=this.depth)return;let l=new e(c,this.editor,i,i||o?n:null);i&&(l.actualDepth=this.depth+1),t.push(l)}),t}get firstChild(){return this.children[0]||null}get lastChild(){let e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,r=this.parent;for(;r&&!n;){if(r.node.type.name===e)if(Object.keys(t).length>0){let e=r.node.attrs,n=Object.keys(t);for(let r=0;r{n&&r.length>0||(a.node.type.name===e&&i.every(e=>t[e]===a.node.attrs[e])&&r.push(a),!(n&&r.length>0)&&(r=r.concat(a.querySelectorAll(e,t,n))))}),r}setAttribute(e){let{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},LMe=`.ProseMirror { position: relative; } @@ -8621,15 +8621,15 @@ img.ProseMirror-separator { .ProseMirror-focused .ProseMirror-gapcursor { display: block; -}`;function LMe(e,t,n){let r=document.querySelector(`style[data-tiptap-style${n?`-${n}`:``}]`);if(r!==null)return r;let i=document.createElement(`style`);return t&&i.setAttribute(`nonce`,t),i.setAttribute(`data-tiptap-style${n?`-${n}`:``}`,``),i.innerHTML=e,document.getElementsByTagName(`head`)[0].appendChild(i),i}var RMe=class extends TMe{constructor(e={}){super(),this.css=null,this.className=`tiptap`,this.editorView=null,this.isFocused=!1,this.isInitialized=!1,this.extensionStorage={},this.instanceId=Math.random().toString(36).slice(2,9),this.options={element:typeof document<`u`?document.createElement(`div`):null,content:``,injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,textDirection:void 0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onMount:()=>null,onUnmount:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:e})=>{throw e},onPaste:()=>null,onDrop:()=>null,onDelete:()=>null,enableExtensionDispatchTransaction:!0},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.utils={getUpdatedPosition:nMe,createMappablePosition:rMe},this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on(`beforeCreate`,this.options.onBeforeCreate),this.emit(`beforeCreate`,{editor:this}),this.on(`mount`,this.options.onMount),this.on(`unmount`,this.options.onUnmount),this.on(`contentError`,this.options.onContentError),this.on(`create`,this.options.onCreate),this.on(`update`,this.options.onUpdate),this.on(`selectionUpdate`,this.options.onSelectionUpdate),this.on(`transaction`,this.options.onTransaction),this.on(`focus`,this.options.onFocus),this.on(`blur`,this.options.onBlur),this.on(`destroy`,this.options.onDestroy),this.on(`drop`,({event:e,slice:t,moved:n})=>this.options.onDrop(e,t,n)),this.on(`paste`,({event:e,slice:t})=>this.options.onPaste(e,t)),this.on(`delete`,this.options.onDelete);let t=this.createDoc(),n=O1(t,this.options.autofocus);this.editorState=LOe.create({doc:t,schema:this.schema,selection:n||void 0}),this.options.element&&this.mount(this.options.element)}mount(e){if(typeof document>`u`)throw Error(`[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.`);this.createView(e),this.emit(`mount`,{editor:this}),this.css&&!document.head.contains(this.css)&&document.head.appendChild(this.css),window.setTimeout(()=>{this.isDestroyed||(this.options.autofocus!==!1&&this.options.autofocus!==null&&this.commands.focus(this.options.autofocus),this.emit(`create`,{editor:this}),this.isInitialized=!0)},0)}unmount(){if(this.editorView){let e=this.editorView.dom;e?.editor&&delete e.editor,this.editorView.destroy()}if(this.editorView=null,this.isInitialized=!1,this.css&&!document.querySelectorAll(`.${this.className}`).length)try{typeof this.css.remove==`function`?this.css.remove():this.css.parentNode&&this.css.parentNode.removeChild(this.css)}catch(e){console.warn(`Failed to remove CSS element:`,e)}this.css=null,this.emit(`unmount`,{editor:this})}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager.chain()}can(){return this.commandManager.can()}injectCSS(){this.options.injectCSS&&typeof document<`u`&&(this.css=LMe(IMe,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},!(!this.editorView||!this.state||this.isDestroyed)&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit(`update`,{editor:this,transaction:this.state.tr,appendedTransactions:[]})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get view(){return this.editorView?this.editorView:new Proxy({state:this.editorState,updateState:e=>{this.editorState=e},dispatch:e=>{this.dispatchTransaction(e)},composing:!1,dragging:null,editable:!0,isDestroyed:!1},{get:(e,t)=>{if(this.editorView)return this.editorView[t];if(t===`state`)return this.editorState;if(t in e)return Reflect.get(e,t);throw Error(`[tiptap error]: The editor view is not available. Cannot access view['${t}']. The editor may not be mounted yet.`)}})}get state(){return this.editorView&&(this.editorState=this.view.state),this.editorState}registerPlugin(e,t){let n=G1(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}unregisterPlugin(e){if(this.isDestroyed)return;let t=this.state.plugins,n=t;if([].concat(e).forEach(e=>{let t=typeof e==`string`?`${e}$`:e.key;n=n.filter(e=>!e.key.startsWith(t))}),t.length===n.length)return;let r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}createExtensionManager(){let e=[...this.options.enableCoreExtensions?[j0,D0.configure({blockSeparator:this.options.coreExtensionOptions?.clipboardTextSerializer?.blockSeparator}),O0,N0,P0,I0,A0,F0,k0,L0.configure({direction:this.options.textDirection})].filter(e=>typeof this.options.enableCoreExtensions==`object`?this.options.enableCoreExtensions[e.name]!==!1:!0):[],...this.options.extensions].filter(e=>[`extension`,`node`,`mark`].includes(e?.type));this.extensionManager=new T0(e,this)}createCommandManager(){this.commandManager=new _1({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let e;try{e=R1(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(t){if(!(t instanceof Error)||![`[tiptap error]: Invalid JSON content`,`[tiptap error]: Invalid HTML content`].includes(t.message))throw t;this.emit(`contentError`,{editor:this,error:t,disableCollaboration:()=>{`collaboration`in this.storage&&typeof this.storage.collaboration==`object`&&this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(e=>e.name!==`collaboration`),this.createExtensionManager()}}),e=R1(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}return e}createView(e){let{editorProps:t,enableExtensionDispatchTransaction:n}=this.options,r=t.dispatchTransaction||this.dispatchTransaction.bind(this),i=n?this.extensionManager.dispatchTransaction(r):r;this.editorView=new r1(e,{...t,attributes:{role:`textbox`,...t?.attributes},dispatchTransaction:i,state:this.editorState,markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews});let a=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(a),this.prependClass(),this.injectCSS();let o=this.view.dom;o.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`${this.className} ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;let t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(e=>this.capturedTransaction?.step(e));return}let{state:t,transactions:n}=this.state.applyTransaction(e),r=!this.state.selection.eq(t.selection),i=n.includes(e),a=this.state;if(this.emit(`beforeTransaction`,{editor:this,transaction:e,nextState:t}),!i)return;this.view.updateState(t),this.emit(`transaction`,{editor:this,transaction:e,appendedTransactions:n.slice(1)}),r&&this.emit(`selectionUpdate`,{editor:this,transaction:e});let o=n.findLast(e=>e.getMeta(`focus`)||e.getMeta(`blur`)),s=o?.getMeta(`focus`),c=o?.getMeta(`blur`);s&&this.emit(`focus`,{editor:this,event:s.event,transaction:o}),c&&this.emit(`blur`,{editor:this,event:c.event,transaction:o}),!(e.getMeta(`preventUpdate`)||!n.some(e=>e.docChanged)||a.doc.eq(t.doc))&&this.emit(`update`,{editor:this,transaction:e,appendedTransactions:n.slice(1)})}getAttributes(e){return i0(this.state,e)}isActive(e,t){let n=typeof e==`string`?e:null,r=typeof e==`string`?t:e;return $je(this.state,n,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return W1(this.state.doc.content,this.schema)}getText(e){let{blockSeparator:t=` +}`;function RMe(e,t,n){let r=document.querySelector(`style[data-tiptap-style${n?`-${n}`:``}]`);if(r!==null)return r;let i=document.createElement(`style`);return t&&i.setAttribute(`nonce`,t),i.setAttribute(`data-tiptap-style${n?`-${n}`:``}`,``),i.innerHTML=e,document.getElementsByTagName(`head`)[0].appendChild(i),i}var zMe=class extends EMe{constructor(e={}){super(),this.css=null,this.className=`tiptap`,this.editorView=null,this.isFocused=!1,this.isInitialized=!1,this.extensionStorage={},this.instanceId=Math.random().toString(36).slice(2,9),this.options={element:typeof document<`u`?document.createElement(`div`):null,content:``,injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,textDirection:void 0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onMount:()=>null,onUnmount:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:e})=>{throw e},onPaste:()=>null,onDrop:()=>null,onDelete:()=>null,enableExtensionDispatchTransaction:!0},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.utils={getUpdatedPosition:rMe,createMappablePosition:iMe},this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on(`beforeCreate`,this.options.onBeforeCreate),this.emit(`beforeCreate`,{editor:this}),this.on(`mount`,this.options.onMount),this.on(`unmount`,this.options.onUnmount),this.on(`contentError`,this.options.onContentError),this.on(`create`,this.options.onCreate),this.on(`update`,this.options.onUpdate),this.on(`selectionUpdate`,this.options.onSelectionUpdate),this.on(`transaction`,this.options.onTransaction),this.on(`focus`,this.options.onFocus),this.on(`blur`,this.options.onBlur),this.on(`destroy`,this.options.onDestroy),this.on(`drop`,({event:e,slice:t,moved:n})=>this.options.onDrop(e,t,n)),this.on(`paste`,({event:e,slice:t})=>this.options.onPaste(e,t)),this.on(`delete`,this.options.onDelete);let t=this.createDoc(),n=O1(t,this.options.autofocus);this.editorState=ROe.create({doc:t,schema:this.schema,selection:n||void 0}),this.options.element&&this.mount(this.options.element)}mount(e){if(typeof document>`u`)throw Error(`[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.`);this.createView(e),this.emit(`mount`,{editor:this}),this.css&&!document.head.contains(this.css)&&document.head.appendChild(this.css),window.setTimeout(()=>{this.isDestroyed||(this.options.autofocus!==!1&&this.options.autofocus!==null&&this.commands.focus(this.options.autofocus),this.emit(`create`,{editor:this}),this.isInitialized=!0)},0)}unmount(){if(this.editorView){let e=this.editorView.dom;e?.editor&&delete e.editor,this.editorView.destroy()}if(this.editorView=null,this.isInitialized=!1,this.css&&!document.querySelectorAll(`.${this.className}`).length)try{typeof this.css.remove==`function`?this.css.remove():this.css.parentNode&&this.css.parentNode.removeChild(this.css)}catch(e){console.warn(`Failed to remove CSS element:`,e)}this.css=null,this.emit(`unmount`,{editor:this})}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager.chain()}can(){return this.commandManager.can()}injectCSS(){this.options.injectCSS&&typeof document<`u`&&(this.css=RMe(LMe,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},!(!this.editorView||!this.state||this.isDestroyed)&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit(`update`,{editor:this,transaction:this.state.tr,appendedTransactions:[]})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get view(){return this.editorView?this.editorView:new Proxy({state:this.editorState,updateState:e=>{this.editorState=e},dispatch:e=>{this.dispatchTransaction(e)},composing:!1,dragging:null,editable:!0,isDestroyed:!1},{get:(e,t)=>{if(this.editorView)return this.editorView[t];if(t===`state`)return this.editorState;if(t in e)return Reflect.get(e,t);throw Error(`[tiptap error]: The editor view is not available. Cannot access view['${t}']. The editor may not be mounted yet.`)}})}get state(){return this.editorView&&(this.editorState=this.view.state),this.editorState}registerPlugin(e,t){let n=G1(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}unregisterPlugin(e){if(this.isDestroyed)return;let t=this.state.plugins,n=t;if([].concat(e).forEach(e=>{let t=typeof e==`string`?`${e}$`:e.key;n=n.filter(e=>!e.key.startsWith(t))}),t.length===n.length)return;let r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}createExtensionManager(){let e=[...this.options.enableCoreExtensions?[j0,D0.configure({blockSeparator:this.options.coreExtensionOptions?.clipboardTextSerializer?.blockSeparator}),O0,N0,P0,I0,A0,F0,k0,L0.configure({direction:this.options.textDirection})].filter(e=>typeof this.options.enableCoreExtensions==`object`?this.options.enableCoreExtensions[e.name]!==!1:!0):[],...this.options.extensions].filter(e=>[`extension`,`node`,`mark`].includes(e?.type));this.extensionManager=new T0(e,this)}createCommandManager(){this.commandManager=new _1({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let e;try{e=R1(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(t){if(!(t instanceof Error)||![`[tiptap error]: Invalid JSON content`,`[tiptap error]: Invalid HTML content`].includes(t.message))throw t;this.emit(`contentError`,{editor:this,error:t,disableCollaboration:()=>{`collaboration`in this.storage&&typeof this.storage.collaboration==`object`&&this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(e=>e.name!==`collaboration`),this.createExtensionManager()}}),e=R1(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}return e}createView(e){let{editorProps:t,enableExtensionDispatchTransaction:n}=this.options,r=t.dispatchTransaction||this.dispatchTransaction.bind(this),i=n?this.extensionManager.dispatchTransaction(r):r;this.editorView=new r1(e,{...t,attributes:{role:`textbox`,...t?.attributes},dispatchTransaction:i,state:this.editorState,markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews});let a=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(a),this.prependClass(),this.injectCSS();let o=this.view.dom;o.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`${this.className} ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;let t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(e=>this.capturedTransaction?.step(e));return}let{state:t,transactions:n}=this.state.applyTransaction(e),r=!this.state.selection.eq(t.selection),i=n.includes(e),a=this.state;if(this.emit(`beforeTransaction`,{editor:this,transaction:e,nextState:t}),!i)return;this.view.updateState(t),this.emit(`transaction`,{editor:this,transaction:e,appendedTransactions:n.slice(1)}),r&&this.emit(`selectionUpdate`,{editor:this,transaction:e});let o=n.findLast(e=>e.getMeta(`focus`)||e.getMeta(`blur`)),s=o?.getMeta(`focus`),c=o?.getMeta(`blur`);s&&this.emit(`focus`,{editor:this,event:s.event,transaction:o}),c&&this.emit(`blur`,{editor:this,event:c.event,transaction:o}),!(e.getMeta(`preventUpdate`)||!n.some(e=>e.docChanged)||a.doc.eq(t.doc))&&this.emit(`update`,{editor:this,transaction:e,appendedTransactions:n.slice(1)})}getAttributes(e){return i0(this.state,e)}isActive(e,t){let n=typeof e==`string`?e:null,r=typeof e==`string`?t:e;return eMe(this.state,n,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return W1(this.state.doc.content,this.schema)}getText(e){let{blockSeparator:t=` -`,textSerializers:n={}}=e||{};return qje(this.state.doc,{blockSeparator:t,textSerializers:{...r0(this.schema),...n}})}get isEmpty(){return f0(this.state.doc)}destroy(){this.emit(`destroy`),this.unmount(),this.removeAllListeners()}get isDestroyed(){return this.editorView?.isDestroyed??!0}$node(e,t){return this.$doc?.querySelector(e,t)||null}$nodes(e,t){return this.$doc?.querySelectorAll(e,t)||null}$pos(e){return new FMe(this.state.doc.resolve(e),this)}get $doc(){return this.$pos(0)}};function R0(e){return new v0({find:e.find,handler:({state:t,range:n,match:r})=>{let i=K1(e.getAttributes,void 0,r);if(i===!1||i===null)return null;let{tr:a}=t,o=r[r.length-1],s=r[0];if(o){let r=s.search(/\S/),c=n.from+s.indexOf(o),l=c+o.length;if(o0(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>c).length)return null;ln.from&&a.delete(n.from+r,c);let u=n.from+r+o.length;a.addMark(n.from+r,u,e.type.create(i||{})),a.removeStoredMark(e.type)}},undoable:e.undoable})}function z0(e){return new v0({find:e.find,handler:({state:t,range:n,match:r})=>{let i=K1(e.getAttributes,void 0,r)||{},{tr:a}=t,o=n.from,s=n.to,c=e.type.create(i);if(r[1]){let e=o+r[0].lastIndexOf(r[1]);e>s?e=s:s=e+r[1].length;let t=r[0][r[0].length-1];a.insertText(t,o+r[0].length-1),a.replaceWith(e,s,c)}else if(r[0]){let t=e.type.isInline?o:o-1;a.insert(t,e.type.create(i)).delete(a.mapping.map(o),a.mapping.map(s))}a.scrollIntoView()},undoable:e.undoable})}function B0(e){return new v0({find:e.find,handler:({state:t,range:n,match:r})=>{let i=t.doc.resolve(n.from),a=K1(e.getAttributes,void 0,r)||{};if(!i.node(-1).canReplaceWith(i.index(-1),i.indexAfter(-1),e.type))return null;t.tr.delete(n.from,n.to).setBlockType(n.from,n.from,e.type,a)},undoable:e.undoable})}function V0(e){return new v0({find:e.find,handler:({state:t,range:n,match:r,chain:i})=>{let a=K1(e.getAttributes,void 0,r)||{},o=t.tr.delete(n.from,n.to),s=o.doc.resolve(n.from).blockRange(),c=s&&uX(s,e.type,a);if(!c)return null;if(o.wrap(s,c),e.keepMarks&&e.editor){let{selection:n,storedMarks:r}=t,{splittableMarks:i}=e.editor.extensionManager,a=r||n.$to.parentOffset&&n.$from.marks();if(a){let e=a.filter(e=>i.includes(e.type.name));o.ensureMarks(e)}}if(e.keepAttributes){let t=e.type.name===`bulletList`||e.type.name===`orderedList`?`listItem`:`taskList`;i().updateAttributes(t,a).run()}let l=o.doc.resolve(n.from-1).nodeBefore;l&&l.type===e.type&&hX(o.doc,n.from-1)&&(!e.joinPredicate||e.joinPredicate(r,l))&&o.join(n.from-1)},undoable:e.undoable})}var zMe=e=>`touches`in e,BMe=class{constructor(e){this.directions=[`bottom-left`,`bottom-right`,`top-left`,`top-right`],this.minSize={height:8,width:8},this.preserveAspectRatio=!1,this.classNames={container:``,wrapper:``,handle:``,resizing:``},this.initialWidth=0,this.initialHeight=0,this.aspectRatio=1,this.isResizing=!1,this.activeHandle=null,this.startX=0,this.startY=0,this.startWidth=0,this.startHeight=0,this.isShiftKeyPressed=!1,this.lastEditableState=void 0,this.handleMap=new Map,this.handleMouseMove=e=>{if(!this.isResizing||!this.activeHandle)return;let t=e.clientX-this.startX,n=e.clientY-this.startY;this.handleResize(t,n)},this.handleTouchMove=e=>{if(!this.isResizing||!this.activeHandle)return;let t=e.touches[0];if(!t)return;let n=t.clientX-this.startX,r=t.clientY-this.startY;this.handleResize(n,r)},this.handleMouseUp=()=>{if(!this.isResizing)return;let e=this.element.offsetWidth,t=this.element.offsetHeight;this.onCommit(e,t),this.isResizing=!1,this.activeHandle=null,this.container.dataset.resizeState=`false`,this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener(`mousemove`,this.handleMouseMove),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`keydown`,this.handleKeyDown),document.removeEventListener(`keyup`,this.handleKeyUp)},this.handleKeyDown=e=>{e.key===`Shift`&&(this.isShiftKeyPressed=!0)},this.handleKeyUp=e=>{e.key===`Shift`&&(this.isShiftKeyPressed=!1)},this.node=e.node,this.editor=e.editor,this.element=e.element,this.contentElement=e.contentElement,this.getPos=e.getPos,this.onResize=e.onResize,this.onCommit=e.onCommit,this.onUpdate=e.onUpdate,e.options?.min&&(this.minSize={...this.minSize,...e.options.min}),e.options?.max&&(this.maxSize=e.options.max),e?.options?.directions&&(this.directions=e.options.directions),e.options?.preserveAspectRatio&&(this.preserveAspectRatio=e.options.preserveAspectRatio),e.options?.className&&(this.classNames={container:e.options.className.container||``,wrapper:e.options.className.wrapper||``,handle:e.options.className.handle||``,resizing:e.options.className.resizing||``}),e.options?.createCustomHandle&&(this.createCustomHandle=e.options.createCustomHandle),this.wrapper=this.createWrapper(),this.container=this.createContainer(),this.applyInitialSize(),this.attachHandles(),this.editor.on(`update`,this.handleEditorUpdate.bind(this))}get dom(){return this.container}get contentDOM(){return this.contentElement??null}handleEditorUpdate(){let e=this.editor.isEditable;e!==this.lastEditableState&&(this.lastEditableState=e,e?e&&this.handleMap.size===0&&this.attachHandles():this.removeHandles())}update(e,t,n){return e.type===this.node.type?(this.node=e,this.onUpdate?this.onUpdate(e,t,n):!0):!1}destroy(){this.isResizing&&(this.container.dataset.resizeState=`false`,this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener(`mousemove`,this.handleMouseMove),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`keydown`,this.handleKeyDown),document.removeEventListener(`keyup`,this.handleKeyUp),this.isResizing=!1,this.activeHandle=null),this.editor.off(`update`,this.handleEditorUpdate.bind(this)),this.container.remove()}createContainer(){let e=document.createElement(`div`);return e.dataset.resizeContainer=``,e.dataset.node=this.node.type.name,e.style.display=`flex`,this.classNames.container&&(e.className=this.classNames.container),e.appendChild(this.wrapper),e}createWrapper(){let e=document.createElement(`div`);return e.style.position=`relative`,e.style.display=`block`,e.dataset.resizeWrapper=``,this.classNames.wrapper&&(e.className=this.classNames.wrapper),e.appendChild(this.element),e}createHandle(e){let t=document.createElement(`div`);return t.dataset.resizeHandle=e,t.style.position=`absolute`,this.classNames.handle&&(t.className=this.classNames.handle),t}positionHandle(e,t){let n=t.includes(`top`),r=t.includes(`bottom`),i=t.includes(`left`),a=t.includes(`right`);n&&(e.style.top=`0`),r&&(e.style.bottom=`0`),i&&(e.style.left=`0`),a&&(e.style.right=`0`),(t===`top`||t===`bottom`)&&(e.style.left=`0`,e.style.right=`0`),(t===`left`||t===`right`)&&(e.style.top=`0`,e.style.bottom=`0`)}attachHandles(){this.directions.forEach(e=>{let t;t=this.createCustomHandle?this.createCustomHandle(e):this.createHandle(e),t instanceof HTMLElement||(console.warn(`[ResizableNodeView] createCustomHandle("${e}") did not return an HTMLElement. Falling back to default handle.`),t=this.createHandle(e)),this.createCustomHandle||this.positionHandle(t,e),t.addEventListener(`mousedown`,t=>this.handleResizeStart(t,e)),t.addEventListener(`touchstart`,t=>this.handleResizeStart(t,e)),this.handleMap.set(e,t),this.wrapper.appendChild(t)})}removeHandles(){this.handleMap.forEach(e=>e.remove()),this.handleMap.clear()}applyInitialSize(){let e=this.node.attrs.width,t=this.node.attrs.height;e?(this.element.style.width=`${e}px`,this.initialWidth=e):this.initialWidth=this.element.offsetWidth,t?(this.element.style.height=`${t}px`,this.initialHeight=t):this.initialHeight=this.element.offsetHeight,this.initialWidth>0&&this.initialHeight>0&&(this.aspectRatio=this.initialWidth/this.initialHeight)}handleResizeStart(e,t){e.preventDefault(),e.stopPropagation(),this.isResizing=!0,this.activeHandle=t,zMe(e)?(this.startX=e.touches[0].clientX,this.startY=e.touches[0].clientY):(this.startX=e.clientX,this.startY=e.clientY),this.startWidth=this.element.offsetWidth,this.startHeight=this.element.offsetHeight,this.startWidth>0&&this.startHeight>0&&(this.aspectRatio=this.startWidth/this.startHeight),this.getPos(),this.container.dataset.resizeState=`true`,this.classNames.resizing&&this.container.classList.add(this.classNames.resizing),document.addEventListener(`mousemove`,this.handleMouseMove),document.addEventListener(`touchmove`,this.handleTouchMove),document.addEventListener(`mouseup`,this.handleMouseUp),document.addEventListener(`keydown`,this.handleKeyDown),document.addEventListener(`keyup`,this.handleKeyUp)}handleResize(e,t){if(!this.activeHandle)return;let n=this.preserveAspectRatio||this.isShiftKeyPressed,{width:r,height:i}=this.calculateNewDimensions(this.activeHandle,e,t),a=this.applyConstraints(r,i,n);this.element.style.width=`${a.width}px`,this.element.style.height=`${a.height}px`,this.onResize&&this.onResize(a.width,a.height)}calculateNewDimensions(e,t,n){let r=this.startWidth,i=this.startHeight,a=e.includes(`right`),o=e.includes(`left`),s=e.includes(`bottom`),c=e.includes(`top`);return a?r=this.startWidth+t:o&&(r=this.startWidth-t),s?i=this.startHeight+n:c&&(i=this.startHeight-n),(e===`right`||e===`left`)&&(r=this.startWidth+(a?t:-t)),(e===`top`||e===`bottom`)&&(i=this.startHeight+(s?n:-n)),this.preserveAspectRatio||this.isShiftKeyPressed?this.applyAspectRatio(r,i,e):{width:r,height:i}}applyConstraints(e,t,n){if(!n){let n=Math.max(this.minSize.width,e),r=Math.max(this.minSize.height,t);return this.maxSize?.width&&(n=Math.min(this.maxSize.width,n)),this.maxSize?.height&&(r=Math.min(this.maxSize.height,r)),{width:n,height:r}}let r=e,i=t;return rthis.maxSize.width&&(r=this.maxSize.width,i=r/this.aspectRatio),this.maxSize?.height&&i>this.maxSize.height&&(i=this.maxSize.height,r=i*this.aspectRatio),{width:r,height:i}}applyAspectRatio(e,t,n){return n===`left`||n===`right`?{width:e,height:e/this.aspectRatio}:n===`top`||n===`bottom`?{width:t*this.aspectRatio,height:t}:{width:e,height:e/this.aspectRatio}}};function VMe(e,t){let{selection:n}=e,{$from:r}=n;if(n instanceof RX){let e=r.index();return r.parent.canReplaceWith(e,e+1,t)}let i=r.depth;for(;i>=0;){let e=r.index(i);if(r.node(i).contentMatchAt(e).matchType(t))return!0;--i}return!1}h1({},{createAtomBlockMarkdownSpec:()=>HMe,createBlockMarkdownSpec:()=>UMe,createInlineMarkdownSpec:()=>KMe,parseAttributes:()=>H0,parseIndentedBlocks:()=>W0,renderNestedMarkdownContent:()=>G0,serializeAttributes:()=>U0});function H0(e){if(!e?.trim())return{};let t={},n=[],r=e.replace(/["']([^"']*)["']/g,e=>(n.push(e),`__QUOTED_${n.length-1}__`)),i=r.match(/(?:^|\s)\.([a-zA-Z][\w-]*)/g);i&&(t.class=i.map(e=>e.trim().slice(1)).join(` `));let a=r.match(/(?:^|\s)#([a-zA-Z][\w-]*)/);a&&(t.id=a[1]),Array.from(r.matchAll(/([a-zA-Z][\w-]*)\s*=\s*(__QUOTED_\d+__)/g)).forEach(([,e,r])=>{let i=n[parseInt(r.match(/__QUOTED_(\d+)__/)?.[1]||`0`,10)];i&&(t[e]=i.slice(1,-1))});let o=r.replace(/(?:^|\s)\.([a-zA-Z][\w-]*)/g,``).replace(/(?:^|\s)#([a-zA-Z][\w-]*)/g,``).replace(/([a-zA-Z][\w-]*)\s*=\s*__QUOTED_\d+__/g,``).trim();return o&&o.split(/\s+/).filter(Boolean).forEach(e=>{e.match(/^[a-zA-Z][\w-]*$/)&&(t[e]=!0)}),t}function U0(e){if(!e||Object.keys(e).length===0)return``;let t=[];return e.class&&String(e.class).split(/\s+/).filter(Boolean).forEach(e=>t.push(`.${e}`)),e.id&&t.push(`#${e.id}`),Object.entries(e).forEach(([e,n])=>{e===`class`||e===`id`||(n===!0?t.push(e):n!==!1&&n!=null&&t.push(`${e}="${String(n)}"`))}),t.join(` `)}function HMe(e){let{nodeName:t,name:n,parseAttributes:r=H0,serializeAttributes:i=U0,defaultAttributes:a={},requiredAttributes:o=[],allowedAttributes:s}=e,c=n||t,l=e=>{if(!s)return e;let t={};return s.forEach(n=>{n in e&&(t[n]=e[n])}),t};return{parseMarkdown:(e,n)=>{let r={...a,...e.attributes};return n.createNode(t,r,[])},markdownTokenizer:{name:t,level:`block`,start(e){let t=RegExp(`^:::${c}(?:\\s|$)`,`m`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,i){let a=RegExp(`^:::${c}(?:\\s+\\{([^}]*)\\})?\\s*:::(?:\\n|$)`),s=e.match(a);if(!s)return;let l=r(s[1]||``);if(!o.find(e=>!(e in l)))return{type:t,raw:s[0],attributes:l}}},renderMarkdown:e=>{let t=i(l(e.attrs||{}));return`:::${c}${t?` {${t}}`:``} :::`}}}function UMe(e){let{nodeName:t,name:n,getContent:r,parseAttributes:i=H0,serializeAttributes:a=U0,defaultAttributes:o={},content:s=`block`,allowedAttributes:c}=e,l=n||t,u=e=>{if(!c)return e;let t={};return c.forEach(n=>{n in e&&(t[n]=e[n])}),t};return{parseMarkdown:(e,n)=>{let i;if(r){let t=r(e);i=typeof t==`string`?[{type:`text`,text:t}]:t}else i=s===`block`?n.parseChildren(e.tokens||[]):n.parseInline(e.tokens||[]);let a={...o,...e.attributes};return n.createNode(t,a,i)},markdownTokenizer:{name:t,level:`block`,start(e){let t=RegExp(`^:::${l}`,`m`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,r){let a=RegExp(`^:::${l}(?:\\s+\\{([^}]*)\\})?\\s*\\n`),o=e.match(a);if(!o)return;let[c,u=``]=o,d=i(u),f=1,p=c.length,m=``,h=/^:::([\w-]*)(\s.*)?/gm,g=e.slice(p);for(h.lastIndex=0;;){let n=h.exec(g);if(n===null)break;let i=n.index,a=n[1];if(!n[2]?.endsWith(`:::`)){if(a)f+=1;else if(--f,f===0){let a=g.slice(0,i);m=a.trim();let o=e.slice(0,p+i+n[0].length),c=[];if(m)if(s===`block`)for(c=r.blockTokens(a),c.forEach(e=>{e.text&&(!e.tokens||e.tokens.length===0)&&(e.tokens=r.inlineTokens(e.text))});c.length>0;){let e=c[c.length-1];if(e.type===`paragraph`&&(!e.text||e.text.trim()===``))c.pop();else break}else c=r.inlineTokens(m);return{type:t,raw:o,attributes:d,content:m,tokens:c}}}}}},renderMarkdown:(e,t)=>{let n=a(u(e.attrs||{}));return`:::${l}${n?` {${n}}`:``} +`,textSerializers:n={}}=e||{};return Jje(this.state.doc,{blockSeparator:t,textSerializers:{...r0(this.schema),...n}})}get isEmpty(){return f0(this.state.doc)}destroy(){this.emit(`destroy`),this.unmount(),this.removeAllListeners()}get isDestroyed(){return this.editorView?.isDestroyed??!0}$node(e,t){return this.$doc?.querySelector(e,t)||null}$nodes(e,t){return this.$doc?.querySelectorAll(e,t)||null}$pos(e){return new IMe(this.state.doc.resolve(e),this)}get $doc(){return this.$pos(0)}};function R0(e){return new v0({find:e.find,handler:({state:t,range:n,match:r})=>{let i=K1(e.getAttributes,void 0,r);if(i===!1||i===null)return null;let{tr:a}=t,o=r[r.length-1],s=r[0];if(o){let r=s.search(/\S/),c=n.from+s.indexOf(o),l=c+o.length;if(o0(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>c).length)return null;ln.from&&a.delete(n.from+r,c);let u=n.from+r+o.length;a.addMark(n.from+r,u,e.type.create(i||{})),a.removeStoredMark(e.type)}},undoable:e.undoable})}function z0(e){return new v0({find:e.find,handler:({state:t,range:n,match:r})=>{let i=K1(e.getAttributes,void 0,r)||{},{tr:a}=t,o=n.from,s=n.to,c=e.type.create(i);if(r[1]){let e=o+r[0].lastIndexOf(r[1]);e>s?e=s:s=e+r[1].length;let t=r[0][r[0].length-1];a.insertText(t,o+r[0].length-1),a.replaceWith(e,s,c)}else if(r[0]){let t=e.type.isInline?o:o-1;a.insert(t,e.type.create(i)).delete(a.mapping.map(o),a.mapping.map(s))}a.scrollIntoView()},undoable:e.undoable})}function B0(e){return new v0({find:e.find,handler:({state:t,range:n,match:r})=>{let i=t.doc.resolve(n.from),a=K1(e.getAttributes,void 0,r)||{};if(!i.node(-1).canReplaceWith(i.index(-1),i.indexAfter(-1),e.type))return null;t.tr.delete(n.from,n.to).setBlockType(n.from,n.from,e.type,a)},undoable:e.undoable})}function V0(e){return new v0({find:e.find,handler:({state:t,range:n,match:r,chain:i})=>{let a=K1(e.getAttributes,void 0,r)||{},o=t.tr.delete(n.from,n.to),s=o.doc.resolve(n.from).blockRange(),c=s&&uX(s,e.type,a);if(!c)return null;if(o.wrap(s,c),e.keepMarks&&e.editor){let{selection:n,storedMarks:r}=t,{splittableMarks:i}=e.editor.extensionManager,a=r||n.$to.parentOffset&&n.$from.marks();if(a){let e=a.filter(e=>i.includes(e.type.name));o.ensureMarks(e)}}if(e.keepAttributes){let t=e.type.name===`bulletList`||e.type.name===`orderedList`?`listItem`:`taskList`;i().updateAttributes(t,a).run()}let l=o.doc.resolve(n.from-1).nodeBefore;l&&l.type===e.type&&hX(o.doc,n.from-1)&&(!e.joinPredicate||e.joinPredicate(r,l))&&o.join(n.from-1)},undoable:e.undoable})}var BMe=e=>`touches`in e,VMe=class{constructor(e){this.directions=[`bottom-left`,`bottom-right`,`top-left`,`top-right`],this.minSize={height:8,width:8},this.preserveAspectRatio=!1,this.classNames={container:``,wrapper:``,handle:``,resizing:``},this.initialWidth=0,this.initialHeight=0,this.aspectRatio=1,this.isResizing=!1,this.activeHandle=null,this.startX=0,this.startY=0,this.startWidth=0,this.startHeight=0,this.isShiftKeyPressed=!1,this.lastEditableState=void 0,this.handleMap=new Map,this.handleMouseMove=e=>{if(!this.isResizing||!this.activeHandle)return;let t=e.clientX-this.startX,n=e.clientY-this.startY;this.handleResize(t,n)},this.handleTouchMove=e=>{if(!this.isResizing||!this.activeHandle)return;let t=e.touches[0];if(!t)return;let n=t.clientX-this.startX,r=t.clientY-this.startY;this.handleResize(n,r)},this.handleMouseUp=()=>{if(!this.isResizing)return;let e=this.element.offsetWidth,t=this.element.offsetHeight;this.onCommit(e,t),this.isResizing=!1,this.activeHandle=null,this.container.dataset.resizeState=`false`,this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener(`mousemove`,this.handleMouseMove),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`keydown`,this.handleKeyDown),document.removeEventListener(`keyup`,this.handleKeyUp)},this.handleKeyDown=e=>{e.key===`Shift`&&(this.isShiftKeyPressed=!0)},this.handleKeyUp=e=>{e.key===`Shift`&&(this.isShiftKeyPressed=!1)},this.node=e.node,this.editor=e.editor,this.element=e.element,this.contentElement=e.contentElement,this.getPos=e.getPos,this.onResize=e.onResize,this.onCommit=e.onCommit,this.onUpdate=e.onUpdate,e.options?.min&&(this.minSize={...this.minSize,...e.options.min}),e.options?.max&&(this.maxSize=e.options.max),e?.options?.directions&&(this.directions=e.options.directions),e.options?.preserveAspectRatio&&(this.preserveAspectRatio=e.options.preserveAspectRatio),e.options?.className&&(this.classNames={container:e.options.className.container||``,wrapper:e.options.className.wrapper||``,handle:e.options.className.handle||``,resizing:e.options.className.resizing||``}),e.options?.createCustomHandle&&(this.createCustomHandle=e.options.createCustomHandle),this.wrapper=this.createWrapper(),this.container=this.createContainer(),this.applyInitialSize(),this.attachHandles(),this.editor.on(`update`,this.handleEditorUpdate.bind(this))}get dom(){return this.container}get contentDOM(){return this.contentElement??null}handleEditorUpdate(){let e=this.editor.isEditable;e!==this.lastEditableState&&(this.lastEditableState=e,e?e&&this.handleMap.size===0&&this.attachHandles():this.removeHandles())}update(e,t,n){return e.type===this.node.type?(this.node=e,this.onUpdate?this.onUpdate(e,t,n):!0):!1}destroy(){this.isResizing&&(this.container.dataset.resizeState=`false`,this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener(`mousemove`,this.handleMouseMove),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`keydown`,this.handleKeyDown),document.removeEventListener(`keyup`,this.handleKeyUp),this.isResizing=!1,this.activeHandle=null),this.editor.off(`update`,this.handleEditorUpdate.bind(this)),this.container.remove()}createContainer(){let e=document.createElement(`div`);return e.dataset.resizeContainer=``,e.dataset.node=this.node.type.name,e.style.display=`flex`,this.classNames.container&&(e.className=this.classNames.container),e.appendChild(this.wrapper),e}createWrapper(){let e=document.createElement(`div`);return e.style.position=`relative`,e.style.display=`block`,e.dataset.resizeWrapper=``,this.classNames.wrapper&&(e.className=this.classNames.wrapper),e.appendChild(this.element),e}createHandle(e){let t=document.createElement(`div`);return t.dataset.resizeHandle=e,t.style.position=`absolute`,this.classNames.handle&&(t.className=this.classNames.handle),t}positionHandle(e,t){let n=t.includes(`top`),r=t.includes(`bottom`),i=t.includes(`left`),a=t.includes(`right`);n&&(e.style.top=`0`),r&&(e.style.bottom=`0`),i&&(e.style.left=`0`),a&&(e.style.right=`0`),(t===`top`||t===`bottom`)&&(e.style.left=`0`,e.style.right=`0`),(t===`left`||t===`right`)&&(e.style.top=`0`,e.style.bottom=`0`)}attachHandles(){this.directions.forEach(e=>{let t;t=this.createCustomHandle?this.createCustomHandle(e):this.createHandle(e),t instanceof HTMLElement||(console.warn(`[ResizableNodeView] createCustomHandle("${e}") did not return an HTMLElement. Falling back to default handle.`),t=this.createHandle(e)),this.createCustomHandle||this.positionHandle(t,e),t.addEventListener(`mousedown`,t=>this.handleResizeStart(t,e)),t.addEventListener(`touchstart`,t=>this.handleResizeStart(t,e)),this.handleMap.set(e,t),this.wrapper.appendChild(t)})}removeHandles(){this.handleMap.forEach(e=>e.remove()),this.handleMap.clear()}applyInitialSize(){let e=this.node.attrs.width,t=this.node.attrs.height;e?(this.element.style.width=`${e}px`,this.initialWidth=e):this.initialWidth=this.element.offsetWidth,t?(this.element.style.height=`${t}px`,this.initialHeight=t):this.initialHeight=this.element.offsetHeight,this.initialWidth>0&&this.initialHeight>0&&(this.aspectRatio=this.initialWidth/this.initialHeight)}handleResizeStart(e,t){e.preventDefault(),e.stopPropagation(),this.isResizing=!0,this.activeHandle=t,BMe(e)?(this.startX=e.touches[0].clientX,this.startY=e.touches[0].clientY):(this.startX=e.clientX,this.startY=e.clientY),this.startWidth=this.element.offsetWidth,this.startHeight=this.element.offsetHeight,this.startWidth>0&&this.startHeight>0&&(this.aspectRatio=this.startWidth/this.startHeight),this.getPos(),this.container.dataset.resizeState=`true`,this.classNames.resizing&&this.container.classList.add(this.classNames.resizing),document.addEventListener(`mousemove`,this.handleMouseMove),document.addEventListener(`touchmove`,this.handleTouchMove),document.addEventListener(`mouseup`,this.handleMouseUp),document.addEventListener(`keydown`,this.handleKeyDown),document.addEventListener(`keyup`,this.handleKeyUp)}handleResize(e,t){if(!this.activeHandle)return;let n=this.preserveAspectRatio||this.isShiftKeyPressed,{width:r,height:i}=this.calculateNewDimensions(this.activeHandle,e,t),a=this.applyConstraints(r,i,n);this.element.style.width=`${a.width}px`,this.element.style.height=`${a.height}px`,this.onResize&&this.onResize(a.width,a.height)}calculateNewDimensions(e,t,n){let r=this.startWidth,i=this.startHeight,a=e.includes(`right`),o=e.includes(`left`),s=e.includes(`bottom`),c=e.includes(`top`);return a?r=this.startWidth+t:o&&(r=this.startWidth-t),s?i=this.startHeight+n:c&&(i=this.startHeight-n),(e===`right`||e===`left`)&&(r=this.startWidth+(a?t:-t)),(e===`top`||e===`bottom`)&&(i=this.startHeight+(s?n:-n)),this.preserveAspectRatio||this.isShiftKeyPressed?this.applyAspectRatio(r,i,e):{width:r,height:i}}applyConstraints(e,t,n){if(!n){let n=Math.max(this.minSize.width,e),r=Math.max(this.minSize.height,t);return this.maxSize?.width&&(n=Math.min(this.maxSize.width,n)),this.maxSize?.height&&(r=Math.min(this.maxSize.height,r)),{width:n,height:r}}let r=e,i=t;return rthis.maxSize.width&&(r=this.maxSize.width,i=r/this.aspectRatio),this.maxSize?.height&&i>this.maxSize.height&&(i=this.maxSize.height,r=i*this.aspectRatio),{width:r,height:i}}applyAspectRatio(e,t,n){return n===`left`||n===`right`?{width:e,height:e/this.aspectRatio}:n===`top`||n===`bottom`?{width:t*this.aspectRatio,height:t}:{width:e,height:e/this.aspectRatio}}};function HMe(e,t){let{selection:n}=e,{$from:r}=n;if(n instanceof RX){let e=r.index();return r.parent.canReplaceWith(e,e+1,t)}let i=r.depth;for(;i>=0;){let e=r.index(i);if(r.node(i).contentMatchAt(e).matchType(t))return!0;--i}return!1}h1({},{createAtomBlockMarkdownSpec:()=>UMe,createBlockMarkdownSpec:()=>WMe,createInlineMarkdownSpec:()=>qMe,parseAttributes:()=>H0,parseIndentedBlocks:()=>W0,renderNestedMarkdownContent:()=>G0,serializeAttributes:()=>U0});function H0(e){if(!e?.trim())return{};let t={},n=[],r=e.replace(/["']([^"']*)["']/g,e=>(n.push(e),`__QUOTED_${n.length-1}__`)),i=r.match(/(?:^|\s)\.([a-zA-Z][\w-]*)/g);i&&(t.class=i.map(e=>e.trim().slice(1)).join(` `));let a=r.match(/(?:^|\s)#([a-zA-Z][\w-]*)/);a&&(t.id=a[1]),Array.from(r.matchAll(/([a-zA-Z][\w-]*)\s*=\s*(__QUOTED_\d+__)/g)).forEach(([,e,r])=>{let i=n[parseInt(r.match(/__QUOTED_(\d+)__/)?.[1]||`0`,10)];i&&(t[e]=i.slice(1,-1))});let o=r.replace(/(?:^|\s)\.([a-zA-Z][\w-]*)/g,``).replace(/(?:^|\s)#([a-zA-Z][\w-]*)/g,``).replace(/([a-zA-Z][\w-]*)\s*=\s*__QUOTED_\d+__/g,``).trim();return o&&o.split(/\s+/).filter(Boolean).forEach(e=>{e.match(/^[a-zA-Z][\w-]*$/)&&(t[e]=!0)}),t}function U0(e){if(!e||Object.keys(e).length===0)return``;let t=[];return e.class&&String(e.class).split(/\s+/).filter(Boolean).forEach(e=>t.push(`.${e}`)),e.id&&t.push(`#${e.id}`),Object.entries(e).forEach(([e,n])=>{e===`class`||e===`id`||(n===!0?t.push(e):n!==!1&&n!=null&&t.push(`${e}="${String(n)}"`))}),t.join(` `)}function UMe(e){let{nodeName:t,name:n,parseAttributes:r=H0,serializeAttributes:i=U0,defaultAttributes:a={},requiredAttributes:o=[],allowedAttributes:s}=e,c=n||t,l=e=>{if(!s)return e;let t={};return s.forEach(n=>{n in e&&(t[n]=e[n])}),t};return{parseMarkdown:(e,n)=>{let r={...a,...e.attributes};return n.createNode(t,r,[])},markdownTokenizer:{name:t,level:`block`,start(e){let t=RegExp(`^:::${c}(?:\\s|$)`,`m`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,i){let a=RegExp(`^:::${c}(?:\\s+\\{([^}]*)\\})?\\s*:::(?:\\n|$)`),s=e.match(a);if(!s)return;let l=r(s[1]||``);if(!o.find(e=>!(e in l)))return{type:t,raw:s[0],attributes:l}}},renderMarkdown:e=>{let t=i(l(e.attrs||{}));return`:::${c}${t?` {${t}}`:``} :::`}}}function WMe(e){let{nodeName:t,name:n,getContent:r,parseAttributes:i=H0,serializeAttributes:a=U0,defaultAttributes:o={},content:s=`block`,allowedAttributes:c}=e,l=n||t,u=e=>{if(!c)return e;let t={};return c.forEach(n=>{n in e&&(t[n]=e[n])}),t};return{parseMarkdown:(e,n)=>{let i;if(r){let t=r(e);i=typeof t==`string`?[{type:`text`,text:t}]:t}else i=s===`block`?n.parseChildren(e.tokens||[]):n.parseInline(e.tokens||[]);let a={...o,...e.attributes};return n.createNode(t,a,i)},markdownTokenizer:{name:t,level:`block`,start(e){let t=RegExp(`^:::${l}`,`m`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,r){let a=RegExp(`^:::${l}(?:\\s+\\{([^}]*)\\})?\\s*\\n`),o=e.match(a);if(!o)return;let[c,u=``]=o,d=i(u),f=1,p=c.length,m=``,h=/^:::([\w-]*)(\s.*)?/gm,g=e.slice(p);for(h.lastIndex=0;;){let n=h.exec(g);if(n===null)break;let i=n.index,a=n[1];if(!n[2]?.endsWith(`:::`)){if(a)f+=1;else if(--f,f===0){let a=g.slice(0,i);m=a.trim();let o=e.slice(0,p+i+n[0].length),c=[];if(m)if(s===`block`)for(c=r.blockTokens(a),c.forEach(e=>{e.text&&(!e.tokens||e.tokens.length===0)&&(e.tokens=r.inlineTokens(e.text))});c.length>0;){let e=c[c.length-1];if(e.type===`paragraph`&&(!e.text||e.text.trim()===``))c.pop();else break}else c=r.inlineTokens(m);return{type:t,raw:o,attributes:d,content:m,tokens:c}}}}}},renderMarkdown:(e,t)=>{let n=a(u(e.attrs||{}));return`:::${l}${n?` {${n}}`:``} ${t.renderChildren(e.content||[],` `)} -:::`}}}function WMe(e){if(!e.trim())return{};let t={},n=/(\w+)=(?:"([^"]*)"|'([^']*)')/g,r=n.exec(e);for(;r!==null;){let[,i,a,o]=r;t[i]=a||o,r=n.exec(e)}return t}function GMe(e){return Object.entries(e).filter(([,e])=>e!=null).map(([e,t])=>`${e}="${t}"`).join(` `)}function KMe(e){let{nodeName:t,name:n,getContent:r,parseAttributes:i=WMe,serializeAttributes:a=GMe,defaultAttributes:o={},selfClosing:s=!1,allowedAttributes:c}=e,l=n||t,u=e=>{if(!c)return e;let t={};return c.forEach(n=>{let r=typeof n==`string`?n:n.name,i=typeof n==`string`?void 0:n.skipIfDefault;if(r in e){let n=e[r];if(i!==void 0&&n===i)return;t[r]=n}}),t},d=l.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return{parseMarkdown:(e,n)=>{let i={...o,...e.attributes};if(s)return n.createNode(t,i);let a=r?r(e):e.content||``;return a?n.createNode(t,i,[n.createTextNode(a)]):n.createNode(t,i,[])},markdownTokenizer:{name:t,level:`inline`,start(e){let t=RegExp(s?`\\[${d}\\s*[^\\]]*\\]`:`\\[${d}\\s*[^\\]]*\\][\\s\\S]*?\\[\\/${d}\\]`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,r){let a=RegExp(s?`^\\[${d}\\s*([^\\]]*)\\]`:`^\\[${d}\\s*([^\\]]*)\\]([\\s\\S]*?)\\[\\/${d}\\]`),o=e.match(a);if(!o)return;let c=``,l=``;if(s){let[,e]=o;l=e}else{let[,e,t]=o;l=e,c=t||``}let u=i(l.trim());return{type:t,raw:o[0],content:c.trim(),attributes:u}}},renderMarkdown:e=>{let t=``;r?t=r(e):e.content&&e.content.length>0&&(t=e.content.filter(e=>e.type===`text`).map(e=>e.text).join(``));let n=a(u(e.attrs||{})),i=n?` ${n}`:``;return s?`[${l}${i}]`:`[${l}${i}]${t}[/${l}]`}}}function W0(e,t,n){let r=e.split(` +:::`}}}function GMe(e){if(!e.trim())return{};let t={},n=/(\w+)=(?:"([^"]*)"|'([^']*)')/g,r=n.exec(e);for(;r!==null;){let[,i,a,o]=r;t[i]=a||o,r=n.exec(e)}return t}function KMe(e){return Object.entries(e).filter(([,e])=>e!=null).map(([e,t])=>`${e}="${t}"`).join(` `)}function qMe(e){let{nodeName:t,name:n,getContent:r,parseAttributes:i=GMe,serializeAttributes:a=KMe,defaultAttributes:o={},selfClosing:s=!1,allowedAttributes:c}=e,l=n||t,u=e=>{if(!c)return e;let t={};return c.forEach(n=>{let r=typeof n==`string`?n:n.name,i=typeof n==`string`?void 0:n.skipIfDefault;if(r in e){let n=e[r];if(i!==void 0&&n===i)return;t[r]=n}}),t},d=l.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return{parseMarkdown:(e,n)=>{let i={...o,...e.attributes};if(s)return n.createNode(t,i);let a=r?r(e):e.content||``;return a?n.createNode(t,i,[n.createTextNode(a)]):n.createNode(t,i,[])},markdownTokenizer:{name:t,level:`inline`,start(e){let t=RegExp(s?`\\[${d}\\s*[^\\]]*\\]`:`\\[${d}\\s*[^\\]]*\\][\\s\\S]*?\\[\\/${d}\\]`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,r){let a=RegExp(s?`^\\[${d}\\s*([^\\]]*)\\]`:`^\\[${d}\\s*([^\\]]*)\\]([\\s\\S]*?)\\[\\/${d}\\]`),o=e.match(a);if(!o)return;let c=``,l=``;if(s){let[,e]=o;l=e}else{let[,e,t]=o;l=e,c=t||``}let u=i(l.trim());return{type:t,raw:o[0],content:c.trim(),attributes:u}}},renderMarkdown:e=>{let t=``;r?t=r(e):e.content&&e.content.length>0&&(t=e.content.filter(e=>e.type===`text`).map(e=>e.text).join(``));let n=a(u(e.attrs||{})),i=n?` ${n}`:``;return s?`[${l}${i}]`:`[${l}${i}]${t}[/${l}]`}}}function W0(e,t,n){let r=e.split(` `),i=[],a=``,o=0,s=t.baseIndentSize||2;for(;o0)break;if(e.trim()===``){o+=1,a=`${a}${e} `;continue}else return}let l=t.extractItemData(c),{indentLevel:u,mainContent:d}=l;a=`${a}${e} `;let f=[d];for(o+=1;oe.trim()!==``);if(t===-1)break;if((r[o+1+t].match(/^(\s*)/)?.[1]?.length||0)>u){f.push(e),a=`${a}${e} @@ -8638,11 +8638,11 @@ ${t.renderChildren(e.content||[],` `);e.trim()&&(p=t.customNestedParser?t.customNestedParser(e):n.blockTokens(e))}let h=t.createToken(l,p);i.push(h)}if(i.length!==0)return{items:i,raw:a}}function G0(e,t,n,r){if(!e||!Array.isArray(e.content))return``;let i=typeof n==`function`?n(r):n,[a,...o]=e.content,s=[`${i}${t.renderChildren([a])}`];return o&&o.length>0&&o.forEach(e=>{let n=t.renderChildren([e]);if(n){let e=n.split(` `).map(e=>e?t.indent(e):``).join(` `);s.push(e)}}),s.join(` -`)}function qMe(e,t,n={}){let{state:r}=t,{doc:i,tr:a}=r,o=e;i.descendants((t,r)=>{let i=a.mapping.map(r),s=a.mapping.map(r)+t.nodeSize,c=null;if(t.marks.forEach(e=>{if(e!==o)return!1;c=e}),!c)return;let l=!1;if(Object.keys(n).forEach(e=>{n[e]!==c.attrs[e]&&(l=!0)}),l){let t=e.type.create({...e.attrs,...n});a.removeMark(i,s,e.type),a.addMark(i,s,t)}}),a.docChanged&&t.view.dispatch(a)}var K0=class e extends S0{constructor(){super(...arguments),this.type=`node`}static create(t={}){return new e(typeof t==`function`?t():t)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}};function q0(e){return new AMe({find:e.find,handler:({state:t,range:n,match:r,pasteEvent:i})=>{let a=K1(e.getAttributes,void 0,r,i);if(a===!1||a===null)return null;let{tr:o}=t,s=r[r.length-1],c=r[0],l=n.to;if(s){let r=c.search(/\S/),i=n.from+c.indexOf(s),u=i+s.length;if(o0(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>i).length)return null;un.from&&o.delete(n.from+r,i),l=n.from+r+s.length,o.addMark(n.from+r,l,e.type.create(a||{})),o.removeStoredMark(e.type)}}})}var{getOwnPropertyNames:JMe,getOwnPropertySymbols:YMe}=Object,{hasOwnProperty:XMe}=Object.prototype;function J0(e,t){return function(n,r,i){return e(n,r,i)&&t(n,r,i)}}function Y0(e){return function(t,n,r){if(!t||!n||typeof t!=`object`||typeof n!=`object`)return e(t,n,r);let{cache:i}=r,a=i.get(t),o=i.get(n);if(a&&o)return a===n&&o===t;i.set(t,n),i.set(n,t);let s=e(t,n,r);return i.delete(t),i.delete(n),s}}function ZMe(e){return e?.[Symbol.toStringTag]}function X0(e){return JMe(e).concat(YMe(e))}var QMe=Object.hasOwn||((e,t)=>XMe.call(e,t));function Z0(e,t){return e===t||!e&&!t&&e!==e&&t!==t}var $Me=`__v`,eNe=`__o`,tNe=`_owner`,{getOwnPropertyDescriptor:Q0,keys:$0}=Object;function nNe(e,t){return e.byteLength===t.byteLength&&r2(new Uint8Array(e),new Uint8Array(t))}function rNe(e,t,n){let r=e.length;if(t.length!==r)return!1;for(;r-- >0;)if(!n.equals(e[r],t[r],r,r,e,t,n))return!1;return!0}function iNe(e,t){return e.byteLength===t.byteLength&&r2(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),new Uint8Array(t.buffer,t.byteOffset,t.byteLength))}function aNe(e,t){return Z0(e.getTime(),t.getTime())}function oNe(e,t){return e.name===t.name&&e.message===t.message&&e.cause===t.cause&&e.stack===t.stack}function sNe(e,t){return e===t}function e2(e,t,n){let r=e.size;if(r!==t.size)return!1;if(!r)return!0;let i=Array(r),a=e.entries(),o,s,c=0;for(;(o=a.next())&&!o.done;){let r=t.entries(),a=!1,l=0;for(;(s=r.next())&&!s.done;){if(i[l]){l++;continue}let r=o.value,u=s.value;if(n.equals(r[0],u[0],c,l,e,t,n)&&n.equals(r[1],u[1],r[0],u[0],e,t,n)){a=i[l]=!0;break}l++}if(!a)return!1;c++}return!0}var cNe=Z0;function lNe(e,t,n){let r=$0(e),i=r.length;if($0(t).length!==i)return!1;for(;i-- >0;)if(!i2(e,t,n,r[i]))return!1;return!0}function t2(e,t,n){let r=X0(e),i=r.length;if(X0(t).length!==i)return!1;let a,o,s;for(;i-- >0;)if(a=r[i],!i2(e,t,n,a)||(o=Q0(e,a),s=Q0(t,a),(o||s)&&(!o||!s||o.configurable!==s.configurable||o.enumerable!==s.enumerable||o.writable!==s.writable)))return!1;return!0}function uNe(e,t){return Z0(e.valueOf(),t.valueOf())}function dNe(e,t){return e.source===t.source&&e.flags===t.flags}function n2(e,t,n){let r=e.size;if(r!==t.size)return!1;if(!r)return!0;let i=Array(r),a=e.values(),o,s;for(;(o=a.next())&&!o.done;){let r=t.values(),a=!1,c=0;for(;(s=r.next())&&!s.done;){if(!i[c]&&n.equals(o.value,s.value,o.value,s.value,e,t,n)){a=i[c]=!0;break}c++}if(!a)return!1}return!0}function r2(e,t){let n=e.byteLength;if(t.byteLength!==n||e.byteOffset!==t.byteOffset)return!1;for(;n-- >0;)if(e[n]!==t[n])return!1;return!0}function fNe(e,t){return e.hostname===t.hostname&&e.pathname===t.pathname&&e.protocol===t.protocol&&e.port===t.port&&e.hash===t.hash&&e.username===t.username&&e.password===t.password}function i2(e,t,n,r){return(r===tNe||r===eNe||r===$Me)&&(e.$$typeof||t.$$typeof)?!0:QMe(t,r)&&n.equals(e[r],t[r],r,r,e,t,n)}var pNe=`[object ArrayBuffer]`,mNe=`[object Arguments]`,hNe=`[object Boolean]`,gNe=`[object DataView]`,_Ne=`[object Date]`,vNe=`[object Error]`,yNe=`[object Map]`,bNe=`[object Number]`,xNe=`[object Object]`,SNe=`[object RegExp]`,CNe=`[object Set]`,wNe=`[object String]`,TNe={"[object Int8Array]":!0,"[object Uint8Array]":!0,"[object Uint8ClampedArray]":!0,"[object Int16Array]":!0,"[object Uint16Array]":!0,"[object Int32Array]":!0,"[object Uint32Array]":!0,"[object Float16Array]":!0,"[object Float32Array]":!0,"[object Float64Array]":!0,"[object BigInt64Array]":!0,"[object BigUint64Array]":!0},ENe=`[object URL]`,DNe=Object.prototype.toString;function ONe({areArrayBuffersEqual:e,areArraysEqual:t,areDataViewsEqual:n,areDatesEqual:r,areErrorsEqual:i,areFunctionsEqual:a,areMapsEqual:o,areNumbersEqual:s,areObjectsEqual:c,arePrimitiveWrappersEqual:l,areRegExpsEqual:u,areSetsEqual:d,areTypedArraysEqual:f,areUrlsEqual:p,unknownTagComparators:m}){return function(h,g,_){if(h===g)return!0;if(h==null||g==null)return!1;let v=typeof h;if(v!==typeof g)return!1;if(v!==`object`)return v===`number`?s(h,g,_):v===`function`?a(h,g,_):!1;let y=h.constructor;if(y!==g.constructor)return!1;if(y===Object)return c(h,g,_);if(Array.isArray(h))return t(h,g,_);if(y===Date)return r(h,g,_);if(y===RegExp)return u(h,g,_);if(y===Map)return o(h,g,_);if(y===Set)return d(h,g,_);let b=DNe.call(h);if(b===_Ne)return r(h,g,_);if(b===SNe)return u(h,g,_);if(b===yNe)return o(h,g,_);if(b===CNe)return d(h,g,_);if(b===xNe)return typeof h.then!=`function`&&typeof g.then!=`function`&&c(h,g,_);if(b===ENe)return p(h,g,_);if(b===vNe)return i(h,g,_);if(b===mNe)return c(h,g,_);if(TNe[b])return f(h,g,_);if(b===pNe)return e(h,g,_);if(b===gNe)return n(h,g,_);if(b===hNe||b===bNe||b===wNe)return l(h,g,_);if(m){let e=m[b];if(!e){let t=ZMe(h);t&&(e=m[t])}if(e)return e(h,g,_)}return!1}}function kNe({circular:e,createCustomConfig:t,strict:n}){let r={areArrayBuffersEqual:nNe,areArraysEqual:n?t2:rNe,areDataViewsEqual:iNe,areDatesEqual:aNe,areErrorsEqual:oNe,areFunctionsEqual:sNe,areMapsEqual:n?J0(e2,t2):e2,areNumbersEqual:cNe,areObjectsEqual:n?t2:lNe,arePrimitiveWrappersEqual:uNe,areRegExpsEqual:dNe,areSetsEqual:n?J0(n2,t2):n2,areTypedArraysEqual:n?J0(r2,t2):r2,areUrlsEqual:fNe,unknownTagComparators:void 0};if(t&&(r=Object.assign({},r,t(r))),e){let e=Y0(r.areArraysEqual),t=Y0(r.areMapsEqual),n=Y0(r.areObjectsEqual),i=Y0(r.areSetsEqual);r=Object.assign({},r,{areArraysEqual:e,areMapsEqual:t,areObjectsEqual:n,areSetsEqual:i})}return r}function ANe(e){return function(t,n,r,i,a,o,s){return e(t,n,s)}}function jNe({circular:e,comparator:t,createState:n,equals:r,strict:i}){if(n)return function(a,o){let{cache:s=e?new WeakMap:void 0,meta:c}=n();return t(a,o,{cache:s,equals:r,meta:c,strict:i})};if(e)return function(e,n){return t(e,n,{cache:new WeakMap,equals:r,meta:void 0,strict:i})};let a={cache:void 0,equals:r,meta:void 0,strict:i};return function(e,n){return t(e,n,a)}}var MNe=a2();a2({strict:!0}),a2({circular:!0}),a2({circular:!0,strict:!0}),a2({createInternalComparator:()=>Z0}),a2({strict:!0,createInternalComparator:()=>Z0}),a2({circular:!0,createInternalComparator:()=>Z0}),a2({circular:!0,createInternalComparator:()=>Z0,strict:!0});function a2(e={}){let{circular:t=!1,createInternalComparator:n,createState:r,strict:i=!1}=e,a=ONe(kNe(e));return jNe({circular:t,comparator:a,createState:r,equals:n?n(a):ANe(a),strict:i})}var NNe=(...e)=>t=>{e.forEach(e=>{typeof e==`function`?e(t):e&&(e.current=t)})},PNe=({contentComponent:e})=>{let t=(0,Xe.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getServerSnapshot);return(0,K.jsx)(K.Fragment,{children:Object.values(t)})};function FNe(){let e=new Set,t={};return{subscribe(t){return e.add(t),()=>{e.delete(t)}},getSnapshot(){return t},getServerSnapshot(){return t},setRenderer(n,r){t={...t,[n]:Zf.createPortal(r.reactElement,r.element,n)},e.forEach(e=>e())},removeRenderer(n){let r={...t};delete r[n],t=r,e.forEach(e=>e())}}}var INe=class extends y.Component{constructor(e){super(e),this.editorContentRef=y.createRef(),this.initialized=!1,this.state={hasContentComponentInitialized:!!e.editor?.contentComponent}}componentDidMount(){this.init()}componentDidUpdate(){this.init()}init(){let e=this.props.editor;if(e&&!e.isDestroyed&&e.view.dom?.parentNode){if(e.contentComponent)return;let t=this.editorContentRef.current;t.append(...e.view.dom.parentNode.childNodes),e.setOptions({element:t}),e.contentComponent=FNe(),this.state.hasContentComponentInitialized||(this.unsubscribeToContentComponent=e.contentComponent.subscribe(()=>{this.setState(e=>e.hasContentComponentInitialized?e:{hasContentComponentInitialized:!0}),this.unsubscribeToContentComponent&&this.unsubscribeToContentComponent()})),e.createNodeViews(),this.initialized=!0}}componentWillUnmount(){let e=this.props.editor;if(e){this.initialized=!1,e.isDestroyed||e.view.setProps({nodeViews:{}}),this.unsubscribeToContentComponent&&this.unsubscribeToContentComponent(),e.contentComponent=null;try{if(!e.view.dom?.parentNode)return;let t=document.createElement(`div`);t.append(...e.view.dom.parentNode.childNodes),e.setOptions({element:t})}catch{}}}render(){let{editor:e,innerRef:t,...n}=this.props;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{ref:NNe(t,this.editorContentRef),...n}),e?.contentComponent&&(0,K.jsx)(PNe,{contentComponent:e.contentComponent})]})}},LNe=(0,y.forwardRef)((e,t)=>{let n=y.useMemo(()=>Math.floor(Math.random()*4294967295).toString(),[e.editor]);return y.createElement(INe,{key:n,innerRef:t,...e})}),o2=y.memo(LNe),RNe=typeof window<`u`?y.useLayoutEffect:y.useEffect,zNe=class{constructor(e){this.transactionNumber=0,this.lastTransactionNumber=0,this.subscribers=new Set,this.editor=e,this.lastSnapshot={editor:e,transactionNumber:0},this.getSnapshot=this.getSnapshot.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.watch=this.watch.bind(this),this.subscribe=this.subscribe.bind(this)}getSnapshot(){return this.transactionNumber===this.lastTransactionNumber?this.lastSnapshot:(this.lastTransactionNumber=this.transactionNumber,this.lastSnapshot={editor:this.editor,transactionNumber:this.transactionNumber},this.lastSnapshot)}getServerSnapshot(){return{editor:null,transactionNumber:0}}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}watch(e){if(this.editor=e,this.editor){let e=()=>{this.transactionNumber+=1,this.subscribers.forEach(e=>e())},t=this.editor;return t.on(`transaction`,e),()=>{t.off(`transaction`,e)}}}};function BNe(e){let[t]=(0,y.useState)(()=>new zNe(e.editor)),n=(0,PD.useSyncExternalStoreWithSelector)(t.subscribe,t.getSnapshot,t.getServerSnapshot,e.selector,e.equalityFn??MNe);return RNe(()=>t.watch(e.editor),[e.editor,t]),(0,y.useDebugValue)(n),n}var s2=!1,c2=typeof window>`u`,VNe=c2||!!(typeof window<`u`&&window.next),HNe=class e{constructor(e){this.editor=null,this.subscriptions=new Set,this.isComponentMounted=!1,this.previousDeps=null,this.instanceId=``,this.options=e,this.subscriptions=new Set,this.setEditor(this.getInitialEditor()),this.scheduleDestroy(),this.getEditor=this.getEditor.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.subscribe=this.subscribe.bind(this),this.refreshEditorInstance=this.refreshEditorInstance.bind(this),this.scheduleDestroy=this.scheduleDestroy.bind(this),this.onRender=this.onRender.bind(this),this.createEditor=this.createEditor.bind(this)}setEditor(e){this.editor=e,this.instanceId=Math.random().toString(36).slice(2,9),this.subscriptions.forEach(e=>e())}getInitialEditor(){if(this.options.current.immediatelyRender===void 0){if(c2||VNe){if(s2)throw Error("Tiptap Error: SSR has been detected, please set `immediatelyRender` explicitly to `false` to avoid hydration mismatches.");return null}return this.createEditor()}if(this.options.current.immediatelyRender&&c2&&s2)throw Error("Tiptap Error: SSR has been detected, and `immediatelyRender` has been set to `true` this is an unsupported configuration that may result in errors, explicitly set `immediatelyRender` to `false` to avoid hydration mismatches.");return this.options.current.immediatelyRender?this.createEditor():null}createEditor(){return new RMe({...this.options.current,onBeforeCreate:(...e)=>{var t;return(t=this.options.current).onBeforeCreate?.call(t,...e)},onBlur:(...e)=>{var t;return(t=this.options.current).onBlur?.call(t,...e)},onCreate:(...e)=>{var t;return(t=this.options.current).onCreate?.call(t,...e)},onDestroy:(...e)=>{var t;return(t=this.options.current).onDestroy?.call(t,...e)},onFocus:(...e)=>{var t;return(t=this.options.current).onFocus?.call(t,...e)},onSelectionUpdate:(...e)=>{var t;return(t=this.options.current).onSelectionUpdate?.call(t,...e)},onTransaction:(...e)=>{var t;return(t=this.options.current).onTransaction?.call(t,...e)},onUpdate:(...e)=>{var t;return(t=this.options.current).onUpdate?.call(t,...e)},onContentError:(...e)=>{var t;return(t=this.options.current).onContentError?.call(t,...e)},onDrop:(...e)=>{var t;return(t=this.options.current).onDrop?.call(t,...e)},onPaste:(...e)=>{var t;return(t=this.options.current).onPaste?.call(t,...e)},onDelete:(...e)=>{var t;return(t=this.options.current).onDelete?.call(t,...e)}})}getEditor(){return this.editor}getServerSnapshot(){return null}subscribe(e){return this.subscriptions.add(e),()=>{this.subscriptions.delete(e)}}static compareOptions(e,t){return Object.keys(e).every(n=>[`onCreate`,`onBeforeCreate`,`onDestroy`,`onUpdate`,`onTransaction`,`onFocus`,`onBlur`,`onSelectionUpdate`,`onContentError`,`onDrop`,`onPaste`].includes(n)?!0:n===`extensions`&&e.extensions&&t.extensions?e.extensions.length===t.extensions.length?e.extensions.every((e,n)=>e===t.extensions?.[n]):!1:e[n]===t[n])}onRender(t){return()=>(this.isComponentMounted=!0,clearTimeout(this.scheduledDestructionTimeout),this.editor&&!this.editor.isDestroyed&&t.length===0?e.compareOptions(this.options.current,this.editor.options)||this.editor.setOptions({...this.options.current,editable:this.editor.isEditable}):this.refreshEditorInstance(t),()=>{this.isComponentMounted=!1,this.scheduleDestroy()})}refreshEditorInstance(e){if(this.editor&&!this.editor.isDestroyed){if(this.previousDeps===null){this.previousDeps=e;return}if(this.previousDeps.length===e.length&&this.previousDeps.every((t,n)=>t===e[n]))return}this.editor&&!this.editor.isDestroyed&&this.editor.destroy(),this.setEditor(this.createEditor()),this.previousDeps=e}scheduleDestroy(){let e=this.instanceId,t=this.editor;this.scheduledDestructionTimeout=setTimeout(()=>{if(this.isComponentMounted&&this.instanceId===e){t&&t.setOptions(this.options.current);return}t&&!t.isDestroyed&&(t.destroy(),this.instanceId===e&&this.setEditor(null))},1)}};function UNe(e={},t=[]){let n=(0,y.useRef)(e);n.current=e;let[r]=(0,y.useState)(()=>new HNe(n)),i=(0,Xe.useSyncExternalStore)(r.subscribe,r.getEditor,r.getServerSnapshot);return(0,y.useDebugValue)(i),(0,y.useEffect)(r.onRender(t)),BNe({editor:i,selector:({transactionNumber:t})=>e.shouldRerenderOnTransaction===!1||e.shouldRerenderOnTransaction===void 0?null:e.immediatelyRender&&t===0?0:t+1}),i}var l2=(0,y.createContext)({editor:null});l2.Consumer;var WNe=(0,y.createContext)({onDragStart:()=>{},nodeViewContentChildren:void 0,nodeViewContentRef:()=>{}}),GNe=()=>(0,y.useContext)(WNe);y.forwardRef((e,t)=>{let{onDragStart:n}=GNe();return(0,K.jsx)(e.as||`div`,{...e,ref:t,"data-node-view-wrapper":``,onDragStart:n,style:{whiteSpace:`normal`,...e.style}})}),y.createContext({markViewContentRef:()=>{}});var u2=(0,y.createContext)({get editor(){throw Error(`useTiptap must be used within a provider`)}});u2.displayName=`TiptapContext`;var KNe=()=>(0,y.useContext)(u2);function d2({editor:e,instance:t,children:n}){let r=e??t;if(!r)throw Error("Tiptap: An editor instance is required. Pass a non-null `editor` prop.");let i=(0,y.useMemo)(()=>({editor:r}),[r]),a=(0,y.useMemo)(()=>({editor:r}),[r]);return(0,K.jsx)(l2.Provider,{value:a,children:(0,K.jsx)(u2.Provider,{value:i,children:n})})}d2.displayName=`Tiptap`;function f2({...e}){let{editor:t}=KNe();return(0,K.jsx)(o2,{editor:t,...e})}f2.displayName=`Tiptap.Content`,Object.assign(d2,{Content:f2});var p2=(e,t)=>{if(e===`slot`)return 0;if(e instanceof Function)return e(t);let{children:n,...r}=t??{};if(e===`svg`)throw Error(`SVG elements are not supported in the JSX syntax, use the array syntax instead`);return[e,r,n]},qNe=/^\s*>\s$/,JNe=K0.create({name:`blockquote`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,group:`block`,defining:!0,parseHTML(){return[{tag:`blockquote`}]},renderHTML({HTMLAttributes:e}){return p2(`blockquote`,{...Y1(this.options.HTMLAttributes,e),children:p2(`slot`,{})})},parseMarkdown:(e,t)=>t.createNode(`blockquote`,void 0,t.parseChildren(e.tokens||[])),renderMarkdown:(e,t)=>{if(!e.content)return``;let n=[];return e.content.forEach(e=>{let r=t.renderChildren([e]).split(` +`)}function JMe(e,t,n={}){let{state:r}=t,{doc:i,tr:a}=r,o=e;i.descendants((t,r)=>{let i=a.mapping.map(r),s=a.mapping.map(r)+t.nodeSize,c=null;if(t.marks.forEach(e=>{if(e!==o)return!1;c=e}),!c)return;let l=!1;if(Object.keys(n).forEach(e=>{n[e]!==c.attrs[e]&&(l=!0)}),l){let t=e.type.create({...e.attrs,...n});a.removeMark(i,s,e.type),a.addMark(i,s,t)}}),a.docChanged&&t.view.dispatch(a)}var K0=class e extends S0{constructor(){super(...arguments),this.type=`node`}static create(t={}){return new e(typeof t==`function`?t():t)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}};function q0(e){return new jMe({find:e.find,handler:({state:t,range:n,match:r,pasteEvent:i})=>{let a=K1(e.getAttributes,void 0,r,i);if(a===!1||a===null)return null;let{tr:o}=t,s=r[r.length-1],c=r[0],l=n.to;if(s){let r=c.search(/\S/),i=n.from+c.indexOf(s),u=i+s.length;if(o0(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>i).length)return null;un.from&&o.delete(n.from+r,i),l=n.from+r+s.length,o.addMark(n.from+r,l,e.type.create(a||{})),o.removeStoredMark(e.type)}}})}var{getOwnPropertyNames:YMe,getOwnPropertySymbols:XMe}=Object,{hasOwnProperty:ZMe}=Object.prototype;function J0(e,t){return function(n,r,i){return e(n,r,i)&&t(n,r,i)}}function Y0(e){return function(t,n,r){if(!t||!n||typeof t!=`object`||typeof n!=`object`)return e(t,n,r);let{cache:i}=r,a=i.get(t),o=i.get(n);if(a&&o)return a===n&&o===t;i.set(t,n),i.set(n,t);let s=e(t,n,r);return i.delete(t),i.delete(n),s}}function QMe(e){return e?.[Symbol.toStringTag]}function X0(e){return YMe(e).concat(XMe(e))}var $Me=Object.hasOwn||((e,t)=>ZMe.call(e,t));function Z0(e,t){return e===t||!e&&!t&&e!==e&&t!==t}var eNe=`__v`,tNe=`__o`,nNe=`_owner`,{getOwnPropertyDescriptor:Q0,keys:$0}=Object;function rNe(e,t){return e.byteLength===t.byteLength&&r2(new Uint8Array(e),new Uint8Array(t))}function iNe(e,t,n){let r=e.length;if(t.length!==r)return!1;for(;r-- >0;)if(!n.equals(e[r],t[r],r,r,e,t,n))return!1;return!0}function aNe(e,t){return e.byteLength===t.byteLength&&r2(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),new Uint8Array(t.buffer,t.byteOffset,t.byteLength))}function oNe(e,t){return Z0(e.getTime(),t.getTime())}function sNe(e,t){return e.name===t.name&&e.message===t.message&&e.cause===t.cause&&e.stack===t.stack}function cNe(e,t){return e===t}function e2(e,t,n){let r=e.size;if(r!==t.size)return!1;if(!r)return!0;let i=Array(r),a=e.entries(),o,s,c=0;for(;(o=a.next())&&!o.done;){let r=t.entries(),a=!1,l=0;for(;(s=r.next())&&!s.done;){if(i[l]){l++;continue}let r=o.value,u=s.value;if(n.equals(r[0],u[0],c,l,e,t,n)&&n.equals(r[1],u[1],r[0],u[0],e,t,n)){a=i[l]=!0;break}l++}if(!a)return!1;c++}return!0}var lNe=Z0;function uNe(e,t,n){let r=$0(e),i=r.length;if($0(t).length!==i)return!1;for(;i-- >0;)if(!i2(e,t,n,r[i]))return!1;return!0}function t2(e,t,n){let r=X0(e),i=r.length;if(X0(t).length!==i)return!1;let a,o,s;for(;i-- >0;)if(a=r[i],!i2(e,t,n,a)||(o=Q0(e,a),s=Q0(t,a),(o||s)&&(!o||!s||o.configurable!==s.configurable||o.enumerable!==s.enumerable||o.writable!==s.writable)))return!1;return!0}function dNe(e,t){return Z0(e.valueOf(),t.valueOf())}function fNe(e,t){return e.source===t.source&&e.flags===t.flags}function n2(e,t,n){let r=e.size;if(r!==t.size)return!1;if(!r)return!0;let i=Array(r),a=e.values(),o,s;for(;(o=a.next())&&!o.done;){let r=t.values(),a=!1,c=0;for(;(s=r.next())&&!s.done;){if(!i[c]&&n.equals(o.value,s.value,o.value,s.value,e,t,n)){a=i[c]=!0;break}c++}if(!a)return!1}return!0}function r2(e,t){let n=e.byteLength;if(t.byteLength!==n||e.byteOffset!==t.byteOffset)return!1;for(;n-- >0;)if(e[n]!==t[n])return!1;return!0}function pNe(e,t){return e.hostname===t.hostname&&e.pathname===t.pathname&&e.protocol===t.protocol&&e.port===t.port&&e.hash===t.hash&&e.username===t.username&&e.password===t.password}function i2(e,t,n,r){return(r===nNe||r===tNe||r===eNe)&&(e.$$typeof||t.$$typeof)?!0:$Me(t,r)&&n.equals(e[r],t[r],r,r,e,t,n)}var mNe=`[object ArrayBuffer]`,hNe=`[object Arguments]`,gNe=`[object Boolean]`,_Ne=`[object DataView]`,vNe=`[object Date]`,yNe=`[object Error]`,bNe=`[object Map]`,xNe=`[object Number]`,SNe=`[object Object]`,CNe=`[object RegExp]`,wNe=`[object Set]`,TNe=`[object String]`,ENe={"[object Int8Array]":!0,"[object Uint8Array]":!0,"[object Uint8ClampedArray]":!0,"[object Int16Array]":!0,"[object Uint16Array]":!0,"[object Int32Array]":!0,"[object Uint32Array]":!0,"[object Float16Array]":!0,"[object Float32Array]":!0,"[object Float64Array]":!0,"[object BigInt64Array]":!0,"[object BigUint64Array]":!0},DNe=`[object URL]`,ONe=Object.prototype.toString;function kNe({areArrayBuffersEqual:e,areArraysEqual:t,areDataViewsEqual:n,areDatesEqual:r,areErrorsEqual:i,areFunctionsEqual:a,areMapsEqual:o,areNumbersEqual:s,areObjectsEqual:c,arePrimitiveWrappersEqual:l,areRegExpsEqual:u,areSetsEqual:d,areTypedArraysEqual:f,areUrlsEqual:p,unknownTagComparators:m}){return function(h,g,_){if(h===g)return!0;if(h==null||g==null)return!1;let v=typeof h;if(v!==typeof g)return!1;if(v!==`object`)return v===`number`?s(h,g,_):v===`function`?a(h,g,_):!1;let y=h.constructor;if(y!==g.constructor)return!1;if(y===Object)return c(h,g,_);if(Array.isArray(h))return t(h,g,_);if(y===Date)return r(h,g,_);if(y===RegExp)return u(h,g,_);if(y===Map)return o(h,g,_);if(y===Set)return d(h,g,_);let b=ONe.call(h);if(b===vNe)return r(h,g,_);if(b===CNe)return u(h,g,_);if(b===bNe)return o(h,g,_);if(b===wNe)return d(h,g,_);if(b===SNe)return typeof h.then!=`function`&&typeof g.then!=`function`&&c(h,g,_);if(b===DNe)return p(h,g,_);if(b===yNe)return i(h,g,_);if(b===hNe)return c(h,g,_);if(ENe[b])return f(h,g,_);if(b===mNe)return e(h,g,_);if(b===_Ne)return n(h,g,_);if(b===gNe||b===xNe||b===TNe)return l(h,g,_);if(m){let e=m[b];if(!e){let t=QMe(h);t&&(e=m[t])}if(e)return e(h,g,_)}return!1}}function ANe({circular:e,createCustomConfig:t,strict:n}){let r={areArrayBuffersEqual:rNe,areArraysEqual:n?t2:iNe,areDataViewsEqual:aNe,areDatesEqual:oNe,areErrorsEqual:sNe,areFunctionsEqual:cNe,areMapsEqual:n?J0(e2,t2):e2,areNumbersEqual:lNe,areObjectsEqual:n?t2:uNe,arePrimitiveWrappersEqual:dNe,areRegExpsEqual:fNe,areSetsEqual:n?J0(n2,t2):n2,areTypedArraysEqual:n?J0(r2,t2):r2,areUrlsEqual:pNe,unknownTagComparators:void 0};if(t&&(r=Object.assign({},r,t(r))),e){let e=Y0(r.areArraysEqual),t=Y0(r.areMapsEqual),n=Y0(r.areObjectsEqual),i=Y0(r.areSetsEqual);r=Object.assign({},r,{areArraysEqual:e,areMapsEqual:t,areObjectsEqual:n,areSetsEqual:i})}return r}function jNe(e){return function(t,n,r,i,a,o,s){return e(t,n,s)}}function MNe({circular:e,comparator:t,createState:n,equals:r,strict:i}){if(n)return function(a,o){let{cache:s=e?new WeakMap:void 0,meta:c}=n();return t(a,o,{cache:s,equals:r,meta:c,strict:i})};if(e)return function(e,n){return t(e,n,{cache:new WeakMap,equals:r,meta:void 0,strict:i})};let a={cache:void 0,equals:r,meta:void 0,strict:i};return function(e,n){return t(e,n,a)}}var NNe=a2();a2({strict:!0}),a2({circular:!0}),a2({circular:!0,strict:!0}),a2({createInternalComparator:()=>Z0}),a2({strict:!0,createInternalComparator:()=>Z0}),a2({circular:!0,createInternalComparator:()=>Z0}),a2({circular:!0,createInternalComparator:()=>Z0,strict:!0});function a2(e={}){let{circular:t=!1,createInternalComparator:n,createState:r,strict:i=!1}=e,a=kNe(ANe(e));return MNe({circular:t,comparator:a,createState:r,equals:n?n(a):jNe(a),strict:i})}var PNe=(...e)=>t=>{e.forEach(e=>{typeof e==`function`?e(t):e&&(e.current=t)})},FNe=({contentComponent:e})=>{let t=(0,Xe.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getServerSnapshot);return(0,K.jsx)(K.Fragment,{children:Object.values(t)})};function INe(){let e=new Set,t={};return{subscribe(t){return e.add(t),()=>{e.delete(t)}},getSnapshot(){return t},getServerSnapshot(){return t},setRenderer(n,r){t={...t,[n]:Zf.createPortal(r.reactElement,r.element,n)},e.forEach(e=>e())},removeRenderer(n){let r={...t};delete r[n],t=r,e.forEach(e=>e())}}}var LNe=class extends y.Component{constructor(e){super(e),this.editorContentRef=y.createRef(),this.initialized=!1,this.state={hasContentComponentInitialized:!!e.editor?.contentComponent}}componentDidMount(){this.init()}componentDidUpdate(){this.init()}init(){let e=this.props.editor;if(e&&!e.isDestroyed&&e.view.dom?.parentNode){if(e.contentComponent)return;let t=this.editorContentRef.current;t.append(...e.view.dom.parentNode.childNodes),e.setOptions({element:t}),e.contentComponent=INe(),this.state.hasContentComponentInitialized||(this.unsubscribeToContentComponent=e.contentComponent.subscribe(()=>{this.setState(e=>e.hasContentComponentInitialized?e:{hasContentComponentInitialized:!0}),this.unsubscribeToContentComponent&&this.unsubscribeToContentComponent()})),e.createNodeViews(),this.initialized=!0}}componentWillUnmount(){let e=this.props.editor;if(e){this.initialized=!1,e.isDestroyed||e.view.setProps({nodeViews:{}}),this.unsubscribeToContentComponent&&this.unsubscribeToContentComponent(),e.contentComponent=null;try{if(!e.view.dom?.parentNode)return;let t=document.createElement(`div`);t.append(...e.view.dom.parentNode.childNodes),e.setOptions({element:t})}catch{}}}render(){let{editor:e,innerRef:t,...n}=this.props;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{ref:PNe(t,this.editorContentRef),...n}),e?.contentComponent&&(0,K.jsx)(FNe,{contentComponent:e.contentComponent})]})}},RNe=(0,y.forwardRef)((e,t)=>{let n=y.useMemo(()=>Math.floor(Math.random()*4294967295).toString(),[e.editor]);return y.createElement(LNe,{key:n,innerRef:t,...e})}),o2=y.memo(RNe),zNe=typeof window<`u`?y.useLayoutEffect:y.useEffect,BNe=class{constructor(e){this.transactionNumber=0,this.lastTransactionNumber=0,this.subscribers=new Set,this.editor=e,this.lastSnapshot={editor:e,transactionNumber:0},this.getSnapshot=this.getSnapshot.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.watch=this.watch.bind(this),this.subscribe=this.subscribe.bind(this)}getSnapshot(){return this.transactionNumber===this.lastTransactionNumber?this.lastSnapshot:(this.lastTransactionNumber=this.transactionNumber,this.lastSnapshot={editor:this.editor,transactionNumber:this.transactionNumber},this.lastSnapshot)}getServerSnapshot(){return{editor:null,transactionNumber:0}}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}watch(e){if(this.editor=e,this.editor){let e=()=>{this.transactionNumber+=1,this.subscribers.forEach(e=>e())},t=this.editor;return t.on(`transaction`,e),()=>{t.off(`transaction`,e)}}}};function VNe(e){let[t]=(0,y.useState)(()=>new BNe(e.editor)),n=(0,PD.useSyncExternalStoreWithSelector)(t.subscribe,t.getSnapshot,t.getServerSnapshot,e.selector,e.equalityFn??NNe);return zNe(()=>t.watch(e.editor),[e.editor,t]),(0,y.useDebugValue)(n),n}var s2=!1,c2=typeof window>`u`,HNe=c2||!!(typeof window<`u`&&window.next),UNe=class e{constructor(e){this.editor=null,this.subscriptions=new Set,this.isComponentMounted=!1,this.previousDeps=null,this.instanceId=``,this.options=e,this.subscriptions=new Set,this.setEditor(this.getInitialEditor()),this.scheduleDestroy(),this.getEditor=this.getEditor.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.subscribe=this.subscribe.bind(this),this.refreshEditorInstance=this.refreshEditorInstance.bind(this),this.scheduleDestroy=this.scheduleDestroy.bind(this),this.onRender=this.onRender.bind(this),this.createEditor=this.createEditor.bind(this)}setEditor(e){this.editor=e,this.instanceId=Math.random().toString(36).slice(2,9),this.subscriptions.forEach(e=>e())}getInitialEditor(){if(this.options.current.immediatelyRender===void 0){if(c2||HNe){if(s2)throw Error("Tiptap Error: SSR has been detected, please set `immediatelyRender` explicitly to `false` to avoid hydration mismatches.");return null}return this.createEditor()}if(this.options.current.immediatelyRender&&c2&&s2)throw Error("Tiptap Error: SSR has been detected, and `immediatelyRender` has been set to `true` this is an unsupported configuration that may result in errors, explicitly set `immediatelyRender` to `false` to avoid hydration mismatches.");return this.options.current.immediatelyRender?this.createEditor():null}createEditor(){return new zMe({...this.options.current,onBeforeCreate:(...e)=>{var t;return(t=this.options.current).onBeforeCreate?.call(t,...e)},onBlur:(...e)=>{var t;return(t=this.options.current).onBlur?.call(t,...e)},onCreate:(...e)=>{var t;return(t=this.options.current).onCreate?.call(t,...e)},onDestroy:(...e)=>{var t;return(t=this.options.current).onDestroy?.call(t,...e)},onFocus:(...e)=>{var t;return(t=this.options.current).onFocus?.call(t,...e)},onSelectionUpdate:(...e)=>{var t;return(t=this.options.current).onSelectionUpdate?.call(t,...e)},onTransaction:(...e)=>{var t;return(t=this.options.current).onTransaction?.call(t,...e)},onUpdate:(...e)=>{var t;return(t=this.options.current).onUpdate?.call(t,...e)},onContentError:(...e)=>{var t;return(t=this.options.current).onContentError?.call(t,...e)},onDrop:(...e)=>{var t;return(t=this.options.current).onDrop?.call(t,...e)},onPaste:(...e)=>{var t;return(t=this.options.current).onPaste?.call(t,...e)},onDelete:(...e)=>{var t;return(t=this.options.current).onDelete?.call(t,...e)}})}getEditor(){return this.editor}getServerSnapshot(){return null}subscribe(e){return this.subscriptions.add(e),()=>{this.subscriptions.delete(e)}}static compareOptions(e,t){return Object.keys(e).every(n=>[`onCreate`,`onBeforeCreate`,`onDestroy`,`onUpdate`,`onTransaction`,`onFocus`,`onBlur`,`onSelectionUpdate`,`onContentError`,`onDrop`,`onPaste`].includes(n)?!0:n===`extensions`&&e.extensions&&t.extensions?e.extensions.length===t.extensions.length?e.extensions.every((e,n)=>e===t.extensions?.[n]):!1:e[n]===t[n])}onRender(t){return()=>(this.isComponentMounted=!0,clearTimeout(this.scheduledDestructionTimeout),this.editor&&!this.editor.isDestroyed&&t.length===0?e.compareOptions(this.options.current,this.editor.options)||this.editor.setOptions({...this.options.current,editable:this.editor.isEditable}):this.refreshEditorInstance(t),()=>{this.isComponentMounted=!1,this.scheduleDestroy()})}refreshEditorInstance(e){if(this.editor&&!this.editor.isDestroyed){if(this.previousDeps===null){this.previousDeps=e;return}if(this.previousDeps.length===e.length&&this.previousDeps.every((t,n)=>t===e[n]))return}this.editor&&!this.editor.isDestroyed&&this.editor.destroy(),this.setEditor(this.createEditor()),this.previousDeps=e}scheduleDestroy(){let e=this.instanceId,t=this.editor;this.scheduledDestructionTimeout=setTimeout(()=>{if(this.isComponentMounted&&this.instanceId===e){t&&t.setOptions(this.options.current);return}t&&!t.isDestroyed&&(t.destroy(),this.instanceId===e&&this.setEditor(null))},1)}};function WNe(e={},t=[]){let n=(0,y.useRef)(e);n.current=e;let[r]=(0,y.useState)(()=>new UNe(n)),i=(0,Xe.useSyncExternalStore)(r.subscribe,r.getEditor,r.getServerSnapshot);return(0,y.useDebugValue)(i),(0,y.useEffect)(r.onRender(t)),VNe({editor:i,selector:({transactionNumber:t})=>e.shouldRerenderOnTransaction===!1||e.shouldRerenderOnTransaction===void 0?null:e.immediatelyRender&&t===0?0:t+1}),i}var l2=(0,y.createContext)({editor:null});l2.Consumer;var GNe=(0,y.createContext)({onDragStart:()=>{},nodeViewContentChildren:void 0,nodeViewContentRef:()=>{}}),KNe=()=>(0,y.useContext)(GNe);y.forwardRef((e,t)=>{let{onDragStart:n}=KNe();return(0,K.jsx)(e.as||`div`,{...e,ref:t,"data-node-view-wrapper":``,onDragStart:n,style:{whiteSpace:`normal`,...e.style}})}),y.createContext({markViewContentRef:()=>{}});var u2=(0,y.createContext)({get editor(){throw Error(`useTiptap must be used within a provider`)}});u2.displayName=`TiptapContext`;var qNe=()=>(0,y.useContext)(u2);function d2({editor:e,instance:t,children:n}){let r=e??t;if(!r)throw Error("Tiptap: An editor instance is required. Pass a non-null `editor` prop.");let i=(0,y.useMemo)(()=>({editor:r}),[r]),a=(0,y.useMemo)(()=>({editor:r}),[r]);return(0,K.jsx)(l2.Provider,{value:a,children:(0,K.jsx)(u2.Provider,{value:i,children:n})})}d2.displayName=`Tiptap`;function f2({...e}){let{editor:t}=qNe();return(0,K.jsx)(o2,{editor:t,...e})}f2.displayName=`Tiptap.Content`,Object.assign(d2,{Content:f2});var p2=(e,t)=>{if(e===`slot`)return 0;if(e instanceof Function)return e(t);let{children:n,...r}=t??{};if(e===`svg`)throw Error(`SVG elements are not supported in the JSX syntax, use the array syntax instead`);return[e,r,n]},JNe=/^\s*>\s$/,YNe=K0.create({name:`blockquote`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,group:`block`,defining:!0,parseHTML(){return[{tag:`blockquote`}]},renderHTML({HTMLAttributes:e}){return p2(`blockquote`,{...Y1(this.options.HTMLAttributes,e),children:p2(`slot`,{})})},parseMarkdown:(e,t)=>t.createNode(`blockquote`,void 0,t.parseChildren(e.tokens||[])),renderMarkdown:(e,t)=>{if(!e.content)return``;let n=[];return e.content.forEach(e=>{let r=t.renderChildren([e]).split(` `).map(e=>e.trim()===``?`>`:`> ${e}`);n.push(r.join(` `))}),n.join(` > -`)},addCommands(){return{setBlockquote:()=>({commands:e})=>e.wrapIn(this.name),toggleBlockquote:()=>({commands:e})=>e.toggleWrap(this.name),unsetBlockquote:()=>({commands:e})=>e.lift(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-b":()=>this.editor.commands.toggleBlockquote()}},addInputRules(){return[V0({find:qNe,type:this.type})]}}),YNe=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,XNe=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,ZNe=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,QNe=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,$Ne=C0.create({name:`bold`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`strong`},{tag:`b`,getAttrs:e=>e.style.fontWeight!==`normal`&&null},{style:`font-weight=400`,clearMark:e=>e.type.name===this.name},{style:`font-weight`,getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}]},renderHTML({HTMLAttributes:e}){return p2(`strong`,{...Y1(this.options.HTMLAttributes,e),children:p2(`slot`,{})})},markdownTokenName:`strong`,parseMarkdown:(e,t)=>t.applyMark(`bold`,t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>`**${t.renderChildren(e)}**`,addCommands(){return{setBold:()=>({commands:e})=>e.setMark(this.name),toggleBold:()=>({commands:e})=>e.toggleMark(this.name),unsetBold:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[R0({find:YNe,type:this.type}),R0({find:ZNe,type:this.type})]},addPasteRules(){return[q0({find:XNe,type:this.type}),q0({find:QNe,type:this.type})]}}),ePe=/(^|[^`])`([^`]+)`(?!`)$/,tPe=/(^|[^`])`([^`]+)`(?!`)/g,nPe=C0.create({name:`code`,addOptions(){return{HTMLAttributes:{}}},excludes:`_`,code:!0,exitable:!0,parseHTML(){return[{tag:`code`}]},renderHTML({HTMLAttributes:e}){return[`code`,Y1(this.options.HTMLAttributes,e),0]},markdownTokenName:`codespan`,parseMarkdown:(e,t)=>t.applyMark(`code`,[{type:`text`,text:e.text||``}]),renderMarkdown:(e,t)=>e.content?`\`${t.renderChildren(e.content)}\``:``,addCommands(){return{setCode:()=>({commands:e})=>e.setMark(this.name),toggleCode:()=>({commands:e})=>e.toggleMark(this.name),unsetCode:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-e":()=>this.editor.commands.toggleCode()}},addInputRules(){return[R0({find:ePe,type:this.type})]},addPasteRules(){return[q0({find:tPe,type:this.type})]}}),m2=4,rPe=/^```([a-z]+)?[\s\n]$/,iPe=/^~~~([a-z]+)?[\s\n]$/,aPe=K0.create({name:`codeBlock`,addOptions(){return{languageClassPrefix:`language-`,exitOnTripleEnter:!0,exitOnArrowDown:!0,defaultLanguage:null,enableTabIndentation:!1,tabSize:m2,HTMLAttributes:{}}},content:`text*`,marks:``,group:`block`,code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:e=>{let{languageClassPrefix:t}=this.options;return t&&[...e.firstElementChild?.classList||[]].filter(e=>e.startsWith(t)).map(e=>e.replace(t,``))[0]||null},rendered:!1}}},parseHTML(){return[{tag:`pre`,preserveWhitespace:`full`}]},renderHTML({node:e,HTMLAttributes:t}){return[`pre`,Y1(this.options.HTMLAttributes,t),[`code`,{class:e.attrs.language?this.options.languageClassPrefix+e.attrs.language:null},0]]},markdownTokenName:`code`,parseMarkdown:(e,t)=>e.raw?.startsWith("```")===!1&&e.codeBlockStyle!==`indented`?[]:t.createNode(`codeBlock`,{language:e.lang||null},e.text?[t.createTextNode(e.text)]:[]),renderMarkdown:(e,t)=>{let n=``,r=e.attrs?.language||``;return n=e.content?[`\`\`\`${r}`,t.renderChildren(e.content),"```"].join(` +`)},addCommands(){return{setBlockquote:()=>({commands:e})=>e.wrapIn(this.name),toggleBlockquote:()=>({commands:e})=>e.toggleWrap(this.name),unsetBlockquote:()=>({commands:e})=>e.lift(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-b":()=>this.editor.commands.toggleBlockquote()}},addInputRules(){return[V0({find:JNe,type:this.type})]}}),XNe=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,ZNe=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,QNe=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,$Ne=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,ePe=C0.create({name:`bold`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`strong`},{tag:`b`,getAttrs:e=>e.style.fontWeight!==`normal`&&null},{style:`font-weight=400`,clearMark:e=>e.type.name===this.name},{style:`font-weight`,getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}]},renderHTML({HTMLAttributes:e}){return p2(`strong`,{...Y1(this.options.HTMLAttributes,e),children:p2(`slot`,{})})},markdownTokenName:`strong`,parseMarkdown:(e,t)=>t.applyMark(`bold`,t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>`**${t.renderChildren(e)}**`,addCommands(){return{setBold:()=>({commands:e})=>e.setMark(this.name),toggleBold:()=>({commands:e})=>e.toggleMark(this.name),unsetBold:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[R0({find:XNe,type:this.type}),R0({find:QNe,type:this.type})]},addPasteRules(){return[q0({find:ZNe,type:this.type}),q0({find:$Ne,type:this.type})]}}),tPe=/(^|[^`])`([^`]+)`(?!`)$/,nPe=/(^|[^`])`([^`]+)`(?!`)/g,rPe=C0.create({name:`code`,addOptions(){return{HTMLAttributes:{}}},excludes:`_`,code:!0,exitable:!0,parseHTML(){return[{tag:`code`}]},renderHTML({HTMLAttributes:e}){return[`code`,Y1(this.options.HTMLAttributes,e),0]},markdownTokenName:`codespan`,parseMarkdown:(e,t)=>t.applyMark(`code`,[{type:`text`,text:e.text||``}]),renderMarkdown:(e,t)=>e.content?`\`${t.renderChildren(e.content)}\``:``,addCommands(){return{setCode:()=>({commands:e})=>e.setMark(this.name),toggleCode:()=>({commands:e})=>e.toggleMark(this.name),unsetCode:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-e":()=>this.editor.commands.toggleCode()}},addInputRules(){return[R0({find:tPe,type:this.type})]},addPasteRules(){return[q0({find:nPe,type:this.type})]}}),m2=4,iPe=/^```([a-z]+)?[\s\n]$/,aPe=/^~~~([a-z]+)?[\s\n]$/,oPe=K0.create({name:`codeBlock`,addOptions(){return{languageClassPrefix:`language-`,exitOnTripleEnter:!0,exitOnArrowDown:!0,defaultLanguage:null,enableTabIndentation:!1,tabSize:m2,HTMLAttributes:{}}},content:`text*`,marks:``,group:`block`,code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:e=>{let{languageClassPrefix:t}=this.options;return t&&[...e.firstElementChild?.classList||[]].filter(e=>e.startsWith(t)).map(e=>e.replace(t,``))[0]||null},rendered:!1}}},parseHTML(){return[{tag:`pre`,preserveWhitespace:`full`}]},renderHTML({node:e,HTMLAttributes:t}){return[`pre`,Y1(this.options.HTMLAttributes,t),[`code`,{class:e.attrs.language?this.options.languageClassPrefix+e.attrs.language:null},0]]},markdownTokenName:`code`,parseMarkdown:(e,t)=>e.raw?.startsWith("```")===!1&&e.codeBlockStyle!==`indented`?[]:t.createNode(`codeBlock`,{language:e.lang||null},e.text?[t.createTextNode(e.text)]:[]),renderMarkdown:(e,t)=>{let n=``,r=e.attrs?.language||``;return n=e.content?[`\`\`\`${r}`,t.renderChildren(e.content),"```"].join(` `):`\`\`\`${r} \`\`\``,n},addCommands(){return{setCodeBlock:e=>({commands:t})=>t.setNode(this.name,e),toggleCodeBlock:e=>({commands:t})=>t.toggleNode(this.name,`paragraph`,e)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{let{empty:e,$anchor:t}=this.editor.state.selection,n=t.pos===1;return!e||t.parent.type.name!==this.name?!1:n||!t.parent.textContent.length?this.editor.commands.clearNodes():!1},Tab:({editor:e})=>{if(!this.options.enableTabIndentation)return!1;let t=this.options.tabSize??m2,{state:n}=e,{selection:r}=n,{$from:i,empty:a}=r;if(i.parent.type!==this.type)return!1;let o=` `.repeat(t);return a?e.commands.insertContent(o):e.commands.command(({tr:e})=>{let{from:t,to:i}=r,a=n.doc.textBetween(t,i,` @@ -8658,39 +8658,39 @@ ${t.renderChildren(e.content||[],` `).map(e=>{let n=e.match(/^ */)?.[0]||``,r=Math.min(n.length,t);return e.slice(r)}).join(` `);return e.replaceWith(i,a,n.schema.text(o)),!0}):!1},Enter:({editor:e})=>{if(!this.options.exitOnTripleEnter)return!1;let{state:t}=e,{selection:n}=t,{$from:r,empty:i}=n;if(!i||r.parent.type!==this.type)return!1;let a=r.parentOffset===r.parent.nodeSize-2,o=r.parent.textContent.endsWith(` -`);return!a||!o?!1:e.chain().command(({tr:e})=>(e.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowDown:({editor:e})=>{if(!this.options.exitOnArrowDown)return!1;let{state:t}=e,{selection:n,doc:r}=t,{$from:i,empty:a}=n;if(!a||i.parent.type!==this.type||i.parentOffset!==i.parent.nodeSize-2)return!1;let o=i.after();return o===void 0?!1:r.nodeAt(o)?e.commands.command(({tr:e})=>(e.setSelection(NX.near(r.resolve(o))),!0)):e.commands.exitCode()}}},addInputRules(){return[B0({find:rPe,type:this.type,getAttributes:e=>({language:e[1]})}),B0({find:iPe,type:this.type,getAttributes:e=>({language:e[1]})})]},addProseMirrorPlugins(){return[new YX({key:new QX(`codeBlockVSCodeHandler`),props:{handlePaste:(e,t)=>{if(!t.clipboardData||this.editor.isActive(this.type.name))return!1;let n=t.clipboardData.getData(`text/plain`),r=t.clipboardData.getData(`vscode-editor-data`),i=(r?JSON.parse(r):void 0)?.mode;if(!n||!i)return!1;let{tr:a,schema:o}=e.state,s=o.text(n.replace(/\r\n?/g,` -`));return a.replaceSelectionWith(this.type.create({language:i},s)),a.selection.$from.parent.type!==this.type&&a.setSelection(IX.near(a.doc.resolve(Math.max(0,a.selection.from-2)))),a.setMeta(`paste`,!0),e.dispatch(a),!0}}})]}}),oPe=K0.create({name:`doc`,topNode:!0,content:`block+`,renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` +`);return!a||!o?!1:e.chain().command(({tr:e})=>(e.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowDown:({editor:e})=>{if(!this.options.exitOnArrowDown)return!1;let{state:t}=e,{selection:n,doc:r}=t,{$from:i,empty:a}=n;if(!a||i.parent.type!==this.type||i.parentOffset!==i.parent.nodeSize-2)return!1;let o=i.after();return o===void 0?!1:r.nodeAt(o)?e.commands.command(({tr:e})=>(e.setSelection(NX.near(r.resolve(o))),!0)):e.commands.exitCode()}}},addInputRules(){return[B0({find:iPe,type:this.type,getAttributes:e=>({language:e[1]})}),B0({find:aPe,type:this.type,getAttributes:e=>({language:e[1]})})]},addProseMirrorPlugins(){return[new YX({key:new QX(`codeBlockVSCodeHandler`),props:{handlePaste:(e,t)=>{if(!t.clipboardData||this.editor.isActive(this.type.name))return!1;let n=t.clipboardData.getData(`text/plain`),r=t.clipboardData.getData(`vscode-editor-data`),i=(r?JSON.parse(r):void 0)?.mode;if(!n||!i)return!1;let{tr:a,schema:o}=e.state,s=o.text(n.replace(/\r\n?/g,` +`));return a.replaceSelectionWith(this.type.create({language:i},s)),a.selection.$from.parent.type!==this.type&&a.setSelection(IX.near(a.doc.resolve(Math.max(0,a.selection.from-2)))),a.setMeta(`paste`,!0),e.dispatch(a),!0}}})]}}),sPe=K0.create({name:`doc`,topNode:!0,content:`block+`,renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` -`):``}),sPe=K0.create({name:`hardBreak`,markdownTokenName:`br`,addOptions(){return{keepMarks:!0,HTMLAttributes:{}}},inline:!0,group:`inline`,selectable:!1,linebreakReplacement:!0,parseHTML(){return[{tag:`br`}]},renderHTML({HTMLAttributes:e}){return[`br`,Y1(this.options.HTMLAttributes,e)]},renderText(){return` +`):``}),cPe=K0.create({name:`hardBreak`,markdownTokenName:`br`,addOptions(){return{keepMarks:!0,HTMLAttributes:{}}},inline:!0,group:`inline`,selectable:!1,linebreakReplacement:!0,parseHTML(){return[{tag:`br`}]},renderHTML({HTMLAttributes:e}){return[`br`,Y1(this.options.HTMLAttributes,e)]},renderText(){return` `},renderMarkdown:()=>` -`,parseMarkdown:()=>({type:`hardBreak`}),addCommands(){return{setHardBreak:()=>({commands:e,chain:t,state:n,editor:r})=>e.first([()=>e.exitCode(),()=>e.command(()=>{let{selection:e,storedMarks:i}=n;if(e.$from.parent.type.spec.isolating)return!1;let{keepMarks:a}=this.options,{splittableMarks:o}=r.extensionManager,s=i||e.$to.parentOffset&&e.$from.marks();return t().insertContent({type:this.name}).command(({tr:e,dispatch:t})=>{if(t&&s&&a){let t=s.filter(e=>o.includes(e.type.name));e.ensureMarks(t)}return!0}).run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),cPe=K0.create({name:`heading`,addOptions(){return{levels:[1,2,3,4,5,6],HTMLAttributes:{}}},content:`inline*`,group:`block`,defining:!0,addAttributes(){return{level:{default:1,rendered:!1}}},parseHTML(){return this.options.levels.map(e=>({tag:`h${e}`,attrs:{level:e}}))},renderHTML({node:e,HTMLAttributes:t}){return[`h${this.options.levels.includes(e.attrs.level)?e.attrs.level:this.options.levels[0]}`,Y1(this.options.HTMLAttributes,t),0]},parseMarkdown:(e,t)=>t.createNode(`heading`,{level:e.depth||1},t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>{let n=e.attrs?.level?parseInt(e.attrs.level,10):1,r=`#`.repeat(n);return e.content?`${r} ${t.renderChildren(e.content)}`:``},addCommands(){return{setHeading:e=>({commands:t})=>this.options.levels.includes(e.level)?t.setNode(this.name,e):!1,toggleHeading:e=>({commands:t})=>this.options.levels.includes(e.level)?t.toggleNode(this.name,`paragraph`,e):!1}},addKeyboardShortcuts(){return this.options.levels.reduce((e,t)=>({...e,[`Mod-Alt-${t}`]:()=>this.editor.commands.toggleHeading({level:t})}),{})},addInputRules(){return this.options.levels.map(e=>B0({find:RegExp(`^(#{${Math.min(...this.options.levels)},${e}})\\s$`),type:this.type,getAttributes:{level:e}}))}}),lPe=K0.create({name:`horizontalRule`,addOptions(){return{HTMLAttributes:{},nextNodeType:`paragraph`}},group:`block`,parseHTML(){return[{tag:`hr`}]},renderHTML({HTMLAttributes:e}){return[`hr`,Y1(this.options.HTMLAttributes,e)]},markdownTokenName:`hr`,parseMarkdown:(e,t)=>t.createNode(`horizontalRule`),renderMarkdown:()=>`---`,addCommands(){return{setHorizontalRule:()=>({chain:e,state:t})=>{if(!VMe(t,t.schema.nodes[this.name]))return!1;let{selection:n}=t,{$to:r}=n,i=e();return p0(n)?i.insertContentAt(r.pos,{type:this.name}):i.insertContent({type:this.name}),i.command(({state:e,tr:t,dispatch:n})=>{if(n){let{$to:n}=t.selection,r=n.end();if(n.nodeAfter)n.nodeAfter.isTextblock?t.setSelection(IX.create(t.doc,n.pos+1)):n.nodeAfter.isBlock?t.setSelection(RX.create(t.doc,n.pos)):t.setSelection(IX.create(t.doc,n.pos));else{let i=(e.schema.nodes[this.options.nextNodeType]||n.parent.type.contentMatch.defaultType)?.create();i&&(t.insert(r,i),t.setSelection(IX.create(t.doc,r+1)))}t.scrollIntoView()}return!0}).run()}}},addInputRules(){return[z0({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),uPe=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,dPe=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,fPe=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,pPe=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,mPe=C0.create({name:`italic`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`em`},{tag:`i`,getAttrs:e=>e.style.fontStyle!==`normal`&&null},{style:`font-style=normal`,clearMark:e=>e.type.name===this.name},{style:`font-style=italic`}]},renderHTML({HTMLAttributes:e}){return[`em`,Y1(this.options.HTMLAttributes,e),0]},addCommands(){return{setItalic:()=>({commands:e})=>e.setMark(this.name),toggleItalic:()=>({commands:e})=>e.toggleMark(this.name),unsetItalic:()=>({commands:e})=>e.unsetMark(this.name)}},markdownTokenName:`em`,parseMarkdown:(e,t)=>t.applyMark(`italic`,t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>`*${t.renderChildren(e)}*`,addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[R0({find:uPe,type:this.type}),R0({find:fPe,type:this.type})]},addPasteRules(){return[q0({find:dPe,type:this.type}),q0({find:pPe,type:this.type})]}}),hPe=`aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2`,gPe=`ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2`,h2=`numeric`,g2=`ascii`,_2=`alpha`,v2=`asciinumeric`,y2=`alphanumeric`,b2=`domain`,x2=`emoji`,_Pe=`scheme`,vPe=`slashscheme`,S2=`whitespace`;function yPe(e,t){return e in t||(t[e]=[]),t[e]}function C2(e,t,n){t[h2]&&(t[v2]=!0,t[y2]=!0),t[g2]&&(t[v2]=!0,t[_2]=!0),t[v2]&&(t[y2]=!0),t[_2]&&(t[y2]=!0),t[y2]&&(t[b2]=!0),t[x2]&&(t[b2]=!0);for(let r in t){let t=yPe(r,n);t.indexOf(e)<0&&t.push(e)}}function bPe(e,t){let n={};for(let r in t)t[r].indexOf(e)>=0&&(n[r]=!0);return n}function w2(e=null){this.j={},this.jr=[],this.jd=null,this.t=e}w2.groups={},w2.prototype={accepts(){return!!this.t},go(e){let t=this,n=t.j[e];if(n)return n;for(let n=0;ne.ta(t,n,r,i),E2=(e,t,n,r,i)=>e.tr(t,n,r,i),D2=(e,t,n,r,i)=>e.ts(t,n,r,i),O2=(e,t,n,r,i)=>e.tt(t,n,r,i),k2=`WORD`,A2=`UWORD`,j2=`ASCIINUMERICAL`,M2=`ALPHANUMERICAL`,N2=`LOCALHOST`,P2=`TLD`,F2=`UTLD`,I2=`SCHEME`,L2=`SLASH_SCHEME`,R2=`NUM`,z2=`WS`,B2=`NL`,V2=`OPENBRACE`,H2=`CLOSEBRACE`,U2=`OPENBRACKET`,W2=`CLOSEBRACKET`,G2=`OPENPAREN`,K2=`CLOSEPAREN`,q2=`OPENANGLEBRACKET`,J2=`CLOSEANGLEBRACKET`,Y2=`FULLWIDTHLEFTPAREN`,X2=`FULLWIDTHRIGHTPAREN`,Z2=`LEFTCORNERBRACKET`,Q2=`RIGHTCORNERBRACKET`,$2=`LEFTWHITECORNERBRACKET`,e4=`RIGHTWHITECORNERBRACKET`,t4=`FULLWIDTHLESSTHAN`,n4=`FULLWIDTHGREATERTHAN`,r4=`AMPERSAND`,i4=`APOSTROPHE`,a4=`ASTERISK`,o4=`AT`,s4=`BACKSLASH`,c4=`BACKTICK`,l4=`CARET`,u4=`COLON`,d4=`COMMA`,f4=`DOLLAR`,p4=`DOT`,m4=`EQUALS`,h4=`EXCLAMATION`,g4=`HYPHEN`,_4=`PERCENT`,v4=`PIPE`,y4=`PLUS`,b4=`POUND`,x4=`QUERY`,S4=`QUOTE`,C4=`FULLWIDTHMIDDLEDOT`,w4=`SEMI`,T4=`SLASH`,E4=`TILDE`,D4=`UNDERSCORE`,O4=`EMOJI`,k4=`SYM`,A4=Object.freeze({__proto__:null,ALPHANUMERICAL:M2,AMPERSAND:r4,APOSTROPHE:i4,ASCIINUMERICAL:j2,ASTERISK:a4,AT:o4,BACKSLASH:s4,BACKTICK:c4,CARET:l4,CLOSEANGLEBRACKET:J2,CLOSEBRACE:H2,CLOSEBRACKET:W2,CLOSEPAREN:K2,COLON:u4,COMMA:d4,DOLLAR:f4,DOT:p4,EMOJI:O4,EQUALS:m4,EXCLAMATION:h4,FULLWIDTHGREATERTHAN:n4,FULLWIDTHLEFTPAREN:Y2,FULLWIDTHLESSTHAN:t4,FULLWIDTHMIDDLEDOT:C4,FULLWIDTHRIGHTPAREN:X2,HYPHEN:g4,LEFTCORNERBRACKET:Z2,LEFTWHITECORNERBRACKET:$2,LOCALHOST:N2,NL:B2,NUM:R2,OPENANGLEBRACKET:q2,OPENBRACE:V2,OPENBRACKET:U2,OPENPAREN:G2,PERCENT:_4,PIPE:v4,PLUS:y4,POUND:b4,QUERY:x4,QUOTE:S4,RIGHTCORNERBRACKET:Q2,RIGHTWHITECORNERBRACKET:e4,SCHEME:I2,SEMI:w4,SLASH:T4,SLASH_SCHEME:L2,SYM:k4,TILDE:E4,TLD:P2,UNDERSCORE:D4,UTLD:F2,UWORD:A2,WORD:k2,WS:z2}),j4=/[a-z]/,M4=/\p{L}/u,N4=/\p{Emoji}/u,P4=/\d/,F4=/\s/,I4=`\r`,L4=` -`,xPe=`️`,SPe=`‍`,R4=``,z4=null,B4=null;function CPe(e=[]){let t={};w2.groups=t;let n=new w2;z4??=U4(hPe),B4??=U4(gPe),O2(n,`'`,i4),O2(n,`{`,V2),O2(n,`}`,H2),O2(n,`[`,U2),O2(n,`]`,W2),O2(n,`(`,G2),O2(n,`)`,K2),O2(n,`<`,q2),O2(n,`>`,J2),O2(n,`(`,Y2),O2(n,`)`,X2),O2(n,`「`,Z2),O2(n,`」`,Q2),O2(n,`『`,$2),O2(n,`』`,e4),O2(n,`<`,t4),O2(n,`>`,n4),O2(n,`&`,r4),O2(n,`*`,a4),O2(n,`@`,o4),O2(n,"`",c4),O2(n,`^`,l4),O2(n,`:`,u4),O2(n,`,`,d4),O2(n,`$`,f4),O2(n,`.`,p4),O2(n,`=`,m4),O2(n,`!`,h4),O2(n,`-`,g4),O2(n,`%`,_4),O2(n,`|`,v4),O2(n,`+`,y4),O2(n,`#`,b4),O2(n,`?`,x4),O2(n,`"`,S4),O2(n,`/`,T4),O2(n,`;`,w4),O2(n,`~`,E4),O2(n,`_`,D4),O2(n,`\\`,s4),O2(n,`・`,C4);let r=E2(n,P4,R2,{[h2]:!0});E2(r,P4,r);let i=E2(r,j4,j2,{[v2]:!0}),a=E2(r,M4,M2,{[y2]:!0}),o=E2(n,j4,k2,{[g2]:!0});E2(o,P4,i),E2(o,j4,o),E2(i,P4,i),E2(i,j4,i);let s=E2(n,M4,A2,{[_2]:!0});E2(s,j4),E2(s,P4,a),E2(s,M4,s),E2(a,P4,a),E2(a,j4),E2(a,M4,a);let c=O2(n,L4,B2,{[S2]:!0}),l=O2(n,I4,z2,{[S2]:!0}),u=E2(n,F4,z2,{[S2]:!0});O2(n,R4,u),O2(l,L4,c),O2(l,R4,u),E2(l,F4,u),O2(u,I4),O2(u,L4),E2(u,F4,u),O2(u,R4,u);let d=E2(n,N4,O4,{[x2]:!0});O2(d,`#`),E2(d,N4,d),O2(d,xPe,d);let f=O2(d,SPe);O2(f,`#`),E2(f,N4,d);let p=[[j4,o],[P4,i]],m=[[j4,null],[M4,s],[P4,a]];for(let e=0;ee[0]>t[0]?1:-1);for(let t=0;t=0?i[b2]=!0:j4.test(r)?P4.test(r)?i[v2]=!0:i[g2]=!0:i[h2]=!0,D2(n,r,r,i)}return D2(n,`localhost`,N2,{ascii:!0}),n.jd=new w2(k4),{start:n,tokens:Object.assign({groups:t},A4)}}function V4(e,t){let n=wPe(t.replace(/[A-Z]/g,e=>e.toLowerCase())),r=n.length,i=[],a=0,o=0;for(;o=0&&(d+=n[o].length,f++),l+=n[o].length,a+=n[o].length,o++;a-=d,o-=f,l-=d,i.push({t:u.t,v:t.slice(a-l,a),s:a-l,e:a})}return i}function wPe(e){let t=[],n=e.length,r=0;for(;r56319||r+1===n||(a=e.charCodeAt(r+1))<56320||a>57343?e[r]:e.slice(r,r+2);t.push(o),r+=o.length}return t}function H4(e,t,n,r,i){let a,o=t.length;for(let n=0;n=0;)i++;if(i>0){t.push(n.join(``));for(let t=parseInt(e.substring(r,r+i),10);t>0;t--)n.pop();r+=i}else n.push(e[r]),r++}return t}var W4={defaultProtocol:`http`,events:null,format:K4,formatHref:K4,nl2br:!1,tagName:`a`,target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],render:null};function G4(e,t=null){let n=Object.assign({},W4);e&&(n=Object.assign(n,e instanceof G4?e.o:e));let r=n.ignoreTags,i=[];for(let e=0;en?r.substring(0,n)+`…`:r},toFormattedHref(e){return e.get(`formatHref`,this.toHref(e.get(`defaultProtocol`)),this)},startIndex(){return this.tk[0].s},endIndex(){return this.tk[this.tk.length-1].e},toObject(e=W4.defaultProtocol){return{type:this.t,value:this.toString(),isLink:this.isLink,href:this.toHref(e),start:this.startIndex(),end:this.endIndex()}},toFormattedObject(e){return{type:this.t,value:this.toFormattedString(e),isLink:this.isLink,href:this.toFormattedHref(e),start:this.startIndex(),end:this.endIndex()}},validate(e){return e.get(`validate`,this.toString(),this)},render(e){let t=this,n=this.toHref(e.get(`defaultProtocol`)),r=e.get(`formatHref`,n,this),i=e.get(`tagName`,n,t),a=this.toFormattedString(e),o={},s=e.get(`className`,n,t),c=e.get(`target`,n,t),l=e.get(`rel`,n,t),u=e.getObj(`attributes`,n,t),d=e.getObj(`events`,n,t);return o.href=r,s&&(o.class=s),c&&(o.target=c),l&&(o.rel=l),u&&Object.assign(o,u),{tagName:i,attributes:o,content:a,eventListeners:d}}};function J4(e,t){class n extends q4{constructor(t,n){super(t,n),this.t=e}}for(let e in t)n.prototype[e]=t[e];return n.t=e,n}var Y4=J4(`email`,{isLink:!0,toHref(){return`mailto:`+this.toString()}}),X4=J4(`text`),TPe=J4(`nl`),Z4=J4(`url`,{isLink:!0,toHref(e=W4.defaultProtocol){return this.hasProtocol()?this.v:`${e}://${this.v}`},hasProtocol(){let e=this.tk;return e.length>=2&&e[0].t!==N2&&e[1].t===u4}}),Q4=e=>new w2(e);function EPe({groups:e}){let t=e.domain.concat([r4,a4,o4,s4,c4,l4,f4,m4,g4,R2,_4,v4,y4,b4,T4,k4,E4,D4]),n=[i4,u4,d4,p4,h4,_4,x4,S4,w4,q2,J2,V2,H2,W2,U2,G2,K2,Y2,X2,Z2,Q2,$2,e4,t4,n4],r=[r4,i4,a4,s4,c4,l4,f4,m4,g4,V2,H2,_4,v4,y4,b4,x4,T4,k4,E4,D4],i=Q4(),a=O2(i,E4);T2(a,r,a),T2(a,e.domain,a);let o=Q4(),s=Q4(),c=Q4();T2(i,e.domain,o),T2(i,e.scheme,s),T2(i,e.slashscheme,c),T2(o,r,a),T2(o,e.domain,o);let l=O2(o,o4);O2(a,o4,l),O2(s,o4,l),O2(c,o4,l);let u=O2(a,p4);T2(u,r,a),T2(u,e.domain,a);let d=Q4();T2(l,e.domain,d),T2(d,e.domain,d);let f=O2(d,p4);T2(f,e.domain,d);let p=Q4(Y4);T2(f,e.tld,p),T2(f,e.utld,p),O2(l,N2,p);let m=O2(d,g4);O2(m,g4,m),T2(m,e.domain,d),T2(p,e.domain,d),O2(p,p4,f),O2(p,g4,m),T2(O2(p,u4),e.numeric,Y4);let h=O2(o,g4),g=O2(o,p4);O2(h,g4,h),T2(h,e.domain,o),T2(g,r,a),T2(g,e.domain,o);let _=Q4(Z4);T2(g,e.tld,_),T2(g,e.utld,_),T2(_,e.domain,o),T2(_,r,a),O2(_,p4,g),O2(_,g4,h),O2(_,o4,l);let v=O2(_,u4),y=Q4(Z4);T2(v,e.numeric,y);let b=Q4(Z4),x=Q4();T2(b,t,b),T2(b,n,x),T2(x,t,b),T2(x,n,x),O2(_,T4,b),O2(y,T4,b);let S=O2(s,u4),C=O2(O2(O2(c,u4),T4),T4);T2(s,e.domain,o),O2(s,p4,g),O2(s,g4,h),T2(c,e.domain,o),O2(c,p4,g),O2(c,g4,h),T2(S,e.domain,b),O2(S,T4,b),O2(S,x4,b),T2(C,e.domain,b),T2(C,t,b),O2(C,T4,b);let w=[[V2,H2],[U2,W2],[G2,K2],[q2,J2],[Y2,X2],[Z2,Q2],[$2,e4],[t4,n4]];for(let e=0;e=0&&f++,i++,u++;if(f<0)i-=u,i0&&(a.push($4(X4,t,o)),o=[]),i-=f,u-=f;let e=d.t,r=n.slice(i-u,i);a.push($4(e,t,r))}}return o.length>0&&a.push($4(X4,t,o)),a}function $4(e,t,n){let r=n[0].s,i=n[n.length-1].e;return new e(t.slice(r,i),n)}var OPe=typeof console<`u`&&console&&console.warn||(()=>{}),kPe=`until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.`,e3={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function APe(){return w2.groups={},e3.scanner=null,e3.parser=null,e3.tokenQueue=[],e3.pluginQueue=[],e3.customSchemes=[],e3.initialized=!1,e3}function t3(e,t=!1){if(e3.initialized&&OPe(`linkifyjs: already initialized - will not register custom scheme "${e}" ${kPe}`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(e))throw Error(`linkifyjs: incorrect scheme format. +`,parseMarkdown:()=>({type:`hardBreak`}),addCommands(){return{setHardBreak:()=>({commands:e,chain:t,state:n,editor:r})=>e.first([()=>e.exitCode(),()=>e.command(()=>{let{selection:e,storedMarks:i}=n;if(e.$from.parent.type.spec.isolating)return!1;let{keepMarks:a}=this.options,{splittableMarks:o}=r.extensionManager,s=i||e.$to.parentOffset&&e.$from.marks();return t().insertContent({type:this.name}).command(({tr:e,dispatch:t})=>{if(t&&s&&a){let t=s.filter(e=>o.includes(e.type.name));e.ensureMarks(t)}return!0}).run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),lPe=K0.create({name:`heading`,addOptions(){return{levels:[1,2,3,4,5,6],HTMLAttributes:{}}},content:`inline*`,group:`block`,defining:!0,addAttributes(){return{level:{default:1,rendered:!1}}},parseHTML(){return this.options.levels.map(e=>({tag:`h${e}`,attrs:{level:e}}))},renderHTML({node:e,HTMLAttributes:t}){return[`h${this.options.levels.includes(e.attrs.level)?e.attrs.level:this.options.levels[0]}`,Y1(this.options.HTMLAttributes,t),0]},parseMarkdown:(e,t)=>t.createNode(`heading`,{level:e.depth||1},t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>{let n=e.attrs?.level?parseInt(e.attrs.level,10):1,r=`#`.repeat(n);return e.content?`${r} ${t.renderChildren(e.content)}`:``},addCommands(){return{setHeading:e=>({commands:t})=>this.options.levels.includes(e.level)?t.setNode(this.name,e):!1,toggleHeading:e=>({commands:t})=>this.options.levels.includes(e.level)?t.toggleNode(this.name,`paragraph`,e):!1}},addKeyboardShortcuts(){return this.options.levels.reduce((e,t)=>({...e,[`Mod-Alt-${t}`]:()=>this.editor.commands.toggleHeading({level:t})}),{})},addInputRules(){return this.options.levels.map(e=>B0({find:RegExp(`^(#{${Math.min(...this.options.levels)},${e}})\\s$`),type:this.type,getAttributes:{level:e}}))}}),uPe=K0.create({name:`horizontalRule`,addOptions(){return{HTMLAttributes:{},nextNodeType:`paragraph`}},group:`block`,parseHTML(){return[{tag:`hr`}]},renderHTML({HTMLAttributes:e}){return[`hr`,Y1(this.options.HTMLAttributes,e)]},markdownTokenName:`hr`,parseMarkdown:(e,t)=>t.createNode(`horizontalRule`),renderMarkdown:()=>`---`,addCommands(){return{setHorizontalRule:()=>({chain:e,state:t})=>{if(!HMe(t,t.schema.nodes[this.name]))return!1;let{selection:n}=t,{$to:r}=n,i=e();return p0(n)?i.insertContentAt(r.pos,{type:this.name}):i.insertContent({type:this.name}),i.command(({state:e,tr:t,dispatch:n})=>{if(n){let{$to:n}=t.selection,r=n.end();if(n.nodeAfter)n.nodeAfter.isTextblock?t.setSelection(IX.create(t.doc,n.pos+1)):n.nodeAfter.isBlock?t.setSelection(RX.create(t.doc,n.pos)):t.setSelection(IX.create(t.doc,n.pos));else{let i=(e.schema.nodes[this.options.nextNodeType]||n.parent.type.contentMatch.defaultType)?.create();i&&(t.insert(r,i),t.setSelection(IX.create(t.doc,r+1)))}t.scrollIntoView()}return!0}).run()}}},addInputRules(){return[z0({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),dPe=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,fPe=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,pPe=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,mPe=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,hPe=C0.create({name:`italic`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`em`},{tag:`i`,getAttrs:e=>e.style.fontStyle!==`normal`&&null},{style:`font-style=normal`,clearMark:e=>e.type.name===this.name},{style:`font-style=italic`}]},renderHTML({HTMLAttributes:e}){return[`em`,Y1(this.options.HTMLAttributes,e),0]},addCommands(){return{setItalic:()=>({commands:e})=>e.setMark(this.name),toggleItalic:()=>({commands:e})=>e.toggleMark(this.name),unsetItalic:()=>({commands:e})=>e.unsetMark(this.name)}},markdownTokenName:`em`,parseMarkdown:(e,t)=>t.applyMark(`italic`,t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>`*${t.renderChildren(e)}*`,addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[R0({find:dPe,type:this.type}),R0({find:pPe,type:this.type})]},addPasteRules(){return[q0({find:fPe,type:this.type}),q0({find:mPe,type:this.type})]}}),gPe=`aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2`,_Pe=`ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2`,h2=`numeric`,g2=`ascii`,_2=`alpha`,v2=`asciinumeric`,y2=`alphanumeric`,b2=`domain`,x2=`emoji`,vPe=`scheme`,yPe=`slashscheme`,S2=`whitespace`;function bPe(e,t){return e in t||(t[e]=[]),t[e]}function C2(e,t,n){t[h2]&&(t[v2]=!0,t[y2]=!0),t[g2]&&(t[v2]=!0,t[_2]=!0),t[v2]&&(t[y2]=!0),t[_2]&&(t[y2]=!0),t[y2]&&(t[b2]=!0),t[x2]&&(t[b2]=!0);for(let r in t){let t=bPe(r,n);t.indexOf(e)<0&&t.push(e)}}function xPe(e,t){let n={};for(let r in t)t[r].indexOf(e)>=0&&(n[r]=!0);return n}function w2(e=null){this.j={},this.jr=[],this.jd=null,this.t=e}w2.groups={},w2.prototype={accepts(){return!!this.t},go(e){let t=this,n=t.j[e];if(n)return n;for(let n=0;ne.ta(t,n,r,i),E2=(e,t,n,r,i)=>e.tr(t,n,r,i),D2=(e,t,n,r,i)=>e.ts(t,n,r,i),O2=(e,t,n,r,i)=>e.tt(t,n,r,i),k2=`WORD`,A2=`UWORD`,j2=`ASCIINUMERICAL`,M2=`ALPHANUMERICAL`,N2=`LOCALHOST`,P2=`TLD`,F2=`UTLD`,I2=`SCHEME`,L2=`SLASH_SCHEME`,R2=`NUM`,z2=`WS`,B2=`NL`,V2=`OPENBRACE`,H2=`CLOSEBRACE`,U2=`OPENBRACKET`,W2=`CLOSEBRACKET`,G2=`OPENPAREN`,K2=`CLOSEPAREN`,q2=`OPENANGLEBRACKET`,J2=`CLOSEANGLEBRACKET`,Y2=`FULLWIDTHLEFTPAREN`,X2=`FULLWIDTHRIGHTPAREN`,Z2=`LEFTCORNERBRACKET`,Q2=`RIGHTCORNERBRACKET`,$2=`LEFTWHITECORNERBRACKET`,e4=`RIGHTWHITECORNERBRACKET`,t4=`FULLWIDTHLESSTHAN`,n4=`FULLWIDTHGREATERTHAN`,r4=`AMPERSAND`,i4=`APOSTROPHE`,a4=`ASTERISK`,o4=`AT`,s4=`BACKSLASH`,c4=`BACKTICK`,l4=`CARET`,u4=`COLON`,d4=`COMMA`,f4=`DOLLAR`,p4=`DOT`,m4=`EQUALS`,h4=`EXCLAMATION`,g4=`HYPHEN`,_4=`PERCENT`,v4=`PIPE`,y4=`PLUS`,b4=`POUND`,x4=`QUERY`,S4=`QUOTE`,C4=`FULLWIDTHMIDDLEDOT`,w4=`SEMI`,T4=`SLASH`,E4=`TILDE`,D4=`UNDERSCORE`,O4=`EMOJI`,k4=`SYM`,A4=Object.freeze({__proto__:null,ALPHANUMERICAL:M2,AMPERSAND:r4,APOSTROPHE:i4,ASCIINUMERICAL:j2,ASTERISK:a4,AT:o4,BACKSLASH:s4,BACKTICK:c4,CARET:l4,CLOSEANGLEBRACKET:J2,CLOSEBRACE:H2,CLOSEBRACKET:W2,CLOSEPAREN:K2,COLON:u4,COMMA:d4,DOLLAR:f4,DOT:p4,EMOJI:O4,EQUALS:m4,EXCLAMATION:h4,FULLWIDTHGREATERTHAN:n4,FULLWIDTHLEFTPAREN:Y2,FULLWIDTHLESSTHAN:t4,FULLWIDTHMIDDLEDOT:C4,FULLWIDTHRIGHTPAREN:X2,HYPHEN:g4,LEFTCORNERBRACKET:Z2,LEFTWHITECORNERBRACKET:$2,LOCALHOST:N2,NL:B2,NUM:R2,OPENANGLEBRACKET:q2,OPENBRACE:V2,OPENBRACKET:U2,OPENPAREN:G2,PERCENT:_4,PIPE:v4,PLUS:y4,POUND:b4,QUERY:x4,QUOTE:S4,RIGHTCORNERBRACKET:Q2,RIGHTWHITECORNERBRACKET:e4,SCHEME:I2,SEMI:w4,SLASH:T4,SLASH_SCHEME:L2,SYM:k4,TILDE:E4,TLD:P2,UNDERSCORE:D4,UTLD:F2,UWORD:A2,WORD:k2,WS:z2}),j4=/[a-z]/,M4=/\p{L}/u,N4=/\p{Emoji}/u,P4=/\d/,F4=/\s/,I4=`\r`,L4=` +`,SPe=`️`,CPe=`‍`,R4=``,z4=null,B4=null;function wPe(e=[]){let t={};w2.groups=t;let n=new w2;z4??=U4(gPe),B4??=U4(_Pe),O2(n,`'`,i4),O2(n,`{`,V2),O2(n,`}`,H2),O2(n,`[`,U2),O2(n,`]`,W2),O2(n,`(`,G2),O2(n,`)`,K2),O2(n,`<`,q2),O2(n,`>`,J2),O2(n,`(`,Y2),O2(n,`)`,X2),O2(n,`「`,Z2),O2(n,`」`,Q2),O2(n,`『`,$2),O2(n,`』`,e4),O2(n,`<`,t4),O2(n,`>`,n4),O2(n,`&`,r4),O2(n,`*`,a4),O2(n,`@`,o4),O2(n,"`",c4),O2(n,`^`,l4),O2(n,`:`,u4),O2(n,`,`,d4),O2(n,`$`,f4),O2(n,`.`,p4),O2(n,`=`,m4),O2(n,`!`,h4),O2(n,`-`,g4),O2(n,`%`,_4),O2(n,`|`,v4),O2(n,`+`,y4),O2(n,`#`,b4),O2(n,`?`,x4),O2(n,`"`,S4),O2(n,`/`,T4),O2(n,`;`,w4),O2(n,`~`,E4),O2(n,`_`,D4),O2(n,`\\`,s4),O2(n,`・`,C4);let r=E2(n,P4,R2,{[h2]:!0});E2(r,P4,r);let i=E2(r,j4,j2,{[v2]:!0}),a=E2(r,M4,M2,{[y2]:!0}),o=E2(n,j4,k2,{[g2]:!0});E2(o,P4,i),E2(o,j4,o),E2(i,P4,i),E2(i,j4,i);let s=E2(n,M4,A2,{[_2]:!0});E2(s,j4),E2(s,P4,a),E2(s,M4,s),E2(a,P4,a),E2(a,j4),E2(a,M4,a);let c=O2(n,L4,B2,{[S2]:!0}),l=O2(n,I4,z2,{[S2]:!0}),u=E2(n,F4,z2,{[S2]:!0});O2(n,R4,u),O2(l,L4,c),O2(l,R4,u),E2(l,F4,u),O2(u,I4),O2(u,L4),E2(u,F4,u),O2(u,R4,u);let d=E2(n,N4,O4,{[x2]:!0});O2(d,`#`),E2(d,N4,d),O2(d,SPe,d);let f=O2(d,CPe);O2(f,`#`),E2(f,N4,d);let p=[[j4,o],[P4,i]],m=[[j4,null],[M4,s],[P4,a]];for(let e=0;ee[0]>t[0]?1:-1);for(let t=0;t=0?i[b2]=!0:j4.test(r)?P4.test(r)?i[v2]=!0:i[g2]=!0:i[h2]=!0,D2(n,r,r,i)}return D2(n,`localhost`,N2,{ascii:!0}),n.jd=new w2(k4),{start:n,tokens:Object.assign({groups:t},A4)}}function V4(e,t){let n=TPe(t.replace(/[A-Z]/g,e=>e.toLowerCase())),r=n.length,i=[],a=0,o=0;for(;o=0&&(d+=n[o].length,f++),l+=n[o].length,a+=n[o].length,o++;a-=d,o-=f,l-=d,i.push({t:u.t,v:t.slice(a-l,a),s:a-l,e:a})}return i}function TPe(e){let t=[],n=e.length,r=0;for(;r56319||r+1===n||(a=e.charCodeAt(r+1))<56320||a>57343?e[r]:e.slice(r,r+2);t.push(o),r+=o.length}return t}function H4(e,t,n,r,i){let a,o=t.length;for(let n=0;n=0;)i++;if(i>0){t.push(n.join(``));for(let t=parseInt(e.substring(r,r+i),10);t>0;t--)n.pop();r+=i}else n.push(e[r]),r++}return t}var W4={defaultProtocol:`http`,events:null,format:K4,formatHref:K4,nl2br:!1,tagName:`a`,target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],render:null};function G4(e,t=null){let n=Object.assign({},W4);e&&(n=Object.assign(n,e instanceof G4?e.o:e));let r=n.ignoreTags,i=[];for(let e=0;en?r.substring(0,n)+`…`:r},toFormattedHref(e){return e.get(`formatHref`,this.toHref(e.get(`defaultProtocol`)),this)},startIndex(){return this.tk[0].s},endIndex(){return this.tk[this.tk.length-1].e},toObject(e=W4.defaultProtocol){return{type:this.t,value:this.toString(),isLink:this.isLink,href:this.toHref(e),start:this.startIndex(),end:this.endIndex()}},toFormattedObject(e){return{type:this.t,value:this.toFormattedString(e),isLink:this.isLink,href:this.toFormattedHref(e),start:this.startIndex(),end:this.endIndex()}},validate(e){return e.get(`validate`,this.toString(),this)},render(e){let t=this,n=this.toHref(e.get(`defaultProtocol`)),r=e.get(`formatHref`,n,this),i=e.get(`tagName`,n,t),a=this.toFormattedString(e),o={},s=e.get(`className`,n,t),c=e.get(`target`,n,t),l=e.get(`rel`,n,t),u=e.getObj(`attributes`,n,t),d=e.getObj(`events`,n,t);return o.href=r,s&&(o.class=s),c&&(o.target=c),l&&(o.rel=l),u&&Object.assign(o,u),{tagName:i,attributes:o,content:a,eventListeners:d}}};function J4(e,t){class n extends q4{constructor(t,n){super(t,n),this.t=e}}for(let e in t)n.prototype[e]=t[e];return n.t=e,n}var Y4=J4(`email`,{isLink:!0,toHref(){return`mailto:`+this.toString()}}),X4=J4(`text`),EPe=J4(`nl`),Z4=J4(`url`,{isLink:!0,toHref(e=W4.defaultProtocol){return this.hasProtocol()?this.v:`${e}://${this.v}`},hasProtocol(){let e=this.tk;return e.length>=2&&e[0].t!==N2&&e[1].t===u4}}),Q4=e=>new w2(e);function DPe({groups:e}){let t=e.domain.concat([r4,a4,o4,s4,c4,l4,f4,m4,g4,R2,_4,v4,y4,b4,T4,k4,E4,D4]),n=[i4,u4,d4,p4,h4,_4,x4,S4,w4,q2,J2,V2,H2,W2,U2,G2,K2,Y2,X2,Z2,Q2,$2,e4,t4,n4],r=[r4,i4,a4,s4,c4,l4,f4,m4,g4,V2,H2,_4,v4,y4,b4,x4,T4,k4,E4,D4],i=Q4(),a=O2(i,E4);T2(a,r,a),T2(a,e.domain,a);let o=Q4(),s=Q4(),c=Q4();T2(i,e.domain,o),T2(i,e.scheme,s),T2(i,e.slashscheme,c),T2(o,r,a),T2(o,e.domain,o);let l=O2(o,o4);O2(a,o4,l),O2(s,o4,l),O2(c,o4,l);let u=O2(a,p4);T2(u,r,a),T2(u,e.domain,a);let d=Q4();T2(l,e.domain,d),T2(d,e.domain,d);let f=O2(d,p4);T2(f,e.domain,d);let p=Q4(Y4);T2(f,e.tld,p),T2(f,e.utld,p),O2(l,N2,p);let m=O2(d,g4);O2(m,g4,m),T2(m,e.domain,d),T2(p,e.domain,d),O2(p,p4,f),O2(p,g4,m),T2(O2(p,u4),e.numeric,Y4);let h=O2(o,g4),g=O2(o,p4);O2(h,g4,h),T2(h,e.domain,o),T2(g,r,a),T2(g,e.domain,o);let _=Q4(Z4);T2(g,e.tld,_),T2(g,e.utld,_),T2(_,e.domain,o),T2(_,r,a),O2(_,p4,g),O2(_,g4,h),O2(_,o4,l);let v=O2(_,u4),y=Q4(Z4);T2(v,e.numeric,y);let b=Q4(Z4),x=Q4();T2(b,t,b),T2(b,n,x),T2(x,t,b),T2(x,n,x),O2(_,T4,b),O2(y,T4,b);let S=O2(s,u4),C=O2(O2(O2(c,u4),T4),T4);T2(s,e.domain,o),O2(s,p4,g),O2(s,g4,h),T2(c,e.domain,o),O2(c,p4,g),O2(c,g4,h),T2(S,e.domain,b),O2(S,T4,b),O2(S,x4,b),T2(C,e.domain,b),T2(C,t,b),O2(C,T4,b);let w=[[V2,H2],[U2,W2],[G2,K2],[q2,J2],[Y2,X2],[Z2,Q2],[$2,e4],[t4,n4]];for(let e=0;e=0&&f++,i++,u++;if(f<0)i-=u,i0&&(a.push($4(X4,t,o)),o=[]),i-=f,u-=f;let e=d.t,r=n.slice(i-u,i);a.push($4(e,t,r))}}return o.length>0&&a.push($4(X4,t,o)),a}function $4(e,t,n){let r=n[0].s,i=n[n.length-1].e;return new e(t.slice(r,i),n)}var kPe=typeof console<`u`&&console&&console.warn||(()=>{}),APe=`until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.`,e3={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function jPe(){return w2.groups={},e3.scanner=null,e3.parser=null,e3.tokenQueue=[],e3.pluginQueue=[],e3.customSchemes=[],e3.initialized=!1,e3}function t3(e,t=!1){if(e3.initialized&&kPe(`linkifyjs: already initialized - will not register custom scheme "${e}" ${APe}`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(e))throw Error(`linkifyjs: incorrect scheme format. 1. Must only contain digits, lowercase ASCII letters or "-" 2. Cannot start or end with "-" -3. "-" cannot repeat`);e3.customSchemes.push([e,t])}function jPe(){e3.scanner=CPe(e3.customSchemes);for(let e=0;e{let i=t.some(e=>e.docChanged)&&!n.doc.eq(r.doc),a=t.some(e=>e.getMeta(`preventAutolink`));if(!i||a)return;let{tr:o}=r;if(a0(B1(n.doc,[...t])).forEach(({newRange:t})=>{let n=Vje(r.doc,t,e=>e.isTextblock),i,a;if(n.length>1)i=n[0],a=r.doc.textBetween(i.pos,i.pos+i.node.nodeSize,void 0,` `);else if(n.length){let e=r.doc.textBetween(t.from,t.to,` `,` `);if(!NPe.test(e))return;i=n[0],a=r.doc.textBetween(i.pos,t.to,void 0,` `)}if(i&&a){let t=a.split(MPe).filter(Boolean);if(t.length<=0)return!1;let n=t[t.length-1],s=i.pos+a.lastIndexOf(n);if(!n)return!1;let c=n3(n).map(t=>t.toObject(e.defaultProtocol));if(!FPe(c))return!1;c.filter(e=>e.isLink).map(e=>({...e,from:s+e.start+1,to:s+e.end+1})).filter(e=>r.schema.marks.code?!r.doc.rangeHasMark(e.from,e.to,r.schema.marks.code):!0).filter(t=>e.validate(t.value)).filter(t=>e.shouldAutoLink(t.value)).forEach(t=>{o0(t.from,t.to,r.doc).some(t=>t.mark.type===e.type)||o.addMark(t.from,t.to,e.type.create({href:t.href}))})}}),o.steps.length)return o}})}function LPe(e){return new YX({key:new QX(`handleClickLink`),props:{handleClick:(t,n,r)=>{if(r.button!==0||!t.editable)return!1;let i=null;if(r.target instanceof HTMLAnchorElement)i=r.target;else{let t=r.target;if(!t)return!1;let n=e.editor.view.dom;i=t.closest(`a`),i&&!n.contains(i)&&(i=null)}if(!i)return!1;let a=!1;if(e.enableClickSelection&&(a=e.editor.commands.extendMarkRange(e.type.name)),e.openOnClick){let n=i0(t.state,e.type.name),r=i.href??n.href,o=i.target??n.target;r&&(window.open(r,o),a=!0)}return a}}})}function RPe(e){return new YX({key:new QX(`handlePasteLink`),props:{handlePaste:(t,n,r)=>{let{shouldAutoLink:i}=e,{state:a}=t,{selection:o}=a,{empty:s}=o;if(s)return!1;let c=``;r.content.forEach(e=>{c+=e.textContent});let l=r3(c,{defaultProtocol:e.defaultProtocol}).find(e=>e.isLink&&e.value===c);return!c||!l||i!==void 0&&!i(l.value)?!1:e.editor.commands.setMark(e.type,{href:l.href})}}})}function a3(e,t){let n=[`http`,`https`,`ftp`,`ftps`,`mailto`,`tel`,`callto`,`sms`,`cid`,`xmpp`];return t&&t.forEach(e=>{let t=typeof e==`string`?e:e.scheme;t&&n.push(t)}),!e||e.replace(PPe,``).match(RegExp(`^(?:(?:${n.join(`|`)}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,`i`))}var o3=C0.create({name:`link`,priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(e=>{if(typeof e==`string`){t3(e);return}t3(e.scheme,e.optionalSlashes)})},onDestroy(){APe()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,enableClickSelection:!1,linkOnPaste:!0,autolink:!0,protocols:[],defaultProtocol:`http`,HTMLAttributes:{target:`_blank`,rel:`noopener noreferrer nofollow`,class:null},isAllowedUri:(e,t)=>!!a3(e,t.protocols),validate:e=>!!e,shouldAutoLink:e=>{let t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e),n=/^[a-z][a-z0-9+.-]*:/i.test(e);if(t||n&&!e.includes(`@`))return!0;let r=(e.includes(`@`)?e.split(`@`).pop():e).split(/[/?#:]/)[0];return!(/^\d{1,3}(\.\d{1,3}){3}$/.test(r)||!/\./.test(r))}}},addAttributes(){return{href:{default:null,parseHTML(e){return e.getAttribute(`href`)}},target:{default:this.options.HTMLAttributes.target},rel:{default:this.options.HTMLAttributes.rel},class:{default:this.options.HTMLAttributes.class},title:{default:null}}},parseHTML(){return[{tag:`a[href]`,getAttrs:e=>{let t=e.getAttribute(`href`);return!t||!this.options.isAllowedUri(t,{defaultValidate:e=>!!a3(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:null}}]},renderHTML({HTMLAttributes:e}){return this.options.isAllowedUri(e.href,{defaultValidate:e=>!!a3(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?[`a`,Y1(this.options.HTMLAttributes,e),0]:[`a`,Y1(this.options.HTMLAttributes,{...e,href:``}),0]},markdownTokenName:`link`,parseMarkdown:(e,t)=>t.applyMark(`link`,t.parseInline(e.tokens||[]),{href:e.href,title:e.title||null}),renderMarkdown:(e,t)=>{let n=e.attrs?.href??``,r=e.attrs?.title??``,i=t.renderChildren(e);return r?`[${i}](${n} "${r}")`:`[${i}](${n})`},addCommands(){return{setLink:e=>({chain:t})=>{let{href:n}=e;return this.options.isAllowedUri(n,{defaultValidate:e=>!!a3(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?t().setMark(this.name,e).setMeta(`preventAutolink`,!0).run():!1},toggleLink:e=>({chain:t})=>{let{href:n}=e||{};return n&&!this.options.isAllowedUri(n,{defaultValidate:e=>!!a3(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:t().toggleMark(this.name,e,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()},unsetLink:()=>({chain:e})=>e().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()}},addPasteRules(){return[q0({find:e=>{let t=[];if(e){let{protocols:n,defaultProtocol:r}=this.options,i=r3(e).filter(e=>e.isLink&&this.options.isAllowedUri(e.value,{defaultValidate:e=>!!a3(e,n),protocols:n,defaultProtocol:r}));i.length&&i.forEach(e=>{this.options.shouldAutoLink(e.value)&&t.push({text:e.value,data:{href:e.href},index:e.start})})}return t},type:this.type,getAttributes:e=>({href:e.data?.href})})]},addProseMirrorPlugins(){let e=[],{protocols:t,defaultProtocol:n}=this.options;return this.options.autolink&&e.push(IPe({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!a3(e,t),protocols:t,defaultProtocol:n}),shouldAutoLink:this.options.shouldAutoLink})),e.push(LPe({type:this.type,editor:this.editor,openOnClick:this.options.openOnClick===`whenNotEditable`?!0:this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&e.push(RPe({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),e}}),zPe=o3,BPe=Object.defineProperty,VPe=(e,t)=>{for(var n in t)BPe(e,n,{get:t[n],enumerable:!0})},HPe=`listItem`,s3=`textStyle`,c3=/^\s*([-+*])\s$/,l3=K0.create({name:`bulletList`,addOptions(){return{itemTypeName:`listItem`,HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:`block list`,content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul`}]},renderHTML({HTMLAttributes:e}){return[`ul`,Y1(this.options.HTMLAttributes,e),0]},markdownTokenName:`list`,parseMarkdown:(e,t)=>e.type!==`list`||e.ordered?[]:{type:`bulletList`,content:e.items?t.parseChildren(e.items):[]},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` -`):``,markdownOptions:{indentsContent:!0},addCommands(){return{toggleBulletList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(HPe,this.editor.getAttributes(s3)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let e=V0({find:c3,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(e=V0({find:c3,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(s3),editor:this.editor})),[e]}}),u3=K0.create({name:`listItem`,addOptions(){return{HTMLAttributes:{},bulletListTypeName:`bulletList`,orderedListTypeName:`orderedList`}},content:`paragraph block*`,defining:!0,parseHTML(){return[{tag:`li`}]},renderHTML({HTMLAttributes:e}){return[`li`,Y1(this.options.HTMLAttributes,e),0]},markdownTokenName:`list_item`,parseMarkdown:(e,t)=>{if(e.type!==`list_item`)return[];let n=[];if(e.tokens&&e.tokens.length>0)if(e.tokens.some(e=>e.type===`paragraph`))n=t.parseChildren(e.tokens);else{let r=e.tokens[0];if(r&&r.type===`text`&&r.tokens&&r.tokens.length>0){if(n=[{type:`paragraph`,content:t.parseInline(r.tokens)}],e.tokens.length>1){let r=e.tokens.slice(1),i=t.parseChildren(r);n.push(...i)}}else n=t.parseChildren(e.tokens)}return n.length===0&&(n=[{type:`paragraph`,content:[]}]),{type:`listItem`,content:n}},renderMarkdown:(e,t,n)=>G0(e,t,e=>e.parentType===`bulletList`?`- `:e.parentType===`orderedList`?`${(e.meta?.parentAttrs?.start||1)+e.index}. `:`- `,n),addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}});VPe({},{findListItemPos:()=>d3,getNextListDepth:()=>f3,handleBackspace:()=>g3,handleDelete:()=>y3,hasListBefore:()=>p3,hasListItemAfter:()=>UPe,hasListItemBefore:()=>m3,listItemHasSubList:()=>h3,nextListIsDeeper:()=>_3,nextListIsHigher:()=>v3});var d3=(e,t)=>{let{$from:n}=t.selection,r=y1(e,t.schema),i=null,a=n.depth,o=n.pos,s=null;for(;a>0&&s===null;)i=n.node(a),i.type===r?s=a:(--a,--o);return s===null?null:{$pos:t.doc.resolve(o),depth:s}},f3=(e,t)=>{let n=d3(e,t);if(!n)return!1;let[,r]=Zje(t,e,n.$pos.pos+4);return r},p3=(e,t,n)=>{let{$anchor:r}=e.selection,i=Math.max(0,r.pos-2),a=e.doc.resolve(i).node();return!(!a||!n.includes(a.type.name))},m3=(e,t)=>{let{$anchor:n}=t.selection,r=t.doc.resolve(n.pos-2);return!(r.index()===0||r.nodeBefore?.type.name!==e)},h3=(e,t,n)=>{if(!n)return!1;let r=y1(e,t.schema),i=!1;return n.descendants(e=>{e.type===r&&(i=!0)}),i},g3=(e,t,n)=>{if(e.commands.undoInputRule())return!0;if(e.state.selection.from!==e.state.selection.to)return!1;if(!F1(e.state,t)&&p3(e.state,t,n)){let{$anchor:n}=e.state.selection,r=e.state.doc.resolve(n.before()-1),i=[];r.node().descendants((e,n)=>{e.type.name===t&&i.push({node:e,pos:n})});let a=i.at(-1);if(!a)return!1;let o=e.state.doc.resolve(r.start()+a.pos+1);return e.chain().cut({from:n.start()-1,to:n.end()+1},o.end()).joinForward().run()}if(!F1(e.state,t)||!tMe(e.state))return!1;let r=d3(t,e.state);if(!r)return!1;let i=e.state.doc.resolve(r.$pos.pos-2).node(r.depth),a=h3(t,e.state,i);return m3(t,e.state)&&!a?e.commands.joinItemBackward():e.chain().liftListItem(t).run()},_3=(e,t)=>{let n=f3(e,t),r=d3(e,t);return!r||!n?!1:n>r.depth},v3=(e,t)=>{let n=f3(e,t),r=d3(e,t);return!r||!n?!1:n{if(!F1(e.state,t)||!eMe(e.state,t))return!1;let{selection:n}=e.state,{$from:r,$to:i}=n;return!n.empty&&r.sameParent(i)?!1:_3(t,e.state)?e.chain().focus(e.state.selection.from+4).lift(t).joinBackward().run():v3(t,e.state)?e.chain().joinForward().joinBackward().run():e.commands.joinItemForward()},UPe=(e,t)=>{let{$anchor:n}=t.selection,r=t.doc.resolve(n.pos-n.parentOffset-2);return!(r.index()===r.parent.childCount-1||r.nodeAfter?.type.name!==e)},b3=E0.create({name:`listKeymap`,addOptions(){return{listTypes:[{itemName:`listItem`,wrapperNames:[`bulletList`,`orderedList`]},{itemName:`taskItem`,wrapperNames:[`taskList`]}]}},addKeyboardShortcuts(){return{Delete:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&y3(e,n)&&(t=!0)}),t},"Mod-Delete":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&y3(e,n)&&(t=!0)}),t},Backspace:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{e.state.schema.nodes[n]!==void 0&&g3(e,n,r)&&(t=!0)}),t},"Mod-Backspace":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{e.state.schema.nodes[n]!==void 0&&g3(e,n,r)&&(t=!0)}),t}}}}),x3=/^(\s*)(\d+)\.\s+(.*)$/,WPe=/^\s/;function GPe(e){let t=[],n=0,r=0;for(;n{let i=t.some(e=>e.docChanged)&&!n.doc.eq(r.doc),a=t.some(e=>e.getMeta(`preventAutolink`));if(!i||a)return;let{tr:o}=r;if(a0(B1(n.doc,[...t])).forEach(({newRange:t})=>{let n=Hje(r.doc,t,e=>e.isTextblock),i,a;if(n.length>1)i=n[0],a=r.doc.textBetween(i.pos,i.pos+i.node.nodeSize,void 0,` `);else if(n.length){let e=r.doc.textBetween(t.from,t.to,` `,` `);if(!PPe.test(e))return;i=n[0],a=r.doc.textBetween(i.pos,t.to,void 0,` `)}if(i&&a){let t=a.split(NPe).filter(Boolean);if(t.length<=0)return!1;let n=t[t.length-1],s=i.pos+a.lastIndexOf(n);if(!n)return!1;let c=n3(n).map(t=>t.toObject(e.defaultProtocol));if(!IPe(c))return!1;c.filter(e=>e.isLink).map(e=>({...e,from:s+e.start+1,to:s+e.end+1})).filter(e=>r.schema.marks.code?!r.doc.rangeHasMark(e.from,e.to,r.schema.marks.code):!0).filter(t=>e.validate(t.value)).filter(t=>e.shouldAutoLink(t.value)).forEach(t=>{o0(t.from,t.to,r.doc).some(t=>t.mark.type===e.type)||o.addMark(t.from,t.to,e.type.create({href:t.href}))})}}),o.steps.length)return o}})}function RPe(e){return new YX({key:new QX(`handleClickLink`),props:{handleClick:(t,n,r)=>{if(r.button!==0||!t.editable)return!1;let i=null;if(r.target instanceof HTMLAnchorElement)i=r.target;else{let t=r.target;if(!t)return!1;let n=e.editor.view.dom;i=t.closest(`a`),i&&!n.contains(i)&&(i=null)}if(!i)return!1;let a=!1;if(e.enableClickSelection&&(a=e.editor.commands.extendMarkRange(e.type.name)),e.openOnClick){let n=i0(t.state,e.type.name),r=i.href??n.href,o=i.target??n.target;r&&(window.open(r,o),a=!0)}return a}}})}function zPe(e){return new YX({key:new QX(`handlePasteLink`),props:{handlePaste:(t,n,r)=>{let{shouldAutoLink:i}=e,{state:a}=t,{selection:o}=a,{empty:s}=o;if(s)return!1;let c=``;r.content.forEach(e=>{c+=e.textContent});let l=r3(c,{defaultProtocol:e.defaultProtocol}).find(e=>e.isLink&&e.value===c);return!c||!l||i!==void 0&&!i(l.value)?!1:e.editor.commands.setMark(e.type,{href:l.href})}}})}function a3(e,t){let n=[`http`,`https`,`ftp`,`ftps`,`mailto`,`tel`,`callto`,`sms`,`cid`,`xmpp`];return t&&t.forEach(e=>{let t=typeof e==`string`?e:e.scheme;t&&n.push(t)}),!e||e.replace(FPe,``).match(RegExp(`^(?:(?:${n.join(`|`)}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,`i`))}var o3=C0.create({name:`link`,priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(e=>{if(typeof e==`string`){t3(e);return}t3(e.scheme,e.optionalSlashes)})},onDestroy(){jPe()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,enableClickSelection:!1,linkOnPaste:!0,autolink:!0,protocols:[],defaultProtocol:`http`,HTMLAttributes:{target:`_blank`,rel:`noopener noreferrer nofollow`,class:null},isAllowedUri:(e,t)=>!!a3(e,t.protocols),validate:e=>!!e,shouldAutoLink:e=>{let t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e),n=/^[a-z][a-z0-9+.-]*:/i.test(e);if(t||n&&!e.includes(`@`))return!0;let r=(e.includes(`@`)?e.split(`@`).pop():e).split(/[/?#:]/)[0];return!(/^\d{1,3}(\.\d{1,3}){3}$/.test(r)||!/\./.test(r))}}},addAttributes(){return{href:{default:null,parseHTML(e){return e.getAttribute(`href`)}},target:{default:this.options.HTMLAttributes.target},rel:{default:this.options.HTMLAttributes.rel},class:{default:this.options.HTMLAttributes.class},title:{default:null}}},parseHTML(){return[{tag:`a[href]`,getAttrs:e=>{let t=e.getAttribute(`href`);return!t||!this.options.isAllowedUri(t,{defaultValidate:e=>!!a3(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:null}}]},renderHTML({HTMLAttributes:e}){return this.options.isAllowedUri(e.href,{defaultValidate:e=>!!a3(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?[`a`,Y1(this.options.HTMLAttributes,e),0]:[`a`,Y1(this.options.HTMLAttributes,{...e,href:``}),0]},markdownTokenName:`link`,parseMarkdown:(e,t)=>t.applyMark(`link`,t.parseInline(e.tokens||[]),{href:e.href,title:e.title||null}),renderMarkdown:(e,t)=>{let n=e.attrs?.href??``,r=e.attrs?.title??``,i=t.renderChildren(e);return r?`[${i}](${n} "${r}")`:`[${i}](${n})`},addCommands(){return{setLink:e=>({chain:t})=>{let{href:n}=e;return this.options.isAllowedUri(n,{defaultValidate:e=>!!a3(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?t().setMark(this.name,e).setMeta(`preventAutolink`,!0).run():!1},toggleLink:e=>({chain:t})=>{let{href:n}=e||{};return n&&!this.options.isAllowedUri(n,{defaultValidate:e=>!!a3(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:t().toggleMark(this.name,e,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()},unsetLink:()=>({chain:e})=>e().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()}},addPasteRules(){return[q0({find:e=>{let t=[];if(e){let{protocols:n,defaultProtocol:r}=this.options,i=r3(e).filter(e=>e.isLink&&this.options.isAllowedUri(e.value,{defaultValidate:e=>!!a3(e,n),protocols:n,defaultProtocol:r}));i.length&&i.forEach(e=>{this.options.shouldAutoLink(e.value)&&t.push({text:e.value,data:{href:e.href},index:e.start})})}return t},type:this.type,getAttributes:e=>({href:e.data?.href})})]},addProseMirrorPlugins(){let e=[],{protocols:t,defaultProtocol:n}=this.options;return this.options.autolink&&e.push(LPe({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!a3(e,t),protocols:t,defaultProtocol:n}),shouldAutoLink:this.options.shouldAutoLink})),e.push(RPe({type:this.type,editor:this.editor,openOnClick:this.options.openOnClick===`whenNotEditable`?!0:this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&e.push(zPe({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),e}}),BPe=o3,VPe=Object.defineProperty,HPe=(e,t)=>{for(var n in t)VPe(e,n,{get:t[n],enumerable:!0})},UPe=`listItem`,s3=`textStyle`,c3=/^\s*([-+*])\s$/,l3=K0.create({name:`bulletList`,addOptions(){return{itemTypeName:`listItem`,HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:`block list`,content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul`}]},renderHTML({HTMLAttributes:e}){return[`ul`,Y1(this.options.HTMLAttributes,e),0]},markdownTokenName:`list`,parseMarkdown:(e,t)=>e.type!==`list`||e.ordered?[]:{type:`bulletList`,content:e.items?t.parseChildren(e.items):[]},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` +`):``,markdownOptions:{indentsContent:!0},addCommands(){return{toggleBulletList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(UPe,this.editor.getAttributes(s3)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let e=V0({find:c3,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(e=V0({find:c3,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(s3),editor:this.editor})),[e]}}),u3=K0.create({name:`listItem`,addOptions(){return{HTMLAttributes:{},bulletListTypeName:`bulletList`,orderedListTypeName:`orderedList`}},content:`paragraph block*`,defining:!0,parseHTML(){return[{tag:`li`}]},renderHTML({HTMLAttributes:e}){return[`li`,Y1(this.options.HTMLAttributes,e),0]},markdownTokenName:`list_item`,parseMarkdown:(e,t)=>{if(e.type!==`list_item`)return[];let n=[];if(e.tokens&&e.tokens.length>0)if(e.tokens.some(e=>e.type===`paragraph`))n=t.parseChildren(e.tokens);else{let r=e.tokens[0];if(r&&r.type===`text`&&r.tokens&&r.tokens.length>0){if(n=[{type:`paragraph`,content:t.parseInline(r.tokens)}],e.tokens.length>1){let r=e.tokens.slice(1),i=t.parseChildren(r);n.push(...i)}}else n=t.parseChildren(e.tokens)}return n.length===0&&(n=[{type:`paragraph`,content:[]}]),{type:`listItem`,content:n}},renderMarkdown:(e,t,n)=>G0(e,t,e=>e.parentType===`bulletList`?`- `:e.parentType===`orderedList`?`${(e.meta?.parentAttrs?.start||1)+e.index}. `:`- `,n),addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}});HPe({},{findListItemPos:()=>d3,getNextListDepth:()=>f3,handleBackspace:()=>g3,handleDelete:()=>y3,hasListBefore:()=>p3,hasListItemAfter:()=>WPe,hasListItemBefore:()=>m3,listItemHasSubList:()=>h3,nextListIsDeeper:()=>_3,nextListIsHigher:()=>v3});var d3=(e,t)=>{let{$from:n}=t.selection,r=y1(e,t.schema),i=null,a=n.depth,o=n.pos,s=null;for(;a>0&&s===null;)i=n.node(a),i.type===r?s=a:(--a,--o);return s===null?null:{$pos:t.doc.resolve(o),depth:s}},f3=(e,t)=>{let n=d3(e,t);if(!n)return!1;let[,r]=Qje(t,e,n.$pos.pos+4);return r},p3=(e,t,n)=>{let{$anchor:r}=e.selection,i=Math.max(0,r.pos-2),a=e.doc.resolve(i).node();return!(!a||!n.includes(a.type.name))},m3=(e,t)=>{let{$anchor:n}=t.selection,r=t.doc.resolve(n.pos-2);return!(r.index()===0||r.nodeBefore?.type.name!==e)},h3=(e,t,n)=>{if(!n)return!1;let r=y1(e,t.schema),i=!1;return n.descendants(e=>{e.type===r&&(i=!0)}),i},g3=(e,t,n)=>{if(e.commands.undoInputRule())return!0;if(e.state.selection.from!==e.state.selection.to)return!1;if(!F1(e.state,t)&&p3(e.state,t,n)){let{$anchor:n}=e.state.selection,r=e.state.doc.resolve(n.before()-1),i=[];r.node().descendants((e,n)=>{e.type.name===t&&i.push({node:e,pos:n})});let a=i.at(-1);if(!a)return!1;let o=e.state.doc.resolve(r.start()+a.pos+1);return e.chain().cut({from:n.start()-1,to:n.end()+1},o.end()).joinForward().run()}if(!F1(e.state,t)||!nMe(e.state))return!1;let r=d3(t,e.state);if(!r)return!1;let i=e.state.doc.resolve(r.$pos.pos-2).node(r.depth),a=h3(t,e.state,i);return m3(t,e.state)&&!a?e.commands.joinItemBackward():e.chain().liftListItem(t).run()},_3=(e,t)=>{let n=f3(e,t),r=d3(e,t);return!r||!n?!1:n>r.depth},v3=(e,t)=>{let n=f3(e,t),r=d3(e,t);return!r||!n?!1:n{if(!F1(e.state,t)||!tMe(e.state,t))return!1;let{selection:n}=e.state,{$from:r,$to:i}=n;return!n.empty&&r.sameParent(i)?!1:_3(t,e.state)?e.chain().focus(e.state.selection.from+4).lift(t).joinBackward().run():v3(t,e.state)?e.chain().joinForward().joinBackward().run():e.commands.joinItemForward()},WPe=(e,t)=>{let{$anchor:n}=t.selection,r=t.doc.resolve(n.pos-n.parentOffset-2);return!(r.index()===r.parent.childCount-1||r.nodeAfter?.type.name!==e)},b3=E0.create({name:`listKeymap`,addOptions(){return{listTypes:[{itemName:`listItem`,wrapperNames:[`bulletList`,`orderedList`]},{itemName:`taskItem`,wrapperNames:[`taskList`]}]}},addKeyboardShortcuts(){return{Delete:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&y3(e,n)&&(t=!0)}),t},"Mod-Delete":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&y3(e,n)&&(t=!0)}),t},Backspace:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{e.state.schema.nodes[n]!==void 0&&g3(e,n,r)&&(t=!0)}),t},"Mod-Backspace":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{e.state.schema.nodes[n]!==void 0&&g3(e,n,r)&&(t=!0)}),t}}}}),x3=/^(\s*)(\d+)\.\s+(.*)$/,GPe=/^\s/;function KPe(e){let t=[],n=0,r=0;for(;nt;)d.push(e[u]),u+=1;if(d.length>0){let e=S3(d,Math.min(...d.map(e=>e.indent)),n);c.push({type:`list`,ordered:!0,start:d[0].number,items:e,raw:d.map(e=>e.raw).join(` -`)})}r.push({type:`list_item`,raw:a.raw,tokens:c}),i=u}else i+=1}return r}function KPe(e,t){return e.map(e=>{if(e.type!==`list_item`)return t.parseChildren([e])[0];let n=[];return e.tokens&&e.tokens.length>0&&e.tokens.forEach(e=>{if(e.type===`paragraph`||e.type===`list`||e.type===`blockquote`||e.type===`code`)n.push(...t.parseChildren([e]));else if(e.type===`text`&&e.tokens){let r=t.parseChildren([e]);n.push({type:`paragraph`,content:r})}else{let r=t.parseChildren([e]);r.length>0&&n.push(...r)}}),{type:`listItem`,content:n}})}var qPe=`listItem`,C3=`textStyle`,w3=/^(\d+)\.\s$/,T3=K0.create({name:`orderedList`,addOptions(){return{itemTypeName:`listItem`,HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:`block list`,content(){return`${this.options.itemTypeName}+`},addAttributes(){return{start:{default:1,parseHTML:e=>e.hasAttribute(`start`)?parseInt(e.getAttribute(`start`)||``,10):1},type:{default:null,parseHTML:e=>e.getAttribute(`type`)}}},parseHTML(){return[{tag:`ol`}]},renderHTML({HTMLAttributes:e}){let{start:t,...n}=e;return t===1?[`ol`,Y1(this.options.HTMLAttributes,n),0]:[`ol`,Y1(this.options.HTMLAttributes,e),0]},markdownTokenName:`list`,parseMarkdown:(e,t)=>{if(e.type!==`list`||!e.ordered)return[];let n=e.start||1,r=e.items?KPe(e.items,t):[];return n===1?{type:`orderedList`,content:r}:{type:`orderedList`,attrs:{start:n},content:r}},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` +`)})}r.push({type:`list_item`,raw:a.raw,tokens:c}),i=u}else i+=1}return r}function qPe(e,t){return e.map(e=>{if(e.type!==`list_item`)return t.parseChildren([e])[0];let n=[];return e.tokens&&e.tokens.length>0&&e.tokens.forEach(e=>{if(e.type===`paragraph`||e.type===`list`||e.type===`blockquote`||e.type===`code`)n.push(...t.parseChildren([e]));else if(e.type===`text`&&e.tokens){let r=t.parseChildren([e]);n.push({type:`paragraph`,content:r})}else{let r=t.parseChildren([e]);r.length>0&&n.push(...r)}}),{type:`listItem`,content:n}})}var JPe=`listItem`,C3=`textStyle`,w3=/^(\d+)\.\s$/,T3=K0.create({name:`orderedList`,addOptions(){return{itemTypeName:`listItem`,HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:`block list`,content(){return`${this.options.itemTypeName}+`},addAttributes(){return{start:{default:1,parseHTML:e=>e.hasAttribute(`start`)?parseInt(e.getAttribute(`start`)||``,10):1},type:{default:null,parseHTML:e=>e.getAttribute(`type`)}}},parseHTML(){return[{tag:`ol`}]},renderHTML({HTMLAttributes:e}){let{start:t,...n}=e;return t===1?[`ol`,Y1(this.options.HTMLAttributes,n),0]:[`ol`,Y1(this.options.HTMLAttributes,e),0]},markdownTokenName:`list`,parseMarkdown:(e,t)=>{if(e.type!==`list`||!e.ordered)return[];let n=e.start||1,r=e.items?qPe(e.items,t):[];return n===1?{type:`orderedList`,content:r}:{type:`orderedList`,attrs:{start:n},content:r}},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` `):``,markdownTokenizer:{name:`orderedList`,level:`block`,start:e=>{let t=e.match(/^(\s*)(\d+)\.\s+/)?.index;return t===void 0?-1:t},tokenize:(e,t,n)=>{let r=e.split(` -`),[i,a]=GPe(r);if(i.length===0)return;let o=S3(i,0,n);if(o.length!==0)return{type:`list`,ordered:!0,start:i[0]?.number||1,items:o,raw:r.slice(0,a).join(` -`)}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleOrderedList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(qPe,this.editor.getAttributes(C3)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addInputRules(){let e=V0({find:w3,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1]});return(this.options.keepMarks||this.options.keepAttributes)&&(e=V0({find:w3,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(C3)}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1],editor:this.editor})),[e]}}),JPe=/^\s*(\[([( |x])?\])\s$/,YPe=K0.create({name:`taskItem`,addOptions(){return{nested:!1,HTMLAttributes:{},taskListTypeName:`taskList`,a11y:void 0}},content(){return this.options.nested?`paragraph block*`:`paragraph+`},defining:!0,addAttributes(){return{checked:{default:!1,keepOnSplit:!1,parseHTML:e=>{let t=e.getAttribute(`data-checked`);return t===``||t===`true`},renderHTML:e=>({"data-checked":e.checked})}}},parseHTML(){return[{tag:`li[data-type="${this.name}"]`,priority:51}]},renderHTML({node:e,HTMLAttributes:t}){return[`li`,Y1(this.options.HTMLAttributes,t,{"data-type":this.name}),[`label`,[`input`,{type:`checkbox`,checked:e.attrs.checked?`checked`:null}],[`span`]],[`div`,0]]},parseMarkdown:(e,t)=>{let n=[];if(e.tokens&&e.tokens.length>0?n.push(t.createNode(`paragraph`,{},t.parseInline(e.tokens))):e.text?n.push(t.createNode(`paragraph`,{},[t.createNode(`text`,{text:e.text})])):n.push(t.createNode(`paragraph`,{},[])),e.nestedTokens&&e.nestedTokens.length>0){let r=t.parseChildren(e.nestedTokens);n.push(...r)}return t.createNode(`taskItem`,{checked:e.checked||!1},n)},renderMarkdown:(e,t)=>G0(e,t,`- [${e.attrs?.checked?`x`:` `}] `),addKeyboardShortcuts(){let e={Enter:()=>this.editor.commands.splitListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)};return this.options.nested?{...e,Tab:()=>this.editor.commands.sinkListItem(this.name)}:e},addNodeView(){return({node:e,HTMLAttributes:t,getPos:n,editor:r})=>{let i=document.createElement(`li`),a=document.createElement(`label`),o=document.createElement(`span`),s=document.createElement(`input`),c=document.createElement(`div`),l=e=>{var t;s.ariaLabel=((t=this.options.a11y)?.checkboxLabel)?.call(t,e,s.checked)||`Task item checkbox for ${e.textContent||`empty task item`}`};l(e),a.contentEditable=`false`,s.type=`checkbox`,s.addEventListener(`mousedown`,e=>e.preventDefault()),s.addEventListener(`change`,t=>{if(!r.isEditable&&!this.options.onReadOnlyChecked){s.checked=!s.checked;return}let{checked:i}=t.target;r.isEditable&&typeof n==`function`&&r.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:e})=>{let t=n();if(typeof t!=`number`)return!1;let r=e.doc.nodeAt(t);return e.setNodeMarkup(t,void 0,{...r?.attrs,checked:i}),!0}).run(),!r.isEditable&&this.options.onReadOnlyChecked&&(this.options.onReadOnlyChecked(e,i)||(s.checked=!s.checked))}),Object.entries(this.options.HTMLAttributes).forEach(([e,t])=>{i.setAttribute(e,t)}),i.dataset.checked=e.attrs.checked,s.checked=e.attrs.checked,a.append(s,o),i.append(a,c),Object.entries(t).forEach(([e,t])=>{i.setAttribute(e,t)});let u=new Set(Object.keys(t));return{dom:i,contentDOM:c,update:e=>{if(e.type!==this.type)return!1;i.dataset.checked=e.attrs.checked,s.checked=e.attrs.checked,l(e);let t=r.extensionManager.attributes,n=X1(e,t),a=new Set(Object.keys(n)),o=this.options.HTMLAttributes;return u.forEach(e=>{a.has(e)||(e in o?i.setAttribute(e,o[e]):i.removeAttribute(e))}),Object.entries(n).forEach(([e,t])=>{t==null?e in o?i.setAttribute(e,o[e]):i.removeAttribute(e):i.setAttribute(e,t)}),u=a,!0}}}},addInputRules(){return[V0({find:JPe,type:this.type,getAttributes:e=>({checked:e[e.length-1]===`x`})})]}}),XPe=K0.create({name:`taskList`,addOptions(){return{itemTypeName:`taskItem`,HTMLAttributes:{}}},group:`block list`,content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul[data-type="${this.name}"]`,priority:51}]},renderHTML({HTMLAttributes:e}){return[`ul`,Y1(this.options.HTMLAttributes,e,{"data-type":this.name}),0]},parseMarkdown:(e,t)=>t.createNode(`taskList`,{},t.parseChildren(e.items||[])),renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` -`):``,markdownTokenizer:{name:`taskList`,level:`block`,start(e){let t=e.match(/^\s*[-+*]\s+\[([ xX])\]\s+/)?.index;return t===void 0?-1:t},tokenize(e,t,n){let r=e=>{let t=W0(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);return t?[{type:`taskList`,raw:t.raw,items:t.items}]:n.blockTokens(e)},i=W0(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);if(i)return{type:`taskList`,raw:i.raw,items:i.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:e})=>e.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});E0.create({name:`listKit`,addExtensions(){let e=[];return this.options.bulletList!==!1&&e.push(l3.configure(this.options.bulletList)),this.options.listItem!==!1&&e.push(u3.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(b3.configure(this.options.listKeymap)),this.options.orderedList!==!1&&e.push(T3.configure(this.options.orderedList)),this.options.taskItem!==!1&&e.push(YPe.configure(this.options.taskItem)),this.options.taskList!==!1&&e.push(XPe.configure(this.options.taskList)),e}});var E3=` `,ZPe=`\xA0`,QPe=K0.create({name:`paragraph`,priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:`block`,content:`inline*`,parseHTML(){return[{tag:`p`}]},renderHTML({HTMLAttributes:e}){return[`p`,Y1(this.options.HTMLAttributes,e),0]},parseMarkdown:(e,t)=>{let n=e.tokens||[];if(n.length===1&&n[0].type===`image`)return t.parseChildren([n[0]]);let r=t.parseInline(n);return r.length===1&&r[0].type===`text`&&(r[0].text===E3||r[0].text===ZPe)?t.createNode(`paragraph`,void 0,[]):t.createNode(`paragraph`,void 0,r)},renderMarkdown:(e,t)=>{if(!e)return``;let n=Array.isArray(e.content)?e.content:[];return n.length===0?E3:t.renderChildren(n)},addCommands(){return{setParagraph:()=>({commands:e})=>e.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),$Pe=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,eFe=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,tFe=C0.create({name:`strike`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`s`},{tag:`del`},{tag:`strike`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`line-through`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`s`,Y1(this.options.HTMLAttributes,e),0]},markdownTokenName:`del`,parseMarkdown:(e,t)=>t.applyMark(`strike`,t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>`~~${t.renderChildren(e)}~~`,addCommands(){return{setStrike:()=>({commands:e})=>e.setMark(this.name),toggleStrike:()=>({commands:e})=>e.toggleMark(this.name),unsetStrike:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[R0({find:$Pe,type:this.type})]},addPasteRules(){return[q0({find:eFe,type:this.type})]}}),nFe=K0.create({name:`text`,group:`inline`,parseMarkdown:e=>({type:`text`,text:e.text||``}),renderMarkdown:e=>e.text||``}),D3=C0.create({name:`underline`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`u`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`underline`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`u`,Y1(this.options.HTMLAttributes,e),0]},parseMarkdown(e,t){return t.applyMark(this.name||`underline`,t.parseInline(e.tokens||[]))},renderMarkdown(e,t){return`++${t.renderChildren(e)}++`},markdownTokenizer:{name:`underline`,level:`inline`,start(e){return e.indexOf(`++`)},tokenize(e,t,n){let r=/^(\+\+)([\s\S]+?)(\+\+)/.exec(e);if(!r)return;let i=r[2].trim();return{type:`underline`,raw:r[0],text:i,tokens:n.inlineTokens(i)}}},addCommands(){return{setUnderline:()=>({commands:e})=>e.setMark(this.name),toggleUnderline:()=>({commands:e})=>e.toggleMark(this.name),unsetUnderline:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),rFe=D3;function iFe(e={}){return new YX({view(t){return new aFe(t,e)}})}var aFe=class{constructor(e,t){this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=t.width??1,this.color=t.color===!1?void 0:t.color||`black`,this.class=t.class,this.handlers=[`dragover`,`dragend`,`drop`,`dragleave`].map(t=>{let n=e=>{this[t](e)};return e.dom.addEventListener(t,n),{name:t,handler:n}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,n,r=this.editorView.dom,i=r.getBoundingClientRect(),a=i.width/r.offsetWidth,o=i.height/r.offsetHeight;if(t){let t=e.nodeBefore,r=e.nodeAfter;if(t||r){let e=this.editorView.nodeDOM(this.cursorPos-(t?t.nodeSize:0));if(e){let i=e.getBoundingClientRect(),a=t?i.bottom:i.top;t&&r&&(a=(a+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let s=this.width/2*o;n={left:i.left,right:i.right,top:a-s,bottom:a+s}}}}if(!n){let e=this.editorView.coordsAtPos(this.cursorPos),t=this.width/2*a;n={left:e.left-t,right:e.left+t,top:e.top,bottom:e.bottom}}let s=this.editorView.dom.offsetParent;this.element||(this.element=s.appendChild(document.createElement(`div`)),this.class&&(this.element.className=this.class),this.element.style.cssText=`position: absolute; z-index: 50; pointer-events: none;`,this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle(`prosemirror-dropcursor-block`,t),this.element.classList.toggle(`prosemirror-dropcursor-inline`,!t);let c,l;if(!s||s==document.body&&getComputedStyle(s).position==`static`)c=-pageXOffset,l=-pageYOffset;else{let e=s.getBoundingClientRect(),t=e.width/s.offsetWidth,n=e.height/s.offsetHeight;c=e.left-s.scrollLeft*t,l=e.top-s.scrollTop*n}this.element.style.left=(n.left-c)/a+`px`,this.element.style.top=(n.top-l)/o+`px`,this.element.style.width=(n.right-n.left)/a+`px`,this.element.style.height=(n.bottom-n.top)/o+`px`}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=n&&n.type.spec.disableDropCursor,i=typeof r==`function`?r(this.editorView,t,e):r;if(t&&!i){let e=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let t=vX(this.editorView.state.doc,e,this.editorView.dragging.slice);t!=null&&(e=t)}this.setCursor(e),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}},O3=class e extends NX{constructor(e){super(e,e)}map(t,n){let r=t.resolve(n.map(this.head));return e.valid(r)?new e(r):NX.near(r)}content(){return QJ.empty}eq(t){return t instanceof e&&t.head==this.head}toJSON(){return{type:`gapcursor`,pos:this.head}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for GapCursor.fromJSON`);return new e(t.resolve(n.pos))}getBookmark(){return new oFe(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!sFe(e)||!cFe(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(t,n,r=!1){search:for(;;){if(!r&&e.valid(t))return t;let i=t.pos,a=null;for(let r=t.depth;;r--){let o=t.node(r);if(n>0?t.indexAfter(r)0){a=o.child(n>0?t.indexAfter(r):t.index(r)-1);break}else if(r==0)return null;i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}for(;;){let o=n>0?a.firstChild:a.lastChild;if(!o){if(a.isAtom&&!a.isText&&!RX.isSelectable(a)){t=t.doc.resolve(i+a.nodeSize*n),r=!1;continue search}break}a=o,i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}return null}}};O3.prototype.visible=!1,O3.findFrom=O3.findGapCursorFrom,NX.jsonID(`gapcursor`,O3);var oFe=class e{constructor(e){this.pos=e}map(t){return new e(t.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return O3.valid(t)?new O3(t):NX.near(t)}};function k3(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}function sFe(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),r=e.node(t);if(n==0){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n-1);;e=e.lastChild){if(e.childCount==0&&!e.inlineContent||k3(e.type))return!0;if(e.inlineContent)return!1}}return!0}function cFe(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),r=e.node(t);if(n==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n);;e=e.firstChild){if(e.childCount==0&&!e.inlineContent||k3(e.type))return!0;if(e.inlineContent)return!1}}return!0}function lFe(){return new YX({props:{decorations:pFe,createSelectionBetween(e,t,n){return t.pos==n.pos&&O3.valid(n)?new O3(n):null},handleClick:dFe,handleKeyDown:uFe,handleDOMEvents:{beforeinput:fFe}}})}var uFe=m1({ArrowLeft:A3(`horiz`,-1),ArrowRight:A3(`horiz`,1),ArrowUp:A3(`vert`,-1),ArrowDown:A3(`vert`,1)});function A3(e,t){let n=e==`vert`?t>0?`down`:`up`:t>0?`right`:`left`;return function(e,r,i){let a=e.selection,o=t>0?a.$to:a.$from,s=a.empty;if(a instanceof IX){if(!i.endOfTextblock(n)||o.depth==0)return!1;s=!1,o=e.doc.resolve(t>0?o.after():o.before())}let c=O3.findGapCursorFrom(o,t,s);return c?(r&&r(e.tr.setSelection(new O3(c))),!0):!1}}function dFe(e,t,n){if(!e||!e.editable)return!1;let r=e.state.doc.resolve(t);if(!O3.valid(r))return!1;let i=e.posAtCoords({left:n.clientX,top:n.clientY});return i&&i.inside>-1&&RX.isSelectable(e.state.doc.nodeAt(i.inside))?!1:(e.dispatch(e.state.tr.setSelection(new O3(r))),!0)}function fFe(e,t){if(t.inputType!=`insertCompositionText`||!(e.state.selection instanceof O3))return!1;let{$from:n}=e.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!r)return!1;let i=KJ.empty;for(let e=r.length-1;e>=0;e--)i=KJ.from(r[e].createAndFill(null,i));let a=e.state.tr.replace(n.pos,n.pos,new QJ(i,0,0));return a.setSelection(IX.near(a.doc.resolve(n.pos+1))),e.dispatch(a),!1}function pFe(e){if(!(e.selection instanceof O3))return null;let t=document.createElement(`div`);return t.className=`ProseMirror-gapcursor`,B$.create(e.doc,[L$.widget(e.selection.head,t,{key:`gapcursor`})])}var j3=200,M3=function(){};M3.prototype.append=function(e){return e.length?(e=M3.from(e),!this.length&&e||e.length=t?M3.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},M3.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},M3.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},M3.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var r=[];return this.forEach(function(t,n){return r.push(e(t,n))},t,n),r},M3.from=function(e){return e instanceof M3?e:e&&e.length?new N3(e):M3.empty};var N3=function(e){function t(t){e.call(this),this.values=t}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(e,n){return e==0&&n==this.length?this:new t(this.values.slice(e,n))},t.prototype.getInner=function(e){return this.values[e]},t.prototype.forEachInner=function(e,t,n,r){for(var i=t;i=n;i--)if(e(this.values[i],r+i)===!1)return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=j3)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=j3)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(M3);M3.empty=new N3([]);var mFe=function(e){function t(t,n){e.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return ei&&this.right.forEachInner(e,Math.max(t-i,0),Math.min(this.length,n)-i,r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){var i=this.left.length;if(t>i&&this.right.forEachInvertedInner(e,t-i,Math.max(n,i)-i,r+i)===!1||n=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))},t.prototype.leafAppend=function(e){var n=this.right.leafAppend(e);if(n)return new t(this.left,n)},t.prototype.leafPrepend=function(e){var n=this.left.leafPrepend(e);if(n)return new t(n,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t}(M3),hFe=500,P3=class e{constructor(e,t){this.items=e,this.eventCount=t}popEvent(t,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,a;n&&(i=this.remapping(r,this.items.length),a=i.maps.length);let o=t.tr,s,c,l=[],u=[];return this.items.forEach((t,n)=>{if(!t.step){i||(i=this.remapping(r,n+1),a=i.maps.length),a--,u.push(t);return}if(i){u.push(new F3(t.map));let e=t.step.map(i.slice(a)),n;e&&o.maybeStep(e).doc&&(n=o.mapping.maps[o.mapping.maps.length-1],l.push(new F3(n,void 0,void 0,l.length+u.length))),a--,n&&i.appendMap(n,a)}else o.maybeStep(t.step);if(t.selection)return s=i?t.selection.map(i.slice(a)):t.selection,c=new e(this.items.slice(0,r).append(u.reverse().concat(l)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:o,selection:s}}addTransform(t,n,r,i){let a=[],o=this.eventCount,s=this.items,c=!i&&s.length?s.get(s.length-1):null;for(let e=0;e_Fe&&(s=gFe(s,l),o-=l),new e(s.append(a),o)}remapping(e,t){let n=new XY;return this.items.forEach((t,r)=>{let i=t.mirrorOffset!=null&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,i)},e,t),n}addMaps(t){return this.eventCount==0?this:new e(this.items.append(t.map(e=>new F3(e))),this.eventCount)}rebased(t,n){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-n),a=t.mapping,o=t.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},i);let c=n;this.items.forEach(e=>{let n=a.getMirror(--c);if(n==null)return;o=Math.min(o,n);let i=a.maps[n];if(e.step){let o=t.steps[n].invert(t.docs[n]),l=e.selection&&e.selection.map(a.slice(c+1,n));l&&s++,r.push(new F3(i,o,l))}else r.push(new F3(i))},i);let l=[];for(let e=n;ehFe&&(u=u.compress(this.items.length-r.length)),u}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(t=this.items.length){let n=this.remapping(0,t),r=n.maps.length,i=[],a=0;return this.items.forEach((e,o)=>{if(o>=t)i.push(e),e.selection&&a++;else if(e.step){let t=e.step.map(n.slice(r)),o=t&&t.getMap();if(r--,o&&n.appendMap(o,r),t){let s=e.selection&&e.selection.map(n.slice(r));s&&a++;let c=new F3(o.invert(),t,s),l,u=i.length-1;(l=i.length&&i[u].merge(c))?i[u]=l:i.push(c)}}else e.map&&r--},this.items.length,0),new e(M3.from(i.reverse()),a)}};P3.empty=new P3(M3.empty,0);function gFe(e,t){let n;return e.forEach((e,r)=>{if(e.selection&&t--==0)return n=r,!1}),e.slice(n)}var F3=class e{constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(t){if(this.step&&t.step&&!t.selection){let n=t.step.merge(this.step);if(n)return new e(n.getMap().invert(),n,this.selection)}}},I3=class{constructor(e,t,n,r,i){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r,this.prevComposition=i}},_Fe=20;function vFe(e,t,n,r){let i=n.getMeta(H3),a;if(i)return i.historyState;n.getMeta(xFe)&&(e=new I3(e.done,e.undone,null,0,-1));let o=n.getMeta(`appendedTransaction`);if(n.steps.length==0)return e;if(o&&o.getMeta(H3))return o.getMeta(H3).redo?new I3(e.done.addTransform(n,void 0,r,V3(t)),e.undone,L3(n.mapping.maps),e.prevTime,e.prevComposition):new I3(e.done,e.undone.addTransform(n,void 0,r,V3(t)),null,e.prevTime,e.prevComposition);if(n.getMeta(`addToHistory`)!==!1&&!(o&&o.getMeta(`addToHistory`)===!1)){let i=n.getMeta(`composition`),a=e.prevTime==0||!o&&e.prevComposition!=i&&(e.prevTime<(n.time||0)-r.newGroupDelay||!yFe(n,e.prevRanges)),s=o?R3(e.prevRanges,n.mapping):L3(n.mapping.maps);return new I3(e.done.addTransform(n,a?t.selection.getBookmark():void 0,r,V3(t)),P3.empty,s,n.time,i??e.prevComposition)}else if(a=n.getMeta(`rebased`))return new I3(e.done.rebased(n,a),e.undone.rebased(n,a),R3(e.prevRanges,n.mapping),e.prevTime,e.prevComposition);else return new I3(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),R3(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function yFe(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,r)=>{for(let i=0;i=t[i]&&(n=!0)}),n}function L3(e){let t=[];for(let n=e.length-1;n>=0&&t.length==0;n--)e[n].forEach((e,n,r,i)=>t.push(r,i));return t}function R3(e,t){if(!e)return null;let n=[];for(let r=0;r{let i=H3.getState(n);if(!i||(e?i.undone:i.done).eventCount==0)return!1;if(r){let a=bFe(i,n,e);a&&r(t?a.scrollIntoView():a)}return!0}}var W3=U3(!1,!0),G3=U3(!0,!0);E0.create({name:`characterCount`,addOptions(){return{limit:null,mode:`textSize`,textCounter:e=>e.length,wordCounter:e=>e.split(` `).filter(e=>e!==``).length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=e=>{let t=e?.node||this.editor.state.doc;if((e?.mode||this.options.mode)===`textSize`){let e=t.textBetween(0,t.content.size,void 0,` `);return this.options.textCounter(e)}return t.nodeSize},this.storage.words=e=>{let t=e?.node||this.editor.state.doc,n=t.textBetween(0,t.content.size,` `,` `);return this.options.wordCounter(n)}},addProseMirrorPlugins(){let e=!1;return[new YX({key:new QX(`characterCount`),appendTransaction:(t,n,r)=>{if(e)return;let i=this.options.limit;if(i==null||i===0){e=!0;return}let a=this.storage.characters({node:r.doc});if(a>i){let t=a-i;console.warn(`[CharacterCount] Initial content exceeded limit of ${i} characters. Content was automatically trimmed.`);let n=r.tr.deleteRange(0,t);return e=!0,n}e=!0},filterTransaction:(e,t)=>{let n=this.options.limit;if(!e.docChanged||n===0||n==null)return!0;let r=this.storage.characters({node:t.doc}),i=this.storage.characters({node:e.doc});if(i<=n||r>n&&i>n&&i<=r)return!0;if(r>n&&i>n&&i>r||!e.getMeta(`paste`))return!1;let a=e.selection.$head.pos,o=a-(i-n),s=a;return e.deleteRange(o,s),!(this.storage.characters({node:e.doc})>n)}})]}});var CFe=E0.create({name:`dropCursor`,addOptions(){return{color:`currentColor`,width:1,class:void 0}},addProseMirrorPlugins(){return[iFe(this.options)]}});E0.create({name:`focus`,addOptions(){return{className:`has-focus`,mode:`all`}},addProseMirrorPlugins(){return[new YX({key:new QX(`focus`),props:{decorations:({doc:e,selection:t})=>{let{isEditable:n,isFocused:r}=this.editor,{anchor:i}=t,a=[];if(!n||!r)return B$.create(e,[]);let o=0;this.options.mode===`deepest`&&e.descendants((e,t)=>{if(!e.isText){if(!(i>=t&&i<=t+e.nodeSize-1))return!1;o+=1}});let s=0;return e.descendants((e,t)=>{if(e.isText||!(i>=t&&i<=t+e.nodeSize-1))return!1;if(s+=1,this.options.mode===`deepest`&&o-s>0||this.options.mode===`shallowest`&&s>1)return this.options.mode===`deepest`;a.push(L$.node(t,t+e.nodeSize,{class:this.options.className}))}),B$.create(e,a)}}})]}});var wFe=E0.create({name:`gapCursor`,addProseMirrorPlugins(){return[lFe()]},extendNodeSchema(e){return{allowGapCursor:K1(H1(e,`allowGapCursor`,{name:e.name,options:e.options,storage:e.storage}))??null}}}),K3=`placeholder`;function TFe(e){return e.replace(/\s+/g,`-`).replace(/[^a-zA-Z0-9-]/g,``).replace(/^[0-9-]+/,``).replace(/^-+/,``).toLowerCase()}E0.create({name:`placeholder`,addOptions(){return{emptyEditorClass:`is-editor-empty`,emptyNodeClass:`is-empty`,dataAttribute:K3,placeholder:`Write something …`,showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){let e=this.options.dataAttribute?`data-${TFe(this.options.dataAttribute)}`:`data-${K3}`;return[new YX({key:new QX(`placeholder`),props:{decorations:({doc:t,selection:n})=>{let r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:i}=n,a=[];if(!r)return null;let o=this.editor.isEmpty;return t.descendants((t,n)=>{let r=i>=n&&i<=n+t.nodeSize,s=!t.isLeaf&&f0(t);if((r||!this.options.showOnlyCurrent)&&s){let i=[this.options.emptyNodeClass];o&&i.push(this.options.emptyEditorClass);let s=L$.node(n,n+t.nodeSize,{class:i.join(` `),[e]:typeof this.options.placeholder==`function`?this.options.placeholder({editor:this.editor,node:t,pos:n,hasAnchor:r}):this.options.placeholder});a.push(s)}return this.options.includeChildren}),B$.create(t,a)}}})]}}),E0.create({name:`selection`,addOptions(){return{className:`selection`}},addProseMirrorPlugins(){let{editor:e,options:t}=this;return[new YX({key:new QX(`selection`),props:{decorations(n){return n.selection.empty||e.isFocused||!e.isEditable||p0(n.selection)||e.view.dragging?null:B$.create(n.doc,[L$.inline(n.selection.from,n.selection.to,{class:t.className})])}}})]}});function q3({types:e,node:t}){return t&&Array.isArray(e)&&e.includes(t.type)||t?.type===e}var EFe=E0.create({name:`trailingNode`,addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){let e=new QX(this.name),t=this.options.node||this.editor.schema.topNodeType.contentMatch.defaultType?.name||`paragraph`,n=Object.entries(this.editor.schema.nodes).map(([,e])=>e).filter(e=>(this.options.notAfter||[]).concat(t).includes(e.name));return[new YX({key:e,appendTransaction:(n,r,i)=>{let{doc:a,tr:o,schema:s}=i,c=e.getState(i),l=a.content.size,u=s.nodes[t];if(c)return o.insert(l,u.create())},state:{init:(e,t)=>{let r=t.tr.doc.lastChild;return!q3({node:r,types:n})},apply:(e,t)=>{if(!e.docChanged||e.getMeta(`__uniqueIDTransaction`))return t;let r=e.doc.lastChild;return!q3({node:r,types:n})}}})]}}),DFe=E0.create({name:`undoRedo`,addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:e,dispatch:t})=>W3(e,t),redo:()=>({state:e,dispatch:t})=>G3(e,t)}},addProseMirrorPlugins(){return[SFe(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),OFe=E0.create({name:`starterKit`,addExtensions(){let e=[];return this.options.bold!==!1&&e.push($Ne.configure(this.options.bold)),this.options.blockquote!==!1&&e.push(JNe.configure(this.options.blockquote)),this.options.bulletList!==!1&&e.push(l3.configure(this.options.bulletList)),this.options.code!==!1&&e.push(nPe.configure(this.options.code)),this.options.codeBlock!==!1&&e.push(aPe.configure(this.options.codeBlock)),this.options.document!==!1&&e.push(oPe.configure(this.options.document)),this.options.dropcursor!==!1&&e.push(CFe.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&e.push(wFe.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&e.push(sPe.configure(this.options.hardBreak)),this.options.heading!==!1&&e.push(cPe.configure(this.options.heading)),this.options.undoRedo!==!1&&e.push(DFe.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&e.push(lPe.configure(this.options.horizontalRule)),this.options.italic!==!1&&e.push(mPe.configure(this.options.italic)),this.options.listItem!==!1&&e.push(u3.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(b3.configure(this.options?.listKeymap)),this.options.link!==!1&&e.push(o3.configure(this.options?.link)),this.options.orderedList!==!1&&e.push(T3.configure(this.options.orderedList)),this.options.paragraph!==!1&&e.push(QPe.configure(this.options.paragraph)),this.options.strike!==!1&&e.push(tFe.configure(this.options.strike)),this.options.text!==!1&&e.push(nFe.configure(this.options.text)),this.options.underline!==!1&&e.push(D3.configure(this.options?.underline)),this.options.trailingNode!==!1&&e.push(EFe.configure(this.options?.trailingNode)),e}}),kFe=E0.create({name:`textAlign`,addOptions(){return{types:[],alignments:[`left`,`center`,`right`,`justify`],defaultAlignment:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:e=>{let t=e.style.textAlign;return this.options.alignments.includes(t)?t:this.options.defaultAlignment},renderHTML:e=>e.textAlign?{style:`text-align: ${e.textAlign}`}:{}}}}]},addCommands(){return{setTextAlign:e=>({commands:t})=>this.options.alignments.includes(e)?this.options.types.map(n=>t.updateAttributes(n,{textAlign:e})).some(e=>e):!1,unsetTextAlign:()=>({commands:e})=>this.options.types.map(t=>e.resetAttributes(t,`textAlign`)).some(e=>e),toggleTextAlign:e=>({editor:t,commands:n})=>this.options.alignments.includes(e)?t.isActive({textAlign:e})?n.unsetTextAlign():n.setTextAlign(e):!1}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign(`left`),"Mod-Shift-e":()=>this.editor.commands.setTextAlign(`center`),"Mod-Shift-r":()=>this.editor.commands.setTextAlign(`right`),"Mod-Shift-j":()=>this.editor.commands.setTextAlign(`justify`)}}}),AFe=20,J3=(e,t=0)=>{let n=[];return!e.children.length||t>AFe||Array.from(e.children).forEach(e=>{e.tagName===`SPAN`?n.push(e):e.children.length&&n.push(...J3(e,t+1))}),n},jFe=e=>{if(!e.children.length)return;let t=J3(e);t&&t.forEach(e=>{let t=e.getAttribute(`style`),n=(e.parentElement?.closest(`span`))?.getAttribute(`style`);e.setAttribute(`style`,`${n};${t}`)})},Y3=C0.create({name:`textStyle`,priority:101,addOptions(){return{HTMLAttributes:{},mergeNestedSpanStyles:!0}},parseHTML(){return[{tag:`span`,consuming:!1,getAttrs:e=>e.hasAttribute(`style`)?(this.options.mergeNestedSpanStyles&&jFe(e),{}):!1}]},renderHTML({HTMLAttributes:e}){return[`span`,Y1(this.options.HTMLAttributes,e),0]},addCommands(){return{toggleTextStyle:e=>({commands:t})=>t.toggleMark(this.name,e),removeEmptyTextStyle:()=>({tr:e})=>{let{selection:t}=e;return e.doc.nodesBetween(t.from,t.to,(t,n)=>{if(t.isTextblock)return!0;t.marks.filter(e=>e.type===this.type).some(e=>Object.values(e.attrs).some(e=>!!e))||e.removeMark(n,n+t.nodeSize,this.type)}),!0}}}}),MFe=E0.create({name:`backgroundColor`,addOptions(){return{types:[`textStyle`]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{backgroundColor:{default:null,parseHTML:e=>{let t=e.getAttribute(`style`);if(t){let e=t.split(`;`).map(e=>e.trim()).filter(Boolean);for(let t=e.length-1;t>=0;--t){let n=e[t].split(`:`);if(n.length>=2){let e=n[0].trim().toLowerCase(),t=n.slice(1).join(`:`).trim();if(e===`background-color`)return t.replace(/['"]+/g,``)}}}return e.style.backgroundColor?.replace(/['"]+/g,``)},renderHTML:e=>e.backgroundColor?{style:`background-color: ${e.backgroundColor}`}:{}}}}]},addCommands(){return{setBackgroundColor:e=>({chain:t})=>t().setMark(`textStyle`,{backgroundColor:e}).run(),unsetBackgroundColor:()=>({chain:e})=>e().setMark(`textStyle`,{backgroundColor:null}).removeEmptyTextStyle().run()}}}),X3=E0.create({name:`color`,addOptions(){return{types:[`textStyle`]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{color:{default:null,parseHTML:e=>{let t=e.getAttribute(`style`);if(t){let e=t.split(`;`).map(e=>e.trim()).filter(Boolean);for(let t=e.length-1;t>=0;--t){let n=e[t].split(`:`);if(n.length>=2){let e=n[0].trim().toLowerCase(),t=n.slice(1).join(`:`).trim();if(e===`color`)return t.replace(/['"]+/g,``)}}}return e.style.color?.replace(/['"]+/g,``)},renderHTML:e=>e.color?{style:`color: ${e.color}`}:{}}}}]},addCommands(){return{setColor:e=>({chain:t})=>t().setMark(`textStyle`,{color:e}).run(),unsetColor:()=>({chain:e})=>e().setMark(`textStyle`,{color:null}).removeEmptyTextStyle().run()}}}),NFe=E0.create({name:`fontFamily`,addOptions(){return{types:[`textStyle`]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontFamily:{default:null,parseHTML:e=>e.style.fontFamily,renderHTML:e=>e.fontFamily?{style:`font-family: ${e.fontFamily}`}:{}}}}]},addCommands(){return{setFontFamily:e=>({chain:t})=>t().setMark(`textStyle`,{fontFamily:e}).run(),unsetFontFamily:()=>({chain:e})=>e().setMark(`textStyle`,{fontFamily:null}).removeEmptyTextStyle().run()}}}),PFe=E0.create({name:`fontSize`,addOptions(){return{types:[`textStyle`]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:e=>e.style.fontSize,renderHTML:e=>e.fontSize?{style:`font-size: ${e.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:e=>({chain:t})=>t().setMark(`textStyle`,{fontSize:e}).run(),unsetFontSize:()=>({chain:e})=>e().setMark(`textStyle`,{fontSize:null}).removeEmptyTextStyle().run()}}}),FFe=E0.create({name:`lineHeight`,addOptions(){return{types:[`textStyle`]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{lineHeight:{default:null,parseHTML:e=>e.style.lineHeight,renderHTML:e=>e.lineHeight?{style:`line-height: ${e.lineHeight}`}:{}}}}]},addCommands(){return{setLineHeight:e=>({chain:t})=>t().setMark(`textStyle`,{lineHeight:e}).run(),unsetLineHeight:()=>({chain:e})=>e().setMark(`textStyle`,{lineHeight:null}).removeEmptyTextStyle().run()}}});E0.create({name:`textStyleKit`,addExtensions(){let e=[];return this.options.backgroundColor!==!1&&e.push(MFe.configure(this.options.backgroundColor)),this.options.color!==!1&&e.push(X3.configure(this.options.color)),this.options.fontFamily!==!1&&e.push(NFe.configure(this.options.fontFamily)),this.options.fontSize!==!1&&e.push(PFe.configure(this.options.fontSize)),this.options.lineHeight!==!1&&e.push(FFe.configure(this.options.lineHeight)),this.options.textStyle!==!1&&e.push(Y3.configure(this.options.textStyle)),e}});var IFe=X3,LFe=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,RFe=K0.create({name:`image`,addOptions(){return{inline:!1,allowBase64:!1,HTMLAttributes:{},resize:!1}},inline(){return this.options.inline},group(){return this.options.inline?`inline`:`block`},draggable:!0,addAttributes(){return{src:{default:null},alt:{default:null},title:{default:null},width:{default:null},height:{default:null}}},parseHTML(){return[{tag:this.options.allowBase64?`img[src]`:`img[src]:not([src^="data:"])`}]},renderHTML({HTMLAttributes:e}){return[`img`,Y1(this.options.HTMLAttributes,e)]},parseMarkdown:(e,t)=>t.createNode(`image`,{src:e.href,title:e.title,alt:e.text}),renderMarkdown:e=>{let t=e.attrs?.src??``,n=e.attrs?.alt??``,r=e.attrs?.title??``;return r?`![${n}](${t} "${r}")`:`![${n}](${t})`},addNodeView(){if(!this.options.resize||!this.options.resize.enabled||typeof document>`u`)return null;let{directions:e,minWidth:t,minHeight:n,alwaysPreserveAspectRatio:r}=this.options.resize;return({node:i,getPos:a,HTMLAttributes:o,editor:s})=>{let c=document.createElement(`img`);Object.entries(o).forEach(([e,t])=>{if(t!=null)switch(e){case`width`:case`height`:break;default:c.setAttribute(e,t);break}}),c.src=o.src;let l=new BMe({element:c,editor:s,node:i,getPos:a,onResize:(e,t)=>{c.style.width=`${e}px`,c.style.height=`${t}px`},onCommit:(e,t)=>{let n=a();n!==void 0&&this.editor.chain().setNodeSelection(n).updateAttributes(this.name,{width:e,height:t}).run()},onUpdate:(e,t,n)=>e.type===i.type,options:{directions:e,min:{width:t,height:n},preserveAspectRatio:r===!0}}),u=l.dom;return u.style.visibility=`hidden`,u.style.pointerEvents=`none`,c.onload=()=>{u.style.visibility=``,u.style.pointerEvents=``},l}},addCommands(){return{setImage:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}},addInputRules(){return[z0({find:LFe,type:this.type,getAttributes:e=>{let[,,t,n,r]=e;return{src:n,alt:t,title:r}}})]}});function Z3({content:e,onChange:t,placeholder:n}){let{t:r}=G(),i=UNe({extensions:[OFe.configure({heading:!1,codeBlock:!1,code:!1}),rFe,zPe.configure({openOnClick:!1,HTMLAttributes:{target:`_blank`,rel:`noopener noreferrer`}}),kFe.configure({types:[`paragraph`]}),Y3,IFe,RFe.configure({HTMLAttributes:{style:`max-width: 100%; height: auto;`}})],content:e,onUpdate:({editor:e})=>{t(e.getHTML())},editorProps:{attributes:{class:`prose prose-invert prose-sm max-w-none focus:outline-none min-h-[120px] px-3 py-2`,placeholder:n||``}}});if(!i)return null;let a=({onClick:e,isActive:t=!1,children:n,title:r})=>(0,K.jsx)(`button`,{type:`button`,onClick:e,title:r,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary transition-colors ${t?`bg-bambu-dark-tertiary text-bambu-green`:`text-bambu-gray`}`,children:n});return(0,K.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden bg-bambu-dark`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5 p-1.5 border-b border-bambu-dark-tertiary bg-bambu-dark-secondary`,children:[(0,K.jsx)(a,{onClick:()=>i.chain().focus().toggleBold().run(),isActive:i.isActive(`bold`),title:r(`richTextEditor.bold`),children:(0,K.jsx)(Lo,{className:`w-4 h-4`})}),(0,K.jsx)(a,{onClick:()=>i.chain().focus().toggleItalic().run(),isActive:i.isActive(`italic`),title:r(`richTextEditor.italic`),children:(0,K.jsx)(Ac,{className:`w-4 h-4`})}),(0,K.jsx)(a,{onClick:()=>i.chain().focus().toggleUnderline().run(),isActive:i.isActive(`underline`),title:r(`richTextEditor.underline`),children:(0,K.jsx)(yu,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary mx-1`}),(0,K.jsx)(a,{onClick:()=>i.chain().focus().toggleBulletList().run(),isActive:i.isActive(`bulletList`),title:r(`richTextEditor.bulletList`),children:(0,K.jsx)(Bc,{className:`w-4 h-4`})}),(0,K.jsx)(a,{onClick:()=>i.chain().focus().toggleOrderedList().run(),isActive:i.isActive(`orderedList`),title:r(`richTextEditor.numberedList`),children:(0,K.jsx)(Rc,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary mx-1`}),(0,K.jsx)(a,{onClick:()=>i.chain().focus().setTextAlign(`left`).run(),isActive:i.isActive({textAlign:`left`}),title:r(`richTextEditor.alignLeft`),children:(0,K.jsx)(fu,{className:`w-4 h-4`})}),(0,K.jsx)(a,{onClick:()=>i.chain().focus().setTextAlign(`center`).run(),isActive:i.isActive({textAlign:`center`}),title:r(`richTextEditor.alignCenter`),children:(0,K.jsx)(uu,{className:`w-4 h-4`})}),(0,K.jsx)(a,{onClick:()=>i.chain().focus().setTextAlign(`right`).run(),isActive:i.isActive({textAlign:`right`}),title:r(`richTextEditor.alignRight`),children:(0,K.jsx)(du,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary mx-1`}),(0,K.jsx)(a,{onClick:()=>{let e=window.prompt(`Enter URL:`);e&&i.chain().focus().setLink({href:e}).run()},isActive:i.isActive(`link`),title:r(`richTextEditor.addLink`),children:(0,K.jsx)(Lc,{className:`w-4 h-4`})}),i.isActive(`link`)&&(0,K.jsx)(a,{onClick:()=>i.chain().focus().unsetLink().run(),title:r(`richTextEditor.removeLink`),children:(0,K.jsx)(xu,{className:`w-4 h-4`})})]}),(0,K.jsx)(o2,{editor:i})]})}function Q3({archiveId:e,archiveName:t,onClose:n}){let r=Qa(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)({}),{data:u,isLoading:d,error:f}=q({queryKey:[`archive-project-page`,e],queryFn:()=>Q.getArchiveProjectPage(e)}),p=J({mutationFn:t=>Q.updateArchiveProjectPage(e,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`archive-project-page`,e]}),a(!1),l({})}});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(o===null?i?_():n():s(null))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[o,i,n]);let m=[...u?.model_pictures||[],...u?.profile_pictures||[]],h=()=>{l({title:u?.title||``,description:u?.description||``,designer:u?.designer||``,license:u?.license||``,profile_title:u?.profile_title||``,profile_description:u?.profile_description||``}),a(!0)},g=()=>{p.mutate(c)},_=()=>{a(!1),l({})},v=e=>HJ.sanitize(e,{ALLOWED_TAGS:[`p`,`br`,`b`,`strong`,`i`,`em`,`u`,`a`,`ul`,`ol`,`li`,`figure`,`img`],ALLOWED_ATTR:[`href`,`src`,`target`,`rel`,`style`],ADD_ATTR:[`target`]}),b=u&&(u.title||u.description||u.designer||u.profile_title||m.length>0);return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:e=>{e.target===e.currentTarget&&n()},children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl max-w-4xl w-full max-h-[90vh] overflow-hidden 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`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(Zs,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[`Project Page`,t&&(0,K.jsxs)(`span`,{className:`text-bambu-gray ml-2`,children:[`- `,t]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!i&&b&&(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:h,children:[(0,K.jsx)(dl,{className:`w-4 h-4 mr-1`}),`Edit`]}),i&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:_,children:`Cancel`}),(0,K.jsxs)($,{variant:`primary`,size:`sm`,onClick:g,disabled:p.isPending,children:[(0,K.jsx)(Ol,{className:`w-4 h-4 mr-1`}),`Save`]})]}),(0,K.jsx)(`button`,{onClick:n,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5 text-bambu-gray`})})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:[d&&(0,K.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,K.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-2 border-bambu-green border-t-transparent`})}),f&&(0,K.jsx)(`div`,{className:`text-red-400 text-center py-12`,children:`Failed to load project page data`}),u&&!b&&(0,K.jsxs)(`div`,{className:`text-bambu-gray text-center py-12`,children:[(0,K.jsx)(Zs,{className:`w-12 h-12 mx-auto mb-4 opacity-50`}),(0,K.jsx)(`p`,{children:`No project page data found in this 3MF file.`}),(0,K.jsx)(`p`,{className:`text-sm mt-2`,children:`Project pages are typically included in files downloaded from MakerWorld.`})]}),u&&b&&(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{className:`space-y-4`,children:[i?(0,K.jsx)(`input`,{type:`text`,value:c.title||``,onChange:e=>l({...c,title:e.target.value}),placeholder:`Title`,className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-lg px-4 py-2 text-white text-xl font-semibold`}):u.title&&(0,K.jsx)(`h3`,{className:`text-xl font-semibold text-white`,children:u.title}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-4 text-sm`,children:[i?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Cu,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:c.designer||``,onChange:e=>l({...c,designer:e.target.value}),placeholder:`Designer`,className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-white`})]}):u.designer&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,K.jsx)(Cu,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:u.designer}),u.designer_user_id&&(0,K.jsx)(`a`,{href:`https://makerworld.com/en/@${u.designer_user_id}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline`,children:(0,K.jsx)(Us,{className:`w-3 h-3`})})]}),u.creation_date&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,K.jsx)(qo,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:u.creation_date})]}),i?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Zs,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:c.license||``,onChange:e=>l({...c,license:e.target.value}),placeholder:`License`,className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-white`})]}):u.license&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,K.jsx)(Zs,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:u.license})]}),u.origin&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark rounded text-bambu-gray`,children:u.origin})]})]}),(u.description||i)&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray uppercase tracking-wide`,children:`Description`}),i?(0,K.jsx)(Z3,{content:c.description||``,onChange:e=>l({...c,description:e}),placeholder:`Enter description...`}):(0,K.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none text-bambu-gray-light`,dangerouslySetInnerHTML:{__html:v(u.description||``)}})]}),(u.profile_title||u.profile_description||i)&&(0,K.jsxs)(`div`,{className:`space-y-2 p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray uppercase tracking-wide`,children:`Print Profile`}),i?(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:c.profile_title||``,onChange:e=>l({...c,profile_title:e.target.value}),placeholder:`Profile Title`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-white`}),(0,K.jsx)(Z3,{content:c.profile_description||``,onChange:e=>l({...c,profile_description:e}),placeholder:`Profile description...`})]}):(0,K.jsxs)(K.Fragment,{children:[u.profile_title&&(0,K.jsx)(`p`,{className:`text-white font-medium`,children:u.profile_title}),u.profile_description&&(0,K.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none text-bambu-gray-light`,dangerouslySetInnerHTML:{__html:v(u.profile_description)}}),u.profile_user_name&&(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`by `,u.profile_user_name]})]})]}),m.length>0&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`h4`,{className:`text-sm font-medium text-bambu-gray uppercase tracking-wide flex items-center gap-2`,children:[(0,K.jsx)(Dc,{className:`w-4 h-4`}),`Images (`,m.length,`)`]}),(0,K.jsx)(`div`,{className:`grid grid-cols-3 sm:grid-cols-4 md:grid-cols-5 gap-2`,children:m.map((e,t)=>(0,K.jsx)(`button`,{onClick:()=>s(t),className:`aspect-square rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,children:(0,K.jsx)(`img`,{src:e.url,alt:e.name,className:`w-full h-full object-cover`})},e.path))})]}),u.design_model_id&&(0,K.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`a`,{href:`https://makerworld.com/en/models/${u.design_model_id}`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-2 text-bambu-green hover:underline`,children:[(0,K.jsx)(Us,{className:`w-4 h-4`}),`View on MakerWorld`]})})]})]})]}),o!==null&&m[o]&&(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-60`,onClick:()=>s(null),children:[(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),s(Math.max(0,o-1))},disabled:o===0,className:`absolute left-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary disabled:opacity-30`,children:(0,K.jsx)(ns,{className:`w-6 h-6 text-white`})}),(0,K.jsx)(`img`,{src:m[o].url,alt:m[o].name,className:`max-w-[90vw] max-h-[90vh] object-contain`,onClick:e=>e.stopPropagation()}),(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),s(Math.min(m.length-1,o+1))},disabled:o===m.length-1,className:`absolute right-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary disabled:opacity-30`,children:(0,K.jsx)(ts,{className:`w-6 h-6 text-white`})}),(0,K.jsx)(`button`,{onClick:()=>s(null),className:`absolute top-4 right-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(Pu,{className:`w-6 h-6 text-white`})}),(0,K.jsxs)(`div`,{className:`absolute bottom-4 text-white text-sm`,children:[o+1,` / `,m.length]})]})]})}var zFe=[.25,.5,.75,1,1.5,2,3,4];function BFe({archiveId:e,timelapseSrc:t,onClose:n,onSave:r}){let{showToast:i}=xd(),a=(0,y.useRef)(null),o=(0,y.useRef)(null),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(0),[d,f]=(0,y.useState)(0),[p,m]=(0,y.useState)(0),[h,g]=(0,y.useState)(0),[_,v]=(0,y.useState)(1),[b,x]=(0,y.useState)(null),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(.8),[E,D]=(0,y.useState)(!1),{data:O,isLoading:k}=q({queryKey:[`timelapse-info`,e],queryFn:()=>Q.getTimelapseInfo(e)}),{data:A}=q({queryKey:[`timelapse-thumbnails`,e],queryFn:()=>Q.getTimelapseThumbnails(e,15)}),j=J({mutationFn:()=>Q.processTimelapse(e,{trimStart:p,trimEnd:h,speed:_,saveMode:`replace`},b||void 0),onSuccess:e=>{i(e.message,`success`),r?.(),n()},onError:e=>{i(e.message||`Processing failed`,`error`)}});(0,y.useEffect)(()=>{O?.duration&&h===0&&g(O.duration)},[O?.duration,h]),(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,y.useEffect)(()=>{let e=a.current;if(!e)return;let t=()=>{let t=e.currentTime;u(t),t>=h&&(e.currentTime=p)},n=()=>{f(e.duration),h===0&&g(e.duration)},r=()=>c(!0),i=()=>c(!1);return e.addEventListener(`timeupdate`,t),e.addEventListener(`durationchange`,n),e.addEventListener(`play`,r),e.addEventListener(`pause`,i),()=>{e.removeEventListener(`timeupdate`,t),e.removeEventListener(`durationchange`,n),e.removeEventListener(`play`,r),e.removeEventListener(`pause`,i)}},[p,h]),(0,y.useEffect)(()=>{let e=o.current,t=a.current;!e||!t||!S||(e.currentTime=t.currentTime,e.playbackRate=t.playbackRate,s&&!E?e.play().catch(()=>{}):e.pause())},[s,S,E]),(0,y.useEffect)(()=>{o.current&&(o.current.volume=E?0:w)},[w,E]),(0,y.useEffect)(()=>{a.current&&(a.current.playbackRate=_),o.current&&(o.current.playbackRate=_)},[_]);let M=(0,y.useCallback)(()=>{let e=a.current;e&&(s?e.pause():(e.currentTime{let t=a.current;t&&(t.currentTime=Math.max(p,Math.min(h,e)))},P=e=>{let t=e.target.files?.[0];t&&(S&&URL.revokeObjectURL(S),x(t),C(URL.createObjectURL(t)))},F=()=>{S&&URL.revokeObjectURL(S),x(null),C(null)};(0,y.useEffect)(()=>()=>{S&&URL.revokeObjectURL(S)},[S]);let I=h-p,L=I/_;return k?(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/80`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-white`,children:[(0,K.jsx)(X,{className:`w-6 h-6 animate-spin`}),`Loading video info...`]})}):(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/80`,children:(0,K.jsxs)(`div`,{className:`relative bg-bambu-dark-secondary rounded-xl max-w-5xl w-full mx-4 max-h-[90vh] overflow-hidden flex flex-col`,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)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)($s,{className:`w-5 h-5 text-bambu-green`}),`Edit Timelapse`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($,{variant:`primary`,size:`sm`,onClick:()=>j.mutate(),disabled:j.isPending,children:j.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)(Ol,{className:`w-4 h-4`}),`Save`]})}),(0,K.jsx)(`button`,{onClick:n,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5 text-bambu-gray`})})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`video`,{ref:a,src:t,className:`w-full rounded-lg bg-black`,onClick:M,muted:!!S}),!s&&(0,K.jsx)(`button`,{onClick:M,className:`absolute inset-0 flex items-center justify-center bg-black/30 hover:bg-black/40 transition-colors`,children:(0,K.jsx)(`div`,{className:`p-4 bg-bambu-green rounded-full`,children:(0,K.jsx)(hl,{className:`w-8 h-8 text-white`})})}),S&&(0,K.jsx)(`audio`,{ref:o,src:S,loop:!0})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(Ml,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:`Trim`}),(0,K.jsxs)(`span`,{className:`ml-auto`,children:[xf(p),` - `,xf(h),` (`,xf(I),`)`]})]}),(0,K.jsxs)(`div`,{className:`relative h-16 bg-bambu-dark rounded-lg overflow-hidden`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 flex`,children:A?.thumbnails.map((e,t)=>(0,K.jsx)(`div`,{className:`flex-1 bg-cover bg-center`,style:{backgroundImage:`url(data:image/jpeg;base64,${e})`}},t))}),(0,K.jsx)(`div`,{className:`absolute inset-y-0 left-0 bg-black/60`,style:{width:`${p/d*100}%`}}),(0,K.jsx)(`div`,{className:`absolute inset-y-0 right-0 bg-black/60`,style:{width:`${(d-h)/d*100}%`}}),(0,K.jsx)(`div`,{className:`absolute inset-y-0 border-2 border-bambu-green`,style:{left:`${p/d*100}%`,right:`${(d-h)/d*100}%`}}),(0,K.jsx)(`div`,{className:`absolute top-0 bottom-0 w-0.5 bg-white shadow-lg`,style:{left:`${l/d*100}%`}}),(0,K.jsx)(`input`,{type:`range`,min:0,max:d,step:.1,value:p,onChange:e=>{let t=parseFloat(e.target.value);t{let t=parseFloat(e.target.value);t>p+1&&g(t)},className:`absolute inset-0 w-full opacity-0 cursor-ew-resize`,style:{clipPath:`inset(0 0 0 50%)`}})]}),(0,K.jsx)(`input`,{type:`range`,min:0,max:d,step:.1,value:l,onChange:e=>N(parseFloat(e.target.value)),className:`w-full h-1 bg-bambu-dark-tertiary rounded-lg appearance-none cursor-pointer +`),[i,a]=KPe(r);if(i.length===0)return;let o=S3(i,0,n);if(o.length!==0)return{type:`list`,ordered:!0,start:i[0]?.number||1,items:o,raw:r.slice(0,a).join(` +`)}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleOrderedList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(JPe,this.editor.getAttributes(C3)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addInputRules(){let e=V0({find:w3,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1]});return(this.options.keepMarks||this.options.keepAttributes)&&(e=V0({find:w3,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(C3)}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1],editor:this.editor})),[e]}}),YPe=/^\s*(\[([( |x])?\])\s$/,XPe=K0.create({name:`taskItem`,addOptions(){return{nested:!1,HTMLAttributes:{},taskListTypeName:`taskList`,a11y:void 0}},content(){return this.options.nested?`paragraph block*`:`paragraph+`},defining:!0,addAttributes(){return{checked:{default:!1,keepOnSplit:!1,parseHTML:e=>{let t=e.getAttribute(`data-checked`);return t===``||t===`true`},renderHTML:e=>({"data-checked":e.checked})}}},parseHTML(){return[{tag:`li[data-type="${this.name}"]`,priority:51}]},renderHTML({node:e,HTMLAttributes:t}){return[`li`,Y1(this.options.HTMLAttributes,t,{"data-type":this.name}),[`label`,[`input`,{type:`checkbox`,checked:e.attrs.checked?`checked`:null}],[`span`]],[`div`,0]]},parseMarkdown:(e,t)=>{let n=[];if(e.tokens&&e.tokens.length>0?n.push(t.createNode(`paragraph`,{},t.parseInline(e.tokens))):e.text?n.push(t.createNode(`paragraph`,{},[t.createNode(`text`,{text:e.text})])):n.push(t.createNode(`paragraph`,{},[])),e.nestedTokens&&e.nestedTokens.length>0){let r=t.parseChildren(e.nestedTokens);n.push(...r)}return t.createNode(`taskItem`,{checked:e.checked||!1},n)},renderMarkdown:(e,t)=>G0(e,t,`- [${e.attrs?.checked?`x`:` `}] `),addKeyboardShortcuts(){let e={Enter:()=>this.editor.commands.splitListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)};return this.options.nested?{...e,Tab:()=>this.editor.commands.sinkListItem(this.name)}:e},addNodeView(){return({node:e,HTMLAttributes:t,getPos:n,editor:r})=>{let i=document.createElement(`li`),a=document.createElement(`label`),o=document.createElement(`span`),s=document.createElement(`input`),c=document.createElement(`div`),l=e=>{var t;s.ariaLabel=((t=this.options.a11y)?.checkboxLabel)?.call(t,e,s.checked)||`Task item checkbox for ${e.textContent||`empty task item`}`};l(e),a.contentEditable=`false`,s.type=`checkbox`,s.addEventListener(`mousedown`,e=>e.preventDefault()),s.addEventListener(`change`,t=>{if(!r.isEditable&&!this.options.onReadOnlyChecked){s.checked=!s.checked;return}let{checked:i}=t.target;r.isEditable&&typeof n==`function`&&r.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:e})=>{let t=n();if(typeof t!=`number`)return!1;let r=e.doc.nodeAt(t);return e.setNodeMarkup(t,void 0,{...r?.attrs,checked:i}),!0}).run(),!r.isEditable&&this.options.onReadOnlyChecked&&(this.options.onReadOnlyChecked(e,i)||(s.checked=!s.checked))}),Object.entries(this.options.HTMLAttributes).forEach(([e,t])=>{i.setAttribute(e,t)}),i.dataset.checked=e.attrs.checked,s.checked=e.attrs.checked,a.append(s,o),i.append(a,c),Object.entries(t).forEach(([e,t])=>{i.setAttribute(e,t)});let u=new Set(Object.keys(t));return{dom:i,contentDOM:c,update:e=>{if(e.type!==this.type)return!1;i.dataset.checked=e.attrs.checked,s.checked=e.attrs.checked,l(e);let t=r.extensionManager.attributes,n=X1(e,t),a=new Set(Object.keys(n)),o=this.options.HTMLAttributes;return u.forEach(e=>{a.has(e)||(e in o?i.setAttribute(e,o[e]):i.removeAttribute(e))}),Object.entries(n).forEach(([e,t])=>{t==null?e in o?i.setAttribute(e,o[e]):i.removeAttribute(e):i.setAttribute(e,t)}),u=a,!0}}}},addInputRules(){return[V0({find:YPe,type:this.type,getAttributes:e=>({checked:e[e.length-1]===`x`})})]}}),ZPe=K0.create({name:`taskList`,addOptions(){return{itemTypeName:`taskItem`,HTMLAttributes:{}}},group:`block list`,content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul[data-type="${this.name}"]`,priority:51}]},renderHTML({HTMLAttributes:e}){return[`ul`,Y1(this.options.HTMLAttributes,e,{"data-type":this.name}),0]},parseMarkdown:(e,t)=>t.createNode(`taskList`,{},t.parseChildren(e.items||[])),renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` +`):``,markdownTokenizer:{name:`taskList`,level:`block`,start(e){let t=e.match(/^\s*[-+*]\s+\[([ xX])\]\s+/)?.index;return t===void 0?-1:t},tokenize(e,t,n){let r=e=>{let t=W0(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);return t?[{type:`taskList`,raw:t.raw,items:t.items}]:n.blockTokens(e)},i=W0(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);if(i)return{type:`taskList`,raw:i.raw,items:i.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:e})=>e.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});E0.create({name:`listKit`,addExtensions(){let e=[];return this.options.bulletList!==!1&&e.push(l3.configure(this.options.bulletList)),this.options.listItem!==!1&&e.push(u3.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(b3.configure(this.options.listKeymap)),this.options.orderedList!==!1&&e.push(T3.configure(this.options.orderedList)),this.options.taskItem!==!1&&e.push(XPe.configure(this.options.taskItem)),this.options.taskList!==!1&&e.push(ZPe.configure(this.options.taskList)),e}});var E3=` `,QPe=`\xA0`,$Pe=K0.create({name:`paragraph`,priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:`block`,content:`inline*`,parseHTML(){return[{tag:`p`}]},renderHTML({HTMLAttributes:e}){return[`p`,Y1(this.options.HTMLAttributes,e),0]},parseMarkdown:(e,t)=>{let n=e.tokens||[];if(n.length===1&&n[0].type===`image`)return t.parseChildren([n[0]]);let r=t.parseInline(n);return r.length===1&&r[0].type===`text`&&(r[0].text===E3||r[0].text===QPe)?t.createNode(`paragraph`,void 0,[]):t.createNode(`paragraph`,void 0,r)},renderMarkdown:(e,t)=>{if(!e)return``;let n=Array.isArray(e.content)?e.content:[];return n.length===0?E3:t.renderChildren(n)},addCommands(){return{setParagraph:()=>({commands:e})=>e.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),eFe=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,tFe=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,nFe=C0.create({name:`strike`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`s`},{tag:`del`},{tag:`strike`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`line-through`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`s`,Y1(this.options.HTMLAttributes,e),0]},markdownTokenName:`del`,parseMarkdown:(e,t)=>t.applyMark(`strike`,t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>`~~${t.renderChildren(e)}~~`,addCommands(){return{setStrike:()=>({commands:e})=>e.setMark(this.name),toggleStrike:()=>({commands:e})=>e.toggleMark(this.name),unsetStrike:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[R0({find:eFe,type:this.type})]},addPasteRules(){return[q0({find:tFe,type:this.type})]}}),rFe=K0.create({name:`text`,group:`inline`,parseMarkdown:e=>({type:`text`,text:e.text||``}),renderMarkdown:e=>e.text||``}),D3=C0.create({name:`underline`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`u`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`underline`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`u`,Y1(this.options.HTMLAttributes,e),0]},parseMarkdown(e,t){return t.applyMark(this.name||`underline`,t.parseInline(e.tokens||[]))},renderMarkdown(e,t){return`++${t.renderChildren(e)}++`},markdownTokenizer:{name:`underline`,level:`inline`,start(e){return e.indexOf(`++`)},tokenize(e,t,n){let r=/^(\+\+)([\s\S]+?)(\+\+)/.exec(e);if(!r)return;let i=r[2].trim();return{type:`underline`,raw:r[0],text:i,tokens:n.inlineTokens(i)}}},addCommands(){return{setUnderline:()=>({commands:e})=>e.setMark(this.name),toggleUnderline:()=>({commands:e})=>e.toggleMark(this.name),unsetUnderline:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),iFe=D3;function aFe(e={}){return new YX({view(t){return new oFe(t,e)}})}var oFe=class{constructor(e,t){this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=t.width??1,this.color=t.color===!1?void 0:t.color||`black`,this.class=t.class,this.handlers=[`dragover`,`dragend`,`drop`,`dragleave`].map(t=>{let n=e=>{this[t](e)};return e.dom.addEventListener(t,n),{name:t,handler:n}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,n,r=this.editorView.dom,i=r.getBoundingClientRect(),a=i.width/r.offsetWidth,o=i.height/r.offsetHeight;if(t){let t=e.nodeBefore,r=e.nodeAfter;if(t||r){let e=this.editorView.nodeDOM(this.cursorPos-(t?t.nodeSize:0));if(e){let i=e.getBoundingClientRect(),a=t?i.bottom:i.top;t&&r&&(a=(a+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let s=this.width/2*o;n={left:i.left,right:i.right,top:a-s,bottom:a+s}}}}if(!n){let e=this.editorView.coordsAtPos(this.cursorPos),t=this.width/2*a;n={left:e.left-t,right:e.left+t,top:e.top,bottom:e.bottom}}let s=this.editorView.dom.offsetParent;this.element||(this.element=s.appendChild(document.createElement(`div`)),this.class&&(this.element.className=this.class),this.element.style.cssText=`position: absolute; z-index: 50; pointer-events: none;`,this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle(`prosemirror-dropcursor-block`,t),this.element.classList.toggle(`prosemirror-dropcursor-inline`,!t);let c,l;if(!s||s==document.body&&getComputedStyle(s).position==`static`)c=-pageXOffset,l=-pageYOffset;else{let e=s.getBoundingClientRect(),t=e.width/s.offsetWidth,n=e.height/s.offsetHeight;c=e.left-s.scrollLeft*t,l=e.top-s.scrollTop*n}this.element.style.left=(n.left-c)/a+`px`,this.element.style.top=(n.top-l)/o+`px`,this.element.style.width=(n.right-n.left)/a+`px`,this.element.style.height=(n.bottom-n.top)/o+`px`}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=n&&n.type.spec.disableDropCursor,i=typeof r==`function`?r(this.editorView,t,e):r;if(t&&!i){let e=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let t=vX(this.editorView.state.doc,e,this.editorView.dragging.slice);t!=null&&(e=t)}this.setCursor(e),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}},O3=class e extends NX{constructor(e){super(e,e)}map(t,n){let r=t.resolve(n.map(this.head));return e.valid(r)?new e(r):NX.near(r)}content(){return QJ.empty}eq(t){return t instanceof e&&t.head==this.head}toJSON(){return{type:`gapcursor`,pos:this.head}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for GapCursor.fromJSON`);return new e(t.resolve(n.pos))}getBookmark(){return new sFe(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!cFe(e)||!lFe(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(t,n,r=!1){search:for(;;){if(!r&&e.valid(t))return t;let i=t.pos,a=null;for(let r=t.depth;;r--){let o=t.node(r);if(n>0?t.indexAfter(r)0){a=o.child(n>0?t.indexAfter(r):t.index(r)-1);break}else if(r==0)return null;i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}for(;;){let o=n>0?a.firstChild:a.lastChild;if(!o){if(a.isAtom&&!a.isText&&!RX.isSelectable(a)){t=t.doc.resolve(i+a.nodeSize*n),r=!1;continue search}break}a=o,i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}return null}}};O3.prototype.visible=!1,O3.findFrom=O3.findGapCursorFrom,NX.jsonID(`gapcursor`,O3);var sFe=class e{constructor(e){this.pos=e}map(t){return new e(t.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return O3.valid(t)?new O3(t):NX.near(t)}};function k3(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}function cFe(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),r=e.node(t);if(n==0){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n-1);;e=e.lastChild){if(e.childCount==0&&!e.inlineContent||k3(e.type))return!0;if(e.inlineContent)return!1}}return!0}function lFe(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),r=e.node(t);if(n==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n);;e=e.firstChild){if(e.childCount==0&&!e.inlineContent||k3(e.type))return!0;if(e.inlineContent)return!1}}return!0}function uFe(){return new YX({props:{decorations:mFe,createSelectionBetween(e,t,n){return t.pos==n.pos&&O3.valid(n)?new O3(n):null},handleClick:fFe,handleKeyDown:dFe,handleDOMEvents:{beforeinput:pFe}}})}var dFe=m1({ArrowLeft:A3(`horiz`,-1),ArrowRight:A3(`horiz`,1),ArrowUp:A3(`vert`,-1),ArrowDown:A3(`vert`,1)});function A3(e,t){let n=e==`vert`?t>0?`down`:`up`:t>0?`right`:`left`;return function(e,r,i){let a=e.selection,o=t>0?a.$to:a.$from,s=a.empty;if(a instanceof IX){if(!i.endOfTextblock(n)||o.depth==0)return!1;s=!1,o=e.doc.resolve(t>0?o.after():o.before())}let c=O3.findGapCursorFrom(o,t,s);return c?(r&&r(e.tr.setSelection(new O3(c))),!0):!1}}function fFe(e,t,n){if(!e||!e.editable)return!1;let r=e.state.doc.resolve(t);if(!O3.valid(r))return!1;let i=e.posAtCoords({left:n.clientX,top:n.clientY});return i&&i.inside>-1&&RX.isSelectable(e.state.doc.nodeAt(i.inside))?!1:(e.dispatch(e.state.tr.setSelection(new O3(r))),!0)}function pFe(e,t){if(t.inputType!=`insertCompositionText`||!(e.state.selection instanceof O3))return!1;let{$from:n}=e.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!r)return!1;let i=KJ.empty;for(let e=r.length-1;e>=0;e--)i=KJ.from(r[e].createAndFill(null,i));let a=e.state.tr.replace(n.pos,n.pos,new QJ(i,0,0));return a.setSelection(IX.near(a.doc.resolve(n.pos+1))),e.dispatch(a),!1}function mFe(e){if(!(e.selection instanceof O3))return null;let t=document.createElement(`div`);return t.className=`ProseMirror-gapcursor`,B$.create(e.doc,[L$.widget(e.selection.head,t,{key:`gapcursor`})])}var j3=200,M3=function(){};M3.prototype.append=function(e){return e.length?(e=M3.from(e),!this.length&&e||e.length=t?M3.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},M3.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},M3.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},M3.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var r=[];return this.forEach(function(t,n){return r.push(e(t,n))},t,n),r},M3.from=function(e){return e instanceof M3?e:e&&e.length?new N3(e):M3.empty};var N3=function(e){function t(t){e.call(this),this.values=t}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(e,n){return e==0&&n==this.length?this:new t(this.values.slice(e,n))},t.prototype.getInner=function(e){return this.values[e]},t.prototype.forEachInner=function(e,t,n,r){for(var i=t;i=n;i--)if(e(this.values[i],r+i)===!1)return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=j3)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=j3)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(M3);M3.empty=new N3([]);var hFe=function(e){function t(t,n){e.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return ei&&this.right.forEachInner(e,Math.max(t-i,0),Math.min(this.length,n)-i,r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){var i=this.left.length;if(t>i&&this.right.forEachInvertedInner(e,t-i,Math.max(n,i)-i,r+i)===!1||n=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))},t.prototype.leafAppend=function(e){var n=this.right.leafAppend(e);if(n)return new t(this.left,n)},t.prototype.leafPrepend=function(e){var n=this.left.leafPrepend(e);if(n)return new t(n,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t}(M3),gFe=500,P3=class e{constructor(e,t){this.items=e,this.eventCount=t}popEvent(t,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,a;n&&(i=this.remapping(r,this.items.length),a=i.maps.length);let o=t.tr,s,c,l=[],u=[];return this.items.forEach((t,n)=>{if(!t.step){i||(i=this.remapping(r,n+1),a=i.maps.length),a--,u.push(t);return}if(i){u.push(new F3(t.map));let e=t.step.map(i.slice(a)),n;e&&o.maybeStep(e).doc&&(n=o.mapping.maps[o.mapping.maps.length-1],l.push(new F3(n,void 0,void 0,l.length+u.length))),a--,n&&i.appendMap(n,a)}else o.maybeStep(t.step);if(t.selection)return s=i?t.selection.map(i.slice(a)):t.selection,c=new e(this.items.slice(0,r).append(u.reverse().concat(l)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:o,selection:s}}addTransform(t,n,r,i){let a=[],o=this.eventCount,s=this.items,c=!i&&s.length?s.get(s.length-1):null;for(let e=0;evFe&&(s=_Fe(s,l),o-=l),new e(s.append(a),o)}remapping(e,t){let n=new XY;return this.items.forEach((t,r)=>{let i=t.mirrorOffset!=null&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,i)},e,t),n}addMaps(t){return this.eventCount==0?this:new e(this.items.append(t.map(e=>new F3(e))),this.eventCount)}rebased(t,n){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-n),a=t.mapping,o=t.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},i);let c=n;this.items.forEach(e=>{let n=a.getMirror(--c);if(n==null)return;o=Math.min(o,n);let i=a.maps[n];if(e.step){let o=t.steps[n].invert(t.docs[n]),l=e.selection&&e.selection.map(a.slice(c+1,n));l&&s++,r.push(new F3(i,o,l))}else r.push(new F3(i))},i);let l=[];for(let e=n;egFe&&(u=u.compress(this.items.length-r.length)),u}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(t=this.items.length){let n=this.remapping(0,t),r=n.maps.length,i=[],a=0;return this.items.forEach((e,o)=>{if(o>=t)i.push(e),e.selection&&a++;else if(e.step){let t=e.step.map(n.slice(r)),o=t&&t.getMap();if(r--,o&&n.appendMap(o,r),t){let s=e.selection&&e.selection.map(n.slice(r));s&&a++;let c=new F3(o.invert(),t,s),l,u=i.length-1;(l=i.length&&i[u].merge(c))?i[u]=l:i.push(c)}}else e.map&&r--},this.items.length,0),new e(M3.from(i.reverse()),a)}};P3.empty=new P3(M3.empty,0);function _Fe(e,t){let n;return e.forEach((e,r)=>{if(e.selection&&t--==0)return n=r,!1}),e.slice(n)}var F3=class e{constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(t){if(this.step&&t.step&&!t.selection){let n=t.step.merge(this.step);if(n)return new e(n.getMap().invert(),n,this.selection)}}},I3=class{constructor(e,t,n,r,i){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r,this.prevComposition=i}},vFe=20;function yFe(e,t,n,r){let i=n.getMeta(H3),a;if(i)return i.historyState;n.getMeta(SFe)&&(e=new I3(e.done,e.undone,null,0,-1));let o=n.getMeta(`appendedTransaction`);if(n.steps.length==0)return e;if(o&&o.getMeta(H3))return o.getMeta(H3).redo?new I3(e.done.addTransform(n,void 0,r,V3(t)),e.undone,L3(n.mapping.maps),e.prevTime,e.prevComposition):new I3(e.done,e.undone.addTransform(n,void 0,r,V3(t)),null,e.prevTime,e.prevComposition);if(n.getMeta(`addToHistory`)!==!1&&!(o&&o.getMeta(`addToHistory`)===!1)){let i=n.getMeta(`composition`),a=e.prevTime==0||!o&&e.prevComposition!=i&&(e.prevTime<(n.time||0)-r.newGroupDelay||!bFe(n,e.prevRanges)),s=o?R3(e.prevRanges,n.mapping):L3(n.mapping.maps);return new I3(e.done.addTransform(n,a?t.selection.getBookmark():void 0,r,V3(t)),P3.empty,s,n.time,i??e.prevComposition)}else if(a=n.getMeta(`rebased`))return new I3(e.done.rebased(n,a),e.undone.rebased(n,a),R3(e.prevRanges,n.mapping),e.prevTime,e.prevComposition);else return new I3(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),R3(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function bFe(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,r)=>{for(let i=0;i=t[i]&&(n=!0)}),n}function L3(e){let t=[];for(let n=e.length-1;n>=0&&t.length==0;n--)e[n].forEach((e,n,r,i)=>t.push(r,i));return t}function R3(e,t){if(!e)return null;let n=[];for(let r=0;r{let i=H3.getState(n);if(!i||(e?i.undone:i.done).eventCount==0)return!1;if(r){let a=xFe(i,n,e);a&&r(t?a.scrollIntoView():a)}return!0}}var W3=U3(!1,!0),G3=U3(!0,!0);E0.create({name:`characterCount`,addOptions(){return{limit:null,mode:`textSize`,textCounter:e=>e.length,wordCounter:e=>e.split(` `).filter(e=>e!==``).length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=e=>{let t=e?.node||this.editor.state.doc;if((e?.mode||this.options.mode)===`textSize`){let e=t.textBetween(0,t.content.size,void 0,` `);return this.options.textCounter(e)}return t.nodeSize},this.storage.words=e=>{let t=e?.node||this.editor.state.doc,n=t.textBetween(0,t.content.size,` `,` `);return this.options.wordCounter(n)}},addProseMirrorPlugins(){let e=!1;return[new YX({key:new QX(`characterCount`),appendTransaction:(t,n,r)=>{if(e)return;let i=this.options.limit;if(i==null||i===0){e=!0;return}let a=this.storage.characters({node:r.doc});if(a>i){let t=a-i;console.warn(`[CharacterCount] Initial content exceeded limit of ${i} characters. Content was automatically trimmed.`);let n=r.tr.deleteRange(0,t);return e=!0,n}e=!0},filterTransaction:(e,t)=>{let n=this.options.limit;if(!e.docChanged||n===0||n==null)return!0;let r=this.storage.characters({node:t.doc}),i=this.storage.characters({node:e.doc});if(i<=n||r>n&&i>n&&i<=r)return!0;if(r>n&&i>n&&i>r||!e.getMeta(`paste`))return!1;let a=e.selection.$head.pos,o=a-(i-n),s=a;return e.deleteRange(o,s),!(this.storage.characters({node:e.doc})>n)}})]}});var wFe=E0.create({name:`dropCursor`,addOptions(){return{color:`currentColor`,width:1,class:void 0}},addProseMirrorPlugins(){return[aFe(this.options)]}});E0.create({name:`focus`,addOptions(){return{className:`has-focus`,mode:`all`}},addProseMirrorPlugins(){return[new YX({key:new QX(`focus`),props:{decorations:({doc:e,selection:t})=>{let{isEditable:n,isFocused:r}=this.editor,{anchor:i}=t,a=[];if(!n||!r)return B$.create(e,[]);let o=0;this.options.mode===`deepest`&&e.descendants((e,t)=>{if(!e.isText){if(!(i>=t&&i<=t+e.nodeSize-1))return!1;o+=1}});let s=0;return e.descendants((e,t)=>{if(e.isText||!(i>=t&&i<=t+e.nodeSize-1))return!1;if(s+=1,this.options.mode===`deepest`&&o-s>0||this.options.mode===`shallowest`&&s>1)return this.options.mode===`deepest`;a.push(L$.node(t,t+e.nodeSize,{class:this.options.className}))}),B$.create(e,a)}}})]}});var TFe=E0.create({name:`gapCursor`,addProseMirrorPlugins(){return[uFe()]},extendNodeSchema(e){return{allowGapCursor:K1(H1(e,`allowGapCursor`,{name:e.name,options:e.options,storage:e.storage}))??null}}}),K3=`placeholder`;function EFe(e){return e.replace(/\s+/g,`-`).replace(/[^a-zA-Z0-9-]/g,``).replace(/^[0-9-]+/,``).replace(/^-+/,``).toLowerCase()}E0.create({name:`placeholder`,addOptions(){return{emptyEditorClass:`is-editor-empty`,emptyNodeClass:`is-empty`,dataAttribute:K3,placeholder:`Write something …`,showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){let e=this.options.dataAttribute?`data-${EFe(this.options.dataAttribute)}`:`data-${K3}`;return[new YX({key:new QX(`placeholder`),props:{decorations:({doc:t,selection:n})=>{let r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:i}=n,a=[];if(!r)return null;let o=this.editor.isEmpty;return t.descendants((t,n)=>{let r=i>=n&&i<=n+t.nodeSize,s=!t.isLeaf&&f0(t);if((r||!this.options.showOnlyCurrent)&&s){let i=[this.options.emptyNodeClass];o&&i.push(this.options.emptyEditorClass);let s=L$.node(n,n+t.nodeSize,{class:i.join(` `),[e]:typeof this.options.placeholder==`function`?this.options.placeholder({editor:this.editor,node:t,pos:n,hasAnchor:r}):this.options.placeholder});a.push(s)}return this.options.includeChildren}),B$.create(t,a)}}})]}}),E0.create({name:`selection`,addOptions(){return{className:`selection`}},addProseMirrorPlugins(){let{editor:e,options:t}=this;return[new YX({key:new QX(`selection`),props:{decorations(n){return n.selection.empty||e.isFocused||!e.isEditable||p0(n.selection)||e.view.dragging?null:B$.create(n.doc,[L$.inline(n.selection.from,n.selection.to,{class:t.className})])}}})]}});function q3({types:e,node:t}){return t&&Array.isArray(e)&&e.includes(t.type)||t?.type===e}var DFe=E0.create({name:`trailingNode`,addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){let e=new QX(this.name),t=this.options.node||this.editor.schema.topNodeType.contentMatch.defaultType?.name||`paragraph`,n=Object.entries(this.editor.schema.nodes).map(([,e])=>e).filter(e=>(this.options.notAfter||[]).concat(t).includes(e.name));return[new YX({key:e,appendTransaction:(n,r,i)=>{let{doc:a,tr:o,schema:s}=i,c=e.getState(i),l=a.content.size,u=s.nodes[t];if(c)return o.insert(l,u.create())},state:{init:(e,t)=>{let r=t.tr.doc.lastChild;return!q3({node:r,types:n})},apply:(e,t)=>{if(!e.docChanged||e.getMeta(`__uniqueIDTransaction`))return t;let r=e.doc.lastChild;return!q3({node:r,types:n})}}})]}}),OFe=E0.create({name:`undoRedo`,addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:e,dispatch:t})=>W3(e,t),redo:()=>({state:e,dispatch:t})=>G3(e,t)}},addProseMirrorPlugins(){return[CFe(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),kFe=E0.create({name:`starterKit`,addExtensions(){let e=[];return this.options.bold!==!1&&e.push(ePe.configure(this.options.bold)),this.options.blockquote!==!1&&e.push(YNe.configure(this.options.blockquote)),this.options.bulletList!==!1&&e.push(l3.configure(this.options.bulletList)),this.options.code!==!1&&e.push(rPe.configure(this.options.code)),this.options.codeBlock!==!1&&e.push(oPe.configure(this.options.codeBlock)),this.options.document!==!1&&e.push(sPe.configure(this.options.document)),this.options.dropcursor!==!1&&e.push(wFe.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&e.push(TFe.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&e.push(cPe.configure(this.options.hardBreak)),this.options.heading!==!1&&e.push(lPe.configure(this.options.heading)),this.options.undoRedo!==!1&&e.push(OFe.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&e.push(uPe.configure(this.options.horizontalRule)),this.options.italic!==!1&&e.push(hPe.configure(this.options.italic)),this.options.listItem!==!1&&e.push(u3.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(b3.configure(this.options?.listKeymap)),this.options.link!==!1&&e.push(o3.configure(this.options?.link)),this.options.orderedList!==!1&&e.push(T3.configure(this.options.orderedList)),this.options.paragraph!==!1&&e.push($Pe.configure(this.options.paragraph)),this.options.strike!==!1&&e.push(nFe.configure(this.options.strike)),this.options.text!==!1&&e.push(rFe.configure(this.options.text)),this.options.underline!==!1&&e.push(D3.configure(this.options?.underline)),this.options.trailingNode!==!1&&e.push(DFe.configure(this.options?.trailingNode)),e}}),AFe=E0.create({name:`textAlign`,addOptions(){return{types:[],alignments:[`left`,`center`,`right`,`justify`],defaultAlignment:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:e=>{let t=e.style.textAlign;return this.options.alignments.includes(t)?t:this.options.defaultAlignment},renderHTML:e=>e.textAlign?{style:`text-align: ${e.textAlign}`}:{}}}}]},addCommands(){return{setTextAlign:e=>({commands:t})=>this.options.alignments.includes(e)?this.options.types.map(n=>t.updateAttributes(n,{textAlign:e})).some(e=>e):!1,unsetTextAlign:()=>({commands:e})=>this.options.types.map(t=>e.resetAttributes(t,`textAlign`)).some(e=>e),toggleTextAlign:e=>({editor:t,commands:n})=>this.options.alignments.includes(e)?t.isActive({textAlign:e})?n.unsetTextAlign():n.setTextAlign(e):!1}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign(`left`),"Mod-Shift-e":()=>this.editor.commands.setTextAlign(`center`),"Mod-Shift-r":()=>this.editor.commands.setTextAlign(`right`),"Mod-Shift-j":()=>this.editor.commands.setTextAlign(`justify`)}}}),jFe=20,J3=(e,t=0)=>{let n=[];return!e.children.length||t>jFe||Array.from(e.children).forEach(e=>{e.tagName===`SPAN`?n.push(e):e.children.length&&n.push(...J3(e,t+1))}),n},MFe=e=>{if(!e.children.length)return;let t=J3(e);t&&t.forEach(e=>{let t=e.getAttribute(`style`),n=(e.parentElement?.closest(`span`))?.getAttribute(`style`);e.setAttribute(`style`,`${n};${t}`)})},Y3=C0.create({name:`textStyle`,priority:101,addOptions(){return{HTMLAttributes:{},mergeNestedSpanStyles:!0}},parseHTML(){return[{tag:`span`,consuming:!1,getAttrs:e=>e.hasAttribute(`style`)?(this.options.mergeNestedSpanStyles&&MFe(e),{}):!1}]},renderHTML({HTMLAttributes:e}){return[`span`,Y1(this.options.HTMLAttributes,e),0]},addCommands(){return{toggleTextStyle:e=>({commands:t})=>t.toggleMark(this.name,e),removeEmptyTextStyle:()=>({tr:e})=>{let{selection:t}=e;return e.doc.nodesBetween(t.from,t.to,(t,n)=>{if(t.isTextblock)return!0;t.marks.filter(e=>e.type===this.type).some(e=>Object.values(e.attrs).some(e=>!!e))||e.removeMark(n,n+t.nodeSize,this.type)}),!0}}}}),NFe=E0.create({name:`backgroundColor`,addOptions(){return{types:[`textStyle`]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{backgroundColor:{default:null,parseHTML:e=>{let t=e.getAttribute(`style`);if(t){let e=t.split(`;`).map(e=>e.trim()).filter(Boolean);for(let t=e.length-1;t>=0;--t){let n=e[t].split(`:`);if(n.length>=2){let e=n[0].trim().toLowerCase(),t=n.slice(1).join(`:`).trim();if(e===`background-color`)return t.replace(/['"]+/g,``)}}}return e.style.backgroundColor?.replace(/['"]+/g,``)},renderHTML:e=>e.backgroundColor?{style:`background-color: ${e.backgroundColor}`}:{}}}}]},addCommands(){return{setBackgroundColor:e=>({chain:t})=>t().setMark(`textStyle`,{backgroundColor:e}).run(),unsetBackgroundColor:()=>({chain:e})=>e().setMark(`textStyle`,{backgroundColor:null}).removeEmptyTextStyle().run()}}}),X3=E0.create({name:`color`,addOptions(){return{types:[`textStyle`]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{color:{default:null,parseHTML:e=>{let t=e.getAttribute(`style`);if(t){let e=t.split(`;`).map(e=>e.trim()).filter(Boolean);for(let t=e.length-1;t>=0;--t){let n=e[t].split(`:`);if(n.length>=2){let e=n[0].trim().toLowerCase(),t=n.slice(1).join(`:`).trim();if(e===`color`)return t.replace(/['"]+/g,``)}}}return e.style.color?.replace(/['"]+/g,``)},renderHTML:e=>e.color?{style:`color: ${e.color}`}:{}}}}]},addCommands(){return{setColor:e=>({chain:t})=>t().setMark(`textStyle`,{color:e}).run(),unsetColor:()=>({chain:e})=>e().setMark(`textStyle`,{color:null}).removeEmptyTextStyle().run()}}}),PFe=E0.create({name:`fontFamily`,addOptions(){return{types:[`textStyle`]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontFamily:{default:null,parseHTML:e=>e.style.fontFamily,renderHTML:e=>e.fontFamily?{style:`font-family: ${e.fontFamily}`}:{}}}}]},addCommands(){return{setFontFamily:e=>({chain:t})=>t().setMark(`textStyle`,{fontFamily:e}).run(),unsetFontFamily:()=>({chain:e})=>e().setMark(`textStyle`,{fontFamily:null}).removeEmptyTextStyle().run()}}}),FFe=E0.create({name:`fontSize`,addOptions(){return{types:[`textStyle`]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:e=>e.style.fontSize,renderHTML:e=>e.fontSize?{style:`font-size: ${e.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:e=>({chain:t})=>t().setMark(`textStyle`,{fontSize:e}).run(),unsetFontSize:()=>({chain:e})=>e().setMark(`textStyle`,{fontSize:null}).removeEmptyTextStyle().run()}}}),IFe=E0.create({name:`lineHeight`,addOptions(){return{types:[`textStyle`]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{lineHeight:{default:null,parseHTML:e=>e.style.lineHeight,renderHTML:e=>e.lineHeight?{style:`line-height: ${e.lineHeight}`}:{}}}}]},addCommands(){return{setLineHeight:e=>({chain:t})=>t().setMark(`textStyle`,{lineHeight:e}).run(),unsetLineHeight:()=>({chain:e})=>e().setMark(`textStyle`,{lineHeight:null}).removeEmptyTextStyle().run()}}});E0.create({name:`textStyleKit`,addExtensions(){let e=[];return this.options.backgroundColor!==!1&&e.push(NFe.configure(this.options.backgroundColor)),this.options.color!==!1&&e.push(X3.configure(this.options.color)),this.options.fontFamily!==!1&&e.push(PFe.configure(this.options.fontFamily)),this.options.fontSize!==!1&&e.push(FFe.configure(this.options.fontSize)),this.options.lineHeight!==!1&&e.push(IFe.configure(this.options.lineHeight)),this.options.textStyle!==!1&&e.push(Y3.configure(this.options.textStyle)),e}});var LFe=X3,RFe=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,zFe=K0.create({name:`image`,addOptions(){return{inline:!1,allowBase64:!1,HTMLAttributes:{},resize:!1}},inline(){return this.options.inline},group(){return this.options.inline?`inline`:`block`},draggable:!0,addAttributes(){return{src:{default:null},alt:{default:null},title:{default:null},width:{default:null},height:{default:null}}},parseHTML(){return[{tag:this.options.allowBase64?`img[src]`:`img[src]:not([src^="data:"])`}]},renderHTML({HTMLAttributes:e}){return[`img`,Y1(this.options.HTMLAttributes,e)]},parseMarkdown:(e,t)=>t.createNode(`image`,{src:e.href,title:e.title,alt:e.text}),renderMarkdown:e=>{let t=e.attrs?.src??``,n=e.attrs?.alt??``,r=e.attrs?.title??``;return r?`![${n}](${t} "${r}")`:`![${n}](${t})`},addNodeView(){if(!this.options.resize||!this.options.resize.enabled||typeof document>`u`)return null;let{directions:e,minWidth:t,minHeight:n,alwaysPreserveAspectRatio:r}=this.options.resize;return({node:i,getPos:a,HTMLAttributes:o,editor:s})=>{let c=document.createElement(`img`);Object.entries(o).forEach(([e,t])=>{if(t!=null)switch(e){case`width`:case`height`:break;default:c.setAttribute(e,t);break}}),c.src=o.src;let l=new VMe({element:c,editor:s,node:i,getPos:a,onResize:(e,t)=>{c.style.width=`${e}px`,c.style.height=`${t}px`},onCommit:(e,t)=>{let n=a();n!==void 0&&this.editor.chain().setNodeSelection(n).updateAttributes(this.name,{width:e,height:t}).run()},onUpdate:(e,t,n)=>e.type===i.type,options:{directions:e,min:{width:t,height:n},preserveAspectRatio:r===!0}}),u=l.dom;return u.style.visibility=`hidden`,u.style.pointerEvents=`none`,c.onload=()=>{u.style.visibility=``,u.style.pointerEvents=``},l}},addCommands(){return{setImage:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}},addInputRules(){return[z0({find:RFe,type:this.type,getAttributes:e=>{let[,,t,n,r]=e;return{src:n,alt:t,title:r}}})]}});function Z3({content:e,onChange:t,placeholder:n}){let{t:r}=G(),i=WNe({extensions:[kFe.configure({heading:!1,codeBlock:!1,code:!1}),iFe,BPe.configure({openOnClick:!1,HTMLAttributes:{target:`_blank`,rel:`noopener noreferrer`}}),AFe.configure({types:[`paragraph`]}),Y3,LFe,zFe.configure({HTMLAttributes:{style:`max-width: 100%; height: auto;`}})],content:e,onUpdate:({editor:e})=>{t(e.getHTML())},editorProps:{attributes:{class:`prose prose-invert prose-sm max-w-none focus:outline-none min-h-[120px] px-3 py-2`,placeholder:n||``}}});if(!i)return null;let a=({onClick:e,isActive:t=!1,children:n,title:r})=>(0,K.jsx)(`button`,{type:`button`,onClick:e,title:r,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary transition-colors ${t?`bg-bambu-dark-tertiary text-bambu-green`:`text-bambu-gray`}`,children:n});return(0,K.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden bg-bambu-dark`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5 p-1.5 border-b border-bambu-dark-tertiary bg-bambu-dark-secondary`,children:[(0,K.jsx)(a,{onClick:()=>i.chain().focus().toggleBold().run(),isActive:i.isActive(`bold`),title:r(`richTextEditor.bold`),children:(0,K.jsx)(Lo,{className:`w-4 h-4`})}),(0,K.jsx)(a,{onClick:()=>i.chain().focus().toggleItalic().run(),isActive:i.isActive(`italic`),title:r(`richTextEditor.italic`),children:(0,K.jsx)(Ac,{className:`w-4 h-4`})}),(0,K.jsx)(a,{onClick:()=>i.chain().focus().toggleUnderline().run(),isActive:i.isActive(`underline`),title:r(`richTextEditor.underline`),children:(0,K.jsx)(yu,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary mx-1`}),(0,K.jsx)(a,{onClick:()=>i.chain().focus().toggleBulletList().run(),isActive:i.isActive(`bulletList`),title:r(`richTextEditor.bulletList`),children:(0,K.jsx)(Bc,{className:`w-4 h-4`})}),(0,K.jsx)(a,{onClick:()=>i.chain().focus().toggleOrderedList().run(),isActive:i.isActive(`orderedList`),title:r(`richTextEditor.numberedList`),children:(0,K.jsx)(Rc,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary mx-1`}),(0,K.jsx)(a,{onClick:()=>i.chain().focus().setTextAlign(`left`).run(),isActive:i.isActive({textAlign:`left`}),title:r(`richTextEditor.alignLeft`),children:(0,K.jsx)(fu,{className:`w-4 h-4`})}),(0,K.jsx)(a,{onClick:()=>i.chain().focus().setTextAlign(`center`).run(),isActive:i.isActive({textAlign:`center`}),title:r(`richTextEditor.alignCenter`),children:(0,K.jsx)(uu,{className:`w-4 h-4`})}),(0,K.jsx)(a,{onClick:()=>i.chain().focus().setTextAlign(`right`).run(),isActive:i.isActive({textAlign:`right`}),title:r(`richTextEditor.alignRight`),children:(0,K.jsx)(du,{className:`w-4 h-4`})}),(0,K.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary mx-1`}),(0,K.jsx)(a,{onClick:()=>{let e=window.prompt(`Enter URL:`);e&&i.chain().focus().setLink({href:e}).run()},isActive:i.isActive(`link`),title:r(`richTextEditor.addLink`),children:(0,K.jsx)(Lc,{className:`w-4 h-4`})}),i.isActive(`link`)&&(0,K.jsx)(a,{onClick:()=>i.chain().focus().unsetLink().run(),title:r(`richTextEditor.removeLink`),children:(0,K.jsx)(xu,{className:`w-4 h-4`})})]}),(0,K.jsx)(o2,{editor:i})]})}function Q3({archiveId:e,archiveName:t,onClose:n}){let r=Qa(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)({}),{data:u,isLoading:d,error:f}=q({queryKey:[`archive-project-page`,e],queryFn:()=>Q.getArchiveProjectPage(e)}),p=J({mutationFn:t=>Q.updateArchiveProjectPage(e,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`archive-project-page`,e]}),a(!1),l({})}});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(o===null?i?_():n():s(null))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[o,i,n]);let m=[...u?.model_pictures||[],...u?.profile_pictures||[]],h=()=>{l({title:u?.title||``,description:u?.description||``,designer:u?.designer||``,license:u?.license||``,profile_title:u?.profile_title||``,profile_description:u?.profile_description||``}),a(!0)},g=()=>{p.mutate(c)},_=()=>{a(!1),l({})},v=e=>HJ.sanitize(e,{ALLOWED_TAGS:[`p`,`br`,`b`,`strong`,`i`,`em`,`u`,`a`,`ul`,`ol`,`li`,`figure`,`img`],ALLOWED_ATTR:[`href`,`src`,`target`,`rel`,`style`],ADD_ATTR:[`target`]}),b=u&&(u.title||u.description||u.designer||u.profile_title||m.length>0);return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:e=>{e.target===e.currentTarget&&n()},children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl max-w-4xl w-full max-h-[90vh] overflow-hidden 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`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(Zs,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[`Project Page`,t&&(0,K.jsxs)(`span`,{className:`text-bambu-gray ml-2`,children:[`- `,t]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!i&&b&&(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:h,children:[(0,K.jsx)(dl,{className:`w-4 h-4 mr-1`}),`Edit`]}),i&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:_,children:`Cancel`}),(0,K.jsxs)($,{variant:`primary`,size:`sm`,onClick:g,disabled:p.isPending,children:[(0,K.jsx)(Ol,{className:`w-4 h-4 mr-1`}),`Save`]})]}),(0,K.jsx)(`button`,{onClick:n,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5 text-bambu-gray`})})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:[d&&(0,K.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,K.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-2 border-bambu-green border-t-transparent`})}),f&&(0,K.jsx)(`div`,{className:`text-red-400 text-center py-12`,children:`Failed to load project page data`}),u&&!b&&(0,K.jsxs)(`div`,{className:`text-bambu-gray text-center py-12`,children:[(0,K.jsx)(Zs,{className:`w-12 h-12 mx-auto mb-4 opacity-50`}),(0,K.jsx)(`p`,{children:`No project page data found in this 3MF file.`}),(0,K.jsx)(`p`,{className:`text-sm mt-2`,children:`Project pages are typically included in files downloaded from MakerWorld.`})]}),u&&b&&(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{className:`space-y-4`,children:[i?(0,K.jsx)(`input`,{type:`text`,value:c.title||``,onChange:e=>l({...c,title:e.target.value}),placeholder:`Title`,className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-lg px-4 py-2 text-white text-xl font-semibold`}):u.title&&(0,K.jsx)(`h3`,{className:`text-xl font-semibold text-white`,children:u.title}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-4 text-sm`,children:[i?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Cu,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:c.designer||``,onChange:e=>l({...c,designer:e.target.value}),placeholder:`Designer`,className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-white`})]}):u.designer&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,K.jsx)(Cu,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:u.designer}),u.designer_user_id&&(0,K.jsx)(`a`,{href:`https://makerworld.com/en/@${u.designer_user_id}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline`,children:(0,K.jsx)(Us,{className:`w-3 h-3`})})]}),u.creation_date&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,K.jsx)(qo,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:u.creation_date})]}),i?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Zs,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:c.license||``,onChange:e=>l({...c,license:e.target.value}),placeholder:`License`,className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-white`})]}):u.license&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,K.jsx)(Zs,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:u.license})]}),u.origin&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark rounded text-bambu-gray`,children:u.origin})]})]}),(u.description||i)&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray uppercase tracking-wide`,children:`Description`}),i?(0,K.jsx)(Z3,{content:c.description||``,onChange:e=>l({...c,description:e}),placeholder:`Enter description...`}):(0,K.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none text-bambu-gray-light`,dangerouslySetInnerHTML:{__html:v(u.description||``)}})]}),(u.profile_title||u.profile_description||i)&&(0,K.jsxs)(`div`,{className:`space-y-2 p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray uppercase tracking-wide`,children:`Print Profile`}),i?(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:c.profile_title||``,onChange:e=>l({...c,profile_title:e.target.value}),placeholder:`Profile Title`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-white`}),(0,K.jsx)(Z3,{content:c.profile_description||``,onChange:e=>l({...c,profile_description:e}),placeholder:`Profile description...`})]}):(0,K.jsxs)(K.Fragment,{children:[u.profile_title&&(0,K.jsx)(`p`,{className:`text-white font-medium`,children:u.profile_title}),u.profile_description&&(0,K.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none text-bambu-gray-light`,dangerouslySetInnerHTML:{__html:v(u.profile_description)}}),u.profile_user_name&&(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`by `,u.profile_user_name]})]})]}),m.length>0&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`h4`,{className:`text-sm font-medium text-bambu-gray uppercase tracking-wide flex items-center gap-2`,children:[(0,K.jsx)(Dc,{className:`w-4 h-4`}),`Images (`,m.length,`)`]}),(0,K.jsx)(`div`,{className:`grid grid-cols-3 sm:grid-cols-4 md:grid-cols-5 gap-2`,children:m.map((e,t)=>(0,K.jsx)(`button`,{onClick:()=>s(t),className:`aspect-square rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,children:(0,K.jsx)(`img`,{src:e.url,alt:e.name,className:`w-full h-full object-cover`})},e.path))})]}),u.design_model_id&&(0,K.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`a`,{href:`https://makerworld.com/en/models/${u.design_model_id}`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-2 text-bambu-green hover:underline`,children:[(0,K.jsx)(Us,{className:`w-4 h-4`}),`View on MakerWorld`]})})]})]})]}),o!==null&&m[o]&&(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-60`,onClick:()=>s(null),children:[(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),s(Math.max(0,o-1))},disabled:o===0,className:`absolute left-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary disabled:opacity-30`,children:(0,K.jsx)(ns,{className:`w-6 h-6 text-white`})}),(0,K.jsx)(`img`,{src:m[o].url,alt:m[o].name,className:`max-w-[90vw] max-h-[90vh] object-contain`,onClick:e=>e.stopPropagation()}),(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),s(Math.min(m.length-1,o+1))},disabled:o===m.length-1,className:`absolute right-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary disabled:opacity-30`,children:(0,K.jsx)(ts,{className:`w-6 h-6 text-white`})}),(0,K.jsx)(`button`,{onClick:()=>s(null),className:`absolute top-4 right-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(Pu,{className:`w-6 h-6 text-white`})}),(0,K.jsxs)(`div`,{className:`absolute bottom-4 text-white text-sm`,children:[o+1,` / `,m.length]})]})]})}var BFe=[.25,.5,.75,1,1.5,2,3,4];function VFe({archiveId:e,timelapseSrc:t,onClose:n,onSave:r}){let{showToast:i}=xd(),a=(0,y.useRef)(null),o=(0,y.useRef)(null),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(0),[d,f]=(0,y.useState)(0),[p,m]=(0,y.useState)(0),[h,g]=(0,y.useState)(0),[_,v]=(0,y.useState)(1),[b,x]=(0,y.useState)(null),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(.8),[E,D]=(0,y.useState)(!1),{data:O,isLoading:k}=q({queryKey:[`timelapse-info`,e],queryFn:()=>Q.getTimelapseInfo(e)}),{data:A}=q({queryKey:[`timelapse-thumbnails`,e],queryFn:()=>Q.getTimelapseThumbnails(e,15)}),j=J({mutationFn:()=>Q.processTimelapse(e,{trimStart:p,trimEnd:h,speed:_,saveMode:`replace`},b||void 0),onSuccess:e=>{i(e.message,`success`),r?.(),n()},onError:e=>{i(e.message||`Processing failed`,`error`)}});(0,y.useEffect)(()=>{O?.duration&&h===0&&g(O.duration)},[O?.duration,h]),(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,y.useEffect)(()=>{let e=a.current;if(!e)return;let t=()=>{let t=e.currentTime;u(t),t>=h&&(e.currentTime=p)},n=()=>{f(e.duration),h===0&&g(e.duration)},r=()=>c(!0),i=()=>c(!1);return e.addEventListener(`timeupdate`,t),e.addEventListener(`durationchange`,n),e.addEventListener(`play`,r),e.addEventListener(`pause`,i),()=>{e.removeEventListener(`timeupdate`,t),e.removeEventListener(`durationchange`,n),e.removeEventListener(`play`,r),e.removeEventListener(`pause`,i)}},[p,h]),(0,y.useEffect)(()=>{let e=o.current,t=a.current;!e||!t||!S||(e.currentTime=t.currentTime,e.playbackRate=t.playbackRate,s&&!E?e.play().catch(()=>{}):e.pause())},[s,S,E]),(0,y.useEffect)(()=>{o.current&&(o.current.volume=E?0:w)},[w,E]),(0,y.useEffect)(()=>{a.current&&(a.current.playbackRate=_),o.current&&(o.current.playbackRate=_)},[_]);let M=(0,y.useCallback)(()=>{let e=a.current;e&&(s?e.pause():(e.currentTime{let t=a.current;t&&(t.currentTime=Math.max(p,Math.min(h,e)))},P=e=>{let t=e.target.files?.[0];t&&(S&&URL.revokeObjectURL(S),x(t),C(URL.createObjectURL(t)))},F=()=>{S&&URL.revokeObjectURL(S),x(null),C(null)};(0,y.useEffect)(()=>()=>{S&&URL.revokeObjectURL(S)},[S]);let I=h-p,L=I/_;return k?(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/80`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-white`,children:[(0,K.jsx)(X,{className:`w-6 h-6 animate-spin`}),`Loading video info...`]})}):(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/80`,children:(0,K.jsxs)(`div`,{className:`relative bg-bambu-dark-secondary rounded-xl max-w-5xl w-full mx-4 max-h-[90vh] overflow-hidden flex flex-col`,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)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)($s,{className:`w-5 h-5 text-bambu-green`}),`Edit Timelapse`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($,{variant:`primary`,size:`sm`,onClick:()=>j.mutate(),disabled:j.isPending,children:j.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)(Ol,{className:`w-4 h-4`}),`Save`]})}),(0,K.jsx)(`button`,{onClick:n,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5 text-bambu-gray`})})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`video`,{ref:a,src:t,className:`w-full rounded-lg bg-black`,onClick:M,muted:!!S}),!s&&(0,K.jsx)(`button`,{onClick:M,className:`absolute inset-0 flex items-center justify-center bg-black/30 hover:bg-black/40 transition-colors`,children:(0,K.jsx)(`div`,{className:`p-4 bg-bambu-green rounded-full`,children:(0,K.jsx)(hl,{className:`w-8 h-8 text-white`})})}),S&&(0,K.jsx)(`audio`,{ref:o,src:S,loop:!0})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(Ml,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:`Trim`}),(0,K.jsxs)(`span`,{className:`ml-auto`,children:[xf(p),` - `,xf(h),` (`,xf(I),`)`]})]}),(0,K.jsxs)(`div`,{className:`relative h-16 bg-bambu-dark rounded-lg overflow-hidden`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 flex`,children:A?.thumbnails.map((e,t)=>(0,K.jsx)(`div`,{className:`flex-1 bg-cover bg-center`,style:{backgroundImage:`url(data:image/jpeg;base64,${e})`}},t))}),(0,K.jsx)(`div`,{className:`absolute inset-y-0 left-0 bg-black/60`,style:{width:`${p/d*100}%`}}),(0,K.jsx)(`div`,{className:`absolute inset-y-0 right-0 bg-black/60`,style:{width:`${(d-h)/d*100}%`}}),(0,K.jsx)(`div`,{className:`absolute inset-y-0 border-2 border-bambu-green`,style:{left:`${p/d*100}%`,right:`${(d-h)/d*100}%`}}),(0,K.jsx)(`div`,{className:`absolute top-0 bottom-0 w-0.5 bg-white shadow-lg`,style:{left:`${l/d*100}%`}}),(0,K.jsx)(`input`,{type:`range`,min:0,max:d,step:.1,value:p,onChange:e=>{let t=parseFloat(e.target.value);t{let t=parseFloat(e.target.value);t>p+1&&g(t)},className:`absolute inset-0 w-full opacity-0 cursor-ew-resize`,style:{clipPath:`inset(0 0 0 50%)`}})]}),(0,K.jsx)(`input`,{type:`range`,min:0,max:d,step:.1,value:l,onChange:e=>N(parseFloat(e.target.value)),className:`w-full h-1 bg-bambu-dark-tertiary rounded-lg appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-3 [&::-webkit-slider-thumb]:h-3 [&::-webkit-slider-thumb]:bg-bambu-green [&::-webkit-slider-thumb]:rounded-full - [&::-webkit-slider-thumb]:cursor-pointer`}),(0,K.jsx)(`div`,{className:`flex items-center justify-center gap-2`,children:(0,K.jsx)(`button`,{onClick:M,className:`p-2 bg-bambu-green hover:bg-bambu-green-dark rounded-lg transition-colors`,children:s?(0,K.jsx)(ul,{className:`w-5 h-5 text-white`}):(0,K.jsx)(hl,{className:`w-5 h-5 text-white`})})})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(uc,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:`Speed`}),(0,K.jsxs)(`span`,{className:`ml-auto`,children:[_,`x (output: `,xf(L),`)`]})]}),(0,K.jsx)(`div`,{className:`flex gap-1`,children:zFe.map(e=>(0,K.jsxs)(`button`,{onClick:()=>v(e),className:`flex-1 px-2 py-2 text-sm rounded transition-colors ${_===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[e,`x`]},e))})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(al,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:`Music Overlay`})]}),b?(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(al,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:b.name}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[(b.size/1024/1024).toFixed(1),` MB`]})]}),(0,K.jsx)(`button`,{onClick:()=>D(!E),className:`p-2 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:E?(0,K.jsx)(Du,{className:`w-4 h-4 text-bambu-gray`}):(0,K.jsx)(Eu,{className:`w-4 h-4 text-bambu-green`})}),(0,K.jsx)(`input`,{type:`range`,min:0,max:1,step:.1,value:w,onChange:e=>T(parseFloat(e.target.value)),className:`w-20 h-1 bg-bambu-dark-tertiary rounded-lg appearance-none cursor-pointer + [&::-webkit-slider-thumb]:cursor-pointer`}),(0,K.jsx)(`div`,{className:`flex items-center justify-center gap-2`,children:(0,K.jsx)(`button`,{onClick:M,className:`p-2 bg-bambu-green hover:bg-bambu-green-dark rounded-lg transition-colors`,children:s?(0,K.jsx)(ul,{className:`w-5 h-5 text-white`}):(0,K.jsx)(hl,{className:`w-5 h-5 text-white`})})})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(uc,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:`Speed`}),(0,K.jsxs)(`span`,{className:`ml-auto`,children:[_,`x (output: `,xf(L),`)`]})]}),(0,K.jsx)(`div`,{className:`flex gap-1`,children:BFe.map(e=>(0,K.jsxs)(`button`,{onClick:()=>v(e),className:`flex-1 px-2 py-2 text-sm rounded transition-colors ${_===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[e,`x`]},e))})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(al,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:`Music Overlay`})]}),b?(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(al,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:b.name}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[(b.size/1024/1024).toFixed(1),` MB`]})]}),(0,K.jsx)(`button`,{onClick:()=>D(!E),className:`p-2 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:E?(0,K.jsx)(Du,{className:`w-4 h-4 text-bambu-gray`}):(0,K.jsx)(Eu,{className:`w-4 h-4 text-bambu-green`})}),(0,K.jsx)(`input`,{type:`range`,min:0,max:1,step:.1,value:w,onChange:e=>T(parseFloat(e.target.value)),className:`w-20 h-1 bg-bambu-dark-tertiary rounded-lg appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-3 [&::-webkit-slider-thumb]:h-3 - [&::-webkit-slider-thumb]:bg-bambu-green [&::-webkit-slider-thumb]:rounded-full`}),(0,K.jsx)(`button`,{onClick:F,className:`p-2 hover:bg-red-500/20 rounded transition-colors`,children:(0,K.jsx)(hu,{className:`w-4 h-4 text-red-400`})})]}):(0,K.jsxs)(`label`,{className:`flex flex-col items-center justify-center gap-2 p-6 border-2 border-dashed border-bambu-dark-tertiary rounded-lg cursor-pointer hover:border-bambu-green/50 transition-colors`,children:[(0,K.jsx)(Su,{className:`w-8 h-8 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`Drop audio file or click to upload`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:`MP3, WAV, M4A, AAC, OGG`}),(0,K.jsx)(`input`,{type:`file`,accept:`.mp3,.wav,.m4a,.aac,.ogg,audio/*`,onChange:P,className:`hidden`})]})]}),(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg text-sm space-y-1`,children:[(0,K.jsxs)(`p`,{className:`text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`text-white`,children:`Original:`}),` `,xf(d),` @ `,O?.width,`x`,O?.height]}),(0,K.jsxs)(`p`,{className:`text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`text-white`,children:`Output:`}),` `,xf(L),` @ `,_,`x speed`,b&&` + music overlay`]})]})]}),j.isPending&&(0,K.jsxs)(`div`,{className:`absolute inset-0 bg-black/80 flex flex-col items-center justify-center gap-4`,children:[(0,K.jsx)(X,{className:`w-12 h-12 text-bambu-green animate-spin`}),(0,K.jsx)(`p`,{className:`text-white text-lg`,children:`Processing timelapse...`}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:`This may take a few moments`})]})]})})}var VFe=[.25,.5,.75,1,1.5,2,3,4];function $3({src:e,title:t,downloadFilename:n,archiveId:r,onClose:i,onEdit:a}){let o=(0,y.useRef)(null),[s,c]=(0,y.useState)(!0),[l,u]=(0,y.useState)(1),[d,f]=(0,y.useState)(0),[p,m]=(0,y.useState)(0),[h,g]=(0,y.useState)(!1);(0,y.useEffect)(()=>{let e=o.current;e&&(e.playbackRate=l)},[l]),(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,y.useEffect)(()=>{let e=o.current;if(!e)return;let t=()=>f(e.currentTime),n=()=>m(e.duration),r=()=>c(!0),i=()=>c(!1);return e.addEventListener(`timeupdate`,t),e.addEventListener(`durationchange`,n),e.addEventListener(`play`,r),e.addEventListener(`pause`,i),()=>{e.removeEventListener(`timeupdate`,t),e.removeEventListener(`durationchange`,n),e.removeEventListener(`play`,r),e.removeEventListener(`pause`,i)}},[]);let _=()=>{let e=o.current;e&&(s?e.pause():e.play())};return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/80`,children:[(0,K.jsxs)(`div`,{className:`relative bg-bambu-dark-secondary rounded-xl max-w-4xl w-full mx-4 overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)($s,{className:`w-5 h-5 text-bambu-green`}),t]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>g(!0),children:[(0,K.jsx)(pl,{className:`w-4 h-4`}),`Edit`]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>{let t=document.createElement(`a`);t.href=e,t.download=n,t.click()},children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),`Download`]}),(0,K.jsx)(`button`,{onClick:i,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5 text-bambu-gray`})})]})]}),(0,K.jsxs)(`div`,{className:`p-4`,children:[(0,K.jsx)(`video`,{ref:o,src:e,autoPlay:!0,className:`w-full rounded-lg`,onClick:_}),(0,K.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray w-12 text-right`,children:xf(d)}),(0,K.jsx)(`input`,{type:`range`,min:0,max:p||100,value:d,onChange:e=>{let t=o.current;t&&(t.currentTime=parseFloat(e.target.value))},className:`flex-1 h-1 bg-bambu-dark-tertiary rounded-lg appearance-none cursor-pointer + [&::-webkit-slider-thumb]:bg-bambu-green [&::-webkit-slider-thumb]:rounded-full`}),(0,K.jsx)(`button`,{onClick:F,className:`p-2 hover:bg-red-500/20 rounded transition-colors`,children:(0,K.jsx)(hu,{className:`w-4 h-4 text-red-400`})})]}):(0,K.jsxs)(`label`,{className:`flex flex-col items-center justify-center gap-2 p-6 border-2 border-dashed border-bambu-dark-tertiary rounded-lg cursor-pointer hover:border-bambu-green/50 transition-colors`,children:[(0,K.jsx)(Su,{className:`w-8 h-8 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`Drop audio file or click to upload`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:`MP3, WAV, M4A, AAC, OGG`}),(0,K.jsx)(`input`,{type:`file`,accept:`.mp3,.wav,.m4a,.aac,.ogg,audio/*`,onChange:P,className:`hidden`})]})]}),(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg text-sm space-y-1`,children:[(0,K.jsxs)(`p`,{className:`text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`text-white`,children:`Original:`}),` `,xf(d),` @ `,O?.width,`x`,O?.height]}),(0,K.jsxs)(`p`,{className:`text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`text-white`,children:`Output:`}),` `,xf(L),` @ `,_,`x speed`,b&&` + music overlay`]})]})]}),j.isPending&&(0,K.jsxs)(`div`,{className:`absolute inset-0 bg-black/80 flex flex-col items-center justify-center gap-4`,children:[(0,K.jsx)(X,{className:`w-12 h-12 text-bambu-green animate-spin`}),(0,K.jsx)(`p`,{className:`text-white text-lg`,children:`Processing timelapse...`}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:`This may take a few moments`})]})]})})}var HFe=[.25,.5,.75,1,1.5,2,3,4];function $3({src:e,title:t,downloadFilename:n,archiveId:r,onClose:i,onEdit:a}){let o=(0,y.useRef)(null),[s,c]=(0,y.useState)(!0),[l,u]=(0,y.useState)(1),[d,f]=(0,y.useState)(0),[p,m]=(0,y.useState)(0),[h,g]=(0,y.useState)(!1);(0,y.useEffect)(()=>{let e=o.current;e&&(e.playbackRate=l)},[l]),(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,y.useEffect)(()=>{let e=o.current;if(!e)return;let t=()=>f(e.currentTime),n=()=>m(e.duration),r=()=>c(!0),i=()=>c(!1);return e.addEventListener(`timeupdate`,t),e.addEventListener(`durationchange`,n),e.addEventListener(`play`,r),e.addEventListener(`pause`,i),()=>{e.removeEventListener(`timeupdate`,t),e.removeEventListener(`durationchange`,n),e.removeEventListener(`play`,r),e.removeEventListener(`pause`,i)}},[]);let _=()=>{let e=o.current;e&&(s?e.pause():e.play())};return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/80`,children:[(0,K.jsxs)(`div`,{className:`relative bg-bambu-dark-secondary rounded-xl max-w-4xl w-full mx-4 overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)($s,{className:`w-5 h-5 text-bambu-green`}),t]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>g(!0),children:[(0,K.jsx)(pl,{className:`w-4 h-4`}),`Edit`]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>{let t=document.createElement(`a`);t.href=e,t.download=n,t.click()},children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),`Download`]}),(0,K.jsx)(`button`,{onClick:i,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5 text-bambu-gray`})})]})]}),(0,K.jsxs)(`div`,{className:`p-4`,children:[(0,K.jsx)(`video`,{ref:o,src:e,autoPlay:!0,className:`w-full rounded-lg`,onClick:_}),(0,K.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray w-12 text-right`,children:xf(d)}),(0,K.jsx)(`input`,{type:`range`,min:0,max:p||100,value:d,onChange:e=>{let t=o.current;t&&(t.currentTime=parseFloat(e.target.value))},className:`flex-1 h-1 bg-bambu-dark-tertiary rounded-lg appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-3 [&::-webkit-slider-thumb]:h-3 [&::-webkit-slider-thumb]:bg-bambu-green [&::-webkit-slider-thumb]:rounded-full - [&::-webkit-slider-thumb]:cursor-pointer`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray w-12`,children:xf(p)})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>{let e=o.current;e&&(e.currentTime=Math.max(0,e.currentTime-5))},className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:`Skip back 5s`,children:(0,K.jsx)(Gl,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:_,className:`p-2 bg-bambu-green hover:bg-bambu-green-dark rounded-lg transition-colors`,children:s?(0,K.jsx)(ul,{className:`w-5 h-5 text-white`}):(0,K.jsx)(hl,{className:`w-5 h-5 text-white`})}),(0,K.jsx)(`button`,{onClick:()=>{let e=o.current;e&&(e.currentTime=Math.min(p,e.currentTime+5))},className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:`Skip forward 5s`,children:(0,K.jsx)(Kl,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`Speed:`}),(0,K.jsx)(`div`,{className:`flex gap-1`,children:VFe.map(e=>(0,K.jsxs)(`button`,{onClick:()=>u(e),className:`px-2 py-1 text-xs rounded transition-colors ${l===e?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:bg-bambu-dark-tertiary/80`}`,children:[e,`x`]},e))})]})]})]})]})]}),h&&r&&(0,K.jsx)(BFe,{archiveId:r,timelapseSrc:e,onClose:()=>g(!1),onSave:a})]})}function HFe({archiveIds:e,onClose:t}){(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let{data:n,isLoading:r,error:i}=q({queryKey:[`archive-comparison`,e],queryFn:()=>Q.compareArchives(e)});return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg max-w-4xl w-full max-h-[90vh] flex flex-col border border-bambu-dark-tertiary`,onClick: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)(`h3`,{className:`text-lg font-semibold text-white`,children:[`Compare Archives (`,e.length,`)`]}),(0,K.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white p-1`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-auto p-4 bg-bambu-dark-secondary`,children:r?(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`})}):i?(0,K.jsxs)(`div`,{className:`text-center py-12 text-red-400`,children:[(0,K.jsx)(vu,{className:`w-12 h-12 mx-auto mb-4 opacity-50`}),(0,K.jsx)(`p`,{children:`Failed to load comparison`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:i instanceof Error?i.message:`Unknown error`})]}):n?(0,K.jsx)(UFe,{comparison:n}):null}),(0,K.jsx)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsx)($,{variant:`secondary`,onClick:t,className:`w-full`,children:`Close`})})]})})}function UFe({comparison:e}){return(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`text-left text-sm text-bambu-gray font-medium pb-2 pr-4 min-w-[150px]`,children:`Setting`}),e.archives.map(e=>(0,K.jsxs)(`th`,{className:`text-left text-sm font-medium pb-2 px-2 min-w-[120px]`,children:[(0,K.jsx)(`div`,{className:`text-white truncate max-w-[150px]`,title:e.print_name,children:e.print_name}),(0,K.jsx)(`div`,{className:`text-xs ${e.status===`completed`?`text-status-ok`:e.status===`failed`?`text-status-error`:`text-bambu-gray`}`,children:e.status})]},e.id))]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-bambu-gray/20`,children:e.comparison.map(e=>(0,K.jsxs)(`tr`,{className:e.has_difference?`bg-yellow-500/5`:``,children:[(0,K.jsx)(`td`,{className:`py-2 pr-4 text-sm`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.has_difference&&(0,K.jsx)(vu,{className:`w-3 h-3 text-yellow-400 flex-shrink-0`}),(0,K.jsx)(`span`,{className:e.has_difference?`text-yellow-400`:`text-bambu-gray`,children:e.label})]})}),e.values.map((t,n)=>(0,K.jsxs)(`td`,{className:`py-2 px-2 text-sm text-white`,children:[t??(0,K.jsx)(`span`,{className:`text-bambu-gray/50`,children:`-`}),e.unit&&t!==null&&(0,K.jsx)(`span`,{className:`text-bambu-gray ml-1`,children:e.unit})]},n))]},e.field))})]})}),e.differences.length>0&&(0,K.jsxs)(`div`,{className:`p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg`,children:[(0,K.jsxs)(`h4`,{className:`text-sm font-medium text-yellow-400 mb-2 flex items-center gap-2`,children:[(0,K.jsx)(vu,{className:`w-4 h-4`}),e.differences.length,` Difference`,e.differences.length>1?`s`:``,` Found`]}),(0,K.jsxs)(`ul`,{className:`text-sm text-white/80 space-y-1`,children:[e.differences.slice(0,5).map(e=>(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`span`,{className:`text-yellow-400`,children:e.label}),`: `,e.values.join(` vs `),` `,e.unit||``]},e.field)),e.differences.length>5&&(0,K.jsxs)(`li`,{className:`text-bambu-gray`,children:[`...and `,e.differences.length-5,` more`]})]})]}),e.success_correlation.has_both_outcomes?(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`h4`,{className:`text-sm font-medium text-white mb-3 flex items-center gap-2`,children:[(0,K.jsx)($o,{className:`w-4 h-4 text-bambu-green`}),`Success/Failure Analysis`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm mb-3`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-green`,children:[e.success_correlation.successful_count,` successful`]}),(0,K.jsxs)(`span`,{className:`text-red-400`,children:[e.success_correlation.failed_count,` failed`]})]}),e.success_correlation.insights&&e.success_correlation.insights.length>0?(0,K.jsx)(`div`,{className:`space-y-2`,children:e.success_correlation.insights.map(e=>(0,K.jsxs)(`div`,{className:`text-sm p-2 bg-bambu-dark-secondary rounded`,children:[(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[e.label,`:`]}),` `,(0,K.jsx)(`span`,{className:`text-white/80`,children:e.insight})]},e.field))}):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`No clear correlations found between settings and outcomes.`})]}):(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-lg text-sm text-bambu-gray`,children:(0,K.jsx)(`p`,{children:e.success_correlation.message||`Need both successful and failed prints for correlation analysis.`})})]})}function WFe(e){let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`Just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function GFe({upload:e,projects:t,onArchive:n,onDiscard:r,isArchiving:i,isDiscarding:a}){let[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(e.tags||``),[u,d]=(0,y.useState)(e.notes||``),[f,p]=(0,y.useState)(e.project_id),[m,h]=(0,y.useState)(!1);return(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`py-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(qs,{className:`w-8 h-8 text-bambu-green flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,title:e.filename,children:e.display_name||e.filename}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:yd(e.file_size)}),(0,K.jsx)(`span`,{children:`·`}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),WFe(e.uploaded_at)]}),e.source_ip&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{children:`·`}),(0,K.jsxs)(`span`,{children:[`from `,e.source_ip]})]})]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>s(!o),className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:o?(0,K.jsx)(rs,{className:`w-5 h-5`}):(0,K.jsx)(es,{className:`w-5 h-5`})}),(0,K.jsx)($,{variant:`primary`,size:`sm`,onClick:()=>n(e.id,{tags:c,notes:u,project_id:f||void 0}),disabled:i,children:i?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(wo,{className:`w-4 h-4`}),`Archive`]})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>h(!0),disabled:a,children:a?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hu,{className:`w-4 h-4 text-red-400`})})]})]}),m&&(0,K.jsx)(Ed,{title:`Discard Upload`,message:`Are you sure you want to discard "${e.filename}"? This cannot be undone.`,confirmText:`Discard`,variant:`danger`,onConfirm:()=>{r(e.id),h(!1)},onCancel:()=>h(!1)}),o&&(0,K.jsxs)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Tags`}),(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`e.g., functional, prototype, gift`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white placeholder-bambu-gray text-sm`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Notes`}),(0,K.jsx)(`textarea`,{value:u,onChange:e=>d(e.target.value),placeholder:`Add notes about this print...`,rows:2,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white placeholder-bambu-gray text-sm resize-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Project`}),(0,K.jsxs)(`select`,{value:f||``,onChange:e=>p(e.target.value?Number(e.target.value):null),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm`,children:[(0,K.jsx)(`option`,{value:``,children:`No project`}),t.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]})]})})}function KFe(){let e=Qa(),{showToast:t}=xd(),[n,r]=(0,y.useState)(!1),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(new Set),[c,l]=(0,y.useState)(new Set),{data:u,isLoading:d}=q({queryKey:[`pending-uploads`],queryFn:$u.list,refetchInterval:1e4}),{data:f}=q({queryKey:[`projects`],queryFn:()=>Q.getProjects(),select:e=>[...e].sort((e,t)=>e.name.localeCompare(t.name))}),p=J({mutationFn:({id:e,data:t})=>$u.archive(e,t),onMutate:({id:e})=>{s(t=>new Set(t).add(e))},onSettled:(e,t,{id:n})=>{s(e=>{let t=new Set(e);return t.delete(n),t})},onSuccess:n=>{e.invalidateQueries({queryKey:[`pending-uploads`]}),e.invalidateQueries({queryKey:[`archives`]}),t(`Archived: ${n.print_name}`)},onError:e=>{t(e.message||`Failed to archive`,`error`)}}),m=J({mutationFn:e=>$u.discard(e),onMutate:e=>{l(t=>new Set(t).add(e))},onSettled:(e,t,n)=>{l(e=>{let t=new Set(e);return t.delete(n),t})},onSuccess:()=>{e.invalidateQueries({queryKey:[`pending-uploads`]}),t(`Upload discarded`)},onError:e=>{t(e.message||`Failed to discard`,`error`)}}),h=J({mutationFn:$u.archiveAll,onSuccess:n=>{e.invalidateQueries({queryKey:[`pending-uploads`]}),e.invalidateQueries({queryKey:[`archives`]}),t(`Archived ${n.archived} files${n.failed>0?`, ${n.failed} failed`:``}`)},onError:e=>{t(e.message||`Failed to archive all`,`error`)}}),g=J({mutationFn:$u.discardAll,onSuccess:n=>{e.invalidateQueries({queryKey:[`pending-uploads`]}),t(`Discarded ${n.discarded} files`)},onError:e=>{t(e.message||`Failed to discard all`,`error`)}});return d?(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-8 flex justify-center`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})})}):!u||u.length===0?null:(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(pd,{className:`border-l-4 border-l-yellow-500`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Su,{className:`w-5 h-5 text-yellow-500`}),(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[`Pending Uploads (`,u.length,`)`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($,{variant:`primary`,size:`sm`,onClick:()=>r(!0),disabled:h.isPending,children:h.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(wo,{className:`w-4 h-4`}),`Archive All`]})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>a(!0),disabled:g.isPending,children:g.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),`Discard All`]})})]})]})}),(0,K.jsxs)(hd,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:`These files were uploaded via the virtual printer. Review and archive them to add to your collection.`}),(0,K.jsx)(`div`,{className:`space-y-3`,children:u.map(e=>(0,K.jsx)(GFe,{upload:e,projects:f||[],onArchive:(e,t)=>p.mutate({id:e,data:t}),onDiscard:e=>m.mutate(e),isArchiving:o.has(e.id),isDiscarding:c.has(e.id)},e.id))})]})]}),n&&(0,K.jsx)(Ed,{title:`Archive All Uploads`,message:`Are you sure you want to archive all ${u.length} pending uploads?`,confirmText:`Archive All`,onConfirm:()=>{h.mutate(),r(!1)},onCancel:()=>r(!1)}),i&&(0,K.jsx)(Ed,{title:`Discard All Uploads`,message:`Are you sure you want to discard all ${u.length} pending uploads? This cannot be undone.`,confirmText:`Discard All`,variant:`danger`,onConfirm:()=>{g.mutate(),a(!1)},onCancel:()=>a(!1)})]})}function qFe({onClose:e}){let t=Qa(),{showToast:n}=xd(),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(`count`);(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&(a?o(null):l?u(null):e())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,a,l]);let{data:p,isLoading:m}=q({queryKey:[`tags`],queryFn:Q.getTags}),h=J({mutationFn:({oldName:e,newName:t})=>Q.renameTag(e,t),onSuccess:(e,{oldName:r,newName:i})=>{t.invalidateQueries({queryKey:[`tags`]}),t.invalidateQueries({queryKey:[`archives`]}),n(`Renamed "${r}" to "${i}" in ${e.affected} archive${e.affected===1?``:`s`}`),o(null)},onError:e=>{n(e.message||`Failed to rename tag`,`error`)}}),g=J({mutationFn:e=>Q.deleteTag(e),onSuccess:(e,r)=>{t.invalidateQueries({queryKey:[`tags`]}),t.invalidateQueries({queryKey:[`archives`]}),n(`Deleted "${r}" from ${e.affected} archive${e.affected===1?``:`s`}`),u(null)},onError:e=>{n(e.message||`Failed to delete tag`,`error`)}}),_=e=>{o(e.name),c(e.name),u(null)},v=()=>{o(null),c(``)},b=()=>{if(!a||!s.trim())return;let e=s.trim();if(e===a){v();return}h.mutate({oldName:a,newName:e})},x=e=>{e.key===`Enter`?(e.preventDefault(),b()):e.key===`Escape`&&(e.preventDefault(),v())},S=e=>{u(e),o(null)},C=()=>{l&&g.mutate(l)},w=p?.filter(e=>e.name.toLowerCase().includes(r.toLowerCase())).sort((e,t)=>d===`count`&&t.count-e.count||e.name.localeCompare(t.name)),T=p?.reduce((e,t)=>e+t.count,0)||0;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)(pd,{className:`w-full max-w-lg max-h-[80vh] flex flex-col`,children:(0,K.jsxs)(hd,{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 flex-shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(su,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:`Manage Tags`})]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,placeholder:`Search tags...`,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:r,onChange:e=>i(e.target.value)})]}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:d,onChange:e=>f(e.target.value),children:[(0,K.jsx)(`option`,{value:`count`,children:`Sort by Count`}),(0,K.jsx)(`option`,{value:`name`,children:`Sort by Name`})]})]}),p&&(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:[p.length,` tag`,p.length===1?``:`s`,` across `,T,` usage`,T===1?``:`s`]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto min-h-0 p-4`,children:m?(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`})}):w?.length?(0,K.jsx)(`div`,{className:`space-y-2`,children:w.map(e=>(0,K.jsx)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors group`,children:a===e.name?(0,K.jsxs)(`div`,{className:`flex-1 flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,className:`flex-1 px-2 py-1 bg-bambu-dark-tertiary border border-bambu-green rounded text-white text-sm focus:outline-none`,value:s,onChange:e=>c(e.target.value),onKeyDown:x,autoFocus:!0}),(0,K.jsx)($,{size:`sm`,variant:`primary`,onClick:b,disabled:!s.trim()||h.isPending,className:`p-1.5`,children:h.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)($o,{className:`w-4 h-4`})}),(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:v,className:`p-1.5`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}):l===e.name?(0,K.jsxs)(`div`,{className:`flex-1 flex items-center gap-2`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-yellow-400 flex-shrink-0`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray-light flex-1`,children:[`Delete "`,e.name,`" from `,e.count,` archive`,e.count===1?``:`s`,`?`]}),(0,K.jsx)($,{size:`sm`,variant:`danger`,onClick:C,disabled:g.isPending,className:`p-1.5`,children:g.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hu,{className:`w-4 h-4`})}),(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>u(null),className:`p-1.5`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(su,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-white flex-1 truncate`,children:e.name}),(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray text-xs`,children:e.count}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,K.jsx)(`button`,{onClick:()=>_(e),className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors`,title:`Rename tag`,children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>S(e.name),className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors`,title:`Delete tag`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]})},e.name))}):(0,K.jsx)(`div`,{className:`text-center py-8 text-bambu-gray`,children:r?`No tags match your search`:`No tags found`})}),(0,K.jsx)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:(0,K.jsx)($,{variant:`secondary`,onClick:e,className:`flex-1`,children:`Close`})})]})})})}function e6(e){let t=e.filename;if(t){let e=t.toLowerCase();if(e.endsWith(`.gcode`)||e.includes(`.gcode.`))return!0}return!!(e.total_layers||e.print_time_seconds)}async function t6(e,t,n,r){try{if(n===`source`){let{token:n}=await Q.createSourceSlicerToken(e),i=Q.getSourceSlicerDownloadUrl(e,n,t);Uq(`${window.location.origin}${i}`,r)}else{let{token:n}=await Q.createArchiveSlicerToken(e),i=Q.getArchiveSlicerDownloadUrl(e,n,t);Uq(`${window.location.origin}${i}`,r)}}catch{let i=n===`source`?Q.getSource3mfForSlicer(e,t):Q.getArchiveForSlicer(e,t);Uq(`${window.location.origin}${i}`,r)}}function JFe({archive:e,printerName:t,isSelected:n,onSelect:r,selectionMode:i,projects:a,isHighlighted:o,timeFormat:s=`system`,preferredSlicer:c=`bambu_studio`,useSlicerApi:l=!1,currency:u,t:d,onNavigateToArchive:f}){o&&console.log(`ArchiveCard isHighlighted=true for archive:`,e.id);let p=Qa(),{showToast:m}=xd(),{hasPermission:h,canModify:g}=sd(),_=Gq(),v=Yn(),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),O=q({queryKey:[`archive`,e.id,`delete-impact`],queryFn:()=>Q.getArchiveDeleteImpact(e.id),enabled:w,staleTime:0}),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)([]),[z,B]=(0,y.useState)(!1),[V,ee]=(0,y.useState)(!1),[H,te]=(0,y.useState)(!1),[ne,re]=(0,y.useState)(!1),[U,ie]=(0,y.useState)(!1),[ae,W]=(0,y.useState)(!1),[oe,se]=(0,y.useState)(!1),[ce,le]=(0,y.useState)(null),[ue,de]=(0,y.useState)(null),[fe,pe]=(0,y.useState)(!1),[me,he]=(0,y.useState)(null),ge=(0,y.useRef)(null),_e=(0,y.useRef)(null),ve=(0,y.useRef)(null),{data:ye}=q({queryKey:[`archive-plates`,e.id],queryFn:()=>Q.getArchivePlates(e.id),enabled:fe,staleTime:300*1e3}),be=e.duplicate_sequence??0,xe=e.original_archive_id??null,Se=ye?.plates??[],Ce=ye?.is_multi_plate??!1,we=ue??0,Te=async()=>{try{let t=await Q.getArchivePlates(e.id);if(t.has_gcode===!1){m(d(`archives.platePicker.noGcode`),`info`);return}if(t.is_multi_plate&&t.plates.length>1){he(t.plates);return}}catch{}v(`/gcode-viewer?archive=${e.id}`)},Ee=J({mutationFn:()=>Q.deleteArchiveTimelapse(e.id),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.timelapseRemoved`))},onError:e=>{m(e.message||d(`archives.toast.failedRemoveTimelapse`),`error`)}}),De=J({mutationFn:t=>Q.uploadArchiveTimelapse(e.id,t),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.timelapseUploaded`,{filename:e.filename}))},onError:e=>{m(e.message||d(`archives.toast.failedUploadTimelapse`),`error`)}}),Oe=J({mutationFn:t=>Q.uploadSource3mf(e.id,t),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.source3mfAttached`,{filename:e.filename}))},onError:e=>{m(e.message||d(`archives.toast.failedUploadSource3mf`),`error`)}}),ke=J({mutationFn:()=>Q.deleteSource3mf(e.id),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.source3mfRemoved`))},onError:e=>{m(e.message||d(`archives.toast.failedRemoveSource3mf`),`error`)}}),Ae=J({mutationFn:t=>Q.uploadF3d(e.id,t),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.f3dAttached`,{filename:e.filename}))},onError:e=>{m(e.message||d(`archives.toast.failedUploadF3d`),`error`)}}),je=J({mutationFn:()=>Q.deleteF3d(e.id),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.f3dRemoved`))},onError:e=>{m(e.message||d(`archives.toast.failedRemoveF3d`),`error`)}}),Me=J({mutationFn:()=>Q.scanArchiveTimelapse(e.id),onSuccess:e=>{e.status===`attached`?(p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.timelapseAttached`,{filename:e.filename}))):e.status===`exists`?m(d(`archives.toast.timelapseAlreadyAttached`)):e.status===`not_found`&&e.available_files&&e.available_files.length>0?(R(e.available_files),I(!0)):m(e.message||d(`archives.toast.noMatchingTimelapse`),`warning`)},onError:e=>{m(e.message||d(`archives.toast.failedScanTimelapse`),`error`)}}),Ne=J({mutationFn:t=>Q.selectArchiveTimelapse(e.id,t),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.timelapseAttached`,{filename:e.filename})),I(!1),R([])},onError:e=>{m(e.message||d(`archives.toast.failedAttachTimelapse`),`error`)}}),Pe=J({mutationFn:t=>Q.deleteArchive(e.id,t),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.archiveDeleted`))},onError:()=>{m(d(`archives.toast.failedDeleteArchive`),`error`)}}),Fe=J({mutationFn:()=>Q.toggleFavorite(e.id),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(e.is_favorite?d(`archives.toast.addedToFavorites`):d(`archives.toast.removedFromFavorites`))}}),{data:Ie}=q({queryKey:[`archive-folders`,e.id],queryFn:()=>Q.getLibraryFoldersByArchive(e.id)}),Le=J({mutationFn:t=>Q.updateArchive(e.id,{project_id:t}),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),p.invalidateQueries({queryKey:[`projects`]}),m(d(`archives.toast.projectUpdated`))},onError:()=>{m(d(`archives.toast.failedUpdateProject`),`error`)}}),Re=e=>{e.preventDefault(),le({x:e.clientX,y:e.clientY})},ze=[...e6(e)?[{label:d(`archives.menu.print`),icon:(0,K.jsx)(bl,{className:`w-4 h-4`}),onClick:()=>x(!0),disabled:!e.file_path||!g(`archives`,`reprint`,e.created_by_id),title:e.file_path?g(`archives`,`reprint`,e.created_by_id)?void 0:d(`archives.permission.noReprint`):d(`archives.card.noFileForReprint`)},{label:d(`archives.menu.schedule`),icon:(0,K.jsx)(qo,{className:`w-4 h-4`}),onClick:()=>re(!0),disabled:!e.file_path||!h(`queue:create`),title:e.file_path?h(`queue:create`)?void 0:d(`archives.permission.noAddToQueue`):d(`archives.card.noFileForReprint`)},{label:d(`archives.menu.openInBambuStudio`),icon:(0,K.jsx)(Us,{className:`w-4 h-4`}),onClick:()=>{let t=e.print_name||e.filename||`model`;t6(e.id,t,`file`,c)},disabled:!e.file_path,title:e.file_path?void 0:d(`archives.card.noFileForReprint`)}]:[{label:d(`archives.menu.slice`),icon:l?(0,K.jsx)(ws,{className:`w-4 h-4`}):(0,K.jsx)(Us,{className:`w-4 h-4`}),onClick:()=>{if(l)C(!0);else{let t=e.print_name||e.filename||`model`;t6(e.id,t,`file`,c)}}}],{label:e.external_url?d(`archives.menu.externalLink`):d(`archives.menu.viewOnMakerWorld`),icon:(0,K.jsx)(hc,{className:`w-4 h-4`}),onClick:()=>{let t=e.external_url||e.makerworld_url;t&&window.open(t,`_blank`)},disabled:!e.external_url&&!e.makerworld_url},{label:``,divider:!0,onClick:()=>{}},{label:d(`archives.menu.preview3d`),icon:(0,K.jsx)(Bo,{className:`w-4 h-4`}),onClick:()=>{Te()}},{label:d(`archives.menu.viewTimelapse`),icon:(0,K.jsx)($s,{className:`w-4 h-4`}),onClick:()=>P(!0),disabled:!e.timelapse_path},{label:d(`archives.menu.scanForTimelapse`),icon:(0,K.jsx)(jl,{className:`w-4 h-4`}),onClick:()=>Me.mutate(),disabled:!e.printer_id||!!e.timelapse_path||Me.isPending||!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},{label:d(`archives.menu.uploadTimelapse`),icon:(0,K.jsx)(Su,{className:`w-4 h-4`}),onClick:()=>ve.current?.click(),disabled:!!e.timelapse_path||!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},...e.timelapse_path?[{label:d(`archives.menu.removeTimelapse`),icon:(0,K.jsx)(hu,{className:`w-4 h-4`}),onClick:()=>se(!0),danger:!0,disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)}]:[],{label:``,divider:!0,onClick:()=>{}},{label:e.source_3mf_path?d(`archives.menu.downloadSource3mf`):d(`archives.menu.uploadSource3mf`),icon:(0,K.jsx)(Js,{className:`w-4 h-4`}),onClick:()=>{e.source_3mf_path?Q.downloadSource3mf(e.id).catch(e=>{console.error(`Source 3MF download failed:`,e)}):ge.current?.click()},disabled:!e.source_3mf_path&&!g(`archives`,`update`,e.created_by_id),title:!e.source_3mf_path&&!g(`archives`,`update`,e.created_by_id)?d(`archives.permission.noUploadFiles`):void 0},...e.source_3mf_path?[{label:d(`archives.menu.replaceSource3mf`),icon:(0,K.jsx)(Su,{className:`w-4 h-4`}),onClick:()=>ge.current?.click(),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},{label:d(`archives.menu.removeSource3mf`),icon:(0,K.jsx)(hu,{className:`w-4 h-4`}),onClick:()=>ie(!0),danger:!0,disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)}]:[],{label:e.f3d_path?d(`archives.menu.replaceF3d`):d(`archives.menu.uploadF3d`),icon:(0,K.jsx)(Bo,{className:`w-4 h-4`}),onClick:()=>_e.current?.click(),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},...e.f3d_path?[{label:d(`archives.menu.downloadF3d`),icon:(0,K.jsx)(Is,{className:`w-4 h-4`}),onClick:()=>{Q.downloadF3d(e.id).catch(e=>{console.error(`F3D download failed:`,e)})}},{label:d(`archives.menu.removeF3d`),icon:(0,K.jsx)(hu,{className:`w-4 h-4`}),onClick:()=>W(!0),danger:!0,disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)}]:[],{label:``,divider:!0,onClick:()=>{}},{label:d(`archives.menu.download`),icon:(0,K.jsx)(Is,{className:`w-4 h-4`}),onClick:()=>{Q.downloadArchive(e.id,`${e.print_name||e.filename}.3mf`).catch(e=>{console.error(`Archive download failed:`,e)})},disabled:!h(`archives:read`),title:h(`archives:read`)?void 0:d(`archives.permission.noDownload`)},{label:d(`archives.menu.copyDownloadLink`),icon:(0,K.jsx)(Ds,{className:`w-4 h-4`}),onClick:()=>{let t=`${window.location.origin}${Q.getArchiveDownload(e.id)}`;navigator.clipboard.writeText(t).then(()=>{m(d(`archives.toast.linkCopied`))}).catch(()=>{m(d(`archives.toast.failedCopyLink`),`error`)})},disabled:!h(`archives:read`),title:h(`archives:read`)?void 0:d(`archives.permission.noCopyLink`)},{label:d(`archives.menu.qrCode`),icon:(0,K.jsx)(xl,{className:`w-4 h-4`}),onClick:()=>B(!0)},{label:e.photos?.length?d(`archives.menu.viewPhotosCount`,{count:e.photos.length}):d(`archives.menu.viewPhotos`),icon:(0,K.jsx)(Jo,{className:`w-4 h-4`}),onClick:()=>ee(!0),disabled:!e.photos?.length},{label:d(`archives.menu.projectPage`),icon:(0,K.jsx)(Zs,{className:`w-4 h-4`}),onClick:()=>te(!0)},{label:``,divider:!0,onClick:()=>{}},{label:e.is_favorite?d(`archives.menu.removeFromFavorites`):d(`archives.menu.addToFavorites`),icon:(0,K.jsx)(nu,{className:`w-4 h-4 ${e.is_favorite?`fill-yellow-400 text-yellow-400`:``}`}),onClick:()=>Fe.mutate(),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},{label:d(`archives.menu.edit`),icon:(0,K.jsx)(pl,{className:`w-4 h-4`}),onClick:()=>A(!0),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},{label:d(`archives.menu.printLog`),icon:(0,K.jsx)(wc,{className:`w-4 h-4`}),onClick:()=>M(!0)},...e.project_id&&e.project_name?[{label:d(`archives.menu.goToProject`,{name:e.project_name}),icon:(0,K.jsx)(nc,{className:`w-4 h-4 text-bambu-green`}),onClick:()=>window.location.href=`/projects`}]:[],{label:d(`archives.menu.addToProject`),icon:(0,K.jsx)(nc,{className:`w-4 h-4`}),onClick:()=>{},disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`),submenuSearchPlaceholder:(a?.filter(e=>e.status===`active`).length??0)>5?d(`archives.menu.searchProjects`):void 0,submenu:(()=>{let t=[];if(e.project_id&&t.push({label:d(`archives.menu.removeFromProject`),icon:(0,K.jsx)(Pu,{className:`w-4 h-4`}),onClick:()=>Le.mutate(null),disabled:!g(`archives`,`update`,e.created_by_id)}),!a)t.push({label:d(`archives.menu.loading`),icon:(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),onClick:()=>{},disabled:!0});else{let n=a.filter(e=>e.status===`active`).sort((e,t)=>e.name.localeCompare(t.name));n.length===0?t.push({label:d(`archives.menu.noProjectsAvailable`),icon:(0,K.jsx)(nc,{className:`w-4 h-4 opacity-50`}),onClick:()=>{},disabled:!0}):n.forEach(n=>{t.push({label:n.name,icon:(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:n.color||`#888`}}),onClick:()=>Le.mutate(n.id),disabled:e.project_id===n.id||!g(`archives`,`update`,e.created_by_id)})})}return t})()},{label:d(n?`archives.menu.deselect`:`archives.menu.select`),icon:n?(0,K.jsx)($l,{className:`w-4 h-4`}):(0,K.jsx)(tu,{className:`w-4 h-4`}),onClick:()=>r(e.id)},{label:``,divider:!0,onClick:()=>{}},{label:d(`archives.menu.delete`),icon:(0,K.jsx)(hu,{className:`w-4 h-4`}),onClick:()=>T(!0),danger:!0,disabled:!g(`archives`,`delete`,e.created_by_id),title:g(`archives`,`delete`,e.created_by_id)?void 0:d(`archives.permission.noDelete`)}];return(0,K.jsxs)(pd,{"data-archive-id":e.id,className:`relative flex flex-col group ${n?`ring-2 ring-bambu-green`:``} ${i?`cursor-pointer`:``}`,style:o?{outline:`4px solid #facc15`,outlineOffset:`2px`}:void 0,onContextMenu:Re,onClick:i?()=>r(e.id):void 0,children:[i&&(0,K.jsx)(`button`,{className:`absolute top-2 left-2 z-10 p-1 rounded bg-black/50 hover:bg-black/70 transition-colors`,onClick:t=>{t.stopPropagation(),r(e.id)},children:n?(0,K.jsx)($l,{className:`w-5 h-5 text-bambu-green`}):(0,K.jsx)(tu,{className:`w-5 h-5 text-white`})}),(0,K.jsxs)(`div`,{className:`aspect-video bg-bambu-dark relative flex-shrink-0 overflow-hidden rounded-t-xl`,onMouseEnter:()=>pe(!0),onMouseLeave:()=>pe(!1),children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:ue!==null&&Se.length>0?Q.getArchivePlateThumbnail(e.id,Se[we]?.index??0):Q.getArchiveThumbnail(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,K.jsx)(Dc,{className:`w-12 h-12 text-bambu-dark-tertiary`})}),Ce&&Se.length>1&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{className:`absolute left-1 top-1/2 -translate-y-1/2 p-1 rounded-full bg-black/60 hover:bg-black/80 transition-all ${_?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,onClick:e=>{e.stopPropagation(),de(e=>{let t=e??0;return t>0?t-1:Se.length-1})},title:d(`archives.card.previousPlate`),children:(0,K.jsx)(ns,{className:`w-4 h-4 text-white`})}),(0,K.jsx)(`button`,{className:`absolute right-1 top-1/2 -translate-y-1/2 p-1 rounded-full bg-black/60 hover:bg-black/80 transition-all ${_?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,onClick:e=>{e.stopPropagation(),de(e=>{let t=e??0;return t(0,K.jsx)(`button`,{className:`w-2 h-2 rounded-full transition-colors ${t===we?`bg-bambu-green`:`bg-white/50 hover:bg-white/80`}`,onClick:e=>{e.stopPropagation(),de(t)},title:e.name||d(`archives.card.plateNumber`,{index:e.index})},e.index))})]}),(0,K.jsx)(`button`,{className:`absolute top-2 left-2 p-1.5 rounded bg-black/50 hover:bg-black/70 transition-all ${_?`opacity-100`:`opacity-0 group-hover:opacity-100`} ${i?`left-10`:``}`,onClick:e=>{e.stopPropagation();let t=e.currentTarget.getBoundingClientRect();le({x:t.left,y:t.bottom+4})},title:d(`archives.card.moreOptions`),children:(0,K.jsx)(zs,{className:`w-5 h-5 text-white`})}),(0,K.jsx)(`button`,{className:`absolute top-2 right-2 p-1 rounded transition-colors ${g(`archives`,`update`,e.created_by_id)?`bg-black/50 hover:bg-black/70`:`bg-black/30 cursor-not-allowed`}`,onClick:t=>{t.stopPropagation(),g(`archives`,`update`,e.created_by_id)&&Fe.mutate()},disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?e.is_favorite?d(`archives.card.removeFromFavorites`):d(`archives.card.addToFavorites`):d(`archives.permission.noUpdateArchives`),children:(0,K.jsx)(nu,{className:`w-5 h-5 ${e.is_favorite?`text-yellow-400 fill-yellow-400`:`text-white`} ${g(`archives`,`update`,e.created_by_id)?``:`opacity-50`}`})}),(e.status===`failed`||e.status===`aborted`)&&(0,K.jsx)(`div`,{className:`absolute top-2 left-12 px-2 py-1 rounded text-xs bg-status-error/80 text-white`,children:e.status===`aborted`?d(`archives.card.cancelled`):d(`archives.card.failed`)}),e.duplicate_count>0&&be>0&&xe&&(0,K.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),f?.(xe)},className:`absolute top-2 right-12 px-2 py-1 rounded text-xs bg-purple-500/80 hover:bg-purple-600/90 text-white flex items-center gap-1 transition-colors cursor-pointer`,title:d(`archives.viewOriginalPrint`,{id:xe}),children:[(0,K.jsx)(Ds,{className:`w-3 h-3`}),`#`,be]}),e.duplicate_count>0&&be===0&&(0,K.jsxs)(`span`,{className:`absolute top-2 right-12 px-2 py-1 rounded text-xs bg-purple-500/80 text-white flex items-center gap-1`,title:`${e.duplicate_count} reprint${e.duplicate_count===1?``:`s`}`,children:[(0,K.jsx)(fc,{className:`w-3 h-3`}),`+`,e.duplicate_count]}),e.source_3mf_path&&(0,K.jsx)(`button`,{className:`absolute bottom-2 left-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:t=>{t.stopPropagation();let n=(e.print_name||e.filename||`source`).replace(/\.gcode\.3mf$/i,``)+`_source`;t6(e.id,n,`source`,c)},title:d(`archives.card.openSource3mf`),children:(0,K.jsx)(Js,{className:`w-4 h-4 text-orange-400`})}),e.f3d_path&&(0,K.jsx)(`button`,{className:`absolute bottom-2 ${e.source_3mf_path?`left-12`:`left-2`} p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:t=>{t.stopPropagation(),Q.downloadF3d(e.id).catch(e=>{console.error(`F3D download failed:`,e)})},title:d(`archives.card.downloadF3d`),children:(0,K.jsx)(Bo,{className:`w-4 h-4 text-cyan-400`})}),(0,K.jsx)(`button`,{className:`absolute bottom-2 right-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:e=>{e.stopPropagation(),Te()},title:d(`archives.card.preview3d`),children:(0,K.jsx)(Nc,{className:`w-4 h-4 text-white`})}),e.timelapse_path&&(0,K.jsx)(`button`,{className:`absolute bottom-2 right-12 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:e=>{e.stopPropagation(),P(!0)},title:d(`archives.card.viewTimelapse`),children:(0,K.jsx)($s,{className:`w-4 h-4 text-bambu-green`})}),e.photos&&e.photos.length>0&&(0,K.jsxs)(`button`,{className:`absolute bottom-2 ${e.timelapse_path?`right-[5.5rem]`:`right-12`} p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:e=>{e.stopPropagation(),ee(!0)},title:e.photos.length===1?d(`archives.card.viewPhoto`):d(`archives.card.viewPhotos`,{count:e.photos.length}),children:[(0,K.jsx)(Jo,{className:`w-4 h-4 text-blue-400`}),e.photos.length>1&&(0,K.jsx)(`span`,{className:`absolute -top-1 -right-1 w-4 h-4 bg-blue-500 rounded-full text-[10px] text-white flex items-center justify-center`,children:e.photos.length})]}),Ie&&Ie.length>0&&(0,K.jsx)(bi,{to:`/files?folder=${Ie[0].id}`,className:`absolute bottom-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:e=>e.stopPropagation(),title:d(`archives.card.openFolder`,{name:Ie[0].name}),style:{left:e.source_3mf_path?e.f3d_path?`5.5rem`:`3rem`:e.f3d_path?`3rem`:`0.5rem`},children:(0,K.jsx)(rc,{className:`w-4 h-4 text-yellow-400`})})]}),(0,K.jsxs)(hd,{className:`p-4 flex-1 flex flex-col`,children:[(0,K.jsxs)(`p`,{className:`text-[10px] text-bambu-gray/70 mb-1`,children:[`#`,e.id]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,K.jsx)(`h3`,{className:`min-w-0 font-medium text-white truncate`,children:e.print_name||e.filename}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,className:`p-1 sm:p-1.5 shrink-0`,onClick:()=>A(!0),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?d(`archives.card.edit`):d(`archives.card.noPermissionEdit`),children:(0,K.jsx)(pl,{className:`w-3 h-3 sm:w-4 sm:h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 flex-wrap`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t}),(()=>{let t=$K(e.bed_type);return t?(0,K.jsx)(`img`,{src:t.icon,alt:t.label,title:t.label,className:`w-4 h-4 flex-shrink-0`}):null})(),(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${e6(e)?`bg-bambu-green/20 text-bambu-green`:`bg-orange-500/20 text-orange-400`}`,title:e6(e)?d(`archives.card.slicedFile`):d(`archives.card.sourceFile`),children:e6(e)?d(`archives.card.gcode`):d(`archives.card.source`)}),e.content_hash&&(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded font-mono bg-bambu-dark-tertiary/50 text-bambu-gray-light opacity-0 transition-opacity duration-150 group-hover:opacity-100`,title:`SHA256: ${e.content_hash}`,children:e.content_hash.slice(0,8).toUpperCase()}),e.project_name&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full truncate max-w-[120px]`,style:{backgroundColor:`${a?.find(t=>t.id===e.project_id)?.color||`#6b7280`}20`,color:a?.find(t=>t.id===e.project_id)?.color||`#6b7280`},title:d(`archives.card.project`,{name:e.project_name}),children:e.project_name}),e.run_count>1&&(0,K.jsx)(`button`,{className:`text-[10px] px-1.5 py-0.5 rounded font-medium bg-bambu-orange/20 text-bambu-orange hover:bg-bambu-orange/30 transition-colors cursor-pointer`,onClick:e=>{e.stopPropagation(),M(!0)},title:d(`archives.card.runsBadgeTitle`,{count:e.run_count,successful:e.successful_run_count,failed:e.failed_run_count}),children:d(`archives.card.runsBadge`,{count:e.run_count})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs mb-4 min-h-[48px]`,children:[(e.print_time_seconds||e.actual_time_seconds)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,title:e.time_accuracy?`Estimated: ${yf(e.print_time_seconds||0)}\nActual: ${yf(e.actual_time_seconds||0)}\nAccuracy: ${e.time_accuracy.toFixed(0)}%`:e.actual_time_seconds?`Actual: ${yf(e.actual_time_seconds)}`:`Estimated: ${yf(e.print_time_seconds||0)}`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),yf(e.actual_time_seconds||e.print_time_seconds||0),e.time_accuracy&&(0,K.jsxs)(`span`,{className:`text-[10px] px-1 rounded ${e.time_accuracy>=95&&e.time_accuracy<=105?`bg-bambu-green/20 text-bambu-green`:e.time_accuracy>105?`bg-blue-500/20 text-blue-400`:`bg-orange-500/20 text-orange-400`}`,children:[e.time_accuracy>100?`+`:``,(e.time_accuracy-100).toFixed(0),`%`]})]}),e.filament_used_grams&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,K.jsx)(cl,{className:`w-3 h-3`}),e.filament_used_grams.toFixed(1),`g`]}),(e.cost!=null||e.energy_cost!=null)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-bambu-gray`,children:[e.cost!=null&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(Cs,{className:`w-3 h-3`}),u,e.cost.toFixed(2)]}),e.energy_cost!=null&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:`${d(`stats.energyUsed`)}: ${e.energy_kwh?.toFixed(3)||`N/A`} kWh`,children:[(0,K.jsx)(Iu,{className:`w-3 h-3`}),u,e.energy_cost.toFixed(2)]})]}),(e.layer_height||e.total_layers)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,K.jsx)(Nc,{className:`w-3 h-3`}),e.total_layers&&(0,K.jsx)(`span`,{children:e.total_layers===1?d(`archives.card.layer`,{count:e.total_layers}):d(`archives.card.layers`,{count:e.total_layers})}),e.total_layers&&e.layer_height&&(0,K.jsx)(`span`,{className:`text-bambu-gray/50`,children:`·`}),e.layer_height&&(0,K.jsxs)(`span`,{children:[e.layer_height,`mm`]})]}),e.object_count!=null&&e.object_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,title:e.object_count===1?d(`archives.card.object`,{count:e.object_count}):d(`archives.card.objects`,{count:e.object_count}),children:[(0,K.jsx)(Bo,{className:`w-3 h-3`}),e.object_count===1?d(`archives.card.object`,{count:e.object_count}):d(`archives.card.objects`,{count:e.object_count})]}),e.sliced_for_model&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,title:d(`archives.card.slicedFor`,{model:e.sliced_for_model}),children:[(0,K.jsx)(bl,{className:`w-3 h-3`}),e.sliced_for_model]}),e.filament_type&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 col-span-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e.filament_type}),e.filament_color&&(0,K.jsx)(`div`,{className:`flex items-center gap-0.5 flex-wrap`,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},title:e},t))})]})]}),(e.tags||e.notes)&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 mb-3`,children:[e.notes&&(0,K.jsx)(`div`,{className:`flex items-center gap-1 px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded text-xs`,title:e.notes,children:(0,K.jsx)(iu,{className:`w-3 h-3`})}),e.tags?.split(`,`).map((e,t)=>(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-bambu-dark-tertiary text-bambu-gray-light rounded text-xs`,children:e.trim()},t))]}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray border-t border-bambu-dark-tertiary pt-3`,children:[(0,K.jsx)(`span`,{children:gf(e.created_at,s)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.created_by_username&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,title:d(`archives.card.uploadedBy`,{name:e.created_by_username}),children:[(0,K.jsx)(Cu,{className:`w-3 h-3`}),e.created_by_username]}),(0,K.jsx)(`span`,{children:yd(e.file_size)})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-1 mt-3`,children:[e6(e)?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`primary`,size:`sm`,className:`flex-1 min-w-0 overflow-hidden`,onClick:()=>x(!0),disabled:!e.file_path||!g(`archives`,`reprint`,e.created_by_id),title:e.file_path?g(`archives`,`reprint`,e.created_by_id)?void 0:d(`archives.card.noPermissionReprint`):d(`archives.card.noFileForReprint`),children:[(0,K.jsx)(bl,{className:`w-3 h-3 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`hidden xl:inline truncate`,children:d(`archives.card.reprint`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,className:`flex-1 min-w-0 overflow-hidden`,onClick:()=>re(!0),disabled:!e.file_path||!h(`queue:create`),title:e.file_path?h(`queue:create`)?d(`archives.card.schedulePrint`):d(`archives.permission.noAddToQueue`):d(`archives.card.noFileForReprint`),children:[(0,K.jsx)(qo,{className:`w-3 h-3 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`hidden xl:inline truncate`,children:d(`archives.card.schedule`)})]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,className:`min-w-0 p-1 sm:p-1.5`,onClick:()=>{let t=e.print_name||e.filename||`model`;t6(e.id,t,`file`,c)},title:d(`archives.card.openInBambuStudio`),children:(0,K.jsx)(Us,{className:`w-3 h-3 sm:w-4 sm:h-4`})})]}):(0,K.jsxs)($,{variant:`primary`,size:`sm`,className:`flex-1 min-w-0 overflow-hidden`,onClick:()=>{if(l)C(!0);else{let t=e.print_name||e.filename||`model`;t6(e.id,t,`file`,c)}},title:d(l?`slice.title`:`archives.card.openInBambuStudioToSlice`),children:[l?(0,K.jsx)(ws,{className:`w-3 h-3 flex-shrink-0`}):(0,K.jsx)(Us,{className:`w-3 h-3 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`hidden xl:inline truncate`,children:d(`archives.card.slice`)})]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,className:`min-w-0 p-1 sm:p-1.5`,onClick:()=>{let t=e.external_url||e.makerworld_url;t&&window.open(t,`_blank`)},disabled:!e.external_url&&!e.makerworld_url,title:e.external_url?d(`archives.card.externalLink`):e.makerworld_url?d(`archives.card.makerWorld`,{designer:e.designer||d(`archives.card.viewProject`)}):d(`archives.card.noExternalLink`),children:(0,K.jsx)(hc,{className:`w-3 h-3 sm:w-4 sm:h-4 ${!e.external_url&&!e.makerworld_url?`opacity-20`:``}`})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,className:`min-w-0 p-1 sm:p-1.5`,onClick:()=>{Q.downloadArchive(e.id,`${e.print_name||e.filename}.3mf`).catch(e=>{console.error(`Archive download failed:`,e)})},title:d(`archives.card.download`),children:(0,K.jsx)(Is,{className:`w-3 h-3 sm:w-4 sm:h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,className:`min-w-0 p-1 sm:p-1.5`,onClick:()=>T(!0),disabled:!g(`archives`,`delete`,e.created_by_id),title:g(`archives`,`delete`,e.created_by_id)?d(`archives.card.delete`):d(`archives.card.noPermissionDelete`),children:(0,K.jsx)(hu,{className:`w-3 h-3 sm:w-4 sm:h-4 text-red-400`})})]})]}),k&&(0,K.jsx)(Jq,{archive:e,onClose:()=>A(!1)}),j&&(0,K.jsx)(Yq,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>M(!1)}),me&&(0,K.jsx)(Fq,{plates:me,onSelect:t=>{he(null),v(`/gcode-viewer?archive=${e.id}&plate=${t}`)},onClose:()=>he(null)}),b&&(0,K.jsx)(sq,{mode:`reprint`,archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>x(!1)}),S&&(0,K.jsx)(Bq,{source:{kind:`archive`,id:e.id,filename:e.print_name||e.filename||`model`},onClose:()=>C(!1)}),w&&(0,K.jsxs)(Ed,{title:d(`archives.modal.deleteArchive`),message:d(`archives.modal.deleteConfirm`,{name:e.print_name||e.filename}),confirmText:d(`archives.modal.deleteButton`),variant:`danger`,confirmDisabled:(O.data?.currently_printing??0)>0,onConfirm:()=>{Pe.mutate(E),T(!1),D(!1)},onCancel:()=>{T(!1),D(!1)},children:[(O.data?.related_queue_items??0)>0&&(0,K.jsx)(`div`,{className:(O.data?.currently_printing??0)>0?`text-sm text-red-400 mb-2`:`text-sm text-amber-400 mb-2`,children:(O.data?.currently_printing??0)>0?d(`archives.modal.deleteBlockedByPrinting`,{count:O.data.currently_printing}):d(`archives.modal.deleteQueueItemsWarning`,{count:O.data.related_queue_items})}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer text-sm text-bambu-gray`,children:[(0,K.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 accent-red-500`,checked:E,onChange:e=>D(e.target.checked)}),(0,K.jsx)(`span`,{children:d(`archives.modal.deletePurgeStats`)})]})]}),U&&(0,K.jsx)(Ed,{title:d(`archives.modal.removeSource3mf`),message:d(`archives.modal.removeSource3mfConfirm`,{name:e.print_name||e.filename}),confirmText:d(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{ke.mutate(),ie(!1)},onCancel:()=>ie(!1)}),ae&&(0,K.jsx)(Ed,{title:d(`archives.modal.removeF3d`),message:d(`archives.modal.removeF3dConfirm`,{name:e.print_name||e.filename}),confirmText:d(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{je.mutate(),W(!1)},onCancel:()=>W(!1)}),oe&&(0,K.jsx)(Ed,{title:d(`archives.modal.removeTimelapse`),message:d(`archives.modal.removeTimelapseConfirm`,{name:e.print_name||e.filename}),confirmText:d(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{Ee.mutate(),se(!1)},onCancel:()=>se(!1)}),ce&&(0,K.jsx)(Xq,{x:ce.x,y:ce.y,items:ze,onClose:()=>le(null)}),N&&e.timelapse_path&&(0,K.jsx)($3,{src:Q.getArchiveTimelapse(e.id),title:d(`archives.modal.timelapse`,{name:e.print_name||e.filename}),downloadFilename:`${e.print_name||e.filename}_timelapse.mp4`,archiveId:e.id,onClose:()=>P(!1),onEdit:()=>{p.invalidateQueries({queryKey:[`archives`]}),P(!1)}}),F&&L.length>0&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-card-dark rounded-lg max-w-lg w-full max-h-[80vh] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-700`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:d(`archives.modal.selectTimelapse`)}),(0,K.jsx)(`p`,{className:`text-sm text-gray-400 mt-1`,children:d(`archives.modal.selectTimelapseDesc`)})]}),(0,K.jsx)(`button`,{onClick:()=>{I(!1),R([])},className:`text-gray-400 hover:text-white p-1`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`overflow-y-auto flex-1 p-2`,children:L.map(e=>(0,K.jsxs)(`button`,{onClick:()=>Ne.mutate(e.name),disabled:Ne.isPending,className:`w-full text-left p-3 rounded-lg hover:bg-gray-700 transition-colors flex items-center gap-3 disabled:opacity-50`,children:[(0,K.jsx)($s,{className:`w-8 h-8 text-bambu-green flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.name}),(0,K.jsxs)(`p`,{className:`text-sm text-gray-400`,children:[yd(e.size),e.mtime&&` • ${gf(e.mtime,s)}`]})]})]},e.name))}),(0,K.jsx)(`div`,{className:`p-4 border-t border-gray-700`,children:(0,K.jsx)($,{variant:`secondary`,onClick:()=>{I(!1),R([])},className:`w-full`,children:`Cancel`})})]})}),z&&(0,K.jsx)(Zq,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>B(!1)}),V&&e.photos&&e.photos.length>0&&(0,K.jsx)(Qq,{archiveId:e.id,archiveName:e.print_name||e.filename,photos:e.photos,onClose:()=>ee(!1),onDelete:async t=>{try{await Q.deleteArchivePhoto(e.id,t),p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.photoDeleted`))}catch{m(d(`archives.toast.failedDeletePhoto`),`error`)}}}),H&&(0,K.jsx)(Q3,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>te(!1)}),ne&&(0,K.jsx)(sq,{mode:`add-to-queue`,archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>re(!1)}),(0,K.jsx)(`input`,{ref:ge,type:`file`,accept:`.3mf`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&Oe.mutate(t),e.target.value=``}}),(0,K.jsx)(`input`,{ref:_e,type:`file`,accept:`.f3d`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&Ae.mutate(t),e.target.value=``}}),(0,K.jsx)(`input`,{ref:ve,type:`file`,accept:`.mp4,.avi,.mkv`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&De.mutate(t),e.target.value=``}})]})}function YFe({archive:e,printerName:t,isSelected:n,onSelect:r,selectionMode:i,projects:a,isHighlighted:o,preferredSlicer:s=`bambu_studio`,useSlicerApi:c=!1,t:l,onNavigateToArchive:u}){let d=Qa(),{showToast:f}=xd(),{hasPermission:p,canModify:m}=sd(),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),w=q({queryKey:[`archive`,e.id,`delete-impact`],queryFn:()=>Q.getArchiveDeleteImpact(e.id),enabled:b,staleTime:0}),T=Yn(),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)([]),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(!1),[ee,H]=(0,y.useState)(!1),[te,ne]=(0,y.useState)(!1),[re,U]=(0,y.useState)(!1),[ie,ae]=(0,y.useState)(!1),[W,oe]=(0,y.useState)(null),se=(0,y.useRef)(null),ce=(0,y.useRef)(null),le=(0,y.useRef)(null),[ue,de]=(0,y.useState)(null),fe=e.duplicate_sequence??0,pe=e.original_archive_id??null,me=async()=>{try{let t=await Q.getArchivePlates(e.id);if(t.is_multi_plate&&t.plates.length>1){de(t.plates);return}}catch{}T(`/gcode-viewer?archive=${e.id}`)},he=J({mutationFn:()=>Q.deleteArchiveTimelapse(e.id),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.timelapseRemoved`))},onError:e=>{f(e.message||l(`archives.toast.failedRemoveTimelapse`),`error`)}}),ge=J({mutationFn:t=>Q.uploadArchiveTimelapse(e.id,t),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.timelapseUploaded`,{filename:e.filename}))},onError:e=>{f(e.message||l(`archives.toast.failedUploadTimelapse`),`error`)}}),_e=J({mutationFn:t=>Q.uploadSource3mf(e.id,t),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.source3mfAttached`,{filename:e.filename}))},onError:e=>{f(e.message||l(`archives.toast.failedUploadSource3mf`),`error`)}}),ve=J({mutationFn:()=>Q.deleteSource3mf(e.id),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.source3mfRemoved`))},onError:e=>{f(e.message||l(`archives.toast.failedRemoveSource3mf`),`error`)}}),ye=J({mutationFn:t=>Q.uploadF3d(e.id,t),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.f3dAttached`,{filename:e.filename}))},onError:e=>{f(e.message||l(`archives.toast.failedUploadF3d`),`error`)}}),be=J({mutationFn:()=>Q.deleteF3d(e.id),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.f3dRemoved`))},onError:e=>{f(e.message||l(`archives.toast.failedRemoveF3d`),`error`)}}),xe=J({mutationFn:()=>Q.scanArchiveTimelapse(e.id),onSuccess:e=>{e.status===`attached`?(d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.timelapseAttached`,{filename:e.filename}))):e.status===`exists`?f(l(`archives.toast.timelapseAlreadyAttached`)):e.status===`not_found`&&e.available_files&&e.available_files.length>0?(L(e.available_files),F(!0)):f(e.message||l(`archives.toast.noMatchingTimelapse`),`warning`)},onError:e=>{f(e.message||l(`archives.toast.failedScanTimelapse`),`error`)}}),Se=J({mutationFn:t=>Q.selectArchiveTimelapse(e.id,t),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.timelapseAttached`,{filename:e.filename})),F(!1),L([])},onError:e=>{f(e.message||l(`archives.toast.failedAttachTimelapse`),`error`)}}),Ce=J({mutationFn:t=>Q.deleteArchive(e.id,t),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.archiveDeleted`))},onError:()=>{f(l(`archives.toast.failedDeleteArchive`),`error`)}}),we=J({mutationFn:()=>Q.toggleFavorite(e.id),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(e.is_favorite?l(`archives.toast.addedToFavorites`):l(`archives.toast.removedFromFavorites`))}}),{data:Te}=q({queryKey:[`archive-folders`,e.id],queryFn:()=>Q.getLibraryFoldersByArchive(e.id)}),Ee=J({mutationFn:t=>Q.updateArchive(e.id,{project_id:t}),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),d.invalidateQueries({queryKey:[`projects`]}),f(l(`archives.toast.projectUpdated`))},onError:()=>{f(l(`archives.toast.failedUpdateProject`),`error`)}}),De=e=>{e.preventDefault(),oe({x:e.clientX,y:e.clientY})},Oe=[...e6(e)?[{label:l(`archives.menu.print`),icon:(0,K.jsx)(bl,{className:`w-4 h-4`}),onClick:()=>D(!0),disabled:!e.file_path||!m(`archives`,`reprint`,e.created_by_id),title:e.file_path?m(`archives`,`reprint`,e.created_by_id)?void 0:l(`archives.permission.noReprint`):l(`archives.card.noFileForReprint`)},{label:l(`archives.menu.schedule`),icon:(0,K.jsx)(qo,{className:`w-4 h-4`}),onClick:()=>j(!0),disabled:!e.file_path||!p(`queue:create`),title:e.file_path?p(`queue:create`)?void 0:l(`archives.permission.noAddToQueue`):l(`archives.card.noFileForReprint`)},{label:l(`archives.menu.openInBambuStudio`),icon:(0,K.jsx)(Us,{className:`w-4 h-4`}),onClick:()=>{let t=e.print_name||e.filename||`model`;t6(e.id,t,`file`,s)},disabled:!e.file_path,title:e.file_path?void 0:l(`archives.card.noFileForReprint`)}]:[{label:l(`archives.menu.slice`),icon:c?(0,K.jsx)(ws,{className:`w-4 h-4`}):(0,K.jsx)(Us,{className:`w-4 h-4`}),onClick:()=>{if(c)k(!0);else{let t=e.print_name||e.filename||`model`;t6(e.id,t,`file`,s)}}}],{label:e.external_url?l(`archives.menu.externalLink`):l(`archives.menu.viewOnMakerWorld`),icon:(0,K.jsx)(hc,{className:`w-4 h-4`}),onClick:()=>{let t=e.external_url||e.makerworld_url;t&&window.open(t,`_blank`)},disabled:!e.external_url&&!e.makerworld_url},{label:``,divider:!0,onClick:()=>{}},{label:l(`archives.menu.preview3d`),icon:(0,K.jsx)(Bo,{className:`w-4 h-4`}),onClick:()=>{me()}},{label:l(`archives.menu.viewTimelapse`),icon:(0,K.jsx)($s,{className:`w-4 h-4`}),onClick:()=>N(!0),disabled:!e.timelapse_path},{label:l(`archives.menu.scanForTimelapse`),icon:(0,K.jsx)(jl,{className:`w-4 h-4`}),onClick:()=>xe.mutate(),disabled:!e.printer_id||!!e.timelapse_path||xe.isPending||!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},{label:l(`archives.menu.uploadTimelapse`),icon:(0,K.jsx)(Su,{className:`w-4 h-4`}),onClick:()=>le.current?.click(),disabled:!!e.timelapse_path||!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},...e.timelapse_path?[{label:l(`archives.menu.removeTimelapse`),icon:(0,K.jsx)(hu,{className:`w-4 h-4`}),onClick:()=>ae(!0),danger:!0,disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)}]:[],{label:``,divider:!0,onClick:()=>{}},{label:e.source_3mf_path?l(`archives.menu.downloadSource3mf`):l(`archives.menu.uploadSource3mf`),icon:(0,K.jsx)(Js,{className:`w-4 h-4`}),onClick:()=>{e.source_3mf_path?Q.downloadSource3mf(e.id).catch(e=>{console.error(`Source 3MF download failed:`,e)}):se.current?.click()},disabled:!e.source_3mf_path&&!m(`archives`,`update`,e.created_by_id),title:!e.source_3mf_path&&!m(`archives`,`update`,e.created_by_id)?l(`archives.permission.noUploadFiles`):void 0},...e.source_3mf_path?[{label:l(`archives.menu.replaceSource3mf`),icon:(0,K.jsx)(Su,{className:`w-4 h-4`}),onClick:()=>se.current?.click(),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},{label:l(`archives.menu.removeSource3mf`),icon:(0,K.jsx)(hu,{className:`w-4 h-4`}),onClick:()=>ne(!0),danger:!0,disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)}]:[],{label:e.f3d_path?l(`archives.menu.replaceF3d`):l(`archives.menu.uploadF3d`),icon:(0,K.jsx)(Bo,{className:`w-4 h-4`}),onClick:()=>ce.current?.click(),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},...e.f3d_path?[{label:l(`archives.menu.downloadF3d`),icon:(0,K.jsx)(Is,{className:`w-4 h-4`}),onClick:()=>{Q.downloadF3d(e.id).catch(e=>{console.error(`F3D download failed:`,e)})}},{label:l(`archives.menu.removeF3d`),icon:(0,K.jsx)(hu,{className:`w-4 h-4`}),onClick:()=>U(!0),danger:!0,disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)}]:[],{label:``,divider:!0,onClick:()=>{}},{label:l(`archives.menu.download`),icon:(0,K.jsx)(Is,{className:`w-4 h-4`}),onClick:()=>{Q.downloadArchive(e.id,`${e.print_name||e.filename}.3mf`).catch(e=>{console.error(`Archive download failed:`,e)})},disabled:!p(`archives:read`),title:p(`archives:read`)?void 0:l(`archives.permission.noDownload`)},{label:l(`archives.menu.copyDownloadLink`),icon:(0,K.jsx)(Ds,{className:`w-4 h-4`}),onClick:()=>{let t=`${window.location.origin}${Q.getArchiveDownload(e.id)}`;navigator.clipboard.writeText(t).then(()=>{f(l(`archives.toast.linkCopied`))}).catch(()=>{f(l(`archives.toast.failedCopyLink`),`error`)})},disabled:!p(`archives:read`),title:p(`archives:read`)?void 0:l(`archives.permission.noCopyLink`)},{label:l(`archives.menu.qrCode`),icon:(0,K.jsx)(xl,{className:`w-4 h-4`}),onClick:()=>z(!0)},{label:e.photos?.length?l(`archives.menu.viewPhotosCount`,{count:e.photos.length}):l(`archives.menu.viewPhotos`),icon:(0,K.jsx)(Jo,{className:`w-4 h-4`}),onClick:()=>V(!0),disabled:!e.photos?.length},{label:l(`archives.menu.projectPage`),icon:(0,K.jsx)(Zs,{className:`w-4 h-4`}),onClick:()=>H(!0)},{label:``,divider:!0,onClick:()=>{}},{label:e.is_favorite?l(`archives.menu.removeFromFavorites`):l(`archives.menu.addToFavorites`),icon:(0,K.jsx)(nu,{className:`w-4 h-4 ${e.is_favorite?`fill-yellow-400 text-yellow-400`:``}`}),onClick:()=>we.mutate(),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},{label:l(`archives.menu.edit`),icon:(0,K.jsx)(pl,{className:`w-4 h-4`}),onClick:()=>g(!0),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},{label:l(`archives.menu.printLog`),icon:(0,K.jsx)(wc,{className:`w-4 h-4`}),onClick:()=>v(!0)},...e.project_id&&e.project_name?[{label:l(`archives.menu.goToProject`,{name:e.project_name}),icon:(0,K.jsx)(nc,{className:`w-4 h-4 text-bambu-green`}),onClick:()=>window.location.href=`/projects`}]:[],{label:l(`archives.menu.addToProject`),icon:(0,K.jsx)(nc,{className:`w-4 h-4`}),onClick:()=>{},submenuSearchPlaceholder:(a?.filter(e=>e.status===`active`).length??0)>5?l(`archives.menu.searchProjects`):void 0,submenu:(()=>{let t=[];if(e.project_id&&t.push({label:l(`archives.menu.removeFromProject`),icon:(0,K.jsx)(Pu,{className:`w-4 h-4`}),onClick:()=>Ee.mutate(null)}),!a)t.push({label:l(`archives.menu.loading`),icon:(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),onClick:()=>{},disabled:!0});else{let n=a.filter(e=>e.status===`active`).sort((e,t)=>e.name.localeCompare(t.name));n.length===0?t.push({label:l(`archives.menu.noProjectsAvailable`),icon:(0,K.jsx)(nc,{className:`w-4 h-4 opacity-50`}),onClick:()=>{},disabled:!0}):n.forEach(n=>{t.push({label:n.name,icon:(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:n.color||`#888`}}),onClick:()=>Ee.mutate(n.id),disabled:e.project_id===n.id})})}return t})()},{label:l(n?`archives.menu.deselect`:`archives.menu.select`),icon:n?(0,K.jsx)($l,{className:`w-4 h-4`}):(0,K.jsx)(tu,{className:`w-4 h-4`}),onClick:()=>r(e.id)},{label:``,divider:!0,onClick:()=>{}},{label:l(`archives.menu.delete`),icon:(0,K.jsx)(hu,{className:`w-4 h-4`}),onClick:()=>x(!0),danger:!0,disabled:!m(`archives`,`delete`,e.created_by_id),title:m(`archives`,`delete`,e.created_by_id)?void 0:l(`archives.permission.noDelete`)}];return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{"data-archive-id":e.id,className:`grid grid-cols-12 gap-4 px-4 py-3 items-center hover:bg-bambu-dark-tertiary/30 ${n?`bg-bambu-green/10`:``}`,style:o?{outline:`4px solid #facc15`,outlineOffset:`-4px`}:void 0,onContextMenu:De,children:[(0,K.jsxs)(`div`,{className:`col-span-1 flex items-center gap-2`,children:[i&&(0,K.jsx)(`button`,{onClick:()=>r(e.id),children:n?(0,K.jsx)($l,{className:`w-4 h-4 text-bambu-green`}):(0,K.jsx)(tu,{className:`w-4 h-4 text-bambu-gray`})}),e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:``,className:`w-10 h-10 object-cover rounded`}):(0,K.jsx)(`div`,{className:`w-10 h-10 bg-bambu-dark rounded flex items-center justify-center`,children:(0,K.jsx)(Dc,{className:`w-5 h-5 text-bambu-dark-tertiary`})})]}),(0,K.jsxs)(`div`,{className:`col-span-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`p`,{className:`text-white text-sm truncate`,children:e.print_name||e.filename}),(e.status===`failed`||e.status===`aborted`)&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] leading-tight bg-status-error/80 text-white flex-shrink-0`,children:e.status===`aborted`?l(`archives.card.cancelled`):l(`archives.card.failed`)}),e.duplicate_count>0&&fe>0&&pe&&(0,K.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),u?.(pe)},className:`px-1.5 py-0.5 rounded text-[10px] leading-tight bg-purple-500/80 hover:bg-purple-600/90 text-white flex-shrink-0 transition-colors flex items-center gap-1`,title:l(`archives.viewOriginalPrint`,{id:pe}),children:[(0,K.jsx)(Ds,{className:`w-3 h-3`}),`#`,fe]}),e.duplicate_count>0&&fe===0&&(0,K.jsxs)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] leading-tight bg-purple-500/80 text-white flex-shrink-0 flex items-center gap-1`,title:`${e.duplicate_count} reprint${e.duplicate_count===1?``:`s`}`,children:[(0,K.jsx)(fc,{className:`w-3 h-3`}),`+`,e.duplicate_count]}),e.timelapse_path&&(0,K.jsx)(`span`,{title:l(`archives.list.hasTimelapse`),children:(0,K.jsx)($s,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`})}),Te&&Te.length>0&&(0,K.jsx)(bi,{to:`/files?folder=${Te[0].id}`,className:`flex-shrink-0`,title:l(`archives.card.openFolder`,{name:Te[0].name}),onClick:e=>e.stopPropagation(),children:(0,K.jsx)(rc,{className:`w-3.5 h-3.5 text-yellow-400`})})]}),(e.filament_type||e.sliced_for_model)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[e.sliced_for_model&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1`,title:l(`archives.card.slicedFor`,{model:e.sliced_for_model}),children:[(0,K.jsx)(bl,{className:`w-2.5 h-2.5`}),e.sliced_for_model]}),(()=>{let t=$K(e.bed_type);return t?(0,K.jsx)(`img`,{src:t.icon,alt:t.label,title:t.label,className:`w-3.5 h-3.5 flex-shrink-0`}):null})(),e.sliced_for_model&&e.filament_type&&(0,K.jsx)(`span`,{className:`text-bambu-gray/50`,children:`·`}),e.filament_type&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.filament_type}),e.filament_color&&(0,K.jsx)(`div`,{className:`flex items-center gap-0.5 flex-wrap`,children:e.filament_color.split(`,`).map((e,t)=>(0,K.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full border border-black/20`,style:{backgroundColor:e},title:e},t))})]})]}),(0,K.jsx)(`div`,{className:`col-span-2 text-sm text-bambu-gray truncate`,children:t}),(0,K.jsxs)(`div`,{className:`col-span-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(`div`,{children:hf(e.created_at)}),e.created_by_username&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-xs opacity-75`,title:l(`archives.card.uploadedBy`,{name:e.created_by_username}),children:[(0,K.jsx)(Cu,{className:`w-3 h-3`}),e.created_by_username]})]}),(0,K.jsx)(`div`,{className:`col-span-1 text-sm text-bambu-gray`,children:yd(e.file_size)}),(0,K.jsxs)(`div`,{className:`col-span-2 flex justify-end gap-1`,children:[e6(e)&&(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>D(!0),disabled:!m(`archives`,`reprint`,e.created_by_id),title:m(`archives`,`reprint`,e.created_by_id)?l(`archives.card.reprint`):l(`archives.card.noPermissionReprint`),className:`text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10`,children:(0,K.jsx)(hl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{let t=e.print_name||e.filename||`model`;t6(e.id,t,`file`,s)},title:l(`archives.card.openInBambuStudio`),children:(0,K.jsx)(Us,{className:`w-4 h-4`})}),(e.external_url||e.makerworld_url)&&(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>window.open(e.external_url||e.makerworld_url,`_blank`),title:e.external_url?l(`archives.card.externalLink`):`MakerWorld`,children:(0,K.jsx)(hc,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{Q.downloadArchive(e.id,`${e.print_name||e.filename}.3mf`).catch(e=>{console.error(`Archive download failed:`,e)})},title:l(`archives.card.download`),children:(0,K.jsx)(Is,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>g(!0),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?l(`archives.card.edit`):l(`archives.card.noPermissionEdit`),children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>x(!0),disabled:!m(`archives`,`delete`,e.created_by_id),title:m(`archives`,`delete`,e.created_by_id)?l(`archives.card.delete`):l(`archives.card.noPermissionDelete`),children:(0,K.jsx)(hu,{className:`w-4 h-4 text-red-400`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();oe({x:t.left,y:t.bottom+4})},title:l(`archives.card.moreOptions`),children:(0,K.jsx)(zs,{className:`w-4 h-4`})})]})]}),h&&(0,K.jsx)(Jq,{archive:e,onClose:()=>g(!1)}),_&&(0,K.jsx)(Yq,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>v(!1)}),ue&&(0,K.jsx)(Fq,{plates:ue,onSelect:t=>{de(null),T(`/gcode-viewer?archive=${e.id}&plate=${t}`)},onClose:()=>de(null)}),E&&(0,K.jsx)(sq,{mode:`reprint`,archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>D(!1)}),O&&(0,K.jsx)(Bq,{source:{kind:`archive`,id:e.id,filename:e.print_name||e.filename||`model`},onClose:()=>k(!1)}),b&&(0,K.jsxs)(Ed,{title:l(`archives.modal.deleteArchive`),message:l(`archives.modal.deleteConfirm`,{name:e.print_name||e.filename}),confirmText:l(`archives.modal.deleteButton`),variant:`danger`,confirmDisabled:(w.data?.currently_printing??0)>0,onConfirm:()=>{Ce.mutate(S),x(!1),C(!1)},onCancel:()=>{x(!1),C(!1)},children:[(w.data?.related_queue_items??0)>0&&(0,K.jsx)(`div`,{className:(w.data?.currently_printing??0)>0?`text-sm text-red-400 mb-2`:`text-sm text-amber-400 mb-2`,children:(w.data?.currently_printing??0)>0?l(`archives.modal.deleteBlockedByPrinting`,{count:w.data.currently_printing}):l(`archives.modal.deleteQueueItemsWarning`,{count:w.data.related_queue_items})}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer text-sm text-bambu-gray`,children:[(0,K.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 accent-red-500`,checked:S,onChange:e=>C(e.target.checked)}),(0,K.jsx)(`span`,{children:l(`archives.modal.deletePurgeStats`)})]})]}),te&&(0,K.jsx)(Ed,{title:l(`archives.modal.removeSource3mf`),message:l(`archives.modal.removeSource3mfConfirm`,{name:e.print_name||e.filename}),confirmText:l(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{ve.mutate(),ne(!1)},onCancel:()=>ne(!1)}),re&&(0,K.jsx)(Ed,{title:l(`archives.modal.removeF3d`),message:l(`archives.modal.removeF3dConfirm`,{name:e.print_name||e.filename}),confirmText:l(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{be.mutate(),U(!1)},onCancel:()=>U(!1)}),ie&&(0,K.jsx)(Ed,{title:l(`archives.modal.removeTimelapse`),message:l(`archives.modal.removeTimelapseConfirm`,{name:e.print_name||e.filename}),confirmText:l(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{he.mutate(),ae(!1)},onCancel:()=>ae(!1)}),W&&(0,K.jsx)(Xq,{x:W.x,y:W.y,items:Oe,onClose:()=>oe(null)}),M&&e.timelapse_path&&(0,K.jsx)($3,{src:Q.getArchiveTimelapse(e.id),title:l(`archives.modal.timelapse`,{name:e.print_name||e.filename}),downloadFilename:`${e.print_name||e.filename}_timelapse.mp4`,archiveId:e.id,onClose:()=>N(!1),onEdit:()=>{d.invalidateQueries({queryKey:[`archives`]}),N(!1)}}),P&&I.length>0&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-card-dark rounded-lg max-w-lg w-full max-h-[80vh] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-700`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:l(`archives.modal.selectTimelapse`)}),(0,K.jsx)(`p`,{className:`text-sm text-gray-400 mt-1`,children:l(`archives.modal.selectTimelapseDesc`)})]}),(0,K.jsx)(`button`,{onClick:()=>{F(!1),L([])},className:`text-gray-400 hover:text-white p-1`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`overflow-y-auto flex-1 p-2`,children:I.map(e=>(0,K.jsxs)(`button`,{onClick:()=>Se.mutate(e.name),disabled:Se.isPending,className:`w-full text-left p-3 rounded-lg hover:bg-gray-700 transition-colors mb-1`,children:[(0,K.jsx)(`div`,{className:`font-medium text-white`,children:e.name}),(0,K.jsxs)(`div`,{className:`text-sm text-gray-400 flex gap-3`,children:[(0,K.jsx)(`span`,{children:yd(e.size)}),e.mtime&&(0,K.jsx)(`span`,{children:hf(e.mtime)})]})]},e.name))})]})}),R&&(0,K.jsx)(Zq,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>z(!1)}),B&&e.photos&&(0,K.jsx)(Qq,{archiveId:e.id,archiveName:e.print_name||e.filename,photos:e.photos,onClose:()=>V(!1),onDelete:async t=>{try{await Q.deleteArchivePhoto(e.id,t),d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.photoDeleted`))}catch{f(l(`archives.toast.failedDeletePhoto`),`error`)}}}),ee&&(0,K.jsx)(Q3,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>H(!1)}),A&&(0,K.jsx)(sq,{mode:`add-to-queue`,archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>j(!1)}),(0,K.jsx)(`input`,{ref:se,type:`file`,accept:`.3mf`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&_e.mutate(t),e.target.value=``}}),(0,K.jsx)(`input`,{ref:ce,type:`file`,accept:`.f3d`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&ye.mutate(t),e.target.value=``}}),(0,K.jsx)(`input`,{ref:le,type:`file`,accept:`.mp4,.avi,.mkv`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&ge.mutate(t),e.target.value=``}})]})}var XFe=[`completed`,`failed`,`aborted`,`cancelled`,`stopped`],ZFe=[{id:`all`,label:`All Archives`,icon:(0,K.jsx)(rc,{className:`w-4 h-4`})},{id:`recent`,label:`Last 24 Hours`,icon:(0,K.jsx)(_s,{className:`w-4 h-4`})},{id:`this-week`,label:`This Week`,icon:(0,K.jsx)(qo,{className:`w-4 h-4`})},{id:`this-month`,label:`This Month`,icon:(0,K.jsx)(qo,{className:`w-4 h-4`})},{id:`favorites`,label:`Favorites`,icon:(0,K.jsx)(nu,{className:`w-4 h-4`})},{id:`not-printed`,label:`Not Printed`,icon:(0,K.jsx)(Su,{className:`w-4 h-4`})},{id:`printed`,label:`Printed`,icon:(0,K.jsx)(bl,{className:`w-4 h-4`})},{id:`failed`,label:`Failed Prints`,icon:(0,K.jsx)(ss,{className:`w-4 h-4`})},{id:`duplicates`,label:`Duplicates`,icon:(0,K.jsx)(Ds,{className:`w-4 h-4`})}];function QFe(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),{hasPermission:r,hasAnyPermission:i}=sd(),a=(0,y.useRef)(null),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(()=>{let e=localStorage.getItem(`archiveFilterPrinter`);return e?Number(e):null}),[u,d]=(0,y.useState)(()=>localStorage.getItem(`archiveFilterMaterial`)),[f,p]=(0,y.useState)(()=>{let e=localStorage.getItem(`archiveFilterColors`);return e?new Set(JSON.parse(e)):new Set}),[m,h]=(0,y.useState)(()=>localStorage.getItem(`archiveColorFilterMode`)||`or`),[g,_]=(0,y.useState)(()=>localStorage.getItem(`archiveFilterFavorites`)===`true`),[v,b]=(0,y.useState)(()=>localStorage.getItem(`archiveHideFailed`)===`true`),[x,S]=(0,y.useState)(()=>localStorage.getItem(`archiveHideDuplicates`)===`true`),[C,w]=(0,y.useState)(()=>localStorage.getItem(`archiveFilterTag`)),[T,E]=(0,y.useState)(()=>localStorage.getItem(`archiveFilterFileType`)||`all`),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)([]),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)(new Set),[F,I]=(0,y.useState)(()=>localStorage.getItem(`archiveNo3MFWarningDismissed`)===`true`),{data:L}=q({queryKey:[`archives`,`no-3mf-warning`],queryFn:Q.getNo3MFWarning,staleTime:300*1e3,enabled:!F}),R=()=>{localStorage.setItem(`archiveNo3MFWarningDismissed`,`true`),I(!0)},[z,B]=(0,y.useState)(!1),[V,ee]=(0,y.useState)(!1),[H,te]=(0,y.useState)(!1),[ne,re]=(0,y.useState)(!1),[U,ie]=(0,y.useState)(()=>localStorage.getItem(`archiveViewMode`)||`grid`),[ae,W]=(0,y.useState)(()=>localStorage.getItem(`archiveSortBy`)||`date-desc`),[oe,se]=(0,y.useState)(()=>localStorage.getItem(`archiveCollection`)||`all`),[ce,le]=(0,y.useState)(0),[ue,de]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`archivePageSize`);return e?Number(e):50}catch{return 50}}),[fe,pe]=(0,y.useState)(!1),[me,he]=(0,y.useState)(!1),[ge,_e]=(0,y.useState)(!1),[ve,ye]=(0,y.useState)(!1),[be,xe]=(0,y.useState)(!1),[Se,Ce]=(0,y.useState)(null),[we,Te]=(0,y.useState)(null),[Ee,De]=(0,y.useState)(()=>localStorage.getItem(`logFilterUser`)||null),[Oe,ke]=(0,y.useState)(()=>localStorage.getItem(`logFilterStatus`)),[Ae,je]=(0,y.useState)(()=>localStorage.getItem(`logFilterDateFrom`)||``),[Me,Ne]=(0,y.useState)(()=>localStorage.getItem(`logFilterDateTo`)||``),[Pe,Fe]=(0,y.useState)(()=>{let e=localStorage.getItem(`logOffset`);return e?Number(e):0}),[Ie,Le]=(0,y.useState)(!1),[Re,ze]=(0,y.useState)(null),[Be,Ve]=(0,y.useState)(null),[He,Ue]=(0,y.useState)(``),[We,Ge]=(0,y.useState)(``),[Ke,qe]=(0,y.useState)(()=>{let e=localStorage.getItem(`logPageSize`);return e?Number(e):25}),Je=(0,y.useCallback)(e=>{Te(e),Ce(e)},[]);(0,y.useEffect)(()=>{if(Se){let t=setTimeout(()=>{let t=document.querySelector(`[data-archive-id="${Se}"]`);t?t.scrollIntoView({behavior:`smooth`,block:`center`}):we===Se&&n(e(`archives.originalPrintNotVisible`),`warning`),we===Se&&Te(null)},100),r=setTimeout(()=>Ce(null),5e3);return()=>{clearTimeout(t),clearTimeout(r)}}},[Se,we,n,e]);let{data:Ye,isLoading:Xe}=q({queryKey:[`archives`,c],queryFn:()=>Q.getArchives(c||void 0)}),{data:Ze}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:Qe}=q({queryKey:[`projects`],queryFn:()=>Q.getProjects()}),{data:$e}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:et}=q({queryKey:[`users`],queryFn:Q.getUsers,enabled:U===`log`}),{data:tt,isLoading:nt}=q({queryKey:[`print-log`,c,Ee,Oe,Ae,Me,o,Pe,Ke],queryFn:()=>Q.getPrintLog({search:o||void 0,printerId:c||void 0,username:Ee||void 0,status:Oe||void 0,dateFrom:Ae||void 0,dateTo:Me||void 0,limit:Ke,offset:Pe}),enabled:U===`log`}),rt=$e?.time_format||`system`,it=$e?.open_in_slicer||$e?.preferred_slicer||`bambu_studio`,at=$e?.use_slicer_api??!1,ot=Yd($e?.currency||`USD`),st=J({mutationFn:async e=>(await Promise.all(e.map(e=>Q.deleteArchive(e))),e.length),onSuccess:e=>{t.invalidateQueries({queryKey:[`archives`]}),P(new Set),n(`${e} archive${e===1?``:`s`} deleted`)},onError:()=>{n(e(`archives.toast.failedDeleteArchives`),`error`)}}),ct=J({mutationFn:()=>Q.clearPrintLog(),onSuccess:r=>{t.invalidateQueries({queryKey:[`print-log`]}),Fe(0),n(e(`archives.log.cleared`,{count:r.deleted}))},onError:()=>{n(e(`archives.log.clearFailed`),`error`)}}),lt=J({mutationFn:e=>Q.deletePrintLogEntry(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`print-log`]}),t.invalidateQueries({queryKey:[`archives-stats`]}),n(e(`archives.log.entryDeleted`))},onError:()=>{n(e(`archives.log.entryDeleteFailed`),`error`)}}),ut=J({mutationFn:({id:e,body:t})=>Q.updatePrintLogEntry(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`print-log`]}),t.invalidateQueries({queryKey:[`archives-stats`]}),Ve(null),n(e(`archives.log.entryUpdated`))},onError:()=>{n(e(`archives.log.entryUpdateFailed`),`error`)}});(0,y.useEffect)(()=>{c===null?localStorage.removeItem(`archiveFilterPrinter`):localStorage.setItem(`archiveFilterPrinter`,c.toString())},[c]),(0,y.useEffect)(()=>{u?localStorage.setItem(`archiveFilterMaterial`,u):localStorage.removeItem(`archiveFilterMaterial`)},[u]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveFilterColors`,JSON.stringify([...f]))},[f]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveColorFilterMode`,m)},[m]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveFilterFavorites`,g.toString())},[g]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveHideFailed`,v.toString())},[v]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveHideDuplicates`,x.toString())},[x]),(0,y.useEffect)(()=>{C?localStorage.setItem(`archiveFilterTag`,C):localStorage.removeItem(`archiveFilterTag`)},[C]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveFilterFileType`,T)},[T]),(0,y.useEffect)(()=>{le(0)},[o,c,u,f,m,g,v,x,C,T,ae,oe]),(0,y.useEffect)(()=>{try{localStorage.setItem(`archivePageSize`,String(ue))}catch{}},[ue]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveViewMode`,U)},[U]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveSortBy`,ae)},[ae]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveCollection`,oe)},[oe]),(0,y.useEffect)(()=>{Ee?localStorage.setItem(`logFilterUser`,Ee):localStorage.removeItem(`logFilterUser`)},[Ee]),(0,y.useEffect)(()=>{Oe?localStorage.setItem(`logFilterStatus`,Oe):localStorage.removeItem(`logFilterStatus`)},[Oe]),(0,y.useEffect)(()=>{Ae?localStorage.setItem(`logFilterDateFrom`,Ae):localStorage.removeItem(`logFilterDateFrom`)},[Ae]),(0,y.useEffect)(()=>{Me?localStorage.setItem(`logFilterDateTo`,Me):localStorage.removeItem(`logFilterDateTo`)},[Me]),(0,y.useEffect)(()=>{localStorage.setItem(`logOffset`,Pe.toString())},[Pe]),(0,y.useEffect)(()=>{localStorage.setItem(`logPageSize`,Ke.toString())},[Ke]);let dt=new Map(Ze?.map(e=>[e.id,e.name])||[]),ft=[...new Set(Ye?.flatMap(e=>e.filament_type?.split(`, `)||[]).filter(Boolean)||[])].sort(),pt=[...new Set(Ye?.flatMap(e=>e.filament_color?.split(`,`)||[]).filter(Boolean)||[])],mt=[...new Set(Ye?.flatMap(e=>e.tags?.split(`,`).map(e=>e.trim())||[]).filter(Boolean)||[])].sort(),ht=Ye?.filter(e=>{let t=new Date,n=mf(e.created_at)||new Date(0),r=!0;switch(oe){case`recent`:r=t.getTime()-n.getTime()<1440*60*1e3;break;case`this-week`:r=t.getTime()-n.getTime()<10080*60*1e3;break;case`this-month`:r=n.getMonth()===t.getMonth()&&n.getFullYear()===t.getFullYear();break;case`favorites`:r=e.is_favorite===!0;break;case`not-printed`:r=e.status===`archived`;break;case`printed`:r=XFe.includes(e.status);break;case`failed`:r=e.status===`failed`||e.status===`aborted`;break;case`duplicates`:r=e.duplicate_count>0;break}let i=(e.print_name||e.filename).toLowerCase().includes(o.toLowerCase()),a=!u||e.filament_type?.split(`, `).includes(u),s=e.filament_color?.split(`,`)||[],c=f.size===0||(m===`or`?s.some(e=>f.has(e)):[...f].every(e=>s.includes(e))),l=oe===`favorites`||!g||e.is_favorite,d=oe===`failed`||!v||e.status!==`failed`&&e.status!==`aborted`,p=oe===`duplicates`||!x||e.duplicate_count===0||e.duplicate_sequence===0,h=e.tags?.split(`,`).map(e=>e.trim())||[],_=!C||h.includes(C),y=e6(e);return r&&i&&a&&c&&l&&d&&p&&_&&(T===`all`||T===`gcode`&&y||T===`source`&&!y)}).sort((e,t)=>{switch(ae){case`date-desc`:return(mf(t.created_at)?.getTime()||0)-(mf(e.created_at)?.getTime()||0);case`date-asc`:return(mf(e.created_at)?.getTime()||0)-(mf(t.created_at)?.getTime()||0);case`name-asc`:return(e.print_name||e.filename).localeCompare(t.print_name||t.filename);case`name-desc`:return(t.print_name||t.filename).localeCompare(e.print_name||e.filename);case`size-desc`:return t.file_size-e.file_size;case`size-asc`:return e.file_size-t.file_size;default:return 0}}),gt=ht?.length||0,_t=ue===-1,vt=_t?gt||1:ue,yt=Math.max(1,Math.ceil(gt/vt)),bt=_t?ht:ht?.slice(ce*vt,(ce+1)*vt);(0,y.useEffect)(()=>{if(Se&&ht&&!_t){let e=ht.findIndex(e=>e.id===Se);if(e>=0){let t=Math.floor(e/vt);t!==ce&&le(t)}}},[Se]);let xt=z||N.size>0,St=e=>{P(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Ct=()=>{ht&&P(new Set(ht.map(e=>e.id)))},wt=()=>{P(new Set),B(!1)},Tt=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Et=()=>{p(new Set)},Dt=()=>{s(``),l(null),d(null),_(!1),b(!1),S(!1),w(null),E(`all`)},Ot=o||c||u||g||v||x||C||T!==`all`,kt=(0,y.useCallback)(e=>{e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&M(!0)},[]),At=(0,y.useCallback)(e=>{e.preventDefault(),e.currentTarget===e.target&&M(!1)},[]),jt=(0,y.useCallback)(t=>{t.preventDefault(),M(!1);let r=Array.from(t.dataTransfer.files).filter(e=>e.name.endsWith(`.3mf`));r.length>0?(A(r),O(!0)):t.dataTransfer.files.length>0&&n(e(`archives.page.only3mfSupported`),`warning`)},[n,e]),Mt=(0,y.useCallback)(e=>{let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable){e.key===`Escape`&&t.blur();return}switch(e.key){case`/`:e.preventDefault(),a.current?.focus();break;case`u`:case`U`:!e.metaKey&&!e.ctrlKey&&(e.preventDefault(),O(!0));break;case`Escape`:xt&&wt();break}},[xt]);return(0,y.useEffect)(()=>(document.addEventListener(`keydown`,Mt),()=>document.removeEventListener(`keydown`,Mt)),[Mt]),(0,K.jsxs)(`div`,{className:`p-4 md:p-8 relative`,onDragOver:kt,onDragLeave:At,onDrop:jt,children:[j&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none`,children:(0,K.jsxs)(`div`,{className:`border-4 border-dashed border-bambu-green rounded-xl p-12 text-center`,children:[(0,K.jsx)(Su,{className:`w-16 h-16 mx-auto mb-4 text-bambu-green`}),(0,K.jsx)(`p`,{className:`text-2xl font-semibold text-white mb-2`,children:`Drop .3mf files here`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`archives.releaseToUpload`)})]})}),xt&&(0,K.jsxs)(`div`,{className:`fixed bottom-6 left-1/2 -translate-x-1/2 z-40 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl px-4 py-3 flex items-center gap-4`,children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:wt,children:[(0,K.jsx)(Pu,{className:`w-4 h-4`}),`Close`]}),(0,K.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[N.size,` selected`]}),(0,K.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:Ct,children:`Select All`}),(0,K.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>te(!0),disabled:!i(`archives:update_own`,`archives:update_all`),title:i(`archives:update_own`,`archives:update_all`)?void 0:e(`archives.permission.noUpdateArchives`),children:[(0,K.jsx)(su,{className:`w-4 h-4`}),`Tags`]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>re(!0),disabled:!i(`archives:update_own`,`archives:update_all`),title:i(`archives:update_own`,`archives:update_all`)?void 0:e(`archives.permission.noUpdateArchives`),children:[(0,K.jsx)(nc,{className:`w-4 h-4`}),`Project`]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,disabled:!i(`archives:update_own`,`archives:update_all`),title:i(`archives:update_own`,`archives:update_all`)?void 0:e(`archives.permission.noUpdateArchives`),onClick:()=>{let r=Array.from(N);Promise.all(r.map(e=>Q.toggleFavorite(e))).then(()=>{t.invalidateQueries({queryKey:[`archives`]}),n(`Toggled favorites for ${r.length} archive${r.length===1?``:`s`}`)}).catch(()=>{n(e(`archives.toast.failedUpdateFavorites`),`error`)})},children:[(0,K.jsx)(nu,{className:`w-4 h-4`}),`Favorite`]}),(0,K.jsxs)($,{size:`sm`,className:`bg-red-500 hover:bg-red-600`,onClick:()=>ee(!0),disabled:!i(`archives:delete_own`,`archives:delete_all`),title:i(`archives:delete_own`,`archives:delete_all`)?void 0:e(`archives.permission.noDelete`),children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),`Delete`]})]}),L?.has_fallback&&!F&&(0,K.jsxs)(`div`,{className:`mb-6 rounded-lg border border-amber-500/30 bg-amber-500/10 px-4 py-3 flex items-start gap-3`,children:[(0,K.jsx)(ss,{className:`w-5 h-5 text-amber-400 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-amber-200`,children:e(`archives.no3mfBanner.title`)}),(0,K.jsxs)(`div`,{className:`text-xs text-amber-200/80 mt-1`,children:[e(`archives.no3mfBanner.body`),` `,(0,K.jsxs)(`a`,{href:`https://bambuddy.cool/wiki/getting-started/#step-4-enable-store-sent-files-on-external-storage`,target:`_blank`,rel:`noreferrer`,className:`underline hover:text-amber-100 inline-flex items-center gap-1`,children:[e(`archives.no3mfBanner.docsLink`),(0,K.jsx)(Us,{className:`w-3 h-3`})]})]})]}),(0,K.jsx)(`button`,{onClick:R,className:`text-amber-200/60 hover:text-amber-200 flex-shrink-0 p-1 -m-1`,title:e(`archives.no3mfBanner.dismissLabel`),"aria-label":e(`archives.no3mfBanner.dismissLabel`),children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-8`,children:[(0,K.jsx)(`div`,{children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,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)(wo,{className:`w-7 h-7 text-bambu-green`}),`Archives`]}),(0,K.jsxs)(`p`,{className:`text-bambu-gray mt-1`,children:[ht?.length||0,` of `,Ye?.length||0,` prints`]})]}),(0,K.jsx)(`select`,{className:`mt-0.5 px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray-light text-sm focus:border-bambu-green focus:outline-none`,value:oe,onChange:e=>se(e.target.value),children:ZFe.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.label},e.id))})]})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3 flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:()=>pe(!fe),disabled:me,children:[me?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Xs,{className:`w-4 h-4`}),`Export`]}),fe&&(0,K.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20`,children:[(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg`,onClick:async()=>{pe(!1),he(!0);try{let{blob:t,filename:r}=await Q.exportArchives({format:`csv`,printerId:c||void 0,status:oe===`failed`?`failed`:void 0,search:o||void 0}),i=URL.createObjectURL(t),a=document.createElement(`a`);a.href=i,a.download=r,a.click(),URL.revokeObjectURL(i),n(e(`archives.toast.exportDownloaded`))}catch{n(e(`archives.toast.exportFailed`),`error`)}finally{he(!1)}},children:[(0,K.jsx)(Zs,{className:`w-4 h-4`}),`Export as CSV`]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg`,onClick:async()=>{pe(!1),he(!0);try{let{blob:t,filename:r}=await Q.exportArchives({format:`xlsx`,printerId:c||void 0,status:oe===`failed`?`failed`:void 0,search:o||void 0}),i=URL.createObjectURL(t),a=document.createElement(`a`);a.href=i,a.download=r,a.click(),URL.revokeObjectURL(i),n(e(`archives.toast.exportDownloaded`))}catch{n(e(`archives.toast.exportFailed`),`error`)}finally{he(!1)}},children:[(0,K.jsx)(Xs,{className:`w-4 h-4`}),`Export as Excel`]})]})]}),N.size>=2&&N.size<=5&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>_e(!0),children:[(0,K.jsx)(pc,{className:`w-4 h-4`}),`Compare (`,N.size,`)`]}),!xt&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>B(!0),children:[(0,K.jsx)($l,{className:`w-4 h-4`}),`Select`]}),(0,K.jsxs)($,{onClick:()=>O(!0),disabled:!r(`archives:create`),title:r(`archives:create`)?void 0:e(`archives.permission.noCreate`),children:[(0,K.jsx)(Su,{className:`w-4 h-4`}),`Upload 3MF`]}),r(`archives:purge`)&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>xe(!0),title:e(`archivePurge.headerTooltip`),children:[(0,K.jsx)(hu,{className:`w-4 h-4 mr-2`}),e(`archivePurge.headerButton`)]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center border border-bambu-dark-tertiary rounded-lg overflow-hidden flex-shrink-0 w-fit mb-4`,children:[(0,K.jsx)(`button`,{className:`p-2 ${U===`grid`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,onClick:()=>ie(`grid`),title:e(`archives.gridView`),children:(0,K.jsx)(Pc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{className:`p-2 ${U===`list`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,onClick:()=>ie(`list`),title:e(`archives.listView`),children:(0,K.jsx)(Bc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{className:`p-2 ${U===`calendar`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,onClick:()=>ie(`calendar`),title:e(`archives.calendarView`),children:(0,K.jsx)(Go,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{className:`p-2 ${U===`log`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,onClick:()=>ie(`log`),title:e(`archives.logView`),children:(0,K.jsx)(gs,{className:`w-4 h-4`})})]}),U!==`log`&&(0,K.jsx)(pd,{className:`mb-6`,children:(0,K.jsxs)(hd,{className:`py-4`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-3 md:gap-4 md:items-center md:flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`w-full md:flex-1 relative md:min-w-[200px]`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{ref:a,type:`text`,placeholder:e(`archives.searchPlaceholder`),className:`w-full pl-10 pr-4 py-3 md:py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:o,onChange:e=>s(e.target.value)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 md:gap-4 overflow-x-auto pb-1 md:pb-0 -mx-4 px-4 md:mx-0 md:px-0 md:flex-wrap scrollbar-hide`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(lc,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:c||``,onChange:e=>l(e.target.value?Number(e.target.value):null),children:[(0,K.jsx)(`option`,{value:``,children:`All Printers`}),Ze?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(cl,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:u||``,onChange:e=>d(e.target.value||null),children:[(0,K.jsx)(`option`,{value:``,children:`All Materials`}),ft.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(Js,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:T,onChange:e=>E(e.target.value),children:[(0,K.jsx)(`option`,{value:`all`,children:`All Files`}),(0,K.jsx)(`option`,{value:`gcode`,children:`Sliced (GCODE)`}),(0,K.jsx)(`option`,{value:`source`,children:`Source Only`})]})]}),(0,K.jsxs)(`button`,{onClick:()=>_(!g),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${g?`bg-yellow-500/20 border-yellow-500 text-yellow-400`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,title:e(g?`archives.showAll`:`archives.showFavoritesOnly`),children:[(0,K.jsx)(nu,{className:`w-4 h-4 ${g?`fill-yellow-400`:``}`}),(0,K.jsx)(`span`,{className:`text-sm hidden md:inline`,children:`Favorites`})]}),(0,K.jsxs)(`button`,{onClick:()=>b(!v),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${v?`bg-red-500/20 border-red-500 text-red-400`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,title:e(v?`archives.showFailedPrints`:`archives.hideFailedPrints`),children:[(0,K.jsx)(ss,{className:`w-4 h-4 `}),(0,K.jsx)(`span`,{className:`text-sm hidden md:inline`,children:`Hide Failed`})]}),(0,K.jsxs)(`button`,{onClick:()=>S(!x),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${x?`bg-purple-500/20 border-purple-500 text-purple-400`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,title:e(`archives.hideDuplicates`),children:[(0,K.jsx)(Ds,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-sm hidden md:inline`,children:e(`archives.hideDuplicates`)})]}),mt.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(su,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:C||``,onChange:e=>w(e.target.value||null),children:[(0,K.jsx)(`option`,{value:``,children:`All Tags`}),mt.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),(0,K.jsx)(`button`,{onClick:()=>ye(!0),className:`p-2 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-green transition-colors`,title:e(`archives.manageTags`),children:(0,K.jsx)(Rl,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(Ao,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:ae,onChange:e=>W(e.target.value),children:[(0,K.jsx)(`option`,{value:`date-desc`,children:e(`archives.sortNewest`)}),(0,K.jsx)(`option`,{value:`date-asc`,children:e(`archives.sortOldest`)}),(0,K.jsxs)(`option`,{value:`name-asc`,children:[e(`archives.sortName`),` A-Z`]}),(0,K.jsxs)(`option`,{value:`name-desc`,children:[e(`archives.sortName`),` Z-A`]}),(0,K.jsx)(`option`,{value:`size-desc`,children:e(`archives.sortLargest`)}),(0,K.jsx)(`option`,{value:`size-asc`,children:e(`archives.sortSmallest`)})]})]})]}),Ot&&(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:Dt,className:`text-bambu-gray hover:text-white`,children:[(0,K.jsx)(Pu,{className:`w-4 h-4`}),`Reset`]})]}),pt.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`Colors:`}),f.size>1&&(0,K.jsx)(`button`,{onClick:()=>h(e=>e===`or`?`and`:`or`),className:`px-2 py-0.5 text-xs rounded transition-colors ${m===`and`?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,title:m===`or`?`Match ANY selected color`:`Match ALL selected colors`,children:m.toUpperCase()}),(0,K.jsx)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:pt.map(e=>(0,K.jsx)(`button`,{onClick:()=>Tt(e),className:`w-6 h-6 rounded-full border-2 transition-all ${f.has(e)?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:e},title:e},e))}),f.size>0&&(0,K.jsxs)(`button`,{onClick:Et,className:`text-xs text-bambu-gray hover:text-white flex items-center gap-1`,children:[(0,K.jsx)(Pu,{className:`w-3 h-3`}),`Clear`]})]})]})}),(0,K.jsx)(KFe,{}),Xe?(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`archives.loadingArchives`)}):ht?.length===0?(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`text-center py-12`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(o?`archives.noArchivesSearch`:`archives.noArchivesYet`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:`Archives are created automatically when prints complete`})]})}):U===`calendar`?(0,K.jsx)(pd,{className:`p-6`,children:(0,K.jsx)(iDe,{archives:ht||[],onArchiveClick:e=>{s(``),ie(`grid`),Ce(e.id)},highlightedArchiveId:Se})}):U===`grid`?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6`,children:bt?.map(t=>(0,K.jsx)(JFe,{archive:t,printerName:t.printer_id?dt.get(t.printer_id)||`Unknown`:t.sliced_for_model||`No Printer`,isSelected:N.has(t.id),onSelect:St,selectionMode:xt,projects:Qe,isHighlighted:t.id===Se,timeFormat:rt,preferredSlicer:it,useSlicerApi:at,currency:ot,t:e,onNavigateToArchive:Je},t.id))}),(0,K.jsx)(n6,{pageIndex:ce,pageSize:ue,totalRows:gt,totalPages:yt,onPageChange:le,onPageSizeChange:e=>{de(e),le(0)},t:e})]}):U===`list`?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(pd,{children:(0,K.jsxs)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-12 gap-4 px-4 py-3 text-xs text-bambu-gray font-medium`,children:[(0,K.jsx)(`div`,{className:`col-span-1`}),(0,K.jsx)(`div`,{className:`col-span-4`,children:`Name`}),(0,K.jsx)(`div`,{className:`col-span-2`,children:`Printer`}),(0,K.jsx)(`div`,{className:`col-span-2`,children:`Date`}),(0,K.jsx)(`div`,{className:`col-span-1`,children:`Size`}),(0,K.jsx)(`div`,{className:`col-span-2 text-right`,children:`Actions`})]}),bt?.map(t=>(0,K.jsx)(YFe,{archive:t,printerName:t.printer_id?dt.get(t.printer_id)||`Unknown`:t.sliced_for_model||`No Printer`,isSelected:N.has(t.id),onSelect:St,selectionMode:xt,projects:Qe,isHighlighted:t.id===Se,preferredSlicer:it,useSlicerApi:at,t:e,onNavigateToArchive:Je},t.id))]})}),(0,K.jsx)(n6,{pageIndex:ce,pageSize:ue,totalRows:gt,totalPages:yt,onPageChange:le,onPageSizeChange:e=>{de(e),le(0)},t:e})]}):U===`log`?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-3`,children:(0,K.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-3 md:items-center md:flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`flex-1 relative md:min-w-[200px]`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,placeholder:e(`archives.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:o,onChange:e=>{s(e.target.value),Fe(0)}})]}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:c||``,onChange:e=>{l(e.target.value?Number(e.target.value):null),Fe(0)},children:[(0,K.jsx)(`option`,{value:``,children:e(`archives.log.allPrinters`)}),Ze?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:Ee||``,onChange:e=>{De(e.target.value||null),Fe(0)},children:[(0,K.jsx)(`option`,{value:``,children:e(`archives.log.allUsers`)}),et?.map(e=>(0,K.jsx)(`option`,{value:e.username,children:e.username},e.id))]}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:Oe||``,onChange:e=>{ke(e.target.value||null),Fe(0)},children:[(0,K.jsx)(`option`,{value:``,children:e(`archives.log.allStatuses`)}),(0,K.jsx)(`option`,{value:`completed`,children:e(`archives.status.completed`)}),(0,K.jsx)(`option`,{value:`failed`,children:e(`archives.status.failed`)}),(0,K.jsx)(`option`,{value:`stopped`,children:e(`archives.status.stopped`)}),(0,K.jsx)(`option`,{value:`cancelled`,children:e(`archives.log.cancelled`)}),(0,K.jsx)(`option`,{value:`skipped`,children:e(`archives.log.skipped`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`label`,{className:`text-sm text-bambu-gray`,children:e(`archives.log.dateFrom`)}),(0,K.jsx)(`input`,{type:`date`,className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:Ae,onChange:e=>{je(e.target.value),Fe(0)}})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`label`,{className:`text-sm text-bambu-gray`,children:e(`archives.log.dateTo`)}),(0,K.jsx)(`input`,{type:`date`,className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:Me,onChange:e=>{Ne(e.target.value),Fe(0)}})]}),(0,K.jsx)(`div`,{className:`ml-auto`,children:(0,K.jsxs)($,{variant:`danger`,size:`sm`,onClick:()=>Le(!0),disabled:!r(`archives:delete_all`)||ct.isPending,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`archives.log.clearLog`)]})})]})})}),(0,K.jsx)(pd,{children:nt?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):tt?.items.length?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-bambu-gray text-left`,children:[(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.date`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.printName`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.printer`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.user`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.status`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.duration`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.filament`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium w-10`,"aria-label":e(`common.actions`)})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:tt.items.map(t=>(0,K.jsxs)(`tr`,{className:`hover:bg-bambu-dark-secondary/50`,children:[(0,K.jsx)(`td`,{className:`px-4 py-3 text-white whitespace-nowrap`,children:gf(t.started_at||t.created_at,rt)}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.thumbnail_path&&(0,K.jsx)(`img`,{src:Q.getPrintLogThumbnail(t.id),alt:``,className:`w-8 h-8 rounded object-cover flex-shrink-0`,onError:e=>{e.target.style.display=`none`}}),(0,K.jsx)(`span`,{className:`text-white break-words`,title:t.print_name||``,children:t.print_name||`—`})]})}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-bambu-gray-light`,children:t.printer_name||`—`}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-bambu-gray-light`,children:t.created_by_username||`—`}),(0,K.jsxs)(`td`,{className:`px-4 py-3`,children:[(0,K.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${t.status===`completed`?`bg-green-500/20 text-green-400`:t.status===`failed`?`bg-red-500/20 text-red-400`:t.status===`stopped`?`bg-yellow-500/20 text-yellow-400`:t.status===`cancelled`?`bg-orange-500/20 text-orange-400`:t.status===`skipped`?`bg-blue-500/20 text-blue-400`:`bg-gray-500/20 text-gray-400`}`,children:t.status}),t.failure_reason&&(0,K.jsx)(`span`,{className:`block text-[10px] text-bambu-gray mt-0.5`,children:e(`editArchive.failureReasons.${t.failure_reason}`,{defaultValue:t.failure_reason})})]}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-bambu-gray-light whitespace-nowrap`,children:t.duration_seconds?yf(t.duration_seconds):`—`}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[t.filament_color&&(0,K.jsx)(`div`,{className:`flex items-center gap-0.5 flex-wrap`,children:t.filament_color.split(`,`).map((e,t)=>{let n=e.trim();return(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:n.startsWith(`#`)?n:void 0},title:n},t)})}),(0,K.jsx)(`span`,{className:`text-bambu-gray-light text-xs`,children:t.filament_type||`—`})]})}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-right`,children:(0,K.jsxs)(`div`,{className:`inline-flex items-center gap-2`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{Ve(t),Ue(t.failure_reason||``),Ge(t.status)},disabled:ut.isPending||!(r(`archives:update_all`)||r(`archives:update_own`)),title:r(`archives:update_all`)||r(`archives:update_own`)?e(`archives.log.editEntryTitle`):e(`archives.permission.noEdit`),className:`text-bambu-gray hover:text-bambu-blue disabled:opacity-40 disabled:hover:text-bambu-gray transition-colors`,children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>ze(t.id),disabled:lt.isPending||!(r(`archives:delete_all`)||r(`archives:delete_own`)),title:r(`archives:delete_all`)||r(`archives:delete_own`)?e(`archives.log.deleteEntryTitle`):e(`archives.permission.noDelete`),className:`text-bambu-gray hover:text-red-400 disabled:opacity-40 disabled:hover:text-bambu-gray transition-colors`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})})]},t.id))})]})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-t border-bambu-dark-tertiary flex-wrap gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`archives.log.showing`,{count:Math.min(Pe+Ke,tt.total),total:tt.total})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:e(`archives.log.rowsPerPage`)}),(0,K.jsxs)(`select`,{className:`px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs focus:border-bambu-green focus:outline-none`,value:Ke,onChange:e=>{qe(Number(e.target.value)),Fe(0)},children:[(0,K.jsx)(`option`,{value:10,children:`10`}),(0,K.jsx)(`option`,{value:25,children:`25`}),(0,K.jsx)(`option`,{value:50,children:`50`}),(0,K.jsx)(`option`,{value:100,children:`100`})]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`archives.log.page`),` `,Math.floor(Pe/Ke)+1,` / `,Math.max(1,Math.ceil(tt.total/Ke))]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>Fe(Math.max(0,Pe-Ke)),disabled:Pe===0,children:(0,K.jsx)(ns,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>Fe(Pe+Ke),disabled:Pe+Ke>=tt.total,children:(0,K.jsx)(ts,{className:`w-4 h-4`})})]})]})]}):(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`archives.log.noEntries`)})})]}):null,D&&(0,K.jsx)(GEe,{onClose:()=>{O(!1),A([])},initialFiles:k}),be&&(0,K.jsx)(qEe,{onClose:()=>xe(!1)}),V&&(0,K.jsx)(Ed,{title:e(`archives.modal.deleteArchives`),message:e(`archives.modal.deleteArchivesConfirm`,{count:N.size}),confirmText:e(`archives.modal.deleteCount`,{count:N.size}),variant:`danger`,onConfirm:()=>{st.mutate(Array.from(N)),ee(!1)},onCancel:()=>ee(!1)}),H&&(0,K.jsx)(QEe,{selectedIds:Array.from(N),existingTags:mt,onClose:()=>te(!1)}),ne&&(0,K.jsx)($Ee,{selectedIds:Array.from(N),onClose:()=>re(!1)}),ge&&N.size>=2&&N.size<=5&&(0,K.jsx)(HFe,{archiveIds:Array.from(N),onClose:()=>{_e(!1),P(new Set),B(!1)}}),ve&&(0,K.jsx)(qFe,{onClose:()=>ye(!1)}),Ie&&(0,K.jsx)(Ed,{title:e(`archives.log.clearLogTitle`),message:e(`archives.log.clearLogConfirm`),confirmText:e(`archives.log.clearLogButton`),variant:`danger`,onConfirm:()=>{ct.mutate(),Le(!1)},onCancel:()=>Le(!1)}),Re!==null&&(0,K.jsx)(Ed,{title:e(`archives.log.deleteEntryTitle`),message:e(`archives.log.deleteEntryConfirm`),confirmText:e(`common.delete`),variant:`danger`,onConfirm:()=>{lt.mutate(Re),ze(null)},onCancel:()=>ze(null)}),Be!==null&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:()=>Ve(null),children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-md mx-4 p-6`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-4`,children:e(`archives.log.editEntryTitle`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4`,children:e(`archives.log.editEntryDescription`)}),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`editArchive.status`)}),(0,K.jsxs)(`select`,{value:We,onChange:e=>Ge(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`completed`,children:e(`archives.log.statuses.completed`,{defaultValue:`completed`})}),(0,K.jsx)(`option`,{value:`failed`,children:e(`archives.log.statuses.failed`,{defaultValue:`failed`})}),(0,K.jsx)(`option`,{value:`stopped`,children:e(`archives.log.statuses.stopped`,{defaultValue:`stopped`})}),(0,K.jsx)(`option`,{value:`cancelled`,children:e(`archives.log.statuses.cancelled`,{defaultValue:`cancelled`})}),(0,K.jsx)(`option`,{value:`skipped`,children:e(`archives.log.statuses.skipped`,{defaultValue:`skipped`})})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`editArchive.failureReason`)}),(0,K.jsxs)(`select`,{value:He,onChange:e=>Ue(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:``,children:e(`editArchive.selectReason`)}),qq.map(t=>(0,K.jsx)(`option`,{value:t,children:e(`editArchive.failureReasons.${t}`)},t))]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 mt-6`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>Ve(null),children:e(`common.cancel`)}),(0,K.jsx)($,{variant:`primary`,onClick:()=>{let e={};if(He!==(Be.failure_reason||``)&&(e.failure_reason=He||null),We!==Be.status&&(e.status=We),Object.keys(e).length===0){Ve(null);return}ut.mutate({id:Be.id,body:e})},disabled:ut.isPending,children:ut.isPending?e(`editArchive.saving`):e(`common.save`)})]})]})})]})}function n6({pageIndex:e,pageSize:t,totalRows:n,totalPages:r,onPageChange:i,onPageSizeChange:a,t:o}){let s=t===-1;if(r<=1&&!s)return null;let c=s?n||1:t;return(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-2 text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:s?`${n} ${o(`archives.prints`)}`:(0,K.jsxs)(K.Fragment,{children:[o(`archives.pagination.showing`),` `,e*c+1,` `,o(`archives.pagination.to`),` `,Math.min((e+1)*c,n),` `,o(`archives.pagination.of`),` `,n,` `,o(`archives.prints`)]})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:o(`archives.pagination.show`)}),(0,K.jsxs)(`select`,{value:t,onChange:e=>a(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[25,50,100,200].map(e=>(0,K.jsx)(`option`,{value:e,children:e},e)),(0,K.jsx)(`option`,{value:-1,children:o(`archives.pagination.all`)})]}),!s&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:()=>i(0),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(is,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>i(Math.max(0,e-1)),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(ns,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[o(`archives.pagination.page`),` `,e+1,` `,o(`archives.pagination.of`),` `,r]}),(0,K.jsx)(`button`,{onClick:()=>i(Math.min(r-1,e+1)),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(ts,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>i(r-1),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(as,{className:`w-4 h-4`})})]})]})]})}function $Fe(){var e=[...arguments];return(0,y.useMemo)(()=>t=>{e.forEach(e=>e(t))},e)}var r6=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function i6(e){let t=Object.prototype.toString.call(e);return t===`[object Window]`||t===`[object global]`}function a6(e){return`nodeType`in e}function o6(e){return e?i6(e)?e:a6(e)?e.ownerDocument?.defaultView??window:window:window}function s6(e){let{Document:t}=o6(e);return e instanceof t}function c6(e){return i6(e)?!1:e instanceof o6(e).HTMLElement}function l6(e){return e instanceof o6(e).SVGElement}function u6(e){return e?i6(e)?e.document:a6(e)?s6(e)?e:c6(e)||l6(e)?e.ownerDocument:document:document:document}var d6=r6?y.useLayoutEffect:y.useEffect;function f6(e){let t=(0,y.useRef)(e);return d6(()=>{t.current=e}),(0,y.useCallback)(function(){var e=[...arguments];return t.current==null?void 0:t.current(...e)},[])}function eIe(){let e=(0,y.useRef)(null);return[(0,y.useCallback)((t,n)=>{e.current=setInterval(t,n)},[]),(0,y.useCallback)(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[])]}function p6(e,t){t===void 0&&(t=[e]);let n=(0,y.useRef)(e);return d6(()=>{n.current!==e&&(n.current=e)},t),n}function m6(e,t){let n=(0,y.useRef)();return(0,y.useMemo)(()=>{let t=e(n.current);return n.current=t,t},[...t])}function h6(e){let t=f6(e),n=(0,y.useRef)(null);return[n,(0,y.useCallback)(e=>{e!==n.current&&t?.(e,n.current),n.current=e},[])]}function g6(e){let t=(0,y.useRef)();return(0,y.useEffect)(()=>{t.current=e},[e]),t.current}var _6={};function v6(e,t){return(0,y.useMemo)(()=>{if(t)return t;let n=_6[e]==null?0:_6[e]+1;return _6[e]=n,e+`-`+n},[e,t])}function y6(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>{let r=Object.entries(n);for(let[n,i]of r){let r=t[n];r!=null&&(t[n]=r+e*i)}return t},{...t})}}var b6=y6(1),x6=y6(-1);function tIe(e){return`clientX`in e&&`clientY`in e}function S6(e){if(!e)return!1;let{KeyboardEvent:t}=o6(e.target);return t&&e instanceof t}function nIe(e){if(!e)return!1;let{TouchEvent:t}=o6(e.target);return t&&e instanceof t}function C6(e){if(nIe(e)){if(e.touches&&e.touches.length){let{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){let{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return tIe(e)?{x:e.clientX,y:e.clientY}:null}var w6=Object.freeze({Translate:{toString(e){if(!e)return;let{x:t,y:n}=e;return`translate3d(`+(t?Math.round(t):0)+`px, `+(n?Math.round(n):0)+`px, 0)`}},Scale:{toString(e){if(!e)return;let{scaleX:t,scaleY:n}=e;return`scaleX(`+t+`) scaleY(`+n+`)`}},Transform:{toString(e){if(e)return[w6.Translate.toString(e),w6.Scale.toString(e)].join(` `)}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+` `+n+`ms `+r}}}),T6=`a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]`;function rIe(e){return e.matches(T6)?e:e.querySelector(T6)}var iIe={display:`none`};function aIe(e){let{id:t,value:n}=e;return y.createElement(`div`,{id:t,style:iIe},n)}function oIe(e){let{id:t,announcement:n,ariaLiveType:r=`assertive`}=e;return y.createElement(`div`,{id:t,style:{position:`fixed`,top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:`hidden`,clip:`rect(0 0 0 0)`,clipPath:`inset(100%)`,whiteSpace:`nowrap`},role:`status`,"aria-live":r,"aria-atomic":!0},n)}function sIe(){let[e,t]=(0,y.useState)(``);return{announce:(0,y.useCallback)(e=>{e!=null&&t(e)},[]),announcement:e}}var E6=(0,y.createContext)(null);function cIe(e){let t=(0,y.useContext)(E6);(0,y.useEffect)(()=>{if(!t)throw Error(`useDndMonitor must be used within a children of `);return t(e)},[e,t])}function lIe(){let[e]=(0,y.useState)(()=>new Set),t=(0,y.useCallback)(t=>(e.add(t),()=>e.delete(t)),[e]);return[(0,y.useCallback)(t=>{let{type:n,event:r}=t;e.forEach(e=>e[n]?.call(e,r))},[e]),t]}var uIe={draggable:` + [&::-webkit-slider-thumb]:cursor-pointer`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray w-12`,children:xf(p)})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>{let e=o.current;e&&(e.currentTime=Math.max(0,e.currentTime-5))},className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:`Skip back 5s`,children:(0,K.jsx)(Gl,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:_,className:`p-2 bg-bambu-green hover:bg-bambu-green-dark rounded-lg transition-colors`,children:s?(0,K.jsx)(ul,{className:`w-5 h-5 text-white`}):(0,K.jsx)(hl,{className:`w-5 h-5 text-white`})}),(0,K.jsx)(`button`,{onClick:()=>{let e=o.current;e&&(e.currentTime=Math.min(p,e.currentTime+5))},className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:`Skip forward 5s`,children:(0,K.jsx)(Kl,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`Speed:`}),(0,K.jsx)(`div`,{className:`flex gap-1`,children:HFe.map(e=>(0,K.jsxs)(`button`,{onClick:()=>u(e),className:`px-2 py-1 text-xs rounded transition-colors ${l===e?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:bg-bambu-dark-tertiary/80`}`,children:[e,`x`]},e))})]})]})]})]})]}),h&&r&&(0,K.jsx)(VFe,{archiveId:r,timelapseSrc:e,onClose:()=>g(!1),onSave:a})]})}function UFe({archiveIds:e,onClose:t}){(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let{data:n,isLoading:r,error:i}=q({queryKey:[`archive-comparison`,e],queryFn:()=>Q.compareArchives(e)});return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg max-w-4xl w-full max-h-[90vh] flex flex-col border border-bambu-dark-tertiary`,onClick: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)(`h3`,{className:`text-lg font-semibold text-white`,children:[`Compare Archives (`,e.length,`)`]}),(0,K.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white p-1`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-auto p-4 bg-bambu-dark-secondary`,children:r?(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`})}):i?(0,K.jsxs)(`div`,{className:`text-center py-12 text-red-400`,children:[(0,K.jsx)(vu,{className:`w-12 h-12 mx-auto mb-4 opacity-50`}),(0,K.jsx)(`p`,{children:`Failed to load comparison`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:i instanceof Error?i.message:`Unknown error`})]}):n?(0,K.jsx)(WFe,{comparison:n}):null}),(0,K.jsx)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsx)($,{variant:`secondary`,onClick:t,className:`w-full`,children:`Close`})})]})})}function WFe({comparison:e}){return(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`text-left text-sm text-bambu-gray font-medium pb-2 pr-4 min-w-[150px]`,children:`Setting`}),e.archives.map(e=>(0,K.jsxs)(`th`,{className:`text-left text-sm font-medium pb-2 px-2 min-w-[120px]`,children:[(0,K.jsx)(`div`,{className:`text-white truncate max-w-[150px]`,title:e.print_name,children:e.print_name}),(0,K.jsx)(`div`,{className:`text-xs ${e.status===`completed`?`text-status-ok`:e.status===`failed`?`text-status-error`:`text-bambu-gray`}`,children:e.status})]},e.id))]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-bambu-gray/20`,children:e.comparison.map(e=>(0,K.jsxs)(`tr`,{className:e.has_difference?`bg-yellow-500/5`:``,children:[(0,K.jsx)(`td`,{className:`py-2 pr-4 text-sm`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.has_difference&&(0,K.jsx)(vu,{className:`w-3 h-3 text-yellow-400 flex-shrink-0`}),(0,K.jsx)(`span`,{className:e.has_difference?`text-yellow-400`:`text-bambu-gray`,children:e.label})]})}),e.values.map((t,n)=>(0,K.jsxs)(`td`,{className:`py-2 px-2 text-sm text-white`,children:[t??(0,K.jsx)(`span`,{className:`text-bambu-gray/50`,children:`-`}),e.unit&&t!==null&&(0,K.jsx)(`span`,{className:`text-bambu-gray ml-1`,children:e.unit})]},n))]},e.field))})]})}),e.differences.length>0&&(0,K.jsxs)(`div`,{className:`p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg`,children:[(0,K.jsxs)(`h4`,{className:`text-sm font-medium text-yellow-400 mb-2 flex items-center gap-2`,children:[(0,K.jsx)(vu,{className:`w-4 h-4`}),e.differences.length,` Difference`,e.differences.length>1?`s`:``,` Found`]}),(0,K.jsxs)(`ul`,{className:`text-sm text-white/80 space-y-1`,children:[e.differences.slice(0,5).map(e=>(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`span`,{className:`text-yellow-400`,children:e.label}),`: `,e.values.join(` vs `),` `,e.unit||``]},e.field)),e.differences.length>5&&(0,K.jsxs)(`li`,{className:`text-bambu-gray`,children:[`...and `,e.differences.length-5,` more`]})]})]}),e.success_correlation.has_both_outcomes?(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`h4`,{className:`text-sm font-medium text-white mb-3 flex items-center gap-2`,children:[(0,K.jsx)($o,{className:`w-4 h-4 text-bambu-green`}),`Success/Failure Analysis`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm mb-3`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-green`,children:[e.success_correlation.successful_count,` successful`]}),(0,K.jsxs)(`span`,{className:`text-red-400`,children:[e.success_correlation.failed_count,` failed`]})]}),e.success_correlation.insights&&e.success_correlation.insights.length>0?(0,K.jsx)(`div`,{className:`space-y-2`,children:e.success_correlation.insights.map(e=>(0,K.jsxs)(`div`,{className:`text-sm p-2 bg-bambu-dark-secondary rounded`,children:[(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[e.label,`:`]}),` `,(0,K.jsx)(`span`,{className:`text-white/80`,children:e.insight})]},e.field))}):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`No clear correlations found between settings and outcomes.`})]}):(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-lg text-sm text-bambu-gray`,children:(0,K.jsx)(`p`,{children:e.success_correlation.message||`Need both successful and failed prints for correlation analysis.`})})]})}function GFe(e){let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`Just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function KFe({upload:e,projects:t,onArchive:n,onDiscard:r,isArchiving:i,isDiscarding:a}){let[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(e.tags||``),[u,d]=(0,y.useState)(e.notes||``),[f,p]=(0,y.useState)(e.project_id),[m,h]=(0,y.useState)(!1);return(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`py-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(qs,{className:`w-8 h-8 text-bambu-green flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,title:e.filename,children:e.display_name||e.filename}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:yd(e.file_size)}),(0,K.jsx)(`span`,{children:`·`}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),GFe(e.uploaded_at)]}),e.source_ip&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{children:`·`}),(0,K.jsxs)(`span`,{children:[`from `,e.source_ip]})]})]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>s(!o),className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:o?(0,K.jsx)(rs,{className:`w-5 h-5`}):(0,K.jsx)(es,{className:`w-5 h-5`})}),(0,K.jsx)($,{variant:`primary`,size:`sm`,onClick:()=>n(e.id,{tags:c,notes:u,project_id:f||void 0}),disabled:i,children:i?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(wo,{className:`w-4 h-4`}),`Archive`]})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>h(!0),disabled:a,children:a?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hu,{className:`w-4 h-4 text-red-400`})})]})]}),m&&(0,K.jsx)(Ed,{title:`Discard Upload`,message:`Are you sure you want to discard "${e.filename}"? This cannot be undone.`,confirmText:`Discard`,variant:`danger`,onConfirm:()=>{r(e.id),h(!1)},onCancel:()=>h(!1)}),o&&(0,K.jsxs)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Tags`}),(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`e.g., functional, prototype, gift`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white placeholder-bambu-gray text-sm`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Notes`}),(0,K.jsx)(`textarea`,{value:u,onChange:e=>d(e.target.value),placeholder:`Add notes about this print...`,rows:2,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white placeholder-bambu-gray text-sm resize-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Project`}),(0,K.jsxs)(`select`,{value:f||``,onChange:e=>p(e.target.value?Number(e.target.value):null),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm`,children:[(0,K.jsx)(`option`,{value:``,children:`No project`}),t.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]})]})})}function qFe(){let e=Qa(),{showToast:t}=xd(),[n,r]=(0,y.useState)(!1),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(new Set),[c,l]=(0,y.useState)(new Set),{data:u,isLoading:d}=q({queryKey:[`pending-uploads`],queryFn:$u.list,refetchInterval:1e4}),{data:f}=q({queryKey:[`projects`],queryFn:()=>Q.getProjects(),select:e=>[...e].sort((e,t)=>e.name.localeCompare(t.name))}),p=J({mutationFn:({id:e,data:t})=>$u.archive(e,t),onMutate:({id:e})=>{s(t=>new Set(t).add(e))},onSettled:(e,t,{id:n})=>{s(e=>{let t=new Set(e);return t.delete(n),t})},onSuccess:n=>{e.invalidateQueries({queryKey:[`pending-uploads`]}),e.invalidateQueries({queryKey:[`archives`]}),t(`Archived: ${n.print_name}`)},onError:e=>{t(e.message||`Failed to archive`,`error`)}}),m=J({mutationFn:e=>$u.discard(e),onMutate:e=>{l(t=>new Set(t).add(e))},onSettled:(e,t,n)=>{l(e=>{let t=new Set(e);return t.delete(n),t})},onSuccess:()=>{e.invalidateQueries({queryKey:[`pending-uploads`]}),t(`Upload discarded`)},onError:e=>{t(e.message||`Failed to discard`,`error`)}}),h=J({mutationFn:$u.archiveAll,onSuccess:n=>{e.invalidateQueries({queryKey:[`pending-uploads`]}),e.invalidateQueries({queryKey:[`archives`]}),t(`Archived ${n.archived} files${n.failed>0?`, ${n.failed} failed`:``}`)},onError:e=>{t(e.message||`Failed to archive all`,`error`)}}),g=J({mutationFn:$u.discardAll,onSuccess:n=>{e.invalidateQueries({queryKey:[`pending-uploads`]}),t(`Discarded ${n.discarded} files`)},onError:e=>{t(e.message||`Failed to discard all`,`error`)}});return d?(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-8 flex justify-center`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})})}):!u||u.length===0?null:(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(pd,{className:`border-l-4 border-l-yellow-500`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Su,{className:`w-5 h-5 text-yellow-500`}),(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[`Pending Uploads (`,u.length,`)`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($,{variant:`primary`,size:`sm`,onClick:()=>r(!0),disabled:h.isPending,children:h.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(wo,{className:`w-4 h-4`}),`Archive All`]})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>a(!0),disabled:g.isPending,children:g.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),`Discard All`]})})]})]})}),(0,K.jsxs)(hd,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:`These files were uploaded via the virtual printer. Review and archive them to add to your collection.`}),(0,K.jsx)(`div`,{className:`space-y-3`,children:u.map(e=>(0,K.jsx)(KFe,{upload:e,projects:f||[],onArchive:(e,t)=>p.mutate({id:e,data:t}),onDiscard:e=>m.mutate(e),isArchiving:o.has(e.id),isDiscarding:c.has(e.id)},e.id))})]})]}),n&&(0,K.jsx)(Ed,{title:`Archive All Uploads`,message:`Are you sure you want to archive all ${u.length} pending uploads?`,confirmText:`Archive All`,onConfirm:()=>{h.mutate(),r(!1)},onCancel:()=>r(!1)}),i&&(0,K.jsx)(Ed,{title:`Discard All Uploads`,message:`Are you sure you want to discard all ${u.length} pending uploads? This cannot be undone.`,confirmText:`Discard All`,variant:`danger`,onConfirm:()=>{g.mutate(),a(!1)},onCancel:()=>a(!1)})]})}function JFe({onClose:e}){let t=Qa(),{showToast:n}=xd(),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(`count`);(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&(a?o(null):l?u(null):e())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,a,l]);let{data:p,isLoading:m}=q({queryKey:[`tags`],queryFn:Q.getTags}),h=J({mutationFn:({oldName:e,newName:t})=>Q.renameTag(e,t),onSuccess:(e,{oldName:r,newName:i})=>{t.invalidateQueries({queryKey:[`tags`]}),t.invalidateQueries({queryKey:[`archives`]}),n(`Renamed "${r}" to "${i}" in ${e.affected} archive${e.affected===1?``:`s`}`),o(null)},onError:e=>{n(e.message||`Failed to rename tag`,`error`)}}),g=J({mutationFn:e=>Q.deleteTag(e),onSuccess:(e,r)=>{t.invalidateQueries({queryKey:[`tags`]}),t.invalidateQueries({queryKey:[`archives`]}),n(`Deleted "${r}" from ${e.affected} archive${e.affected===1?``:`s`}`),u(null)},onError:e=>{n(e.message||`Failed to delete tag`,`error`)}}),_=e=>{o(e.name),c(e.name),u(null)},v=()=>{o(null),c(``)},b=()=>{if(!a||!s.trim())return;let e=s.trim();if(e===a){v();return}h.mutate({oldName:a,newName:e})},x=e=>{e.key===`Enter`?(e.preventDefault(),b()):e.key===`Escape`&&(e.preventDefault(),v())},S=e=>{u(e),o(null)},C=()=>{l&&g.mutate(l)},w=p?.filter(e=>e.name.toLowerCase().includes(r.toLowerCase())).sort((e,t)=>d===`count`&&t.count-e.count||e.name.localeCompare(t.name)),T=p?.reduce((e,t)=>e+t.count,0)||0;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)(pd,{className:`w-full max-w-lg max-h-[80vh] flex flex-col`,children:(0,K.jsxs)(hd,{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 flex-shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(su,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:`Manage Tags`})]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,placeholder:`Search tags...`,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:r,onChange:e=>i(e.target.value)})]}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:d,onChange:e=>f(e.target.value),children:[(0,K.jsx)(`option`,{value:`count`,children:`Sort by Count`}),(0,K.jsx)(`option`,{value:`name`,children:`Sort by Name`})]})]}),p&&(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:[p.length,` tag`,p.length===1?``:`s`,` across `,T,` usage`,T===1?``:`s`]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto min-h-0 p-4`,children:m?(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`})}):w?.length?(0,K.jsx)(`div`,{className:`space-y-2`,children:w.map(e=>(0,K.jsx)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors group`,children:a===e.name?(0,K.jsxs)(`div`,{className:`flex-1 flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,className:`flex-1 px-2 py-1 bg-bambu-dark-tertiary border border-bambu-green rounded text-white text-sm focus:outline-none`,value:s,onChange:e=>c(e.target.value),onKeyDown:x,autoFocus:!0}),(0,K.jsx)($,{size:`sm`,variant:`primary`,onClick:b,disabled:!s.trim()||h.isPending,className:`p-1.5`,children:h.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)($o,{className:`w-4 h-4`})}),(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:v,className:`p-1.5`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}):l===e.name?(0,K.jsxs)(`div`,{className:`flex-1 flex items-center gap-2`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-yellow-400 flex-shrink-0`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray-light flex-1`,children:[`Delete "`,e.name,`" from `,e.count,` archive`,e.count===1?``:`s`,`?`]}),(0,K.jsx)($,{size:`sm`,variant:`danger`,onClick:C,disabled:g.isPending,className:`p-1.5`,children:g.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hu,{className:`w-4 h-4`})}),(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>u(null),className:`p-1.5`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(su,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-white flex-1 truncate`,children:e.name}),(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray text-xs`,children:e.count}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,K.jsx)(`button`,{onClick:()=>_(e),className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors`,title:`Rename tag`,children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>S(e.name),className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors`,title:`Delete tag`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]})},e.name))}):(0,K.jsx)(`div`,{className:`text-center py-8 text-bambu-gray`,children:r?`No tags match your search`:`No tags found`})}),(0,K.jsx)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:(0,K.jsx)($,{variant:`secondary`,onClick:e,className:`flex-1`,children:`Close`})})]})})})}function e6(e){let t=e.filename;if(t){let e=t.toLowerCase();if(e.endsWith(`.gcode`)||e.includes(`.gcode.`))return!0}return!!(e.total_layers||e.print_time_seconds)}async function t6(e,t,n,r){try{if(n===`source`){let{token:n}=await Q.createSourceSlicerToken(e),i=Q.getSourceSlicerDownloadUrl(e,n,t);Uq(`${window.location.origin}${i}`,r)}else{let{token:n}=await Q.createArchiveSlicerToken(e),i=Q.getArchiveSlicerDownloadUrl(e,n,t);Uq(`${window.location.origin}${i}`,r)}}catch{let i=n===`source`?Q.getSource3mfForSlicer(e,t):Q.getArchiveForSlicer(e,t);Uq(`${window.location.origin}${i}`,r)}}function YFe({archive:e,printerName:t,isSelected:n,onSelect:r,selectionMode:i,projects:a,isHighlighted:o,timeFormat:s=`system`,preferredSlicer:c=`bambu_studio`,useSlicerApi:l=!1,currency:u,t:d,onNavigateToArchive:f}){o&&console.log(`ArchiveCard isHighlighted=true for archive:`,e.id);let p=Qa(),{showToast:m}=xd(),{hasPermission:h,canModify:g}=sd(),_=Gq(),v=Yn(),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),O=q({queryKey:[`archive`,e.id,`delete-impact`],queryFn:()=>Q.getArchiveDeleteImpact(e.id),enabled:w,staleTime:0}),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)([]),[z,B]=(0,y.useState)(!1),[V,ee]=(0,y.useState)(!1),[H,te]=(0,y.useState)(!1),[ne,re]=(0,y.useState)(!1),[U,ie]=(0,y.useState)(!1),[ae,W]=(0,y.useState)(!1),[oe,se]=(0,y.useState)(!1),[ce,le]=(0,y.useState)(null),[ue,de]=(0,y.useState)(null),[fe,pe]=(0,y.useState)(!1),[me,he]=(0,y.useState)(null),ge=(0,y.useRef)(null),_e=(0,y.useRef)(null),ve=(0,y.useRef)(null),{data:ye}=q({queryKey:[`archive-plates`,e.id],queryFn:()=>Q.getArchivePlates(e.id),enabled:fe,staleTime:300*1e3}),be=e.duplicate_sequence??0,xe=e.original_archive_id??null,Se=ye?.plates??[],Ce=ye?.is_multi_plate??!1,we=ue??0,Te=async()=>{try{let t=await Q.getArchivePlates(e.id);if(t.has_gcode===!1){m(d(`archives.platePicker.noGcode`),`info`);return}if(t.is_multi_plate&&t.plates.length>1){he(t.plates);return}}catch{}v(`/gcode-viewer?archive=${e.id}`)},Ee=J({mutationFn:()=>Q.deleteArchiveTimelapse(e.id),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.timelapseRemoved`))},onError:e=>{m(e.message||d(`archives.toast.failedRemoveTimelapse`),`error`)}}),De=J({mutationFn:t=>Q.uploadArchiveTimelapse(e.id,t),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.timelapseUploaded`,{filename:e.filename}))},onError:e=>{m(e.message||d(`archives.toast.failedUploadTimelapse`),`error`)}}),Oe=J({mutationFn:t=>Q.uploadSource3mf(e.id,t),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.source3mfAttached`,{filename:e.filename}))},onError:e=>{m(e.message||d(`archives.toast.failedUploadSource3mf`),`error`)}}),ke=J({mutationFn:()=>Q.deleteSource3mf(e.id),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.source3mfRemoved`))},onError:e=>{m(e.message||d(`archives.toast.failedRemoveSource3mf`),`error`)}}),Ae=J({mutationFn:t=>Q.uploadF3d(e.id,t),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.f3dAttached`,{filename:e.filename}))},onError:e=>{m(e.message||d(`archives.toast.failedUploadF3d`),`error`)}}),je=J({mutationFn:()=>Q.deleteF3d(e.id),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.f3dRemoved`))},onError:e=>{m(e.message||d(`archives.toast.failedRemoveF3d`),`error`)}}),Me=J({mutationFn:()=>Q.scanArchiveTimelapse(e.id),onSuccess:e=>{e.status===`attached`?(p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.timelapseAttached`,{filename:e.filename}))):e.status===`exists`?m(d(`archives.toast.timelapseAlreadyAttached`)):e.status===`not_found`&&e.available_files&&e.available_files.length>0?(R(e.available_files),I(!0)):m(e.message||d(`archives.toast.noMatchingTimelapse`),`warning`)},onError:e=>{m(e.message||d(`archives.toast.failedScanTimelapse`),`error`)}}),Ne=J({mutationFn:t=>Q.selectArchiveTimelapse(e.id,t),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.timelapseAttached`,{filename:e.filename})),I(!1),R([])},onError:e=>{m(e.message||d(`archives.toast.failedAttachTimelapse`),`error`)}}),Pe=J({mutationFn:t=>Q.deleteArchive(e.id,t),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.archiveDeleted`))},onError:()=>{m(d(`archives.toast.failedDeleteArchive`),`error`)}}),Fe=J({mutationFn:()=>Q.toggleFavorite(e.id),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(e.is_favorite?d(`archives.toast.addedToFavorites`):d(`archives.toast.removedFromFavorites`))}}),{data:Ie}=q({queryKey:[`archive-folders`,e.id],queryFn:()=>Q.getLibraryFoldersByArchive(e.id)}),Le=J({mutationFn:t=>Q.updateArchive(e.id,{project_id:t}),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),p.invalidateQueries({queryKey:[`projects`]}),m(d(`archives.toast.projectUpdated`))},onError:()=>{m(d(`archives.toast.failedUpdateProject`),`error`)}}),Re=e=>{e.preventDefault(),le({x:e.clientX,y:e.clientY})},ze=[...e6(e)?[{label:d(`archives.menu.print`),icon:(0,K.jsx)(bl,{className:`w-4 h-4`}),onClick:()=>x(!0),disabled:!e.file_path||!g(`archives`,`reprint`,e.created_by_id),title:e.file_path?g(`archives`,`reprint`,e.created_by_id)?void 0:d(`archives.permission.noReprint`):d(`archives.card.noFileForReprint`)},{label:d(`archives.menu.schedule`),icon:(0,K.jsx)(qo,{className:`w-4 h-4`}),onClick:()=>re(!0),disabled:!e.file_path||!h(`queue:create`),title:e.file_path?h(`queue:create`)?void 0:d(`archives.permission.noAddToQueue`):d(`archives.card.noFileForReprint`)},{label:d(`archives.menu.openInBambuStudio`),icon:(0,K.jsx)(Us,{className:`w-4 h-4`}),onClick:()=>{let t=e.print_name||e.filename||`model`;t6(e.id,t,`file`,c)},disabled:!e.file_path,title:e.file_path?void 0:d(`archives.card.noFileForReprint`)}]:[{label:d(`archives.menu.slice`),icon:l?(0,K.jsx)(ws,{className:`w-4 h-4`}):(0,K.jsx)(Us,{className:`w-4 h-4`}),onClick:()=>{if(l)C(!0);else{let t=e.print_name||e.filename||`model`;t6(e.id,t,`file`,c)}}}],{label:e.external_url?d(`archives.menu.externalLink`):d(`archives.menu.viewOnMakerWorld`),icon:(0,K.jsx)(hc,{className:`w-4 h-4`}),onClick:()=>{let t=e.external_url||e.makerworld_url;t&&window.open(t,`_blank`)},disabled:!e.external_url&&!e.makerworld_url},{label:``,divider:!0,onClick:()=>{}},{label:d(`archives.menu.preview3d`),icon:(0,K.jsx)(Bo,{className:`w-4 h-4`}),onClick:()=>{Te()}},{label:d(`archives.menu.viewTimelapse`),icon:(0,K.jsx)($s,{className:`w-4 h-4`}),onClick:()=>P(!0),disabled:!e.timelapse_path},{label:d(`archives.menu.scanForTimelapse`),icon:(0,K.jsx)(jl,{className:`w-4 h-4`}),onClick:()=>Me.mutate(),disabled:!e.printer_id||!!e.timelapse_path||Me.isPending||!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},{label:d(`archives.menu.uploadTimelapse`),icon:(0,K.jsx)(Su,{className:`w-4 h-4`}),onClick:()=>ve.current?.click(),disabled:!!e.timelapse_path||!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},...e.timelapse_path?[{label:d(`archives.menu.removeTimelapse`),icon:(0,K.jsx)(hu,{className:`w-4 h-4`}),onClick:()=>se(!0),danger:!0,disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)}]:[],{label:``,divider:!0,onClick:()=>{}},{label:e.source_3mf_path?d(`archives.menu.downloadSource3mf`):d(`archives.menu.uploadSource3mf`),icon:(0,K.jsx)(Js,{className:`w-4 h-4`}),onClick:()=>{e.source_3mf_path?Q.downloadSource3mf(e.id).catch(e=>{console.error(`Source 3MF download failed:`,e)}):ge.current?.click()},disabled:!e.source_3mf_path&&!g(`archives`,`update`,e.created_by_id),title:!e.source_3mf_path&&!g(`archives`,`update`,e.created_by_id)?d(`archives.permission.noUploadFiles`):void 0},...e.source_3mf_path?[{label:d(`archives.menu.replaceSource3mf`),icon:(0,K.jsx)(Su,{className:`w-4 h-4`}),onClick:()=>ge.current?.click(),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},{label:d(`archives.menu.removeSource3mf`),icon:(0,K.jsx)(hu,{className:`w-4 h-4`}),onClick:()=>ie(!0),danger:!0,disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)}]:[],{label:e.f3d_path?d(`archives.menu.replaceF3d`):d(`archives.menu.uploadF3d`),icon:(0,K.jsx)(Bo,{className:`w-4 h-4`}),onClick:()=>_e.current?.click(),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},...e.f3d_path?[{label:d(`archives.menu.downloadF3d`),icon:(0,K.jsx)(Is,{className:`w-4 h-4`}),onClick:()=>{Q.downloadF3d(e.id).catch(e=>{console.error(`F3D download failed:`,e)})}},{label:d(`archives.menu.removeF3d`),icon:(0,K.jsx)(hu,{className:`w-4 h-4`}),onClick:()=>W(!0),danger:!0,disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)}]:[],{label:``,divider:!0,onClick:()=>{}},{label:d(`archives.menu.download`),icon:(0,K.jsx)(Is,{className:`w-4 h-4`}),onClick:()=>{Q.downloadArchive(e.id,`${e.print_name||e.filename}.3mf`).catch(e=>{console.error(`Archive download failed:`,e)})},disabled:!h(`archives:read`),title:h(`archives:read`)?void 0:d(`archives.permission.noDownload`)},{label:d(`archives.menu.copyDownloadLink`),icon:(0,K.jsx)(Ds,{className:`w-4 h-4`}),onClick:()=>{let t=`${window.location.origin}${Q.getArchiveDownload(e.id)}`;navigator.clipboard.writeText(t).then(()=>{m(d(`archives.toast.linkCopied`))}).catch(()=>{m(d(`archives.toast.failedCopyLink`),`error`)})},disabled:!h(`archives:read`),title:h(`archives:read`)?void 0:d(`archives.permission.noCopyLink`)},{label:d(`archives.menu.qrCode`),icon:(0,K.jsx)(xl,{className:`w-4 h-4`}),onClick:()=>B(!0)},{label:e.photos?.length?d(`archives.menu.viewPhotosCount`,{count:e.photos.length}):d(`archives.menu.viewPhotos`),icon:(0,K.jsx)(Jo,{className:`w-4 h-4`}),onClick:()=>ee(!0),disabled:!e.photos?.length},{label:d(`archives.menu.projectPage`),icon:(0,K.jsx)(Zs,{className:`w-4 h-4`}),onClick:()=>te(!0)},{label:``,divider:!0,onClick:()=>{}},{label:e.is_favorite?d(`archives.menu.removeFromFavorites`):d(`archives.menu.addToFavorites`),icon:(0,K.jsx)(nu,{className:`w-4 h-4 ${e.is_favorite?`fill-yellow-400 text-yellow-400`:``}`}),onClick:()=>Fe.mutate(),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},{label:d(`archives.menu.edit`),icon:(0,K.jsx)(pl,{className:`w-4 h-4`}),onClick:()=>A(!0),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},{label:d(`archives.menu.printLog`),icon:(0,K.jsx)(wc,{className:`w-4 h-4`}),onClick:()=>M(!0)},...e.project_id&&e.project_name?[{label:d(`archives.menu.goToProject`,{name:e.project_name}),icon:(0,K.jsx)(nc,{className:`w-4 h-4 text-bambu-green`}),onClick:()=>window.location.href=`/projects`}]:[],{label:d(`archives.menu.addToProject`),icon:(0,K.jsx)(nc,{className:`w-4 h-4`}),onClick:()=>{},disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`),submenuSearchPlaceholder:(a?.filter(e=>e.status===`active`).length??0)>5?d(`archives.menu.searchProjects`):void 0,submenu:(()=>{let t=[];if(e.project_id&&t.push({label:d(`archives.menu.removeFromProject`),icon:(0,K.jsx)(Pu,{className:`w-4 h-4`}),onClick:()=>Le.mutate(null),disabled:!g(`archives`,`update`,e.created_by_id)}),!a)t.push({label:d(`archives.menu.loading`),icon:(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),onClick:()=>{},disabled:!0});else{let n=a.filter(e=>e.status===`active`).sort((e,t)=>e.name.localeCompare(t.name));n.length===0?t.push({label:d(`archives.menu.noProjectsAvailable`),icon:(0,K.jsx)(nc,{className:`w-4 h-4 opacity-50`}),onClick:()=>{},disabled:!0}):n.forEach(n=>{t.push({label:n.name,icon:(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:n.color||`#888`}}),onClick:()=>Le.mutate(n.id),disabled:e.project_id===n.id||!g(`archives`,`update`,e.created_by_id)})})}return t})()},{label:d(n?`archives.menu.deselect`:`archives.menu.select`),icon:n?(0,K.jsx)($l,{className:`w-4 h-4`}):(0,K.jsx)(tu,{className:`w-4 h-4`}),onClick:()=>r(e.id)},{label:``,divider:!0,onClick:()=>{}},{label:d(`archives.menu.delete`),icon:(0,K.jsx)(hu,{className:`w-4 h-4`}),onClick:()=>T(!0),danger:!0,disabled:!g(`archives`,`delete`,e.created_by_id),title:g(`archives`,`delete`,e.created_by_id)?void 0:d(`archives.permission.noDelete`)}];return(0,K.jsxs)(pd,{"data-archive-id":e.id,className:`relative flex flex-col group ${n?`ring-2 ring-bambu-green`:``} ${i?`cursor-pointer`:``}`,style:o?{outline:`4px solid #facc15`,outlineOffset:`2px`}:void 0,onContextMenu:Re,onClick:i?()=>r(e.id):void 0,children:[i&&(0,K.jsx)(`button`,{className:`absolute top-2 left-2 z-10 p-1 rounded bg-black/50 hover:bg-black/70 transition-colors`,onClick:t=>{t.stopPropagation(),r(e.id)},children:n?(0,K.jsx)($l,{className:`w-5 h-5 text-bambu-green`}):(0,K.jsx)(tu,{className:`w-5 h-5 text-white`})}),(0,K.jsxs)(`div`,{className:`aspect-video bg-bambu-dark relative flex-shrink-0 overflow-hidden rounded-t-xl`,onMouseEnter:()=>pe(!0),onMouseLeave:()=>pe(!1),children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:ue!==null&&Se.length>0?Q.getArchivePlateThumbnail(e.id,Se[we]?.index??0):Q.getArchiveThumbnail(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,K.jsx)(Dc,{className:`w-12 h-12 text-bambu-dark-tertiary`})}),Ce&&Se.length>1&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{className:`absolute left-1 top-1/2 -translate-y-1/2 p-1 rounded-full bg-black/60 hover:bg-black/80 transition-all ${_?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,onClick:e=>{e.stopPropagation(),de(e=>{let t=e??0;return t>0?t-1:Se.length-1})},title:d(`archives.card.previousPlate`),children:(0,K.jsx)(ns,{className:`w-4 h-4 text-white`})}),(0,K.jsx)(`button`,{className:`absolute right-1 top-1/2 -translate-y-1/2 p-1 rounded-full bg-black/60 hover:bg-black/80 transition-all ${_?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,onClick:e=>{e.stopPropagation(),de(e=>{let t=e??0;return t(0,K.jsx)(`button`,{className:`w-2 h-2 rounded-full transition-colors ${t===we?`bg-bambu-green`:`bg-white/50 hover:bg-white/80`}`,onClick:e=>{e.stopPropagation(),de(t)},title:e.name||d(`archives.card.plateNumber`,{index:e.index})},e.index))})]}),(0,K.jsx)(`button`,{className:`absolute top-2 left-2 p-1.5 rounded bg-black/50 hover:bg-black/70 transition-all ${_?`opacity-100`:`opacity-0 group-hover:opacity-100`} ${i?`left-10`:``}`,onClick:e=>{e.stopPropagation();let t=e.currentTarget.getBoundingClientRect();le({x:t.left,y:t.bottom+4})},title:d(`archives.card.moreOptions`),children:(0,K.jsx)(zs,{className:`w-5 h-5 text-white`})}),(0,K.jsx)(`button`,{className:`absolute top-2 right-2 p-1 rounded transition-colors ${g(`archives`,`update`,e.created_by_id)?`bg-black/50 hover:bg-black/70`:`bg-black/30 cursor-not-allowed`}`,onClick:t=>{t.stopPropagation(),g(`archives`,`update`,e.created_by_id)&&Fe.mutate()},disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?e.is_favorite?d(`archives.card.removeFromFavorites`):d(`archives.card.addToFavorites`):d(`archives.permission.noUpdateArchives`),children:(0,K.jsx)(nu,{className:`w-5 h-5 ${e.is_favorite?`text-yellow-400 fill-yellow-400`:`text-white`} ${g(`archives`,`update`,e.created_by_id)?``:`opacity-50`}`})}),(e.status===`failed`||e.status===`aborted`)&&(0,K.jsx)(`div`,{className:`absolute top-2 left-12 px-2 py-1 rounded text-xs bg-status-error/80 text-white`,children:e.status===`aborted`?d(`archives.card.cancelled`):d(`archives.card.failed`)}),e.duplicate_count>0&&be>0&&xe&&(0,K.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),f?.(xe)},className:`absolute top-2 right-12 px-2 py-1 rounded text-xs bg-purple-500/80 hover:bg-purple-600/90 text-white flex items-center gap-1 transition-colors cursor-pointer`,title:d(`archives.viewOriginalPrint`,{id:xe}),children:[(0,K.jsx)(Ds,{className:`w-3 h-3`}),`#`,be]}),e.duplicate_count>0&&be===0&&(0,K.jsxs)(`span`,{className:`absolute top-2 right-12 px-2 py-1 rounded text-xs bg-purple-500/80 text-white flex items-center gap-1`,title:`${e.duplicate_count} reprint${e.duplicate_count===1?``:`s`}`,children:[(0,K.jsx)(fc,{className:`w-3 h-3`}),`+`,e.duplicate_count]}),e.source_3mf_path&&(0,K.jsx)(`button`,{className:`absolute bottom-2 left-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:t=>{t.stopPropagation();let n=(e.print_name||e.filename||`source`).replace(/\.gcode\.3mf$/i,``)+`_source`;t6(e.id,n,`source`,c)},title:d(`archives.card.openSource3mf`),children:(0,K.jsx)(Js,{className:`w-4 h-4 text-orange-400`})}),e.f3d_path&&(0,K.jsx)(`button`,{className:`absolute bottom-2 ${e.source_3mf_path?`left-12`:`left-2`} p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:t=>{t.stopPropagation(),Q.downloadF3d(e.id).catch(e=>{console.error(`F3D download failed:`,e)})},title:d(`archives.card.downloadF3d`),children:(0,K.jsx)(Bo,{className:`w-4 h-4 text-cyan-400`})}),(0,K.jsx)(`button`,{className:`absolute bottom-2 right-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:e=>{e.stopPropagation(),Te()},title:d(`archives.card.preview3d`),children:(0,K.jsx)(Nc,{className:`w-4 h-4 text-white`})}),e.timelapse_path&&(0,K.jsx)(`button`,{className:`absolute bottom-2 right-12 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:e=>{e.stopPropagation(),P(!0)},title:d(`archives.card.viewTimelapse`),children:(0,K.jsx)($s,{className:`w-4 h-4 text-bambu-green`})}),e.photos&&e.photos.length>0&&(0,K.jsxs)(`button`,{className:`absolute bottom-2 ${e.timelapse_path?`right-[5.5rem]`:`right-12`} p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:e=>{e.stopPropagation(),ee(!0)},title:e.photos.length===1?d(`archives.card.viewPhoto`):d(`archives.card.viewPhotos`,{count:e.photos.length}),children:[(0,K.jsx)(Jo,{className:`w-4 h-4 text-blue-400`}),e.photos.length>1&&(0,K.jsx)(`span`,{className:`absolute -top-1 -right-1 w-4 h-4 bg-blue-500 rounded-full text-[10px] text-white flex items-center justify-center`,children:e.photos.length})]}),Ie&&Ie.length>0&&(0,K.jsx)(bi,{to:`/files?folder=${Ie[0].id}`,className:`absolute bottom-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:e=>e.stopPropagation(),title:d(`archives.card.openFolder`,{name:Ie[0].name}),style:{left:e.source_3mf_path?e.f3d_path?`5.5rem`:`3rem`:e.f3d_path?`3rem`:`0.5rem`},children:(0,K.jsx)(rc,{className:`w-4 h-4 text-yellow-400`})})]}),(0,K.jsxs)(hd,{className:`p-4 flex-1 flex flex-col`,children:[(0,K.jsxs)(`p`,{className:`text-[10px] text-bambu-gray/70 mb-1`,children:[`#`,e.id]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,K.jsx)(`h3`,{className:`min-w-0 font-medium text-white truncate`,children:e.print_name||e.filename}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,className:`p-1 sm:p-1.5 shrink-0`,onClick:()=>A(!0),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?d(`archives.card.edit`):d(`archives.card.noPermissionEdit`),children:(0,K.jsx)(pl,{className:`w-3 h-3 sm:w-4 sm:h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 flex-wrap`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t}),(()=>{let t=$K(e.bed_type);return t?(0,K.jsx)(`img`,{src:t.icon,alt:t.label,title:t.label,className:`w-4 h-4 flex-shrink-0`}):null})(),(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${e6(e)?`bg-bambu-green/20 text-bambu-green`:`bg-orange-500/20 text-orange-400`}`,title:e6(e)?d(`archives.card.slicedFile`):d(`archives.card.sourceFile`),children:e6(e)?d(`archives.card.gcode`):d(`archives.card.source`)}),e.content_hash&&(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded font-mono bg-bambu-dark-tertiary/50 text-bambu-gray-light opacity-0 transition-opacity duration-150 group-hover:opacity-100`,title:`SHA256: ${e.content_hash}`,children:e.content_hash.slice(0,8).toUpperCase()}),e.project_name&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full truncate max-w-[120px]`,style:{backgroundColor:`${a?.find(t=>t.id===e.project_id)?.color||`#6b7280`}20`,color:a?.find(t=>t.id===e.project_id)?.color||`#6b7280`},title:d(`archives.card.project`,{name:e.project_name}),children:e.project_name}),e.run_count>1&&(0,K.jsx)(`button`,{className:`text-[10px] px-1.5 py-0.5 rounded font-medium bg-bambu-orange/20 text-bambu-orange hover:bg-bambu-orange/30 transition-colors cursor-pointer`,onClick:e=>{e.stopPropagation(),M(!0)},title:d(`archives.card.runsBadgeTitle`,{count:e.run_count,successful:e.successful_run_count,failed:e.failed_run_count}),children:d(`archives.card.runsBadge`,{count:e.run_count})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs mb-4 min-h-[48px]`,children:[(e.print_time_seconds||e.actual_time_seconds)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,title:e.time_accuracy?`Estimated: ${yf(e.print_time_seconds||0)}\nActual: ${yf(e.actual_time_seconds||0)}\nAccuracy: ${e.time_accuracy.toFixed(0)}%`:e.actual_time_seconds?`Actual: ${yf(e.actual_time_seconds)}`:`Estimated: ${yf(e.print_time_seconds||0)}`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),yf(e.actual_time_seconds||e.print_time_seconds||0),e.time_accuracy&&(0,K.jsxs)(`span`,{className:`text-[10px] px-1 rounded ${e.time_accuracy>=95&&e.time_accuracy<=105?`bg-bambu-green/20 text-bambu-green`:e.time_accuracy>105?`bg-blue-500/20 text-blue-400`:`bg-orange-500/20 text-orange-400`}`,children:[e.time_accuracy>100?`+`:``,(e.time_accuracy-100).toFixed(0),`%`]})]}),e.filament_used_grams&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,K.jsx)(cl,{className:`w-3 h-3`}),e.filament_used_grams.toFixed(1),`g`]}),(e.cost!=null||e.energy_cost!=null)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-bambu-gray`,children:[e.cost!=null&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(Cs,{className:`w-3 h-3`}),u,e.cost.toFixed(2)]}),e.energy_cost!=null&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:`${d(`stats.energyUsed`)}: ${e.energy_kwh?.toFixed(3)||`N/A`} kWh`,children:[(0,K.jsx)(Iu,{className:`w-3 h-3`}),u,e.energy_cost.toFixed(2)]})]}),(e.layer_height||e.total_layers)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,K.jsx)(Nc,{className:`w-3 h-3`}),e.total_layers&&(0,K.jsx)(`span`,{children:e.total_layers===1?d(`archives.card.layer`,{count:e.total_layers}):d(`archives.card.layers`,{count:e.total_layers})}),e.total_layers&&e.layer_height&&(0,K.jsx)(`span`,{className:`text-bambu-gray/50`,children:`·`}),e.layer_height&&(0,K.jsxs)(`span`,{children:[e.layer_height,`mm`]})]}),e.object_count!=null&&e.object_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,title:e.object_count===1?d(`archives.card.object`,{count:e.object_count}):d(`archives.card.objects`,{count:e.object_count}),children:[(0,K.jsx)(Bo,{className:`w-3 h-3`}),e.object_count===1?d(`archives.card.object`,{count:e.object_count}):d(`archives.card.objects`,{count:e.object_count})]}),e.sliced_for_model&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,title:d(`archives.card.slicedFor`,{model:e.sliced_for_model}),children:[(0,K.jsx)(bl,{className:`w-3 h-3`}),e.sliced_for_model]}),e.filament_type&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 col-span-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e.filament_type}),e.filament_color&&(0,K.jsx)(`div`,{className:`flex items-center gap-0.5 flex-wrap`,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},title:e},t))})]})]}),(e.tags||e.notes)&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 mb-3`,children:[e.notes&&(0,K.jsx)(`div`,{className:`flex items-center gap-1 px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded text-xs`,title:e.notes,children:(0,K.jsx)(iu,{className:`w-3 h-3`})}),e.tags?.split(`,`).map((e,t)=>(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-bambu-dark-tertiary text-bambu-gray-light rounded text-xs`,children:e.trim()},t))]}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray border-t border-bambu-dark-tertiary pt-3`,children:[(0,K.jsx)(`span`,{children:gf(e.created_at,s)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.created_by_username&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,title:d(`archives.card.uploadedBy`,{name:e.created_by_username}),children:[(0,K.jsx)(Cu,{className:`w-3 h-3`}),e.created_by_username]}),(0,K.jsx)(`span`,{children:yd(e.file_size)})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-1 mt-3`,children:[e6(e)?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`primary`,size:`sm`,className:`flex-1 min-w-0 overflow-hidden`,onClick:()=>x(!0),disabled:!e.file_path||!g(`archives`,`reprint`,e.created_by_id),title:e.file_path?g(`archives`,`reprint`,e.created_by_id)?void 0:d(`archives.card.noPermissionReprint`):d(`archives.card.noFileForReprint`),children:[(0,K.jsx)(bl,{className:`w-3 h-3 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`hidden xl:inline truncate`,children:d(`archives.card.reprint`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,className:`flex-1 min-w-0 overflow-hidden`,onClick:()=>re(!0),disabled:!e.file_path||!h(`queue:create`),title:e.file_path?h(`queue:create`)?d(`archives.card.schedulePrint`):d(`archives.permission.noAddToQueue`):d(`archives.card.noFileForReprint`),children:[(0,K.jsx)(qo,{className:`w-3 h-3 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`hidden xl:inline truncate`,children:d(`archives.card.schedule`)})]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,className:`min-w-0 p-1 sm:p-1.5`,onClick:()=>{let t=e.print_name||e.filename||`model`;t6(e.id,t,`file`,c)},title:d(`archives.card.openInBambuStudio`),children:(0,K.jsx)(Us,{className:`w-3 h-3 sm:w-4 sm:h-4`})})]}):(0,K.jsxs)($,{variant:`primary`,size:`sm`,className:`flex-1 min-w-0 overflow-hidden`,onClick:()=>{if(l)C(!0);else{let t=e.print_name||e.filename||`model`;t6(e.id,t,`file`,c)}},title:d(l?`slice.title`:`archives.card.openInBambuStudioToSlice`),children:[l?(0,K.jsx)(ws,{className:`w-3 h-3 flex-shrink-0`}):(0,K.jsx)(Us,{className:`w-3 h-3 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`hidden xl:inline truncate`,children:d(`archives.card.slice`)})]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,className:`min-w-0 p-1 sm:p-1.5`,onClick:()=>{let t=e.external_url||e.makerworld_url;t&&window.open(t,`_blank`)},disabled:!e.external_url&&!e.makerworld_url,title:e.external_url?d(`archives.card.externalLink`):e.makerworld_url?d(`archives.card.makerWorld`,{designer:e.designer||d(`archives.card.viewProject`)}):d(`archives.card.noExternalLink`),children:(0,K.jsx)(hc,{className:`w-3 h-3 sm:w-4 sm:h-4 ${!e.external_url&&!e.makerworld_url?`opacity-20`:``}`})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,className:`min-w-0 p-1 sm:p-1.5`,onClick:()=>{Q.downloadArchive(e.id,`${e.print_name||e.filename}.3mf`).catch(e=>{console.error(`Archive download failed:`,e)})},title:d(`archives.card.download`),children:(0,K.jsx)(Is,{className:`w-3 h-3 sm:w-4 sm:h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,className:`min-w-0 p-1 sm:p-1.5`,onClick:()=>T(!0),disabled:!g(`archives`,`delete`,e.created_by_id),title:g(`archives`,`delete`,e.created_by_id)?d(`archives.card.delete`):d(`archives.card.noPermissionDelete`),children:(0,K.jsx)(hu,{className:`w-3 h-3 sm:w-4 sm:h-4 text-red-400`})})]})]}),k&&(0,K.jsx)(Jq,{archive:e,onClose:()=>A(!1)}),j&&(0,K.jsx)(Yq,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>M(!1)}),me&&(0,K.jsx)(Fq,{plates:me,onSelect:t=>{he(null),v(`/gcode-viewer?archive=${e.id}&plate=${t}`)},onClose:()=>he(null)}),b&&(0,K.jsx)(sq,{mode:`reprint`,archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>x(!1)}),S&&(0,K.jsx)(Bq,{source:{kind:`archive`,id:e.id,filename:e.print_name||e.filename||`model`},onClose:()=>C(!1)}),w&&(0,K.jsxs)(Ed,{title:d(`archives.modal.deleteArchive`),message:d(`archives.modal.deleteConfirm`,{name:e.print_name||e.filename}),confirmText:d(`archives.modal.deleteButton`),variant:`danger`,confirmDisabled:(O.data?.currently_printing??0)>0,onConfirm:()=>{Pe.mutate(E),T(!1),D(!1)},onCancel:()=>{T(!1),D(!1)},children:[(O.data?.related_queue_items??0)>0&&(0,K.jsx)(`div`,{className:(O.data?.currently_printing??0)>0?`text-sm text-red-400 mb-2`:`text-sm text-amber-400 mb-2`,children:(O.data?.currently_printing??0)>0?d(`archives.modal.deleteBlockedByPrinting`,{count:O.data.currently_printing}):d(`archives.modal.deleteQueueItemsWarning`,{count:O.data.related_queue_items})}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer text-sm text-bambu-gray`,children:[(0,K.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 accent-red-500`,checked:E,onChange:e=>D(e.target.checked)}),(0,K.jsx)(`span`,{children:d(`archives.modal.deletePurgeStats`)})]})]}),U&&(0,K.jsx)(Ed,{title:d(`archives.modal.removeSource3mf`),message:d(`archives.modal.removeSource3mfConfirm`,{name:e.print_name||e.filename}),confirmText:d(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{ke.mutate(),ie(!1)},onCancel:()=>ie(!1)}),ae&&(0,K.jsx)(Ed,{title:d(`archives.modal.removeF3d`),message:d(`archives.modal.removeF3dConfirm`,{name:e.print_name||e.filename}),confirmText:d(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{je.mutate(),W(!1)},onCancel:()=>W(!1)}),oe&&(0,K.jsx)(Ed,{title:d(`archives.modal.removeTimelapse`),message:d(`archives.modal.removeTimelapseConfirm`,{name:e.print_name||e.filename}),confirmText:d(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{Ee.mutate(),se(!1)},onCancel:()=>se(!1)}),ce&&(0,K.jsx)(Xq,{x:ce.x,y:ce.y,items:ze,onClose:()=>le(null)}),N&&e.timelapse_path&&(0,K.jsx)($3,{src:Q.getArchiveTimelapse(e.id),title:d(`archives.modal.timelapse`,{name:e.print_name||e.filename}),downloadFilename:`${e.print_name||e.filename}_timelapse.mp4`,archiveId:e.id,onClose:()=>P(!1),onEdit:()=>{p.invalidateQueries({queryKey:[`archives`]}),P(!1)}}),F&&L.length>0&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-card-dark rounded-lg max-w-lg w-full max-h-[80vh] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-700`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:d(`archives.modal.selectTimelapse`)}),(0,K.jsx)(`p`,{className:`text-sm text-gray-400 mt-1`,children:d(`archives.modal.selectTimelapseDesc`)})]}),(0,K.jsx)(`button`,{onClick:()=>{I(!1),R([])},className:`text-gray-400 hover:text-white p-1`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`overflow-y-auto flex-1 p-2`,children:L.map(e=>(0,K.jsxs)(`button`,{onClick:()=>Ne.mutate(e.name),disabled:Ne.isPending,className:`w-full text-left p-3 rounded-lg hover:bg-gray-700 transition-colors flex items-center gap-3 disabled:opacity-50`,children:[(0,K.jsx)($s,{className:`w-8 h-8 text-bambu-green flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.name}),(0,K.jsxs)(`p`,{className:`text-sm text-gray-400`,children:[yd(e.size),e.mtime&&` • ${gf(e.mtime,s)}`]})]})]},e.name))}),(0,K.jsx)(`div`,{className:`p-4 border-t border-gray-700`,children:(0,K.jsx)($,{variant:`secondary`,onClick:()=>{I(!1),R([])},className:`w-full`,children:`Cancel`})})]})}),z&&(0,K.jsx)(Zq,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>B(!1)}),V&&e.photos&&e.photos.length>0&&(0,K.jsx)(Qq,{archiveId:e.id,archiveName:e.print_name||e.filename,photos:e.photos,onClose:()=>ee(!1),onDelete:async t=>{try{await Q.deleteArchivePhoto(e.id,t),p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.photoDeleted`))}catch{m(d(`archives.toast.failedDeletePhoto`),`error`)}}}),H&&(0,K.jsx)(Q3,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>te(!1)}),ne&&(0,K.jsx)(sq,{mode:`add-to-queue`,archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>re(!1)}),(0,K.jsx)(`input`,{ref:ge,type:`file`,accept:`.3mf`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&Oe.mutate(t),e.target.value=``}}),(0,K.jsx)(`input`,{ref:_e,type:`file`,accept:`.f3d`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&Ae.mutate(t),e.target.value=``}}),(0,K.jsx)(`input`,{ref:ve,type:`file`,accept:`.mp4,.avi,.mkv`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&De.mutate(t),e.target.value=``}})]})}function XFe({archive:e,printerName:t,isSelected:n,onSelect:r,selectionMode:i,projects:a,isHighlighted:o,preferredSlicer:s=`bambu_studio`,useSlicerApi:c=!1,t:l,onNavigateToArchive:u}){let d=Qa(),{showToast:f}=xd(),{hasPermission:p,canModify:m}=sd(),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),w=q({queryKey:[`archive`,e.id,`delete-impact`],queryFn:()=>Q.getArchiveDeleteImpact(e.id),enabled:b,staleTime:0}),T=Yn(),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)([]),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(!1),[ee,H]=(0,y.useState)(!1),[te,ne]=(0,y.useState)(!1),[re,U]=(0,y.useState)(!1),[ie,ae]=(0,y.useState)(!1),[W,oe]=(0,y.useState)(null),se=(0,y.useRef)(null),ce=(0,y.useRef)(null),le=(0,y.useRef)(null),[ue,de]=(0,y.useState)(null),fe=e.duplicate_sequence??0,pe=e.original_archive_id??null,me=async()=>{try{let t=await Q.getArchivePlates(e.id);if(t.is_multi_plate&&t.plates.length>1){de(t.plates);return}}catch{}T(`/gcode-viewer?archive=${e.id}`)},he=J({mutationFn:()=>Q.deleteArchiveTimelapse(e.id),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.timelapseRemoved`))},onError:e=>{f(e.message||l(`archives.toast.failedRemoveTimelapse`),`error`)}}),ge=J({mutationFn:t=>Q.uploadArchiveTimelapse(e.id,t),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.timelapseUploaded`,{filename:e.filename}))},onError:e=>{f(e.message||l(`archives.toast.failedUploadTimelapse`),`error`)}}),_e=J({mutationFn:t=>Q.uploadSource3mf(e.id,t),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.source3mfAttached`,{filename:e.filename}))},onError:e=>{f(e.message||l(`archives.toast.failedUploadSource3mf`),`error`)}}),ve=J({mutationFn:()=>Q.deleteSource3mf(e.id),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.source3mfRemoved`))},onError:e=>{f(e.message||l(`archives.toast.failedRemoveSource3mf`),`error`)}}),ye=J({mutationFn:t=>Q.uploadF3d(e.id,t),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.f3dAttached`,{filename:e.filename}))},onError:e=>{f(e.message||l(`archives.toast.failedUploadF3d`),`error`)}}),be=J({mutationFn:()=>Q.deleteF3d(e.id),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.f3dRemoved`))},onError:e=>{f(e.message||l(`archives.toast.failedRemoveF3d`),`error`)}}),xe=J({mutationFn:()=>Q.scanArchiveTimelapse(e.id),onSuccess:e=>{e.status===`attached`?(d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.timelapseAttached`,{filename:e.filename}))):e.status===`exists`?f(l(`archives.toast.timelapseAlreadyAttached`)):e.status===`not_found`&&e.available_files&&e.available_files.length>0?(L(e.available_files),F(!0)):f(e.message||l(`archives.toast.noMatchingTimelapse`),`warning`)},onError:e=>{f(e.message||l(`archives.toast.failedScanTimelapse`),`error`)}}),Se=J({mutationFn:t=>Q.selectArchiveTimelapse(e.id,t),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.timelapseAttached`,{filename:e.filename})),F(!1),L([])},onError:e=>{f(e.message||l(`archives.toast.failedAttachTimelapse`),`error`)}}),Ce=J({mutationFn:t=>Q.deleteArchive(e.id,t),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.archiveDeleted`))},onError:()=>{f(l(`archives.toast.failedDeleteArchive`),`error`)}}),we=J({mutationFn:()=>Q.toggleFavorite(e.id),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(e.is_favorite?l(`archives.toast.addedToFavorites`):l(`archives.toast.removedFromFavorites`))}}),{data:Te}=q({queryKey:[`archive-folders`,e.id],queryFn:()=>Q.getLibraryFoldersByArchive(e.id)}),Ee=J({mutationFn:t=>Q.updateArchive(e.id,{project_id:t}),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),d.invalidateQueries({queryKey:[`projects`]}),f(l(`archives.toast.projectUpdated`))},onError:()=>{f(l(`archives.toast.failedUpdateProject`),`error`)}}),De=e=>{e.preventDefault(),oe({x:e.clientX,y:e.clientY})},Oe=[...e6(e)?[{label:l(`archives.menu.print`),icon:(0,K.jsx)(bl,{className:`w-4 h-4`}),onClick:()=>D(!0),disabled:!e.file_path||!m(`archives`,`reprint`,e.created_by_id),title:e.file_path?m(`archives`,`reprint`,e.created_by_id)?void 0:l(`archives.permission.noReprint`):l(`archives.card.noFileForReprint`)},{label:l(`archives.menu.schedule`),icon:(0,K.jsx)(qo,{className:`w-4 h-4`}),onClick:()=>j(!0),disabled:!e.file_path||!p(`queue:create`),title:e.file_path?p(`queue:create`)?void 0:l(`archives.permission.noAddToQueue`):l(`archives.card.noFileForReprint`)},{label:l(`archives.menu.openInBambuStudio`),icon:(0,K.jsx)(Us,{className:`w-4 h-4`}),onClick:()=>{let t=e.print_name||e.filename||`model`;t6(e.id,t,`file`,s)},disabled:!e.file_path,title:e.file_path?void 0:l(`archives.card.noFileForReprint`)}]:[{label:l(`archives.menu.slice`),icon:c?(0,K.jsx)(ws,{className:`w-4 h-4`}):(0,K.jsx)(Us,{className:`w-4 h-4`}),onClick:()=>{if(c)k(!0);else{let t=e.print_name||e.filename||`model`;t6(e.id,t,`file`,s)}}}],{label:e.external_url?l(`archives.menu.externalLink`):l(`archives.menu.viewOnMakerWorld`),icon:(0,K.jsx)(hc,{className:`w-4 h-4`}),onClick:()=>{let t=e.external_url||e.makerworld_url;t&&window.open(t,`_blank`)},disabled:!e.external_url&&!e.makerworld_url},{label:``,divider:!0,onClick:()=>{}},{label:l(`archives.menu.preview3d`),icon:(0,K.jsx)(Bo,{className:`w-4 h-4`}),onClick:()=>{me()}},{label:l(`archives.menu.viewTimelapse`),icon:(0,K.jsx)($s,{className:`w-4 h-4`}),onClick:()=>N(!0),disabled:!e.timelapse_path},{label:l(`archives.menu.scanForTimelapse`),icon:(0,K.jsx)(jl,{className:`w-4 h-4`}),onClick:()=>xe.mutate(),disabled:!e.printer_id||!!e.timelapse_path||xe.isPending||!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},{label:l(`archives.menu.uploadTimelapse`),icon:(0,K.jsx)(Su,{className:`w-4 h-4`}),onClick:()=>le.current?.click(),disabled:!!e.timelapse_path||!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},...e.timelapse_path?[{label:l(`archives.menu.removeTimelapse`),icon:(0,K.jsx)(hu,{className:`w-4 h-4`}),onClick:()=>ae(!0),danger:!0,disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)}]:[],{label:``,divider:!0,onClick:()=>{}},{label:e.source_3mf_path?l(`archives.menu.downloadSource3mf`):l(`archives.menu.uploadSource3mf`),icon:(0,K.jsx)(Js,{className:`w-4 h-4`}),onClick:()=>{e.source_3mf_path?Q.downloadSource3mf(e.id).catch(e=>{console.error(`Source 3MF download failed:`,e)}):se.current?.click()},disabled:!e.source_3mf_path&&!m(`archives`,`update`,e.created_by_id),title:!e.source_3mf_path&&!m(`archives`,`update`,e.created_by_id)?l(`archives.permission.noUploadFiles`):void 0},...e.source_3mf_path?[{label:l(`archives.menu.replaceSource3mf`),icon:(0,K.jsx)(Su,{className:`w-4 h-4`}),onClick:()=>se.current?.click(),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},{label:l(`archives.menu.removeSource3mf`),icon:(0,K.jsx)(hu,{className:`w-4 h-4`}),onClick:()=>ne(!0),danger:!0,disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)}]:[],{label:e.f3d_path?l(`archives.menu.replaceF3d`):l(`archives.menu.uploadF3d`),icon:(0,K.jsx)(Bo,{className:`w-4 h-4`}),onClick:()=>ce.current?.click(),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},...e.f3d_path?[{label:l(`archives.menu.downloadF3d`),icon:(0,K.jsx)(Is,{className:`w-4 h-4`}),onClick:()=>{Q.downloadF3d(e.id).catch(e=>{console.error(`F3D download failed:`,e)})}},{label:l(`archives.menu.removeF3d`),icon:(0,K.jsx)(hu,{className:`w-4 h-4`}),onClick:()=>U(!0),danger:!0,disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)}]:[],{label:``,divider:!0,onClick:()=>{}},{label:l(`archives.menu.download`),icon:(0,K.jsx)(Is,{className:`w-4 h-4`}),onClick:()=>{Q.downloadArchive(e.id,`${e.print_name||e.filename}.3mf`).catch(e=>{console.error(`Archive download failed:`,e)})},disabled:!p(`archives:read`),title:p(`archives:read`)?void 0:l(`archives.permission.noDownload`)},{label:l(`archives.menu.copyDownloadLink`),icon:(0,K.jsx)(Ds,{className:`w-4 h-4`}),onClick:()=>{let t=`${window.location.origin}${Q.getArchiveDownload(e.id)}`;navigator.clipboard.writeText(t).then(()=>{f(l(`archives.toast.linkCopied`))}).catch(()=>{f(l(`archives.toast.failedCopyLink`),`error`)})},disabled:!p(`archives:read`),title:p(`archives:read`)?void 0:l(`archives.permission.noCopyLink`)},{label:l(`archives.menu.qrCode`),icon:(0,K.jsx)(xl,{className:`w-4 h-4`}),onClick:()=>z(!0)},{label:e.photos?.length?l(`archives.menu.viewPhotosCount`,{count:e.photos.length}):l(`archives.menu.viewPhotos`),icon:(0,K.jsx)(Jo,{className:`w-4 h-4`}),onClick:()=>V(!0),disabled:!e.photos?.length},{label:l(`archives.menu.projectPage`),icon:(0,K.jsx)(Zs,{className:`w-4 h-4`}),onClick:()=>H(!0)},{label:``,divider:!0,onClick:()=>{}},{label:e.is_favorite?l(`archives.menu.removeFromFavorites`):l(`archives.menu.addToFavorites`),icon:(0,K.jsx)(nu,{className:`w-4 h-4 ${e.is_favorite?`fill-yellow-400 text-yellow-400`:``}`}),onClick:()=>we.mutate(),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},{label:l(`archives.menu.edit`),icon:(0,K.jsx)(pl,{className:`w-4 h-4`}),onClick:()=>g(!0),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},{label:l(`archives.menu.printLog`),icon:(0,K.jsx)(wc,{className:`w-4 h-4`}),onClick:()=>v(!0)},...e.project_id&&e.project_name?[{label:l(`archives.menu.goToProject`,{name:e.project_name}),icon:(0,K.jsx)(nc,{className:`w-4 h-4 text-bambu-green`}),onClick:()=>window.location.href=`/projects`}]:[],{label:l(`archives.menu.addToProject`),icon:(0,K.jsx)(nc,{className:`w-4 h-4`}),onClick:()=>{},submenuSearchPlaceholder:(a?.filter(e=>e.status===`active`).length??0)>5?l(`archives.menu.searchProjects`):void 0,submenu:(()=>{let t=[];if(e.project_id&&t.push({label:l(`archives.menu.removeFromProject`),icon:(0,K.jsx)(Pu,{className:`w-4 h-4`}),onClick:()=>Ee.mutate(null)}),!a)t.push({label:l(`archives.menu.loading`),icon:(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),onClick:()=>{},disabled:!0});else{let n=a.filter(e=>e.status===`active`).sort((e,t)=>e.name.localeCompare(t.name));n.length===0?t.push({label:l(`archives.menu.noProjectsAvailable`),icon:(0,K.jsx)(nc,{className:`w-4 h-4 opacity-50`}),onClick:()=>{},disabled:!0}):n.forEach(n=>{t.push({label:n.name,icon:(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:n.color||`#888`}}),onClick:()=>Ee.mutate(n.id),disabled:e.project_id===n.id})})}return t})()},{label:l(n?`archives.menu.deselect`:`archives.menu.select`),icon:n?(0,K.jsx)($l,{className:`w-4 h-4`}):(0,K.jsx)(tu,{className:`w-4 h-4`}),onClick:()=>r(e.id)},{label:``,divider:!0,onClick:()=>{}},{label:l(`archives.menu.delete`),icon:(0,K.jsx)(hu,{className:`w-4 h-4`}),onClick:()=>x(!0),danger:!0,disabled:!m(`archives`,`delete`,e.created_by_id),title:m(`archives`,`delete`,e.created_by_id)?void 0:l(`archives.permission.noDelete`)}];return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{"data-archive-id":e.id,className:`grid grid-cols-12 gap-4 px-4 py-3 items-center hover:bg-bambu-dark-tertiary/30 ${n?`bg-bambu-green/10`:``}`,style:o?{outline:`4px solid #facc15`,outlineOffset:`-4px`}:void 0,onContextMenu:De,children:[(0,K.jsxs)(`div`,{className:`col-span-1 flex items-center gap-2`,children:[i&&(0,K.jsx)(`button`,{onClick:()=>r(e.id),children:n?(0,K.jsx)($l,{className:`w-4 h-4 text-bambu-green`}):(0,K.jsx)(tu,{className:`w-4 h-4 text-bambu-gray`})}),e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:``,className:`w-10 h-10 object-cover rounded`}):(0,K.jsx)(`div`,{className:`w-10 h-10 bg-bambu-dark rounded flex items-center justify-center`,children:(0,K.jsx)(Dc,{className:`w-5 h-5 text-bambu-dark-tertiary`})})]}),(0,K.jsxs)(`div`,{className:`col-span-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`p`,{className:`text-white text-sm truncate`,children:e.print_name||e.filename}),(e.status===`failed`||e.status===`aborted`)&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] leading-tight bg-status-error/80 text-white flex-shrink-0`,children:e.status===`aborted`?l(`archives.card.cancelled`):l(`archives.card.failed`)}),e.duplicate_count>0&&fe>0&&pe&&(0,K.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),u?.(pe)},className:`px-1.5 py-0.5 rounded text-[10px] leading-tight bg-purple-500/80 hover:bg-purple-600/90 text-white flex-shrink-0 transition-colors flex items-center gap-1`,title:l(`archives.viewOriginalPrint`,{id:pe}),children:[(0,K.jsx)(Ds,{className:`w-3 h-3`}),`#`,fe]}),e.duplicate_count>0&&fe===0&&(0,K.jsxs)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] leading-tight bg-purple-500/80 text-white flex-shrink-0 flex items-center gap-1`,title:`${e.duplicate_count} reprint${e.duplicate_count===1?``:`s`}`,children:[(0,K.jsx)(fc,{className:`w-3 h-3`}),`+`,e.duplicate_count]}),e.timelapse_path&&(0,K.jsx)(`span`,{title:l(`archives.list.hasTimelapse`),children:(0,K.jsx)($s,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`})}),Te&&Te.length>0&&(0,K.jsx)(bi,{to:`/files?folder=${Te[0].id}`,className:`flex-shrink-0`,title:l(`archives.card.openFolder`,{name:Te[0].name}),onClick:e=>e.stopPropagation(),children:(0,K.jsx)(rc,{className:`w-3.5 h-3.5 text-yellow-400`})})]}),(e.filament_type||e.sliced_for_model)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[e.sliced_for_model&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1`,title:l(`archives.card.slicedFor`,{model:e.sliced_for_model}),children:[(0,K.jsx)(bl,{className:`w-2.5 h-2.5`}),e.sliced_for_model]}),(()=>{let t=$K(e.bed_type);return t?(0,K.jsx)(`img`,{src:t.icon,alt:t.label,title:t.label,className:`w-3.5 h-3.5 flex-shrink-0`}):null})(),e.sliced_for_model&&e.filament_type&&(0,K.jsx)(`span`,{className:`text-bambu-gray/50`,children:`·`}),e.filament_type&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.filament_type}),e.filament_color&&(0,K.jsx)(`div`,{className:`flex items-center gap-0.5 flex-wrap`,children:e.filament_color.split(`,`).map((e,t)=>(0,K.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full border border-black/20`,style:{backgroundColor:e},title:e},t))})]})]}),(0,K.jsx)(`div`,{className:`col-span-2 text-sm text-bambu-gray truncate`,children:t}),(0,K.jsxs)(`div`,{className:`col-span-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(`div`,{children:hf(e.created_at)}),e.created_by_username&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-xs opacity-75`,title:l(`archives.card.uploadedBy`,{name:e.created_by_username}),children:[(0,K.jsx)(Cu,{className:`w-3 h-3`}),e.created_by_username]})]}),(0,K.jsx)(`div`,{className:`col-span-1 text-sm text-bambu-gray`,children:yd(e.file_size)}),(0,K.jsxs)(`div`,{className:`col-span-2 flex justify-end gap-1`,children:[e6(e)&&(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>D(!0),disabled:!m(`archives`,`reprint`,e.created_by_id),title:m(`archives`,`reprint`,e.created_by_id)?l(`archives.card.reprint`):l(`archives.card.noPermissionReprint`),className:`text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10`,children:(0,K.jsx)(hl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{let t=e.print_name||e.filename||`model`;t6(e.id,t,`file`,s)},title:l(`archives.card.openInBambuStudio`),children:(0,K.jsx)(Us,{className:`w-4 h-4`})}),(e.external_url||e.makerworld_url)&&(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>window.open(e.external_url||e.makerworld_url,`_blank`),title:e.external_url?l(`archives.card.externalLink`):`MakerWorld`,children:(0,K.jsx)(hc,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{Q.downloadArchive(e.id,`${e.print_name||e.filename}.3mf`).catch(e=>{console.error(`Archive download failed:`,e)})},title:l(`archives.card.download`),children:(0,K.jsx)(Is,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>g(!0),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?l(`archives.card.edit`):l(`archives.card.noPermissionEdit`),children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>x(!0),disabled:!m(`archives`,`delete`,e.created_by_id),title:m(`archives`,`delete`,e.created_by_id)?l(`archives.card.delete`):l(`archives.card.noPermissionDelete`),children:(0,K.jsx)(hu,{className:`w-4 h-4 text-red-400`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();oe({x:t.left,y:t.bottom+4})},title:l(`archives.card.moreOptions`),children:(0,K.jsx)(zs,{className:`w-4 h-4`})})]})]}),h&&(0,K.jsx)(Jq,{archive:e,onClose:()=>g(!1)}),_&&(0,K.jsx)(Yq,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>v(!1)}),ue&&(0,K.jsx)(Fq,{plates:ue,onSelect:t=>{de(null),T(`/gcode-viewer?archive=${e.id}&plate=${t}`)},onClose:()=>de(null)}),E&&(0,K.jsx)(sq,{mode:`reprint`,archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>D(!1)}),O&&(0,K.jsx)(Bq,{source:{kind:`archive`,id:e.id,filename:e.print_name||e.filename||`model`},onClose:()=>k(!1)}),b&&(0,K.jsxs)(Ed,{title:l(`archives.modal.deleteArchive`),message:l(`archives.modal.deleteConfirm`,{name:e.print_name||e.filename}),confirmText:l(`archives.modal.deleteButton`),variant:`danger`,confirmDisabled:(w.data?.currently_printing??0)>0,onConfirm:()=>{Ce.mutate(S),x(!1),C(!1)},onCancel:()=>{x(!1),C(!1)},children:[(w.data?.related_queue_items??0)>0&&(0,K.jsx)(`div`,{className:(w.data?.currently_printing??0)>0?`text-sm text-red-400 mb-2`:`text-sm text-amber-400 mb-2`,children:(w.data?.currently_printing??0)>0?l(`archives.modal.deleteBlockedByPrinting`,{count:w.data.currently_printing}):l(`archives.modal.deleteQueueItemsWarning`,{count:w.data.related_queue_items})}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer text-sm text-bambu-gray`,children:[(0,K.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 accent-red-500`,checked:S,onChange:e=>C(e.target.checked)}),(0,K.jsx)(`span`,{children:l(`archives.modal.deletePurgeStats`)})]})]}),te&&(0,K.jsx)(Ed,{title:l(`archives.modal.removeSource3mf`),message:l(`archives.modal.removeSource3mfConfirm`,{name:e.print_name||e.filename}),confirmText:l(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{ve.mutate(),ne(!1)},onCancel:()=>ne(!1)}),re&&(0,K.jsx)(Ed,{title:l(`archives.modal.removeF3d`),message:l(`archives.modal.removeF3dConfirm`,{name:e.print_name||e.filename}),confirmText:l(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{be.mutate(),U(!1)},onCancel:()=>U(!1)}),ie&&(0,K.jsx)(Ed,{title:l(`archives.modal.removeTimelapse`),message:l(`archives.modal.removeTimelapseConfirm`,{name:e.print_name||e.filename}),confirmText:l(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{he.mutate(),ae(!1)},onCancel:()=>ae(!1)}),W&&(0,K.jsx)(Xq,{x:W.x,y:W.y,items:Oe,onClose:()=>oe(null)}),M&&e.timelapse_path&&(0,K.jsx)($3,{src:Q.getArchiveTimelapse(e.id),title:l(`archives.modal.timelapse`,{name:e.print_name||e.filename}),downloadFilename:`${e.print_name||e.filename}_timelapse.mp4`,archiveId:e.id,onClose:()=>N(!1),onEdit:()=>{d.invalidateQueries({queryKey:[`archives`]}),N(!1)}}),P&&I.length>0&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-card-dark rounded-lg max-w-lg w-full max-h-[80vh] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-700`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:l(`archives.modal.selectTimelapse`)}),(0,K.jsx)(`p`,{className:`text-sm text-gray-400 mt-1`,children:l(`archives.modal.selectTimelapseDesc`)})]}),(0,K.jsx)(`button`,{onClick:()=>{F(!1),L([])},className:`text-gray-400 hover:text-white p-1`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`overflow-y-auto flex-1 p-2`,children:I.map(e=>(0,K.jsxs)(`button`,{onClick:()=>Se.mutate(e.name),disabled:Se.isPending,className:`w-full text-left p-3 rounded-lg hover:bg-gray-700 transition-colors mb-1`,children:[(0,K.jsx)(`div`,{className:`font-medium text-white`,children:e.name}),(0,K.jsxs)(`div`,{className:`text-sm text-gray-400 flex gap-3`,children:[(0,K.jsx)(`span`,{children:yd(e.size)}),e.mtime&&(0,K.jsx)(`span`,{children:hf(e.mtime)})]})]},e.name))})]})}),R&&(0,K.jsx)(Zq,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>z(!1)}),B&&e.photos&&(0,K.jsx)(Qq,{archiveId:e.id,archiveName:e.print_name||e.filename,photos:e.photos,onClose:()=>V(!1),onDelete:async t=>{try{await Q.deleteArchivePhoto(e.id,t),d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.photoDeleted`))}catch{f(l(`archives.toast.failedDeletePhoto`),`error`)}}}),ee&&(0,K.jsx)(Q3,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>H(!1)}),A&&(0,K.jsx)(sq,{mode:`add-to-queue`,archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>j(!1)}),(0,K.jsx)(`input`,{ref:se,type:`file`,accept:`.3mf`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&_e.mutate(t),e.target.value=``}}),(0,K.jsx)(`input`,{ref:ce,type:`file`,accept:`.f3d`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&ye.mutate(t),e.target.value=``}}),(0,K.jsx)(`input`,{ref:le,type:`file`,accept:`.mp4,.avi,.mkv`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&ge.mutate(t),e.target.value=``}})]})}var ZFe=[`completed`,`failed`,`aborted`,`cancelled`,`stopped`],QFe=[{id:`all`,label:`All Archives`,icon:(0,K.jsx)(rc,{className:`w-4 h-4`})},{id:`recent`,label:`Last 24 Hours`,icon:(0,K.jsx)(_s,{className:`w-4 h-4`})},{id:`this-week`,label:`This Week`,icon:(0,K.jsx)(qo,{className:`w-4 h-4`})},{id:`this-month`,label:`This Month`,icon:(0,K.jsx)(qo,{className:`w-4 h-4`})},{id:`favorites`,label:`Favorites`,icon:(0,K.jsx)(nu,{className:`w-4 h-4`})},{id:`not-printed`,label:`Not Printed`,icon:(0,K.jsx)(Su,{className:`w-4 h-4`})},{id:`printed`,label:`Printed`,icon:(0,K.jsx)(bl,{className:`w-4 h-4`})},{id:`failed`,label:`Failed Prints`,icon:(0,K.jsx)(ss,{className:`w-4 h-4`})},{id:`duplicates`,label:`Duplicates`,icon:(0,K.jsx)(Ds,{className:`w-4 h-4`})}];function $Fe(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),{hasPermission:r,hasAnyPermission:i}=sd(),a=(0,y.useRef)(null),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(()=>{let e=localStorage.getItem(`archiveFilterPrinter`);return e?Number(e):null}),[u,d]=(0,y.useState)(()=>localStorage.getItem(`archiveFilterMaterial`)),[f,p]=(0,y.useState)(()=>{let e=localStorage.getItem(`archiveFilterColors`);return e?new Set(JSON.parse(e)):new Set}),[m,h]=(0,y.useState)(()=>localStorage.getItem(`archiveColorFilterMode`)||`or`),[g,_]=(0,y.useState)(()=>localStorage.getItem(`archiveFilterFavorites`)===`true`),[v,b]=(0,y.useState)(()=>localStorage.getItem(`archiveHideFailed`)===`true`),[x,S]=(0,y.useState)(()=>localStorage.getItem(`archiveHideDuplicates`)===`true`),[C,w]=(0,y.useState)(()=>localStorage.getItem(`archiveFilterTag`)),[T,E]=(0,y.useState)(()=>localStorage.getItem(`archiveFilterFileType`)||`all`),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)([]),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)(new Set),[F,I]=(0,y.useState)(()=>localStorage.getItem(`archiveNo3MFWarningDismissed`)===`true`),{data:L}=q({queryKey:[`archives`,`no-3mf-warning`],queryFn:Q.getNo3MFWarning,staleTime:300*1e3,enabled:!F}),R=()=>{localStorage.setItem(`archiveNo3MFWarningDismissed`,`true`),I(!0)},[z,B]=(0,y.useState)(!1),[V,ee]=(0,y.useState)(!1),[H,te]=(0,y.useState)(!1),[ne,re]=(0,y.useState)(!1),[U,ie]=(0,y.useState)(()=>localStorage.getItem(`archiveViewMode`)||`grid`),[ae,W]=(0,y.useState)(()=>localStorage.getItem(`archiveSortBy`)||`date-desc`),[oe,se]=(0,y.useState)(()=>localStorage.getItem(`archiveCollection`)||`all`),[ce,le]=(0,y.useState)(0),[ue,de]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`archivePageSize`);return e?Number(e):50}catch{return 50}}),[fe,pe]=(0,y.useState)(!1),[me,he]=(0,y.useState)(!1),[ge,_e]=(0,y.useState)(!1),[ve,ye]=(0,y.useState)(!1),[be,xe]=(0,y.useState)(!1),[Se,Ce]=(0,y.useState)(null),[we,Te]=(0,y.useState)(null),[Ee,De]=(0,y.useState)(()=>localStorage.getItem(`logFilterUser`)||null),[Oe,ke]=(0,y.useState)(()=>localStorage.getItem(`logFilterStatus`)),[Ae,je]=(0,y.useState)(()=>localStorage.getItem(`logFilterDateFrom`)||``),[Me,Ne]=(0,y.useState)(()=>localStorage.getItem(`logFilterDateTo`)||``),[Pe,Fe]=(0,y.useState)(()=>{let e=localStorage.getItem(`logOffset`);return e?Number(e):0}),[Ie,Le]=(0,y.useState)(!1),[Re,ze]=(0,y.useState)(null),[Be,Ve]=(0,y.useState)(null),[He,Ue]=(0,y.useState)(``),[We,Ge]=(0,y.useState)(``),[Ke,qe]=(0,y.useState)(()=>{let e=localStorage.getItem(`logPageSize`);return e?Number(e):25}),Je=(0,y.useCallback)(e=>{Te(e),Ce(e)},[]);(0,y.useEffect)(()=>{if(Se){let t=setTimeout(()=>{let t=document.querySelector(`[data-archive-id="${Se}"]`);t?t.scrollIntoView({behavior:`smooth`,block:`center`}):we===Se&&n(e(`archives.originalPrintNotVisible`),`warning`),we===Se&&Te(null)},100),r=setTimeout(()=>Ce(null),5e3);return()=>{clearTimeout(t),clearTimeout(r)}}},[Se,we,n,e]);let{data:Ye,isLoading:Xe}=q({queryKey:[`archives`,c],queryFn:()=>Q.getArchives(c||void 0)}),{data:Ze}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:Qe}=q({queryKey:[`projects`],queryFn:()=>Q.getProjects()}),{data:$e}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:et}=q({queryKey:[`users`],queryFn:Q.getUsers,enabled:U===`log`}),{data:tt,isLoading:nt}=q({queryKey:[`print-log`,c,Ee,Oe,Ae,Me,o,Pe,Ke],queryFn:()=>Q.getPrintLog({search:o||void 0,printerId:c||void 0,username:Ee||void 0,status:Oe||void 0,dateFrom:Ae||void 0,dateTo:Me||void 0,limit:Ke,offset:Pe}),enabled:U===`log`}),rt=$e?.time_format||`system`,it=$e?.open_in_slicer||$e?.preferred_slicer||`bambu_studio`,at=$e?.use_slicer_api??!1,ot=Yd($e?.currency||`USD`),st=J({mutationFn:async e=>(await Promise.all(e.map(e=>Q.deleteArchive(e))),e.length),onSuccess:e=>{t.invalidateQueries({queryKey:[`archives`]}),P(new Set),n(`${e} archive${e===1?``:`s`} deleted`)},onError:()=>{n(e(`archives.toast.failedDeleteArchives`),`error`)}}),ct=J({mutationFn:()=>Q.clearPrintLog(),onSuccess:r=>{t.invalidateQueries({queryKey:[`print-log`]}),Fe(0),n(e(`archives.log.cleared`,{count:r.deleted}))},onError:()=>{n(e(`archives.log.clearFailed`),`error`)}}),lt=J({mutationFn:e=>Q.deletePrintLogEntry(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`print-log`]}),t.invalidateQueries({queryKey:[`archives-stats`]}),n(e(`archives.log.entryDeleted`))},onError:()=>{n(e(`archives.log.entryDeleteFailed`),`error`)}}),ut=J({mutationFn:({id:e,body:t})=>Q.updatePrintLogEntry(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`print-log`]}),t.invalidateQueries({queryKey:[`archives-stats`]}),Ve(null),n(e(`archives.log.entryUpdated`))},onError:()=>{n(e(`archives.log.entryUpdateFailed`),`error`)}});(0,y.useEffect)(()=>{c===null?localStorage.removeItem(`archiveFilterPrinter`):localStorage.setItem(`archiveFilterPrinter`,c.toString())},[c]),(0,y.useEffect)(()=>{u?localStorage.setItem(`archiveFilterMaterial`,u):localStorage.removeItem(`archiveFilterMaterial`)},[u]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveFilterColors`,JSON.stringify([...f]))},[f]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveColorFilterMode`,m)},[m]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveFilterFavorites`,g.toString())},[g]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveHideFailed`,v.toString())},[v]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveHideDuplicates`,x.toString())},[x]),(0,y.useEffect)(()=>{C?localStorage.setItem(`archiveFilterTag`,C):localStorage.removeItem(`archiveFilterTag`)},[C]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveFilterFileType`,T)},[T]),(0,y.useEffect)(()=>{le(0)},[o,c,u,f,m,g,v,x,C,T,ae,oe]),(0,y.useEffect)(()=>{try{localStorage.setItem(`archivePageSize`,String(ue))}catch{}},[ue]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveViewMode`,U)},[U]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveSortBy`,ae)},[ae]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveCollection`,oe)},[oe]),(0,y.useEffect)(()=>{Ee?localStorage.setItem(`logFilterUser`,Ee):localStorage.removeItem(`logFilterUser`)},[Ee]),(0,y.useEffect)(()=>{Oe?localStorage.setItem(`logFilterStatus`,Oe):localStorage.removeItem(`logFilterStatus`)},[Oe]),(0,y.useEffect)(()=>{Ae?localStorage.setItem(`logFilterDateFrom`,Ae):localStorage.removeItem(`logFilterDateFrom`)},[Ae]),(0,y.useEffect)(()=>{Me?localStorage.setItem(`logFilterDateTo`,Me):localStorage.removeItem(`logFilterDateTo`)},[Me]),(0,y.useEffect)(()=>{localStorage.setItem(`logOffset`,Pe.toString())},[Pe]),(0,y.useEffect)(()=>{localStorage.setItem(`logPageSize`,Ke.toString())},[Ke]);let dt=new Map(Ze?.map(e=>[e.id,e.name])||[]),ft=[...new Set(Ye?.flatMap(e=>e.filament_type?.split(`, `)||[]).filter(Boolean)||[])].sort(),pt=[...new Set(Ye?.flatMap(e=>e.filament_color?.split(`,`)||[]).filter(Boolean)||[])],mt=[...new Set(Ye?.flatMap(e=>e.tags?.split(`,`).map(e=>e.trim())||[]).filter(Boolean)||[])].sort(),ht=Ye?.filter(e=>{let t=new Date,n=mf(e.created_at)||new Date(0),r=!0;switch(oe){case`recent`:r=t.getTime()-n.getTime()<1440*60*1e3;break;case`this-week`:r=t.getTime()-n.getTime()<10080*60*1e3;break;case`this-month`:r=n.getMonth()===t.getMonth()&&n.getFullYear()===t.getFullYear();break;case`favorites`:r=e.is_favorite===!0;break;case`not-printed`:r=e.status===`archived`;break;case`printed`:r=ZFe.includes(e.status);break;case`failed`:r=e.status===`failed`||e.status===`aborted`;break;case`duplicates`:r=e.duplicate_count>0;break}let i=(e.print_name||e.filename).toLowerCase().includes(o.toLowerCase()),a=!u||e.filament_type?.split(`, `).includes(u),s=e.filament_color?.split(`,`)||[],c=f.size===0||(m===`or`?s.some(e=>f.has(e)):[...f].every(e=>s.includes(e))),l=oe===`favorites`||!g||e.is_favorite,d=oe===`failed`||!v||e.status!==`failed`&&e.status!==`aborted`,p=oe===`duplicates`||!x||e.duplicate_count===0||e.duplicate_sequence===0,h=e.tags?.split(`,`).map(e=>e.trim())||[],_=!C||h.includes(C),y=e6(e);return r&&i&&a&&c&&l&&d&&p&&_&&(T===`all`||T===`gcode`&&y||T===`source`&&!y)}).sort((e,t)=>{switch(ae){case`date-desc`:return(mf(t.created_at)?.getTime()||0)-(mf(e.created_at)?.getTime()||0);case`date-asc`:return(mf(e.created_at)?.getTime()||0)-(mf(t.created_at)?.getTime()||0);case`name-asc`:return(e.print_name||e.filename).localeCompare(t.print_name||t.filename);case`name-desc`:return(t.print_name||t.filename).localeCompare(e.print_name||e.filename);case`size-desc`:return t.file_size-e.file_size;case`size-asc`:return e.file_size-t.file_size;default:return 0}}),gt=ht?.length||0,_t=ue===-1,vt=_t?gt||1:ue,yt=Math.max(1,Math.ceil(gt/vt)),bt=_t?ht:ht?.slice(ce*vt,(ce+1)*vt);(0,y.useEffect)(()=>{if(Se&&ht&&!_t){let e=ht.findIndex(e=>e.id===Se);if(e>=0){let t=Math.floor(e/vt);t!==ce&&le(t)}}},[Se]);let xt=z||N.size>0,St=e=>{P(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Ct=()=>{ht&&P(new Set(ht.map(e=>e.id)))},wt=()=>{P(new Set),B(!1)},Tt=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Et=()=>{p(new Set)},Dt=()=>{s(``),l(null),d(null),_(!1),b(!1),S(!1),w(null),E(`all`)},Ot=o||c||u||g||v||x||C||T!==`all`,kt=(0,y.useCallback)(e=>{e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&M(!0)},[]),At=(0,y.useCallback)(e=>{e.preventDefault(),e.currentTarget===e.target&&M(!1)},[]),jt=(0,y.useCallback)(t=>{t.preventDefault(),M(!1);let r=Array.from(t.dataTransfer.files).filter(e=>e.name.endsWith(`.3mf`));r.length>0?(A(r),O(!0)):t.dataTransfer.files.length>0&&n(e(`archives.page.only3mfSupported`),`warning`)},[n,e]),Mt=(0,y.useCallback)(e=>{let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable){e.key===`Escape`&&t.blur();return}switch(e.key){case`/`:e.preventDefault(),a.current?.focus();break;case`u`:case`U`:!e.metaKey&&!e.ctrlKey&&(e.preventDefault(),O(!0));break;case`Escape`:xt&&wt();break}},[xt]);return(0,y.useEffect)(()=>(document.addEventListener(`keydown`,Mt),()=>document.removeEventListener(`keydown`,Mt)),[Mt]),(0,K.jsxs)(`div`,{className:`p-4 md:p-8 relative`,onDragOver:kt,onDragLeave:At,onDrop:jt,children:[j&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none`,children:(0,K.jsxs)(`div`,{className:`border-4 border-dashed border-bambu-green rounded-xl p-12 text-center`,children:[(0,K.jsx)(Su,{className:`w-16 h-16 mx-auto mb-4 text-bambu-green`}),(0,K.jsx)(`p`,{className:`text-2xl font-semibold text-white mb-2`,children:`Drop .3mf files here`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`archives.releaseToUpload`)})]})}),xt&&(0,K.jsxs)(`div`,{className:`fixed bottom-6 left-1/2 -translate-x-1/2 z-40 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl px-4 py-3 flex items-center gap-4`,children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:wt,children:[(0,K.jsx)(Pu,{className:`w-4 h-4`}),`Close`]}),(0,K.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[N.size,` selected`]}),(0,K.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:Ct,children:`Select All`}),(0,K.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>te(!0),disabled:!i(`archives:update_own`,`archives:update_all`),title:i(`archives:update_own`,`archives:update_all`)?void 0:e(`archives.permission.noUpdateArchives`),children:[(0,K.jsx)(su,{className:`w-4 h-4`}),`Tags`]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>re(!0),disabled:!i(`archives:update_own`,`archives:update_all`),title:i(`archives:update_own`,`archives:update_all`)?void 0:e(`archives.permission.noUpdateArchives`),children:[(0,K.jsx)(nc,{className:`w-4 h-4`}),`Project`]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,disabled:!i(`archives:update_own`,`archives:update_all`),title:i(`archives:update_own`,`archives:update_all`)?void 0:e(`archives.permission.noUpdateArchives`),onClick:()=>{let r=Array.from(N);Promise.all(r.map(e=>Q.toggleFavorite(e))).then(()=>{t.invalidateQueries({queryKey:[`archives`]}),n(`Toggled favorites for ${r.length} archive${r.length===1?``:`s`}`)}).catch(()=>{n(e(`archives.toast.failedUpdateFavorites`),`error`)})},children:[(0,K.jsx)(nu,{className:`w-4 h-4`}),`Favorite`]}),(0,K.jsxs)($,{size:`sm`,className:`bg-red-500 hover:bg-red-600`,onClick:()=>ee(!0),disabled:!i(`archives:delete_own`,`archives:delete_all`),title:i(`archives:delete_own`,`archives:delete_all`)?void 0:e(`archives.permission.noDelete`),children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),`Delete`]})]}),L?.has_fallback&&!F&&(0,K.jsxs)(`div`,{className:`mb-6 rounded-lg border border-amber-500/30 bg-amber-500/10 px-4 py-3 flex items-start gap-3`,children:[(0,K.jsx)(ss,{className:`w-5 h-5 text-amber-400 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-amber-200`,children:e(`archives.no3mfBanner.title`)}),(0,K.jsxs)(`div`,{className:`text-xs text-amber-200/80 mt-1`,children:[e(`archives.no3mfBanner.body`),` `,(0,K.jsxs)(`a`,{href:`https://bambuddy.cool/wiki/getting-started/#step-4-enable-store-sent-files-on-external-storage`,target:`_blank`,rel:`noreferrer`,className:`underline hover:text-amber-100 inline-flex items-center gap-1`,children:[e(`archives.no3mfBanner.docsLink`),(0,K.jsx)(Us,{className:`w-3 h-3`})]})]})]}),(0,K.jsx)(`button`,{onClick:R,className:`text-amber-200/60 hover:text-amber-200 flex-shrink-0 p-1 -m-1`,title:e(`archives.no3mfBanner.dismissLabel`),"aria-label":e(`archives.no3mfBanner.dismissLabel`),children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-8`,children:[(0,K.jsx)(`div`,{children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,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)(wo,{className:`w-7 h-7 text-bambu-green`}),`Archives`]}),(0,K.jsxs)(`p`,{className:`text-bambu-gray mt-1`,children:[ht?.length||0,` of `,Ye?.length||0,` prints`]})]}),(0,K.jsx)(`select`,{className:`mt-0.5 px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray-light text-sm focus:border-bambu-green focus:outline-none`,value:oe,onChange:e=>se(e.target.value),children:QFe.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.label},e.id))})]})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3 flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:()=>pe(!fe),disabled:me,children:[me?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Xs,{className:`w-4 h-4`}),`Export`]}),fe&&(0,K.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20`,children:[(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg`,onClick:async()=>{pe(!1),he(!0);try{let{blob:t,filename:r}=await Q.exportArchives({format:`csv`,printerId:c||void 0,status:oe===`failed`?`failed`:void 0,search:o||void 0}),i=URL.createObjectURL(t),a=document.createElement(`a`);a.href=i,a.download=r,a.click(),URL.revokeObjectURL(i),n(e(`archives.toast.exportDownloaded`))}catch{n(e(`archives.toast.exportFailed`),`error`)}finally{he(!1)}},children:[(0,K.jsx)(Zs,{className:`w-4 h-4`}),`Export as CSV`]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg`,onClick:async()=>{pe(!1),he(!0);try{let{blob:t,filename:r}=await Q.exportArchives({format:`xlsx`,printerId:c||void 0,status:oe===`failed`?`failed`:void 0,search:o||void 0}),i=URL.createObjectURL(t),a=document.createElement(`a`);a.href=i,a.download=r,a.click(),URL.revokeObjectURL(i),n(e(`archives.toast.exportDownloaded`))}catch{n(e(`archives.toast.exportFailed`),`error`)}finally{he(!1)}},children:[(0,K.jsx)(Xs,{className:`w-4 h-4`}),`Export as Excel`]})]})]}),N.size>=2&&N.size<=5&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>_e(!0),children:[(0,K.jsx)(pc,{className:`w-4 h-4`}),`Compare (`,N.size,`)`]}),!xt&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>B(!0),children:[(0,K.jsx)($l,{className:`w-4 h-4`}),`Select`]}),(0,K.jsxs)($,{onClick:()=>O(!0),disabled:!r(`archives:create`),title:r(`archives:create`)?void 0:e(`archives.permission.noCreate`),children:[(0,K.jsx)(Su,{className:`w-4 h-4`}),`Upload 3MF`]}),r(`archives:purge`)&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>xe(!0),title:e(`archivePurge.headerTooltip`),children:[(0,K.jsx)(hu,{className:`w-4 h-4 mr-2`}),e(`archivePurge.headerButton`)]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center border border-bambu-dark-tertiary rounded-lg overflow-hidden flex-shrink-0 w-fit mb-4`,children:[(0,K.jsx)(`button`,{className:`p-2 ${U===`grid`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,onClick:()=>ie(`grid`),title:e(`archives.gridView`),children:(0,K.jsx)(Pc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{className:`p-2 ${U===`list`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,onClick:()=>ie(`list`),title:e(`archives.listView`),children:(0,K.jsx)(Bc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{className:`p-2 ${U===`calendar`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,onClick:()=>ie(`calendar`),title:e(`archives.calendarView`),children:(0,K.jsx)(Go,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{className:`p-2 ${U===`log`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,onClick:()=>ie(`log`),title:e(`archives.logView`),children:(0,K.jsx)(gs,{className:`w-4 h-4`})})]}),U!==`log`&&(0,K.jsx)(pd,{className:`mb-6`,children:(0,K.jsxs)(hd,{className:`py-4`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-3 md:gap-4 md:items-center md:flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`w-full md:flex-1 relative md:min-w-[200px]`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{ref:a,type:`text`,placeholder:e(`archives.searchPlaceholder`),className:`w-full pl-10 pr-4 py-3 md:py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:o,onChange:e=>s(e.target.value)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 md:gap-4 overflow-x-auto pb-1 md:pb-0 -mx-4 px-4 md:mx-0 md:px-0 md:flex-wrap scrollbar-hide`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(lc,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:c||``,onChange:e=>l(e.target.value?Number(e.target.value):null),children:[(0,K.jsx)(`option`,{value:``,children:`All Printers`}),Ze?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(cl,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:u||``,onChange:e=>d(e.target.value||null),children:[(0,K.jsx)(`option`,{value:``,children:`All Materials`}),ft.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(Js,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:T,onChange:e=>E(e.target.value),children:[(0,K.jsx)(`option`,{value:`all`,children:`All Files`}),(0,K.jsx)(`option`,{value:`gcode`,children:`Sliced (GCODE)`}),(0,K.jsx)(`option`,{value:`source`,children:`Source Only`})]})]}),(0,K.jsxs)(`button`,{onClick:()=>_(!g),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${g?`bg-yellow-500/20 border-yellow-500 text-yellow-400`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,title:e(g?`archives.showAll`:`archives.showFavoritesOnly`),children:[(0,K.jsx)(nu,{className:`w-4 h-4 ${g?`fill-yellow-400`:``}`}),(0,K.jsx)(`span`,{className:`text-sm hidden md:inline`,children:`Favorites`})]}),(0,K.jsxs)(`button`,{onClick:()=>b(!v),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${v?`bg-red-500/20 border-red-500 text-red-400`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,title:e(v?`archives.showFailedPrints`:`archives.hideFailedPrints`),children:[(0,K.jsx)(ss,{className:`w-4 h-4 `}),(0,K.jsx)(`span`,{className:`text-sm hidden md:inline`,children:`Hide Failed`})]}),(0,K.jsxs)(`button`,{onClick:()=>S(!x),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${x?`bg-purple-500/20 border-purple-500 text-purple-400`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,title:e(`archives.hideDuplicates`),children:[(0,K.jsx)(Ds,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-sm hidden md:inline`,children:e(`archives.hideDuplicates`)})]}),mt.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(su,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:C||``,onChange:e=>w(e.target.value||null),children:[(0,K.jsx)(`option`,{value:``,children:`All Tags`}),mt.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),(0,K.jsx)(`button`,{onClick:()=>ye(!0),className:`p-2 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-green transition-colors`,title:e(`archives.manageTags`),children:(0,K.jsx)(Rl,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(Ao,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:ae,onChange:e=>W(e.target.value),children:[(0,K.jsx)(`option`,{value:`date-desc`,children:e(`archives.sortNewest`)}),(0,K.jsx)(`option`,{value:`date-asc`,children:e(`archives.sortOldest`)}),(0,K.jsxs)(`option`,{value:`name-asc`,children:[e(`archives.sortName`),` A-Z`]}),(0,K.jsxs)(`option`,{value:`name-desc`,children:[e(`archives.sortName`),` Z-A`]}),(0,K.jsx)(`option`,{value:`size-desc`,children:e(`archives.sortLargest`)}),(0,K.jsx)(`option`,{value:`size-asc`,children:e(`archives.sortSmallest`)})]})]})]}),Ot&&(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:Dt,className:`text-bambu-gray hover:text-white`,children:[(0,K.jsx)(Pu,{className:`w-4 h-4`}),`Reset`]})]}),pt.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`Colors:`}),f.size>1&&(0,K.jsx)(`button`,{onClick:()=>h(e=>e===`or`?`and`:`or`),className:`px-2 py-0.5 text-xs rounded transition-colors ${m===`and`?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,title:m===`or`?`Match ANY selected color`:`Match ALL selected colors`,children:m.toUpperCase()}),(0,K.jsx)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:pt.map(e=>(0,K.jsx)(`button`,{onClick:()=>Tt(e),className:`w-6 h-6 rounded-full border-2 transition-all ${f.has(e)?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:e},title:e},e))}),f.size>0&&(0,K.jsxs)(`button`,{onClick:Et,className:`text-xs text-bambu-gray hover:text-white flex items-center gap-1`,children:[(0,K.jsx)(Pu,{className:`w-3 h-3`}),`Clear`]})]})]})}),(0,K.jsx)(qFe,{}),Xe?(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`archives.loadingArchives`)}):ht?.length===0?(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`text-center py-12`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(o?`archives.noArchivesSearch`:`archives.noArchivesYet`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:`Archives are created automatically when prints complete`})]})}):U===`calendar`?(0,K.jsx)(pd,{className:`p-6`,children:(0,K.jsx)(aDe,{archives:ht||[],onArchiveClick:e=>{s(``),ie(`grid`),Ce(e.id)},highlightedArchiveId:Se})}):U===`grid`?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6`,children:bt?.map(t=>(0,K.jsx)(YFe,{archive:t,printerName:t.printer_id?dt.get(t.printer_id)||`Unknown`:t.sliced_for_model||`No Printer`,isSelected:N.has(t.id),onSelect:St,selectionMode:xt,projects:Qe,isHighlighted:t.id===Se,timeFormat:rt,preferredSlicer:it,useSlicerApi:at,currency:ot,t:e,onNavigateToArchive:Je},t.id))}),(0,K.jsx)(n6,{pageIndex:ce,pageSize:ue,totalRows:gt,totalPages:yt,onPageChange:le,onPageSizeChange:e=>{de(e),le(0)},t:e})]}):U===`list`?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(pd,{children:(0,K.jsxs)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-12 gap-4 px-4 py-3 text-xs text-bambu-gray font-medium`,children:[(0,K.jsx)(`div`,{className:`col-span-1`}),(0,K.jsx)(`div`,{className:`col-span-4`,children:`Name`}),(0,K.jsx)(`div`,{className:`col-span-2`,children:`Printer`}),(0,K.jsx)(`div`,{className:`col-span-2`,children:`Date`}),(0,K.jsx)(`div`,{className:`col-span-1`,children:`Size`}),(0,K.jsx)(`div`,{className:`col-span-2 text-right`,children:`Actions`})]}),bt?.map(t=>(0,K.jsx)(XFe,{archive:t,printerName:t.printer_id?dt.get(t.printer_id)||`Unknown`:t.sliced_for_model||`No Printer`,isSelected:N.has(t.id),onSelect:St,selectionMode:xt,projects:Qe,isHighlighted:t.id===Se,preferredSlicer:it,useSlicerApi:at,t:e,onNavigateToArchive:Je},t.id))]})}),(0,K.jsx)(n6,{pageIndex:ce,pageSize:ue,totalRows:gt,totalPages:yt,onPageChange:le,onPageSizeChange:e=>{de(e),le(0)},t:e})]}):U===`log`?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-3`,children:(0,K.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-3 md:items-center md:flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`flex-1 relative md:min-w-[200px]`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,placeholder:e(`archives.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:o,onChange:e=>{s(e.target.value),Fe(0)}})]}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:c||``,onChange:e=>{l(e.target.value?Number(e.target.value):null),Fe(0)},children:[(0,K.jsx)(`option`,{value:``,children:e(`archives.log.allPrinters`)}),Ze?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:Ee||``,onChange:e=>{De(e.target.value||null),Fe(0)},children:[(0,K.jsx)(`option`,{value:``,children:e(`archives.log.allUsers`)}),et?.map(e=>(0,K.jsx)(`option`,{value:e.username,children:e.username},e.id))]}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:Oe||``,onChange:e=>{ke(e.target.value||null),Fe(0)},children:[(0,K.jsx)(`option`,{value:``,children:e(`archives.log.allStatuses`)}),(0,K.jsx)(`option`,{value:`completed`,children:e(`archives.status.completed`)}),(0,K.jsx)(`option`,{value:`failed`,children:e(`archives.status.failed`)}),(0,K.jsx)(`option`,{value:`stopped`,children:e(`archives.status.stopped`)}),(0,K.jsx)(`option`,{value:`cancelled`,children:e(`archives.log.cancelled`)}),(0,K.jsx)(`option`,{value:`skipped`,children:e(`archives.log.skipped`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`label`,{className:`text-sm text-bambu-gray`,children:e(`archives.log.dateFrom`)}),(0,K.jsx)(`input`,{type:`date`,className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:Ae,onChange:e=>{je(e.target.value),Fe(0)}})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`label`,{className:`text-sm text-bambu-gray`,children:e(`archives.log.dateTo`)}),(0,K.jsx)(`input`,{type:`date`,className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:Me,onChange:e=>{Ne(e.target.value),Fe(0)}})]}),(0,K.jsx)(`div`,{className:`ml-auto`,children:(0,K.jsxs)($,{variant:`danger`,size:`sm`,onClick:()=>Le(!0),disabled:!r(`archives:delete_all`)||ct.isPending,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`archives.log.clearLog`)]})})]})})}),(0,K.jsx)(pd,{children:nt?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):tt?.items.length?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-bambu-gray text-left`,children:[(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.date`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.printName`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.printer`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.user`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.status`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.duration`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.filament`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium w-10`,"aria-label":e(`common.actions`)})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:tt.items.map(t=>(0,K.jsxs)(`tr`,{className:`hover:bg-bambu-dark-secondary/50`,children:[(0,K.jsx)(`td`,{className:`px-4 py-3 text-white whitespace-nowrap`,children:gf(t.started_at||t.created_at,rt)}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.thumbnail_path&&(0,K.jsx)(`img`,{src:Q.getPrintLogThumbnail(t.id),alt:``,className:`w-8 h-8 rounded object-cover flex-shrink-0`,onError:e=>{e.target.style.display=`none`}}),(0,K.jsx)(`span`,{className:`text-white break-words`,title:t.print_name||``,children:t.print_name||`—`})]})}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-bambu-gray-light`,children:t.printer_name||`—`}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-bambu-gray-light`,children:t.created_by_username||`—`}),(0,K.jsxs)(`td`,{className:`px-4 py-3`,children:[(0,K.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${t.status===`completed`?`bg-green-500/20 text-green-400`:t.status===`failed`?`bg-red-500/20 text-red-400`:t.status===`stopped`?`bg-yellow-500/20 text-yellow-400`:t.status===`cancelled`?`bg-orange-500/20 text-orange-400`:t.status===`skipped`?`bg-blue-500/20 text-blue-400`:`bg-gray-500/20 text-gray-400`}`,children:t.status}),t.failure_reason&&(0,K.jsx)(`span`,{className:`block text-[10px] text-bambu-gray mt-0.5`,children:e(`editArchive.failureReasons.${t.failure_reason}`,{defaultValue:t.failure_reason})})]}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-bambu-gray-light whitespace-nowrap`,children:t.duration_seconds?yf(t.duration_seconds):`—`}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[t.filament_color&&(0,K.jsx)(`div`,{className:`flex items-center gap-0.5 flex-wrap`,children:t.filament_color.split(`,`).map((e,t)=>{let n=e.trim();return(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:n.startsWith(`#`)?n:void 0},title:n},t)})}),(0,K.jsx)(`span`,{className:`text-bambu-gray-light text-xs`,children:t.filament_type||`—`})]})}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-right`,children:(0,K.jsxs)(`div`,{className:`inline-flex items-center gap-2`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{Ve(t),Ue(t.failure_reason||``),Ge(t.status)},disabled:ut.isPending||!(r(`archives:update_all`)||r(`archives:update_own`)),title:r(`archives:update_all`)||r(`archives:update_own`)?e(`archives.log.editEntryTitle`):e(`archives.permission.noEdit`),className:`text-bambu-gray hover:text-bambu-blue disabled:opacity-40 disabled:hover:text-bambu-gray transition-colors`,children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>ze(t.id),disabled:lt.isPending||!(r(`archives:delete_all`)||r(`archives:delete_own`)),title:r(`archives:delete_all`)||r(`archives:delete_own`)?e(`archives.log.deleteEntryTitle`):e(`archives.permission.noDelete`),className:`text-bambu-gray hover:text-red-400 disabled:opacity-40 disabled:hover:text-bambu-gray transition-colors`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})})]},t.id))})]})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-t border-bambu-dark-tertiary flex-wrap gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`archives.log.showing`,{count:Math.min(Pe+Ke,tt.total),total:tt.total})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:e(`archives.log.rowsPerPage`)}),(0,K.jsxs)(`select`,{className:`px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs focus:border-bambu-green focus:outline-none`,value:Ke,onChange:e=>{qe(Number(e.target.value)),Fe(0)},children:[(0,K.jsx)(`option`,{value:10,children:`10`}),(0,K.jsx)(`option`,{value:25,children:`25`}),(0,K.jsx)(`option`,{value:50,children:`50`}),(0,K.jsx)(`option`,{value:100,children:`100`})]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`archives.log.page`),` `,Math.floor(Pe/Ke)+1,` / `,Math.max(1,Math.ceil(tt.total/Ke))]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>Fe(Math.max(0,Pe-Ke)),disabled:Pe===0,children:(0,K.jsx)(ns,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>Fe(Pe+Ke),disabled:Pe+Ke>=tt.total,children:(0,K.jsx)(ts,{className:`w-4 h-4`})})]})]})]}):(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`archives.log.noEntries`)})})]}):null,D&&(0,K.jsx)(KEe,{onClose:()=>{O(!1),A([])},initialFiles:k}),be&&(0,K.jsx)(JEe,{onClose:()=>xe(!1)}),V&&(0,K.jsx)(Ed,{title:e(`archives.modal.deleteArchives`),message:e(`archives.modal.deleteArchivesConfirm`,{count:N.size}),confirmText:e(`archives.modal.deleteCount`,{count:N.size}),variant:`danger`,onConfirm:()=>{st.mutate(Array.from(N)),ee(!1)},onCancel:()=>ee(!1)}),H&&(0,K.jsx)($Ee,{selectedIds:Array.from(N),existingTags:mt,onClose:()=>te(!1)}),ne&&(0,K.jsx)(eDe,{selectedIds:Array.from(N),onClose:()=>re(!1)}),ge&&N.size>=2&&N.size<=5&&(0,K.jsx)(UFe,{archiveIds:Array.from(N),onClose:()=>{_e(!1),P(new Set),B(!1)}}),ve&&(0,K.jsx)(JFe,{onClose:()=>ye(!1)}),Ie&&(0,K.jsx)(Ed,{title:e(`archives.log.clearLogTitle`),message:e(`archives.log.clearLogConfirm`),confirmText:e(`archives.log.clearLogButton`),variant:`danger`,onConfirm:()=>{ct.mutate(),Le(!1)},onCancel:()=>Le(!1)}),Re!==null&&(0,K.jsx)(Ed,{title:e(`archives.log.deleteEntryTitle`),message:e(`archives.log.deleteEntryConfirm`),confirmText:e(`common.delete`),variant:`danger`,onConfirm:()=>{lt.mutate(Re),ze(null)},onCancel:()=>ze(null)}),Be!==null&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:()=>Ve(null),children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-md mx-4 p-6`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-4`,children:e(`archives.log.editEntryTitle`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4`,children:e(`archives.log.editEntryDescription`)}),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`editArchive.status`)}),(0,K.jsxs)(`select`,{value:We,onChange:e=>Ge(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`completed`,children:e(`archives.log.statuses.completed`,{defaultValue:`completed`})}),(0,K.jsx)(`option`,{value:`failed`,children:e(`archives.log.statuses.failed`,{defaultValue:`failed`})}),(0,K.jsx)(`option`,{value:`stopped`,children:e(`archives.log.statuses.stopped`,{defaultValue:`stopped`})}),(0,K.jsx)(`option`,{value:`cancelled`,children:e(`archives.log.statuses.cancelled`,{defaultValue:`cancelled`})}),(0,K.jsx)(`option`,{value:`skipped`,children:e(`archives.log.statuses.skipped`,{defaultValue:`skipped`})})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`editArchive.failureReason`)}),(0,K.jsxs)(`select`,{value:He,onChange:e=>Ue(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:``,children:e(`editArchive.selectReason`)}),qq.map(t=>(0,K.jsx)(`option`,{value:t,children:e(`editArchive.failureReasons.${t}`)},t))]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 mt-6`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>Ve(null),children:e(`common.cancel`)}),(0,K.jsx)($,{variant:`primary`,onClick:()=>{let e={};if(He!==(Be.failure_reason||``)&&(e.failure_reason=He||null),We!==Be.status&&(e.status=We),Object.keys(e).length===0){Ve(null);return}ut.mutate({id:Be.id,body:e})},disabled:ut.isPending,children:ut.isPending?e(`editArchive.saving`):e(`common.save`)})]})]})})]})}function n6({pageIndex:e,pageSize:t,totalRows:n,totalPages:r,onPageChange:i,onPageSizeChange:a,t:o}){let s=t===-1;if(r<=1&&!s)return null;let c=s?n||1:t;return(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-2 text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:s?`${n} ${o(`archives.prints`)}`:(0,K.jsxs)(K.Fragment,{children:[o(`archives.pagination.showing`),` `,e*c+1,` `,o(`archives.pagination.to`),` `,Math.min((e+1)*c,n),` `,o(`archives.pagination.of`),` `,n,` `,o(`archives.prints`)]})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:o(`archives.pagination.show`)}),(0,K.jsxs)(`select`,{value:t,onChange:e=>a(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[25,50,100,200].map(e=>(0,K.jsx)(`option`,{value:e,children:e},e)),(0,K.jsx)(`option`,{value:-1,children:o(`archives.pagination.all`)})]}),!s&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:()=>i(0),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(is,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>i(Math.max(0,e-1)),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(ns,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[o(`archives.pagination.page`),` `,e+1,` `,o(`archives.pagination.of`),` `,r]}),(0,K.jsx)(`button`,{onClick:()=>i(Math.min(r-1,e+1)),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(ts,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>i(r-1),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(as,{className:`w-4 h-4`})})]})]})]})}function eIe(){var e=[...arguments];return(0,y.useMemo)(()=>t=>{e.forEach(e=>e(t))},e)}var r6=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function i6(e){let t=Object.prototype.toString.call(e);return t===`[object Window]`||t===`[object global]`}function a6(e){return`nodeType`in e}function o6(e){return e?i6(e)?e:a6(e)?e.ownerDocument?.defaultView??window:window:window}function s6(e){let{Document:t}=o6(e);return e instanceof t}function c6(e){return i6(e)?!1:e instanceof o6(e).HTMLElement}function l6(e){return e instanceof o6(e).SVGElement}function u6(e){return e?i6(e)?e.document:a6(e)?s6(e)?e:c6(e)||l6(e)?e.ownerDocument:document:document:document}var d6=r6?y.useLayoutEffect:y.useEffect;function f6(e){let t=(0,y.useRef)(e);return d6(()=>{t.current=e}),(0,y.useCallback)(function(){var e=[...arguments];return t.current==null?void 0:t.current(...e)},[])}function tIe(){let e=(0,y.useRef)(null);return[(0,y.useCallback)((t,n)=>{e.current=setInterval(t,n)},[]),(0,y.useCallback)(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[])]}function p6(e,t){t===void 0&&(t=[e]);let n=(0,y.useRef)(e);return d6(()=>{n.current!==e&&(n.current=e)},t),n}function m6(e,t){let n=(0,y.useRef)();return(0,y.useMemo)(()=>{let t=e(n.current);return n.current=t,t},[...t])}function h6(e){let t=f6(e),n=(0,y.useRef)(null);return[n,(0,y.useCallback)(e=>{e!==n.current&&t?.(e,n.current),n.current=e},[])]}function g6(e){let t=(0,y.useRef)();return(0,y.useEffect)(()=>{t.current=e},[e]),t.current}var _6={};function v6(e,t){return(0,y.useMemo)(()=>{if(t)return t;let n=_6[e]==null?0:_6[e]+1;return _6[e]=n,e+`-`+n},[e,t])}function y6(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>{let r=Object.entries(n);for(let[n,i]of r){let r=t[n];r!=null&&(t[n]=r+e*i)}return t},{...t})}}var b6=y6(1),x6=y6(-1);function nIe(e){return`clientX`in e&&`clientY`in e}function S6(e){if(!e)return!1;let{KeyboardEvent:t}=o6(e.target);return t&&e instanceof t}function rIe(e){if(!e)return!1;let{TouchEvent:t}=o6(e.target);return t&&e instanceof t}function C6(e){if(rIe(e)){if(e.touches&&e.touches.length){let{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){let{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return nIe(e)?{x:e.clientX,y:e.clientY}:null}var w6=Object.freeze({Translate:{toString(e){if(!e)return;let{x:t,y:n}=e;return`translate3d(`+(t?Math.round(t):0)+`px, `+(n?Math.round(n):0)+`px, 0)`}},Scale:{toString(e){if(!e)return;let{scaleX:t,scaleY:n}=e;return`scaleX(`+t+`) scaleY(`+n+`)`}},Transform:{toString(e){if(e)return[w6.Translate.toString(e),w6.Scale.toString(e)].join(` `)}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+` `+n+`ms `+r}}}),T6=`a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]`;function iIe(e){return e.matches(T6)?e:e.querySelector(T6)}var aIe={display:`none`};function oIe(e){let{id:t,value:n}=e;return y.createElement(`div`,{id:t,style:aIe},n)}function sIe(e){let{id:t,announcement:n,ariaLiveType:r=`assertive`}=e;return y.createElement(`div`,{id:t,style:{position:`fixed`,top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:`hidden`,clip:`rect(0 0 0 0)`,clipPath:`inset(100%)`,whiteSpace:`nowrap`},role:`status`,"aria-live":r,"aria-atomic":!0},n)}function cIe(){let[e,t]=(0,y.useState)(``);return{announce:(0,y.useCallback)(e=>{e!=null&&t(e)},[]),announcement:e}}var E6=(0,y.createContext)(null);function lIe(e){let t=(0,y.useContext)(E6);(0,y.useEffect)(()=>{if(!t)throw Error(`useDndMonitor must be used within a children of `);return t(e)},[e,t])}function uIe(){let[e]=(0,y.useState)(()=>new Set),t=(0,y.useCallback)(t=>(e.add(t),()=>e.delete(t)),[e]);return[(0,y.useCallback)(t=>{let{type:n,event:r}=t;e.forEach(e=>e[n]?.call(e,r))},[e]),t]}var dIe={draggable:` To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel. - `},dIe={onDragStart(e){let{active:t}=e;return`Picked up draggable item `+t.id+`.`},onDragOver(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was moved over droppable area `+n.id+`.`:`Draggable item `+t.id+` is no longer over a droppable area.`},onDragEnd(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was dropped over droppable area `+n.id:`Draggable item `+t.id+` was dropped.`},onDragCancel(e){let{active:t}=e;return`Dragging was cancelled. Draggable item `+t.id+` was dropped.`}};function fIe(e){let{announcements:t=dIe,container:n,hiddenTextDescribedById:r,screenReaderInstructions:i=uIe}=e,{announce:a,announcement:o}=sIe(),s=v6(`DndLiveRegion`),[c,l]=(0,y.useState)(!1);if((0,y.useEffect)(()=>{l(!0)},[]),cIe((0,y.useMemo)(()=>({onDragStart(e){let{active:n}=e;a(t.onDragStart({active:n}))},onDragMove(e){let{active:n,over:r}=e;t.onDragMove&&a(t.onDragMove({active:n,over:r}))},onDragOver(e){let{active:n,over:r}=e;a(t.onDragOver({active:n,over:r}))},onDragEnd(e){let{active:n,over:r}=e;a(t.onDragEnd({active:n,over:r}))},onDragCancel(e){let{active:n,over:r}=e;a(t.onDragCancel({active:n,over:r}))}}),[a,t])),!c)return null;let u=y.createElement(y.Fragment,null,y.createElement(aIe,{id:r,value:i.draggable}),y.createElement(oIe,{id:s,announcement:o}));return n?(0,Zf.createPortal)(u,n):u}var D6;(function(e){e.DragStart=`dragStart`,e.DragMove=`dragMove`,e.DragEnd=`dragEnd`,e.DragCancel=`dragCancel`,e.DragOver=`dragOver`,e.RegisterDroppable=`registerDroppable`,e.SetDroppableDisabled=`setDroppableDisabled`,e.UnregisterDroppable=`unregisterDroppable`})(D6||={});function O6(){}function k6(e,t){return(0,y.useMemo)(()=>({sensor:e,options:t??{}}),[e,t])}function A6(){var e=[...arguments];return(0,y.useMemo)(()=>[...e].filter(e=>e!=null),[...e])}var j6=Object.freeze({x:0,y:0});function M6(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function pIe(e,t){let n=C6(e);if(!n)return`0 0`;let r={x:(n.x-t.left)/t.width*100,y:(n.y-t.top)/t.height*100};return r.x+`% `+r.y+`%`}function N6(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function mIe(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function P6(e){let{left:t,top:n,height:r,width:i}=e;return[{x:t,y:n},{x:t+i,y:n},{x:t,y:n+r},{x:t+i,y:n+r}]}function F6(e,t){if(!e||e.length===0)return null;let[n]=e;return t?n[t]:n}function I6(e,t,n){return t===void 0&&(t=e.left),n===void 0&&(n=e.top),{x:t+e.width*.5,y:n+e.height*.5}}var L6=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=I6(t,t.left,t.top),a=[];for(let e of r){let{id:t}=e,r=n.get(t);if(r){let n=M6(I6(r),i);a.push({id:t,data:{droppableContainer:e,value:n}})}}return a.sort(N6)},hIe=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=P6(t),a=[];for(let e of r){let{id:t}=e,r=n.get(t);if(r){let n=P6(r),o=i.reduce((e,t,r)=>e+M6(n[r],t),0),s=Number((o/4).toFixed(4));a.push({id:t,data:{droppableContainer:e,value:s}})}}return a.sort(N6)};function gIe(e,t){let n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),a=Math.min(t.top+t.height,e.top+e.height),o=i-r,s=a-n;if(r{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=[];for(let e of r){let{id:r}=e,a=n.get(r);if(a){let n=gIe(a,t);n>0&&i.push({id:r,data:{droppableContainer:e,value:n}})}}return i.sort(mIe)};function vIe(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function R6(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:j6}function yIe(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>({...t,top:t.top+e*n.y,bottom:t.bottom+e*n.y,left:t.left+e*n.x,right:t.right+e*n.x}),{...t})}}var bIe=yIe(1);function z6(e){if(e.startsWith(`matrix3d(`)){let t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith(`matrix(`)){let t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function xIe(e,t,n){let r=z6(t);if(!r)return e;let{scaleX:i,scaleY:a,x:o,y:s}=r,c=e.left-o-(1-i)*parseFloat(n),l=e.top-s-(1-a)*parseFloat(n.slice(n.indexOf(` `)+1)),u=i?e.width/i:e.width,d=a?e.height/a:e.height;return{width:u,height:d,top:l,right:c+u,bottom:l+d,left:c}}var SIe={ignoreTransform:!1};function B6(e,t){t===void 0&&(t=SIe);let n=e.getBoundingClientRect();if(t.ignoreTransform){let{transform:t,transformOrigin:r}=o6(e).getComputedStyle(e);t&&(n=xIe(n,t,r))}let{top:r,left:i,width:a,height:o,bottom:s,right:c}=n;return{top:r,left:i,width:a,height:o,bottom:s,right:c}}function V6(e){return B6(e,{ignoreTransform:!0})}function CIe(e){let t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function wIe(e,t){return t===void 0&&(t=o6(e).getComputedStyle(e)),t.position===`fixed`}function TIe(e,t){t===void 0&&(t=o6(e).getComputedStyle(e));let n=/(auto|scroll|overlay)/;return[`overflow`,`overflowX`,`overflowY`].some(e=>{let r=t[e];return typeof r==`string`?n.test(r):!1})}function H6(e,t){let n=[];function r(i){if(t!=null&&n.length>=t||!i)return n;if(s6(i)&&i.scrollingElement!=null&&!n.includes(i.scrollingElement))return n.push(i.scrollingElement),n;if(!c6(i)||l6(i)||n.includes(i))return n;let a=o6(e).getComputedStyle(i);return i!==e&&TIe(i,a)&&n.push(i),wIe(i,a)?n:r(i.parentNode)}return e?r(e):n}function U6(e){let[t]=H6(e,1);return t??null}function W6(e){return!r6||!e?null:i6(e)?e:a6(e)?s6(e)||e===u6(e).scrollingElement?window:c6(e)?e:null:null}function G6(e){return i6(e)?e.scrollX:e.scrollLeft}function K6(e){return i6(e)?e.scrollY:e.scrollTop}function q6(e){return{x:G6(e),y:K6(e)}}var J6;(function(e){e[e.Forward=1]=`Forward`,e[e.Backward=-1]=`Backward`})(J6||={});function Y6(e){return!r6||!e?!1:e===document.scrollingElement}function X6(e){let t={x:0,y:0},n=Y6(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},r={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height};return{isTop:e.scrollTop<=t.y,isLeft:e.scrollLeft<=t.x,isBottom:e.scrollTop>=r.y,isRight:e.scrollLeft>=r.x,maxScroll:r,minScroll:t}}var EIe={x:.2,y:.2};function DIe(e,t,n,r,i){let{top:a,left:o,right:s,bottom:c}=n;r===void 0&&(r=10),i===void 0&&(i=EIe);let{isTop:l,isBottom:u,isLeft:d,isRight:f}=X6(e),p={x:0,y:0},m={x:0,y:0},h={height:t.height*i.y,width:t.width*i.x};return!l&&a<=t.top+h.height?(p.y=J6.Backward,m.y=r*Math.abs((t.top+h.height-a)/h.height)):!u&&c>=t.bottom-h.height&&(p.y=J6.Forward,m.y=r*Math.abs((t.bottom-h.height-c)/h.height)),!f&&s>=t.right-h.width?(p.x=J6.Forward,m.x=r*Math.abs((t.right-h.width-s)/h.width)):!d&&o<=t.left+h.width&&(p.x=J6.Backward,m.x=r*Math.abs((t.left+h.width-o)/h.width)),{direction:p,speed:m}}function OIe(e){if(e===document.scrollingElement){let{innerWidth:e,innerHeight:t}=window;return{top:0,left:0,right:e,bottom:t,width:e,height:t}}let{top:t,left:n,right:r,bottom:i}=e.getBoundingClientRect();return{top:t,left:n,right:r,bottom:i,width:e.clientWidth,height:e.clientHeight}}function Z6(e){return e.reduce((e,t)=>b6(e,q6(t)),j6)}function kIe(e){return e.reduce((e,t)=>e+G6(t),0)}function AIe(e){return e.reduce((e,t)=>e+K6(t),0)}function Q6(e,t){if(t===void 0&&(t=B6),!e)return;let{top:n,left:r,bottom:i,right:a}=t(e);U6(e)&&(i<=0||a<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:`center`,inline:`center`})}var jIe=[[`x`,[`left`,`right`],kIe],[`y`,[`top`,`bottom`],AIe]],$6=class{constructor(e,t){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;let n=H6(t),r=Z6(n);this.rect={...e},this.width=e.width,this.height=e.height;for(let[e,t,i]of jIe)for(let a of t)Object.defineProperty(this,a,{get:()=>{let t=i(n),o=r[e]-t;return this.rect[a]+o},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}},e8=class{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(e=>this.target?.removeEventListener(...e))},this.target=e}add(e,t,n){var r;(r=this.target)==null||r.addEventListener(e,t,n),this.listeners.push([e,t,n])}};function MIe(e){let{EventTarget:t}=o6(e);return e instanceof t?e:u6(e)}function t8(e,t){let n=Math.abs(e.x),r=Math.abs(e.y);return typeof t==`number`?Math.sqrt(n**2+r**2)>t:`x`in t&&`y`in t?n>t.x&&r>t.y:`x`in t?n>t.x:`y`in t?r>t.y:!1}var n8;(function(e){e.Click=`click`,e.DragStart=`dragstart`,e.Keydown=`keydown`,e.ContextMenu=`contextmenu`,e.Resize=`resize`,e.SelectionChange=`selectionchange`,e.VisibilityChange=`visibilitychange`})(n8||={});function r8(e){e.preventDefault()}function NIe(e){e.stopPropagation()}var i8;(function(e){e.Space=`Space`,e.Down=`ArrowDown`,e.Right=`ArrowRight`,e.Left=`ArrowLeft`,e.Up=`ArrowUp`,e.Esc=`Escape`,e.Enter=`Enter`,e.Tab=`Tab`})(i8||={});var a8={start:[i8.Space,i8.Enter],cancel:[i8.Esc],end:[i8.Space,i8.Enter,i8.Tab]},PIe=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case i8.Right:return{...n,x:n.x+25};case i8.Left:return{...n,x:n.x-25};case i8.Down:return{...n,y:n.y+25};case i8.Up:return{...n,y:n.y-25}}},o8=class{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;let{event:{target:t}}=e;this.props=e,this.listeners=new e8(u6(t)),this.windowListeners=new e8(o6(t)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(n8.Resize,this.handleCancel),this.windowListeners.add(n8.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(n8.Keydown,this.handleKeyDown))}handleStart(){let{activeNode:e,onStart:t}=this.props,n=e.node.current;n&&Q6(n),t(j6)}handleKeyDown(e){if(S6(e)){let{active:t,context:n,options:r}=this.props,{keyboardCodes:i=a8,coordinateGetter:a=PIe,scrollBehavior:o=`smooth`}=r,{code:s}=e;if(i.end.includes(s)){this.handleEnd(e);return}if(i.cancel.includes(s)){this.handleCancel(e);return}let{collisionRect:c}=n.current,l=c?{x:c.left,y:c.top}:j6;this.referenceCoordinates||=l;let u=a(e,{active:t,context:n.current,currentCoordinates:l});if(u){let t=x6(u,l),r={x:0,y:0},{scrollableAncestors:i}=n.current;for(let n of i){let i=e.code,{isTop:a,isRight:s,isLeft:c,isBottom:l,maxScroll:d,minScroll:f}=X6(n),p=OIe(n),m={x:Math.min(i===i8.Right?p.right-p.width/2:p.right,Math.max(i===i8.Right?p.left:p.left+p.width/2,u.x)),y:Math.min(i===i8.Down?p.bottom-p.height/2:p.bottom,Math.max(i===i8.Down?p.top:p.top+p.height/2,u.y))},h=i===i8.Right&&!s||i===i8.Left&&!c,g=i===i8.Down&&!l||i===i8.Up&&!a;if(h&&m.x!==u.x){let e=n.scrollLeft+t.x,a=i===i8.Right&&e<=d.x||i===i8.Left&&e>=f.x;if(a&&!t.y){n.scrollTo({left:e,behavior:o});return}a?r.x=n.scrollLeft-e:r.x=i===i8.Right?n.scrollLeft-d.x:n.scrollLeft-f.x,r.x&&n.scrollBy({left:-r.x,behavior:o});break}else if(g&&m.y!==u.y){let e=n.scrollTop+t.y,a=i===i8.Down&&e<=d.y||i===i8.Up&&e>=f.y;if(a&&!t.x){n.scrollTo({top:e,behavior:o});return}a?r.y=n.scrollTop-e:r.y=i===i8.Down?n.scrollTop-d.y:n.scrollTop-f.y,r.y&&n.scrollBy({top:-r.y,behavior:o});break}}this.handleMove(e,b6(x6(u,this.referenceCoordinates),r))}}}handleMove(e,t){let{onMove:n}=this.props;e.preventDefault(),n(t)}handleEnd(e){let{onEnd:t}=this.props;e.preventDefault(),this.detach(),t()}handleCancel(e){let{onCancel:t}=this.props;e.preventDefault(),this.detach(),t()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}};o8.activators=[{eventName:`onKeyDown`,handler:(e,t,n)=>{let{keyboardCodes:r=a8,onActivation:i}=t,{active:a}=n,{code:o}=e.nativeEvent;if(r.start.includes(o)){let t=a.activatorNode.current;return t&&e.target!==t?!1:(e.preventDefault(),i?.({event:e.nativeEvent}),!0)}return!1}}];function s8(e){return!!(e&&`distance`in e)}function c8(e){return!!(e&&`delay`in e)}var l8=class{constructor(e,t,n){n===void 0&&(n=MIe(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=t;let{event:r}=e,{target:i}=r;this.props=e,this.events=t,this.document=u6(i),this.documentListeners=new e8(this.document),this.listeners=new e8(n),this.windowListeners=new e8(o6(i)),this.initialCoordinates=C6(r)??j6,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){let{events:e,props:{options:{activationConstraint:t,bypassActivationConstraint:n}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(n8.Resize,this.handleCancel),this.windowListeners.add(n8.DragStart,r8),this.windowListeners.add(n8.VisibilityChange,this.handleCancel),this.windowListeners.add(n8.ContextMenu,r8),this.documentListeners.add(n8.Keydown,this.handleKeydown),t){if(n!=null&&n({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(c8(t)){this.timeoutId=setTimeout(this.handleStart,t.delay),this.handlePending(t);return}if(s8(t)){this.handlePending(t);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,t){let{active:n,onPending:r}=this.props;r(n,e,this.initialCoordinates,t)}handleStart(){let{initialCoordinates:e}=this,{onStart:t}=this.props;e&&(this.activated=!0,this.documentListeners.add(n8.Click,NIe,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(n8.SelectionChange,this.removeTextSelection),t(e))}handleMove(e){let{activated:t,initialCoordinates:n,props:r}=this,{onMove:i,options:{activationConstraint:a}}=r;if(!n)return;let o=C6(e)??j6,s=x6(n,o);if(!t&&a){if(s8(a)){if(a.tolerance!=null&&t8(s,a.tolerance))return this.handleCancel();if(t8(s,a.distance))return this.handleStart()}if(c8(a)&&t8(s,a.tolerance))return this.handleCancel();this.handlePending(a,s);return}e.cancelable&&e.preventDefault(),i(o)}handleEnd(){let{onAbort:e,onEnd:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleCancel(){let{onAbort:e,onCancel:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleKeydown(e){e.code===i8.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}},FIe={cancel:{name:`pointercancel`},move:{name:`pointermove`},end:{name:`pointerup`}},u8=class extends l8{constructor(e){let{event:t}=e,n=u6(t.target);super(e,FIe,n)}};u8.activators=[{eventName:`onPointerDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r?.({event:n}),!0)}}];var IIe={move:{name:`mousemove`},end:{name:`mouseup`}},d8;(function(e){e[e.RightClick=2]=`RightClick`})(d8||={});var LIe=class extends l8{constructor(e){super(e,IIe,u6(e.event.target))}};LIe.activators=[{eventName:`onMouseDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===d8.RightClick?!1:(r?.({event:n}),!0)}}];var f8={cancel:{name:`touchcancel`},move:{name:`touchmove`},end:{name:`touchend`}},RIe=class extends l8{constructor(e){super(e,f8)}static setup(){return window.addEventListener(f8.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(f8.move.name,e)};function e(){}}};RIe.activators=[{eventName:`onTouchStart`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t,{touches:i}=n;return i.length>1?!1:(r?.({event:n}),!0)}}];var p8;(function(e){e[e.Pointer=0]=`Pointer`,e[e.DraggableRect=1]=`DraggableRect`})(p8||={});var m8;(function(e){e[e.TreeOrder=0]=`TreeOrder`,e[e.ReversedTreeOrder=1]=`ReversedTreeOrder`})(m8||={});function zIe(e){let{acceleration:t,activator:n=p8.Pointer,canScroll:r,draggingRect:i,enabled:a,interval:o=5,order:s=m8.TreeOrder,pointerCoordinates:c,scrollableAncestors:l,scrollableAncestorRects:u,delta:d,threshold:f}=e,p=VIe({delta:d,disabled:!a}),[m,h]=eIe(),g=(0,y.useRef)({x:0,y:0}),_=(0,y.useRef)({x:0,y:0}),v=(0,y.useMemo)(()=>{switch(n){case p8.Pointer:return c?{top:c.y,bottom:c.y,left:c.x,right:c.x}:null;case p8.DraggableRect:return i}},[n,i,c]),b=(0,y.useRef)(null),x=(0,y.useCallback)(()=>{let e=b.current;if(!e)return;let t=g.current.x*_.current.x,n=g.current.y*_.current.y;e.scrollBy(t,n)},[]),S=(0,y.useMemo)(()=>s===m8.TreeOrder?[...l].reverse():l,[s,l]);(0,y.useEffect)(()=>{if(!a||!l.length||!v){h();return}for(let e of S){if(r?.(e)===!1)continue;let n=u[l.indexOf(e)];if(!n)continue;let{direction:i,speed:a}=DIe(e,n,v,t,f);for(let e of[`x`,`y`])p[e][i[e]]||(a[e]=0,i[e]=0);if(a.x>0||a.y>0){h(),b.current=e,m(x,o),g.current=a,_.current=i;return}}g.current={x:0,y:0},_.current={x:0,y:0},h()},[t,x,r,h,a,o,JSON.stringify(v),JSON.stringify(p),m,l,S,u,JSON.stringify(f)])}var BIe={x:{[J6.Backward]:!1,[J6.Forward]:!1},y:{[J6.Backward]:!1,[J6.Forward]:!1}};function VIe(e){let{delta:t,disabled:n}=e,r=g6(t);return m6(e=>{if(n||!r||!e)return BIe;let i={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[J6.Backward]:e.x[J6.Backward]||i.x===-1,[J6.Forward]:e.x[J6.Forward]||i.x===1},y:{[J6.Backward]:e.y[J6.Backward]||i.y===-1,[J6.Forward]:e.y[J6.Forward]||i.y===1}}},[n,t,r])}function HIe(e,t){let n=t==null?void 0:e.get(t),r=n?n.node.current:null;return m6(e=>t==null?null:r??e??null,[r,t])}function UIe(e,t){return(0,y.useMemo)(()=>e.reduce((e,n)=>{let{sensor:r}=n,i=r.activators.map(e=>({eventName:e.eventName,handler:t(e.handler,n)}));return[...e,...i]},[]),[e,t])}var h8;(function(e){e[e.Always=0]=`Always`,e[e.BeforeDragging=1]=`BeforeDragging`,e[e.WhileDragging=2]=`WhileDragging`})(h8||={});var g8;(function(e){e.Optimized=`optimized`})(g8||={});var _8=new Map;function WIe(e,t){let{dragging:n,dependencies:r,config:i}=t,[a,o]=(0,y.useState)(null),{frequency:s,measure:c,strategy:l}=i,u=(0,y.useRef)(e),d=g(),f=p6(d),p=(0,y.useCallback)(function(e){e===void 0&&(e=[]),!f.current&&o(t=>t===null?e:t.concat(e.filter(e=>!t.includes(e))))},[f]),m=(0,y.useRef)(null),h=m6(t=>{if(d&&!n)return _8;if(!t||t===_8||u.current!==e||a!=null){let t=new Map;for(let n of e){if(!n)continue;if(a&&a.length>0&&!a.includes(n.id)&&n.rect.current){t.set(n.id,n.rect.current);continue}let e=n.node.current,r=e?new $6(c(e),e):null;n.rect.current=r,r&&t.set(n.id,r)}return t}return t},[e,a,n,d,c]);return(0,y.useEffect)(()=>{u.current=e},[e]),(0,y.useEffect)(()=>{d||p()},[n,d]),(0,y.useEffect)(()=>{a&&a.length>0&&o(null)},[JSON.stringify(a)]),(0,y.useEffect)(()=>{d||typeof s!=`number`||m.current!==null||(m.current=setTimeout(()=>{p(),m.current=null},s))},[s,d,p,...r]),{droppableRects:h,measureDroppableContainers:p,measuringScheduled:a!=null};function g(){switch(l){case h8.Always:return!1;case h8.BeforeDragging:return n;default:return!n}}}function v8(e,t){return m6(n=>e?n||(typeof t==`function`?t(e):e):null,[t,e])}function GIe(e,t){return v8(e,t)}function KIe(e){let{callback:t,disabled:n}=e,r=f6(t),i=(0,y.useMemo)(()=>{if(n||typeof window>`u`||window.MutationObserver===void 0)return;let{MutationObserver:e}=window;return new e(r)},[r,n]);return(0,y.useEffect)(()=>()=>i?.disconnect(),[i]),i}function y8(e){let{callback:t,disabled:n}=e,r=f6(t),i=(0,y.useMemo)(()=>{if(n||typeof window>`u`||window.ResizeObserver===void 0)return;let{ResizeObserver:e}=window;return new e(r)},[n]);return(0,y.useEffect)(()=>()=>i?.disconnect(),[i]),i}function qIe(e){return new $6(B6(e),e)}function b8(e,t,n){t===void 0&&(t=qIe);let[r,i]=(0,y.useState)(null);function a(){i(r=>{if(!e)return null;if(e.isConnected===!1)return r??n??null;let i=t(e);return JSON.stringify(r)===JSON.stringify(i)?r:i})}let o=KIe({callback(t){if(e)for(let n of t){let{type:t,target:r}=n;if(t===`childList`&&r instanceof HTMLElement&&r.contains(e)){a();break}}}}),s=y8({callback:a});return d6(()=>{a(),e?(s?.observe(e),o?.observe(document.body,{childList:!0,subtree:!0})):(s?.disconnect(),o?.disconnect())},[e]),r}function JIe(e){return R6(e,v8(e))}var x8=[];function YIe(e){let t=(0,y.useRef)(e),n=m6(n=>e?n&&n!==x8&&e&&t.current&&e.parentNode===t.current.parentNode?n:H6(e):x8,[e]);return(0,y.useEffect)(()=>{t.current=e},[e]),n}function XIe(e){let[t,n]=(0,y.useState)(null),r=(0,y.useRef)(e),i=(0,y.useCallback)(e=>{let t=W6(e.target);t&&n(e=>e?(e.set(t,q6(t)),new Map(e)):null)},[]);return(0,y.useEffect)(()=>{let t=r.current;if(e!==t){a(t);let o=e.map(e=>{let t=W6(e);return t?(t.addEventListener(`scroll`,i,{passive:!0}),[t,q6(t)]):null}).filter(e=>e!=null);n(o.length?new Map(o):null),r.current=e}return()=>{a(e),a(t)};function a(e){e.forEach(e=>{W6(e)?.removeEventListener(`scroll`,i)})}},[i,e]),(0,y.useMemo)(()=>e.length?t?Array.from(t.values()).reduce((e,t)=>b6(e,t),j6):Z6(e):j6,[e,t])}function S8(e,t){t===void 0&&(t=[]);let n=(0,y.useRef)(null);return(0,y.useEffect)(()=>{n.current=null},t),(0,y.useEffect)(()=>{let t=e!==j6;t&&!n.current&&(n.current=e),!t&&n.current&&(n.current=null)},[e]),n.current?x6(e,n.current):j6}function ZIe(e){(0,y.useEffect)(()=>{if(!r6)return;let t=e.map(e=>{let{sensor:t}=e;return t.setup==null?void 0:t.setup()});return()=>{for(let e of t)e?.()}},e.map(e=>{let{sensor:t}=e;return t}))}function QIe(e,t){return(0,y.useMemo)(()=>e.reduce((e,n)=>{let{eventName:r,handler:i}=n;return e[r]=e=>{i(e,t)},e},{}),[e,t])}function C8(e){return(0,y.useMemo)(()=>e?CIe(e):null,[e])}var w8=[];function $Ie(e,t){t===void 0&&(t=B6);let[n]=e,r=C8(n?o6(n):null),[i,a]=(0,y.useState)(w8);function o(){a(()=>e.length?e.map(e=>Y6(e)?r:new $6(t(e),e)):w8)}let s=y8({callback:o});return d6(()=>{s?.disconnect(),o(),e.forEach(e=>s?.observe(e))},[e]),i}function T8(e){if(!e)return null;if(e.children.length>1)return e;let t=e.children[0];return c6(t)?t:e}function eLe(e){let{measure:t}=e,[n,r]=(0,y.useState)(null),i=y8({callback:(0,y.useCallback)(e=>{for(let{target:n}of e)if(c6(n)){r(e=>{let r=t(n);return e?{...e,width:r.width,height:r.height}:r});break}},[t])}),[a,o]=h6((0,y.useCallback)(e=>{let n=T8(e);i?.disconnect(),n&&i?.observe(n),r(n?t(n):null)},[t,i]));return(0,y.useMemo)(()=>({nodeRef:a,rect:n,setRef:o}),[n,a,o])}var tLe=[{sensor:u8,options:{}},{sensor:o8,options:{}}],nLe={current:{}},E8={draggable:{measure:V6},droppable:{measure:V6,strategy:h8.WhileDragging,frequency:g8.Optimized},dragOverlay:{measure:B6}},D8=class extends Map{get(e){return e==null?void 0:super.get(e)??void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:t}=e;return!t})}getNodeFor(e){return this.get(e)?.node.current??void 0}},rLe={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new D8,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:O6},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:E8,measureDroppableContainers:O6,windowRect:null,measuringScheduled:!1},O8={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:``},dispatch:O6,draggableNodes:new Map,over:null,measureDroppableContainers:O6},k8=(0,y.createContext)(O8),A8=(0,y.createContext)(rLe);function iLe(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new D8}}}function aLe(e,t){switch(t.type){case D6.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case D6.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case D6.DragEnd:case D6.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case D6.RegisterDroppable:{let{element:n}=t,{id:r}=n,i=new D8(e.droppable.containers);return i.set(r,n),{...e,droppable:{...e.droppable,containers:i}}}case D6.SetDroppableDisabled:{let{id:n,key:r,disabled:i}=t,a=e.droppable.containers.get(n);if(!a||r!==a.key)return e;let o=new D8(e.droppable.containers);return o.set(n,{...a,disabled:i}),{...e,droppable:{...e.droppable,containers:o}}}case D6.UnregisterDroppable:{let{id:n,key:r}=t,i=e.droppable.containers.get(n);if(!i||r!==i.key)return e;let a=new D8(e.droppable.containers);return a.delete(n),{...e,droppable:{...e.droppable,containers:a}}}default:return e}}function oLe(e){let{disabled:t}=e,{active:n,activatorEvent:r,draggableNodes:i}=(0,y.useContext)(k8),a=g6(r),o=g6(n?.id);return(0,y.useEffect)(()=>{if(!t&&!r&&a&&o!=null){if(!S6(a)||document.activeElement===a.target)return;let e=i.get(o);if(!e)return;let{activatorNode:t,node:n}=e;if(!t.current&&!n.current)return;requestAnimationFrame(()=>{for(let e of[t.current,n.current]){if(!e)continue;let t=rIe(e);if(t){t.focus();break}}})}},[r,t,i,o,a]),null}function j8(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((e,t)=>t({transform:e,...r}),n):n}function sLe(e){return(0,y.useMemo)(()=>({draggable:{...E8.draggable,...e?.draggable},droppable:{...E8.droppable,...e?.droppable},dragOverlay:{...E8.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function cLe(e){let{activeNode:t,measure:n,initialRect:r,config:i=!0}=e,a=(0,y.useRef)(!1),{x:o,y:s}=typeof i==`boolean`?{x:i,y:i}:i;d6(()=>{if(!o&&!s||!t){a.current=!1;return}if(a.current||!r)return;let e=t?.node.current;if(!e||e.isConnected===!1)return;let i=R6(n(e),r);if(o||(i.x=0),s||(i.y=0),a.current=!0,Math.abs(i.x)>0||Math.abs(i.y)>0){let t=U6(e);t&&t.scrollBy({top:i.y,left:i.x})}},[t,o,s,r,n])}var M8=(0,y.createContext)({...j6,scaleX:1,scaleY:1}),N8;(function(e){e[e.Uninitialized=0]=`Uninitialized`,e[e.Initializing=1]=`Initializing`,e[e.Initialized=2]=`Initialized`})(N8||={});var P8=(0,y.memo)(function(e){let{id:t,accessibility:n,autoScroll:r=!0,children:i,sensors:a=tLe,collisionDetection:o=_Ie,measuring:s,modifiers:c,...l}=e,[u,d]=(0,y.useReducer)(aLe,void 0,iLe),[f,p]=lIe(),[m,h]=(0,y.useState)(N8.Uninitialized),g=m===N8.Initialized,{draggable:{active:_,nodes:v,translate:b},droppable:{containers:x}}=u,S=_==null?null:v.get(_),C=(0,y.useRef)({initial:null,translated:null}),w=(0,y.useMemo)(()=>_==null?null:{id:_,data:S?.data??nLe,rect:C},[_,S]),T=(0,y.useRef)(null),[E,D]=(0,y.useState)(null),[O,k]=(0,y.useState)(null),A=p6(l,Object.values(l)),j=v6(`DndDescribedBy`,t),M=(0,y.useMemo)(()=>x.getEnabled(),[x]),N=sLe(s),{droppableRects:P,measureDroppableContainers:F,measuringScheduled:I}=WIe(M,{dragging:g,dependencies:[b.x,b.y],config:N.droppable}),L=HIe(v,_),R=(0,y.useMemo)(()=>O?C6(O):null,[O]),z=Te(),B=GIe(L,N.draggable.measure);cLe({activeNode:_==null?null:v.get(_),config:z.layoutShiftCompensation,initialRect:B,measure:N.draggable.measure});let V=b8(L,N.draggable.measure,B),ee=b8(L?L.parentElement:null),H=(0,y.useRef)({activatorEvent:null,active:null,activeNode:L,collisionRect:null,collisions:null,droppableRects:P,draggableNodes:v,draggingNode:null,draggingNodeRect:null,droppableContainers:x,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),te=x.getNodeFor(H.current.over?.id),ne=eLe({measure:N.dragOverlay.measure}),re=ne.nodeRef.current??L,U=g?ne.rect??V:null,ie=!!(ne.nodeRef.current&&ne.rect),ae=JIe(ie?null:V),W=C8(re?o6(re):null),oe=YIe(g?te??L:null),se=$Ie(oe),ce=j8(c,{transform:{x:b.x-ae.x,y:b.y-ae.y,scaleX:1,scaleY:1},activatorEvent:O,active:w,activeNodeRect:V,containerNodeRect:ee,draggingNodeRect:U,over:H.current.over,overlayNodeRect:ne.rect,scrollableAncestors:oe,scrollableAncestorRects:se,windowRect:W}),le=R?b6(R,b):null,ue=XIe(oe),de=S8(ue),fe=S8(ue,[V]),pe=b6(ce,de),me=U?bIe(U,ce):null,he=w&&me?o({active:w,collisionRect:me,droppableRects:P,droppableContainers:M,pointerCoordinates:le}):null,ge=F6(he,`id`),[_e,ve]=(0,y.useState)(null),ye=vIe(ie?ce:b6(ce,fe),_e?.rect??null,V),be=(0,y.useRef)(null),xe=(0,y.useCallback)((e,t)=>{let{sensor:n,options:r}=t;if(T.current==null)return;let i=v.get(T.current);if(!i)return;let a=e.nativeEvent;be.current=new n({active:T.current,activeNode:i,event:a,options:r,context:H,onAbort(e){if(!v.get(e))return;let{onDragAbort:t}=A.current,n={id:e};t?.(n),f({type:`onDragAbort`,event:n})},onPending(e,t,n,r){if(!v.get(e))return;let{onDragPending:i}=A.current,a={id:e,constraint:t,initialCoordinates:n,offset:r};i?.(a),f({type:`onDragPending`,event:a})},onStart(e){let t=T.current;if(t==null)return;let n=v.get(t);if(!n)return;let{onDragStart:r}=A.current,i={activatorEvent:a,active:{id:t,data:n.data,rect:C}};(0,Zf.unstable_batchedUpdates)(()=>{r?.(i),h(N8.Initializing),d({type:D6.DragStart,initialCoordinates:e,active:t}),f({type:`onDragStart`,event:i}),D(be.current),k(a)})},onMove(e){d({type:D6.DragMove,coordinates:e})},onEnd:o(D6.DragEnd),onCancel:o(D6.DragCancel)});function o(e){return async function(){let{active:t,collisions:n,over:r,scrollAdjustedTranslate:i}=H.current,o=null;if(t&&i){let{cancelDrop:s}=A.current;o={activatorEvent:a,active:t,collisions:n,delta:i,over:r},e===D6.DragEnd&&typeof s==`function`&&await Promise.resolve(s(o))&&(e=D6.DragCancel)}T.current=null,(0,Zf.unstable_batchedUpdates)(()=>{d({type:e}),h(N8.Uninitialized),ve(null),D(null),k(null),be.current=null;let t=e===D6.DragEnd?`onDragEnd`:`onDragCancel`;if(o){let e=A.current[t];e?.(o),f({type:t,event:o})}})}}},[v]),Se=UIe(a,(0,y.useCallback)((e,t)=>(n,r)=>{let i=n.nativeEvent,a=v.get(r);if(T.current!==null||!a||i.dndKit||i.defaultPrevented)return;let o={active:a};e(n,t.options,o)===!0&&(i.dndKit={capturedBy:t.sensor},T.current=r,xe(n,t))},[v,xe]));ZIe(a),d6(()=>{V&&m===N8.Initializing&&h(N8.Initialized)},[V,m]),(0,y.useEffect)(()=>{let{onDragMove:e}=A.current,{active:t,activatorEvent:n,collisions:r,over:i}=H.current;if(!t||!n)return;let a={active:t,activatorEvent:n,collisions:r,delta:{x:pe.x,y:pe.y},over:i};(0,Zf.unstable_batchedUpdates)(()=>{e?.(a),f({type:`onDragMove`,event:a})})},[pe.x,pe.y]),(0,y.useEffect)(()=>{let{active:e,activatorEvent:t,collisions:n,droppableContainers:r,scrollAdjustedTranslate:i}=H.current;if(!e||T.current==null||!t||!i)return;let{onDragOver:a}=A.current,o=r.get(ge),s=o&&o.rect.current?{id:o.id,rect:o.rect.current,data:o.data,disabled:o.disabled}:null,c={active:e,activatorEvent:t,collisions:n,delta:{x:i.x,y:i.y},over:s};(0,Zf.unstable_batchedUpdates)(()=>{ve(s),a?.(c),f({type:`onDragOver`,event:c})})},[ge]),d6(()=>{H.current={activatorEvent:O,active:w,activeNode:L,collisionRect:me,collisions:he,droppableRects:P,draggableNodes:v,draggingNode:re,draggingNodeRect:U,droppableContainers:x,over:_e,scrollableAncestors:oe,scrollAdjustedTranslate:pe},C.current={initial:U,translated:me}},[w,L,he,me,v,re,U,P,x,_e,oe,pe]),zIe({...z,delta:b,draggingRect:me,pointerCoordinates:le,scrollableAncestors:oe,scrollableAncestorRects:se});let Ce=(0,y.useMemo)(()=>({active:w,activeNode:L,activeNodeRect:V,activatorEvent:O,collisions:he,containerNodeRect:ee,dragOverlay:ne,draggableNodes:v,droppableContainers:x,droppableRects:P,over:_e,measureDroppableContainers:F,scrollableAncestors:oe,scrollableAncestorRects:se,measuringConfiguration:N,measuringScheduled:I,windowRect:W}),[w,L,V,O,he,ee,ne,v,x,P,_e,F,oe,se,N,I,W]),we=(0,y.useMemo)(()=>({activatorEvent:O,activators:Se,active:w,activeNodeRect:V,ariaDescribedById:{draggable:j},dispatch:d,draggableNodes:v,over:_e,measureDroppableContainers:F}),[O,Se,w,V,d,j,v,_e,F]);return y.createElement(E6.Provider,{value:p},y.createElement(k8.Provider,{value:we},y.createElement(A8.Provider,{value:Ce},y.createElement(M8.Provider,{value:ye},i)),y.createElement(oLe,{disabled:n?.restoreFocus===!1})),y.createElement(fIe,{...n,hiddenTextDescribedById:j}));function Te(){let e=E?.autoScrollEnabled===!1,t=typeof r==`object`?r.enabled===!1:r===!1,n=g&&!e&&!t;return typeof r==`object`?{...r,enabled:n}:{enabled:n}}}),lLe=(0,y.createContext)(null),F8=`button`,uLe=`Draggable`;function dLe(e){let{id:t,data:n,disabled:r=!1,attributes:i}=e,a=v6(uLe),{activators:o,activatorEvent:s,active:c,activeNodeRect:l,ariaDescribedById:u,draggableNodes:d,over:f}=(0,y.useContext)(k8),{role:p=F8,roleDescription:m=`draggable`,tabIndex:h=0}=i??{},g=c?.id===t,_=(0,y.useContext)(g?M8:lLe),[v,b]=h6(),[x,S]=h6(),C=QIe(o,t),w=p6(n);return d6(()=>(d.set(t,{id:t,key:a,node:v,activatorNode:x,data:w}),()=>{let e=d.get(t);e&&e.key===a&&d.delete(t)}),[d,t]),{active:c,activatorEvent:s,activeNodeRect:l,attributes:(0,y.useMemo)(()=>({role:p,tabIndex:h,"aria-disabled":r,"aria-pressed":g&&p===F8?!0:void 0,"aria-roledescription":m,"aria-describedby":u.draggable}),[r,p,h,g,m,u.draggable]),isDragging:g,listeners:r?void 0:C,node:v,over:f,setNodeRef:b,setActivatorNodeRef:S,transform:_}}function I8(){return(0,y.useContext)(A8)}var fLe=`Droppable`,pLe={timeout:25};function mLe(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:i}=e,a=v6(fLe),{active:o,dispatch:s,over:c,measureDroppableContainers:l}=(0,y.useContext)(k8),u=(0,y.useRef)({disabled:n}),d=(0,y.useRef)(!1),f=(0,y.useRef)(null),p=(0,y.useRef)(null),{disabled:m,updateMeasurementsFor:h,timeout:g}={...pLe,...i},_=p6(h??r),v=y8({callback:(0,y.useCallback)(()=>{if(!d.current){d.current=!0;return}p.current!=null&&clearTimeout(p.current),p.current=setTimeout(()=>{l(Array.isArray(_.current)?_.current:[_.current]),p.current=null},g)},[g]),disabled:m||!o}),[b,x]=h6((0,y.useCallback)((e,t)=>{v&&(t&&(v.unobserve(t),d.current=!1),e&&v.observe(e))},[v])),S=p6(t);return(0,y.useEffect)(()=>{!v||!b.current||(v.disconnect(),d.current=!1,v.observe(b.current))},[b,v]),(0,y.useEffect)(()=>(s({type:D6.RegisterDroppable,element:{id:r,key:a,disabled:n,node:b,rect:f,data:S}}),()=>s({type:D6.UnregisterDroppable,key:a,id:r})),[r]),(0,y.useEffect)(()=>{n!==u.current.disabled&&(s({type:D6.SetDroppableDisabled,id:r,key:a,disabled:n}),u.current.disabled=n)},[r,a,n,s]),{active:o,rect:f,isOver:c?.id===r,node:b,over:c,setNodeRef:x}}function hLe(e){let{animation:t,children:n}=e,[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(null),s=g6(n);return!n&&!r&&s&&i(s),d6(()=>{if(!a)return;let e=r?.key,n=r?.props.id;if(e==null||n==null){i(null);return}Promise.resolve(t(n,a)).then(()=>{i(null)})},[t,r,a]),y.createElement(y.Fragment,null,n,r?(0,y.cloneElement)(r,{ref:o}):null)}var gLe={x:0,y:0,scaleX:1,scaleY:1};function _Le(e){let{children:t}=e;return y.createElement(k8.Provider,{value:O8},y.createElement(M8.Provider,{value:gLe},t))}var vLe={position:`fixed`,touchAction:`none`},yLe=e=>S6(e)?`transform 250ms ease`:void 0,bLe=(0,y.forwardRef)((e,t)=>{let{as:n,activatorEvent:r,adjustScale:i,children:a,className:o,rect:s,style:c,transform:l,transition:u=yLe}=e;if(!s)return null;let d=i?l:{...l,scaleX:1,scaleY:1},f={...vLe,width:s.width,height:s.height,top:s.top,left:s.left,transform:w6.Transform.toString(d),transformOrigin:i&&r?pIe(r,s):void 0,transition:typeof u==`function`?u(r):u,...c};return y.createElement(n,{className:o,style:f,ref:t},a)}),xLe={duration:250,easing:`ease`,keyframes:e=>{let{transform:{initial:t,final:n}}=e;return[{transform:w6.Transform.toString(t)},{transform:w6.Transform.toString(n)}]},sideEffects:(e=>t=>{let{active:n,dragOverlay:r}=t,i={},{styles:a,className:o}=e;if(a!=null&&a.active)for(let[e,t]of Object.entries(a.active))t!==void 0&&(i[e]=n.node.style.getPropertyValue(e),n.node.style.setProperty(e,t));if(a!=null&&a.dragOverlay)for(let[e,t]of Object.entries(a.dragOverlay))t!==void 0&&r.node.style.setProperty(e,t);return o!=null&&o.active&&n.node.classList.add(o.active),o!=null&&o.dragOverlay&&r.node.classList.add(o.dragOverlay),function(){for(let[e,t]of Object.entries(i))n.node.style.setProperty(e,t);o!=null&&o.active&&n.node.classList.remove(o.active)}})({styles:{active:{opacity:`0`}}})};function SLe(e){let{config:t,draggableNodes:n,droppableContainers:r,measuringConfiguration:i}=e;return f6((e,a)=>{if(t===null)return;let o=n.get(e);if(!o)return;let s=o.node.current;if(!s)return;let c=T8(a);if(!c)return;let{transform:l}=o6(a).getComputedStyle(a),u=z6(l);if(!u)return;let d=typeof t==`function`?t:CLe(t);return Q6(s,i.draggable.measure),d({active:{id:e,data:o.data,node:s,rect:i.draggable.measure(s)},draggableNodes:n,dragOverlay:{node:a,rect:i.dragOverlay.measure(c)},droppableContainers:r,measuringConfiguration:i,transform:u})})}function CLe(e){let{duration:t,easing:n,sideEffects:r,keyframes:i}={...xLe,...e};return e=>{let{active:a,dragOverlay:o,transform:s,...c}=e;if(!t)return;let l={x:o.rect.left-a.rect.left,y:o.rect.top-a.rect.top},u={scaleX:s.scaleX===1?1:a.rect.width*s.scaleX/o.rect.width,scaleY:s.scaleY===1?1:a.rect.height*s.scaleY/o.rect.height},d={x:s.x-l.x,y:s.y-l.y,...u},f=i({...c,active:a,dragOverlay:o,transform:{initial:s,final:d}}),[p]=f,m=f[f.length-1];if(JSON.stringify(p)===JSON.stringify(m))return;let h=r?.({active:a,dragOverlay:o,...c}),g=o.node.animate(f,{duration:t,easing:n,fill:`forwards`});return new Promise(e=>{g.onfinish=()=>{h?.(),e()}})}}var L8=0;function wLe(e){return(0,y.useMemo)(()=>{if(e!=null)return L8++,L8},[e])}var TLe=y.memo(e=>{let{adjustScale:t=!1,children:n,dropAnimation:r,style:i,transition:a,modifiers:o,wrapperElement:s=`div`,className:c,zIndex:l=999}=e,{activatorEvent:u,active:d,activeNodeRect:f,containerNodeRect:p,draggableNodes:m,droppableContainers:h,dragOverlay:g,over:_,measuringConfiguration:v,scrollableAncestors:b,scrollableAncestorRects:x,windowRect:S}=I8(),C=(0,y.useContext)(M8),w=wLe(d?.id),T=j8(o,{activatorEvent:u,active:d,activeNodeRect:f,containerNodeRect:p,draggingNodeRect:g.rect,over:_,overlayNodeRect:g.rect,scrollableAncestors:b,scrollableAncestorRects:x,transform:C,windowRect:S}),E=v8(f),D=SLe({config:r,draggableNodes:m,droppableContainers:h,measuringConfiguration:v}),O=E?g.setRef:void 0;return y.createElement(_Le,null,y.createElement(hLe,{animation:D},d&&w?y.createElement(bLe,{key:w,id:d.id,ref:O,as:s,activatorEvent:u,adjustScale:t,className:c,transition:a,rect:E,style:{zIndex:l,...i},transform:T},n):null))});function R8(e,t,n){let r=e.slice();return r.splice(n<0?r.length+n:n,0,r.splice(t,1)[0]),r}function ELe(e,t){return e.reduce((e,n,r)=>{let i=t.get(n);return i&&(e[r]=i),e},Array(e.length))}function z8(e){return e!==null&&e>=0}function DLe(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n{let{rects:t,activeIndex:n,overIndex:r,index:i}=e,a=R8(t,r,n),o=t[i],s=a[i];return!s||!o?null:{x:s.left-o.left,y:s.top-o.top,scaleX:s.width/o.width,scaleY:s.height/o.height}},V8={scaleX:1,scaleY:1},kLe=e=>{let{activeIndex:t,activeNodeRect:n,index:r,rects:i,overIndex:a}=e,o=i[t]??n;if(!o)return null;if(r===t){let e=i[a];return e?{x:0,y:tt&&r<=a?{x:0,y:-o.height-s,...V8}:r=a?{x:0,y:o.height+s,...V8}:{x:0,y:0,...V8}};function ALe(e,t,n){let r=e[t],i=e[t-1],a=e[t+1];return r?nr.map(e=>typeof e==`object`&&`id`in e?e.id:e),[r]),m=o!=null,h=o?p.indexOf(o.id):-1,g=l?p.indexOf(l.id):-1,_=(0,y.useRef)(p),v=!DLe(p,_.current),b=g!==-1&&h===-1||v,x=OLe(a);d6(()=>{v&&m&&u(p)},[v,p,m,u]),(0,y.useEffect)(()=>{_.current=p},[p]);let S=(0,y.useMemo)(()=>({activeIndex:h,containerId:d,disabled:x,disableTransforms:b,items:p,overIndex:g,useDragOverlay:f,sortedRects:ELe(p,c),strategy:i}),[h,d,x.draggable,x.droppable,b,p,g,c,f,i]);return y.createElement(U8.Provider,{value:S},t)}var jLe=e=>{let{id:t,items:n,activeIndex:r,overIndex:i}=e;return R8(n,r,i).indexOf(t)},MLe=e=>{let{containerId:t,isSorting:n,wasDragging:r,index:i,items:a,newIndex:o,previousItems:s,previousContainerId:c,transition:l}=e;return!l||!r||s!==a&&i===o?!1:n?!0:o!==i&&t===c},NLe={duration:200,easing:`ease`},G8=`transform`,PLe=w6.Transition.toString({property:G8,duration:0,easing:`linear`}),FLe={roleDescription:`sortable`};function ILe(e){let{disabled:t,index:n,node:r,rect:i}=e,[a,o]=(0,y.useState)(null),s=(0,y.useRef)(n);return d6(()=>{if(!t&&n!==s.current&&r.current){let e=i.current;if(e){let t=B6(r.current,{ignoreTransform:!0}),n={x:e.left-t.left,y:e.top-t.top,scaleX:e.width/t.width,scaleY:e.height/t.height};(n.x||n.y)&&o(n)}}n!==s.current&&(s.current=n)},[t,n,r,i]),(0,y.useEffect)(()=>{a&&o(null)},[a]),a}function K8(e){let{animateLayoutChanges:t=MLe,attributes:n,disabled:r,data:i,getNewIndex:a=jLe,id:o,strategy:s,resizeObserverConfig:c,transition:l=NLe}=e,{items:u,containerId:d,activeIndex:f,disabled:p,disableTransforms:m,sortedRects:h,overIndex:g,useDragOverlay:_,strategy:v}=(0,y.useContext)(U8),b=LLe(r,p),x=u.indexOf(o),S=(0,y.useMemo)(()=>({sortable:{containerId:d,index:x,items:u},...i}),[d,i,x,u]),C=(0,y.useMemo)(()=>u.slice(u.indexOf(o)),[u,o]),{rect:w,node:T,isOver:E,setNodeRef:D}=mLe({id:o,data:S,disabled:b.droppable,resizeObserverConfig:{updateMeasurementsFor:C,...c}}),{active:O,activatorEvent:k,activeNodeRect:A,attributes:j,setNodeRef:M,listeners:N,isDragging:P,over:F,setActivatorNodeRef:I,transform:L}=dLe({id:o,data:S,attributes:{...FLe,...n},disabled:b.draggable}),R=$Fe(D,M),z=!!O,B=z&&!m&&z8(f)&&z8(g),V=!_&&P,ee=B?(V&&B?L:null)??(s??v)({rects:h,activeNodeRect:A,activeIndex:f,overIndex:g,index:x}):null,H=z8(f)&&z8(g)?a({id:o,items:u,activeIndex:f,overIndex:g}):x,te=O?.id,ne=(0,y.useRef)({activeId:te,items:u,newIndex:H,containerId:d}),re=u!==ne.current.items,U=t({active:O,containerId:d,isDragging:P,isSorting:z,id:o,index:x,items:u,newIndex:ne.current.newIndex,previousItems:ne.current.items,previousContainerId:ne.current.containerId,transition:l,wasDragging:ne.current.activeId!=null}),ie=ILe({disabled:!U,index:x,node:T,rect:w});return(0,y.useEffect)(()=>{z&&ne.current.newIndex!==H&&(ne.current.newIndex=H),d!==ne.current.containerId&&(ne.current.containerId=d),u!==ne.current.items&&(ne.current.items=u)},[z,H,d,u]),(0,y.useEffect)(()=>{if(te===ne.current.activeId)return;if(te!=null&&ne.current.activeId==null){ne.current.activeId=te;return}let e=setTimeout(()=>{ne.current.activeId=te},50);return()=>clearTimeout(e)},[te]),{active:O,activeIndex:f,attributes:j,data:S,rect:w,index:x,newIndex:H,items:u,isOver:E,isSorting:z,isDragging:P,listeners:N,node:T,overIndex:g,over:F,setNodeRef:R,setActivatorNodeRef:I,setDroppableNodeRef:D,setDraggableNodeRef:M,transform:ie??ee,transition:ae()};function ae(){if(ie||re&&ne.current.newIndex===x)return PLe;if(!(V&&!S6(k)||!l)&&(z||U))return w6.Transition.toString({...l,property:G8})}}function LLe(e,t){return typeof e==`boolean`?{draggable:e,droppable:!1}:{draggable:e?.draggable??t.draggable,droppable:e?.droppable??t.droppable}}function q8(e){if(!e)return!1;let t=e.data.current;return!!(t&&`sortable`in t&&typeof t.sortable==`object`&&`containerId`in t.sortable&&`items`in t.sortable&&`index`in t.sortable)}var RLe=[i8.Down,i8.Right,i8.Up,i8.Left],J8=(e,t)=>{let{context:{active:n,collisionRect:r,droppableRects:i,droppableContainers:a,over:o,scrollableAncestors:s}}=t;if(RLe.includes(e.code)){if(e.preventDefault(),!n||!r)return;let t=[];a.getEnabled().forEach(n=>{if(!n||n!=null&&n.disabled)return;let a=i.get(n.id);if(a)switch(e.code){case i8.Down:r.topa.top&&t.push(n);break;case i8.Left:r.left>a.left&&t.push(n);break;case i8.Right:r.left1&&(l=c[1].id),l!=null){let e=a.get(n.id),t=a.get(l),o=t?i.get(t.id):null,c=t?.node.current;if(c&&o&&e&&t){let n=H6(c).some((e,t)=>s[t]!==e),i=Y8(e,t),a=zLe(e,t),l=n||!i?{x:0,y:0}:{x:a?r.width-o.width:0,y:a?r.height-o.height:0},u={x:o.left,y:o.top};return l.x&&l.y?u:x6(u,l)}}}};function Y8(e,t){return!q8(e)||!q8(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function zLe(e,t){return!q8(e)||!q8(t)||!Y8(e,t)?!1:e.data.current.sortable.index=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function VLe({activeCount:e,pendingCount:t,totalTime:n,totalWeight:r,historyCount:i,t:a}){return(0,K.jsx)(`div`,{className:`flex items-center gap-3 sm:gap-5 flex-wrap px-4 py-3 bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary mb-6`,children:[{icon:hl,value:e,label:a(`queue.summary.printing`),color:`text-blue-400`},{icon:_s,value:t,label:a(`queue.summary.queued`),color:`text-yellow-400`},{icon:mu,value:yf(n),label:a(`queue.summary.totalTime`),color:`text-bambu-green`},{icon:ku,value:BLe(r),label:a(`queue.summary.totalWeight`),color:`text-purple-400`},{icon:ls,value:i,label:a(`queue.summary.history`),color:`text-bambu-gray`}].map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[t>0&&(0,K.jsx)(`span`,{className:`hidden sm:block text-bambu-dark-tertiary`,children:`|`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(e.icon,{className:`w-4 h-4 ${e.color}`}),(0,K.jsx)(`span`,{className:`text-sm font-semibold text-white`,children:e.value}),(0,K.jsx)(`span`,{className:`text-xs sm:text-sm text-bambu-gray`,children:e.label})]})]},t))})}var X8={completed:{icon:ls,color:`text-emerald-400`,border:`border-l-emerald-500`},failed:{icon:ms,color:`text-red-400`,border:`border-l-red-500`},skipped:{icon:Kl,color:`text-orange-400`,border:`border-l-gray-500`},cancelled:{icon:No,color:`text-gray-400`,border:`border-l-gray-500`}};function HLe(e){if(!e)return null;let t=e.startsWith(`#`)?e.slice(1):e;return/^0{6,8}$/.test(t)||!/^[0-9a-fA-F]{6,8}$/.test(t)?null:`#${t.slice(0,6)}`}function Z8({item:e,onRequeue:t,onRemove:n,timeFormat:r=`system`,hasPermission:i,canModify:a,t:o}){let s=X8[e.status]||X8.cancelled,c=s.icon,l=e.archive_name||e.library_file_name||`File #${e.archive_id||e.library_file_id}`,u=e.archive_thumbnail?Q.getArchiveThumbnail(e.archive_id):e.library_file_thumbnail?Q.getLibraryFileThumbnailUrl(e.library_file_id):null,d=e.completed_at||e.created_at,f=HLe(e.filament_color),p=e.filament_used_grams?Math.round(e.filament_used_grams):null,m=!!e.error_message&&(e.status===`failed`||e.status===`skipped`);return(0,K.jsxs)(`div`,{className:`px-3 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary border-l-[3px] ${s.border}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[(0,K.jsx)(c,{className:`w-4 h-4 shrink-0 ${s.color}`}),(0,K.jsxs)(`div`,{className:`relative shrink-0 history-thumb-hover`,children:[(0,K.jsx)(`div`,{className:`w-8 h-8 bg-bambu-dark rounded overflow-hidden`,children:u?(0,K.jsx)(`img`,{src:u,alt:``,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,K.jsx)(Nc,{className:`w-4 h-4`})})}),u&&(0,K.jsx)(`div`,{className:`history-thumb-preview absolute z-[60] left-full top-0 ml-2 w-48 h-48 pointer-events-none opacity-0 transition-opacity`,children:(0,K.jsx)(`img`,{src:u,alt:``,className:`w-full h-full object-cover rounded-lg shadow-2xl border-2 border-bambu-dark-tertiary bg-bambu-dark`})})]}),(0,K.jsx)(`span`,{className:`text-sm text-white font-medium truncate min-w-0 flex-1`,children:l}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,title:d??void 0,children:bf(d,r,o)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:t,disabled:!i(`queue:create`),title:i(`queue:create`)?o(`queue.actions.requeue`):o(`queue.permissions.noRequeue`),className:`text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5`,children:(0,K.jsx)(Cl,{className:`w-3.5 h-3.5`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:n,disabled:!a(`queue`,`delete`,e.created_by_id),title:a(`queue`,`delete`,e.created_by_id)?o(`common.remove`):o(`queue.permissions.noRemove`),className:`p-1.5`,children:(0,K.jsx)(hu,{className:`w-3.5 h-3.5`})})]})]}),(0,K.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-bambu-gray`,children:[e.printer_name&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,K.jsx)(bl,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{className:`truncate max-w-[100px] sm:max-w-[140px]`,children:e.printer_name})]}),(f||p)&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[f?(0,K.jsx)(`span`,{className:`inline-block w-2.5 h-2.5 rounded-full border border-white/15`,style:{backgroundColor:f},"aria-hidden":!0}):(0,K.jsx)(ku,{className:`w-3 h-3`}),(0,K.jsxs)(`span`,{className:`truncate`,children:[p?`${p}g`:null,p&&e.filament_type?` ${e.filament_type}`:null,!p&&e.filament_type?e.filament_type:null]})]}),e.print_time_seconds&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,K.jsx)(mu,{className:`w-3 h-3`}),yf(e.print_time_seconds)]}),e.created_by_username&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,title:o(`queue.addedBy`,{name:e.created_by_username}),children:[(0,K.jsx)(Cu,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{className:`truncate max-w-[120px]`,children:e.created_by_username})]})]}),m&&(0,K.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex items-start gap-1 text-xs text-red-400`,children:[(0,K.jsx)(ss,{className:`w-3 h-3 mt-0.5 shrink-0`}),(0,K.jsx)(`span`,{className:`break-words`,children:e.error_message})]})]})}var Q8=3600*1e3,$8=24,e5=$8*Q8,ULe=32,WLe=40;function GLe(e){return e.toLocaleTimeString(void 0,{hour:`numeric`})}function t5(e){return e.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}function KLe({queueItems:e,printers:t,printerStatuses:n,onItemClick:r,t:i}){let[a,o]=(0,y.useState)(()=>new Date);(0,y.useEffect)(()=>{let e=setInterval(()=>o(new Date),6e4);return()=>clearInterval(e)},[]);let[s,c]=(0,y.useState)(0),l=(0,y.useMemo)(()=>{let e=a.getTime()+s;return Math.floor(e/Q8)*Q8},[a,s]),u=l+e5,d=a.getTime(),f=(0,y.useMemo)(()=>{let t=[],r=new Map,i=new Set,a=new Map,o=e=>e.printer_id==null?e.target_model?`model:${e.target_model}`:`unassigned`:`printer:${e.printer_id}`;for(let s of e)if(s.status===`printing`){let e=s.printer_id==null?void 0:n[s.printer_id],r=mf(s.started_at)||new Date,c;if(e?.remaining_time!=null&&e.remaining_time>0)c=new Date(d+e.remaining_time*60*1e3);else if(s.print_time_seconds){let t=e?.progress||0,n=Math.max(0,1-t/100);c=new Date(d+s.print_time_seconds*n*1e3)}else c=new Date(d+Q8);t.push({item:s,estimatedStart:r,estimatedEnd:c,progress:e?.progress??void 0,type:`printing`});let l=o(s);i.add(l),a.set(l,Math.max(a.get(l)??d,c.getTime()))}else if(s.status===`pending`){if(s.manual_start||s.waiting_reason)continue;let e=o(s);r.has(e)||r.set(e,[]),r.get(e).push(s)}let s=Date.now()+4320*Q8;for(let[e,n]of r){n.sort((e,t)=>e.position-t.position);let r=i.has(e),o=n[0]?mf(n[0].scheduled_time):null,c=o&&o.getTime()<=s;if(!r&&!c)continue;let l=a.get(e)??d;for(let e of n){let n=mf(e.scheduled_time);n&&n.getTime()<=s&&(l=Math.max(l,n.getTime()));let r=(e.print_time_seconds||3600)*1e3;t.push({item:e,estimatedStart:new Date(l),estimatedEnd:new Date(l+r),type:`queued`}),l+=r}}return t},[e,n,d]),p=(0,y.useMemo)(()=>{let e=[];for(let n of t)e.push({key:`printer:${n.id}`,label:n.name,printerId:n.id,targetModel:null});let n=new Set,r=!1;for(let t of f)if(t.item.printer_id==null)if(t.item.target_model){let r=`model:${t.item.target_model}`;n.has(r)||(n.add(r),e.push({key:r,label:`${i(`queue.filter.any`)} ${t.item.target_model}`,printerId:null,targetModel:t.item.target_model}))}else r=!0;return r&&e.push({key:`unassigned`,label:i(`queue.filter.unassigned`),printerId:null,targetModel:null}),e},[t,f,i]),m=(0,y.useMemo)(()=>{let e=new Map;for(let t of f){let n;n=t.item.printer_id==null?t.item.target_model?`model:${t.item.target_model}`:`unassigned`:`printer:${t.item.printer_id}`,e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[f]),h=(0,y.useMemo)(()=>{let e=[];for(let t=0;t<=$8;t+=2){let n=l+t*Q8;e.push({ms:n,pct:t/$8*100,label:GLe(new Date(n))})}return e},[l]),g=(d-l)/e5*100,_=g>=0&&g<=100,v=(0,y.useMemo)(()=>{let e=0;for(let t of f)e=Math.max(e,t.estimatedEnd.getTime());return e>0?new Date(e):null},[f]),b=(0,y.useRef)(null);return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>c(e=>e-12*Q8),className:`p-1.5`,title:i(`queue.timeline.window.back12h`),children:(0,K.jsx)(ns,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-sm font-medium text-white min-w-[180px] text-center`,children:[new Date(l).toLocaleString(void 0,{weekday:`short`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}),` → `,new Date(u).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>c(e=>e+12*Q8),className:`p-1.5`,title:i(`queue.timeline.window.forward12h`),children:(0,K.jsx)(ts,{className:`w-4 h-4`})}),s!==0&&(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>c(0),className:`text-xs text-bambu-green`,children:i(`queue.timeline.window.now`)})]}),v&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1.5`,children:[(0,K.jsx)(_s,{className:`w-3.5 h-3.5`}),i(`queue.timeline.allDoneBy`,{time:v.toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})})]})]}),p.length>0&&f.length===0&&(0,K.jsx)(`div`,{className:`mb-4 p-3 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark/40 text-xs text-bambu-gray`,children:i(`queue.timeline.nothingCommitted`)}),p.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,K.jsx)(Nc,{className:`w-12 h-12 mb-3 opacity-30`}),(0,K.jsx)(`p`,{className:`text-sm`,children:i(`queue.timeline.noData`)})]}):(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-2 text-xs font-medium text-bambu-gray border-r border-bambu-dark-tertiary`,children:i(`queue.timeline.printerColumnHeader`)}),(0,K.jsx)(`div`,{className:`relative flex-1 h-9`,children:h.map(e=>(0,K.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/40 text-[10px] sm:text-xs text-bambu-gray pl-1 flex items-center`,style:{left:`${e.pct}%`},children:e.label},e.ms))})]}),(0,K.jsxs)(`div`,{ref:b,className:`relative`,children:[p.map(e=>{let t=m.get(e.key)??[];return(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary/40 last:border-b-0`,children:[(0,K.jsxs)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-3 border-r border-bambu-dark-tertiary flex items-center gap-2`,children:[(0,K.jsx)(bl,{className:`w-3.5 h-3.5 shrink-0 ${e.printerId==null&&e.targetModel==null?`text-orange-400`:e.targetModel?`text-blue-400`:`text-bambu-green`}`}),(0,K.jsx)(`span`,{className:`text-sm text-white truncate`,children:e.label})]}),(0,K.jsxs)(`div`,{className:`relative flex-1`,style:{height:56},children:[h.map(e=>(0,K.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/30`,style:{left:`${e.pct}%`}},e.ms)),(0,K.jsx)(`div`,{className:`absolute inset-0 opacity-30`,style:{backgroundImage:`repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(255,255,255,0.04) 6px, rgba(255,255,255,0.04) 12px)`},"aria-hidden":!0}),t.map(e=>{let t=Math.max(l,e.estimatedStart.getTime()),n=Math.min(u,e.estimatedEnd.getTime());if(n<=l||t>=u)return null;let i=(t-l)/e5*100,a=(n-t)/e5*100,o=e.item.archive_name||e.item.library_file_name||`#${e.item.id}`,s=e.item.archive_thumbnail?Q.getArchiveThumbnail(e.item.archive_id):e.item.library_file_thumbnail?Q.getLibraryFileThumbnailUrl(e.item.library_file_id):null,c=e.type===`printing`,d=e.item.batch_id!=null;return(0,K.jsxs)(`button`,{onClick:()=>r(e.item),title:[o,`${t5(e.estimatedStart)} → ${t5(e.estimatedEnd)}`,e.item.print_time_seconds?yf(e.item.print_time_seconds):null,c&&e.progress!=null?`${Math.round(e.progress)}%`:null,e.item.batch_name?`batch: ${e.item.batch_name}`:null].filter(Boolean).join(` · `),className:`absolute rounded-md transition-all hover:brightness-110 hover:z-10 overflow-hidden flex items-center gap-1.5 px-1.5 text-left ${c?`bg-blue-500/30 border border-blue-400/60`:d?`bg-cyan-500/20 border border-cyan-400/50`:`bg-bambu-green/20 border border-bambu-green/40`}`,style:{left:`${i}%`,width:`max(${ULe}px, ${a}%)`,top:8,height:WLe},children:[s&&(0,K.jsx)(`img`,{src:s,alt:``,className:`w-7 h-7 rounded object-cover shrink-0 bg-bambu-dark`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`div`,{className:`text-xs text-white font-medium truncate leading-tight`,children:o}),(0,K.jsxs)(`div`,{className:`text-[10px] text-bambu-gray truncate leading-tight`,children:[e.item.print_time_seconds?yf(e.item.print_time_seconds):``,c&&e.progress!=null?` · ${Math.round(e.progress)}%`:``]})]}),c&&e.progress!=null&&(0,K.jsx)(`div`,{className:`absolute bottom-0 left-0 h-0.5 bg-blue-300`,style:{width:`${e.progress}%`},"aria-hidden":!0})]},e.item.id)})]})]},e.key)}),_&&(0,K.jsxs)(`div`,{className:`absolute top-0 bottom-0 pointer-events-none z-20 flex inset-x-0`,children:[(0,K.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0`}),(0,K.jsx)(`div`,{className:`relative flex-1`,children:(0,K.jsx)(`div`,{className:`absolute top-0 bottom-0 w-0.5 bg-red-400 shadow-[0_0_8px_rgba(248,113,113,0.6)]`,style:{left:`${g}%`},children:(0,K.jsx)(`div`,{className:`absolute -top-1 -left-1 w-2.5 h-2.5 bg-red-400 rounded-full`})})})]})]})]})]})}function n5(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function qLe({status:e,waitingReason:t,printerState:n,t:r}){if(e===`pending`&&t)return(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-purple-400 bg-purple-400/10 border-purple-400/20`,children:[(0,K.jsx)(_s,{className:`w-3.5 h-3.5`}),r(`queue.status.waiting`)]});if(e===`printing`&&n===`PAUSE`)return(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-yellow-400 bg-yellow-400/10 border-yellow-400/20`,children:[(0,K.jsx)(ul,{className:`w-3.5 h-3.5`}),r(`queue.status.paused`)]});let{icon:i,color:a,label:o}={pending:{icon:_s,color:`text-status-warning bg-status-warning/10 border-status-warning/20`,label:r(`queue.status.pending`)},printing:{icon:hl,color:`text-blue-400 bg-blue-400/10 border-blue-400/20`,label:r(`queue.status.printing`)},completed:{icon:ls,color:`text-status-ok bg-status-ok/10 border-status-ok/20`,label:r(`queue.status.completed`)},failed:{icon:ms,color:`text-status-error bg-status-error/10 border-status-error/20`,label:r(`queue.status.failed`)},skipped:{icon:Kl,color:`text-orange-400 bg-orange-400/10 border-orange-400/20`,label:r(`queue.status.skipped`)},cancelled:{icon:Pu,color:`text-gray-400 bg-gray-400/10 border-gray-400/20`,label:r(`queue.status.cancelled`)}}[e];return(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border ${a}`,children:[(0,K.jsx)(i,{className:`w-3.5 h-3.5`}),o]})}function JLe({selectedCount:e,printers:t,onSave:n,onClose:r,isSaving:i,canControlPrinter:a,t:o}){let[s,c]=(0,y.useState)(`unchanged`),[l,u]=(0,y.useState)(`unchanged`),[d,f]=(0,y.useState)(`unchanged`),[p,m]=(0,y.useState)(`unchanged`),[h,g]=(0,y.useState)(`unchanged`),[_,v]=(0,y.useState)(`unchanged`),[b,x]=(0,y.useState)(`unchanged`),[S,C]=(0,y.useState)(`unchanged`),[w,T]=(0,y.useState)(`unchanged`),[E,D]=(0,y.useState)(`unchanged`),[O,k]=(0,y.useState)(`unchanged`),A=t.some(e=>e.nozzle_count===2),j=()=>{let e={};s!==`unchanged`&&(e.printer_id=s),l!==`unchanged`&&(e.manual_start=l),d!==`unchanged`&&(e.auto_off_after=d),p!==`unchanged`&&(e.require_previous_success=p),h!==`unchanged`&&(e.bed_levelling=h),_!==`unchanged`&&(e.flow_cali=_),b!==`unchanged`&&(e.vibration_cali=b),S!==`unchanged`&&(e.layer_inspect=S),w!==`unchanged`&&(e.timelapse=w),E!==`unchanged`&&(e.use_ams=E),O!==`unchanged`&&(e.nozzle_offset_cali=O),n(e)},M=s!==`unchanged`||l!==`unchanged`||d!==`unchanged`||p!==`unchanged`||h!==`unchanged`||_!==`unchanged`||b!==`unchanged`||S!==`unchanged`||w!==`unchanged`||E!==`unchanged`||O!==`unchanged`;return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,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-lg font-semibold text-white`,children:o(`queue.bulkEdit.title`,{count:e})}),(0,K.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,K.jsx)(Pu,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:o(`queue.bulkEdit.description`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:o(`queue.bulkEdit.printer`)}),(0,K.jsxs)(`select`,{value:s===null?`null`:s===`unchanged`?`unchanged`:String(s),onChange:e=>{let t=e.target.value;c(t===`unchanged`?`unchanged`:t===`null`?null:Number(t))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`unchanged`,children:o(`queue.bulkEdit.noChange`)}),(0,K.jsx)(`option`,{value:`null`,children:o(`queue.filter.unassigned`)}),t.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:o(`queue.bulkEdit.queueOptions`)}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(r5,{label:o(`queue.bulkEdit.staged`),value:l,onChange:u,t:o}),(0,K.jsx)(r5,{label:o(`queue.bulkEdit.autoPowerOff`),value:d,onChange:f,disabled:!a,t:o}),(0,K.jsx)(r5,{label:o(`queue.bulkEdit.requirePrevious`),value:p,onChange:m,t:o})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:o(`queue.bulkEdit.printOptions`)}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(r5,{label:o(`queue.bulkEdit.bedLevelling`),value:h,onChange:g,t:o}),(0,K.jsx)(r5,{label:o(`queue.bulkEdit.flowCalibration`),value:_,onChange:v,t:o}),(0,K.jsx)(r5,{label:o(`queue.bulkEdit.vibrationCalibration`),value:b,onChange:x,t:o}),(0,K.jsx)(r5,{label:o(`queue.bulkEdit.layerInspection`),value:S,onChange:C,t:o}),(0,K.jsx)(r5,{label:o(`queue.bulkEdit.timelapse`),value:w,onChange:T,t:o}),(0,K.jsx)(r5,{label:o(`queue.bulkEdit.useAms`),value:E,onChange:D,t:o}),A&&(0,K.jsx)(r5,{label:o(`queue.bulkEdit.nozzleOffsetCali`),value:O,onChange:k,t:o})]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:r,children:o(`common.cancel`)}),(0,K.jsx)($,{onClick:j,disabled:!M||i,children:o(i?`common.saving`:`queue.bulkEdit.applyChanges`)})]})]})})}function r5({label:e,value:t,onChange:n,disabled:r,t:i}){return(0,K.jsxs)(`div`,{className:`flex items-center justify-between py-1 ${r?`opacity-50`:``}`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded-lg p-0.5`,children:[(0,K.jsx)(`button`,{onClick:()=>n(`unchanged`),disabled:r,className:`px-2 py-1 text-xs rounded ${t===`unchanged`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:`—`}),(0,K.jsx)(`button`,{onClick:()=>n(!1),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!1?`bg-red-500/20 text-red-400`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.off`)}),(0,K.jsx)(`button`,{onClick:()=>n(!0),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!0?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.on`)})]})]})}function i5({item:e,position:t,onEdit:n,onCancel:r,onRemove:i,onStop:a,onRequeue:o,onStart:s,timeFormat:c=`system`,isSelected:l=!1,onToggleSelect:u,hasPermission:d,canModify:f,printerState:p,t:m}){let{data:h}=q({queryKey:[`printerStatus`,e.printer_id],queryFn:()=>Q.getPrinterStatus(e.printer_id),refetchInterval:3e4,enabled:e.printer_id!=null&&p===`printing`}),g=!!e.library_file_id&&!e.archive_id,{data:_}=q({queryKey:[`archive-plates`,e.archive_id],queryFn:()=>Q.getArchivePlates(e.archive_id),enabled:!!e.archive_id&&!g&&!e.archive_deleted}),{data:v}=q({queryKey:[`library-file-plates`,e.library_file_id],queryFn:()=>Q.getLibraryFilePlates(e.library_file_id),enabled:g&&!!e.library_file_id}),y=g?v:_,b=y?.plates??[],x=d(`queue:reorder`),{attributes:S,listeners:C,setNodeRef:w,transform:T,transition:E,isDragging:D}=K8({id:e.id,disabled:e.status!==`pending`||!x}),O={transform:w6.Transform.toString(T),transition:E},k=e.status===`printing`,A=e.status===`pending`,j=[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status),M=A&&u;return(0,K.jsxs)(`div`,{ref:w,style:O,className:` + `},fIe={onDragStart(e){let{active:t}=e;return`Picked up draggable item `+t.id+`.`},onDragOver(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was moved over droppable area `+n.id+`.`:`Draggable item `+t.id+` is no longer over a droppable area.`},onDragEnd(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was dropped over droppable area `+n.id:`Draggable item `+t.id+` was dropped.`},onDragCancel(e){let{active:t}=e;return`Dragging was cancelled. Draggable item `+t.id+` was dropped.`}};function pIe(e){let{announcements:t=fIe,container:n,hiddenTextDescribedById:r,screenReaderInstructions:i=dIe}=e,{announce:a,announcement:o}=cIe(),s=v6(`DndLiveRegion`),[c,l]=(0,y.useState)(!1);if((0,y.useEffect)(()=>{l(!0)},[]),lIe((0,y.useMemo)(()=>({onDragStart(e){let{active:n}=e;a(t.onDragStart({active:n}))},onDragMove(e){let{active:n,over:r}=e;t.onDragMove&&a(t.onDragMove({active:n,over:r}))},onDragOver(e){let{active:n,over:r}=e;a(t.onDragOver({active:n,over:r}))},onDragEnd(e){let{active:n,over:r}=e;a(t.onDragEnd({active:n,over:r}))},onDragCancel(e){let{active:n,over:r}=e;a(t.onDragCancel({active:n,over:r}))}}),[a,t])),!c)return null;let u=y.createElement(y.Fragment,null,y.createElement(oIe,{id:r,value:i.draggable}),y.createElement(sIe,{id:s,announcement:o}));return n?(0,Zf.createPortal)(u,n):u}var D6;(function(e){e.DragStart=`dragStart`,e.DragMove=`dragMove`,e.DragEnd=`dragEnd`,e.DragCancel=`dragCancel`,e.DragOver=`dragOver`,e.RegisterDroppable=`registerDroppable`,e.SetDroppableDisabled=`setDroppableDisabled`,e.UnregisterDroppable=`unregisterDroppable`})(D6||={});function O6(){}function k6(e,t){return(0,y.useMemo)(()=>({sensor:e,options:t??{}}),[e,t])}function A6(){var e=[...arguments];return(0,y.useMemo)(()=>[...e].filter(e=>e!=null),[...e])}var j6=Object.freeze({x:0,y:0});function M6(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function mIe(e,t){let n=C6(e);if(!n)return`0 0`;let r={x:(n.x-t.left)/t.width*100,y:(n.y-t.top)/t.height*100};return r.x+`% `+r.y+`%`}function N6(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function hIe(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function P6(e){let{left:t,top:n,height:r,width:i}=e;return[{x:t,y:n},{x:t+i,y:n},{x:t,y:n+r},{x:t+i,y:n+r}]}function F6(e,t){if(!e||e.length===0)return null;let[n]=e;return t?n[t]:n}function I6(e,t,n){return t===void 0&&(t=e.left),n===void 0&&(n=e.top),{x:t+e.width*.5,y:n+e.height*.5}}var L6=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=I6(t,t.left,t.top),a=[];for(let e of r){let{id:t}=e,r=n.get(t);if(r){let n=M6(I6(r),i);a.push({id:t,data:{droppableContainer:e,value:n}})}}return a.sort(N6)},gIe=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=P6(t),a=[];for(let e of r){let{id:t}=e,r=n.get(t);if(r){let n=P6(r),o=i.reduce((e,t,r)=>e+M6(n[r],t),0),s=Number((o/4).toFixed(4));a.push({id:t,data:{droppableContainer:e,value:s}})}}return a.sort(N6)};function _Ie(e,t){let n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),a=Math.min(t.top+t.height,e.top+e.height),o=i-r,s=a-n;if(r{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=[];for(let e of r){let{id:r}=e,a=n.get(r);if(a){let n=_Ie(a,t);n>0&&i.push({id:r,data:{droppableContainer:e,value:n}})}}return i.sort(hIe)};function yIe(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function R6(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:j6}function bIe(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>({...t,top:t.top+e*n.y,bottom:t.bottom+e*n.y,left:t.left+e*n.x,right:t.right+e*n.x}),{...t})}}var xIe=bIe(1);function z6(e){if(e.startsWith(`matrix3d(`)){let t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith(`matrix(`)){let t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function SIe(e,t,n){let r=z6(t);if(!r)return e;let{scaleX:i,scaleY:a,x:o,y:s}=r,c=e.left-o-(1-i)*parseFloat(n),l=e.top-s-(1-a)*parseFloat(n.slice(n.indexOf(` `)+1)),u=i?e.width/i:e.width,d=a?e.height/a:e.height;return{width:u,height:d,top:l,right:c+u,bottom:l+d,left:c}}var CIe={ignoreTransform:!1};function B6(e,t){t===void 0&&(t=CIe);let n=e.getBoundingClientRect();if(t.ignoreTransform){let{transform:t,transformOrigin:r}=o6(e).getComputedStyle(e);t&&(n=SIe(n,t,r))}let{top:r,left:i,width:a,height:o,bottom:s,right:c}=n;return{top:r,left:i,width:a,height:o,bottom:s,right:c}}function V6(e){return B6(e,{ignoreTransform:!0})}function wIe(e){let t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function TIe(e,t){return t===void 0&&(t=o6(e).getComputedStyle(e)),t.position===`fixed`}function EIe(e,t){t===void 0&&(t=o6(e).getComputedStyle(e));let n=/(auto|scroll|overlay)/;return[`overflow`,`overflowX`,`overflowY`].some(e=>{let r=t[e];return typeof r==`string`?n.test(r):!1})}function H6(e,t){let n=[];function r(i){if(t!=null&&n.length>=t||!i)return n;if(s6(i)&&i.scrollingElement!=null&&!n.includes(i.scrollingElement))return n.push(i.scrollingElement),n;if(!c6(i)||l6(i)||n.includes(i))return n;let a=o6(e).getComputedStyle(i);return i!==e&&EIe(i,a)&&n.push(i),TIe(i,a)?n:r(i.parentNode)}return e?r(e):n}function U6(e){let[t]=H6(e,1);return t??null}function W6(e){return!r6||!e?null:i6(e)?e:a6(e)?s6(e)||e===u6(e).scrollingElement?window:c6(e)?e:null:null}function G6(e){return i6(e)?e.scrollX:e.scrollLeft}function K6(e){return i6(e)?e.scrollY:e.scrollTop}function q6(e){return{x:G6(e),y:K6(e)}}var J6;(function(e){e[e.Forward=1]=`Forward`,e[e.Backward=-1]=`Backward`})(J6||={});function Y6(e){return!r6||!e?!1:e===document.scrollingElement}function X6(e){let t={x:0,y:0},n=Y6(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},r={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height};return{isTop:e.scrollTop<=t.y,isLeft:e.scrollLeft<=t.x,isBottom:e.scrollTop>=r.y,isRight:e.scrollLeft>=r.x,maxScroll:r,minScroll:t}}var DIe={x:.2,y:.2};function OIe(e,t,n,r,i){let{top:a,left:o,right:s,bottom:c}=n;r===void 0&&(r=10),i===void 0&&(i=DIe);let{isTop:l,isBottom:u,isLeft:d,isRight:f}=X6(e),p={x:0,y:0},m={x:0,y:0},h={height:t.height*i.y,width:t.width*i.x};return!l&&a<=t.top+h.height?(p.y=J6.Backward,m.y=r*Math.abs((t.top+h.height-a)/h.height)):!u&&c>=t.bottom-h.height&&(p.y=J6.Forward,m.y=r*Math.abs((t.bottom-h.height-c)/h.height)),!f&&s>=t.right-h.width?(p.x=J6.Forward,m.x=r*Math.abs((t.right-h.width-s)/h.width)):!d&&o<=t.left+h.width&&(p.x=J6.Backward,m.x=r*Math.abs((t.left+h.width-o)/h.width)),{direction:p,speed:m}}function kIe(e){if(e===document.scrollingElement){let{innerWidth:e,innerHeight:t}=window;return{top:0,left:0,right:e,bottom:t,width:e,height:t}}let{top:t,left:n,right:r,bottom:i}=e.getBoundingClientRect();return{top:t,left:n,right:r,bottom:i,width:e.clientWidth,height:e.clientHeight}}function Z6(e){return e.reduce((e,t)=>b6(e,q6(t)),j6)}function AIe(e){return e.reduce((e,t)=>e+G6(t),0)}function jIe(e){return e.reduce((e,t)=>e+K6(t),0)}function Q6(e,t){if(t===void 0&&(t=B6),!e)return;let{top:n,left:r,bottom:i,right:a}=t(e);U6(e)&&(i<=0||a<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:`center`,inline:`center`})}var MIe=[[`x`,[`left`,`right`],AIe],[`y`,[`top`,`bottom`],jIe]],$6=class{constructor(e,t){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;let n=H6(t),r=Z6(n);this.rect={...e},this.width=e.width,this.height=e.height;for(let[e,t,i]of MIe)for(let a of t)Object.defineProperty(this,a,{get:()=>{let t=i(n),o=r[e]-t;return this.rect[a]+o},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}},e8=class{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(e=>this.target?.removeEventListener(...e))},this.target=e}add(e,t,n){var r;(r=this.target)==null||r.addEventListener(e,t,n),this.listeners.push([e,t,n])}};function NIe(e){let{EventTarget:t}=o6(e);return e instanceof t?e:u6(e)}function t8(e,t){let n=Math.abs(e.x),r=Math.abs(e.y);return typeof t==`number`?Math.sqrt(n**2+r**2)>t:`x`in t&&`y`in t?n>t.x&&r>t.y:`x`in t?n>t.x:`y`in t?r>t.y:!1}var n8;(function(e){e.Click=`click`,e.DragStart=`dragstart`,e.Keydown=`keydown`,e.ContextMenu=`contextmenu`,e.Resize=`resize`,e.SelectionChange=`selectionchange`,e.VisibilityChange=`visibilitychange`})(n8||={});function r8(e){e.preventDefault()}function PIe(e){e.stopPropagation()}var i8;(function(e){e.Space=`Space`,e.Down=`ArrowDown`,e.Right=`ArrowRight`,e.Left=`ArrowLeft`,e.Up=`ArrowUp`,e.Esc=`Escape`,e.Enter=`Enter`,e.Tab=`Tab`})(i8||={});var a8={start:[i8.Space,i8.Enter],cancel:[i8.Esc],end:[i8.Space,i8.Enter,i8.Tab]},FIe=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case i8.Right:return{...n,x:n.x+25};case i8.Left:return{...n,x:n.x-25};case i8.Down:return{...n,y:n.y+25};case i8.Up:return{...n,y:n.y-25}}},o8=class{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;let{event:{target:t}}=e;this.props=e,this.listeners=new e8(u6(t)),this.windowListeners=new e8(o6(t)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(n8.Resize,this.handleCancel),this.windowListeners.add(n8.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(n8.Keydown,this.handleKeyDown))}handleStart(){let{activeNode:e,onStart:t}=this.props,n=e.node.current;n&&Q6(n),t(j6)}handleKeyDown(e){if(S6(e)){let{active:t,context:n,options:r}=this.props,{keyboardCodes:i=a8,coordinateGetter:a=FIe,scrollBehavior:o=`smooth`}=r,{code:s}=e;if(i.end.includes(s)){this.handleEnd(e);return}if(i.cancel.includes(s)){this.handleCancel(e);return}let{collisionRect:c}=n.current,l=c?{x:c.left,y:c.top}:j6;this.referenceCoordinates||=l;let u=a(e,{active:t,context:n.current,currentCoordinates:l});if(u){let t=x6(u,l),r={x:0,y:0},{scrollableAncestors:i}=n.current;for(let n of i){let i=e.code,{isTop:a,isRight:s,isLeft:c,isBottom:l,maxScroll:d,minScroll:f}=X6(n),p=kIe(n),m={x:Math.min(i===i8.Right?p.right-p.width/2:p.right,Math.max(i===i8.Right?p.left:p.left+p.width/2,u.x)),y:Math.min(i===i8.Down?p.bottom-p.height/2:p.bottom,Math.max(i===i8.Down?p.top:p.top+p.height/2,u.y))},h=i===i8.Right&&!s||i===i8.Left&&!c,g=i===i8.Down&&!l||i===i8.Up&&!a;if(h&&m.x!==u.x){let e=n.scrollLeft+t.x,a=i===i8.Right&&e<=d.x||i===i8.Left&&e>=f.x;if(a&&!t.y){n.scrollTo({left:e,behavior:o});return}a?r.x=n.scrollLeft-e:r.x=i===i8.Right?n.scrollLeft-d.x:n.scrollLeft-f.x,r.x&&n.scrollBy({left:-r.x,behavior:o});break}else if(g&&m.y!==u.y){let e=n.scrollTop+t.y,a=i===i8.Down&&e<=d.y||i===i8.Up&&e>=f.y;if(a&&!t.x){n.scrollTo({top:e,behavior:o});return}a?r.y=n.scrollTop-e:r.y=i===i8.Down?n.scrollTop-d.y:n.scrollTop-f.y,r.y&&n.scrollBy({top:-r.y,behavior:o});break}}this.handleMove(e,b6(x6(u,this.referenceCoordinates),r))}}}handleMove(e,t){let{onMove:n}=this.props;e.preventDefault(),n(t)}handleEnd(e){let{onEnd:t}=this.props;e.preventDefault(),this.detach(),t()}handleCancel(e){let{onCancel:t}=this.props;e.preventDefault(),this.detach(),t()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}};o8.activators=[{eventName:`onKeyDown`,handler:(e,t,n)=>{let{keyboardCodes:r=a8,onActivation:i}=t,{active:a}=n,{code:o}=e.nativeEvent;if(r.start.includes(o)){let t=a.activatorNode.current;return t&&e.target!==t?!1:(e.preventDefault(),i?.({event:e.nativeEvent}),!0)}return!1}}];function s8(e){return!!(e&&`distance`in e)}function c8(e){return!!(e&&`delay`in e)}var l8=class{constructor(e,t,n){n===void 0&&(n=NIe(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=t;let{event:r}=e,{target:i}=r;this.props=e,this.events=t,this.document=u6(i),this.documentListeners=new e8(this.document),this.listeners=new e8(n),this.windowListeners=new e8(o6(i)),this.initialCoordinates=C6(r)??j6,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){let{events:e,props:{options:{activationConstraint:t,bypassActivationConstraint:n}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(n8.Resize,this.handleCancel),this.windowListeners.add(n8.DragStart,r8),this.windowListeners.add(n8.VisibilityChange,this.handleCancel),this.windowListeners.add(n8.ContextMenu,r8),this.documentListeners.add(n8.Keydown,this.handleKeydown),t){if(n!=null&&n({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(c8(t)){this.timeoutId=setTimeout(this.handleStart,t.delay),this.handlePending(t);return}if(s8(t)){this.handlePending(t);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,t){let{active:n,onPending:r}=this.props;r(n,e,this.initialCoordinates,t)}handleStart(){let{initialCoordinates:e}=this,{onStart:t}=this.props;e&&(this.activated=!0,this.documentListeners.add(n8.Click,PIe,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(n8.SelectionChange,this.removeTextSelection),t(e))}handleMove(e){let{activated:t,initialCoordinates:n,props:r}=this,{onMove:i,options:{activationConstraint:a}}=r;if(!n)return;let o=C6(e)??j6,s=x6(n,o);if(!t&&a){if(s8(a)){if(a.tolerance!=null&&t8(s,a.tolerance))return this.handleCancel();if(t8(s,a.distance))return this.handleStart()}if(c8(a)&&t8(s,a.tolerance))return this.handleCancel();this.handlePending(a,s);return}e.cancelable&&e.preventDefault(),i(o)}handleEnd(){let{onAbort:e,onEnd:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleCancel(){let{onAbort:e,onCancel:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleKeydown(e){e.code===i8.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}},IIe={cancel:{name:`pointercancel`},move:{name:`pointermove`},end:{name:`pointerup`}},u8=class extends l8{constructor(e){let{event:t}=e,n=u6(t.target);super(e,IIe,n)}};u8.activators=[{eventName:`onPointerDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r?.({event:n}),!0)}}];var LIe={move:{name:`mousemove`},end:{name:`mouseup`}},d8;(function(e){e[e.RightClick=2]=`RightClick`})(d8||={});var RIe=class extends l8{constructor(e){super(e,LIe,u6(e.event.target))}};RIe.activators=[{eventName:`onMouseDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===d8.RightClick?!1:(r?.({event:n}),!0)}}];var f8={cancel:{name:`touchcancel`},move:{name:`touchmove`},end:{name:`touchend`}},zIe=class extends l8{constructor(e){super(e,f8)}static setup(){return window.addEventListener(f8.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(f8.move.name,e)};function e(){}}};zIe.activators=[{eventName:`onTouchStart`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t,{touches:i}=n;return i.length>1?!1:(r?.({event:n}),!0)}}];var p8;(function(e){e[e.Pointer=0]=`Pointer`,e[e.DraggableRect=1]=`DraggableRect`})(p8||={});var m8;(function(e){e[e.TreeOrder=0]=`TreeOrder`,e[e.ReversedTreeOrder=1]=`ReversedTreeOrder`})(m8||={});function BIe(e){let{acceleration:t,activator:n=p8.Pointer,canScroll:r,draggingRect:i,enabled:a,interval:o=5,order:s=m8.TreeOrder,pointerCoordinates:c,scrollableAncestors:l,scrollableAncestorRects:u,delta:d,threshold:f}=e,p=HIe({delta:d,disabled:!a}),[m,h]=tIe(),g=(0,y.useRef)({x:0,y:0}),_=(0,y.useRef)({x:0,y:0}),v=(0,y.useMemo)(()=>{switch(n){case p8.Pointer:return c?{top:c.y,bottom:c.y,left:c.x,right:c.x}:null;case p8.DraggableRect:return i}},[n,i,c]),b=(0,y.useRef)(null),x=(0,y.useCallback)(()=>{let e=b.current;if(!e)return;let t=g.current.x*_.current.x,n=g.current.y*_.current.y;e.scrollBy(t,n)},[]),S=(0,y.useMemo)(()=>s===m8.TreeOrder?[...l].reverse():l,[s,l]);(0,y.useEffect)(()=>{if(!a||!l.length||!v){h();return}for(let e of S){if(r?.(e)===!1)continue;let n=u[l.indexOf(e)];if(!n)continue;let{direction:i,speed:a}=OIe(e,n,v,t,f);for(let e of[`x`,`y`])p[e][i[e]]||(a[e]=0,i[e]=0);if(a.x>0||a.y>0){h(),b.current=e,m(x,o),g.current=a,_.current=i;return}}g.current={x:0,y:0},_.current={x:0,y:0},h()},[t,x,r,h,a,o,JSON.stringify(v),JSON.stringify(p),m,l,S,u,JSON.stringify(f)])}var VIe={x:{[J6.Backward]:!1,[J6.Forward]:!1},y:{[J6.Backward]:!1,[J6.Forward]:!1}};function HIe(e){let{delta:t,disabled:n}=e,r=g6(t);return m6(e=>{if(n||!r||!e)return VIe;let i={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[J6.Backward]:e.x[J6.Backward]||i.x===-1,[J6.Forward]:e.x[J6.Forward]||i.x===1},y:{[J6.Backward]:e.y[J6.Backward]||i.y===-1,[J6.Forward]:e.y[J6.Forward]||i.y===1}}},[n,t,r])}function UIe(e,t){let n=t==null?void 0:e.get(t),r=n?n.node.current:null;return m6(e=>t==null?null:r??e??null,[r,t])}function WIe(e,t){return(0,y.useMemo)(()=>e.reduce((e,n)=>{let{sensor:r}=n,i=r.activators.map(e=>({eventName:e.eventName,handler:t(e.handler,n)}));return[...e,...i]},[]),[e,t])}var h8;(function(e){e[e.Always=0]=`Always`,e[e.BeforeDragging=1]=`BeforeDragging`,e[e.WhileDragging=2]=`WhileDragging`})(h8||={});var g8;(function(e){e.Optimized=`optimized`})(g8||={});var _8=new Map;function GIe(e,t){let{dragging:n,dependencies:r,config:i}=t,[a,o]=(0,y.useState)(null),{frequency:s,measure:c,strategy:l}=i,u=(0,y.useRef)(e),d=g(),f=p6(d),p=(0,y.useCallback)(function(e){e===void 0&&(e=[]),!f.current&&o(t=>t===null?e:t.concat(e.filter(e=>!t.includes(e))))},[f]),m=(0,y.useRef)(null),h=m6(t=>{if(d&&!n)return _8;if(!t||t===_8||u.current!==e||a!=null){let t=new Map;for(let n of e){if(!n)continue;if(a&&a.length>0&&!a.includes(n.id)&&n.rect.current){t.set(n.id,n.rect.current);continue}let e=n.node.current,r=e?new $6(c(e),e):null;n.rect.current=r,r&&t.set(n.id,r)}return t}return t},[e,a,n,d,c]);return(0,y.useEffect)(()=>{u.current=e},[e]),(0,y.useEffect)(()=>{d||p()},[n,d]),(0,y.useEffect)(()=>{a&&a.length>0&&o(null)},[JSON.stringify(a)]),(0,y.useEffect)(()=>{d||typeof s!=`number`||m.current!==null||(m.current=setTimeout(()=>{p(),m.current=null},s))},[s,d,p,...r]),{droppableRects:h,measureDroppableContainers:p,measuringScheduled:a!=null};function g(){switch(l){case h8.Always:return!1;case h8.BeforeDragging:return n;default:return!n}}}function v8(e,t){return m6(n=>e?n||(typeof t==`function`?t(e):e):null,[t,e])}function KIe(e,t){return v8(e,t)}function qIe(e){let{callback:t,disabled:n}=e,r=f6(t),i=(0,y.useMemo)(()=>{if(n||typeof window>`u`||window.MutationObserver===void 0)return;let{MutationObserver:e}=window;return new e(r)},[r,n]);return(0,y.useEffect)(()=>()=>i?.disconnect(),[i]),i}function y8(e){let{callback:t,disabled:n}=e,r=f6(t),i=(0,y.useMemo)(()=>{if(n||typeof window>`u`||window.ResizeObserver===void 0)return;let{ResizeObserver:e}=window;return new e(r)},[n]);return(0,y.useEffect)(()=>()=>i?.disconnect(),[i]),i}function JIe(e){return new $6(B6(e),e)}function b8(e,t,n){t===void 0&&(t=JIe);let[r,i]=(0,y.useState)(null);function a(){i(r=>{if(!e)return null;if(e.isConnected===!1)return r??n??null;let i=t(e);return JSON.stringify(r)===JSON.stringify(i)?r:i})}let o=qIe({callback(t){if(e)for(let n of t){let{type:t,target:r}=n;if(t===`childList`&&r instanceof HTMLElement&&r.contains(e)){a();break}}}}),s=y8({callback:a});return d6(()=>{a(),e?(s?.observe(e),o?.observe(document.body,{childList:!0,subtree:!0})):(s?.disconnect(),o?.disconnect())},[e]),r}function YIe(e){return R6(e,v8(e))}var x8=[];function XIe(e){let t=(0,y.useRef)(e),n=m6(n=>e?n&&n!==x8&&e&&t.current&&e.parentNode===t.current.parentNode?n:H6(e):x8,[e]);return(0,y.useEffect)(()=>{t.current=e},[e]),n}function ZIe(e){let[t,n]=(0,y.useState)(null),r=(0,y.useRef)(e),i=(0,y.useCallback)(e=>{let t=W6(e.target);t&&n(e=>e?(e.set(t,q6(t)),new Map(e)):null)},[]);return(0,y.useEffect)(()=>{let t=r.current;if(e!==t){a(t);let o=e.map(e=>{let t=W6(e);return t?(t.addEventListener(`scroll`,i,{passive:!0}),[t,q6(t)]):null}).filter(e=>e!=null);n(o.length?new Map(o):null),r.current=e}return()=>{a(e),a(t)};function a(e){e.forEach(e=>{W6(e)?.removeEventListener(`scroll`,i)})}},[i,e]),(0,y.useMemo)(()=>e.length?t?Array.from(t.values()).reduce((e,t)=>b6(e,t),j6):Z6(e):j6,[e,t])}function S8(e,t){t===void 0&&(t=[]);let n=(0,y.useRef)(null);return(0,y.useEffect)(()=>{n.current=null},t),(0,y.useEffect)(()=>{let t=e!==j6;t&&!n.current&&(n.current=e),!t&&n.current&&(n.current=null)},[e]),n.current?x6(e,n.current):j6}function QIe(e){(0,y.useEffect)(()=>{if(!r6)return;let t=e.map(e=>{let{sensor:t}=e;return t.setup==null?void 0:t.setup()});return()=>{for(let e of t)e?.()}},e.map(e=>{let{sensor:t}=e;return t}))}function $Ie(e,t){return(0,y.useMemo)(()=>e.reduce((e,n)=>{let{eventName:r,handler:i}=n;return e[r]=e=>{i(e,t)},e},{}),[e,t])}function C8(e){return(0,y.useMemo)(()=>e?wIe(e):null,[e])}var w8=[];function eLe(e,t){t===void 0&&(t=B6);let[n]=e,r=C8(n?o6(n):null),[i,a]=(0,y.useState)(w8);function o(){a(()=>e.length?e.map(e=>Y6(e)?r:new $6(t(e),e)):w8)}let s=y8({callback:o});return d6(()=>{s?.disconnect(),o(),e.forEach(e=>s?.observe(e))},[e]),i}function T8(e){if(!e)return null;if(e.children.length>1)return e;let t=e.children[0];return c6(t)?t:e}function tLe(e){let{measure:t}=e,[n,r]=(0,y.useState)(null),i=y8({callback:(0,y.useCallback)(e=>{for(let{target:n}of e)if(c6(n)){r(e=>{let r=t(n);return e?{...e,width:r.width,height:r.height}:r});break}},[t])}),[a,o]=h6((0,y.useCallback)(e=>{let n=T8(e);i?.disconnect(),n&&i?.observe(n),r(n?t(n):null)},[t,i]));return(0,y.useMemo)(()=>({nodeRef:a,rect:n,setRef:o}),[n,a,o])}var nLe=[{sensor:u8,options:{}},{sensor:o8,options:{}}],rLe={current:{}},E8={draggable:{measure:V6},droppable:{measure:V6,strategy:h8.WhileDragging,frequency:g8.Optimized},dragOverlay:{measure:B6}},D8=class extends Map{get(e){return e==null?void 0:super.get(e)??void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:t}=e;return!t})}getNodeFor(e){return this.get(e)?.node.current??void 0}},iLe={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new D8,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:O6},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:E8,measureDroppableContainers:O6,windowRect:null,measuringScheduled:!1},O8={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:``},dispatch:O6,draggableNodes:new Map,over:null,measureDroppableContainers:O6},k8=(0,y.createContext)(O8),A8=(0,y.createContext)(iLe);function aLe(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new D8}}}function oLe(e,t){switch(t.type){case D6.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case D6.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case D6.DragEnd:case D6.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case D6.RegisterDroppable:{let{element:n}=t,{id:r}=n,i=new D8(e.droppable.containers);return i.set(r,n),{...e,droppable:{...e.droppable,containers:i}}}case D6.SetDroppableDisabled:{let{id:n,key:r,disabled:i}=t,a=e.droppable.containers.get(n);if(!a||r!==a.key)return e;let o=new D8(e.droppable.containers);return o.set(n,{...a,disabled:i}),{...e,droppable:{...e.droppable,containers:o}}}case D6.UnregisterDroppable:{let{id:n,key:r}=t,i=e.droppable.containers.get(n);if(!i||r!==i.key)return e;let a=new D8(e.droppable.containers);return a.delete(n),{...e,droppable:{...e.droppable,containers:a}}}default:return e}}function sLe(e){let{disabled:t}=e,{active:n,activatorEvent:r,draggableNodes:i}=(0,y.useContext)(k8),a=g6(r),o=g6(n?.id);return(0,y.useEffect)(()=>{if(!t&&!r&&a&&o!=null){if(!S6(a)||document.activeElement===a.target)return;let e=i.get(o);if(!e)return;let{activatorNode:t,node:n}=e;if(!t.current&&!n.current)return;requestAnimationFrame(()=>{for(let e of[t.current,n.current]){if(!e)continue;let t=iIe(e);if(t){t.focus();break}}})}},[r,t,i,o,a]),null}function j8(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((e,t)=>t({transform:e,...r}),n):n}function cLe(e){return(0,y.useMemo)(()=>({draggable:{...E8.draggable,...e?.draggable},droppable:{...E8.droppable,...e?.droppable},dragOverlay:{...E8.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function lLe(e){let{activeNode:t,measure:n,initialRect:r,config:i=!0}=e,a=(0,y.useRef)(!1),{x:o,y:s}=typeof i==`boolean`?{x:i,y:i}:i;d6(()=>{if(!o&&!s||!t){a.current=!1;return}if(a.current||!r)return;let e=t?.node.current;if(!e||e.isConnected===!1)return;let i=R6(n(e),r);if(o||(i.x=0),s||(i.y=0),a.current=!0,Math.abs(i.x)>0||Math.abs(i.y)>0){let t=U6(e);t&&t.scrollBy({top:i.y,left:i.x})}},[t,o,s,r,n])}var M8=(0,y.createContext)({...j6,scaleX:1,scaleY:1}),N8;(function(e){e[e.Uninitialized=0]=`Uninitialized`,e[e.Initializing=1]=`Initializing`,e[e.Initialized=2]=`Initialized`})(N8||={});var P8=(0,y.memo)(function(e){let{id:t,accessibility:n,autoScroll:r=!0,children:i,sensors:a=nLe,collisionDetection:o=vIe,measuring:s,modifiers:c,...l}=e,[u,d]=(0,y.useReducer)(oLe,void 0,aLe),[f,p]=uIe(),[m,h]=(0,y.useState)(N8.Uninitialized),g=m===N8.Initialized,{draggable:{active:_,nodes:v,translate:b},droppable:{containers:x}}=u,S=_==null?null:v.get(_),C=(0,y.useRef)({initial:null,translated:null}),w=(0,y.useMemo)(()=>_==null?null:{id:_,data:S?.data??rLe,rect:C},[_,S]),T=(0,y.useRef)(null),[E,D]=(0,y.useState)(null),[O,k]=(0,y.useState)(null),A=p6(l,Object.values(l)),j=v6(`DndDescribedBy`,t),M=(0,y.useMemo)(()=>x.getEnabled(),[x]),N=cLe(s),{droppableRects:P,measureDroppableContainers:F,measuringScheduled:I}=GIe(M,{dragging:g,dependencies:[b.x,b.y],config:N.droppable}),L=UIe(v,_),R=(0,y.useMemo)(()=>O?C6(O):null,[O]),z=Te(),B=KIe(L,N.draggable.measure);lLe({activeNode:_==null?null:v.get(_),config:z.layoutShiftCompensation,initialRect:B,measure:N.draggable.measure});let V=b8(L,N.draggable.measure,B),ee=b8(L?L.parentElement:null),H=(0,y.useRef)({activatorEvent:null,active:null,activeNode:L,collisionRect:null,collisions:null,droppableRects:P,draggableNodes:v,draggingNode:null,draggingNodeRect:null,droppableContainers:x,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),te=x.getNodeFor(H.current.over?.id),ne=tLe({measure:N.dragOverlay.measure}),re=ne.nodeRef.current??L,U=g?ne.rect??V:null,ie=!!(ne.nodeRef.current&&ne.rect),ae=YIe(ie?null:V),W=C8(re?o6(re):null),oe=XIe(g?te??L:null),se=eLe(oe),ce=j8(c,{transform:{x:b.x-ae.x,y:b.y-ae.y,scaleX:1,scaleY:1},activatorEvent:O,active:w,activeNodeRect:V,containerNodeRect:ee,draggingNodeRect:U,over:H.current.over,overlayNodeRect:ne.rect,scrollableAncestors:oe,scrollableAncestorRects:se,windowRect:W}),le=R?b6(R,b):null,ue=ZIe(oe),de=S8(ue),fe=S8(ue,[V]),pe=b6(ce,de),me=U?xIe(U,ce):null,he=w&&me?o({active:w,collisionRect:me,droppableRects:P,droppableContainers:M,pointerCoordinates:le}):null,ge=F6(he,`id`),[_e,ve]=(0,y.useState)(null),ye=yIe(ie?ce:b6(ce,fe),_e?.rect??null,V),be=(0,y.useRef)(null),xe=(0,y.useCallback)((e,t)=>{let{sensor:n,options:r}=t;if(T.current==null)return;let i=v.get(T.current);if(!i)return;let a=e.nativeEvent;be.current=new n({active:T.current,activeNode:i,event:a,options:r,context:H,onAbort(e){if(!v.get(e))return;let{onDragAbort:t}=A.current,n={id:e};t?.(n),f({type:`onDragAbort`,event:n})},onPending(e,t,n,r){if(!v.get(e))return;let{onDragPending:i}=A.current,a={id:e,constraint:t,initialCoordinates:n,offset:r};i?.(a),f({type:`onDragPending`,event:a})},onStart(e){let t=T.current;if(t==null)return;let n=v.get(t);if(!n)return;let{onDragStart:r}=A.current,i={activatorEvent:a,active:{id:t,data:n.data,rect:C}};(0,Zf.unstable_batchedUpdates)(()=>{r?.(i),h(N8.Initializing),d({type:D6.DragStart,initialCoordinates:e,active:t}),f({type:`onDragStart`,event:i}),D(be.current),k(a)})},onMove(e){d({type:D6.DragMove,coordinates:e})},onEnd:o(D6.DragEnd),onCancel:o(D6.DragCancel)});function o(e){return async function(){let{active:t,collisions:n,over:r,scrollAdjustedTranslate:i}=H.current,o=null;if(t&&i){let{cancelDrop:s}=A.current;o={activatorEvent:a,active:t,collisions:n,delta:i,over:r},e===D6.DragEnd&&typeof s==`function`&&await Promise.resolve(s(o))&&(e=D6.DragCancel)}T.current=null,(0,Zf.unstable_batchedUpdates)(()=>{d({type:e}),h(N8.Uninitialized),ve(null),D(null),k(null),be.current=null;let t=e===D6.DragEnd?`onDragEnd`:`onDragCancel`;if(o){let e=A.current[t];e?.(o),f({type:t,event:o})}})}}},[v]),Se=WIe(a,(0,y.useCallback)((e,t)=>(n,r)=>{let i=n.nativeEvent,a=v.get(r);if(T.current!==null||!a||i.dndKit||i.defaultPrevented)return;let o={active:a};e(n,t.options,o)===!0&&(i.dndKit={capturedBy:t.sensor},T.current=r,xe(n,t))},[v,xe]));QIe(a),d6(()=>{V&&m===N8.Initializing&&h(N8.Initialized)},[V,m]),(0,y.useEffect)(()=>{let{onDragMove:e}=A.current,{active:t,activatorEvent:n,collisions:r,over:i}=H.current;if(!t||!n)return;let a={active:t,activatorEvent:n,collisions:r,delta:{x:pe.x,y:pe.y},over:i};(0,Zf.unstable_batchedUpdates)(()=>{e?.(a),f({type:`onDragMove`,event:a})})},[pe.x,pe.y]),(0,y.useEffect)(()=>{let{active:e,activatorEvent:t,collisions:n,droppableContainers:r,scrollAdjustedTranslate:i}=H.current;if(!e||T.current==null||!t||!i)return;let{onDragOver:a}=A.current,o=r.get(ge),s=o&&o.rect.current?{id:o.id,rect:o.rect.current,data:o.data,disabled:o.disabled}:null,c={active:e,activatorEvent:t,collisions:n,delta:{x:i.x,y:i.y},over:s};(0,Zf.unstable_batchedUpdates)(()=>{ve(s),a?.(c),f({type:`onDragOver`,event:c})})},[ge]),d6(()=>{H.current={activatorEvent:O,active:w,activeNode:L,collisionRect:me,collisions:he,droppableRects:P,draggableNodes:v,draggingNode:re,draggingNodeRect:U,droppableContainers:x,over:_e,scrollableAncestors:oe,scrollAdjustedTranslate:pe},C.current={initial:U,translated:me}},[w,L,he,me,v,re,U,P,x,_e,oe,pe]),BIe({...z,delta:b,draggingRect:me,pointerCoordinates:le,scrollableAncestors:oe,scrollableAncestorRects:se});let Ce=(0,y.useMemo)(()=>({active:w,activeNode:L,activeNodeRect:V,activatorEvent:O,collisions:he,containerNodeRect:ee,dragOverlay:ne,draggableNodes:v,droppableContainers:x,droppableRects:P,over:_e,measureDroppableContainers:F,scrollableAncestors:oe,scrollableAncestorRects:se,measuringConfiguration:N,measuringScheduled:I,windowRect:W}),[w,L,V,O,he,ee,ne,v,x,P,_e,F,oe,se,N,I,W]),we=(0,y.useMemo)(()=>({activatorEvent:O,activators:Se,active:w,activeNodeRect:V,ariaDescribedById:{draggable:j},dispatch:d,draggableNodes:v,over:_e,measureDroppableContainers:F}),[O,Se,w,V,d,j,v,_e,F]);return y.createElement(E6.Provider,{value:p},y.createElement(k8.Provider,{value:we},y.createElement(A8.Provider,{value:Ce},y.createElement(M8.Provider,{value:ye},i)),y.createElement(sLe,{disabled:n?.restoreFocus===!1})),y.createElement(pIe,{...n,hiddenTextDescribedById:j}));function Te(){let e=E?.autoScrollEnabled===!1,t=typeof r==`object`?r.enabled===!1:r===!1,n=g&&!e&&!t;return typeof r==`object`?{...r,enabled:n}:{enabled:n}}}),uLe=(0,y.createContext)(null),F8=`button`,dLe=`Draggable`;function fLe(e){let{id:t,data:n,disabled:r=!1,attributes:i}=e,a=v6(dLe),{activators:o,activatorEvent:s,active:c,activeNodeRect:l,ariaDescribedById:u,draggableNodes:d,over:f}=(0,y.useContext)(k8),{role:p=F8,roleDescription:m=`draggable`,tabIndex:h=0}=i??{},g=c?.id===t,_=(0,y.useContext)(g?M8:uLe),[v,b]=h6(),[x,S]=h6(),C=$Ie(o,t),w=p6(n);return d6(()=>(d.set(t,{id:t,key:a,node:v,activatorNode:x,data:w}),()=>{let e=d.get(t);e&&e.key===a&&d.delete(t)}),[d,t]),{active:c,activatorEvent:s,activeNodeRect:l,attributes:(0,y.useMemo)(()=>({role:p,tabIndex:h,"aria-disabled":r,"aria-pressed":g&&p===F8?!0:void 0,"aria-roledescription":m,"aria-describedby":u.draggable}),[r,p,h,g,m,u.draggable]),isDragging:g,listeners:r?void 0:C,node:v,over:f,setNodeRef:b,setActivatorNodeRef:S,transform:_}}function I8(){return(0,y.useContext)(A8)}var pLe=`Droppable`,mLe={timeout:25};function hLe(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:i}=e,a=v6(pLe),{active:o,dispatch:s,over:c,measureDroppableContainers:l}=(0,y.useContext)(k8),u=(0,y.useRef)({disabled:n}),d=(0,y.useRef)(!1),f=(0,y.useRef)(null),p=(0,y.useRef)(null),{disabled:m,updateMeasurementsFor:h,timeout:g}={...mLe,...i},_=p6(h??r),v=y8({callback:(0,y.useCallback)(()=>{if(!d.current){d.current=!0;return}p.current!=null&&clearTimeout(p.current),p.current=setTimeout(()=>{l(Array.isArray(_.current)?_.current:[_.current]),p.current=null},g)},[g]),disabled:m||!o}),[b,x]=h6((0,y.useCallback)((e,t)=>{v&&(t&&(v.unobserve(t),d.current=!1),e&&v.observe(e))},[v])),S=p6(t);return(0,y.useEffect)(()=>{!v||!b.current||(v.disconnect(),d.current=!1,v.observe(b.current))},[b,v]),(0,y.useEffect)(()=>(s({type:D6.RegisterDroppable,element:{id:r,key:a,disabled:n,node:b,rect:f,data:S}}),()=>s({type:D6.UnregisterDroppable,key:a,id:r})),[r]),(0,y.useEffect)(()=>{n!==u.current.disabled&&(s({type:D6.SetDroppableDisabled,id:r,key:a,disabled:n}),u.current.disabled=n)},[r,a,n,s]),{active:o,rect:f,isOver:c?.id===r,node:b,over:c,setNodeRef:x}}function gLe(e){let{animation:t,children:n}=e,[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(null),s=g6(n);return!n&&!r&&s&&i(s),d6(()=>{if(!a)return;let e=r?.key,n=r?.props.id;if(e==null||n==null){i(null);return}Promise.resolve(t(n,a)).then(()=>{i(null)})},[t,r,a]),y.createElement(y.Fragment,null,n,r?(0,y.cloneElement)(r,{ref:o}):null)}var _Le={x:0,y:0,scaleX:1,scaleY:1};function vLe(e){let{children:t}=e;return y.createElement(k8.Provider,{value:O8},y.createElement(M8.Provider,{value:_Le},t))}var yLe={position:`fixed`,touchAction:`none`},bLe=e=>S6(e)?`transform 250ms ease`:void 0,xLe=(0,y.forwardRef)((e,t)=>{let{as:n,activatorEvent:r,adjustScale:i,children:a,className:o,rect:s,style:c,transform:l,transition:u=bLe}=e;if(!s)return null;let d=i?l:{...l,scaleX:1,scaleY:1},f={...yLe,width:s.width,height:s.height,top:s.top,left:s.left,transform:w6.Transform.toString(d),transformOrigin:i&&r?mIe(r,s):void 0,transition:typeof u==`function`?u(r):u,...c};return y.createElement(n,{className:o,style:f,ref:t},a)}),SLe={duration:250,easing:`ease`,keyframes:e=>{let{transform:{initial:t,final:n}}=e;return[{transform:w6.Transform.toString(t)},{transform:w6.Transform.toString(n)}]},sideEffects:(e=>t=>{let{active:n,dragOverlay:r}=t,i={},{styles:a,className:o}=e;if(a!=null&&a.active)for(let[e,t]of Object.entries(a.active))t!==void 0&&(i[e]=n.node.style.getPropertyValue(e),n.node.style.setProperty(e,t));if(a!=null&&a.dragOverlay)for(let[e,t]of Object.entries(a.dragOverlay))t!==void 0&&r.node.style.setProperty(e,t);return o!=null&&o.active&&n.node.classList.add(o.active),o!=null&&o.dragOverlay&&r.node.classList.add(o.dragOverlay),function(){for(let[e,t]of Object.entries(i))n.node.style.setProperty(e,t);o!=null&&o.active&&n.node.classList.remove(o.active)}})({styles:{active:{opacity:`0`}}})};function CLe(e){let{config:t,draggableNodes:n,droppableContainers:r,measuringConfiguration:i}=e;return f6((e,a)=>{if(t===null)return;let o=n.get(e);if(!o)return;let s=o.node.current;if(!s)return;let c=T8(a);if(!c)return;let{transform:l}=o6(a).getComputedStyle(a),u=z6(l);if(!u)return;let d=typeof t==`function`?t:wLe(t);return Q6(s,i.draggable.measure),d({active:{id:e,data:o.data,node:s,rect:i.draggable.measure(s)},draggableNodes:n,dragOverlay:{node:a,rect:i.dragOverlay.measure(c)},droppableContainers:r,measuringConfiguration:i,transform:u})})}function wLe(e){let{duration:t,easing:n,sideEffects:r,keyframes:i}={...SLe,...e};return e=>{let{active:a,dragOverlay:o,transform:s,...c}=e;if(!t)return;let l={x:o.rect.left-a.rect.left,y:o.rect.top-a.rect.top},u={scaleX:s.scaleX===1?1:a.rect.width*s.scaleX/o.rect.width,scaleY:s.scaleY===1?1:a.rect.height*s.scaleY/o.rect.height},d={x:s.x-l.x,y:s.y-l.y,...u},f=i({...c,active:a,dragOverlay:o,transform:{initial:s,final:d}}),[p]=f,m=f[f.length-1];if(JSON.stringify(p)===JSON.stringify(m))return;let h=r?.({active:a,dragOverlay:o,...c}),g=o.node.animate(f,{duration:t,easing:n,fill:`forwards`});return new Promise(e=>{g.onfinish=()=>{h?.(),e()}})}}var L8=0;function TLe(e){return(0,y.useMemo)(()=>{if(e!=null)return L8++,L8},[e])}var ELe=y.memo(e=>{let{adjustScale:t=!1,children:n,dropAnimation:r,style:i,transition:a,modifiers:o,wrapperElement:s=`div`,className:c,zIndex:l=999}=e,{activatorEvent:u,active:d,activeNodeRect:f,containerNodeRect:p,draggableNodes:m,droppableContainers:h,dragOverlay:g,over:_,measuringConfiguration:v,scrollableAncestors:b,scrollableAncestorRects:x,windowRect:S}=I8(),C=(0,y.useContext)(M8),w=TLe(d?.id),T=j8(o,{activatorEvent:u,active:d,activeNodeRect:f,containerNodeRect:p,draggingNodeRect:g.rect,over:_,overlayNodeRect:g.rect,scrollableAncestors:b,scrollableAncestorRects:x,transform:C,windowRect:S}),E=v8(f),D=CLe({config:r,draggableNodes:m,droppableContainers:h,measuringConfiguration:v}),O=E?g.setRef:void 0;return y.createElement(vLe,null,y.createElement(gLe,{animation:D},d&&w?y.createElement(xLe,{key:w,id:d.id,ref:O,as:s,activatorEvent:u,adjustScale:t,className:c,transition:a,rect:E,style:{zIndex:l,...i},transform:T},n):null))});function R8(e,t,n){let r=e.slice();return r.splice(n<0?r.length+n:n,0,r.splice(t,1)[0]),r}function DLe(e,t){return e.reduce((e,n,r)=>{let i=t.get(n);return i&&(e[r]=i),e},Array(e.length))}function z8(e){return e!==null&&e>=0}function OLe(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n{let{rects:t,activeIndex:n,overIndex:r,index:i}=e,a=R8(t,r,n),o=t[i],s=a[i];return!s||!o?null:{x:s.left-o.left,y:s.top-o.top,scaleX:s.width/o.width,scaleY:s.height/o.height}},V8={scaleX:1,scaleY:1},ALe=e=>{let{activeIndex:t,activeNodeRect:n,index:r,rects:i,overIndex:a}=e,o=i[t]??n;if(!o)return null;if(r===t){let e=i[a];return e?{x:0,y:tt&&r<=a?{x:0,y:-o.height-s,...V8}:r=a?{x:0,y:o.height+s,...V8}:{x:0,y:0,...V8}};function jLe(e,t,n){let r=e[t],i=e[t-1],a=e[t+1];return r?nr.map(e=>typeof e==`object`&&`id`in e?e.id:e),[r]),m=o!=null,h=o?p.indexOf(o.id):-1,g=l?p.indexOf(l.id):-1,_=(0,y.useRef)(p),v=!OLe(p,_.current),b=g!==-1&&h===-1||v,x=kLe(a);d6(()=>{v&&m&&u(p)},[v,p,m,u]),(0,y.useEffect)(()=>{_.current=p},[p]);let S=(0,y.useMemo)(()=>({activeIndex:h,containerId:d,disabled:x,disableTransforms:b,items:p,overIndex:g,useDragOverlay:f,sortedRects:DLe(p,c),strategy:i}),[h,d,x.draggable,x.droppable,b,p,g,c,f,i]);return y.createElement(U8.Provider,{value:S},t)}var MLe=e=>{let{id:t,items:n,activeIndex:r,overIndex:i}=e;return R8(n,r,i).indexOf(t)},NLe=e=>{let{containerId:t,isSorting:n,wasDragging:r,index:i,items:a,newIndex:o,previousItems:s,previousContainerId:c,transition:l}=e;return!l||!r||s!==a&&i===o?!1:n?!0:o!==i&&t===c},PLe={duration:200,easing:`ease`},G8=`transform`,FLe=w6.Transition.toString({property:G8,duration:0,easing:`linear`}),ILe={roleDescription:`sortable`};function LLe(e){let{disabled:t,index:n,node:r,rect:i}=e,[a,o]=(0,y.useState)(null),s=(0,y.useRef)(n);return d6(()=>{if(!t&&n!==s.current&&r.current){let e=i.current;if(e){let t=B6(r.current,{ignoreTransform:!0}),n={x:e.left-t.left,y:e.top-t.top,scaleX:e.width/t.width,scaleY:e.height/t.height};(n.x||n.y)&&o(n)}}n!==s.current&&(s.current=n)},[t,n,r,i]),(0,y.useEffect)(()=>{a&&o(null)},[a]),a}function K8(e){let{animateLayoutChanges:t=NLe,attributes:n,disabled:r,data:i,getNewIndex:a=MLe,id:o,strategy:s,resizeObserverConfig:c,transition:l=PLe}=e,{items:u,containerId:d,activeIndex:f,disabled:p,disableTransforms:m,sortedRects:h,overIndex:g,useDragOverlay:_,strategy:v}=(0,y.useContext)(U8),b=RLe(r,p),x=u.indexOf(o),S=(0,y.useMemo)(()=>({sortable:{containerId:d,index:x,items:u},...i}),[d,i,x,u]),C=(0,y.useMemo)(()=>u.slice(u.indexOf(o)),[u,o]),{rect:w,node:T,isOver:E,setNodeRef:D}=hLe({id:o,data:S,disabled:b.droppable,resizeObserverConfig:{updateMeasurementsFor:C,...c}}),{active:O,activatorEvent:k,activeNodeRect:A,attributes:j,setNodeRef:M,listeners:N,isDragging:P,over:F,setActivatorNodeRef:I,transform:L}=fLe({id:o,data:S,attributes:{...ILe,...n},disabled:b.draggable}),R=eIe(D,M),z=!!O,B=z&&!m&&z8(f)&&z8(g),V=!_&&P,ee=B?(V&&B?L:null)??(s??v)({rects:h,activeNodeRect:A,activeIndex:f,overIndex:g,index:x}):null,H=z8(f)&&z8(g)?a({id:o,items:u,activeIndex:f,overIndex:g}):x,te=O?.id,ne=(0,y.useRef)({activeId:te,items:u,newIndex:H,containerId:d}),re=u!==ne.current.items,U=t({active:O,containerId:d,isDragging:P,isSorting:z,id:o,index:x,items:u,newIndex:ne.current.newIndex,previousItems:ne.current.items,previousContainerId:ne.current.containerId,transition:l,wasDragging:ne.current.activeId!=null}),ie=LLe({disabled:!U,index:x,node:T,rect:w});return(0,y.useEffect)(()=>{z&&ne.current.newIndex!==H&&(ne.current.newIndex=H),d!==ne.current.containerId&&(ne.current.containerId=d),u!==ne.current.items&&(ne.current.items=u)},[z,H,d,u]),(0,y.useEffect)(()=>{if(te===ne.current.activeId)return;if(te!=null&&ne.current.activeId==null){ne.current.activeId=te;return}let e=setTimeout(()=>{ne.current.activeId=te},50);return()=>clearTimeout(e)},[te]),{active:O,activeIndex:f,attributes:j,data:S,rect:w,index:x,newIndex:H,items:u,isOver:E,isSorting:z,isDragging:P,listeners:N,node:T,overIndex:g,over:F,setNodeRef:R,setActivatorNodeRef:I,setDroppableNodeRef:D,setDraggableNodeRef:M,transform:ie??ee,transition:ae()};function ae(){if(ie||re&&ne.current.newIndex===x)return FLe;if(!(V&&!S6(k)||!l)&&(z||U))return w6.Transition.toString({...l,property:G8})}}function RLe(e,t){return typeof e==`boolean`?{draggable:e,droppable:!1}:{draggable:e?.draggable??t.draggable,droppable:e?.droppable??t.droppable}}function q8(e){if(!e)return!1;let t=e.data.current;return!!(t&&`sortable`in t&&typeof t.sortable==`object`&&`containerId`in t.sortable&&`items`in t.sortable&&`index`in t.sortable)}var zLe=[i8.Down,i8.Right,i8.Up,i8.Left],J8=(e,t)=>{let{context:{active:n,collisionRect:r,droppableRects:i,droppableContainers:a,over:o,scrollableAncestors:s}}=t;if(zLe.includes(e.code)){if(e.preventDefault(),!n||!r)return;let t=[];a.getEnabled().forEach(n=>{if(!n||n!=null&&n.disabled)return;let a=i.get(n.id);if(a)switch(e.code){case i8.Down:r.topa.top&&t.push(n);break;case i8.Left:r.left>a.left&&t.push(n);break;case i8.Right:r.left1&&(l=c[1].id),l!=null){let e=a.get(n.id),t=a.get(l),o=t?i.get(t.id):null,c=t?.node.current;if(c&&o&&e&&t){let n=H6(c).some((e,t)=>s[t]!==e),i=Y8(e,t),a=BLe(e,t),l=n||!i?{x:0,y:0}:{x:a?r.width-o.width:0,y:a?r.height-o.height:0},u={x:o.left,y:o.top};return l.x&&l.y?u:x6(u,l)}}}};function Y8(e,t){return!q8(e)||!q8(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function BLe(e,t){return!q8(e)||!q8(t)||!Y8(e,t)?!1:e.data.current.sortable.index=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function HLe({activeCount:e,pendingCount:t,totalTime:n,totalWeight:r,historyCount:i,t:a}){return(0,K.jsx)(`div`,{className:`flex items-center gap-3 sm:gap-5 flex-wrap px-4 py-3 bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary mb-6`,children:[{icon:hl,value:e,label:a(`queue.summary.printing`),color:`text-blue-400`},{icon:_s,value:t,label:a(`queue.summary.queued`),color:`text-yellow-400`},{icon:mu,value:yf(n),label:a(`queue.summary.totalTime`),color:`text-bambu-green`},{icon:ku,value:VLe(r),label:a(`queue.summary.totalWeight`),color:`text-purple-400`},{icon:ls,value:i,label:a(`queue.summary.history`),color:`text-bambu-gray`}].map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[t>0&&(0,K.jsx)(`span`,{className:`hidden sm:block text-bambu-dark-tertiary`,children:`|`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(e.icon,{className:`w-4 h-4 ${e.color}`}),(0,K.jsx)(`span`,{className:`text-sm font-semibold text-white`,children:e.value}),(0,K.jsx)(`span`,{className:`text-xs sm:text-sm text-bambu-gray`,children:e.label})]})]},t))})}var X8={completed:{icon:ls,color:`text-emerald-400`,border:`border-l-emerald-500`},failed:{icon:ms,color:`text-red-400`,border:`border-l-red-500`},skipped:{icon:Kl,color:`text-orange-400`,border:`border-l-gray-500`},cancelled:{icon:No,color:`text-gray-400`,border:`border-l-gray-500`}};function ULe(e){if(!e)return null;let t=e.startsWith(`#`)?e.slice(1):e;return/^0{6,8}$/.test(t)||!/^[0-9a-fA-F]{6,8}$/.test(t)?null:`#${t.slice(0,6)}`}function Z8({item:e,onRequeue:t,onRemove:n,timeFormat:r=`system`,hasPermission:i,canModify:a,t:o}){let s=X8[e.status]||X8.cancelled,c=s.icon,l=e.archive_name||e.library_file_name||`File #${e.archive_id||e.library_file_id}`,u=e.archive_thumbnail?Q.getArchiveThumbnail(e.archive_id):e.library_file_thumbnail?Q.getLibraryFileThumbnailUrl(e.library_file_id):null,d=e.completed_at||e.created_at,f=ULe(e.filament_color),p=e.filament_used_grams?Math.round(e.filament_used_grams):null,m=!!e.error_message&&(e.status===`failed`||e.status===`skipped`);return(0,K.jsxs)(`div`,{className:`px-3 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary border-l-[3px] ${s.border}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[(0,K.jsx)(c,{className:`w-4 h-4 shrink-0 ${s.color}`}),(0,K.jsxs)(`div`,{className:`relative shrink-0 history-thumb-hover`,children:[(0,K.jsx)(`div`,{className:`w-8 h-8 bg-bambu-dark rounded overflow-hidden`,children:u?(0,K.jsx)(`img`,{src:u,alt:``,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,K.jsx)(Nc,{className:`w-4 h-4`})})}),u&&(0,K.jsx)(`div`,{className:`history-thumb-preview absolute z-[60] left-full top-0 ml-2 w-48 h-48 pointer-events-none opacity-0 transition-opacity`,children:(0,K.jsx)(`img`,{src:u,alt:``,className:`w-full h-full object-cover rounded-lg shadow-2xl border-2 border-bambu-dark-tertiary bg-bambu-dark`})})]}),(0,K.jsx)(`span`,{className:`text-sm text-white font-medium truncate min-w-0 flex-1`,children:l}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,title:d??void 0,children:bf(d,r,o)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:t,disabled:!i(`queue:create`),title:i(`queue:create`)?o(`queue.actions.requeue`):o(`queue.permissions.noRequeue`),className:`text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5`,children:(0,K.jsx)(Cl,{className:`w-3.5 h-3.5`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:n,disabled:!a(`queue`,`delete`,e.created_by_id),title:a(`queue`,`delete`,e.created_by_id)?o(`common.remove`):o(`queue.permissions.noRemove`),className:`p-1.5`,children:(0,K.jsx)(hu,{className:`w-3.5 h-3.5`})})]})]}),(0,K.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-bambu-gray`,children:[e.printer_name&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,K.jsx)(bl,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{className:`truncate max-w-[100px] sm:max-w-[140px]`,children:e.printer_name})]}),(f||p)&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[f?(0,K.jsx)(`span`,{className:`inline-block w-2.5 h-2.5 rounded-full border border-white/15`,style:{backgroundColor:f},"aria-hidden":!0}):(0,K.jsx)(ku,{className:`w-3 h-3`}),(0,K.jsxs)(`span`,{className:`truncate`,children:[p?`${p}g`:null,p&&e.filament_type?` ${e.filament_type}`:null,!p&&e.filament_type?e.filament_type:null]})]}),e.print_time_seconds&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,K.jsx)(mu,{className:`w-3 h-3`}),yf(e.print_time_seconds)]}),e.created_by_username&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,title:o(`queue.addedBy`,{name:e.created_by_username}),children:[(0,K.jsx)(Cu,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{className:`truncate max-w-[120px]`,children:e.created_by_username})]})]}),m&&(0,K.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex items-start gap-1 text-xs text-red-400`,children:[(0,K.jsx)(ss,{className:`w-3 h-3 mt-0.5 shrink-0`}),(0,K.jsx)(`span`,{className:`break-words`,children:e.error_message})]})]})}var Q8=3600*1e3,$8=24,e5=$8*Q8,WLe=32,GLe=40;function KLe(e){return e.toLocaleTimeString(void 0,{hour:`numeric`})}function t5(e){return e.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}function qLe({queueItems:e,printers:t,printerStatuses:n,onItemClick:r,t:i}){let[a,o]=(0,y.useState)(()=>new Date);(0,y.useEffect)(()=>{let e=setInterval(()=>o(new Date),6e4);return()=>clearInterval(e)},[]);let[s,c]=(0,y.useState)(0),l=(0,y.useMemo)(()=>{let e=a.getTime()+s;return Math.floor(e/Q8)*Q8},[a,s]),u=l+e5,d=a.getTime(),f=(0,y.useMemo)(()=>{let t=[],r=new Map,i=new Set,a=new Map,o=e=>e.printer_id==null?e.target_model?`model:${e.target_model}`:`unassigned`:`printer:${e.printer_id}`;for(let s of e)if(s.status===`printing`){let e=s.printer_id==null?void 0:n[s.printer_id],r=mf(s.started_at)||new Date,c;if(e?.remaining_time!=null&&e.remaining_time>0)c=new Date(d+e.remaining_time*60*1e3);else if(s.print_time_seconds){let t=e?.progress||0,n=Math.max(0,1-t/100);c=new Date(d+s.print_time_seconds*n*1e3)}else c=new Date(d+Q8);t.push({item:s,estimatedStart:r,estimatedEnd:c,progress:e?.progress??void 0,type:`printing`});let l=o(s);i.add(l),a.set(l,Math.max(a.get(l)??d,c.getTime()))}else if(s.status===`pending`){if(s.manual_start||s.waiting_reason)continue;let e=o(s);r.has(e)||r.set(e,[]),r.get(e).push(s)}let s=Date.now()+4320*Q8;for(let[e,n]of r){n.sort((e,t)=>e.position-t.position);let r=i.has(e),o=n[0]?mf(n[0].scheduled_time):null,c=o&&o.getTime()<=s;if(!r&&!c)continue;let l=a.get(e)??d;for(let e of n){let n=mf(e.scheduled_time);n&&n.getTime()<=s&&(l=Math.max(l,n.getTime()));let r=(e.print_time_seconds||3600)*1e3;t.push({item:e,estimatedStart:new Date(l),estimatedEnd:new Date(l+r),type:`queued`}),l+=r}}return t},[e,n,d]),p=(0,y.useMemo)(()=>{let e=[];for(let n of t)e.push({key:`printer:${n.id}`,label:n.name,printerId:n.id,targetModel:null});let n=new Set,r=!1;for(let t of f)if(t.item.printer_id==null)if(t.item.target_model){let r=`model:${t.item.target_model}`;n.has(r)||(n.add(r),e.push({key:r,label:`${i(`queue.filter.any`)} ${t.item.target_model}`,printerId:null,targetModel:t.item.target_model}))}else r=!0;return r&&e.push({key:`unassigned`,label:i(`queue.filter.unassigned`),printerId:null,targetModel:null}),e},[t,f,i]),m=(0,y.useMemo)(()=>{let e=new Map;for(let t of f){let n;n=t.item.printer_id==null?t.item.target_model?`model:${t.item.target_model}`:`unassigned`:`printer:${t.item.printer_id}`,e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[f]),h=(0,y.useMemo)(()=>{let e=[];for(let t=0;t<=$8;t+=2){let n=l+t*Q8;e.push({ms:n,pct:t/$8*100,label:KLe(new Date(n))})}return e},[l]),g=(d-l)/e5*100,_=g>=0&&g<=100,v=(0,y.useMemo)(()=>{let e=0;for(let t of f)e=Math.max(e,t.estimatedEnd.getTime());return e>0?new Date(e):null},[f]),b=(0,y.useRef)(null);return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>c(e=>e-12*Q8),className:`p-1.5`,title:i(`queue.timeline.window.back12h`),children:(0,K.jsx)(ns,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-sm font-medium text-white min-w-[180px] text-center`,children:[new Date(l).toLocaleString(void 0,{weekday:`short`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}),` → `,new Date(u).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>c(e=>e+12*Q8),className:`p-1.5`,title:i(`queue.timeline.window.forward12h`),children:(0,K.jsx)(ts,{className:`w-4 h-4`})}),s!==0&&(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>c(0),className:`text-xs text-bambu-green`,children:i(`queue.timeline.window.now`)})]}),v&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1.5`,children:[(0,K.jsx)(_s,{className:`w-3.5 h-3.5`}),i(`queue.timeline.allDoneBy`,{time:v.toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})})]})]}),p.length>0&&f.length===0&&(0,K.jsx)(`div`,{className:`mb-4 p-3 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark/40 text-xs text-bambu-gray`,children:i(`queue.timeline.nothingCommitted`)}),p.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,K.jsx)(Nc,{className:`w-12 h-12 mb-3 opacity-30`}),(0,K.jsx)(`p`,{className:`text-sm`,children:i(`queue.timeline.noData`)})]}):(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-2 text-xs font-medium text-bambu-gray border-r border-bambu-dark-tertiary`,children:i(`queue.timeline.printerColumnHeader`)}),(0,K.jsx)(`div`,{className:`relative flex-1 h-9`,children:h.map(e=>(0,K.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/40 text-[10px] sm:text-xs text-bambu-gray pl-1 flex items-center`,style:{left:`${e.pct}%`},children:e.label},e.ms))})]}),(0,K.jsxs)(`div`,{ref:b,className:`relative`,children:[p.map(e=>{let t=m.get(e.key)??[];return(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary/40 last:border-b-0`,children:[(0,K.jsxs)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-3 border-r border-bambu-dark-tertiary flex items-center gap-2`,children:[(0,K.jsx)(bl,{className:`w-3.5 h-3.5 shrink-0 ${e.printerId==null&&e.targetModel==null?`text-orange-400`:e.targetModel?`text-blue-400`:`text-bambu-green`}`}),(0,K.jsx)(`span`,{className:`text-sm text-white truncate`,children:e.label})]}),(0,K.jsxs)(`div`,{className:`relative flex-1`,style:{height:56},children:[h.map(e=>(0,K.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/30`,style:{left:`${e.pct}%`}},e.ms)),(0,K.jsx)(`div`,{className:`absolute inset-0 opacity-30`,style:{backgroundImage:`repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(255,255,255,0.04) 6px, rgba(255,255,255,0.04) 12px)`},"aria-hidden":!0}),t.map(e=>{let t=Math.max(l,e.estimatedStart.getTime()),n=Math.min(u,e.estimatedEnd.getTime());if(n<=l||t>=u)return null;let i=(t-l)/e5*100,a=(n-t)/e5*100,o=e.item.archive_name||e.item.library_file_name||`#${e.item.id}`,s=e.item.archive_thumbnail?Q.getArchiveThumbnail(e.item.archive_id):e.item.library_file_thumbnail?Q.getLibraryFileThumbnailUrl(e.item.library_file_id):null,c=e.type===`printing`,d=e.item.batch_id!=null;return(0,K.jsxs)(`button`,{onClick:()=>r(e.item),title:[o,`${t5(e.estimatedStart)} → ${t5(e.estimatedEnd)}`,e.item.print_time_seconds?yf(e.item.print_time_seconds):null,c&&e.progress!=null?`${Math.round(e.progress)}%`:null,e.item.batch_name?`batch: ${e.item.batch_name}`:null].filter(Boolean).join(` · `),className:`absolute rounded-md transition-all hover:brightness-110 hover:z-10 overflow-hidden flex items-center gap-1.5 px-1.5 text-left ${c?`bg-blue-500/30 border border-blue-400/60`:d?`bg-cyan-500/20 border border-cyan-400/50`:`bg-bambu-green/20 border border-bambu-green/40`}`,style:{left:`${i}%`,width:`max(${WLe}px, ${a}%)`,top:8,height:GLe},children:[s&&(0,K.jsx)(`img`,{src:s,alt:``,className:`w-7 h-7 rounded object-cover shrink-0 bg-bambu-dark`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`div`,{className:`text-xs text-white font-medium truncate leading-tight`,children:o}),(0,K.jsxs)(`div`,{className:`text-[10px] text-bambu-gray truncate leading-tight`,children:[e.item.print_time_seconds?yf(e.item.print_time_seconds):``,c&&e.progress!=null?` · ${Math.round(e.progress)}%`:``]})]}),c&&e.progress!=null&&(0,K.jsx)(`div`,{className:`absolute bottom-0 left-0 h-0.5 bg-blue-300`,style:{width:`${e.progress}%`},"aria-hidden":!0})]},e.item.id)})]})]},e.key)}),_&&(0,K.jsxs)(`div`,{className:`absolute top-0 bottom-0 pointer-events-none z-20 flex inset-x-0`,children:[(0,K.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0`}),(0,K.jsx)(`div`,{className:`relative flex-1`,children:(0,K.jsx)(`div`,{className:`absolute top-0 bottom-0 w-0.5 bg-red-400 shadow-[0_0_8px_rgba(248,113,113,0.6)]`,style:{left:`${g}%`},children:(0,K.jsx)(`div`,{className:`absolute -top-1 -left-1 w-2.5 h-2.5 bg-red-400 rounded-full`})})})]})]})]})]})}function n5(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function JLe({status:e,waitingReason:t,printerState:n,t:r}){if(e===`pending`&&t)return(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-purple-400 bg-purple-400/10 border-purple-400/20`,children:[(0,K.jsx)(_s,{className:`w-3.5 h-3.5`}),r(`queue.status.waiting`)]});if(e===`printing`&&n===`PAUSE`)return(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-yellow-400 bg-yellow-400/10 border-yellow-400/20`,children:[(0,K.jsx)(ul,{className:`w-3.5 h-3.5`}),r(`queue.status.paused`)]});let{icon:i,color:a,label:o}={pending:{icon:_s,color:`text-status-warning bg-status-warning/10 border-status-warning/20`,label:r(`queue.status.pending`)},printing:{icon:hl,color:`text-blue-400 bg-blue-400/10 border-blue-400/20`,label:r(`queue.status.printing`)},completed:{icon:ls,color:`text-status-ok bg-status-ok/10 border-status-ok/20`,label:r(`queue.status.completed`)},failed:{icon:ms,color:`text-status-error bg-status-error/10 border-status-error/20`,label:r(`queue.status.failed`)},skipped:{icon:Kl,color:`text-orange-400 bg-orange-400/10 border-orange-400/20`,label:r(`queue.status.skipped`)},cancelled:{icon:Pu,color:`text-gray-400 bg-gray-400/10 border-gray-400/20`,label:r(`queue.status.cancelled`)}}[e];return(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border ${a}`,children:[(0,K.jsx)(i,{className:`w-3.5 h-3.5`}),o]})}function YLe({selectedCount:e,printers:t,onSave:n,onClose:r,isSaving:i,canControlPrinter:a,t:o}){let[s,c]=(0,y.useState)(`unchanged`),[l,u]=(0,y.useState)(`unchanged`),[d,f]=(0,y.useState)(`unchanged`),[p,m]=(0,y.useState)(`unchanged`),[h,g]=(0,y.useState)(`unchanged`),[_,v]=(0,y.useState)(`unchanged`),[b,x]=(0,y.useState)(`unchanged`),[S,C]=(0,y.useState)(`unchanged`),[w,T]=(0,y.useState)(`unchanged`),[E,D]=(0,y.useState)(`unchanged`),[O,k]=(0,y.useState)(`unchanged`),A=t.some(e=>e.nozzle_count===2),j=()=>{let e={};s!==`unchanged`&&(e.printer_id=s),l!==`unchanged`&&(e.manual_start=l),d!==`unchanged`&&(e.auto_off_after=d),p!==`unchanged`&&(e.require_previous_success=p),h!==`unchanged`&&(e.bed_levelling=h),_!==`unchanged`&&(e.flow_cali=_),b!==`unchanged`&&(e.vibration_cali=b),S!==`unchanged`&&(e.layer_inspect=S),w!==`unchanged`&&(e.timelapse=w),E!==`unchanged`&&(e.use_ams=E),O!==`unchanged`&&(e.nozzle_offset_cali=O),n(e)},M=s!==`unchanged`||l!==`unchanged`||d!==`unchanged`||p!==`unchanged`||h!==`unchanged`||_!==`unchanged`||b!==`unchanged`||S!==`unchanged`||w!==`unchanged`||E!==`unchanged`||O!==`unchanged`;return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,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-lg font-semibold text-white`,children:o(`queue.bulkEdit.title`,{count:e})}),(0,K.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,K.jsx)(Pu,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:o(`queue.bulkEdit.description`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:o(`queue.bulkEdit.printer`)}),(0,K.jsxs)(`select`,{value:s===null?`null`:s===`unchanged`?`unchanged`:String(s),onChange:e=>{let t=e.target.value;c(t===`unchanged`?`unchanged`:t===`null`?null:Number(t))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`unchanged`,children:o(`queue.bulkEdit.noChange`)}),(0,K.jsx)(`option`,{value:`null`,children:o(`queue.filter.unassigned`)}),t.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:o(`queue.bulkEdit.queueOptions`)}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(r5,{label:o(`queue.bulkEdit.staged`),value:l,onChange:u,t:o}),(0,K.jsx)(r5,{label:o(`queue.bulkEdit.autoPowerOff`),value:d,onChange:f,disabled:!a,t:o}),(0,K.jsx)(r5,{label:o(`queue.bulkEdit.requirePrevious`),value:p,onChange:m,t:o})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:o(`queue.bulkEdit.printOptions`)}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(r5,{label:o(`queue.bulkEdit.bedLevelling`),value:h,onChange:g,t:o}),(0,K.jsx)(r5,{label:o(`queue.bulkEdit.flowCalibration`),value:_,onChange:v,t:o}),(0,K.jsx)(r5,{label:o(`queue.bulkEdit.vibrationCalibration`),value:b,onChange:x,t:o}),(0,K.jsx)(r5,{label:o(`queue.bulkEdit.layerInspection`),value:S,onChange:C,t:o}),(0,K.jsx)(r5,{label:o(`queue.bulkEdit.timelapse`),value:w,onChange:T,t:o}),(0,K.jsx)(r5,{label:o(`queue.bulkEdit.useAms`),value:E,onChange:D,t:o}),A&&(0,K.jsx)(r5,{label:o(`queue.bulkEdit.nozzleOffsetCali`),value:O,onChange:k,t:o})]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:r,children:o(`common.cancel`)}),(0,K.jsx)($,{onClick:j,disabled:!M||i,children:o(i?`common.saving`:`queue.bulkEdit.applyChanges`)})]})]})})}function r5({label:e,value:t,onChange:n,disabled:r,t:i}){return(0,K.jsxs)(`div`,{className:`flex items-center justify-between py-1 ${r?`opacity-50`:``}`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded-lg p-0.5`,children:[(0,K.jsx)(`button`,{onClick:()=>n(`unchanged`),disabled:r,className:`px-2 py-1 text-xs rounded ${t===`unchanged`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:`—`}),(0,K.jsx)(`button`,{onClick:()=>n(!1),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!1?`bg-red-500/20 text-red-400`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.off`)}),(0,K.jsx)(`button`,{onClick:()=>n(!0),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!0?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.on`)})]})]})}function i5({item:e,position:t,onEdit:n,onCancel:r,onRemove:i,onStop:a,onRequeue:o,onStart:s,timeFormat:c=`system`,isSelected:l=!1,onToggleSelect:u,hasPermission:d,canModify:f,printerState:p,t:m}){let{data:h}=q({queryKey:[`printerStatus`,e.printer_id],queryFn:()=>Q.getPrinterStatus(e.printer_id),refetchInterval:3e4,enabled:e.printer_id!=null&&p===`printing`}),g=!!e.library_file_id&&!e.archive_id,{data:_}=q({queryKey:[`archive-plates`,e.archive_id],queryFn:()=>Q.getArchivePlates(e.archive_id),enabled:!!e.archive_id&&!g&&!e.archive_deleted}),{data:v}=q({queryKey:[`library-file-plates`,e.library_file_id],queryFn:()=>Q.getLibraryFilePlates(e.library_file_id),enabled:g&&!!e.library_file_id}),y=g?v:_,b=y?.plates??[],x=d(`queue:reorder`),{attributes:S,listeners:C,setNodeRef:w,transform:T,transition:E,isDragging:D}=K8({id:e.id,disabled:e.status!==`pending`||!x}),O={transform:w6.Transform.toString(T),transition:E},k=e.status===`printing`,A=e.status===`pending`,j=[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status),M=A&&u;return(0,K.jsxs)(`div`,{ref:w,style:O,className:` group relative bg-bambu-dark-secondary rounded-xl border transition-all duration-200 border-l-[3px] ${k?`border-l-blue-500`:A?`border-l-yellow-500`:e.status===`completed`?`border-l-emerald-500`:e.status===`failed`?`border-l-red-500`:`border-l-gray-500`} ${D?`opacity-50 scale-[1.02] shadow-xl z-50`:``} @@ -8698,15 +8698,15 @@ ${t.slice(l+2)}`,d+=1;else break}t.push({indent:l,number:parseInt(s,10),content: ${l&&M?`sm:border-bambu-dark-tertiary border-bambu-green/40`:``} ${!l&&!k?`border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80`:``} ${M?`sm:cursor-default`:``} - `,onClick:M?()=>{window.innerWidth<640&&u()}:void 0,children:[M&&l&&(0,K.jsx)(`div`,{className:`sm:hidden absolute left-0 top-3 bottom-3 w-1 rounded-full bg-bambu-green`}),(0,K.jsxs)(`div`,{className:`flex items-start sm:items-center gap-2 sm:gap-4 p-3 sm:p-4`,children:[A&&u&&(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),u()},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${l?`bg-bambu-green border-bambu-green text-white`:`border-white/30 bg-black/30 hover:border-bambu-green/50`}`,children:l&&(0,K.jsx)($o,{className:`w-4 h-4`})}),A?(0,K.jsx)(`div`,{...S,...C,className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-manipulation shrink-0`,children:(0,K.jsx)(gc,{className:`w-4 h-4 text-bambu-gray`})}):t===void 0?(0,K.jsx)(`div`,{className:`hidden sm:block w-8 shrink-0`}):(0,K.jsxs)(`div`,{className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark text-bambu-gray text-sm font-medium shrink-0`,children:[`#`,t]}),(0,K.jsx)(`div`,{className:`w-10 h-10 sm:w-14 sm:h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden`,children:e.archive_thumbnail?(0,K.jsx)(`img`,{src:e.plate_id==null?Q.getArchiveThumbnail(e.archive_id):Q.getArchivePlateThumbnail(e.archive_id,e.plate_id),alt:``,className:`w-full h-full object-cover`}):e.library_file_thumbnail?(0,K.jsx)(`img`,{src:e.plate_id==null?Q.getLibraryFileThumbnailUrl(e.library_file_id):Q.getLibraryFilePlateThumbnail(e.library_file_id,e.plate_id),alt:``,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,K.jsx)(Nc,{className:`w-5 h-5 sm:w-6 sm:h-6`})})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsxs)(`p`,{className:`text-sm sm:text-base text-white font-medium truncate`,children:[e.archive_name||e.library_file_name||`File #${e.archive_id||e.library_file_id}`,(y?.is_multi_plate??!1)&&e.plate_id!==void 0&&e.plate_id!==null&&` • ${b.find(t=>t.index===e.plate_id)?.name||m(`queue.plateNumber`,{index:e.plate_id})}`]}),e.archive_id?(0,K.jsx)(bi,{to:`/archives?highlight=${e.archive_id}`,className:`text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:m(`queue.viewArchive`),children:(0,K.jsx)(Us,{className:`w-3.5 h-3.5`})}):e.library_file_id?(0,K.jsx)(bi,{to:`/library?highlight=${e.library_file_id}`,className:`text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:m(`queue.viewInFileManager`),children:(0,K.jsx)(Us,{className:`w-3.5 h-3.5`})}):null,e.batch_name&&(0,K.jsx)(`span`,{className:`flex-shrink-0 px-1.5 py-0.5 text-[10px] sm:text-xs bg-cyan-500/20 text-cyan-300 rounded border border-cyan-500/30`,children:e.batch_name})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 ${e.printer_id===null&&!e.target_model?`text-orange-400`:``} ${e.target_model&&!e.printer_id?`text-blue-400`:``}`,children:[(0,K.jsx)(bl,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),(0,K.jsx)(`span`,{className:`truncate max-w-[120px] sm:max-w-none`,children:e.target_model&&!e.printer_id?`${m(`queue.filter.any`)} ${e.target_model}${e.target_location?` @ ${e.target_location}`:``}${e.required_filament_types?.length?` (${e.required_filament_types.join(`, `)})`:``}`:e.printer_id===null?m(`queue.filter.unassigned`):e.printer_name||`${m(`common.printer`)} #${e.printer_id}`})]}),e.print_time_seconds&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,K.jsx)(mu,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),yf(e.print_time_seconds)]}),e.filament_used_grams&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,K.jsx)(ku,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),n5(e.filament_used_grams)]}),(()=>{let t=$K(e.bed_type);return t?(0,K.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,title:t.label,children:[(0,K.jsx)(`img`,{src:t.icon,alt:``,className:`w-3.5 h-3.5 sm:w-4 sm:h-4 object-contain`}),(0,K.jsx)(`span`,{className:`truncate max-w-[120px]`,children:t.label})]}):null})(),e.created_by_username&&(0,K.jsxs)(`span`,{className:`hidden sm:flex items-center gap-1.5`,title:m(`queue.addedBy`,{name:e.created_by_username}),children:[(0,K.jsx)(Cu,{className:`w-3.5 h-3.5`}),e.created_by_username]}),A&&!e.manual_start&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(_s,{className:`w-3.5 h-3.5`}),e.scheduled_time?(mf(e.scheduled_time)?.getTime()??0)-Date.now()<-6e4?m?.(`queue.time.overdue`)??`Overdue`:bf(e.scheduled_time,c,m):m?.(`queue.time.asap`)??`ASAP`]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 sm:gap-2 mt-1.5 sm:mt-2`,children:[e.manual_start&&(0,K.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-purple-500/10 text-purple-400 rounded-full border border-purple-500/20 flex items-center gap-1`,children:[(0,K.jsx)(vc,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),m(`queue.badges.staged`)]}),e.require_previous_success&&(0,K.jsx)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-orange-500/10 text-orange-400 rounded-full border border-orange-500/20`,children:m(`queue.badges.requiresPrevious`)}),e.auto_off_after&&(0,K.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-blue-500/10 text-blue-400 rounded-full border border-blue-500/20 flex items-center gap-1`,children:[(0,K.jsx)(yl,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),m(`queue.badges.autoPowerOff`)]}),e.gcode_injection&&(0,K.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-emerald-500/10 text-emerald-400 rounded-full border border-emerald-500/20 flex items-center gap-1`,children:[(0,K.jsx)(xs,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),m(`queue.badges.gcodeInjection`)]})]}),k&&h&&(()=>{let e=h.state===`RUNNING`||h.state===`PAUSE`,t=e&&h.progress||0,n=e?h.remaining_time:null,r=e?h.layer_num:null,i=e?h.total_layers:null;return(0,K.jsxs)(`div`,{className:`mt-2 sm:mt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs sm:text-sm`,children:[(0,K.jsx)(`div`,{className:`flex-1 bg-bambu-dark-tertiary rounded-full h-1.5 sm:h-2 mr-3`,children:(0,K.jsx)(`div`,{className:`bg-bambu-green h-1.5 sm:h-2 rounded-full transition-all`,style:{width:`${t}%`}})}),(0,K.jsxs)(`span`,{className:`text-white`,children:[Math.round(t),`%`]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mt-1.5 sm:mt-2 text-[10px] sm:text-xs text-bambu-gray`,children:[n!=null&&n>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),yf(n*60)]}),(0,K.jsxs)(`span`,{className:`text-bambu-green font-medium`,title:m(`printers.estimatedCompletion`),children:[`ETA `,vf(n,c,m)]})]}),r!=null&&i!=null&&i>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(Nc,{className:`w-3 h-3`}),r,`/`,i]})]})]})})(),e.waiting_reason&&e.status===`pending`&&(0,K.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-purple-400 mt-1.5 sm:mt-2 flex items-start gap-1`,children:[(0,K.jsx)(ss,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`span`,{children:e.waiting_reason})]}),e.filament_short&&e.status===`pending`&&(0,K.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-yellow-400 mt-1.5 sm:mt-2 flex items-start gap-1`,title:m(`queue.filamentShort.rowTooltip`),children:[(0,K.jsx)(ss,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`span`,{children:m(`queue.filamentShort.rowBadge`)})]}),e.error_message&&(0,K.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-red-400 mt-1.5 sm:mt-2 flex items-center gap-1`,children:[(0,K.jsx)(ss,{className:`w-3 h-3`}),e.error_message]})]}),(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-end sm:items-center gap-2 sm:gap-1 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(qLe,{status:e.status,waitingReason:e.waiting_reason,printerState:p,t:m}),(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5 sm:gap-1`,children:[k&&(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:a,disabled:!d(`printers:control`),title:d(`printers:control`)?m(`queue.actions.stopPrint`):m(`queue.permissions.noStopPrint`),className:`text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,K.jsx)(ps,{className:`w-4 h-4`})}),A&&(0,K.jsxs)(K.Fragment,{children:[e.manual_start&&(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:s,disabled:!d(`printers:control`),title:d(`printers:control`)?m(`queue.actions.startPrint`):m(`queue.permissions.noStartPrint`),className:`text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10 p-1.5 sm:p-2`,children:(0,K.jsx)(hl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:n,disabled:!f(`queue`,`update`,e.created_by_id),title:f(`queue`,`update`,e.created_by_id)?m(`common.edit`):m(`queue.permissions.noEdit`),className:`p-1.5 sm:p-2`,children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:r,disabled:!f(`queue`,`delete`,e.created_by_id),title:f(`queue`,`delete`,e.created_by_id)?m(`common.cancel`):m(`queue.permissions.noCancel`),className:`text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}),j&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:o,disabled:!d(`queue:create`),title:d(`queue:create`)?m(`queue.actions.requeue`):m(`queue.permissions.noRequeue`),className:`text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5 sm:p-2`,children:(0,K.jsx)(Cl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:i,disabled:!f(`queue`,`delete`,e.created_by_id),title:f(`queue`,`delete`,e.created_by_id)?m(`common.remove`):m(`queue.permissions.noRemove`),className:`p-1.5 sm:p-2`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]})]})]})]})}function a5({row:e,collapsed:t,onToggleBatch:n,onUngroup:r,setEditItem:i,setConfirmAction:a,startMutation:o,selectedItems:s,handleToggleSelect:c,timeFormat:l,hasPermission:u,canModify:d,t:f,aggregateForRows:p}){if(e.kind===`item`)return(0,K.jsx)(i5,{item:e.item,onEdit:()=>i(e.item),onCancel:()=>a({type:`cancel`,item:e.item}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>o.mutate({id:e.item.id}),timeFormat:l,isSelected:s.includes(e.item.id),onToggleSelect:()=>c(e.item.id),hasPermission:u,canModify:d,t:f});let m=p([e]),h=e.items.map(e=>e.id),g=h.length>0&&h.every(e=>s.includes(e)),_=new Set(e.items.map(e=>e.status)),v=_.has(`failed`)?`failed`:_.has(`printing`)?`printing`:`pending`,y=e.items.filter(e=>e.status===`pending`).length;return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-l-[3px] border-l-cyan-400 border-bambu-dark-tertiary overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3 p-3 sm:p-4`,children:[(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),h.forEach(e=>{(g&&s.includes(e)||!g&&!s.includes(e))&&c(e)})},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${g?`bg-bambu-green border-bambu-green text-white`:`border-white/30 bg-black/30 hover:border-bambu-green/50`}`,title:f(g?`queue.bulkEdit.deselectAll`:`queue.bulkEdit.selectAll`),children:g&&(0,K.jsx)($o,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:n,className:`flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors shrink-0`,title:f(t?`queue.batch.expand`:`queue.batch.collapse`),children:t?(0,K.jsx)(ts,{className:`w-4 h-4 text-bambu-gray`}):(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray`})}),(0,K.jsx)(`div`,{className:`w-10 h-10 sm:w-12 sm:h-12 flex-shrink-0 bg-bambu-dark rounded-lg flex items-center justify-center`,children:t?(0,K.jsx)(cl,{className:`w-5 h-5 text-cyan-300`}):(0,K.jsx)(sl,{className:`w-5 h-5 text-cyan-300`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsx)(`p`,{className:`text-sm sm:text-base text-white font-medium truncate`,children:e.batchName}),(0,K.jsx)(`span`,{className:`flex-shrink-0 px-1.5 py-0.5 text-[10px] sm:text-xs bg-cyan-500/15 text-cyan-300 rounded border border-cyan-500/30`,children:f(`queue.batch.label`,{count:m.count})})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray`,children:[m.time>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,K.jsx)(mu,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),yf(m.time)]}),m.weight>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,K.jsx)(ku,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),n5(m.weight)]}),y>0&&v===`pending`&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 text-yellow-400`,children:[(0,K.jsx)(_s,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),f(`queue.batch.pendingCount`,{count:y})]})]})]}),(0,K.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:r&&(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:r,title:f(`queue.batch.ungroup`),className:`text-cyan-300 hover:text-cyan-200 hover:bg-cyan-500/10 p-1.5 sm:p-2`,children:(0,K.jsx)(bu,{className:`w-4 h-4`})})})]}),!t&&(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary bg-black/20 p-2 sm:p-3 space-y-2`,children:e.items.map(e=>(0,K.jsx)(i5,{item:e,onEdit:()=>i(e),onCancel:()=>a({type:`cancel`,item:e}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>o.mutate({id:e.id}),timeFormat:l,isSelected:s.includes(e.id),onToggleSelect:()=>c(e.id),hasPermission:u,canModify:d,t:f},e.id))})]})}function YLe({items:e,sortBy:t,sortAsc:n,onSortByChange:r,onSortAscToggle:i,onRemove:a,onRequeue:o,timeFormat:s,batchCollapsed:c,toggleBatchCollapsed:l,hasPermission:u,canModify:d,t:f}){if(e.length===0)return(0,K.jsxs)(pd,{className:`p-12 text-center border-dashed`,children:[(0,K.jsx)(Rc,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,K.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:f(`queue.history.emptyTitle`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:f(`queue.history.emptyDescription`)})]});let p=[],m=new Set;for(let t of e.slice(0,50))if(t.batch_id!=null){if(m.has(t.batch_id))continue;m.add(t.batch_id);let n=e.filter(e=>e.batch_id===t.batch_id);p.push({kind:`batch`,batchId:t.batch_id,batchName:t.batch_name||f(`queue.batch.defaultName`),items:n})}else p.push({kind:`item`,item:t});return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4`,children:[(0,K.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white flex items-center gap-2`,children:[f(`queue.sections.history`),(0,K.jsxs)(`span`,{className:`text-xs sm:text-sm font-normal text-bambu-gray`,children:[`(`,f(`queue.itemCount`,{count:e.length}),`)`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`select`,{className:`px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:t,onChange:e=>r(e.target.value),children:[(0,K.jsx)(`option`,{value:`date`,children:f(`queue.sort.byDate`)}),(0,K.jsx)(`option`,{value:`name`,children:f(`queue.sort.byName`)}),(0,K.jsx)(`option`,{value:`printer`,children:f(`queue.sort.byPrinter`)})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:i,title:f(n?`queue.sort.ascendingOldest`:`queue.sort.descendingNewest`),className:`px-2`,children:n?(0,K.jsx)(Mo,{className:`w-4 h-4`}):(0,K.jsx)(Eo,{className:`w-4 h-4`})})]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:p.map(e=>{if(e.kind===`item`)return(0,K.jsx)(Z8,{item:e.item,onRemove:()=>a(e.item),onRequeue:()=>o(e.item),timeFormat:s,hasPermission:u,canModify:d,t:f},e.item.id);let t=c[e.batchId]??!0,n=e.items.filter(e=>e.status===`completed`).length,r=e.items.filter(e=>e.status===`failed`).length,i=e.items.filter(e=>e.status===`skipped`).length,p=e.items.filter(e=>e.status===`cancelled`).length,m=e.items.map(e=>e.completed_at||e.created_at).filter(e=>!!e).sort().at(-1);return(0,K.jsxs)(`div`,{className:`md:col-span-2 xl:col-span-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary border-l-[3px] border-l-cyan-400`,children:[(0,K.jsxs)(`button`,{onClick:()=>l(e.batchId),className:`w-full flex items-center gap-2 sm:gap-3 px-3 py-2 hover:bg-bambu-dark/30 transition-colors text-left`,title:f(t?`queue.batch.expand`:`queue.batch.collapse`),children:[t?(0,K.jsx)(ts,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray shrink-0`}),t?(0,K.jsx)(cl,{className:`w-5 h-5 text-cyan-300 shrink-0`}):(0,K.jsx)(sl,{className:`w-5 h-5 text-cyan-300 shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm text-white font-medium truncate min-w-0 flex-1`,children:e.batchName}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray shrink-0`,children:[n>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-emerald-400`,children:[(0,K.jsx)(ls,{className:`w-3 h-3`}),n]}),r>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-red-400`,children:[(0,K.jsx)(ms,{className:`w-3 h-3`}),r]}),i>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-orange-400`,children:[(0,K.jsx)(Kl,{className:`w-3 h-3`}),i]}),p>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-400`,children:[(0,K.jsx)(No,{className:`w-3 h-3`}),p]}),(0,K.jsx)(`span`,{title:m??void 0,children:m?bf(m,s,f):null})]})]}),!t&&(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary bg-black/20 p-2 grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:e.items.map(e=>(0,K.jsx)(Z8,{item:e,onRemove:()=>a(e),onRequeue:()=>o(e),timeFormat:s,hasPermission:u,canModify:d,t:f},e.id))})]},`batch-${e.batchId}`)})})]})}function XLe(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),{hasPermission:r,hasAnyPermission:i,canModify:a}=sd(),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(null),[x,S]=(0,y.useState)([]),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(()=>localStorage.getItem(`queue.historySortBy`)||`date`),[D,O]=(0,y.useState)(()=>{let e=localStorage.getItem(`queue.historySortAsc`);return e===null?!1:e===`true`}),[k,A]=(0,y.useState)(()=>localStorage.getItem(`queue.pendingSortBy`)||`position`),[j,M]=(0,y.useState)(()=>{let e=localStorage.getItem(`queue.pendingSortAsc`);return e===null?!0:e===`true`}),[N,P]=(0,y.useState)(()=>{let e=localStorage.getItem(`queue.activeTab`);return e===`history`||e===`timeline`?e:`queue`}),[F,I]=(0,y.useState)(()=>localStorage.getItem(`queue.activeLayout`)===`printer`?`printer`:`position`),[L,R]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`queue.batchCollapsed`);return e?JSON.parse(e):{}}catch{return{}}}),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)(!1),[H,te]=(0,y.useState)(null);(0,y.useEffect)(()=>{localStorage.setItem(`queue.historySortBy`,T)},[T]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.historySortAsc`,String(D))},[D]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.pendingSortBy`,k)},[k]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.pendingSortAsc`,String(j))},[j]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.activeTab`,N)},[N]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.activeLayout`,F)},[F]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.batchCollapsed`,JSON.stringify(L))},[L]);let ne=A6(k6(u8,{activationConstraint:{distance:8}}),k6(o8,{coordinateGetter:J8})),{data:re}=q({queryKey:[`settings`],queryFn:Q.getSettings}),U=re?.time_format||`system`,{data:ie,isLoading:ae}=q({queryKey:[`queue`,o,c],queryFn:()=>Q.getQueue(o||void 0,c||void 0),refetchInterval:5e3}),{data:W}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters()}),oe=J({mutationFn:e=>Q.updateSettings({queue_shortest_first:e}),onSuccess:()=>{t.invalidateQueries({queryKey:[`settings`]})}}),se=J({mutationFn:e=>Q.cancelQueueItem(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.cancelled`))},onError:()=>n(e(`queue.toast.cancelFailed`),`error`)}),ce=J({mutationFn:e=>Q.removeFromQueue(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.removed`))},onError:()=>n(e(`queue.toast.removeFailed`),`error`)}),le=J({mutationFn:e=>Q.stopQueueItem(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.stopped`))},onError:()=>n(e(`queue.toast.stopFailed`),`error`)}),[ue,de]=(0,y.useState)(null),fe=J({mutationFn:({id:e,skipFilamentCheck:t})=>Q.startQueueItem(e,{skipFilamentCheck:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.released`)),de(null)},onError:(t,r)=>{if(t instanceof zu&&t.status===409&&t.code===`insufficient_filament`){let e=t.detail?.deficit??[];de({itemId:r.id,deficit:e});return}n(e(`queue.toast.startFailed`),`error`)}}),pe=J({mutationFn:e=>Q.reorderQueue(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]})},onError:()=>n(e(`queue.toast.reorderFailed`),`error`)}),me=J({mutationFn:async()=>{let e=ie?.filter(e=>[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status))||[];for(let t of e)await Q.removeFromQueue(t.id);return e.length},onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.historyCleared`,{count:r}))},onError:()=>n(e(`queue.toast.clearHistoryFailed`),`error`)}),he=J({mutationFn:e=>Q.bulkUpdateQueue(e),onSuccess:e=>{t.invalidateQueries({queryKey:[`queue`]}),S([]),w(!1),n(e.message)},onError:()=>n(e(`queue.toast.updateFailed`),`error`)}),ge=J({mutationFn:async e=>{for(let t of e)await Q.cancelQueueItem(t);return e.length},onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),S([]),n(e(`queue.toast.bulkCancelled`,{count:r}))},onError:()=>n(e(`queue.toast.bulkCancelFailed`),`error`)}),_e=J({mutationFn:e=>Q.createBatch(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),S([]),ee(!1),R(e=>({...e,[r.id]:!1})),n(e(`queue.toast.batchCreated`,{name:r.name}))},onError:()=>n(e(`queue.toast.batchCreateFailed`),`error`)}),ve=J({mutationFn:e=>Q.ungroupBatch(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),te(null),n(e(`queue.toast.batchUngrouped`,{count:r.ungrouped_count}))},onError:()=>n(e(`queue.toast.batchUngroupFailed`),`error`)}),ye=e=>{S(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},be=(0,y.useMemo)(()=>{let e=new Set;return W?.forEach(t=>{t.location&&e.add(t.location)}),ie?.forEach(t=>{t.target_location&&e.add(t.target_location)}),Array.from(e).sort()},[W,ie]),xe=(0,y.useCallback)(e=>u?e.target_location?e.target_location===u:e.printer_id?W?.find(t=>t.id===e.printer_id)?.location===u:!1:!0,[u,W]),Se=(0,y.useMemo)(()=>{let e=ie?.filter(e=>e.status===`pending`)||[];u&&(e=e.filter(xe));let t=e=>{if(!e.scheduled_time)return 0;let t=mf(e.scheduled_time)?.getTime()??0;return t>Date.now()+4320*60*60*1e3?0:t};return re?.queue_shortest_first?[...e].sort((e,t)=>{let n=e.printer_id??-(e.target_model?.charCodeAt(0)??0),r=t.printer_id??-(t.target_model?.charCodeAt(0)??0);if(n!==r)return n-r;let i=+!!e.been_jumped,a=+!!t.been_jumped;if(i!==a)return a-i;let o=e.print_time_seconds??1/0,s=t.print_time_seconds??1/0;return o===s?e.position-t.position:o-s}):[...e].sort((e,n)=>{let r;if(k===`name`){let t=e.archive_name||e.library_file_name||``,i=n.archive_name||n.library_file_name||``;r=t.localeCompare(i)}else r=k===`printer`?(e.printer_name||``).localeCompare(n.printer_name||``):k===`time`?t(e)-t(n):e.position-n.position;return j?r:-r})},[ie,k,j,xe,u,re?.queue_shortest_first]),Ce=()=>{let e=Se.map(e=>e.id);x.length===e.length?S([]):S(e)},we=(0,y.useMemo)(()=>{let e=ie?.filter(e=>e.status===`printing`)||[];return u&&(e=e.filter(xe)),e},[ie,u,xe]),Te=(0,y.useMemo)(()=>{let e=new Set;return we.forEach(t=>{t.printer_id&&e.add(t.printer_id)}),Array.from(e)},[we]),Ee=po({queries:Te.map(e=>({queryKey:[`printerStatus`,e],queryFn:()=>Q.getPrinterStatus(e),refetchInterval:5e3}))}),De=(0,y.useMemo)(()=>{let e={};return Te.forEach((t,n)=>{let r=Ee[n];r?.data?.state&&(e[t]=r.data.state)}),e},[Te,Ee]),Oe=(0,y.useMemo)(()=>{let e={};return Te.forEach((t,n)=>{let r=Ee[n];r?.data&&(e[t]={progress:r.data.progress??void 0,remaining_time:r.data.remaining_time??void 0,state:r.data.state??void 0})}),e},[Te,Ee]),ke=(0,y.useMemo)(()=>{let e=ie?.filter(e=>[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status))||[];return u&&(e=e.filter(xe)),[...e].sort((e,t)=>{let n;if(T===`name`){let r=e.archive_name||e.library_file_name||``,i=t.archive_name||t.library_file_name||``;n=r.localeCompare(i)}else n=T===`printer`?(e.printer_name||``).localeCompare(t.printer_name||``):(mf(t.completed_at||t.created_at)?.getTime()??0)-(mf(e.completed_at||e.created_at)?.getTime()??0);return D?-n:n})},[ie,T,D,xe,u]),Ae=(0,y.useMemo)(()=>Se.reduce((e,t)=>e+(t.print_time_seconds||0),0),[Se]),je=(0,y.useMemo)(()=>Se.reduce((e,t)=>e+(t.filament_used_grams||0),0),[Se]),Me=e=>{B(typeof e.active.id==`number`?e.active.id:null)},Ne=e=>{let{active:t,over:n}=e;if(B(null),!n||t.id===n.id)return;let r=t.id,i=x.includes(r)&&x.length>1?x.slice().sort((e,t)=>Se.findIndex(t=>t.id===e)-Se.findIndex(e=>e.id===t)):[r],a=Se.findIndex(e=>e.id===n.id);if(a===-1)return;let o=Se.filter(e=>!i.includes(e.id)),s=o.findIndex(e=>e.id===n.id);s===-1&&(s=a),Se.findIndex(e=>e.id===r)Se.find(t=>t.id===e)).filter(e=>!!e),...o.slice(s)].map((e,t)=>({id:e.id,position:t+1}));pe.mutate(c)},Pe=(0,y.useMemo)(()=>{let t=[],n=new Set;for(let r of Se)if(r.batch_id!=null){if(n.has(r.batch_id))continue;n.add(r.batch_id);let i=Se.filter(e=>e.batch_id===r.batch_id);t.push({kind:`batch`,batchId:r.batch_id,batchName:r.batch_name||e(`queue.batch.defaultName`),items:i})}else t.push({kind:`item`,item:r});return t},[Se,e]),Fe=(0,y.useMemo)(()=>{let e=[];for(let t of Pe)if(t.kind===`item`)e.push(t.item.id);else if(!(L[t.batchId]??!0))for(let n of t.items)e.push(n.id);return e},[Pe,L]),Ie=(0,y.useMemo)(()=>x.length<2?!1:x.every(e=>{let t=Se.find(t=>t.id===e);return t&&t.batch_id==null}),[x,Se]),Le=e=>{R(t=>({...t,[e]:!(t[e]??!0)}))},Re=(0,y.useMemo)(()=>{let t=new Map,n=t=>t.printer_id?{key:`printer:${t.printer_id}`,label:t.printer_name||`Printer #${t.printer_id}`,printerId:t.printer_id,targetModel:null,isUnassigned:!1}:t.target_model?{key:`model:${t.target_model}`,label:`${e(`queue.filter.any`)} ${t.target_model}`,printerId:null,targetModel:t.target_model,isUnassigned:!1}:{key:`unassigned`,label:e(`queue.filter.unassigned`),printerId:null,targetModel:null,isUnassigned:!0};for(let e of Pe){let r=e.kind===`item`?e.item:e.items[0];if(!r)continue;let i=n(r);t.has(i.key)||t.set(i.key,{...i,rows:[]}),t.get(i.key).rows.push(e)}return Array.from(t.values()).sort((e,t)=>e.isUnassigned&&!t.isUnassigned?1:!e.isUnassigned&&t.isUnassigned?-1:e.label.localeCompare(t.label))},[Pe,e]),ze=e=>{let t=0,n=0,r=0;for(let i of e){let e=i.kind===`item`?[i.item]:i.items;for(let i of e)t+=1,n+=i.print_time_seconds||0,r+=i.filament_used_grams||0}return{count:t,time:n,weight:r}};return(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between 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)(Rc,{className:`w-7 h-7 text-bambu-green`}),e(`queue.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`queue.subtitle`)})]})}),(0,K.jsx)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary mb-6 overflow-x-auto`,children:[{id:`queue`,label:e(`queue.tabs.queue`),icon:_s,count:Se.length+we.length},{id:`history`,label:e(`queue.tabs.history`),icon:Rc,count:ke.length},{id:`timeline`,label:e(`queue.tabs.timeline`),icon:Qo,count:null}].map(({id:e,label:t,icon:n,count:r})=>(0,K.jsxs)(`button`,{onClick:()=>P(e),className:`px-4 py-2.5 text-sm flex items-center gap-2 border-b-2 -mb-px transition-colors whitespace-nowrap ${N===e?`text-white border-bambu-green font-medium`:`text-bambu-gray border-transparent hover:text-white`}`,children:[(0,K.jsx)(n,{className:`w-4 h-4`}),t,r!==null&&r>0&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${N===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:r})]},e))}),(0,K.jsx)(VLe,{activeCount:we.length,pendingCount:Se.length,totalTime:Ae,totalWeight:je,historyCount:ke.length,t:e}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-4 mb-6`,children:[(0,K.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:o===-1?`unassigned`:o||``,onChange:e=>{let t=e.target.value;s(t===`unassigned`?-1:t===``?null:Number(t))},children:[(0,K.jsx)(`option`,{value:``,children:e(`queue.filter.allPrinters`)}),(0,K.jsx)(`option`,{value:`unassigned`,children:e(`queue.filter.unassigned`)}),W?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,K.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:c,onChange:e=>l(e.target.value),children:[(0,K.jsx)(`option`,{value:``,children:e(`queue.filter.allStatus`)}),(0,K.jsx)(`option`,{value:`pending`,children:e(`queue.status.pending`)}),(0,K.jsx)(`option`,{value:`printing`,children:e(`queue.status.printing`)}),(0,K.jsx)(`option`,{value:`completed`,children:e(`queue.status.completed`)}),(0,K.jsx)(`option`,{value:`failed`,children:e(`queue.status.failed`)}),(0,K.jsx)(`option`,{value:`skipped`,children:e(`queue.status.skipped`)}),(0,K.jsx)(`option`,{value:`cancelled`,children:e(`queue.status.cancelled`)})]}),be.length>0&&(0,K.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:u,onChange:e=>d(e.target.value),children:[(0,K.jsx)(`option`,{value:``,children:e(`queue.filter.allLocations`)}),be.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),(0,K.jsx)(`div`,{className:`hidden sm:block flex-1`}),N===`history`&&ke.length>0&&(0,K.jsxs)($,{className:`w-full sm:w-auto`,variant:`secondary`,size:`sm`,onClick:()=>p(!0),disabled:!r(`queue:delete_all`),title:r(`queue:delete_all`)?void 0:e(`queue.permissions.noClearHistory`),children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`queue.clearHistory`)]})]}),N===`queue`&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mb-6`,children:[(0,K.jsxs)(`div`,{className:`inline-flex items-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,K.jsxs)(`button`,{className:`px-3 py-1.5 text-xs sm:text-sm rounded-md transition-colors flex items-center gap-1.5 ${F===`position`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,onClick:()=>I(`position`),title:e(`queue.layout.flatList`),children:[(0,K.jsx)(Bc,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.layout.flatList`)})]}),(0,K.jsxs)(`button`,{className:`px-3 py-1.5 text-xs sm:text-sm rounded-md transition-colors flex items-center gap-1.5 ${F===`printer`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,onClick:()=>I(`printer`),title:e(`queue.layout.groupByPrinter`),children:[(0,K.jsx)(bl,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.layout.byPrinter`)})]})]}),(0,K.jsxs)(`button`,{onClick:()=>{let e=!(re?.queue_shortest_first??!1);oe.mutate(e)},className:`flex items-center gap-1 px-2 py-1.5 text-xs rounded-lg border transition-colors ${re?.queue_shortest_first?`bg-bambu-green/20 border-bambu-green text-bambu-green`:`bg-bambu-dark-secondary border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,title:e(`queue.sjf.tooltip`,`Shortest Job First — scheduler prioritizes shorter prints`),children:[(0,K.jsx)(Xl,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.sjf.label`,`SJF`)}),(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${re?.queue_shortest_first?`bg-bambu-green`:`bg-bambu-gray`}`})]})]}),ae?(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`common.loading`)}):ie?.length===0?(0,K.jsxs)(pd,{className:`p-12 text-center border-dashed`,children:[(0,K.jsx)(qo,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,K.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:e(`queue.empty.title`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:e(`queue.empty.description`)})]}):N===`timeline`?(0,K.jsx)(KLe,{queueItems:ie||[],printers:W||[],printerStatuses:Oe,onItemClick:e=>{[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status)?_(e):e.status===`pending`?h(e):e.status===`printing`&&b({type:`stop`,item:e})},t:e}):N===`history`?(0,K.jsx)(YLe,{items:ke,collapsed:!1,sortBy:T,sortAsc:D,onSortByChange:E,onSortAscToggle:()=>O(!D),onRemove:e=>b({type:`remove`,item:e}),onRequeue:_,timeFormat:U,batchCollapsed:L,toggleBatchCollapsed:Le,hasPermission:r,canModify:a,t:e}):(0,K.jsxs)(`div`,{className:`space-y-6 sm:space-y-8`,children:[we.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white mb-3 sm:mb-4 flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-blue-400 animate-pulse`}),e(`queue.sections.currentlyPrinting`)]}),(0,K.jsx)(`div`,{className:`space-y-2 sm:space-y-3`,children:we.map(t=>(0,K.jsx)(i5,{item:t,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>b({type:`stop`,item:t}),onRequeue:()=>{},onStart:()=>{},timeFormat:U,hasPermission:r,canModify:a,printerState:t.printer_id?De[t.printer_id]:null,t:e},t.id))})]}),Se.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4`,children:[(0,K.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(_s,{className:`w-4 h-4 sm:w-5 sm:h-5 text-yellow-400`}),e(`queue.sections.queued`),(0,K.jsxs)(`span`,{className:`text-xs sm:text-sm font-normal text-bambu-gray`,children:[`(`,e(`queue.itemCount`,{count:Se.length}),`)`]}),(0,K.jsx)(`span`,{className:`hidden sm:inline text-xs text-bambu-gray ml-2`,title:e(`queue.reorderHint`),children:e(`queue.dragToReorder`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`select`,{className:`px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:k,onChange:e=>A(e.target.value),children:[(0,K.jsx)(`option`,{value:`position`,children:e(`queue.sort.byPosition`)}),(0,K.jsx)(`option`,{value:`name`,children:e(`queue.sort.byName`)}),(0,K.jsx)(`option`,{value:`printer`,children:e(`queue.sort.byPrinter`)}),(0,K.jsx)(`option`,{value:`time`,children:e(`queue.sort.bySchedule`)})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>M(!j),title:e(j?`common.ascending`:`common.descending`),className:`px-2`,children:j?(0,K.jsx)(Mo,{className:`w-4 h-4`}):(0,K.jsx)(Eo,{className:`w-4 h-4`})})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-3 sm:mb-4 p-2 sm:p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:Ce,className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm`,children:[x.length===Se.length&&Se.length>0?(0,K.jsx)($l,{className:`w-4 h-4 text-bambu-green`}):(0,K.jsx)(tu,{className:`w-4 h-4`}),x.length===Se.length&&Se.length>0?e(`queue.bulkEdit.deselectAll`):e(`queue.bulkEdit.selectAll`)]}),x.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`text-xs sm:text-sm text-bambu-gray`,children:e(`queue.bulkEdit.selected`,{count:x.length})}),(0,K.jsx)(`div`,{className:`hidden sm:block h-4 w-px bg-bambu-dark-tertiary`}),Ie&&(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>ee(!0),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-cyan-300 hover:text-cyan-200`,title:e(`queue.batch.groupAsBatch`),children:[(0,K.jsx)(cl,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.batch.groupAsBatch`)})]}),(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>w(!0),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-bambu-green hover:text-bambu-green-light`,disabled:!i(`queue:update_own`,`queue:update_all`),title:i(`queue:update_own`,`queue:update_all`)?e(`queue.bulkEdit.editSelected`):e(`queue.permissions.noEditItems`),children:[(0,K.jsx)(pl,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.bulkEdit.editSelected`)})]}),(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>ge.mutate(x),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-red-400 hover:text-red-300`,disabled:ge.isPending||!i(`queue:delete_own`,`queue:delete_all`),title:i(`queue:delete_own`,`queue:delete_all`)?e(`queue.bulkEdit.cancelSelected`):e(`queue.permissions.noCancelItems`),children:[(0,K.jsx)(Pu,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.bulkEdit.cancelSelected`)})]})]})]}),(0,K.jsxs)(P8,{sensors:ne,collisionDetection:L6,onDragStart:Me,onDragEnd:Ne,children:[(0,K.jsx)(W8,{items:Fe,strategy:kLe,children:F===`position`?(0,K.jsx)(`div`,{className:`space-y-2 sm:space-y-3`,children:Pe.map(t=>(0,K.jsx)(a5,{row:t,collapsed:t.kind===`batch`?L[t.batchId]??!0:!1,onToggleBatch:t.kind===`batch`?()=>Le(t.batchId):void 0,onUngroup:t.kind===`batch`?()=>te(t.batchId):void 0,setEditItem:h,setConfirmAction:b,startMutation:fe,selectedItems:x,handleToggleSelect:ye,timeFormat:U,hasPermission:r,canModify:a,t:e,aggregateForRows:ze},t.kind===`item`?`item-${t.item.id}`:`batch-${t.batchId}`))}):(0,K.jsx)(`div`,{className:`space-y-4`,children:Re.map(t=>{let n=ze(t.rows);return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-t-lg`,children:[(0,K.jsx)(bl,{className:`w-4 h-4 ${t.isUnassigned?`text-orange-400`:t.targetModel?`text-blue-400`:`text-bambu-green`}`}),(0,K.jsx)(`span`,{className:`font-semibold text-white text-sm`,children:t.label}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray flex flex-wrap gap-x-3`,children:[(0,K.jsx)(`span`,{children:e(`queue.itemCount`,{count:n.count})}),n.time>0&&(0,K.jsx)(`span`,{children:yf(n.time)}),n.weight>0&&(0,K.jsx)(`span`,{children:n5(n.weight)})]})]}),(0,K.jsx)(`div`,{className:`bg-bambu-dark/40 border border-t-0 border-bambu-dark-tertiary rounded-b-lg p-2 space-y-2`,children:t.rows.map(t=>(0,K.jsx)(a5,{row:t,collapsed:t.kind===`batch`?L[t.batchId]??!0:!1,onToggleBatch:t.kind===`batch`?()=>Le(t.batchId):void 0,onUngroup:t.kind===`batch`?()=>te(t.batchId):void 0,setEditItem:h,setConfirmAction:b,startMutation:fe,selectedItems:x,handleToggleSelect:ye,timeFormat:U,hasPermission:r,canModify:a,t:e,aggregateForRows:ze},t.kind===`item`?`item-${t.item.id}`:`batch-${t.batchId}`))})]},t.key)})})}),(0,K.jsx)(TLe,{children:z!==null&&x.includes(z)&&x.length>1?(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border-2 border-cyan-400 rounded-lg shadow-2xl`,children:[(0,K.jsx)(cl,{className:`w-4 h-4 text-cyan-300`}),(0,K.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e(`queue.dragGhost.multiCount`,{count:x.length})})]}):null})]})]})]}),m&&(0,K.jsx)(sq,{mode:`edit-queue-item`,archiveId:m.archive_id??void 0,libraryFileId:m.library_file_id??void 0,archiveName:m.archive_name||m.library_file_name||`File #${m.archive_id||m.library_file_id}`,queueItem:m,onClose:()=>h(null)}),g&&(0,K.jsx)(sq,{mode:`add-to-queue`,archiveId:g.archive_id??void 0,libraryFileId:g.library_file_id??void 0,archiveName:g.archive_name||g.library_file_name||`File #${g.archive_id||g.library_file_id}`,onClose:()=>_(null)}),ue&&(0,K.jsx)(Ed,{title:e(`queue.filamentShort.confirmTitle`),message:e(`queue.filamentShort.confirmIntro`)+` + `,onClick:M?()=>{window.innerWidth<640&&u()}:void 0,children:[M&&l&&(0,K.jsx)(`div`,{className:`sm:hidden absolute left-0 top-3 bottom-3 w-1 rounded-full bg-bambu-green`}),(0,K.jsxs)(`div`,{className:`flex items-start sm:items-center gap-2 sm:gap-4 p-3 sm:p-4`,children:[A&&u&&(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),u()},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${l?`bg-bambu-green border-bambu-green text-white`:`border-white/30 bg-black/30 hover:border-bambu-green/50`}`,children:l&&(0,K.jsx)($o,{className:`w-4 h-4`})}),A?(0,K.jsx)(`div`,{...S,...C,className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-manipulation shrink-0`,children:(0,K.jsx)(gc,{className:`w-4 h-4 text-bambu-gray`})}):t===void 0?(0,K.jsx)(`div`,{className:`hidden sm:block w-8 shrink-0`}):(0,K.jsxs)(`div`,{className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark text-bambu-gray text-sm font-medium shrink-0`,children:[`#`,t]}),(0,K.jsx)(`div`,{className:`w-10 h-10 sm:w-14 sm:h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden`,children:e.archive_thumbnail?(0,K.jsx)(`img`,{src:e.plate_id==null?Q.getArchiveThumbnail(e.archive_id):Q.getArchivePlateThumbnail(e.archive_id,e.plate_id),alt:``,className:`w-full h-full object-cover`}):e.library_file_thumbnail?(0,K.jsx)(`img`,{src:e.plate_id==null?Q.getLibraryFileThumbnailUrl(e.library_file_id):Q.getLibraryFilePlateThumbnail(e.library_file_id,e.plate_id),alt:``,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,K.jsx)(Nc,{className:`w-5 h-5 sm:w-6 sm:h-6`})})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsxs)(`p`,{className:`text-sm sm:text-base text-white font-medium truncate`,children:[e.archive_name||e.library_file_name||`File #${e.archive_id||e.library_file_id}`,(y?.is_multi_plate??!1)&&e.plate_id!==void 0&&e.plate_id!==null&&` • ${b.find(t=>t.index===e.plate_id)?.name||m(`queue.plateNumber`,{index:e.plate_id})}`]}),e.archive_id?(0,K.jsx)(bi,{to:`/archives?highlight=${e.archive_id}`,className:`text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:m(`queue.viewArchive`),children:(0,K.jsx)(Us,{className:`w-3.5 h-3.5`})}):e.library_file_id?(0,K.jsx)(bi,{to:`/library?highlight=${e.library_file_id}`,className:`text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:m(`queue.viewInFileManager`),children:(0,K.jsx)(Us,{className:`w-3.5 h-3.5`})}):null,e.batch_name&&(0,K.jsx)(`span`,{className:`flex-shrink-0 px-1.5 py-0.5 text-[10px] sm:text-xs bg-cyan-500/20 text-cyan-300 rounded border border-cyan-500/30`,children:e.batch_name})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 ${e.printer_id===null&&!e.target_model?`text-orange-400`:``} ${e.target_model&&!e.printer_id?`text-blue-400`:``}`,children:[(0,K.jsx)(bl,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),(0,K.jsx)(`span`,{className:`truncate max-w-[120px] sm:max-w-none`,children:e.target_model&&!e.printer_id?`${m(`queue.filter.any`)} ${e.target_model}${e.target_location?` @ ${e.target_location}`:``}${e.required_filament_types?.length?` (${e.required_filament_types.join(`, `)})`:``}`:e.printer_id===null?m(`queue.filter.unassigned`):e.printer_name||`${m(`common.printer`)} #${e.printer_id}`})]}),e.print_time_seconds&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,K.jsx)(mu,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),yf(e.print_time_seconds)]}),e.filament_used_grams&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,K.jsx)(ku,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),n5(e.filament_used_grams)]}),(()=>{let t=$K(e.bed_type);return t?(0,K.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,title:t.label,children:[(0,K.jsx)(`img`,{src:t.icon,alt:``,className:`w-3.5 h-3.5 sm:w-4 sm:h-4 object-contain`}),(0,K.jsx)(`span`,{className:`truncate max-w-[120px]`,children:t.label})]}):null})(),e.created_by_username&&(0,K.jsxs)(`span`,{className:`hidden sm:flex items-center gap-1.5`,title:m(`queue.addedBy`,{name:e.created_by_username}),children:[(0,K.jsx)(Cu,{className:`w-3.5 h-3.5`}),e.created_by_username]}),A&&!e.manual_start&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(_s,{className:`w-3.5 h-3.5`}),e.scheduled_time?(mf(e.scheduled_time)?.getTime()??0)-Date.now()<-6e4?m?.(`queue.time.overdue`)??`Overdue`:bf(e.scheduled_time,c,m):m?.(`queue.time.asap`)??`ASAP`]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 sm:gap-2 mt-1.5 sm:mt-2`,children:[e.manual_start&&(0,K.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-purple-500/10 text-purple-400 rounded-full border border-purple-500/20 flex items-center gap-1`,children:[(0,K.jsx)(vc,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),m(`queue.badges.staged`)]}),e.require_previous_success&&(0,K.jsx)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-orange-500/10 text-orange-400 rounded-full border border-orange-500/20`,children:m(`queue.badges.requiresPrevious`)}),e.auto_off_after&&(0,K.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-blue-500/10 text-blue-400 rounded-full border border-blue-500/20 flex items-center gap-1`,children:[(0,K.jsx)(yl,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),m(`queue.badges.autoPowerOff`)]}),e.gcode_injection&&(0,K.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-emerald-500/10 text-emerald-400 rounded-full border border-emerald-500/20 flex items-center gap-1`,children:[(0,K.jsx)(xs,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),m(`queue.badges.gcodeInjection`)]})]}),k&&h&&(()=>{let e=h.state===`RUNNING`||h.state===`PAUSE`,t=e&&h.progress||0,n=e?h.remaining_time:null,r=e?h.layer_num:null,i=e?h.total_layers:null;return(0,K.jsxs)(`div`,{className:`mt-2 sm:mt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs sm:text-sm`,children:[(0,K.jsx)(`div`,{className:`flex-1 bg-bambu-dark-tertiary rounded-full h-1.5 sm:h-2 mr-3`,children:(0,K.jsx)(`div`,{className:`bg-bambu-green h-1.5 sm:h-2 rounded-full transition-all`,style:{width:`${t}%`}})}),(0,K.jsxs)(`span`,{className:`text-white`,children:[Math.round(t),`%`]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mt-1.5 sm:mt-2 text-[10px] sm:text-xs text-bambu-gray`,children:[n!=null&&n>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),yf(n*60)]}),(0,K.jsxs)(`span`,{className:`text-bambu-green font-medium`,title:m(`printers.estimatedCompletion`),children:[`ETA `,vf(n,c,m)]})]}),r!=null&&i!=null&&i>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(Nc,{className:`w-3 h-3`}),r,`/`,i]})]})]})})(),e.waiting_reason&&e.status===`pending`&&(0,K.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-purple-400 mt-1.5 sm:mt-2 flex items-start gap-1`,children:[(0,K.jsx)(ss,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`span`,{children:e.waiting_reason})]}),e.filament_short&&e.status===`pending`&&(0,K.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-yellow-400 mt-1.5 sm:mt-2 flex items-start gap-1`,title:m(`queue.filamentShort.rowTooltip`),children:[(0,K.jsx)(ss,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`span`,{children:m(`queue.filamentShort.rowBadge`)})]}),e.error_message&&(0,K.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-red-400 mt-1.5 sm:mt-2 flex items-center gap-1`,children:[(0,K.jsx)(ss,{className:`w-3 h-3`}),e.error_message]})]}),(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-end sm:items-center gap-2 sm:gap-1 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(JLe,{status:e.status,waitingReason:e.waiting_reason,printerState:p,t:m}),(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5 sm:gap-1`,children:[k&&(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:a,disabled:!d(`printers:control`),title:d(`printers:control`)?m(`queue.actions.stopPrint`):m(`queue.permissions.noStopPrint`),className:`text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,K.jsx)(ps,{className:`w-4 h-4`})}),A&&(0,K.jsxs)(K.Fragment,{children:[e.manual_start&&(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:s,disabled:!d(`printers:control`),title:d(`printers:control`)?m(`queue.actions.startPrint`):m(`queue.permissions.noStartPrint`),className:`text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10 p-1.5 sm:p-2`,children:(0,K.jsx)(hl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:n,disabled:!f(`queue`,`update`,e.created_by_id),title:f(`queue`,`update`,e.created_by_id)?m(`common.edit`):m(`queue.permissions.noEdit`),className:`p-1.5 sm:p-2`,children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:r,disabled:!f(`queue`,`delete`,e.created_by_id),title:f(`queue`,`delete`,e.created_by_id)?m(`common.cancel`):m(`queue.permissions.noCancel`),className:`text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}),j&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:o,disabled:!d(`queue:create`),title:d(`queue:create`)?m(`queue.actions.requeue`):m(`queue.permissions.noRequeue`),className:`text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5 sm:p-2`,children:(0,K.jsx)(Cl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:i,disabled:!f(`queue`,`delete`,e.created_by_id),title:f(`queue`,`delete`,e.created_by_id)?m(`common.remove`):m(`queue.permissions.noRemove`),className:`p-1.5 sm:p-2`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]})]})]})]})}function a5({row:e,collapsed:t,onToggleBatch:n,onUngroup:r,setEditItem:i,setConfirmAction:a,startMutation:o,selectedItems:s,handleToggleSelect:c,timeFormat:l,hasPermission:u,canModify:d,t:f,aggregateForRows:p}){if(e.kind===`item`)return(0,K.jsx)(i5,{item:e.item,onEdit:()=>i(e.item),onCancel:()=>a({type:`cancel`,item:e.item}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>o.mutate({id:e.item.id}),timeFormat:l,isSelected:s.includes(e.item.id),onToggleSelect:()=>c(e.item.id),hasPermission:u,canModify:d,t:f});let m=p([e]),h=e.items.map(e=>e.id),g=h.length>0&&h.every(e=>s.includes(e)),_=new Set(e.items.map(e=>e.status)),v=_.has(`failed`)?`failed`:_.has(`printing`)?`printing`:`pending`,y=e.items.filter(e=>e.status===`pending`).length;return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-l-[3px] border-l-cyan-400 border-bambu-dark-tertiary overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3 p-3 sm:p-4`,children:[(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),h.forEach(e=>{(g&&s.includes(e)||!g&&!s.includes(e))&&c(e)})},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${g?`bg-bambu-green border-bambu-green text-white`:`border-white/30 bg-black/30 hover:border-bambu-green/50`}`,title:f(g?`queue.bulkEdit.deselectAll`:`queue.bulkEdit.selectAll`),children:g&&(0,K.jsx)($o,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:n,className:`flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors shrink-0`,title:f(t?`queue.batch.expand`:`queue.batch.collapse`),children:t?(0,K.jsx)(ts,{className:`w-4 h-4 text-bambu-gray`}):(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray`})}),(0,K.jsx)(`div`,{className:`w-10 h-10 sm:w-12 sm:h-12 flex-shrink-0 bg-bambu-dark rounded-lg flex items-center justify-center`,children:t?(0,K.jsx)(cl,{className:`w-5 h-5 text-cyan-300`}):(0,K.jsx)(sl,{className:`w-5 h-5 text-cyan-300`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsx)(`p`,{className:`text-sm sm:text-base text-white font-medium truncate`,children:e.batchName}),(0,K.jsx)(`span`,{className:`flex-shrink-0 px-1.5 py-0.5 text-[10px] sm:text-xs bg-cyan-500/15 text-cyan-300 rounded border border-cyan-500/30`,children:f(`queue.batch.label`,{count:m.count})})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray`,children:[m.time>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,K.jsx)(mu,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),yf(m.time)]}),m.weight>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,K.jsx)(ku,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),n5(m.weight)]}),y>0&&v===`pending`&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 text-yellow-400`,children:[(0,K.jsx)(_s,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),f(`queue.batch.pendingCount`,{count:y})]})]})]}),(0,K.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:r&&(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:r,title:f(`queue.batch.ungroup`),className:`text-cyan-300 hover:text-cyan-200 hover:bg-cyan-500/10 p-1.5 sm:p-2`,children:(0,K.jsx)(bu,{className:`w-4 h-4`})})})]}),!t&&(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary bg-black/20 p-2 sm:p-3 space-y-2`,children:e.items.map(e=>(0,K.jsx)(i5,{item:e,onEdit:()=>i(e),onCancel:()=>a({type:`cancel`,item:e}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>o.mutate({id:e.id}),timeFormat:l,isSelected:s.includes(e.id),onToggleSelect:()=>c(e.id),hasPermission:u,canModify:d,t:f},e.id))})]})}function XLe({items:e,sortBy:t,sortAsc:n,onSortByChange:r,onSortAscToggle:i,onRemove:a,onRequeue:o,timeFormat:s,batchCollapsed:c,toggleBatchCollapsed:l,hasPermission:u,canModify:d,t:f}){if(e.length===0)return(0,K.jsxs)(pd,{className:`p-12 text-center border-dashed`,children:[(0,K.jsx)(Rc,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,K.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:f(`queue.history.emptyTitle`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:f(`queue.history.emptyDescription`)})]});let p=[],m=new Set;for(let t of e.slice(0,50))if(t.batch_id!=null){if(m.has(t.batch_id))continue;m.add(t.batch_id);let n=e.filter(e=>e.batch_id===t.batch_id);p.push({kind:`batch`,batchId:t.batch_id,batchName:t.batch_name||f(`queue.batch.defaultName`),items:n})}else p.push({kind:`item`,item:t});return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4`,children:[(0,K.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white flex items-center gap-2`,children:[f(`queue.sections.history`),(0,K.jsxs)(`span`,{className:`text-xs sm:text-sm font-normal text-bambu-gray`,children:[`(`,f(`queue.itemCount`,{count:e.length}),`)`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`select`,{className:`px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:t,onChange:e=>r(e.target.value),children:[(0,K.jsx)(`option`,{value:`date`,children:f(`queue.sort.byDate`)}),(0,K.jsx)(`option`,{value:`name`,children:f(`queue.sort.byName`)}),(0,K.jsx)(`option`,{value:`printer`,children:f(`queue.sort.byPrinter`)})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:i,title:f(n?`queue.sort.ascendingOldest`:`queue.sort.descendingNewest`),className:`px-2`,children:n?(0,K.jsx)(Mo,{className:`w-4 h-4`}):(0,K.jsx)(Eo,{className:`w-4 h-4`})})]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:p.map(e=>{if(e.kind===`item`)return(0,K.jsx)(Z8,{item:e.item,onRemove:()=>a(e.item),onRequeue:()=>o(e.item),timeFormat:s,hasPermission:u,canModify:d,t:f},e.item.id);let t=c[e.batchId]??!0,n=e.items.filter(e=>e.status===`completed`).length,r=e.items.filter(e=>e.status===`failed`).length,i=e.items.filter(e=>e.status===`skipped`).length,p=e.items.filter(e=>e.status===`cancelled`).length,m=e.items.map(e=>e.completed_at||e.created_at).filter(e=>!!e).sort().at(-1);return(0,K.jsxs)(`div`,{className:`md:col-span-2 xl:col-span-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary border-l-[3px] border-l-cyan-400`,children:[(0,K.jsxs)(`button`,{onClick:()=>l(e.batchId),className:`w-full flex items-center gap-2 sm:gap-3 px-3 py-2 hover:bg-bambu-dark/30 transition-colors text-left`,title:f(t?`queue.batch.expand`:`queue.batch.collapse`),children:[t?(0,K.jsx)(ts,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray shrink-0`}),t?(0,K.jsx)(cl,{className:`w-5 h-5 text-cyan-300 shrink-0`}):(0,K.jsx)(sl,{className:`w-5 h-5 text-cyan-300 shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm text-white font-medium truncate min-w-0 flex-1`,children:e.batchName}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray shrink-0`,children:[n>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-emerald-400`,children:[(0,K.jsx)(ls,{className:`w-3 h-3`}),n]}),r>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-red-400`,children:[(0,K.jsx)(ms,{className:`w-3 h-3`}),r]}),i>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-orange-400`,children:[(0,K.jsx)(Kl,{className:`w-3 h-3`}),i]}),p>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-400`,children:[(0,K.jsx)(No,{className:`w-3 h-3`}),p]}),(0,K.jsx)(`span`,{title:m??void 0,children:m?bf(m,s,f):null})]})]}),!t&&(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary bg-black/20 p-2 grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:e.items.map(e=>(0,K.jsx)(Z8,{item:e,onRemove:()=>a(e),onRequeue:()=>o(e),timeFormat:s,hasPermission:u,canModify:d,t:f},e.id))})]},`batch-${e.batchId}`)})})]})}function ZLe(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),{hasPermission:r,hasAnyPermission:i,canModify:a}=sd(),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(null),[x,S]=(0,y.useState)([]),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(()=>localStorage.getItem(`queue.historySortBy`)||`date`),[D,O]=(0,y.useState)(()=>{let e=localStorage.getItem(`queue.historySortAsc`);return e===null?!1:e===`true`}),[k,A]=(0,y.useState)(()=>localStorage.getItem(`queue.pendingSortBy`)||`position`),[j,M]=(0,y.useState)(()=>{let e=localStorage.getItem(`queue.pendingSortAsc`);return e===null?!0:e===`true`}),[N,P]=(0,y.useState)(()=>{let e=localStorage.getItem(`queue.activeTab`);return e===`history`||e===`timeline`?e:`queue`}),[F,I]=(0,y.useState)(()=>localStorage.getItem(`queue.activeLayout`)===`printer`?`printer`:`position`),[L,R]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`queue.batchCollapsed`);return e?JSON.parse(e):{}}catch{return{}}}),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)(!1),[H,te]=(0,y.useState)(null);(0,y.useEffect)(()=>{localStorage.setItem(`queue.historySortBy`,T)},[T]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.historySortAsc`,String(D))},[D]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.pendingSortBy`,k)},[k]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.pendingSortAsc`,String(j))},[j]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.activeTab`,N)},[N]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.activeLayout`,F)},[F]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.batchCollapsed`,JSON.stringify(L))},[L]);let ne=A6(k6(u8,{activationConstraint:{distance:8}}),k6(o8,{coordinateGetter:J8})),{data:re}=q({queryKey:[`settings`],queryFn:Q.getSettings}),U=re?.time_format||`system`,{data:ie,isLoading:ae}=q({queryKey:[`queue`,o,c],queryFn:()=>Q.getQueue(o||void 0,c||void 0),refetchInterval:5e3}),{data:W}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters()}),oe=J({mutationFn:e=>Q.updateSettings({queue_shortest_first:e}),onSuccess:()=>{t.invalidateQueries({queryKey:[`settings`]})}}),se=J({mutationFn:e=>Q.cancelQueueItem(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.cancelled`))},onError:()=>n(e(`queue.toast.cancelFailed`),`error`)}),ce=J({mutationFn:e=>Q.removeFromQueue(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.removed`))},onError:()=>n(e(`queue.toast.removeFailed`),`error`)}),le=J({mutationFn:e=>Q.stopQueueItem(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.stopped`))},onError:()=>n(e(`queue.toast.stopFailed`),`error`)}),[ue,de]=(0,y.useState)(null),fe=J({mutationFn:({id:e,skipFilamentCheck:t})=>Q.startQueueItem(e,{skipFilamentCheck:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.released`)),de(null)},onError:(t,r)=>{if(t instanceof zu&&t.status===409&&t.code===`insufficient_filament`){let e=t.detail?.deficit??[];de({itemId:r.id,deficit:e});return}n(e(`queue.toast.startFailed`),`error`)}}),pe=J({mutationFn:e=>Q.reorderQueue(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]})},onError:()=>n(e(`queue.toast.reorderFailed`),`error`)}),me=J({mutationFn:async()=>{let e=ie?.filter(e=>[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status))||[];for(let t of e)await Q.removeFromQueue(t.id);return e.length},onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.historyCleared`,{count:r}))},onError:()=>n(e(`queue.toast.clearHistoryFailed`),`error`)}),he=J({mutationFn:e=>Q.bulkUpdateQueue(e),onSuccess:e=>{t.invalidateQueries({queryKey:[`queue`]}),S([]),w(!1),n(e.message)},onError:()=>n(e(`queue.toast.updateFailed`),`error`)}),ge=J({mutationFn:async e=>{for(let t of e)await Q.cancelQueueItem(t);return e.length},onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),S([]),n(e(`queue.toast.bulkCancelled`,{count:r}))},onError:()=>n(e(`queue.toast.bulkCancelFailed`),`error`)}),_e=J({mutationFn:e=>Q.createBatch(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),S([]),ee(!1),R(e=>({...e,[r.id]:!1})),n(e(`queue.toast.batchCreated`,{name:r.name}))},onError:()=>n(e(`queue.toast.batchCreateFailed`),`error`)}),ve=J({mutationFn:e=>Q.ungroupBatch(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),te(null),n(e(`queue.toast.batchUngrouped`,{count:r.ungrouped_count}))},onError:()=>n(e(`queue.toast.batchUngroupFailed`),`error`)}),ye=e=>{S(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},be=(0,y.useMemo)(()=>{let e=new Set;return W?.forEach(t=>{t.location&&e.add(t.location)}),ie?.forEach(t=>{t.target_location&&e.add(t.target_location)}),Array.from(e).sort()},[W,ie]),xe=(0,y.useCallback)(e=>u?e.target_location?e.target_location===u:e.printer_id?W?.find(t=>t.id===e.printer_id)?.location===u:!1:!0,[u,W]),Se=(0,y.useMemo)(()=>{let e=ie?.filter(e=>e.status===`pending`)||[];u&&(e=e.filter(xe));let t=e=>{if(!e.scheduled_time)return 0;let t=mf(e.scheduled_time)?.getTime()??0;return t>Date.now()+4320*60*60*1e3?0:t};return re?.queue_shortest_first?[...e].sort((e,t)=>{let n=e.printer_id??-(e.target_model?.charCodeAt(0)??0),r=t.printer_id??-(t.target_model?.charCodeAt(0)??0);if(n!==r)return n-r;let i=+!!e.been_jumped,a=+!!t.been_jumped;if(i!==a)return a-i;let o=e.print_time_seconds??1/0,s=t.print_time_seconds??1/0;return o===s?e.position-t.position:o-s}):[...e].sort((e,n)=>{let r;if(k===`name`){let t=e.archive_name||e.library_file_name||``,i=n.archive_name||n.library_file_name||``;r=t.localeCompare(i)}else r=k===`printer`?(e.printer_name||``).localeCompare(n.printer_name||``):k===`time`?t(e)-t(n):e.position-n.position;return j?r:-r})},[ie,k,j,xe,u,re?.queue_shortest_first]),Ce=()=>{let e=Se.map(e=>e.id);x.length===e.length?S([]):S(e)},we=(0,y.useMemo)(()=>{let e=ie?.filter(e=>e.status===`printing`)||[];return u&&(e=e.filter(xe)),e},[ie,u,xe]),Te=(0,y.useMemo)(()=>{let e=new Set;return we.forEach(t=>{t.printer_id&&e.add(t.printer_id)}),Array.from(e)},[we]),Ee=po({queries:Te.map(e=>({queryKey:[`printerStatus`,e],queryFn:()=>Q.getPrinterStatus(e),refetchInterval:5e3}))}),De=(0,y.useMemo)(()=>{let e={};return Te.forEach((t,n)=>{let r=Ee[n];r?.data?.state&&(e[t]=r.data.state)}),e},[Te,Ee]),Oe=(0,y.useMemo)(()=>{let e={};return Te.forEach((t,n)=>{let r=Ee[n];r?.data&&(e[t]={progress:r.data.progress??void 0,remaining_time:r.data.remaining_time??void 0,state:r.data.state??void 0})}),e},[Te,Ee]),ke=(0,y.useMemo)(()=>{let e=ie?.filter(e=>[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status))||[];return u&&(e=e.filter(xe)),[...e].sort((e,t)=>{let n;if(T===`name`){let r=e.archive_name||e.library_file_name||``,i=t.archive_name||t.library_file_name||``;n=r.localeCompare(i)}else n=T===`printer`?(e.printer_name||``).localeCompare(t.printer_name||``):(mf(t.completed_at||t.created_at)?.getTime()??0)-(mf(e.completed_at||e.created_at)?.getTime()??0);return D?-n:n})},[ie,T,D,xe,u]),Ae=(0,y.useMemo)(()=>Se.reduce((e,t)=>e+(t.print_time_seconds||0),0),[Se]),je=(0,y.useMemo)(()=>Se.reduce((e,t)=>e+(t.filament_used_grams||0),0),[Se]),Me=e=>{B(typeof e.active.id==`number`?e.active.id:null)},Ne=e=>{let{active:t,over:n}=e;if(B(null),!n||t.id===n.id)return;let r=t.id,i=x.includes(r)&&x.length>1?x.slice().sort((e,t)=>Se.findIndex(t=>t.id===e)-Se.findIndex(e=>e.id===t)):[r],a=Se.findIndex(e=>e.id===n.id);if(a===-1)return;let o=Se.filter(e=>!i.includes(e.id)),s=o.findIndex(e=>e.id===n.id);s===-1&&(s=a),Se.findIndex(e=>e.id===r)Se.find(t=>t.id===e)).filter(e=>!!e),...o.slice(s)].map((e,t)=>({id:e.id,position:t+1}));pe.mutate(c)},Pe=(0,y.useMemo)(()=>{let t=[],n=new Set;for(let r of Se)if(r.batch_id!=null){if(n.has(r.batch_id))continue;n.add(r.batch_id);let i=Se.filter(e=>e.batch_id===r.batch_id);t.push({kind:`batch`,batchId:r.batch_id,batchName:r.batch_name||e(`queue.batch.defaultName`),items:i})}else t.push({kind:`item`,item:r});return t},[Se,e]),Fe=(0,y.useMemo)(()=>{let e=[];for(let t of Pe)if(t.kind===`item`)e.push(t.item.id);else if(!(L[t.batchId]??!0))for(let n of t.items)e.push(n.id);return e},[Pe,L]),Ie=(0,y.useMemo)(()=>x.length<2?!1:x.every(e=>{let t=Se.find(t=>t.id===e);return t&&t.batch_id==null}),[x,Se]),Le=e=>{R(t=>({...t,[e]:!(t[e]??!0)}))},Re=(0,y.useMemo)(()=>{let t=new Map,n=t=>t.printer_id?{key:`printer:${t.printer_id}`,label:t.printer_name||`Printer #${t.printer_id}`,printerId:t.printer_id,targetModel:null,isUnassigned:!1}:t.target_model?{key:`model:${t.target_model}`,label:`${e(`queue.filter.any`)} ${t.target_model}`,printerId:null,targetModel:t.target_model,isUnassigned:!1}:{key:`unassigned`,label:e(`queue.filter.unassigned`),printerId:null,targetModel:null,isUnassigned:!0};for(let e of Pe){let r=e.kind===`item`?e.item:e.items[0];if(!r)continue;let i=n(r);t.has(i.key)||t.set(i.key,{...i,rows:[]}),t.get(i.key).rows.push(e)}return Array.from(t.values()).sort((e,t)=>e.isUnassigned&&!t.isUnassigned?1:!e.isUnassigned&&t.isUnassigned?-1:e.label.localeCompare(t.label))},[Pe,e]),ze=e=>{let t=0,n=0,r=0;for(let i of e){let e=i.kind===`item`?[i.item]:i.items;for(let i of e)t+=1,n+=i.print_time_seconds||0,r+=i.filament_used_grams||0}return{count:t,time:n,weight:r}};return(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between 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)(Rc,{className:`w-7 h-7 text-bambu-green`}),e(`queue.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`queue.subtitle`)})]})}),(0,K.jsx)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary mb-6 overflow-x-auto`,children:[{id:`queue`,label:e(`queue.tabs.queue`),icon:_s,count:Se.length+we.length},{id:`history`,label:e(`queue.tabs.history`),icon:Rc,count:ke.length},{id:`timeline`,label:e(`queue.tabs.timeline`),icon:Qo,count:null}].map(({id:e,label:t,icon:n,count:r})=>(0,K.jsxs)(`button`,{onClick:()=>P(e),className:`px-4 py-2.5 text-sm flex items-center gap-2 border-b-2 -mb-px transition-colors whitespace-nowrap ${N===e?`text-white border-bambu-green font-medium`:`text-bambu-gray border-transparent hover:text-white`}`,children:[(0,K.jsx)(n,{className:`w-4 h-4`}),t,r!==null&&r>0&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${N===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:r})]},e))}),(0,K.jsx)(HLe,{activeCount:we.length,pendingCount:Se.length,totalTime:Ae,totalWeight:je,historyCount:ke.length,t:e}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-4 mb-6`,children:[(0,K.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:o===-1?`unassigned`:o||``,onChange:e=>{let t=e.target.value;s(t===`unassigned`?-1:t===``?null:Number(t))},children:[(0,K.jsx)(`option`,{value:``,children:e(`queue.filter.allPrinters`)}),(0,K.jsx)(`option`,{value:`unassigned`,children:e(`queue.filter.unassigned`)}),W?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,K.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:c,onChange:e=>l(e.target.value),children:[(0,K.jsx)(`option`,{value:``,children:e(`queue.filter.allStatus`)}),(0,K.jsx)(`option`,{value:`pending`,children:e(`queue.status.pending`)}),(0,K.jsx)(`option`,{value:`printing`,children:e(`queue.status.printing`)}),(0,K.jsx)(`option`,{value:`completed`,children:e(`queue.status.completed`)}),(0,K.jsx)(`option`,{value:`failed`,children:e(`queue.status.failed`)}),(0,K.jsx)(`option`,{value:`skipped`,children:e(`queue.status.skipped`)}),(0,K.jsx)(`option`,{value:`cancelled`,children:e(`queue.status.cancelled`)})]}),be.length>0&&(0,K.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:u,onChange:e=>d(e.target.value),children:[(0,K.jsx)(`option`,{value:``,children:e(`queue.filter.allLocations`)}),be.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),(0,K.jsx)(`div`,{className:`hidden sm:block flex-1`}),N===`history`&&ke.length>0&&(0,K.jsxs)($,{className:`w-full sm:w-auto`,variant:`secondary`,size:`sm`,onClick:()=>p(!0),disabled:!r(`queue:delete_all`),title:r(`queue:delete_all`)?void 0:e(`queue.permissions.noClearHistory`),children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`queue.clearHistory`)]})]}),N===`queue`&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mb-6`,children:[(0,K.jsxs)(`div`,{className:`inline-flex items-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,K.jsxs)(`button`,{className:`px-3 py-1.5 text-xs sm:text-sm rounded-md transition-colors flex items-center gap-1.5 ${F===`position`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,onClick:()=>I(`position`),title:e(`queue.layout.flatList`),children:[(0,K.jsx)(Bc,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.layout.flatList`)})]}),(0,K.jsxs)(`button`,{className:`px-3 py-1.5 text-xs sm:text-sm rounded-md transition-colors flex items-center gap-1.5 ${F===`printer`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,onClick:()=>I(`printer`),title:e(`queue.layout.groupByPrinter`),children:[(0,K.jsx)(bl,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.layout.byPrinter`)})]})]}),(0,K.jsxs)(`button`,{onClick:()=>{let e=!(re?.queue_shortest_first??!1);oe.mutate(e)},className:`flex items-center gap-1 px-2 py-1.5 text-xs rounded-lg border transition-colors ${re?.queue_shortest_first?`bg-bambu-green/20 border-bambu-green text-bambu-green`:`bg-bambu-dark-secondary border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,title:e(`queue.sjf.tooltip`,`Shortest Job First — scheduler prioritizes shorter prints`),children:[(0,K.jsx)(Xl,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.sjf.label`,`SJF`)}),(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${re?.queue_shortest_first?`bg-bambu-green`:`bg-bambu-gray`}`})]})]}),ae?(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`common.loading`)}):ie?.length===0?(0,K.jsxs)(pd,{className:`p-12 text-center border-dashed`,children:[(0,K.jsx)(qo,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,K.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:e(`queue.empty.title`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:e(`queue.empty.description`)})]}):N===`timeline`?(0,K.jsx)(qLe,{queueItems:ie||[],printers:W||[],printerStatuses:Oe,onItemClick:e=>{[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status)?_(e):e.status===`pending`?h(e):e.status===`printing`&&b({type:`stop`,item:e})},t:e}):N===`history`?(0,K.jsx)(XLe,{items:ke,collapsed:!1,sortBy:T,sortAsc:D,onSortByChange:E,onSortAscToggle:()=>O(!D),onRemove:e=>b({type:`remove`,item:e}),onRequeue:_,timeFormat:U,batchCollapsed:L,toggleBatchCollapsed:Le,hasPermission:r,canModify:a,t:e}):(0,K.jsxs)(`div`,{className:`space-y-6 sm:space-y-8`,children:[we.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white mb-3 sm:mb-4 flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-blue-400 animate-pulse`}),e(`queue.sections.currentlyPrinting`)]}),(0,K.jsx)(`div`,{className:`space-y-2 sm:space-y-3`,children:we.map(t=>(0,K.jsx)(i5,{item:t,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>b({type:`stop`,item:t}),onRequeue:()=>{},onStart:()=>{},timeFormat:U,hasPermission:r,canModify:a,printerState:t.printer_id?De[t.printer_id]:null,t:e},t.id))})]}),Se.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4`,children:[(0,K.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(_s,{className:`w-4 h-4 sm:w-5 sm:h-5 text-yellow-400`}),e(`queue.sections.queued`),(0,K.jsxs)(`span`,{className:`text-xs sm:text-sm font-normal text-bambu-gray`,children:[`(`,e(`queue.itemCount`,{count:Se.length}),`)`]}),(0,K.jsx)(`span`,{className:`hidden sm:inline text-xs text-bambu-gray ml-2`,title:e(`queue.reorderHint`),children:e(`queue.dragToReorder`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`select`,{className:`px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:k,onChange:e=>A(e.target.value),children:[(0,K.jsx)(`option`,{value:`position`,children:e(`queue.sort.byPosition`)}),(0,K.jsx)(`option`,{value:`name`,children:e(`queue.sort.byName`)}),(0,K.jsx)(`option`,{value:`printer`,children:e(`queue.sort.byPrinter`)}),(0,K.jsx)(`option`,{value:`time`,children:e(`queue.sort.bySchedule`)})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>M(!j),title:e(j?`common.ascending`:`common.descending`),className:`px-2`,children:j?(0,K.jsx)(Mo,{className:`w-4 h-4`}):(0,K.jsx)(Eo,{className:`w-4 h-4`})})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-3 sm:mb-4 p-2 sm:p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:Ce,className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm`,children:[x.length===Se.length&&Se.length>0?(0,K.jsx)($l,{className:`w-4 h-4 text-bambu-green`}):(0,K.jsx)(tu,{className:`w-4 h-4`}),x.length===Se.length&&Se.length>0?e(`queue.bulkEdit.deselectAll`):e(`queue.bulkEdit.selectAll`)]}),x.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`text-xs sm:text-sm text-bambu-gray`,children:e(`queue.bulkEdit.selected`,{count:x.length})}),(0,K.jsx)(`div`,{className:`hidden sm:block h-4 w-px bg-bambu-dark-tertiary`}),Ie&&(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>ee(!0),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-cyan-300 hover:text-cyan-200`,title:e(`queue.batch.groupAsBatch`),children:[(0,K.jsx)(cl,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.batch.groupAsBatch`)})]}),(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>w(!0),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-bambu-green hover:text-bambu-green-light`,disabled:!i(`queue:update_own`,`queue:update_all`),title:i(`queue:update_own`,`queue:update_all`)?e(`queue.bulkEdit.editSelected`):e(`queue.permissions.noEditItems`),children:[(0,K.jsx)(pl,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.bulkEdit.editSelected`)})]}),(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>ge.mutate(x),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-red-400 hover:text-red-300`,disabled:ge.isPending||!i(`queue:delete_own`,`queue:delete_all`),title:i(`queue:delete_own`,`queue:delete_all`)?e(`queue.bulkEdit.cancelSelected`):e(`queue.permissions.noCancelItems`),children:[(0,K.jsx)(Pu,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.bulkEdit.cancelSelected`)})]})]})]}),(0,K.jsxs)(P8,{sensors:ne,collisionDetection:L6,onDragStart:Me,onDragEnd:Ne,children:[(0,K.jsx)(W8,{items:Fe,strategy:ALe,children:F===`position`?(0,K.jsx)(`div`,{className:`space-y-2 sm:space-y-3`,children:Pe.map(t=>(0,K.jsx)(a5,{row:t,collapsed:t.kind===`batch`?L[t.batchId]??!0:!1,onToggleBatch:t.kind===`batch`?()=>Le(t.batchId):void 0,onUngroup:t.kind===`batch`?()=>te(t.batchId):void 0,setEditItem:h,setConfirmAction:b,startMutation:fe,selectedItems:x,handleToggleSelect:ye,timeFormat:U,hasPermission:r,canModify:a,t:e,aggregateForRows:ze},t.kind===`item`?`item-${t.item.id}`:`batch-${t.batchId}`))}):(0,K.jsx)(`div`,{className:`space-y-4`,children:Re.map(t=>{let n=ze(t.rows);return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-t-lg`,children:[(0,K.jsx)(bl,{className:`w-4 h-4 ${t.isUnassigned?`text-orange-400`:t.targetModel?`text-blue-400`:`text-bambu-green`}`}),(0,K.jsx)(`span`,{className:`font-semibold text-white text-sm`,children:t.label}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray flex flex-wrap gap-x-3`,children:[(0,K.jsx)(`span`,{children:e(`queue.itemCount`,{count:n.count})}),n.time>0&&(0,K.jsx)(`span`,{children:yf(n.time)}),n.weight>0&&(0,K.jsx)(`span`,{children:n5(n.weight)})]})]}),(0,K.jsx)(`div`,{className:`bg-bambu-dark/40 border border-t-0 border-bambu-dark-tertiary rounded-b-lg p-2 space-y-2`,children:t.rows.map(t=>(0,K.jsx)(a5,{row:t,collapsed:t.kind===`batch`?L[t.batchId]??!0:!1,onToggleBatch:t.kind===`batch`?()=>Le(t.batchId):void 0,onUngroup:t.kind===`batch`?()=>te(t.batchId):void 0,setEditItem:h,setConfirmAction:b,startMutation:fe,selectedItems:x,handleToggleSelect:ye,timeFormat:U,hasPermission:r,canModify:a,t:e,aggregateForRows:ze},t.kind===`item`?`item-${t.item.id}`:`batch-${t.batchId}`))})]},t.key)})})}),(0,K.jsx)(ELe,{children:z!==null&&x.includes(z)&&x.length>1?(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border-2 border-cyan-400 rounded-lg shadow-2xl`,children:[(0,K.jsx)(cl,{className:`w-4 h-4 text-cyan-300`}),(0,K.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e(`queue.dragGhost.multiCount`,{count:x.length})})]}):null})]})]})]}),m&&(0,K.jsx)(sq,{mode:`edit-queue-item`,archiveId:m.archive_id??void 0,libraryFileId:m.library_file_id??void 0,archiveName:m.archive_name||m.library_file_name||`File #${m.archive_id||m.library_file_id}`,queueItem:m,onClose:()=>h(null)}),g&&(0,K.jsx)(sq,{mode:`add-to-queue`,archiveId:g.archive_id??void 0,libraryFileId:g.library_file_id??void 0,archiveName:g.archive_name||g.library_file_name||`File #${g.archive_id||g.library_file_id}`,onClose:()=>_(null)}),ue&&(0,K.jsx)(Ed,{title:e(`queue.filamentShort.confirmTitle`),message:e(`queue.filamentShort.confirmIntro`)+` `+ue.deficit.map(t=>e(`queue.filamentShort.lineItem`,{slot:t.slot_id,required:Math.round(t.required_grams),remaining:t.remaining_grams==null?e(`queue.filamentShort.unknown`):Math.round(t.remaining_grams)})).join(` -`),confirmText:e(`queue.filamentShort.printAnyway`),variant:`warning`,onConfirm:()=>{fe.mutate({id:ue.itemId,skipFilamentCheck:!0})},onCancel:()=>de(null)}),v&&(0,K.jsx)(Ed,{title:v.type===`cancel`?e(`queue.confirm.cancelTitle`):v.type===`stop`?e(`queue.confirm.stopTitle`):e(`queue.confirm.removeTitle`),message:v.type===`cancel`?e(`queue.confirm.cancelMessage`,{name:v.item.archive_name||v.item.library_file_name||e(`queue.confirm.thisPrint`)}):v.type===`stop`?e(`queue.confirm.stopMessage`,{name:v.item.archive_name||v.item.library_file_name||e(`queue.confirm.thisPrint`)}):e(`queue.confirm.removeMessage`,{name:v.item.archive_name||v.item.library_file_name||e(`queue.confirm.thisItem`)}),confirmText:v.type===`cancel`?e(`queue.confirm.cancelButton`):v.type===`stop`?e(`queue.confirm.stopButton`):e(`common.remove`),variant:`danger`,onConfirm:()=>{v.type===`cancel`?se.mutate(v.item.id):v.type===`stop`?le.mutate(v.item.id):ce.mutate(v.item.id),b(null)},onCancel:()=>b(null)}),f&&(0,K.jsx)(Ed,{title:e(`queue.confirm.clearHistoryTitle`),message:e(`queue.confirm.clearHistoryMessage`,{count:ke.length}),confirmText:e(`queue.clearHistory`),variant:`danger`,onConfirm:()=>{me.mutate(),p(!1)},onCancel:()=>p(!1)}),C&&(0,K.jsx)(JLe,{selectedCount:x.length,printers:W?.map(e=>({id:e.id,name:e.name,nozzle_count:e.nozzle_count}))||[],onSave:e=>{Object.keys(e).length>0&&he.mutate({item_ids:x,...e})},onClose:()=>w(!1),isSaving:he.isPending,canControlPrinter:r(`printers:control`),t:e}),V&&(0,K.jsx)(ZLe,{itemCount:x.length,isSaving:_e.isPending,defaultName:(()=>{let t=Se.find(e=>x.includes(e.id)),n=(t?.archive_name||t?.library_file_name||``).replace(/\.gcode\.3mf$/i,``).replace(/\.3mf$/i,``);return n?`${n}`:e(`queue.batch.defaultName`)})(),onSave:e=>_e.mutate({name:e,item_ids:x}),onClose:()=>ee(!1),t:e}),H!==null&&(0,K.jsx)(Ed,{title:e(`queue.batch.ungroupConfirmTitle`),message:e(`queue.batch.ungroupConfirmMessage`),confirmText:e(`queue.batch.ungroup`),variant:`warning`,onConfirm:()=>ve.mutate(H),onCancel:()=>te(null)})]})}function ZLe({itemCount:e,defaultName:t,isSaving:n,onSave:r,onClose:i,t:a}){let[o,s]=(0,y.useState)(t);return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 w-full max-w-md`,children:[(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white mb-2 flex items-center gap-2`,children:[(0,K.jsx)(cl,{className:`w-5 h-5 text-cyan-300`}),a(`queue.batch.groupAsBatch`)]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:a(`queue.batch.groupAsBatchDescription`,{count:e})}),(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:a(`queue.batch.nameLabel`)}),(0,K.jsx)(`input`,{type:`text`,autoFocus:!0,value:o,onChange:e=>s(e.target.value),placeholder:a(`queue.batch.namePlaceholder`),maxLength:120,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none mb-5`}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:i,disabled:n,children:a(`common.cancel`)}),(0,K.jsx)($,{variant:`primary`,size:`sm`,onClick:()=>{let e=o.trim();e&&r(e)},disabled:n||!o.trim(),children:a(n?`common.saving`:`queue.batch.create`)})]})]})})}function QLe({printDates:e,months:t=3}){let n=(0,y.useRef)(null),[r,i]=(0,y.useState)(0);(0,y.useEffect)(()=>{let e=n.current;if(!e)return;let t=new ResizeObserver(e=>{i(e[0]?.contentRect.width||0)});return t.observe(e),()=>t.disconnect()},[]);let{weeks:a,monthLabels:o,printCounts:s}=(0,y.useMemo)(()=>{let n={};e.forEach(e=>{let t=Cf(e);t&&(n[t]=(n[t]||0)+1)});let r=new Date,i=new Date(r);i.setMonth(i.getMonth()-t),i.setDate(i.getDate()-i.getDay());let a=[],o=[],s=[],c=-1,l=new Date(i),u=0;for(;l<=r;)l.getDay()===0&&s.length>0&&(a.push(s),s=[],u++),l.getMonth()!==c&&(o.push({month:l.toLocaleDateString(`en-US`,{month:`short`}),weekIndex:u}),c=l.getMonth()),s.push(new Date(l)),l.setDate(l.getDate()+1);return s.length>0&&a.push(s),{weeks:a,monthLabels:o,printCounts:n}},[e,t]),c=Math.max(1,...Object.values(s)),l=e=>{if(e===0)return`bg-bambu-dark`;let t=e/c;return t<=.25?`bg-bambu-green/30`:t<=.5?`bg-bambu-green/50`:t<=.75?`bg-bambu-green/75`:`bg-bambu-green`},u=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],d=a.length,f=r-32-16,p=d>0?Math.floor((f-(d-1)*2)/d):12,m=Math.max(8,Math.min(20,p)),h=m<=10?10:12;return(0,K.jsx)(`div`,{ref:n,className:`w-full flex justify-center`,children:r>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`flex mb-1`,style:{marginLeft:36},children:o.map(({month:e,weekIndex:t},n)=>(0,K.jsx)(`div`,{className:`text-bambu-gray`,style:{fontSize:h,marginLeft:n===0?0:`${(t-(o[n-1]?.weekIndex||0))*(m+2)-24}px`},children:e},n))}),(0,K.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,K.jsx)(`div`,{className:`flex flex-col`,style:{gap:2,marginRight:4,width:32},children:u.map((e,t)=>(0,K.jsx)(`div`,{className:`text-bambu-gray flex items-center`,style:{width:32,height:m,fontSize:h,visibility:t%2==1?`visible`:`hidden`},children:e},e))}),a.map((e,t)=>(0,K.jsx)(`div`,{className:`flex flex-col`,style:{gap:2},children:[0,1,2,3,4,5,6].map(t=>{let n=e.find(e=>e.getDay()===t);if(!n)return(0,K.jsx)(`div`,{style:{width:m,height:m}},t);let r=Cf(n),i=s[r]||0,a=r===Cf(new Date);return(0,K.jsx)(`div`,{className:`rounded-sm ${l(i)} ${a?`ring-1 ring-white`:``}`,style:{width:m,height:m},title:`${n.toLocaleDateString()}: ${i} print${i===1?``:`s`}`},t)})},t))]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-3 text-bambu-gray`,style:{fontSize:h},children:[(0,K.jsx)(`span`,{children:`Less`}),(0,K.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-dark`,style:{width:m,height:m}}),(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-green/30`,style:{width:m,height:m}}),(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-green/50`,style:{width:m,height:m}}),(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-green/75`,style:{width:m,height:m}}),(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-green`,style:{width:m,height:m}})]}),(0,K.jsx)(`span`,{children:`More`})]})]})})}var o5=[`weight`,`prints`,`time`];function s5({value:e,onChange:t,exclude:n}){let{t:r}=G(),i={weight:r(`stats.filamentByWeight`),prints:r(`stats.filamentByPrints`),time:r(`stats.filamentByTime`)};return(0,K.jsx)(`div`,{className:`flex gap-0.5 bg-bambu-dark rounded-lg p-0.5`,children:(n?o5.filter(e=>!n.includes(e)):o5).map(n=>(0,K.jsx)(`button`,{onClick:()=>t(n),className:`px-2 py-0.5 text-xs rounded-md transition-colors ${e===n?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:i[n]},n))})}function c5(e){if(e>=1e6){let t=e/1e6;return`${t%1==0?t.toFixed(0):t.toFixed(1)}t`}if(e>=1e3){let t=e/1e3;return`${t%1==0?t.toFixed(0):t.toFixed(1)}kg`}return`${Math.round(e)}g`}var l5=[`#00ae42`,`#3b82f6`,`#f59e0b`,`#ef4444`,`#8b5cf6`,`#ec4899`,`#14b8a6`,`#f97316`],$Le=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],u5=[`12am`,`1am`,`2am`,`3am`,`4am`,`5am`,`6am`,`7am`,`8am`,`9am`,`10am`,`11am`,`12pm`,`1pm`,`2pm`,`3pm`,`4pm`,`5pm`,`6pm`,`7pm`,`8pm`,`9pm`,`10pm`,`11pm`];function eRe({archives:e,currency:t=`$`,dateFrom:n,dateTo:r}){let{t:i}=G(),[a,o]=(0,y.useState)(`weight`),[s,c]=(0,y.useState)(`weight`),l=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=mf(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)||{date:r,filament:0,cost:0,prints:0};i.filament+=e.filament_used_grams||0,i.cost+=e.cost||0,i.prints+=e.quantity||1,t.set(r,i)}),Array.from(t.values()).sort((e,t)=>e.date.localeCompare(t.date)).map(e=>({...e,dateLabel:new Date(e.date).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}))},[e]),u=(0,y.useMemo)(()=>{if(n&&r)return Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1;if(n)return Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1;if(e.length<2)return 0;let t=e.map(e=>new Date(e.completed_at||e.created_at).getTime());return(Math.max(...t)-Math.min(...t))/864e5},[e,n,r]),d=(0,y.useMemo)(()=>{if(u>7)return[];let t=new Map,n=u>1;return e.forEach(e=>{let n=mf(e.completed_at||e.created_at)||new Date,r=n.getHours(),i=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}T${String(r).padStart(2,`0`)}`,a=t.get(i)||{date:i,filament:0,cost:0,prints:0};a.filament+=e.filament_used_grams||0,a.cost+=e.cost||0,a.prints+=e.quantity||1,t.set(i,a)}),Array.from(t.values()).sort((e,t)=>e.date.localeCompare(t.date)).map(e=>{let[t,r]=e.date.split(`T`),i=new Date(t),a=parseInt(r,10),o=n?`${$Le[i.getDay()]} ${u5[a]}`:u5[a];return{...e,dateLabel:o}})},[e,u]),f=(0,y.useMemo)(()=>{if(l.length<=60)return l;let e=new Map;return l.forEach(t=>{let n=new Date(t.date),r=new Date(n);r.setDate(n.getDate()-n.getDay());let i=`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,`0`)}-${String(r.getDate()).padStart(2,`0`)}`,a=e.get(i)||{week:i,filament:0,cost:0,prints:0};a.filament+=t.filament,a.cost+=t.cost,a.prints+=t.prints,e.set(i,a)}),Array.from(e.values()).sort((e,t)=>e.week.localeCompare(t.week)).map(e=>({date:e.week,dateLabel:`Week of ${new Date(e.week).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}`,...e}))},[l]),p=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=(e.filament_type||`Unknown`).split(`, `);n.forEach(r=>{let i=(e.filament_used_grams||0)/n.length;t.set(r,(t.get(r)||0)+i)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:Math.round(t)})).sort((e,t)=>t.value-e.value)},[e]),m=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{(e.filament_type||`Unknown`).split(`, `).forEach(e=>{t.set(e,(t.get(e)||0)+1)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:t})).sort((e,t)=>t.value-e.value)},[e]),h=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=(e.filament_type||`Unknown`).split(`, `),r=(e.actual_time_seconds||e.print_time_seconds||0)/n.length;n.forEach(e=>{t.set(e,(t.get(e)||0)+r)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:Math.round(t/3600*10)/10})).sort((e,t)=>t.value-e.value)},[e]),g=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{e.status!==`completed`&&e.status!==`failed`||(e.filament_type||`Unknown`).split(`, `).forEach(n=>{let r=t.get(n)||{completed:0,failed:0};e.status===`completed`?r.completed++:r.failed++,t.set(n,r)})}),Array.from(t.entries()).filter(([,e])=>e.completed+e.failed>=2).map(([e,t])=>{let n=t.completed+t.failed;return{name:e,rate:Math.round(t.completed/n*100),total:n}}).sort((e,t)=>t.rate-e.rate)},[e]),_=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{if(!e.filament_color)return;let n=e.filament_color.split(`,`).map(e=>e.trim()),r=(e.filament_used_grams||0)/n.length;n.forEach(e=>{let n=t.get(e)||{count:0,weight:0};n.count++,n.weight+=r,t.set(e,n)})}),Array.from(t.entries()).map(([e,t])=>({hex:e,value:s===`prints`?t.count:Math.round(t.weight)})).sort((e,t)=>t.value-e.value)},[e,s]),v=a===`weight`?p:a===`prints`?m:h,b=u<=7&&d.length>0?d:f,x=e.reduce((e,t)=>e+(t.filament_used_grams||0),0),S=e.reduce((e,t)=>e+(t.cost||0),0),C=e.reduce((e,t)=>e+(t.quantity||1),0),w=new Set(e.map(e=>e.printer_id).filter(Boolean)).size;return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-[640px]:grid-cols-1`,children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:i(`stats.periodFilament`)}),(0,K.jsx)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:c5(x)})]}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[w,` `,i(`nav.printers`).toLowerCase()]})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:i(`stats.periodCost`)}),(0,K.jsxs)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:[t,S.toFixed(2)]})]}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[C,` `,i(`common.prints`)]})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:i(`stats.avgPerPrint`)}),(0,K.jsxs)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:[C>0?(x/C).toFixed(0):0,`g`]})]}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[t,C>0?(S/C).toFixed(2):`0.00`,` avg`]})]})]}),b.length>0?(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-4`,children:i(`stats.usageOverTime`)}),(0,K.jsx)(RA,{width:`100%`,height:250,children:(0,K.jsxs)(WG,{data:b,children:[(0,K.jsx)(`defs`,{children:(0,K.jsxs)(`linearGradient`,{id:`colorFilament`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,K.jsx)(`stop`,{offset:`5%`,stopColor:`#00ae42`,stopOpacity:.3}),(0,K.jsx)(`stop`,{offset:`95%`,stopColor:`#00ae42`,stopOpacity:0})]})}),(0,K.jsx)(XU,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,K.jsx)(eG,{dataKey:`dateLabel`,stroke:`#9ca3af`,tick:{fontSize:12},interval:`preserveStartEnd`}),(0,K.jsx)(aG,{stroke:`#9ca3af`,tick:{fontSize:12},tickFormatter:e=>`${e}g`}),(0,K.jsx)(Xz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},labelStyle:{color:`#fff`},formatter:e=>[`${Number(e??0).toFixed(0)}g`,`Filament`]}),(0,K.jsx)(MW,{type:`monotone`,dataKey:`filament`,stroke:`#00ae42`,strokeWidth:2,fillOpacity:1,fill:`url(#colorFilament)`})]})})]}):(0,K.jsx)(`div`,{className:`bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray`,children:i(`stats.noPrintDataInRange`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:i(`stats.byMaterial`)}),(0,K.jsx)(s5,{value:a,onChange:o})]}),v.length>0?(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(RA,{width:160,height:160,children:(0,K.jsxs)(UG,{children:[(0,K.jsx)(BH,{data:v,cx:`50%`,cy:`50%`,innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:`value`,children:v.map((e,t)=>(0,K.jsx)(Zz,{fill:l5[t%l5.length]},`cell-${t}`))}),(0,K.jsx)(Xz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},formatter:e=>[a===`weight`?c5(Number(e??0)):a===`time`?`${Number(e??0)}h`:`${e??0}`,a===`weight`?`Usage`:a===`time`?`Time`:`Prints`]})]})}),(0,K.jsx)(`div`,{className:`flex-1 space-y-2 overflow-hidden`,children:v.map((e,t)=>{let n=v.reduce((e,t)=>e+t.value,0),r=n>0?(e.value/n*100).toFixed(0):0;return(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-sm flex-shrink-0`,style:{backgroundColor:l5[t%l5.length]}}),(0,K.jsx)(`span`,{className:`text-white truncate flex-1`,children:e.name}),(0,K.jsxs)(`span`,{className:`text-bambu-gray flex-shrink-0`,children:[a===`weight`?c5(e.value):a===`time`?`${e.value}h`:e.value,` · `,r,`%`]})]},e.name)})})]}):(0,K.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:i(`stats.noFilamentData`)})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-4`,children:i(`stats.filamentSuccess`)}),g.length>0?(0,K.jsx)(`div`,{className:`space-y-1.5`,children:g.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`span`,{className:`text-white truncate w-20 flex-shrink-0`,children:e.name}),(0,K.jsx)(`div`,{className:`flex-1 h-1.5 bg-bambu-dark-secondary rounded-full`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all ${e.rate>=90?`bg-status-ok`:e.rate>=70?`bg-status-warning`:`bg-status-error`}`,style:{width:`${e.rate}%`}})}),(0,K.jsxs)(`span`,{className:`font-medium flex-shrink-0 tabular-nums ${e.rate>=90?`text-status-ok`:e.rate>=70?`text-status-warning`:`text-status-error`}`,children:[e.rate,`%`]}),(0,K.jsxs)(`span`,{className:`text-bambu-gray flex-shrink-0 text-xs`,children:[`(`,e.total,`)`]})]},e.name))}):(0,K.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:i(`stats.noArchiveData`)})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:i(`stats.colorDistribution`)}),(0,K.jsx)(s5,{value:s,onChange:c,exclude:[`time`]})]}),_.length>0?(()=>{let e=_.reduce((e,t)=>e+t.value,0);return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`relative mx-auto`,style:{width:160,height:160},children:[(0,K.jsx)(RA,{width:`100%`,height:`100%`,children:(0,K.jsxs)(UG,{children:[(0,K.jsx)(BH,{data:_,cx:`50%`,cy:`50%`,innerRadius:45,outerRadius:70,paddingAngle:2,dataKey:`value`,children:_.map((e,t)=>(0,K.jsx)(Zz,{fill:e.hex,stroke:`#1a1a1a`,strokeWidth:1},`color-${t}`))}),(0,K.jsx)(Xz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},formatter:e=>[s===`weight`?c5(Number(e??0)):`${e??0}`,i(s===`weight`?`stats.filamentByWeight`:`stats.filamentByPrints`)]})]})}),(0,K.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,K.jsx)(`span`,{className:`text-lg font-bold text-white`,children:s===`weight`?c5(e):e}),(0,K.jsxs)(`span`,{className:`text-[10px] text-bambu-gray`,children:[_.length,` `,_.length===1?`color`:`colors`]})]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-1 mt-2`,children:_.slice(0,8).map(t=>{let n=e>0?(t.value/e*100).toFixed(0):0;return(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs min-w-0`,children:[(0,K.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 border border-black/20`,style:{backgroundColor:t.hex}}),(0,K.jsxs)(`span`,{className:`text-bambu-gray truncate`,children:[n,`%`]})]},t.hex)})}),_.length>8&&(0,K.jsxs)(`p`,{className:`text-[10px] text-bambu-gray mt-1 text-center`,children:[`+`,_.length-8,` more`]})]})})():(0,K.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:i(`stats.noColorData`)})]})]})]})}function tRe({id:e,title:t,component:n,isHidden:r,size:i,columnSpan:a,onToggleVisibility:o,onToggleSize:s}){let{attributes:c,listeners:l,setNodeRef:u,transform:d,transition:f,isDragging:p}=K8({id:e}),m={transform:w6.Transform.toString(d),transition:f,opacity:p?.5:1};return r?null:(0,K.jsxs)(`div`,{ref:u,style:{...m,gridColumn:`span ${a}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${p?`ring-2 ring-bambu-green shadow-lg`:``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{...c,...l,className:`cursor-grab active:cursor-grabbing p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Drag to reorder`,children:(0,K.jsx)(gc,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray`})}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:t})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:s,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Size: ${i===1?`1/4`:i===2?`1/2`:`Full`} - Click to cycle`,children:i===4?(0,K.jsx)(Qc,{className:`w-4 h-4 text-bambu-gray hover:text-white`}):(0,K.jsx)(Jc,{className:`w-4 h-4 text-bambu-gray hover:text-white`})}),(0,K.jsx)(`button`,{onClick:o,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Hide widget`,children:(0,K.jsx)(Ws,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]})]}),(0,K.jsx)(`div`,{className:`p-4`,children:typeof n==`function`?n(i):n})]})}function nRe({widgets:e,storageKey:t,columns:n=4,stackBelow:r,hideControls:i=!1,onResetLayout:a,renderControls:o}){let s=()=>{let t={};return e.forEach(e=>{t[e.id]=e.defaultSize||4}),t},[c,l]=(0,y.useState)(()=>{let n=localStorage.getItem(t);if(n)try{let e=JSON.parse(n);if(!e.sizes)e.sizes=s();else{let t=s();for(let n in t)n in e.sizes||(e.sizes[n]=t[n])}return e}catch{}return{order:e.map(e=>e.id),hidden:e.filter(e=>e.defaultVisible===!1).map(e=>e.id),sizes:s()}}),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(!1);(0,y.useEffect)(()=>{if(!r)return;let e=window.matchMedia(`(max-width: ${r}px)`),t=e=>{p(e.matches)};t(e);let n=e=>t(e);return e.addEventListener?e.addEventListener(`change`,n):e.addListener(n),()=>{e.removeEventListener?e.removeEventListener(`change`,n):e.removeListener(n)}},[r]);let m=r&&f?1:n;(0,y.useEffect)(()=>{let e=()=>d(e=>!e);return window.addEventListener(`toggle-hidden-panel`,e),()=>window.removeEventListener(`toggle-hidden-panel`,e)},[]),(0,y.useEffect)(()=>{localStorage.setItem(t,JSON.stringify(c))},[c,t]),(0,y.useEffect)(()=>{let t=e.map(e=>e.id).filter(e=>!c.order.includes(e));t.length>0&&l(e=>({...e,order:[...e.order,...t]}))},[e,c.order]);let h=A6(k6(u8,{activationConstraint:{distance:8}}),k6(o8,{coordinateGetter:J8})),g=e=>{let{active:t,over:n}=e;n&&t.id!==n.id&&l(e=>{let r=e.order.indexOf(t.id),i=e.order.indexOf(n.id);return{...e,order:R8(e.order,r,i)}})},_=e=>{l(t=>({...t,hidden:t.hidden.includes(e)?t.hidden.filter(t=>t!==e):[...t.hidden,e]}))},v=e=>{l(t=>{let n=t.sizes[e]||4,r=n===1?2:n===2?4:1;return{...t,sizes:{...t.sizes,[e]:r}}})},b=()=>{l({order:e.map(e=>e.id),hidden:e.filter(e=>e.defaultVisible===!1).map(e=>e.id),sizes:s()}),a?.()},x=c.order.map(t=>e.find(e=>e.id===t)).filter(Boolean),S=x.filter(e=>!c.hidden.includes(e.id)),C=x.filter(e=>c.hidden.includes(e.id)),w=o?.({hiddenCount:C.length,showHiddenPanel:u,setShowHiddenPanel:d,resetLayout:b});return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[w,!i&&!o&&(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:b,children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),`Reset Layout`]}),C.length>0&&(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>d(!u),children:[(0,K.jsx)(Gs,{className:`w-4 h-4`}),C.length,` Hidden`]})]}),u&&C.length>0&&(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:`Hidden widgets (click to show):`}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:C.map(e=>(0,K.jsxs)(`button`,{onClick:()=>_(e.id),className:`px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2`,children:[(0,K.jsx)(Gs,{className:`w-3 h-3`}),e.title]},e.id))})]}),(0,K.jsx)(P8,{sensors:h,collisionDetection:L6,onDragEnd:g,children:(0,K.jsx)(W8,{items:S.map(e=>e.id),strategy:B8,children:(0,K.jsx)(`div`,{className:`grid gap-6`,style:{gridTemplateColumns:`repeat(${m}, minmax(0, 1fr))`},children:S.map(e=>{let t=c.sizes[e.id]||2,n=Math.min(t,m);return(0,K.jsx)(tRe,{id:e.id,title:e.title,component:e.component,isHidden:c.hidden.includes(e.id),size:t,columnSpan:n,onToggleVisibility:()=>_(e.id),onToggleSize:()=>v(e.id)},e.id)})})})}),S.length===0&&(0,K.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,K.jsx)(`p`,{children:`All widgets are hidden.`}),(0,K.jsx)($,{className:`mt-4`,onClick:b,children:`Reset Layout`})]})]})}function rRe(e){let t=new Date,n=t.getUTCFullYear(),r=t.getUTCMonth(),i=t.getUTCDate(),a=e=>e.toISOString().split(`T`)[0],o=a(t);switch(e){case`today`:return{dateFrom:o,dateTo:o};case`this-week`:{let e=t.getUTCDay();return{dateFrom:a(new Date(Date.UTC(n,r,i-(e===0?6:e-1)))),dateTo:o}}case`this-month`:return{dateFrom:a(new Date(Date.UTC(n,r,1))),dateTo:o};case`last-7`:return{dateFrom:a(new Date(Date.UTC(n,r,i-6))),dateTo:o};case`last-30`:return{dateFrom:a(new Date(Date.UTC(n,r,i-29))),dateTo:o};case`last-90`:return{dateFrom:a(new Date(Date.UTC(n,r,i-89))),dateTo:o};case`this-year`:return{dateFrom:a(new Date(Date.UTC(n,0,1))),dateTo:o};case`all-time`:return{dateFrom:void 0,dateTo:void 0};case`custom`:return{}}}var iRe=[`today`,`this-week`,`this-month`,`last-7`,`last-30`,`last-90`,`this-year`,`all-time`],aRe=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],d5=[`12am`,`1am`,`2am`,`3am`,`4am`,`5am`,`6am`,`7am`,`8am`,`9am`,`10am`,`11am`,`12pm`,`1pm`,`2pm`,`3pm`,`4pm`,`5pm`,`6pm`,`7pm`,`8pm`,`9pm`,`10pm`,`11pm`],f5=[{key:`<30m`,max:1800},{key:`30m-1h`,max:3600},{key:`1-2h`,max:7200},{key:`2-4h`,max:14400},{key:`4-8h`,max:28800},{key:`8-12h`,max:43200},{key:`12-24h`,max:86400},{key:`24h+`,max:1/0}],p5={backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`};function oRe({stats:e,currency:t}){let{t:n}=G(),r=e?.energy_data_warming_up===!0,i=r?n(`stats.energyWarmingUpTooltip`):void 0;return(0,K.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-4`,children:[{icon:cl,color:`text-bambu-green`,label:n(`stats.totalPrints`),value:`${e?.total_prints||0}`},{icon:_s,color:`text-blue-400`,label:n(`stats.printTime`),value:`${e?.total_print_time_hours?.toFixed(1)??`0`}h`},{icon:cl,color:`text-orange-400`,label:n(`stats.filamentUsed`),value:c5(e?.total_filament_grams||0)},{icon:Ns,color:`text-green-400`,label:n(`stats.filamentCost`),value:`${t} ${e?.total_cost?.toFixed(2)??`0.00`}`},{icon:Iu,color:`text-yellow-400`,label:n(`stats.energyUsed`),value:`${e?.total_energy_kwh?.toFixed(3)??`0.000`} kWh`,warning:r,tooltip:i},{icon:Ns,color:`text-yellow-500`,label:n(`stats.energyCost`),value:`${t} ${e?.total_energy_cost?.toFixed(2)??`0.00`}`,warning:r,tooltip:i}].map(e=>(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,title:e.tooltip,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${e.color}`,children:(0,K.jsx)(e.icon,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray flex items-center gap-1`,children:[e.label,e.warning&&(0,K.jsx)(vu,{className:`w-3 h-3 text-yellow-400`,"aria-label":e.tooltip})]}),(0,K.jsx)(`p`,{className:`text-xl font-bold text-white`,children:e.value})]})]},e.label))})}function sRe({stats:e,printerMap:t,size:n=1}){let{t:r}=G(),i=(e?.successful_prints||0)+(e?.failed_prints||0),a=i?Math.round((e?.successful_prints||0)/i*100):0,o=n===1?112:n===2?128:144,s=o/2-8,c=s*2*Math.PI;return(0,K.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,K.jsxs)(`div`,{className:`relative flex-shrink-0`,style:{width:o,height:o},children:[(0,K.jsxs)(`svg`,{className:`w-full h-full -rotate-90`,children:[(0,K.jsx)(`circle`,{cx:o/2,cy:o/2,r:s,fill:`none`,stroke:`#3d3d3d`,strokeWidth:`10`}),(0,K.jsx)(`circle`,{cx:o/2,cy:o/2,r:s,fill:`none`,stroke:`#00ae42`,strokeWidth:`10`,strokeLinecap:`round`,strokeDasharray:`${a/100*c} ${c}`})]}),(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,K.jsxs)(`span`,{className:`font-bold text-white ${n>=2?`text-2xl`:`text-xl`}`,children:[a,`%`]})})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(ls,{className:`w-4 h-4 text-status-ok flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.successful`)}),(0,K.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.successful_prints||0})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(ms,{className:`w-4 h-4 text-status-error flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.failed`)}),(0,K.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.failed_prints||0})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(No,{className:`w-4 h-4 text-status-warning flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.cancelled`)}),(0,K.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.cancelled_prints||0})]})]}),n>=2&&e?.prints_by_printer&&Object.keys(e.prints_by_printer).length>0&&(0,K.jsxs)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray font-medium mb-2`,children:r(`stats.printsByPrinter`)}),(0,K.jsx)(`div`,{className:`grid gap-x-6 gap-y-1 ${n===4?`grid-cols-3`:`grid-cols-2`}`,style:{width:`fit-content`},children:Object.entries(e.prints_by_printer).map(([e,n])=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray truncate max-w-[120px]`,children:t.get(e)||`${r(`common.printer`)} ${e}`}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:n})]},e))})]})]})]})}function cRe({stats:e,printerMap:t,size:n=1}){let{t:r}=G(),i=e?.average_time_accuracy;if(i==null)return(0,K.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,K.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noTimeAccuracyData`)})});let a=(Math.min(150,Math.max(50,i))-50)/100*100,o=(e=>e>=95&&e<=105?`#00ae42`:e>105?`#3b82f6`:`#f97316`)(i),s=i-100,c=n===1?112:n===2?128:144,l=c/2-8,u=l*2*Math.PI,d=n===1?3:n===2?6:999,f=e?.time_accuracy_by_printer?Object.entries(e.time_accuracy_by_printer).slice(0,d):[];return(0,K.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,K.jsxs)(`div`,{className:`relative flex-shrink-0`,style:{width:c,height:c},children:[(0,K.jsxs)(`svg`,{className:`w-full h-full -rotate-90`,children:[(0,K.jsx)(`circle`,{cx:c/2,cy:c/2,r:l,fill:`none`,stroke:`#3d3d3d`,strokeWidth:`10`}),(0,K.jsx)(`circle`,{cx:c/2,cy:c/2,r:l,fill:`none`,stroke:o,strokeWidth:`10`,strokeLinecap:`round`,strokeDasharray:`${a/100*u} ${u}`})]}),(0,K.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,K.jsxs)(`span`,{className:`font-bold text-white ${n>=2?`text-2xl`:`text-xl`}`,children:[i.toFixed(0),`%`]}),(0,K.jsxs)(`span`,{className:`text-xs ${s>=0?`text-blue-400`:`text-orange-400`}`,children:[s>=0?`+`:``,s.toFixed(0),`%`]})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:[(0,K.jsx)(cu,{className:`w-3 h-3 flex-shrink-0`}),(0,K.jsx)(`span`,{children:r(`stats.perfectEstimate`)})]}),f.length>0&&(0,K.jsx)(`div`,{className:`mt-2 ${n===4?`grid grid-cols-3 gap-x-6 gap-y-1`:n===2?`grid grid-cols-2 gap-x-6 gap-y-1`:`space-y-1`}`,style:{width:`fit-content`},children:f.map(([e,n])=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray truncate max-w-[100px]`,children:t.get(e)||`${r(`common.printer`)} ${e}`}),(0,K.jsxs)(`span`,{className:`font-medium ${n>=95&&n<=105?`text-status-ok`:n>105?`text-blue-400`:`text-status-warning`}`,children:[n.toFixed(0),`%`]})]},e))})]})]})}function lRe({printDates:e,dateFrom:t,dateTo:n}){let{days:r,hourlyCounts:i,maxCount:a}=(0,y.useMemo)(()=>{let r=new Date(t+`T00:00:00`),i=new Date(n+`T00:00:00`),a=[],o=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`,s=new Date(r);for(;s<=i;)a.push({key:o(s),label:s.toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`})}),s.setDate(s.getDate()+1);let c={},l=0;return e.forEach(e=>{let t=mf(e);if(!t)return;let n=`${`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}-${t.getHours()}`;c[n]=(c[n]||0)+1,c[n]>l&&(l=c[n])}),{days:a,hourlyCounts:c,maxCount:Math.max(1,l)}},[e,t,n]),o=e=>{if(e===0)return`bg-bambu-dark`;let t=e/a;return t<=.25?`bg-bambu-green/30`:t<=.5?`bg-bambu-green/50`:t<=.75?`bg-bambu-green/75`:`bg-bambu-green`};return(0,K.jsxs)(`div`,{className:`w-full overflow-x-auto`,children:[(0,K.jsxs)(`div`,{className:`inline-flex flex-col`,style:{gap:2},children:[(0,K.jsx)(`div`,{className:`flex`,style:{gap:2,marginLeft:84},children:d5.map((e,t)=>(0,K.jsx)(`div`,{className:`text-bambu-gray text-[10px] text-center`,style:{width:20,visibility:t%2==0?`visible`:`hidden`},children:e},t))}),r.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center`,style:{gap:2},children:[(0,K.jsx)(`div`,{className:`text-bambu-gray text-[10px] flex-shrink-0 truncate`,style:{width:80},children:e.label}),Array.from({length:24},(t,n)=>{let r=i[`${e.key}-${n}`]||0;return(0,K.jsx)(`div`,{className:`rounded-sm ${o(r)}`,style:{width:20,height:20},title:`${e.label} ${d5[n]}: ${r} print${r===1?``:`s`}`},n)})]},e.key))]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-3 text-bambu-gray text-xs`,children:[(0,K.jsx)(`span`,{children:`Less`}),(0,K.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-dark`,style:{width:20,height:20}}),(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-green/30`,style:{width:20,height:20}}),(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-green/50`,style:{width:20,height:20}}),(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-green/75`,style:{width:20,height:20}}),(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-green`,style:{width:20,height:20}})]}),(0,K.jsx)(`span`,{children:`More`})]})]})}function uRe({printDates:e,size:t=2,dateFrom:n,dateTo:r}){let i=(0,y.useMemo)(()=>n&&r?Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1:n?Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1:1/0,[n,r]);return i<=7&&n&&r?(0,K.jsx)(lRe,{printDates:e,dateFrom:n,dateTo:r}):(0,K.jsx)(QLe,{printDates:e,months:i===1/0?t===1?3:t===2?6:12:Math.max(1,Math.ceil(i/30))})}function dRe({stats:e,archives:t,printerMap:n}){let{t:r}=G(),[i,a]=(0,y.useState)(`weight`),[o,s]=(0,y.useState)(`weight`),c=(0,y.useMemo)(()=>{let a=new Map;return e?.prints_by_printer&&Object.entries(e.prints_by_printer).forEach(([e,t])=>{let n=a.get(e)||{prints:0,weight:0,time:0};n.prints=t,a.set(e,n)}),t.forEach(t=>{if(!t.printer_id)return;let n=String(t.printer_id),r=a.get(n)||{prints:0,weight:0,time:0};r.weight+=t.filament_used_grams||0,r.time+=t.actual_time_seconds||t.print_time_seconds||0,e?.prints_by_printer||r.prints++,a.set(n,r)}),Array.from(a.entries()).map(([e,t])=>({name:n.get(e)||`${r(`common.printer`)} ${e}`,value:i===`prints`?t.prints:i===`weight`?Math.round(t.weight):Math.round(t.time/3600*10)/10})).sort((e,t)=>t.value-e.value)},[e,t,n,i,r]),l=(0,y.useMemo)(()=>{let e=Array.from({length:24},(e,t)=>({hour:t,label:d5[t],total:0,failures:0}));return t.forEach(t=>{if(!t.started_at)return;let n=mf(t.started_at);if(!n)return;let r=n.getHours();e[r].total++,t.status===`failed`&&e[r].failures++}),e},[t]),u=(0,y.useMemo)(()=>{let e=f5.map(e=>({name:e.key,count:0}));return t.forEach(t=>{let n=t.actual_time_seconds||t.print_time_seconds;if(!(!n||n<=0)){for(let t=0;t{let e=[0,0,0,0,0,0,0],n=new Set;t.forEach(t=>{let r=mf(t.created_at)||new Date(t.created_at),i=r.getDay()-1;i<0&&(i=6),o===`prints`?e[i]++:o===`weight`?e[i]+=t.filament_used_grams||0:e[i]+=(t.actual_time_seconds||t.print_time_seconds||0)/3600;let a=new Date(r);a.setDate(r.getDate()-(r.getDay()+6)%7),n.add(`${a.getFullYear()}-${String(a.getMonth()+1).padStart(2,`0`)}-${String(a.getDate()).padStart(2,`0`)}`)});let r=Math.max(n.size,1);return aRe.map((t,n)=>({name:t,avg:Math.round(e[n]/r*10)/10}))},[t,o]),f=e=>({unit:e===`weight`?`g`:e===`time`?`h`:``,color:e===`weight`?`#00ae42`:e===`time`?`#3b82f6`:`#f59e0b`}),p=f(i),m=r(i===`weight`?`stats.filamentByWeight`:i===`time`?`stats.hours`:`common.prints`),h=f(o),g=r(o===`weight`?`stats.avgWeight`:o===`time`?`stats.avgTime`:`stats.avgPrints`);return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:r(`stats.printsByPrinter`)}),(0,K.jsx)(s5,{value:i,onChange:a})]}),c.length>0?(0,K.jsx)(RA,{width:`100%`,height:Math.max(140,c.length*40),children:(0,K.jsxs)(RG,{data:c,layout:`vertical`,margin:{left:10},children:[(0,K.jsx)(XU,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,K.jsx)(eG,{type:`number`,stroke:`#9ca3af`,tick:{fontSize:11},unit:p.unit}),(0,K.jsx)(aG,{type:`category`,dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11},width:100}),(0,K.jsx)(Xz,{contentStyle:p5,formatter:e=>[i===`weight`?c5(Number(e??0)):`${e??0}${p.unit}`,m]}),(0,K.jsx)(KW,{dataKey:`value`,fill:p.color,radius:[0,4,4,0]})]})}):(0,K.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noPrinterData`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:r(`stats.printDuration`)}),t.length>0?(0,K.jsx)(RA,{width:`100%`,height:160,children:(0,K.jsxs)(RG,{data:u,children:[(0,K.jsx)(XU,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,K.jsx)(eG,{dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11}}),(0,K.jsx)(aG,{stroke:`#9ca3af`,tick:{fontSize:11},allowDecimals:!1}),(0,K.jsx)(Xz,{contentStyle:p5}),(0,K.jsx)(KW,{dataKey:`count`,name:r(`common.prints`),fill:`#00ae42`,radius:[4,4,0,0]})]})}):(0,K.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:r(`stats.printHabits`)}),(0,K.jsx)(s5,{value:o,onChange:s})]}),t.length>0?(0,K.jsx)(RA,{width:`100%`,height:160,children:(0,K.jsxs)(RG,{data:d,children:[(0,K.jsx)(XU,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,K.jsx)(eG,{dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11}}),(0,K.jsx)(aG,{stroke:`#9ca3af`,tick:{fontSize:11},unit:h.unit}),(0,K.jsx)(Xz,{contentStyle:p5,formatter:e=>[`${e??0}${h.unit}`,g]}),(0,K.jsx)(KW,{dataKey:`avg`,fill:h.color,radius:[4,4,0,0]})]})}):(0,K.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:r(`stats.printTimeOfDay`)}),t.length>0?(0,K.jsx)(RA,{width:`100%`,height:160,children:(0,K.jsxs)(RG,{data:l,children:[(0,K.jsx)(XU,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,K.jsx)(eG,{dataKey:`label`,stroke:`#9ca3af`,tick:{fontSize:10},interval:5}),(0,K.jsx)(aG,{stroke:`#9ca3af`,tick:{fontSize:11},allowDecimals:!1}),(0,K.jsx)(Xz,{contentStyle:p5}),(0,K.jsx)(KW,{dataKey:`total`,name:r(`stats.totalPrints`),fill:`#00ae42`,radius:[2,2,0,0]}),(0,K.jsx)(KW,{dataKey:`failures`,name:r(`stats.failed`),fill:`#ef4444`,radius:[2,2,0,0]})]})}):(0,K.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]})]})]})}function fRe({archives:e,currency:t,dateFrom:n,dateTo:r}){let{t:i}=G();return!e||e.length===0?(0,K.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:i(`stats.noPrintData`)}):(0,K.jsx)(eRe,{archives:e,currency:t,dateFrom:n,dateTo:r})}function pRe({size:e=1,dateFrom:t,dateTo:n,createdById:r}){let{t:i}=G(),a=!!(t||n),{data:o,isLoading:s}=q({queryKey:[`failureAnalysis`,t,n,r??`all`],queryFn:()=>Q.getFailureAnalysis({...a?{dateFrom:t,dateTo:n}:{days:30},createdById:r})});if(s)return(0,K.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})});if(!o||o.total_prints===0)return(0,K.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:i(a?`stats.noPrintDataInRange`:`stats.noPrintDataLast30Days`)});let c=e===1?5:e===2?8:999,l=Object.entries(o.failures_by_reason).sort(([,e],[,t])=>t-e),u=l.slice(0,c),d=l.length>c;return(0,K.jsxs)(`div`,{className:`${e>=2?`flex gap-8`:`space-y-4`}`,children:[(0,K.jsxs)(`div`,{className:e>=2?`flex-shrink-0`:``,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(vu,{className:`w-5 h-5 ${o.failure_rate>20?`text-status-error`:o.failure_rate>10?`text-status-warning`:`text-status-ok`}`}),(0,K.jsxs)(`span`,{className:`font-bold text-white ${e>=2?`text-3xl`:`text-2xl`}`,children:[o.failure_rate.toFixed(1),`%`]})]})}),(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray mt-1`,children:i(`stats.failedPrintsCount`,{failed:o.failed_prints,total:o.total_prints})}),o.trend&&o.trend.length>=2&&(0,K.jsx)(`div`,{className:`${e>=2?`mt-4`:`mt-2 pt-2 border-t border-bambu-dark-tertiary`}`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(gu,{className:`w-4 h-4 ${o.trend[o.trend.length-1].failure_rate0&&(0,K.jsxs)(`div`,{className:`flex-1 ${e>=2?`border-l border-bambu-dark-tertiary pl-8`:`pt-2`}`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray font-medium mb-2`,children:i(e>=2?`stats.failureReasons`:`stats.topFailureReasons`)}),(0,K.jsx)(`div`,{className:`${e===4?`grid grid-cols-2 gap-x-6 gap-y-1`:`space-y-1`}`,children:u.map(([t,n])=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,K.jsx)(`span`,{className:`text-white truncate ${e===4?`max-w-[200px]`:`max-w-[160px]`}`,children:t?i(`editArchive.failureReasons.${t}`,{defaultValue:t}):i(`common.unknown`)}),(0,K.jsx)(`span`,{className:`text-bambu-gray ml-2`,children:n})]},t))}),d&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:i(`common.more`,{count:l.length-c})})]})]})}function mRe({archives:e,currency:t}){let{t:n}=G(),r=(0,y.useMemo)(()=>{let r=[];if(e.length===0)return r;let i=t=>{let n=null,r=0;return e.forEach(e=>{let i=t(e);i&&i>r&&(r=i,n=e)}),{archive:n,value:r}},a=i(e=>e.status===`completed`?e.actual_time_seconds:null);a.archive&&r.push({icon:_s,iconColor:`text-blue-400`,label:n(`stats.longestPrint`),value:yf(a.value),detail:a.archive.print_name||null});let o=i(e=>e.filament_used_grams);o.archive&&r.push({icon:cl,iconColor:`text-orange-400`,label:n(`stats.heaviestPrint`),value:c5(o.value),detail:o.archive.print_name||null});let s=i(e=>e.cost);s.archive&&r.push({icon:Ns,iconColor:`text-green-400`,label:n(`stats.mostExpensivePrint`),value:`${t}${s.value.toFixed(2)}`,detail:s.archive.print_name||null});let c=new Map;e.forEach(e=>{let t=mf(e.created_at)||new Date(e.created_at),n=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`;c.set(n,(c.get(n)||0)+1)});let l=``,u=0;c.forEach((e,t)=>{e>u&&(u=e,l=t)}),u>1&&r.push({icon:qo,iconColor:`text-purple-400`,label:n(`stats.busiestDay`),value:`${u} ${n(`common.prints`)}`,detail:(()=>{let[e,t,n]=l.split(`-`).map(Number);return new Date(e,t-1,n).toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})})()});let d=[...e].filter(e=>e.status===`completed`||e.status===`failed`).sort((e,t)=>new Date(t.completed_at||t.created_at).getTime()-new Date(e.completed_at||e.created_at).getTime()),f=0;for(let e of d)if(e.status===`completed`)f++;else break;return f>0&&r.push({icon:Iu,iconColor:`text-yellow-400`,label:n(`stats.successStreak`),value:`${f}`,detail:f===1?n(`stats.streakPrint`):n(`stats.streakPrints`,{count:f})}),r},[e,t,n]);return r.length===0?(0,K.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:n(`stats.noArchiveData`)}):(0,K.jsx)(`div`,{className:`space-y-3`,children:r.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-1.5 rounded-lg bg-bambu-dark ${e.iconColor}`,children:(0,K.jsx)(e.icon,{className:`w-4 h-4`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.label}),(0,K.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-bold text-white`,children:e.value}),e.detail&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:e.detail})]})]})]},t))})}function hRe(){let{t:e}=G(),{showToast:t}=xd(),{hasPermission:n,authEnabled:r}=sd(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(0),[u,d]=(0,y.useState)(0),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(!1),v=r&&n(`stats:filter_by_user`),[b,x]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`bambusy-stats-timeframe`);if(e){let t=JSON.parse(e);if(t.preset)return t}}catch{}return{preset:`all-time`,dateFrom:void 0,dateTo:void 0}}),[S,C]=(0,y.useState)(!1);(0,y.useEffect)(()=>{localStorage.setItem(`bambusy-stats-timeframe`,JSON.stringify(b))},[b]);let w=(0,y.useMemo)(()=>b.preset===`custom`?{dateFrom:b.dateFrom,dateTo:b.dateTo}:rRe(b.preset),[b]);(0,y.useEffect)(()=>{let e=()=>{try{let e=localStorage.getItem(`bambusy-dashboard-layout-v2`);e&&d(JSON.parse(e).hidden?.length||0)}catch{d(0)}};e(),window.addEventListener(`storage`,e);let t=setInterval(e,2e3);return()=>{window.removeEventListener(`storage`,e),clearInterval(t)}},[c]);let T=m===null?void 0:m,{data:E,isLoading:D,isFetching:O,refetch:k}=q({queryKey:[`archiveStats`,w.dateFrom,w.dateTo,T??`all`],queryFn:()=>Q.getArchiveStats({dateFrom:w.dateFrom,dateTo:w.dateTo,createdById:T})}),{data:A}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:j,isFetching:M,refetch:N}=q({queryKey:[`archivesSlim`,w.dateFrom,w.dateTo,T??`all`],queryFn:()=>Q.getArchivesSlim(w.dateFrom,w.dateTo,T)}),{data:P}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:F}=q({queryKey:[`users`],queryFn:Q.getUsers,enabled:v}),I=(0,y.useMemo)(()=>m===null?e(`stats.allUsers`,`All Users`):m===-1?e(`stats.noUser`,`No User (System)`):F?.find(e=>e.id===m)?.username??`?`,[m,F,e]),L=async n=>{s(!1),a(!0);try{let{blob:r,filename:i}=await Q.exportStats({format:n,days:90,createdById:T}),a=URL.createObjectURL(r),o=document.createElement(`a`);o.href=a,o.download=i,o.click(),URL.revokeObjectURL(a),t(e(`stats.exportDownloaded`))}catch{t(e(`stats.exportFailed`),`error`)}finally{a(!1)}},R=async()=>{p(!0);try{let n=await Q.recalculateCosts();await Promise.all([k(),N()]),t(e(`stats.recalculatedCosts`,{count:n.updated}))}catch{t(e(`stats.recalculateFailed`),`error`)}finally{p(!1)}},z=(O||M)&&!D,B=Yd(P?.currency||`USD`),V=new Map(A?.map(e=>[String(e.id),e.name])||[]),ee=(0,y.useMemo)(()=>j?.map(e=>e.created_at)||[],[j]);if(D)return(0,K.jsx)(`div`,{className:`p-4 md:p-8`,children:(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`stats.loadingStats`)})});let H=[{id:`quick-stats`,title:e(`stats.quickStats`),component:(0,K.jsx)(oRe,{stats:E,currency:B}),defaultSize:2},{id:`success-rate`,title:e(`stats.successRate`),component:e=>(0,K.jsx)(sRe,{stats:E,printerMap:V,size:e}),defaultSize:1},{id:`time-accuracy`,title:e(`stats.timeAccuracy`),component:e=>(0,K.jsx)(cRe,{stats:E,printerMap:V,size:e}),defaultSize:1},{id:`failure-analysis`,title:e(`stats.failureAnalysis`),component:e=>(0,K.jsx)(pRe,{size:e,dateFrom:w.dateFrom,dateTo:w.dateTo,createdById:T}),defaultSize:1},{id:`print-activity`,title:e(`stats.printActivity`),component:e=>(0,K.jsx)(uRe,{printDates:ee,size:e,dateFrom:w.dateFrom,dateTo:w.dateTo}),defaultSize:2},{id:`records`,title:e(`stats.records`),component:(0,K.jsx)(mRe,{archives:j||[],currency:B}),defaultSize:1},{id:`printer-stats`,title:e(`stats.printerStats`),component:(0,K.jsx)(dRe,{stats:E,archives:j||[],printerMap:V}),defaultSize:4},{id:`filament-trends`,title:e(`stats.filamentTrends`),component:(0,K.jsx)(fRe,{archives:j||[],currency:B,dateFrom:w.dateFrom,dateTo:w.dateTo}),defaultSize:4}];return(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(Yo,{className:`w-7 h-7 text-bambu-green`}),e(`stats.title`)]}),z&&(0,K.jsx)(X,{className:`w-5 h-5 text-bambu-green animate-spin`})]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`stats.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u>0&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>{window.dispatchEvent(new CustomEvent(`toggle-hidden-panel`))},children:[(0,K.jsx)(Gs,{className:`w-4 h-4`}),e(`stats.hiddenCount`,{count:u})]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>{localStorage.removeItem(`bambusy-dashboard-layout-v2`),l(e=>e+1),t(e(`stats.layoutReset`))},disabled:!n(`settings:update`),title:n(`settings:update`)?void 0:e(`stats.noPermissionResetLayout`),children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),e(`stats.resetLayout`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:R,disabled:f||!n(`archives:update_all`),title:n(`archives:update_all`)?e(`stats.recalculateCostsHint`):e(`stats.noPermissionRecalculate`),children:[f?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Wo,{className:`w-4 h-4`}),e(`stats.recalculateCosts`)]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:()=>s(!o),disabled:i,children:[i?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Xs,{className:`w-4 h-4`}),e(`stats.exportStats`)]}),o&&(0,K.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20`,children:[(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg`,onClick:()=>L(`csv`),children:[(0,K.jsx)(Zs,{className:`w-4 h-4`}),e(`stats.exportAsCsv`)]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg`,onClick:()=>L(`xlsx`),children:[(0,K.jsx)(Xs,{className:`w-4 h-4`}),e(`stats.exportAsExcel`)]})]})]}),v&&F&&F.length>0&&(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:()=>_(!g),children:[(0,K.jsx)(wu,{className:`w-4 h-4`}),I,(0,K.jsx)(es,{className:`w-3 h-3`})]}),g&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>_(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2 max-h-64 overflow-y-auto`,children:[(0,K.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${m===null?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{h(null),_(!1)},children:e(`stats.allUsers`,`All Users`)}),(0,K.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${m===-1?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{h(-1),_(!1)},children:e(`stats.noUser`,`No User (System)`)}),(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary my-1`}),F.map(e=>(0,K.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${m===e.id?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{h(e.id),_(!1)},children:e.username},e.id))]})]})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:()=>C(!S),children:[(0,K.jsx)(qo,{className:`w-4 h-4`}),e(`stats.timeframe.${b.preset}`),(0,K.jsx)(es,{className:`w-3 h-3`})]}),S&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>C(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-64 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2`,children:[iRe.map(t=>(0,K.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${b.preset===t?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{x({preset:t,dateFrom:void 0,dateTo:void 0}),C(!1)},children:e(`stats.timeframe.${t}`)},t)),(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary my-2`}),(0,K.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${b.preset===`custom`?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>x(e=>({...e,preset:`custom`})),children:e(`stats.timeframe.custom`)}),b.preset===`custom`&&(0,K.jsxs)(`div`,{className:`mt-2 px-1 pb-1 space-y-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:e(`stats.timeframe.from`)}),(0,K.jsx)(`input`,{type:`date`,value:b.dateFrom||``,max:b.dateTo||new Date().toISOString().split(`T`)[0],onChange:e=>x(t=>({...t,dateFrom:e.target.value||void 0})),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white [color-scheme:dark]`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:e(`stats.timeframe.to`)}),(0,K.jsx)(`input`,{type:`date`,value:b.dateTo||``,min:b.dateFrom,max:new Date().toISOString().split(`T`)[0],onChange:e=>x(t=>({...t,dateTo:e.target.value||void 0})),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white [color-scheme:dark]`})]}),(0,K.jsx)($,{variant:`primary`,onClick:()=>C(!1),className:`w-full`,children:e(`common.apply`)})]})]})]})]})]})]}),(0,K.jsx)(nRe,{widgets:H,storageKey:`bambusy-dashboard-layout-v2`,stackBelow:640,hideControls:!0},c)]})}function m5(e){return e.length<8?`tooShort`:/[A-Z]/.test(e)?/[a-z]/.test(e)?/\d/.test(e)?/[^A-Za-z0-9]/.test(e)?null:`needsSpecial`:`needsDigit`:`needsLowercase`:`needsUppercase`}function gRe(){let{t:e}=G();return(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(cl,{className:`w-4 h-4 text-bambu-gray`}),e(`settings.slicerBundlesRemoved.title`,{defaultValue:`Slicer Bundles (removed)`})]})}),(0,K.jsxs)(hd,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.slicerBundlesRemoved.description`,{defaultValue:`Printer Preset Bundle (.bbscfg) import was removed. BambuStudio's bundle export only includes user-customised presets, so the import never delivered standard processes / filaments and slicing fell back to embedded settings.`})}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.slicerBundlesRemoved.alternatives`,{defaultValue:`Use Single Preset Import for individual customs, or sync via Bambu Cloud / Orca Cloud. Stock presets come from the slicer sidecar automatically.`})}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.slicerBundlesRemoved.lookupOrder`,{defaultValue:`Slice-time preset lookup order: 1) Imported (local), 2) Orca Cloud, 3) Bambu Cloud, 4) Standard (sidecar fallback).`})})]})]})}var h5=90,g5=365;function _5(e){if(!e)return`—`;let t=mf(e);return t?t.toLocaleString():`—`}function _Re(e){let t=mf(e);return t?t.getTime(){if(s.preventDefault(),r.trim()){c(!0);try{e(await Q.createLongLivedCameraToken({name:r.trim(),expires_in_days:a})),i(``),o(h5),n(t(`cameraTokens.toast.created`,`Token created`))}catch(e){n(e instanceof Error?e.message:t(`cameraTokens.toast.createFailed`,`Failed to create token`),`error`)}finally{c(!1)}}},className:`bg-bambu-dark-secondary rounded-lg p-4 mb-6 border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:t(`cameraTokens.create.title`,`Create new token`)}),(0,K.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-[1fr_140px_auto]`,children:[(0,K.jsx)(`input`,{type:`text`,maxLength:100,required:!0,value:r,onChange:e=>i(e.target.value),placeholder:t(`cameraTokens.create.namePlaceholder`,`e.g. Home Assistant`),className:`px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":t(`cameraTokens.create.nameLabel`,`Token name`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:g5,required:!0,value:a,onChange:e=>{let t=Number(e.target.value);o(Math.min(Math.max(t,1),g5))},className:`px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":t(`cameraTokens.create.daysLabel`,`Days until expiry`)}),(0,K.jsxs)(`button`,{type:`submit`,disabled:s||!r.trim(),className:`flex items-center gap-2 px-4 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),t(`cameraTokens.create.submit`,`Create`)]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:t(`cameraTokens.create.hint`,`Maximum lifetime is 365 days. The token value is shown only once on creation — copy it now.`)})]})}function yRe({token:e,onConfirm:t,onCancel:n}){let{t:r}=G();return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full border border-red-500/40`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,K.jsx)(vu,{className:`w-6 h-6 text-red-400 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`cameraTokens.confirmRevoke.title`,`Revoke this token?`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`cameraTokens.confirmRevoke.body`,`Any device using "{{name}}" will lose access immediately. This cannot be undone.`,{name:e.name})})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:n,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:r(`cameraTokens.confirmRevoke.cancel`,`Cancel`)}),(0,K.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600`,children:r(`cameraTokens.confirmRevoke.confirm`,`Revoke`)})]})]})})}function bRe({token:e,onClose:t}){let{t:n}=G(),{showToast:r}=xd(),i=e.token??``;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-2xl w-full border border-bambu-green/40`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,K.jsx)(vu,{className:`w-6 h-6 text-yellow-400 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`cameraTokens.created.title`,`Token created — copy it now`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:n(`cameraTokens.created.warning`,`This is the only time this token will be visible. After you close this dialog you can never view it again.`)})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,K.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:i}),(0,K.jsxs)(`button`,{type:`button`,onClick:async()=>{if(i)try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(i);else{let e=document.createElement(`textarea`);e.value=i,e.style.position=`fixed`,e.style.opacity=`0`,document.body.appendChild(e);try{e.select(),document.execCommand(`copy`)}finally{document.body.removeChild(e)}}r(n(`cameraTokens.toast.copied`,`Copied to clipboard`))}catch{r(n(`cameraTokens.toast.copyFailed`,`Copy failed — select and copy manually`),`error`)}},className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,K.jsx)(Ds,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]}),(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:n(`cameraTokens.created.dismiss`,`I've saved it`)})})]})})}function xRe({token:e,showOwner:t,ownerLabel:n,onRevoke:r}){let{t:i}=G(),a=_Re(e.expires_at);return(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,K.jsx)(`td`,{className:`py-3 px-3 text-white`,children:e.name}),t&&(0,K.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:n}),(0,K.jsxs)(`td`,{className:`py-3 px-3 text-bambu-gray font-mono text-xs`,children:[e.lookup_prefix,`…`]}),(0,K.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:_5(e.created_at)}),(0,K.jsxs)(`td`,{className:`py-3 px-3 ${a?`text-red-400`:`text-bambu-gray`}`,children:[_5(e.expires_at),a&&(0,K.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs bg-red-500/20 text-red-300 rounded`,children:i(`cameraTokens.list.expired`,`Expired`)})]}),(0,K.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:_5(e.last_used_at)}),(0,K.jsx)(`td`,{className:`py-3 px-3 text-right`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>r(e.id),className:`inline-flex items-center gap-1 px-2 py-1 text-sm text-red-400 hover:text-red-300`,title:i(`cameraTokens.list.revoke`,`Revoke`),children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),i(`cameraTokens.list.revoke`,`Revoke`)]})})]})}function v5({tokens:e,showOwner:t,userIdToName:n,onRevoke:r,emptyMessage:i}){let{t:a}=G();return e.length===0?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:i}):(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`text-bambu-gray text-left border-b border-bambu-dark-tertiary`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.name`,`Name`)}),t&&(0,K.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.owner`,`Owner`)}),(0,K.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.prefix`,`Prefix`)}),(0,K.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.created`,`Created`)}),(0,K.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.expires`,`Expires`)}),(0,K.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.lastUsed`,`Last used`)}),(0,K.jsx)(`th`,{className:`py-2 px-3`})]})}),(0,K.jsx)(`tbody`,{children:e.map(e=>(0,K.jsx)(xRe,{token:e,showOwner:t,ownerLabel:n?.get(e.user_id)??`#${e.user_id}`,onRevoke:r},e.id))})]})})}function SRe(){let{t:e}=G(),{user:t,isAdmin:n}=sd(),{showToast:r}=xd(),[i,a]=(0,y.useState)([]),[o,s]=(0,y.useState)([]),[c,l]=(0,y.useState)(new Map),[u,d]=(0,y.useState)(!0),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null),g=async()=>{d(!0);try{if(a(await Q.listMyLongLivedCameraTokens()),n){s(await Q.listAllLongLivedCameraTokens());try{let e=await Q.getUsers();l(new Map(e.map(e=>[e.id,e.username])))}catch{l(new Map)}}}catch(t){r(t instanceof Error?t.message:e(`cameraTokens.toast.loadFailed`,`Failed to load tokens`),`error`)}finally{d(!1)}};(0,y.useEffect)(()=>{g()},[n]);let _=async e=>{let t=[...i,...o].find(t=>t.id===e);t&&h(t)},v=async()=>{if(!m)return;let t=m.id;h(null);try{await Q.revokeLongLivedCameraToken(t),r(e(`cameraTokens.toast.revoked`,`Token revoked`)),await g()}catch(t){r(t instanceof Error?t.message:e(`cameraTokens.toast.revokeFailed`,`Failed to revoke token`),`error`)}},b=(0,y.useMemo)(()=>o.filter(e=>e.user_id!==t?.id),[o,t?.id]);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`cameraTokens.description`,`Long-lived tokens for embedding the camera stream into Home Assistant, Frigate, kiosks, or any other tool that needs a stable URL. Each token is camera-stream-only and can be revoked at any time.`)}),(0,K.jsx)(vRe,{onCreated:e=>{p(e),g()}}),(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:e(`cameraTokens.list.myTitle`,`My tokens`)}),u?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`cameraTokens.loading`,`Loading…`)}):(0,K.jsx)(v5,{tokens:i,onRevoke:_,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),n&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:e(`cameraTokens.list.allTitle`,`All users (admin view)`)}),(0,K.jsx)(v5,{tokens:b,showOwner:!0,userIdToName:c,onRevoke:_,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),f&&(0,K.jsx)(bRe,{token:f,onClose:()=>p(null)}),m&&(0,K.jsx)(yRe,{token:m,onConfirm:()=>void v(),onCancel:()=>h(null)})]})}function CRe({plug:e,onEdit:t}){let{t:n}=G(),r=Qa(),{showToast:i}=xd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),{data:p,isLoading:m}=q({queryKey:[`smart-plug-status`,e.id],queryFn:()=>Q.getSmartPlugStatus(e.id),refetchInterval:3e4}),{data:h}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),g=h?.find(t=>t.id===e.printer_id),_=J({mutationFn:t=>Q.controlSmartPlug(e.id,t),onMutate:async t=>{await r.cancelQueries({queryKey:[`smart-plug-status`,e.id]});let n=r.getQueryData([`smart-plug-status`,e.id]),i=t===`on`?`ON`:t===`off`||p?.state===`ON`?`OFF`:`ON`;return r.setQueryData([`smart-plug-status`,e.id],e=>({...e,state:i})),{previousStatus:n}},onError:(t,a,o)=>{o?.previousStatus&&r.setQueryData([`smart-plug-status`,e.id],o.previousStatus),i(n(`smartPlugs.failedToTurn`,{action:a,name:e.name}),`error`)},onSettled:()=>{setTimeout(()=>{r.invalidateQueries({queryKey:[`smart-plug-status`,e.id]}),r.invalidateQueries({queryKey:[`smart-plugs`]})},1e3)}}),v=J({mutationFn:t=>Q.updateSmartPlug(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),e.printer_id&&(r.invalidateQueries({queryKey:[`smartPlugByPrinter`,e.printer_id]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`,e.printer_id]}))}}),b=J({mutationFn:()=>Q.deleteSmartPlug(e.id),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),e.printer_id&&r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`,e.printer_id]})}}),x=p?.state===`ON`,S=e.plug_type===`mqtt`&&p?.energy?.power!==null&&p?.energy?.power!==void 0,C=(p?.reachable??!1)||S,w=_.isPending,T=(()=>{if(e.plug_type!==`tasmota`||!e.ip_address)return null;let t=e.ip_address;return e.username&&e.password?`http://${encodeURIComponent(e.username)}:${encodeURIComponent(e.password)}@${t}/`:`http://${t}/`})();return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(pd,{className:`relative`,children:(0,K.jsxs)(hd,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-2 mb-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg flex-shrink-0 ${e.plug_type===`mqtt`?C?`bg-teal-500/20`:`bg-red-500/20`:C?x?`bg-bambu-green/20`:`bg-bambu-dark`:`bg-red-500/20`}`,children:e.plug_type===`mqtt`?(0,K.jsx)(Sl,{className:`w-5 h-5 ${C?`text-teal-400`:`text-red-400`}`}):e.plug_type===`homeassistant`?(0,K.jsx)(Tc,{className:`w-5 h-5 ${C?x?`text-bambu-green`:`text-bambu-gray`:`text-red-400`}`}):e.plug_type===`rest`?(0,K.jsx)(hc,{className:`w-5 h-5 ${C?x?`text-bambu-green`:`text-bambu-gray`:`text-red-400`}`}):(0,K.jsx)(gl,{className:`w-5 h-5 ${C?x?`text-bambu-green`:`text-bambu-gray`:`text-red-400`}`})}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`h3`,{className:`font-medium text-white truncate`,children:e.name}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray truncate`,title:e.plug_type===`mqtt`?e.mqtt_topic??void 0:e.plug_type===`homeassistant`?e.ha_entity_id??void 0:e.plug_type===`rest`?e.rest_on_url??e.rest_off_url??void 0:e.ip_address??void 0,children:e.plug_type===`mqtt`?e.mqtt_topic:e.plug_type===`homeassistant`?e.ha_entity_id:e.plug_type===`rest`?e.rest_on_url||e.rest_off_url:e.ip_address})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-col items-end gap-1 flex-shrink-0`,children:[m?(0,K.jsx)(X,{className:`w-4 h-4 text-bambu-gray animate-spin`}):e.plug_type===`mqtt`?(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm whitespace-nowrap`,children:[(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-teal-500/20 text-teal-400 text-[10px] font-medium rounded flex-shrink-0`,children:`MQTT`}),C&&(0,K.jsx)(`span`,{className:`text-status-ok`,children:`✓`})]}):e.plug_type===`homeassistant`?(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,K.jsx)(`span`,{className:`px-1 py-0.5 bg-blue-500/20 text-blue-400 text-[10px] font-medium rounded`,children:`HA`}),(0,K.jsx)(`span`,{className:C?x?`text-status-ok`:`text-bambu-gray`:`text-status-error`,children:C?p?.state||`?`:n(`smartPlugs.offline`)})]}):e.plug_type===`rest`?(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,K.jsx)(`span`,{className:`px-1 py-0.5 bg-purple-500/20 text-purple-400 text-[10px] font-medium rounded`,children:`REST`}),(0,K.jsx)(`span`,{className:C?x?`text-status-ok`:`text-bambu-gray`:`text-status-error`,children:C?p?.state||`?`:n(`smartPlugs.offline`)})]}):C?(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,K.jsx)(ju,{className:`w-4 h-4 text-status-ok`}),(0,K.jsx)(`span`,{className:x?`text-status-ok`:`text-bambu-gray`,children:p?.state||n(`smartPlugs.unknown`)})]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-sm text-status-error`,children:[(0,K.jsx)(Au,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:n(`smartPlugs.offline`)})]}),T&&(0,K.jsxs)(`a`,{href:T,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 px-2 py-0.5 bg-bambu-dark hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white text-xs rounded-full transition-colors`,title:n(`smartPlugs.openPlugAdminPage`),children:[(0,K.jsx)(Us,{className:`w-3 h-3`}),n(`smartPlugs.admin`)]})]})]}),g&&(0,K.jsxs)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[n(`smartPlugs.linkedTo`),` `]}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:g.name})]}),(e.power_alert_enabled||e.schedule_enabled||e.plug_type===`mqtt`)&&(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[e.plug_type===`mqtt`&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-teal-500/20 text-teal-400 text-xs rounded-full`,children:[(0,K.jsx)(Gs,{className:`w-3 h-3`}),n(`smartPlugs.monitorOnly`)]}),e.power_alert_enabled&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded-full`,children:[(0,K.jsx)(Io,{className:`w-3 h-3`}),n(`smartPlugs.alerts`)]}),e.schedule_enabled&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded-full`,children:[(0,K.jsx)(qo,{className:`w-3 h-3`}),e.schedule_on_time&&e.schedule_off_time?`${e.schedule_on_time} - ${e.schedule_off_time}`:e.schedule_on_time?n(`smartPlugs.scheduleOn`,{time:e.schedule_on_time}):n(`smartPlugs.scheduleOff`,{time:e.schedule_off_time})]})]}),e.plug_type!==`mqtt`&&(0,K.jsxs)(`div`,{className:`flex gap-2 mb-3`,children:[(0,K.jsxs)($,{size:`sm`,variant:x?`primary`:`secondary`,disabled:!C||w,onClick:()=>c(!0),className:`flex-1`,children:[w?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(yl,{className:`w-4 h-4`}),n(`smartPlugs.on`)]}),(0,K.jsxs)($,{size:`sm`,variant:x?`secondary`:`primary`,disabled:!C||w,onClick:()=>u(!0),className:`flex-1`,children:[w?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(vl,{className:`w-4 h-4`}),n(`smartPlugs.off`)]})]}),e.plug_type===`mqtt`&&p?.energy&&(0,K.jsxs)(`div`,{className:`flex gap-2 mb-3 px-3 py-2 bg-bambu-dark rounded-lg`,children:[p.energy.power!==null&&p.energy.power!==void 0&&(0,K.jsxs)(`div`,{className:`flex-1 text-center`,children:[(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Math.round(p.energy.power),`W`]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.power`)})]}),p.energy.today!==null&&p.energy.today!==void 0&&(0,K.jsxs)(`div`,{className:`flex-1 text-center border-l border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:p.energy.today.toFixed(3)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.kwhToday`)})]})]}),(0,K.jsxs)(`button`,{onClick:()=>f(!d),className:`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Ll,{className:`w-4 h-4`}),e.plug_type===`mqtt`?n(`smartPlugs.settings`):n(`smartPlugs.automationSettings`)]}),(0,K.jsx)(`span`,{children:d?`-`:`+`})]}),d&&(0,K.jsxs)(`div`,{className:`pt-3 border-t border-bambu-dark-tertiary space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Pc,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.showInSwitchbar`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.quickAccessSidebar`)})]})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.show_in_switchbar,onChange:e=>v.mutate({show_in_switchbar:e.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.plug_type!==`mqtt`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.enabled`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.enableAutomation`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>v.mutate({enabled:e.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOn`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOnDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.auto_on,onChange:e=>v.mutate({auto_on:e.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOff`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.auto_off,onChange:e=>v.mutate({auto_off:e.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOffPersistent`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffPersistentDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.auto_off_persistent,onChange:e=>v.mutate({auto_off_persistent:e.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off&&(0,K.jsxs)(`div`,{className:`space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white mb-2`,children:n(`smartPlugs.turnOffDelayMode`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`button`,{onClick:()=>v.mutate({off_delay_mode:`time`}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${e.off_delay_mode===`time`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(_s,{className:`w-4 h-4`}),n(`smartPlugs.time`)]}),(0,K.jsxs)(`button`,{onClick:()=>v.mutate({off_delay_mode:`temperature`}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${e.off_delay_mode===`temperature`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(pu,{className:`w-4 h-4`}),n(`smartPlugs.temp`)]})]})]}),e.off_delay_mode===`time`?(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.delayMinutes`)}),(0,K.jsx)(`input`,{type:`number`,min:`1`,max:`60`,value:e.off_delay_minutes,onChange:e=>v.mutate({off_delay_minutes:parseInt(e.target.value)||5}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}):(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.tempThreshold`)}),(0,K.jsx)(`input`,{type:`number`,min:`30`,max:`100`,value:e.off_temp_threshold,onChange:e=>v.mutate({off_temp_threshold:parseInt(e.target.value)||70}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`smartPlugs.tempThresholdDescription`)})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOffAfterDrying`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffAfterDryingDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.auto_off_after_drying,onChange:e=>v.mutate({auto_off_after_drying:e.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off_after_drying&&(0,K.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.delayAfterDryingMinutes`)}),(0,K.jsx)(`input`,{type:`number`,min:`0`,max:`120`,value:e.off_delay_after_drying_minutes,onChange:e=>v.mutate({off_delay_after_drying_minutes:parseInt(e.target.value)||10}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>t(e),className:`flex-1`,children:[(0,K.jsx)(fl,{className:`w-4 h-4`}),n(`smartPlugs.edit`)]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>o(!0),className:`text-red-400 hover:text-red-300`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]})]})}),a&&(0,K.jsx)(Ed,{title:n(`smartPlugs.deleteSmartPlug`),message:n(`smartPlugs.deleteConfirm`,{name:e.name}),confirmText:n(`smartPlugs.delete`),variant:`danger`,onConfirm:()=>{b.mutate(),o(!1)},onCancel:()=>o(!1)}),s&&(0,K.jsx)(Ed,{title:n(`smartPlugs.turnOnSmartPlug`),message:n(`smartPlugs.turnOnConfirm`,{name:e.name}),confirmText:n(`smartPlugs.turnOn`),variant:`default`,onConfirm:()=>{_.mutate(`on`),c(!1)},onCancel:()=>c(!1)}),l&&(0,K.jsx)(Ed,{title:n(`smartPlugs.turnOffSmartPlug`),message:n(`smartPlugs.turnOffConfirm`,{name:e.name}),confirmText:n(`smartPlugs.turnOff`),variant:`danger`,onConfirm:()=>{_.mutate(`off`),u(!1)},onCancel:()=>u(!1)})]})}function wRe({plug:e,onClose:t}){let{t:n}=G(),r=Qa(),i=!!e,[a,o]=(0,y.useState)(e?.plug_type||`tasmota`),[s,c]=(0,y.useState)(e?.name||``),[l,u]=(0,y.useState)(e?.ip_address||``),[d,f]=(0,y.useState)(e?.username||``),[p,m]=(0,y.useState)(e?.password||``),[h,g]=(0,y.useState)(e?.ha_entity_id||``),[_,v]=(0,y.useState)(e?.mqtt_power_topic||e?.mqtt_topic||``),[b,x]=(0,y.useState)(e?.mqtt_power_path||``),[S,C]=(0,y.useState)((e?.mqtt_power_multiplier??e?.mqtt_multiplier??1).toString()),[w,T]=(0,y.useState)(e?.mqtt_energy_topic||``),[E,D]=(0,y.useState)(e?.mqtt_energy_path||``),[O,k]=(0,y.useState)((e?.mqtt_energy_multiplier??1).toString()),[A,j]=(0,y.useState)(e?.mqtt_state_topic||``),[M,N]=(0,y.useState)(e?.mqtt_state_path||``),[P,F]=(0,y.useState)(e?.mqtt_state_on_value||``),[I,L]=(0,y.useState)(e?.rest_on_url||``),[R,z]=(0,y.useState)(e?.rest_on_body||``),[B,V]=(0,y.useState)(e?.rest_off_url||``),[ee,H]=(0,y.useState)(e?.rest_off_body||``),[te,ne]=(0,y.useState)(e?.rest_method||`POST`),[re,U]=(0,y.useState)(e?.rest_headers||``),[ie,ae]=(0,y.useState)(e?.rest_status_url||``),[W,oe]=(0,y.useState)(e?.rest_status_path||``),[se,ce]=(0,y.useState)(e?.rest_status_on_value||``),[le,ue]=(0,y.useState)(e?.rest_power_url||``),[de,fe]=(0,y.useState)(e?.rest_power_path||``),[pe,me]=(0,y.useState)((e?.rest_power_multiplier??1).toString()),[he,ge]=(0,y.useState)(e?.rest_energy_url||``),[_e,ve]=(0,y.useState)(e?.rest_energy_path||``),[ye,be]=(0,y.useState)((e?.rest_energy_multiplier??1).toString()),[xe,Se]=(0,y.useState)(e?.ha_power_entity||``),[Ce,we]=(0,y.useState)(e?.ha_energy_today_entity||``),[Te,Ee]=(0,y.useState)(e?.ha_energy_total_entity||``),[De,Oe]=(0,y.useState)(``),[ke,Ae]=(0,y.useState)(``),[je,Me]=(0,y.useState)(!1),Ne=(0,y.useRef)(null),[Pe,Fe]=(0,y.useState)(``),[Ie,Le]=(0,y.useState)(!1),Re=(0,y.useRef)(null),[ze,Be]=(0,y.useState)(``),[Ve,He]=(0,y.useState)(!1),Ue=(0,y.useRef)(null),[We,Ge]=(0,y.useState)(``),[Ke,qe]=(0,y.useState)(!1),Je=(0,y.useRef)(null),[Ye,Xe]=(0,y.useState)(e?.printer_id||null),[Ze,Qe]=(0,y.useState)(null),[$e,et]=(0,y.useState)(null),[tt,nt]=(0,y.useState)(e?.power_alert_enabled||!1),[rt,it]=(0,y.useState)(e?.power_alert_high?.toString()||``),[at,ot]=(0,y.useState)(e?.power_alert_low?.toString()||``),[st,ct]=(0,y.useState)(e?.schedule_enabled||!1),[lt,ut]=(0,y.useState)(e?.schedule_on_time||``),[dt,ft]=(0,y.useState)(e?.schedule_off_time||``),[pt,mt]=(0,y.useState)(e?.show_in_switchbar||!1),[ht,gt]=(0,y.useState)(e?.show_on_printer_card??!0),[_t,vt]=(0,y.useState)(!1),[yt,bt]=(0,y.useState)({scanned:0,total:0}),[xt,St]=(0,y.useState)([]),Ct=(0,y.useRef)(null),{data:wt}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:Tt}=q({queryKey:[`smart-plugs`],queryFn:Q.getSmartPlugs}),{data:Et}=q({queryKey:[`settings`],queryFn:Q.getSettings}),Dt=!!(Et?.ha_enabled&&Et?.ha_url&&Et?.ha_token);(0,y.useEffect)(()=>{let e=setTimeout(()=>{Ae(De)},300);return()=>clearTimeout(e)},[De]),(0,y.useEffect)(()=>{let e=e=>{Ne.current&&!Ne.current.contains(e.target)&&Me(!1),Re.current&&!Re.current.contains(e.target)&&Le(!1),Ue.current&&!Ue.current.contains(e.target)&&He(!1),Je.current&&!Je.current.contains(e.target)&&qe(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let{data:Ot,isLoading:kt,error:At}=q({queryKey:[`ha-entities`,ke],queryFn:()=>Q.getHAEntities(ke||void 0),enabled:a===`homeassistant`&&Dt,retry:!1,staleTime:0}),{data:jt}=q({queryKey:[`ha-sensor-entities`],queryFn:Q.getHASensorEntities,enabled:a===`homeassistant`&&Dt,retry:!1,staleTime:0});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e),Ct.current&&clearInterval(Ct.current)}},[t]);let Mt=async()=>{vt(!0),St([]),bt({scanned:0,total:0}),et(null);try{await Q.startTasmotaScan();let e=async()=>{try{let e=await Q.getTasmotaScanStatus();bt({scanned:e.scanned,total:e.total}),St(await Q.getDiscoveredTasmotaDevices()),e.running||(vt(!1),Ct.current&&=(clearInterval(Ct.current),null))}catch(e){console.error(`Polling error:`,e)}};await e(),Ct.current=setInterval(e,500)}catch(e){vt(!1),et((e instanceof Error?e.message:typeof e==`string`?e:JSON.stringify(e))||n(`smartPlugs.failedToStartScan`))}},Nt=async()=>{try{await Q.stopTasmotaScan()}catch{}vt(!1),Ct.current&&=(clearInterval(Ct.current),null)},Pt=e=>{u(e.ip_address),c(e.name),Qe(null)},Ft=J({mutationFn:()=>Q.testSmartPlugConnection(l,d||null,p||null),onSuccess:e=>{Qe(e),et(null),!s&&e.device_name&&c(e.device_name)},onError:e=>{Qe(null),et(e.message)}}),It=J({mutationFn:e=>Q.createSmartPlug(e),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{et(e.message)}}),Lt=J({mutationFn:t=>Q.updateSmartPlug(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{et(e.message)}}),Rt=wt?.filter(t=>a===`tasmota`?!Tt?.some(n=>n.printer_id===t.id&&n.id!==e?.id&&n.plug_type===`tasmota`):!0),zt=e=>{if(e.preventDefault(),et(null),!s.trim()){et(n(`smartPlugs.nameRequired`));return}if(a===`tasmota`&&!l.trim()){et(`IP address is required for Tasmota plugs`);return}if(a===`homeassistant`&&!h){et(n(`smartPlugs.entityRequired`));return}if(a===`mqtt`){let e=_.trim(),t=w.trim(),r=A.trim();if(!e&&!t&&!r){et(n(`smartPlugs.mqttTopicRequired`));return}}if(a===`rest`&&!I.trim()&&!B.trim()){et(n(`smartPlugs.restUrlRequired`));return}let t={name:s.trim(),plug_type:a,ip_address:a===`tasmota`?l.trim():null,ha_entity_id:a===`homeassistant`?h:null,ha_power_entity:a===`homeassistant`&&xe||null,ha_energy_today_entity:a===`homeassistant`&&Ce||null,ha_energy_total_entity:a===`homeassistant`&&Te||null,mqtt_power_topic:a===`mqtt`&&_.trim()||null,mqtt_power_path:a===`mqtt`&&b.trim()||null,mqtt_power_multiplier:a===`mqtt`&&parseFloat(S)||1,mqtt_energy_topic:a===`mqtt`&&w.trim()||null,mqtt_energy_path:a===`mqtt`&&E.trim()||null,mqtt_energy_multiplier:a===`mqtt`&&parseFloat(O)||1,mqtt_state_topic:a===`mqtt`&&A.trim()||null,mqtt_state_path:a===`mqtt`&&M.trim()||null,mqtt_state_on_value:a===`mqtt`&&P.trim()||null,rest_on_url:a===`rest`&&I.trim()||null,rest_on_body:a===`rest`&&R.trim()||null,rest_off_url:a===`rest`&&B.trim()||null,rest_off_body:a===`rest`&&ee.trim()||null,rest_method:a===`rest`?te:null,rest_headers:a===`rest`&&re.trim()||null,rest_status_url:a===`rest`&&ie.trim()||null,rest_status_path:a===`rest`&&W.trim()||null,rest_status_on_value:a===`rest`&&se.trim()||null,rest_power_url:a===`rest`&&le.trim()||null,rest_power_path:a===`rest`&&de.trim()||null,rest_power_multiplier:a===`rest`&&parseFloat(pe)||1,rest_energy_url:a===`rest`&&he.trim()||null,rest_energy_path:a===`rest`&&_e.trim()||null,rest_energy_multiplier:a===`rest`&&parseFloat(ye)||1,username:a===`tasmota`&&d.trim()||null,password:a===`tasmota`&&p.trim()||null,printer_id:Ye,power_alert_enabled:tt,power_alert_high:rt?parseFloat(rt):null,power_alert_low:at?parseFloat(at):null,schedule_enabled:st,schedule_on_time:lt||null,schedule_off_time:dt||null,show_in_switchbar:pt,show_on_printer_card:ht};i?Lt.mutate(t):It.mutate(t)},Bt=It.isPending||Lt.isPending;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 flex-shrink-0`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(i?`smartPlugs.editTitle`:`smartPlugs.addTitle`)}),(0,K.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`form`,{onSubmit:zt,className:`p-6 space-y-4 overflow-y-auto`,children:[$e&&(0,K.jsx)(`div`,{className:`p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400`,children:$e}),!i&&(0,K.jsxs)(`div`,{className:`flex gap-2 mb-2`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{o(`tasmota`),Qe(null),et(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`tasmota`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,K.jsx)(gl,{className:`w-4 h-4`}),`Tasmota`]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{o(`homeassistant`),Qe(null),et(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`homeassistant`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,K.jsx)(Tc,{className:`w-4 h-4`}),`HA`]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{o(`mqtt`),Qe(null),et(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`mqtt`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,K.jsx)(Sl,{className:`w-4 h-4`}),`MQTT`]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{o(`rest`),Qe(null),et(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`rest`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,K.jsx)(hc,{className:`w-4 h-4`}),`REST`]})]}),!i&&a===`tasmota`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[_t?(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:Nt,className:`w-full`,children:[(0,K.jsx)(Pu,{className:`w-4 h-4`}),n(`smartPlugs.stopScanning`)]}):(0,K.jsxs)($,{type:`button`,variant:`primary`,onClick:Mt,className:`w-full`,children:[(0,K.jsx)(Nl,{className:`w-4 h-4`}),n(`smartPlugs.discoverTasmota`)]}),_t&&yt.total>0&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:n(`smartPlugs.addSmartPlug.scanningNetwork`)}),(0,K.jsxs)(`span`,{children:[yt.scanned,` / `,yt.total]})]}),(0,K.jsx)(`div`,{className:`w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,K.jsx)(`div`,{className:`bg-bambu-green h-2 rounded-full transition-all duration-300`,style:{width:`${yt.scanned/yt.total*100}%`}})})]}),xt.length>0&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.foundDevices`,{count:xt.length})}),(0,K.jsx)(`div`,{className:`max-h-40 overflow-y-auto space-y-1`,children:xt.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>Pt(e),className:`w-full flex items-center justify-between p-2 bg-bambu-dark hover:bg-bambu-dark-tertiary rounded-lg transition-colors text-left border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(gl,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.ip_address})]})]}),e.state&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-xs ${e.state===`ON`?`text-bambu-green`:`text-bambu-gray`}`,children:[(0,K.jsx)(yl,{className:`w-3 h-3`}),e.state]})]},e.ip_address))})]}),!_t&&xt.length===0&&yt.total>0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray text-center py-2`,children:n(`smartPlugs.noDevicesFound`)})]}),a===`homeassistant`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[!Dt&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400`,children:[n(`smartPlugs.haNotConfigured`),` `,(0,K.jsx)(`span`,{className:`font-medium`,children:n(`smartPlugs.haSettingsPath`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 opacity-50`,children:n(`smartPlugs.selectEntity`)}),(0,K.jsx)(`select`,{disabled:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed opacity-50`,children:(0,K.jsx)(`option`,{children:n(`smartPlugs.addSmartPlug.chooseEntity`)})})]})]}),Dt&&(0,K.jsxs)(K.Fragment,{children:[kt&&(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-4 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-5 h-5 animate-spin mr-2`}),n(`smartPlugs.loadingEntities`)]}),At&&(0,K.jsx)(`div`,{className:`p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400`,children:n(`smartPlugs.failedToLoadEntities`,{error:At.message})}),(()=>{let t=Tt?.filter(t=>t.ha_entity_id&&t.id!==e?.id).map(e=>e.ha_entity_id)||[],r=(Ot||[]).filter(e=>!t.includes(e.entity_id)),i=Ot?.find(e=>e.entity_id===h);return(0,K.jsxs)(`div`,{ref:Ne,className:`relative`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.selectEntity`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{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:je?De:i?`${i.friendly_name} (${i.entity_id})`:``,onChange:e=>{Oe(e.target.value),je||Me(!0)},onFocus:()=>{Me(!0),Oe(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEntities`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),h&&!je&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{g(``),Oe(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,K.jsx)(Pu,{className:`w-4 h-4 text-bambu-gray hover:text-white`})}),kt&&(0,K.jsx)(X,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin`})]}),je&&(0,K.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-60 overflow-y-auto`,children:[kt&&(0,K.jsxs)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray flex items-center gap-2`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),n(`smartPlugs.loading`)]}),!kt&&r.length===0&&(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:ke?n(`smartPlugs.noEntitiesMatching`,{search:ke}):n(`smartPlugs.noEntitiesAvailable`)}),!kt&&r.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{g(e.entity_id),Me(!1),Oe(``),s||c(e.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${e.entity_id===h?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center justify-between`,children:[(0,K.jsx)(`span`,{children:e.entity_id}),(0,K.jsx)(`span`,{className:e.state===`on`?`text-bambu-green`:``,children:e.state})]})]},e.entity_id))]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(ke?`smartPlugs.searchingEntities`:`smartPlugs.showingEntities`,{count:r.length})})]})})(),h&&jt&&jt.length>0&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium mb-1`,children:n(`smartPlugs.energyMonitoringOptional`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:n(`smartPlugs.energyMonitoringHint`)})]}),(()=>{let e=jt.filter(e=>e.unit_of_measurement===`W`||e.unit_of_measurement===`kW`||e.unit_of_measurement===`mW`),t=Pe?e.filter(e=>e.entity_id.toLowerCase().includes(Pe.toLowerCase())||e.friendly_name.toLowerCase().includes(Pe.toLowerCase())):e,r=jt.find(e=>e.entity_id===xe);return(0,K.jsxs)(`div`,{ref:Re,className:`relative`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.powerSensorW`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{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:Ie?Pe:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Fe(e.target.value),Ie||Le(!0)},onFocus:()=>{Le(!0),Fe(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchPowerSensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),xe&&!Ie&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{Se(``),Fe(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,K.jsx)(Pu,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),Ie&&(0,K.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{Se(``),Le(!1),Fe(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{Se(e.entity_id),Le(!1),Fe(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===xe?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})(),(()=>{let e=jt.filter(e=>e.unit_of_measurement===`kWh`||e.unit_of_measurement===`Wh`||e.unit_of_measurement===`MWh`),t=ze?e.filter(e=>e.entity_id.toLowerCase().includes(ze.toLowerCase())||e.friendly_name.toLowerCase().includes(ze.toLowerCase())):e,r=jt.find(e=>e.entity_id===Ce);return(0,K.jsxs)(`div`,{ref:Ue,className:`relative`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.energyTodayKwh`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{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:Ve?ze:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Be(e.target.value),Ve||He(!0)},onFocus:()=>{He(!0),Be(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEnergySensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),Ce&&!Ve&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{we(``),Be(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,K.jsx)(Pu,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),Ve&&(0,K.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{we(``),He(!1),Be(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{we(e.entity_id),He(!1),Be(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===Ce?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})(),(()=>{let e=jt.filter(e=>e.unit_of_measurement===`kWh`||e.unit_of_measurement===`Wh`||e.unit_of_measurement===`MWh`),t=We?e.filter(e=>e.entity_id.toLowerCase().includes(We.toLowerCase())||e.friendly_name.toLowerCase().includes(We.toLowerCase())):e,r=jt.find(e=>e.entity_id===Te);return(0,K.jsxs)(`div`,{ref:Je,className:`relative`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.totalEnergyKwh`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{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:Ke?We:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Ge(e.target.value),Ke||qe(!0)},onFocus:()=>{qe(!0),Ge(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEnergySensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),Te&&!Ke&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{Ee(``),Ge(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,K.jsx)(Pu,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),Ke&&(0,K.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{Ee(``),qe(!1),Ge(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{Ee(e.entity_id),qe(!1),Ge(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===Te?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})()]})]})]}),a===`mqtt`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[!Et?.mqtt_broker&&(0,K.jsxs)(`div`,{className:`p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400`,children:[n(`smartPlugs.mqttNotConfigured`),` `,(0,K.jsx)(`span`,{className:`font-medium`,children:n(`smartPlugs.mqttSettingsPath`)}),` `,n(`smartPlugs.mqttNotConfiguredSuffix`)]}),Et?.mqtt_broker&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg text-sm text-blue-300`,children:[(0,K.jsx)(`p`,{className:`font-medium mb-1`,children:n(`smartPlugs.monitorOnly`)}),(0,K.jsx)(`p`,{className:`text-xs opacity-80`,children:n(`smartPlugs.mqttMonitorOnlyDescription`)})]}),(0,K.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium text-sm`,children:n(`smartPlugs.powerMonitoring`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,K.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:`zigbee2mqtt/shelly-working-room`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,K.jsx)(`input`,{type:`text`,value:b,onChange:e=>x(e.target.value),placeholder:`power_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.multiplier`)}),(0,K.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttPowerHint`)})]}),(0,K.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.energyMonitoring`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,K.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:`Same as power topic, or different`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,K.jsx)(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),placeholder:`energy_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.multiplier`)}),(0,K.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttEnergyHint`)})]}),(0,K.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.stateMonitoring`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,K.jsx)(`input`,{type:`text`,value:A,onChange:e=>j(e.target.value),placeholder:`Same as power topic, or different`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,K.jsx)(`input`,{type:`text`,value:M,onChange:e=>N(e.target.value),placeholder:`state_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.onValue`)}),(0,K.jsx)(`input`,{type:`text`,value:P,onChange:e=>F(e.target.value),placeholder:n(`smartPlugs.addSmartPlug.placeholders.mqttStateOnValue`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttStateHint`)})]})]})]}),a===`rest`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium text-sm`,children:n(`smartPlugs.restControl`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restMethod`)}),(0,K.jsxs)(`select`,{value:te,onChange:e=>ne(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`GET`,children:`GET`}),(0,K.jsx)(`option`,{value:`POST`,children:`POST`}),(0,K.jsx)(`option`,{value:`PUT`,children:`PUT`}),(0,K.jsx)(`option`,{value:`PATCH`,children:`PATCH`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restOnUrl`)}),(0,K.jsx)(`input`,{type:`text`,value:I,onChange:e=>{L(e.target.value),Qe(null)},placeholder:`http://openhab:8080/rest/items/MyPlug`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restOnBody`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),placeholder:n(`smartPlugs.restBodyHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restOffUrl`)}),(0,K.jsx)(`input`,{type:`text`,value:B,onChange:e=>{V(e.target.value),Qe(null)},placeholder:`http://openhab:8080/rest/items/MyPlug`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restOffBody`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsx)(`input`,{type:`text`,value:ee,onChange:e=>H(e.target.value),placeholder:n(`smartPlugs.restBodyHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.restHeaders`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsx)(`div`,{children:(0,K.jsx)(`textarea`,{value:re,onChange:e=>U(e.target.value),placeholder:n(`smartPlugs.restHeadersHint`),rows:2,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none font-mono text-sm`})})]}),(0,K.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.stateMonitoring`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusUrl`)}),(0,K.jsx)(`input`,{type:`text`,value:ie,onChange:e=>ae(e.target.value),placeholder:n(`smartPlugs.restStatusHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusPath`)}),(0,K.jsx)(`input`,{type:`text`,value:W,onChange:e=>oe(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusOnValue`)}),(0,K.jsx)(`input`,{type:`text`,value:se,onChange:e=>ce(e.target.value),placeholder:`ON`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.energyMonitoring`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restPowerUrl`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsx)(`input`,{type:`text`,value:le,onChange:e=>ue(e.target.value),placeholder:n(`smartPlugs.restPowerUrlHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restPowerPath`)}),(0,K.jsx)(`input`,{type:`text`,value:de,onChange:e=>fe(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restPowerMultiplier`)}),(0,K.jsx)(`input`,{type:`text`,value:pe,onChange:e=>me(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restEnergyUrl`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsx)(`input`,{type:`text`,value:he,onChange:e=>ge(e.target.value),placeholder:n(`smartPlugs.restEnergyUrlHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyPath`)}),(0,K.jsx)(`input`,{type:`text`,value:_e,onChange:e=>ve(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyMultiplier`)}),(0,K.jsx)(`input`,{type:`text`,value:ye,onChange:e=>be(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.restEnergyHint`)})]}),(I.trim()||B.trim())&&(0,K.jsx)(`div`,{className:`flex gap-2`,children:(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:async()=>{Qe(null);try{let e=I.trim()||B.trim(),t=await Q.testRESTConnection(e,te,re.trim()||null);Qe({success:t.success}),t.success||et(t.error||n(`smartPlugs.addSmartPlug.connectionFailed`))}catch{Qe({success:!1}),et(n(`smartPlugs.addSmartPlug.connectionFailed`))}},className:`w-full`,children:[(0,K.jsx)(ju,{className:`w-4 h-4`}),n(`smartPlugs.testConnection`)]})}),Ze&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm ${Ze.success?`text-green-400`:`text-red-400`}`,children:[Ze.success?(0,K.jsx)(ls,{className:`w-4 h-4`}):(0,K.jsx)(Au,{className:`w-4 h-4`}),Ze.success?n(`smartPlugs.connectionSuccess`):n(`smartPlugs.addSmartPlug.connectionFailed`)]})]}),a===`tasmota`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.ipAddress`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:l,onChange:e=>{u(e.target.value),Qe(null)},placeholder:`192.168.1.100`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:()=>Ft.mutate(),disabled:!l.trim()||Ft.isPending,children:[Ft.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(ju,{className:`w-4 h-4`}),n(`smartPlugs.test`)]})]})]}),a===`tasmota`&&Ze&&(0,K.jsx)(`div`,{className:`p-3 rounded-lg flex items-center gap-2 ${Ze.success?`bg-bambu-green/20 border border-bambu-green/50 text-bambu-green`:`bg-red-500/20 border border-red-500/50 text-red-400`}`,children:Ze.success?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ls,{className:`w-5 h-5`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium`,children:n(`smartPlugs.connectedResult`)}),(0,K.jsxs)(`p`,{className:`text-sm opacity-80`,children:[Ze.device_name&&n(`smartPlugs.deviceLabel`,{name:Ze.device_name}),n(`smartPlugs.stateLabel`,{state:Ze.state})]})]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Au,{className:`w-5 h-5`}),(0,K.jsx)(`span`,{children:n(`smartPlugs.addSmartPlug.connectionFailed`)})]})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.nameLabel`)}),(0,K.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:n(`smartPlugs.addSmartPlug.placeholders.plugName`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),a===`tasmota`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.username`)}),(0,K.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`admin`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.password`)}),(0,K.jsx)(`input`,{type:`password`,value:p,onChange:e=>m(e.target.value),placeholder:`********`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray -mt-2`,children:n(`smartPlugs.authHint`)})]}),a!==`mqtt`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.linkToPrinter`)}),(0,K.jsxs)(`select`,{value:Ye??``,onChange:e=>Xe(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:n(`smartPlugs.noPrinter`)}),Rt?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`smartPlugs.linkingDescription`)})]}),(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Io,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.powerAlerts`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:tt,onChange:e=>nt(e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),tt&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.alertAbove`)}),(0,K.jsx)(`input`,{type:`number`,value:rt,onChange:e=>it(e.target.value),placeholder:`e.g. 200`,min:`0`,max:`5000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.alertBelow`)}),(0,K.jsx)(`input`,{type:`number`,value:at,onChange:e=>ot(e.target.value),placeholder:`e.g. 10`,min:`0`,max:`5000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.alertDescription`)})]})]}),a!==`mqtt`&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(_s,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.dailySchedule`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:st,onChange:e=>ct(e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),st&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.turnOnAt`)}),(0,K.jsx)(`input`,{type:`time`,value:lt,onChange:e=>ut(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.turnOffAt`)}),(0,K.jsx)(`input`,{type:`time`,value:dt,onChange:e=>ft(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.scheduleDescription`)})]})]}),(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Pc,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.showInSwitchbar`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.quickAccessSidebar`)})]})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:pt,onChange:e=>mt(e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})}),a===`homeassistant`&&(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Gs,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.showOnPrinterCard`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.displayOnPrinterCard`)})]})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:ht,onChange:e=>gt(e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})}),(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`smartPlugs.cancel`)}),(0,K.jsxs)($,{type:`submit`,disabled:Bt,className:`flex-1`,children:[Bt?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Ol,{className:`w-4 h-4`}),n(i?`smartPlugs.save`:`smartPlugs.add`)]})]})]})]})})}function y5({checked:e,onChange:t,disabled:n}){return(0,K.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":e,disabled:n,onClick:r=>{r.preventDefault(),r.stopPropagation(),n||t(!e)},className:`relative inline-flex w-11 h-7 md:w-9 md:h-5 rounded-full transition-colors flex-shrink-0 focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${n?`bg-bambu-dark-tertiary/50 cursor-not-allowed opacity-50`:e?`bg-bambu-green cursor-pointer`:`bg-bambu-dark-tertiary cursor-pointer hover:bg-bambu-dark-tertiary/80`}`,children:(0,K.jsx)(`span`,{className:`pointer-events-none absolute top-[3px] md:top-[2px] left-[3px] md:left-[2px] w-5 h-5 md:w-4 md:h-4 bg-white rounded-full shadow transition-transform duration-200 ease-in-out ${e?`translate-x-4`:`translate-x-0`}`})})}function TRe({provider:e,onEdit:t}){let{t:n}=G(),r=Qa(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),{data:u}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),d=u?.find(t=>t.id===e.printer_id),f=J({mutationFn:t=>Q.updateNotificationProvider(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]})}}),p=J({mutationFn:()=>Q.deleteNotificationProvider(e.id),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]})}}),m=J({mutationFn:()=>Q.testNotificationProvider(e.id),onSuccess:e=>{l(e),r.invalidateQueries({queryKey:[`notification-providers`]})},onError:e=>{l({success:!1,message:e.message})}}),h=e=>e||``;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(pd,{className:`relative`,children:(0,K.jsxs)(hd,{className:`p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between ${e.enabled?`mb-3`:`mb-0`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${e.enabled?`bg-bambu-green/20`:`bg-bambu-dark`}`,children:(0,K.jsx)(Io,{className:`w-5 h-5 ${e.enabled?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`font-medium text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.providerTypes.${e.provider_type}`,e.provider_type)})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.last_success&&(0,K.jsx)(`span`,{className:`text-xs text-status-ok hidden sm:inline`,children:n(`notifications.lastSuccess`,{date:hf(e.last_success)})}),e.last_error&&e.last_error_at&&(!e.last_success||(mf(e.last_error_at)?.getTime()||0)>(mf(e.last_success)?.getTime()||0))&&(0,K.jsx)(`span`,{className:`text-xs text-status-error`,title:e.last_error,children:n(`notifications.error`)}),(0,K.jsx)(y5,{checked:e.enabled,onChange:e=>f.mutate({enabled:e})})]})]}),e.enabled&&(0,K.jsxs)(K.Fragment,{children:[d&&(0,K.jsxs)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[n(`notifications.printer`),` `]}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:d.name})]}),!d&&!e.printer_id&&(0,K.jsx)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.allPrinters`)})}),(0,K.jsxs)(`div`,{className:`mb-3 flex flex-wrap gap-1`,children:[e.on_print_start&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded`,children:n(`notifications.start`)}),e.on_plate_not_empty&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-600/20 text-rose-300 text-xs rounded`,children:n(`notifications.plateCheck`)}),e.on_print_complete&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded`,children:n(`notifications.complete`)}),e.on_print_failed&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-red-500/20 text-red-400 text-xs rounded`,children:n(`notifications.failed`)}),e.on_print_stopped&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded`,children:n(`notifications.stopped`)}),e.on_print_progress&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded`,children:n(`notifications.progress`)}),e.on_printer_offline&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded`,children:n(`notifications.offline`)}),e.on_printer_error&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-500/20 text-rose-400 text-xs rounded`,children:n(`notifications.error`)}),e.on_filament_low&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-cyan-500/20 text-cyan-400 text-xs rounded`,children:n(`notifications.lowFilament`)}),e.on_maintenance_due&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded`,children:n(`notifications.maintenance`)}),e.on_ams_humidity_high&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-blue-600/20 text-blue-300 text-xs rounded`,children:n(`notifications.amsHumidity`)}),e.on_ams_temperature_high&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-orange-600/20 text-orange-300 text-xs rounded`,children:n(`notifications.amsTemp`)}),e.on_ams_ht_humidity_high&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-cyan-600/20 text-cyan-300 text-xs rounded`,children:n(`notifications.amsHtHumidity`)}),e.on_ams_ht_temperature_high&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-600/20 text-amber-300 text-xs rounded`,children:n(`notifications.amsHtTemp`)}),e.on_bed_cooled&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-teal-500/20 text-teal-400 text-xs rounded`,children:n(`notifications.bedCooled`)}),e.on_first_layer_complete&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-emerald-600/20 text-emerald-300 text-xs rounded`,children:n(`notifications.firstLayer`)}),e.on_print_missing_spool_assignment&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-500/20 text-amber-300 text-xs rounded`,children:n(`notifications.missingSpoolAssignmentLabel`)}),e.on_stock_reorder_alert&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-lime-500/20 text-lime-400 text-xs rounded`,children:n(`notifications.stockReorderAlert`)}),e.on_stock_break_alert&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-red-600/20 text-red-300 text-xs rounded`,children:n(`notifications.stockBreakAlert`)}),e.quiet_hours_enabled&&(0,K.jsxs)(`span`,{className:`px-2 py-0.5 bg-indigo-500/20 text-indigo-400 text-xs rounded flex items-center gap-1`,children:[(0,K.jsx)(nl,{className:`w-3 h-3`}),n(`notifications.quiet`)]}),e.daily_digest_enabled&&(0,K.jsxs)(`span`,{className:`px-2 py-0.5 bg-emerald-500/20 text-emerald-400 text-xs rounded flex items-center gap-1`,children:[(0,K.jsx)(qo,{className:`w-3 h-3`}),n(`notifications.digest`,{time:e.daily_digest_time})]})]}),(0,K.jsx)(`div`,{className:`mb-3`,children:(0,K.jsxs)($,{size:`sm`,variant:`secondary`,disabled:m.isPending,onClick:()=>{l(null),m.mutate()},className:`w-full`,children:[m.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Pl,{className:`w-4 h-4`}),n(`notifications.sendTestNotification`)]})}),c&&(0,K.jsxs)(`div`,{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${c.success?`bg-bambu-green/20 text-bambu-green`:`bg-red-500/20 text-red-400`}`,children:[c.success?(0,K.jsx)(ls,{className:`w-4 h-4`}):(0,K.jsx)(ms,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:c.message})]})]}),(0,K.jsxs)(`button`,{onClick:()=>s(!o),className:`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors ${e.enabled?`border-t border-bambu-dark-tertiary`:`mt-2 border-t border-bambu-dark-tertiary`}`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Ll,{className:`w-4 h-4`}),n(`notifications.eventSettings`)]}),o?(0,K.jsx)(rs,{className:`w-4 h-4`}):(0,K.jsx)(es,{className:`w-4 h-4`})]}),o&&(0,K.jsxs)(`div`,{className:`pt-3 border-t border-bambu-dark-tertiary space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.enabled`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.sendFromProvider`)})]}),(0,K.jsx)(y5,{checked:e.enabled,onChange:e=>f.mutate({enabled:e})})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printEvents`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printStarted`)}),(0,K.jsx)(y5,{checked:e.on_print_start,onChange:e=>f.mutate({on_print_start:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.plateNotEmpty`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.plateNotEmptyDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_plate_not_empty??!0,onChange:e=>f.mutate({on_plate_not_empty:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printCompleted`)}),(0,K.jsx)(y5,{checked:e.on_print_complete,onChange:e=>f.mutate({on_print_complete:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.bedCooledLabel`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.bedCooledDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_bed_cooled??!1,onChange:e=>f.mutate({on_bed_cooled:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.firstLayerCompleteLabel`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.firstLayerCompleteDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_first_layer_complete??!1,onChange:e=>f.mutate({on_first_layer_complete:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.missingSpoolAssignmentLabel`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.missingSpoolAssignmentDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_print_missing_spool_assignment??!1,onChange:e=>f.mutate({on_print_missing_spool_assignment:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printFailed`)}),(0,K.jsx)(y5,{checked:e.on_print_failed,onChange:e=>f.mutate({on_print_failed:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printStopped`)}),(0,K.jsx)(y5,{checked:e.on_print_stopped,onChange:e=>f.mutate({on_print_stopped:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.progressMilestones`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.progressMilestonesDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_print_progress,onChange:e=>f.mutate({on_print_progress:e})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printerStatus`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printerOffline`)}),(0,K.jsx)(y5,{checked:e.on_printer_offline,onChange:e=>f.mutate({on_printer_offline:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printerError`)}),(0,K.jsx)(y5,{checked:e.on_printer_error,onChange:e=>f.mutate({on_printer_error:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.lowFilamentLabel`)}),(0,K.jsx)(y5,{checked:e.on_filament_low,onChange:e=>f.mutate({on_filament_low:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.maintenanceDue`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.maintenanceDueDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_maintenance_due??!1,onChange:e=>f.mutate({on_maintenance_due:e})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.amsAlarms`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHumidityHigh`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHumidityHighDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_ams_humidity_high??!1,onChange:e=>f.mutate({on_ams_humidity_high:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsTemperatureHigh`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsTemperatureHighDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_ams_temperature_high??!1,onChange:e=>f.mutate({on_ams_temperature_high:e})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.amsHtAlarms`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHtHumidityHigh`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHtHumidityHighDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_ams_ht_humidity_high??!1,onChange:e=>f.mutate({on_ams_ht_humidity_high:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHtTemperatureHigh`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHtTemperatureHighDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_ams_ht_temperature_high??!1,onChange:e=>f.mutate({on_ams_ht_temperature_high:e})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.inventoryAlerts`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.stockReorderAlert`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.stockReorderAlertDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_stock_reorder_alert??!1,onChange:e=>f.mutate({on_stock_reorder_alert:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.stockBreakAlert`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.stockBreakAlertDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_stock_break_alert??!1,onChange:e=>f.mutate({on_stock_break_alert:e})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printQueue`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobAdded`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobAddedDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_queue_job_added??!1,onChange:e=>f.mutate({on_queue_job_added:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobAssigned`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobAssignedDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_queue_job_assigned??!1,onChange:e=>f.mutate({on_queue_job_assigned:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobStarted`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobStartedDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_queue_job_started??!1,onChange:e=>f.mutate({on_queue_job_started:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobWaiting`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobWaitingDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_queue_job_waiting??!0,onChange:e=>f.mutate({on_queue_job_waiting:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobSkipped`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobSkippedDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_queue_job_skipped??!0,onChange:e=>f.mutate({on_queue_job_skipped:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobFailed`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobFailedDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_queue_job_failed??!0,onChange:e=>f.mutate({on_queue_job_failed:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.queueComplete`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.queueCompleteDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_queue_completed??!1,onChange:e=>f.mutate({on_queue_completed:e})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(nl,{className:`w-4 h-4 text-purple-400`}),(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.quietHours`)})]}),(0,K.jsx)(y5,{checked:e.quiet_hours_enabled,onChange:e=>f.mutate({quiet_hours_enabled:e})})]}),e.quiet_hours_enabled&&(0,K.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.noNotificationsDuring`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(_s,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsxs)(`span`,{className:`text-sm text-white`,children:[h(e.quiet_hours_start)||`22:00`,` - `,h(e.quiet_hours_end)||`07:00`]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.editProviderToChangeQuietHours`)})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(qo,{className:`w-4 h-4 text-emerald-400`}),(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.dailyDigest`)})]}),(0,K.jsx)(y5,{checked:e.daily_digest_enabled,onChange:e=>f.mutate({daily_digest_enabled:e})})]}),e.daily_digest_enabled&&(0,K.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.batchNotifications`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(_s,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.sendAt`,{time:h(e.daily_digest_time)||`08:00`})})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.editProviderToChangeDigestTime`)})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>t(e),className:`flex-1`,children:[(0,K.jsx)(fl,{className:`w-4 h-4`}),n(`notifications.edit`)]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>a(!0),className:`text-red-400 hover:text-red-300`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]})]})}),i&&(0,K.jsx)(Ed,{title:n(`notifications.deleteProvider`),message:n(`notifications.deleteConfirm`,{name:e.name}),confirmText:n(`notifications.delete`),variant:`danger`,onConfirm:()=>{p.mutate(),a(!1)},onCancel:()=>a(!1)})]})}var ERe=[`email`,`telegram`,`discord`,`ntfy`,`pushover`,`callmebot`,`webhook`,`homeassistant`];function DRe({provider:e,onClose:t}){let{t:n}=G(),r=Qa(),i=!!e,[a,o]=(0,y.useState)(e?.name||``),[s,c]=(0,y.useState)(e?.provider_type||`email`),[l,u]=(0,y.useState)(e?.printer_id||null),[d,f]=(0,y.useState)(e?.quiet_hours_enabled||!1),[p,m]=(0,y.useState)(e?.quiet_hours_start||`22:00`),[h,g]=(0,y.useState)(e?.quiet_hours_end||`07:00`),[_,v]=(0,y.useState)(e?.daily_digest_enabled||!1),[b,x]=(0,y.useState)(e?.daily_digest_time||`08:00`),[S,C]=(0,y.useState)(e?.on_print_start??!1),[w,T]=(0,y.useState)(e?.on_print_complete??!0),[E,D]=(0,y.useState)(e?.on_print_failed??!0),[O,k]=(0,y.useState)(e?.on_print_stopped??!0),[A,j]=(0,y.useState)(e?.on_print_progress??!1),[M,N]=(0,y.useState)(e?.on_printer_offline??!1),[P,F]=(0,y.useState)(e?.on_printer_error??!1),[I,L]=(0,y.useState)(e?.on_filament_low??!1),[R,z]=(0,y.useState)(e?.on_maintenance_due??!1),[B,V]=(0,y.useState)(e?.on_stock_reorder_alert??!1),[ee,H]=(0,y.useState)(e?.on_stock_break_alert??!1),[te,ne]=(0,y.useState)(e?.on_bed_cooled??!1),[re,U]=(0,y.useState)(e?.on_first_layer_complete??!1),[ie,ae]=(0,y.useState)(e?.config?Object.fromEntries(Object.entries(e.config).filter(([e])=>e!==`event_priorities`).map(([e,t])=>[e,String(t)])):{}),[W,oe]=(0,y.useState)((()=>{let t=e?.config?.event_priorities;if(!t||typeof t!=`object`)return{};let n={};for(let[e,r]of Object.entries(t)){let t=Number(r);Number.isInteger(t)&&t>=1&&t<=5&&(n[e]=t)}return n})()),[se,ce]=(0,y.useState)(null),[le,ue]=(0,y.useState)(null),{data:de}=q({queryKey:[`printers`],queryFn:Q.getPrinters});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let fe=J({mutationFn:()=>Q.testNotificationConfig({provider_type:s,config:ie}),onSuccess:e=>{ce(e),ue(null)},onError:e=>{ce({success:!1,message:e.message})}}),pe=J({mutationFn:e=>Q.createNotificationProvider(e),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]}),t()},onError:e=>{ue(e.message)}}),me=J({mutationFn:t=>Q.updateNotificationProvider(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]}),t()},onError:e=>{ue(e.message)}}),he=e=>{if(e.preventDefault(),ue(null),!a.trim()){ue(n(`notifications.nameRequired`));return}let t=ve(s);for(let e of t)if(!ie[e.key]?.trim()){ue(n(`notifications.fieldRequired`,{field:e.label}));return}let r=s===`ntfy`&&Object.keys(W).length>0?{...ie,event_priorities:W}:ie,o={name:a.trim(),provider_type:s,config:r,printer_id:l,quiet_hours_enabled:d,quiet_hours_start:d?p:null,quiet_hours_end:d?h:null,daily_digest_enabled:_,daily_digest_time:_?b:null,on_print_start:S,on_print_complete:w,on_print_failed:E,on_print_stopped:O,on_print_progress:A,on_printer_offline:M,on_printer_error:P,on_filament_low:I,on_maintenance_due:R,on_stock_reorder_alert:B,on_stock_break_alert:ee,on_bed_cooled:te,on_first_layer_complete:re};i?me.mutate(o):pe.mutate(o)},ge=pe.isPending||me.isPending,_e=e=>{switch(e){case`callmebot`:return[{key:`phone`,label:`Phone Number`,placeholder:`+1234567890`,type:`text`,required:!0},{key:`apikey`,label:`API Key`,placeholder:`Your CallMeBot API key`,type:`text`,required:!0}];case`ntfy`:return[{key:`server`,label:`Server URL`,placeholder:`https://ntfy.sh`,type:`text`,required:!1},{key:`topic`,label:`Topic`,placeholder:`my-bambuddy`,type:`text`,required:!0},{key:`auth_token`,label:`Auth Token`,placeholder:`Optional authentication`,type:`password`,required:!1}];case`pushover`:return[{key:`user_key`,label:`User Key`,placeholder:`Your Pushover user key`,type:`text`,required:!0},{key:`app_token`,label:`App Token`,placeholder:`Your Pushover app token`,type:`text`,required:!0},{key:`priority`,label:`Priority`,placeholder:`0 (normal)`,type:`number`,required:!1}];case`telegram`:return[{key:`bot_token`,label:`Bot Token`,placeholder:`Bot token from @BotFather`,type:`password`,required:!0},{key:`chat_id`,label:`Chat ID`,placeholder:`Your chat or group ID`,type:`text`,required:!0}];case`email`:return[{key:`smtp_server`,label:`SMTP Server`,placeholder:`smtp.gmail.com`,type:`text`,required:!0},{key:`smtp_port`,label:`SMTP Port`,placeholder:`587`,type:`number`,required:!1},{key:`security`,label:`Security`,type:`select`,required:!1,options:[{value:`starttls`,label:`STARTTLS (Port 587)`},{value:`ssl`,label:`SSL/TLS (Port 465)`},{value:`none`,label:`None (Port 25)`}]},{key:`auth_enabled`,label:`Authentication`,type:`select`,required:!1,options:[{value:`true`,label:`Enabled`},{value:`false`,label:`Disabled`}]},{key:`username`,label:`Username`,placeholder:`your@email.com`,type:`text`,required:!1},{key:`password`,label:`Password`,placeholder:`App password`,type:`password`,required:!1},{key:`from_email`,label:`From Email`,placeholder:`your@email.com`,type:`text`,required:!0},{key:`to_email`,label:`To Email`,placeholder:`recipient@email.com`,type:`text`,required:!0}];case`discord`:return[{key:`webhook_url`,label:`Webhook URL`,placeholder:`https://discord.com/api/webhooks/...`,type:`text`,required:!0}];case`webhook`:return[{key:`webhook_url`,label:`Webhook URL`,placeholder:`https://example.com/webhook`,type:`text`,required:!0},{key:`payload_format`,label:`Payload Format`,type:`select`,required:!1,options:[{value:`generic`,label:`Generic JSON`},{value:`slack`,label:`Slack / Mattermost`}]},{key:`auth_header`,label:`Authorization`,placeholder:`Bearer token (optional)`,type:`password`,required:!1},{key:`field_title`,label:`Title Field Name`,placeholder:`title`,type:`text`,required:!1,showIf:e=>e.payload_format!==`slack`},{key:`field_message`,label:`Message Field Name`,placeholder:`message`,type:`text`,required:!1,showIf:e=>e.payload_format!==`slack`}];case`homeassistant`:return[{key:`service`,label:`Home Assistant Service`,placeholder:`notify.mobile_app_myphone`,type:`text`,required:!1}];default:return[]}},ve=e=>_e(e).filter(e=>e.required),ye=_e(s);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto`,onClick:t,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg my-8 max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,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:n(i?`notifications.editTitle`:`notifications.addTitle`)}),(0,K.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`form`,{onSubmit:he,className:`p-6 space-y-4`,children:[le&&(0,K.jsx)(`div`,{className:`p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400`,children:le}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.nameLabel`)}),(0,K.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:n(`notifications.namePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.providerTypeLabel`)}),(0,K.jsx)(`select`,{value:s,onChange:e=>{c(e.target.value),ae({}),ce(null)},disabled:i,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`,children:ERe.map(e=>(0,K.jsx)(`option`,{value:e,children:n(`notifications.providerTypes.${e}`,e)},e))}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.providerDescriptions.${s}`,``)})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.configuration`)}),ye.filter(e=>!(`showIf`in e)||e.showIf?.(ie)!==!1).map(e=>(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[e.label,` `,e.required&&`*`]}),e.type===`select`&&`options`in e&&e.options?(0,K.jsx)(`select`,{value:ie[e.key]||e.options[0]?.value||``,onChange:t=>{ae({...ie,[e.key]:t.target.value}),ce(null)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:e.options.map(e=>(0,K.jsx)(`option`,{value:e.value,children:e.label},e.value))}):(0,K.jsx)(`input`,{type:e.type,value:ie[e.key]||``,onChange:t=>{ae({...ie,[e.key]:t.target.value}),ce(null)},placeholder:e.placeholder,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]},e.key))]}),(0,K.jsx)(`div`,{className:`flex gap-2`,children:(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:()=>{ce(null),fe.mutate()},disabled:fe.isPending||ve(s).length>0&&!ie[ve(s)[0]?.key],className:`flex-1`,children:[fe.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Pl,{className:`w-4 h-4`}),n(`notifications.testConfiguration`)]})}),se&&(0,K.jsx)(`div`,{className:`p-3 rounded-lg flex items-center gap-2 ${se.success?`bg-bambu-green/20 border border-bambu-green/50 text-bambu-green`:`bg-red-500/20 border border-red-500/50 text-red-400`}`,children:se.success?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ls,{className:`w-5 h-5`}),(0,K.jsx)(`span`,{children:se.message})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ms,{className:`w-5 h-5`}),(0,K.jsx)(`span`,{children:se.message})]})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.printerFilter`)}),(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:n(`notifications.allPrinters`)}),de?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.onlyFromPrinter`)})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.quietHoursDnd`)}),(0,K.jsx)(y5,{checked:d,onChange:f})]}),d&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.quietStart`)}),(0,K.jsx)(`input`,{type:`time`,value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.quietEnd`)}),(0,K.jsx)(`input`,{type:`time`,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`})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.dailyDigestLabel`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.batchNotifications`)})]}),(0,K.jsx)(y5,{checked:_,onChange:v})]}),_&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.sendDigestAt`)}),(0,K.jsx)(`input`,{type:`time`,value:b,onChange:e=>x(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.digestCollected`)})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.notificationEvents`)}),(0,K.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.printEvents`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.start`)}),(0,K.jsx)(y5,{checked:S,onChange:C})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.complete`)}),(0,K.jsx)(y5,{checked:w,onChange:T})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.failed`)}),(0,K.jsx)(y5,{checked:E,onChange:D})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stopped`)}),(0,K.jsx)(y5,{checked:O,onChange:k})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.progress`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.progressPercent`)})]}),(0,K.jsx)(y5,{checked:A,onChange:j})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.bedCooled`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.bedCooledAfterPrint`)})]}),(0,K.jsx)(y5,{checked:te,onChange:ne})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.firstLayerCompleteLabel`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.firstLayerCompleteDescription`)})]}),(0,K.jsx)(y5,{checked:re,onChange:U})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.printerStatus`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.offline`)}),(0,K.jsx)(y5,{checked:M,onChange:N})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.error`)}),(0,K.jsx)(y5,{checked:P,onChange:F})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.lowFilament`)}),(0,K.jsx)(y5,{checked:I,onChange:L})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.maintenance`)}),(0,K.jsx)(y5,{checked:R,onChange:z})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.inventoryAlerts`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stockReorderAlert`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.stockReorderAlertDescription`)})]}),(0,K.jsx)(y5,{checked:B,onChange:V})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stockBreakAlert`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.stockBreakAlertDescription`)})]}),(0,K.jsx)(y5,{checked:ee,onChange:H})]})]})]}),s===`ntfy`&&(()=>{let e=[];return S&&e.push({key:`on_print_start`,label:n(`notifications.start`)}),w&&e.push({key:`on_print_complete`,label:n(`notifications.complete`)}),E&&e.push({key:`on_print_failed`,label:n(`notifications.failed`)}),O&&e.push({key:`on_print_stopped`,label:n(`notifications.stopped`)}),A&&e.push({key:`on_print_progress`,label:n(`notifications.progress`)}),te&&e.push({key:`on_bed_cooled`,label:n(`notifications.bedCooled`)}),re&&e.push({key:`on_first_layer_complete`,label:n(`notifications.firstLayerCompleteLabel`)}),M&&e.push({key:`on_printer_offline`,label:n(`notifications.offline`)}),P&&e.push({key:`on_printer_error`,label:n(`notifications.error`)}),I&&e.push({key:`on_filament_low`,label:n(`notifications.lowFilament`)}),R&&e.push({key:`on_maintenance_due`,label:n(`notifications.maintenance`)}),B&&e.push({key:`on_stock_reorder_alert`,label:n(`notifications.stockReorderAlert`)}),ee&&e.push({key:`on_stock_break_alert`,label:n(`notifications.stockBreakAlert`)}),e.length===0?null:(0,K.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-1`,children:n(`notifications.eventPriority.sectionTitle`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`notifications.eventPriority.helpNtfy`)}),(0,K.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:e.label}),(0,K.jsxs)(`select`,{value:W[e.key]??3,onChange:t=>{let n=Number(t.target.value);oe(t=>({...t,[e.key]:n}))},className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:1,children:n(`notifications.eventPriority.min`)}),(0,K.jsx)(`option`,{value:2,children:n(`notifications.eventPriority.low`)}),(0,K.jsx)(`option`,{value:3,children:n(`notifications.eventPriority.default`)}),(0,K.jsx)(`option`,{value:4,children:n(`notifications.eventPriority.high`)}),(0,K.jsx)(`option`,{value:5,children:n(`notifications.eventPriority.urgent`)})]})]},e.key))})]})})()]}),(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`notifications.cancel`)}),(0,K.jsxs)($,{type:`submit`,disabled:ge,className:`flex-1`,children:[ge?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Ol,{className:`w-4 h-4`}),n(i?`notifications.save`:`notifications.add`)]})]})]})]})})}function ORe({template:e,onClose:t}){let{t:n}=G(),r=Qa(),i=(0,y.useRef)(null),[a,o]=(0,y.useState)(e.title_template),[s,c]=(0,y.useState)(e.body_template),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!0),{data:p}=q({queryKey:[`template-variables`],queryFn:Q.getTemplateVariables}),m=p?.find(t=>t.event_type===e.event_type),{data:h,isLoading:g}=q({queryKey:[`template-preview`,e.event_type,a,s],queryFn:()=>Q.previewTemplate({event_type:e.event_type,title_template:a,body_template:s}),enabled:d&&a.length>0&&s.length>0});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let _=J({mutationFn:t=>Q.updateNotificationTemplate(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-templates`]}),t()},onError:e=>{u(e.message)}}),v=J({mutationFn:()=>Q.resetNotificationTemplate(e.id),onSuccess:e=>{o(e.title_template),c(e.body_template),r.invalidateQueries({queryKey:[`notification-templates`]})},onError:e=>{u(e.message)}}),b=e=>{if(e.preventDefault(),u(null),!a.trim()){u(n(`notifications.titleRequired`));return}if(!s.trim()){u(n(`notifications.bodyRequired`));return}_.mutate({title_template:a,body_template:s})},x=e=>{let t=i.current;if(!t)return;let n=t.selectionStart,r=t.selectionEnd,a=s,o=a.substring(0,n),l=a.substring(r);c(o+`{${e}}`+l),setTimeout(()=>{t.focus();let r=n+e.length+2;t.setSelectionRange(r,r)},0)},S=a!==e.title_template||s!==e.body_template;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`notifications.editTemplate`,{name:e.name})}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`form`,{onSubmit:b,className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[l&&(0,K.jsx)(`div`,{className:`p-3 bg-red-500/20 border border-red-500/50 rounded text-red-400 text-sm`,children:l}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:n(`notifications.titleLabel`)}),(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 text-white focus:outline-none focus:ring-1 focus:ring-bambu-green`,placeholder:n(`notifications.titlePlaceholder`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:n(`notifications.bodyLabel`)}),(0,K.jsx)(`textarea`,{ref:i,value:s,onChange:e=>c(e.target.value),rows:4,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green font-mono text-sm resize-none`,placeholder:n(`notifications.bodyPlaceholder`)})]}),m&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-2`,children:n(`notifications.availableVariables`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.variables.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>x(e),className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,K.jsx)(_l,{className:`w-3 h-3`}),e]},e))}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:n(`notifications.clickToInsert`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`label`,{className:`text-sm font-medium text-bambu-gray flex items-center gap-2`,children:[(0,K.jsx)(Gs,{className:`w-4 h-4`}),n(`notifications.livePreview`)]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>f(!d),className:`text-xs text-bambu-green hover:text-bambu-green-light`,children:n(d?`notifications.hide`:`notifications.show`)})]}),d&&(0,K.jsx)(`div`,{className:`bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2`,children:g?(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(`notifications.loadingPreview`)]}):h?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.titlePreview`)}),(0,K.jsx)(`div`,{className:`text-white font-medium`,children:h.title})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.bodyPreview`)}),(0,K.jsx)(`div`,{className:`text-white whitespace-pre-wrap text-sm`,children:h.body})]})]}):(0,K.jsx)(`div`,{className:`text-bambu-gray text-sm`,children:n(`notifications.enterTemplateContent`)})})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0`,children:[(0,K.jsxs)($,{type:`button`,variant:`ghost`,onClick:()=>v.mutate(),disabled:v.isPending,className:`text-orange-400 hover:text-orange-300`,children:[v.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-2`}):(0,K.jsx)(Tl,{className:`w-4 h-4 mr-2`}),n(`notifications.resetToDefault`)]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,children:n(`notifications.cancel`)}),(0,K.jsxs)($,{onClick:b,disabled:_.isPending||!S,children:[_.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-2`}):(0,K.jsx)(Ol,{className:`w-4 h-4 mr-2`}),n(`notifications.save`)]})]})]})]})})}var kRe={print_start:`text-blue-400`,print_complete:`text-bambu-green`,print_failed:`text-red-400`,print_stopped:`text-orange-400`,print_progress:`text-yellow-400`,printer_offline:`text-gray-400`,printer_error:`text-rose-400`,filament_low:`text-cyan-400`,maintenance_due:`text-purple-400`,test:`text-bambu-gray`};function ARe({onClose:e}){let{t}=G(),n=Qa(),{showToast:r}=xd(),[i,a]=(0,y.useState)(7),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(!1),{data:u}=q({queryKey:[`settings`],queryFn:Q.getSettings}),d=u?.time_format||`system`,{data:f,isLoading:p,refetch:m,isRefetching:h}=q({queryKey:[`notification-logs`,i,c],queryFn:()=>Q.getNotificationLogs({days:i,limit:100,success:c?!1:void 0})}),{data:g}=q({queryKey:[`notification-log-stats`,i],queryFn:()=>Q.getNotificationLogStats(i)}),_=J({mutationFn:()=>Q.clearNotificationLogs(30),onSuccess:e=>{r(e.message,`success`),n.invalidateQueries({queryKey:[`notification-logs`]}),n.invalidateQueries({queryKey:[`notification-log-stats`]})},onError:e=>{r(`Failed to clear logs: ${e.message}`,`error`)}}),v=e=>{let n=mf(e);if(!n)return``;let r=new Date().getTime()-n.getTime();return r<6e4?t(`notifications.justNow`):r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?`${Math.floor(r/36e5)}h ago`:n.toLocaleDateString()+` `+_f(n,d)};return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-3xl max-h-[85vh] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(wc,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t(`notifications.notificationLog`)})]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:`×`})]}),g&&(0,K.jsx)(`div`,{className:`px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-6 text-sm`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`notifications.statsSummary`,{days:i}),` `,(0,K.jsx)(`span`,{className:`text-white font-medium`,children:g.total}),` `,t(`notifications.statsNotifications`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-green`,children:[(0,K.jsx)(ls,{className:`w-4 h-4`}),t(`notifications.statsSent`,{count:g.success_count})]}),g.failure_count>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-red-400`,children:[(0,K.jsx)(ms,{className:`w-4 h-4`}),t(`notifications.statsFailed`,{count:g.failure_count})]})]})}),(0,K.jsxs)(`div`,{className:`px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4`,children:[(0,K.jsxs)(`select`,{value:i,onChange:e=>a(Number(e.target.value)),className:`px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green`,children:[(0,K.jsx)(`option`,{value:1,children:t(`notifications.last24Hours`)}),(0,K.jsx)(`option`,{value:7,children:t(`notifications.last7Days`)}),(0,K.jsx)(`option`,{value:30,children:t(`notifications.last30Days`)}),(0,K.jsx)(`option`,{value:90,children:t(`notifications.last90Days`)})]}),(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:c,onChange:e=>l(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),t(`notifications.showFailedOnly`)]}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>m(),disabled:h,children:[h?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),t(`notifications.refresh`)]}),(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>_.mutate(),disabled:_.isPending,className:`text-red-400 hover:text-red-300`,children:[_.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hu,{className:`w-4 h-4`}),t(`notifications.clearOld`)]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:p?(0,K.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})}):f&&f.length>0?(0,K.jsx)(`div`,{className:`space-y-2`,children:f.map(e=>(0,K.jsx)(jRe,{log:e,isExpanded:o===e.id,onToggle:()=>s(o===e.id?null:e.id),formatDate:v,formatFullDate:e=>gf(e,d)},e.id))}):(0,K.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,K.jsx)(wc,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,K.jsx)(`p`,{className:`text-sm`,children:t(c?`notifications.noFailedNotifications`:`notifications.noNotificationsLogged`)})]})})]})})}function jRe({log:e,isExpanded:t,onToggle:n,formatDate:r,formatFullDate:i}){let{t:a}=G();return(0,K.jsxs)(`div`,{className:`border rounded-lg overflow-hidden transition-colors ${e.success?`border-bambu-dark-tertiary bg-bambu-dark/30`:`border-red-500/30 bg-red-500/5`}`,children:[(0,K.jsxs)(`button`,{className:`w-full px-3 py-2 flex items-center gap-3 text-left hover:bg-bambu-dark/50 transition-colors`,onClick:n,children:[e.success?(0,K.jsx)(ls,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,K.jsx)(ms,{className:`w-4 h-4 text-red-400 shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs font-medium ${kRe[e.event_type]||`text-bambu-gray`}`,children:a(`notifications.eventTypes.${e.event_type}`,e.event_type)}),(0,K.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:e.provider_name||a(`notifications.unknownProvider`)}),e.printer_name&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.printer_name}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:r(e.created_at)}),t?(0,K.jsx)(rs,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),t&&(0,K.jsxs)(`div`,{className:`px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:a(`notifications.logTitle`)}),(0,K.jsx)(`p`,{className:`text-sm text-white`,children:e.title})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:a(`notifications.logMessage`)}),(0,K.jsx)(`p`,{className:`text-sm text-white whitespace-pre-wrap`,children:e.message})]}),!e.success&&e.error_message&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-red-400 mb-1`,children:a(`notifications.logError`)}),(0,K.jsx)(`p`,{className:`text-sm text-red-300`,children:e.error_message})]}),(0,K.jsxs)(`div`,{className:`flex gap-4 text-xs text-bambu-gray pt-1`,children:[(0,K.jsx)(`span`,{children:a(`notifications.logProvider`,{type:e.provider_type})}),(0,K.jsx)(`span`,{children:a(`notifications.logTime`,{time:i(e.created_at)})})]})]})]})}var MRe=Object.defineProperty,b5=Object.getOwnPropertySymbols,x5=Object.prototype.hasOwnProperty,S5=Object.prototype.propertyIsEnumerable,C5=(e,t,n)=>t in e?MRe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,w5=(e,t)=>{for(var n in t||={})x5.call(t,n)&&C5(e,n,t[n]);if(b5)for(var n of b5(t))S5.call(t,n)&&C5(e,n,t[n]);return e},T5=(e,t)=>{var n={};for(var r in e)x5.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&b5)for(var r of b5(e))t.indexOf(r)<0&&S5.call(e,r)&&(n[r]=e[r]);return n},E5;(e=>{let t=class t{constructor(e,n,r,a){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],et.MAX_VERSION)throw RangeError(`Version value out of range`);if(a<-1||a>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let o=[];for(let e=0;e7)throw RangeError(`Invalid value`);let u,d;for(u=a;;u++){let n=t.getNumDataCodewords(u,r)*8,i=o.getTotalBits(e,u);if(i<=n){d=i;break}if(u>=s)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])l&&d<=t.getNumDataCodewords(u,e)*8&&(r=e);let f=[];for(let t of e){n(t.mode.modeBits,4,f),n(t.numChars,t.mode.numCharCountBits(u),f);for(let e of t.getData())f.push(e)}i(f.length==d);let p=t.getNumDataCodewords(u,r)*8;i(f.length<=p),n(0,Math.min(4,p-f.length),f),n(0,(8-f.length%8)%8,f),i(f.length%8==0);for(let e=236;f.lengthm[t>>>3]|=e<<7-(t&7)),new t(u,r,m,c)}getModule(e,t){return 0<=e&&e>>9)*1335;let a=(t<<10|n)^21522;i(a>>>15==0);for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(a,e));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(a,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(a,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(a,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;i(t>>>18==0);for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;0<=a&&a{(e!=l-o||n>=c)&&f.push(t[e])});return i(f.length==s),f}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let i=0;i>>3],7-(n&7)),n++)}}i(n==e.length*8)}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;ne+ +!!t,n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return i(0<=a&&a<=9),e+=a*t.PENALTY_N4,i(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{let e=Math.floor(this.version/7)+2,t=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.lengtht.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return i(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return i(n>>>8==0),n}finderPenaltyCountPatterns(e){let t=e[1];i(t<=this.size*3);let n=t>0&&e[2]==t&&e[3]==t*3&&e[4]==t&&e[5]==t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]==0&&(e+=this.size),t.pop(),t.unshift(e)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return(e>>>t&1)!=0}function i(e){if(!e)throw Error(`Assertion error`)}let a=class e{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}static makeBytes(t){let r=[];for(let e of t)n(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw RangeError(`String contains non-numeric characters`);let r=[];for(let e=0;e=1<{(e=>{let t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(E5||={}),(e=>{(e=>{let t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(E5||={});var D5=E5,NRe={L:D5.QrCode.Ecc.LOW,M:D5.QrCode.Ecc.MEDIUM,Q:D5.QrCode.Ecc.QUARTILE,H:D5.QrCode.Ecc.HIGH},O5=128,k5=`L`,A5=`#FFFFFF`,j5=`#000000`,M5=!1,N5=1,PRe=4,FRe=0,IRe=.1;function P5(e,t=0){let n=[];return e.forEach(function(e,r){let i=null;e.forEach(function(a,o){if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function F5(e,t){return e.slice().map((e,n)=>n=t.y+t.h?e:e.map((e,n)=>n=t.x+t.w?e:!1))}function LRe(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*IRe),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,d=r.opacity==null?1:r.opacity,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}let p=r.crossOrigin;return{x:l,y:u,h:c,w:s,excavation:f,opacity:d,crossOrigin:p}}function RRe(e,t){return t==null?e?PRe:FRe:Math.max(Math.floor(t),0)}function I5({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:s}){let c=y.useMemo(()=>{let r=(Array.isArray(e)?e:[e]).reduce((e,t)=>(e.push(...D5.QrSegment.makeSegments(t)),e),[]);return D5.QrCode.encodeSegments(r,NRe[t],n,void 0,void 0,s)},[e,t,n,s]),{cells:l,margin:u,numCells:d,calculatedImageSettings:f}=y.useMemo(()=>{let e=c.getModules(),t=RRe(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:LRe(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var zRe=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),BRe=y.forwardRef(function(e,t){let n=e,{value:r,size:i=O5,level:a=k5,bgColor:o=A5,fgColor:s=j5,includeMargin:c=M5,minVersion:l=N5,boostLevel:u,marginSize:d,imageSettings:f}=n,p=T5(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=T5(p,[`style`]),g=f?.src,_=y.useRef(null),v=y.useRef(null),b=y.useCallback(e=>{_.current=e,typeof t==`function`?t(e):t&&(t.current=e)},[t]),[x,S]=y.useState(!1),{margin:C,cells:w,numCells:T,calculatedImageSettings:E}=I5({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:d,imageSettings:f,size:i});y.useEffect(()=>{if(_.current!=null){let e=_.current,t=e.getContext(`2d`);if(!t)return;let n=w,r=v.current,a=E!=null&&r!==null&&r.complete&&r.naturalHeight!==0&&r.naturalWidth!==0;a&&E.excavation!=null&&(n=F5(w,E.excavation));let c=window.devicePixelRatio||1;e.height=e.width=i*c;let l=i/T*c;t.scale(l,l),t.fillStyle=o,t.fillRect(0,0,T,T),t.fillStyle=s,zRe?t.fill(new Path2D(P5(n,C))):w.forEach(function(e,n){e.forEach(function(e,r){e&&t.fillRect(r+C,n+C,1,1)})}),E&&(t.globalAlpha=E.opacity),a&&t.drawImage(r,E.x+C,E.y+C,E.w,E.h)}}),y.useEffect(()=>{S(!1)},[g]);let D=w5({height:i,width:i},m),O=null;return g!=null&&(O=y.createElement(`img`,{src:g,key:g,style:{display:`none`},onLoad:()=>{S(!0)},ref:v,crossOrigin:E?.crossOrigin})),y.createElement(y.Fragment,null,y.createElement(`canvas`,w5({style:D,height:i,width:i,ref:b,role:`img`},h)),O)});BRe.displayName=`QRCodeCanvas`;var L5=y.forwardRef(function(e,t){let n=e,{value:r,size:i=O5,level:a=k5,bgColor:o=A5,fgColor:s=j5,includeMargin:c=M5,minVersion:l=N5,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=T5(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:v}=I5({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:f,imageSettings:p,size:i}),b=g,x=null;p!=null&&v!=null&&(v.excavation!=null&&(b=F5(g,v.excavation)),x=y.createElement(`image`,{href:p.src,height:v.h,width:v.w,x:v.x+h,y:v.y+h,preserveAspectRatio:`none`,opacity:v.opacity,crossOrigin:v.crossOrigin}));let S=P5(b,h);return y.createElement(`svg`,w5({height:i,width:i,viewBox:`0 0 ${_} ${_}`,ref:t,role:`img`},m),!!d&&y.createElement(`title`,null,d),y.createElement(`path`,{fill:o,d:`M0,0 h${_}v${_}H0z`,shapeRendering:`crispEdges`}),y.createElement(`path`,{fill:s,d:S,shapeRendering:`crispEdges`}),x)});L5.displayName=`QRCodeSVG`;function VRe(e,t){return`bambuddy://config?v=1&url=${encodeURIComponent(e)}&key=${encodeURIComponent(t)}`}function HRe({apiKey:e,baseUrl:t,onClose:n}){let{t:r}=G(),i=VRe(t??window.location.origin,e);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:r(`settings.apiKeyQrTitle`)}),(0,K.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`),children:(0,K.jsx)(Pu,{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`,children:r(`settings.apiKeyQrCaption`)}),(0,K.jsx)(`div`,{className:`bg-white p-4 rounded-lg mb-4`,children:(0,K.jsx)(L5,{value:i,size:256})}),(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-xs text-amber-400 mb-4`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 flex-shrink-0 mt-0.5`}),(0,K.jsx)(`span`,{children:r(`settings.apiKeyQrWarning`)})]}),(0,K.jsx)($,{onClick:n,className:`w-full`,children:r(`common.close`)})]})]})})}var URe=300,R5=2;function z5({onSuccess:e}){let{t}=G(),n=Qa(),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null);(0,y.useEffect)(()=>{let e=r.trim();if(e.lengtho(e),URe);return()=>clearTimeout(t)},[r]),(0,y.useEffect)(()=>{c(null),u(null)},[a]);let d=q({queryKey:[`ldap-search`,a],queryFn:()=>Q.searchLDAPDirectory(a),enabled:a.length>=R5,staleTime:3e4}),f=J({mutationFn:e=>Q.provisionLDAPUser(e),onSuccess:t=>{n.invalidateQueries({queryKey:[`users`]}),e(t)},onError:e=>{u(e.message||t(`users.modal.ldapErrorProvision`))}}),p=(0,y.useMemo)(()=>d.data?.find(e=>e.dn===s)??null,[d.data,s]),m=r.trim().length>0&&r.trim().length=R5,g=!!d.data&&d.data.length>0,_=!h&&!!d.data&&d.data.length===0&&a.length>=R5;return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:t(`users.modal.ldapSearchLabel`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,K.jsx)(`input`,{type:`text`,value:r,onChange:e=>i(e.target.value),className:`w-full pl-9 pr-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`users.modal.ldapSearchPlaceholder`),autoComplete:`off`})]}),m&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:t(`users.modal.ldapMinChars`)})]}),(0,K.jsxs)(`div`,{className:`min-h-[8rem] max-h-64 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[h&&(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-2`}),(0,K.jsx)(`span`,{children:t(`users.modal.ldapSearching`)})]}),_&&(0,K.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapNoResults`)}),d.isError&&(0,K.jsx)(`div`,{className:`px-3 py-4 text-sm text-red-400`,children:d.error instanceof Error?d.error.message:t(`users.modal.ldapSearchError`)}),!h&&g&&(0,K.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary`,children:d.data.map(e=>(0,K.jsx)(WRe,{result:e,selected:s===e.dn,onSelect:()=>c(e.dn)},e.dn))}),!h&&!d.data&&!d.isError&&(0,K.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapTypeToSearch`)})]}),p&&(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-1`,children:[(0,K.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`users.modal.ldapSelectedLabel`),`: `]}),(0,K.jsx)(`span`,{className:`font-medium`,children:p.username}),p.display_name&&(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,p.display_name]})]}),p.email&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:p.email}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray break-all`,children:p.dn})]}),l&&(0,K.jsx)(`div`,{className:`bg-red-500/10 border border-red-500/30 rounded-lg p-3`,children:(0,K.jsx)(`p`,{className:`text-sm text-red-400`,children:l})}),(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsx)($,{onClick:()=>{!p||p.already_provisioned||(u(null),f.mutate(p.username))},disabled:!p||p.already_provisioned||f.isPending,children:f.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),t(`users.modal.ldapProvisioning`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),t(`users.modal.ldapProvision`)]})})})]})}function WRe({result:e,selected:t,onSelect:n}){let{t:r}=G(),i=e.already_provisioned;return(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,onClick:n,disabled:i,className:`w-full text-left px-3 py-2 flex items-center gap-3 transition-colors ${i?`opacity-50 cursor-not-allowed`:t?`bg-bambu-green/10`:`hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`p`,{className:`text-sm text-white truncate`,children:[(0,K.jsx)(`span`,{className:`font-medium`,children:e.username}),e.display_name&&(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,e.display_name]})]}),e.email&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.email})]}),i&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray whitespace-nowrap`,children:[(0,K.jsx)(us,{className:`w-3.5 h-3.5`}),r(`users.modal.ldapAlreadyProvisioned`)]})]})})}function GRe({formData:e,setFormData:t,groups:n,onClose:r,onCreate:i,isCreating:a,isCreateButtonDisabled:o,ldapEnabled:s=!1,onLdapProvisioned:c}){let{t:l}=G(),[u,d]=(0,y.useState)(`local`);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let f=n=>{t({...e,group_ids:e.group_ids.includes(n)?e.group_ids.filter(e=>e!==n):[...e.group_ids,n]})};return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:r,children:(0,K.jsxs)(pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(wu,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:l(`users.modal.createUser`)})]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray ml-7`,children:l(`users.modal.advancedAuthSubtitle`)||`with Advanced Authentication`})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:r,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]})}),(0,K.jsxs)(hd,{children:[s&&(0,K.jsxs)(`div`,{className:`mb-4 flex items-center gap-1 p-1 bg-bambu-dark-secondary rounded-lg`,role:`tablist`,"aria-label":l(`users.modal.tabsAriaLabel`),children:[(0,K.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":u===`local`,onClick:()=>d(`local`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${u===`local`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:l(`users.modal.localTab`)}),(0,K.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":u===`ldap`,onClick:()=>d(`ldap`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${u===`ldap`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:l(`users.modal.ldapTab`)})]}),u===`ldap`&&s?(0,K.jsx)(z5,{onSuccess:e=>{c?.(e)}}):(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[l(`users.form.username`),` `,(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsx)(`input`,{type:`text`,value:e.username,onChange:n=>t({...e,username:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:l(`users.form.usernamePlaceholder`),autoComplete:`username`,required:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[l(`users.form.email`)||`Email`,` `,(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsx)(`input`,{type:`email`,value:e.email,onChange:n=>t({...e,email:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:l(`users.form.emailPlaceholder`)||`user@example.com`,required:!0})]}),(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3`,children:(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:l(`users.form.autoGeneratedPassword`)||`A secure password will be automatically generated and emailed to the user.`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:l(`users.form.groups`)}),(0,K.jsxs)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[n.map(t=>(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.group_ids.includes(t.id),onChange:()=>f(t.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:t.name}),t.is_system&&(0,K.jsxs)(`span`,{className:`text-xs text-yellow-400`,children:[`(`,l(`users.system`),`)`]})]},t.id)),n.length===0&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:l(`users.noGroupsAvailable`)})]})]})]}),(0,K.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:r,children:l(`users.modal.cancel`)}),u===`local`&&(0,K.jsx)($,{onClick:i,disabled:o,children:a?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),l(`users.modal.creating`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),l(`users.modal.createUser`)]})})]})]})]})})}function KRe(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`auto`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!0),[p,m]=(0,y.useState)(`all`),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),{data:w,isLoading:T}=q({queryKey:[`spoolman-settings`],queryFn:Q.getSpoolmanSettings}),{data:E,isLoading:D,refetch:O}=q({queryKey:[`spoolman-status`],queryFn:Q.getSpoolmanStatus,refetchInterval:3e4}),{data:k}=q({queryKey:[`printers`],queryFn:Q.getPrinters});(0,y.useEffect)(()=>{w&&(i(w.spoolman_enabled===`true`),o(w.spoolman_url||``),c(w.spoolman_sync_mode||`auto`),u(w.spoolman_disable_weight_sync===`true`),f(w.spoolman_report_partial_usage!==`false`),g(!0))},[w]),(0,y.useEffect)(()=>{if(!(!h||!w)&&(w.spoolman_enabled===`true`!==r||(w.spoolman_url||``)!==a||(w.spoolman_sync_mode||`auto`)!==s||w.spoolman_disable_weight_sync===`true`!==l||w.spoolman_report_partial_usage!==`false`!==d)){let e=setTimeout(()=>{A.mutate()},500);return()=>clearTimeout(e)}},[r,a,s,l,d,h]);let A=J({mutationFn:()=>Q.updateSpoolmanSettings({spoolman_enabled:r?`true`:`false`,spoolman_url:a,spoolman_sync_mode:s,spoolman_disable_weight_sync:l?`true`:`false`,spoolman_report_partial_usage:d?`true`:`false`}),onSuccess:()=>{t.invalidateQueries({queryKey:[`spoolman-settings`]}),t.invalidateQueries({queryKey:[`spoolman-status`]}),t.invalidateQueries({queryKey:[`spool-assignments`]}),t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`spoolman-inventory-filaments`]}),n(e(`settings.toast.settingsSaved`))},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),j=J({mutationFn:Q.connectSpoolman,onSuccess:()=>{O()},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),M=J({mutationFn:Q.disconnectSpoolman,onSuccess:()=>{O()},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),N=J({mutationFn:Q.syncAllPrintersAms,onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),P=J({mutationFn:e=>Q.syncPrinterAms(e),onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),F=()=>{p===`all`?N.mutate():P.mutate(p)},I=J({mutationFn:Q.syncWeightsFromAms,onSuccess:r=>{t.invalidateQueries({queryKey:[`spools`]}),t.invalidateQueries({queryKey:[`inventory-spools`]}),n(e(`settings.amsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),x(!1)},onError:()=>{n(e(`settings.amsSyncError`),`error`),x(!1)}}),L=J({mutationFn:Q.syncSpoolmanAmsWeights,onSuccess:r=>{t.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),n(e(`settings.spoolmanAmsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),C(!1)},onError:t=>{t instanceof zu&&t.status===503?n(e(`settings.spoolmanAmsSyncErrorUnreachable`),`error`):t instanceof zu&&t.status===400?n(e(`settings.spoolmanAmsSyncErrorNotConfigured`),`error`):n(e(`settings.spoolmanAmsSyncError`),`error`),C(!1)}}),R=N.isPending||P.isPending,z=p===`all`?N.data:P.data,B=p===`all`?N.isSuccess:P.isSuccess;return T?(0,K.jsxs)(pd,{id:`card-spoolman`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(js,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]})}),(0,K.jsx)(hd,{children:(0,K.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})})})]}):(0,K.jsxs)(pd,{id:`card-spoolman`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(js,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]}),A.isPending&&(0,K.jsx)(X,{className:`w-4 h-4 text-bambu-green animate-spin`})]})}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.filamentTrackingDesc`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>i(!1),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`:`border-bambu-green bg-bambu-green/10`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,K.jsx)(cl,{className:`w-4 h-4 ${r?`text-bambu-gray`:`text-bambu-green`}`}),(0,K.jsx)(`span`,{className:`text-sm font-medium ${r?`text-bambu-gray`:`text-white`}`,children:e(`settings.trackingModeBuiltIn`)})]}),(0,K.jsx)(`p`,{className:`text-xs ${r?`text-bambu-gray/60`:`text-bambu-gray`}`,children:e(`settings.trackingModeBuiltInDesc`)}),!r&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,K.jsx)($o,{className:`w-3 h-3 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,K.jsx)(Us,{className:`w-4 h-4 ${r?`text-bambu-green`:`text-bambu-gray`}`}),(0,K.jsx)(`span`,{className:`text-sm font-medium ${r?`text-white`:`text-bambu-gray`}`,children:`Spoolman`})]}),(0,K.jsx)(`p`,{className:`text-xs ${r?`text-bambu-gray`:`text-bambu-gray/60`}`,children:e(`settings.trackingModeSpoolmanDesc`)}),r&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,K.jsx)($o,{className:`w-3 h-3 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]})]}),!r&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`div`,{className:`p-3 bg-bambu-green/5 border border-bambu-green/20 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(kc,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-0.5`}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,K.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:[(0,K.jsx)(`li`,{children:e(`settings.builtInFeatureRfid`)}),(0,K.jsx)(`li`,{children:e(`settings.builtInFeatureUsage`)}),(0,K.jsx)(`li`,{children:e(`settings.builtInFeatureCatalog`)}),(0,K.jsx)(`li`,{children:e(`settings.builtInFeatureThirdParty`)})]})})]})}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>x(!0),disabled:I.isPending,children:[I.isPending?(0,K.jsx)(X,{className:`w-4 h-4 mr-2 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4 mr-2`}),e(`settings.amsSyncButton`)]})]}),r&&(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`div`,{className:`p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(kc,{className:`w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`text-xs text-blue-300`,children:[(0,K.jsx)(`p`,{className:`font-medium mb-1`,children:e(`settings.howSyncWorks`)}),(0,K.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5 text-blue-300/80`,children:[(0,K.jsx)(`li`,{children:e(`settings.syncInfoRfidOnly`)}),(0,K.jsx)(`li`,{children:e(`settings.syncInfoAutoCreate`)}),(0,K.jsx)(`li`,{children:e(`settings.syncInfoThirdPartySkipped`)})]}),(0,K.jsx)(`p`,{className:`font-medium mt-2 mb-1`,children:e(`settings.linkingExistingSpools`)}),(0,K.jsx)(`p`,{className:`text-blue-300/80`,children:e(`settings.linkingExistingSpoolsDesc`)})]})]})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.spoolmanUrl`)}),(0,K.jsx)(`input`,{type:`text`,placeholder:`http://192.168.1.100:7912`,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 placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.spoolmanUrlHint`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.syncMode`)}),(0,K.jsxs)(`select`,{value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`auto`,children:e(`settings.syncModeAuto`)}),(0,K.jsx)(`option`,{value:`manual`,children:e(`settings.syncModeManual`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(s===`auto`?`settings.syncModeAutoDesc`:`settings.syncModeManualDesc`)})]}),s===`auto`&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:e(`spoolman.disableWeightSync`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.disableWeightSyncDesc`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),l&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:e(`spoolman.reportPartialUsage`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.reportPartialUsageDesc`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`settings.status`),`:`]}),D?(0,K.jsx)(X,{className:`w-4 h-4 text-bambu-gray animate-spin`}):E?.connected?(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-green-500`,children:[(0,K.jsx)($o,{className:`w-4 h-4`}),e(`settings.spoolmanConnected`)]}):(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-red-500`,children:[(0,K.jsx)(Pu,{className:`w-4 h-4`}),e(`settings.spoolmanDisconnected`)]})]}),(0,K.jsx)(`div`,{className:`flex gap-2`,children:E?.connected?(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>M.mutate(),disabled:M.isPending,children:[M.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Fc,{className:`w-4 h-4`}),e(`settings.disconnect`)]}):(0,K.jsxs)($,{size:`sm`,onClick:()=>j.mutate(),disabled:j.isPending||!a,children:[j.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Ic,{className:`w-4 h-4`}),e(`settings.connect`)]})})]}),(j.isError||M.isError)&&(0,K.jsx)(`div`,{className:`mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400`,children:(j.error||M.error).message}),E?.connected&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.syncAmsData`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.syncAmsDataDesc`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value===`all`?`all`:Number(e.target.value)),className:`w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,K.jsx)(`option`,{value:`all`,children:e(`settings.allPrinters`)}),k?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,K.jsx)(es,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:F,disabled:R,children:[R?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),e(`spoolman.sync`)]})]})]}),E?.connected&&(0,K.jsx)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.spoolmanAmsSyncButton`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.spoolmanAmsSyncMessage`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>C(!0),disabled:L.isPending,children:[L.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),L.isPending?e(`settings.spoolmanAmsSyncing`):e(`settings.spoolmanAmsSyncButton`)]})]})}),B&&z&&(0,K.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded text-sm ${z.success?`bg-green-500/20 border border-green-500/50 text-green-400`:`bg-yellow-500/20 border border-yellow-500/50 text-yellow-400`}`,children:z.success?`Synced ${z.synced_count} spool${z.synced_count===1?``:`s`} successfully`:`Synced ${z.synced_count} spool${z.synced_count===1?``:`s`} with ${z.errors.length} error${z.errors.length===1?``:`s`}`}),z.skipped_count>0&&(0,K.jsxs)(`div`,{className:`p-2 bg-amber-500/10 border border-amber-500/30 rounded text-sm`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-amber-400 mb-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(vu,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{className:`font-medium`,children:[z.skipped_count,` spool`,z.skipped_count===1?``:`s`,` skipped`]})]}),z.skipped_count>5&&(0,K.jsx)(`button`,{onClick:()=>v(!_),className:`text-xs text-amber-400 hover:text-amber-300 underline`,children:_?`Show less`:`Show all`})]}),(0,K.jsxs)(`ul`,{className:`text-xs text-amber-300/80 space-y-0.5`,children:[(_?z.skipped:z.skipped.slice(0,5)).map((e,t)=>(0,K.jsxs)(`li`,{className:`flex items-center gap-2`,children:[e.color&&(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:`#${e.color}`}}),(0,K.jsx)(`span`,{children:e.location}),(0,K.jsxs)(`span`,{className:`text-amber-300/60`,children:[`- `,e.reason]})]},t)),!_&&z.skipped_count>5&&(0,K.jsxs)(`li`,{className:`text-amber-300/60 italic`,children:[`...and `,z.skipped_count-5,` more`]})]})]}),z.errors.length>0&&(0,K.jsxs)(`div`,{className:`p-2 bg-red-500/10 border border-red-500/30 rounded text-sm`,children:[(0,K.jsx)(`div`,{className:`text-red-400 font-medium mb-1`,children:`Errors:`}),(0,K.jsx)(`ul`,{className:`text-xs text-red-300/80 space-y-0.5`,children:z.errors.map((e,t)=>(0,K.jsx)(`li`,{children:e},t))})]})]})]})]})]}),b&&(0,K.jsx)(Ed,{title:e(`settings.amsSyncTitle`),message:e(`settings.amsSyncMessage`),confirmText:e(`settings.amsSyncButton`),variant:`warning`,isLoading:I.isPending,loadingText:e(`settings.amsSyncing`),onConfirm:()=>I.mutate(),onCancel:()=>x(!1)}),S&&(0,K.jsx)(Ed,{title:e(`settings.spoolmanAmsSyncTitle`),message:e(`settings.spoolmanAmsSyncMessage`),confirmText:e(`settings.spoolmanAmsSyncButton`),variant:`warning`,isLoading:L.isPending,loadingText:e(`settings.spoolmanAmsSyncing`),onConfirm:()=>L.mutate(),onCancel:()=>C(!1)})]})}function qRe(){let{t:e}=G(),{showToast:t}=xd(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(``),c=(0,y.useRef)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(new Set),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(null),[E,D]=(0,y.useState)(!1),O=(0,y.useCallback)(async()=>{try{r(await Q.getSpoolCatalog())}catch(n){console.error(`SpoolCatalogSettings.loadCatalog failed:`,n),t(e(`settings.catalog.loadFailed`),`error`)}finally{a(!1)}},[t,e]);(0,y.useEffect)(()=>{O()},[O]);let k=n.filter(e=>e.name.toLowerCase().includes(o.toLowerCase())),A=async()=>{if(!p.trim()||!h){t(e(`settings.catalog.nameWeightRequired`),`error`);return}v(!0);try{let n=await Q.addCatalogEntry({name:p.trim(),weight:parseInt(h)});r(e=>[...e,n].sort((e,t)=>e.name.localeCompare(t.name))),u(!1),m(``),g(``),t(e(`settings.catalog.entryAdded`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleAdd failed:`,n),t(e(`settings.catalog.addFailed`),`error`)}finally{v(!1)}},j=e=>{f(e.id),m(e.name),g(e.weight.toString())},M=()=>{f(null),m(``),g(``)},N=async n=>{if(!p.trim()||!h){t(e(`settings.catalog.nameWeightRequired`),`error`);return}v(!0);try{let i=await Q.updateCatalogEntry(n,{name:p.trim(),weight:parseInt(h)});r(e=>e.map(e=>e.id===n?i:e).sort((e,t)=>e.name.localeCompare(t.name))),f(null),m(``),g(``),t(e(`settings.catalog.entryUpdated`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleUpdate failed:`,n),t(e(`settings.catalog.updateFailed`),`error`)}finally{v(!1)}},P=async()=>{if(w)try{await Q.deleteCatalogEntry(w.id),r(e=>e.filter(e=>e.id!==w.id)),t(e(`settings.catalog.entryDeleted`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleDelete failed:`,n),t(e(`settings.catalog.deleteFailed`),`error`)}finally{T(null)}},F=async()=>{D(!1),a(!0);try{await Q.resetSpoolCatalog(),await O(),t(e(`settings.catalog.resetSuccess`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleReset failed:`,n),t(e(`settings.catalog.resetFailed`),`error`),a(!1)}},I=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,K.jsxs)(pd,{id:`card-spool-catalog`,children:[(0,K.jsxs)(md,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,K.jsx)(js,{className:`w-5 h-5 text-bambu-gray`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.catalog.spoolCatalog`)}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,n.length,`)`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.jsxs)(`button`,{onClick:()=>{let r=n.map(({name:e,weight:t})=>({name:e,weight:t})),i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`spool-catalog.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),t(e(`settings.catalog.exported`,{count:n.length}),`success`)},className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.exportTooltip`),children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.export`)})]}),(0,K.jsxs)(`button`,{onClick:()=>c.current?.click(),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.importTooltip`),children:[(0,K.jsx)(Su,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.import`)})]}),(0,K.jsx)(`input`,{ref:c,type:`file`,accept:`.json`,className:`hidden`,onChange:async i=>{let a=i.target.files?.[0];if(a){try{let i=await a.text(),o=JSON.parse(i);if(!Array.isArray(o))throw Error(`Invalid format`);let s=0,c=0;for(let e of o){if(!e.name||typeof e.weight!=`number`){c++;continue}if(n.some(t=>t.name.toLowerCase()===e.name.toLowerCase())){c++;continue}try{let t=await Q.addCatalogEntry({name:e.name,weight:e.weight});r(e=>[...e,t].sort((e,t)=>e.name.localeCompare(t.name))),s++}catch(e){console.error(`SpoolCatalogSettings import item failed:`,e),c++}}t(e(`settings.catalog.imported`,{added:s,skipped:c}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleImport failed:`,n),t(e(`settings.catalog.importFailed`),`error`)}c.current&&(c.current.value=``)}}}),(0,K.jsxs)(`button`,{onClick:()=>D(!0),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.resetTooltip`),children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.reset`)})]}),(0,K.jsxs)(`button`,{onClick:()=>u(!0),className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.add`)})]})]}),b.size>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg`,children:[(0,K.jsx)(`span`,{className:`text-sm text-red-400`,children:e(`settings.catalog.selectedCount`,{count:b.size})}),(0,K.jsxs)(`button`,{onClick:()=>C(!0),className:`ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5`,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`settings.catalog.deleteSelected`)]}),(0,K.jsx)(`button`,{onClick:()=>x(new Set),className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors`,children:e(`common.cancel`)})]})]}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.catalog.spoolCatalogDescription`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.catalog.searchCatalog`),value:o,onChange:e=>s(e.target.value)})]}),l&&(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e(`settings.catalog.addNewEntry`)}),(0,K.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,K.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.catalog.namePlaceholder`),value:p,onChange:e=>m(e.target.value)})}),(0,K.jsx)(`input`,{type:`number`,className:`w-20 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-center focus:border-bambu-green focus:outline-none`,placeholder:`g`,value:h,onChange:e=>g(e.target.value)}),(0,K.jsx)(`span`,{className:`text-bambu-gray shrink-0`,children:`g`}),(0,K.jsxs)(`button`,{onClick:A,disabled:_,className:`px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center gap-1 shrink-0`,children:[_?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)($o,{className:`w-4 h-4`}),e(`common.add`)]}),(0,K.jsx)(`button`,{onClick:()=>{u(!1),m(``),g(``)},className:`p-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]})]}),i?(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-5 h-5 animate-spin mr-2`}),e(`common.loading`)]}):(0,K.jsx)(`div`,{className:`max-h-[600px] overflow-y-auto border border-bambu-dark-tertiary rounded-lg`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`px-2 py-2 w-10`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:k.length>0&&b.size===k.length,onChange:()=>{b.size===k.length?x(new Set):x(new Set(k.map(e=>e.id)))},className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium`,children:e(`common.name`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-right text-bambu-gray font-medium w-24`,children:e(`settings.catalog.weight`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-center text-bambu-gray font-medium w-20`,children:e(`settings.catalog.type`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 w-24`})]})}),(0,K.jsx)(`tbody`,{children:k.length===0?(0,K.jsx)(`tr`,{children:(0,K.jsx)(`td`,{colSpan:5,className:`px-4 py-8 text-center text-bambu-gray`,children:e(o?`settings.catalog.noMatch`:`settings.catalog.empty`)})}):k.map(t=>(0,K.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${b.has(t.id)?`bg-bambu-dark`:``}`,children:d===t.id?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`td`,{className:`px-2 py-2`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:b.has(t.id),onChange:()=>I(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white focus:border-bambu-green focus:outline-none`,value:p,onChange:e=>m(e.target.value)})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsx)(`input`,{type:`number`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-right focus:border-bambu-green focus:outline-none`,value:h,onChange:e=>g(e.target.value)})}),(0,K.jsx)(`td`,{className:`px-4 py-2 text-center`,children:(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`-`})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>N(t.id),disabled:_,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:_?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)($o,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:M,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`td`,{className:`px-2 py-2`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:b.has(t.id),onChange:()=>I(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,K.jsx)(`td`,{className:`px-4 py-2 text-white`,children:t.name}),(0,K.jsxs)(`td`,{className:`px-4 py-2 text-right font-mono text-white`,children:[t.weight,`g`]}),(0,K.jsx)(`td`,{className:`px-4 py-2 text-center`,children:t.is_default?(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray`,children:e(`settings.catalog.default`)}):(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:e(`settings.catalog.custom`)})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>j(t),className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>T(t),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})})]})},t.id))})]})})]}),w&&(0,K.jsx)(Ed,{title:e(`settings.catalog.deleteEntry`),message:e(`settings.catalog.deleteConfirm`,{name:w.name}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:P,onCancel:()=>T(null)}),S&&(0,K.jsx)(Ed,{title:e(`settings.catalog.deleteSelected`),message:e(`settings.catalog.bulkDeleteConfirm`,{count:b.size}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:async()=>{if(C(!1),b.size!==0)try{let n=await Q.bulkDeleteCatalogEntries([...b]);r(e=>e.filter(e=>!b.has(e.id))),x(new Set),t(e(`settings.catalog.bulkDeleted`,{count:n.deleted}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleBulkDelete failed:`,n),t(e(`settings.catalog.bulkDeleteFailed`),`error`)}},onCancel:()=>C(!1)}),E&&(0,K.jsx)(Ed,{title:e(`settings.catalog.resetCatalog`),message:e(`settings.catalog.resetConfirm`),confirmText:e(`common.reset`),variant:`danger`,onConfirm:F,onCancel:()=>D(!1)})]})}var JRe=2166136261,YRe=16777619;function XRe(...e){let t=JRe,n=new TextEncoder,r=n.encode(`__|`);for(let i of e)typeof i==`string`?t=B5(t,n.encode(i+`|`)):i??(t=B5(t,r));return t>>>0}function B5(e,t){for(let n of t)e^=n,e=Math.imul(e,YRe)>>>0;return e}function ZRe(e){let t=()=>{e|=0,e=e+1831565813|0;let t=Math.imul(e^e>>>15,1|e);return t=t+Math.imul(t^t>>>7,61|t)^t,(t^t>>>14)>>>0},n=(e,n)=>{if(!Number.isFinite(e)||!Number.isFinite(n))throw RangeError(`from and to must be finite numbers`);if(e>n)throw RangeError(`from must be less than or equal to to`);return e===n?e:e+t()/4294967295*(n-e)};return{next:()=>t()/4294967295,floatBetween:(e,t)=>n(e,t),intBetween:(e,t)=>{if(!Number.isInteger(e)||!Number.isInteger(t))throw RangeError(`from and to must be integers`);return Math.round(n(e,t))}}}var V5={table:{dotCount:5,dotScale:1},preview:{dotCount:8,dotScale:1.5},card:{dotCount:40,dotScale:2},bar:{dotCount:20,dotScale:2},groupheader:{dotCount:80,dotScale:2}},H5=[{value:``,labelKey:`inventory.colorEffect.none`},{value:`sparkle`,labelKey:`inventory.colorEffect.sparkle`},{value:`wood`,labelKey:`inventory.colorEffect.wood`},{value:`marble`,labelKey:`inventory.colorEffect.marble`},{value:`glow`,labelKey:`inventory.colorEffect.glow`},{value:`matte`,labelKey:`inventory.colorEffect.matte`},{value:`silk`,labelKey:`inventory.colorEffect.silk`},{value:`galaxy`,labelKey:`inventory.colorEffect.galaxy`},{value:`rainbow`,labelKey:`inventory.colorEffect.rainbow`},{value:`metal`,labelKey:`inventory.colorEffect.metal`},{value:`translucent`,labelKey:`inventory.colorEffect.translucent`},{value:`gradient`,labelKey:`inventory.colorEffect.gradient`},{value:`dual-color`,labelKey:`inventory.colorEffect.dualColor`},{value:`tri-color`,labelKey:`inventory.colorEffect.triColor`},{value:`multicolor`,labelKey:`inventory.colorEffect.multicolor`}],QRe=`repeating-conic-gradient(#979797 0% 25%, #f5f5f5 0% 50%)`,$Re=`12px 12px`,eze={sparkle:(e=0,t=`table`)=>{let n=ZRe(e),r=V5[t]??V5.table,i=[];for(let e=0;e`repeating-linear-gradient(90deg, rgba(0,0,0,0.18) 0 1px, transparent 1px 6px, rgba(0,0,0,0.08) 6px 7px, transparent 7px 12px)`,marble:()=>`repeating-linear-gradient(135deg, rgba(255,255,255,0.18) 0 2px, transparent 2px 8px), repeating-linear-gradient(45deg, rgba(0,0,0,0.10) 0 1px, transparent 1px 7px)`,glow:()=>`radial-gradient(circle at 50% 50%, rgba(255,255,255,0.35) 0%, rgba(255,255,255,0) 70%)`,matte:()=>`linear-gradient(180deg, rgba(0,0,0,0.10) 0%, rgba(0,0,0,0) 50%, rgba(0,0,0,0.10) 100%)`,silk:()=>`linear-gradient(110deg, rgba(255,255,255,0) 30%, rgba(255,255,255,0.30) 50%, rgba(255,255,255,0) 70%)`,galaxy:()=>`linear-gradient(110deg, rgba(255,255,255,0) 25%, rgba(255,255,255,0.40) 50%, rgba(255,255,255,0) 75%)`,metal:()=>`repeating-linear-gradient(90deg, rgba(255,255,255,0.10) 0 1px, transparent 1px 3px), linear-gradient(180deg, rgba(255,255,255,0.18) 0%, rgba(0,0,0,0.18) 100%)`};function U5(e){let t=e.trim().replace(/^#/,``);return t.length!==6&&t.length!==8||!/^[0-9a-fA-F]+$/.test(t)?null:`#${t}`}function W5(e){return e?e.split(`,`).map(e=>U5(e)).filter(e=>!!e):[]}function tze(e,t,n,r){let i=e?U5(e):null;if(t.length===0)return`linear-gradient(${i??`#808080`}, ${i??`#808080`})`;let a=t.length===1?[t[0],t[0]]:t,o=(n??``).toLowerCase(),s=(r??``).toLowerCase();if(o===`multicolor`||s===`multicolor`){let e=a.length;return`conic-gradient(from 0deg, ${a.map((t,n)=>`${t} ${(n/e*360).toFixed(3)}deg ${((n+1)/e*360).toFixed(3)}deg`).join(`, `)})`}if(s===`dual-color`||s===`tri-color`){let e=a.length;return`linear-gradient(to right, ${a.map((t,n)=>`${t} ${(n/e*100).toFixed(3)}% ${((n+1)/e*100).toFixed(3)}%`).join(`, `)})`}return`linear-gradient(135deg, ${a.join(`, `)})`}function nze(e,t,n){let r=eze[e];return r?r(n,t):null}function G5(e){let t=W5(e.extraColors),n=tze(e.rgba,t,e.subtype,e.effectType),r=XRe(e.rgba,e.extraColors,e.subtype,e.effectType),i=typeof e.effectType==`string`?nze(e.effectType,e.effectSize,r):null,a=[];return i&&(Array.isArray(i)?i:[i]).forEach(e=>{a.push({image:e,size:`cover`})}),a.push({image:n,size:`cover`}),a.push({image:QRe,size:$Re}),{backgroundImage:a.map(e=>e.image).join(`, `),backgroundSize:a.map(e=>e.size).join(`, `)}}function K5({rgba:e,extraColors:t,effectType:n,subtype:r,className:i=`w-5 h-5`,shape:a=`circle`,style:o,title:s,effectSize:c}){let l=(0,y.useMemo)(()=>W5(t),[t]),u=(0,y.useMemo)(()=>G5({effectSize:c,rgba:e,extraColors:t,effectType:n,subtype:r}),[c,e,t,n,r]),d=u.backgroundImage,f=u.backgroundSize,p=a===`circle`||a===`pill`?`rounded-full`:`rounded`,m=(()=>{if(!e)return;let t=e.replace(/^#/,``);return t.length>=8&&t.substring(6,8).toLowerCase()!==`ff`?`#${t.substring(0,8)}`:`#${t.substring(0,6)}`})(),h=s??(l.length>0?l.join(`, `):m);return(0,K.jsx)(`span`,{"data-testid":`filament-swatch`,className:`${i} ${p} border border-black/20 inline-block flex-shrink-0`,style:{backgroundImage:d,backgroundSize:f,...o},title:h})}function rze(){let{t:e}=G(),{showToast:t}=xd(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),u=(0,y.useRef)(null),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(`#FFFFFF`),[S,C]=(0,y.useState)(``),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(``),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(new Set),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(null),[B,V]=(0,y.useState)(!1),ee=(0,y.useCallback)(async()=>{try{r(await Q.getColorCatalog())}catch{t(e(`settings.colorCatalog.loadFailed`),`error`)}finally{a(!1)}},[t,e]);(0,y.useEffect)(()=>{ee()},[ee]);let H=[...new Set(n.map(e=>e.manufacturer))].sort(),te=n.filter(e=>{let t=o===``||e.manufacturer.toLowerCase().includes(o.toLowerCase())||e.color_name.toLowerCase().includes(o.toLowerCase())||(e.material?.toLowerCase().includes(o.toLowerCase())??!1),n=c===``||e.manufacturer===c;return t&&n}),ne=()=>{g(``),v(``),x(`#FFFFFF`),C(``),T(``),D(``)},re=async()=>{if(!h.trim()||!_.trim()||!b){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}k(!0);try{let n=await Q.addColorEntry({manufacturer:h.trim(),color_name:_.trim(),hex_color:b,material:S.trim()||null,extra_colors:w.trim()||null,effect_type:E.trim()||null});r(e=>[...e,n].sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),f(!1),ne(),t(e(`settings.colorCatalog.colorAdded`),`success`)}catch{t(e(`settings.colorCatalog.addFailed`),`error`)}finally{k(!1)}},U=e=>{m(e.id),g(e.manufacturer),v(e.color_name),x(e.hex_color),C(e.material||``),T(e.extra_colors||``),D(e.effect_type||``)},ie=()=>{m(null),ne()},ae=async n=>{if(!h.trim()||!_.trim()||!b){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}k(!0);try{let i=await Q.updateColorEntry(n,{manufacturer:h.trim(),color_name:_.trim(),hex_color:b,material:S.trim()||null,extra_colors:w.trim()||null,effect_type:E.trim()||null});r(e=>e.map(e=>e.id===n?i:e).sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),m(null),ne(),t(e(`settings.colorCatalog.colorUpdated`),`success`)}catch{t(e(`settings.colorCatalog.updateFailed`),`error`)}finally{k(!1)}},W=async()=>{if(R)try{await Q.deleteColorEntry(R.id),r(e=>e.filter(e=>e.id!==R.id)),t(e(`settings.colorCatalog.colorDeleted`),`success`)}catch{t(e(`settings.colorCatalog.deleteFailed`),`error`)}finally{z(null)}},oe=async()=>{V(!1),a(!0);try{await Q.resetColorCatalog(),await ee(),t(e(`settings.colorCatalog.resetSuccess`),`success`)}catch{t(e(`settings.colorCatalog.resetFailed`),`error`),a(!1)}},se=async()=>{F(!0),L(null);try{let n={},r=Hu();r&&(n.Authorization=`Bearer ${r}`);let i=await fetch(`/api/v1/inventory/colors/sync`,{method:`POST`,headers:n});if(!i.ok)throw Error(`Failed to start sync`);let a=i.body?.getReader();if(!a)throw Error(`No response body`);let o=new TextDecoder,s=``;for(;;){let{done:n,value:r}=await a.read();if(n)break;s+=o.decode(r,{stream:!0});let i=s.split(` -`);s=i.pop()||``;for(let n of i)if(n.startsWith(`data: `))try{let r=JSON.parse(n.slice(6));r.type===`progress`?L({fetched:r.total_fetched,total:r.total_available}):r.type===`complete`?r.added===0?t(e(`settings.colorCatalog.syncUpToDate`,{count:r.total_fetched}),`success`):t(e(`settings.colorCatalog.syncComplete`,{added:r.added,skipped:r.skipped}),`success`):r.type===`error`&&t(`${e(`settings.colorCatalog.syncError`)}: ${r.error}`,`error`)}catch{}}await ee()}catch{t(e(`settings.colorCatalog.syncFailed`),`error`)}finally{F(!1),L(null)}},ce=e=>{j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,K.jsxs)(pd,{id:`card-color-catalog`,children:[(0,K.jsxs)(md,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,K.jsx)(ll,{className:`w-5 h-5 text-bambu-gray`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.colorCatalog.title`)}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,n.length,`)`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.jsxs)(`button`,{onClick:()=>{let r=n.map(({manufacturer:e,color_name:t,hex_color:n,material:r,extra_colors:i,effect_type:a})=>({manufacturer:e,color_name:t,hex_color:n,material:r,extra_colors:i,effect_type:a})),i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`color-catalog.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),t(e(`settings.colorCatalog.exported`,{count:n.length}),`success`)},className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.export`)})]}),(0,K.jsxs)(`button`,{onClick:()=>u.current?.click(),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,K.jsx)(Su,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.import`)})]}),(0,K.jsx)(`input`,{ref:u,type:`file`,accept:`.json`,className:`hidden`,onChange:async i=>{let a=i.target.files?.[0];if(a){try{let i=await a.text(),o=JSON.parse(i);if(!Array.isArray(o))throw Error(`Invalid format`);let s=0,c=0;for(let e of o){if(!e.manufacturer||!e.color_name||!e.hex_color){c++;continue}if(n.some(t=>t.manufacturer.toLowerCase()===e.manufacturer.toLowerCase()&&t.color_name.toLowerCase()===e.color_name.toLowerCase()&&(t.material||``).toLowerCase()===(e.material||``).toLowerCase())){c++;continue}try{let t=await Q.addColorEntry({manufacturer:e.manufacturer,color_name:e.color_name,hex_color:e.hex_color,material:e.material||null,extra_colors:e.extra_colors||null,effect_type:e.effect_type||null});r(e=>[...e,t].sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),s++}catch{c++}}t(e(`settings.colorCatalog.imported`,{added:s,skipped:c}),`success`)}catch{t(e(`settings.colorCatalog.importFailed`),`error`)}u.current&&(u.current.value=``)}}}),(0,K.jsxs)(`button`,{onClick:se,disabled:P,className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.colorCatalog.syncTooltip`),children:[P?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(ys,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:P?I?`${Math.min(I.fetched,I.total)} / ${I.total}`:e(`settings.colorCatalog.starting`):e(`settings.colorCatalog.sync`)})]}),(0,K.jsxs)(`button`,{onClick:()=>V(!0),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.reset`)})]}),(0,K.jsxs)(`button`,{onClick:()=>f(!0),className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.add`)})]})]}),A.size>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg`,children:[(0,K.jsx)(`span`,{className:`text-sm text-red-400`,children:e(`settings.colorCatalog.selectedCount`,{count:A.size})}),(0,K.jsxs)(`button`,{onClick:()=>N(!0),className:`ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5`,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`settings.colorCatalog.deleteSelected`)]}),(0,K.jsx)(`button`,{onClick:()=>j(new Set),className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors`,children:e(`common.cancel`)})]})]}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.colorCatalog.description`)}),(0,K.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1 min-w-[200px]`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.searchColors`),value:o,onChange:e=>s(e.target.value)})]}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:c,onChange:e=>l(e.target.value),children:[(0,K.jsx)(`option`,{value:``,children:e(`settings.colorCatalog.allManufacturers`)}),H.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]})]}),d&&(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e(`settings.colorCatalog.addNewColor`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-2 items-end`,children:[(0,K.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.manufacturer`),value:h,onChange:e=>g(e.target.value)}),(0,K.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.colorName`),value:_,onChange:e=>v(e.target.value)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`color`,className:`w-20 h-10 rounded cursor-pointer border border-bambu-dark-tertiary`,value:b,onChange:e=>x(e.target.value)}),(0,K.jsx)(`input`,{type:`text`,className:`w-32 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:`#FFFFFF`,value:b,onChange:e=>x(e.target.value)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`input`,{type:`text`,className:`flex-1 max-w-lg min-w-[200px] px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.materialOptional`),value:S,onChange:e=>C(e.target.value)}),(0,K.jsxs)(`button`,{onClick:re,disabled:O,className:`w-24 px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center justify-center gap-3`,children:[O?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)($o,{className:`w-4 h-4`}),e(`common.add`)]}),(0,K.jsx)(`button`,{onClick:()=>{f(!1),ne()},className:`p-2 ml-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 mt-2`,children:[(0,K.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`inventory.extraColorsPlaceholder`),value:w,onChange:e=>T(e.target.value)}),(0,K.jsx)(`select`,{className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:E,onChange:e=>D(e.target.value),children:H5.map(t=>(0,K.jsx)(`option`,{value:t.value,children:e(t.labelKey)},t.value||`none`))})]})]}),(o||c)&&(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:e(`settings.colorCatalog.showing`,{filtered:te.length,total:n.length})}),i?(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-5 h-5 animate-spin mr-2`}),e(`common.loading`)]}):(0,K.jsx)(`div`,{className:`max-h-[600px] overflow-auto border border-bambu-dark-tertiary rounded-lg`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`px-2 py-2 w-10`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:te.length>0&&A.size===te.length,onChange:()=>{A.size===te.length?j(new Set):j(new Set(te.map(e=>e.id)))},className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,K.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium w-12`}),(0,K.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`settings.colorCatalog.manufacturer`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`inventory.material`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`settings.colorCatalog.colorName`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium w-24`,children:e(`settings.colorCatalog.hex`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 w-16`})]})}),(0,K.jsx)(`tbody`,{children:te.length===0?(0,K.jsx)(`tr`,{children:(0,K.jsx)(`td`,{colSpan:7,className:`px-3 py-8 text-center text-bambu-gray`,children:e(o||c?`settings.colorCatalog.noMatch`:`settings.colorCatalog.empty`)})}):te.map(t=>(0,K.jsxs)(y.Fragment,{children:[(0,K.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${A.has(t.id)?`bg-bambu-dark`:``}`,children:p===t.id?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`td`,{className:`px-2 py-2`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:A.has(t.id),onChange:()=>ce(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{type:`color`,className:`w-8 h-8 rounded cursor-pointer border border-bambu-dark-tertiary`,value:b,onChange:e=>x(e.target.value)})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:h,onChange:e=>g(e.target.value)})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:S,onChange:e=>C(e.target.value)})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:_,onChange:e=>v(e.target.value)})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:b,onChange:e=>x(e.target.value)})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>ae(t.id),disabled:O,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:O?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)($o,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:ie,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`td`,{className:`px-2 py-2`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:A.has(t.id),onChange:()=>ce(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(K5,{rgba:t.hex_color.replace(/^#/,``)+(t.hex_color.length===7?`FF`:``),extraColors:t.extra_colors,effectType:t.effect_type,className:`w-8 h-8`,shape:`square`,title:t.hex_color,effectSize:`table`})}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-white`,children:t.manufacturer}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:t.material||`-`}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-white`,children:t.color_name}),(0,K.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs text-bambu-gray`,children:t.hex_color}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>U(t),className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>z(t),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})})]})}),p===t.id&&(0,K.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary/50 bg-bambu-dark`,children:[(0,K.jsx)(`td`,{colSpan:2}),(0,K.jsx)(`td`,{className:`px-3 py-2`,colSpan:2,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`,placeholder:e(`inventory.extraColorsPlaceholder`),value:w,onChange:e=>T(e.target.value)})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,colSpan:2,children:(0,K.jsx)(`select`,{className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:E,onChange:e=>D(e.target.value),children:H5.map(t=>(0,K.jsx)(`option`,{value:t.value,children:e(t.labelKey)},t.value||`none`))})}),(0,K.jsx)(`td`,{})]})]},t.id))})]})})]}),R&&(0,K.jsx)(Ed,{title:e(`settings.colorCatalog.deleteColor`),message:e(`settings.colorCatalog.deleteConfirm`,{name:`${R.manufacturer} - ${R.color_name}`}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:W,onCancel:()=>z(null)}),M&&(0,K.jsx)(Ed,{title:e(`settings.colorCatalog.deleteSelected`),message:e(`settings.colorCatalog.bulkDeleteConfirm`,{count:A.size}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:async()=>{if(N(!1),A.size!==0)try{let n=await Q.bulkDeleteColorEntries([...A]);r(e=>e.filter(e=>!A.has(e.id))),j(new Set),t(e(`settings.colorCatalog.bulkDeleted`,{count:n.deleted}),`success`)}catch{t(e(`settings.colorCatalog.bulkDeleteFailed`),`error`)}},onCancel:()=>N(!1)}),B&&(0,K.jsx)(Ed,{title:e(`settings.colorCatalog.resetCatalog`),message:e(`settings.colorCatalog.resetConfirm`),confirmText:e(`common.reset`),variant:`danger`,onConfirm:oe,onCancel:()=>V(!1)})]})}function ize({link:e,onClose:t}){let{t:n}=G(),r=Qa(),i=!!e,a=(0,y.useRef)(null),[o,s]=(0,y.useState)(e?.name||``),[c,l]=(0,y.useState)(e?.url||``),[u,d]=(0,y.useState)(e?.icon||`link`),[f,p]=(0,y.useState)(e?.open_in_new_tab||!1),[m,h]=(0,y.useState)(!!e?.custom_icon),[g,_]=(0,y.useState)(e?.custom_icon?Q.getExternalLinkIconUrl(e.id):null),[v,b]=(0,y.useState)(null),[x,S]=(0,y.useState)(null);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let C=J({mutationFn:async e=>{let t=await Q.createExternalLink(e);return v?await Q.uploadExternalLinkIcon(t.id,v):t},onSuccess:()=>{r.invalidateQueries({queryKey:[`external-links`]}),t()},onError:e=>{S(e.message)}}),w=J({mutationFn:async t=>{let n=await Q.updateExternalLink(e.id,t);return v?n=await Q.uploadExternalLinkIcon(e.id,v):!m&&e?.custom_icon&&(n=await Q.deleteExternalLinkIcon(e.id)),n},onSuccess:()=>{r.invalidateQueries({queryKey:[`external-links`]}),t()},onError:e=>{S(e.message)}}),T=e=>{let t=e.target.files?.[0];if(t){if(![`image/png`,`image/jpeg`,`image/gif`,`image/svg+xml`,`image/webp`,`image/x-icon`].includes(t.type)){S(`Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)`);return}if(t.size>1024*1024){S(`Image file must be less than 1MB`);return}b(t),h(!0);let e=new FileReader;e.onload=e=>{_(e.target?.result)},e.readAsDataURL(t)}},E=()=>{b(null),_(null),h(!1),a.current&&(a.current.value=``)},D=e=>{if(e.preventDefault(),S(null),!o.trim()){S(`Name is required`);return}if(!c.trim()){S(`URL is required`);return}if(!c.startsWith(`http://`)&&!c.startsWith(`https://`)){S(`URL must start with http:// or https://`);return}let t={name:o.trim(),url:c.trim(),icon:u,open_in_new_tab:f};i?w.mutate(t):C.mutate(t)},O=C.isPending||w.isPending,k=Ad(u);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`,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-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:m&&g?(0,K.jsx)(`img`,{src:g,alt:``,className:`w-5 h-5 rounded`}):(0,K.jsx)(k,{className:`w-5 h-5`})}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i?`Edit Link`:`Add External Link`})]}),(0,K.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`form`,{onSubmit:D,className:`p-6 space-y-4`,children:[x&&(0,K.jsx)(`div`,{className:`p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400`,children:x}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Name *`}),(0,K.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`My Link`,maxLength:50,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`URL *`}),(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`https://example.com`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`label`,{className:`text-sm text-bambu-gray`,children:n(`externalLinks.openInNewTab`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>p(!f),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${f?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${f?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray`,children:`Icon`}),(0,K.jsxs)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:`Custom Icon`}),(0,K.jsx)(`input`,{ref:a,type:`file`,accept:`image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon`,className:`hidden`,onChange:T}),m&&g?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`img`,{src:g,alt:`Custom icon`,className:`w-8 h-8 rounded border border-bambu-dark-tertiary`}),(0,K.jsx)(`button`,{type:`button`,onClick:E,className:`p-1 text-red-400 hover:text-red-300 transition-colors`,title:`Remove custom icon`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]}):(0,K.jsxs)($,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>a.current?.click(),children:[(0,K.jsx)(Su,{className:`w-4 h-4`}),`Upload`]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:`PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB.`})]}),!m&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray block mb-2`,children:`Or choose a preset icon`}),(0,K.jsx)(jd,{value:u,onChange:d})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:`Cancel`}),(0,K.jsxs)($,{type:`submit`,disabled:O,className:`flex-1`,children:[O?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Ol,{className:`w-4 h-4`}),i?`Save`:`Add`]})]})]})]})})}function aze(){let{t:e}=G(),t=Qa(),{authEnabled:n,hasPermission:r}=sd(),{showToast:i}=xd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(Gf),[_,v]=(0,y.useState)(()=>Uf(qf.map(e=>e.id))),{data:b,isLoading:x}=q({queryKey:[`external-links`],queryFn:Q.getExternalLinks}),S=J({mutationFn:e=>Q.deleteExternalLink(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`external-links`]})}}),{data:C}=q({queryKey:[`settings`],queryFn:Q.getSettings,enabled:n&&r(`settings:update`)}),w=J({mutationFn:e=>Q.updateSettings({default_sidebar_order:e}),onSuccess:(n,r)=>{t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`default-sidebar-order`]}),i(e(r?`settings.sidebarDefaultSet`:`settings.sidebarDefaultCleared`),`success`)},onError:()=>{i(e(`settings.sidebarDefaultFailed`),`error`)}}),T=(0,y.useMemo)(()=>{let e=new Map(qf.map(e=>[e.id,e])),t=new Map((b||[]).map(e=>[`ext-${e.id}`,e])),n=[],r=new Set,i=i=>{if(r.has(i))return;let a=e.get(i);if(a){n.push({type:`system`,id:i,navItem:a}),r.add(i);return}let o=t.get(i);o&&(n.push({type:`external`,id:i,link:o}),r.add(i))};return _.forEach(i),qf.forEach(e=>i(e.id)),(b||[]).forEach(e=>i(`ext-${e.id}`)),n},[b,_]),E=e=>{v(e),Wf(e)},D=(e,t)=>{f(t),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},O=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`,m(t)},k=(e,t)=>{if(e.preventDefault(),d===null||d===t){f(null),m(null);return}let n=T.map(e=>e.id),r=n.indexOf(d),i=n.indexOf(t);if(r===-1||i===-1){f(null),m(null);return}n.splice(r,1),n.splice(i,0,d),E(n),f(null),m(null)},A=()=>{f(null),m(null)},j=e=>{u(e)},M=()=>{l&&(S.mutate(l.id),u(null))},N=()=>{let e=[...qf.map(e=>e.id),...(b||[]).map(e=>`ext-${e.id}`)];g([]),v(e),Kf([]),Wf(e)},P=e=>{let t=T.map(e=>e.id);w.mutate(e?JSON.stringify({order:t,hiddenSystemItemIds:h}):``)},F=e=>{if(e===`settings`)return;let t=h.includes(e)?h.filter(t=>t!==e):[...h,e];g(t),Kf(t)},I=n&&r(`settings:update`),L=!!C?.default_sidebar_order;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(pd,{id:`card-sidebar-links`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-y-2 gap-x-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Ic,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`externalLinks.sidebarLayout`)})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[I&&(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:e(`settings.setDefault`)}),(0,K.jsx)(y5,{checked:L,onChange:P,disabled:w.isPending})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:N,className:`whitespace-nowrap`,children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),e(`settings.reset`)]}),(0,K.jsxs)($,{size:`sm`,onClick:()=>o(!0),className:`whitespace-nowrap`,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),`Add Link`]})]})]})}),(0,K.jsxs)(hd,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`externalLinks.sidebarLayoutDescription`)}),x?(0,K.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})}):(0,K.jsx)(`div`,{className:`space-y-2`,children:T.map(t=>{let n=t.type===`system`&&h.includes(t.id),r=t.id===`settings`;if(t.type===`system`){let i=t.navItem.icon;return(0,K.jsxs)(`div`,{draggable:!0,onDragStart:e=>D(e,t.id),onDragOver:e=>O(e,t.id),onDragLeave:()=>m(null),onDrop:e=>k(e,t.id),onDragEnd:A,className:`relative flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${d===t.id?`opacity-50`:n?`opacity-60`:``} ${p===t.id&&d!==t.id?`before:absolute before:left-3 before:right-3 before:top-0 before:h-0.5 before:bg-bambu-green`:``}`,children:[(0,K.jsx)(gc,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0`}),(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray`,children:(0,K.jsx)(i,{className:`w-4 h-4`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`span`,{className:`text-white font-medium truncate block`,children:e(t.navItem.labelKey)}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray truncate block`,children:e(r?`externalLinks.requiredInSidebar`:n?`externalLinks.hiddenFromSidebar`:`externalLinks.visibleInSidebar`)})]}),(0,K.jsx)(`button`,{onClick:()=>F(t.id),disabled:r,className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors flex-shrink-0 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-bambu-gray`,title:e(r?`externalLinks.settingsCannotBeHidden`:n?`externalLinks.showPage`:`externalLinks.hidePage`),"aria-label":e(r?`externalLinks.settingsCannotBeHidden`:n?`externalLinks.showPage`:`externalLinks.hidePage`),children:n?(0,K.jsx)(Ws,{className:`w-4 h-4`}):(0,K.jsx)(Gs,{className:`w-4 h-4`})})]},t.id)}let i=t.link,a=Ad(i.icon);return(0,K.jsxs)(`div`,{draggable:!0,onDragStart:e=>D(e,t.id),onDragOver:e=>O(e,t.id),onDragLeave:()=>m(null),onDrop:e=>k(e,t.id),onDragEnd:A,className:`relative flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${d===t.id?`opacity-50`:``} ${p===t.id&&d!==t.id?`before:absolute before:left-3 before:right-3 before:top-0 before:h-0.5 before:bg-bambu-green`:``}`,children:[(0,K.jsx)(gc,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0`}),(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray`,children:i.custom_icon?(0,K.jsx)(`img`,{src:Q.getExternalLinkIconUrl(i.id),alt:``,className:`w-4 h-4`}):(0,K.jsx)(a,{className:`w-4 h-4`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-white font-medium truncate`,children:i.name}),(0,K.jsx)(Us,{className:`w-3 h-3 text-bambu-gray flex-shrink-0`})]}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray truncate block`,children:i.url})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,K.jsx)(`button`,{onClick:()=>c(i),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,title:e(`common.edit`),children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>j(i),disabled:S.isPending,className:`p-2 rounded-lg hover:bg-red-500/20 text-bambu-gray hover:text-red-400 transition-colors disabled:opacity-50`,title:e(`externalLinks.deleteLink`),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]},t.id)})})]})]}),(a||s)&&(0,K.jsx)(ize,{link:s,onClose:()=>{o(!1),c(null)}}),l&&(0,K.jsx)(Ed,{title:`Delete Link`,message:`Are you sure you want to delete "${l.name}"? This action cannot be undone.`,confirmText:`Delete`,cancelText:`Cancel`,variant:`danger`,onConfirm:M,onCancel:()=>u(null)})]})}async function q5(e){if(navigator.clipboard&&window.isSecureContext)try{return await navigator.clipboard.writeText(e),!0}catch{}let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{return t.select(),document.execCommand(`copy`)}catch{return!1}finally{t.parentNode&&t.parentNode.removeChild(t)}}function oze(e,t,n=`text/plain`){let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i)}function sze({status:e}){return e===`pass`?(0,K.jsx)(us,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}):e===`fail`?(0,K.jsx)(ms,{className:`w-5 h-5 text-red-400 flex-shrink-0`}):e===`warn`?(0,K.jsx)(vu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}):(0,K.jsx)(fs,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`})}function cze({vpId:e,vpName:t,onClose:n}){let{t:r}=G(),i=J({mutationFn:()=>Qu.diagnose(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,o=a?.overall===`ok`?`bg-bambu-green/10 border-bambu-green/30 text-bambu-green`:a?.overall===`warnings`?`bg-amber-500/10 border-amber-500/30 text-amber-300`:`bg-red-500/10 border-red-500/30 text-red-300`;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 max-h-[85vh]`,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)(ru,{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(`vpDiagnostic.title`,{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)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-6 space-y-4 overflow-y-auto`,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(`vpDiagnostic.running`)})]}),i.isError&&(0,K.jsx)(`div`,{className:`rounded-lg bg-red-500/10 border border-red-500/30 px-4 py-3 text-sm text-red-300`,children:r(`vpDiagnostic.runFailed`,{error:i.error.message})}),a&&(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`ol`,{className:`space-y-2`,children:a.checks.map(e=>{let t=r(`vpDiagnostic.check.${e.id}.${e.status}`,{...e.params,defaultValue:``});return(0,K.jsxs)(`li`,{className:`flex items-start gap-3 bg-bambu-dark rounded-lg px-4 py-2.5 ${e.status===`skip`?`opacity-60`:``}`,children:[(0,K.jsx)(`div`,{className:`mt-0.5`,children:(0,K.jsx)(sze,{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(`vpDiagnostic.check.${e.id}.title`,e.params)}),t&&(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5`,children:t})]})]},e.id)})}),(0,K.jsx)(`div`,{className:`rounded-lg border px-4 py-3 text-sm ${o}`,children:r(`vpDiagnostic.overall.${a.overall}`)})]})]}),(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(`vpDiagnostic.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 J5={archive:`archive`,review:`review`,queue:`queue`,proxy:`proxy`};function Y5(e){return e===`immediate`?`archive`:e===`print_queue`||e===`queue`?`queue`:e===`archive`||e===`review`||e===`proxy`?e:`archive`}function lze({printer:e,models:t}){let{t:n}=G(),r=Qa(),{showToast:i}=xd(),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(e.enabled),[l,u]=(0,y.useState)(e.name),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(Y5(e.mode)),[h,g]=(0,y.useState)(e.target_printer_id),[_,v]=(0,y.useState)(e.bind_ip||``),[b,x]=(0,y.useState)(e.remote_interface_ip||``),[S,C]=(0,y.useState)(e.model||``),[w,T]=(0,y.useState)(e.auto_dispatch??!0),[E,D]=(0,y.useState)(e.queue_force_color_match??!1),[O,k]=(0,y.useState)(e.gcode_injection??!1),[A,j]=(0,y.useState)(e.tailscale_disabled??!0),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(null),[I,L]=(0,y.useState)(!1),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(!1),{data:ee}=q({queryKey:[`tailscale-status`],queryFn:Qu.getTailscaleStatus,enabled:!A,staleTime:6e4}),H=ee?.available?ee.fqdn:``,te=ee?.available?ee.tailscale_ips?.[0]??``:``,ne=async e=>{e.stopPropagation();let t=H;t&&(await q5(t)?(V(!0),i(n(`printers.copied`)),setTimeout(()=>V(!1),2e3)):i(n(`virtualPrinter.toast.copyFailed`),`error`))};(0,y.useEffect)(()=>{P||(c(e.enabled),m(Y5(e.mode)),u(e.name),g(e.target_printer_id),v(e.bind_ip||``),x(e.remote_interface_ip||``),C(e.model||``),T(e.auto_dispatch??!0),D(e.queue_force_color_match??!1),k(e.gcode_injection??!1),j(e.tailscale_disabled??!0))},[e,P]);let{data:re}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:U}=q({queryKey:[`network-interfaces`],queryFn:()=>Q.getNetworkInterfaces().then(e=>e.interfaces)}),ie=J({mutationFn:t=>Qu.update(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`virtual-printers`]}),i(n(`virtualPrinter.toast.updated`)),F(null)},onError:t=>{i(t.message||n(`virtualPrinter.toast.failedToUpdate`),`error`),c(e.enabled),m(Y5(e.mode)),g(e.target_printer_id),v(e.bind_ip||``),j(e.tailscale_disabled??!0),F(null)}}),ae=J({mutationFn:()=>Qu.remove(e.id),onSuccess:()=>{r.invalidateQueries({queryKey:[`virtual-printers`]}),i(n(`virtualPrinter.toast.deleted`)),L(!1)},onError:e=>{i(e.message||n(`virtualPrinter.toast.failedToDelete`),`error`),L(!1)}}),W=t=>{t.stopPropagation();let r=!s;if(r){if(!_){i(n(`virtualPrinter.toast.bindIpRequired`),`error`);return}if(p===`proxy`){if(!h){i(n(`virtualPrinter.toast.targetPrinterRequired`),`error`);return}}else if(!d&&!e.access_code_set){i(n(`virtualPrinter.toast.accessCodeRequired`),`error`);return}}c(r),F(`toggle`),ie.mutate({enabled:r})},oe=()=>{l.trim()&&(F(`name`),ie.mutate({name:l.trim()}))},se=()=>{if(!d){i(n(`virtualPrinter.toast.accessCodeEmpty`),`error`);return}if(d.length!==8){i(n(`virtualPrinter.toast.accessCodeLength`),`error`);return}F(`accessCode`),ie.mutate({access_code:d}),f(``)},ce=e=>{m(e),F(`mode`),ie.mutate({mode:e})},le=e=>{C(e),F(`model`),ie.mutate({model:e})},ue=e=>{let t=me?.access_code,r=re?.find(t=>t.id===e)?.access_code;g(e),F(`targetPrinter`),ie.mutate({target_printer_id:e},{onSuccess:()=>{t&&r&&t!==r&&i(n(`virtualPrinter.toast.targetCodeChangedRebind`),`info`)}})},de=e=>{x(e),F(`remoteInterface`),ie.mutate({remote_interface_ip:e})},fe=e.status?.running||!1,pe=n(`virtualPrinter.mode.${J5[p]||`archive`}`),me=re?.find(e=>e.id===h),he=me?.name,ge=!!h,_e=ge?me?.access_code??``:``;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(pd,{children:[(0,K.jsxs)(`div`,{className:`px-4 py-3 flex items-center gap-3 cursor-pointer select-none`,onClick:()=>o(!a),children:[(0,K.jsx)(`button`,{className:`text-bambu-gray flex-shrink-0`,children:a?(0,K.jsx)(es,{className:`w-4 h-4`}):(0,K.jsx)(ts,{className:`w-4 h-4`})}),(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full flex-shrink-0 ${fe?`bg-green-400 animate-pulse`:`bg-gray-500`}`}),(0,K.jsx)(`span`,{className:`text-white font-medium truncate`,children:e.name}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:pe}),e.model_name&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:e.model_name}),he&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0 truncate`,children:[p===`proxy`&&(0,K.jsx)(Oo,{className:`w-3 h-3 inline mr-1`}),he]}),_&&(0,K.jsx)(`span`,{className:`text-[10px] text-bambu-gray flex-shrink-0 font-mono`,children:_}),b&&(0,K.jsx)(`span`,{className:`text-[10px] text-bambu-gray flex-shrink-0 font-mono`,children:b}),(0,K.jsx)(`div`,{className:`ml-auto flex items-center gap-2 flex-shrink-0`,onClick:e=>e.stopPropagation(),children:(0,K.jsx)(`button`,{onClick:W,disabled:P===`toggle`,className:`relative w-10 h-5 rounded-full transition-colors ${s?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${P===`toggle`?`opacity-50`:``}`,children:(0,K.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${s?`translate-x-5`:``}`})})})]}),a&&(0,K.jsxs)(hd,{className:`pt-0 space-y-4`,children:[(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),onBlur:oe,onKeyDown:e=>e.key===`Enter`&&oe(),className:`flex-1 text-sm text-white bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`button`,{onClick:()=>z(!0),className:`p-1.5 text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:n(`vpDiagnostic.runButton`),children:(0,K.jsx)(ru,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>L(!0),className:`p-1.5 text-bambu-gray hover:text-red-400 transition-colors flex-shrink-0`,title:n(`common.delete`),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 -mt-2`,children:[H&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-green-400/70 min-w-0`,children:[(0,K.jsx)(Bl,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`font-mono text-xs truncate`,children:te?`${te} (${H})`:H}),(0,K.jsx)(`button`,{onClick:ne,className:`p-0.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors flex-shrink-0`,title:n(B?`printers.copied`:`printers.copyToClipboard`),children:B?(0,K.jsx)($o,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,K.jsx)(Ds,{className:`w-3.5 h-3.5`})})]}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-mono ml-auto flex-shrink-0`,children:e.serial})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium mb-2`,children:n(`virtualPrinter.mode.title`)}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:[`archive`,`review`,`queue`,`proxy`].map(e=>(0,K.jsxs)(`button`,{onClick:()=>ce(e),disabled:P===`mode`,className:`p-2 rounded-lg border text-left transition-colors ${p===e?e===`proxy`?`border-blue-500 bg-blue-500/10`:`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-white text-xs font-medium`,children:[e===`proxy`&&(0,K.jsx)(Oo,{className:`w-3 h-3`}),n(`virtualPrinter.mode.${J5[e]}`)]}),(0,K.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.mode.${J5[e]}Desc`)})]},e))})]}),p===`queue`&&(0,K.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.autoDispatch.title`)}),(0,K.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.autoDispatch.description`)})]}),(0,K.jsx)(`button`,{onClick:()=>{let e=!w;T(e),F(`autoDispatch`),ie.mutate({auto_dispatch:e})},disabled:P===`autoDispatch`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${w?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${P===`autoDispatch`?`opacity-50`:``}`,children:(0,K.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${w?`translate-x-5`:``}`})})]})}),p===`queue`&&(0,K.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.queueForceColorMatch.title`)}),(0,K.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.queueForceColorMatch.description`)})]}),(0,K.jsx)(`button`,{onClick:()=>{let e=!E;D(e),F(`queueForceColorMatch`),ie.mutate({queue_force_color_match:e})},disabled:P===`queueForceColorMatch`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${E?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${P===`queueForceColorMatch`?`opacity-50`:``}`,children:(0,K.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${E?`translate-x-5`:``}`})})]})}),p===`queue`&&(0,K.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.gcodeInjection.title`)}),(0,K.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.gcodeInjection.description`)})]}),(0,K.jsx)(`button`,{onClick:()=>{let e=!O;k(e),F(`gcodeInjection`),ie.mutate({gcode_injection:e})},disabled:P===`gcodeInjection`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${O?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${P===`gcodeInjection`?`opacity-50`:``}`,children:(0,K.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${O?`translate-x-5`:``}`})})]})}),(0,K.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.tailscaleDisabled.title`)}),(0,K.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.tailscaleDisabled.description`)})]}),(0,K.jsx)(`button`,{onClick:()=>{let e=!A;j(e),F(`tailscaleDisabled`),ie.mutate({tailscale_disabled:e})},disabled:P===`tailscaleDisabled`,className:`relative w-10 h-5 rounded-full transition-colors shrink-0 ${A?`bg-bambu-dark-tertiary`:`bg-bambu-green`} ${P===`tailscaleDisabled`?`opacity-50`:``}`,children:(0,K.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${A?``:`translate-x-5`}`})})]})}),p!==`proxy`&&(0,K.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium mb-1`,children:n(`virtualPrinter.model.title`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`virtualPrinter.model.description`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`select`,{value:S,onChange:e=>le(e.target.value),disabled:P===`model`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:Object.entries(t).map(([e,t])=>(0,K.jsxs)(`option`,{value:e,children:[t,` (`,e,`)`]},e))}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),p===`proxy`&&(0,K.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2 p-2 rounded bg-blue-500/10 border border-blue-500/30`,children:[(0,K.jsx)(kc,{className:`w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`virtualPrinter.proxy.accessCodeHint`)})]})}),p!==`proxy`&&(0,K.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.accessCode.title`)}),ge?(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-blue-400`,children:[(0,K.jsx)(kc,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.inheritedFromTarget`)]}):e.access_code_set?(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-green-400`,children:[(0,K.jsx)($o,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.isSet`)]}):(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-yellow-400`,children:[(0,K.jsx)(vu,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.notSet`)]})]}),ge?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{type:M?`text`:`password`,value:_e,readOnly:!0,"aria-label":n(`virtualPrinter.accessCode.title`),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm pr-10 font-mono opacity-90 cursor-default`}),(0,K.jsx)(`button`,{onClick:()=>N(!M),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,"aria-label":n(M?`virtualPrinter.accessCode.hide`:`virtualPrinter.accessCode.reveal`),children:M?(0,K.jsx)(Ws,{className:`w-4 h-4`}):(0,K.jsx)(Gs,{className:`w-4 h-4`})})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`virtualPrinter.accessCode.derivedFromTargetHint`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(`input`,{type:M?`text`:`password`,value:d,onChange:e=>f(e.target.value),placeholder:e.access_code_set?n(`virtualPrinter.accessCode.placeholderChange`):n(`virtualPrinter.accessCode.placeholder`),maxLength:8,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm placeholder-bambu-gray pr-10 font-mono`}),(0,K.jsx)(`button`,{onClick:()=>N(!M),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:M?(0,K.jsx)(Ws,{className:`w-4 h-4`}):(0,K.jsx)(Gs,{className:`w-4 h-4`})})]}),(0,K.jsx)($,{onClick:se,disabled:!d||P===`accessCode`,variant:`primary`,children:P===`accessCode`?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]}),d&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:(0,K.jsx)(`span`,{className:d.length===8?`text-green-400`:`text-yellow-400`,children:n(`virtualPrinter.accessCode.charCount`,{count:d.length})})})]})]}),(0,K.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium mb-2`,children:n(`virtualPrinter.targetPrinter.title`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:h??``,onChange:e=>{let t=parseInt(e.target.value,10);isNaN(t)||ue(t)},disabled:P===`targetPrinter`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,K.jsx)(`option`,{value:``,children:n(`virtualPrinter.targetPrinter.placeholder`)}),re?.map(e=>(0,K.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.ip_address,`)`]},e.id))]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,K.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium mb-1`,children:n(`virtualPrinter.bindIp.title`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:_,onChange:e=>{v(e.target.value),F(`bindIp`),ie.mutate({bind_ip:e.target.value})},disabled:P===`bindIp`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,K.jsx)(`option`,{value:``,children:n(`virtualPrinter.bindIp.placeholder`)}),U?.map(e=>(0,K.jsxs)(`option`,{value:e.ip,children:[e.name,` (`,e.ip,`)`,e.is_alias?` [alias]`:``,` - `,e.subnet]},e.ip))]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`virtualPrinter.bindIp.hint`)})]}),(0,K.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.remoteInterface.title`)}),b?(0,K.jsx)(`span`,{className:`flex items-center gap-1 text-xs text-green-400`,children:(0,K.jsx)($o,{className:`w-3 h-3`})}):(0,K.jsx)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray`,title:n(`virtualPrinter.remoteInterface.optional`),children:(0,K.jsx)(kc,{className:`w-3 h-3`})})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:b,onChange:e=>de(e.target.value),disabled:P===`remoteInterface`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,K.jsx)(`option`,{value:``,children:n(`virtualPrinter.remoteInterface.placeholder`)}),U?.map(e=>(0,K.jsxs)(`option`,{value:e.ip,children:[e.name,` (`,e.ip,`) - `,e.subnet]},e.ip))]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]})]})]}),I&&(0,K.jsx)(Ed,{title:n(`virtualPrinter.deleteConfirm.title`),message:n(`virtualPrinter.deleteConfirm.message`,{name:e.name}),variant:`danger`,confirmText:n(`common.delete`),isLoading:ae.isPending,onConfirm:()=>ae.mutate(),onCancel:()=>L(!1)}),R&&(0,K.jsx)(cze,{vpId:e.id,vpName:e.name,onClose:()=>z(!1)})]})}var X5={archive:`archive`,review:`review`,queue:`queue`,proxy:`proxy`};function uze({onClose:e}){let{t}=G(),n=Qa(),{showToast:r}=xd(),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(`archive`),[c,l]=(0,y.useState)(null),{data:u}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),d=J({mutationFn:()=>Qu.create({name:i.trim()||`Bambuddy`,mode:o,target_printer_id:o===`proxy`?c??void 0:void 0}),onSuccess:()=>{n.invalidateQueries({queryKey:[`virtual-printers`]}),r(t(`virtualPrinter.toast.created`)),e()},onError:e=>{r(e.message||t(`virtualPrinter.toast.failedToCreate`),`error`)}});return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:e,children:(0,K.jsx)(pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(hd,{className:`p-6 space-y-4`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t(`virtualPrinter.addDialog.title`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.addDialog.name`)}),(0,K.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`Bambuddy`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm placeholder-bambu-gray`,autoFocus:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.mode.title`)}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:[`archive`,`review`,`queue`,`proxy`].map(e=>(0,K.jsxs)(`button`,{onClick:()=>s(e),className:`p-2 rounded-lg border text-left transition-colors ${o===e?e===`proxy`?`border-blue-500 bg-blue-500/10`:`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-white text-xs font-medium`,children:[e===`proxy`&&(0,K.jsx)(Oo,{className:`w-3 h-3`}),t(`virtualPrinter.mode.${X5[e]}`)]}),(0,K.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:t(`virtualPrinter.mode.${X5[e]}Desc`)})]},e))})]}),o===`proxy`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.targetPrinter.title`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:c??``,onChange:e=>{let t=parseInt(e.target.value,10);l(isNaN(t)?null:t)},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm appearance-none cursor-pointer pr-10`,children:[(0,K.jsx)(`option`,{value:``,children:t(`virtualPrinter.targetPrinter.placeholder`)}),u?.map(e=>(0,K.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.ip_address,`)`]},e.id))]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`virtualPrinter.addDialog.hint`)}),(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:e,className:`flex-1`,disabled:d.isPending,children:t(`common.cancel`)}),(0,K.jsx)($,{variant:`primary`,onClick:()=>d.mutate(),className:`flex-1`,disabled:d.isPending,children:d.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):t(`virtualPrinter.addDialog.create`)})]})]})})})}function dze(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),[r,i]=(0,y.useState)(!1),{data:a,isLoading:o}=q({queryKey:[`virtual-printers`],queryFn:Qu.list,refetchInterval:1e4}),{data:s}=q({queryKey:[`virtual-printer-settings`],queryFn:Zu.getSettings}),c=J({mutationFn:e=>Zu.updateSettings({archive_name_source:e}),onSuccess:()=>{t.invalidateQueries({queryKey:[`virtual-printer-settings`]}),n(e(`virtualPrinter.toast.updated`))},onError:t=>{n(t.message||e(`virtualPrinter.toast.failedToUpdate`),`error`)}}),l=s?.archive_name_source===`filename`,{data:u}=q({queryKey:[`vp-ca-certificate`],queryFn:Qu.getCaCertificate,staleTime:1/0}),[d,f]=(0,y.useState)(!1),p=async()=>{u&&(await q5(u.pem)?(f(!0),n(e(`virtualPrinter.caCert.copied`)),setTimeout(()=>f(!1),2e3)):n(e(`virtualPrinter.toast.copyFailed`),`error`))},m=()=>{u&&oze(u.pem,`bambuddy-virtual-printer-ca.crt`,`application/x-pem-file`)};if(o)return(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-8 flex justify-center`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})})});let h=a?.printers||[],g=a?.models||{};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4 items-stretch`,children:[(0,K.jsx)(pd,{className:`border-l-4 border-l-yellow-500`,children:(0,K.jsx)(hd,{className:`py-3 px-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`text-xs`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`virtualPrinter.setupRequired.title`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`virtualPrinter.setupRequired.description`)}),(0,K.jsxs)(`a`,{href:`https://wiki.bambuddy.cool/features/virtual-printer/`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 mt-2 px-3 py-1.5 bg-yellow-500/20 border border-yellow-500/50 rounded text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs`,children:[(0,K.jsx)(Us,{className:`w-3 h-3`}),e(`virtualPrinter.setupRequired.readGuide`)]})]})]})})}),(0,K.jsx)(pd,{className:`lg:col-span-2`,children:(0,K.jsx)(hd,{className:`py-3 px-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(kc,{className:`w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`virtualPrinter.howItWorks.title`)}),(0,K.jsxs)(`ul`,{className:`space-y-1 list-disc list-inside`,children:[(0,K.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step1`)}),(0,K.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step2`)}),(0,K.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step3`)})]})]})]})})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4 items-stretch`,children:[(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-3 px-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(Bl,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-1`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`virtualPrinter.caCert.title`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsxs)(`button`,{onClick:p,disabled:!u,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[d?(0,K.jsx)($o,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,K.jsx)(Ds,{className:`w-3.5 h-3.5`}),e(d?`virtualPrinter.caCert.copied`:`virtualPrinter.caCert.copy`)]}),(0,K.jsxs)(`button`,{onClick:m,disabled:!u,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[(0,K.jsx)(Is,{className:`w-3.5 h-3.5`}),e(`virtualPrinter.caCert.download`)]})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`virtualPrinter.caCert.description`)}),u&&(0,K.jsxs)(`p`,{className:`text-[10px] text-bambu-gray font-mono mt-1 truncate`,title:u.fingerprint_sha256,children:[e(`virtualPrinter.caCert.fingerprint`),`: `,u.fingerprint_sha256]})]})]})})}),(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-3 px-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(Zs,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-1`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`virtualPrinter.archiveNameSource.title`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(`span`,{className:`text-xs ${l?`text-bambu-gray`:`text-white`}`,children:e(`virtualPrinter.archiveNameSource.metadata`)}),(0,K.jsx)(y5,{checked:l,onChange:e=>c.mutate(e?`filename`:`metadata`),disabled:c.isPending}),(0,K.jsx)(`span`,{className:`text-xs ${l?`text-white`:`text-bambu-gray`}`,children:e(`virtualPrinter.archiveNameSource.filename`)})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`virtualPrinter.archiveNameSource.description`)})]})]})})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(bl,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`virtualPrinter.list.title`)}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,h.length,`)`]})]}),(0,K.jsxs)($,{variant:`primary`,onClick:()=>i(!0),children:[(0,K.jsx)(_l,{className:`w-4 h-4 mr-1`}),e(`virtualPrinter.list.add`)]})]}),h.length===0?(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`py-8 text-center`,children:[(0,K.jsx)(bl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3`}),(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`virtualPrinter.list.empty`)}),(0,K.jsxs)($,{variant:`primary`,onClick:()=>i(!0),children:[(0,K.jsx)(_l,{className:`w-4 h-4 mr-1`}),e(`virtualPrinter.list.addFirst`)]})]})}):(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 items-start`,children:h.map(e=>(0,K.jsx)(lze,{printer:e,models:g},e.id))}),r&&(0,K.jsx)(uze,{onClose:()=>i(!1)})]})}function Z5(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60),r=t%60;if(n<24)return r?`${n}h ${r}m`:`${n}h`;let i=Math.floor(n/24),a=n%24;return a?`${i}d ${a}h`:`${i}d`}function Q5(e){return e==null?`—`:e>=1024?`${(e/1024).toFixed(1)} GB`:`${Math.round(e)} MB`}function fze({device:e,onUnregister:t,isDeleting:n}){let{t:r}=G(),{showToast:i}=xd(),a=e.system_stats,o=a?.memory,s=a?.disk,c=e.online,[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),p=async t=>{f(t);try{t===`update`?await nd.triggerUpdate(e.device_id):await nd.systemCommand(e.device_id,t),i(r(`settings.spoolbuddy.commandQueued`),`success`)}catch(e){i(e instanceof Error?e.message:r(`settings.spoolbuddy.commandError`),`error`)}finally{f(null),u(null)}},m=[{key:`update`,label:r(`settings.spoolbuddy.update`),icon:Is},{key:`restart_browser`,label:r(`settings.spoolbuddy.restartBrowser`),icon:tl},{key:`restart_daemon`,label:r(`settings.spoolbuddy.restartDaemon`),icon:Cl},{key:`reboot`,label:r(`settings.spoolbuddy.reboot`),icon:El},{key:`shutdown`,label:r(`settings.spoolbuddy.shutdown`),icon:yl,variant:`danger`}],h={update:r(`settings.spoolbuddy.updateConfirmTitle`),restart_browser:r(`settings.spoolbuddy.restartBrowserConfirmTitle`),restart_daemon:r(`settings.spoolbuddy.restartDaemonConfirmTitle`),reboot:r(`settings.spoolbuddy.rebootConfirmTitle`),shutdown:r(`settings.spoolbuddy.shutdownConfirmTitle`)},g={update:r(`settings.spoolbuddy.updateConfirmBody`,{hostname:e.hostname}),restart_browser:r(`settings.spoolbuddy.restartBrowserConfirmBody`,{hostname:e.hostname}),restart_daemon:r(`settings.spoolbuddy.restartDaemonConfirmBody`,{hostname:e.hostname}),reboot:r(`settings.spoolbuddy.rebootConfirmBody`,{hostname:e.hostname}),shutdown:r(`settings.spoolbuddy.shutdownConfirmBody`,{hostname:e.hostname})};return(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`text-base font-semibold text-white truncate`,children:e.hostname}),(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${c?`bg-green-500/15 text-green-400 border border-green-500/40`:`bg-gray-500/15 text-gray-400 border border-gray-500/40`}`,children:[c?(0,K.jsx)(ju,{className:`w-3 h-3`}):(0,K.jsx)(Au,{className:`w-3 h-3`}),r(c?`settings.spoolbuddy.online`:`settings.spoolbuddy.offline`)]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray font-mono mt-1 truncate`,children:e.device_id})]}),(0,K.jsxs)($,{variant:`danger`,size:`sm`,onClick:()=>t(e),disabled:n,"aria-label":r(`settings.spoolbuddy.unregister`),children:[(0,K.jsx)(hu,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:r(`settings.spoolbuddy.unregister`)})]})]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.ipAddress`)}),(0,K.jsx)(`div`,{className:`text-white font-mono`,children:e.ip_address})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.firmware`)}),(0,K.jsx)(`div`,{className:`text-white`,children:e.firmware_version??`—`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`text-bambu-gray flex items-center gap-1`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),r(`settings.spoolbuddy.lastSeen`)]}),(0,K.jsx)(`div`,{className:`text-white`,children:e.last_seen?bf(e.last_seen):r(`settings.spoolbuddy.never`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.daemonUptime`)}),(0,K.jsx)(`div`,{className:`text-white`,children:Z5(e.uptime_s)})]})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.map(({key:e,label:t,icon:n,variant:r})=>(0,K.jsxs)($,{variant:r??`secondary`,size:`sm`,onClick:()=>u(e),disabled:!c||d!==null,"aria-label":t,children:[d===e?(0,K.jsx)(X,{className:`w-3.5 h-3.5 animate-spin`}):(0,K.jsx)(n,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{children:t})]},e))}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-xs flex-wrap`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[e.nfc_ok?(0,K.jsx)(us,{className:`w-3.5 h-3.5 text-green-400`}):(0,K.jsx)(ms,{className:`w-3.5 h-3.5 text-red-400`}),r(`settings.spoolbuddy.nfc`),e.nfc_reader_type&&(0,K.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[`(`,e.nfc_reader_type,`)`]})]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[e.scale_ok?(0,K.jsx)(us,{className:`w-3.5 h-3.5 text-green-400`}):(0,K.jsx)(ms,{className:`w-3.5 h-3.5 text-red-400`}),r(`settings.spoolbuddy.scale`)]})]}),a&&(0,K.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3 text-xs`,children:[a.cpu_temp_c!==void 0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(pu,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.cpuTemp`)}),(0,K.jsxs)(`div`,{className:`text-white`,children:[a.cpu_temp_c.toFixed(1),`°C`]})]})]}),a.load_avg&&a.load_avg.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(So,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.cpuLoad`)}),(0,K.jsxs)(`div`,{className:`text-white`,children:[a.load_avg[0].toFixed(2),a.cpu_count?` / ${a.cpu_count} (${Math.round(a.load_avg[0]/a.cpu_count*100)}%)`:``]})]})]}),o&&o.percent!==void 0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Os,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.memory`)}),(0,K.jsxs)(`div`,{className:`text-white`,children:[o.percent.toFixed(0),`% (`,Q5(o.used_mb),` / `,Q5(o.total_mb),`)`]})]})]}),s&&s.percent!==void 0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(yc,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.disk`)}),(0,K.jsxs)(`div`,{className:`text-white`,children:[s.percent.toFixed(0),`% (`,s.used_gb?.toFixed(1),` / `,s.total_gb?.toFixed(1),` GB)`]})]})]}),a.system_uptime_s!==void 0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(_s,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.systemUptime`)}),(0,K.jsx)(`div`,{className:`text-white`,children:Z5(a.system_uptime_s)})]})]})]}),a.os&&(0,K.jsx)(`div`,{className:`mt-3 text-xs text-bambu-gray font-mono truncate`,children:[a.os.os,a.os.kernel,a.os.arch,a.os.python&&`Python ${a.os.python}`].filter(Boolean).join(` · `)})]})]}),l&&(0,K.jsx)(Ed,{variant:l===`shutdown`||l===`reboot`?`danger`:`default`,title:h[l],message:g[l],confirmText:r(`settings.spoolbuddy.commandConfirm`),isLoading:d!==null,onConfirm:()=>p(l),onCancel:()=>u(null)})]})}function pze(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),[r,i]=(0,y.useState)(null),{data:a=[],isLoading:o}=q({queryKey:[`spoolbuddy-devices`],queryFn:()=>nd.getDevices(),refetchInterval:15e3}),s=J({mutationFn:e=>nd.deleteDevice(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`spoolbuddy-devices`]}),n(e(`settings.spoolbuddy.unregisterSuccess`),`success`),i(null)},onError:t=>{n(t.message||e(`settings.spoolbuddy.unregisterError`),`error`)}});if(o)return(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-8 flex justify-center`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})})});let c=a.length>1;return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-3 px-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,K.jsx)(kc,{className:`w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`settings.spoolbuddy.infoTitle`)}),(0,K.jsx)(`p`,{children:e(`settings.spoolbuddy.infoBody`)})]})]})})}),c&&(0,K.jsx)(pd,{className:`border-l-4 border-l-yellow-500`,children:(0,K.jsx)(hd,{className:`py-3 px-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`settings.spoolbuddy.duplicatesTitle`,{count:a.length})}),(0,K.jsx)(`p`,{children:e(`settings.spoolbuddy.duplicatesBody`)})]})]})})}),a.length===0?(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-8 text-center text-bambu-gray text-sm`,children:e(`settings.spoolbuddy.empty`)})}):(0,K.jsx)(`div`,{className:`space-y-3`,children:a.map(e=>(0,K.jsx)(fze,{device:e,onUnregister:i,isDeleting:s.isPending&&s.variables===e.device_id},e.id))}),r&&(0,K.jsx)(Ed,{variant:`danger`,title:e(`settings.spoolbuddy.confirmTitle`),message:e(`settings.spoolbuddy.confirmBody`,{hostname:r.hostname,deviceId:r.device_id}),confirmText:e(`settings.spoolbuddy.unregister`),isLoading:s.isPending,onConfirm:()=>s.mutate(r.device_id),onCancel:()=>i(null)})]})}function $5(e){if(!e)return`-`;let t=mf(e);return t?t.toLocaleString():`-`}function e7({status:e}){if(!e)return null;let t={success:`bg-green-500/20 text-green-400`,failed:`bg-red-500/20 text-red-400`,skipped:`bg-yellow-500/20 text-yellow-400`,running:`bg-blue-500/20 text-blue-400`},n={success:(0,K.jsx)(ls,{className:`w-3 h-3`}),failed:(0,K.jsx)(ms,{className:`w-3 h-3`}),skipped:(0,K.jsx)(Kl,{className:`w-3 h-3`}),running:(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`})};return(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium ${t[e]||`bg-gray-500/20 text-gray-400`}`,children:[n[e],e.charAt(0).toUpperCase()+e.slice(1)]})}var mze={github:`backup.repoUrlPlaceholderGitHub`,gitea:`backup.repoUrlPlaceholderGitea`,forgejo:`backup.repoUrlPlaceholderForgejo`,gitlab:`backup.repoUrlPlaceholderGitLab`},hze={github:`ghp_xxxxxxxxxxxx`,gitea:`your_access_token`,forgejo:`your_access_token`,gitlab:`glpat-xxxxxxxxxxxx`};function t7(e){return JSON.stringify(e)}function gze(e,t){if(!t)return e;let n={};for(let r of Object.keys(e))e[r]!==t[r]&&(n[r]=e[r]);return n}function _ze(){let e=Qa(),{showToast:t}=xd(),{t:n}=G(),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`main`),[l,u]=(0,y.useState)(`github`),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(`daily`),[h,g]=(0,y.useState)(!0),[_,v]=(0,y.useState)(!0),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!0),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(``),[I,L]=(0,y.useState)(!1),[R,z]=(0,y.useState)(null),[B,V]=(0,y.useState)(null),ee=(0,y.useRef)(null),[H,te]=(0,y.useState)(null),[ne,re]=(0,y.useState)(null),[U,ie]=(0,y.useState)(``),{data:ae,refetch:W}=q({queryKey:[`local-backup-status`],queryFn:Q.getLocalBackupStatus,refetchInterval:e=>e.state.data?.is_running?1e3:1e4}),{data:oe,refetch:se}=q({queryKey:[`local-backup-files`],queryFn:Q.getLocalBackups,refetchInterval:3e4});(0,y.useEffect)(()=>{ae?.path!==void 0&&ie(ae.path)},[ae?.path]);let ce=J({mutationFn:Q.triggerLocalBackup,onSuccess:e=>{e.success?t(n(`backup.scheduledBackupComplete`)):t(e.message,`error`),W(),se()},onError:()=>t(n(`backup.scheduledBackupFailed`),`error`)}),le=J({mutationFn:e=>Q.deleteLocalBackup(e),onSuccess:()=>{se(),te(null)}}),ue=J({mutationFn:async e=>(re(null),N(!0),V(null),F(n(`backup.restoring`)),Q.restoreLocalBackup(e)),onSuccess:e=>{N(!1),F(``),e.success?(V({success:!0,message:e.message}),t(n(`backup.backupRestoredRestart`),`success`)):(V({success:!1,message:e.message}),t(e.message,`error`))},onError:e=>{N(!1),F(``);let r=e instanceof Error?e.message:n(`backup.failedToRestore`);V({success:!1,message:r}),t(r,`error`)}});(0,y.useEffect)(()=>{if(A||M){let e=e=>(e.preventDefault(),e.returnValue=`A backup operation is in progress. Are you sure you want to leave?`,e.returnValue);return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)}},[A,M]);let[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(null),[he,ge]=(0,y.useState)(null),_e=(0,y.useRef)(null),ve=(0,y.useRef)(null),ye=(0,y.useRef)(null),be=(0,y.useRef)(null),xe=(0,y.useRef)(``),[Se,Ce]=(0,y.useState)(!1),we=(0,y.useMemo)(()=>({repository_url:r,branch:s,provider:l,allow_insecure_http:E,schedule_enabled:d,schedule_type:p,backup_kprofiles:h,backup_cloud_profiles:_,backup_settings:b,backup_spools:S,backup_archives:w,enabled:O}),[r,s,l,E,d,p,h,_,b,S,w,O]),Te=(0,y.useMemo)(()=>t7(we),[we]),{data:Ee,isLoading:De}=q({queryKey:[`github-backup-config`],queryFn:Q.getGitHubBackupConfig}),{data:Oe}=q({queryKey:[`github-backup-status`],queryFn:Q.getGitHubBackupStatus,refetchInterval:e=>e.state.data?.is_running?500:1e4}),{data:ke}=q({queryKey:[`github-backup-logs`],queryFn:()=>Q.getGitHubBackupLogs(20)}),{data:Ae}=q({queryKey:[`cloud-status`],queryFn:Q.getCloudStatus}),{data:je}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),Me=po({queries:(je??[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),staleTime:1e4,refetchInterval:3e4}))}),Ne=(je??[]).map((e,t)=>({printer:e,connected:Me[t]?.data?.connected??!1})),Pe=Ne.length,Fe=Ne.filter(e=>e.connected).length,Ie=Pe>0&&Fe===0,Le=Fe>0&&Fe(ye.current&&clearTimeout(ye.current),Ee?(Ce(!1),be.current={repository_url:Ee.repository_url,branch:Ee.branch,provider:Ee.provider??`github`,allow_insecure_http:Ee.allow_insecure_http??!1,schedule_enabled:Ee.schedule_enabled,schedule_type:Ee.schedule_type,backup_kprofiles:Ee.backup_kprofiles,backup_cloud_profiles:Ee.backup_cloud_profiles,backup_settings:Ee.backup_settings,backup_spools:Ee.backup_spools,backup_archives:Ee.backup_archives,enabled:Ee.enabled},i(Ee.repository_url),c(Ee.branch),u(Ee.provider??`github`),f(Ee.schedule_enabled),m(Ee.schedule_type),g(Ee.backup_kprofiles),v(Ee.backup_cloud_profiles),x(Ee.backup_settings),C(Ee.backup_spools),T(Ee.backup_archives),D(Ee.allow_insecure_http??!1),k(Ee.enabled),o(``),ye.current=setTimeout(()=>{Ce(!0)},100)):(Ce(!1),be.current=null,o(``)),()=>{ye.current&&clearTimeout(ye.current)}),[Ee]);let Re=(0,y.useCallback)(async(r=!1)=>{if(Ee)try{r&&a?(await Q.saveGitHubBackupConfig({...we,access_token:a}),o(``),ge(null),t(n(`backup.tokenUpdated`)),xe.current=``):(await Q.updateGitHubBackupConfig(gze(we,be.current)),ge(null),t(n(`backup.settingsSaved`))),be.current=we,e.invalidateQueries({queryKey:[`github-backup-config`]}),e.invalidateQueries({queryKey:[`github-backup-status`]})}catch(e){ge(e.message)}},[Ee,a,we,e,t,n]),ze=(0,y.useRef)(Re);(0,y.useEffect)(()=>{ze.current=Re},[Re]),(0,y.useEffect)(()=>{if(!(!Se||!Ee)&&!(be.current&&Te===t7(be.current)))return _e.current&&clearTimeout(_e.current),_e.current=setTimeout(()=>{Re(!1)},500),()=>{_e.current&&clearTimeout(_e.current)}},[Se,Ee,Te,Re]),(0,y.useEffect)(()=>{if(!(!Se||!Ee||!a)&&a!==xe.current)return xe.current=a,ve.current&&clearTimeout(ve.current),ve.current=setTimeout(()=>{ze.current(!0)},1e3),()=>{ve.current&&clearTimeout(ve.current)}},[Se,a,Ee]);let Be=J({mutationFn:e=>Q.saveGitHubBackupConfig(e),onMutate:()=>{ge(null)},onSuccess:()=>{e.invalidateQueries({queryKey:[`github-backup-config`]}),e.invalidateQueries({queryKey:[`github-backup-status`]}),t(n(`backup.githubBackupEnabled`)),o(``),Ce(!0)},onError:e=>{ge(e.message)}}),Ve=J({mutationFn:Q.triggerGitHubBackup,onSuccess:r=>{e.invalidateQueries({queryKey:[`github-backup-status`]}),e.invalidateQueries({queryKey:[`github-backup-logs`]}),r.success?r.files_changed>0?t(n(`backup.backupCompleteFiles`,{count:r.files_changed})):t(n(`backup.backupSkippedNoChanges`)):t(n(`backup.backupFailed2`,{message:r.message}),`error`)},onError:e=>{t(n(`backup.backupFailed2`,{message:e.message}),`error`)}}),He=J({mutationFn:()=>Q.clearGitHubBackupLogs(0),onSuccess:r=>{e.invalidateQueries({queryKey:[`github-backup-logs`]}),t(n(`backup.clearedLogs`,{count:r.deleted}))},onError:e=>{t(n(`backup.failedToClearLogs`,{message:e.message}),`error`)}}),Ue=async()=>{fe(!0),me(null);try{let e;if(a){if(!r){t(n(`backup.enterRepoUrl`),`error`),fe(!1);return}e=await Q.testGitHubConnection(r,a,l)}else if(Ee?.has_token)e=await Q.testGitHubStoredConnection();else{t(n(`backup.enterRepoAndToken`),`error`),fe(!1);return}me({success:e.success,message:e.message,isPrivate:e.is_private})}catch(e){me({success:!1,message:e.message,isPrivate:null})}finally{fe(!1)}};return De?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,K.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(pd,{id:`card-backup-github`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(mc,{className:`w-5 h-5 text-gray-400`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.githubBackup`)})]}),Ee&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`backup.enabled`)}),(0,K.jsx)(y5,{checked:O,onChange:k})]})]})}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.githubDescription`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`git-provider-select`,className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.provider`)}),(0,K.jsxs)(`select`,{id:`git-provider-select`,value:l,onChange:e=>{u(e.target.value),me(null),ge(null)},className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`github`,children:n(`backup.providerGitHub`)}),(0,K.jsx)(`option`,{value:`gitlab`,children:n(`backup.providerGitLab`)}),(0,K.jsx)(`option`,{value:`gitea`,children:n(`backup.providerGitea`)}),(0,K.jsx)(`option`,{value:`forgejo`,children:n(`backup.providerForgejo`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.repositoryUrl`)}),(0,K.jsx)(`input`,{type:`text`,value:r,onChange:e=>{i(e.target.value),me(null),ge(null)},placeholder:n(mze[l]),className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 mt-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:E,onChange:e=>{D(e.target.checked),me(null)},className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`backup.allowInsecureHttp`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.allowInsecureHttpHint`)})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`backup.personalAccessToken`),` `,Ee?.has_token&&(0,K.jsx)(`span`,{className:`text-green-400`,children:n(`backup.tokenSaved`)})]}),(0,K.jsx)(`input`,{type:`password`,value:a,onChange:e=>{o(e.target.value),me(null),ge(null)},placeholder:Ee?.has_token?n(`backup.enterNewToken`):hze[l],className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`backup.tokenHint`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.branch`)}),(0,K.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`main`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.autoBackup`)}),(0,K.jsxs)(`select`,{value:d?p:`disabled`,onChange:e=>{e.target.value===`disabled`?f(!1):(f(!0),m(e.target.value))},className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`disabled`,children:n(`backup.manualOnly`)}),(0,K.jsx)(`option`,{value:`hourly`,children:n(`backup.hourly`)}),(0,K.jsx)(`option`,{value:`daily`,children:n(`backup.daily`)}),(0,K.jsx)(`option`,{value:`weekly`,children:n(`backup.weekly`)})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:n(`backup.includeInBackup`)}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`label`,{className:`flex items-start gap-2 ${Ie?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`,disabled:Ie}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm ${Ie?`text-bambu-gray`:`text-white`}`,children:n(`backup.kProfiles`)}),Ie&&(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400`,children:[(0,K.jsx)(vu,{className:`w-3 h-3`}),n(`backup.noPrintersConnected`)]}),Le&&(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400`,children:[(0,K.jsx)(vu,{className:`w-3 h-3`}),n(`backup.printersConnected`,{connected:Fe,total:Pe})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.kProfilesDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 ${Ae?.is_authenticated?`cursor-pointer`:`cursor-not-allowed opacity-60`}`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`,disabled:!Ae?.is_authenticated}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm ${Ae?.is_authenticated?`text-white`:`text-bambu-gray`}`,children:n(`backup.cloudProfiles`)}),!Ae?.is_authenticated&&(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400`,children:[(0,K.jsx)(vu,{className:`w-3 h-3`}),n(`backup.cloudLoginRequiredShort`)]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.cloudProfilesDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>x(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.appSettings`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.appSettingsDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:S,onChange:e=>C(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.spoolInventory`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.spoolInventoryDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:w,onChange:e=>T(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.printArchives`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.printArchivesDescription`)})]})]})]})]}),(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 space-y-3`,children:[Oe?.configured&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:Oe.last_backup_at?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{children:[n(`backup.lastBackupAt`),` `,bf(Oe.last_backup_at,`system`,n)]}),(0,K.jsx)(e7,{status:Oe.last_backup_status})]}):(0,K.jsx)(`span`,{children:n(`backup.noBackupsYet`)})}),Oe.next_scheduled_run&&(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[(0,K.jsx)(_s,{className:`w-3 h-3 inline mr-1`}),n(`backup.next`),` `,bf(Oe.next_scheduled_run,`system`,n)]})]}),he&&(0,K.jsxs)(`div`,{className:`text-sm text-red-400 bg-red-500/10 border border-red-500/30 rounded p-3 flex items-start gap-2`,children:[(0,K.jsx)(ms,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,K.jsx)(`div`,{className:`flex-1 leading-relaxed whitespace-pre-wrap break-words`,children:he}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>ge(null),className:`text-bambu-gray hover:text-white shrink-0`,"aria-label":n(`common.dismiss`,`Dismiss`),children:(0,K.jsx)(ms,{className:`w-4 h-4`})})]}),pe&&(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsxs)(`div`,{className:`text-sm flex items-center gap-1 ${pe.success?`text-green-400`:`text-red-400`}`,children:[pe.success?(0,K.jsx)(ls,{className:`w-4 h-4`}):(0,K.jsx)(ms,{className:`w-4 h-4`}),pe.message]}),pe.success&&pe.isPrivate===!0&&(0,K.jsxs)(`div`,{className:`text-xs flex items-center gap-1 text-green-400`,children:[(0,K.jsx)(ls,{className:`w-3.5 h-3.5`}),n(`backup.repoIsPrivate`,`Repository is private — safe to back up to.`)]}),pe.success&&pe.isPrivate===!1&&(0,K.jsxs)(`div`,{className:`text-xs text-red-400 bg-red-500/10 border border-red-500/30 rounded p-2 flex items-start gap-1.5`,children:[(0,K.jsx)(ms,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,K.jsx)(`span`,{children:n(`backup.repoIsPublicWarning`,`Repository is PUBLIC. Bambuddy backups include MQTT credentials, Home Assistant tokens, Prometheus tokens, your Bambu Cloud email, and printer access codes via K-profiles. Saving is blocked until you make the repository private in your provider's settings.`)})]}),pe.success&&pe.isPrivate===null&&(0,K.jsxs)(`div`,{className:`text-xs text-yellow-400 bg-yellow-500/10 border border-yellow-500/30 rounded p-2 flex items-start gap-1.5`,children:[(0,K.jsx)(ms,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,K.jsx)(`span`,{children:n(`backup.repoVisibilityUnknown`,`Could not determine repository visibility. Bambuddy refuses to back up to anything not confirmed private; saving will be blocked.`)})]})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:Oe?.configured?(0,K.jsx)(K.Fragment,{children:Ve.isPending||Oe.is_running?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-green`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),(0,K.jsx)(`span`,{className:`text-sm`,children:Oe.progress||n(`backup.startingBackup`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`primary`,size:`sm`,onClick:()=>Ve.mutate(),disabled:!Ee?.enabled,children:[(0,K.jsx)(hl,{className:`w-4 h-4`}),n(`backup.backupNow`)]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:Ue,disabled:de,children:[de?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),n(`backup.test`)]})]})}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`primary`,size:`sm`,onClick:()=>{if(!r){t(n(`backup.repoRequired`),`error`);return}if(!a){t(n(`backup.tokenRequired`),`error`);return}Be.mutate({repository_url:r,access_token:a,branch:s,provider:l,allow_insecure_http:E,schedule_enabled:d,schedule_type:p,backup_kprofiles:h,backup_cloud_profiles:_,backup_settings:b,backup_spools:S,backup_archives:w,enabled:O})},disabled:Be.isPending||!r||!a,children:[Be.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(ls,{className:`w-4 h-4`}),n(`backup.enableBackup`)]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:Ue,disabled:de||!r||!a,children:[de?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),n(`backup.testConnection`)]})]})})]})]})]}),ke&&ke.length>0&&(0,K.jsxs)(pd,{id:`card-backup-history`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(wc,{className:`w-5 h-5 text-gray-400`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.history`)})]}),(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>He.mutate(),disabled:He.isPending,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),n(`backup.clear`)]})]})}),(0,K.jsx)(hd,{children:(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,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-2 px-2`,children:n(`backup.date`)}),(0,K.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.status`)}),(0,K.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.commit`)})]})}),(0,K.jsx)(`tbody`,{children:ke.slice(0,10).map(e=>(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary`,children:[(0,K.jsx)(`td`,{className:`py-2 px-2 text-white`,children:$5(e.started_at)}),(0,K.jsx)(`td`,{className:`py-2 px-2`,children:(0,K.jsx)(e7,{status:e.status})}),(0,K.jsx)(`td`,{className:`py-2 px-2`,children:e.commit_sha?(0,K.jsxs)(`a`,{href:`${Ee?.repository_url}/commit/${e.commit_sha}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline inline-flex items-center gap-1`,children:[e.commit_sha.substring(0,7),(0,K.jsx)(Us,{className:`w-3 h-3`})]}):(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`-`})})]},e.id))})]})})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(pd,{id:`card-backup-local`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(js,{className:`w-5 h-5 text-gray-400`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.localBackup`)})]})}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.localBackupDescription`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:n(`backup.downloadBackupLabel`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.completeBackupZip`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,disabled:A||M,onClick:async()=>{j(!0),F(n(`backup.preparingBackup`));try{F(n(`backup.creatingArchive`));let{blob:e,filename:r}=await Q.exportBackup();F(n(`backup.downloadingFile`));let i=URL.createObjectURL(e),a=document.createElement(`a`);a.href=i,a.download=r,a.click(),URL.revokeObjectURL(i),t(n(`backup.backupDownloaded`))}catch(e){t(n(`backup.failedToCreateBackup`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}finally{j(!1),F(``)}},children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),n(`backup.download`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:n(`backup.restoreBackup`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.restoreDescription`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.restoreNote`)})]}),(0,K.jsx)(`input`,{ref:ee,type:`file`,accept:`.zip`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&(z(t),L(!0)),e.target.value=``}}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,disabled:M||A,onClick:()=>ee.current?.click(),children:[(0,K.jsx)(Su,{className:`w-4 h-4`}),n(`backup.restore`)]})]}),B&&(0,K.jsx)(`div`,{className:`p-3 rounded-lg ${B.success?`bg-green-500/10 border border-green-500/30`:`bg-red-500/10 border border-red-500/30`}`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[B.success?(0,K.jsx)(ls,{className:`w-4 h-4 text-green-400 mt-0.5 flex-shrink-0`}):(0,K.jsx)(ms,{className:`w-4 h-4 text-red-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:B.success?`text-green-200`:`text-red-200`,children:[B.message,B.success&&(0,K.jsx)(`div`,{className:`mt-2`,children:(0,K.jsxs)($,{size:`sm`,onClick:()=>window.location.reload(),children:[(0,K.jsx)(Tl,{className:`w-3 h-3`}),n(`backup.reloadNow`)]})})]})]})}),(0,K.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`text-yellow-200`,children:[(0,K.jsx)(`span`,{className:`font-medium`,children:n(`backup.restoreReplacesAll`)}),` `,(0,K.jsx)(`span`,{className:`text-yellow-200/70`,children:n(`backup.restoreReplacesAllDetail`)})]})]})})]})]}),(0,K.jsxs)(pd,{id:`card-backup-scheduled`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(tc,{className:`w-5 h-5 text-gray-400`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.scheduledBackup`)})]}),(0,K.jsx)(y5,{checked:ae?.enabled??!1,onChange:async r=>{try{await Q.updateSettings({local_backup_enabled:r}),e.invalidateQueries({queryKey:[`settings`]}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}W()}})]})}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.scheduledBackupDescription`)}),ae?.enabled&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.frequency`)}),(0,K.jsxs)(`select`,{value:ae?.schedule??`daily`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{try{await Q.updateSettings({local_backup_schedule:e.target.value}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}W()},children:[(0,K.jsx)(`option`,{value:`hourly`,children:n(`backup.hourly`)}),(0,K.jsx)(`option`,{value:`daily`,children:n(`backup.daily`)}),(0,K.jsx)(`option`,{value:`weekly`,children:n(`backup.weekly`)})]})]}),(ae?.schedule??`daily`)!==`hourly`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.backupTime`)}),(0,K.jsx)(`input`,{type:`time`,value:ae?.time??`03:00`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none [color-scheme:dark]`,onChange:async e=>{try{await Q.updateSettings({local_backup_time:e.target.value}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}W()}}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.localTimeHint`,{tz:ae?.timezone||`UTC`})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.retention`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:100,value:ae?.retention??5,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{let r=Math.max(1,Math.min(100,parseInt(e.target.value)||5));try{await Q.updateSettings({local_backup_retention:r}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}W()}}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.retentionDescription`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.outputPath`)}),(0,K.jsx)(`input`,{type:`text`,value:U,onChange:e=>ie(e.target.value),className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onBlur:async()=>{try{await Q.updateSettings({local_backup_path:U}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}W(),se()},onKeyDown:e=>{e.key===`Enter`&&e.target.blur()}}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:U?n(`backup.outputPathDescription`):(0,K.jsxs)(K.Fragment,{children:[n(`backup.defaultPathLabel`),` `,(0,K.jsx)(`code`,{className:`text-bambu-gray`,children:ae?.default_path||`...`})]})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`text-sm`,children:[ae?.last_backup_at&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,K.jsxs)(`span`,{children:[n(`backup.lastBackup`),`:`]}),(0,K.jsx)(e7,{status:ae.last_status}),(0,K.jsx)(`span`,{children:bf(ae.last_backup_at)})]}),ae?.next_run&&(0,K.jsxs)(`div`,{className:`text-bambu-gray mt-1`,children:[(0,K.jsxs)(`span`,{children:[n(`backup.nextBackup`),`: `]}),(0,K.jsx)(`span`,{children:$5(ae.next_run)})]})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,disabled:ae?.is_running||ce.isPending,onClick:()=>ce.mutate(),children:[ae?.is_running||ce.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hl,{className:`w-4 h-4`}),ae?.is_running?n(`backup.backupRunning`):n(`backup.runNow`)]})]}),oe&&oe.length>0&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-2`,children:n(`backup.backupFiles`)}),(0,K.jsx)(`div`,{className:`space-y-1`,children:oe.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between py-1.5 px-2 rounded hover:bg-bambu-dark-tertiary/50 text-sm`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`span`,{className:`text-white truncate block`,children:e.filename}),(0,K.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[(e.size/1024/1024).toFixed(1),` MB · `,$5(e.created_at)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,K.jsx)(`button`,{className:`text-bambu-gray hover:text-bambu-green p-1`,title:n(`backup.download`),onClick:async()=>{try{let{blob:t,filename:n}=await Q.downloadLocalBackup(e.filename),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=n,i.click(),URL.revokeObjectURL(r)}catch{t(n(`backup.scheduledBackupFailed`),`error`)}},children:(0,K.jsx)(Is,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{className:`text-bambu-gray hover:text-yellow-400 p-1`,title:n(`backup.restore`),onClick:()=>re(e.filename),children:(0,K.jsx)(Tl,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{className:`text-bambu-gray hover:text-red-400 p-1`,onClick:()=>te(e.filename),title:n(`backup.deleteBackup`),children:(0,K.jsx)(hu,{className:`w-3.5 h-3.5`})})]})]},e.filename))})]}),oe&&oe.length===0&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-3 border-t border-bambu-dark-tertiary`,children:n(`backup.noScheduledBackups`)})]})]})]})]}),H&&(0,K.jsx)(Ed,{title:n(`backup.deleteBackup`),message:n(`backup.deleteBackupConfirm`),confirmText:n(`backup.deleteBackup`),variant:`danger`,onConfirm:()=>le.mutate(H),onCancel:()=>te(null)}),ne&&(0,K.jsx)(Ed,{title:n(`backup.restoreConfirmTitle`),message:n(`backup.restoreConfirmMessage`,{filename:ne}),confirmText:n(`backup.restoreConfirmButton`),variant:`danger`,onConfirm:()=>ue.mutate(ne),onCancel:()=>re(null)}),I&&R&&(0,K.jsx)(Ed,{title:n(`backup.restoreConfirmTitle`),message:n(`backup.restoreConfirmMessage`,{filename:R.name}),confirmText:n(`backup.restoreConfirmButton`),variant:`danger`,onConfirm:async()=>{L(!1),N(!0),V(null);try{F(n(`backup.uploadingFile`));let e=await Q.importBackup(R);V(e),e.success?t(n(`backup.backupRestoredRestart`),`success`):t(e.message,`error`)}catch(e){let r=e instanceof Error?e.message:n(`backup.failedToRestore`);V({success:!1,message:r}),t(r,`error`)}finally{N(!1),F(``),z(null)}},onCancel:()=>{L(!1),z(null)}}),(A||M)&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-[100]`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-8 max-w-md w-full mx-4 text-center`,children:[(0,K.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`div`,{className:`w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full`}),(0,K.jsx)(`div`,{className:`w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin`})]})}),(0,K.jsx)(`h3`,{className:`text-xl font-semibold text-white mb-2`,children:n(A?`backup.creatingBackup`:`backup.restoringBackup`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:P||n(A?`backup.preparing`:`backup.processing`)}),(0,K.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`p`,{className:`text-yellow-200 text-left`,children:n(`backup.doNotClosePage`)})]})})]})})]})}function vze(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`medium`),[l,u]=(0,y.useState)(`notify`),[d,f]=(0,y.useState)(10),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(!1),{data:b}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:x,refetch:S}=q({queryKey:[`obico-status`],queryFn:Q.getObicoStatus,refetchInterval:1e4}),{data:C}=q({queryKey:[`printers`],queryFn:Q.getPrinters});(0,y.useEffect)(()=>{if(b){i(b.obico_enabled??!1),o(b.obico_ml_url??``),c(b.obico_sensitivity??`medium`),u(b.obico_action??`notify`),f(b.obico_poll_interval??10);try{let e=b.obico_enabled_printers?JSON.parse(b.obico_enabled_printers):null;m(Array.isArray(e)?e:null)}catch{m(null)}v(!0)}},[b]);let w=J({mutationFn:()=>Q.updateSettings({obico_enabled:r,obico_ml_url:a,obico_sensitivity:s,obico_action:l,obico_poll_interval:d,obico_enabled_printers:p===null?``:JSON.stringify(p)}),onSuccess:()=>{t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`obico-status`]}),n(e(`settings.toast.settingsSaved`))}});(0,y.useEffect)(()=>{if(!_||!b||!(b.obico_enabled!==r||b.obico_ml_url!==a||b.obico_sensitivity!==s||b.obico_action!==l||b.obico_poll_interval!==d||b.obico_enabled_printers!==(p===null?``:JSON.stringify(p))))return;let e=setTimeout(()=>w.mutate(),500);return()=>clearTimeout(e)},[r,a,s,l,d,p,_]);let T=async()=>{g(null);try{let t=await Q.testObicoConnection(a);t.ok?g({ok:!0,message:e(`failureDetection.testSuccess`)}):g({ok:!1,message:t.error||`HTTP ${t.status_code??`?`} — ${t.body??e(`failureDetection.testFailed`)}`})}catch(e){g({ok:!1,message:e instanceof Error?e.message:String(e)})}},E=(e,t)=>{if(p===null){let n=C?.map(e=>e.id)??[];m(t?n:n.filter(t=>t!==e));return}m(t?[...p,e]:p.filter(t=>t!==e))};return(0,K.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,K.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,K.jsxs)(pd,{id:`card-fd-ml`,children:[(0,K.jsxs)(md,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Al,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.title`)})]}),(0,K.jsx)(y5,{checked:r,onChange:i})]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:e(`failureDetection.description`)})]}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.mlUrl`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:`http://192.168.1.10:3333`,className:`flex-1 bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,disabled:!r}),(0,K.jsx)($,{onClick:T,disabled:!a||w.isPending,variant:`secondary`,children:e(`failureDetection.test`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.mlUrlHint`)}),h&&(0,K.jsxs)(`div`,{className:`flex items-start gap-2 mt-2 text-sm ${h.ok?`text-green-400`:`text-red-400`}`,children:[h.ok?(0,K.jsx)($o,{className:`w-4 h-4 mt-0.5`}):(0,K.jsx)(Pu,{className:`w-4 h-4 mt-0.5`}),(0,K.jsx)(`span`,{children:h.message})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.sensitivity`)}),(0,K.jsxs)(`select`,{value:s,onChange:e=>c(e.target.value),disabled:!r,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,children:[(0,K.jsx)(`option`,{value:`low`,children:e(`failureDetection.sensitivityLow`)}),(0,K.jsx)(`option`,{value:`medium`,children:e(`failureDetection.sensitivityMedium`)}),(0,K.jsx)(`option`,{value:`high`,children:e(`failureDetection.sensitivityHigh`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.sensitivityHint`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.action`)}),(0,K.jsxs)(`select`,{value:l,onChange:e=>u(e.target.value),disabled:!r,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,children:[(0,K.jsx)(`option`,{value:`notify`,children:e(`failureDetection.actionNotify`)}),(0,K.jsx)(`option`,{value:`pause`,children:e(`failureDetection.actionPause`)}),(0,K.jsx)(`option`,{value:`pause_and_off`,children:e(`failureDetection.actionPauseOff`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.pollInterval`)}),(0,K.jsx)(`input`,{type:`number`,value:d,onChange:e=>f(Math.max(5,Math.min(120,Number(e.target.value)||10))),min:5,max:120,disabled:!r,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.pollIntervalHint`)})]}),x&&!x.external_url_configured&&r&&(0,K.jsxs)(`div`,{className:`flex items-start gap-2 p-3 bg-amber-900/30 border border-amber-700 rounded text-sm text-amber-200`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`font-medium`,children:e(`failureDetection.externalUrlMissing`)}),(0,K.jsx)(`div`,{className:`text-xs mt-1`,children:e(`failureDetection.externalUrlHint`)})]})]})]})]}),(0,K.jsxs)(pd,{id:`card-fd-perprinter`,children:[(0,K.jsxs)(md,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.perPrinterTitle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`failureDetection.perPrinterHint`)})]}),(0,K.jsxs)(hd,{className:`space-y-2`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:p===null,onChange:e=>m(e.target.checked?null:C?.map(e=>e.id)??[]),disabled:!r}),(0,K.jsx)(`span`,{className:`text-white`,children:e(`failureDetection.monitorAll`)})]}),p!==null&&C&&(0,K.jsx)(`div`,{className:`pl-5 space-y-1 border-l border-gray-700`,children:C.map(e=>(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:p.includes(e.id),onChange:t=>E(e.id,t.target.checked),disabled:!r}),(0,K.jsx)(`span`,{className:`text-white`,children:e.name})]},e.id))})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,K.jsxs)(pd,{id:`card-fd-status`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.statusTitle`)})}),(0,K.jsx)(hd,{children:x?(0,K.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e(`failureDetection.serviceRunning`)}),(0,K.jsx)(`span`,{className:x.is_running?`text-green-400`:`text-red-400`,children:x.is_running?e(`common.yes`):e(`common.no`)})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e(`failureDetection.thresholds`)}),(0,K.jsxs)(`span`,{className:`text-white font-mono`,children:[x.thresholds.low.toFixed(2),` / `,x.thresholds.high.toFixed(2)]})]}),x.last_error&&(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-red-400`,children:[(0,K.jsx)(Pu,{className:`w-4 h-4 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`break-words`,children:x.last_error})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray mb-1`,children:e(`failureDetection.activePrinters`)}),Object.keys(x.per_printer).length===0?(0,K.jsx)(`div`,{className:`text-bambu-gray italic text-xs`,children:e(`failureDetection.noActivePrints`)}):(0,K.jsx)(`div`,{className:`space-y-1`,children:Object.entries(x.per_printer).map(([e,t])=>{let n=C?.find(t=>String(t.id)===e),r=t.class===`failure`?`text-red-400`:t.class===`warning`?`text-amber-400`:`text-green-400`;return(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-white`,children:n?.name??`Printer ${e}`}),(0,K.jsxs)(`span`,{className:`font-mono ${r}`,children:[t.class,` (`,t.score.toFixed(3),`, `,t.frame_count,`f)`]})]},e)})})]})]}):(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:e(`common.loading`)})]})})]}),(0,K.jsxs)(pd,{id:`card-fd-history`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.historyTitle`)}),(0,K.jsx)(`button`,{onClick:()=>S(),className:`text-xs text-bambu-gray hover:text-white`,children:e(`common.refresh`)})]})}),(0,K.jsx)(hd,{children:!x||x.history.length===0?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,K.jsx)(kc,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:e(`failureDetection.noHistory`)})]}):(0,K.jsx)(`div`,{className:`space-y-1 max-h-96 overflow-y-auto text-xs font-mono`,children:x.history.map((e,t)=>{let n=C?.find(t=>t.id===e.printer_id),r=e.class===`failure`?`text-red-400`:e.class===`warning`?`text-amber-400`:`text-bambu-gray`;return(0,K.jsxs)(`div`,{className:`flex justify-between gap-2 py-1 border-b border-gray-800`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:new Date(e.timestamp).toLocaleTimeString()}),(0,K.jsx)(`span`,{className:`text-white truncate`,children:n?.name??`#${e.printer_id}`}),(0,K.jsxs)(`span`,{className:r,children:[e.class,` `,e.score.toFixed(3)]})]},t)})})})]})]})]})}var yze={starttls:587,ssl:465,none:25},bze={587:`starttls`,465:`ssl`,25:`none`};function xze(){let{t:e}=G(),{showToast:t}=xd(),n=Qa(),[r,i]=(0,y.useState)({smtp_host:``,smtp_port:587,smtp_username:``,smtp_password:``,smtp_security:`starttls`,smtp_auth_enabled:!0,smtp_from_email:``,smtp_from_name:`BamBuddy`}),[a,o]=(0,y.useState)(``),{data:s,isLoading:c}=q({queryKey:[`smtpSettings`],queryFn:()=>Q.getSMTPSettings()}),{authEnabled:l}=sd(),{data:u}=q({queryKey:[`advancedAuthStatus`],queryFn:()=>Q.getAdvancedAuthStatus()});(0,y.useEffect)(()=>{s&&i({...s,smtp_password:``})},[s]);let d=e=>{i({...r,smtp_security:e,smtp_port:yze[e]})},f=e=>{let t=bze[e];i({...r,smtp_port:e,...t?{smtp_security:t}:{}})},p=e=>{i({...r,smtp_auth_enabled:e,...e?{}:{smtp_username:``,smtp_password:``}})},m=J({mutationFn:e=>Q.saveSMTPSettings(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`smtpSettings`]}),n.invalidateQueries({queryKey:[`advancedAuthStatus`]}),t(e(`settings.email.success.settingsSaved`),`success`)},onError:e=>{t(e.message,`error`)}}),h=J({mutationFn:e=>Q.testSMTP(e),onSuccess:e=>{t(e.message,e.success?`success`:`error`)},onError:e=>{t(e.message,`error`)}}),g=J({mutationFn:e=>e?Q.enableAdvancedAuth():Q.disableAdvancedAuth(),onSuccess:e=>{n.invalidateQueries({queryKey:[`advancedAuthStatus`]}),t(e.message,`success`)},onError:e=>{t(e.message,`error`)}}),_=()=>{if(!r.smtp_host||!r.smtp_from_email){t(e(`settings.email.errors.requiredFields`),`error`);return}if(r.smtp_auth_enabled&&!r.smtp_username){t(e(`settings.email.errors.usernameRequired`),`error`);return}m.mutate(r)},v=()=>{if(!a){t(e(`settings.email.errors.enterTestEmail`),`error`);return}h.mutate({test_recipient:a})},b=()=>{if(!l){t(e(`settings.email.errors.enableAuthFirst`),`error`);return}if(!u?.advanced_auth_enabled&&!u?.smtp_configured){t(e(`settings.email.errors.configureSmtpFirst`),`error`);return}g.mutate(!u?.advanced_auth_enabled)};if(c)return(0,K.jsx)(`div`,{className:`flex items-center justify-center p-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})});let x=u?.advanced_auth_enabled??!1,S=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,C=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white/40 placeholder-bambu-gray/40 cursor-not-allowed`;return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(pd,{id:`card-email-advanced-auth`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Gc,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.advancedAuth`)||`Advanced Authentication`})]}),(0,K.jsx)($,{onClick:b,disabled:g.isPending,variant:x?`danger`:`primary`,children:x?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Vc,{className:`w-4 h-4`}),e(`settings.email.disable`)||`Disable`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Hc,{className:`w-4 h-4`}),e(`settings.email.enable`)||`Enable`]})})]})}),(0,K.jsx)(hd,{children:(0,K.jsx)(`div`,{className:`space-y-3`,children:x?(0,K.jsx)(`div`,{className:`bg-green-500/10 border border-green-500/30 rounded-lg p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(ls,{className:`w-5 h-5 text-green-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.email.advancedAuthEnabled`)||`Advanced Authentication is enabled`}),(0,K.jsxs)(`ul`,{className:`text-sm text-green-300 space-y-1 list-disc list-inside`,children:[(0,K.jsx)(`li`,{children:e(`settings.email.feature1`)||`Passwords are auto-generated and emailed to new users`}),(0,K.jsx)(`li`,{children:e(`settings.email.feature2`)||`Users can login with username or email`}),(0,K.jsx)(`li`,{children:e(`settings.email.feature3`)||`Forgot password feature is available`}),(0,K.jsx)(`li`,{children:e(`settings.email.feature4`)||`Admins can reset user passwords via email`})]})]})]})}):(0,K.jsx)(`div`,{className:`bg-yellow-500/10 border border-yellow-500/30 rounded-lg p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(vu,{className:`w-5 h-5 text-yellow-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.email.advancedAuthDisabled`)||`Advanced Authentication is disabled`}),(0,K.jsx)(`p`,{className:`text-sm text-yellow-300`,children:e(`settings.email.advancedAuthDisabledDesc`)||`Enable advanced authentication to activate email-based features for user management.`})]})]})})})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,K.jsx)(`div`,{className:`lg:col-span-2`,children:(0,K.jsxs)(pd,{id:`card-smtp-config`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.smtpSettings`)||`SMTP Configuration`})}),(0,K.jsx)(hd,{children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.authentication`)||`Authentication`}),(0,K.jsxs)(`select`,{value:r.smtp_auth_enabled?`true`:`false`,onChange:e=>p(e.target.value===`true`),className:S,children:[(0,K.jsx)(`option`,{value:`true`,children:e(`settings.email.authOptions.enabled`)}),(0,K.jsx)(`option`,{value:`false`,children:e(`settings.email.authOptions.disabled`)})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 transition-opacity ${r.smtp_auth_enabled?``:`opacity-40 pointer-events-none`}`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.username`)||`Username`}),(0,K.jsx)(`input`,{type:`text`,value:r.smtp_username||``,onChange:e=>i({...r,smtp_username:e.target.value}),placeholder:`your.email@gmail.com`,disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?S:C})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.password`)||`Password`}),(0,K.jsx)(`input`,{type:`password`,value:r.smtp_password||``,onChange:e=>i({...r,smtp_password:e.target.value}),placeholder:s?`••••••••`:`App password`,disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?S:C})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:[e(`settings.email.smtpHost`)||`SMTP Server`,` *`]}),(0,K.jsx)(`input`,{type:`text`,value:r.smtp_host,onChange:e=>i({...r,smtp_host:e.target.value}),placeholder:`smtp.gmail.com`,className:S})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.smtpPort`)||`SMTP Port`}),(0,K.jsx)(`input`,{type:`number`,value:r.smtp_port,onChange:e=>f(parseInt(e.target.value)||587),placeholder:`587`,className:S})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.security`)||`Security`}),(0,K.jsxs)(`select`,{value:r.smtp_security,onChange:e=>d(e.target.value),className:S,children:[(0,K.jsx)(`option`,{value:`starttls`,children:e(`settings.email.securityOptions.starttls`)}),(0,K.jsx)(`option`,{value:`ssl`,children:e(`settings.email.securityOptions.ssl`)}),(0,K.jsx)(`option`,{value:`none`,children:e(`settings.email.securityOptions.none`)})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:[e(`settings.email.fromEmail`)||`From Email`,` *`]}),(0,K.jsx)(`input`,{type:`email`,value:r.smtp_from_email,onChange:e=>i({...r,smtp_from_email:e.target.value}),placeholder:`your@email.com`,className:S})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.fromName`)||`From Name`}),(0,K.jsx)(`input`,{type:`text`,value:r.smtp_from_name,onChange:e=>i({...r,smtp_from_name:e.target.value}),placeholder:`BamBuddy`,className:S})]})]}),(0,K.jsx)(`div`,{className:`flex gap-2`,children:(0,K.jsx)($,{onClick:_,disabled:m.isPending,className:`flex-1`,children:m.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),e(`settings.email.saving`)||`Saving...`]}):e(`settings.email.save`)||`Save Settings`})})]})})]})}),(0,K.jsx)(`div`,{children:(0,K.jsxs)(pd,{id:`card-email-test`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.testConnection`)||`Test SMTP Connection`})}),(0,K.jsx)(hd,{children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.testRecipient`)||`Test Recipient Email`}),(0,K.jsx)(`input`,{type:`email`,value:a,onChange:e=>o(e.target.value),placeholder:`test@example.com`,className:S})]}),(0,K.jsx)($,{onClick:v,disabled:h.isPending,variant:`secondary`,children:h.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),e(`settings.email.sending`)||`Sending...`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Pl,{className:`w-4 h-4`}),e(`settings.email.sendTest`)||`Send Test Email`]})})]})})]})})]})]})}var Sze={starttls:`389`,ldaps:`636`};function Cze(){let{t:e}=G(),{showToast:t}=xd(),n=Qa(),{authEnabled:r}=sd(),[i,a]=(0,y.useState)({ldap_server_url:``,ldap_bind_dn:``,ldap_bind_password:``,ldap_search_base:``,ldap_user_filter:`(sAMAccountName={username})`,ldap_security:`starttls`,ldap_group_mapping:``,ldap_auto_provision:!1,ldap_default_group:``}),{data:o,isLoading:s}=q({queryKey:[`settings`],queryFn:()=>Q.getSettings()}),{data:c}=q({queryKey:[`ldapStatus`],queryFn:()=>Q.getLDAPStatus()}),{data:l=[]}=q({queryKey:[`groups`],queryFn:()=>Q.getGroups()});(0,y.useEffect)(()=>{o&&a({ldap_server_url:o.ldap_server_url||``,ldap_bind_dn:o.ldap_bind_dn||``,ldap_bind_password:``,ldap_search_base:o.ldap_search_base||``,ldap_user_filter:o.ldap_user_filter||`(sAMAccountName={username})`,ldap_security:o.ldap_security||`starttls`,ldap_group_mapping:o.ldap_group_mapping||``,ldap_auto_provision:o.ldap_auto_provision??!1,ldap_default_group:o.ldap_default_group||``})},[o]);let u=J({mutationFn:e=>Q.updateSettings(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`settings`]}),n.invalidateQueries({queryKey:[`ldapStatus`]}),t(e(`settings.ldap.settingsSaved`)||`LDAP settings saved`,`success`)},onError:e=>{t(e.message,`error`)}}),d=J({mutationFn:e=>Q.updateSettings({ldap_enabled:e}),onSuccess:()=>{n.invalidateQueries({queryKey:[`settings`]}),n.invalidateQueries({queryKey:[`ldapStatus`]}),t(c?.ldap_enabled?e(`settings.ldap.disabled`)||`LDAP authentication disabled`:e(`settings.ldap.enabled`)||`LDAP authentication enabled`,`success`)},onError:e=>{t(e.message,`error`)}}),f=J({mutationFn:()=>Q.testLDAP(),onSuccess:e=>{t(e.message,e.success?`success`:`error`)},onError:e=>{t(e.message,`error`)}}),p=()=>{if(!i.ldap_server_url){t(e(`settings.ldap.errors.serverRequired`)||`LDAP server URL is required`,`error`);return}if(!i.ldap_search_base){t(e(`settings.ldap.errors.searchBaseRequired`)||`Search base DN is required`,`error`);return}let n={ldap_server_url:i.ldap_server_url,ldap_bind_dn:i.ldap_bind_dn,ldap_search_base:i.ldap_search_base,ldap_user_filter:i.ldap_user_filter,ldap_security:i.ldap_security,ldap_group_mapping:i.ldap_group_mapping,ldap_auto_provision:i.ldap_auto_provision,ldap_default_group:i.ldap_default_group};i.ldap_bind_password&&(n.ldap_bind_password=i.ldap_bind_password),u.mutate(n)},m=()=>{if(!r){t(e(`settings.ldap.errors.enableAuthFirst`)||`Enable authentication first`,`error`);return}if(!c?.ldap_enabled&&!c?.ldap_configured){t(e(`settings.ldap.errors.configureLdapFirst`)||`Save LDAP settings first`,`error`);return}d.mutate(!c?.ldap_enabled)};if(s)return(0,K.jsx)(`div`,{className:`flex items-center justify-center p-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})});let h=c?.ldap_enabled??!1,g=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`;return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(pd,{id:`card-ldap-toggle`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Hl,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.ldap.title`)||`LDAP Authentication`})]}),(0,K.jsx)($,{onClick:m,disabled:d.isPending,variant:h?`danger`:`primary`,children:h?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Vc,{className:`w-4 h-4`}),e(`common.disable`)||`Disable`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Hc,{className:`w-4 h-4`}),e(`common.enable`)||`Enable`]})})]})}),(0,K.jsx)(hd,{children:h?(0,K.jsx)(`div`,{className:`bg-green-500/10 border border-green-500/30 rounded-lg p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(ls,{className:`w-5 h-5 text-green-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.ldap.enabledDesc`)||`LDAP authentication is enabled`}),(0,K.jsxs)(`ul`,{className:`text-sm text-green-300 space-y-1 list-disc list-inside`,children:[(0,K.jsx)(`li`,{children:e(`settings.ldap.feature1`)||`Users can login with LDAP credentials`}),(0,K.jsx)(`li`,{children:e(`settings.ldap.feature2`)||`Local admin account remains as fallback`}),(0,K.jsx)(`li`,{children:e(`settings.ldap.feature3`)||`LDAP groups are mapped to BamBuddy groups on login`})]})]})]})}):(0,K.jsx)(`div`,{className:`bg-yellow-500/10 border border-yellow-500/30 rounded-lg p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(vu,{className:`w-5 h-5 text-yellow-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.ldap.disabledDesc`)||`LDAP authentication is disabled`}),(0,K.jsx)(`p`,{className:`text-sm text-yellow-300 mt-1`,children:e(`settings.ldap.disabledHint`)||`Configure and save LDAP settings below, then enable.`})]})]})})})]}),(0,K.jsxs)(pd,{id:`card-ldap-server`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.ldap.serverConfig`)||`LDAP Server Configuration`})}),(0,K.jsx)(hd,{children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-3`,children:[(0,K.jsxs)(`div`,{className:`md:col-span-2`,children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.serverUrl`)||`Server URL`}),(0,K.jsx)(`input`,{type:`text`,className:g,placeholder:`ldaps://ldap.example.com:636`,value:i.ldap_server_url,onChange:e=>a({...i,ldap_server_url:e.target.value})}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.serverUrlHint`)||`Use ldaps:// for SSL or ldap:// with StartTLS`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.security`)||`Security`}),(0,K.jsx)(`div`,{className:`flex gap-2`,children:[`starttls`,`ldaps`].map(e=>(0,K.jsx)(`button`,{onClick:()=>a({...i,ldap_security:e}),className:`flex-1 px-2 py-2 rounded-lg text-sm font-medium transition-colors ${i.ldap_security===e?`bg-bambu-green text-black`:`bg-bambu-dark-secondary text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:e===`starttls`?`StartTLS`:`LDAPS`},e))}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.securityHint`)||`Default port: ${Sze[i.ldap_security]}`})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.bindDn`)||`Bind DN (Service Account)`}),(0,K.jsx)(`input`,{type:`text`,className:g,placeholder:`cn=service-account,ou=service,dc=example,dc=com`,value:i.ldap_bind_dn,onChange:e=>a({...i,ldap_bind_dn:e.target.value})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.bindPassword`)||`Bind Password`}),(0,K.jsx)(`input`,{type:`password`,className:g,placeholder:o?.ldap_bind_dn?`••••••••`:``,value:i.ldap_bind_password,onChange:e=>a({...i,ldap_bind_password:e.target.value})})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.searchBase`)||`Search Base DN`}),(0,K.jsx)(`input`,{type:`text`,className:g,placeholder:`ou=users,dc=example,dc=com`,value:i.ldap_search_base,onChange:e=>a({...i,ldap_search_base:e.target.value})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.userFilter`)||`User Search Filter`}),(0,K.jsx)(`input`,{type:`text`,className:g,placeholder:`(sAMAccountName={username})`,value:i.ldap_user_filter,onChange:e=>a({...i,ldap_user_filter:e.target.value})})]})]}),(0,K.jsx)(Mf,{summary:(0,K.jsx)(`span`,{className:`text-sm font-medium text-bambu-gray`,children:e(`settings.ldap.advanced`)||`Advanced`}),className:`border-t border-bambu-dark-tertiary pt-3`,summaryClassName:`py-1`,children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white`,children:e(`settings.ldap.autoProvision`)||`Auto-provision users`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e(`settings.ldap.autoProvisionHint`)||`Automatically create a BamBuddy account on first LDAP login`})]}),(0,K.jsx)(`button`,{onClick:()=>a({...i,ldap_auto_provision:!i.ldap_auto_provision}),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors flex-shrink-0 ${i.ldap_auto_provision?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${i.ldap_auto_provision?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.defaultGroup`)||`Default group`}),(0,K.jsxs)(`select`,{className:g,value:i.ldap_default_group,onChange:e=>a({...i,ldap_default_group:e.target.value}),children:[(0,K.jsx)(`option`,{value:``,children:e(`settings.ldap.defaultGroupNone`)||`— None (reject login) —`}),l.map(e=>(0,K.jsx)(`option`,{value:e.name,children:e.name},e.id))]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.defaultGroupHint`)||`Fallback group assigned when an LDAP user authenticates but is not listed in any mapped group. Leave empty to leave unmapped users without permissions.`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.groupMapping`)||`Group Mapping (JSON)`}),(0,K.jsx)(`textarea`,{className:`${g} font-mono text-sm`,rows:4,placeholder:`{ +`),confirmText:e(`queue.filamentShort.printAnyway`),variant:`warning`,onConfirm:()=>{fe.mutate({id:ue.itemId,skipFilamentCheck:!0})},onCancel:()=>de(null)}),v&&(0,K.jsx)(Ed,{title:v.type===`cancel`?e(`queue.confirm.cancelTitle`):v.type===`stop`?e(`queue.confirm.stopTitle`):e(`queue.confirm.removeTitle`),message:v.type===`cancel`?e(`queue.confirm.cancelMessage`,{name:v.item.archive_name||v.item.library_file_name||e(`queue.confirm.thisPrint`)}):v.type===`stop`?e(`queue.confirm.stopMessage`,{name:v.item.archive_name||v.item.library_file_name||e(`queue.confirm.thisPrint`)}):e(`queue.confirm.removeMessage`,{name:v.item.archive_name||v.item.library_file_name||e(`queue.confirm.thisItem`)}),confirmText:v.type===`cancel`?e(`queue.confirm.cancelButton`):v.type===`stop`?e(`queue.confirm.stopButton`):e(`common.remove`),variant:`danger`,onConfirm:()=>{v.type===`cancel`?se.mutate(v.item.id):v.type===`stop`?le.mutate(v.item.id):ce.mutate(v.item.id),b(null)},onCancel:()=>b(null)}),f&&(0,K.jsx)(Ed,{title:e(`queue.confirm.clearHistoryTitle`),message:e(`queue.confirm.clearHistoryMessage`,{count:ke.length}),confirmText:e(`queue.clearHistory`),variant:`danger`,onConfirm:()=>{me.mutate(),p(!1)},onCancel:()=>p(!1)}),C&&(0,K.jsx)(YLe,{selectedCount:x.length,printers:W?.map(e=>({id:e.id,name:e.name,nozzle_count:e.nozzle_count}))||[],onSave:e=>{Object.keys(e).length>0&&he.mutate({item_ids:x,...e})},onClose:()=>w(!1),isSaving:he.isPending,canControlPrinter:r(`printers:control`),t:e}),V&&(0,K.jsx)(QLe,{itemCount:x.length,isSaving:_e.isPending,defaultName:(()=>{let t=Se.find(e=>x.includes(e.id)),n=(t?.archive_name||t?.library_file_name||``).replace(/\.gcode\.3mf$/i,``).replace(/\.3mf$/i,``);return n?`${n}`:e(`queue.batch.defaultName`)})(),onSave:e=>_e.mutate({name:e,item_ids:x}),onClose:()=>ee(!1),t:e}),H!==null&&(0,K.jsx)(Ed,{title:e(`queue.batch.ungroupConfirmTitle`),message:e(`queue.batch.ungroupConfirmMessage`),confirmText:e(`queue.batch.ungroup`),variant:`warning`,onConfirm:()=>ve.mutate(H),onCancel:()=>te(null)})]})}function QLe({itemCount:e,defaultName:t,isSaving:n,onSave:r,onClose:i,t:a}){let[o,s]=(0,y.useState)(t);return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 w-full max-w-md`,children:[(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white mb-2 flex items-center gap-2`,children:[(0,K.jsx)(cl,{className:`w-5 h-5 text-cyan-300`}),a(`queue.batch.groupAsBatch`)]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:a(`queue.batch.groupAsBatchDescription`,{count:e})}),(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:a(`queue.batch.nameLabel`)}),(0,K.jsx)(`input`,{type:`text`,autoFocus:!0,value:o,onChange:e=>s(e.target.value),placeholder:a(`queue.batch.namePlaceholder`),maxLength:120,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none mb-5`}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:i,disabled:n,children:a(`common.cancel`)}),(0,K.jsx)($,{variant:`primary`,size:`sm`,onClick:()=>{let e=o.trim();e&&r(e)},disabled:n||!o.trim(),children:a(n?`common.saving`:`queue.batch.create`)})]})]})})}function $Le({printDates:e,months:t=3}){let n=(0,y.useRef)(null),[r,i]=(0,y.useState)(0);(0,y.useEffect)(()=>{let e=n.current;if(!e)return;let t=new ResizeObserver(e=>{i(e[0]?.contentRect.width||0)});return t.observe(e),()=>t.disconnect()},[]);let{weeks:a,monthLabels:o,printCounts:s}=(0,y.useMemo)(()=>{let n={};e.forEach(e=>{let t=Cf(e);t&&(n[t]=(n[t]||0)+1)});let r=new Date,i=new Date(r);i.setMonth(i.getMonth()-t),i.setDate(i.getDate()-i.getDay());let a=[],o=[],s=[],c=-1,l=new Date(i),u=0;for(;l<=r;)l.getDay()===0&&s.length>0&&(a.push(s),s=[],u++),l.getMonth()!==c&&(o.push({month:l.toLocaleDateString(`en-US`,{month:`short`}),weekIndex:u}),c=l.getMonth()),s.push(new Date(l)),l.setDate(l.getDate()+1);return s.length>0&&a.push(s),{weeks:a,monthLabels:o,printCounts:n}},[e,t]),c=Math.max(1,...Object.values(s)),l=e=>{if(e===0)return`bg-bambu-dark`;let t=e/c;return t<=.25?`bg-bambu-green/30`:t<=.5?`bg-bambu-green/50`:t<=.75?`bg-bambu-green/75`:`bg-bambu-green`},u=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],d=a.length,f=r-32-16,p=d>0?Math.floor((f-(d-1)*2)/d):12,m=Math.max(8,Math.min(20,p)),h=m<=10?10:12;return(0,K.jsx)(`div`,{ref:n,className:`w-full flex justify-center`,children:r>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`flex mb-1`,style:{marginLeft:36},children:o.map(({month:e,weekIndex:t},n)=>(0,K.jsx)(`div`,{className:`text-bambu-gray`,style:{fontSize:h,marginLeft:n===0?0:`${(t-(o[n-1]?.weekIndex||0))*(m+2)-24}px`},children:e},n))}),(0,K.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,K.jsx)(`div`,{className:`flex flex-col`,style:{gap:2,marginRight:4,width:32},children:u.map((e,t)=>(0,K.jsx)(`div`,{className:`text-bambu-gray flex items-center`,style:{width:32,height:m,fontSize:h,visibility:t%2==1?`visible`:`hidden`},children:e},e))}),a.map((e,t)=>(0,K.jsx)(`div`,{className:`flex flex-col`,style:{gap:2},children:[0,1,2,3,4,5,6].map(t=>{let n=e.find(e=>e.getDay()===t);if(!n)return(0,K.jsx)(`div`,{style:{width:m,height:m}},t);let r=Cf(n),i=s[r]||0,a=r===Cf(new Date);return(0,K.jsx)(`div`,{className:`rounded-sm ${l(i)} ${a?`ring-1 ring-white`:``}`,style:{width:m,height:m},title:`${n.toLocaleDateString()}: ${i} print${i===1?``:`s`}`},t)})},t))]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-3 text-bambu-gray`,style:{fontSize:h},children:[(0,K.jsx)(`span`,{children:`Less`}),(0,K.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-dark`,style:{width:m,height:m}}),(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-green/30`,style:{width:m,height:m}}),(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-green/50`,style:{width:m,height:m}}),(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-green/75`,style:{width:m,height:m}}),(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-green`,style:{width:m,height:m}})]}),(0,K.jsx)(`span`,{children:`More`})]})]})})}var o5=[`weight`,`prints`,`time`];function s5({value:e,onChange:t,exclude:n}){let{t:r}=G(),i={weight:r(`stats.filamentByWeight`),prints:r(`stats.filamentByPrints`),time:r(`stats.filamentByTime`)};return(0,K.jsx)(`div`,{className:`flex gap-0.5 bg-bambu-dark rounded-lg p-0.5`,children:(n?o5.filter(e=>!n.includes(e)):o5).map(n=>(0,K.jsx)(`button`,{onClick:()=>t(n),className:`px-2 py-0.5 text-xs rounded-md transition-colors ${e===n?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:i[n]},n))})}function c5(e){if(e>=1e6){let t=e/1e6;return`${t%1==0?t.toFixed(0):t.toFixed(1)}t`}if(e>=1e3){let t=e/1e3;return`${t%1==0?t.toFixed(0):t.toFixed(1)}kg`}return`${Math.round(e)}g`}var l5=[`#00ae42`,`#3b82f6`,`#f59e0b`,`#ef4444`,`#8b5cf6`,`#ec4899`,`#14b8a6`,`#f97316`],eRe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],u5=[`12am`,`1am`,`2am`,`3am`,`4am`,`5am`,`6am`,`7am`,`8am`,`9am`,`10am`,`11am`,`12pm`,`1pm`,`2pm`,`3pm`,`4pm`,`5pm`,`6pm`,`7pm`,`8pm`,`9pm`,`10pm`,`11pm`];function tRe({archives:e,currency:t=`$`,dateFrom:n,dateTo:r}){let{t:i}=G(),[a,o]=(0,y.useState)(`weight`),[s,c]=(0,y.useState)(`weight`),l=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=mf(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)||{date:r,filament:0,cost:0,prints:0};i.filament+=e.filament_used_grams||0,i.cost+=e.cost||0,i.prints+=e.quantity||1,t.set(r,i)}),Array.from(t.values()).sort((e,t)=>e.date.localeCompare(t.date)).map(e=>({...e,dateLabel:new Date(e.date).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}))},[e]),u=(0,y.useMemo)(()=>{if(n&&r)return Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1;if(n)return Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1;if(e.length<2)return 0;let t=e.map(e=>new Date(e.completed_at||e.created_at).getTime());return(Math.max(...t)-Math.min(...t))/864e5},[e,n,r]),d=(0,y.useMemo)(()=>{if(u>7)return[];let t=new Map,n=u>1;return e.forEach(e=>{let n=mf(e.completed_at||e.created_at)||new Date,r=n.getHours(),i=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}T${String(r).padStart(2,`0`)}`,a=t.get(i)||{date:i,filament:0,cost:0,prints:0};a.filament+=e.filament_used_grams||0,a.cost+=e.cost||0,a.prints+=e.quantity||1,t.set(i,a)}),Array.from(t.values()).sort((e,t)=>e.date.localeCompare(t.date)).map(e=>{let[t,r]=e.date.split(`T`),i=new Date(t),a=parseInt(r,10),o=n?`${eRe[i.getDay()]} ${u5[a]}`:u5[a];return{...e,dateLabel:o}})},[e,u]),f=(0,y.useMemo)(()=>{if(l.length<=60)return l;let e=new Map;return l.forEach(t=>{let n=new Date(t.date),r=new Date(n);r.setDate(n.getDate()-n.getDay());let i=`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,`0`)}-${String(r.getDate()).padStart(2,`0`)}`,a=e.get(i)||{week:i,filament:0,cost:0,prints:0};a.filament+=t.filament,a.cost+=t.cost,a.prints+=t.prints,e.set(i,a)}),Array.from(e.values()).sort((e,t)=>e.week.localeCompare(t.week)).map(e=>({date:e.week,dateLabel:`Week of ${new Date(e.week).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}`,...e}))},[l]),p=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=(e.filament_type||`Unknown`).split(`, `);n.forEach(r=>{let i=(e.filament_used_grams||0)/n.length;t.set(r,(t.get(r)||0)+i)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:Math.round(t)})).sort((e,t)=>t.value-e.value)},[e]),m=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{(e.filament_type||`Unknown`).split(`, `).forEach(e=>{t.set(e,(t.get(e)||0)+1)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:t})).sort((e,t)=>t.value-e.value)},[e]),h=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=(e.filament_type||`Unknown`).split(`, `),r=(e.actual_time_seconds||e.print_time_seconds||0)/n.length;n.forEach(e=>{t.set(e,(t.get(e)||0)+r)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:Math.round(t/3600*10)/10})).sort((e,t)=>t.value-e.value)},[e]),g=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{e.status!==`completed`&&e.status!==`failed`||(e.filament_type||`Unknown`).split(`, `).forEach(n=>{let r=t.get(n)||{completed:0,failed:0};e.status===`completed`?r.completed++:r.failed++,t.set(n,r)})}),Array.from(t.entries()).filter(([,e])=>e.completed+e.failed>=2).map(([e,t])=>{let n=t.completed+t.failed;return{name:e,rate:Math.round(t.completed/n*100),total:n}}).sort((e,t)=>t.rate-e.rate)},[e]),_=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{if(!e.filament_color)return;let n=e.filament_color.split(`,`).map(e=>e.trim()),r=(e.filament_used_grams||0)/n.length;n.forEach(e=>{let n=t.get(e)||{count:0,weight:0};n.count++,n.weight+=r,t.set(e,n)})}),Array.from(t.entries()).map(([e,t])=>({hex:e,value:s===`prints`?t.count:Math.round(t.weight)})).sort((e,t)=>t.value-e.value)},[e,s]),v=a===`weight`?p:a===`prints`?m:h,b=u<=7&&d.length>0?d:f,x=e.reduce((e,t)=>e+(t.filament_used_grams||0),0),S=e.reduce((e,t)=>e+(t.cost||0),0),C=e.reduce((e,t)=>e+(t.quantity||1),0),w=new Set(e.map(e=>e.printer_id).filter(Boolean)).size;return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-[640px]:grid-cols-1`,children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:i(`stats.periodFilament`)}),(0,K.jsx)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:c5(x)})]}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[w,` `,i(`nav.printers`).toLowerCase()]})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:i(`stats.periodCost`)}),(0,K.jsxs)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:[t,S.toFixed(2)]})]}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[C,` `,i(`common.prints`)]})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:i(`stats.avgPerPrint`)}),(0,K.jsxs)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:[C>0?(x/C).toFixed(0):0,`g`]})]}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[t,C>0?(S/C).toFixed(2):`0.00`,` avg`]})]})]}),b.length>0?(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-4`,children:i(`stats.usageOverTime`)}),(0,K.jsx)(RA,{width:`100%`,height:250,children:(0,K.jsxs)(WG,{data:b,children:[(0,K.jsx)(`defs`,{children:(0,K.jsxs)(`linearGradient`,{id:`colorFilament`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,K.jsx)(`stop`,{offset:`5%`,stopColor:`#00ae42`,stopOpacity:.3}),(0,K.jsx)(`stop`,{offset:`95%`,stopColor:`#00ae42`,stopOpacity:0})]})}),(0,K.jsx)(XU,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,K.jsx)(eG,{dataKey:`dateLabel`,stroke:`#9ca3af`,tick:{fontSize:12},interval:`preserveStartEnd`}),(0,K.jsx)(aG,{stroke:`#9ca3af`,tick:{fontSize:12},tickFormatter:e=>`${e}g`}),(0,K.jsx)(Xz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},labelStyle:{color:`#fff`},formatter:e=>[`${Number(e??0).toFixed(0)}g`,`Filament`]}),(0,K.jsx)(MW,{type:`monotone`,dataKey:`filament`,stroke:`#00ae42`,strokeWidth:2,fillOpacity:1,fill:`url(#colorFilament)`})]})})]}):(0,K.jsx)(`div`,{className:`bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray`,children:i(`stats.noPrintDataInRange`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:i(`stats.byMaterial`)}),(0,K.jsx)(s5,{value:a,onChange:o})]}),v.length>0?(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(RA,{width:160,height:160,children:(0,K.jsxs)(UG,{children:[(0,K.jsx)(BH,{data:v,cx:`50%`,cy:`50%`,innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:`value`,children:v.map((e,t)=>(0,K.jsx)(Zz,{fill:l5[t%l5.length]},`cell-${t}`))}),(0,K.jsx)(Xz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},formatter:e=>[a===`weight`?c5(Number(e??0)):a===`time`?`${Number(e??0)}h`:`${e??0}`,a===`weight`?`Usage`:a===`time`?`Time`:`Prints`]})]})}),(0,K.jsx)(`div`,{className:`flex-1 space-y-2 overflow-hidden`,children:v.map((e,t)=>{let n=v.reduce((e,t)=>e+t.value,0),r=n>0?(e.value/n*100).toFixed(0):0;return(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-sm flex-shrink-0`,style:{backgroundColor:l5[t%l5.length]}}),(0,K.jsx)(`span`,{className:`text-white truncate flex-1`,children:e.name}),(0,K.jsxs)(`span`,{className:`text-bambu-gray flex-shrink-0`,children:[a===`weight`?c5(e.value):a===`time`?`${e.value}h`:e.value,` · `,r,`%`]})]},e.name)})})]}):(0,K.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:i(`stats.noFilamentData`)})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-4`,children:i(`stats.filamentSuccess`)}),g.length>0?(0,K.jsx)(`div`,{className:`space-y-1.5`,children:g.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`span`,{className:`text-white truncate w-20 flex-shrink-0`,children:e.name}),(0,K.jsx)(`div`,{className:`flex-1 h-1.5 bg-bambu-dark-secondary rounded-full`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all ${e.rate>=90?`bg-status-ok`:e.rate>=70?`bg-status-warning`:`bg-status-error`}`,style:{width:`${e.rate}%`}})}),(0,K.jsxs)(`span`,{className:`font-medium flex-shrink-0 tabular-nums ${e.rate>=90?`text-status-ok`:e.rate>=70?`text-status-warning`:`text-status-error`}`,children:[e.rate,`%`]}),(0,K.jsxs)(`span`,{className:`text-bambu-gray flex-shrink-0 text-xs`,children:[`(`,e.total,`)`]})]},e.name))}):(0,K.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:i(`stats.noArchiveData`)})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:i(`stats.colorDistribution`)}),(0,K.jsx)(s5,{value:s,onChange:c,exclude:[`time`]})]}),_.length>0?(()=>{let e=_.reduce((e,t)=>e+t.value,0);return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`relative mx-auto`,style:{width:160,height:160},children:[(0,K.jsx)(RA,{width:`100%`,height:`100%`,children:(0,K.jsxs)(UG,{children:[(0,K.jsx)(BH,{data:_,cx:`50%`,cy:`50%`,innerRadius:45,outerRadius:70,paddingAngle:2,dataKey:`value`,children:_.map((e,t)=>(0,K.jsx)(Zz,{fill:e.hex,stroke:`#1a1a1a`,strokeWidth:1},`color-${t}`))}),(0,K.jsx)(Xz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},formatter:e=>[s===`weight`?c5(Number(e??0)):`${e??0}`,i(s===`weight`?`stats.filamentByWeight`:`stats.filamentByPrints`)]})]})}),(0,K.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,K.jsx)(`span`,{className:`text-lg font-bold text-white`,children:s===`weight`?c5(e):e}),(0,K.jsxs)(`span`,{className:`text-[10px] text-bambu-gray`,children:[_.length,` `,_.length===1?`color`:`colors`]})]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-1 mt-2`,children:_.slice(0,8).map(t=>{let n=e>0?(t.value/e*100).toFixed(0):0;return(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs min-w-0`,children:[(0,K.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 border border-black/20`,style:{backgroundColor:t.hex}}),(0,K.jsxs)(`span`,{className:`text-bambu-gray truncate`,children:[n,`%`]})]},t.hex)})}),_.length>8&&(0,K.jsxs)(`p`,{className:`text-[10px] text-bambu-gray mt-1 text-center`,children:[`+`,_.length-8,` more`]})]})})():(0,K.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:i(`stats.noColorData`)})]})]})]})}function nRe({id:e,title:t,component:n,isHidden:r,size:i,columnSpan:a,onToggleVisibility:o,onToggleSize:s}){let{attributes:c,listeners:l,setNodeRef:u,transform:d,transition:f,isDragging:p}=K8({id:e}),m={transform:w6.Transform.toString(d),transition:f,opacity:p?.5:1};return r?null:(0,K.jsxs)(`div`,{ref:u,style:{...m,gridColumn:`span ${a}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${p?`ring-2 ring-bambu-green shadow-lg`:``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{...c,...l,className:`cursor-grab active:cursor-grabbing p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Drag to reorder`,children:(0,K.jsx)(gc,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray`})}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:t})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:s,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Size: ${i===1?`1/4`:i===2?`1/2`:`Full`} - Click to cycle`,children:i===4?(0,K.jsx)(Qc,{className:`w-4 h-4 text-bambu-gray hover:text-white`}):(0,K.jsx)(Jc,{className:`w-4 h-4 text-bambu-gray hover:text-white`})}),(0,K.jsx)(`button`,{onClick:o,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Hide widget`,children:(0,K.jsx)(Ws,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]})]}),(0,K.jsx)(`div`,{className:`p-4`,children:typeof n==`function`?n(i):n})]})}function rRe({widgets:e,storageKey:t,columns:n=4,stackBelow:r,hideControls:i=!1,onResetLayout:a,renderControls:o}){let s=()=>{let t={};return e.forEach(e=>{t[e.id]=e.defaultSize||4}),t},[c,l]=(0,y.useState)(()=>{let n=localStorage.getItem(t);if(n)try{let e=JSON.parse(n);if(!e.sizes)e.sizes=s();else{let t=s();for(let n in t)n in e.sizes||(e.sizes[n]=t[n])}return e}catch{}return{order:e.map(e=>e.id),hidden:e.filter(e=>e.defaultVisible===!1).map(e=>e.id),sizes:s()}}),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(!1);(0,y.useEffect)(()=>{if(!r)return;let e=window.matchMedia(`(max-width: ${r}px)`),t=e=>{p(e.matches)};t(e);let n=e=>t(e);return e.addEventListener?e.addEventListener(`change`,n):e.addListener(n),()=>{e.removeEventListener?e.removeEventListener(`change`,n):e.removeListener(n)}},[r]);let m=r&&f?1:n;(0,y.useEffect)(()=>{let e=()=>d(e=>!e);return window.addEventListener(`toggle-hidden-panel`,e),()=>window.removeEventListener(`toggle-hidden-panel`,e)},[]),(0,y.useEffect)(()=>{localStorage.setItem(t,JSON.stringify(c))},[c,t]),(0,y.useEffect)(()=>{let t=e.map(e=>e.id).filter(e=>!c.order.includes(e));t.length>0&&l(e=>({...e,order:[...e.order,...t]}))},[e,c.order]);let h=A6(k6(u8,{activationConstraint:{distance:8}}),k6(o8,{coordinateGetter:J8})),g=e=>{let{active:t,over:n}=e;n&&t.id!==n.id&&l(e=>{let r=e.order.indexOf(t.id),i=e.order.indexOf(n.id);return{...e,order:R8(e.order,r,i)}})},_=e=>{l(t=>({...t,hidden:t.hidden.includes(e)?t.hidden.filter(t=>t!==e):[...t.hidden,e]}))},v=e=>{l(t=>{let n=t.sizes[e]||4,r=n===1?2:n===2?4:1;return{...t,sizes:{...t.sizes,[e]:r}}})},b=()=>{l({order:e.map(e=>e.id),hidden:e.filter(e=>e.defaultVisible===!1).map(e=>e.id),sizes:s()}),a?.()},x=c.order.map(t=>e.find(e=>e.id===t)).filter(Boolean),S=x.filter(e=>!c.hidden.includes(e.id)),C=x.filter(e=>c.hidden.includes(e.id)),w=o?.({hiddenCount:C.length,showHiddenPanel:u,setShowHiddenPanel:d,resetLayout:b});return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[w,!i&&!o&&(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:b,children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),`Reset Layout`]}),C.length>0&&(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>d(!u),children:[(0,K.jsx)(Gs,{className:`w-4 h-4`}),C.length,` Hidden`]})]}),u&&C.length>0&&(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:`Hidden widgets (click to show):`}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:C.map(e=>(0,K.jsxs)(`button`,{onClick:()=>_(e.id),className:`px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2`,children:[(0,K.jsx)(Gs,{className:`w-3 h-3`}),e.title]},e.id))})]}),(0,K.jsx)(P8,{sensors:h,collisionDetection:L6,onDragEnd:g,children:(0,K.jsx)(W8,{items:S.map(e=>e.id),strategy:B8,children:(0,K.jsx)(`div`,{className:`grid gap-6`,style:{gridTemplateColumns:`repeat(${m}, minmax(0, 1fr))`},children:S.map(e=>{let t=c.sizes[e.id]||2,n=Math.min(t,m);return(0,K.jsx)(nRe,{id:e.id,title:e.title,component:e.component,isHidden:c.hidden.includes(e.id),size:t,columnSpan:n,onToggleVisibility:()=>_(e.id),onToggleSize:()=>v(e.id)},e.id)})})})}),S.length===0&&(0,K.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,K.jsx)(`p`,{children:`All widgets are hidden.`}),(0,K.jsx)($,{className:`mt-4`,onClick:b,children:`Reset Layout`})]})]})}function iRe(e){let t=new Date,n=t.getUTCFullYear(),r=t.getUTCMonth(),i=t.getUTCDate(),a=e=>e.toISOString().split(`T`)[0],o=a(t);switch(e){case`today`:return{dateFrom:o,dateTo:o};case`this-week`:{let e=t.getUTCDay();return{dateFrom:a(new Date(Date.UTC(n,r,i-(e===0?6:e-1)))),dateTo:o}}case`this-month`:return{dateFrom:a(new Date(Date.UTC(n,r,1))),dateTo:o};case`last-7`:return{dateFrom:a(new Date(Date.UTC(n,r,i-6))),dateTo:o};case`last-30`:return{dateFrom:a(new Date(Date.UTC(n,r,i-29))),dateTo:o};case`last-90`:return{dateFrom:a(new Date(Date.UTC(n,r,i-89))),dateTo:o};case`this-year`:return{dateFrom:a(new Date(Date.UTC(n,0,1))),dateTo:o};case`all-time`:return{dateFrom:void 0,dateTo:void 0};case`custom`:return{}}}var aRe=[`today`,`this-week`,`this-month`,`last-7`,`last-30`,`last-90`,`this-year`,`all-time`],oRe=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],d5=[`12am`,`1am`,`2am`,`3am`,`4am`,`5am`,`6am`,`7am`,`8am`,`9am`,`10am`,`11am`,`12pm`,`1pm`,`2pm`,`3pm`,`4pm`,`5pm`,`6pm`,`7pm`,`8pm`,`9pm`,`10pm`,`11pm`],f5=[{key:`<30m`,max:1800},{key:`30m-1h`,max:3600},{key:`1-2h`,max:7200},{key:`2-4h`,max:14400},{key:`4-8h`,max:28800},{key:`8-12h`,max:43200},{key:`12-24h`,max:86400},{key:`24h+`,max:1/0}],p5={backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`};function sRe({stats:e,currency:t}){let{t:n}=G(),r=e?.energy_data_warming_up===!0,i=r?n(`stats.energyWarmingUpTooltip`):void 0;return(0,K.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-4`,children:[{icon:cl,color:`text-bambu-green`,label:n(`stats.totalPrints`),value:`${e?.total_prints||0}`},{icon:_s,color:`text-blue-400`,label:n(`stats.printTime`),value:`${e?.total_print_time_hours?.toFixed(1)??`0`}h`},{icon:cl,color:`text-orange-400`,label:n(`stats.filamentUsed`),value:c5(e?.total_filament_grams||0)},{icon:Ns,color:`text-green-400`,label:n(`stats.filamentCost`),value:`${t} ${e?.total_cost?.toFixed(2)??`0.00`}`},{icon:Iu,color:`text-yellow-400`,label:n(`stats.energyUsed`),value:`${e?.total_energy_kwh?.toFixed(3)??`0.000`} kWh`,warning:r,tooltip:i},{icon:Ns,color:`text-yellow-500`,label:n(`stats.energyCost`),value:`${t} ${e?.total_energy_cost?.toFixed(2)??`0.00`}`,warning:r,tooltip:i}].map(e=>(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,title:e.tooltip,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${e.color}`,children:(0,K.jsx)(e.icon,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray flex items-center gap-1`,children:[e.label,e.warning&&(0,K.jsx)(vu,{className:`w-3 h-3 text-yellow-400`,"aria-label":e.tooltip})]}),(0,K.jsx)(`p`,{className:`text-xl font-bold text-white`,children:e.value})]})]},e.label))})}function cRe({stats:e,printerMap:t,size:n=1}){let{t:r}=G(),i=(e?.successful_prints||0)+(e?.failed_prints||0),a=i?Math.round((e?.successful_prints||0)/i*100):0,o=n===1?112:n===2?128:144,s=o/2-8,c=s*2*Math.PI;return(0,K.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,K.jsxs)(`div`,{className:`relative flex-shrink-0`,style:{width:o,height:o},children:[(0,K.jsxs)(`svg`,{className:`w-full h-full -rotate-90`,children:[(0,K.jsx)(`circle`,{cx:o/2,cy:o/2,r:s,fill:`none`,stroke:`#3d3d3d`,strokeWidth:`10`}),(0,K.jsx)(`circle`,{cx:o/2,cy:o/2,r:s,fill:`none`,stroke:`#00ae42`,strokeWidth:`10`,strokeLinecap:`round`,strokeDasharray:`${a/100*c} ${c}`})]}),(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,K.jsxs)(`span`,{className:`font-bold text-white ${n>=2?`text-2xl`:`text-xl`}`,children:[a,`%`]})})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(ls,{className:`w-4 h-4 text-status-ok flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.successful`)}),(0,K.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.successful_prints||0})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(ms,{className:`w-4 h-4 text-status-error flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.failed`)}),(0,K.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.failed_prints||0})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(No,{className:`w-4 h-4 text-status-warning flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.cancelled`)}),(0,K.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.cancelled_prints||0})]})]}),n>=2&&e?.prints_by_printer&&Object.keys(e.prints_by_printer).length>0&&(0,K.jsxs)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray font-medium mb-2`,children:r(`stats.printsByPrinter`)}),(0,K.jsx)(`div`,{className:`grid gap-x-6 gap-y-1 ${n===4?`grid-cols-3`:`grid-cols-2`}`,style:{width:`fit-content`},children:Object.entries(e.prints_by_printer).map(([e,n])=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray truncate max-w-[120px]`,children:t.get(e)||`${r(`common.printer`)} ${e}`}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:n})]},e))})]})]})]})}function lRe({stats:e,printerMap:t,size:n=1}){let{t:r}=G(),i=e?.average_time_accuracy;if(i==null)return(0,K.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,K.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noTimeAccuracyData`)})});let a=(Math.min(150,Math.max(50,i))-50)/100*100,o=(e=>e>=95&&e<=105?`#00ae42`:e>105?`#3b82f6`:`#f97316`)(i),s=i-100,c=n===1?112:n===2?128:144,l=c/2-8,u=l*2*Math.PI,d=n===1?3:n===2?6:999,f=e?.time_accuracy_by_printer?Object.entries(e.time_accuracy_by_printer).slice(0,d):[];return(0,K.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,K.jsxs)(`div`,{className:`relative flex-shrink-0`,style:{width:c,height:c},children:[(0,K.jsxs)(`svg`,{className:`w-full h-full -rotate-90`,children:[(0,K.jsx)(`circle`,{cx:c/2,cy:c/2,r:l,fill:`none`,stroke:`#3d3d3d`,strokeWidth:`10`}),(0,K.jsx)(`circle`,{cx:c/2,cy:c/2,r:l,fill:`none`,stroke:o,strokeWidth:`10`,strokeLinecap:`round`,strokeDasharray:`${a/100*u} ${u}`})]}),(0,K.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,K.jsxs)(`span`,{className:`font-bold text-white ${n>=2?`text-2xl`:`text-xl`}`,children:[i.toFixed(0),`%`]}),(0,K.jsxs)(`span`,{className:`text-xs ${s>=0?`text-blue-400`:`text-orange-400`}`,children:[s>=0?`+`:``,s.toFixed(0),`%`]})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:[(0,K.jsx)(cu,{className:`w-3 h-3 flex-shrink-0`}),(0,K.jsx)(`span`,{children:r(`stats.perfectEstimate`)})]}),f.length>0&&(0,K.jsx)(`div`,{className:`mt-2 ${n===4?`grid grid-cols-3 gap-x-6 gap-y-1`:n===2?`grid grid-cols-2 gap-x-6 gap-y-1`:`space-y-1`}`,style:{width:`fit-content`},children:f.map(([e,n])=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray truncate max-w-[100px]`,children:t.get(e)||`${r(`common.printer`)} ${e}`}),(0,K.jsxs)(`span`,{className:`font-medium ${n>=95&&n<=105?`text-status-ok`:n>105?`text-blue-400`:`text-status-warning`}`,children:[n.toFixed(0),`%`]})]},e))})]})]})}function uRe({printDates:e,dateFrom:t,dateTo:n}){let{days:r,hourlyCounts:i,maxCount:a}=(0,y.useMemo)(()=>{let r=new Date(t+`T00:00:00`),i=new Date(n+`T00:00:00`),a=[],o=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`,s=new Date(r);for(;s<=i;)a.push({key:o(s),label:s.toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`})}),s.setDate(s.getDate()+1);let c={},l=0;return e.forEach(e=>{let t=mf(e);if(!t)return;let n=`${`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}-${t.getHours()}`;c[n]=(c[n]||0)+1,c[n]>l&&(l=c[n])}),{days:a,hourlyCounts:c,maxCount:Math.max(1,l)}},[e,t,n]),o=e=>{if(e===0)return`bg-bambu-dark`;let t=e/a;return t<=.25?`bg-bambu-green/30`:t<=.5?`bg-bambu-green/50`:t<=.75?`bg-bambu-green/75`:`bg-bambu-green`};return(0,K.jsxs)(`div`,{className:`w-full overflow-x-auto`,children:[(0,K.jsxs)(`div`,{className:`inline-flex flex-col`,style:{gap:2},children:[(0,K.jsx)(`div`,{className:`flex`,style:{gap:2,marginLeft:84},children:d5.map((e,t)=>(0,K.jsx)(`div`,{className:`text-bambu-gray text-[10px] text-center`,style:{width:20,visibility:t%2==0?`visible`:`hidden`},children:e},t))}),r.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center`,style:{gap:2},children:[(0,K.jsx)(`div`,{className:`text-bambu-gray text-[10px] flex-shrink-0 truncate`,style:{width:80},children:e.label}),Array.from({length:24},(t,n)=>{let r=i[`${e.key}-${n}`]||0;return(0,K.jsx)(`div`,{className:`rounded-sm ${o(r)}`,style:{width:20,height:20},title:`${e.label} ${d5[n]}: ${r} print${r===1?``:`s`}`},n)})]},e.key))]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-3 text-bambu-gray text-xs`,children:[(0,K.jsx)(`span`,{children:`Less`}),(0,K.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-dark`,style:{width:20,height:20}}),(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-green/30`,style:{width:20,height:20}}),(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-green/50`,style:{width:20,height:20}}),(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-green/75`,style:{width:20,height:20}}),(0,K.jsx)(`div`,{className:`rounded-sm bg-bambu-green`,style:{width:20,height:20}})]}),(0,K.jsx)(`span`,{children:`More`})]})]})}function dRe({printDates:e,size:t=2,dateFrom:n,dateTo:r}){let i=(0,y.useMemo)(()=>n&&r?Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1:n?Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1:1/0,[n,r]);return i<=7&&n&&r?(0,K.jsx)(uRe,{printDates:e,dateFrom:n,dateTo:r}):(0,K.jsx)($Le,{printDates:e,months:i===1/0?t===1?3:t===2?6:12:Math.max(1,Math.ceil(i/30))})}function fRe({stats:e,archives:t,printerMap:n}){let{t:r}=G(),[i,a]=(0,y.useState)(`weight`),[o,s]=(0,y.useState)(`weight`),c=(0,y.useMemo)(()=>{let a=new Map;return e?.prints_by_printer&&Object.entries(e.prints_by_printer).forEach(([e,t])=>{let n=a.get(e)||{prints:0,weight:0,time:0};n.prints=t,a.set(e,n)}),t.forEach(t=>{if(!t.printer_id)return;let n=String(t.printer_id),r=a.get(n)||{prints:0,weight:0,time:0};r.weight+=t.filament_used_grams||0,r.time+=t.actual_time_seconds||t.print_time_seconds||0,e?.prints_by_printer||r.prints++,a.set(n,r)}),Array.from(a.entries()).map(([e,t])=>({name:n.get(e)||`${r(`common.printer`)} ${e}`,value:i===`prints`?t.prints:i===`weight`?Math.round(t.weight):Math.round(t.time/3600*10)/10})).sort((e,t)=>t.value-e.value)},[e,t,n,i,r]),l=(0,y.useMemo)(()=>{let e=Array.from({length:24},(e,t)=>({hour:t,label:d5[t],total:0,failures:0}));return t.forEach(t=>{if(!t.started_at)return;let n=mf(t.started_at);if(!n)return;let r=n.getHours();e[r].total++,t.status===`failed`&&e[r].failures++}),e},[t]),u=(0,y.useMemo)(()=>{let e=f5.map(e=>({name:e.key,count:0}));return t.forEach(t=>{let n=t.actual_time_seconds||t.print_time_seconds;if(!(!n||n<=0)){for(let t=0;t{let e=[0,0,0,0,0,0,0],n=new Set;t.forEach(t=>{let r=mf(t.created_at)||new Date(t.created_at),i=r.getDay()-1;i<0&&(i=6),o===`prints`?e[i]++:o===`weight`?e[i]+=t.filament_used_grams||0:e[i]+=(t.actual_time_seconds||t.print_time_seconds||0)/3600;let a=new Date(r);a.setDate(r.getDate()-(r.getDay()+6)%7),n.add(`${a.getFullYear()}-${String(a.getMonth()+1).padStart(2,`0`)}-${String(a.getDate()).padStart(2,`0`)}`)});let r=Math.max(n.size,1);return oRe.map((t,n)=>({name:t,avg:Math.round(e[n]/r*10)/10}))},[t,o]),f=e=>({unit:e===`weight`?`g`:e===`time`?`h`:``,color:e===`weight`?`#00ae42`:e===`time`?`#3b82f6`:`#f59e0b`}),p=f(i),m=r(i===`weight`?`stats.filamentByWeight`:i===`time`?`stats.hours`:`common.prints`),h=f(o),g=r(o===`weight`?`stats.avgWeight`:o===`time`?`stats.avgTime`:`stats.avgPrints`);return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:r(`stats.printsByPrinter`)}),(0,K.jsx)(s5,{value:i,onChange:a})]}),c.length>0?(0,K.jsx)(RA,{width:`100%`,height:Math.max(140,c.length*40),children:(0,K.jsxs)(RG,{data:c,layout:`vertical`,margin:{left:10},children:[(0,K.jsx)(XU,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,K.jsx)(eG,{type:`number`,stroke:`#9ca3af`,tick:{fontSize:11},unit:p.unit}),(0,K.jsx)(aG,{type:`category`,dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11},width:100}),(0,K.jsx)(Xz,{contentStyle:p5,formatter:e=>[i===`weight`?c5(Number(e??0)):`${e??0}${p.unit}`,m]}),(0,K.jsx)(KW,{dataKey:`value`,fill:p.color,radius:[0,4,4,0]})]})}):(0,K.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noPrinterData`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:r(`stats.printDuration`)}),t.length>0?(0,K.jsx)(RA,{width:`100%`,height:160,children:(0,K.jsxs)(RG,{data:u,children:[(0,K.jsx)(XU,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,K.jsx)(eG,{dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11}}),(0,K.jsx)(aG,{stroke:`#9ca3af`,tick:{fontSize:11},allowDecimals:!1}),(0,K.jsx)(Xz,{contentStyle:p5}),(0,K.jsx)(KW,{dataKey:`count`,name:r(`common.prints`),fill:`#00ae42`,radius:[4,4,0,0]})]})}):(0,K.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:r(`stats.printHabits`)}),(0,K.jsx)(s5,{value:o,onChange:s})]}),t.length>0?(0,K.jsx)(RA,{width:`100%`,height:160,children:(0,K.jsxs)(RG,{data:d,children:[(0,K.jsx)(XU,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,K.jsx)(eG,{dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11}}),(0,K.jsx)(aG,{stroke:`#9ca3af`,tick:{fontSize:11},unit:h.unit}),(0,K.jsx)(Xz,{contentStyle:p5,formatter:e=>[`${e??0}${h.unit}`,g]}),(0,K.jsx)(KW,{dataKey:`avg`,fill:h.color,radius:[4,4,0,0]})]})}):(0,K.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:r(`stats.printTimeOfDay`)}),t.length>0?(0,K.jsx)(RA,{width:`100%`,height:160,children:(0,K.jsxs)(RG,{data:l,children:[(0,K.jsx)(XU,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,K.jsx)(eG,{dataKey:`label`,stroke:`#9ca3af`,tick:{fontSize:10},interval:5}),(0,K.jsx)(aG,{stroke:`#9ca3af`,tick:{fontSize:11},allowDecimals:!1}),(0,K.jsx)(Xz,{contentStyle:p5}),(0,K.jsx)(KW,{dataKey:`total`,name:r(`stats.totalPrints`),fill:`#00ae42`,radius:[2,2,0,0]}),(0,K.jsx)(KW,{dataKey:`failures`,name:r(`stats.failed`),fill:`#ef4444`,radius:[2,2,0,0]})]})}):(0,K.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]})]})]})}function pRe({archives:e,currency:t,dateFrom:n,dateTo:r}){let{t:i}=G();return!e||e.length===0?(0,K.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:i(`stats.noPrintData`)}):(0,K.jsx)(tRe,{archives:e,currency:t,dateFrom:n,dateTo:r})}function mRe({size:e=1,dateFrom:t,dateTo:n,createdById:r}){let{t:i}=G(),a=!!(t||n),{data:o,isLoading:s}=q({queryKey:[`failureAnalysis`,t,n,r??`all`],queryFn:()=>Q.getFailureAnalysis({...a?{dateFrom:t,dateTo:n}:{days:30},createdById:r})});if(s)return(0,K.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})});if(!o||o.total_prints===0)return(0,K.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:i(a?`stats.noPrintDataInRange`:`stats.noPrintDataLast30Days`)});let c=e===1?5:e===2?8:999,l=Object.entries(o.failures_by_reason).sort(([,e],[,t])=>t-e),u=l.slice(0,c),d=l.length>c;return(0,K.jsxs)(`div`,{className:`${e>=2?`flex gap-8`:`space-y-4`}`,children:[(0,K.jsxs)(`div`,{className:e>=2?`flex-shrink-0`:``,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(vu,{className:`w-5 h-5 ${o.failure_rate>20?`text-status-error`:o.failure_rate>10?`text-status-warning`:`text-status-ok`}`}),(0,K.jsxs)(`span`,{className:`font-bold text-white ${e>=2?`text-3xl`:`text-2xl`}`,children:[o.failure_rate.toFixed(1),`%`]})]})}),(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray mt-1`,children:i(`stats.failedPrintsCount`,{failed:o.failed_prints,total:o.total_prints})}),o.trend&&o.trend.length>=2&&(0,K.jsx)(`div`,{className:`${e>=2?`mt-4`:`mt-2 pt-2 border-t border-bambu-dark-tertiary`}`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(gu,{className:`w-4 h-4 ${o.trend[o.trend.length-1].failure_rate0&&(0,K.jsxs)(`div`,{className:`flex-1 ${e>=2?`border-l border-bambu-dark-tertiary pl-8`:`pt-2`}`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray font-medium mb-2`,children:i(e>=2?`stats.failureReasons`:`stats.topFailureReasons`)}),(0,K.jsx)(`div`,{className:`${e===4?`grid grid-cols-2 gap-x-6 gap-y-1`:`space-y-1`}`,children:u.map(([t,n])=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,K.jsx)(`span`,{className:`text-white truncate ${e===4?`max-w-[200px]`:`max-w-[160px]`}`,children:t?i(`editArchive.failureReasons.${t}`,{defaultValue:t}):i(`common.unknown`)}),(0,K.jsx)(`span`,{className:`text-bambu-gray ml-2`,children:n})]},t))}),d&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:i(`common.more`,{count:l.length-c})})]})]})}function hRe({archives:e,currency:t}){let{t:n}=G(),r=(0,y.useMemo)(()=>{let r=[];if(e.length===0)return r;let i=t=>{let n=null,r=0;return e.forEach(e=>{let i=t(e);i&&i>r&&(r=i,n=e)}),{archive:n,value:r}},a=i(e=>e.status===`completed`?e.actual_time_seconds:null);a.archive&&r.push({icon:_s,iconColor:`text-blue-400`,label:n(`stats.longestPrint`),value:yf(a.value),detail:a.archive.print_name||null});let o=i(e=>e.filament_used_grams);o.archive&&r.push({icon:cl,iconColor:`text-orange-400`,label:n(`stats.heaviestPrint`),value:c5(o.value),detail:o.archive.print_name||null});let s=i(e=>e.cost);s.archive&&r.push({icon:Ns,iconColor:`text-green-400`,label:n(`stats.mostExpensivePrint`),value:`${t}${s.value.toFixed(2)}`,detail:s.archive.print_name||null});let c=new Map;e.forEach(e=>{let t=mf(e.created_at)||new Date(e.created_at),n=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`;c.set(n,(c.get(n)||0)+1)});let l=``,u=0;c.forEach((e,t)=>{e>u&&(u=e,l=t)}),u>1&&r.push({icon:qo,iconColor:`text-purple-400`,label:n(`stats.busiestDay`),value:`${u} ${n(`common.prints`)}`,detail:(()=>{let[e,t,n]=l.split(`-`).map(Number);return new Date(e,t-1,n).toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})})()});let d=[...e].filter(e=>e.status===`completed`||e.status===`failed`).sort((e,t)=>new Date(t.completed_at||t.created_at).getTime()-new Date(e.completed_at||e.created_at).getTime()),f=0;for(let e of d)if(e.status===`completed`)f++;else break;return f>0&&r.push({icon:Iu,iconColor:`text-yellow-400`,label:n(`stats.successStreak`),value:`${f}`,detail:f===1?n(`stats.streakPrint`):n(`stats.streakPrints`,{count:f})}),r},[e,t,n]);return r.length===0?(0,K.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:n(`stats.noArchiveData`)}):(0,K.jsx)(`div`,{className:`space-y-3`,children:r.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-1.5 rounded-lg bg-bambu-dark ${e.iconColor}`,children:(0,K.jsx)(e.icon,{className:`w-4 h-4`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.label}),(0,K.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-bold text-white`,children:e.value}),e.detail&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:e.detail})]})]})]},t))})}function gRe(){let{t:e}=G(),{showToast:t}=xd(),{hasPermission:n,authEnabled:r}=sd(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(0),[u,d]=(0,y.useState)(0),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(!1),v=r&&n(`stats:filter_by_user`),[b,x]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`bambusy-stats-timeframe`);if(e){let t=JSON.parse(e);if(t.preset)return t}}catch{}return{preset:`all-time`,dateFrom:void 0,dateTo:void 0}}),[S,C]=(0,y.useState)(!1);(0,y.useEffect)(()=>{localStorage.setItem(`bambusy-stats-timeframe`,JSON.stringify(b))},[b]);let w=(0,y.useMemo)(()=>b.preset===`custom`?{dateFrom:b.dateFrom,dateTo:b.dateTo}:iRe(b.preset),[b]);(0,y.useEffect)(()=>{let e=()=>{try{let e=localStorage.getItem(`bambusy-dashboard-layout-v2`);e&&d(JSON.parse(e).hidden?.length||0)}catch{d(0)}};e(),window.addEventListener(`storage`,e);let t=setInterval(e,2e3);return()=>{window.removeEventListener(`storage`,e),clearInterval(t)}},[c]);let T=m===null?void 0:m,{data:E,isLoading:D,isFetching:O,refetch:k}=q({queryKey:[`archiveStats`,w.dateFrom,w.dateTo,T??`all`],queryFn:()=>Q.getArchiveStats({dateFrom:w.dateFrom,dateTo:w.dateTo,createdById:T})}),{data:A}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:j,isFetching:M,refetch:N}=q({queryKey:[`archivesSlim`,w.dateFrom,w.dateTo,T??`all`],queryFn:()=>Q.getArchivesSlim(w.dateFrom,w.dateTo,T)}),{data:P}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:F}=q({queryKey:[`users`],queryFn:Q.getUsers,enabled:v}),I=(0,y.useMemo)(()=>m===null?e(`stats.allUsers`,`All Users`):m===-1?e(`stats.noUser`,`No User (System)`):F?.find(e=>e.id===m)?.username??`?`,[m,F,e]),L=async n=>{s(!1),a(!0);try{let{blob:r,filename:i}=await Q.exportStats({format:n,days:90,createdById:T}),a=URL.createObjectURL(r),o=document.createElement(`a`);o.href=a,o.download=i,o.click(),URL.revokeObjectURL(a),t(e(`stats.exportDownloaded`))}catch{t(e(`stats.exportFailed`),`error`)}finally{a(!1)}},R=async()=>{p(!0);try{let n=await Q.recalculateCosts();await Promise.all([k(),N()]),t(e(`stats.recalculatedCosts`,{count:n.updated}))}catch{t(e(`stats.recalculateFailed`),`error`)}finally{p(!1)}},z=(O||M)&&!D,B=Yd(P?.currency||`USD`),V=new Map(A?.map(e=>[String(e.id),e.name])||[]),ee=(0,y.useMemo)(()=>j?.map(e=>e.created_at)||[],[j]);if(D)return(0,K.jsx)(`div`,{className:`p-4 md:p-8`,children:(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`stats.loadingStats`)})});let H=[{id:`quick-stats`,title:e(`stats.quickStats`),component:(0,K.jsx)(sRe,{stats:E,currency:B}),defaultSize:2},{id:`success-rate`,title:e(`stats.successRate`),component:e=>(0,K.jsx)(cRe,{stats:E,printerMap:V,size:e}),defaultSize:1},{id:`time-accuracy`,title:e(`stats.timeAccuracy`),component:e=>(0,K.jsx)(lRe,{stats:E,printerMap:V,size:e}),defaultSize:1},{id:`failure-analysis`,title:e(`stats.failureAnalysis`),component:e=>(0,K.jsx)(mRe,{size:e,dateFrom:w.dateFrom,dateTo:w.dateTo,createdById:T}),defaultSize:1},{id:`print-activity`,title:e(`stats.printActivity`),component:e=>(0,K.jsx)(dRe,{printDates:ee,size:e,dateFrom:w.dateFrom,dateTo:w.dateTo}),defaultSize:2},{id:`records`,title:e(`stats.records`),component:(0,K.jsx)(hRe,{archives:j||[],currency:B}),defaultSize:1},{id:`printer-stats`,title:e(`stats.printerStats`),component:(0,K.jsx)(fRe,{stats:E,archives:j||[],printerMap:V}),defaultSize:4},{id:`filament-trends`,title:e(`stats.filamentTrends`),component:(0,K.jsx)(pRe,{archives:j||[],currency:B,dateFrom:w.dateFrom,dateTo:w.dateTo}),defaultSize:4}];return(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(Yo,{className:`w-7 h-7 text-bambu-green`}),e(`stats.title`)]}),z&&(0,K.jsx)(X,{className:`w-5 h-5 text-bambu-green animate-spin`})]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`stats.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u>0&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>{window.dispatchEvent(new CustomEvent(`toggle-hidden-panel`))},children:[(0,K.jsx)(Gs,{className:`w-4 h-4`}),e(`stats.hiddenCount`,{count:u})]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>{localStorage.removeItem(`bambusy-dashboard-layout-v2`),l(e=>e+1),t(e(`stats.layoutReset`))},disabled:!n(`settings:update`),title:n(`settings:update`)?void 0:e(`stats.noPermissionResetLayout`),children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),e(`stats.resetLayout`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:R,disabled:f||!n(`archives:update_all`),title:n(`archives:update_all`)?e(`stats.recalculateCostsHint`):e(`stats.noPermissionRecalculate`),children:[f?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Wo,{className:`w-4 h-4`}),e(`stats.recalculateCosts`)]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:()=>s(!o),disabled:i,children:[i?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Xs,{className:`w-4 h-4`}),e(`stats.exportStats`)]}),o&&(0,K.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20`,children:[(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg`,onClick:()=>L(`csv`),children:[(0,K.jsx)(Zs,{className:`w-4 h-4`}),e(`stats.exportAsCsv`)]}),(0,K.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg`,onClick:()=>L(`xlsx`),children:[(0,K.jsx)(Xs,{className:`w-4 h-4`}),e(`stats.exportAsExcel`)]})]})]}),v&&F&&F.length>0&&(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:()=>_(!g),children:[(0,K.jsx)(wu,{className:`w-4 h-4`}),I,(0,K.jsx)(es,{className:`w-3 h-3`})]}),g&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>_(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2 max-h-64 overflow-y-auto`,children:[(0,K.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${m===null?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{h(null),_(!1)},children:e(`stats.allUsers`,`All Users`)}),(0,K.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${m===-1?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{h(-1),_(!1)},children:e(`stats.noUser`,`No User (System)`)}),(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary my-1`}),F.map(e=>(0,K.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${m===e.id?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{h(e.id),_(!1)},children:e.username},e.id))]})]})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:()=>C(!S),children:[(0,K.jsx)(qo,{className:`w-4 h-4`}),e(`stats.timeframe.${b.preset}`),(0,K.jsx)(es,{className:`w-3 h-3`})]}),S&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>C(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-64 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2`,children:[aRe.map(t=>(0,K.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${b.preset===t?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{x({preset:t,dateFrom:void 0,dateTo:void 0}),C(!1)},children:e(`stats.timeframe.${t}`)},t)),(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary my-2`}),(0,K.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${b.preset===`custom`?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>x(e=>({...e,preset:`custom`})),children:e(`stats.timeframe.custom`)}),b.preset===`custom`&&(0,K.jsxs)(`div`,{className:`mt-2 px-1 pb-1 space-y-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:e(`stats.timeframe.from`)}),(0,K.jsx)(`input`,{type:`date`,value:b.dateFrom||``,max:b.dateTo||new Date().toISOString().split(`T`)[0],onChange:e=>x(t=>({...t,dateFrom:e.target.value||void 0})),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white [color-scheme:dark]`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:e(`stats.timeframe.to`)}),(0,K.jsx)(`input`,{type:`date`,value:b.dateTo||``,min:b.dateFrom,max:new Date().toISOString().split(`T`)[0],onChange:e=>x(t=>({...t,dateTo:e.target.value||void 0})),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white [color-scheme:dark]`})]}),(0,K.jsx)($,{variant:`primary`,onClick:()=>C(!1),className:`w-full`,children:e(`common.apply`)})]})]})]})]})]})]}),(0,K.jsx)(rRe,{widgets:H,storageKey:`bambusy-dashboard-layout-v2`,stackBelow:640,hideControls:!0},c)]})}function m5(e){return e.length<8?`tooShort`:/[A-Z]/.test(e)?/[a-z]/.test(e)?/\d/.test(e)?/[^A-Za-z0-9]/.test(e)?null:`needsSpecial`:`needsDigit`:`needsLowercase`:`needsUppercase`}function _Re(){let{t:e}=G();return(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(cl,{className:`w-4 h-4 text-bambu-gray`}),e(`settings.slicerBundlesRemoved.title`,{defaultValue:`Slicer Bundles (removed)`})]})}),(0,K.jsxs)(hd,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.slicerBundlesRemoved.description`,{defaultValue:`Printer Preset Bundle (.bbscfg) import was removed. BambuStudio's bundle export only includes user-customised presets, so the import never delivered standard processes / filaments and slicing fell back to embedded settings.`})}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.slicerBundlesRemoved.alternatives`,{defaultValue:`Use Single Preset Import for individual customs, or sync via Bambu Cloud / Orca Cloud. Stock presets come from the slicer sidecar automatically.`})}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.slicerBundlesRemoved.lookupOrder`,{defaultValue:`Slice-time preset lookup order: 1) Imported (local), 2) Orca Cloud, 3) Bambu Cloud, 4) Standard (sidecar fallback).`})})]})]})}var h5=90,g5=365;function _5(e){if(!e)return`—`;let t=mf(e);return t?t.toLocaleString():`—`}function vRe(e){let t=mf(e);return t?t.getTime(){if(s.preventDefault(),r.trim()){c(!0);try{e(await Q.createLongLivedCameraToken({name:r.trim(),expires_in_days:a})),i(``),o(h5),n(t(`cameraTokens.toast.created`,`Token created`))}catch(e){n(e instanceof Error?e.message:t(`cameraTokens.toast.createFailed`,`Failed to create token`),`error`)}finally{c(!1)}}},className:`bg-bambu-dark-secondary rounded-lg p-4 mb-6 border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:t(`cameraTokens.create.title`,`Create new token`)}),(0,K.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-[1fr_140px_auto]`,children:[(0,K.jsx)(`input`,{type:`text`,maxLength:100,required:!0,value:r,onChange:e=>i(e.target.value),placeholder:t(`cameraTokens.create.namePlaceholder`,`e.g. Home Assistant`),className:`px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":t(`cameraTokens.create.nameLabel`,`Token name`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:g5,required:!0,value:a,onChange:e=>{let t=Number(e.target.value);o(Math.min(Math.max(t,1),g5))},className:`px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":t(`cameraTokens.create.daysLabel`,`Days until expiry`)}),(0,K.jsxs)(`button`,{type:`submit`,disabled:s||!r.trim(),className:`flex items-center gap-2 px-4 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),t(`cameraTokens.create.submit`,`Create`)]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:t(`cameraTokens.create.hint`,`Maximum lifetime is 365 days. The token value is shown only once on creation — copy it now.`)})]})}function bRe({token:e,onConfirm:t,onCancel:n}){let{t:r}=G();return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full border border-red-500/40`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,K.jsx)(vu,{className:`w-6 h-6 text-red-400 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`cameraTokens.confirmRevoke.title`,`Revoke this token?`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`cameraTokens.confirmRevoke.body`,`Any device using "{{name}}" will lose access immediately. This cannot be undone.`,{name:e.name})})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:n,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:r(`cameraTokens.confirmRevoke.cancel`,`Cancel`)}),(0,K.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600`,children:r(`cameraTokens.confirmRevoke.confirm`,`Revoke`)})]})]})})}function xRe({token:e,onClose:t}){let{t:n}=G(),{showToast:r}=xd(),i=e.token??``;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-2xl w-full border border-bambu-green/40`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,K.jsx)(vu,{className:`w-6 h-6 text-yellow-400 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`cameraTokens.created.title`,`Token created — copy it now`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:n(`cameraTokens.created.warning`,`This is the only time this token will be visible. After you close this dialog you can never view it again.`)})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,K.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:i}),(0,K.jsxs)(`button`,{type:`button`,onClick:async()=>{if(i)try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(i);else{let e=document.createElement(`textarea`);e.value=i,e.style.position=`fixed`,e.style.opacity=`0`,document.body.appendChild(e);try{e.select(),document.execCommand(`copy`)}finally{document.body.removeChild(e)}}r(n(`cameraTokens.toast.copied`,`Copied to clipboard`))}catch{r(n(`cameraTokens.toast.copyFailed`,`Copy failed — select and copy manually`),`error`)}},className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,K.jsx)(Ds,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]}),(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:n(`cameraTokens.created.dismiss`,`I've saved it`)})})]})})}function SRe({token:e,showOwner:t,ownerLabel:n,onRevoke:r}){let{t:i}=G(),a=vRe(e.expires_at);return(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,K.jsx)(`td`,{className:`py-3 px-3 text-white`,children:e.name}),t&&(0,K.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:n}),(0,K.jsxs)(`td`,{className:`py-3 px-3 text-bambu-gray font-mono text-xs`,children:[e.lookup_prefix,`…`]}),(0,K.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:_5(e.created_at)}),(0,K.jsxs)(`td`,{className:`py-3 px-3 ${a?`text-red-400`:`text-bambu-gray`}`,children:[_5(e.expires_at),a&&(0,K.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs bg-red-500/20 text-red-300 rounded`,children:i(`cameraTokens.list.expired`,`Expired`)})]}),(0,K.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:_5(e.last_used_at)}),(0,K.jsx)(`td`,{className:`py-3 px-3 text-right`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>r(e.id),className:`inline-flex items-center gap-1 px-2 py-1 text-sm text-red-400 hover:text-red-300`,title:i(`cameraTokens.list.revoke`,`Revoke`),children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),i(`cameraTokens.list.revoke`,`Revoke`)]})})]})}function v5({tokens:e,showOwner:t,userIdToName:n,onRevoke:r,emptyMessage:i}){let{t:a}=G();return e.length===0?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:i}):(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`text-bambu-gray text-left border-b border-bambu-dark-tertiary`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.name`,`Name`)}),t&&(0,K.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.owner`,`Owner`)}),(0,K.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.prefix`,`Prefix`)}),(0,K.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.created`,`Created`)}),(0,K.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.expires`,`Expires`)}),(0,K.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.lastUsed`,`Last used`)}),(0,K.jsx)(`th`,{className:`py-2 px-3`})]})}),(0,K.jsx)(`tbody`,{children:e.map(e=>(0,K.jsx)(SRe,{token:e,showOwner:t,ownerLabel:n?.get(e.user_id)??`#${e.user_id}`,onRevoke:r},e.id))})]})})}function CRe(){let{t:e}=G(),{user:t,isAdmin:n}=sd(),{showToast:r}=xd(),[i,a]=(0,y.useState)([]),[o,s]=(0,y.useState)([]),[c,l]=(0,y.useState)(new Map),[u,d]=(0,y.useState)(!0),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null),g=async()=>{d(!0);try{if(a(await Q.listMyLongLivedCameraTokens()),n){s(await Q.listAllLongLivedCameraTokens());try{let e=await Q.getUsers();l(new Map(e.map(e=>[e.id,e.username])))}catch{l(new Map)}}}catch(t){r(t instanceof Error?t.message:e(`cameraTokens.toast.loadFailed`,`Failed to load tokens`),`error`)}finally{d(!1)}};(0,y.useEffect)(()=>{g()},[n]);let _=async e=>{let t=[...i,...o].find(t=>t.id===e);t&&h(t)},v=async()=>{if(!m)return;let t=m.id;h(null);try{await Q.revokeLongLivedCameraToken(t),r(e(`cameraTokens.toast.revoked`,`Token revoked`)),await g()}catch(t){r(t instanceof Error?t.message:e(`cameraTokens.toast.revokeFailed`,`Failed to revoke token`),`error`)}},b=(0,y.useMemo)(()=>o.filter(e=>e.user_id!==t?.id),[o,t?.id]);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`cameraTokens.description`,`Long-lived tokens for embedding the camera stream into Home Assistant, Frigate, kiosks, or any other tool that needs a stable URL. Each token is camera-stream-only and can be revoked at any time.`)}),(0,K.jsx)(yRe,{onCreated:e=>{p(e),g()}}),(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:e(`cameraTokens.list.myTitle`,`My tokens`)}),u?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`cameraTokens.loading`,`Loading…`)}):(0,K.jsx)(v5,{tokens:i,onRevoke:_,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),n&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:e(`cameraTokens.list.allTitle`,`All users (admin view)`)}),(0,K.jsx)(v5,{tokens:b,showOwner:!0,userIdToName:c,onRevoke:_,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),f&&(0,K.jsx)(xRe,{token:f,onClose:()=>p(null)}),m&&(0,K.jsx)(bRe,{token:m,onConfirm:()=>void v(),onCancel:()=>h(null)})]})}function wRe({plug:e,onEdit:t}){let{t:n}=G(),r=Qa(),{showToast:i}=xd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),{data:p,isLoading:m}=q({queryKey:[`smart-plug-status`,e.id],queryFn:()=>Q.getSmartPlugStatus(e.id),refetchInterval:3e4}),{data:h}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),g=h?.find(t=>t.id===e.printer_id),_=J({mutationFn:t=>Q.controlSmartPlug(e.id,t),onMutate:async t=>{await r.cancelQueries({queryKey:[`smart-plug-status`,e.id]});let n=r.getQueryData([`smart-plug-status`,e.id]),i=t===`on`?`ON`:t===`off`||p?.state===`ON`?`OFF`:`ON`;return r.setQueryData([`smart-plug-status`,e.id],e=>({...e,state:i})),{previousStatus:n}},onError:(t,a,o)=>{o?.previousStatus&&r.setQueryData([`smart-plug-status`,e.id],o.previousStatus),i(n(`smartPlugs.failedToTurn`,{action:a,name:e.name}),`error`)},onSettled:()=>{setTimeout(()=>{r.invalidateQueries({queryKey:[`smart-plug-status`,e.id]}),r.invalidateQueries({queryKey:[`smart-plugs`]})},1e3)}}),v=J({mutationFn:t=>Q.updateSmartPlug(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),e.printer_id&&(r.invalidateQueries({queryKey:[`smartPlugByPrinter`,e.printer_id]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`,e.printer_id]}))}}),b=J({mutationFn:()=>Q.deleteSmartPlug(e.id),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),e.printer_id&&r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`,e.printer_id]})}}),x=p?.state===`ON`,S=e.plug_type===`mqtt`&&p?.energy?.power!==null&&p?.energy?.power!==void 0,C=(p?.reachable??!1)||S,w=_.isPending,T=(()=>{if(e.plug_type!==`tasmota`||!e.ip_address)return null;let t=e.ip_address;return e.username&&e.password?`http://${encodeURIComponent(e.username)}:${encodeURIComponent(e.password)}@${t}/`:`http://${t}/`})();return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(pd,{className:`relative`,children:(0,K.jsxs)(hd,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-2 mb-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg flex-shrink-0 ${e.plug_type===`mqtt`?C?`bg-teal-500/20`:`bg-red-500/20`:C?x?`bg-bambu-green/20`:`bg-bambu-dark`:`bg-red-500/20`}`,children:e.plug_type===`mqtt`?(0,K.jsx)(Sl,{className:`w-5 h-5 ${C?`text-teal-400`:`text-red-400`}`}):e.plug_type===`homeassistant`?(0,K.jsx)(Tc,{className:`w-5 h-5 ${C?x?`text-bambu-green`:`text-bambu-gray`:`text-red-400`}`}):e.plug_type===`rest`?(0,K.jsx)(hc,{className:`w-5 h-5 ${C?x?`text-bambu-green`:`text-bambu-gray`:`text-red-400`}`}):(0,K.jsx)(gl,{className:`w-5 h-5 ${C?x?`text-bambu-green`:`text-bambu-gray`:`text-red-400`}`})}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`h3`,{className:`font-medium text-white truncate`,children:e.name}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray truncate`,title:e.plug_type===`mqtt`?e.mqtt_topic??void 0:e.plug_type===`homeassistant`?e.ha_entity_id??void 0:e.plug_type===`rest`?e.rest_on_url??e.rest_off_url??void 0:e.ip_address??void 0,children:e.plug_type===`mqtt`?e.mqtt_topic:e.plug_type===`homeassistant`?e.ha_entity_id:e.plug_type===`rest`?e.rest_on_url||e.rest_off_url:e.ip_address})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-col items-end gap-1 flex-shrink-0`,children:[m?(0,K.jsx)(X,{className:`w-4 h-4 text-bambu-gray animate-spin`}):e.plug_type===`mqtt`?(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm whitespace-nowrap`,children:[(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-teal-500/20 text-teal-400 text-[10px] font-medium rounded flex-shrink-0`,children:`MQTT`}),C&&(0,K.jsx)(`span`,{className:`text-status-ok`,children:`✓`})]}):e.plug_type===`homeassistant`?(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,K.jsx)(`span`,{className:`px-1 py-0.5 bg-blue-500/20 text-blue-400 text-[10px] font-medium rounded`,children:`HA`}),(0,K.jsx)(`span`,{className:C?x?`text-status-ok`:`text-bambu-gray`:`text-status-error`,children:C?p?.state||`?`:n(`smartPlugs.offline`)})]}):e.plug_type===`rest`?(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,K.jsx)(`span`,{className:`px-1 py-0.5 bg-purple-500/20 text-purple-400 text-[10px] font-medium rounded`,children:`REST`}),(0,K.jsx)(`span`,{className:C?x?`text-status-ok`:`text-bambu-gray`:`text-status-error`,children:C?p?.state||`?`:n(`smartPlugs.offline`)})]}):C?(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,K.jsx)(ju,{className:`w-4 h-4 text-status-ok`}),(0,K.jsx)(`span`,{className:x?`text-status-ok`:`text-bambu-gray`,children:p?.state||n(`smartPlugs.unknown`)})]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-sm text-status-error`,children:[(0,K.jsx)(Au,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:n(`smartPlugs.offline`)})]}),T&&(0,K.jsxs)(`a`,{href:T,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 px-2 py-0.5 bg-bambu-dark hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white text-xs rounded-full transition-colors`,title:n(`smartPlugs.openPlugAdminPage`),children:[(0,K.jsx)(Us,{className:`w-3 h-3`}),n(`smartPlugs.admin`)]})]})]}),g&&(0,K.jsxs)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[n(`smartPlugs.linkedTo`),` `]}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:g.name})]}),(e.power_alert_enabled||e.schedule_enabled||e.plug_type===`mqtt`)&&(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[e.plug_type===`mqtt`&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-teal-500/20 text-teal-400 text-xs rounded-full`,children:[(0,K.jsx)(Gs,{className:`w-3 h-3`}),n(`smartPlugs.monitorOnly`)]}),e.power_alert_enabled&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded-full`,children:[(0,K.jsx)(Io,{className:`w-3 h-3`}),n(`smartPlugs.alerts`)]}),e.schedule_enabled&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded-full`,children:[(0,K.jsx)(qo,{className:`w-3 h-3`}),e.schedule_on_time&&e.schedule_off_time?`${e.schedule_on_time} - ${e.schedule_off_time}`:e.schedule_on_time?n(`smartPlugs.scheduleOn`,{time:e.schedule_on_time}):n(`smartPlugs.scheduleOff`,{time:e.schedule_off_time})]})]}),e.plug_type!==`mqtt`&&(0,K.jsxs)(`div`,{className:`flex gap-2 mb-3`,children:[(0,K.jsxs)($,{size:`sm`,variant:x?`primary`:`secondary`,disabled:!C||w,onClick:()=>c(!0),className:`flex-1`,children:[w?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(yl,{className:`w-4 h-4`}),n(`smartPlugs.on`)]}),(0,K.jsxs)($,{size:`sm`,variant:x?`secondary`:`primary`,disabled:!C||w,onClick:()=>u(!0),className:`flex-1`,children:[w?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(vl,{className:`w-4 h-4`}),n(`smartPlugs.off`)]})]}),e.plug_type===`mqtt`&&p?.energy&&(0,K.jsxs)(`div`,{className:`flex gap-2 mb-3 px-3 py-2 bg-bambu-dark rounded-lg`,children:[p.energy.power!==null&&p.energy.power!==void 0&&(0,K.jsxs)(`div`,{className:`flex-1 text-center`,children:[(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Math.round(p.energy.power),`W`]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.power`)})]}),p.energy.today!==null&&p.energy.today!==void 0&&(0,K.jsxs)(`div`,{className:`flex-1 text-center border-l border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:p.energy.today.toFixed(3)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.kwhToday`)})]})]}),(0,K.jsxs)(`button`,{onClick:()=>f(!d),className:`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Ll,{className:`w-4 h-4`}),e.plug_type===`mqtt`?n(`smartPlugs.settings`):n(`smartPlugs.automationSettings`)]}),(0,K.jsx)(`span`,{children:d?`-`:`+`})]}),d&&(0,K.jsxs)(`div`,{className:`pt-3 border-t border-bambu-dark-tertiary space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Pc,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.showInSwitchbar`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.quickAccessSidebar`)})]})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.show_in_switchbar,onChange:e=>v.mutate({show_in_switchbar:e.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.plug_type!==`mqtt`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.enabled`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.enableAutomation`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>v.mutate({enabled:e.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOn`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOnDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.auto_on,onChange:e=>v.mutate({auto_on:e.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOff`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.auto_off,onChange:e=>v.mutate({auto_off:e.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOffPersistent`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffPersistentDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.auto_off_persistent,onChange:e=>v.mutate({auto_off_persistent:e.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off&&(0,K.jsxs)(`div`,{className:`space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white mb-2`,children:n(`smartPlugs.turnOffDelayMode`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`button`,{onClick:()=>v.mutate({off_delay_mode:`time`}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${e.off_delay_mode===`time`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(_s,{className:`w-4 h-4`}),n(`smartPlugs.time`)]}),(0,K.jsxs)(`button`,{onClick:()=>v.mutate({off_delay_mode:`temperature`}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${e.off_delay_mode===`temperature`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(pu,{className:`w-4 h-4`}),n(`smartPlugs.temp`)]})]})]}),e.off_delay_mode===`time`?(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.delayMinutes`)}),(0,K.jsx)(`input`,{type:`number`,min:`1`,max:`60`,value:e.off_delay_minutes,onChange:e=>v.mutate({off_delay_minutes:parseInt(e.target.value)||5}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}):(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.tempThreshold`)}),(0,K.jsx)(`input`,{type:`number`,min:`30`,max:`100`,value:e.off_temp_threshold,onChange:e=>v.mutate({off_temp_threshold:parseInt(e.target.value)||70}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`smartPlugs.tempThresholdDescription`)})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOffAfterDrying`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffAfterDryingDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.auto_off_after_drying,onChange:e=>v.mutate({auto_off_after_drying:e.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off_after_drying&&(0,K.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.delayAfterDryingMinutes`)}),(0,K.jsx)(`input`,{type:`number`,min:`0`,max:`120`,value:e.off_delay_after_drying_minutes,onChange:e=>v.mutate({off_delay_after_drying_minutes:parseInt(e.target.value)||10}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>t(e),className:`flex-1`,children:[(0,K.jsx)(fl,{className:`w-4 h-4`}),n(`smartPlugs.edit`)]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>o(!0),className:`text-red-400 hover:text-red-300`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]})]})}),a&&(0,K.jsx)(Ed,{title:n(`smartPlugs.deleteSmartPlug`),message:n(`smartPlugs.deleteConfirm`,{name:e.name}),confirmText:n(`smartPlugs.delete`),variant:`danger`,onConfirm:()=>{b.mutate(),o(!1)},onCancel:()=>o(!1)}),s&&(0,K.jsx)(Ed,{title:n(`smartPlugs.turnOnSmartPlug`),message:n(`smartPlugs.turnOnConfirm`,{name:e.name}),confirmText:n(`smartPlugs.turnOn`),variant:`default`,onConfirm:()=>{_.mutate(`on`),c(!1)},onCancel:()=>c(!1)}),l&&(0,K.jsx)(Ed,{title:n(`smartPlugs.turnOffSmartPlug`),message:n(`smartPlugs.turnOffConfirm`,{name:e.name}),confirmText:n(`smartPlugs.turnOff`),variant:`danger`,onConfirm:()=>{_.mutate(`off`),u(!1)},onCancel:()=>u(!1)})]})}function TRe({plug:e,onClose:t}){let{t:n}=G(),r=Qa(),i=!!e,[a,o]=(0,y.useState)(e?.plug_type||`tasmota`),[s,c]=(0,y.useState)(e?.name||``),[l,u]=(0,y.useState)(e?.ip_address||``),[d,f]=(0,y.useState)(e?.username||``),[p,m]=(0,y.useState)(e?.password||``),[h,g]=(0,y.useState)(e?.ha_entity_id||``),[_,v]=(0,y.useState)(e?.mqtt_power_topic||e?.mqtt_topic||``),[b,x]=(0,y.useState)(e?.mqtt_power_path||``),[S,C]=(0,y.useState)((e?.mqtt_power_multiplier??e?.mqtt_multiplier??1).toString()),[w,T]=(0,y.useState)(e?.mqtt_energy_topic||``),[E,D]=(0,y.useState)(e?.mqtt_energy_path||``),[O,k]=(0,y.useState)((e?.mqtt_energy_multiplier??1).toString()),[A,j]=(0,y.useState)(e?.mqtt_state_topic||``),[M,N]=(0,y.useState)(e?.mqtt_state_path||``),[P,F]=(0,y.useState)(e?.mqtt_state_on_value||``),[I,L]=(0,y.useState)(e?.rest_on_url||``),[R,z]=(0,y.useState)(e?.rest_on_body||``),[B,V]=(0,y.useState)(e?.rest_off_url||``),[ee,H]=(0,y.useState)(e?.rest_off_body||``),[te,ne]=(0,y.useState)(e?.rest_method||`POST`),[re,U]=(0,y.useState)(e?.rest_headers||``),[ie,ae]=(0,y.useState)(e?.rest_status_url||``),[W,oe]=(0,y.useState)(e?.rest_status_path||``),[se,ce]=(0,y.useState)(e?.rest_status_on_value||``),[le,ue]=(0,y.useState)(e?.rest_power_url||``),[de,fe]=(0,y.useState)(e?.rest_power_path||``),[pe,me]=(0,y.useState)((e?.rest_power_multiplier??1).toString()),[he,ge]=(0,y.useState)(e?.rest_energy_url||``),[_e,ve]=(0,y.useState)(e?.rest_energy_path||``),[ye,be]=(0,y.useState)((e?.rest_energy_multiplier??1).toString()),[xe,Se]=(0,y.useState)(e?.ha_power_entity||``),[Ce,we]=(0,y.useState)(e?.ha_energy_today_entity||``),[Te,Ee]=(0,y.useState)(e?.ha_energy_total_entity||``),[De,Oe]=(0,y.useState)(``),[ke,Ae]=(0,y.useState)(``),[je,Me]=(0,y.useState)(!1),Ne=(0,y.useRef)(null),[Pe,Fe]=(0,y.useState)(``),[Ie,Le]=(0,y.useState)(!1),Re=(0,y.useRef)(null),[ze,Be]=(0,y.useState)(``),[Ve,He]=(0,y.useState)(!1),Ue=(0,y.useRef)(null),[We,Ge]=(0,y.useState)(``),[Ke,qe]=(0,y.useState)(!1),Je=(0,y.useRef)(null),[Ye,Xe]=(0,y.useState)(e?.printer_id||null),[Ze,Qe]=(0,y.useState)(null),[$e,et]=(0,y.useState)(null),[tt,nt]=(0,y.useState)(e?.power_alert_enabled||!1),[rt,it]=(0,y.useState)(e?.power_alert_high?.toString()||``),[at,ot]=(0,y.useState)(e?.power_alert_low?.toString()||``),[st,ct]=(0,y.useState)(e?.schedule_enabled||!1),[lt,ut]=(0,y.useState)(e?.schedule_on_time||``),[dt,ft]=(0,y.useState)(e?.schedule_off_time||``),[pt,mt]=(0,y.useState)(e?.show_in_switchbar||!1),[ht,gt]=(0,y.useState)(e?.show_on_printer_card??!0),[_t,vt]=(0,y.useState)(!1),[yt,bt]=(0,y.useState)({scanned:0,total:0}),[xt,St]=(0,y.useState)([]),Ct=(0,y.useRef)(null),{data:wt}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:Tt}=q({queryKey:[`smart-plugs`],queryFn:Q.getSmartPlugs}),{data:Et}=q({queryKey:[`settings`],queryFn:Q.getSettings}),Dt=!!(Et?.ha_enabled&&Et?.ha_url&&Et?.ha_token);(0,y.useEffect)(()=>{let e=setTimeout(()=>{Ae(De)},300);return()=>clearTimeout(e)},[De]),(0,y.useEffect)(()=>{let e=e=>{Ne.current&&!Ne.current.contains(e.target)&&Me(!1),Re.current&&!Re.current.contains(e.target)&&Le(!1),Ue.current&&!Ue.current.contains(e.target)&&He(!1),Je.current&&!Je.current.contains(e.target)&&qe(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let{data:Ot,isLoading:kt,error:At}=q({queryKey:[`ha-entities`,ke],queryFn:()=>Q.getHAEntities(ke||void 0),enabled:a===`homeassistant`&&Dt,retry:!1,staleTime:0}),{data:jt}=q({queryKey:[`ha-sensor-entities`],queryFn:Q.getHASensorEntities,enabled:a===`homeassistant`&&Dt,retry:!1,staleTime:0});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e),Ct.current&&clearInterval(Ct.current)}},[t]);let Mt=async()=>{vt(!0),St([]),bt({scanned:0,total:0}),et(null);try{await Q.startTasmotaScan();let e=async()=>{try{let e=await Q.getTasmotaScanStatus();bt({scanned:e.scanned,total:e.total}),St(await Q.getDiscoveredTasmotaDevices()),e.running||(vt(!1),Ct.current&&=(clearInterval(Ct.current),null))}catch(e){console.error(`Polling error:`,e)}};await e(),Ct.current=setInterval(e,500)}catch(e){vt(!1),et((e instanceof Error?e.message:typeof e==`string`?e:JSON.stringify(e))||n(`smartPlugs.failedToStartScan`))}},Nt=async()=>{try{await Q.stopTasmotaScan()}catch{}vt(!1),Ct.current&&=(clearInterval(Ct.current),null)},Pt=e=>{u(e.ip_address),c(e.name),Qe(null)},Ft=J({mutationFn:()=>Q.testSmartPlugConnection(l,d||null,p||null),onSuccess:e=>{Qe(e),et(null),!s&&e.device_name&&c(e.device_name)},onError:e=>{Qe(null),et(e.message)}}),It=J({mutationFn:e=>Q.createSmartPlug(e),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{et(e.message)}}),Lt=J({mutationFn:t=>Q.updateSmartPlug(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{et(e.message)}}),Rt=wt?.filter(t=>a===`tasmota`?!Tt?.some(n=>n.printer_id===t.id&&n.id!==e?.id&&n.plug_type===`tasmota`):!0),zt=e=>{if(e.preventDefault(),et(null),!s.trim()){et(n(`smartPlugs.nameRequired`));return}if(a===`tasmota`&&!l.trim()){et(`IP address is required for Tasmota plugs`);return}if(a===`homeassistant`&&!h){et(n(`smartPlugs.entityRequired`));return}if(a===`mqtt`){let e=_.trim(),t=w.trim(),r=A.trim();if(!e&&!t&&!r){et(n(`smartPlugs.mqttTopicRequired`));return}}if(a===`rest`&&!I.trim()&&!B.trim()){et(n(`smartPlugs.restUrlRequired`));return}let t={name:s.trim(),plug_type:a,ip_address:a===`tasmota`?l.trim():null,ha_entity_id:a===`homeassistant`?h:null,ha_power_entity:a===`homeassistant`&&xe||null,ha_energy_today_entity:a===`homeassistant`&&Ce||null,ha_energy_total_entity:a===`homeassistant`&&Te||null,mqtt_power_topic:a===`mqtt`&&_.trim()||null,mqtt_power_path:a===`mqtt`&&b.trim()||null,mqtt_power_multiplier:a===`mqtt`&&parseFloat(S)||1,mqtt_energy_topic:a===`mqtt`&&w.trim()||null,mqtt_energy_path:a===`mqtt`&&E.trim()||null,mqtt_energy_multiplier:a===`mqtt`&&parseFloat(O)||1,mqtt_state_topic:a===`mqtt`&&A.trim()||null,mqtt_state_path:a===`mqtt`&&M.trim()||null,mqtt_state_on_value:a===`mqtt`&&P.trim()||null,rest_on_url:a===`rest`&&I.trim()||null,rest_on_body:a===`rest`&&R.trim()||null,rest_off_url:a===`rest`&&B.trim()||null,rest_off_body:a===`rest`&&ee.trim()||null,rest_method:a===`rest`?te:null,rest_headers:a===`rest`&&re.trim()||null,rest_status_url:a===`rest`&&ie.trim()||null,rest_status_path:a===`rest`&&W.trim()||null,rest_status_on_value:a===`rest`&&se.trim()||null,rest_power_url:a===`rest`&&le.trim()||null,rest_power_path:a===`rest`&&de.trim()||null,rest_power_multiplier:a===`rest`&&parseFloat(pe)||1,rest_energy_url:a===`rest`&&he.trim()||null,rest_energy_path:a===`rest`&&_e.trim()||null,rest_energy_multiplier:a===`rest`&&parseFloat(ye)||1,username:a===`tasmota`&&d.trim()||null,password:a===`tasmota`&&p.trim()||null,printer_id:Ye,power_alert_enabled:tt,power_alert_high:rt?parseFloat(rt):null,power_alert_low:at?parseFloat(at):null,schedule_enabled:st,schedule_on_time:lt||null,schedule_off_time:dt||null,show_in_switchbar:pt,show_on_printer_card:ht};i?Lt.mutate(t):It.mutate(t)},Bt=It.isPending||Lt.isPending;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 flex-shrink-0`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(i?`smartPlugs.editTitle`:`smartPlugs.addTitle`)}),(0,K.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`form`,{onSubmit:zt,className:`p-6 space-y-4 overflow-y-auto`,children:[$e&&(0,K.jsx)(`div`,{className:`p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400`,children:$e}),!i&&(0,K.jsxs)(`div`,{className:`flex gap-2 mb-2`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{o(`tasmota`),Qe(null),et(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`tasmota`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,K.jsx)(gl,{className:`w-4 h-4`}),`Tasmota`]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{o(`homeassistant`),Qe(null),et(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`homeassistant`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,K.jsx)(Tc,{className:`w-4 h-4`}),`HA`]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{o(`mqtt`),Qe(null),et(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`mqtt`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,K.jsx)(Sl,{className:`w-4 h-4`}),`MQTT`]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{o(`rest`),Qe(null),et(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`rest`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,K.jsx)(hc,{className:`w-4 h-4`}),`REST`]})]}),!i&&a===`tasmota`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[_t?(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:Nt,className:`w-full`,children:[(0,K.jsx)(Pu,{className:`w-4 h-4`}),n(`smartPlugs.stopScanning`)]}):(0,K.jsxs)($,{type:`button`,variant:`primary`,onClick:Mt,className:`w-full`,children:[(0,K.jsx)(Nl,{className:`w-4 h-4`}),n(`smartPlugs.discoverTasmota`)]}),_t&&yt.total>0&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:n(`smartPlugs.addSmartPlug.scanningNetwork`)}),(0,K.jsxs)(`span`,{children:[yt.scanned,` / `,yt.total]})]}),(0,K.jsx)(`div`,{className:`w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,K.jsx)(`div`,{className:`bg-bambu-green h-2 rounded-full transition-all duration-300`,style:{width:`${yt.scanned/yt.total*100}%`}})})]}),xt.length>0&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.foundDevices`,{count:xt.length})}),(0,K.jsx)(`div`,{className:`max-h-40 overflow-y-auto space-y-1`,children:xt.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>Pt(e),className:`w-full flex items-center justify-between p-2 bg-bambu-dark hover:bg-bambu-dark-tertiary rounded-lg transition-colors text-left border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(gl,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.ip_address})]})]}),e.state&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-xs ${e.state===`ON`?`text-bambu-green`:`text-bambu-gray`}`,children:[(0,K.jsx)(yl,{className:`w-3 h-3`}),e.state]})]},e.ip_address))})]}),!_t&&xt.length===0&&yt.total>0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray text-center py-2`,children:n(`smartPlugs.noDevicesFound`)})]}),a===`homeassistant`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[!Dt&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400`,children:[n(`smartPlugs.haNotConfigured`),` `,(0,K.jsx)(`span`,{className:`font-medium`,children:n(`smartPlugs.haSettingsPath`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 opacity-50`,children:n(`smartPlugs.selectEntity`)}),(0,K.jsx)(`select`,{disabled:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed opacity-50`,children:(0,K.jsx)(`option`,{children:n(`smartPlugs.addSmartPlug.chooseEntity`)})})]})]}),Dt&&(0,K.jsxs)(K.Fragment,{children:[kt&&(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-4 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-5 h-5 animate-spin mr-2`}),n(`smartPlugs.loadingEntities`)]}),At&&(0,K.jsx)(`div`,{className:`p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400`,children:n(`smartPlugs.failedToLoadEntities`,{error:At.message})}),(()=>{let t=Tt?.filter(t=>t.ha_entity_id&&t.id!==e?.id).map(e=>e.ha_entity_id)||[],r=(Ot||[]).filter(e=>!t.includes(e.entity_id)),i=Ot?.find(e=>e.entity_id===h);return(0,K.jsxs)(`div`,{ref:Ne,className:`relative`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.selectEntity`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{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:je?De:i?`${i.friendly_name} (${i.entity_id})`:``,onChange:e=>{Oe(e.target.value),je||Me(!0)},onFocus:()=>{Me(!0),Oe(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEntities`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),h&&!je&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{g(``),Oe(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,K.jsx)(Pu,{className:`w-4 h-4 text-bambu-gray hover:text-white`})}),kt&&(0,K.jsx)(X,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin`})]}),je&&(0,K.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-60 overflow-y-auto`,children:[kt&&(0,K.jsxs)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray flex items-center gap-2`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),n(`smartPlugs.loading`)]}),!kt&&r.length===0&&(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:ke?n(`smartPlugs.noEntitiesMatching`,{search:ke}):n(`smartPlugs.noEntitiesAvailable`)}),!kt&&r.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{g(e.entity_id),Me(!1),Oe(``),s||c(e.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${e.entity_id===h?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center justify-between`,children:[(0,K.jsx)(`span`,{children:e.entity_id}),(0,K.jsx)(`span`,{className:e.state===`on`?`text-bambu-green`:``,children:e.state})]})]},e.entity_id))]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(ke?`smartPlugs.searchingEntities`:`smartPlugs.showingEntities`,{count:r.length})})]})})(),h&&jt&&jt.length>0&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium mb-1`,children:n(`smartPlugs.energyMonitoringOptional`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:n(`smartPlugs.energyMonitoringHint`)})]}),(()=>{let e=jt.filter(e=>e.unit_of_measurement===`W`||e.unit_of_measurement===`kW`||e.unit_of_measurement===`mW`),t=Pe?e.filter(e=>e.entity_id.toLowerCase().includes(Pe.toLowerCase())||e.friendly_name.toLowerCase().includes(Pe.toLowerCase())):e,r=jt.find(e=>e.entity_id===xe);return(0,K.jsxs)(`div`,{ref:Re,className:`relative`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.powerSensorW`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{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:Ie?Pe:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Fe(e.target.value),Ie||Le(!0)},onFocus:()=>{Le(!0),Fe(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchPowerSensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),xe&&!Ie&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{Se(``),Fe(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,K.jsx)(Pu,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),Ie&&(0,K.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{Se(``),Le(!1),Fe(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{Se(e.entity_id),Le(!1),Fe(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===xe?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})(),(()=>{let e=jt.filter(e=>e.unit_of_measurement===`kWh`||e.unit_of_measurement===`Wh`||e.unit_of_measurement===`MWh`),t=ze?e.filter(e=>e.entity_id.toLowerCase().includes(ze.toLowerCase())||e.friendly_name.toLowerCase().includes(ze.toLowerCase())):e,r=jt.find(e=>e.entity_id===Ce);return(0,K.jsxs)(`div`,{ref:Ue,className:`relative`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.energyTodayKwh`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{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:Ve?ze:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Be(e.target.value),Ve||He(!0)},onFocus:()=>{He(!0),Be(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEnergySensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),Ce&&!Ve&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{we(``),Be(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,K.jsx)(Pu,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),Ve&&(0,K.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{we(``),He(!1),Be(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{we(e.entity_id),He(!1),Be(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===Ce?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})(),(()=>{let e=jt.filter(e=>e.unit_of_measurement===`kWh`||e.unit_of_measurement===`Wh`||e.unit_of_measurement===`MWh`),t=We?e.filter(e=>e.entity_id.toLowerCase().includes(We.toLowerCase())||e.friendly_name.toLowerCase().includes(We.toLowerCase())):e,r=jt.find(e=>e.entity_id===Te);return(0,K.jsxs)(`div`,{ref:Je,className:`relative`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.totalEnergyKwh`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{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:Ke?We:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Ge(e.target.value),Ke||qe(!0)},onFocus:()=>{qe(!0),Ge(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEnergySensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),Te&&!Ke&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{Ee(``),Ge(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,K.jsx)(Pu,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),Ke&&(0,K.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{Ee(``),qe(!1),Ge(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{Ee(e.entity_id),qe(!1),Ge(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===Te?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})()]})]})]}),a===`mqtt`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[!Et?.mqtt_broker&&(0,K.jsxs)(`div`,{className:`p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400`,children:[n(`smartPlugs.mqttNotConfigured`),` `,(0,K.jsx)(`span`,{className:`font-medium`,children:n(`smartPlugs.mqttSettingsPath`)}),` `,n(`smartPlugs.mqttNotConfiguredSuffix`)]}),Et?.mqtt_broker&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg text-sm text-blue-300`,children:[(0,K.jsx)(`p`,{className:`font-medium mb-1`,children:n(`smartPlugs.monitorOnly`)}),(0,K.jsx)(`p`,{className:`text-xs opacity-80`,children:n(`smartPlugs.mqttMonitorOnlyDescription`)})]}),(0,K.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium text-sm`,children:n(`smartPlugs.powerMonitoring`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,K.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:`zigbee2mqtt/shelly-working-room`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,K.jsx)(`input`,{type:`text`,value:b,onChange:e=>x(e.target.value),placeholder:`power_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.multiplier`)}),(0,K.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttPowerHint`)})]}),(0,K.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.energyMonitoring`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,K.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:`Same as power topic, or different`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,K.jsx)(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),placeholder:`energy_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.multiplier`)}),(0,K.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttEnergyHint`)})]}),(0,K.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.stateMonitoring`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,K.jsx)(`input`,{type:`text`,value:A,onChange:e=>j(e.target.value),placeholder:`Same as power topic, or different`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,K.jsx)(`input`,{type:`text`,value:M,onChange:e=>N(e.target.value),placeholder:`state_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.onValue`)}),(0,K.jsx)(`input`,{type:`text`,value:P,onChange:e=>F(e.target.value),placeholder:n(`smartPlugs.addSmartPlug.placeholders.mqttStateOnValue`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttStateHint`)})]})]})]}),a===`rest`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium text-sm`,children:n(`smartPlugs.restControl`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restMethod`)}),(0,K.jsxs)(`select`,{value:te,onChange:e=>ne(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`GET`,children:`GET`}),(0,K.jsx)(`option`,{value:`POST`,children:`POST`}),(0,K.jsx)(`option`,{value:`PUT`,children:`PUT`}),(0,K.jsx)(`option`,{value:`PATCH`,children:`PATCH`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restOnUrl`)}),(0,K.jsx)(`input`,{type:`text`,value:I,onChange:e=>{L(e.target.value),Qe(null)},placeholder:`http://openhab:8080/rest/items/MyPlug`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restOnBody`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),placeholder:n(`smartPlugs.restBodyHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restOffUrl`)}),(0,K.jsx)(`input`,{type:`text`,value:B,onChange:e=>{V(e.target.value),Qe(null)},placeholder:`http://openhab:8080/rest/items/MyPlug`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restOffBody`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsx)(`input`,{type:`text`,value:ee,onChange:e=>H(e.target.value),placeholder:n(`smartPlugs.restBodyHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.restHeaders`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsx)(`div`,{children:(0,K.jsx)(`textarea`,{value:re,onChange:e=>U(e.target.value),placeholder:n(`smartPlugs.restHeadersHint`),rows:2,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none font-mono text-sm`})})]}),(0,K.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.stateMonitoring`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusUrl`)}),(0,K.jsx)(`input`,{type:`text`,value:ie,onChange:e=>ae(e.target.value),placeholder:n(`smartPlugs.restStatusHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusPath`)}),(0,K.jsx)(`input`,{type:`text`,value:W,onChange:e=>oe(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusOnValue`)}),(0,K.jsx)(`input`,{type:`text`,value:se,onChange:e=>ce(e.target.value),placeholder:`ON`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.energyMonitoring`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restPowerUrl`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsx)(`input`,{type:`text`,value:le,onChange:e=>ue(e.target.value),placeholder:n(`smartPlugs.restPowerUrlHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restPowerPath`)}),(0,K.jsx)(`input`,{type:`text`,value:de,onChange:e=>fe(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restPowerMultiplier`)}),(0,K.jsx)(`input`,{type:`text`,value:pe,onChange:e=>me(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restEnergyUrl`),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,K.jsx)(`input`,{type:`text`,value:he,onChange:e=>ge(e.target.value),placeholder:n(`smartPlugs.restEnergyUrlHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyPath`)}),(0,K.jsx)(`input`,{type:`text`,value:_e,onChange:e=>ve(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyMultiplier`)}),(0,K.jsx)(`input`,{type:`text`,value:ye,onChange:e=>be(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.restEnergyHint`)})]}),(I.trim()||B.trim())&&(0,K.jsx)(`div`,{className:`flex gap-2`,children:(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:async()=>{Qe(null);try{let e=I.trim()||B.trim(),t=await Q.testRESTConnection(e,te,re.trim()||null);Qe({success:t.success}),t.success||et(t.error||n(`smartPlugs.addSmartPlug.connectionFailed`))}catch{Qe({success:!1}),et(n(`smartPlugs.addSmartPlug.connectionFailed`))}},className:`w-full`,children:[(0,K.jsx)(ju,{className:`w-4 h-4`}),n(`smartPlugs.testConnection`)]})}),Ze&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm ${Ze.success?`text-green-400`:`text-red-400`}`,children:[Ze.success?(0,K.jsx)(ls,{className:`w-4 h-4`}):(0,K.jsx)(Au,{className:`w-4 h-4`}),Ze.success?n(`smartPlugs.connectionSuccess`):n(`smartPlugs.addSmartPlug.connectionFailed`)]})]}),a===`tasmota`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.ipAddress`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:l,onChange:e=>{u(e.target.value),Qe(null)},placeholder:`192.168.1.100`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:()=>Ft.mutate(),disabled:!l.trim()||Ft.isPending,children:[Ft.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(ju,{className:`w-4 h-4`}),n(`smartPlugs.test`)]})]})]}),a===`tasmota`&&Ze&&(0,K.jsx)(`div`,{className:`p-3 rounded-lg flex items-center gap-2 ${Ze.success?`bg-bambu-green/20 border border-bambu-green/50 text-bambu-green`:`bg-red-500/20 border border-red-500/50 text-red-400`}`,children:Ze.success?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ls,{className:`w-5 h-5`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium`,children:n(`smartPlugs.connectedResult`)}),(0,K.jsxs)(`p`,{className:`text-sm opacity-80`,children:[Ze.device_name&&n(`smartPlugs.deviceLabel`,{name:Ze.device_name}),n(`smartPlugs.stateLabel`,{state:Ze.state})]})]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Au,{className:`w-5 h-5`}),(0,K.jsx)(`span`,{children:n(`smartPlugs.addSmartPlug.connectionFailed`)})]})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.nameLabel`)}),(0,K.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:n(`smartPlugs.addSmartPlug.placeholders.plugName`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),a===`tasmota`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.username`)}),(0,K.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`admin`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.password`)}),(0,K.jsx)(`input`,{type:`password`,value:p,onChange:e=>m(e.target.value),placeholder:`********`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray -mt-2`,children:n(`smartPlugs.authHint`)})]}),a!==`mqtt`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.linkToPrinter`)}),(0,K.jsxs)(`select`,{value:Ye??``,onChange:e=>Xe(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:n(`smartPlugs.noPrinter`)}),Rt?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`smartPlugs.linkingDescription`)})]}),(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Io,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.powerAlerts`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:tt,onChange:e=>nt(e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),tt&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.alertAbove`)}),(0,K.jsx)(`input`,{type:`number`,value:rt,onChange:e=>it(e.target.value),placeholder:`e.g. 200`,min:`0`,max:`5000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.alertBelow`)}),(0,K.jsx)(`input`,{type:`number`,value:at,onChange:e=>ot(e.target.value),placeholder:`e.g. 10`,min:`0`,max:`5000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.alertDescription`)})]})]}),a!==`mqtt`&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(_s,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.dailySchedule`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:st,onChange:e=>ct(e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),st&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.turnOnAt`)}),(0,K.jsx)(`input`,{type:`time`,value:lt,onChange:e=>ut(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.turnOffAt`)}),(0,K.jsx)(`input`,{type:`time`,value:dt,onChange:e=>ft(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.scheduleDescription`)})]})]}),(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Pc,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.showInSwitchbar`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.quickAccessSidebar`)})]})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:pt,onChange:e=>mt(e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})}),a===`homeassistant`&&(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Gs,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.showOnPrinterCard`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.displayOnPrinterCard`)})]})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:ht,onChange:e=>gt(e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})}),(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`smartPlugs.cancel`)}),(0,K.jsxs)($,{type:`submit`,disabled:Bt,className:`flex-1`,children:[Bt?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Ol,{className:`w-4 h-4`}),n(i?`smartPlugs.save`:`smartPlugs.add`)]})]})]})]})})}function y5({checked:e,onChange:t,disabled:n}){return(0,K.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":e,disabled:n,onClick:r=>{r.preventDefault(),r.stopPropagation(),n||t(!e)},className:`relative inline-flex w-11 h-7 md:w-9 md:h-5 rounded-full transition-colors flex-shrink-0 focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${n?`bg-bambu-dark-tertiary/50 cursor-not-allowed opacity-50`:e?`bg-bambu-green cursor-pointer`:`bg-bambu-dark-tertiary cursor-pointer hover:bg-bambu-dark-tertiary/80`}`,children:(0,K.jsx)(`span`,{className:`pointer-events-none absolute top-[3px] md:top-[2px] left-[3px] md:left-[2px] w-5 h-5 md:w-4 md:h-4 bg-white rounded-full shadow transition-transform duration-200 ease-in-out ${e?`translate-x-4`:`translate-x-0`}`})})}function ERe({provider:e,onEdit:t}){let{t:n}=G(),r=Qa(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),{data:u}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),d=u?.find(t=>t.id===e.printer_id),f=J({mutationFn:t=>Q.updateNotificationProvider(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]})}}),p=J({mutationFn:()=>Q.deleteNotificationProvider(e.id),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]})}}),m=J({mutationFn:()=>Q.testNotificationProvider(e.id),onSuccess:e=>{l(e),r.invalidateQueries({queryKey:[`notification-providers`]})},onError:e=>{l({success:!1,message:e.message})}}),h=e=>e||``;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(pd,{className:`relative`,children:(0,K.jsxs)(hd,{className:`p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between ${e.enabled?`mb-3`:`mb-0`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${e.enabled?`bg-bambu-green/20`:`bg-bambu-dark`}`,children:(0,K.jsx)(Io,{className:`w-5 h-5 ${e.enabled?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`font-medium text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.providerTypes.${e.provider_type}`,e.provider_type)})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.last_success&&(0,K.jsx)(`span`,{className:`text-xs text-status-ok hidden sm:inline`,children:n(`notifications.lastSuccess`,{date:hf(e.last_success)})}),e.last_error&&e.last_error_at&&(!e.last_success||(mf(e.last_error_at)?.getTime()||0)>(mf(e.last_success)?.getTime()||0))&&(0,K.jsx)(`span`,{className:`text-xs text-status-error`,title:e.last_error,children:n(`notifications.error`)}),(0,K.jsx)(y5,{checked:e.enabled,onChange:e=>f.mutate({enabled:e})})]})]}),e.enabled&&(0,K.jsxs)(K.Fragment,{children:[d&&(0,K.jsxs)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[n(`notifications.printer`),` `]}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:d.name})]}),!d&&!e.printer_id&&(0,K.jsx)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.allPrinters`)})}),(0,K.jsxs)(`div`,{className:`mb-3 flex flex-wrap gap-1`,children:[e.on_print_start&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded`,children:n(`notifications.start`)}),e.on_plate_not_empty&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-600/20 text-rose-300 text-xs rounded`,children:n(`notifications.plateCheck`)}),e.on_print_complete&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded`,children:n(`notifications.complete`)}),e.on_print_failed&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-red-500/20 text-red-400 text-xs rounded`,children:n(`notifications.failed`)}),e.on_print_stopped&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded`,children:n(`notifications.stopped`)}),e.on_print_progress&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded`,children:n(`notifications.progress`)}),e.on_printer_offline&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded`,children:n(`notifications.offline`)}),e.on_printer_error&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-500/20 text-rose-400 text-xs rounded`,children:n(`notifications.error`)}),e.on_filament_low&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-cyan-500/20 text-cyan-400 text-xs rounded`,children:n(`notifications.lowFilament`)}),e.on_maintenance_due&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded`,children:n(`notifications.maintenance`)}),e.on_ams_humidity_high&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-blue-600/20 text-blue-300 text-xs rounded`,children:n(`notifications.amsHumidity`)}),e.on_ams_temperature_high&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-orange-600/20 text-orange-300 text-xs rounded`,children:n(`notifications.amsTemp`)}),e.on_ams_ht_humidity_high&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-cyan-600/20 text-cyan-300 text-xs rounded`,children:n(`notifications.amsHtHumidity`)}),e.on_ams_ht_temperature_high&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-600/20 text-amber-300 text-xs rounded`,children:n(`notifications.amsHtTemp`)}),e.on_bed_cooled&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-teal-500/20 text-teal-400 text-xs rounded`,children:n(`notifications.bedCooled`)}),e.on_first_layer_complete&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-emerald-600/20 text-emerald-300 text-xs rounded`,children:n(`notifications.firstLayer`)}),e.on_print_missing_spool_assignment&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-500/20 text-amber-300 text-xs rounded`,children:n(`notifications.missingSpoolAssignmentLabel`)}),e.on_stock_reorder_alert&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-lime-500/20 text-lime-400 text-xs rounded`,children:n(`notifications.stockReorderAlert`)}),e.on_stock_break_alert&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-red-600/20 text-red-300 text-xs rounded`,children:n(`notifications.stockBreakAlert`)}),e.quiet_hours_enabled&&(0,K.jsxs)(`span`,{className:`px-2 py-0.5 bg-indigo-500/20 text-indigo-400 text-xs rounded flex items-center gap-1`,children:[(0,K.jsx)(nl,{className:`w-3 h-3`}),n(`notifications.quiet`)]}),e.daily_digest_enabled&&(0,K.jsxs)(`span`,{className:`px-2 py-0.5 bg-emerald-500/20 text-emerald-400 text-xs rounded flex items-center gap-1`,children:[(0,K.jsx)(qo,{className:`w-3 h-3`}),n(`notifications.digest`,{time:e.daily_digest_time})]})]}),(0,K.jsx)(`div`,{className:`mb-3`,children:(0,K.jsxs)($,{size:`sm`,variant:`secondary`,disabled:m.isPending,onClick:()=>{l(null),m.mutate()},className:`w-full`,children:[m.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Pl,{className:`w-4 h-4`}),n(`notifications.sendTestNotification`)]})}),c&&(0,K.jsxs)(`div`,{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${c.success?`bg-bambu-green/20 text-bambu-green`:`bg-red-500/20 text-red-400`}`,children:[c.success?(0,K.jsx)(ls,{className:`w-4 h-4`}):(0,K.jsx)(ms,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:c.message})]})]}),(0,K.jsxs)(`button`,{onClick:()=>s(!o),className:`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors ${e.enabled?`border-t border-bambu-dark-tertiary`:`mt-2 border-t border-bambu-dark-tertiary`}`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Ll,{className:`w-4 h-4`}),n(`notifications.eventSettings`)]}),o?(0,K.jsx)(rs,{className:`w-4 h-4`}):(0,K.jsx)(es,{className:`w-4 h-4`})]}),o&&(0,K.jsxs)(`div`,{className:`pt-3 border-t border-bambu-dark-tertiary space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.enabled`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.sendFromProvider`)})]}),(0,K.jsx)(y5,{checked:e.enabled,onChange:e=>f.mutate({enabled:e})})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printEvents`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printStarted`)}),(0,K.jsx)(y5,{checked:e.on_print_start,onChange:e=>f.mutate({on_print_start:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.plateNotEmpty`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.plateNotEmptyDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_plate_not_empty??!0,onChange:e=>f.mutate({on_plate_not_empty:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printCompleted`)}),(0,K.jsx)(y5,{checked:e.on_print_complete,onChange:e=>f.mutate({on_print_complete:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.bedCooledLabel`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.bedCooledDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_bed_cooled??!1,onChange:e=>f.mutate({on_bed_cooled:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.firstLayerCompleteLabel`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.firstLayerCompleteDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_first_layer_complete??!1,onChange:e=>f.mutate({on_first_layer_complete:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.missingSpoolAssignmentLabel`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.missingSpoolAssignmentDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_print_missing_spool_assignment??!1,onChange:e=>f.mutate({on_print_missing_spool_assignment:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printFailed`)}),(0,K.jsx)(y5,{checked:e.on_print_failed,onChange:e=>f.mutate({on_print_failed:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printStopped`)}),(0,K.jsx)(y5,{checked:e.on_print_stopped,onChange:e=>f.mutate({on_print_stopped:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.progressMilestones`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.progressMilestonesDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_print_progress,onChange:e=>f.mutate({on_print_progress:e})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printerStatus`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printerOffline`)}),(0,K.jsx)(y5,{checked:e.on_printer_offline,onChange:e=>f.mutate({on_printer_offline:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printerError`)}),(0,K.jsx)(y5,{checked:e.on_printer_error,onChange:e=>f.mutate({on_printer_error:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.lowFilamentLabel`)}),(0,K.jsx)(y5,{checked:e.on_filament_low,onChange:e=>f.mutate({on_filament_low:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.maintenanceDue`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.maintenanceDueDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_maintenance_due??!1,onChange:e=>f.mutate({on_maintenance_due:e})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.amsAlarms`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHumidityHigh`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHumidityHighDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_ams_humidity_high??!1,onChange:e=>f.mutate({on_ams_humidity_high:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsTemperatureHigh`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsTemperatureHighDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_ams_temperature_high??!1,onChange:e=>f.mutate({on_ams_temperature_high:e})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.amsHtAlarms`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHtHumidityHigh`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHtHumidityHighDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_ams_ht_humidity_high??!1,onChange:e=>f.mutate({on_ams_ht_humidity_high:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHtTemperatureHigh`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHtTemperatureHighDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_ams_ht_temperature_high??!1,onChange:e=>f.mutate({on_ams_ht_temperature_high:e})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.inventoryAlerts`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.stockReorderAlert`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.stockReorderAlertDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_stock_reorder_alert??!1,onChange:e=>f.mutate({on_stock_reorder_alert:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.stockBreakAlert`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.stockBreakAlertDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_stock_break_alert??!1,onChange:e=>f.mutate({on_stock_break_alert:e})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printQueue`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobAdded`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobAddedDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_queue_job_added??!1,onChange:e=>f.mutate({on_queue_job_added:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobAssigned`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobAssignedDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_queue_job_assigned??!1,onChange:e=>f.mutate({on_queue_job_assigned:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobStarted`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobStartedDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_queue_job_started??!1,onChange:e=>f.mutate({on_queue_job_started:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobWaiting`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobWaitingDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_queue_job_waiting??!0,onChange:e=>f.mutate({on_queue_job_waiting:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobSkipped`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobSkippedDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_queue_job_skipped??!0,onChange:e=>f.mutate({on_queue_job_skipped:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobFailed`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobFailedDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_queue_job_failed??!0,onChange:e=>f.mutate({on_queue_job_failed:e})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.queueComplete`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.queueCompleteDescription`)})]}),(0,K.jsx)(y5,{checked:e.on_queue_completed??!1,onChange:e=>f.mutate({on_queue_completed:e})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(nl,{className:`w-4 h-4 text-purple-400`}),(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.quietHours`)})]}),(0,K.jsx)(y5,{checked:e.quiet_hours_enabled,onChange:e=>f.mutate({quiet_hours_enabled:e})})]}),e.quiet_hours_enabled&&(0,K.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.noNotificationsDuring`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(_s,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsxs)(`span`,{className:`text-sm text-white`,children:[h(e.quiet_hours_start)||`22:00`,` - `,h(e.quiet_hours_end)||`07:00`]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.editProviderToChangeQuietHours`)})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(qo,{className:`w-4 h-4 text-emerald-400`}),(0,K.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.dailyDigest`)})]}),(0,K.jsx)(y5,{checked:e.daily_digest_enabled,onChange:e=>f.mutate({daily_digest_enabled:e})})]}),e.daily_digest_enabled&&(0,K.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.batchNotifications`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(_s,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.sendAt`,{time:h(e.daily_digest_time)||`08:00`})})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.editProviderToChangeDigestTime`)})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>t(e),className:`flex-1`,children:[(0,K.jsx)(fl,{className:`w-4 h-4`}),n(`notifications.edit`)]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>a(!0),className:`text-red-400 hover:text-red-300`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]})]})}),i&&(0,K.jsx)(Ed,{title:n(`notifications.deleteProvider`),message:n(`notifications.deleteConfirm`,{name:e.name}),confirmText:n(`notifications.delete`),variant:`danger`,onConfirm:()=>{p.mutate(),a(!1)},onCancel:()=>a(!1)})]})}var DRe=[`email`,`telegram`,`discord`,`ntfy`,`pushover`,`callmebot`,`webhook`,`homeassistant`];function ORe({provider:e,onClose:t}){let{t:n}=G(),r=Qa(),i=!!e,[a,o]=(0,y.useState)(e?.name||``),[s,c]=(0,y.useState)(e?.provider_type||`email`),[l,u]=(0,y.useState)(e?.printer_id||null),[d,f]=(0,y.useState)(e?.quiet_hours_enabled||!1),[p,m]=(0,y.useState)(e?.quiet_hours_start||`22:00`),[h,g]=(0,y.useState)(e?.quiet_hours_end||`07:00`),[_,v]=(0,y.useState)(e?.daily_digest_enabled||!1),[b,x]=(0,y.useState)(e?.daily_digest_time||`08:00`),[S,C]=(0,y.useState)(e?.on_print_start??!1),[w,T]=(0,y.useState)(e?.on_print_complete??!0),[E,D]=(0,y.useState)(e?.on_print_failed??!0),[O,k]=(0,y.useState)(e?.on_print_stopped??!0),[A,j]=(0,y.useState)(e?.on_print_progress??!1),[M,N]=(0,y.useState)(e?.on_printer_offline??!1),[P,F]=(0,y.useState)(e?.on_printer_error??!1),[I,L]=(0,y.useState)(e?.on_filament_low??!1),[R,z]=(0,y.useState)(e?.on_maintenance_due??!1),[B,V]=(0,y.useState)(e?.on_stock_reorder_alert??!1),[ee,H]=(0,y.useState)(e?.on_stock_break_alert??!1),[te,ne]=(0,y.useState)(e?.on_bed_cooled??!1),[re,U]=(0,y.useState)(e?.on_first_layer_complete??!1),[ie,ae]=(0,y.useState)(e?.config?Object.fromEntries(Object.entries(e.config).filter(([e])=>e!==`event_priorities`).map(([e,t])=>[e,String(t)])):{}),[W,oe]=(0,y.useState)((()=>{let t=e?.config?.event_priorities;if(!t||typeof t!=`object`)return{};let n={};for(let[e,r]of Object.entries(t)){let t=Number(r);Number.isInteger(t)&&t>=1&&t<=5&&(n[e]=t)}return n})()),[se,ce]=(0,y.useState)(null),[le,ue]=(0,y.useState)(null),{data:de}=q({queryKey:[`printers`],queryFn:Q.getPrinters});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let fe=J({mutationFn:()=>Q.testNotificationConfig({provider_type:s,config:ie}),onSuccess:e=>{ce(e),ue(null)},onError:e=>{ce({success:!1,message:e.message})}}),pe=J({mutationFn:e=>Q.createNotificationProvider(e),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]}),t()},onError:e=>{ue(e.message)}}),me=J({mutationFn:t=>Q.updateNotificationProvider(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]}),t()},onError:e=>{ue(e.message)}}),he=e=>{if(e.preventDefault(),ue(null),!a.trim()){ue(n(`notifications.nameRequired`));return}let t=ve(s);for(let e of t)if(!ie[e.key]?.trim()){ue(n(`notifications.fieldRequired`,{field:e.label}));return}let r=s===`ntfy`&&Object.keys(W).length>0?{...ie,event_priorities:W}:ie,o={name:a.trim(),provider_type:s,config:r,printer_id:l,quiet_hours_enabled:d,quiet_hours_start:d?p:null,quiet_hours_end:d?h:null,daily_digest_enabled:_,daily_digest_time:_?b:null,on_print_start:S,on_print_complete:w,on_print_failed:E,on_print_stopped:O,on_print_progress:A,on_printer_offline:M,on_printer_error:P,on_filament_low:I,on_maintenance_due:R,on_stock_reorder_alert:B,on_stock_break_alert:ee,on_bed_cooled:te,on_first_layer_complete:re};i?me.mutate(o):pe.mutate(o)},ge=pe.isPending||me.isPending,_e=e=>{switch(e){case`callmebot`:return[{key:`phone`,label:`Phone Number`,placeholder:`+1234567890`,type:`text`,required:!0},{key:`apikey`,label:`API Key`,placeholder:`Your CallMeBot API key`,type:`text`,required:!0}];case`ntfy`:return[{key:`server`,label:`Server URL`,placeholder:`https://ntfy.sh`,type:`text`,required:!1},{key:`topic`,label:`Topic`,placeholder:`my-bambuddy`,type:`text`,required:!0},{key:`auth_token`,label:`Auth Token`,placeholder:`Optional authentication`,type:`password`,required:!1}];case`pushover`:return[{key:`user_key`,label:`User Key`,placeholder:`Your Pushover user key`,type:`text`,required:!0},{key:`app_token`,label:`App Token`,placeholder:`Your Pushover app token`,type:`text`,required:!0},{key:`priority`,label:`Priority`,placeholder:`0 (normal)`,type:`number`,required:!1}];case`telegram`:return[{key:`bot_token`,label:`Bot Token`,placeholder:`Bot token from @BotFather`,type:`password`,required:!0},{key:`chat_id`,label:`Chat ID`,placeholder:`Your chat or group ID`,type:`text`,required:!0}];case`email`:return[{key:`smtp_server`,label:`SMTP Server`,placeholder:`smtp.gmail.com`,type:`text`,required:!0},{key:`smtp_port`,label:`SMTP Port`,placeholder:`587`,type:`number`,required:!1},{key:`security`,label:`Security`,type:`select`,required:!1,options:[{value:`starttls`,label:`STARTTLS (Port 587)`},{value:`ssl`,label:`SSL/TLS (Port 465)`},{value:`none`,label:`None (Port 25)`}]},{key:`auth_enabled`,label:`Authentication`,type:`select`,required:!1,options:[{value:`true`,label:`Enabled`},{value:`false`,label:`Disabled`}]},{key:`username`,label:`Username`,placeholder:`your@email.com`,type:`text`,required:!1},{key:`password`,label:`Password`,placeholder:`App password`,type:`password`,required:!1},{key:`from_email`,label:`From Email`,placeholder:`your@email.com`,type:`text`,required:!0},{key:`to_email`,label:`To Email`,placeholder:`recipient@email.com`,type:`text`,required:!0}];case`discord`:return[{key:`webhook_url`,label:`Webhook URL`,placeholder:`https://discord.com/api/webhooks/...`,type:`text`,required:!0}];case`webhook`:return[{key:`webhook_url`,label:`Webhook URL`,placeholder:`https://example.com/webhook`,type:`text`,required:!0},{key:`payload_format`,label:`Payload Format`,type:`select`,required:!1,options:[{value:`generic`,label:`Generic JSON`},{value:`slack`,label:`Slack / Mattermost`}]},{key:`auth_header`,label:`Authorization`,placeholder:`Bearer token (optional)`,type:`password`,required:!1},{key:`field_title`,label:`Title Field Name`,placeholder:`title`,type:`text`,required:!1,showIf:e=>e.payload_format!==`slack`},{key:`field_message`,label:`Message Field Name`,placeholder:`message`,type:`text`,required:!1,showIf:e=>e.payload_format!==`slack`}];case`homeassistant`:return[{key:`service`,label:`Home Assistant Service`,placeholder:`notify.mobile_app_myphone`,type:`text`,required:!1}];default:return[]}},ve=e=>_e(e).filter(e=>e.required),ye=_e(s);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto`,onClick:t,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg my-8 max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,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:n(i?`notifications.editTitle`:`notifications.addTitle`)}),(0,K.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`form`,{onSubmit:he,className:`p-6 space-y-4`,children:[le&&(0,K.jsx)(`div`,{className:`p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400`,children:le}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.nameLabel`)}),(0,K.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:n(`notifications.namePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.providerTypeLabel`)}),(0,K.jsx)(`select`,{value:s,onChange:e=>{c(e.target.value),ae({}),ce(null)},disabled:i,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`,children:DRe.map(e=>(0,K.jsx)(`option`,{value:e,children:n(`notifications.providerTypes.${e}`,e)},e))}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.providerDescriptions.${s}`,``)})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.configuration`)}),ye.filter(e=>!(`showIf`in e)||e.showIf?.(ie)!==!1).map(e=>(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[e.label,` `,e.required&&`*`]}),e.type===`select`&&`options`in e&&e.options?(0,K.jsx)(`select`,{value:ie[e.key]||e.options[0]?.value||``,onChange:t=>{ae({...ie,[e.key]:t.target.value}),ce(null)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:e.options.map(e=>(0,K.jsx)(`option`,{value:e.value,children:e.label},e.value))}):(0,K.jsx)(`input`,{type:e.type,value:ie[e.key]||``,onChange:t=>{ae({...ie,[e.key]:t.target.value}),ce(null)},placeholder:e.placeholder,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]},e.key))]}),(0,K.jsx)(`div`,{className:`flex gap-2`,children:(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:()=>{ce(null),fe.mutate()},disabled:fe.isPending||ve(s).length>0&&!ie[ve(s)[0]?.key],className:`flex-1`,children:[fe.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Pl,{className:`w-4 h-4`}),n(`notifications.testConfiguration`)]})}),se&&(0,K.jsx)(`div`,{className:`p-3 rounded-lg flex items-center gap-2 ${se.success?`bg-bambu-green/20 border border-bambu-green/50 text-bambu-green`:`bg-red-500/20 border border-red-500/50 text-red-400`}`,children:se.success?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ls,{className:`w-5 h-5`}),(0,K.jsx)(`span`,{children:se.message})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ms,{className:`w-5 h-5`}),(0,K.jsx)(`span`,{children:se.message})]})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.printerFilter`)}),(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:n(`notifications.allPrinters`)}),de?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.onlyFromPrinter`)})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.quietHoursDnd`)}),(0,K.jsx)(y5,{checked:d,onChange:f})]}),d&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.quietStart`)}),(0,K.jsx)(`input`,{type:`time`,value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.quietEnd`)}),(0,K.jsx)(`input`,{type:`time`,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`})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.dailyDigestLabel`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.batchNotifications`)})]}),(0,K.jsx)(y5,{checked:_,onChange:v})]}),_&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.sendDigestAt`)}),(0,K.jsx)(`input`,{type:`time`,value:b,onChange:e=>x(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.digestCollected`)})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.notificationEvents`)}),(0,K.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.printEvents`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.start`)}),(0,K.jsx)(y5,{checked:S,onChange:C})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.complete`)}),(0,K.jsx)(y5,{checked:w,onChange:T})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.failed`)}),(0,K.jsx)(y5,{checked:E,onChange:D})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stopped`)}),(0,K.jsx)(y5,{checked:O,onChange:k})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.progress`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.progressPercent`)})]}),(0,K.jsx)(y5,{checked:A,onChange:j})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.bedCooled`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.bedCooledAfterPrint`)})]}),(0,K.jsx)(y5,{checked:te,onChange:ne})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.firstLayerCompleteLabel`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.firstLayerCompleteDescription`)})]}),(0,K.jsx)(y5,{checked:re,onChange:U})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.printerStatus`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.offline`)}),(0,K.jsx)(y5,{checked:M,onChange:N})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.error`)}),(0,K.jsx)(y5,{checked:P,onChange:F})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.lowFilament`)}),(0,K.jsx)(y5,{checked:I,onChange:L})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.maintenance`)}),(0,K.jsx)(y5,{checked:R,onChange:z})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.inventoryAlerts`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stockReorderAlert`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.stockReorderAlertDescription`)})]}),(0,K.jsx)(y5,{checked:B,onChange:V})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stockBreakAlert`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.stockBreakAlertDescription`)})]}),(0,K.jsx)(y5,{checked:ee,onChange:H})]})]})]}),s===`ntfy`&&(()=>{let e=[];return S&&e.push({key:`on_print_start`,label:n(`notifications.start`)}),w&&e.push({key:`on_print_complete`,label:n(`notifications.complete`)}),E&&e.push({key:`on_print_failed`,label:n(`notifications.failed`)}),O&&e.push({key:`on_print_stopped`,label:n(`notifications.stopped`)}),A&&e.push({key:`on_print_progress`,label:n(`notifications.progress`)}),te&&e.push({key:`on_bed_cooled`,label:n(`notifications.bedCooled`)}),re&&e.push({key:`on_first_layer_complete`,label:n(`notifications.firstLayerCompleteLabel`)}),M&&e.push({key:`on_printer_offline`,label:n(`notifications.offline`)}),P&&e.push({key:`on_printer_error`,label:n(`notifications.error`)}),I&&e.push({key:`on_filament_low`,label:n(`notifications.lowFilament`)}),R&&e.push({key:`on_maintenance_due`,label:n(`notifications.maintenance`)}),B&&e.push({key:`on_stock_reorder_alert`,label:n(`notifications.stockReorderAlert`)}),ee&&e.push({key:`on_stock_break_alert`,label:n(`notifications.stockBreakAlert`)}),e.length===0?null:(0,K.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-1`,children:n(`notifications.eventPriority.sectionTitle`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`notifications.eventPriority.helpNtfy`)}),(0,K.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:e.label}),(0,K.jsxs)(`select`,{value:W[e.key]??3,onChange:t=>{let n=Number(t.target.value);oe(t=>({...t,[e.key]:n}))},className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:1,children:n(`notifications.eventPriority.min`)}),(0,K.jsx)(`option`,{value:2,children:n(`notifications.eventPriority.low`)}),(0,K.jsx)(`option`,{value:3,children:n(`notifications.eventPriority.default`)}),(0,K.jsx)(`option`,{value:4,children:n(`notifications.eventPriority.high`)}),(0,K.jsx)(`option`,{value:5,children:n(`notifications.eventPriority.urgent`)})]})]},e.key))})]})})()]}),(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`notifications.cancel`)}),(0,K.jsxs)($,{type:`submit`,disabled:ge,className:`flex-1`,children:[ge?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Ol,{className:`w-4 h-4`}),n(i?`notifications.save`:`notifications.add`)]})]})]})]})})}function kRe({template:e,onClose:t}){let{t:n}=G(),r=Qa(),i=(0,y.useRef)(null),[a,o]=(0,y.useState)(e.title_template),[s,c]=(0,y.useState)(e.body_template),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!0),{data:p}=q({queryKey:[`template-variables`],queryFn:Q.getTemplateVariables}),m=p?.find(t=>t.event_type===e.event_type),{data:h,isLoading:g}=q({queryKey:[`template-preview`,e.event_type,a,s],queryFn:()=>Q.previewTemplate({event_type:e.event_type,title_template:a,body_template:s}),enabled:d&&a.length>0&&s.length>0});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let _=J({mutationFn:t=>Q.updateNotificationTemplate(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-templates`]}),t()},onError:e=>{u(e.message)}}),v=J({mutationFn:()=>Q.resetNotificationTemplate(e.id),onSuccess:e=>{o(e.title_template),c(e.body_template),r.invalidateQueries({queryKey:[`notification-templates`]})},onError:e=>{u(e.message)}}),b=e=>{if(e.preventDefault(),u(null),!a.trim()){u(n(`notifications.titleRequired`));return}if(!s.trim()){u(n(`notifications.bodyRequired`));return}_.mutate({title_template:a,body_template:s})},x=e=>{let t=i.current;if(!t)return;let n=t.selectionStart,r=t.selectionEnd,a=s,o=a.substring(0,n),l=a.substring(r);c(o+`{${e}}`+l),setTimeout(()=>{t.focus();let r=n+e.length+2;t.setSelectionRange(r,r)},0)},S=a!==e.title_template||s!==e.body_template;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`notifications.editTemplate`,{name:e.name})}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`form`,{onSubmit:b,className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[l&&(0,K.jsx)(`div`,{className:`p-3 bg-red-500/20 border border-red-500/50 rounded text-red-400 text-sm`,children:l}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:n(`notifications.titleLabel`)}),(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 text-white focus:outline-none focus:ring-1 focus:ring-bambu-green`,placeholder:n(`notifications.titlePlaceholder`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:n(`notifications.bodyLabel`)}),(0,K.jsx)(`textarea`,{ref:i,value:s,onChange:e=>c(e.target.value),rows:4,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green font-mono text-sm resize-none`,placeholder:n(`notifications.bodyPlaceholder`)})]}),m&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-2`,children:n(`notifications.availableVariables`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.variables.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>x(e),className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,K.jsx)(_l,{className:`w-3 h-3`}),e]},e))}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:n(`notifications.clickToInsert`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`label`,{className:`text-sm font-medium text-bambu-gray flex items-center gap-2`,children:[(0,K.jsx)(Gs,{className:`w-4 h-4`}),n(`notifications.livePreview`)]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>f(!d),className:`text-xs text-bambu-green hover:text-bambu-green-light`,children:n(d?`notifications.hide`:`notifications.show`)})]}),d&&(0,K.jsx)(`div`,{className:`bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2`,children:g?(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(`notifications.loadingPreview`)]}):h?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.titlePreview`)}),(0,K.jsx)(`div`,{className:`text-white font-medium`,children:h.title})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.bodyPreview`)}),(0,K.jsx)(`div`,{className:`text-white whitespace-pre-wrap text-sm`,children:h.body})]})]}):(0,K.jsx)(`div`,{className:`text-bambu-gray text-sm`,children:n(`notifications.enterTemplateContent`)})})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0`,children:[(0,K.jsxs)($,{type:`button`,variant:`ghost`,onClick:()=>v.mutate(),disabled:v.isPending,className:`text-orange-400 hover:text-orange-300`,children:[v.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-2`}):(0,K.jsx)(Tl,{className:`w-4 h-4 mr-2`}),n(`notifications.resetToDefault`)]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,children:n(`notifications.cancel`)}),(0,K.jsxs)($,{onClick:b,disabled:_.isPending||!S,children:[_.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-2`}):(0,K.jsx)(Ol,{className:`w-4 h-4 mr-2`}),n(`notifications.save`)]})]})]})]})})}var ARe={print_start:`text-blue-400`,print_complete:`text-bambu-green`,print_failed:`text-red-400`,print_stopped:`text-orange-400`,print_progress:`text-yellow-400`,printer_offline:`text-gray-400`,printer_error:`text-rose-400`,filament_low:`text-cyan-400`,maintenance_due:`text-purple-400`,test:`text-bambu-gray`};function jRe({onClose:e}){let{t}=G(),n=Qa(),{showToast:r}=xd(),[i,a]=(0,y.useState)(7),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(!1),{data:u}=q({queryKey:[`settings`],queryFn:Q.getSettings}),d=u?.time_format||`system`,{data:f,isLoading:p,refetch:m,isRefetching:h}=q({queryKey:[`notification-logs`,i,c],queryFn:()=>Q.getNotificationLogs({days:i,limit:100,success:c?!1:void 0})}),{data:g}=q({queryKey:[`notification-log-stats`,i],queryFn:()=>Q.getNotificationLogStats(i)}),_=J({mutationFn:()=>Q.clearNotificationLogs(30),onSuccess:e=>{r(e.message,`success`),n.invalidateQueries({queryKey:[`notification-logs`]}),n.invalidateQueries({queryKey:[`notification-log-stats`]})},onError:e=>{r(`Failed to clear logs: ${e.message}`,`error`)}}),v=e=>{let n=mf(e);if(!n)return``;let r=new Date().getTime()-n.getTime();return r<6e4?t(`notifications.justNow`):r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?`${Math.floor(r/36e5)}h ago`:n.toLocaleDateString()+` `+_f(n,d)};return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-3xl max-h-[85vh] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(wc,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t(`notifications.notificationLog`)})]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:`×`})]}),g&&(0,K.jsx)(`div`,{className:`px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-6 text-sm`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`notifications.statsSummary`,{days:i}),` `,(0,K.jsx)(`span`,{className:`text-white font-medium`,children:g.total}),` `,t(`notifications.statsNotifications`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-green`,children:[(0,K.jsx)(ls,{className:`w-4 h-4`}),t(`notifications.statsSent`,{count:g.success_count})]}),g.failure_count>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-red-400`,children:[(0,K.jsx)(ms,{className:`w-4 h-4`}),t(`notifications.statsFailed`,{count:g.failure_count})]})]})}),(0,K.jsxs)(`div`,{className:`px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4`,children:[(0,K.jsxs)(`select`,{value:i,onChange:e=>a(Number(e.target.value)),className:`px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green`,children:[(0,K.jsx)(`option`,{value:1,children:t(`notifications.last24Hours`)}),(0,K.jsx)(`option`,{value:7,children:t(`notifications.last7Days`)}),(0,K.jsx)(`option`,{value:30,children:t(`notifications.last30Days`)}),(0,K.jsx)(`option`,{value:90,children:t(`notifications.last90Days`)})]}),(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:c,onChange:e=>l(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),t(`notifications.showFailedOnly`)]}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>m(),disabled:h,children:[h?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),t(`notifications.refresh`)]}),(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>_.mutate(),disabled:_.isPending,className:`text-red-400 hover:text-red-300`,children:[_.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hu,{className:`w-4 h-4`}),t(`notifications.clearOld`)]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:p?(0,K.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})}):f&&f.length>0?(0,K.jsx)(`div`,{className:`space-y-2`,children:f.map(e=>(0,K.jsx)(MRe,{log:e,isExpanded:o===e.id,onToggle:()=>s(o===e.id?null:e.id),formatDate:v,formatFullDate:e=>gf(e,d)},e.id))}):(0,K.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,K.jsx)(wc,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,K.jsx)(`p`,{className:`text-sm`,children:t(c?`notifications.noFailedNotifications`:`notifications.noNotificationsLogged`)})]})})]})})}function MRe({log:e,isExpanded:t,onToggle:n,formatDate:r,formatFullDate:i}){let{t:a}=G();return(0,K.jsxs)(`div`,{className:`border rounded-lg overflow-hidden transition-colors ${e.success?`border-bambu-dark-tertiary bg-bambu-dark/30`:`border-red-500/30 bg-red-500/5`}`,children:[(0,K.jsxs)(`button`,{className:`w-full px-3 py-2 flex items-center gap-3 text-left hover:bg-bambu-dark/50 transition-colors`,onClick:n,children:[e.success?(0,K.jsx)(ls,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,K.jsx)(ms,{className:`w-4 h-4 text-red-400 shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs font-medium ${ARe[e.event_type]||`text-bambu-gray`}`,children:a(`notifications.eventTypes.${e.event_type}`,e.event_type)}),(0,K.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:e.provider_name||a(`notifications.unknownProvider`)}),e.printer_name&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.printer_name}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:r(e.created_at)}),t?(0,K.jsx)(rs,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),t&&(0,K.jsxs)(`div`,{className:`px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:a(`notifications.logTitle`)}),(0,K.jsx)(`p`,{className:`text-sm text-white`,children:e.title})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:a(`notifications.logMessage`)}),(0,K.jsx)(`p`,{className:`text-sm text-white whitespace-pre-wrap`,children:e.message})]}),!e.success&&e.error_message&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-red-400 mb-1`,children:a(`notifications.logError`)}),(0,K.jsx)(`p`,{className:`text-sm text-red-300`,children:e.error_message})]}),(0,K.jsxs)(`div`,{className:`flex gap-4 text-xs text-bambu-gray pt-1`,children:[(0,K.jsx)(`span`,{children:a(`notifications.logProvider`,{type:e.provider_type})}),(0,K.jsx)(`span`,{children:a(`notifications.logTime`,{time:i(e.created_at)})})]})]})]})}var NRe=Object.defineProperty,b5=Object.getOwnPropertySymbols,x5=Object.prototype.hasOwnProperty,S5=Object.prototype.propertyIsEnumerable,C5=(e,t,n)=>t in e?NRe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,w5=(e,t)=>{for(var n in t||={})x5.call(t,n)&&C5(e,n,t[n]);if(b5)for(var n of b5(t))S5.call(t,n)&&C5(e,n,t[n]);return e},T5=(e,t)=>{var n={};for(var r in e)x5.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&b5)for(var r of b5(e))t.indexOf(r)<0&&S5.call(e,r)&&(n[r]=e[r]);return n},E5;(e=>{let t=class t{constructor(e,n,r,a){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],et.MAX_VERSION)throw RangeError(`Version value out of range`);if(a<-1||a>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let o=[];for(let e=0;e7)throw RangeError(`Invalid value`);let u,d;for(u=a;;u++){let n=t.getNumDataCodewords(u,r)*8,i=o.getTotalBits(e,u);if(i<=n){d=i;break}if(u>=s)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])l&&d<=t.getNumDataCodewords(u,e)*8&&(r=e);let f=[];for(let t of e){n(t.mode.modeBits,4,f),n(t.numChars,t.mode.numCharCountBits(u),f);for(let e of t.getData())f.push(e)}i(f.length==d);let p=t.getNumDataCodewords(u,r)*8;i(f.length<=p),n(0,Math.min(4,p-f.length),f),n(0,(8-f.length%8)%8,f),i(f.length%8==0);for(let e=236;f.lengthm[t>>>3]|=e<<7-(t&7)),new t(u,r,m,c)}getModule(e,t){return 0<=e&&e>>9)*1335;let a=(t<<10|n)^21522;i(a>>>15==0);for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(a,e));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(a,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(a,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(a,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;i(t>>>18==0);for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;0<=a&&a{(e!=l-o||n>=c)&&f.push(t[e])});return i(f.length==s),f}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let i=0;i>>3],7-(n&7)),n++)}}i(n==e.length*8)}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;ne+ +!!t,n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return i(0<=a&&a<=9),e+=a*t.PENALTY_N4,i(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{let e=Math.floor(this.version/7)+2,t=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.lengtht.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return i(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return i(n>>>8==0),n}finderPenaltyCountPatterns(e){let t=e[1];i(t<=this.size*3);let n=t>0&&e[2]==t&&e[3]==t*3&&e[4]==t&&e[5]==t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]==0&&(e+=this.size),t.pop(),t.unshift(e)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return(e>>>t&1)!=0}function i(e){if(!e)throw Error(`Assertion error`)}let a=class e{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}static makeBytes(t){let r=[];for(let e of t)n(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw RangeError(`String contains non-numeric characters`);let r=[];for(let e=0;e=1<{(e=>{let t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(E5||={}),(e=>{(e=>{let t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(E5||={});var D5=E5,PRe={L:D5.QrCode.Ecc.LOW,M:D5.QrCode.Ecc.MEDIUM,Q:D5.QrCode.Ecc.QUARTILE,H:D5.QrCode.Ecc.HIGH},O5=128,k5=`L`,A5=`#FFFFFF`,j5=`#000000`,M5=!1,N5=1,FRe=4,IRe=0,LRe=.1;function P5(e,t=0){let n=[];return e.forEach(function(e,r){let i=null;e.forEach(function(a,o){if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function F5(e,t){return e.slice().map((e,n)=>n=t.y+t.h?e:e.map((e,n)=>n=t.x+t.w?e:!1))}function RRe(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*LRe),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,d=r.opacity==null?1:r.opacity,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}let p=r.crossOrigin;return{x:l,y:u,h:c,w:s,excavation:f,opacity:d,crossOrigin:p}}function zRe(e,t){return t==null?e?FRe:IRe:Math.max(Math.floor(t),0)}function I5({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:s}){let c=y.useMemo(()=>{let r=(Array.isArray(e)?e:[e]).reduce((e,t)=>(e.push(...D5.QrSegment.makeSegments(t)),e),[]);return D5.QrCode.encodeSegments(r,PRe[t],n,void 0,void 0,s)},[e,t,n,s]),{cells:l,margin:u,numCells:d,calculatedImageSettings:f}=y.useMemo(()=>{let e=c.getModules(),t=zRe(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:RRe(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var BRe=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),VRe=y.forwardRef(function(e,t){let n=e,{value:r,size:i=O5,level:a=k5,bgColor:o=A5,fgColor:s=j5,includeMargin:c=M5,minVersion:l=N5,boostLevel:u,marginSize:d,imageSettings:f}=n,p=T5(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=T5(p,[`style`]),g=f?.src,_=y.useRef(null),v=y.useRef(null),b=y.useCallback(e=>{_.current=e,typeof t==`function`?t(e):t&&(t.current=e)},[t]),[x,S]=y.useState(!1),{margin:C,cells:w,numCells:T,calculatedImageSettings:E}=I5({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:d,imageSettings:f,size:i});y.useEffect(()=>{if(_.current!=null){let e=_.current,t=e.getContext(`2d`);if(!t)return;let n=w,r=v.current,a=E!=null&&r!==null&&r.complete&&r.naturalHeight!==0&&r.naturalWidth!==0;a&&E.excavation!=null&&(n=F5(w,E.excavation));let c=window.devicePixelRatio||1;e.height=e.width=i*c;let l=i/T*c;t.scale(l,l),t.fillStyle=o,t.fillRect(0,0,T,T),t.fillStyle=s,BRe?t.fill(new Path2D(P5(n,C))):w.forEach(function(e,n){e.forEach(function(e,r){e&&t.fillRect(r+C,n+C,1,1)})}),E&&(t.globalAlpha=E.opacity),a&&t.drawImage(r,E.x+C,E.y+C,E.w,E.h)}}),y.useEffect(()=>{S(!1)},[g]);let D=w5({height:i,width:i},m),O=null;return g!=null&&(O=y.createElement(`img`,{src:g,key:g,style:{display:`none`},onLoad:()=>{S(!0)},ref:v,crossOrigin:E?.crossOrigin})),y.createElement(y.Fragment,null,y.createElement(`canvas`,w5({style:D,height:i,width:i,ref:b,role:`img`},h)),O)});VRe.displayName=`QRCodeCanvas`;var L5=y.forwardRef(function(e,t){let n=e,{value:r,size:i=O5,level:a=k5,bgColor:o=A5,fgColor:s=j5,includeMargin:c=M5,minVersion:l=N5,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=T5(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:v}=I5({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:f,imageSettings:p,size:i}),b=g,x=null;p!=null&&v!=null&&(v.excavation!=null&&(b=F5(g,v.excavation)),x=y.createElement(`image`,{href:p.src,height:v.h,width:v.w,x:v.x+h,y:v.y+h,preserveAspectRatio:`none`,opacity:v.opacity,crossOrigin:v.crossOrigin}));let S=P5(b,h);return y.createElement(`svg`,w5({height:i,width:i,viewBox:`0 0 ${_} ${_}`,ref:t,role:`img`},m),!!d&&y.createElement(`title`,null,d),y.createElement(`path`,{fill:o,d:`M0,0 h${_}v${_}H0z`,shapeRendering:`crispEdges`}),y.createElement(`path`,{fill:s,d:S,shapeRendering:`crispEdges`}),x)});L5.displayName=`QRCodeSVG`;function HRe(e,t){return`bambuddy://config?v=1&url=${encodeURIComponent(e)}&key=${encodeURIComponent(t)}`}function URe({apiKey:e,baseUrl:t,onClose:n}){let{t:r}=G(),i=HRe(t??window.location.origin,e);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:r(`settings.apiKeyQrTitle`)}),(0,K.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`),children:(0,K.jsx)(Pu,{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`,children:r(`settings.apiKeyQrCaption`)}),(0,K.jsx)(`div`,{className:`bg-white p-4 rounded-lg mb-4`,children:(0,K.jsx)(L5,{value:i,size:256})}),(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-xs text-amber-400 mb-4`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 flex-shrink-0 mt-0.5`}),(0,K.jsx)(`span`,{children:r(`settings.apiKeyQrWarning`)})]}),(0,K.jsx)($,{onClick:n,className:`w-full`,children:r(`common.close`)})]})]})})}var WRe=300,R5=2;function z5({onSuccess:e}){let{t}=G(),n=Qa(),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null);(0,y.useEffect)(()=>{let e=r.trim();if(e.lengtho(e),WRe);return()=>clearTimeout(t)},[r]),(0,y.useEffect)(()=>{c(null),u(null)},[a]);let d=q({queryKey:[`ldap-search`,a],queryFn:()=>Q.searchLDAPDirectory(a),enabled:a.length>=R5,staleTime:3e4}),f=J({mutationFn:e=>Q.provisionLDAPUser(e),onSuccess:t=>{n.invalidateQueries({queryKey:[`users`]}),e(t)},onError:e=>{u(e.message||t(`users.modal.ldapErrorProvision`))}}),p=(0,y.useMemo)(()=>d.data?.find(e=>e.dn===s)??null,[d.data,s]),m=r.trim().length>0&&r.trim().length=R5,g=!!d.data&&d.data.length>0,_=!h&&!!d.data&&d.data.length===0&&a.length>=R5;return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:t(`users.modal.ldapSearchLabel`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,K.jsx)(`input`,{type:`text`,value:r,onChange:e=>i(e.target.value),className:`w-full pl-9 pr-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`users.modal.ldapSearchPlaceholder`),autoComplete:`off`})]}),m&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:t(`users.modal.ldapMinChars`)})]}),(0,K.jsxs)(`div`,{className:`min-h-[8rem] max-h-64 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[h&&(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-2`}),(0,K.jsx)(`span`,{children:t(`users.modal.ldapSearching`)})]}),_&&(0,K.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapNoResults`)}),d.isError&&(0,K.jsx)(`div`,{className:`px-3 py-4 text-sm text-red-400`,children:d.error instanceof Error?d.error.message:t(`users.modal.ldapSearchError`)}),!h&&g&&(0,K.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary`,children:d.data.map(e=>(0,K.jsx)(GRe,{result:e,selected:s===e.dn,onSelect:()=>c(e.dn)},e.dn))}),!h&&!d.data&&!d.isError&&(0,K.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapTypeToSearch`)})]}),p&&(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-1`,children:[(0,K.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`users.modal.ldapSelectedLabel`),`: `]}),(0,K.jsx)(`span`,{className:`font-medium`,children:p.username}),p.display_name&&(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,p.display_name]})]}),p.email&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:p.email}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray break-all`,children:p.dn})]}),l&&(0,K.jsx)(`div`,{className:`bg-red-500/10 border border-red-500/30 rounded-lg p-3`,children:(0,K.jsx)(`p`,{className:`text-sm text-red-400`,children:l})}),(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsx)($,{onClick:()=>{!p||p.already_provisioned||(u(null),f.mutate(p.username))},disabled:!p||p.already_provisioned||f.isPending,children:f.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),t(`users.modal.ldapProvisioning`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),t(`users.modal.ldapProvision`)]})})})]})}function GRe({result:e,selected:t,onSelect:n}){let{t:r}=G(),i=e.already_provisioned;return(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,onClick:n,disabled:i,className:`w-full text-left px-3 py-2 flex items-center gap-3 transition-colors ${i?`opacity-50 cursor-not-allowed`:t?`bg-bambu-green/10`:`hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`p`,{className:`text-sm text-white truncate`,children:[(0,K.jsx)(`span`,{className:`font-medium`,children:e.username}),e.display_name&&(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,e.display_name]})]}),e.email&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.email})]}),i&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray whitespace-nowrap`,children:[(0,K.jsx)(us,{className:`w-3.5 h-3.5`}),r(`users.modal.ldapAlreadyProvisioned`)]})]})})}function KRe({formData:e,setFormData:t,groups:n,onClose:r,onCreate:i,isCreating:a,isCreateButtonDisabled:o,ldapEnabled:s=!1,onLdapProvisioned:c}){let{t:l}=G(),[u,d]=(0,y.useState)(`local`);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let f=n=>{t({...e,group_ids:e.group_ids.includes(n)?e.group_ids.filter(e=>e!==n):[...e.group_ids,n]})};return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:r,children:(0,K.jsxs)(pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(wu,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:l(`users.modal.createUser`)})]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray ml-7`,children:l(`users.modal.advancedAuthSubtitle`)||`with Advanced Authentication`})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:r,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]})}),(0,K.jsxs)(hd,{children:[s&&(0,K.jsxs)(`div`,{className:`mb-4 flex items-center gap-1 p-1 bg-bambu-dark-secondary rounded-lg`,role:`tablist`,"aria-label":l(`users.modal.tabsAriaLabel`),children:[(0,K.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":u===`local`,onClick:()=>d(`local`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${u===`local`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:l(`users.modal.localTab`)}),(0,K.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":u===`ldap`,onClick:()=>d(`ldap`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${u===`ldap`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:l(`users.modal.ldapTab`)})]}),u===`ldap`&&s?(0,K.jsx)(z5,{onSuccess:e=>{c?.(e)}}):(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[l(`users.form.username`),` `,(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsx)(`input`,{type:`text`,value:e.username,onChange:n=>t({...e,username:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:l(`users.form.usernamePlaceholder`),autoComplete:`username`,required:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[l(`users.form.email`)||`Email`,` `,(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsx)(`input`,{type:`email`,value:e.email,onChange:n=>t({...e,email:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:l(`users.form.emailPlaceholder`)||`user@example.com`,required:!0})]}),(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3`,children:(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:l(`users.form.autoGeneratedPassword`)||`A secure password will be automatically generated and emailed to the user.`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:l(`users.form.groups`)}),(0,K.jsxs)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[n.map(t=>(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.group_ids.includes(t.id),onChange:()=>f(t.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:t.name}),t.is_system&&(0,K.jsxs)(`span`,{className:`text-xs text-yellow-400`,children:[`(`,l(`users.system`),`)`]})]},t.id)),n.length===0&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:l(`users.noGroupsAvailable`)})]})]})]}),(0,K.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:r,children:l(`users.modal.cancel`)}),u===`local`&&(0,K.jsx)($,{onClick:i,disabled:o,children:a?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),l(`users.modal.creating`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),l(`users.modal.createUser`)]})})]})]})]})})}function qRe(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`auto`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!0),[p,m]=(0,y.useState)(`all`),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),{data:w,isLoading:T}=q({queryKey:[`spoolman-settings`],queryFn:Q.getSpoolmanSettings}),{data:E,isLoading:D,refetch:O}=q({queryKey:[`spoolman-status`],queryFn:Q.getSpoolmanStatus,refetchInterval:3e4}),{data:k}=q({queryKey:[`printers`],queryFn:Q.getPrinters});(0,y.useEffect)(()=>{w&&(i(w.spoolman_enabled===`true`),o(w.spoolman_url||``),c(w.spoolman_sync_mode||`auto`),u(w.spoolman_disable_weight_sync===`true`),f(w.spoolman_report_partial_usage!==`false`),g(!0))},[w]),(0,y.useEffect)(()=>{if(!(!h||!w)&&(w.spoolman_enabled===`true`!==r||(w.spoolman_url||``)!==a||(w.spoolman_sync_mode||`auto`)!==s||w.spoolman_disable_weight_sync===`true`!==l||w.spoolman_report_partial_usage!==`false`!==d)){let e=setTimeout(()=>{A.mutate()},500);return()=>clearTimeout(e)}},[r,a,s,l,d,h]);let A=J({mutationFn:()=>Q.updateSpoolmanSettings({spoolman_enabled:r?`true`:`false`,spoolman_url:a,spoolman_sync_mode:s,spoolman_disable_weight_sync:l?`true`:`false`,spoolman_report_partial_usage:d?`true`:`false`}),onSuccess:()=>{t.invalidateQueries({queryKey:[`spoolman-settings`]}),t.invalidateQueries({queryKey:[`spoolman-status`]}),t.invalidateQueries({queryKey:[`spool-assignments`]}),t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`spoolman-inventory-filaments`]}),n(e(`settings.toast.settingsSaved`))},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),j=J({mutationFn:Q.connectSpoolman,onSuccess:()=>{O()},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),M=J({mutationFn:Q.disconnectSpoolman,onSuccess:()=>{O()},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),N=J({mutationFn:Q.syncAllPrintersAms,onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),P=J({mutationFn:e=>Q.syncPrinterAms(e),onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),F=()=>{p===`all`?N.mutate():P.mutate(p)},I=J({mutationFn:Q.syncWeightsFromAms,onSuccess:r=>{t.invalidateQueries({queryKey:[`spools`]}),t.invalidateQueries({queryKey:[`inventory-spools`]}),n(e(`settings.amsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),x(!1)},onError:()=>{n(e(`settings.amsSyncError`),`error`),x(!1)}}),L=J({mutationFn:Q.syncSpoolmanAmsWeights,onSuccess:r=>{t.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),n(e(`settings.spoolmanAmsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),C(!1)},onError:t=>{t instanceof zu&&t.status===503?n(e(`settings.spoolmanAmsSyncErrorUnreachable`),`error`):t instanceof zu&&t.status===400?n(e(`settings.spoolmanAmsSyncErrorNotConfigured`),`error`):n(e(`settings.spoolmanAmsSyncError`),`error`),C(!1)}}),R=N.isPending||P.isPending,z=p===`all`?N.data:P.data,B=p===`all`?N.isSuccess:P.isSuccess;return T?(0,K.jsxs)(pd,{id:`card-spoolman`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(js,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]})}),(0,K.jsx)(hd,{children:(0,K.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})})})]}):(0,K.jsxs)(pd,{id:`card-spoolman`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(js,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]}),A.isPending&&(0,K.jsx)(X,{className:`w-4 h-4 text-bambu-green animate-spin`})]})}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.filamentTrackingDesc`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>i(!1),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`:`border-bambu-green bg-bambu-green/10`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,K.jsx)(cl,{className:`w-4 h-4 ${r?`text-bambu-gray`:`text-bambu-green`}`}),(0,K.jsx)(`span`,{className:`text-sm font-medium ${r?`text-bambu-gray`:`text-white`}`,children:e(`settings.trackingModeBuiltIn`)})]}),(0,K.jsx)(`p`,{className:`text-xs ${r?`text-bambu-gray/60`:`text-bambu-gray`}`,children:e(`settings.trackingModeBuiltInDesc`)}),!r&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,K.jsx)($o,{className:`w-3 h-3 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,K.jsx)(Us,{className:`w-4 h-4 ${r?`text-bambu-green`:`text-bambu-gray`}`}),(0,K.jsx)(`span`,{className:`text-sm font-medium ${r?`text-white`:`text-bambu-gray`}`,children:`Spoolman`})]}),(0,K.jsx)(`p`,{className:`text-xs ${r?`text-bambu-gray`:`text-bambu-gray/60`}`,children:e(`settings.trackingModeSpoolmanDesc`)}),r&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,K.jsx)($o,{className:`w-3 h-3 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]})]}),!r&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`div`,{className:`p-3 bg-bambu-green/5 border border-bambu-green/20 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(kc,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-0.5`}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,K.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:[(0,K.jsx)(`li`,{children:e(`settings.builtInFeatureRfid`)}),(0,K.jsx)(`li`,{children:e(`settings.builtInFeatureUsage`)}),(0,K.jsx)(`li`,{children:e(`settings.builtInFeatureCatalog`)}),(0,K.jsx)(`li`,{children:e(`settings.builtInFeatureThirdParty`)})]})})]})}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>x(!0),disabled:I.isPending,children:[I.isPending?(0,K.jsx)(X,{className:`w-4 h-4 mr-2 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4 mr-2`}),e(`settings.amsSyncButton`)]})]}),r&&(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`div`,{className:`p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(kc,{className:`w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`text-xs text-blue-300`,children:[(0,K.jsx)(`p`,{className:`font-medium mb-1`,children:e(`settings.howSyncWorks`)}),(0,K.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5 text-blue-300/80`,children:[(0,K.jsx)(`li`,{children:e(`settings.syncInfoRfidOnly`)}),(0,K.jsx)(`li`,{children:e(`settings.syncInfoAutoCreate`)}),(0,K.jsx)(`li`,{children:e(`settings.syncInfoThirdPartySkipped`)})]}),(0,K.jsx)(`p`,{className:`font-medium mt-2 mb-1`,children:e(`settings.linkingExistingSpools`)}),(0,K.jsx)(`p`,{className:`text-blue-300/80`,children:e(`settings.linkingExistingSpoolsDesc`)})]})]})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.spoolmanUrl`)}),(0,K.jsx)(`input`,{type:`text`,placeholder:`http://192.168.1.100:7912`,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 placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.spoolmanUrlHint`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.syncMode`)}),(0,K.jsxs)(`select`,{value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`auto`,children:e(`settings.syncModeAuto`)}),(0,K.jsx)(`option`,{value:`manual`,children:e(`settings.syncModeManual`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(s===`auto`?`settings.syncModeAutoDesc`:`settings.syncModeManualDesc`)})]}),s===`auto`&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:e(`spoolman.disableWeightSync`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.disableWeightSyncDesc`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),l&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:e(`spoolman.reportPartialUsage`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.reportPartialUsageDesc`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`settings.status`),`:`]}),D?(0,K.jsx)(X,{className:`w-4 h-4 text-bambu-gray animate-spin`}):E?.connected?(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-green-500`,children:[(0,K.jsx)($o,{className:`w-4 h-4`}),e(`settings.spoolmanConnected`)]}):(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-red-500`,children:[(0,K.jsx)(Pu,{className:`w-4 h-4`}),e(`settings.spoolmanDisconnected`)]})]}),(0,K.jsx)(`div`,{className:`flex gap-2`,children:E?.connected?(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>M.mutate(),disabled:M.isPending,children:[M.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Fc,{className:`w-4 h-4`}),e(`settings.disconnect`)]}):(0,K.jsxs)($,{size:`sm`,onClick:()=>j.mutate(),disabled:j.isPending||!a,children:[j.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Ic,{className:`w-4 h-4`}),e(`settings.connect`)]})})]}),(j.isError||M.isError)&&(0,K.jsx)(`div`,{className:`mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400`,children:(j.error||M.error).message}),E?.connected&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.syncAmsData`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.syncAmsDataDesc`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value===`all`?`all`:Number(e.target.value)),className:`w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,K.jsx)(`option`,{value:`all`,children:e(`settings.allPrinters`)}),k?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,K.jsx)(es,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:F,disabled:R,children:[R?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),e(`spoolman.sync`)]})]})]}),E?.connected&&(0,K.jsx)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.spoolmanAmsSyncButton`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.spoolmanAmsSyncMessage`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>C(!0),disabled:L.isPending,children:[L.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),L.isPending?e(`settings.spoolmanAmsSyncing`):e(`settings.spoolmanAmsSyncButton`)]})]})}),B&&z&&(0,K.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded text-sm ${z.success?`bg-green-500/20 border border-green-500/50 text-green-400`:`bg-yellow-500/20 border border-yellow-500/50 text-yellow-400`}`,children:z.success?`Synced ${z.synced_count} spool${z.synced_count===1?``:`s`} successfully`:`Synced ${z.synced_count} spool${z.synced_count===1?``:`s`} with ${z.errors.length} error${z.errors.length===1?``:`s`}`}),z.skipped_count>0&&(0,K.jsxs)(`div`,{className:`p-2 bg-amber-500/10 border border-amber-500/30 rounded text-sm`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-amber-400 mb-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(vu,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{className:`font-medium`,children:[z.skipped_count,` spool`,z.skipped_count===1?``:`s`,` skipped`]})]}),z.skipped_count>5&&(0,K.jsx)(`button`,{onClick:()=>v(!_),className:`text-xs text-amber-400 hover:text-amber-300 underline`,children:_?`Show less`:`Show all`})]}),(0,K.jsxs)(`ul`,{className:`text-xs text-amber-300/80 space-y-0.5`,children:[(_?z.skipped:z.skipped.slice(0,5)).map((e,t)=>(0,K.jsxs)(`li`,{className:`flex items-center gap-2`,children:[e.color&&(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:`#${e.color}`}}),(0,K.jsx)(`span`,{children:e.location}),(0,K.jsxs)(`span`,{className:`text-amber-300/60`,children:[`- `,e.reason]})]},t)),!_&&z.skipped_count>5&&(0,K.jsxs)(`li`,{className:`text-amber-300/60 italic`,children:[`...and `,z.skipped_count-5,` more`]})]})]}),z.errors.length>0&&(0,K.jsxs)(`div`,{className:`p-2 bg-red-500/10 border border-red-500/30 rounded text-sm`,children:[(0,K.jsx)(`div`,{className:`text-red-400 font-medium mb-1`,children:`Errors:`}),(0,K.jsx)(`ul`,{className:`text-xs text-red-300/80 space-y-0.5`,children:z.errors.map((e,t)=>(0,K.jsx)(`li`,{children:e},t))})]})]})]})]})]}),b&&(0,K.jsx)(Ed,{title:e(`settings.amsSyncTitle`),message:e(`settings.amsSyncMessage`),confirmText:e(`settings.amsSyncButton`),variant:`warning`,isLoading:I.isPending,loadingText:e(`settings.amsSyncing`),onConfirm:()=>I.mutate(),onCancel:()=>x(!1)}),S&&(0,K.jsx)(Ed,{title:e(`settings.spoolmanAmsSyncTitle`),message:e(`settings.spoolmanAmsSyncMessage`),confirmText:e(`settings.spoolmanAmsSyncButton`),variant:`warning`,isLoading:L.isPending,loadingText:e(`settings.spoolmanAmsSyncing`),onConfirm:()=>L.mutate(),onCancel:()=>C(!1)})]})}function JRe(){let{t:e}=G(),{showToast:t}=xd(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(``),c=(0,y.useRef)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(new Set),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(null),[E,D]=(0,y.useState)(!1),O=(0,y.useCallback)(async()=>{try{r(await Q.getSpoolCatalog())}catch(n){console.error(`SpoolCatalogSettings.loadCatalog failed:`,n),t(e(`settings.catalog.loadFailed`),`error`)}finally{a(!1)}},[t,e]);(0,y.useEffect)(()=>{O()},[O]);let k=n.filter(e=>e.name.toLowerCase().includes(o.toLowerCase())),A=async()=>{if(!p.trim()||!h){t(e(`settings.catalog.nameWeightRequired`),`error`);return}v(!0);try{let n=await Q.addCatalogEntry({name:p.trim(),weight:parseInt(h)});r(e=>[...e,n].sort((e,t)=>e.name.localeCompare(t.name))),u(!1),m(``),g(``),t(e(`settings.catalog.entryAdded`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleAdd failed:`,n),t(e(`settings.catalog.addFailed`),`error`)}finally{v(!1)}},j=e=>{f(e.id),m(e.name),g(e.weight.toString())},M=()=>{f(null),m(``),g(``)},N=async n=>{if(!p.trim()||!h){t(e(`settings.catalog.nameWeightRequired`),`error`);return}v(!0);try{let i=await Q.updateCatalogEntry(n,{name:p.trim(),weight:parseInt(h)});r(e=>e.map(e=>e.id===n?i:e).sort((e,t)=>e.name.localeCompare(t.name))),f(null),m(``),g(``),t(e(`settings.catalog.entryUpdated`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleUpdate failed:`,n),t(e(`settings.catalog.updateFailed`),`error`)}finally{v(!1)}},P=async()=>{if(w)try{await Q.deleteCatalogEntry(w.id),r(e=>e.filter(e=>e.id!==w.id)),t(e(`settings.catalog.entryDeleted`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleDelete failed:`,n),t(e(`settings.catalog.deleteFailed`),`error`)}finally{T(null)}},F=async()=>{D(!1),a(!0);try{await Q.resetSpoolCatalog(),await O(),t(e(`settings.catalog.resetSuccess`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleReset failed:`,n),t(e(`settings.catalog.resetFailed`),`error`),a(!1)}},I=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,K.jsxs)(pd,{id:`card-spool-catalog`,children:[(0,K.jsxs)(md,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,K.jsx)(js,{className:`w-5 h-5 text-bambu-gray`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.catalog.spoolCatalog`)}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,n.length,`)`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.jsxs)(`button`,{onClick:()=>{let r=n.map(({name:e,weight:t})=>({name:e,weight:t})),i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`spool-catalog.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),t(e(`settings.catalog.exported`,{count:n.length}),`success`)},className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.exportTooltip`),children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.export`)})]}),(0,K.jsxs)(`button`,{onClick:()=>c.current?.click(),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.importTooltip`),children:[(0,K.jsx)(Su,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.import`)})]}),(0,K.jsx)(`input`,{ref:c,type:`file`,accept:`.json`,className:`hidden`,onChange:async i=>{let a=i.target.files?.[0];if(a){try{let i=await a.text(),o=JSON.parse(i);if(!Array.isArray(o))throw Error(`Invalid format`);let s=0,c=0;for(let e of o){if(!e.name||typeof e.weight!=`number`){c++;continue}if(n.some(t=>t.name.toLowerCase()===e.name.toLowerCase())){c++;continue}try{let t=await Q.addCatalogEntry({name:e.name,weight:e.weight});r(e=>[...e,t].sort((e,t)=>e.name.localeCompare(t.name))),s++}catch(e){console.error(`SpoolCatalogSettings import item failed:`,e),c++}}t(e(`settings.catalog.imported`,{added:s,skipped:c}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleImport failed:`,n),t(e(`settings.catalog.importFailed`),`error`)}c.current&&(c.current.value=``)}}}),(0,K.jsxs)(`button`,{onClick:()=>D(!0),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.resetTooltip`),children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.reset`)})]}),(0,K.jsxs)(`button`,{onClick:()=>u(!0),className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.add`)})]})]}),b.size>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg`,children:[(0,K.jsx)(`span`,{className:`text-sm text-red-400`,children:e(`settings.catalog.selectedCount`,{count:b.size})}),(0,K.jsxs)(`button`,{onClick:()=>C(!0),className:`ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5`,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`settings.catalog.deleteSelected`)]}),(0,K.jsx)(`button`,{onClick:()=>x(new Set),className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors`,children:e(`common.cancel`)})]})]}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.catalog.spoolCatalogDescription`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.catalog.searchCatalog`),value:o,onChange:e=>s(e.target.value)})]}),l&&(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e(`settings.catalog.addNewEntry`)}),(0,K.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,K.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.catalog.namePlaceholder`),value:p,onChange:e=>m(e.target.value)})}),(0,K.jsx)(`input`,{type:`number`,className:`w-20 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-center focus:border-bambu-green focus:outline-none`,placeholder:`g`,value:h,onChange:e=>g(e.target.value)}),(0,K.jsx)(`span`,{className:`text-bambu-gray shrink-0`,children:`g`}),(0,K.jsxs)(`button`,{onClick:A,disabled:_,className:`px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center gap-1 shrink-0`,children:[_?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)($o,{className:`w-4 h-4`}),e(`common.add`)]}),(0,K.jsx)(`button`,{onClick:()=>{u(!1),m(``),g(``)},className:`p-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]})]}),i?(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-5 h-5 animate-spin mr-2`}),e(`common.loading`)]}):(0,K.jsx)(`div`,{className:`max-h-[600px] overflow-y-auto border border-bambu-dark-tertiary rounded-lg`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`px-2 py-2 w-10`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:k.length>0&&b.size===k.length,onChange:()=>{b.size===k.length?x(new Set):x(new Set(k.map(e=>e.id)))},className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium`,children:e(`common.name`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-right text-bambu-gray font-medium w-24`,children:e(`settings.catalog.weight`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-center text-bambu-gray font-medium w-20`,children:e(`settings.catalog.type`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 w-24`})]})}),(0,K.jsx)(`tbody`,{children:k.length===0?(0,K.jsx)(`tr`,{children:(0,K.jsx)(`td`,{colSpan:5,className:`px-4 py-8 text-center text-bambu-gray`,children:e(o?`settings.catalog.noMatch`:`settings.catalog.empty`)})}):k.map(t=>(0,K.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${b.has(t.id)?`bg-bambu-dark`:``}`,children:d===t.id?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`td`,{className:`px-2 py-2`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:b.has(t.id),onChange:()=>I(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white focus:border-bambu-green focus:outline-none`,value:p,onChange:e=>m(e.target.value)})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsx)(`input`,{type:`number`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-right focus:border-bambu-green focus:outline-none`,value:h,onChange:e=>g(e.target.value)})}),(0,K.jsx)(`td`,{className:`px-4 py-2 text-center`,children:(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`-`})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>N(t.id),disabled:_,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:_?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)($o,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:M,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`td`,{className:`px-2 py-2`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:b.has(t.id),onChange:()=>I(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,K.jsx)(`td`,{className:`px-4 py-2 text-white`,children:t.name}),(0,K.jsxs)(`td`,{className:`px-4 py-2 text-right font-mono text-white`,children:[t.weight,`g`]}),(0,K.jsx)(`td`,{className:`px-4 py-2 text-center`,children:t.is_default?(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray`,children:e(`settings.catalog.default`)}):(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:e(`settings.catalog.custom`)})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>j(t),className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>T(t),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})})]})},t.id))})]})})]}),w&&(0,K.jsx)(Ed,{title:e(`settings.catalog.deleteEntry`),message:e(`settings.catalog.deleteConfirm`,{name:w.name}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:P,onCancel:()=>T(null)}),S&&(0,K.jsx)(Ed,{title:e(`settings.catalog.deleteSelected`),message:e(`settings.catalog.bulkDeleteConfirm`,{count:b.size}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:async()=>{if(C(!1),b.size!==0)try{let n=await Q.bulkDeleteCatalogEntries([...b]);r(e=>e.filter(e=>!b.has(e.id))),x(new Set),t(e(`settings.catalog.bulkDeleted`,{count:n.deleted}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleBulkDelete failed:`,n),t(e(`settings.catalog.bulkDeleteFailed`),`error`)}},onCancel:()=>C(!1)}),E&&(0,K.jsx)(Ed,{title:e(`settings.catalog.resetCatalog`),message:e(`settings.catalog.resetConfirm`),confirmText:e(`common.reset`),variant:`danger`,onConfirm:F,onCancel:()=>D(!1)})]})}var YRe=2166136261,XRe=16777619;function ZRe(...e){let t=YRe,n=new TextEncoder,r=n.encode(`__|`);for(let i of e)typeof i==`string`?t=B5(t,n.encode(i+`|`)):i??(t=B5(t,r));return t>>>0}function B5(e,t){for(let n of t)e^=n,e=Math.imul(e,XRe)>>>0;return e}function QRe(e){let t=()=>{e|=0,e=e+1831565813|0;let t=Math.imul(e^e>>>15,1|e);return t=t+Math.imul(t^t>>>7,61|t)^t,(t^t>>>14)>>>0},n=(e,n)=>{if(!Number.isFinite(e)||!Number.isFinite(n))throw RangeError(`from and to must be finite numbers`);if(e>n)throw RangeError(`from must be less than or equal to to`);return e===n?e:e+t()/4294967295*(n-e)};return{next:()=>t()/4294967295,floatBetween:(e,t)=>n(e,t),intBetween:(e,t)=>{if(!Number.isInteger(e)||!Number.isInteger(t))throw RangeError(`from and to must be integers`);return Math.round(n(e,t))}}}var V5={table:{dotCount:5,dotScale:1},preview:{dotCount:8,dotScale:1.5},card:{dotCount:40,dotScale:2},bar:{dotCount:20,dotScale:2},groupheader:{dotCount:80,dotScale:2}},H5=[{value:``,labelKey:`inventory.colorEffect.none`},{value:`sparkle`,labelKey:`inventory.colorEffect.sparkle`},{value:`wood`,labelKey:`inventory.colorEffect.wood`},{value:`marble`,labelKey:`inventory.colorEffect.marble`},{value:`glow`,labelKey:`inventory.colorEffect.glow`},{value:`matte`,labelKey:`inventory.colorEffect.matte`},{value:`silk`,labelKey:`inventory.colorEffect.silk`},{value:`galaxy`,labelKey:`inventory.colorEffect.galaxy`},{value:`rainbow`,labelKey:`inventory.colorEffect.rainbow`},{value:`metal`,labelKey:`inventory.colorEffect.metal`},{value:`translucent`,labelKey:`inventory.colorEffect.translucent`},{value:`gradient`,labelKey:`inventory.colorEffect.gradient`},{value:`dual-color`,labelKey:`inventory.colorEffect.dualColor`},{value:`tri-color`,labelKey:`inventory.colorEffect.triColor`},{value:`multicolor`,labelKey:`inventory.colorEffect.multicolor`}],$Re=`repeating-conic-gradient(#979797 0% 25%, #f5f5f5 0% 50%)`,eze=`12px 12px`,tze={sparkle:(e=0,t=`table`)=>{let n=QRe(e),r=V5[t]??V5.table,i=[];for(let e=0;e`repeating-linear-gradient(90deg, rgba(0,0,0,0.18) 0 1px, transparent 1px 6px, rgba(0,0,0,0.08) 6px 7px, transparent 7px 12px)`,marble:()=>`repeating-linear-gradient(135deg, rgba(255,255,255,0.18) 0 2px, transparent 2px 8px), repeating-linear-gradient(45deg, rgba(0,0,0,0.10) 0 1px, transparent 1px 7px)`,glow:()=>`radial-gradient(circle at 50% 50%, rgba(255,255,255,0.35) 0%, rgba(255,255,255,0) 70%)`,matte:()=>`linear-gradient(180deg, rgba(0,0,0,0.10) 0%, rgba(0,0,0,0) 50%, rgba(0,0,0,0.10) 100%)`,silk:()=>`linear-gradient(110deg, rgba(255,255,255,0) 30%, rgba(255,255,255,0.30) 50%, rgba(255,255,255,0) 70%)`,galaxy:()=>`linear-gradient(110deg, rgba(255,255,255,0) 25%, rgba(255,255,255,0.40) 50%, rgba(255,255,255,0) 75%)`,metal:()=>`repeating-linear-gradient(90deg, rgba(255,255,255,0.10) 0 1px, transparent 1px 3px), linear-gradient(180deg, rgba(255,255,255,0.18) 0%, rgba(0,0,0,0.18) 100%)`};function U5(e){let t=e.trim().replace(/^#/,``);return t.length!==6&&t.length!==8||!/^[0-9a-fA-F]+$/.test(t)?null:`#${t}`}function W5(e){return e?e.split(`,`).map(e=>U5(e)).filter(e=>!!e):[]}function nze(e,t,n,r){let i=e?U5(e):null;if(t.length===0)return`linear-gradient(${i??`#808080`}, ${i??`#808080`})`;let a=t.length===1?[t[0],t[0]]:t,o=(n??``).toLowerCase(),s=(r??``).toLowerCase();if(o===`multicolor`||s===`multicolor`){let e=a.length;return`conic-gradient(from 0deg, ${a.map((t,n)=>`${t} ${(n/e*360).toFixed(3)}deg ${((n+1)/e*360).toFixed(3)}deg`).join(`, `)})`}if(s===`dual-color`||s===`tri-color`){let e=a.length;return`linear-gradient(to right, ${a.map((t,n)=>`${t} ${(n/e*100).toFixed(3)}% ${((n+1)/e*100).toFixed(3)}%`).join(`, `)})`}return`linear-gradient(135deg, ${a.join(`, `)})`}function rze(e,t,n){let r=tze[e];return r?r(n,t):null}function G5(e){let t=W5(e.extraColors),n=nze(e.rgba,t,e.subtype,e.effectType),r=ZRe(e.rgba,e.extraColors,e.subtype,e.effectType),i=typeof e.effectType==`string`?rze(e.effectType,e.effectSize,r):null,a=[];return i&&(Array.isArray(i)?i:[i]).forEach(e=>{a.push({image:e,size:`cover`})}),a.push({image:n,size:`cover`}),a.push({image:$Re,size:eze}),{backgroundImage:a.map(e=>e.image).join(`, `),backgroundSize:a.map(e=>e.size).join(`, `)}}function K5({rgba:e,extraColors:t,effectType:n,subtype:r,className:i=`w-5 h-5`,shape:a=`circle`,style:o,title:s,effectSize:c}){let l=(0,y.useMemo)(()=>W5(t),[t]),u=(0,y.useMemo)(()=>G5({effectSize:c,rgba:e,extraColors:t,effectType:n,subtype:r}),[c,e,t,n,r]),d=u.backgroundImage,f=u.backgroundSize,p=a===`circle`||a===`pill`?`rounded-full`:`rounded`,m=(()=>{if(!e)return;let t=e.replace(/^#/,``);return t.length>=8&&t.substring(6,8).toLowerCase()!==`ff`?`#${t.substring(0,8)}`:`#${t.substring(0,6)}`})(),h=s??(l.length>0?l.join(`, `):m);return(0,K.jsx)(`span`,{"data-testid":`filament-swatch`,className:`${i} ${p} border border-black/20 inline-block flex-shrink-0`,style:{backgroundImage:d,backgroundSize:f,...o},title:h})}function ize(){let{t:e}=G(),{showToast:t}=xd(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),u=(0,y.useRef)(null),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(`#FFFFFF`),[S,C]=(0,y.useState)(``),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(``),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(new Set),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(null),[B,V]=(0,y.useState)(!1),ee=(0,y.useCallback)(async()=>{try{r(await Q.getColorCatalog())}catch{t(e(`settings.colorCatalog.loadFailed`),`error`)}finally{a(!1)}},[t,e]);(0,y.useEffect)(()=>{ee()},[ee]);let H=[...new Set(n.map(e=>e.manufacturer))].sort(),te=n.filter(e=>{let t=o===``||e.manufacturer.toLowerCase().includes(o.toLowerCase())||e.color_name.toLowerCase().includes(o.toLowerCase())||(e.material?.toLowerCase().includes(o.toLowerCase())??!1),n=c===``||e.manufacturer===c;return t&&n}),ne=()=>{g(``),v(``),x(`#FFFFFF`),C(``),T(``),D(``)},re=async()=>{if(!h.trim()||!_.trim()||!b){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}k(!0);try{let n=await Q.addColorEntry({manufacturer:h.trim(),color_name:_.trim(),hex_color:b,material:S.trim()||null,extra_colors:w.trim()||null,effect_type:E.trim()||null});r(e=>[...e,n].sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),f(!1),ne(),t(e(`settings.colorCatalog.colorAdded`),`success`)}catch{t(e(`settings.colorCatalog.addFailed`),`error`)}finally{k(!1)}},U=e=>{m(e.id),g(e.manufacturer),v(e.color_name),x(e.hex_color),C(e.material||``),T(e.extra_colors||``),D(e.effect_type||``)},ie=()=>{m(null),ne()},ae=async n=>{if(!h.trim()||!_.trim()||!b){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}k(!0);try{let i=await Q.updateColorEntry(n,{manufacturer:h.trim(),color_name:_.trim(),hex_color:b,material:S.trim()||null,extra_colors:w.trim()||null,effect_type:E.trim()||null});r(e=>e.map(e=>e.id===n?i:e).sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),m(null),ne(),t(e(`settings.colorCatalog.colorUpdated`),`success`)}catch{t(e(`settings.colorCatalog.updateFailed`),`error`)}finally{k(!1)}},W=async()=>{if(R)try{await Q.deleteColorEntry(R.id),r(e=>e.filter(e=>e.id!==R.id)),t(e(`settings.colorCatalog.colorDeleted`),`success`)}catch{t(e(`settings.colorCatalog.deleteFailed`),`error`)}finally{z(null)}},oe=async()=>{V(!1),a(!0);try{await Q.resetColorCatalog(),await ee(),t(e(`settings.colorCatalog.resetSuccess`),`success`)}catch{t(e(`settings.colorCatalog.resetFailed`),`error`),a(!1)}},se=async()=>{F(!0),L(null);try{let n={},r=Hu();r&&(n.Authorization=`Bearer ${r}`);let i=await fetch(`/api/v1/inventory/colors/sync`,{method:`POST`,headers:n});if(!i.ok)throw Error(`Failed to start sync`);let a=i.body?.getReader();if(!a)throw Error(`No response body`);let o=new TextDecoder,s=``;for(;;){let{done:n,value:r}=await a.read();if(n)break;s+=o.decode(r,{stream:!0});let i=s.split(` +`);s=i.pop()||``;for(let n of i)if(n.startsWith(`data: `))try{let r=JSON.parse(n.slice(6));r.type===`progress`?L({fetched:r.total_fetched,total:r.total_available}):r.type===`complete`?r.added===0?t(e(`settings.colorCatalog.syncUpToDate`,{count:r.total_fetched}),`success`):t(e(`settings.colorCatalog.syncComplete`,{added:r.added,skipped:r.skipped}),`success`):r.type===`error`&&t(`${e(`settings.colorCatalog.syncError`)}: ${r.error}`,`error`)}catch{}}await ee()}catch{t(e(`settings.colorCatalog.syncFailed`),`error`)}finally{F(!1),L(null)}},ce=e=>{j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,K.jsxs)(pd,{id:`card-color-catalog`,children:[(0,K.jsxs)(md,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,K.jsx)(ll,{className:`w-5 h-5 text-bambu-gray`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.colorCatalog.title`)}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,n.length,`)`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.jsxs)(`button`,{onClick:()=>{let r=n.map(({manufacturer:e,color_name:t,hex_color:n,material:r,extra_colors:i,effect_type:a})=>({manufacturer:e,color_name:t,hex_color:n,material:r,extra_colors:i,effect_type:a})),i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`color-catalog.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),t(e(`settings.colorCatalog.exported`,{count:n.length}),`success`)},className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.export`)})]}),(0,K.jsxs)(`button`,{onClick:()=>u.current?.click(),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,K.jsx)(Su,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.import`)})]}),(0,K.jsx)(`input`,{ref:u,type:`file`,accept:`.json`,className:`hidden`,onChange:async i=>{let a=i.target.files?.[0];if(a){try{let i=await a.text(),o=JSON.parse(i);if(!Array.isArray(o))throw Error(`Invalid format`);let s=0,c=0;for(let e of o){if(!e.manufacturer||!e.color_name||!e.hex_color){c++;continue}if(n.some(t=>t.manufacturer.toLowerCase()===e.manufacturer.toLowerCase()&&t.color_name.toLowerCase()===e.color_name.toLowerCase()&&(t.material||``).toLowerCase()===(e.material||``).toLowerCase())){c++;continue}try{let t=await Q.addColorEntry({manufacturer:e.manufacturer,color_name:e.color_name,hex_color:e.hex_color,material:e.material||null,extra_colors:e.extra_colors||null,effect_type:e.effect_type||null});r(e=>[...e,t].sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),s++}catch{c++}}t(e(`settings.colorCatalog.imported`,{added:s,skipped:c}),`success`)}catch{t(e(`settings.colorCatalog.importFailed`),`error`)}u.current&&(u.current.value=``)}}}),(0,K.jsxs)(`button`,{onClick:se,disabled:P,className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.colorCatalog.syncTooltip`),children:[P?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(ys,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:P?I?`${Math.min(I.fetched,I.total)} / ${I.total}`:e(`settings.colorCatalog.starting`):e(`settings.colorCatalog.sync`)})]}),(0,K.jsxs)(`button`,{onClick:()=>V(!0),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.reset`)})]}),(0,K.jsxs)(`button`,{onClick:()=>f(!0),className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.add`)})]})]}),A.size>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg`,children:[(0,K.jsx)(`span`,{className:`text-sm text-red-400`,children:e(`settings.colorCatalog.selectedCount`,{count:A.size})}),(0,K.jsxs)(`button`,{onClick:()=>N(!0),className:`ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5`,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`settings.colorCatalog.deleteSelected`)]}),(0,K.jsx)(`button`,{onClick:()=>j(new Set),className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors`,children:e(`common.cancel`)})]})]}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.colorCatalog.description`)}),(0,K.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1 min-w-[200px]`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.searchColors`),value:o,onChange:e=>s(e.target.value)})]}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:c,onChange:e=>l(e.target.value),children:[(0,K.jsx)(`option`,{value:``,children:e(`settings.colorCatalog.allManufacturers`)}),H.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]})]}),d&&(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e(`settings.colorCatalog.addNewColor`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-2 items-end`,children:[(0,K.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.manufacturer`),value:h,onChange:e=>g(e.target.value)}),(0,K.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.colorName`),value:_,onChange:e=>v(e.target.value)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`color`,className:`w-20 h-10 rounded cursor-pointer border border-bambu-dark-tertiary`,value:b,onChange:e=>x(e.target.value)}),(0,K.jsx)(`input`,{type:`text`,className:`w-32 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:`#FFFFFF`,value:b,onChange:e=>x(e.target.value)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`input`,{type:`text`,className:`flex-1 max-w-lg min-w-[200px] px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.materialOptional`),value:S,onChange:e=>C(e.target.value)}),(0,K.jsxs)(`button`,{onClick:re,disabled:O,className:`w-24 px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center justify-center gap-3`,children:[O?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)($o,{className:`w-4 h-4`}),e(`common.add`)]}),(0,K.jsx)(`button`,{onClick:()=>{f(!1),ne()},className:`p-2 ml-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 mt-2`,children:[(0,K.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`inventory.extraColorsPlaceholder`),value:w,onChange:e=>T(e.target.value)}),(0,K.jsx)(`select`,{className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:E,onChange:e=>D(e.target.value),children:H5.map(t=>(0,K.jsx)(`option`,{value:t.value,children:e(t.labelKey)},t.value||`none`))})]})]}),(o||c)&&(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:e(`settings.colorCatalog.showing`,{filtered:te.length,total:n.length})}),i?(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-5 h-5 animate-spin mr-2`}),e(`common.loading`)]}):(0,K.jsx)(`div`,{className:`max-h-[600px] overflow-auto border border-bambu-dark-tertiary rounded-lg`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`px-2 py-2 w-10`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:te.length>0&&A.size===te.length,onChange:()=>{A.size===te.length?j(new Set):j(new Set(te.map(e=>e.id)))},className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,K.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium w-12`}),(0,K.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`settings.colorCatalog.manufacturer`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`inventory.material`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`settings.colorCatalog.colorName`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium w-24`,children:e(`settings.colorCatalog.hex`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 w-16`})]})}),(0,K.jsx)(`tbody`,{children:te.length===0?(0,K.jsx)(`tr`,{children:(0,K.jsx)(`td`,{colSpan:7,className:`px-3 py-8 text-center text-bambu-gray`,children:e(o||c?`settings.colorCatalog.noMatch`:`settings.colorCatalog.empty`)})}):te.map(t=>(0,K.jsxs)(y.Fragment,{children:[(0,K.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${A.has(t.id)?`bg-bambu-dark`:``}`,children:p===t.id?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`td`,{className:`px-2 py-2`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:A.has(t.id),onChange:()=>ce(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{type:`color`,className:`w-8 h-8 rounded cursor-pointer border border-bambu-dark-tertiary`,value:b,onChange:e=>x(e.target.value)})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:h,onChange:e=>g(e.target.value)})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:S,onChange:e=>C(e.target.value)})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:_,onChange:e=>v(e.target.value)})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:b,onChange:e=>x(e.target.value)})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>ae(t.id),disabled:O,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:O?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)($o,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:ie,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`td`,{className:`px-2 py-2`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:A.has(t.id),onChange:()=>ce(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(K5,{rgba:t.hex_color.replace(/^#/,``)+(t.hex_color.length===7?`FF`:``),extraColors:t.extra_colors,effectType:t.effect_type,className:`w-8 h-8`,shape:`square`,title:t.hex_color,effectSize:`table`})}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-white`,children:t.manufacturer}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:t.material||`-`}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-white`,children:t.color_name}),(0,K.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs text-bambu-gray`,children:t.hex_color}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>U(t),className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>z(t),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})})]})}),p===t.id&&(0,K.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary/50 bg-bambu-dark`,children:[(0,K.jsx)(`td`,{colSpan:2}),(0,K.jsx)(`td`,{className:`px-3 py-2`,colSpan:2,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`,placeholder:e(`inventory.extraColorsPlaceholder`),value:w,onChange:e=>T(e.target.value)})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,colSpan:2,children:(0,K.jsx)(`select`,{className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:E,onChange:e=>D(e.target.value),children:H5.map(t=>(0,K.jsx)(`option`,{value:t.value,children:e(t.labelKey)},t.value||`none`))})}),(0,K.jsx)(`td`,{})]})]},t.id))})]})})]}),R&&(0,K.jsx)(Ed,{title:e(`settings.colorCatalog.deleteColor`),message:e(`settings.colorCatalog.deleteConfirm`,{name:`${R.manufacturer} - ${R.color_name}`}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:W,onCancel:()=>z(null)}),M&&(0,K.jsx)(Ed,{title:e(`settings.colorCatalog.deleteSelected`),message:e(`settings.colorCatalog.bulkDeleteConfirm`,{count:A.size}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:async()=>{if(N(!1),A.size!==0)try{let n=await Q.bulkDeleteColorEntries([...A]);r(e=>e.filter(e=>!A.has(e.id))),j(new Set),t(e(`settings.colorCatalog.bulkDeleted`,{count:n.deleted}),`success`)}catch{t(e(`settings.colorCatalog.bulkDeleteFailed`),`error`)}},onCancel:()=>N(!1)}),B&&(0,K.jsx)(Ed,{title:e(`settings.colorCatalog.resetCatalog`),message:e(`settings.colorCatalog.resetConfirm`),confirmText:e(`common.reset`),variant:`danger`,onConfirm:oe,onCancel:()=>V(!1)})]})}function aze({link:e,onClose:t}){let{t:n}=G(),r=Qa(),i=!!e,a=(0,y.useRef)(null),[o,s]=(0,y.useState)(e?.name||``),[c,l]=(0,y.useState)(e?.url||``),[u,d]=(0,y.useState)(e?.icon||`link`),[f,p]=(0,y.useState)(e?.open_in_new_tab||!1),[m,h]=(0,y.useState)(!!e?.custom_icon),[g,_]=(0,y.useState)(e?.custom_icon?Q.getExternalLinkIconUrl(e.id):null),[v,b]=(0,y.useState)(null),[x,S]=(0,y.useState)(null);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let C=J({mutationFn:async e=>{let t=await Q.createExternalLink(e);return v?await Q.uploadExternalLinkIcon(t.id,v):t},onSuccess:()=>{r.invalidateQueries({queryKey:[`external-links`]}),t()},onError:e=>{S(e.message)}}),w=J({mutationFn:async t=>{let n=await Q.updateExternalLink(e.id,t);return v?n=await Q.uploadExternalLinkIcon(e.id,v):!m&&e?.custom_icon&&(n=await Q.deleteExternalLinkIcon(e.id)),n},onSuccess:()=>{r.invalidateQueries({queryKey:[`external-links`]}),t()},onError:e=>{S(e.message)}}),T=e=>{let t=e.target.files?.[0];if(t){if(![`image/png`,`image/jpeg`,`image/gif`,`image/svg+xml`,`image/webp`,`image/x-icon`].includes(t.type)){S(`Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)`);return}if(t.size>1024*1024){S(`Image file must be less than 1MB`);return}b(t),h(!0);let e=new FileReader;e.onload=e=>{_(e.target?.result)},e.readAsDataURL(t)}},E=()=>{b(null),_(null),h(!1),a.current&&(a.current.value=``)},D=e=>{if(e.preventDefault(),S(null),!o.trim()){S(`Name is required`);return}if(!c.trim()){S(`URL is required`);return}if(!c.startsWith(`http://`)&&!c.startsWith(`https://`)){S(`URL must start with http:// or https://`);return}let t={name:o.trim(),url:c.trim(),icon:u,open_in_new_tab:f};i?w.mutate(t):C.mutate(t)},O=C.isPending||w.isPending,k=Ad(u);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`,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-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:m&&g?(0,K.jsx)(`img`,{src:g,alt:``,className:`w-5 h-5 rounded`}):(0,K.jsx)(k,{className:`w-5 h-5`})}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i?`Edit Link`:`Add External Link`})]}),(0,K.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`form`,{onSubmit:D,className:`p-6 space-y-4`,children:[x&&(0,K.jsx)(`div`,{className:`p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400`,children:x}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Name *`}),(0,K.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`My Link`,maxLength:50,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`URL *`}),(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`https://example.com`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`label`,{className:`text-sm text-bambu-gray`,children:n(`externalLinks.openInNewTab`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>p(!f),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${f?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${f?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray`,children:`Icon`}),(0,K.jsxs)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:`Custom Icon`}),(0,K.jsx)(`input`,{ref:a,type:`file`,accept:`image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon`,className:`hidden`,onChange:T}),m&&g?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`img`,{src:g,alt:`Custom icon`,className:`w-8 h-8 rounded border border-bambu-dark-tertiary`}),(0,K.jsx)(`button`,{type:`button`,onClick:E,className:`p-1 text-red-400 hover:text-red-300 transition-colors`,title:`Remove custom icon`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]}):(0,K.jsxs)($,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>a.current?.click(),children:[(0,K.jsx)(Su,{className:`w-4 h-4`}),`Upload`]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:`PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB.`})]}),!m&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray block mb-2`,children:`Or choose a preset icon`}),(0,K.jsx)(jd,{value:u,onChange:d})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:`Cancel`}),(0,K.jsxs)($,{type:`submit`,disabled:O,className:`flex-1`,children:[O?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Ol,{className:`w-4 h-4`}),i?`Save`:`Add`]})]})]})]})})}function oze(){let{t:e}=G(),t=Qa(),{authEnabled:n,hasPermission:r}=sd(),{showToast:i}=xd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(Gf),[_,v]=(0,y.useState)(()=>Uf(qf.map(e=>e.id))),{data:b,isLoading:x}=q({queryKey:[`external-links`],queryFn:Q.getExternalLinks}),S=J({mutationFn:e=>Q.deleteExternalLink(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`external-links`]})}}),{data:C}=q({queryKey:[`settings`],queryFn:Q.getSettings,enabled:n&&r(`settings:update`)}),w=J({mutationFn:e=>Q.updateSettings({default_sidebar_order:e}),onSuccess:(n,r)=>{t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`default-sidebar-order`]}),i(e(r?`settings.sidebarDefaultSet`:`settings.sidebarDefaultCleared`),`success`)},onError:()=>{i(e(`settings.sidebarDefaultFailed`),`error`)}}),T=(0,y.useMemo)(()=>{let e=new Map(qf.map(e=>[e.id,e])),t=new Map((b||[]).map(e=>[`ext-${e.id}`,e])),n=[],r=new Set,i=i=>{if(r.has(i))return;let a=e.get(i);if(a){n.push({type:`system`,id:i,navItem:a}),r.add(i);return}let o=t.get(i);o&&(n.push({type:`external`,id:i,link:o}),r.add(i))};return _.forEach(i),qf.forEach(e=>i(e.id)),(b||[]).forEach(e=>i(`ext-${e.id}`)),n},[b,_]),E=e=>{v(e),Wf(e)},D=(e,t)=>{f(t),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},O=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`,m(t)},k=(e,t)=>{if(e.preventDefault(),d===null||d===t){f(null),m(null);return}let n=T.map(e=>e.id),r=n.indexOf(d),i=n.indexOf(t);if(r===-1||i===-1){f(null),m(null);return}n.splice(r,1),n.splice(i,0,d),E(n),f(null),m(null)},A=()=>{f(null),m(null)},j=e=>{u(e)},M=()=>{l&&(S.mutate(l.id),u(null))},N=()=>{let e=[...qf.map(e=>e.id),...(b||[]).map(e=>`ext-${e.id}`)];g([]),v(e),Kf([]),Wf(e)},P=e=>{let t=T.map(e=>e.id);w.mutate(e?JSON.stringify({order:t,hiddenSystemItemIds:h}):``)},F=e=>{if(e===`settings`)return;let t=h.includes(e)?h.filter(t=>t!==e):[...h,e];g(t),Kf(t)},I=n&&r(`settings:update`),L=!!C?.default_sidebar_order;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(pd,{id:`card-sidebar-links`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-y-2 gap-x-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Ic,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`externalLinks.sidebarLayout`)})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[I&&(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:e(`settings.setDefault`)}),(0,K.jsx)(y5,{checked:L,onChange:P,disabled:w.isPending})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:N,className:`whitespace-nowrap`,children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),e(`settings.reset`)]}),(0,K.jsxs)($,{size:`sm`,onClick:()=>o(!0),className:`whitespace-nowrap`,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),`Add Link`]})]})]})}),(0,K.jsxs)(hd,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`externalLinks.sidebarLayoutDescription`)}),x?(0,K.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})}):(0,K.jsx)(`div`,{className:`space-y-2`,children:T.map(t=>{let n=t.type===`system`&&h.includes(t.id),r=t.id===`settings`;if(t.type===`system`){let i=t.navItem.icon;return(0,K.jsxs)(`div`,{draggable:!0,onDragStart:e=>D(e,t.id),onDragOver:e=>O(e,t.id),onDragLeave:()=>m(null),onDrop:e=>k(e,t.id),onDragEnd:A,className:`relative flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${d===t.id?`opacity-50`:n?`opacity-60`:``} ${p===t.id&&d!==t.id?`before:absolute before:left-3 before:right-3 before:top-0 before:h-0.5 before:bg-bambu-green`:``}`,children:[(0,K.jsx)(gc,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0`}),(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray`,children:(0,K.jsx)(i,{className:`w-4 h-4`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`span`,{className:`text-white font-medium truncate block`,children:e(t.navItem.labelKey)}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray truncate block`,children:e(r?`externalLinks.requiredInSidebar`:n?`externalLinks.hiddenFromSidebar`:`externalLinks.visibleInSidebar`)})]}),(0,K.jsx)(`button`,{onClick:()=>F(t.id),disabled:r,className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors flex-shrink-0 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-bambu-gray`,title:e(r?`externalLinks.settingsCannotBeHidden`:n?`externalLinks.showPage`:`externalLinks.hidePage`),"aria-label":e(r?`externalLinks.settingsCannotBeHidden`:n?`externalLinks.showPage`:`externalLinks.hidePage`),children:n?(0,K.jsx)(Ws,{className:`w-4 h-4`}):(0,K.jsx)(Gs,{className:`w-4 h-4`})})]},t.id)}let i=t.link,a=Ad(i.icon);return(0,K.jsxs)(`div`,{draggable:!0,onDragStart:e=>D(e,t.id),onDragOver:e=>O(e,t.id),onDragLeave:()=>m(null),onDrop:e=>k(e,t.id),onDragEnd:A,className:`relative flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${d===t.id?`opacity-50`:``} ${p===t.id&&d!==t.id?`before:absolute before:left-3 before:right-3 before:top-0 before:h-0.5 before:bg-bambu-green`:``}`,children:[(0,K.jsx)(gc,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0`}),(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray`,children:i.custom_icon?(0,K.jsx)(`img`,{src:Q.getExternalLinkIconUrl(i.id),alt:``,className:`w-4 h-4`}):(0,K.jsx)(a,{className:`w-4 h-4`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-white font-medium truncate`,children:i.name}),(0,K.jsx)(Us,{className:`w-3 h-3 text-bambu-gray flex-shrink-0`})]}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray truncate block`,children:i.url})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,K.jsx)(`button`,{onClick:()=>c(i),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,title:e(`common.edit`),children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>j(i),disabled:S.isPending,className:`p-2 rounded-lg hover:bg-red-500/20 text-bambu-gray hover:text-red-400 transition-colors disabled:opacity-50`,title:e(`externalLinks.deleteLink`),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]},t.id)})})]})]}),(a||s)&&(0,K.jsx)(aze,{link:s,onClose:()=>{o(!1),c(null)}}),l&&(0,K.jsx)(Ed,{title:`Delete Link`,message:`Are you sure you want to delete "${l.name}"? This action cannot be undone.`,confirmText:`Delete`,cancelText:`Cancel`,variant:`danger`,onConfirm:M,onCancel:()=>u(null)})]})}async function q5(e){if(navigator.clipboard&&window.isSecureContext)try{return await navigator.clipboard.writeText(e),!0}catch{}let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{return t.select(),document.execCommand(`copy`)}catch{return!1}finally{t.parentNode&&t.parentNode.removeChild(t)}}function sze(e,t,n=`text/plain`){let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i)}function cze({status:e}){return e===`pass`?(0,K.jsx)(us,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}):e===`fail`?(0,K.jsx)(ms,{className:`w-5 h-5 text-red-400 flex-shrink-0`}):e===`warn`?(0,K.jsx)(vu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}):(0,K.jsx)(fs,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`})}function lze({vpId:e,vpName:t,onClose:n}){let{t:r}=G(),i=J({mutationFn:()=>Qu.diagnose(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,o=a?.overall===`ok`?`bg-bambu-green/10 border-bambu-green/30 text-bambu-green`:a?.overall===`warnings`?`bg-amber-500/10 border-amber-500/30 text-amber-300`:`bg-red-500/10 border-red-500/30 text-red-300`;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 max-h-[85vh]`,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)(ru,{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(`vpDiagnostic.title`,{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)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-6 space-y-4 overflow-y-auto`,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(`vpDiagnostic.running`)})]}),i.isError&&(0,K.jsx)(`div`,{className:`rounded-lg bg-red-500/10 border border-red-500/30 px-4 py-3 text-sm text-red-300`,children:r(`vpDiagnostic.runFailed`,{error:i.error.message})}),a&&(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`ol`,{className:`space-y-2`,children:a.checks.map(e=>{let t=r(`vpDiagnostic.check.${e.id}.${e.status}`,{...e.params,defaultValue:``});return(0,K.jsxs)(`li`,{className:`flex items-start gap-3 bg-bambu-dark rounded-lg px-4 py-2.5 ${e.status===`skip`?`opacity-60`:``}`,children:[(0,K.jsx)(`div`,{className:`mt-0.5`,children:(0,K.jsx)(cze,{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(`vpDiagnostic.check.${e.id}.title`,e.params)}),t&&(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5`,children:t})]})]},e.id)})}),(0,K.jsx)(`div`,{className:`rounded-lg border px-4 py-3 text-sm ${o}`,children:r(`vpDiagnostic.overall.${a.overall}`)})]})]}),(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(`vpDiagnostic.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 J5={archive:`archive`,review:`review`,queue:`queue`,proxy:`proxy`};function Y5(e){return e===`immediate`?`archive`:e===`print_queue`||e===`queue`?`queue`:e===`archive`||e===`review`||e===`proxy`?e:`archive`}function uze({printer:e,models:t}){let{t:n}=G(),r=Qa(),{showToast:i}=xd(),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(e.enabled),[l,u]=(0,y.useState)(e.name),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(Y5(e.mode)),[h,g]=(0,y.useState)(e.target_printer_id),[_,v]=(0,y.useState)(e.bind_ip||``),[b,x]=(0,y.useState)(e.remote_interface_ip||``),[S,C]=(0,y.useState)(e.model||``),[w,T]=(0,y.useState)(e.auto_dispatch??!0),[E,D]=(0,y.useState)(e.queue_force_color_match??!1),[O,k]=(0,y.useState)(e.gcode_injection??!1),[A,j]=(0,y.useState)(e.tailscale_disabled??!0),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(null),[I,L]=(0,y.useState)(!1),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(!1),{data:ee}=q({queryKey:[`tailscale-status`],queryFn:Qu.getTailscaleStatus,enabled:!A,staleTime:6e4}),H=ee?.available?ee.fqdn:``,te=ee?.available?ee.tailscale_ips?.[0]??``:``,ne=async e=>{e.stopPropagation();let t=H;t&&(await q5(t)?(V(!0),i(n(`printers.copied`)),setTimeout(()=>V(!1),2e3)):i(n(`virtualPrinter.toast.copyFailed`),`error`))};(0,y.useEffect)(()=>{P||(c(e.enabled),m(Y5(e.mode)),u(e.name),g(e.target_printer_id),v(e.bind_ip||``),x(e.remote_interface_ip||``),C(e.model||``),T(e.auto_dispatch??!0),D(e.queue_force_color_match??!1),k(e.gcode_injection??!1),j(e.tailscale_disabled??!0))},[e,P]);let{data:re}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:U}=q({queryKey:[`network-interfaces`],queryFn:()=>Q.getNetworkInterfaces().then(e=>e.interfaces)}),ie=J({mutationFn:t=>Qu.update(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`virtual-printers`]}),i(n(`virtualPrinter.toast.updated`)),F(null)},onError:t=>{i(t.message||n(`virtualPrinter.toast.failedToUpdate`),`error`),c(e.enabled),m(Y5(e.mode)),g(e.target_printer_id),v(e.bind_ip||``),j(e.tailscale_disabled??!0),F(null)}}),ae=J({mutationFn:()=>Qu.remove(e.id),onSuccess:()=>{r.invalidateQueries({queryKey:[`virtual-printers`]}),i(n(`virtualPrinter.toast.deleted`)),L(!1)},onError:e=>{i(e.message||n(`virtualPrinter.toast.failedToDelete`),`error`),L(!1)}}),W=t=>{t.stopPropagation();let r=!s;if(r){if(!_){i(n(`virtualPrinter.toast.bindIpRequired`),`error`);return}if(p===`proxy`){if(!h){i(n(`virtualPrinter.toast.targetPrinterRequired`),`error`);return}}else if(!d&&!e.access_code_set){i(n(`virtualPrinter.toast.accessCodeRequired`),`error`);return}}c(r),F(`toggle`),ie.mutate({enabled:r})},oe=()=>{l.trim()&&(F(`name`),ie.mutate({name:l.trim()}))},se=()=>{if(!d){i(n(`virtualPrinter.toast.accessCodeEmpty`),`error`);return}if(d.length!==8){i(n(`virtualPrinter.toast.accessCodeLength`),`error`);return}F(`accessCode`),ie.mutate({access_code:d}),f(``)},ce=e=>{m(e),F(`mode`),ie.mutate({mode:e})},le=e=>{C(e),F(`model`),ie.mutate({model:e})},ue=e=>{let t=me?.access_code,r=re?.find(t=>t.id===e)?.access_code;g(e),F(`targetPrinter`),ie.mutate({target_printer_id:e},{onSuccess:()=>{t&&r&&t!==r&&i(n(`virtualPrinter.toast.targetCodeChangedRebind`),`info`)}})},de=e=>{x(e),F(`remoteInterface`),ie.mutate({remote_interface_ip:e})},fe=e.status?.running||!1,pe=n(`virtualPrinter.mode.${J5[p]||`archive`}`),me=re?.find(e=>e.id===h),he=me?.name,ge=!!h,_e=ge?me?.access_code??``:``;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(pd,{children:[(0,K.jsxs)(`div`,{className:`px-4 py-3 flex items-center gap-3 cursor-pointer select-none`,onClick:()=>o(!a),children:[(0,K.jsx)(`button`,{className:`text-bambu-gray flex-shrink-0`,children:a?(0,K.jsx)(es,{className:`w-4 h-4`}):(0,K.jsx)(ts,{className:`w-4 h-4`})}),(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full flex-shrink-0 ${fe?`bg-green-400 animate-pulse`:`bg-gray-500`}`}),(0,K.jsx)(`span`,{className:`text-white font-medium truncate`,children:e.name}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:pe}),e.model_name&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:e.model_name}),he&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0 truncate`,children:[p===`proxy`&&(0,K.jsx)(Oo,{className:`w-3 h-3 inline mr-1`}),he]}),_&&(0,K.jsx)(`span`,{className:`text-[10px] text-bambu-gray flex-shrink-0 font-mono`,children:_}),b&&(0,K.jsx)(`span`,{className:`text-[10px] text-bambu-gray flex-shrink-0 font-mono`,children:b}),(0,K.jsx)(`div`,{className:`ml-auto flex items-center gap-2 flex-shrink-0`,onClick:e=>e.stopPropagation(),children:(0,K.jsx)(`button`,{onClick:W,disabled:P===`toggle`,className:`relative w-10 h-5 rounded-full transition-colors ${s?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${P===`toggle`?`opacity-50`:``}`,children:(0,K.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${s?`translate-x-5`:``}`})})})]}),a&&(0,K.jsxs)(hd,{className:`pt-0 space-y-4`,children:[(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),onBlur:oe,onKeyDown:e=>e.key===`Enter`&&oe(),className:`flex-1 text-sm text-white bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`button`,{onClick:()=>z(!0),className:`p-1.5 text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:n(`vpDiagnostic.runButton`),children:(0,K.jsx)(ru,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>L(!0),className:`p-1.5 text-bambu-gray hover:text-red-400 transition-colors flex-shrink-0`,title:n(`common.delete`),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 -mt-2`,children:[H&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-green-400/70 min-w-0`,children:[(0,K.jsx)(Bl,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`font-mono text-xs truncate`,children:te?`${te} (${H})`:H}),(0,K.jsx)(`button`,{onClick:ne,className:`p-0.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors flex-shrink-0`,title:n(B?`printers.copied`:`printers.copyToClipboard`),children:B?(0,K.jsx)($o,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,K.jsx)(Ds,{className:`w-3.5 h-3.5`})})]}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-mono ml-auto flex-shrink-0`,children:e.serial})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium mb-2`,children:n(`virtualPrinter.mode.title`)}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:[`archive`,`review`,`queue`,`proxy`].map(e=>(0,K.jsxs)(`button`,{onClick:()=>ce(e),disabled:P===`mode`,className:`p-2 rounded-lg border text-left transition-colors ${p===e?e===`proxy`?`border-blue-500 bg-blue-500/10`:`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-white text-xs font-medium`,children:[e===`proxy`&&(0,K.jsx)(Oo,{className:`w-3 h-3`}),n(`virtualPrinter.mode.${J5[e]}`)]}),(0,K.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.mode.${J5[e]}Desc`)})]},e))})]}),p===`queue`&&(0,K.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.autoDispatch.title`)}),(0,K.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.autoDispatch.description`)})]}),(0,K.jsx)(`button`,{onClick:()=>{let e=!w;T(e),F(`autoDispatch`),ie.mutate({auto_dispatch:e})},disabled:P===`autoDispatch`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${w?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${P===`autoDispatch`?`opacity-50`:``}`,children:(0,K.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${w?`translate-x-5`:``}`})})]})}),p===`queue`&&(0,K.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.queueForceColorMatch.title`)}),(0,K.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.queueForceColorMatch.description`)})]}),(0,K.jsx)(`button`,{onClick:()=>{let e=!E;D(e),F(`queueForceColorMatch`),ie.mutate({queue_force_color_match:e})},disabled:P===`queueForceColorMatch`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${E?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${P===`queueForceColorMatch`?`opacity-50`:``}`,children:(0,K.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${E?`translate-x-5`:``}`})})]})}),p===`queue`&&(0,K.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.gcodeInjection.title`)}),(0,K.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.gcodeInjection.description`)})]}),(0,K.jsx)(`button`,{onClick:()=>{let e=!O;k(e),F(`gcodeInjection`),ie.mutate({gcode_injection:e})},disabled:P===`gcodeInjection`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${O?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${P===`gcodeInjection`?`opacity-50`:``}`,children:(0,K.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${O?`translate-x-5`:``}`})})]})}),(0,K.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.tailscaleDisabled.title`)}),(0,K.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.tailscaleDisabled.description`)})]}),(0,K.jsx)(`button`,{onClick:()=>{let e=!A;j(e),F(`tailscaleDisabled`),ie.mutate({tailscale_disabled:e})},disabled:P===`tailscaleDisabled`,className:`relative w-10 h-5 rounded-full transition-colors shrink-0 ${A?`bg-bambu-dark-tertiary`:`bg-bambu-green`} ${P===`tailscaleDisabled`?`opacity-50`:``}`,children:(0,K.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${A?``:`translate-x-5`}`})})]})}),p!==`proxy`&&(0,K.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium mb-1`,children:n(`virtualPrinter.model.title`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`virtualPrinter.model.description`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`select`,{value:S,onChange:e=>le(e.target.value),disabled:P===`model`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:Object.entries(t).map(([e,t])=>(0,K.jsxs)(`option`,{value:e,children:[t,` (`,e,`)`]},e))}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),p===`proxy`&&(0,K.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2 p-2 rounded bg-blue-500/10 border border-blue-500/30`,children:[(0,K.jsx)(kc,{className:`w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`virtualPrinter.proxy.accessCodeHint`)})]})}),p!==`proxy`&&(0,K.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.accessCode.title`)}),ge?(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-blue-400`,children:[(0,K.jsx)(kc,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.inheritedFromTarget`)]}):e.access_code_set?(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-green-400`,children:[(0,K.jsx)($o,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.isSet`)]}):(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-yellow-400`,children:[(0,K.jsx)(vu,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.notSet`)]})]}),ge?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{type:M?`text`:`password`,value:_e,readOnly:!0,"aria-label":n(`virtualPrinter.accessCode.title`),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm pr-10 font-mono opacity-90 cursor-default`}),(0,K.jsx)(`button`,{onClick:()=>N(!M),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,"aria-label":n(M?`virtualPrinter.accessCode.hide`:`virtualPrinter.accessCode.reveal`),children:M?(0,K.jsx)(Ws,{className:`w-4 h-4`}):(0,K.jsx)(Gs,{className:`w-4 h-4`})})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`virtualPrinter.accessCode.derivedFromTargetHint`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(`input`,{type:M?`text`:`password`,value:d,onChange:e=>f(e.target.value),placeholder:e.access_code_set?n(`virtualPrinter.accessCode.placeholderChange`):n(`virtualPrinter.accessCode.placeholder`),maxLength:8,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm placeholder-bambu-gray pr-10 font-mono`}),(0,K.jsx)(`button`,{onClick:()=>N(!M),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:M?(0,K.jsx)(Ws,{className:`w-4 h-4`}):(0,K.jsx)(Gs,{className:`w-4 h-4`})})]}),(0,K.jsx)($,{onClick:se,disabled:!d||P===`accessCode`,variant:`primary`,children:P===`accessCode`?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]}),d&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:(0,K.jsx)(`span`,{className:d.length===8?`text-green-400`:`text-yellow-400`,children:n(`virtualPrinter.accessCode.charCount`,{count:d.length})})})]})]}),(0,K.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium mb-2`,children:n(`virtualPrinter.targetPrinter.title`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:h??``,onChange:e=>{let t=parseInt(e.target.value,10);isNaN(t)||ue(t)},disabled:P===`targetPrinter`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,K.jsx)(`option`,{value:``,children:n(`virtualPrinter.targetPrinter.placeholder`)}),re?.map(e=>(0,K.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.ip_address,`)`]},e.id))]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,K.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium mb-1`,children:n(`virtualPrinter.bindIp.title`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:_,onChange:e=>{v(e.target.value),F(`bindIp`),ie.mutate({bind_ip:e.target.value})},disabled:P===`bindIp`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,K.jsx)(`option`,{value:``,children:n(`virtualPrinter.bindIp.placeholder`)}),U?.map(e=>(0,K.jsxs)(`option`,{value:e.ip,children:[e.name,` (`,e.ip,`)`,e.is_alias?` [alias]`:``,` - `,e.subnet]},e.ip))]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`virtualPrinter.bindIp.hint`)})]}),(0,K.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.remoteInterface.title`)}),b?(0,K.jsx)(`span`,{className:`flex items-center gap-1 text-xs text-green-400`,children:(0,K.jsx)($o,{className:`w-3 h-3`})}):(0,K.jsx)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray`,title:n(`virtualPrinter.remoteInterface.optional`),children:(0,K.jsx)(kc,{className:`w-3 h-3`})})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:b,onChange:e=>de(e.target.value),disabled:P===`remoteInterface`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,K.jsx)(`option`,{value:``,children:n(`virtualPrinter.remoteInterface.placeholder`)}),U?.map(e=>(0,K.jsxs)(`option`,{value:e.ip,children:[e.name,` (`,e.ip,`) - `,e.subnet]},e.ip))]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]})]})]}),I&&(0,K.jsx)(Ed,{title:n(`virtualPrinter.deleteConfirm.title`),message:n(`virtualPrinter.deleteConfirm.message`,{name:e.name}),variant:`danger`,confirmText:n(`common.delete`),isLoading:ae.isPending,onConfirm:()=>ae.mutate(),onCancel:()=>L(!1)}),R&&(0,K.jsx)(lze,{vpId:e.id,vpName:e.name,onClose:()=>z(!1)})]})}var X5={archive:`archive`,review:`review`,queue:`queue`,proxy:`proxy`};function dze({onClose:e}){let{t}=G(),n=Qa(),{showToast:r}=xd(),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(`archive`),[c,l]=(0,y.useState)(null),{data:u}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),d=J({mutationFn:()=>Qu.create({name:i.trim()||`Bambuddy`,mode:o,target_printer_id:o===`proxy`?c??void 0:void 0}),onSuccess:()=>{n.invalidateQueries({queryKey:[`virtual-printers`]}),r(t(`virtualPrinter.toast.created`)),e()},onError:e=>{r(e.message||t(`virtualPrinter.toast.failedToCreate`),`error`)}});return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:e,children:(0,K.jsx)(pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(hd,{className:`p-6 space-y-4`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t(`virtualPrinter.addDialog.title`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.addDialog.name`)}),(0,K.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`Bambuddy`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm placeholder-bambu-gray`,autoFocus:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.mode.title`)}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:[`archive`,`review`,`queue`,`proxy`].map(e=>(0,K.jsxs)(`button`,{onClick:()=>s(e),className:`p-2 rounded-lg border text-left transition-colors ${o===e?e===`proxy`?`border-blue-500 bg-blue-500/10`:`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-white text-xs font-medium`,children:[e===`proxy`&&(0,K.jsx)(Oo,{className:`w-3 h-3`}),t(`virtualPrinter.mode.${X5[e]}`)]}),(0,K.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:t(`virtualPrinter.mode.${X5[e]}Desc`)})]},e))})]}),o===`proxy`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.targetPrinter.title`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:c??``,onChange:e=>{let t=parseInt(e.target.value,10);l(isNaN(t)?null:t)},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm appearance-none cursor-pointer pr-10`,children:[(0,K.jsx)(`option`,{value:``,children:t(`virtualPrinter.targetPrinter.placeholder`)}),u?.map(e=>(0,K.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.ip_address,`)`]},e.id))]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`virtualPrinter.addDialog.hint`)}),(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:e,className:`flex-1`,disabled:d.isPending,children:t(`common.cancel`)}),(0,K.jsx)($,{variant:`primary`,onClick:()=>d.mutate(),className:`flex-1`,disabled:d.isPending,children:d.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):t(`virtualPrinter.addDialog.create`)})]})]})})})}function fze(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),[r,i]=(0,y.useState)(!1),{data:a,isLoading:o}=q({queryKey:[`virtual-printers`],queryFn:Qu.list,refetchInterval:1e4}),{data:s}=q({queryKey:[`virtual-printer-settings`],queryFn:Zu.getSettings}),c=J({mutationFn:e=>Zu.updateSettings({archive_name_source:e}),onSuccess:()=>{t.invalidateQueries({queryKey:[`virtual-printer-settings`]}),n(e(`virtualPrinter.toast.updated`))},onError:t=>{n(t.message||e(`virtualPrinter.toast.failedToUpdate`),`error`)}}),l=s?.archive_name_source===`filename`,{data:u}=q({queryKey:[`vp-ca-certificate`],queryFn:Qu.getCaCertificate,staleTime:1/0}),[d,f]=(0,y.useState)(!1),p=async()=>{u&&(await q5(u.pem)?(f(!0),n(e(`virtualPrinter.caCert.copied`)),setTimeout(()=>f(!1),2e3)):n(e(`virtualPrinter.toast.copyFailed`),`error`))},m=()=>{u&&sze(u.pem,`bambuddy-virtual-printer-ca.crt`,`application/x-pem-file`)};if(o)return(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-8 flex justify-center`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})})});let h=a?.printers||[],g=a?.models||{};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4 items-stretch`,children:[(0,K.jsx)(pd,{className:`border-l-4 border-l-yellow-500`,children:(0,K.jsx)(hd,{className:`py-3 px-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`text-xs`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`virtualPrinter.setupRequired.title`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`virtualPrinter.setupRequired.description`)}),(0,K.jsxs)(`a`,{href:`https://wiki.bambuddy.cool/features/virtual-printer/`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 mt-2 px-3 py-1.5 bg-yellow-500/20 border border-yellow-500/50 rounded text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs`,children:[(0,K.jsx)(Us,{className:`w-3 h-3`}),e(`virtualPrinter.setupRequired.readGuide`)]})]})]})})}),(0,K.jsx)(pd,{className:`lg:col-span-2`,children:(0,K.jsx)(hd,{className:`py-3 px-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(kc,{className:`w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`virtualPrinter.howItWorks.title`)}),(0,K.jsxs)(`ul`,{className:`space-y-1 list-disc list-inside`,children:[(0,K.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step1`)}),(0,K.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step2`)}),(0,K.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step3`)})]})]})]})})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4 items-stretch`,children:[(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-3 px-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(Bl,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-1`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`virtualPrinter.caCert.title`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsxs)(`button`,{onClick:p,disabled:!u,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[d?(0,K.jsx)($o,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,K.jsx)(Ds,{className:`w-3.5 h-3.5`}),e(d?`virtualPrinter.caCert.copied`:`virtualPrinter.caCert.copy`)]}),(0,K.jsxs)(`button`,{onClick:m,disabled:!u,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[(0,K.jsx)(Is,{className:`w-3.5 h-3.5`}),e(`virtualPrinter.caCert.download`)]})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`virtualPrinter.caCert.description`)}),u&&(0,K.jsxs)(`p`,{className:`text-[10px] text-bambu-gray font-mono mt-1 truncate`,title:u.fingerprint_sha256,children:[e(`virtualPrinter.caCert.fingerprint`),`: `,u.fingerprint_sha256]})]})]})})}),(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-3 px-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(Zs,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-1`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`virtualPrinter.archiveNameSource.title`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(`span`,{className:`text-xs ${l?`text-bambu-gray`:`text-white`}`,children:e(`virtualPrinter.archiveNameSource.metadata`)}),(0,K.jsx)(y5,{checked:l,onChange:e=>c.mutate(e?`filename`:`metadata`),disabled:c.isPending}),(0,K.jsx)(`span`,{className:`text-xs ${l?`text-white`:`text-bambu-gray`}`,children:e(`virtualPrinter.archiveNameSource.filename`)})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`virtualPrinter.archiveNameSource.description`)})]})]})})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(bl,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`virtualPrinter.list.title`)}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,h.length,`)`]})]}),(0,K.jsxs)($,{variant:`primary`,onClick:()=>i(!0),children:[(0,K.jsx)(_l,{className:`w-4 h-4 mr-1`}),e(`virtualPrinter.list.add`)]})]}),h.length===0?(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`py-8 text-center`,children:[(0,K.jsx)(bl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3`}),(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`virtualPrinter.list.empty`)}),(0,K.jsxs)($,{variant:`primary`,onClick:()=>i(!0),children:[(0,K.jsx)(_l,{className:`w-4 h-4 mr-1`}),e(`virtualPrinter.list.addFirst`)]})]})}):(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 items-start`,children:h.map(e=>(0,K.jsx)(uze,{printer:e,models:g},e.id))}),r&&(0,K.jsx)(dze,{onClose:()=>i(!1)})]})}function Z5(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60),r=t%60;if(n<24)return r?`${n}h ${r}m`:`${n}h`;let i=Math.floor(n/24),a=n%24;return a?`${i}d ${a}h`:`${i}d`}function Q5(e){return e==null?`—`:e>=1024?`${(e/1024).toFixed(1)} GB`:`${Math.round(e)} MB`}function pze({device:e,onUnregister:t,isDeleting:n}){let{t:r}=G(),{showToast:i}=xd(),a=e.system_stats,o=a?.memory,s=a?.disk,c=e.online,[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),p=async t=>{f(t);try{t===`update`?await nd.triggerUpdate(e.device_id):await nd.systemCommand(e.device_id,t),i(r(`settings.spoolbuddy.commandQueued`),`success`)}catch(e){i(e instanceof Error?e.message:r(`settings.spoolbuddy.commandError`),`error`)}finally{f(null),u(null)}},m=[{key:`update`,label:r(`settings.spoolbuddy.update`),icon:Is},{key:`restart_browser`,label:r(`settings.spoolbuddy.restartBrowser`),icon:tl},{key:`restart_daemon`,label:r(`settings.spoolbuddy.restartDaemon`),icon:Cl},{key:`reboot`,label:r(`settings.spoolbuddy.reboot`),icon:El},{key:`shutdown`,label:r(`settings.spoolbuddy.shutdown`),icon:yl,variant:`danger`}],h={update:r(`settings.spoolbuddy.updateConfirmTitle`),restart_browser:r(`settings.spoolbuddy.restartBrowserConfirmTitle`),restart_daemon:r(`settings.spoolbuddy.restartDaemonConfirmTitle`),reboot:r(`settings.spoolbuddy.rebootConfirmTitle`),shutdown:r(`settings.spoolbuddy.shutdownConfirmTitle`)},g={update:r(`settings.spoolbuddy.updateConfirmBody`,{hostname:e.hostname}),restart_browser:r(`settings.spoolbuddy.restartBrowserConfirmBody`,{hostname:e.hostname}),restart_daemon:r(`settings.spoolbuddy.restartDaemonConfirmBody`,{hostname:e.hostname}),reboot:r(`settings.spoolbuddy.rebootConfirmBody`,{hostname:e.hostname}),shutdown:r(`settings.spoolbuddy.shutdownConfirmBody`,{hostname:e.hostname})};return(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`text-base font-semibold text-white truncate`,children:e.hostname}),(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${c?`bg-green-500/15 text-green-400 border border-green-500/40`:`bg-gray-500/15 text-gray-400 border border-gray-500/40`}`,children:[c?(0,K.jsx)(ju,{className:`w-3 h-3`}):(0,K.jsx)(Au,{className:`w-3 h-3`}),r(c?`settings.spoolbuddy.online`:`settings.spoolbuddy.offline`)]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray font-mono mt-1 truncate`,children:e.device_id})]}),(0,K.jsxs)($,{variant:`danger`,size:`sm`,onClick:()=>t(e),disabled:n,"aria-label":r(`settings.spoolbuddy.unregister`),children:[(0,K.jsx)(hu,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:r(`settings.spoolbuddy.unregister`)})]})]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.ipAddress`)}),(0,K.jsx)(`div`,{className:`text-white font-mono`,children:e.ip_address})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.firmware`)}),(0,K.jsx)(`div`,{className:`text-white`,children:e.firmware_version??`—`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`text-bambu-gray flex items-center gap-1`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),r(`settings.spoolbuddy.lastSeen`)]}),(0,K.jsx)(`div`,{className:`text-white`,children:e.last_seen?bf(e.last_seen):r(`settings.spoolbuddy.never`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.daemonUptime`)}),(0,K.jsx)(`div`,{className:`text-white`,children:Z5(e.uptime_s)})]})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.map(({key:e,label:t,icon:n,variant:r})=>(0,K.jsxs)($,{variant:r??`secondary`,size:`sm`,onClick:()=>u(e),disabled:!c||d!==null,"aria-label":t,children:[d===e?(0,K.jsx)(X,{className:`w-3.5 h-3.5 animate-spin`}):(0,K.jsx)(n,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{children:t})]},e))}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-xs flex-wrap`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[e.nfc_ok?(0,K.jsx)(us,{className:`w-3.5 h-3.5 text-green-400`}):(0,K.jsx)(ms,{className:`w-3.5 h-3.5 text-red-400`}),r(`settings.spoolbuddy.nfc`),e.nfc_reader_type&&(0,K.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[`(`,e.nfc_reader_type,`)`]})]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[e.scale_ok?(0,K.jsx)(us,{className:`w-3.5 h-3.5 text-green-400`}):(0,K.jsx)(ms,{className:`w-3.5 h-3.5 text-red-400`}),r(`settings.spoolbuddy.scale`)]})]}),a&&(0,K.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3 text-xs`,children:[a.cpu_temp_c!==void 0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(pu,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.cpuTemp`)}),(0,K.jsxs)(`div`,{className:`text-white`,children:[a.cpu_temp_c.toFixed(1),`°C`]})]})]}),a.load_avg&&a.load_avg.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(So,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.cpuLoad`)}),(0,K.jsxs)(`div`,{className:`text-white`,children:[a.load_avg[0].toFixed(2),a.cpu_count?` / ${a.cpu_count} (${Math.round(a.load_avg[0]/a.cpu_count*100)}%)`:``]})]})]}),o&&o.percent!==void 0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Os,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.memory`)}),(0,K.jsxs)(`div`,{className:`text-white`,children:[o.percent.toFixed(0),`% (`,Q5(o.used_mb),` / `,Q5(o.total_mb),`)`]})]})]}),s&&s.percent!==void 0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(yc,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.disk`)}),(0,K.jsxs)(`div`,{className:`text-white`,children:[s.percent.toFixed(0),`% (`,s.used_gb?.toFixed(1),` / `,s.total_gb?.toFixed(1),` GB)`]})]})]}),a.system_uptime_s!==void 0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(_s,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.systemUptime`)}),(0,K.jsx)(`div`,{className:`text-white`,children:Z5(a.system_uptime_s)})]})]})]}),a.os&&(0,K.jsx)(`div`,{className:`mt-3 text-xs text-bambu-gray font-mono truncate`,children:[a.os.os,a.os.kernel,a.os.arch,a.os.python&&`Python ${a.os.python}`].filter(Boolean).join(` · `)})]})]}),l&&(0,K.jsx)(Ed,{variant:l===`shutdown`||l===`reboot`?`danger`:`default`,title:h[l],message:g[l],confirmText:r(`settings.spoolbuddy.commandConfirm`),isLoading:d!==null,onConfirm:()=>p(l),onCancel:()=>u(null)})]})}function mze(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),[r,i]=(0,y.useState)(null),{data:a=[],isLoading:o}=q({queryKey:[`spoolbuddy-devices`],queryFn:()=>nd.getDevices(),refetchInterval:15e3}),s=J({mutationFn:e=>nd.deleteDevice(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`spoolbuddy-devices`]}),n(e(`settings.spoolbuddy.unregisterSuccess`),`success`),i(null)},onError:t=>{n(t.message||e(`settings.spoolbuddy.unregisterError`),`error`)}});if(o)return(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-8 flex justify-center`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})})});let c=a.length>1;return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-3 px-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,K.jsx)(kc,{className:`w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`settings.spoolbuddy.infoTitle`)}),(0,K.jsx)(`p`,{children:e(`settings.spoolbuddy.infoBody`)})]})]})})}),c&&(0,K.jsx)(pd,{className:`border-l-4 border-l-yellow-500`,children:(0,K.jsx)(hd,{className:`py-3 px-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`settings.spoolbuddy.duplicatesTitle`,{count:a.length})}),(0,K.jsx)(`p`,{children:e(`settings.spoolbuddy.duplicatesBody`)})]})]})})}),a.length===0?(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-8 text-center text-bambu-gray text-sm`,children:e(`settings.spoolbuddy.empty`)})}):(0,K.jsx)(`div`,{className:`space-y-3`,children:a.map(e=>(0,K.jsx)(pze,{device:e,onUnregister:i,isDeleting:s.isPending&&s.variables===e.device_id},e.id))}),r&&(0,K.jsx)(Ed,{variant:`danger`,title:e(`settings.spoolbuddy.confirmTitle`),message:e(`settings.spoolbuddy.confirmBody`,{hostname:r.hostname,deviceId:r.device_id}),confirmText:e(`settings.spoolbuddy.unregister`),isLoading:s.isPending,onConfirm:()=>s.mutate(r.device_id),onCancel:()=>i(null)})]})}function $5(e){if(!e)return`-`;let t=mf(e);return t?t.toLocaleString():`-`}function e7({status:e}){if(!e)return null;let t={success:`bg-green-500/20 text-green-400`,failed:`bg-red-500/20 text-red-400`,skipped:`bg-yellow-500/20 text-yellow-400`,running:`bg-blue-500/20 text-blue-400`},n={success:(0,K.jsx)(ls,{className:`w-3 h-3`}),failed:(0,K.jsx)(ms,{className:`w-3 h-3`}),skipped:(0,K.jsx)(Kl,{className:`w-3 h-3`}),running:(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`})};return(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium ${t[e]||`bg-gray-500/20 text-gray-400`}`,children:[n[e],e.charAt(0).toUpperCase()+e.slice(1)]})}var hze={github:`backup.repoUrlPlaceholderGitHub`,gitea:`backup.repoUrlPlaceholderGitea`,forgejo:`backup.repoUrlPlaceholderForgejo`,gitlab:`backup.repoUrlPlaceholderGitLab`},gze={github:`ghp_xxxxxxxxxxxx`,gitea:`your_access_token`,forgejo:`your_access_token`,gitlab:`glpat-xxxxxxxxxxxx`};function t7(e){return JSON.stringify(e)}function _ze(e,t){if(!t)return e;let n={};for(let r of Object.keys(e))e[r]!==t[r]&&(n[r]=e[r]);return n}function vze(){let e=Qa(),{showToast:t}=xd(),{t:n}=G(),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`main`),[l,u]=(0,y.useState)(`github`),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(`daily`),[h,g]=(0,y.useState)(!0),[_,v]=(0,y.useState)(!0),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!0),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(``),[I,L]=(0,y.useState)(!1),[R,z]=(0,y.useState)(null),[B,V]=(0,y.useState)(null),ee=(0,y.useRef)(null),[H,te]=(0,y.useState)(null),[ne,re]=(0,y.useState)(null),[U,ie]=(0,y.useState)(``),{data:ae,refetch:W}=q({queryKey:[`local-backup-status`],queryFn:Q.getLocalBackupStatus,refetchInterval:e=>e.state.data?.is_running?1e3:1e4}),{data:oe,refetch:se}=q({queryKey:[`local-backup-files`],queryFn:Q.getLocalBackups,refetchInterval:3e4});(0,y.useEffect)(()=>{ae?.path!==void 0&&ie(ae.path)},[ae?.path]);let ce=J({mutationFn:Q.triggerLocalBackup,onSuccess:e=>{e.success?t(n(`backup.scheduledBackupComplete`)):t(e.message,`error`),W(),se()},onError:()=>t(n(`backup.scheduledBackupFailed`),`error`)}),le=J({mutationFn:e=>Q.deleteLocalBackup(e),onSuccess:()=>{se(),te(null)}}),ue=J({mutationFn:async e=>(re(null),N(!0),V(null),F(n(`backup.restoring`)),Q.restoreLocalBackup(e)),onSuccess:e=>{N(!1),F(``),e.success?(V({success:!0,message:e.message}),t(n(`backup.backupRestoredRestart`),`success`)):(V({success:!1,message:e.message}),t(e.message,`error`))},onError:e=>{N(!1),F(``);let r=e instanceof Error?e.message:n(`backup.failedToRestore`);V({success:!1,message:r}),t(r,`error`)}});(0,y.useEffect)(()=>{if(A||M){let e=e=>(e.preventDefault(),e.returnValue=`A backup operation is in progress. Are you sure you want to leave?`,e.returnValue);return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)}},[A,M]);let[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(null),[he,ge]=(0,y.useState)(null),_e=(0,y.useRef)(null),ve=(0,y.useRef)(null),ye=(0,y.useRef)(null),be=(0,y.useRef)(null),xe=(0,y.useRef)(``),[Se,Ce]=(0,y.useState)(!1),we=(0,y.useMemo)(()=>({repository_url:r,branch:s,provider:l,allow_insecure_http:E,schedule_enabled:d,schedule_type:p,backup_kprofiles:h,backup_cloud_profiles:_,backup_settings:b,backup_spools:S,backup_archives:w,enabled:O}),[r,s,l,E,d,p,h,_,b,S,w,O]),Te=(0,y.useMemo)(()=>t7(we),[we]),{data:Ee,isLoading:De}=q({queryKey:[`github-backup-config`],queryFn:Q.getGitHubBackupConfig}),{data:Oe}=q({queryKey:[`github-backup-status`],queryFn:Q.getGitHubBackupStatus,refetchInterval:e=>e.state.data?.is_running?500:1e4}),{data:ke}=q({queryKey:[`github-backup-logs`],queryFn:()=>Q.getGitHubBackupLogs(20)}),{data:Ae}=q({queryKey:[`cloud-status`],queryFn:Q.getCloudStatus}),{data:je}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),Me=po({queries:(je??[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),staleTime:1e4,refetchInterval:3e4}))}),Ne=(je??[]).map((e,t)=>({printer:e,connected:Me[t]?.data?.connected??!1})),Pe=Ne.length,Fe=Ne.filter(e=>e.connected).length,Ie=Pe>0&&Fe===0,Le=Fe>0&&Fe(ye.current&&clearTimeout(ye.current),Ee?(Ce(!1),be.current={repository_url:Ee.repository_url,branch:Ee.branch,provider:Ee.provider??`github`,allow_insecure_http:Ee.allow_insecure_http??!1,schedule_enabled:Ee.schedule_enabled,schedule_type:Ee.schedule_type,backup_kprofiles:Ee.backup_kprofiles,backup_cloud_profiles:Ee.backup_cloud_profiles,backup_settings:Ee.backup_settings,backup_spools:Ee.backup_spools,backup_archives:Ee.backup_archives,enabled:Ee.enabled},i(Ee.repository_url),c(Ee.branch),u(Ee.provider??`github`),f(Ee.schedule_enabled),m(Ee.schedule_type),g(Ee.backup_kprofiles),v(Ee.backup_cloud_profiles),x(Ee.backup_settings),C(Ee.backup_spools),T(Ee.backup_archives),D(Ee.allow_insecure_http??!1),k(Ee.enabled),o(``),ye.current=setTimeout(()=>{Ce(!0)},100)):(Ce(!1),be.current=null,o(``)),()=>{ye.current&&clearTimeout(ye.current)}),[Ee]);let Re=(0,y.useCallback)(async(r=!1)=>{if(Ee)try{r&&a?(await Q.saveGitHubBackupConfig({...we,access_token:a}),o(``),ge(null),t(n(`backup.tokenUpdated`)),xe.current=``):(await Q.updateGitHubBackupConfig(_ze(we,be.current)),ge(null),t(n(`backup.settingsSaved`))),be.current=we,e.invalidateQueries({queryKey:[`github-backup-config`]}),e.invalidateQueries({queryKey:[`github-backup-status`]})}catch(e){ge(e.message)}},[Ee,a,we,e,t,n]),ze=(0,y.useRef)(Re);(0,y.useEffect)(()=>{ze.current=Re},[Re]),(0,y.useEffect)(()=>{if(!(!Se||!Ee)&&!(be.current&&Te===t7(be.current)))return _e.current&&clearTimeout(_e.current),_e.current=setTimeout(()=>{Re(!1)},500),()=>{_e.current&&clearTimeout(_e.current)}},[Se,Ee,Te,Re]),(0,y.useEffect)(()=>{if(!(!Se||!Ee||!a)&&a!==xe.current)return xe.current=a,ve.current&&clearTimeout(ve.current),ve.current=setTimeout(()=>{ze.current(!0)},1e3),()=>{ve.current&&clearTimeout(ve.current)}},[Se,a,Ee]);let Be=J({mutationFn:e=>Q.saveGitHubBackupConfig(e),onMutate:()=>{ge(null)},onSuccess:()=>{e.invalidateQueries({queryKey:[`github-backup-config`]}),e.invalidateQueries({queryKey:[`github-backup-status`]}),t(n(`backup.githubBackupEnabled`)),o(``),Ce(!0)},onError:e=>{ge(e.message)}}),Ve=J({mutationFn:Q.triggerGitHubBackup,onSuccess:r=>{e.invalidateQueries({queryKey:[`github-backup-status`]}),e.invalidateQueries({queryKey:[`github-backup-logs`]}),r.success?r.files_changed>0?t(n(`backup.backupCompleteFiles`,{count:r.files_changed})):t(n(`backup.backupSkippedNoChanges`)):t(n(`backup.backupFailed2`,{message:r.message}),`error`)},onError:e=>{t(n(`backup.backupFailed2`,{message:e.message}),`error`)}}),He=J({mutationFn:()=>Q.clearGitHubBackupLogs(0),onSuccess:r=>{e.invalidateQueries({queryKey:[`github-backup-logs`]}),t(n(`backup.clearedLogs`,{count:r.deleted}))},onError:e=>{t(n(`backup.failedToClearLogs`,{message:e.message}),`error`)}}),Ue=async()=>{fe(!0),me(null);try{let e;if(a){if(!r){t(n(`backup.enterRepoUrl`),`error`),fe(!1);return}e=await Q.testGitHubConnection(r,a,l)}else if(Ee?.has_token)e=await Q.testGitHubStoredConnection();else{t(n(`backup.enterRepoAndToken`),`error`),fe(!1);return}me({success:e.success,message:e.message,isPrivate:e.is_private})}catch(e){me({success:!1,message:e.message,isPrivate:null})}finally{fe(!1)}};return De?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,K.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(pd,{id:`card-backup-github`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(mc,{className:`w-5 h-5 text-gray-400`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.githubBackup`)})]}),Ee&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`backup.enabled`)}),(0,K.jsx)(y5,{checked:O,onChange:k})]})]})}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.githubDescription`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`git-provider-select`,className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.provider`)}),(0,K.jsxs)(`select`,{id:`git-provider-select`,value:l,onChange:e=>{u(e.target.value),me(null),ge(null)},className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`github`,children:n(`backup.providerGitHub`)}),(0,K.jsx)(`option`,{value:`gitlab`,children:n(`backup.providerGitLab`)}),(0,K.jsx)(`option`,{value:`gitea`,children:n(`backup.providerGitea`)}),(0,K.jsx)(`option`,{value:`forgejo`,children:n(`backup.providerForgejo`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.repositoryUrl`)}),(0,K.jsx)(`input`,{type:`text`,value:r,onChange:e=>{i(e.target.value),me(null),ge(null)},placeholder:n(hze[l]),className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 mt-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:E,onChange:e=>{D(e.target.checked),me(null)},className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n(`backup.allowInsecureHttp`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.allowInsecureHttpHint`)})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`backup.personalAccessToken`),` `,Ee?.has_token&&(0,K.jsx)(`span`,{className:`text-green-400`,children:n(`backup.tokenSaved`)})]}),(0,K.jsx)(`input`,{type:`password`,value:a,onChange:e=>{o(e.target.value),me(null),ge(null)},placeholder:Ee?.has_token?n(`backup.enterNewToken`):gze[l],className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`backup.tokenHint`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.branch`)}),(0,K.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`main`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.autoBackup`)}),(0,K.jsxs)(`select`,{value:d?p:`disabled`,onChange:e=>{e.target.value===`disabled`?f(!1):(f(!0),m(e.target.value))},className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`disabled`,children:n(`backup.manualOnly`)}),(0,K.jsx)(`option`,{value:`hourly`,children:n(`backup.hourly`)}),(0,K.jsx)(`option`,{value:`daily`,children:n(`backup.daily`)}),(0,K.jsx)(`option`,{value:`weekly`,children:n(`backup.weekly`)})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:n(`backup.includeInBackup`)}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`label`,{className:`flex items-start gap-2 ${Ie?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`,disabled:Ie}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm ${Ie?`text-bambu-gray`:`text-white`}`,children:n(`backup.kProfiles`)}),Ie&&(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400`,children:[(0,K.jsx)(vu,{className:`w-3 h-3`}),n(`backup.noPrintersConnected`)]}),Le&&(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400`,children:[(0,K.jsx)(vu,{className:`w-3 h-3`}),n(`backup.printersConnected`,{connected:Fe,total:Pe})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.kProfilesDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 ${Ae?.is_authenticated?`cursor-pointer`:`cursor-not-allowed opacity-60`}`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`,disabled:!Ae?.is_authenticated}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm ${Ae?.is_authenticated?`text-white`:`text-bambu-gray`}`,children:n(`backup.cloudProfiles`)}),!Ae?.is_authenticated&&(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400`,children:[(0,K.jsx)(vu,{className:`w-3 h-3`}),n(`backup.cloudLoginRequiredShort`)]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.cloudProfilesDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>x(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.appSettings`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.appSettingsDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:S,onChange:e=>C(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.spoolInventory`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.spoolInventoryDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:w,onChange:e=>T(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.printArchives`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.printArchivesDescription`)})]})]})]})]}),(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 space-y-3`,children:[Oe?.configured&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:Oe.last_backup_at?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{children:[n(`backup.lastBackupAt`),` `,bf(Oe.last_backup_at,`system`,n)]}),(0,K.jsx)(e7,{status:Oe.last_backup_status})]}):(0,K.jsx)(`span`,{children:n(`backup.noBackupsYet`)})}),Oe.next_scheduled_run&&(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[(0,K.jsx)(_s,{className:`w-3 h-3 inline mr-1`}),n(`backup.next`),` `,bf(Oe.next_scheduled_run,`system`,n)]})]}),he&&(0,K.jsxs)(`div`,{className:`text-sm text-red-400 bg-red-500/10 border border-red-500/30 rounded p-3 flex items-start gap-2`,children:[(0,K.jsx)(ms,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,K.jsx)(`div`,{className:`flex-1 leading-relaxed whitespace-pre-wrap break-words`,children:he}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>ge(null),className:`text-bambu-gray hover:text-white shrink-0`,"aria-label":n(`common.dismiss`,`Dismiss`),children:(0,K.jsx)(ms,{className:`w-4 h-4`})})]}),pe&&(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsxs)(`div`,{className:`text-sm flex items-center gap-1 ${pe.success?`text-green-400`:`text-red-400`}`,children:[pe.success?(0,K.jsx)(ls,{className:`w-4 h-4`}):(0,K.jsx)(ms,{className:`w-4 h-4`}),pe.message]}),pe.success&&pe.isPrivate===!0&&(0,K.jsxs)(`div`,{className:`text-xs flex items-center gap-1 text-green-400`,children:[(0,K.jsx)(ls,{className:`w-3.5 h-3.5`}),n(`backup.repoIsPrivate`,`Repository is private — safe to back up to.`)]}),pe.success&&pe.isPrivate===!1&&(0,K.jsxs)(`div`,{className:`text-xs text-red-400 bg-red-500/10 border border-red-500/30 rounded p-2 flex items-start gap-1.5`,children:[(0,K.jsx)(ms,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,K.jsx)(`span`,{children:n(`backup.repoIsPublicWarning`,`Repository is PUBLIC. Bambuddy backups include MQTT credentials, Home Assistant tokens, Prometheus tokens, your Bambu Cloud email, and printer access codes via K-profiles. Saving is blocked until you make the repository private in your provider's settings.`)})]}),pe.success&&pe.isPrivate===null&&(0,K.jsxs)(`div`,{className:`text-xs text-yellow-400 bg-yellow-500/10 border border-yellow-500/30 rounded p-2 flex items-start gap-1.5`,children:[(0,K.jsx)(ms,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,K.jsx)(`span`,{children:n(`backup.repoVisibilityUnknown`,`Could not determine repository visibility. Bambuddy refuses to back up to anything not confirmed private; saving will be blocked.`)})]})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:Oe?.configured?(0,K.jsx)(K.Fragment,{children:Ve.isPending||Oe.is_running?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-green`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),(0,K.jsx)(`span`,{className:`text-sm`,children:Oe.progress||n(`backup.startingBackup`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`primary`,size:`sm`,onClick:()=>Ve.mutate(),disabled:!Ee?.enabled,children:[(0,K.jsx)(hl,{className:`w-4 h-4`}),n(`backup.backupNow`)]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:Ue,disabled:de,children:[de?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),n(`backup.test`)]})]})}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`primary`,size:`sm`,onClick:()=>{if(!r){t(n(`backup.repoRequired`),`error`);return}if(!a){t(n(`backup.tokenRequired`),`error`);return}Be.mutate({repository_url:r,access_token:a,branch:s,provider:l,allow_insecure_http:E,schedule_enabled:d,schedule_type:p,backup_kprofiles:h,backup_cloud_profiles:_,backup_settings:b,backup_spools:S,backup_archives:w,enabled:O})},disabled:Be.isPending||!r||!a,children:[Be.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(ls,{className:`w-4 h-4`}),n(`backup.enableBackup`)]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:Ue,disabled:de||!r||!a,children:[de?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),n(`backup.testConnection`)]})]})})]})]})]}),ke&&ke.length>0&&(0,K.jsxs)(pd,{id:`card-backup-history`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(wc,{className:`w-5 h-5 text-gray-400`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.history`)})]}),(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>He.mutate(),disabled:He.isPending,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),n(`backup.clear`)]})]})}),(0,K.jsx)(hd,{children:(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,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-2 px-2`,children:n(`backup.date`)}),(0,K.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.status`)}),(0,K.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.commit`)})]})}),(0,K.jsx)(`tbody`,{children:ke.slice(0,10).map(e=>(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary`,children:[(0,K.jsx)(`td`,{className:`py-2 px-2 text-white`,children:$5(e.started_at)}),(0,K.jsx)(`td`,{className:`py-2 px-2`,children:(0,K.jsx)(e7,{status:e.status})}),(0,K.jsx)(`td`,{className:`py-2 px-2`,children:e.commit_sha?(0,K.jsxs)(`a`,{href:`${Ee?.repository_url}/commit/${e.commit_sha}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline inline-flex items-center gap-1`,children:[e.commit_sha.substring(0,7),(0,K.jsx)(Us,{className:`w-3 h-3`})]}):(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`-`})})]},e.id))})]})})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(pd,{id:`card-backup-local`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(js,{className:`w-5 h-5 text-gray-400`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.localBackup`)})]})}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.localBackupDescription`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:n(`backup.downloadBackupLabel`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.completeBackupZip`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,disabled:A||M,onClick:async()=>{j(!0),F(n(`backup.preparingBackup`));try{F(n(`backup.creatingArchive`));let{blob:e,filename:r}=await Q.exportBackup();F(n(`backup.downloadingFile`));let i=URL.createObjectURL(e),a=document.createElement(`a`);a.href=i,a.download=r,a.click(),URL.revokeObjectURL(i),t(n(`backup.backupDownloaded`))}catch(e){t(n(`backup.failedToCreateBackup`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}finally{j(!1),F(``)}},children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),n(`backup.download`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:n(`backup.restoreBackup`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.restoreDescription`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.restoreNote`)})]}),(0,K.jsx)(`input`,{ref:ee,type:`file`,accept:`.zip`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&(z(t),L(!0)),e.target.value=``}}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,disabled:M||A,onClick:()=>ee.current?.click(),children:[(0,K.jsx)(Su,{className:`w-4 h-4`}),n(`backup.restore`)]})]}),B&&(0,K.jsx)(`div`,{className:`p-3 rounded-lg ${B.success?`bg-green-500/10 border border-green-500/30`:`bg-red-500/10 border border-red-500/30`}`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[B.success?(0,K.jsx)(ls,{className:`w-4 h-4 text-green-400 mt-0.5 flex-shrink-0`}):(0,K.jsx)(ms,{className:`w-4 h-4 text-red-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:B.success?`text-green-200`:`text-red-200`,children:[B.message,B.success&&(0,K.jsx)(`div`,{className:`mt-2`,children:(0,K.jsxs)($,{size:`sm`,onClick:()=>window.location.reload(),children:[(0,K.jsx)(Tl,{className:`w-3 h-3`}),n(`backup.reloadNow`)]})})]})]})}),(0,K.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`text-yellow-200`,children:[(0,K.jsx)(`span`,{className:`font-medium`,children:n(`backup.restoreReplacesAll`)}),` `,(0,K.jsx)(`span`,{className:`text-yellow-200/70`,children:n(`backup.restoreReplacesAllDetail`)})]})]})})]})]}),(0,K.jsxs)(pd,{id:`card-backup-scheduled`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(tc,{className:`w-5 h-5 text-gray-400`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.scheduledBackup`)})]}),(0,K.jsx)(y5,{checked:ae?.enabled??!1,onChange:async r=>{try{await Q.updateSettings({local_backup_enabled:r}),e.invalidateQueries({queryKey:[`settings`]}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}W()}})]})}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.scheduledBackupDescription`)}),ae?.enabled&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.frequency`)}),(0,K.jsxs)(`select`,{value:ae?.schedule??`daily`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{try{await Q.updateSettings({local_backup_schedule:e.target.value}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}W()},children:[(0,K.jsx)(`option`,{value:`hourly`,children:n(`backup.hourly`)}),(0,K.jsx)(`option`,{value:`daily`,children:n(`backup.daily`)}),(0,K.jsx)(`option`,{value:`weekly`,children:n(`backup.weekly`)})]})]}),(ae?.schedule??`daily`)!==`hourly`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.backupTime`)}),(0,K.jsx)(`input`,{type:`time`,value:ae?.time??`03:00`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none [color-scheme:dark]`,onChange:async e=>{try{await Q.updateSettings({local_backup_time:e.target.value}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}W()}}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.localTimeHint`,{tz:ae?.timezone||`UTC`})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.retention`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:100,value:ae?.retention??5,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{let r=Math.max(1,Math.min(100,parseInt(e.target.value)||5));try{await Q.updateSettings({local_backup_retention:r}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}W()}}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.retentionDescription`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.outputPath`)}),(0,K.jsx)(`input`,{type:`text`,value:U,onChange:e=>ie(e.target.value),className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onBlur:async()=>{try{await Q.updateSettings({local_backup_path:U}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}W(),se()},onKeyDown:e=>{e.key===`Enter`&&e.target.blur()}}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:U?n(`backup.outputPathDescription`):(0,K.jsxs)(K.Fragment,{children:[n(`backup.defaultPathLabel`),` `,(0,K.jsx)(`code`,{className:`text-bambu-gray`,children:ae?.default_path||`...`})]})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`text-sm`,children:[ae?.last_backup_at&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,K.jsxs)(`span`,{children:[n(`backup.lastBackup`),`:`]}),(0,K.jsx)(e7,{status:ae.last_status}),(0,K.jsx)(`span`,{children:bf(ae.last_backup_at)})]}),ae?.next_run&&(0,K.jsxs)(`div`,{className:`text-bambu-gray mt-1`,children:[(0,K.jsxs)(`span`,{children:[n(`backup.nextBackup`),`: `]}),(0,K.jsx)(`span`,{children:$5(ae.next_run)})]})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,disabled:ae?.is_running||ce.isPending,onClick:()=>ce.mutate(),children:[ae?.is_running||ce.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hl,{className:`w-4 h-4`}),ae?.is_running?n(`backup.backupRunning`):n(`backup.runNow`)]})]}),oe&&oe.length>0&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-2`,children:n(`backup.backupFiles`)}),(0,K.jsx)(`div`,{className:`space-y-1`,children:oe.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between py-1.5 px-2 rounded hover:bg-bambu-dark-tertiary/50 text-sm`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`span`,{className:`text-white truncate block`,children:e.filename}),(0,K.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[(e.size/1024/1024).toFixed(1),` MB · `,$5(e.created_at)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,K.jsx)(`button`,{className:`text-bambu-gray hover:text-bambu-green p-1`,title:n(`backup.download`),onClick:async()=>{try{let{blob:t,filename:n}=await Q.downloadLocalBackup(e.filename),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=n,i.click(),URL.revokeObjectURL(r)}catch{t(n(`backup.scheduledBackupFailed`),`error`)}},children:(0,K.jsx)(Is,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{className:`text-bambu-gray hover:text-yellow-400 p-1`,title:n(`backup.restore`),onClick:()=>re(e.filename),children:(0,K.jsx)(Tl,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{className:`text-bambu-gray hover:text-red-400 p-1`,onClick:()=>te(e.filename),title:n(`backup.deleteBackup`),children:(0,K.jsx)(hu,{className:`w-3.5 h-3.5`})})]})]},e.filename))})]}),oe&&oe.length===0&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-3 border-t border-bambu-dark-tertiary`,children:n(`backup.noScheduledBackups`)})]})]})]})]}),H&&(0,K.jsx)(Ed,{title:n(`backup.deleteBackup`),message:n(`backup.deleteBackupConfirm`),confirmText:n(`backup.deleteBackup`),variant:`danger`,onConfirm:()=>le.mutate(H),onCancel:()=>te(null)}),ne&&(0,K.jsx)(Ed,{title:n(`backup.restoreConfirmTitle`),message:n(`backup.restoreConfirmMessage`,{filename:ne}),confirmText:n(`backup.restoreConfirmButton`),variant:`danger`,onConfirm:()=>ue.mutate(ne),onCancel:()=>re(null)}),I&&R&&(0,K.jsx)(Ed,{title:n(`backup.restoreConfirmTitle`),message:n(`backup.restoreConfirmMessage`,{filename:R.name}),confirmText:n(`backup.restoreConfirmButton`),variant:`danger`,onConfirm:async()=>{L(!1),N(!0),V(null);try{F(n(`backup.uploadingFile`));let e=await Q.importBackup(R);V(e),e.success?t(n(`backup.backupRestoredRestart`),`success`):t(e.message,`error`)}catch(e){let r=e instanceof Error?e.message:n(`backup.failedToRestore`);V({success:!1,message:r}),t(r,`error`)}finally{N(!1),F(``),z(null)}},onCancel:()=>{L(!1),z(null)}}),(A||M)&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-[100]`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-8 max-w-md w-full mx-4 text-center`,children:[(0,K.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`div`,{className:`w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full`}),(0,K.jsx)(`div`,{className:`w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin`})]})}),(0,K.jsx)(`h3`,{className:`text-xl font-semibold text-white mb-2`,children:n(A?`backup.creatingBackup`:`backup.restoringBackup`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:P||n(A?`backup.preparing`:`backup.processing`)}),(0,K.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`p`,{className:`text-yellow-200 text-left`,children:n(`backup.doNotClosePage`)})]})})]})})]})}function yze(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`medium`),[l,u]=(0,y.useState)(`notify`),[d,f]=(0,y.useState)(10),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(!1),{data:b}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:x,refetch:S}=q({queryKey:[`obico-status`],queryFn:Q.getObicoStatus,refetchInterval:1e4}),{data:C}=q({queryKey:[`printers`],queryFn:Q.getPrinters});(0,y.useEffect)(()=>{if(b){i(b.obico_enabled??!1),o(b.obico_ml_url??``),c(b.obico_sensitivity??`medium`),u(b.obico_action??`notify`),f(b.obico_poll_interval??10);try{let e=b.obico_enabled_printers?JSON.parse(b.obico_enabled_printers):null;m(Array.isArray(e)?e:null)}catch{m(null)}v(!0)}},[b]);let w=J({mutationFn:()=>Q.updateSettings({obico_enabled:r,obico_ml_url:a,obico_sensitivity:s,obico_action:l,obico_poll_interval:d,obico_enabled_printers:p===null?``:JSON.stringify(p)}),onSuccess:()=>{t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`obico-status`]}),n(e(`settings.toast.settingsSaved`))}});(0,y.useEffect)(()=>{if(!_||!b||!(b.obico_enabled!==r||b.obico_ml_url!==a||b.obico_sensitivity!==s||b.obico_action!==l||b.obico_poll_interval!==d||b.obico_enabled_printers!==(p===null?``:JSON.stringify(p))))return;let e=setTimeout(()=>w.mutate(),500);return()=>clearTimeout(e)},[r,a,s,l,d,p,_]);let T=async()=>{g(null);try{let t=await Q.testObicoConnection(a);t.ok?g({ok:!0,message:e(`failureDetection.testSuccess`)}):g({ok:!1,message:t.error||`HTTP ${t.status_code??`?`} — ${t.body??e(`failureDetection.testFailed`)}`})}catch(e){g({ok:!1,message:e instanceof Error?e.message:String(e)})}},E=(e,t)=>{if(p===null){let n=C?.map(e=>e.id)??[];m(t?n:n.filter(t=>t!==e));return}m(t?[...p,e]:p.filter(t=>t!==e))};return(0,K.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,K.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,K.jsxs)(pd,{id:`card-fd-ml`,children:[(0,K.jsxs)(md,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Al,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.title`)})]}),(0,K.jsx)(y5,{checked:r,onChange:i})]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:e(`failureDetection.description`)})]}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.mlUrl`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:`http://192.168.1.10:3333`,className:`flex-1 bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,disabled:!r}),(0,K.jsx)($,{onClick:T,disabled:!a||w.isPending,variant:`secondary`,children:e(`failureDetection.test`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.mlUrlHint`)}),h&&(0,K.jsxs)(`div`,{className:`flex items-start gap-2 mt-2 text-sm ${h.ok?`text-green-400`:`text-red-400`}`,children:[h.ok?(0,K.jsx)($o,{className:`w-4 h-4 mt-0.5`}):(0,K.jsx)(Pu,{className:`w-4 h-4 mt-0.5`}),(0,K.jsx)(`span`,{children:h.message})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.sensitivity`)}),(0,K.jsxs)(`select`,{value:s,onChange:e=>c(e.target.value),disabled:!r,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,children:[(0,K.jsx)(`option`,{value:`low`,children:e(`failureDetection.sensitivityLow`)}),(0,K.jsx)(`option`,{value:`medium`,children:e(`failureDetection.sensitivityMedium`)}),(0,K.jsx)(`option`,{value:`high`,children:e(`failureDetection.sensitivityHigh`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.sensitivityHint`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.action`)}),(0,K.jsxs)(`select`,{value:l,onChange:e=>u(e.target.value),disabled:!r,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,children:[(0,K.jsx)(`option`,{value:`notify`,children:e(`failureDetection.actionNotify`)}),(0,K.jsx)(`option`,{value:`pause`,children:e(`failureDetection.actionPause`)}),(0,K.jsx)(`option`,{value:`pause_and_off`,children:e(`failureDetection.actionPauseOff`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.pollInterval`)}),(0,K.jsx)(`input`,{type:`number`,value:d,onChange:e=>f(Math.max(5,Math.min(120,Number(e.target.value)||10))),min:5,max:120,disabled:!r,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.pollIntervalHint`)})]}),x&&!x.external_url_configured&&r&&(0,K.jsxs)(`div`,{className:`flex items-start gap-2 p-3 bg-amber-900/30 border border-amber-700 rounded text-sm text-amber-200`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`font-medium`,children:e(`failureDetection.externalUrlMissing`)}),(0,K.jsx)(`div`,{className:`text-xs mt-1`,children:e(`failureDetection.externalUrlHint`)})]})]})]})]}),(0,K.jsxs)(pd,{id:`card-fd-perprinter`,children:[(0,K.jsxs)(md,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.perPrinterTitle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`failureDetection.perPrinterHint`)})]}),(0,K.jsxs)(hd,{className:`space-y-2`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:p===null,onChange:e=>m(e.target.checked?null:C?.map(e=>e.id)??[]),disabled:!r}),(0,K.jsx)(`span`,{className:`text-white`,children:e(`failureDetection.monitorAll`)})]}),p!==null&&C&&(0,K.jsx)(`div`,{className:`pl-5 space-y-1 border-l border-gray-700`,children:C.map(e=>(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:p.includes(e.id),onChange:t=>E(e.id,t.target.checked),disabled:!r}),(0,K.jsx)(`span`,{className:`text-white`,children:e.name})]},e.id))})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,K.jsxs)(pd,{id:`card-fd-status`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.statusTitle`)})}),(0,K.jsx)(hd,{children:x?(0,K.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e(`failureDetection.serviceRunning`)}),(0,K.jsx)(`span`,{className:x.is_running?`text-green-400`:`text-red-400`,children:x.is_running?e(`common.yes`):e(`common.no`)})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e(`failureDetection.thresholds`)}),(0,K.jsxs)(`span`,{className:`text-white font-mono`,children:[x.thresholds.low.toFixed(2),` / `,x.thresholds.high.toFixed(2)]})]}),x.last_error&&(0,K.jsxs)(`div`,{className:`flex items-start gap-2 text-red-400`,children:[(0,K.jsx)(Pu,{className:`w-4 h-4 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`break-words`,children:x.last_error})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-bambu-gray mb-1`,children:e(`failureDetection.activePrinters`)}),Object.keys(x.per_printer).length===0?(0,K.jsx)(`div`,{className:`text-bambu-gray italic text-xs`,children:e(`failureDetection.noActivePrints`)}):(0,K.jsx)(`div`,{className:`space-y-1`,children:Object.entries(x.per_printer).map(([e,t])=>{let n=C?.find(t=>String(t.id)===e),r=t.class===`failure`?`text-red-400`:t.class===`warning`?`text-amber-400`:`text-green-400`;return(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-white`,children:n?.name??`Printer ${e}`}),(0,K.jsxs)(`span`,{className:`font-mono ${r}`,children:[t.class,` (`,t.score.toFixed(3),`, `,t.frame_count,`f)`]})]},e)})})]})]}):(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:e(`common.loading`)})]})})]}),(0,K.jsxs)(pd,{id:`card-fd-history`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.historyTitle`)}),(0,K.jsx)(`button`,{onClick:()=>S(),className:`text-xs text-bambu-gray hover:text-white`,children:e(`common.refresh`)})]})}),(0,K.jsx)(hd,{children:!x||x.history.length===0?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,K.jsx)(kc,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:e(`failureDetection.noHistory`)})]}):(0,K.jsx)(`div`,{className:`space-y-1 max-h-96 overflow-y-auto text-xs font-mono`,children:x.history.map((e,t)=>{let n=C?.find(t=>t.id===e.printer_id),r=e.class===`failure`?`text-red-400`:e.class===`warning`?`text-amber-400`:`text-bambu-gray`;return(0,K.jsxs)(`div`,{className:`flex justify-between gap-2 py-1 border-b border-gray-800`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:new Date(e.timestamp).toLocaleTimeString()}),(0,K.jsx)(`span`,{className:`text-white truncate`,children:n?.name??`#${e.printer_id}`}),(0,K.jsxs)(`span`,{className:r,children:[e.class,` `,e.score.toFixed(3)]})]},t)})})})]})]})]})}var bze={starttls:587,ssl:465,none:25},xze={587:`starttls`,465:`ssl`,25:`none`};function Sze(){let{t:e}=G(),{showToast:t}=xd(),n=Qa(),[r,i]=(0,y.useState)({smtp_host:``,smtp_port:587,smtp_username:``,smtp_password:``,smtp_security:`starttls`,smtp_auth_enabled:!0,smtp_from_email:``,smtp_from_name:`BamBuddy`}),[a,o]=(0,y.useState)(``),{data:s,isLoading:c}=q({queryKey:[`smtpSettings`],queryFn:()=>Q.getSMTPSettings()}),{authEnabled:l}=sd(),{data:u}=q({queryKey:[`advancedAuthStatus`],queryFn:()=>Q.getAdvancedAuthStatus()});(0,y.useEffect)(()=>{s&&i({...s,smtp_password:``})},[s]);let d=e=>{i({...r,smtp_security:e,smtp_port:bze[e]})},f=e=>{let t=xze[e];i({...r,smtp_port:e,...t?{smtp_security:t}:{}})},p=e=>{i({...r,smtp_auth_enabled:e,...e?{}:{smtp_username:``,smtp_password:``}})},m=J({mutationFn:e=>Q.saveSMTPSettings(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`smtpSettings`]}),n.invalidateQueries({queryKey:[`advancedAuthStatus`]}),t(e(`settings.email.success.settingsSaved`),`success`)},onError:e=>{t(e.message,`error`)}}),h=J({mutationFn:e=>Q.testSMTP(e),onSuccess:e=>{t(e.message,e.success?`success`:`error`)},onError:e=>{t(e.message,`error`)}}),g=J({mutationFn:e=>e?Q.enableAdvancedAuth():Q.disableAdvancedAuth(),onSuccess:e=>{n.invalidateQueries({queryKey:[`advancedAuthStatus`]}),t(e.message,`success`)},onError:e=>{t(e.message,`error`)}}),_=()=>{if(!r.smtp_host||!r.smtp_from_email){t(e(`settings.email.errors.requiredFields`),`error`);return}if(r.smtp_auth_enabled&&!r.smtp_username){t(e(`settings.email.errors.usernameRequired`),`error`);return}m.mutate(r)},v=()=>{if(!a){t(e(`settings.email.errors.enterTestEmail`),`error`);return}h.mutate({test_recipient:a})},b=()=>{if(!l){t(e(`settings.email.errors.enableAuthFirst`),`error`);return}if(!u?.advanced_auth_enabled&&!u?.smtp_configured){t(e(`settings.email.errors.configureSmtpFirst`),`error`);return}g.mutate(!u?.advanced_auth_enabled)};if(c)return(0,K.jsx)(`div`,{className:`flex items-center justify-center p-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})});let x=u?.advanced_auth_enabled??!1,S=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,C=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white/40 placeholder-bambu-gray/40 cursor-not-allowed`;return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(pd,{id:`card-email-advanced-auth`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Gc,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.advancedAuth`)||`Advanced Authentication`})]}),(0,K.jsx)($,{onClick:b,disabled:g.isPending,variant:x?`danger`:`primary`,children:x?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Vc,{className:`w-4 h-4`}),e(`settings.email.disable`)||`Disable`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Hc,{className:`w-4 h-4`}),e(`settings.email.enable`)||`Enable`]})})]})}),(0,K.jsx)(hd,{children:(0,K.jsx)(`div`,{className:`space-y-3`,children:x?(0,K.jsx)(`div`,{className:`bg-green-500/10 border border-green-500/30 rounded-lg p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(ls,{className:`w-5 h-5 text-green-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.email.advancedAuthEnabled`)||`Advanced Authentication is enabled`}),(0,K.jsxs)(`ul`,{className:`text-sm text-green-300 space-y-1 list-disc list-inside`,children:[(0,K.jsx)(`li`,{children:e(`settings.email.feature1`)||`Passwords are auto-generated and emailed to new users`}),(0,K.jsx)(`li`,{children:e(`settings.email.feature2`)||`Users can login with username or email`}),(0,K.jsx)(`li`,{children:e(`settings.email.feature3`)||`Forgot password feature is available`}),(0,K.jsx)(`li`,{children:e(`settings.email.feature4`)||`Admins can reset user passwords via email`})]})]})]})}):(0,K.jsx)(`div`,{className:`bg-yellow-500/10 border border-yellow-500/30 rounded-lg p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(vu,{className:`w-5 h-5 text-yellow-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.email.advancedAuthDisabled`)||`Advanced Authentication is disabled`}),(0,K.jsx)(`p`,{className:`text-sm text-yellow-300`,children:e(`settings.email.advancedAuthDisabledDesc`)||`Enable advanced authentication to activate email-based features for user management.`})]})]})})})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,K.jsx)(`div`,{className:`lg:col-span-2`,children:(0,K.jsxs)(pd,{id:`card-smtp-config`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.smtpSettings`)||`SMTP Configuration`})}),(0,K.jsx)(hd,{children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.authentication`)||`Authentication`}),(0,K.jsxs)(`select`,{value:r.smtp_auth_enabled?`true`:`false`,onChange:e=>p(e.target.value===`true`),className:S,children:[(0,K.jsx)(`option`,{value:`true`,children:e(`settings.email.authOptions.enabled`)}),(0,K.jsx)(`option`,{value:`false`,children:e(`settings.email.authOptions.disabled`)})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 transition-opacity ${r.smtp_auth_enabled?``:`opacity-40 pointer-events-none`}`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.username`)||`Username`}),(0,K.jsx)(`input`,{type:`text`,value:r.smtp_username||``,onChange:e=>i({...r,smtp_username:e.target.value}),placeholder:`your.email@gmail.com`,disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?S:C})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.password`)||`Password`}),(0,K.jsx)(`input`,{type:`password`,value:r.smtp_password||``,onChange:e=>i({...r,smtp_password:e.target.value}),placeholder:s?`••••••••`:`App password`,disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?S:C})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:[e(`settings.email.smtpHost`)||`SMTP Server`,` *`]}),(0,K.jsx)(`input`,{type:`text`,value:r.smtp_host,onChange:e=>i({...r,smtp_host:e.target.value}),placeholder:`smtp.gmail.com`,className:S})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.smtpPort`)||`SMTP Port`}),(0,K.jsx)(`input`,{type:`number`,value:r.smtp_port,onChange:e=>f(parseInt(e.target.value)||587),placeholder:`587`,className:S})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.security`)||`Security`}),(0,K.jsxs)(`select`,{value:r.smtp_security,onChange:e=>d(e.target.value),className:S,children:[(0,K.jsx)(`option`,{value:`starttls`,children:e(`settings.email.securityOptions.starttls`)}),(0,K.jsx)(`option`,{value:`ssl`,children:e(`settings.email.securityOptions.ssl`)}),(0,K.jsx)(`option`,{value:`none`,children:e(`settings.email.securityOptions.none`)})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:[e(`settings.email.fromEmail`)||`From Email`,` *`]}),(0,K.jsx)(`input`,{type:`email`,value:r.smtp_from_email,onChange:e=>i({...r,smtp_from_email:e.target.value}),placeholder:`your@email.com`,className:S})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.fromName`)||`From Name`}),(0,K.jsx)(`input`,{type:`text`,value:r.smtp_from_name,onChange:e=>i({...r,smtp_from_name:e.target.value}),placeholder:`BamBuddy`,className:S})]})]}),(0,K.jsx)(`div`,{className:`flex gap-2`,children:(0,K.jsx)($,{onClick:_,disabled:m.isPending,className:`flex-1`,children:m.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),e(`settings.email.saving`)||`Saving...`]}):e(`settings.email.save`)||`Save Settings`})})]})})]})}),(0,K.jsx)(`div`,{children:(0,K.jsxs)(pd,{id:`card-email-test`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.testConnection`)||`Test SMTP Connection`})}),(0,K.jsx)(hd,{children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.testRecipient`)||`Test Recipient Email`}),(0,K.jsx)(`input`,{type:`email`,value:a,onChange:e=>o(e.target.value),placeholder:`test@example.com`,className:S})]}),(0,K.jsx)($,{onClick:v,disabled:h.isPending,variant:`secondary`,children:h.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),e(`settings.email.sending`)||`Sending...`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Pl,{className:`w-4 h-4`}),e(`settings.email.sendTest`)||`Send Test Email`]})})]})})]})})]})]})}var Cze={starttls:`389`,ldaps:`636`};function wze(){let{t:e}=G(),{showToast:t}=xd(),n=Qa(),{authEnabled:r}=sd(),[i,a]=(0,y.useState)({ldap_server_url:``,ldap_bind_dn:``,ldap_bind_password:``,ldap_search_base:``,ldap_user_filter:`(sAMAccountName={username})`,ldap_security:`starttls`,ldap_group_mapping:``,ldap_auto_provision:!1,ldap_default_group:``}),{data:o,isLoading:s}=q({queryKey:[`settings`],queryFn:()=>Q.getSettings()}),{data:c}=q({queryKey:[`ldapStatus`],queryFn:()=>Q.getLDAPStatus()}),{data:l=[]}=q({queryKey:[`groups`],queryFn:()=>Q.getGroups()});(0,y.useEffect)(()=>{o&&a({ldap_server_url:o.ldap_server_url||``,ldap_bind_dn:o.ldap_bind_dn||``,ldap_bind_password:``,ldap_search_base:o.ldap_search_base||``,ldap_user_filter:o.ldap_user_filter||`(sAMAccountName={username})`,ldap_security:o.ldap_security||`starttls`,ldap_group_mapping:o.ldap_group_mapping||``,ldap_auto_provision:o.ldap_auto_provision??!1,ldap_default_group:o.ldap_default_group||``})},[o]);let u=J({mutationFn:e=>Q.updateSettings(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`settings`]}),n.invalidateQueries({queryKey:[`ldapStatus`]}),t(e(`settings.ldap.settingsSaved`)||`LDAP settings saved`,`success`)},onError:e=>{t(e.message,`error`)}}),d=J({mutationFn:e=>Q.updateSettings({ldap_enabled:e}),onSuccess:()=>{n.invalidateQueries({queryKey:[`settings`]}),n.invalidateQueries({queryKey:[`ldapStatus`]}),t(c?.ldap_enabled?e(`settings.ldap.disabled`)||`LDAP authentication disabled`:e(`settings.ldap.enabled`)||`LDAP authentication enabled`,`success`)},onError:e=>{t(e.message,`error`)}}),f=J({mutationFn:()=>Q.testLDAP(),onSuccess:e=>{t(e.message,e.success?`success`:`error`)},onError:e=>{t(e.message,`error`)}}),p=()=>{if(!i.ldap_server_url){t(e(`settings.ldap.errors.serverRequired`)||`LDAP server URL is required`,`error`);return}if(!i.ldap_search_base){t(e(`settings.ldap.errors.searchBaseRequired`)||`Search base DN is required`,`error`);return}let n={ldap_server_url:i.ldap_server_url,ldap_bind_dn:i.ldap_bind_dn,ldap_search_base:i.ldap_search_base,ldap_user_filter:i.ldap_user_filter,ldap_security:i.ldap_security,ldap_group_mapping:i.ldap_group_mapping,ldap_auto_provision:i.ldap_auto_provision,ldap_default_group:i.ldap_default_group};i.ldap_bind_password&&(n.ldap_bind_password=i.ldap_bind_password),u.mutate(n)},m=()=>{if(!r){t(e(`settings.ldap.errors.enableAuthFirst`)||`Enable authentication first`,`error`);return}if(!c?.ldap_enabled&&!c?.ldap_configured){t(e(`settings.ldap.errors.configureLdapFirst`)||`Save LDAP settings first`,`error`);return}d.mutate(!c?.ldap_enabled)};if(s)return(0,K.jsx)(`div`,{className:`flex items-center justify-center p-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})});let h=c?.ldap_enabled??!1,g=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`;return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(pd,{id:`card-ldap-toggle`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Hl,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.ldap.title`)||`LDAP Authentication`})]}),(0,K.jsx)($,{onClick:m,disabled:d.isPending,variant:h?`danger`:`primary`,children:h?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Vc,{className:`w-4 h-4`}),e(`common.disable`)||`Disable`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Hc,{className:`w-4 h-4`}),e(`common.enable`)||`Enable`]})})]})}),(0,K.jsx)(hd,{children:h?(0,K.jsx)(`div`,{className:`bg-green-500/10 border border-green-500/30 rounded-lg p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(ls,{className:`w-5 h-5 text-green-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.ldap.enabledDesc`)||`LDAP authentication is enabled`}),(0,K.jsxs)(`ul`,{className:`text-sm text-green-300 space-y-1 list-disc list-inside`,children:[(0,K.jsx)(`li`,{children:e(`settings.ldap.feature1`)||`Users can login with LDAP credentials`}),(0,K.jsx)(`li`,{children:e(`settings.ldap.feature2`)||`Local admin account remains as fallback`}),(0,K.jsx)(`li`,{children:e(`settings.ldap.feature3`)||`LDAP groups are mapped to BamBuddy groups on login`})]})]})]})}):(0,K.jsx)(`div`,{className:`bg-yellow-500/10 border border-yellow-500/30 rounded-lg p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(vu,{className:`w-5 h-5 text-yellow-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.ldap.disabledDesc`)||`LDAP authentication is disabled`}),(0,K.jsx)(`p`,{className:`text-sm text-yellow-300 mt-1`,children:e(`settings.ldap.disabledHint`)||`Configure and save LDAP settings below, then enable.`})]})]})})})]}),(0,K.jsxs)(pd,{id:`card-ldap-server`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.ldap.serverConfig`)||`LDAP Server Configuration`})}),(0,K.jsx)(hd,{children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-3`,children:[(0,K.jsxs)(`div`,{className:`md:col-span-2`,children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.serverUrl`)||`Server URL`}),(0,K.jsx)(`input`,{type:`text`,className:g,placeholder:`ldaps://ldap.example.com:636`,value:i.ldap_server_url,onChange:e=>a({...i,ldap_server_url:e.target.value})}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.serverUrlHint`)||`Use ldaps:// for SSL or ldap:// with StartTLS`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.security`)||`Security`}),(0,K.jsx)(`div`,{className:`flex gap-2`,children:[`starttls`,`ldaps`].map(e=>(0,K.jsx)(`button`,{onClick:()=>a({...i,ldap_security:e}),className:`flex-1 px-2 py-2 rounded-lg text-sm font-medium transition-colors ${i.ldap_security===e?`bg-bambu-green text-black`:`bg-bambu-dark-secondary text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:e===`starttls`?`StartTLS`:`LDAPS`},e))}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.securityHint`)||`Default port: ${Cze[i.ldap_security]}`})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.bindDn`)||`Bind DN (Service Account)`}),(0,K.jsx)(`input`,{type:`text`,className:g,placeholder:`cn=service-account,ou=service,dc=example,dc=com`,value:i.ldap_bind_dn,onChange:e=>a({...i,ldap_bind_dn:e.target.value})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.bindPassword`)||`Bind Password`}),(0,K.jsx)(`input`,{type:`password`,className:g,placeholder:o?.ldap_bind_dn?`••••••••`:``,value:i.ldap_bind_password,onChange:e=>a({...i,ldap_bind_password:e.target.value})})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.searchBase`)||`Search Base DN`}),(0,K.jsx)(`input`,{type:`text`,className:g,placeholder:`ou=users,dc=example,dc=com`,value:i.ldap_search_base,onChange:e=>a({...i,ldap_search_base:e.target.value})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.userFilter`)||`User Search Filter`}),(0,K.jsx)(`input`,{type:`text`,className:g,placeholder:`(sAMAccountName={username})`,value:i.ldap_user_filter,onChange:e=>a({...i,ldap_user_filter:e.target.value})})]})]}),(0,K.jsx)(Mf,{summary:(0,K.jsx)(`span`,{className:`text-sm font-medium text-bambu-gray`,children:e(`settings.ldap.advanced`)||`Advanced`}),className:`border-t border-bambu-dark-tertiary pt-3`,summaryClassName:`py-1`,children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white`,children:e(`settings.ldap.autoProvision`)||`Auto-provision users`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e(`settings.ldap.autoProvisionHint`)||`Automatically create a BamBuddy account on first LDAP login`})]}),(0,K.jsx)(`button`,{onClick:()=>a({...i,ldap_auto_provision:!i.ldap_auto_provision}),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors flex-shrink-0 ${i.ldap_auto_provision?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${i.ldap_auto_provision?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.defaultGroup`)||`Default group`}),(0,K.jsxs)(`select`,{className:g,value:i.ldap_default_group,onChange:e=>a({...i,ldap_default_group:e.target.value}),children:[(0,K.jsx)(`option`,{value:``,children:e(`settings.ldap.defaultGroupNone`)||`— None (reject login) —`}),l.map(e=>(0,K.jsx)(`option`,{value:e.name,children:e.name},e.id))]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.defaultGroupHint`)||`Fallback group assigned when an LDAP user authenticates but is not listed in any mapped group. Leave empty to leave unmapped users without permissions.`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.groupMapping`)||`Group Mapping (JSON)`}),(0,K.jsx)(`textarea`,{className:`${g} font-mono text-sm`,rows:4,placeholder:`{ "CN=PrintFarm_Admins,OU=Groups,DC=example,DC=com": "Administrators", "CN=PrintFarm_Users,OU=Groups,DC=example,DC=com": "Operators" }`,value:i.ldap_group_mapping,onChange:e=>a({...i,ldap_group_mapping:e.target.value})}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[e(`settings.ldap.groupMappingHint`)||`Map LDAP group DNs to BamBuddy groups. Available groups: `,l.map(e=>e.name).join(`, `)]})]})]})}),(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsxs)($,{onClick:p,disabled:u.isPending,children:[u.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(ls,{className:`w-4 h-4`}),e(`common.save`)||`Save`]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>f.mutate(),disabled:f.isPending,children:[f.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Pl,{className:`w-4 h-4`}),e(`settings.ldap.testConnection`)||`Test Connection`]})]})]})})]})]})}function n7({value:e,onChange:t,placeholder:n,maxLength:r=6}){return(0,K.jsx)(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value.toUpperCase().replace(/\s/g,``)),maxLength:r,className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors font-mono tracking-widest text-center`,placeholder:n,autoComplete:`one-time-code`})}function r7({codes:e,onDone:t}){let{t:n}=G(),[r,i]=(0,y.useState)(!1);return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`div`,{className:`bg-amber-500/10 border border-amber-500/30 rounded-lg p-4`,children:(0,K.jsx)(`p`,{className:`text-amber-400 text-sm font-medium`,children:n(`settings.twoFa.backupCodesWarning`)})}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:e.map((e,t)=>(0,K.jsx)(`code`,{className:`bg-bambu-dark-secondary rounded px-3 py-2 text-center font-mono text-sm text-white tracking-widest`,children:e},t))}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>{navigator.clipboard.writeText(e.join(` -`)),i(!0),setTimeout(()=>i(!1),2e3)},className:`flex items-center gap-2`,children:[(0,K.jsx)(Ds,{className:`w-4 h-4`}),n(r?`common.copied`:`common.copy`)]}),(0,K.jsx)($,{variant:`primary`,size:`sm`,onClick:t,className:`flex-1`,children:n(`settings.twoFa.savedCodes`)})]})]})}function wze({onDone:e}){let{t}=G(),n=Qa(),{showToast:r}=xd(),[i,a]=(0,y.useState)(`qr`),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)([]),[u,d]=(0,y.useState)(!1),{data:f,isLoading:p}=q({queryKey:[`totp-setup`],queryFn:()=>Q.setupTOTP(),staleTime:1/0}),m=J({mutationFn:e=>Q.enableTOTP(e),onSuccess:e=>{l(e.backup_codes),a(`backup`),n.invalidateQueries({queryKey:[`2fa-status`]})},onError:()=>r(t(`settings.twoFa.invalidCode`),`error`)});return p||!f?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,K.jsx)(Cl,{className:`w-6 h-6 animate-spin text-bambu-green`})}):i===`qr`?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:t(`settings.twoFa.setupInstructions`)}),(0,K.jsx)(`div`,{className:`flex justify-center`,children:(0,K.jsx)(`img`,{src:`data:image/png;base64,${f.qr_code_b64}`,alt:`TOTP QR Code`,className:`w-48 h-48 rounded-lg`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:t(`settings.twoFa.manualEntry`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 bg-bambu-dark-secondary rounded-lg px-3 py-2`,children:[(0,K.jsx)(`code`,{className:`text-white text-xs font-mono flex-1 break-all`,children:u?f.secret:`••••••••••••••••`}),(0,K.jsx)(`button`,{onClick:()=>d(!u),className:`text-bambu-gray hover:text-white`,children:u?(0,K.jsx)(Ws,{className:`w-4 h-4`}):(0,K.jsx)(Gs,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(f.secret)},className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(Ds,{className:`w-4 h-4`})})]})]}),(0,K.jsx)($,{variant:`primary`,className:`w-full`,onClick:()=>a(`confirm`),children:t(`settings.twoFa.scannedContinue`)})]}):i===`confirm`?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:t(`settings.twoFa.enterCodeToConfirm`)}),(0,K.jsx)(n7,{value:o,onChange:s,placeholder:`000000`}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>a(`qr`),className:`flex-1`,children:t(`common.back`)}),(0,K.jsx)($,{variant:`primary`,className:`flex-1`,disabled:o.length!==6||m.isPending,onClick:()=>m.mutate(o),children:m.isPending?t(`common.saving`):t(`settings.twoFa.activate`)})]})]}):(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`h3`,{className:`text-white font-medium`,children:t(`settings.twoFa.backupCodesTitle`)}),(0,K.jsx)(r7,{codes:c,onDone:e})]})}function Tze(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),{user:r}=sd(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(``),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(``),[T,E]=(0,y.useState)(!1),{data:D,isLoading:O}=q({queryKey:[`2fa-status`],queryFn:()=>Q.get2FAStatus()}),{data:k}=q({queryKey:[`oidc-links`],queryFn:()=>Q.getOIDCLinks()}),A=J({mutationFn:()=>Q.enableEmailOTP(),onSuccess:e=>{_(e.setup_token),n(e.message,`success`)},onError:t=>{let r=t.message??``;r.toLowerCase().includes(`smtp`)?n(e(`settings.twoFa.smtpRequired`),`error`):n(r,`error`)}}),j=J({mutationFn:()=>Q.confirmEnableEmailOTP(g,v),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),_(null),b(``),n(e(`settings.twoFa.emailOtpEnabled`),`success`)},onError:e=>n(e.message,`error`)}),M=J({mutationFn:e=>Q.disableEmailOTP(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),S(!1),w(``),n(e(`settings.twoFa.emailOtpDisabled`),`success`)},onError:e=>n(e.message,`error`)}),N=J({mutationFn:e=>Q.disableTOTP(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),s(!1),d(``),n(e(`settings.twoFa.totpDisabled`),`success`)},onError:()=>n(e(`settings.twoFa.invalidCode`),`error`)}),P=J({mutationFn:e=>Q.regenerateBackupCodes(e),onSuccess:e=>{t.invalidateQueries({queryKey:[`2fa-status`]}),l(!1),p(``),h(e.backup_codes)},onError:()=>n(e(`settings.twoFa.invalidCode`),`error`)}),F=J({mutationFn:e=>Q.deleteOIDCLink(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-links`]}),n(e(`settings.twoFa.oidcUnlinked`),`success`)},onError:e=>n(e.message,`error`)});if(O)return(0,K.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,K.jsx)(Cl,{className:`w-6 h-6 animate-spin text-bambu-green`})});let I=!!r?.email;return(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(pd,{id:`card-2fa-totp`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${D?.totp_enabled?`bg-green-500/20`:`bg-gray-500/20`}`,children:(0,K.jsx)(Yl,{className:`w-5 h-5 ${D?.totp_enabled?`text-green-400`:`text-gray-400`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.totpTitle`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.twoFa.totpDesc`)})]}),(0,K.jsx)(`div`,{className:`ml-auto`,children:D?.totp_enabled?(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-green-400 text-sm font-medium`,children:[(0,K.jsx)(Bl,{className:`w-4 h-4`}),` `,e(`common.enabled`)]}):(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray text-sm`,children:[(0,K.jsx)(Vl,{className:`w-4 h-4`}),` `,e(`common.disabled`)]})})]})}),(0,K.jsx)(hd,{children:i?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`h4`,{className:`text-white font-medium`,children:e(`settings.twoFa.setupAuthApp`)}),(0,K.jsx)(`button`,{onClick:()=>{a(!1),t.removeQueries({queryKey:[`totp-setup`]})},className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsx)(wze,{onDone:()=>{a(!1),t.removeQueries({queryKey:[`totp-setup`]})}})]}):o?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.disableConfirmHint`)}),(0,K.jsx)(n7,{value:u,onChange:d,placeholder:`000000 or XXXXXXXX`,maxLength:8}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>{s(!1),d(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,K.jsx)($,{variant:`danger`,className:`flex-1`,disabled:u.length<6||N.isPending,onClick:()=>N.mutate(u),children:N.isPending?e(`common.saving`):e(`settings.twoFa.disableTotp`)})]})]}):c?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.regenBackupHint`)}),(0,K.jsx)(n7,{value:f,onChange:p,placeholder:`000000 or XXXXXXXX`,maxLength:8}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>{l(!1),p(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,K.jsx)($,{variant:`primary`,className:`flex-1`,disabled:f.length<6||P.isPending,onClick:()=>P.mutate(f),children:P.isPending?e(`common.saving`):e(`settings.twoFa.regenBackup`)})]})]}):m?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`h4`,{className:`text-white font-medium`,children:e(`settings.twoFa.newBackupCodes`)}),(0,K.jsx)(r7,{codes:m,onDone:()=>h(null)})]}):(0,K.jsx)(`div`,{className:`space-y-3`,children:D?.totp_enabled?(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray-light`,children:[(0,K.jsx)(jc,{className:`w-4 h-4`}),e(`settings.twoFa.backupCodesRemaining`,{count:D.backup_codes_remaining})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>l(!0),className:`flex items-center gap-2`,children:[(0,K.jsx)(Cl,{className:`w-4 h-4`}),e(`settings.twoFa.regenBackup`)]}),(0,K.jsxs)($,{variant:`danger`,size:`sm`,onClick:()=>s(!0),className:`flex items-center gap-2`,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`settings.twoFa.disableTotp`)]})]}):(0,K.jsxs)($,{variant:`primary`,onClick:()=>a(!0),className:`flex items-center gap-2`,children:[(0,K.jsx)(Yl,{className:`w-4 h-4`}),e(`settings.twoFa.setupTotp`)]})})})]}),(0,K.jsxs)(pd,{id:`card-2fa-emailotp`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${D?.email_otp_enabled?`bg-green-500/20`:`bg-gray-500/20`}`,children:(0,K.jsx)(Gc,{className:`w-5 h-5 ${D?.email_otp_enabled?`text-green-400`:`text-gray-400`}`})}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.emailOtpTitle`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:I?e(`settings.twoFa.emailOtpDesc`,{email:r?.email}):e(`settings.twoFa.emailOtpNoEmail`)})]}),(0,K.jsx)(`div`,{className:`ml-auto`,children:D?.email_otp_enabled?(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-green-400 text-sm font-medium`,children:[(0,K.jsx)(Bl,{className:`w-4 h-4`}),` `,e(`common.enabled`)]}):(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray text-sm`,children:[(0,K.jsx)(Vl,{className:`w-4 h-4`}),` `,e(`common.disabled`)]})})]})}),(0,K.jsx)(hd,{children:I?g?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.emailSetupEnterCode`)}),(0,K.jsx)(n7,{value:v,onChange:b,placeholder:`000000`}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>{_(null),b(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,K.jsx)($,{variant:`primary`,className:`flex-1`,disabled:v.length!==6||j.isPending,onClick:()=>j.mutate(),children:j.isPending?e(`common.saving`):e(`settings.twoFa.verifyAndEnable`)})]})]}):x?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.emailDisablePasswordHint`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{type:T?`text`:`password`,value:C,onChange:e=>w(e.target.value),placeholder:e(`settings.twoFa.passwordPlaceholder`),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>E(!T),className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:T?(0,K.jsx)(Ws,{className:`w-5 h-5`}):(0,K.jsx)(Gs,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>{S(!1),w(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,K.jsx)($,{variant:`danger`,className:`flex-1`,disabled:!C||M.isPending,onClick:()=>M.mutate(C),children:M.isPending?e(`common.saving`):e(`settings.twoFa.disableEmailOtp`)})]})]}):(0,K.jsx)(`div`,{className:`flex gap-3`,children:D?.email_otp_enabled?(0,K.jsxs)($,{variant:`danger`,size:`sm`,onClick:()=>S(!0),className:`flex items-center gap-2`,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`settings.twoFa.disableEmailOtp`)]}):(0,K.jsxs)($,{variant:`primary`,disabled:!I||A.isPending,onClick:()=>A.mutate(),className:`flex items-center gap-2`,children:[(0,K.jsx)(Gc,{className:`w-4 h-4`}),A.isPending?e(`common.saving`):e(`settings.twoFa.enableEmailOtp`)]})}):(0,K.jsx)(`p`,{className:`text-amber-400 text-sm`,children:e(`settings.twoFa.addEmailFirst`)})})]}),k&&k.length>0&&(0,K.jsxs)(pd,{id:`card-2fa-linked`,children:[(0,K.jsxs)(md,{children:[(0,K.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.linkedAccounts`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.twoFa.linkedAccountsDesc`)})]}),(0,K.jsx)(hd,{children:(0,K.jsx)(`div`,{className:`space-y-3`,children:k.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between py-2 border-b border-bambu-dark-tertiary last:border-0`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white text-sm font-medium`,children:e.provider_name}),e.provider_email&&(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:e.provider_email})]}),(0,K.jsx)($,{variant:`danger`,size:`sm`,onClick:()=>F.mutate(e.provider_id),disabled:F.isPending,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]},e.id))})})]})]})}var Eze={name:``,issuer_url:``,client_id:``,client_secret:``,scopes:`openid email profile`,is_enabled:!0,auto_create_users:!1,auto_link_existing_accounts:!1,email_claim:`email`,require_email_verified:!0,icon_url:void 0,default_group_id:null};function i7({initial:e,isEdit:t=!1,groups:n=[],onSave:r,onCancel:i,isPending:a}){let{t:o}=G(),[s,c]=(0,y.useState)(e),[l,u]=(0,y.useState)(!1),d=(e,t)=>c(n=>({...n,[e]:t})),f=`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors text-sm`,p=`block text-sm font-medium text-white mb-1`,m=()=>{let e={...s};t&&!l&&delete e.client_secret,r(e)},h=s.auto_link_existing_accounts===!0,g=s.require_email_verified??!0,_;return _=h?o(`settings.oidc.form.requireEmailVerifiedAutoLink`):g?o(`settings.oidc.form.requireEmailVerifiedDesc`):(0,K.jsx)(`span`,{className:`text-red-400`,children:o(`settings.oidc.form.requireEmailVerifiedWarning`)}),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.name`),` `,(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsx)(`input`,{className:f,value:s.name,onChange:e=>d(`name`,e.target.value),placeholder:`Google`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.issuerUrl`),` `,(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsx)(`input`,{className:f,value:s.issuer_url,onChange:e=>d(`issuer_url`,e.target.value),placeholder:`https://accounts.google.com`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.clientId`),` `,(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsx)(`input`,{className:f,value:s.client_id,onChange:e=>d(`client_id`,e.target.value),placeholder:`your-client-id`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.clientSecret`),!t&&(0,K.jsx)(`span`,{className:`text-red-400`,children:` *`}),t&&(0,K.jsxs)(`span`,{className:`text-bambu-gray text-xs ml-1`,children:[`(`,o(`settings.oidc.form.secretHint`),`)`]})]}),(0,K.jsx)(`input`,{className:f,type:`password`,value:l?s.client_secret:``,placeholder:t&&!l?`••••••••`:o(`settings.oidc.form.secretPlaceholder`),onChange:e=>{u(!0),d(`client_secret`,e.target.value)}})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:p,children:o(`settings.oidc.form.scopes`)}),(0,K.jsx)(`input`,{className:f,value:s.scopes,onChange:e=>d(`scopes`,e.target.value),placeholder:`openid email profile`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:p,children:o(`settings.oidc.form.iconUrl`)}),(0,K.jsx)(`input`,{className:f,value:s.icon_url??``,onChange:e=>d(`icon_url`,e.target.value===``?null:e.target.value),placeholder:`https://...`})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-6 pt-2`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(y5,{checked:s.is_enabled??!0,onChange:e=>d(`is_enabled`,e)}),(0,K.jsx)(`span`,{className:`text-white text-sm`,children:o(`settings.oidc.form.enabled`)})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(y5,{checked:s.auto_create_users??!1,onChange:e=>d(`auto_create_users`,e)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autoCreate`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autoCreateDesc`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,K.jsx)(y5,{checked:s.auto_link_existing_accounts??!1,onChange:e=>d(`auto_link_existing_accounts`,e)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autoLink`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autoLinkDesc`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,K.jsx)(y5,{checked:g,onChange:e=>d(`require_email_verified`,e),disabled:h}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.requireEmailVerified`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:_})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:p,children:o(`settings.oidc.form.emailClaim`)}),(0,K.jsx)(`input`,{className:f,value:s.email_claim,onChange:e=>d(`email_claim`,e.target.value||`email`),placeholder:o(`settings.oidc.form.emailClaimPlaceholder`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:o(`settings.oidc.form.emailClaimDesc`)}),h&&s.email_claim!==`email`&&(0,K.jsx)(`p`,{className:`text-yellow-400 text-xs mt-1`,children:o(`settings.oidc.form.emailClaimCustomClaimAutoLinkWarning`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:p,children:o(`settings.oidc.form.defaultGroup`)}),(0,K.jsxs)(`select`,{className:f,value:s.default_group_id??``,onChange:e=>d(`default_group_id`,e.target.value?Number(e.target.value):null),children:[(0,K.jsx)(`option`,{value:``,children:o(`settings.oidc.form.defaultGroupViewersFallback`)}),n.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:o(`settings.oidc.form.defaultGroupDesc`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:i,className:`flex-1`,children:o(`common.cancel`)}),(0,K.jsx)($,{variant:`primary`,className:`flex-1`,disabled:!s.name||!s.issuer_url||!s.client_id||!t&&!s.client_secret||t&&l&&!s.client_secret||a,onClick:m,children:o(a?`common.saving`:`common.save`)})]})]})}function Dze({provider:e}){let[t,n]=(0,y.useState)(!1);return e.has_icon&&!t?(0,K.jsx)(`img`,{src:Q.oidcProviderIconUrl(e.id),alt:e.name,className:`w-8 h-8 rounded object-contain`,onError:()=>n(!0)}):(0,K.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,K.jsx)(hc,{className:`w-4 h-4 text-bambu-gray`})})}function Oze(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),{data:l,isLoading:u}=q({queryKey:[`oidc-providers-all`],queryFn:()=>Q.getOIDCProvidersAll()}),{data:d=[]}=q({queryKey:[`groups`],queryFn:()=>Q.getGroups()}),f=J({mutationFn:e=>Q.createOIDCProvider(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),i(!1),n(e(`settings.oidc.created`),`success`)},onError:e=>n(e.message,`error`)}),p=J({mutationFn:({id:e,data:t})=>Q.updateOIDCProvider(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),o(null),n(e(`settings.oidc.updated`),`success`)},onError:e=>n(e.message,`error`)}),m=J({mutationFn:e=>Q.deleteOIDCProvider(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),c(null),n(e(`settings.oidc.deleted`),`success`)},onError:e=>n(e.message,`error`)}),h=J({mutationFn:e=>Q.refreshOIDCProviderIcon(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),t.invalidateQueries({queryKey:[`oidc-providers`]}),n(e(`settings.oidc.iconRefreshed`),`success`)},onError:t=>n(t.message||e(`settings.oidc.iconFetchFailed`),`error`)}),g=J({mutationFn:e=>Q.deleteOIDCProviderIcon(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),t.invalidateQueries({queryKey:[`oidc-providers`]}),n(e(`settings.oidc.iconRemoved`),`success`)},onError:e=>n(e.message,`error`)}),_=e=>p.mutate({id:e.id,data:{is_enabled:!e.is_enabled}});return u?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,K.jsx)(Cl,{className:`w-6 h-6 animate-spin text-bambu-green`})}):(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(pd,{id:`card-oidc`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.oidc.title`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.oidc.desc`)})]}),!r&&(0,K.jsxs)($,{variant:`primary`,size:`sm`,onClick:()=>i(!0),className:`flex items-center gap-2`,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),e(`settings.oidc.addProvider`)]})]})}),r&&(0,K.jsx)(hd,{children:(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,K.jsx)(`h4`,{className:`text-white font-medium mb-4`,children:e(`settings.oidc.newProvider`)}),(0,K.jsx)(i7,{initial:Eze,groups:d,onSave:e=>f.mutate(e),onCancel:()=>i(!1),isPending:f.isPending})]})})]}),l&&l.length===0&&!r&&(0,K.jsx)(pd,{id:`card-oidc-empty`,children:(0,K.jsx)(hd,{children:(0,K.jsxs)(`div`,{className:`text-center py-8 space-y-3`,children:[(0,K.jsx)(hc,{className:`w-12 h-12 text-bambu-gray mx-auto`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.oidc.empty`)}),(0,K.jsxs)($,{variant:`primary`,size:`sm`,onClick:()=>i(!0),className:`inline-flex items-center gap-2`,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),e(`settings.oidc.addProvider`)]})]})})}),l?.map(t=>(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(Dze,{provider:t}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h4`,{className:`text-white font-medium`,children:t.name}),t.is_enabled?(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-green-400 bg-green-400/10 px-2 py-0.5 rounded-full`,children:[(0,K.jsx)($o,{className:`w-3 h-3`}),` `,e(`common.enabled`)]}):(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-0.5 rounded-full`,children:[(0,K.jsx)(Pu,{className:`w-3 h-3`}),` `,e(`common.disabled`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-bambu-gray text-xs mt-0.5`,children:[(0,K.jsx)(Us,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{children:t.issuer_url})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.icon_url&&(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>h.mutate(t.id),disabled:h.isPending,title:e(`settings.oidc.refreshIcon`),"data-testid":`refresh-icon-${t.id}`,children:(0,K.jsx)(Cl,{className:`w-4 h-4 ${h.isPending?`animate-spin`:``}`})}),t.has_icon&&(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>g.mutate(t.id),disabled:g.isPending,title:e(`settings.oidc.removeIcon`),"data-testid":`remove-icon-${t.id}`,children:(0,K.jsx)(Ec,{className:`w-4 h-4`})}),(0,K.jsx)(y5,{checked:t.is_enabled,onChange:()=>_(t),disabled:p.isPending}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>o(a===t.id?null:t.id),children:(0,K.jsx)(fl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`danger`,size:`sm`,onClick:()=>c(t),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]})}),a===t.id&&(0,K.jsx)(hd,{children:(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,K.jsx)(i7,{isEdit:!0,groups:d,initial:{name:t.name,issuer_url:t.issuer_url,client_id:t.client_id,client_secret:``,scopes:t.scopes,is_enabled:t.is_enabled,auto_create_users:t.auto_create_users,auto_link_existing_accounts:t.auto_link_existing_accounts,email_claim:t.email_claim,require_email_verified:t.require_email_verified,icon_url:t.icon_url??void 0,default_group_id:t.default_group_id??null},onSave:e=>p.mutate({id:t.id,data:e}),onCancel:()=>o(null),isPending:p.isPending})})}),a!==t.id&&(0,K.jsx)(hd,{children:(0,K.jsxs)(`dl`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-x-6 gap-y-2 text-sm`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.clientId`)}),(0,K.jsx)(`dd`,{className:`text-white font-mono truncate`,children:t.client_id})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.scopes`)}),(0,K.jsx)(`dd`,{className:`text-white`,children:t.scopes})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.autoCreate`)}),(0,K.jsx)(`dd`,{className:t.auto_create_users?`text-green-400`:`text-bambu-gray`,children:t.auto_create_users?e(`common.yes`):e(`common.no`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.autoLink`)}),(0,K.jsx)(`dd`,{className:t.auto_link_existing_accounts?`text-green-400`:`text-bambu-gray`,children:t.auto_link_existing_accounts?e(`common.yes`):e(`common.no`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.emailClaim`)}),(0,K.jsx)(`dd`,{className:`text-white font-mono`,children:t.email_claim})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.requireEmailVerified`)}),(0,K.jsx)(`dd`,{className:t.require_email_verified?`text-green-400`:`text-red-400`,children:t.require_email_verified?e(`common.yes`):e(`common.no`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.defaultGroup`)}),(0,K.jsx)(`dd`,{className:`text-white`,children:t.default_group_id?d.find(e=>e.id===t.default_group_id)?.name??e(`settings.oidc.form.defaultGroupViewersFallback`):e(`settings.oidc.form.defaultGroupViewersFallback`)})]})]})})]},t.id)),s&&(0,K.jsx)(Ed,{title:e(`settings.oidc.deleteTitle`),message:e(`settings.oidc.deleteMessage`,{name:s.name}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:()=>m.mutate(s.id),onCancel:()=>c(null)})]})}var a7=new Map;function o7(e){a7.set(e.anchor,e)}function kze(){return Array.from(a7.values())}o7({labelKey:`settings.encryption.title`,labelFallback:`MFA Encryption Status`,tab:`users`,subTab:`security`,keywords:`mfa encryption status security backup totp oidc fernet`,anchor:`card-mfa-encryption`});function Aze(){let{t:e}=G(),{data:t,isLoading:n,isError:r,refetch:i}=q({queryKey:[`encryptionStatus`],queryFn:()=>Q.getEncryptionStatus(),refetchInterval:e=>{if(!e.state.error)return 3e4;let t=e.state.fetchFailureCount??0;return t<=3?Math.min(5e3*Math.max(1,t),3e4):!1}});if(n)return(0,K.jsxs)(pd,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Hl,{className:`text-bambu-gray`,size:20}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,K.jsx)(hd,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,"data-testid":`encryption-loading`,children:[(0,K.jsx)(X,{className:`animate-spin`,size:16}),(0,K.jsx)(`span`,{children:e(`common.loading`)})]})})]});if(r||!t)return(0,K.jsxs)(pd,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Hl,{className:`text-bambu-gray`,size:20}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,K.jsxs)(hd,{children:[(0,K.jsx)(`div`,{className:`text-red-400`,"data-testid":`encryption-error`,children:e(`common.errorLoading`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>i(),className:`mt-2 text-sm text-blue-400 underline hover:text-blue-300`,"data-testid":`encryption-retry-button`,children:e(`common.retry`)})]})]});let a=t.legacy_plaintext_rows.oidc_providers+t.legacy_plaintext_rows.user_totp,o=t.encrypted_rows.oidc_providers+t.encrypted_rows.user_totp,s,c,l,u;t.decryption_broken?(s=`bg-red-500/20 border-red-500/50 text-red-400`,c=(0,K.jsx)(ms,{className:`text-red-400`,size:20}),l=e(`settings.encryption.decryptionBrokenTitle`),u=e(`settings.encryption.decryptionBrokenError`,{count:o})):t.key_source===`generated`?(s=`bg-amber-500/10 border-amber-500/30 text-amber-400`,c=(0,K.jsx)(Bl,{className:`text-amber-400`,size:20}),l=e(`settings.encryption.enabledGenerated`),u=e(`settings.encryption.backupHint`)):a>0?(s=`bg-amber-500/10 border-amber-500/30 text-amber-400`,c=(0,K.jsx)(vu,{className:`text-amber-400`,size:20}),l=t.key_source===`env`?e(`settings.encryption.enabledFromEnv`):e(`settings.encryption.enabledFromFile`),u=e(`settings.encryption.legacyRowsWarning`,{count:a})):t.key_configured?(s=`bg-green-500/20 border-green-500/30 text-green-400`,c=(0,K.jsx)(Bl,{className:`text-green-400`,size:20}),l=t.key_source===`env`?e(`settings.encryption.enabledFromEnv`):e(`settings.encryption.enabledFromFile`),u=e(`settings.encryption.allEncrypted`)):(s=`bg-gray-500/20 border-gray-500/30 text-gray-400`,c=(0,K.jsx)(Vl,{className:`text-gray-400`,size:20}),l=e(`settings.encryption.notConfigured`),u=e(`settings.encryption.notConfiguredDesc`));let d=t.key_source===`generated`&&a>0;return(0,K.jsxs)(pd,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c,(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,K.jsxs)(hd,{children:[(0,K.jsxs)(`div`,{className:`p-3 border rounded-lg ${s}`,"data-testid":`encryption-status`,children:[(0,K.jsx)(`p`,{className:`font-medium mb-1`,children:l}),(0,K.jsx)(`p`,{className:`text-sm`,children:u})]}),d&&(0,K.jsx)(`div`,{className:`mt-2 p-3 border rounded-lg bg-amber-500/10 border-amber-500/30 text-amber-400`,"data-testid":`encryption-legacy-warning`,children:(0,K.jsx)(`p`,{className:`text-sm`,children:e(`settings.encryption.legacyRowsWarning`,{count:a})})}),t.migration_error_count>0&&(0,K.jsx)(`div`,{className:`mt-2 p-3 border rounded-lg bg-amber-500/10 border-amber-500/30 text-amber-400`,"data-testid":`encryption-migration-warning`,children:(0,K.jsx)(`p`,{className:`text-sm`,children:e(`settings.encryption.migrationErrorWarning`,{count:t.migration_error_count})})}),(0,K.jsxs)(`div`,{className:`mt-4 grid grid-cols-2 gap-4 text-sm`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.encryption.encryptedRowsLabel`)}),(0,K.jsxs)(`p`,{className:`font-medium`,children:[`OIDC: `,t.encrypted_rows.oidc_providers,` · TOTP: `,t.encrypted_rows.user_totp]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.encryption.legacyRowsLabel`)}),(0,K.jsxs)(`p`,{className:`font-medium`,children:[`OIDC: `,t.legacy_plaintext_rows.oidc_providers,` · TOTP: `,t.legacy_plaintext_rows.user_totp]})]})]})]})]})}var jze={get:`bg-blue-500/20 text-blue-400 border-blue-500/30`,post:`bg-green-500/20 text-green-400 border-green-500/30`,put:`bg-yellow-500/20 text-yellow-400 border-yellow-500/30`,patch:`bg-orange-500/20 text-orange-400 border-orange-500/30`,delete:`bg-red-500/20 text-red-400 border-red-500/30`};function Mze(e,t){let n=t.replace(`#/`,``).split(`/`),r=e;for(let e of n)r=r[e];return r}function s7(e,t,n=0){if(n>5)return`...`;if(t.$ref)return s7(e,Mze(e,t.$ref),n+1);if(t.allOf){let r={};for(let i of t.allOf){let t=s7(e,i,n+1);typeof t==`object`&&t&&Object.assign(r,t)}return r}if(t.example!==void 0)return t.example;if(t.default!==void 0)return t.default;switch(t.type){case`string`:return t.enum?t.enum[0]:`string`;case`integer`:case`number`:return 0;case`boolean`:return!1;case`array`:return t.items?[s7(e,t.items,n+1)]:[];case`object`:if(t.properties){let r={};for(let[i,a]of Object.entries(t.properties))r[i]=s7(e,a,n+1);return r}return{};default:return null}}function Nze({path:e,method:t,spec:n,schema:r,apiKey:i}){let[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)({}),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!1);(0,y.useEffect)(()=>{if(a&&n.parameters){let e={};for(let t of n.parameters)t.schema?.default!==void 0&&(e[t.name]=String(t.schema.default));c(t=>({...e,...t}))}},[a,n.parameters]),(0,y.useEffect)(()=>{if(a&&n.requestBody?.content?.[`application/json`]?.schema&&!l){let e=n.requestBody.content[`application/json`].schema,t=s7(r,e);u(JSON.stringify(t,null,2))}},[a,n.requestBody,r,l]);let _=(()=>{let e=[];for(let t of n.parameters||[])if(t.in===`path`||t.required){let n=s[t.name];(n===void 0||n===``)&&e.push(t.name)}return e})(),v=async()=>{if(_.length>0){f({status:0,statusText:`Validation Error`,headers:{},body:`Missing required parameters: ${_.join(`, `)}`,duration:0});return}m(!0),f(null);try{let r=e,a=new URLSearchParams;for(let e of n.parameters||[]){let t=s[e.name];t!==void 0&&t!==``&&(e.in===`path`?r=r.replace(`{${e.name}}`,encodeURIComponent(t)):e.in===`query`&&a.append(e.name,t))}let o=a.toString(),c=`${r}${o?`?${o}`:``}`,u={"Content-Type":`application/json`};i&&(u[`X-API-Key`]=i);let d={method:t.toUpperCase(),headers:u};[`post`,`put`,`patch`].includes(t)&&l&&(d.body=l);let p=performance.now(),m=await fetch(c,d),h=Math.round(performance.now()-p),g={};m.headers.forEach((e,t)=>{g[t]=e});let _;_=m.headers.get(`content-type`)?.includes(`application/json`)?await m.json():await m.text(),f({status:m.status,statusText:m.statusText,headers:g,body:_,duration:h})}catch(e){f({status:0,statusText:`Network Error`,headers:{},body:e instanceof Error?e.message:`Unknown error`,duration:0})}finally{m(!1)}},b=async()=>{if(d){let e=typeof d.body==`string`?d.body:JSON.stringify(d.body,null,2);try{await navigator.clipboard.writeText(e),g(!0),setTimeout(()=>g(!1),2e3)}catch{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.left=`-999999px`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t),g(!0),setTimeout(()=>g(!1),2e3)}}},x=(n.parameters||[]).filter(e=>e.in===`path`),S=(n.parameters||[]).filter(e=>e.in===`query`),C=[`post`,`put`,`patch`].includes(t)&&n.requestBody;return(0,K.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`button`,{onClick:()=>o(!a),className:`w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left`,children:[a?(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}):(0,K.jsx)(ts,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${jze[t]||`bg-gray-500/20 text-gray-400`}`,children:t}),(0,K.jsx)(`code`,{className:`text-sm text-white font-mono flex-1 truncate`,children:e}),n.summary&&(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray truncate max-w-[40%]`,children:n.summary})]}),a&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50`,children:[n.description&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n.description}),x.length>0&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Path Parameters`}),(0,K.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`label`,{className:`text-sm text-bambu-gray w-32 flex-shrink-0`,children:[e.name,e.required&&(0,K.jsx)(`span`,{className:`text-red-400 ml-1`,children:`*`})]}),(0,K.jsx)(`input`,{type:`text`,value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),placeholder:e.description||e.schema?.type||`value`,className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`})]},e.name))})]}),S.length>0&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Query Parameters`}),(0,K.jsx)(`div`,{className:`space-y-2`,children:S.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`label`,{className:`text-sm text-bambu-gray w-32 flex-shrink-0`,children:[e.name,e.required&&(0,K.jsx)(`span`,{className:`text-red-400 ml-1`,children:`*`})]}),e.schema?.enum?(0,K.jsxs)(`select`,{value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:``,children:`-- Select --`}),e.schema.enum.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}):(0,K.jsx)(`input`,{type:`text`,value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),placeholder:e.description||e.schema?.type||`value`,className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`})]},e.name))})]}),C&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Request Body`}),(0,K.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),rows:8,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono focus:border-bambu-green focus:outline-none resize-y`,placeholder:`JSON request body...`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)($,{onClick:v,disabled:p,children:[p?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hl,{className:`w-4 h-4`}),`Execute`]}),_.length>0&&(0,K.jsxs)(`span`,{className:`text-xs text-yellow-400 flex items-center gap-1`,children:[(0,K.jsx)(ss,{className:`w-3 h-3`}),`Fill in: `,_.join(`, `)]})]}),d&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`h4`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[`Response`,(0,K.jsxs)(`span`,{className:`px-2 py-0.5 text-xs rounded ${d.status>=200&&d.status<300?`bg-green-500/20 text-green-400`:d.status>=400?`bg-red-500/20 text-red-400`:`bg-yellow-500/20 text-yellow-400`}`,children:[d.status,` `,d.statusText]}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[d.duration,`ms`]})]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:b,children:h?(0,K.jsx)(ls,{className:`w-3 h-3 text-green-400`}):(0,K.jsx)(Ds,{className:`w-3 h-3`})})]}),(0,K.jsx)(`pre`,{className:`p-3 bg-bambu-dark rounded-lg text-sm font-mono text-white overflow-auto max-h-96 border border-bambu-dark-tertiary`,children:typeof d.body==`string`?d.body:JSON.stringify(d.body,null,2)})]})]})]})}function Pze({apiKey:e=``}){let[t,n]=(0,y.useState)(null),[r,i]=(0,y.useState)(!0),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(new Set),[l,u]=(0,y.useState)(``);if((0,y.useEffect)(()=>{async function e(){try{let e=await fetch(`/openapi.json`);if(!e.ok)throw Error(`Failed to fetch OpenAPI schema`);n(await e.json())}catch(e){o(e instanceof Error?e.message:`Unknown error`)}finally{i(!1)}}e()},[]),r)return(0,K.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(a||!t)return(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-8`,children:(0,K.jsxs)(`div`,{className:`text-center text-red-400`,children:[(0,K.jsx)(ss,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,K.jsx)(`p`,{children:`Failed to load API schema`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:a})]})})});let d={};for(let[e,n]of Object.entries(t.paths))for(let[t,r]of Object.entries(n)){if(t===`parameters`)continue;let n=r.tags||[`Other`];for(let i of n)d[i]||(d[i]=[]),d[i].push({path:e,method:t,spec:r})}let f=Object.entries(d).map(([e,t])=>l?{tag:e,endpoints:t.filter(({path:e,method:t,spec:n})=>{let r=l.toLowerCase();return e.toLowerCase().includes(r)||t.toLowerCase().includes(r)||(n.summary?.toLowerCase()||``).includes(r)||(n.description?.toLowerCase()||``).includes(r)})}:{tag:e,endpoints:t}).filter(({endpoints:e})=>e.length>0).sort((e,t)=>e.tag.localeCompare(t.tag)),p=e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,K.jsx)(`div`,{className:`flex-1`,children:(0,K.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`Search endpoints...`,className:`w-full max-w-md px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>{c(new Set(f.map(e=>e.tag)))},children:`Expand All`}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>{c(new Set)},children:`Collapse All`}),(0,K.jsxs)(`a`,{href:`/docs`,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-sm text-bambu-green hover:underline`,children:[(0,K.jsx)(Us,{className:`w-4 h-4`}),`Swagger UI`]})]})]}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[f.reduce((e,t)=>e+t.endpoints.length,0),` endpoints in `,f.length,` categories`]}),(0,K.jsx)(`div`,{className:`space-y-3`,children:f.map(({tag:n,endpoints:r})=>(0,K.jsxs)(pd,{children:[(0,K.jsx)(`button`,{onClick:()=>p(n),className:`w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[s.has(n)?(0,K.jsx)(es,{className:`w-5 h-5 text-bambu-gray`}):(0,K.jsx)(ts,{className:`w-5 h-5 text-bambu-gray`}),(0,K.jsx)(`h3`,{className:`text-base font-semibold text-white capitalize`,children:n.replace(/-/g,` `)}),(0,K.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray`,children:r.length})]})}),s.has(n)&&(0,K.jsx)(hd,{className:`pt-0 space-y-2`,children:r.map(({path:n,method:r,spec:i})=>(0,K.jsx)(Nze,{path:n,method:r,spec:i,schema:t,apiKey:e},`${r}-${n}`))})]},n))})]})}var Fze=[`general`,`plugs`,`notifications`,`queue`,`filament`,`network`,`apikeys`,`virtual-printer`,`spoolbuddy`,`failure-detection`,`users`,`backup`];o7({labelKey:`settings.general`,tab:`general`,keywords:`language date time format printer model printers cards`,anchor:`card-general`}),o7({labelKey:`settings.appearance`,tab:`general`,keywords:`theme dark light mode colors`,anchor:`card-appearance`}),o7({labelKey:`settings.archiveSettings`,tab:`general`,keywords:`archive auto save thumbnails captures`,anchor:`card-archive`}),o7({labelKey:`settings.camera`,tab:`general`,keywords:`camera external video stream`,anchor:`card-camera`}),o7({labelKey:`settings.costTracking`,tab:`general`,keywords:`currency filament cost energy kwh price`,anchor:`card-cost`}),o7({labelKey:`settings.fileManager`,tab:`general`,keywords:`file manager archive mode disk warning storage`,anchor:`card-filemanager`}),o7({labelKey:`settings.updates`,tab:`general`,keywords:`updates version firmware beta check`,anchor:`card-updates`}),o7({labelKey:`settings.dataManagement`,tab:`general`,keywords:`data reset clear logs notifications preferences`,anchor:`card-data`}),o7({labelKey:`settings.smartPlugs`,tab:`plugs`,keywords:`smart plug energy power automation tapo kasa tplink shelly`,anchor:`card-plugs`}),o7({labelKey:`settings.providers`,tab:`notifications`,keywords:`telegram discord email notification providers webhook`,anchor:`card-providers`}),o7({labelKey:`settings.messageTemplates`,tab:`notifications`,keywords:`message templates notification text edit`,anchor:`card-templates`}),o7({labelKey:`settings.defaultPrintOptions`,labelFallback:`Default Print Options`,tab:`queue`,keywords:`print bed leveling flow calibration vibration first layer timelapse`,anchor:`card-print-options`}),o7({labelKey:`settings.tempFanPresetsTitle`,labelFallback:`Temperature & Fan Presets`,tab:`queue`,keywords:`temperature fan presets nozzle bed chamber quick buttons popover`,anchor:`card-temp-fan-presets`}),o7({labelKey:`settings.staggeredStart`,labelFallback:`Staggered Start`,tab:`queue`,keywords:`staggered batch delay start queue group`,anchor:`card-staggered`}),o7({labelKey:`settings.plateClear`,labelFallback:`Plate-Clear Confirmation`,tab:`queue`,keywords:`plate clear confirm auto queue`,anchor:`card-plate`}),o7({labelKey:`settings.gcodeInjection`,labelFallback:`G-code Injection`,tab:`queue`,keywords:`gcode injection start end autoprint farmloop swapmod autoclear printflow`,anchor:`card-gcode`}),o7({labelKey:`settings.slicerCard`,labelFallback:`Slicer`,tab:`queue`,keywords:`slicer orcaslicer bambustudio orca bambu api sidecar url docker preferred`,anchor:`card-slicer`}),o7({labelKey:`settings.queueDrying`,tab:`queue`,keywords:`drying presets temperature time humidity ams`,anchor:`card-drying`}),o7({labelKey:`settings.filamentChecks`,tab:`filament`,keywords:`filament check warning runout remaining`,anchor:`card-filamentchecks`}),o7({labelKey:`settings.printModal`,tab:`filament`,keywords:`print modal custom mapping`,anchor:`card-printmodal`}),o7({labelKey:`settings.amsDisplayThresholds`,tab:`filament`,keywords:`ams humidity temperature threshold history retention`,anchor:`card-amsthresholds`}),o7({labelKey:`settings.externalUrl`,tab:`network`,keywords:`external url reverse proxy public notification link`,anchor:`card-externalurl`}),o7({labelKey:`settings.ftpRetry`,tab:`network`,keywords:`ftp retry upload retries backoff`,anchor:`card-ftpretry`}),o7({labelKey:`settings.homeAssistant`,tab:`network`,keywords:`home assistant ha hass mqtt integration`,anchor:`card-ha`}),o7({labelKey:`settings.mqttPublishing`,tab:`network`,keywords:`mqtt publish broker topic`,anchor:`card-mqtt`}),o7({labelKey:`settings.prometheusMetrics`,tab:`network`,keywords:`prometheus metrics grafana monitoring bearer token`,anchor:`card-prometheus`}),o7({labelKey:`settings.createNewApiKey`,tab:`apikeys`,keywords:`api key create permission scope`,anchor:`card-createapi`}),o7({labelKey:`settings.webhookEndpoints`,tab:`apikeys`,keywords:`webhook endpoint post http`,anchor:`card-webhooks`}),o7({labelKey:`settings.apiBrowser`,tab:`apikeys`,keywords:`api browser endpoint documentation test`,anchor:`card-apibrowser`}),o7({labelKey:`cameraTokens.title`,tab:`apikeys`,keywords:`camera token long-lived home assistant frigate kiosk stream`,anchor:`card-camera-tokens`}),o7({labelKey:`settings.tabs.virtualPrinter`,tab:`virtual-printer`,keywords:`virtual printer proxy archive slicer bambustudio orcaslicer ip bind`,anchor:`card-vp`}),o7({labelKey:`settings.tabs.spoolbuddy`,tab:`spoolbuddy`,keywords:`spoolbuddy device scale nfc rfid kiosk unregister`,anchor:`card-spoolbuddy`}),o7({labelKey:`settings.currentUser`,tab:`users`,subTab:`users`,keywords:`current user profile password change`,anchor:`card-currentuser`}),o7({labelKey:`settings.users`,tab:`users`,subTab:`users`,keywords:`users accounts list`,anchor:`card-users`}),o7({labelKey:`settings.groups`,tab:`users`,subTab:`users`,keywords:`groups roles permissions administrators operators viewers`,anchor:`card-groups`}),o7({labelKey:`settings.sessionPolicy.title`,labelFallback:`Session Policy`,tab:`users`,subTab:`users`,keywords:`session timeout expiry logout remember me jwt token lifetime`,anchor:`card-session-policy`}),o7({labelKey:`settings.email.smtpSettings`,labelFallback:`SMTP Configuration`,tab:`users`,subTab:`email`,keywords:`smtp email send server port password auth starttls ssl`,anchor:`card-smtp`}),o7({labelKey:`settings.ldap.title`,labelFallback:`LDAP Authentication`,tab:`users`,subTab:`ldap`,keywords:`ldap active directory ad authentication bind dn search base group mapping`,anchor:`card-ldap`}),o7({labelKey:`settings.tabs.backup`,tab:`backup`,keywords:`backup github restore download cloud sync profiles archives`,anchor:`card-backup`}),o7({labelKey:`externalLinks.sidebarLayout`,labelFallback:`Sidebar`,tab:`general`,keywords:`sidebar layout links pages hide show external custom navigation url add`,anchor:`card-sidebar-links`}),o7({labelKey:`settings.filamentTracking`,tab:`filament`,keywords:`spoolman filament tracking inventory sync remote integration`,anchor:`card-spoolman`}),o7({labelKey:`settings.catalog.spoolCatalog`,labelFallback:`Spool Catalog`,tab:`filament`,keywords:`spool catalog entries brand material reset import export`,anchor:`card-spool-catalog`}),o7({labelKey:`settings.colorCatalog.title`,labelFallback:`Color Catalog`,tab:`filament`,keywords:`color catalog hex swatch palette sync reset`,anchor:`card-color-catalog`}),o7({labelKey:`settings.tabs.failureDetection`,labelFallback:`Failure Detection`,tab:`failure-detection`,keywords:`failure detection ai ml obico spaghetti detect monitoring`,anchor:`card-fd-ml`}),o7({labelKey:`failureDetection.perPrinterTitle`,labelFallback:`Per-Printer Settings`,tab:`failure-detection`,keywords:`failure detection per printer enable per-printer sensitivity`,anchor:`card-fd-perprinter`}),o7({labelKey:`failureDetection.statusTitle`,labelFallback:`Detection Status`,tab:`failure-detection`,keywords:`failure detection status running connection`,anchor:`card-fd-status`}),o7({labelKey:`failureDetection.historyTitle`,labelFallback:`Detection History`,tab:`failure-detection`,keywords:`failure detection history log events`,anchor:`card-fd-history`}),o7({labelKey:`settings.email.advancedAuth`,labelFallback:`Advanced Email Authentication`,tab:`users`,subTab:`email`,keywords:`email authentication advanced password reset self-service forgot`,anchor:`card-email-advanced-auth`}),o7({labelKey:`settings.email.testConnection`,labelFallback:`Test SMTP Connection`,tab:`users`,subTab:`email`,keywords:`email smtp test connection send check`,anchor:`card-email-test`}),o7({labelKey:`settings.twoFa.totpTitle`,labelFallback:`Authenticator App (TOTP)`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa totp authenticator app google authy otp`,anchor:`card-2fa-totp`}),o7({labelKey:`settings.twoFa.emailOtpTitle`,labelFallback:`Email One-Time Codes`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa email otp one time code`,anchor:`card-2fa-emailotp`}),o7({labelKey:`settings.twoFa.linkedAccounts`,labelFallback:`Linked Accounts`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa linked accounts sso oidc provider google github`,anchor:`card-2fa-linked`}),o7({labelKey:`settings.oidc.title`,labelFallback:`Single Sign-On (OIDC)`,tab:`users`,subTab:`oidc`,keywords:`sso oidc openid single sign-on pocketid authentik keycloak google okta azure provider`,anchor:`card-oidc`}),o7({labelKey:`settings.ldap.serverConfig`,labelFallback:`LDAP Server Configuration`,tab:`users`,subTab:`ldap`,keywords:`ldap server url bind dn user search base group filter tls`,anchor:`card-ldap-server`}),o7({labelKey:`backup.githubBackup`,labelFallback:`GitHub Backup`,tab:`backup`,keywords:`github backup cloud remote sync profiles token`,anchor:`card-backup-github`}),o7({labelKey:`backup.history`,labelFallback:`Backup History`,tab:`backup`,keywords:`backup history log runs github commits`,anchor:`card-backup-history`}),o7({labelKey:`backup.localBackup`,labelFallback:`Local Backup`,tab:`backup`,keywords:`local backup download zip manual export`,anchor:`card-backup-local`}),o7({labelKey:`backup.scheduledBackup`,labelFallback:`Scheduled Backups`,tab:`backup`,keywords:`scheduled backup automatic hourly daily weekly retention local path`,anchor:`card-backup-scheduled`});var Ize={database:`bg-blue-600`,library_files:`bg-green-500`,library_thumbnails:`bg-teal-500`,library_other:`bg-emerald-700`,archive_timelapses:`bg-red-500`,archive_thumbnails:`bg-amber-500`,archive_files:`bg-sky-500`,virtual_printer_uploads:`bg-purple-500`,virtual_printer_upload_cache:`bg-fuchsia-500`,virtual_printer_certs:`bg-violet-500`,virtual_printer_other:`bg-purple-700`,downloads:`bg-cyan-500`,plate_calibration:`bg-lime-500`,logs:`bg-orange-500`,other_data:`bg-yellow-500`},c7=[`bg-blue-500`,`bg-green-500`,`bg-yellow-500`,`bg-red-500`,`bg-orange-500`,`bg-teal-500`,`bg-cyan-500`,`bg-purple-500`],l7=(e,t)=>Ize[e]||c7[t%c7.length];function Lze(){let e=Qa(),t=Yn(),[n,r]=Oi(),{t:i,i18n:a}=G(),{showToast:o}=xd(),{authEnabled:s,user:c,isAdmin:l,refreshAuth:u,hasPermission:d}=sd(),{mode:f,resolvedMode:p,darkStyle:m,darkBackground:h,darkAccent:g,lightStyle:_,lightBackground:v,lightAccent:b,setMode:x,setDarkStyle:S,setDarkBackground:C,setDarkAccent:w,setLightStyle:T,setLightBackground:E,setLightAccent:D}=ud(),[O,k]=(0,y.useState)(null),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(null),[B,V]=(0,y.useState)(``),[ee,H]=(0,y.useState)(``),[te,ne]=(0,y.useState)(!1),[re,U]=(0,y.useState)(Jf()),ie=n.get(`tab`),ae=ie===`email`,[W,oe]=(0,y.useState)(ae?`users`:ie&&Fze.includes(ie)?ie:`general`),[se,ce]=(0,y.useState)(ae?`email`:`users`),le=e=>{oe(e),e===`users`&&ce(`users`),e===`general`?n.delete(`tab`):n.set(`tab`,e),r(n,{replace:!0})},[ue,de]=(0,y.useState)(!1),[fe,pe]=(0,y.useState)(``),[me,he]=(0,y.useState)({can_queue:!0,can_control_printer:!1,can_read_status:!0,can_manage_library:!0,can_manage_inventory:!0,can_access_cloud:!1,can_update_energy_cost:!1}),[ge,_e]=(0,y.useState)(null),[ve,ye]=(0,y.useState)(!1),[be,xe]=(0,y.useState)(null),[Se,Ce]=(0,y.useState)(``),[we,Te]=(0,y.useState)(!1),[Ee,De]=(0,y.useState)(!1),[Oe,ke]=(0,y.useState)(null),[Ae,je]=(0,y.useState)(!1),[Me,Ne]=(0,y.useState)(!1),[Pe,Fe]=(0,y.useState)(!1),[Ie,Le]=(0,y.useState)({currentPassword:``,newPassword:``,confirmPassword:``}),[Re,ze]=(0,y.useState)(!1),[Be,Ve]=(0,y.useState)(!1),[He,Ue]=(0,y.useState)(!1),[We,Ge]=(0,y.useState)(`local`),[Ke,qe]=(0,y.useState)(!1),[Je,Ye]=(0,y.useState)(null),[Xe,Ze]=(0,y.useState)(null),[Qe,$e]=(0,y.useState)(null),[et,tt]=(0,y.useState)(!1),[nt,rt]=(0,y.useState)({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),[it,at]=(0,y.useState)(null),[ot,st]=(0,y.useState)(null),[ct,lt]=(0,y.useState)(!1),[ut,dt]=(0,y.useState)({}),[ft,pt]=(0,y.useState)({}),mt=e=>{U(e),Yf(e),o(i(`settings.toast.settingsSaved`),`success`)},{data:ht,isLoading:gt}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:_t,isLoading:vt,isFetching:yt}=q({queryKey:[`storage-usage`],queryFn:()=>Q.getStorageUsage(),enabled:W===`general`,staleTime:1/0,refetchInterval:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1}),bt=async()=>{Ve(!0);try{let t=await Q.getStorageUsage({refresh:!0});e.setQueryData([`storage-usage`],t)}catch(e){o(e instanceof Error?e.message:`Failed to refresh storage usage`,`error`)}finally{Ve(!1)}},{data:xt,isLoading:St}=q({queryKey:[`smart-plugs`],queryFn:Q.getSmartPlugs}),{data:wt,isLoading:Tt}=q({queryKey:[`smart-plugs-energy`,xt?.map(e=>e.id)],queryFn:async()=>{if(!xt||xt.length===0)return null;let e=await Promise.all(xt.filter(e=>e.enabled).map(async e=>{try{return{plug:e,status:await Q.getSmartPlugStatus(e.id)}}catch{return{plug:e,status:null}}})),t=0,n=0,r=0,i=0,a=0;for(let{plug:o,status:s}of e){let e=o.plug_type===`mqtt`&&s?.energy?.power!=null;(s?.reachable||e)&&s?.energy&&(a++,s.energy?.power!=null&&(t+=s.energy.power),s.energy?.today!=null&&(n+=s.energy.today),s.energy?.yesterday!=null&&(r+=s.energy.yesterday),s.energy?.total!=null&&(i+=s.energy.total))}return{totalPower:t,totalToday:n,totalYesterday:r,totalLifetime:i,reachableCount:a,totalPlugs:xt.filter(e=>e.enabled).length}},enabled:W===`plugs`&&!!xt&&xt.length>0,refetchInterval:W===`plugs`?1e4:!1}),{data:Et,isLoading:Dt}=q({queryKey:[`notification-providers`],queryFn:Q.getNotificationProviders}),{data:Ot,isLoading:kt}=q({queryKey:[`api-keys`],queryFn:Q.getAPIKeys}),At=J({mutationFn:e=>Q.createAPIKey(e),onSuccess:t=>{_e(t.key||null),de(!1),pe(``),e.invalidateQueries({queryKey:[`api-keys`]}),o(i(`settings.toast.apiKeyCreated`))},onError:e=>{o(`Failed to create API key: ${e.message}`,`error`)}}),jt=J({mutationFn:e=>Q.deleteAPIKey(e),onSuccess:(t,n)=>{e.setQueryData([`api-keys`],e=>(e??[]).filter(e=>e.id!==n)),o(i(`settings.toast.apiKeyDeleted`))},onError:e=>{o(`Failed to delete API key: ${e.message}`,`error`)}}),{data:Mt}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:Nt,isLoading:Pt}=q({queryKey:[`notification-templates`],queryFn:Q.getNotificationTemplates}),{data:Ft}=q({queryKey:[`virtual-printer-settings`],queryFn:Zu.getSettings,refetchInterval:1e4}),It=Ft?.status?.running??!1,{data:Lt}=q({queryKey:[`spoolbuddy-devices`],queryFn:()=>nd.getDevices(),refetchInterval:15e3}),Rt=Lt?.length??0,zt=Lt?.some(e=>e.online)??!1,{data:Bt}=q({queryKey:[`obico-status`],queryFn:Q.getObicoStatus,refetchInterval:15e3}),Vt=!!(Bt?.is_running&&Bt?.enabled),{data:Ht}=q({queryKey:[`ffmpeg-status`],queryFn:Q.checkFfmpeg}),{data:Ut}=q({queryKey:[`version`],queryFn:Q.getVersion}),Wt=!s||d(`library:purge`),{data:Gt}=q({queryKey:[`library-trash-settings`],queryFn:()=>Q.getLibraryTrashSettings(),enabled:Wt}),Kt=J({mutationFn:e=>Q.updateLibraryTrashSettings(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`library-trash-settings`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>o(e.message||i(`libraryAutoPurge.saveFailed`),`error`)}),qt=e=>{Gt&&Kt.mutate({retention_days:Gt.retention_days,auto_purge_enabled:Gt.auto_purge_enabled,auto_purge_days:Gt.auto_purge_days,auto_purge_include_never_printed:Gt.auto_purge_include_never_printed,...e})},Jt=!s||d(`archives:purge`),{data:Yt}=q({queryKey:[`archive-purge-settings`],queryFn:()=>Q.getArchivePurgeSettings(),enabled:Jt}),Xt=J({mutationFn:e=>Q.updateArchivePurgeSettings(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`archive-purge-settings`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>o(e.message||i(`archiveAutoPurge.saveFailed`),`error`)}),Zt=e=>{Yt&&Xt.mutate({enabled:Yt.enabled,days:Yt.days,purge_stats:Yt.purge_stats,...e})},{data:Qt,refetch:$t,isRefetching:en}=q({queryKey:[`updateCheck`],queryFn:Q.checkForUpdates,enabled:ht?.check_updates!==!1,staleTime:300*1e3}),{data:tn,refetch:nn}=q({queryKey:[`updateStatus`],queryFn:Q.getUpdateStatus,refetchInterval:e=>{let t=e.state.data;return t?.status===`downloading`||t?.status===`installing`?1e3:!1}}),{data:rn}=q({queryKey:[`mqtt-status`],queryFn:Q.getMQTTStatus,refetchInterval:W===`network`?5e3:!1}),{data:an}=q({queryKey:[`github-backup-status`],queryFn:Q.getGitHubBackupStatus}),{data:on}=q({queryKey:[`cloud-status`],queryFn:Q.getCloudStatus}),{data:sn={advanced_auth_enabled:!1,smtp_configured:!1}}=q({queryKey:[`advancedAuthStatus`],queryFn:()=>Q.getAdvancedAuthStatus()}),{data:cn}=q({queryKey:[`ldapStatus`],queryFn:()=>Q.getLDAPStatus()}),{data:ln}=q({queryKey:[`twoFAStatus`],queryFn:()=>Q.get2FAStatus()}),{data:un=[]}=q({queryKey:[`oidcProvidersAll`],queryFn:()=>Q.getOIDCProvidersAll(),enabled:l}),{data:dn=[],isLoading:fn}=q({queryKey:[`users`],queryFn:()=>Q.getUsers(),enabled:s&&d(`users:read`)}),{data:pn=[],isLoading:mn}=q({queryKey:[`groups`],queryFn:()=>Q.getGroups(),enabled:s&&d(`groups:read`)}),hn=J({mutationFn:e=>Q.createUser(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),e.invalidateQueries({queryKey:[`groups`]}),Ue(!1),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`settings.toast.userCreated`))},onError:e=>{o(e.message,`error`)}}),gn=J({mutationFn:({id:e,data:t})=>Q.updateUser(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),e.invalidateQueries({queryKey:[`groups`]}),qe(!1),Ye(null),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`settings.toast.userUpdated`))},onError:e=>{o(e.message,`error`)}}),_n=J({mutationFn:({id:e,deleteItems:t})=>Q.deleteUser(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),o(i(`settings.toast.userDeleted`)),Ze(null),$e(null)},onError:e=>{o(e.message,`error`)}}),vn=J({mutationFn:e=>Q.resetUserPassword({user_id:e}),onSuccess:e=>{o(e.message,`success`)},onError:e=>{o(e.message,`error`)}}),yn=async e=>{Ze(e),tt(!0);try{$e(await Q.getUserItemsCount(e))}catch{$e({archives:0,queue_items:0,library_files:0})}finally{tt(!1)}},bn=J({mutationFn:e=>Q.deleteGroup(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`groups`]}),o(i(`settings.toast.groupDeleted`))},onError:e=>{o(e.message,`error`)}}),xn=()=>{let e=sn?.advanced_auth_enabled||!1;if(!nt.username){o(i(`settings.toast.fillRequiredFields`),`error`);return}if(e&&!nt.email){o(`Email is required when advanced authentication is enabled`,`error`);return}if(!e){if(!nt.password){o(i(`settings.toast.fillRequiredFields`),`error`);return}if(nt.password!==nt.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}let e=m5(nt.password);if(e){o(i({tooShort:`settings.toast.passwordTooShort`,needsUppercase:`settings.toast.passwordNeedsUppercase`,needsLowercase:`settings.toast.passwordNeedsLowercase`,needsDigit:`settings.toast.passwordNeedsDigit`,needsSpecial:`settings.toast.passwordNeedsSpecial`}[e]),`error`);return}}hn.mutate({username:nt.username,password:e?void 0:nt.password,email:nt.email||void 0,role:nt.role,group_ids:nt.group_ids.length>0?nt.group_ids:void 0})},Sn=e=>{if(nt.password){if(nt.password!==nt.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}let e=m5(nt.password);if(e){o(i({tooShort:`settings.toast.passwordTooShort`,needsUppercase:`settings.toast.passwordNeedsUppercase`,needsLowercase:`settings.toast.passwordNeedsLowercase`,needsDigit:`settings.toast.passwordNeedsDigit`,needsSpecial:`settings.toast.passwordNeedsSpecial`}[e]),`error`);return}}let t={username:nt.username||void 0,password:nt.password||void 0,email:nt.email||void 0,role:nt.role,group_ids:nt.group_ids};t.password||delete t.password,gn.mutate({id:e,data:t})},Cn=e=>{Ye(e.id),rt({username:e.username,password:``,email:e.email||``,confirmPassword:``,role:e.role,group_ids:e.groups?.map(e=>e.id)||[]}),qe(!0)},wn=e=>{rt(t=>({...t,group_ids:t.group_ids.includes(e)?t.group_ids.filter(t=>t!==e):[...t.group_ids,e]}))},Tn=J({mutationFn:Q.applyUpdate,onSuccess:e=>{e.is_ha_addon||e.is_docker||e.is_windows_installer?o(e.message,`error`):nn()}}),[En,Dn]=(0,y.useState)(null),On=J({mutationFn:Q.testAllNotificationProviders,onSuccess:t=>{Dn(t),e.invalidateQueries({queryKey:[`notification-providers`]}),t.failed===0?o(`All ${t.tested} providers tested successfully!`,`success`):o(`${t.success}/${t.tested} providers succeeded`,t.failed>0?`error`:`success`)},onError:e=>{o(`Failed to test providers: ${e.message}`,`error`)}}),kn=J({mutationFn:async e=>{if(!xt)return{success:0,failed:0};let t=xt.filter(e=>e.enabled),n=await Promise.all(t.map(async t=>{try{return await Q.controlSmartPlug(t.id,e),{success:!0}}catch{return{success:!1}}}));return{success:n.filter(e=>e.success).length,failed:n.filter(e=>!e.success).length}},onSuccess:(t,n)=>{e.invalidateQueries({queryKey:[`smart-plugs`]}),e.invalidateQueries({queryKey:[`smart-plugs-energy`]}),t.failed===0?o(`All ${t.success} plugs turned ${n}`,`success`):o(`${t.success} plugs turned ${n}, ${t.failed} failed`,`error`)},onError:e=>{o(`Failed: ${e.message}`,`error`)}}),An=(0,y.useRef)(null),jn=(0,y.useRef)(null),Mn=(0,y.useRef)(!1),Nn=(0,y.useRef)(!0);(0,y.useEffect)(()=>{ht&&!O&&(k({...ht,external_url:ht.external_url||window.location.origin}),setTimeout(()=>{Nn.current=!1},100))},[ht,O]);let Pn=J({mutationFn:Q.updateSettings,onSuccess:t=>{e.setQueryData([`settings`],t),e.invalidateQueries({queryKey:[`archiveStats`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>{o(`Failed to save: ${e.message}`,`error`)},onSettled:()=>{Mn.current=!1}}),Fn=J({mutationFn:({id:e,data:t})=>Q.updatePrinter(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`printers`]}),o(i(`settings.toast.cameraSettingsSaved`),`success`)},onError:e=>{o(`Failed to update printer: ${e.message}`,`error`)}});(0,y.useEffect)(()=>{if(!(Nn.current||!O||!ht)&&!(s&&!d(`settings:update`))&&(ht.auto_archive!==O.auto_archive||ht.save_thumbnails!==O.save_thumbnails||ht.capture_finish_photo!==O.capture_finish_photo||ht.default_filament_cost!==O.default_filament_cost||ht.currency!==O.currency||ht.energy_cost_per_kwh!==O.energy_cost_per_kwh||ht.energy_tracking_mode!==O.energy_tracking_mode||ht.check_updates!==O.check_updates||(ht.check_printer_firmware??!0)!==(O.check_printer_firmware??!0)||(ht.include_beta_updates??!1)!==(O.include_beta_updates??!1)||ht.notification_language!==O.notification_language||(ht.bed_cooled_threshold??35)!==(O.bed_cooled_threshold??35)||ht.ams_humidity_good!==O.ams_humidity_good||ht.ams_humidity_fair!==O.ams_humidity_fair||ht.ams_temp_good!==O.ams_temp_good||ht.ams_temp_fair!==O.ams_temp_fair||ht.ams_history_retention_days!==O.ams_history_retention_days||ht.disable_filament_warnings!==O.disable_filament_warnings||ht.prefer_lowest_filament!==O.prefer_lowest_filament||(ht.queue_drying_enabled??!1)!==(O.queue_drying_enabled??!1)||(ht.queue_drying_block??!1)!==(O.queue_drying_block??!1)||(ht.ambient_drying_enabled??!1)!==(O.ambient_drying_enabled??!1)||(ht.drying_presets??``)!==(O.drying_presets??``)||ht.per_printer_mapping_expanded!==O.per_printer_mapping_expanded||ht.date_format!==O.date_format||ht.time_format!==O.time_format||ht.default_printer_id!==O.default_printer_id||ht.ftp_retry_enabled!==O.ftp_retry_enabled||ht.ftp_retry_count!==O.ftp_retry_count||ht.ftp_retry_delay!==O.ftp_retry_delay||ht.ftp_timeout!==O.ftp_timeout||ht.mqtt_enabled!==O.mqtt_enabled||ht.mqtt_broker!==O.mqtt_broker||ht.mqtt_port!==O.mqtt_port||ht.mqtt_username!==O.mqtt_username||ht.mqtt_password!==O.mqtt_password||ht.mqtt_topic_prefix!==O.mqtt_topic_prefix||ht.mqtt_use_tls!==O.mqtt_use_tls||ht.external_url!==O.external_url||ht.ha_enabled!==O.ha_enabled||ht.ha_url!==O.ha_url||ht.ha_token!==O.ha_token||(ht.library_archive_mode??`ask`)!==(O.library_archive_mode??`ask`)||Number(ht.library_disk_warning_gb??5)!==Number(O.library_disk_warning_gb??5)||(ht.camera_view_mode??`window`)!==(O.camera_view_mode??`window`)||(ht.preferred_slicer??`bambu_studio`)!==(O.preferred_slicer??`bambu_studio`)||(ht.open_in_slicer??null)!==(O.open_in_slicer??null)||(ht.use_slicer_api??!1)!==(O.use_slicer_api??!1)||(ht.orcaslicer_api_url??``)!==(O.orcaslicer_api_url??``)||(ht.bambu_studio_api_url??``)!==(O.bambu_studio_api_url??``)||ht.prometheus_enabled!==O.prometheus_enabled||ht.prometheus_token!==O.prometheus_token||(ht.user_notifications_enabled??!0)!==(O.user_notifications_enabled??!0)||(ht.default_bed_levelling??!0)!==(O.default_bed_levelling??!0)||(ht.default_flow_cali??!1)!==(O.default_flow_cali??!1)||(ht.default_vibration_cali??!0)!==(O.default_vibration_cali??!0)||(ht.default_layer_inspect??!1)!==(O.default_layer_inspect??!1)||(ht.default_timelapse??!1)!==(O.default_timelapse??!1)||(ht.default_nozzle_offset_cali??!0)!==(O.default_nozzle_offset_cali??!0)||(ht.stagger_group_size??2)!==(O.stagger_group_size??2)||(ht.stagger_interval_minutes??5)!==(O.stagger_interval_minutes??5)||(ht.require_plate_clear??!1)!==(O.require_plate_clear??!1)||(ht.nozzle_temp_presets??``)!==(O.nozzle_temp_presets??``)||(ht.bed_temp_presets??``)!==(O.bed_temp_presets??``)||(ht.chamber_temp_presets??``)!==(O.chamber_temp_presets??``)||(ht.fan_speed_presets??``)!==(O.fan_speed_presets??``)||(ht.session_max_hours??24)!==(O.session_max_hours??24))&&!Mn.current)return An.current&&clearTimeout(An.current),An.current=setTimeout(()=>{if(Mn.current)return;Mn.current=!0;let e={auto_archive:O.auto_archive,save_thumbnails:O.save_thumbnails,capture_finish_photo:O.capture_finish_photo,default_filament_cost:O.default_filament_cost,currency:O.currency,energy_cost_per_kwh:O.energy_cost_per_kwh,energy_tracking_mode:O.energy_tracking_mode,check_updates:O.check_updates,check_printer_firmware:O.check_printer_firmware,include_beta_updates:O.include_beta_updates,notification_language:O.notification_language,bed_cooled_threshold:O.bed_cooled_threshold,ams_humidity_good:O.ams_humidity_good,ams_humidity_fair:O.ams_humidity_fair,ams_temp_good:O.ams_temp_good,ams_temp_fair:O.ams_temp_fair,ams_history_retention_days:O.ams_history_retention_days,disable_filament_warnings:O.disable_filament_warnings,prefer_lowest_filament:O.prefer_lowest_filament,queue_drying_enabled:O.queue_drying_enabled,queue_drying_block:O.queue_drying_block,ambient_drying_enabled:O.ambient_drying_enabled,drying_presets:O.drying_presets,per_printer_mapping_expanded:O.per_printer_mapping_expanded,date_format:O.date_format,time_format:O.time_format,default_printer_id:O.default_printer_id,ftp_retry_enabled:O.ftp_retry_enabled,ftp_retry_count:O.ftp_retry_count,ftp_retry_delay:O.ftp_retry_delay,ftp_timeout:O.ftp_timeout,mqtt_enabled:O.mqtt_enabled,mqtt_broker:O.mqtt_broker,mqtt_port:O.mqtt_port,mqtt_username:O.mqtt_username,mqtt_password:O.mqtt_password,mqtt_topic_prefix:O.mqtt_topic_prefix,mqtt_use_tls:O.mqtt_use_tls,external_url:O.external_url,ha_enabled:O.ha_enabled,ha_url:O.ha_url,ha_token:O.ha_token,library_archive_mode:O.library_archive_mode,library_disk_warning_gb:O.library_disk_warning_gb,camera_view_mode:O.camera_view_mode,preferred_slicer:O.preferred_slicer,open_in_slicer:O.open_in_slicer,use_slicer_api:O.use_slicer_api,orcaslicer_api_url:O.orcaslicer_api_url,bambu_studio_api_url:O.bambu_studio_api_url,prometheus_enabled:O.prometheus_enabled,prometheus_token:O.prometheus_token,user_notifications_enabled:O.user_notifications_enabled,default_bed_levelling:O.default_bed_levelling,default_flow_cali:O.default_flow_cali,default_vibration_cali:O.default_vibration_cali,default_layer_inspect:O.default_layer_inspect,default_timelapse:O.default_timelapse,default_nozzle_offset_cali:O.default_nozzle_offset_cali,stagger_group_size:O.stagger_group_size,stagger_interval_minutes:O.stagger_interval_minutes,require_plate_clear:O.require_plate_clear,nozzle_temp_presets:O.nozzle_temp_presets,bed_temp_presets:O.bed_temp_presets,chamber_temp_presets:O.chamber_temp_presets,fan_speed_presets:O.fan_speed_presets,session_max_hours:O.session_max_hours};Pn.mutate(e)},500),()=>{An.current&&clearTimeout(An.current)}},[O,ht,Pn,s,d,o,i]);let In=(0,y.useCallback)((e,t)=>{if(s&&!d(`settings:update`)){o(i(`settings.toast.noPermissionUpdate`),`error`);return}k(n=>n?{...n,[e]:t}:null)},[s,d,o,i]),Ln=async(e,t,n)=>{if(!t){o(i(`settings.toast.enterCameraUrl`),`error`);return}pt(t=>({...t,[e]:!0})),dt(t=>({...t,[e]:null}));try{let r=await Q.testExternalCamera(e,t,n);dt(t=>({...t,[e]:r})),r.success?o(i(`settings.toast.cameraConnected`,{resolution:r.resolution||``}),`success`):o(r.error||i(`settings.toast.connectionFailed`),`error`)}catch(t){let n=t instanceof Error?t.message:i(`settings.toast.testFailed`);dt(t=>({...t,[e]:{success:!1,error:n}})),o(n,`error`)}finally{pt(t=>({...t,[e]:!1}))}},[Rn,zn]=(0,y.useState)({}),Bn=(0,y.useRef)({}),Vn=(0,y.useRef)(new Set),[Hn,Un]=(0,y.useState)({}),Wn=(0,y.useRef)({}),Gn=(0,y.useRef)(new Set);(0,y.useEffect)(()=>{if(Mt){let e={},t={};Mt.forEach(n=>{n.external_camera_url&&!Vn.current.has(n.id)&&(e[n.id]=n.external_camera_url,Vn.current.add(n.id)),n.external_camera_snapshot_url&&!Gn.current.has(n.id)&&(t[n.id]=n.external_camera_snapshot_url,Gn.current.add(n.id))}),Object.keys(e).length>0&&zn(t=>({...t,...e})),Object.keys(t).length>0&&Un(e=>({...e,...t}))}},[Mt]);let Kn=(e,t)=>{zn(n=>({...n,[e]:t})),Bn.current[e]&&clearTimeout(Bn.current[e]),Bn.current[e]=setTimeout(()=>{Fn.mutate({id:e,data:{external_camera_url:t||null}})},800)},qn=(e,t)=>{Un(n=>({...n,[e]:t})),Wn.current[e]&&clearTimeout(Wn.current[e]),Wn.current[e]=setTimeout(()=>{Fn.mutate({id:e,data:{external_camera_snapshot_url:t||null}})},800)},Jn=(e,t)=>{let n={};t.type!==void 0&&(n.external_camera_type=t.type||null),t.enabled!==void 0&&(n.external_camera_enabled=t.enabled),t.rotation!==void 0&&(n.camera_rotation=t.rotation),Fn.mutate({id:e,data:n})};if(gt||!O)return(0,K.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})});let Xn=kze().map(e=>({...e,label:i(e.labelKey,e.labelFallback??e.labelKey)})),Zn=ee.trim().toLowerCase(),Qn=Zn?Xn.filter(e=>e.label.toLowerCase().includes(Zn)||e.keywords.toLowerCase().includes(Zn)).slice(0,8):[],$n=e=>{le(e.tab),e.subTab&&ce(e.subTab),H(``),setTimeout(()=>{let t=document.getElementById(e.anchor);t&&(t.scrollIntoView({behavior:`smooth`,block:`start`}),t.classList.add(`ring-2`,`ring-bambu-green`),setTimeout(()=>t.classList.remove(`ring-2`,`ring-bambu-green`),1500))},50)};return(0,K.jsx)(fd,{density:`dense`,children:(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`mb-4 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3`,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)(Rl,{className:`w-7 h-7 text-bambu-green`}),i(`settings.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i(`settings.configureBambuddy`)})]}),(0,K.jsxs)(`div`,{className:`relative sm:w-72`,children:[(0,K.jsx)(Nl,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none`}),(0,K.jsx)(`input`,{type:`text`,value:ee,onChange:e=>H(e.target.value),placeholder:i(`settings.searchPlaceholder`,`Search settings…`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),ee&&(0,K.jsx)(`button`,{onClick:()=>H(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white`,"aria-label":`Clear`,children:(0,K.jsx)(Pu,{className:`w-3.5 h-3.5`})}),Qn.length>0&&(0,K.jsx)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 overflow-hidden`,children:Qn.map(e=>(0,K.jsxs)(`button`,{onClick:()=>$n(e),className:`w-full px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:e.label}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[i(`settings.tabs.${e.tab===`virtual-printer`?`virtualPrinter`:e.tab===`failure-detection`?`failureDetection`:e.tab}`),e.subTab?` › ${i(`settings.tabs.${e.subTab}`,e.subTab)}`:``]})]},e.anchor))}),Zn&&Qn.length===0&&(0,K.jsx)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 p-3`,children:(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray italic`,children:i(`settings.noSearchResults`,`No matching settings.`)})})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,K.jsxs)(`nav`,{className:`flex flex-wrap gap-1 border-b border-bambu-dark-tertiary lg:flex-col lg:flex-nowrap lg:gap-0 lg:border-b-0 lg:border-r lg:w-48 lg:flex-shrink-0 lg:self-start lg:sticky lg:top-4`,children:[(0,K.jsxs)(`button`,{onClick:()=>le(`general`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`general`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(Rl,{className:`w-4 h-4`}),i(`settings.tabs.general`)]}),(0,K.jsxs)(`button`,{onClick:()=>le(`plugs`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`plugs`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(gl,{className:`w-4 h-4`}),i(`settings.tabs.smartPlugs`),xt&&xt.length>0&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:xt.length})]}),(0,K.jsxs)(`button`,{onClick:()=>le(`notifications`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`notifications`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(Io,{className:`w-4 h-4`}),i(`settings.tabs.notifications`),Et&&Et.length>0&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:Et.length})]}),(0,K.jsxs)(`button`,{onClick:()=>le(`queue`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`queue`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(Rc,{className:`w-4 h-4`}),i(`settings.tabs.queue`,`Workflow`)]}),(0,K.jsxs)(`button`,{onClick:()=>le(`filament`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`filament`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(As,{className:`w-4 h-4`}),i(`settings.tabs.filament`)]}),(0,K.jsxs)(`button`,{onClick:()=>le(`network`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`network`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(ju,{className:`w-4 h-4`}),i(`settings.tabs.network`),(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${rn?.enabled?`bg-green-400`:`bg-gray-500`}`})]}),(0,K.jsxs)(`button`,{onClick:()=>le(`apikeys`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`apikeys`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(jc,{className:`w-4 h-4`}),i(`settings.tabs.apiKeys`),Ot&&Ot.length>0&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:Ot.length})]}),(0,K.jsxs)(`button`,{onClick:()=>le(`virtual-printer`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`virtual-printer`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(bl,{className:`w-4 h-4`}),i(`settings.tabs.virtualPrinter`),(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${It?`bg-green-400`:`bg-gray-500`}`})]}),(0,K.jsxs)(`button`,{onClick:()=>le(`spoolbuddy`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`spoolbuddy`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(kl,{className:`w-4 h-4`}),i(`settings.tabs.spoolbuddy`),Rt>0&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:Rt}),(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${zt?`bg-green-400`:`bg-gray-500`}`})]}),(0,K.jsxs)(`button`,{onClick:()=>le(`failure-detection`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`failure-detection`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(Al,{className:`w-4 h-4`}),i(`settings.tabs.failureDetection`),(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${Vt?`bg-green-400`:`bg-gray-500`}`})]}),(0,K.jsxs)(`button`,{onClick:()=>le(`users`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`users`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(wu,{className:`w-4 h-4`}),i(`settings.tabs.users`),s&&(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,K.jsxs)(`button`,{onClick:()=>le(`backup`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`backup`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(js,{className:`w-4 h-4`}),i(`settings.tabs.backup`),(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${on?.is_authenticated&&an?.configured&&an?.enabled||ht?.local_backup_enabled?`bg-green-400`:`bg-gray-500`}`})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[W===`general`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`a`,{href:`https://bambuddy.cool/sponsors.html?from=app-settings`,target:`_blank`,rel:`noopener noreferrer`,className:`group block mb-4 lg:mb-6 rounded-xl border border-bambu-green/30 bg-gradient-to-br from-bambu-green/15 via-bambu-green/5 to-transparent hover:border-bambu-green/50 hover:from-bambu-green/20 transition-colors`,children:(0,K.jsxs)(`div`,{className:`flex flex-col md:flex-row items-start md:items-center gap-4 p-4 md:p-5`,children:[(0,K.jsx)(`div`,{className:`p-3 rounded-lg bg-bambu-green/20 text-bambu-green flex-shrink-0`,children:(0,K.jsx)(Cc,{className:`w-6 h-6`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-base font-semibold text-white`,children:i(`sponsors.sectionTitle`,`Independent & community-funded`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-0.5`,children:i(`sponsors.tagline`,`Bambuddy is free and stays that way because people choose to support it. No VC, no cloud lock-in.`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 rounded-lg bg-bambu-green/20 text-bambu-green group-hover:bg-bambu-green/30 text-sm font-medium whitespace-nowrap self-start md:self-auto`,children:[i(`sponsors.viewSupporters`,`View supporters`),(0,K.jsx)(Us,{className:`w-4 h-4`})]})]})}),(0,K.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,K.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,K.jsxs)(pd,{id:`card-general`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.general`)})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,K.jsx)(hc,{className:`w-4 h-4 inline mr-1`}),i(`settings.language`)]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`select`,{value:a.language,onChange:e=>{let t=e.target.value;if(s&&!d(`settings:update`)){o(i(`settings.toast.noPermissionUpdate`),`error`);return}a.changeLanguage(t),Pn.mutate({language:t})},className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:Ct.map(e=>(0,K.jsxs)(`option`,{value:e.code,children:[e.nativeName,` (`,e.name,`)`]},e.code))}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.languageDescription`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultView`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`select`,{value:re,onChange:e=>mt(e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:qf.map(e=>(0,K.jsx)(`option`,{value:e.to,children:i(e.labelKey)},e.id))}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.defaultViewDescription`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.dateFormat`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:O.date_format||`system`,onChange:e=>In(`date_format`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,K.jsx)(`option`,{value:`system`,children:i(`settings.systemDefault`)}),(0,K.jsx)(`option`,{value:`us`,children:i(`settings.dateFormatUs`)}),(0,K.jsx)(`option`,{value:`eu`,children:i(`settings.dateFormatEu`)}),(0,K.jsx)(`option`,{value:`iso`,children:i(`settings.dateFormatIso`)})]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.timeFormat`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:O.time_format||`system`,onChange:e=>In(`time_format`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,K.jsx)(`option`,{value:`system`,children:i(`settings.systemDefault`)}),(0,K.jsx)(`option`,{value:`12h`,children:i(`settings.timeFormat12`)}),(0,K.jsx)(`option`,{value:`24h`,children:i(`settings.timeFormat24`)})]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultPrinter`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:O.default_printer_id??``,onChange:e=>In(`default_printer_id`,e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,K.jsx)(`option`,{value:``,children:i(`settings.noDefaultPrinter`)}),Mt?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.defaultPrinterDescription`)})]})]})]}),(0,K.jsxs)(pd,{id:`card-appearance`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(ll,{className:`w-5 h-5`}),i(`settings.appearance`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsxs)(`label`,{className:`text-sm text-bambu-gray`,children:[i(`settings.theme`),`:`]}),(0,K.jsx)(`div`,{className:`flex gap-1`,children:[{id:`dark`,label:i(`settings.themeDark`)},{id:`light`,label:i(`settings.themeLight`)},{id:`system`,label:i(`settings.themeSystem`)}].map(({id:e,label:t})=>(0,K.jsx)(`button`,{onClick:()=>{x(e),o(i(`settings.toast.settingsSaved`),`success`)},className:`px-3 py-1 text-xs rounded-lg border transition-colors ${f===e?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-gray-300 dark:border-bambu-dark-tertiary text-gray-500 dark:text-bambu-gray hover:text-gray-900 dark:hover:text-white cursor-pointer`}`,children:t},e))})]}),(0,K.jsxs)(`div`,{className:`space-y-3 p-4 rounded-lg border ${p===`dark`?`border-bambu-green bg-bambu-green/5`:`border-bambu-dark-tertiary`}`,children:[(0,K.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[i(`settings.darkMode`),p===`dark`&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.active`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.background`)}),(0,K.jsxs)(`select`,{value:h,onChange:e=>{C(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`neutral`,children:i(`settings.bgNeutral`)}),(0,K.jsx)(`option`,{value:`warm`,children:i(`settings.bgWarm`)}),(0,K.jsx)(`option`,{value:`cool`,children:i(`settings.bgCool`)}),(0,K.jsx)(`option`,{value:`oled`,children:i(`settings.bgOled`)}),(0,K.jsx)(`option`,{value:`slate`,children:i(`settings.bgSlate`)}),(0,K.jsx)(`option`,{value:`forest`,children:i(`settings.bgForest`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.accent`)}),(0,K.jsxs)(`select`,{value:g,onChange:e=>{w(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`green`,children:i(`settings.accentGreen`)}),(0,K.jsx)(`option`,{value:`teal`,children:i(`settings.accentTeal`)}),(0,K.jsx)(`option`,{value:`blue`,children:i(`settings.accentBlue`)}),(0,K.jsx)(`option`,{value:`orange`,children:i(`settings.accentOrange`)}),(0,K.jsx)(`option`,{value:`purple`,children:i(`settings.accentPurple`)}),(0,K.jsx)(`option`,{value:`red`,children:i(`settings.accentRed`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.style`)}),(0,K.jsxs)(`select`,{value:m,onChange:e=>{S(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`classic`,children:i(`settings.styleClassic`)}),(0,K.jsx)(`option`,{value:`glow`,children:i(`settings.styleGlow`)}),(0,K.jsx)(`option`,{value:`vibrant`,children:i(`settings.styleVibrant`)})]})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3 p-4 rounded-lg border ${p===`light`?`border-bambu-green bg-bambu-green/5`:`border-bambu-dark-tertiary`}`,children:[(0,K.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[i(`settings.lightMode`),p===`light`&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.active`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.background`)}),(0,K.jsxs)(`select`,{value:v,onChange:e=>{E(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`neutral`,children:i(`settings.bgNeutral`)}),(0,K.jsx)(`option`,{value:`warm`,children:i(`settings.bgWarm`)}),(0,K.jsx)(`option`,{value:`cool`,children:i(`settings.bgCool`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.accent`)}),(0,K.jsxs)(`select`,{value:b,onChange:e=>{D(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`green`,children:i(`settings.accentGreen`)}),(0,K.jsx)(`option`,{value:`teal`,children:i(`settings.accentTeal`)}),(0,K.jsx)(`option`,{value:`blue`,children:i(`settings.accentBlue`)}),(0,K.jsx)(`option`,{value:`orange`,children:i(`settings.accentOrange`)}),(0,K.jsx)(`option`,{value:`purple`,children:i(`settings.accentPurple`)}),(0,K.jsx)(`option`,{value:`red`,children:i(`settings.accentRed`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.style`)}),(0,K.jsxs)(`select`,{value:_,onChange:e=>{T(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`classic`,children:i(`settings.styleClassic`)}),(0,K.jsx)(`option`,{value:`glow`,children:i(`settings.styleGlow`)}),(0,K.jsx)(`option`,{value:`vibrant`,children:i(`settings.styleVibrant`)})]})]})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.themeToggleHint`)})]})]}),(0,K.jsxs)(pd,{id:`card-archive`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.archiveSettings`)})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.autoArchivePrints`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoArchiveDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.auto_archive,onChange:e=>In(`auto_archive`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.saveThumbnails`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.saveThumbnailsDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.save_thumbnails,onChange:e=>In(`save_thumbnails`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.captureFinishPhoto`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.captureFinishPhotoDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.capture_finish_photo,onChange:e=>In(`capture_finish_photo`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),O.capture_finish_photo&&Ht&&!Ht.installed&&(0,K.jsxs)(`div`,{className:`flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg`,children:[(0,K.jsx)(vu,{className:`w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`text-sm`,children:[(0,K.jsx)(`p`,{className:`text-yellow-500 font-medium`,children:i(`settings.ffmpegNotInstalled`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i(`settings.ffmpegRequired`)})]})]}),Jt&&Yt&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`archiveAutoPurge.enableLabel`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`archiveAutoPurge.enableDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:Yt.enabled,onChange:e=>Zt({enabled:e.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`archiveAutoPurge.ageLabel`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,min:7,max:3650,disabled:!Yt.enabled,value:Yt.days,onChange:e=>Zt({days:Math.max(7,Math.min(3650,parseInt(e.target.value||`0`,10)||0))}),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`archiveAutoPurge.days`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`archiveAutoPurge.ageDescription`)})]}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,disabled:!Yt.enabled,checked:Yt.purge_stats,onChange:e=>Zt({purge_stats:e.target.checked}),className:`mt-0.5 shrink-0 disabled:opacity-50`}),(0,K.jsxs)(`span`,{className:`text-sm`,children:[(0,K.jsx)(`span`,{className:`text-white block`,children:i(`archiveAutoPurge.purgeStatsLabel`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray block mt-0.5`,children:i(`archiveAutoPurge.purgeStatsDescription`)})]})]})]})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-md`,children:[(0,K.jsxs)(pd,{id:`card-camera`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Tu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.camera`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.cameraViewMode`)}),(0,K.jsxs)(`select`,{value:O.camera_view_mode??`window`,onChange:e=>In(`camera_view_mode`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`window`,children:i(`settings.newWindow`)}),(0,K.jsx)(`option`,{value:`embedded`,children:i(`settings.embeddedOverlay`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:O.camera_view_mode===`embedded`?i(`settings.cameraOverlayDescription`):i(`settings.cameraWindowDescription`)})]}),(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 mt-4`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-2`,children:i(`settings.externalCameras`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:i(`settings.externalCamerasDescription`)}),Mt&&Mt.length>0?(0,K.jsx)(`div`,{className:`space-y-3`,children:Mt.map(e=>(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.external_camera_enabled,onChange:t=>Jn(e.id,{enabled:t.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.external_camera_enabled&&(0,K.jsxs)(`div`,{className:`space-y-2 mt-2`,children:[(0,K.jsx)(`input`,{type:`text`,placeholder:e.external_camera_type===`usb`?i(`settings.cameraPlaceholderUsb`):i(`settings.cameraPlaceholderUrl`),value:Rn[e.id]??e.external_camera_url??``,onChange:t=>Kn(e.id,t.target.value),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`select`,{value:e.external_camera_type||`mjpeg`,onChange:t=>Jn(e.id,{type:t.target.value}),className:`flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`mjpeg`,children:i(`settings.cameraTypeMjpeg`)}),(0,K.jsx)(`option`,{value:`rtsp`,children:i(`settings.cameraTypeRtsp`)}),(0,K.jsx)(`option`,{value:`snapshot`,children:i(`settings.cameraTypeSnapshot`)}),(0,K.jsx)(`option`,{value:`usb`,children:i(`settings.cameraTypeUsb`)})]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>Ln(e.id,Rn[e.id]??e.external_camera_url??``,e.external_camera_type||`mjpeg`),disabled:ft[e.id]||!(Rn[e.id]??e.external_camera_url),children:ft[e.id]?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):i(`settings.test`)})]}),ut[e.id]&&(0,K.jsx)(`div`,{className:`text-xs flex items-center gap-1 ${ut[e.id]?.success?`text-green-500`:`text-red-500`}`,children:ut[e.id]?.success?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ls,{className:`w-3 h-3`}),i(`settings.connected`),ut[e.id]?.resolution&&` (${ut[e.id]?.resolution})`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ms,{className:`w-3 h-3`}),ut[e.id]?.error||i(`settings.toast.connectionFailed`)]})}),(e.external_camera_type===`mjpeg`||e.external_camera_type===`rtsp`||e.external_camera_type===`usb`)&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:i(`settings.cameraSnapshotUrl`,`Snapshot URL (optional)`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,placeholder:i(`settings.cameraSnapshotUrlPlaceholder`,`http://192.168.1.61:1984/api/frame.jpeg?src=printer`),value:Hn[e.id]??e.external_camera_snapshot_url??``,onChange:t=>qn(e.id,t.target.value),className:`flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>Ln(e.id,Hn[e.id]??e.external_camera_snapshot_url??``,`snapshot`),disabled:ft[e.id]||!(Hn[e.id]??e.external_camera_snapshot_url),children:ft[e.id]?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):i(`settings.test`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray opacity-75`,children:i(`settings.cameraSnapshotUrlHelp`,`Single-frame URL used for notification thumbnails, finish photos, timelapse and plate detection. Leave blank to capture from the live stream above. Useful for go2rtc (/api/frame.jpeg) and IP cameras with a dedicated snapshot endpoint.`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:i(`settings.cameraRotation`)}),(0,K.jsxs)(`select`,{value:e.camera_rotation||0,onChange:t=>Jn(e.id,{rotation:parseInt(t.target.value)}),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:0,children:`0°`}),(0,K.jsx)(`option`,{value:90,children:`90°`}),(0,K.jsx)(`option`,{value:180,children:`180°`}),(0,K.jsx)(`option`,{value:270,children:`270°`})]})]})]})]},e.id))}):(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray italic`,children:i(`settings.noPrintersConfigured`)})]})]})]}),(0,K.jsxs)(pd,{id:`card-cost`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.costTracking`)})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.currency`)}),(0,K.jsx)(`select`,{value:O.currency,onChange:e=>In(`currency`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:Xd.map(e=>(0,K.jsx)(`option`,{value:e.code,children:e.label},e.code))})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultFilamentCost`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:Yd(O.currency)}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:O.default_filament_cost,onChange:e=>In(`default_filament_cost`,parseFloat(e.target.value)||0),style:{paddingLeft:`${Math.max(2,Yd(O.currency).length*.6+1)}rem`},className:`w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.electricityCost`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:Yd(O.currency)}),(0,K.jsx)(`input`,{type:`number`,step:`0.001`,min:`0`,value:O.energy_cost_per_kwh,onChange:e=>In(`energy_cost_per_kwh`,parseFloat(e.target.value)||0),style:{paddingLeft:`${Math.max(2,Yd(O.currency).length*.6+1)}rem`},className:`w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.energyDisplayMode`)}),(0,K.jsxs)(`select`,{value:O.energy_tracking_mode||`total`,onChange:e=>In(`energy_tracking_mode`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`print`,children:i(`settings.printsOnly`)}),(0,K.jsx)(`option`,{value:`total`,children:i(`settings.totalConsumption`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:O.energy_tracking_mode===`print`?i(`settings.energyModePrintDescription`):i(`settings.energyModeTotalDescription`)})]})]})]}),(0,K.jsxs)(pd,{id:`card-filemanager`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Zs,{className:`w-5 h-5 text-bambu-green`}),i(`settings.fileManager`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.createArchiveEntry`)}),(0,K.jsxs)(`select`,{value:O.library_archive_mode??`ask`,onChange:e=>In(`library_archive_mode`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`always`,children:i(`settings.archiveMode.always`)}),(0,K.jsx)(`option`,{value:`never`,children:i(`settings.archiveMode.never`)}),(0,K.jsx)(`option`,{value:`ask`,children:i(`settings.archiveMode.ask`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.createArchiveEntryDescription`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.lowDiskSpaceWarning`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,min:`0.5`,max:`100`,step:`0.5`,value:O.library_disk_warning_gb??5,onChange:e=>In(`library_disk_warning_gb`,parseFloat(e.target.value)||5),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`GB`})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.lowDiskSpaceDescription`)})]}),Wt&&Gt&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`libraryAutoPurge.enableLabel`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`libraryAutoPurge.enableDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:Gt.auto_purge_enabled,onChange:e=>qt({auto_purge_enabled:e.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`libraryAutoPurge.ageLabel`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,min:7,max:3650,disabled:!Gt.auto_purge_enabled,value:Gt.auto_purge_days,onChange:e=>qt({auto_purge_days:Math.max(7,Math.min(3650,parseInt(e.target.value||`0`,10)||0))}),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`libraryAutoPurge.days`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`libraryAutoPurge.ageDescription`)})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-white cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,disabled:!Gt.auto_purge_enabled,checked:Gt.auto_purge_include_never_printed,onChange:e=>qt({auto_purge_include_never_printed:e.target.checked}),className:`rounded border-gray-300 disabled:opacity-50`}),i(`libraryAutoPurge.includeNeverPrinted`)]})]})]})]}),(0,K.jsxs)(pd,{id:`card-data`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.dataManagement`)})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.clearNotificationLogs`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.clearNotificationLogsDescription`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>Te(!0),children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),i(`common.clear`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.resetUiPreferences`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.resetUiPreferencesDescription`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>De(!0),children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),i(`settings.reset`)]})]}),(0,K.jsxs)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.storageUsage`,`Storage Usage`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.storageUsageDescription`,`Breakdown of data usage by category`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:bt,disabled:yt||Be,children:[(0,K.jsx)(Cl,{className:`w-4 h-4 ${yt||Be?`animate-spin`:``}`}),i(`common.refresh`,`Refresh`)]})]}),(0,K.jsx)(`div`,{className:`mt-3`,children:vt?(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`}),i(`common.loading`,`Loading`)]}):_t?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`w-full h-3 bg-bambu-dark rounded-full overflow-hidden flex`,children:_t.categories.filter(e=>e.bytes>0).map((e,t)=>(0,K.jsx)(`div`,{className:`${l7(e.key,t)} h-full`,style:{width:`${e.percent_of_total}%`},title:`${e.label}: ${e.formatted}`},e.key))}),(0,K.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-3`,children:_t.categories.filter(e=>e.bytes>0).map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full ${l7(e.key,t)}`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e.label}),(0,K.jsx)(`span`,{className:`text-white`,children:e.formatted}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_of_total.toFixed(1),`%)`]})]},e.key))}),(0,K.jsxs)(`div`,{className:`mt-2 text-xs text-bambu-gray`,children:[i(`settings.storageUsageTotal`,`Total`),`: `,(0,K.jsx)(`span`,{className:`text-white`,children:_t.total_formatted}),_t.scan_errors>0&&(0,K.jsxs)(`span`,{className:`ml-2 text-amber-400`,children:[i(`settings.storageUsageErrors`,`Scan errors`),`: `,_t.scan_errors]})]}),_t.other_breakdown?.length>0&&(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:i(`settings.storageUsageOtherBreakdown`,`Other breakdown`)}),(0,K.jsx)(`div`,{className:`space-y-2`,children:_t.other_breakdown.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-white`,children:e.label}),(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded-full border ${e.kind===`system`?`border-slate-500 text-slate-300`:`border-bambu-green text-bambu-green`}`,children:e.kind===`system`?i(`settings.storageUsageSystem`,`System`):i(`settings.storageUsageData`,`Data`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`text-white`,children:e.formatted}),(0,K.jsxs)(`span`,{children:[`(`,e.percent_of_total.toFixed(1),`%)`]})]})]},`${e.bucket}-${e.kind}`))})]})]}):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.storageUsageUnavailable`,`Storage usage data is unavailable`)})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.backupRestore`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.backupRestoreDescription`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>le(`backup`),children:[(0,K.jsx)(js,{className:`w-4 h-4`}),i(`settings.goToBackup`)]})]})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-sm`,children:[(0,K.jsxs)(pd,{id:`card-updates`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.updates`)})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider`,children:i(`settings.printerFirmware`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.checkPrinterFirmware`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.checkFirmwareDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.check_printer_firmware??!0,onChange:e=>In(`check_printer_firmware`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,K.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider mb-4`,children:i(`settings.bambuddySoftware`)})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.checkForUpdatesLabel`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoCheckDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.check_updates,onChange:e=>In(`check_updates`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between ${O.check_updates?``:`opacity-50`}`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.includeBetaUpdates`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.includeBetaUpdatesDesc`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.include_beta_updates??!1,onChange:e=>In(`include_beta_updates`,e.target.checked),disabled:!O.check_updates,className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.currentVersion`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`v`,Ut?.version||`...`]})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>$t(),disabled:en,children:[en?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),i(`settings.checkNow`)]})]}),Qt?.update_available?(0,K.jsxs)(`div`,{className:`mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`p`,{className:`text-bambu-green font-medium`,children:[`Update available: v`,Qt.latest_version]}),Qt.release_name&&Qt.release_name!==Qt.latest_version&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:Qt.release_name})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[Qt.release_notes&&(0,K.jsx)(`button`,{onClick:()=>je(!0),className:`text-bambu-gray hover:text-white transition-colors text-sm underline`,children:i(`settings.releaseNotes`)}),Qt.release_url&&(0,K.jsx)(`a`,{href:Qt.release_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-white transition-colors`,title:i(`settings.viewReleaseOnGitHub`),children:(0,K.jsx)(Us,{className:`w-4 h-4`})})]})]}),tn?.status===`downloading`||tn?.status===`installing`?(0,K.jsxs)(`div`,{className:`mt-3`,children:[(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`}),(0,K.jsx)(`span`,{children:tn.message})]}),(0,K.jsx)(`div`,{className:`mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,K.jsx)(`div`,{className:`bg-bambu-green h-2 rounded-full transition-all duration-300`,style:{width:`${tn.progress}%`}})})]}):tn?.status===`complete`?(0,K.jsx)(`div`,{className:`mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green`,children:tn.message}):tn?.status===`error`?(0,K.jsx)(`div`,{className:`mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400`,children:tn.error||tn.message}):Qt?.is_ha_addon?(0,K.jsx)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.updateViaHomeAssistant`)})}):Qt?.is_docker?(0,K.jsxs)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:i(`settings.updateViaDocker`)}),(0,K.jsx)(`code`,{className:`block text-xs bg-bambu-dark p-2 rounded text-bambu-green font-mono`,children:`docker compose pull && docker compose up -d`})]}):Qt?.update_method===`windows_installer`?(0,K.jsxs)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:i(`settings.updateViaWindowsInstaller`)}),(0,K.jsxs)(`a`,{href:Qt.installer_download_url||Qt.release_url||`https://github.com/maziggy/bambuddy/releases/tag/v${Qt.latest_version}`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center font-medium rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-bambu-dark disabled:opacity-50 bg-bambu-green hover:bg-bambu-green-light text-white focus:ring-bambu-green px-4 py-2 text-sm gap-2 min-h-[44px] md:min-h-0`,children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),i(`settings.downloadWindowsInstaller`,{version:Qt.latest_version})]})]}):(0,K.jsxs)($,{className:`mt-3`,onClick:()=>Tn.mutate(),disabled:Tn.isPending,children:[Tn.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Is,{className:`w-4 h-4`}),i(`settings.installUpdate`)]})]}):Qt?.error?(0,K.jsx)(`div`,{className:`mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400`,children:i(`settings.failedToCheckUpdates`,{error:Qt.error})}):Qt&&!Qt.update_available?(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:i(`settings.latestVersionRunning`)}):null]})]})]}),(0,K.jsx)(aze,{})]})]})]}),W===`network`&&O&&(0,K.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-6`,children:[(0,K.jsxs)(`div`,{className:`flex-1 lg:max-w-xl space-y-3`,children:[(0,K.jsxs)(pd,{id:`card-externalurl`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(hc,{className:`w-5 h-5 text-blue-400`}),i(`settings.externalUrl`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.externalUrlDescription`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.bambuddyUrl`)}),(0,K.jsx)(`input`,{type:`text`,value:O.external_url??``,onChange:e=>In(`external_url`,e.target.value),placeholder:`http://192.168.1.100:8000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.externalUrlHint`)})]})]})]}),(0,K.jsxs)(pd,{id:`card-ftpretry`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Cl,{className:`w-5 h-5 text-blue-400`}),i(`settings.ftpRetry`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.ftpRetryDescription`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.enableRetry`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoRetryDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.ftp_retry_enabled??!0,onChange:e=>In(`ftp_retry_enabled`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),O.ftp_retry_enabled&&(0,K.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.retryAttempts`)}),(0,K.jsxs)(`div`,{className:`relative w-44`,children:[(0,K.jsx)(`select`,{value:O.ftp_retry_count??3,onChange:e=>In(`ftp_retry_count`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[1,2,3,4,5,6,7,8,9,10].map(e=>(0,K.jsx)(`option`,{value:e,children:i(`settings.time`,{count:e})},e))}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.retryDelay`)}),(0,K.jsxs)(`div`,{className:`relative w-44`,children:[(0,K.jsx)(`select`,{value:O.ftp_retry_delay??2,onChange:e=>In(`ftp_retry_delay`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[1,2,3,5,10,15,20,30].map(e=>(0,K.jsx)(`option`,{value:e,children:i(`settings.second`,{count:e})},e))}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.connectionTimeout`)}),(0,K.jsxs)(`div`,{className:`relative w-44`,children:[(0,K.jsx)(`select`,{value:O.ftp_timeout??30,onChange:e=>In(`ftp_timeout`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[10,15,20,30,45,60,90,120,180,300].map(e=>(0,K.jsx)(`option`,{value:e,children:i(`settings.nSeconds`,{count:e})},e))}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.increaseForWeakWifi`)})]})]})]})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 lg:max-w-xl space-y-3`,children:[(0,K.jsxs)(pd,{id:`card-ha`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Tc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.homeAssistant`)]}),O.ha_enabled&&ot&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${ot.success?`bg-green-400`:`bg-red-400`}`}),(0,K.jsx)(`span`,{className:`text-sm ${ot.success?`text-green-400`:`text-red-400`}`,children:ot.success?i(`settings.connected`):i(`settings.disconnected`)})]})]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.homeAssistantFullDescription`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.enableHomeAssistant`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.homeAssistantDescription`)}),O.ha_env_managed&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1 mt-1`,children:[(0,K.jsx)(Hc,{className:`w-3 h-3 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.autoEnabledViaEnv`)})]})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.ha_enabled??!1,onChange:e=>In(`ha_enabled`,e.target.checked),disabled:O.ha_env_managed,className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green ${O.ha_env_managed?`opacity-60 cursor-not-allowed`:``}`})]})]}),O.ha_enabled&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.homeAssistantUrl`),O.ha_url_from_env&&(0,K.jsx)(`span`,{className:`ml-2 text-xs text-bambu-green`,children:i(`settings.environmentManagedLabel`)})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{type:`text`,value:O.ha_url??``,onChange:e=>In(`ha_url`,e.target.value),placeholder:`http://192.168.1.100:8123`,disabled:O.ha_url_from_env,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${O.ha_url_from_env?`opacity-60 cursor-not-allowed`:``}`}),O.ha_url_from_env&&(0,K.jsx)(Hc,{className:`absolute right-3 top-2.5 w-4 h-4 text-bambu-gray`})]}),O.ha_url_from_env&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.urlFromEnvReadOnly`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.longLivedAccessToken`),O.ha_token_from_env&&(0,K.jsx)(`span`,{className:`ml-2 text-xs text-bambu-green`,children:i(`settings.environmentManagedLabel`)})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{type:`password`,value:O.ha_token??``,onChange:e=>In(`ha_token`,e.target.value),placeholder:`eyJ0eXAiOiJKV1QiLC...`,disabled:O.ha_token_from_env,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${O.ha_token_from_env?`opacity-60 cursor-not-allowed`:``}`}),O.ha_token_from_env&&(0,K.jsx)(Hc,{className:`absolute right-3 top-2.5 w-4 h-4 text-bambu-gray`})]}),O.ha_token_from_env?(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.tokenFromEnvReadOnly`)}):(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.haTokenHint`)})]}),O.ha_url&&O.ha_token&&(0,K.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)($,{variant:`secondary`,size:`sm`,disabled:ct,onClick:async()=>{lt(!0),st(null);try{st(await Q.testHAConnection(O.ha_url,O.ha_token))}catch(e){st({success:!1,message:null,error:e instanceof Error?e.message:i(`common.unknownError`)})}finally{lt(!1)}},children:[ct?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(ju,{className:`w-4 h-4`}),i(`settings.testConnection`)]})})]})]})]}),(0,K.jsxs)(pd,{id:`card-mqtt`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(ju,{className:`w-5 h-5 text-blue-400`}),i(`settings.mqttPublishing`)]}),rn?.enabled&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${rn.connected?`bg-green-400`:`bg-red-400`}`}),(0,K.jsx)(`span`,{className:`text-sm ${rn.connected?`text-green-400`:`text-red-400`}`,children:rn.connected?i(`settings.connected`):i(`settings.disconnected`)})]})]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.mqttDescription`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.enableMqtt`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.mqttEnableDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.mqtt_enabled??!1,onChange:e=>In(`mqtt_enabled`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),O.mqtt_enabled&&(0,K.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.brokerHostname`)}),(0,K.jsx)(`input`,{type:`text`,value:O.mqtt_broker??``,onChange:e=>In(`mqtt_broker`,e.target.value),placeholder:`mqtt.example.com or 192.168.1.100`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex items-end gap-4`,children:[(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.port`)}),(0,K.jsx)(`input`,{type:`number`,min:`1`,max:`65535`,value:O.mqtt_port??1883,onChange:e=>In(`mqtt_port`,Math.min(65535,Math.max(1,parseInt(e.target.value)||1883))),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 pb-2`,children:[(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.mqtt_use_tls??!1,onChange:e=>{let t=e.target.checked;In(`mqtt_use_tls`,t);let n=O.mqtt_port??1883;t&&n===1883?In(`mqtt_port`,8883):!t&&n===8883&&In(`mqtt_port`,1883)},className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]}),(0,K.jsx)(`span`,{className:`text-white text-sm`,children:i(`settings.useTls`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.usernameOptional`)}),(0,K.jsx)(`input`,{type:`text`,value:O.mqtt_username??``,onChange:e=>In(`mqtt_username`,e.target.value),placeholder:i(`settings.leaveEmptyForAnonymous`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.passwordOptional`)}),(0,K.jsx)(`input`,{type:`password`,value:O.mqtt_password??``,onChange:e=>In(`mqtt_password`,e.target.value),placeholder:i(`settings.leaveEmptyForAnonymous`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.topicPrefix`)}),(0,K.jsx)(`input`,{type:`text`,value:O.mqtt_topic_prefix??`bambuddy`,onChange:e=>In(`mqtt_topic_prefix`,e.target.value),placeholder:`bambuddy`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.topicPrefixHint`,{prefix:O.mqtt_topic_prefix||`bambuddy`})})]}),rn&&(0,K.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${rn.connected?`bg-green-400`:`bg-red-400`}`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:rn.connected?(0,K.jsxs)(K.Fragment,{children:[i(`settings.mqttConnectedTo`),` `,(0,K.jsxs)(`span`,{className:`text-white`,children:[rn.broker,`:`,rn.port]})]}):i(`settings.spoolmanDisconnected`)})]})})]})]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 lg:max-w-md space-y-3`,children:(0,K.jsxs)(pd,{id:`card-prometheus`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(_u,{className:`w-5 h-5 text-orange-400`}),i(`settings.prometheusMetrics`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.prometheusEndpointDescription`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.enableMetricsEndpoint`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.prometheusDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.prometheus_enabled??!1,onChange:e=>In(`prometheus_enabled`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),O.prometheus_enabled&&(0,K.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.bearerTokenOptional`)}),(0,K.jsx)(`input`,{type:`password`,value:O.prometheus_token??``,onChange:e=>In(`prometheus_token`,e.target.value),placeholder:i(`settings.leaveEmptyForNoAuth`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.bearerTokenHint`)})]}),(0,K.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white mb-2`,children:i(`settings.availableMetrics`)}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray space-y-1`,children:[(0,K.jsxs)(`p`,{children:[(0,K.jsx)(`code`,{className:`text-orange-400`,children:`bambuddy_printer_connected`}),` - `,i(`settings.metricsConnectionStatus`)]}),(0,K.jsxs)(`p`,{children:[(0,K.jsx)(`code`,{className:`text-orange-400`,children:`bambuddy_printer_state`}),` - `,i(`settings.metricsPrinterState`)]}),(0,K.jsxs)(`p`,{children:[(0,K.jsx)(`code`,{className:`text-orange-400`,children:`bambuddy_print_progress`}),` - `,i(`settings.metricsPrintProgress`)]}),(0,K.jsxs)(`p`,{children:[(0,K.jsx)(`code`,{className:`text-orange-400`,children:`bambuddy_bed_temp_celsius`}),` - `,i(`settings.metricsBedTemp`)]}),(0,K.jsxs)(`p`,{children:[(0,K.jsx)(`code`,{className:`text-orange-400`,children:`bambuddy_nozzle_temp_celsius`}),` - `,i(`settings.metricsNozzleTemp`)]}),(0,K.jsxs)(`p`,{children:[(0,K.jsx)(`code`,{className:`text-orange-400`,children:`bambuddy_prints_total`}),` - `,i(`settings.metricsPrintsTotal`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray/70 italic`,children:i(`settings.metricsMore`)})]})]})]})]})]})})]}),ot&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[ot.success?(0,K.jsx)(ls,{className:`w-8 h-8 text-green-400`}):(0,K.jsx)(ms,{className:`w-8 h-8 text-red-400`}),(0,K.jsx)(`h3`,{className:`text-lg font-medium text-white`,children:ot.success?i(`settings.connectionSuccessful`):i(`settings.connectionFailed`)})]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:ot.success?ot.message||i(`settings.haConnectionSuccess`):ot.error||i(`settings.haConnectionFailed`)}),(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsx)($,{variant:`primary`,onClick:()=>st(null),children:i(`settings.ok`)})})]})}),W===`plugs`&&(0,K.jsxs)(`div`,{id:`card-plugs`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between mb-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(gl,{className:`w-5 h-5 text-bambu-green`}),i(`settings.smartPlugs`)]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.smartPlugsDescription`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 pt-1 shrink-0`,children:[xt&&xt.filter(e=>e.enabled).length>1&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,className:`whitespace-nowrap`,onClick:()=>ke(`on`),disabled:kn.isPending,title:i(`settings.turnAllPlugsOn`),children:[kn.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(yl,{className:`w-4 h-4 text-bambu-green`}),i(`settings.allOn`)]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,className:`whitespace-nowrap`,onClick:()=>ke(`off`),disabled:kn.isPending,title:i(`settings.turnAllPlugsOff`),children:[kn.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(vl,{className:`w-4 h-4 text-red-400`}),i(`settings.allOff`)]})]}),(0,K.jsxs)($,{className:`whitespace-nowrap`,onClick:()=>{N(null),j(!0)},children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.addSmartPlug`)]})]})]}),xt&&xt.length>0&&(0,K.jsxs)(pd,{className:`mb-6`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Iu,{className:`w-4 h-4 text-yellow-400`}),i(`settings.energySummary`),Tt&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin text-bambu-gray ml-2`})]})}),(0,K.jsx)(hd,{children:wt?(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,K.jsx)(Iu,{className:`w-3 h-3`}),i(`settings.currentPower`)]}),(0,K.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[wt.totalPower.toFixed(1),(0,K.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`W`})]}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.plugsOnline`,{reachable:wt.reachableCount,total:wt.totalPlugs})})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,K.jsx)(qo,{className:`w-3 h-3`}),i(`settings.today`)]}),(0,K.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[wt.totalToday.toFixed(3),(0,K.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(O?.energy_cost_per_kwh??0)>0&&(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,(wt.totalToday*(O?.energy_cost_per_kwh??0)).toFixed(2),` `,Yd(O?.currency||`USD`)]})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,K.jsx)(_u,{className:`w-3 h-3`}),i(`settings.yesterday`)]}),(0,K.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[wt.totalYesterday.toFixed(3),(0,K.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(O?.energy_cost_per_kwh??0)>0&&(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,(wt.totalYesterday*(O?.energy_cost_per_kwh??0)).toFixed(2),` `,Yd(O?.currency||`USD`)]})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,K.jsx)(Ns,{className:`w-3 h-3`}),i(`settings.total`)]}),(0,K.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[wt.totalLifetime.toFixed(1),(0,K.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(O?.energy_cost_per_kwh??0)>0&&(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,(wt.totalLifetime*(O?.energy_cost_per_kwh??0)).toFixed(2),` `,Yd(O?.currency||`USD`)]})]})]}):Tt?null:(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.enablePlugsForSummary`)})})]}),St?(0,K.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):xt&&xt.length>0?(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:xt.map(e=>(0,K.jsx)(CRe,{plug:e,onEdit:e=>{N(e),j(!0)}},e.id))}):(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-12`,children:(0,K.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,K.jsx)(gl,{className:`w-16 h-16 mx-auto mb-4 opacity-30`}),(0,K.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.noSmartPlugsTitle`)}),(0,K.jsx)(`p`,{className:`text-sm mb-4`,children:i(`settings.noSmartPlugsDescription`)}),(0,K.jsxs)($,{onClick:()=>{N(null),j(!0)},children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.addFirstSmartPlug`)]})]})})})]}),W===`notifications`&&(0,K.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-providers`,children:[(0,K.jsx)(Io,{className:`w-5 h-5 text-bambu-green`}),i(`settings.providers`)]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>ne(!0),children:[(0,K.jsx)(wc,{className:`w-4 h-4`}),i(`settings.log`)]}),Et&&Et.length>0&&(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>{Dn(null),On.mutate()},disabled:On.isPending,children:[On.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Pl,{className:`w-4 h-4`}),i(`settings.testAll`)]}),(0,K.jsxs)($,{size:`sm`,onClick:()=>{L(null),F(!0)},children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.addNotificationProvider`)]})]})]}),(0,K.jsx)(pd,{className:`mb-4`,children:(0,K.jsx)(hd,{className:`py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.notificationLanguage`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.notificationLanguageDescription`)})]}),(0,K.jsx)(`select`,{value:O.notification_language||`en`,onChange:e=>In(`notification_language`,e.target.value),className:`px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green`,children:Ct.map(e=>(0,K.jsx)(`option`,{value:e.code,children:e.nativeName},e.code))})]})})}),(0,K.jsx)(pd,{className:`mb-4`,children:(0,K.jsx)(hd,{className:`py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.bedCooledThreshold`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.bedCooledThresholdDescription`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`input`,{type:`number`,min:20,max:80,step:1,value:O.bed_cooled_threshold??35,onChange:e=>In(`bed_cooled_threshold`,Number(e.target.value)),className:`w-16 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm text-center focus:outline-none focus:ring-1 focus:ring-bambu-green`}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`°C`})]})]})})}),(0,K.jsx)(pd,{className:`mb-4`,children:(0,K.jsx)(hd,{className:`py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between ${sn?.advanced_auth_enabled?``:`opacity-50`}`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.userNotificationsEnabled`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:sn?.advanced_auth_enabled?i(`settings.userNotificationsEnabledDescription`):i(`settings.userNotificationsDisabledHint`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,className:`sr-only peer`,checked:O.user_notifications_enabled??!0,disabled:!sn?.advanced_auth_enabled,onChange:e=>In(`user_notifications_enabled`,e.target.checked)}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green peer-disabled:cursor-not-allowed`})]})]})})}),En&&(0,K.jsx)(pd,{className:`mb-4`,children:(0,K.jsxs)(hd,{className:`py-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium text-white`,children:i(`settings.testResults`)}),(0,K.jsx)(`button`,{onClick:()=>Dn(null),className:`text-bambu-gray hover:text-white text-xs`,children:i(`common.dismiss`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm mb-2`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-green`,children:[(0,K.jsx)(ls,{className:`w-4 h-4`}),i(`settings.testPassedCount`,{count:En.success})]}),En.failed>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-red-400`,children:[(0,K.jsx)(ms,{className:`w-4 h-4`}),i(`settings.testFailedCount`,{count:En.failed})]})]}),En.results.filter(e=>!e.success).length>0&&(0,K.jsx)(`div`,{className:`space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary`,children:En.results.filter(e=>!e.success).map(e=>(0,K.jsxs)(`div`,{className:`text-xs text-red-400`,children:[(0,K.jsxs)(`span`,{className:`font-medium`,children:[e.provider_name,`:`]}),` `,e.message]},e.provider_id))})]})}),Dt?(0,K.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})}):Et&&Et.length>0?(0,K.jsx)(`div`,{className:`space-y-3`,children:Et.map(e=>(0,K.jsx)(TRe,{provider:e,onEdit:e=>{L(e),F(!0)}},e.id))}):(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-8`,children:(0,K.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,K.jsx)(Io,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,K.jsx)(`p`,{className:`text-sm font-medium text-white mb-2`,children:i(`settings.noProvidersTitle`)}),(0,K.jsx)(`p`,{className:`text-xs mb-3`,children:i(`settings.noProvidersDescription`)}),(0,K.jsxs)($,{size:`sm`,onClick:()=>{L(null),F(!0)},children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.addProvider`)]})]})})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-2`,id:`card-templates`,children:[(0,K.jsx)(Zs,{className:`w-5 h-5 text-bambu-green`}),i(`settings.messageTemplates`)]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:i(`settings.messageTemplatesDescription`)}),(0,K.jsxs)(`div`,{className:`relative mb-3`,children:[(0,K.jsx)(Nl,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none`}),(0,K.jsx)(`input`,{type:`text`,value:B,onChange:e=>V(e.target.value),placeholder:i(`settings.filterTemplates`,`Filter templates…`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),B&&(0,K.jsx)(`button`,{onClick:()=>V(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white`,"aria-label":`Clear filter`,children:(0,K.jsx)(Pu,{className:`w-3.5 h-3.5`})})]}),Pt?(0,K.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})}):Nt&&Nt.length>0?(()=>{let e=B.trim().toLowerCase(),t=[...Nt].sort((e,t)=>e.name.localeCompare(t.name)).filter(t=>!e||t.name.toLowerCase().includes(e)||(t.title_template||``).toLowerCase().includes(e));return t.length===0?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic text-center py-6`,children:i(`settings.noTemplatesMatch`,`No templates match your filter.`)}):(0,K.jsx)(`div`,{className:`space-y-2`,children:t.map(e=>(0,K.jsx)(pd,{className:`cursor-pointer hover:border-bambu-green/50 transition-colors`,onClick:()=>z(e),children:(0,K.jsx)(hd,{className:`py-2.5 px-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium text-sm truncate`,children:e.name}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs truncate mt-0.5`,children:e.title_template})]}),(0,K.jsx)(`button`,{className:`p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2`,onClick:t=>{t.stopPropagation(),z(e)},children:(0,K.jsx)(fl,{className:`w-4 h-4 text-bambu-gray`})})]})})},e.id))})})():(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-8`,children:(0,K.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,K.jsx)(Zs,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,K.jsx)(`p`,{className:`text-sm`,children:i(`settings.noTemplatesAvailable`)})]})})})]})]}),W===`apikeys`&&(0,K.jsxs)(`div`,{className:d(`api_keys:read`)?`grid grid-cols-1 xl:grid-cols-2 gap-4`:`grid grid-cols-1 gap-4`,children:[(0,K.jsxs)(`div`,{children:[d(`api_keys:read`)&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-6`,children:[(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-createapi`,children:[(0,K.jsx)(jc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.apiKeys`)]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.apiKeysDescription`)})]}),(0,K.jsxs)($,{size:`sm`,onClick:()=>de(!0),className:`flex-shrink-0`,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.createKey`)]})]}),ge&&(0,K.jsx)(pd,{className:`mb-6 border-bambu-green`,children:(0,K.jsx)(hd,{className:`py-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(ls,{className:`w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium mb-1`,children:i(`settings.apiKeyCreated`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:i(`settings.apiKeyCopyWarning`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 bg-bambu-dark rounded-lg p-2`,children:[(0,K.jsx)(`code`,{className:`flex-1 text-sm text-bambu-green font-mono break-all`,children:ge}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(ge);else{let e=document.createElement(`textarea`);e.value=ge,e.style.position=`fixed`,e.style.left=`-999999px`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e)}o(i(`settings.toast.keyCopied`))}catch{o(i(`settings.toast.copyFailed`),`error`)}},children:(0,K.jsx)(Ds,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 mt-3`,children:[(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>{Ce(ge),o(i(`settings.toast.keyAddedToBrowser`))},children:i(`settings.useInApiBrowser`)}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>ye(!0),children:[(0,K.jsx)(xl,{className:`w-4 h-4`}),i(`settings.apiKeyQrButton`)]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>{ye(!1),_e(null)},children:i(`common.dismiss`)})]})]})]})})}),ve&&ge&&(0,K.jsx)(HRe,{apiKey:ge,baseUrl:O?.external_url||void 0,onClose:()=>ye(!1)}),ue&&(0,K.jsxs)(pd,{className:`mb-6`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h3`,{className:`text-base font-semibold text-white`,children:i(`settings.createNewApiKey`)})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.keyName`)}),(0,K.jsx)(`input`,{type:`text`,value:fe,onChange:e=>pe(e.target.value),placeholder:i(`settings.keyNamePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:i(`common.permissions`)}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:me.can_read_status,onChange:e=>he(t=>({...t,can_read_status:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white`,children:i(`settings.readStatus`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.readStatusDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:me.can_queue,onChange:e=>he(t=>({...t,can_queue:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white`,children:i(`settings.manageQueue`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageQueueDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:me.can_control_printer,onChange:e=>he(t=>({...t,can_control_printer:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white`,children:i(`settings.controlPrinter`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.controlPrinterDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:me.can_manage_library,onChange:e=>he(t=>({...t,can_manage_library:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white`,children:i(`settings.manageLibrary`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageLibraryDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:me.can_manage_inventory,onChange:e=>he(t=>({...t,can_manage_inventory:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white`,children:i(`settings.manageInventory`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageInventoryDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:me.can_access_cloud,onChange:e=>he(t=>({...t,can_access_cloud:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white`,children:i(`settings.cloudAccess`,`Allow cloud access`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.cloudAccessDescription`,`Read Bambu Cloud presets and filaments on your behalf. Requires you to be signed into Bambu Cloud.`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:me.can_update_energy_cost,onChange:e=>he(t=>({...t,can_update_energy_cost:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white`,children:i(`settings.updateEnergyCost`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.updateEnergyCostDescription`)})]})]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 pt-2`,children:[(0,K.jsxs)($,{onClick:()=>At.mutate({name:fe||i(`settings.unnamedKey`),...me}),disabled:At.isPending,children:[At.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.createKey`)]}),(0,K.jsx)($,{variant:`secondary`,onClick:()=>de(!1),children:i(`common.cancel`)})]})]})]}),kt?(0,K.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):Ot&&Ot.length>0?(0,K.jsx)(`div`,{className:`space-y-3`,children:Ot.map(e=>(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(jc,{className:`w-5 h-5 ${e.enabled?`text-bambu-green`:`text-bambu-gray`}`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e.name}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[e.key_prefix,`••••••••`,e.last_used&&` · ${i(`settings.lastUsed`)}: ${hf(e.last_used)}`]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex gap-1 text-xs flex-wrap justify-end`,children:[e.can_read_status&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded`,children:i(`settings.read`)}),e.can_queue&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded`,children:i(`queue.title`)}),e.can_control_printer&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded`,children:i(`settings.control`)}),e.can_manage_library&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-cyan-500/20 text-cyan-400 rounded`,children:i(`settings.libraryBadge`)}),e.can_manage_inventory&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-pink-500/20 text-pink-400 rounded`,children:i(`settings.inventoryBadge`)}),e.can_access_cloud&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-purple-500/20 text-purple-400 rounded`,children:i(`settings.cloudBadge`,`Cloud`)}),e.can_update_energy_cost&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-amber-500/20 text-amber-400 rounded`,children:i(`settings.energyCostBadge`)}),e.user_id===null&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-yellow-500/20 text-yellow-400 rounded`,title:i(`settings.legacyKeyTooltip`,`Created before per-user ownership; recreate to use cloud access`),children:i(`settings.legacyKey`,`Legacy`)})]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>xe(e.id),children:(0,K.jsx)(hu,{className:`w-4 h-4 text-red-400`})})]})]})})},e.id))}):(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-12`,children:(0,K.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,K.jsx)(jc,{className:`w-16 h-16 mx-auto mb-4 opacity-30`}),(0,K.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.apiKeysEmptyTitle`)}),(0,K.jsx)(`p`,{className:`text-sm mb-4`,children:i(`settings.apiKeysEmptyDescription`)}),(0,K.jsxs)($,{onClick:()=>de(!0),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.createFirstKey`)]})]})})}),(0,K.jsxs)(pd,{className:`mt-6`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h3`,{className:`text-base font-semibold text-white`,id:`card-webhooks`,children:i(`settings.webhookEndpoints`)})}),(0,K.jsxs)(hd,{className:`space-y-3 text-sm`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:i(`settings.webhookApiKeyHint`)}),(0,K.jsxs)(`div`,{className:`space-y-2 font-mono text-xs`,children:[(0,K.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,K.jsx)(`span`,{className:`text-blue-400`,children:`GET`}),` `,(0,K.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/status`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.getAllStatus`)]})]}),(0,K.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,K.jsx)(`span`,{className:`text-blue-400`,children:`GET`}),` `,(0,K.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/status/:id`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.getSpecificStatus`)]})]}),(0,K.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,K.jsx)(`span`,{className:`text-green-400`,children:`POST`}),` `,(0,K.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/queue`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.addToQueue`)]})]}),(0,K.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,K.jsx)(`span`,{className:`text-orange-400`,children:`POST`}),` `,(0,K.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/pause`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.pausePrint`)]})]}),(0,K.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,K.jsx)(`span`,{className:`text-orange-400`,children:`POST`}),` `,(0,K.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/resume`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.resumePrint`)]})]}),(0,K.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,K.jsx)(`span`,{className:`text-red-400`,children:`POST`}),` `,(0,K.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/stop`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.stopPrint`)]})]})]})]})]})]}),(0,K.jsxs)(pd,{className:`mt-6`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-camera-tokens`,children:[(0,K.jsx)(Tu,{className:`w-4 h-4 text-bambu-green`}),i(`cameraTokens.title`,`Camera API Tokens`)]})}),(0,K.jsx)(hd,{children:(0,K.jsx)(SRe,{})})]})]}),d(`api_keys:read`)&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-apibrowser`,children:[(0,K.jsx)(hc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.apiBrowser`)]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.apiBrowserDescription`)})]}),(0,K.jsx)(pd,{className:`mb-4`,children:(0,K.jsxs)(hd,{className:`py-3`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:i(`settings.apiKeyForTesting`)}),(0,K.jsx)(`input`,{type:`text`,value:Se,onChange:e=>Ce(e.target.value),placeholder:i(`settings.apiKeyPlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:i(`settings.apiKeyHint`)})]})}),(0,K.jsx)(Pze,{apiKey:Se})]})]}),W===`virtual-printer`&&(0,K.jsx)(`div`,{id:`card-vp`,children:(0,K.jsx)(dze,{})}),W===`spoolbuddy`&&(0,K.jsx)(`div`,{id:`card-spoolbuddy`,children:(0,K.jsx)(pze,{})}),W===`queue`&&O&&(0,K.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,K.jsxs)(`div`,{className:`lg:w-1/2 space-y-3`,children:[(0,K.jsxs)(pd,{id:`card-print-options`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Rc,{className:`w-4 h-4 text-bambu-green`}),i(`settings.defaultPrintOptions`,`Default Print Options`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.defaultPrintOptionsDescription`,`Set default values for print options when starting new prints. These can be overridden per print in the print dialog.`)}),[{key:`default_bed_levelling`,label:i(`settings.defaultBedLevelling`,`Bed Levelling`),desc:i(`settings.defaultBedLevellingDesc`,`Auto-level bed before print`),fallback:!0,dualNozzleOnly:!1},{key:`default_flow_cali`,label:i(`settings.defaultFlowCali`,`Flow Calibration`),desc:i(`settings.defaultFlowCaliDesc`,`Calibrate extrusion flow`),fallback:!1,dualNozzleOnly:!1},{key:`default_vibration_cali`,label:i(`settings.defaultVibrationCali`,`Vibration Calibration`),desc:i(`settings.defaultVibrationCaliDesc`,`Reduce ringing artifacts`),fallback:!0,dualNozzleOnly:!1},{key:`default_layer_inspect`,label:i(`settings.defaultLayerInspect`,`First Layer Inspection`),desc:i(`settings.defaultLayerInspectDesc`,`AI inspection of first layer`),fallback:!1,dualNozzleOnly:!1},{key:`default_timelapse`,label:i(`settings.defaultTimelapse`,`Timelapse`),desc:i(`settings.defaultTimelapseDesc`,`Record timelapse video`),fallback:!1,dualNozzleOnly:!1},{key:`default_nozzle_offset_cali`,label:i(`settings.defaultNozzleOffsetCali`,`Nozzle Offset Calibration`),desc:i(`settings.defaultNozzleOffsetCaliDesc`,`Calibrate nozzle offsets between extruders`),fallback:!0,dualNozzleOnly:!0}].filter(({dualNozzleOnly:e})=>!e||(Mt||[]).some(e=>e.nozzle_count===2)).map(({key:e,label:t,desc:n,fallback:r})=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:t}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:n})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O[e]??r,onChange:t=>In(e,t.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]},e))]})]}),(0,K.jsxs)(pd,{id:`card-temp-fan-presets`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(pu,{className:`w-4 h-4 text-bambu-green`}),i(`settings.tempFanPresetsTitle`,`Temperature & Fan Presets`)]})}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.tempFanPresetsDescription`,`Customize the quick-select values shown in printer-card temperature and fan-speed popovers. The Off button is always shown.`)}),ap.map(e=>{let t=op(O?.[e.key]??``,e.defaults,e.lo,e.hi),n=e.unit===`C`?`°C`:`%`;return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,K.jsxs)(`label`,{className:`text-sm text-white`,children:[i(`settings.${{nozzle_temp_presets:`tempFanPresetsNozzle`,bed_temp_presets:`tempFanPresetsBed`,chamber_temp_presets:`tempFanPresetsChamber`,fan_speed_presets:`tempFanPresetsFan`}[e.key]}`,{nozzle_temp_presets:`Nozzle temperature`,bed_temp_presets:`Bed temperature`,chamber_temp_presets:`Chamber temperature`,fan_speed_presets:`Fan speed`}[e.key]),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[`(`,n,` · `,e.lo,`–`,e.hi,`)`]})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>In(e.key,``),title:i(`settings.tempFanPresetsReset`,`Reset to defaults`),className:`text-bambu-gray hover:text-white transition-colors p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(Tl,{className:`w-3.5 h-3.5`})})]}),(0,K.jsx)(`div`,{className:`flex gap-2`,children:[0,1,2].map(n=>(0,K.jsx)(`input`,{type:`number`,min:e.lo,max:e.hi,value:t[n],onChange:r=>{let i=[t[0],t[1],t[2]],a=parseInt(r.target.value,10);i[n]=Math.max(e.lo,Math.min(e.hi,Number.isFinite(a)?a:e.lo)),In(e.key,JSON.stringify(i))},className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`},n))})]},e.key)})]})]}),(0,K.jsxs)(pd,{id:`card-staggered`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Nc,{className:`w-4 h-4 text-bambu-green`}),i(`settings.staggeredStart`,`Staggered Start`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.staggeredStartDescription`,`Default group size and interval when staggering multi-printer batch starts. Can be overridden per batch in the print modal.`)}),(0,K.jsxs)(`div`,{className:`flex gap-4`,children:[(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.staggerGroupSize`,`Group size`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:50,value:O.stagger_group_size??2,onChange:e=>In(`stagger_group_size`,Math.max(1,Math.min(50,parseInt(e.target.value)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.staggerGroupSizeHelp`,`Printers to start simultaneously per group`)})]}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.staggerInterval`,`Interval (minutes)`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:60,value:O.stagger_interval_minutes??5,onChange:e=>In(`stagger_interval_minutes`,Math.max(1,Math.min(60,parseInt(e.target.value)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.staggerIntervalHelp`,`Delay between each group starting`)})]})]})]})]}),(0,K.jsxs)(pd,{id:`card-plate`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Hl,{className:`w-4 h-4 text-bambu-green`}),i(`settings.plateClear`,`Plate-Clear Confirmation`)]})}),(0,K.jsx)(hd,{className:`space-y-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:i(`settings.requirePlateClear`,`Require plate-clear confirmation`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.requirePlateClearDescription`,`When enabled, the scheduler waits for per-printer plate-clear confirmation before starting queued prints on printers with finished jobs. Disabling this also hides the plate status badge and the "Mark plate as cleared" button on printer cards.`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.require_plate_clear??!1,onChange:e=>In(`require_plate_clear`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})})]}),(0,K.jsxs)(pd,{id:`card-gcode`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(xs,{className:`w-4 h-4 text-bambu-green`}),i(`settings.gcodeInjection`,`G-code Injection`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.gcodeInjectionDescription`,`Configure custom G-code to inject at the start and/or end of prints for auto-print systems like Farmloop, SwapMod, AutoClear, and Printflow 3D. Snippets are configured per printer model and applied when "Inject G-code" is enabled on a queue item.`)}),(()=>{let e=(()=>{try{return O.gcode_snippets?JSON.parse(O.gcode_snippets):{}}catch{return{}}})(),t=[...new Set((Mt||[]).filter(e=>e.model).map(e=>e.model))].sort(),n=(t,n,r)=>{let i={...e};i[t]||(i[t]={start_gcode:``,end_gcode:``}),i[t][n]=r,!i[t].start_gcode&&!i[t].end_gcode&&delete i[t];let a=Object.keys(i).length>0?JSON.stringify(i):``;k(e=>e?{...e,gcode_snippets:a}:null),jn.current=a},r=()=>{jn.current!==null&&(Pn.mutate({gcode_snippets:jn.current}),jn.current=null)};return t.length===0?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:i(`settings.gcodeInjectionNoPrinters`,`No printers found. Add printers to configure G-code snippets.`)}):t.map(t=>{let a=e[t]||{start_gcode:``,end_gcode:``},o=!!(a.start_gcode||a.end_gcode);return(0,K.jsx)(Mf,{defaultOpen:o,className:`border border-bambu-dark-tertiary rounded-lg px-3 py-2`,summary:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t}),o&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:i(`settings.gcodeConfigured`,`Configured`)})]}),children:(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.gcodeStartLabel`,`Start G-code`)}),(0,K.jsx)(`textarea`,{value:a.start_gcode,onChange:e=>n(t,`start_gcode`,e.target.value),onBlur:r,placeholder:i(`settings.gcodeStartPlaceholder`,`G-code prepended before the print starts...`),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.gcodeEndLabel`,`End G-code`)}),(0,K.jsx)(`textarea`,{value:a.end_gcode,onChange:e=>n(t,`end_gcode`,e.target.value),onBlur:r,placeholder:i(`settings.gcodeEndPlaceholder`,`G-code appended after the print ends...`),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y`})]})]})},t)})})()]})]})]}),(0,K.jsxs)(`div`,{className:`lg:w-1/2 space-y-3`,children:[(0,K.jsxs)(pd,{id:`card-slicer`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(ws,{className:`w-4 h-4 text-bambu-green`}),i(`settings.slicerCard`,`Slicer`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.preferredSlicer`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:O.preferred_slicer??`bambu_studio`,onChange:e=>In(`preferred_slicer`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,K.jsx)(`option`,{value:`bambu_studio`,children:i(`settings.slicerBambuStudio`)}),(0,K.jsx)(`option`,{value:`orcaslicer`,children:i(`settings.slicerOrcaSlicer`)})]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.preferredSlicerDescription`)}),(O.preferred_slicer??`bambu_studio`)===`orcaslicer`&&(0,K.jsx)(`div`,{role:`alert`,className:`text-xs text-amber-200 bg-amber-900/20 border border-amber-700/40 rounded p-2 mt-2`,children:i(`settings.orcaslicerKnownIssuesWarning`,`OrcaSlicer 2.3.2 / 2.4.0-dev have known CLI bugs that block slicing many Bambu-authored 3MFs — see upstream issues #12426 (segfault on painted multi-extruder files) and #13386 (parameter-range strict-validation reject). Bambu Studio is recommended until the upstream fixes land.`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.openInSlicerLabel`,`Open in Slicer`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:O.open_in_slicer??``,onChange:e=>In(`open_in_slicer`,e.target.value===``?null:e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,K.jsx)(`option`,{value:``,children:i(`settings.openInSlicerInherit`,`Same as API slicer`)}),(0,K.jsx)(`option`,{value:`bambu_studio`,children:i(`settings.slicerBambuStudio`)}),(0,K.jsx)(`option`,{value:`orcaslicer`,children:i(`settings.slicerOrcaSlicer`)})]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.openInSlicerDescription`,`Desktop slicer used by the 'Open in Slicer' button. Leave on 'Same as API slicer' to inherit, or pick a different slicer to use locally.`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.useSlicerApi`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.useSlicerApiDescription`)})]}),(0,K.jsxs)(`label`,{className:`flex items-center cursor-pointer shrink-0`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.use_slicer_api??!1,onChange:e=>In(`use_slicer_api`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`relative w-11 h-6 bg-bambu-dark-tertiary rounded-full peer peer-checked:bg-bambu-green peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-bambu-green/50 transition-colors after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-transform peer-checked:after:translate-x-5`})]})]}),(O.use_slicer_api??!1)&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:(O.preferred_slicer??`bambu_studio`)===`orcaslicer`?i(`settings.orcaslicerApiUrl`,`OrcaSlicer sidecar URL`):i(`settings.bambuStudioApiUrl`,`Bambu Studio sidecar URL`)}),(0,K.jsx)(`input`,{type:`text`,value:((O.preferred_slicer??`bambu_studio`)===`orcaslicer`?O.orcaslicer_api_url:O.bambu_studio_api_url)??``,onChange:e=>In((O.preferred_slicer??`bambu_studio`)===`orcaslicer`?`orcaslicer_api_url`:`bambu_studio_api_url`,e.target.value),placeholder:(O.preferred_slicer??`bambu_studio`)===`orcaslicer`?`http://localhost:3003`:`http://localhost:3001`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none placeholder:text-bambu-gray/40`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.slicerApiUrlDescription`,`URL of the slicer-API sidecar container. Leave blank to use the SLICER_API_URL / BAMBU_STUDIO_API_URL env var defaults.`)})]})]})]}),(O.use_slicer_api??!1)&&(0,K.jsx)(gRe,{}),(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-drying`,children:[(0,K.jsx)(ec,{className:`w-4 h-4 text-amber-400`}),i(`settings.queueDrying`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.queueDryingDescription`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.queueDryingEnabled`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.queueDryingEnabledDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.queue_drying_enabled??!1,onChange:e=>In(`queue_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),O.queue_drying_enabled&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.queueDryingBlock`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.queueDryingBlockDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.queue_drying_block??!1,onChange:e=>In(`queue_drying_block`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-amber-500`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.ambientDryingEnabled`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.ambientDryingEnabledDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.ambient_drying_enabled??!1,onChange:e=>In(`ambient_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white font-medium`,children:i(`settings.dryingPresets`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.dryingPresetsDescription`)}),(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`,children:i(`settings.dryingFilament`)}),(0,K.jsx)(`th`,{className:`text-center py-1.5`,colSpan:2,children:`AMS 2 Pro`}),(0,K.jsx)(`th`,{className:`text-center py-1.5`,colSpan:2,children:`AMS-HT`})]})}),(0,K.jsx)(`tbody`,{children:(()=>{let e={PLA:{n3f:45,n3s:45,n3f_hours:12,n3s_hours:12},PETG:{n3f:65,n3s:65,n3f_hours:12,n3s_hours:12},TPU:{n3f:65,n3s:75,n3f_hours:12,n3s_hours:18},ABS:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},ASA:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:12},PC:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PVA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:18}},t={...e};try{if(O.drying_presets){let n=JSON.parse(O.drying_presets);typeof n==`object`&&n&&(t={...e,...n})}}catch{}let n=(e,n,r)=>{let i={...t,[e]:{...t[e],[n]:r}};In(`drying_presets`,JSON.stringify(i))};return Object.entries(t).map(([e,t])=>(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50`,children:[(0,K.jsx)(`td`,{className:`py-1.5 pr-2 text-white font-medium`,children:e}),(0,K.jsx)(`td`,{className:`py-1 px-1`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,K.jsx)(`input`,{type:`number`,min:30,max:65,value:t.n3f,onChange:t=>n(e,`n3f`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})}),(0,K.jsx)(`td`,{className:`py-1 px-1`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`input`,{type:`number`,min:1,max:24,value:t.n3f_hours,onChange:t=>n(e,`n3f_hours`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`h`})]})}),(0,K.jsx)(`td`,{className:`py-1 px-1`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,K.jsx)(`input`,{type:`number`,min:30,max:85,value:t.n3s,onChange:t=>n(e,`n3s`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})}),(0,K.jsx)(`td`,{className:`py-1 px-1`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`input`,{type:`number`,min:1,max:24,value:t.n3s_hours,onChange:t=>n(e,`n3s_hours`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`h`})]})})]},e))})()})]})})]})]})]})]})]}),W===`filament`&&O&&(0,K.jsx)(K.Fragment,{children:(0,K.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,K.jsxs)(`div`,{className:`lg:w-1/3 space-y-3`,children:[(0,K.jsx)(KRe,{}),(0,K.jsxs)(pd,{id:`card-filamentchecks`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.filamentChecks`)})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.disableFilamentWarnings`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.disableFilamentWarningsDesc`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.disable_filament_warnings,onChange:e=>In(`disable_filament_warnings`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.preferLowestFilament`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.preferLowestFilamentDesc`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:i(`settings.preferLowestFilamentBackupNote`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.prefer_lowest_filament,onChange:e=>In(`prefer_lowest_filament`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]})]}),(0,K.jsxs)(pd,{id:`card-printmodal`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.printModal`)})}),(0,K.jsx)(hd,{className:`space-y-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.expandCustomMapping`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.expandCustomMappingDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.per_printer_mapping_expanded??!1,onChange:e=>In(`per_printer_mapping_expanded`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})})]}),(0,K.jsxs)(pd,{id:`card-amsthresholds`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.amsDisplayThresholds`)})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.amsThresholdsDescription`)}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,K.jsx)(Rs,{className:`w-4 h-4 text-blue-400`}),(0,K.jsx)(`span`,{className:`font-medium`,children:i(`settings.humidity`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.goodGreen`),` ≤`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,min:`0`,max:`100`,value:O.ams_humidity_good??40,onChange:e=>In(`ams_humidity_good`,parseInt(e.target.value)||40),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.fairOrange`),` ≤`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,min:`0`,max:`100`,value:O.ams_humidity_fair??60,onChange:e=>In(`ams_humidity_fair`,parseInt(e.target.value)||60),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.aboveFairBad`)}),(0,K.jsx)(`p`,{className:`text-xs text-amber-400/70`,children:i(`settings.fairAlsoDryingThreshold`)})]}),(0,K.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,K.jsx)(pu,{className:`w-4 h-4 text-orange-400`}),(0,K.jsx)(`span`,{className:`font-medium`,children:i(`settings.temperature`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.goodBlue`),` ≤`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,step:`0.5`,min:`0`,max:`60`,value:O.ams_temp_good??28,onChange:e=>In(`ams_temp_good`,parseFloat(e.target.value)||28),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.fairOrange`),` ≤`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,step:`0.5`,min:`0`,max:`60`,value:O.ams_temp_fair??35,onChange:e=>In(`ams_temp_fair`,parseFloat(e.target.value)||35),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.aboveFairHot`)})]}),(0,K.jsxs)(`div`,{className:`space-y-3 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,K.jsx)(js,{className:`w-4 h-4 text-purple-400`}),(0,K.jsx)(`span`,{className:`font-medium`,children:i(`settings.historyRetention`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.keepSensorHistory`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,min:`1`,max:`365`,value:O.ams_history_retention_days??30,onChange:e=>In(`ams_history_retention_days`,parseInt(e.target.value)||30),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`common.days`)})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.historyRetentionDescription`)})]})]})]})]}),(0,K.jsxs)(`div`,{className:`lg:w-2/3 space-y-3`,children:[(0,K.jsx)(qRe,{}),(0,K.jsx)(rze,{})]})]})}),be!==null&&(0,K.jsx)(Ed,{title:i(`settings.deleteApiKeyTitle`),message:i(`settings.deleteApiKeyMessage`),confirmText:i(`settings.deleteKey`),variant:`danger`,onConfirm:()=>{jt.mutate(be),xe(null)},onCancel:()=>xe(null)}),A&&(0,K.jsx)(wRe,{plug:M,onClose:()=>{j(!1),N(null)}}),P&&(0,K.jsx)(DRe,{provider:I,onClose:()=>{F(!1),L(null)}}),R&&(0,K.jsx)(ORe,{template:R,onClose:()=>z(null)}),te&&(0,K.jsx)(ARe,{onClose:()=>ne(!1)}),we&&(0,K.jsx)(Ed,{title:i(`settings.clearNotificationLogs`),message:i(`settings.clearLogsMessage`),confirmText:i(`settings.clearLogs`),variant:`warning`,onConfirm:async()=>{Te(!1);try{o((await Q.clearNotificationLogs(30)).message,`success`)}catch{o(i(`settings.toast.clearLogsFailed`),`error`)}},onCancel:()=>Te(!1)}),Ee&&(0,K.jsx)(Ed,{title:i(`settings.resetUiPreferences`),message:i(`settings.resetUiPreferencesMessage`),confirmText:i(`settings.resetPreferences`),variant:`default`,onConfirm:()=>{De(!1),localStorage.clear(),o(i(`settings.toast.uiPreferencesReset`),`success`),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>De(!1)}),Oe&&(0,K.jsx)(Ed,{title:`Turn All Plugs ${Oe===`on`?`On`:`Off`}`,message:`This will turn ${Oe===`on`?`ON`:`OFF`} all ${xt?.filter(e=>e.enabled).length||0} enabled smart plugs. ${Oe===`off`?`Any running printers may be affected!`:``}`,confirmText:`Turn All ${Oe===`on`?`On`:`Off`}`,variant:Oe===`off`?`danger`:`warning`,onConfirm:()=>{let e=Oe;ke(null),kn.mutate(e)},onCancel:()=>ke(null)}),Ae&&Qt?.release_notes&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>je(!1),children:(0,K.jsxs)(pd,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(md,{className:`flex flex-row items-center justify-between shrink-0`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[`Release Notes - v`,Qt.latest_version]}),Qt.release_name&&Qt.release_name!==Qt.latest_version&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:Qt.release_name})]}),(0,K.jsx)(`button`,{onClick:()=>je(!1),className:`p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsx)(hd,{className:`overflow-y-auto flex-1`,children:(0,K.jsx)(`pre`,{className:`text-sm text-bambu-gray whitespace-pre-wrap font-sans`,children:Qt.release_notes})}),(0,K.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2`,children:[Qt.release_url&&(0,K.jsx)(`a`,{href:Qt.release_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex-1`,children:(0,K.jsxs)($,{variant:`secondary`,className:`w-full`,children:[(0,K.jsx)(Us,{className:`w-4 h-4`}),`View on GitHub`]})}),(0,K.jsx)($,{onClick:()=>je(!1),className:`flex-1`,children:`Close`})]})]})}),W===`users`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`button`,{onClick:()=>ce(`users`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${se===`users`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(wu,{className:`w-4 h-4`}),i(`settings.tabs.users`)]}),(0,K.jsxs)(`button`,{onClick:()=>ce(`email`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${se===`email`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(Gc,{className:`w-4 h-4`}),i(`settings.tabs.emailAuth`)||`Email Authentication`,sn?.advanced_auth_enabled&&(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,K.jsxs)(`button`,{onClick:()=>ce(`ldap`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${se===`ldap`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(Hl,{className:`w-4 h-4`}),i(`settings.tabs.ldap`)||`LDAP`,cn?.ldap_enabled&&(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,K.jsxs)(`button`,{onClick:()=>ce(`twofa`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${se===`twofa`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(Hl,{className:`w-4 h-4`}),i(`settings.tabs.twoFa`),(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${ln?.totp_enabled||ln?.email_otp_enabled?`bg-green-400`:`bg-bambu-gray/40`}`})]}),l&&(0,K.jsxs)(`button`,{onClick:()=>ce(`oidc`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${se===`oidc`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(hc,{className:`w-4 h-4`}),i(`settings.tabs.oidc`),(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${un.some(e=>e.is_enabled)?`bg-green-400`:`bg-bambu-gray/40`}`})]}),l&&(0,K.jsxs)(`button`,{onClick:()=>ce(`security`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${se===`security`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(Hl,{className:`w-4 h-4`}),i(`settings.tabs.security`)]})]}),se===`users`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${s?`bg-green-500/20`:`bg-gray-500/20`}`,children:s?(0,K.jsx)(Hc,{className:`w-5 h-5 text-green-400`}):(0,K.jsx)(Vc,{className:`w-5 h-5 text-gray-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-white font-medium`,children:i(`settings.authentication`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(s?`settings.authEnabledDescription`:`settings.authDisabledDescription`)})]})]}),s?c?.is_admin&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>Ne(!0),children:[(0,K.jsx)(Vc,{className:`w-4 h-4`}),i(`common.disable`)]}):(0,K.jsxs)($,{onClick:()=>t(`/setup`),children:[(0,K.jsx)(Hc,{className:`w-4 h-4`}),i(`common.enable`)]})]})})}),sn?.advanced_auth_enabled&&(0,K.jsx)(pd,{className:`border-blue-500/30 bg-blue-500/5`,children:(0,K.jsx)(hd,{className:`py-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0`,children:(0,K.jsx)(Gc,{className:`w-5 h-5 text-blue-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-white font-medium`,children:i(`settings.email.advancedAuthEnabled`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.email.advancedAuthEnabledDesc`)})]})]})})}),s&&(0,K.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-6`,children:[(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(pd,{id:`card-session-policy`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Hc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.sessionPolicy.title`)]})}),(0,K.jsxs)(hd,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:i(`settings.sessionPolicy.description`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2 mb-4`,children:[[{hours:24,labelKey:`settings.sessionPolicy.preset24h`},{hours:168,labelKey:`settings.sessionPolicy.preset7d`},{hours:720,labelKey:`settings.sessionPolicy.preset30d`}].map(e=>{let t=(O?.session_max_hours??24)===e.hours;return(0,K.jsx)(`button`,{type:`button`,onClick:()=>In(`session_max_hours`,e.hours),disabled:s&&!d(`settings:update`),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors ${t?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark`} disabled:opacity-50 disabled:cursor-not-allowed`,children:i(e.labelKey)},e.hours)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`input`,{type:`number`,min:1,max:720,value:O?.session_max_hours??24,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||In(`session_max_hours`,Math.max(1,Math.min(720,t)))},disabled:s&&!d(`settings:update`),"aria-label":i(`settings.sessionPolicy.customHoursLabel`),className:`w-20 px-2 py-2 bg-bambu-dark-tertiary text-white text-sm rounded-lg border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:i(`settings.sessionPolicy.hoursSuffix`)})]})]}),(O?.session_max_hours??24)>24&&(0,K.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-yellow-400 flex-shrink-0 mt-0.5`}),(0,K.jsx)(`p`,{className:`text-xs text-yellow-200`,children:i(`settings.sessionPolicy.warning`)})]})]})]}),c&&(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-currentuser`,children:[(0,K.jsx)(wu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.currentUser`)]}),c.auth_source!==`ldap`&&(0,K.jsxs)($,{size:`sm`,variant:`ghost`,onClick:()=>Fe(!0),children:[(0,K.jsx)(jc,{className:`w-4 h-4`}),i(`settings.changePassword`)]})]})}),(0,K.jsx)(hd,{children:(0,K.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium text-lg`,children:c.username}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-2`,children:[c.is_admin&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300`,children:i(`settings.admin`)}),c.groups?.map(e=>(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium ${e.name===`Administrators`?`bg-purple-500/20 text-purple-300`:e.name===`Operators`?`bg-blue-500/20 text-blue-300`:e.name===`Viewers`?`bg-green-500/20 text-green-300`:`bg-gray-500/20 text-gray-300`}`,children:e.name},e.id))]})]})})})]}),(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-users`,children:[(0,K.jsx)(wu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.users`)]}),d(`users:create`)&&(0,K.jsxs)($,{size:`sm`,onClick:()=>{Ue(!0),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.addUser`)]})]})}),(0,K.jsx)(hd,{children:fn?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})}):dn.length===0?(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-8`,children:i(`settings.noUsersFound`)}):(0,K.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:dn.map(e=>(0,K.jsxs)(`div`,{className:`py-3 flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.username}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:[e.auth_source===`ldap`&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-cyan-500/20 text-cyan-300`,children:`LDAP`}),e.is_admin&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300`,children:i(`settings.admin`)}),e.groups?.map(e=>(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium ${e.name===`Administrators`?`bg-purple-500/20 text-purple-300`:e.name===`Operators`?`bg-blue-500/20 text-blue-300`:e.name===`Viewers`?`bg-green-500/20 text-green-300`:`bg-gray-500/20 text-gray-300`}`,children:e.name},e.id))]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 ml-4`,children:[d(`users:update`)&&(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>Cn(e),children:(0,K.jsx)(fl,{className:`w-4 h-4`})}),d(`users:delete`)&&e.id!==c?.id&&(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>yn(e.id),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]},e.id))})})]})]}),(0,K.jsx)(`div`,{children:(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-groups`,children:[(0,K.jsx)(Hl,{className:`w-5 h-5 text-bambu-green`}),i(`settings.groups`)]}),d(`groups:create`)&&(0,K.jsxs)($,{size:`sm`,onClick:()=>t(`/groups/new`),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.addGroup`)]})]})}),(0,K.jsx)(hd,{children:mn?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})}):pn.length===0?(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-8`,children:i(`settings.noGroupsFound`)}):(0,K.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:pn.map(e=>(0,K.jsxs)(`div`,{className:`py-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Hl,{className:`w-4 h-4 ${e.name===`Administrators`?`text-purple-400`:e.name===`Operators`?`text-blue-400`:e.name===`Viewers`?`text-green-400`:`text-bambu-gray`}`}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:e.name}),e.is_system&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400`,children:i(`settings.system`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[d(`groups:update`)&&(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>t(`/groups/${e.id}/edit`),children:(0,K.jsx)(fl,{className:`w-4 h-4`})}),d(`groups:delete`)&&!e.is_system&&(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>at(e.id),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1 ml-6`,children:e.description||i(`settings.noDescription`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:i(`settings.userCount`,{count:e.user_count})}),(0,K.jsx)(`span`,{children:i(`settings.permissionCount`,{count:e.permissions.length})})]})]},e.id))})})]})})]}),!s&&(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-6`,children:(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(Vc,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,K.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.authDisabledTitle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 max-w-md mx-auto`,children:i(`settings.authDisabledMessage`)}),(0,K.jsxs)(`ul`,{className:`space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto`,children:[(0,K.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(ls,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,K.jsx)(`span`,{children:i(`settings.authDisabledFeature1`)})]}),(0,K.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(ls,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,K.jsx)(`span`,{children:i(`settings.authDisabledFeature2`)})]}),(0,K.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(ls,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,K.jsx)(`span`,{children:i(`settings.authDisabledFeature3`)})]})]}),(0,K.jsxs)($,{onClick:()=>t(`/setup`),children:[(0,K.jsx)(Hc,{className:`w-4 h-4`}),i(`settings.enableAuthentication`)]})]})})})]}),se===`email`&&(0,K.jsx)(`div`,{className:`max-w-5xl`,id:`card-smtp`,children:(0,K.jsx)(xze,{})}),se===`ldap`&&(0,K.jsx)(`div`,{className:`max-w-5xl`,id:`card-ldap`,children:(0,K.jsx)(Cze,{})}),se===`twofa`&&(0,K.jsx)(`div`,{className:`max-w-2xl`,children:(0,K.jsx)(Tze,{})}),se===`oidc`&&l&&(0,K.jsx)(`div`,{className:`max-w-3xl`,children:(0,K.jsx)(Oze,{})}),se===`security`&&l&&(0,K.jsx)(`div`,{className:`max-w-3xl`,children:(0,K.jsx)(Aze,{})})]}),He&&!sn?.advanced_auth_enabled&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black flex items-center justify-center z-50 p-4`,onClick:()=>{Ue(!1),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,K.jsxs)(pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(wu,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.createUser`)})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{Ue(!1),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]})}),(0,K.jsxs)(hd,{children:[cn?.ldap_enabled&&(0,K.jsxs)(`div`,{className:`mb-4 flex items-center gap-1 p-1 bg-bambu-dark-secondary rounded-lg`,role:`tablist`,"aria-label":i(`users.modal.tabsAriaLabel`),children:[(0,K.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":We===`local`,onClick:()=>Ge(`local`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${We===`local`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:i(`users.modal.localTab`)}),(0,K.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":We===`ldap`,onClick:()=>Ge(`ldap`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${We===`ldap`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:i(`users.modal.ldapTab`)})]}),We===`ldap`&&cn?.ldap_enabled?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(z5,{onSuccess:e=>{Ue(!1),Ge(`local`),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`users.toast.ldapProvisioned`,{username:e.username}))}}),(0,K.jsx)(`div`,{className:`mt-6 flex justify-end`,children:(0,K.jsx)($,{variant:`secondary`,onClick:()=>{Ue(!1),Ge(`local`),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`common.cancel`)})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.username`)}),(0,K.jsx)(`input`,{type:`text`,value:nt.username,onChange:e=>rt({...nt,username:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterUsername`),autoComplete:`username`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.password`)}),(0,K.jsx)(`input`,{type:`password`,value:nt.password,onChange:e=>rt({...nt,password:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterPassword`),autoComplete:`new-password`,minLength:8}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:i(`settings.passwordRequirements`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.confirmPassword`)}),(0,K.jsx)(`input`,{type:`password`,value:nt.confirmPassword,onChange:e=>rt({...nt,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${nt.confirmPassword&&nt.password!==nt.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmPasswordPlaceholder`),autoComplete:`new-password`,minLength:6}),nt.confirmPassword&&nt.password!==nt.confirmPassword&&(0,K.jsx)(`p`,{className:`text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.groups`)}),(0,K.jsxs)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[pn.map(e=>(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:nt.group_ids.includes(e.id),onChange:()=>wn(e.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:e.name}),e.is_system&&(0,K.jsx)(`span`,{className:`text-xs text-yellow-400`,children:i(`settings.systemBadge`)})]},e.id)),pn.length===0&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.noGroupsAvailable`)})]})]})]}),(0,K.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>{Ue(!1),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`common.cancel`)}),(0,K.jsx)($,{onClick:xn,disabled:hn.isPending||!nt.username||!nt.password||nt.password!==nt.confirmPassword||m5(nt.password)!==null,children:hn.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),i(`settings.creating`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.createUser`)]})})]})]})]})]})}),He&&sn?.advanced_auth_enabled&&(0,K.jsx)(GRe,{formData:nt,setFormData:rt,groups:pn,onClose:()=>{Ue(!1),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},onCreate:xn,isCreating:hn.isPending,isCreateButtonDisabled:hn.isPending||!nt.username||!nt.email,ldapEnabled:cn?.ldap_enabled,onLdapProvisioned:e=>{Ue(!1),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`users.toast.ldapProvisioned`,{username:e.username}))}}),Ke&&Je!==null&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black flex items-center justify-center z-50 p-4`,onClick:()=>{qe(!1),Ye(null),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,K.jsxs)(pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(fl,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.editUser`)})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{qe(!1),Ye(null),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]})}),(0,K.jsxs)(hd,{children:[(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`settings.username`),` `,sn?.advanced_auth_enabled&&(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsx)(`input`,{type:`text`,value:nt.username,onChange:e=>rt({...nt,username:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterUsername`),autoComplete:`username`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`users.form.email`)||`Email`,` `,sn?.advanced_auth_enabled?(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`}):(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,i(`users.form.optional`)||`optional`,`)`]})]}),(0,K.jsx)(`input`,{type:`email`,value:nt.email,onChange:e=>rt({...nt,email:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`users.form.emailPlaceholder`)||`user@example.com`,required:sn?.advanced_auth_enabled})]}),!sn?.advanced_auth_enabled&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`users.form.password`)||`Password`,` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,i(`users.form.leaveBlankToKeep`)||`leave blank to keep current`,`)`]})]}),(0,K.jsx)(`input`,{type:`password`,value:nt.password,onChange:e=>rt({...nt,password:e.target.value,confirmPassword:``}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterNewPassword`),autoComplete:`new-password`,minLength:8}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:i(`settings.passwordRequirements`)})]}),nt.password&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.confirmPassword`)}),(0,K.jsx)(`input`,{type:`password`,value:nt.confirmPassword,onChange:e=>rt({...nt,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${nt.confirmPassword&&nt.password!==nt.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmNewPassword`),autoComplete:`new-password`,minLength:6}),nt.confirmPassword&&nt.password!==nt.confirmPassword&&(0,K.jsx)(`p`,{className:`text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]})]}),sn?.advanced_auth_enabled&&(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`users.form.passwordManagedByAdvancedAuth`)||`Password is managed by Advanced Authentication. Use "Reset Password" to send a new password to the user via email.`}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>Je&&vn.mutate(Je),disabled:vn.isPending||!nt.email,className:`w-full`,children:vn.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),i(`users.form.resettingPassword`)||`Resetting Password...`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),i(`users.form.resetPassword`)||`Reset Password`]})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`users.form.groups`)||`Groups`}),(0,K.jsx)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:pn.map(e=>(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:nt.group_ids.includes(e.id),onChange:()=>wn(e.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:e.name}),e.is_system&&(0,K.jsxs)(`span`,{className:`text-xs text-yellow-400`,children:[`(`,i(`users.system`)||`System`,`)`]})]},e.id))})]})]}),(0,K.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>{qe(!1),Ye(null),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`users.modal.cancel`)||`Cancel`}),(0,K.jsx)($,{onClick:()=>Sn(Je),disabled:gn.isPending||!nt.username||sn?.advanced_auth_enabled&&!nt.email||!!(!sn?.advanced_auth_enabled&&nt.password&&(nt.password!==nt.confirmPassword||m5(nt.password)!==null)),children:gn.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),i(`users.modal.saving`)||`Saving...`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),i(`users.modal.saveChanges`)||`Save Changes`]})})]})]})]})}),Xe!==null&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,onClick:()=>{Ze(null),$e(null)},children:(0,K.jsxs)(pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-red-400`,children:[(0,K.jsx)(hu,{className:`w-5 h-5`}),(0,K.jsx)(`h3`,{className:`text-lg font-semibold`,children:i(`settings.deleteUserTitle`)})]})}),(0,K.jsx)(hd,{className:`space-y-3`,children:et?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,K.jsx)(`div`,{className:`animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent`})}):Qe&&Qe.archives+Qe.queue_items+Qe.library_files>0?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.userHasCreated`)}),(0,K.jsxs)(`ul`,{className:`list-disc list-inside text-bambu-gray space-y-1`,children:[Qe.archives>0&&(0,K.jsxs)(`li`,{children:[Qe.archives,` archive`,Qe.archives===1?``:`s`]}),Qe.queue_items>0&&(0,K.jsxs)(`li`,{children:[Qe.queue_items,` queue item`,Qe.queue_items===1?``:`s`]}),Qe.library_files>0&&(0,K.jsxs)(`li`,{children:[Qe.library_files,` library file`,Qe.library_files===1?``:`s`]})]}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:i(`settings.userItemsQuestion`)}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)($,{variant:`danger`,onClick:()=>_n.mutate({id:Xe,deleteItems:!0}),disabled:_n.isPending,className:`justify-center`,children:i(`settings.deleteUserAndItems`)}),(0,K.jsx)($,{variant:`secondary`,onClick:()=>_n.mutate({id:Xe,deleteItems:!1}),disabled:_n.isPending,className:`justify-center`,children:i(`settings.deleteUserKeepItems`)}),(0,K.jsx)($,{variant:`ghost`,onClick:()=>{Ze(null),$e(null)},disabled:_n.isPending,className:`justify-center`,children:i(`common.cancel`)})]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.deleteUserConfirm`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:i(`settings.actionCannotBeUndone`)}),(0,K.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,K.jsx)($,{variant:`ghost`,onClick:()=>{Ze(null),$e(null)},disabled:_n.isPending,children:i(`common.cancel`)}),(0,K.jsx)($,{variant:`danger`,onClick:()=>_n.mutate({id:Xe,deleteItems:!1}),disabled:_n.isPending,children:i(`settings.deleteUserTitle`)})]})]})})]})}),it!==null&&(0,K.jsx)(Ed,{title:i(`settings.deleteGroupTitle`),message:i(`settings.deleteGroupMessage`),confirmText:i(`settings.deleteGroup`),variant:`danger`,onConfirm:()=>{bn.mutate(it),at(null)},onCancel:()=>at(null)}),W===`failure-detection`&&(0,K.jsx)(`div`,{id:`card-failure-detection`,children:(0,K.jsx)(vze,{})}),W===`backup`&&(0,K.jsxs)(`div`,{id:`card-backup`,children:[(0,K.jsxs)(`div`,{className:`mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg flex items-start gap-2`,children:[(0,K.jsx)(Hl,{className:`text-amber-400 flex-shrink-0 mt-0.5`,size:16}),(0,K.jsx)(`p`,{className:`text-sm text-amber-400`,children:i(`backup.includesEncryptionKey`)})]}),(0,K.jsx)(_ze,{})]}),Me&&(0,K.jsx)(Ed,{title:i(`settings.disableAuthenticationTitle`),message:i(`settings.disableAuthenticationMessage`),confirmText:i(`settings.disableAuthentication`),variant:`danger`,onConfirm:async()=>{try{await Q.disableAuth(),o(i(`settings.toast.authDisabled`),`success`),await u(),Ne(!1),window.location.href=`/`}catch(e){o(e instanceof Error?e.message:i(`settings.toast.authDisableFailed`),`error`)}},onCancel:()=>Ne(!1)}),Pe&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>{Fe(!1),Le({currentPassword:``,newPassword:``,confirmPassword:``})},children:(0,K.jsxs)(pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(jc,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.changePassword`)})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{Fe(!1),Le({currentPassword:``,newPassword:``,confirmPassword:``})},children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]})}),(0,K.jsxs)(hd,{children:[(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`Current Password`}),(0,K.jsx)(`input`,{type:`password`,value:Ie.currentPassword,onChange:e=>Le({...Ie,currentPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterCurrentPassword`),autoComplete:`current-password`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`New Password`}),(0,K.jsx)(`input`,{type:`password`,value:Ie.newPassword,onChange:e=>Le({...Ie,newPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterNewPasswordMin6`),autoComplete:`new-password`,minLength:6})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`Confirm New Password`}),(0,K.jsx)(`input`,{type:`password`,value:Ie.confirmPassword,onChange:e=>Le({...Ie,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${Ie.confirmPassword&&Ie.newPassword!==Ie.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmNewPassword`),autoComplete:`new-password`,minLength:6}),Ie.confirmPassword&&Ie.newPassword!==Ie.confirmPassword&&(0,K.jsx)(`p`,{className:`text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]})]}),(0,K.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>{Fe(!1),Le({currentPassword:``,newPassword:``,confirmPassword:``})},children:i(`common.cancel`)}),(0,K.jsx)($,{onClick:async()=>{if(Ie.newPassword!==Ie.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}if(Ie.newPassword.length<6){o(i(`settings.toast.passwordTooShort`),`error`);return}ze(!0);try{await Q.changePassword(Ie.currentPassword,Ie.newPassword),o(i(`settings.toast.passwordChanged`),`success`),Fe(!1),Le({currentPassword:``,newPassword:``,confirmPassword:``})}catch(e){o(e instanceof Error?e.message:`Failed to change password`,`error`)}finally{ze(!1)}},disabled:Re||!Ie.currentPassword||!Ie.newPassword||Ie.newPassword!==Ie.confirmPassword||Ie.newPassword.length<6,children:Re?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),i(`settings.changing`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(jc,{className:`w-4 h-4`}),i(`settings.changePassword`)]})})]})]})]})})]})]})]})})}var u7=e=>(Math.trunc(parseFloat(e)*1e3)/1e3).toFixed(3),Rze=e=>e.startsWith(`HH`)?`HF`:`S`,zze=e=>{let t=e.match(/^([A-Z]{2}\d{2})/);return t?t[1]:`HH00`},d7=e=>{for(let t of[`High Flow_`,`High Flow `,`Standard_`,`Standard `,`HF_`,`HF `,`S_`,`S `])if(e.startsWith(t))return e.slice(t.length);let t=e.indexOf(`_`);return t>0?e.slice(t+1):e};function f7({profile:e,onEdit:t,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:a,note:o}){let s=Rze(e.nozzle_id),c=e.nozzle_diameter;return(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,K.jsx)(`button`,{onClick:a,className:`text-bambu-gray hover:text-white transition-colors p-1`,children:i?(0,K.jsx)($l,{className:`w-4 h-4 text-bambu-green`}):(0,K.jsx)(tu,{className:`w-4 h-4`})}),(0,K.jsxs)(`button`,{onClick:()=>{r&&a?a():t()},className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?`ring-1 ring-bambu-green`:``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-green font-mono text-sm font-bold whitespace-nowrap`,children:u7(e.k_value)}),(0,K.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name||`Unnamed`}),o&&(0,K.jsx)(`span`,{title:`Has note`,children:(0,K.jsx)(iu,{className:`w-3 h-3 text-yellow-500`})}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:[s,` `,c]})]}),o&&(0,K.jsxs)(`div`,{className:`text-xs mt-0.5 truncate text-yellow-500/70`,title:o,children:[`Note: `,o.length>50?o.substring(0,50)+`...`:o]})]}),!r&&n&&(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`text-bambu-gray hover:text-white transition-colors p-1`,title:`Copy profile`,children:(0,K.jsx)(Ds,{className:`w-4 h-4`})})]})}function p7({profile:e,printerId:t,nozzleDiameter:n,existingProfiles:r=[],builtinFilaments:i=[],isDualNozzle:a=!1,initialNote:o=``,initialNoteKey:s=null,onClose:c,onSave:l,onSaveNote:u,hasPermission:d}){let{t:f}=G(),{showToast:p}=xd(),[m,h]=(0,y.useState)(e?.name||``),[g,_]=(0,y.useState)(e?.k_value?u7(e.k_value):`0.020`),[v,b]=(0,y.useState)(e?.filament_id||``),[x,S]=(0,y.useState)(e?.nozzle_id?zze(e.nozzle_id):`HH00`),[C,w]=(0,y.useState)(e?.nozzle_diameter||n),[T,E]=(0,y.useState)(e?[e.extruder_id]:a?[0,1]:[0]),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)({current:0,total:0}),[j,M]=(0,y.useState)(o),N=y.useMemo(()=>{let e=new Map;for(let t of i)e.set(t.filament_id,t.name);let t=new Map;for(let n of r)if(n.filament_id&&!t.has(n.filament_id)){let r=e.get(n.filament_id)||d7(n.name||``);t.set(n.filament_id,{id:n.filament_id,name:r||n.filament_id})}return Array.from(t.values()).sort((e,t)=>e.name.localeCompare(t.name))},[r,i]),P=J({mutationFn:e=>(console.log(`[KProfile] Calling API...`),Q.setKProfile(t,e)),onSuccess:t=>{if(console.log(`[KProfile] Save success:`,t),p(f(`kProfiles.toast.profileSaved`)),u&&j!==o){let t;t=j===``&&s?s:e&&e.slot_id>0?e.setting_id||`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`:`name_${m}_${v}`,u(t,j)}O(!0),setTimeout(()=>{O(!1),l()},2500)},onError:e=>{console.error(`[KProfile] Save error:`,e),p(e.message,`error`),O(!1)}}),F=J({mutationFn:e=>(console.log(`[KProfile] Deleting profile...`),Q.deleteKProfile(t,e)),onSuccess:e=>{console.log(`[KProfile] Delete success:`,e),p(f(`kProfiles.toast.profileDeleted`)),O(!0),setTimeout(()=>{O(!1),c()},4e3)},onError:e=>{console.error(`[KProfile] Delete error:`,e),p(e.message,`error`),O(!1)}}),[I,L]=(0,y.useState)(!1),R=()=>{e&&F.mutate({slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id})};return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:[(0,K.jsxs)(pd,{className:`w-full max-w-md relative`,children:[D&&(0,K.jsxs)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg`,children:[(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin mb-3`}),(0,K.jsx)(`p`,{className:`text-white font-medium`,children:k.total>1?f(`kProfiles.modal.savingExtruder`,{current:k.current,total:k.total}):f(`kProfiles.modal.syncing`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm mt-1`,children:f(`kProfiles.modal.pleaseWait`)})]}),(0,K.jsxs)(hd,{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.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:f(e?`kProfiles.modal.editTitle`:`kProfiles.modal.addTitle`)}),(0,K.jsx)(`button`,{onClick:c,className:`text-bambu-gray hover:text-white transition-colors`,disabled:D,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),a&&!e&&T.length===0){p(f(`kProfiles.toast.selectAtLeastOneExtruder`),`error`);return}let r=parseFloat(g).toFixed(6),i=`${x}-${C}`;if(e||T.length===1){let t={name:m,k_value:r,filament_id:v,nozzle_id:i,nozzle_diameter:C,extruder_id:e?e.extruder_id:T[0],setting_id:e?.setting_id,slot_id:e?.slot_id??0};console.log(`[KProfile] Saving profile:`,t),P.mutate(t);return}O(!0),A({current:1,total:T.length});let o=T.map(e=>({name:m,k_value:r,filament_id:v,nozzle_id:i,nozzle_diameter:C,extruder_id:e,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${o.length} profiles in batch:`,o);try{await Q.setKProfilesBatch(t,o),p(f(`kProfiles.toast.profilesSaved`,{count:T.length})),u&&j&&u(`name_${m}_${v}`,j)}catch(e){console.error(`[KProfile] Failed to save batch:`,e),p(f(`kProfiles.toast.failedToSaveBatch`),`error`),O(!1),A({current:0,total:0});return}A({current:T.length,total:T.length}),setTimeout(()=>{O(!1),A({current:0,total:0}),l()},3e3)},className:`p-4 space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(`kProfiles.modal.profileName`)}),(0,K.jsx)(`input`,{type:`text`,value:m,onChange:e=>h(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,placeholder:f(`kProfiles.modal.profileNamePlaceholder`),required:!e})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(`kProfiles.modal.kValue`)}),(0,K.jsx)(`input`,{type:`text`,inputMode:`decimal`,value:g,onChange:e=>{let t=e.target.value;(t===``||/^\d*\.?\d*$/.test(t))&&_(t)},onBlur:e=>{let t=parseFloat(e.target.value);isNaN(t)||_((Math.trunc(t*1e3)/1e3).toFixed(3))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono`,placeholder:f(`kProfiles.modal.kValuePlaceholder`),required:!0}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:f(`kProfiles.modal.kValueHelp`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(`kProfiles.modal.filament`)}),(0,K.jsxs)(`select`,{value:v,onChange:t=>{let n=t.target.value;if(b(n),!e&&n&&!m){let e=N.find(e=>e.id===n);e&&h(`${x===`HH00`?`HF`:`S`} ${e.name}`)}},disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,required:!e,children:[(0,K.jsx)(`option`,{value:``,children:f(`kProfiles.modal.selectFilament`)}),e?.filament_id&&(0,K.jsx)(`option`,{value:e.filament_id,children:N.find(t=>t.id===e.filament_id)?.name||e.filament_id},e.filament_id),!e&&N.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),!e&&N.length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:f(`kProfiles.modal.noFilamentsHelp`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(`kProfiles.modal.flowType`)}),(0,K.jsxs)(`select`,{value:x,onChange:t=>{let n=t.target.value;if(S(n),!e&&v&&!m){let e=N.find(e=>e.id===v);e&&h(`${n===`HS00`?`HF`:`S`} ${e.name}`)}},disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,K.jsx)(`option`,{value:`HH00`,children:f(`kProfiles.modal.highFlow`)}),(0,K.jsx)(`option`,{value:`HS00`,children:f(`kProfiles.modal.standard`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(`kProfiles.modal.nozzleSize`)}),(0,K.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,K.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,K.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,K.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,K.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]})]}),a&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(e?`kProfiles.modal.extruder`:`kProfiles.modal.extruders`)}),e?(0,K.jsx)(`div`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:e.extruder_id===1?f(`kProfiles.modal.left`):f(`kProfiles.modal.right`)}):(0,K.jsxs)(`div`,{className:`flex gap-4`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:T.includes(1),onChange:e=>{e.target.checked?E([...T,1]):E(T.filter(e=>e!==1))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,K.jsx)(`span`,{className:`text-white`,children:f(`kProfiles.modal.left`)})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:T.includes(0),onChange:e=>{e.target.checked?E([...T,0]):E(T.filter(e=>e!==0))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,K.jsx)(`span`,{className:`text-white`,children:f(`kProfiles.modal.right`)})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(`kProfiles.modal.notes`)}),(0,K.jsx)(`textarea`,{value:j,onChange:e=>M(e.target.value),placeholder:f(`kProfiles.modal.notesPlaceholder`),rows:2,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:f(`kProfiles.modal.notesHelp`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 pt-4`,children:[e&&(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:()=>L(!0),disabled:F.isPending||D||!d(`kprofiles:delete`),title:d(`kprofiles:delete`)?void 0:f(`kProfiles.permission.noDelete`),className:`text-red-500 hover:bg-red-500/10`,children:F.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hu,{className:`w-4 h-4`})}),(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:c,disabled:D,className:`flex-1`,children:f(`common.cancel`)}),(0,K.jsxs)($,{type:`submit`,disabled:P.isPending||D||!d(e?`kprofiles:update`:`kprofiles:create`),title:d(e?`kprofiles:update`:`kprofiles:create`)?void 0:f(e?`kProfiles.permission.noUpdate`:`kProfiles.permission.noCreate`),className:`flex-1`,children:[P.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(uc,{className:`w-4 h-4`}),f(`common.save`)]})]})]})]})]}),I&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-[60]`,children:(0,K.jsx)(pd,{className:`w-full max-w-sm`,children:(0,K.jsxs)(hd,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,K.jsx)(hu,{className:`w-5 h-5 text-red-500`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:f(`kProfiles.deleteConfirm.title`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:f(`kProfiles.deleteConfirm.cannotUndo`)})]})]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:f(`kProfiles.deleteConfirm.message`,{name:e?.name})}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>L(!1),className:`flex-1`,children:f(`common.cancel`)}),(0,K.jsxs)($,{onClick:()=>{L(!1),R()},disabled:F.isPending,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[F.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hu,{className:`w-4 h-4`}),f(`common.delete`)]})]})]})})})]})}var m7={NOZZLE_DIAMETER:`bambusy_kprofiles_nozzle`,SORT_OPTION:`bambusy_kprofiles_sort`};function Bze(){let{t:e}=G(),{showToast:t}=xd(),{hasPermission:n}=sd(),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(()=>localStorage.getItem(m7.NOZZLE_DIAMETER)||`0.4`),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(`all`),[b,x]=(0,y.useState)(()=>localStorage.getItem(m7.SORT_OPTION)||`name`),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(new Set),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),A=(0,y.useCallback)(e=>`${e.slot_id}_${e.extruder_id}`,[]);(0,y.useEffect)(()=>{localStorage.setItem(m7.NOZZLE_DIAMETER,a)},[a]),(0,y.useEffect)(()=>{localStorage.setItem(m7.SORT_OPTION,b)},[b]);let{data:j,isLoading:M}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:N,isLoading:P,isFetching:F,error:I,refetch:L}=q({queryKey:[`kprofiles`,r,a],queryFn:async()=>{console.log(`[KProfiles] Fetching profiles for printer`,r,`nozzle`,a);let e=await Q.getKProfiles(r,a);return console.log(`[KProfiles] Received profiles:`,e?.profiles?.length||0,`profiles`),e},enabled:!!r,retry:!1,staleTime:0,gcTime:0,refetchOnMount:`always`}),{data:R}=q({queryKey:[`kprofiles`,r,`0.4`],queryFn:()=>Q.getKProfiles(r,`0.4`),enabled:!!r,staleTime:6e4}),{data:z}=q({queryKey:[`builtinFilaments`],queryFn:()=>Q.getBuiltinFilaments(),staleTime:3e5}),{data:B}=q({queryKey:[`filamentIdMap`],queryFn:()=>Q.getFilamentIdMap(),staleTime:3e5}),{data:V,refetch:ee}=q({queryKey:[`kprofile-notes`,r],queryFn:()=>Q.getKProfileNotes(r),enabled:!!r,staleTime:3e4}),H=I?.message?.includes(`not connected`);(0,y.useEffect)(()=>{if(!r&&j&&j.length>0){let e=j.find(e=>e.is_active);e&&i(e.id)}},[r,j]),(0,y.useEffect)(()=>{if(r){let e=setTimeout(()=>{L()},150);return()=>clearTimeout(e)}},[r,a]);let te=j?.filter(e=>e.is_active)||[],ne=y.useMemo(()=>{let e=new Map;if(z)for(let t of z)e.set(t.filament_id,t.name);if(B)for(let[t,n]of Object.entries(B))e.has(t)||e.set(t,n);return e},[z,B]),re=y.useMemo(()=>Array.from(ne.entries()).map(([e,t])=>({filament_id:e,name:t})),[ne]),U=y.useCallback(e=>ne.get(e.filament_id)||d7(e.name),[ne]),ie=y.useMemo(()=>N?.profiles?N.profiles.filter(e=>{let t=p.toLowerCase(),n=!t||e.name.toLowerCase().includes(t)||e.filament_id.toLowerCase().includes(t),r=h===`all`||h===`left`&&e.extruder_id===1||h===`right`&&e.extruder_id===0,i=_===`all`||_===`hf`&&e.nozzle_id.startsWith(`HH`)||_===`s`&&e.nozzle_id.startsWith(`HS`);return n&&r&&i}).sort((e,t)=>{switch(b){case`k_value`:return parseFloat(e.k_value)-parseFloat(t.k_value);case`filament`:return U(e).localeCompare(U(t));default:return e.name.localeCompare(t.name)}}):[],[N?.profiles,p,h,_,b,U]),ae=j?.find(e=>e.id===r),W=ae?.nozzle_count===2;(0,y.useEffect)(()=>{let e=e=>{e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||s||l||d||(e.key===`r`||e.key===`R`?(e.preventDefault(),L()):e.key===`n`||e.key===`N`?(e.preventDefault(),u(!0)):e.key===`Escape`&&S&&(e.preventDefault(),C(!1),T(new Set)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[s,l,d,S,L]);let oe=(0,y.useCallback)(()=>{if(!N?.profiles||N.profiles.length===0){t(e(`kProfiles.toast.noProfilesToExport`),`error`);return}let n={version:1,exported_at:new Date().toISOString(),printer:ae?.name||`Unknown`,nozzle_diameter:a,profiles:N.profiles.map(e=>({name:e.name,k_value:e.k_value,filament_id:e.filament_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,extruder_id:e.extruder_id}))},r=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),i=URL.createObjectURL(r),o=document.createElement(`a`);o.href=i,o.download=`kprofiles_${ae?.name||`printer`}_${a}mm_${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(i),t(e(`kProfiles.toast.exportedProfiles`,{count:N.profiles.length}))},[N?.profiles,ae,a,t,e]),se=(0,y.useCallback)(()=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async n=>{let i=n.target.files?.[0];if(i)try{let n=await i.text(),o=JSON.parse(n);if(!o.profiles||!Array.isArray(o.profiles)){t(e(`kProfiles.toast.invalidFileFormat`),`error`);return}let s=0;for(let e of o.profiles)if(!(!e.name||!e.k_value||!e.filament_id))try{await Q.setKProfile(r,{name:e.name,k_value:parseFloat(e.k_value).toFixed(6),filament_id:e.filament_id,nozzle_id:e.nozzle_id||`HH00-${a}`,nozzle_diameter:e.nozzle_diameter||a,extruder_id:e.extruder_id??0,slot_id:0}),s++,await new Promise(e=>setTimeout(e,500))}catch(t){console.error(`Failed to import profile:`,e.name,t)}t(e(`kProfiles.toast.importedProfiles`,{count:s,total:o.profiles.length})),L()}catch(n){console.error(`Import error:`,n),t(e(`kProfiles.toast.failedToParseImport`),`error`)}},n.click()},[r,a,t,L,e]),ce=(0,y.useCallback)(e=>{T(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),le=(0,y.useCallback)(()=>{T(new Set(ie.map(e=>A(e))))},[ie,A]),ue=(0,y.useCallback)(()=>{w.size!==0&&D(!0)},[w.size]),de=(0,y.useCallback)(async()=>{let n=ie.filter(e=>w.has(A(e)));k(!0);let i=0;for(let e of n)try{await Q.deleteKProfile(r,{slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id}),i++,await new Promise(e=>setTimeout(e,300))}catch(t){console.error(`Failed to delete profile:`,e.name,t)}t(e(`kProfiles.toast.profilesDeleted`,{count:i})),k(!1),D(!1),C(!1),T(new Set),L()},[r,w,ie,t,L,A,e]),fe=(0,y.useCallback)(e=>{let t=[];return e.setting_id&&t.push(e.setting_id),t.push(`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`),t.push(`name_${e.name}_${e.filament_id}`),t},[]),pe=(0,y.useCallback)(async(n,i)=>{if(r)try{await Q.setKProfileNote(r,n,i),ee()}catch(n){console.error(`Failed to save note:`,n),t(e(`kProfiles.toast.failedToSaveNote`),`error`)}},[r,ee,t,e]),me=(0,y.useCallback)(e=>{if(!V?.notes)return{note:``,key:null};let t=fe(e);for(let e of t)if(V.notes[e])return{note:V.notes[e],key:e};return{note:``,key:null}},[V,fe]),he=(0,y.useCallback)(e=>me(e).note,[me]);return M?(0,K.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):!j||j.length===0?(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`py-12 text-center`,children:[(0,K.jsx)(ss,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noPrintersConfigured`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.addPrinterInSettings`)})]})}):te.length===0?(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`py-12 text-center`,children:[(0,K.jsx)(bl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noActivePrinters`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.enablePrinterConnection`)})]})}):(0,K.jsxs)(K.Fragment,{children:[F&&!P&&(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40`,children:[(0,K.jsx)(X,{className:`w-10 h-10 text-bambu-green animate-spin mb-3`}),(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`kProfiles.loadingProfiles`)})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-6`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-48`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.printer`)}),(0,K.jsx)(`select`,{value:r||``,onChange:e=>i(parseInt(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:te.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,K.jsxs)(`div`,{className:`w-32`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.nozzle`)}),(0,K.jsxs)(`select`,{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`,children:[(0,K.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,K.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,K.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,K.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:()=>L(),disabled:F||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noRead`),children:[(0,K.jsx)(Cl,{className:`w-4 h-4 ${F?`animate-spin`:``}`}),e(`kProfiles.refresh`)]}),(0,K.jsxs)($,{onClick:()=>u(!0),disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noCreate`),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),e(`kProfiles.addProfile`)]})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-48 relative`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:e(`kProfiles.searchPlaceholder`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),W&&(0,K.jsx)(`div`,{className:`w-36`,children:(0,K.jsxs)(`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:`all`,children:e(`kProfiles.allExtruders`)}),(0,K.jsx)(`option`,{value:`left`,children:e(`kProfiles.leftOnly`)}),(0,K.jsx)(`option`,{value:`right`,children:e(`kProfiles.rightOnly`)})]})}),(0,K.jsx)(`div`,{className:`w-32`,children:(0,K.jsxs)(`select`,{value:_,onChange:e=>v(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:`all`,children:e(`kProfiles.allFlow`)}),(0,K.jsx)(`option`,{value:`hf`,children:e(`kProfiles.hfOnly`)}),(0,K.jsx)(`option`,{value:`s`,children:e(`kProfiles.sOnly`)})]})}),(0,K.jsx)(`div`,{className:`w-32`,children:(0,K.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`name`,children:e(`kProfiles.sortName`)}),(0,K.jsx)(`option`,{value:`k_value`,children:e(`kProfiles.sortKValue`)}),(0,K.jsx)(`option`,{value:`filament`,children:e(`kProfiles.sortFilament`)})]})})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-6`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:oe,disabled:!N?.profiles?.length||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noExport`),children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),e(`kProfiles.export`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:se,disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noImport`),children:[(0,K.jsx)(Su,{className:`w-4 h-4`}),e(`kProfiles.import`)]}),(0,K.jsx)(`div`,{className:`flex-1`}),S?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`secondary`,onClick:le,children:[(0,K.jsx)($l,{className:`w-4 h-4`}),e(`kProfiles.selectAll`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:ue,disabled:w.size===0||!n(`kprofiles:delete`),className:`text-red-500 hover:bg-red-500/10`,title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`kProfiles.delete`),` (`,w.size,`)`]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>{C(!1),T(new Set)},children:[(0,K.jsx)(Pu,{className:`w-4 h-4`}),e(`common.cancel`)]})]}):(0,K.jsxs)($,{variant:`secondary`,onClick:()=>C(!0),disabled:!ie.length||!n(`kprofiles:delete`),title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,K.jsx)($l,{className:`w-4 h-4`}),e(`kProfiles.select`)]})]}),P?(0,K.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):H?(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`py-12 text-center`,children:[(0,K.jsx)(Au,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.printerOffline`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.printerOfflineDesc`)}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>L(),children:[(0,K.jsx)(Cl,{className:`w-4 h-4`}),e(`common.refresh`)]})]})}):ie.length>0?W?(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.leftExtruder`)}),(0,K.jsx)(`div`,{className:`space-y-1`,children:ie.filter(e=>e.extruder_id===1).map(e=>(0,K.jsx)(f7,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>ce(A(e)),note:he(e)},A(e)))})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.rightExtruder`)}),(0,K.jsx)(`div`,{className:`space-y-1`,children:ie.filter(e=>e.extruder_id===0).map(e=>(0,K.jsx)(f7,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>ce(A(e)),note:he(e)},A(e)))})]})]}):(0,K.jsx)(`div`,{className:`space-y-1`,children:ie.map(e=>(0,K.jsx)(f7,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>ce(A(e)),note:he(e)},A(e)))}):p||h!==`all`||_!==`all`?(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`py-12 text-center`,children:[(0,K.jsx)(Nl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noMatchingProfiles`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.noMatchingProfilesDesc`)})]})}):(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`py-12 text-center`,children:[(0,K.jsx)(uc,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noKProfiles`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.noKProfilesDesc`,{diameter:a})}),(0,K.jsxs)($,{onClick:()=>u(!0),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),e(`kProfiles.createFirstProfile`)]})]})}),s&&r&&(()=>{let{note:e,key:t}=me(s);return(0,K.jsx)(p7,{profile:s,printerId:r,nozzleDiameter:a,existingProfiles:R?.profiles||N?.profiles,builtinFilaments:re,isDualNozzle:W,initialNote:e,initialNoteKey:t,onSaveNote:pe,hasPermission:n,onClose:()=>{console.log(`[KProfiles] Edit modal onClose - refetching profiles...`),c(null),L()},onSave:()=>{c(null),L()}})})(),l&&r&&(0,K.jsx)(p7,{printerId:r,nozzleDiameter:a,existingProfiles:R?.profiles||N?.profiles,builtinFilaments:re,isDualNozzle:W,onSaveNote:pe,hasPermission:n,onClose:()=>{u(!1),L()},onSave:()=>{u(!1),L()}}),d&&r&&(0,K.jsx)(p7,{printerId:r,nozzleDiameter:a,existingProfiles:R?.profiles||N?.profiles,builtinFilaments:re,isDualNozzle:W,onSaveNote:pe,hasPermission:n,profile:{...d,slot_id:0,name:`${d.name} (Copy)`},onClose:()=>{f(null),L()},onSave:()=>{f(null),L()}}),E&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(pd,{className:`w-full max-w-sm`,children:(0,K.jsxs)(hd,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,K.jsx)(hu,{className:`w-5 h-5 text-red-500`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e(`kProfiles.bulkDelete.title`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`kProfiles.bulkDelete.cannotUndo`)})]})]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:e(`kProfiles.bulkDelete.message`,{count:w.size})}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>D(!1),disabled:O,className:`flex-1`,children:e(`common.cancel`)}),(0,K.jsxs)($,{onClick:de,disabled:O,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[O?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`common.delete`)]})]})]})})})]})}var h7=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`PVA`,`HIPS`,`PP`,`PET`,`NYLON`],Vze={PLA:`E8E8E8`,PETG:`4A90D9`,ABS:`E67E22`,ASA:`D35400`,TPU:`9B59B6`,PC:`BDC3C7`,PA:`2ECC71`,NYLON:`2ECC71`,PVA:`F1C40F`,HIPS:`95A5A6`,PP:`ECF0F1`,PET:`3498DB`};function Hze(e){let t=e.toUpperCase();for(let e of h7)if(RegExp(`\\b${e}\\b`).test(t))return e;return null}function Uze(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase();for(let e of h7){let r=n.indexOf(e);if(r>0){let e=t.slice(0,r).trim();if(e&&e.length>1)return e}}return null}function g7({preset:e,onDelete:t,onExpand:n,isExpanded:r}){let{t:i}=G(),{hasPermission:a}=sd(),o=e.filament_type||Hze(e.name),s=e.filament_vendor||Uze(e.name),c=null,l=!1;if(e.default_filament_colour)try{let t=JSON.parse(e.default_filament_colour),n=Array.isArray(t)?t[0]:t;typeof n==`string`&&/^#?[0-9a-fA-F]{6,8}$/.test(n.replace(`#`,``))&&(c=n.replace(`#`,``).slice(0,6),l=!0)}catch{let t=e.default_filament_colour;/^#?[0-9a-fA-F]{6,8}$/.test(t.replace(`#`,``))&&(c=t.replace(`#`,``).slice(0,6),l=!0)}return!c&&o&&(c=Vze[o.toUpperCase()]||null),(0,K.jsx)(pd,{className:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors`,children:(0,K.jsxs)(hd,{className:`p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[e.preset_type===`filament`&&(0,K.jsx)(`div`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0 ${!l&&!c?`opacity-25`:l?``:`opacity-50`}`,style:{backgroundColor:c?`#${c}`:`#666`}}),(0,K.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[o&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:o}),s&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:s}),(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400`,children:i(`profiles.localProfiles.badge`)})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[a(`settings:update`)&&(0,K.jsx)(`button`,{onClick:()=>t(e.id),className:`p-1 text-bambu-gray hover:text-red-400 transition-colors`,title:i(`profiles.localProfiles.delete`),children:(0,K.jsx)(hu,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{onClick:()=>n(r?null:e.id),className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:r?(0,K.jsx)(rs,{className:`w-3.5 h-3.5`}):(0,K.jsx)(es,{className:`w-3.5 h-3.5`})})]})]}),r&&(0,K.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5`,children:[o&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.filamentType`)}),(0,K.jsx)(`span`,{className:`text-white`,children:o})]}),s&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.vendor`)}),(0,K.jsx)(`span`,{className:`text-white`,children:s})]}),e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.nozzleTemp`)}),(0,K.jsxs)(`span`,{className:`text-white`,children:[e.nozzle_temp_min,`–`,e.nozzle_temp_max,`°C`]})]}),e.filament_cost&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.cost`)}),(0,K.jsx)(`span`,{className:`text-white`,children:e.filament_cost})]}),e.filament_density&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.density`)}),(0,K.jsxs)(`span`,{className:`text-white`,children:[e.filament_density,` g/cm³`]})]}),e.pressure_advance&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.pressureAdvance`)}),(0,K.jsx)(`span`,{className:`text-white`,children:e.pressure_advance})]}),e.compatible_printers&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.compatiblePrinters`)}),(0,K.jsx)(`span`,{className:`text-white truncate ml-2`,children:(()=>{try{return JSON.parse(e.compatible_printers).join(`, `)}catch{return e.compatible_printers}})()})]}),e.inherits&&e.inherits!==e.name&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.inheritsFrom`)}),(0,K.jsx)(`span`,{className:`text-white truncate ml-2`,children:e.inherits})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.source`)}),(0,K.jsx)(`span`,{className:`text-white capitalize`,children:e.source})]})]})]})})}function Wze(){let{t:e}=G(),{hasPermission:t}=sd(),n=Qa(),{showToast:r}=xd(),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null),{data:f,isLoading:p}=q({queryKey:[`localPresets`],queryFn:()=>Q.getLocalPresets()}),m=J({mutationFn:async e=>{let t=[];for(let n of Array.from(e)){let e=new FormData;e.append(`file`,n),t.push(await Q.importLocalPresets(e))}return t},onSuccess:t=>{n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]});let i=0,a=0,o=0;for(let e of t)i+=e.imported,a+=e.skipped,o+=e.errors.length;i>0&&r(e(`profiles.localProfiles.toast.importSuccess`,{count:i})),a>0&&r(e(`profiles.localProfiles.toast.importSkipped`,{count:a}),`warning`),o>0&&r(e(`profiles.localProfiles.toast.importError`,{count:o}),`error`)},onError:e=>{r(e.message,`error`)}}),h=J({mutationFn:e=>Q.deleteLocalPreset(e),onSuccess:(t,i)=>{n.setQueryData([`localPresets`],e=>e&&{filament:e.filament.filter(e=>e.id!==i),printer:e.printer.filter(e=>e.id!==i),process:e.process.filter(e=>e.id!==i)}),n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]}),d(null),r(e(`profiles.localProfiles.toast.deleted`))}}),g=(0,y.useCallback)(e=>{!e||e.length===0||m.mutate(e)},[m]),_=(0,y.useCallback)(e=>{e.preventDefault(),l(!1),g(e.dataTransfer.files)},[g]),v=(0,y.useCallback)(e=>{if(!i)return e;let t=i.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.filament_type?.toLowerCase().includes(t)||e.filament_vendor?.toLowerCase().includes(t))},[i]),b=(0,y.useMemo)(()=>v(f?.filament||[]),[f?.filament,v]),x=(0,y.useMemo)(()=>v(f?.printer||[]),[f?.printer,v]),S=(0,y.useMemo)(()=>v(f?.process||[]),[f?.process,v]),C=b.length+x.length+S.length,w=(f?.filament?.length??0)+(f?.printer?.length??0)+(f?.process?.length??0)>0;return p?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,K.jsxs)(`div`,{className:`space-y-6`,children:[t(`settings:update`)&&(0,K.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),l(!0)},onDragLeave:()=>l(!1),onDrop:_,className:`relative border-2 border-dashed rounded-lg p-6 text-center transition-colors ${c?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,K.jsx)(`input`,{type:`file`,accept:`.json,.zip,.orca_filament,.bbscfg,.bbsflmt`,multiple:!0,className:`absolute inset-0 w-full h-full opacity-0 cursor-pointer`,onChange:e=>g(e.target.files)}),m.isPending?(0,K.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,K.jsx)(X,{className:`w-5 h-5 text-bambu-green animate-spin`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.importing`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Su,{className:`w-8 h-8 text-bambu-gray mx-auto mb-2`}),(0,K.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`profiles.localProfiles.import`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`profiles.localProfiles.importDesc`)})]})]}),w&&(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:e(`profiles.localProfiles.search`),className:`w-full pl-9 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})]}),!w&&!p&&(0,K.jsxs)(`div`,{className:`text-center py-12`,children:[(0,K.jsx)(yc,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noPresets`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:e(`profiles.localProfiles.importDesc`)})]}),w&&C===0&&!p&&(0,K.jsxs)(`div`,{className:`text-center py-12`,children:[(0,K.jsx)(Nl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noSearchResults`)})]}),C>0&&(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`,children:[b.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,K.jsx)(Ls,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.filament`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,b.length,`)`]})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:b.map(e=>(0,K.jsx)(g7,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]}),S.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,K.jsx)(Nc,{className:`w-4 h-4 text-blue-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.process`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,S.length,`)`]})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:S.map(e=>(0,K.jsx)(g7,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]}),x.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,K.jsx)(Ll,{className:`w-4 h-4 text-orange-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.printer`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,x.length,`)`]})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>(0,K.jsx)(g7,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]})]}),u!==null&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,K.jsx)(ss,{className:`w-5 h-5 text-red-400`}),(0,K.jsx)(`h3`,{className:`text-white font-medium`,children:e(`profiles.localProfiles.deleteConfirmTitle`)})]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`profiles.localProfiles.deleteConfirm`)}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>d(null),children:e(`profiles.localProfiles.cancel`)}),(0,K.jsxs)($,{variant:`danger`,size:`sm`,onClick:()=>h.mutate(u),disabled:h.isPending,children:[h.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`profiles.localProfiles.delete`)]})]})]})})]})}function Gze(e){let t=e.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),n=e.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),r=e.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),i=e.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:t?t[1].trim():null,nozzle:n?(n[1]||n[2])+`mm`:null,layerHeight:r?r[1]+`mm`:null,filamentType:i?i[1].toUpperCase():null}}function Kze({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,t:a}){let[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(`all`),[u,d]=(0,y.useState)(`all`),[f,p]=(0,y.useState)(`all`),[m,h]=(0,y.useState)(`all`),[g,_]=(0,y.useState)(`all`),[v,b]=(0,y.useState)(null),x=(0,y.useMemo)(()=>[...e.filament.map(e=>({...e,type:`filament`})),...e.printer.map(e=>({...e,type:`printer`})),...e.process.map(e=>({...e,type:`process`}))].map(e=>({...e,meta:Gze(e.name)})),[e]),S=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return x.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[x,i]),C=(0,y.useMemo)(()=>u===`all`?null:i.find(e=>e.id.toString()===u)?.model||null,[u,i]),w=(0,y.useMemo)(()=>x.filter(e=>c===`all`||e.type===c).filter(e=>{if(u===`all`||!C)return!0;let t=e.meta.printer?.toLowerCase()||``,n=C.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>f===`all`||e.meta.nozzle===f).filter(e=>m===`all`||e.meta.filamentType===m).filter(e=>g===`all`||e.meta.layerHeight===g).filter(e=>o===``||e.name.toLowerCase().includes(o.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[x,c,u,C,f,m,g,o]),T=()=>{l(`all`),d(`all`),p(`all`),h(`all`),_(`all`),s(``)},E=c!==`all`||u!==`all`||f!==`all`||m!==`all`||g!==`all`||o!==``,D=e.filament.length+e.printer.length+e.process.length,O=e=>w.filter(t=>t.type===e);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:a(`profiles.cloudView.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,K.jsx)(`div`,{className:`flex gap-2`,children:(0,K.jsxs)($,{variant:`secondary`,onClick:n,disabled:r,children:[(0,K.jsx)(Cl,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),a(`profiles.cloudView.refresh`)]})})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(lc,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(b7,{label:a(`profiles.cloudView.filters.type`),value:c,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`),count:D},{value:`filament`,label:a(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:a(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:a(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>l(e)}),S.printers.length>0&&(0,K.jsx)(b7,{label:a(`profiles.cloudView.filters.printer`),value:u,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.printers.map(e=>({value:e.id,label:e.name}))],onChange:d}),S.nozzles.length>0&&(0,K.jsx)(b7,{label:a(`profiles.cloudView.filters.nozzle`),value:f,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.nozzles.map(e=>({value:e,label:e}))],onChange:p}),S.filaments.length>0&&(c===`all`||c===`filament`)&&(0,K.jsx)(b7,{label:a(`profiles.cloudView.filters.filament`),value:m,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.filaments.map(e=>({value:e,label:e}))],onChange:h}),S.layerHeights.length>0&&(c===`all`||c===`process`)&&(0,K.jsx)(b7,{label:a(`profiles.cloudView.filters.layer`),value:g,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.layerHeights.map(e=>({value:e,label:e}))],onChange:_}),E&&(0,K.jsx)(`button`,{onClick:T,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:a(`profiles.cloudView.clearFilters`)})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),a(`profiles.cloudView.lastSynced`),` `,bf(t.toISOString(),`system`,a)]}),(0,K.jsx)(`span`,{children:a(`profiles.cloudView.showingCount`,{showing:w.length,total:D})})]}),w.length===0?(0,K.jsxs)(`div`,{className:`text-center py-16`,children:[(0,K.jsx)(Nc,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:a(`profiles.cloudView.noPresetsFound`)}),E&&(0,K.jsx)(`button`,{onClick:T,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:a(`profiles.cloudView.clearFilters`)})]}):(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,K.jsx)(_7,{icon:(0,K.jsx)(Ls,{className:`w-4 h-4 text-amber-400`}),title:a(`profiles.cloudView.columns.filament`),presets:O(`filament`),emptyText:a(`profiles.cloudView.noFilamentPresets`),onSelect:b}),(0,K.jsx)(_7,{icon:(0,K.jsx)(Ll,{className:`w-4 h-4 text-blue-400`}),title:a(`profiles.cloudView.columns.process`),presets:O(`process`),emptyText:a(`profiles.cloudView.noProcessPresets`),onSelect:b}),(0,K.jsx)(_7,{icon:(0,K.jsx)(bl,{className:`w-4 h-4 text-purple-400`}),title:a(`profiles.cloudView.columns.printer`),presets:O(`printer`),emptyText:a(`profiles.cloudView.noPrinterPresets`),onSelect:b})]}),v&&(0,K.jsx)(Jze,{setting:v,onClose:()=>b(null),t:a})]})}function _7({icon:e,title:t,presets:n,emptyText:r,onSelect:i}){return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[e,(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:t}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,n.length,`)`]})]}),(0,K.jsx)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:n.length===0?(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:r}):n.map(e=>(0,K.jsx)(qze,{preset:e,onClick:()=>i(e)},e.setting_id))})]})}function qze({preset:e,onClick:t}){return(0,K.jsx)(`button`,{onClick:t,className:`w-full text-left px-3 py-2 rounded bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),e.meta.filamentType&&e.type===`filament`&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.filamentType}),e.meta.layerHeight&&e.type===`process`&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.layerHeight}),e.meta.printer&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.printer})]})})}function Jze({setting:e,onClose:t,t:n}){let{data:r,isLoading:i,error:a}=q({queryKey:[`orcaCloudProfileDetail`,e.setting_id],queryFn:()=>Q.orcaCloudGetProfile(e.setting_id),retry:!1});return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4`,onClick:t,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl max-w-4xl w-full max-h-[90vh] flex flex-col`,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`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-bold text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.type})]}),(0,K.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white p-1`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:i?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):a?(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:a.message}):r?(0,K.jsx)(`pre`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark p-3 rounded overflow-x-auto whitespace-pre`,children:JSON.stringify(r.setting,null,2)}):(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:n(`profiles.cloudView.noPresetsFound`)})})]})})}function Yze(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),{hasPermission:r}=sd(),i=r(`orca_cloud:auth`),[a,o]=(0,y.useState)(`picker`),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(null),{data:b,isLoading:x}=q({queryKey:[`orcaCloudStatus`],queryFn:Q.orcaCloudStatus}),S=!!b?.connected,{data:C,isLoading:w,refetch:T,isRefetching:E,error:D,dataUpdatedAt:O}=q({queryKey:[`orcaCloudProfiles`],queryFn:Q.orcaCloudListProfiles,enabled:S,retry:!1,staleTime:1e3*60*5}),{data:k=[]}=q({queryKey:[`printers`],queryFn:Q.getPrinters,enabled:S}),[A,j]=(0,y.useState)();(0,y.useEffect)(()=>{O&&j(new Date(O))},[O]);let M=J({mutationFn:e=>Q.orcaCloudStartAuth(e),onSuccess:e=>{c(e.auth_url),u(``),f(null),o(`paste`),window.open(e.auth_url,`_blank`,`noopener,noreferrer`)},onError:t=>{n(t.message||e(`profiles.orcaCloud.errors.startFailed`),`error`)}}),N=J({mutationFn:e=>Q.orcaCloudFinishAuth(e),onSuccess:r=>{c(null),u(``),f(null),o(`picker`),t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.invalidateQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.toast.connected`,{email:r.email||``}))},onError:t=>{f(t.message||e(`profiles.orcaCloud.errors.finishFailed`))}}),P=J({mutationFn:({email:e,password:t})=>Q.orcaCloudPasswordLogin(e,t),onSuccess:r=>{m(``),g(``),v(null),o(`picker`),t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.invalidateQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.toast.connected`,{email:r.email||``}))},onError:t=>{v(t.message||e(`profiles.orcaCloud.errors.passwordFailed`))}}),F=J({mutationFn:Q.orcaCloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.removeQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.toast.disconnected`))}});return x?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,K.jsxs)(`div`,{children:[S&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`profiles.orcaCloud.connectedAs`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:b?.email})]})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>F.mutate(),disabled:F.isPending||!i,title:i?void 0:e(`profiles.orcaCloud.noLogoutPermission`),children:[(0,K.jsx)(Wc,{className:`w-4 h-4`}),e(`profiles.orcaCloud.logout`)]})]}),S?w?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):D?(0,K.jsxs)(`div`,{className:`text-center py-16`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:D.message}),(0,K.jsx)($,{onClick:()=>T(),children:e(`profiles.orcaCloud.retry`)})]}):C?(0,K.jsx)(Kze,{settings:C,lastSyncTime:A,onRefresh:()=>T(),isRefreshing:E,printers:k,t:e}):null:(0,K.jsx)(Xze,{mode:a,authUrl:s,pastedUrl:l,setPastedUrl:u,pasteError:d,passwordEmail:p,setPasswordEmail:m,passwordValue:h,setPasswordValue:g,passwordError:_,onPickProvider:e=>M.mutate(e),onPickPassword:()=>{o(`password`),v(null)},onSubmitPaste:t=>{t.preventDefault(),f(null);let n=l.trim();if(!n){f(e(`profiles.orcaCloud.errors.emptyPaste`));return}if(!n.includes(`code=`)){f(e(`profiles.orcaCloud.errors.noCode`));return}N.mutate(n)},onSubmitPassword:t=>{t.preventDefault(),v(null);let n=p.trim();if(!n||!h){v(e(`profiles.orcaCloud.errors.passwordEmpty`));return}P.mutate({email:n,password:h})},onBack:()=>{o(`picker`),c(null),u(``),f(null),m(``),g(``),v(null)},isStarting:M.isPending,isFinishing:N.isPending,isPasswordLoading:P.isPending,canManage:i,t:e})]})}function Xze(e){return e.mode===`paste`&&e.authUrl?(0,K.jsx)(Qze,{...e,authUrl:e.authUrl}):e.mode===`password`?(0,K.jsx)($ze,{...e}):(0,K.jsx)(Zze,{...e})}function Zze({onPickProvider:e,onPickPassword:t,isStarting:n,canManage:r,t:i}){return(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-8 text-center`,children:[(0,K.jsx)(ys,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,K.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:i(`profiles.orcaCloud.connect.title`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray mb-6 max-w-xl mx-auto`,children:i(`profiles.orcaCloud.connect.description`)}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 max-w-sm mx-auto`,children:[(0,K.jsxs)($,{onClick:t,disabled:n||!r,title:r?void 0:i(`profiles.orcaCloud.noConnectPermission`),children:[(0,K.jsx)(Gc,{className:`w-4 h-4`}),i(`profiles.orcaCloud.providers.email`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>e(`google`),disabled:n||!r,title:r?void 0:i(`profiles.orcaCloud.noConnectPermission`),children:[n?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Us,{className:`w-4 h-4`}),i(`profiles.orcaCloud.providers.google`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>e(`github`),disabled:n||!r,title:r?void 0:i(`profiles.orcaCloud.noConnectPermission`),children:[(0,K.jsx)(Us,{className:`w-4 h-4`}),i(`profiles.orcaCloud.providers.github`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>e(`apple`),disabled:n||!r,title:r?void 0:i(`profiles.orcaCloud.noConnectPermission`),children:[(0,K.jsx)(Us,{className:`w-4 h-4`}),i(`profiles.orcaCloud.providers.apple`)]})]})]})})}function Qze({authUrl:e,pastedUrl:t,setPastedUrl:n,pasteError:r,onSubmitPaste:i,onBack:a,isFinishing:o,t:s}){return(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-6`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:a,className:`text-bambu-gray hover:text-white text-sm flex items-center gap-1 mb-4`,children:[(0,K.jsx)(Do,{className:`w-4 h-4`}),s(`profiles.orcaCloud.back`)]}),(0,K.jsx)(`h2`,{className:`text-xl font-bold text-white mb-4`,children:s(`profiles.orcaCloud.paste.title`)}),(0,K.jsxs)(`ol`,{className:`space-y-3 mb-6`,children:[(0,K.jsxs)(`li`,{className:`flex gap-3`,children:[(0,K.jsx)(`span`,{className:`flex-shrink-0 w-7 h-7 rounded-full bg-bambu-dark-tertiary text-white text-sm font-bold flex items-center justify-center`,children:`1`}),(0,K.jsx)(`p`,{className:`text-base text-white pt-0.5`,children:s(`profiles.orcaCloud.paste.step1`)})]}),(0,K.jsxs)(`li`,{className:`flex gap-3`,children:[(0,K.jsx)(`span`,{className:`flex-shrink-0 w-7 h-7 rounded-full bg-amber-500/20 text-amber-400 text-sm font-bold flex items-center justify-center`,children:`2`}),(0,K.jsx)(`div`,{className:`flex-1 p-3 bg-amber-500/10 border border-amber-500/40 rounded`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(vu,{className:`w-5 h-5 text-amber-400 flex-shrink-0 mt-0.5`}),(0,K.jsx)(`p`,{className:`text-base text-white font-medium`,children:s(`profiles.orcaCloud.paste.step2`)})]})})]}),(0,K.jsxs)(`li`,{className:`flex gap-3`,children:[(0,K.jsx)(`span`,{className:`flex-shrink-0 w-7 h-7 rounded-full bg-bambu-dark-tertiary text-white text-sm font-bold flex items-center justify-center`,children:`3`}),(0,K.jsx)(`p`,{className:`text-base text-white pt-0.5`,children:s(`profiles.orcaCloud.paste.step3`)})]})]}),(0,K.jsxs)(`div`,{className:`mb-4 p-3 bg-bambu-dark rounded border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:s(`profiles.orcaCloud.paste.signInUrl`)}),(0,K.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green text-sm break-all hover:underline`,children:e})]}),(0,K.jsxs)(`form`,{onSubmit:i,children:[(0,K.jsx)(`label`,{htmlFor:`orca-callback-url`,className:`block text-sm text-bambu-gray mb-2`,children:s(`profiles.orcaCloud.paste.label`)}),(0,K.jsx)(`textarea`,{id:`orca-callback-url`,value:t,onChange:e=>n(e.target.value),placeholder:s(`profiles.orcaCloud.paste.placeholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono resize-none focus:outline-none focus:border-bambu-green`,rows:3,disabled:o}),r&&(0,K.jsxs)(`p`,{className:`mt-2 text-sm text-red-400 flex items-center gap-2`,children:[(0,K.jsx)(ss,{className:`w-4 h-4`}),r]}),(0,K.jsx)(`div`,{className:`mt-4 flex items-center gap-3`,children:(0,K.jsxs)($,{type:`submit`,disabled:o||!t.trim(),children:[o?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)($o,{className:`w-4 h-4`}),s(`profiles.orcaCloud.paste.submit`)]})})]})]})})}function $ze({passwordEmail:e,setPasswordEmail:t,passwordValue:n,setPasswordValue:r,passwordError:i,onSubmitPassword:a,onBack:o,isPasswordLoading:s,t:c}){return(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-6 max-w-md mx-auto`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:o,className:`text-bambu-gray hover:text-white text-sm flex items-center gap-1 mb-4`,children:[(0,K.jsx)(Do,{className:`w-4 h-4`}),c(`profiles.orcaCloud.back`)]}),(0,K.jsx)(`h2`,{className:`text-xl font-bold text-white mb-4`,children:c(`profiles.orcaCloud.password.title`)}),(0,K.jsxs)(`form`,{onSubmit:a,className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`orca-password-email`,className:`block text-sm text-bambu-gray mb-1`,children:c(`profiles.orcaCloud.password.email`)}),(0,K.jsx)(`input`,{id:`orca-password-email`,type:`email`,value:e,onChange:e=>t(e.target.value),placeholder:c(`profiles.orcaCloud.password.emailPlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,disabled:s,autoComplete:`email`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`orca-password-value`,className:`block text-sm text-bambu-gray mb-1`,children:c(`profiles.orcaCloud.password.password`)}),(0,K.jsx)(`input`,{id:`orca-password-value`,type:`password`,value:n,onChange:e=>r(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,disabled:s,autoComplete:`current-password`})]}),i&&(0,K.jsxs)(`p`,{className:`text-sm text-red-400 flex items-center gap-2`,children:[(0,K.jsx)(ss,{className:`w-4 h-4`}),i]}),(0,K.jsxs)($,{type:`submit`,disabled:s||!e.trim()||!n,children:[s?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)($o,{className:`w-4 h-4`}),c(`profiles.orcaCloud.password.submit`)]})]})]})})}function v7(e,t){let n=`${e} ${t||``}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=r?r[1].trim():null,a=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=a?(a[1]||a[2])+`mm`:null,s=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=s?s[1]+`mm`:null,l=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:i,nozzle:o,layerHeight:c,filamentType:l?l[1].toUpperCase():null}}function y7(e){return/^(P[FPM]US|PF\d|PP\d)/.test(e)}function eBe({onSuccess:e,t}){let{showToast:n}=xd(),[r,i]=(0,y.useState)(`email`),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(`global`),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(null),b=J({mutationFn:()=>Q.cloudLogin(a,s,p),onSuccess:r=>{r.success?(n(t(`profiles.login.toast.loggedIn`)),e()):r.needs_verification?(g(r.verification_type||`email`),v(r.tfa_key||null),r.verification_type===`totp`?n(t(`profiles.login.toast.enterTotp`)):n(t(`profiles.login.toast.codeSent`)),i(`code`)):n(r.message,`error`)},onError:e=>n(e.message,`error`)}),x=J({mutationFn:()=>Q.cloudVerify(a,l,_||void 0,p),onSuccess:r=>{r.success?(n(t(`profiles.login.toast.loggedIn`)),e()):n(r.message,`error`)},onError:e=>n(e.message,`error`)}),S=J({mutationFn:()=>Q.cloudSetToken(d,p),onSuccess:()=>{n(t(`profiles.login.toast.tokenSet`)),e()},onError:e=>n(e.message,`error`)}),C=e=>{e.preventDefault(),r===`email`?b.mutate():r===`code`?x.mutate():r===`token`&&S.mutate()},w=b.isPending||x.isPending||S.isPending;return(0,K.jsx)(pd,{className:`max-w-md mx-auto`,children:(0,K.jsxs)(hd,{children:[(0,K.jsxs)(`div`,{className:`text-center mb-6`,children:[(0,K.jsx)(`div`,{className:`inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3`,children:(0,K.jsx)(ys,{className:`w-6 h-6 text-bambu-green`})}),(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:t(`profiles.login.title`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:t(`profiles.login.subtitle`)})]}),(0,K.jsxs)(`form`,{onSubmit:C,className:`space-y-4`,children:[r===`email`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.email`)}),(0,K.jsx)(`input`,{type:`email`,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 placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`your@email.com`,required:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.password`)}),(0,K.jsx)(`input`,{type:`password`,value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`••••••••`,required:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,K.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,K.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),r===`code`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(h===`totp`?`profiles.login.totpCode`:`profiles.login.verificationCode`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:h===`totp`?t(`profiles.login.enterTotpHint`):t(`profiles.login.checkEmail`,{email:a})}),(0,K.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none`,placeholder:`000000`,maxLength:6,required:!0})]}),r===`token`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.accessToken`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:t(`profiles.login.accessTokenHint`)}),(0,K.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none`,placeholder:`eyJ...`,rows:4,required:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,K.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,K.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[r===`code`&&(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:()=>i(`email`),className:`flex-1`,children:t(`profiles.login.back`)}),(0,K.jsxs)($,{type:`submit`,disabled:w,className:`flex-1`,children:[w?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Uc,{className:`w-4 h-4`}),t(r===`email`?`profiles.login.loginButton`:r===`code`?`profiles.login.verifyButton`:`profiles.login.setTokenButton`)]})]}),r===`email`&&(0,K.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>i(`token`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,K.jsx)(jc,{className:`w-4 h-4`}),t(`profiles.login.useToken`)]})}),r===`token`&&(0,K.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>i(`email`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,K.jsx)(Uc,{className:`w-4 h-4`}),t(`profiles.login.useEmail`)]})})]})]})})}function b7({label:e,value:t,options:n,onChange:r}){let[i,a]=(0,y.useState)(!1),o=n.find(e=>e.value===t);return(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[e,`:`]}),(0,K.jsx)(`span`,{children:o?.label||`All`}),(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?`rotate-180`:``}`})]}),i&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>a(!1)}),(0,K.jsx)(`div`,{className:`absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto`,children:n.map(e=>(0,K.jsxs)(`button`,{onClick:()=>{r(e.value),a(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${t===e.value?`text-bambu-green`:`text-white`}`,children:[(0,K.jsx)(`span`,{children:e.label}),e.count!==void 0&&(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e.count})]},e.value))})]})]})}function tBe(){let[e,t]=(0,y.useState)(!1);return(0,y.useEffect)(()=>{let e=()=>{t(window.scrollY>300)};return window.addEventListener(`scroll`,e),()=>window.removeEventListener(`scroll`,e)},[]),e?(0,K.jsx)(`button`,{onClick:()=>{window.scrollTo({top:0,behavior:`smooth`})},className:`fixed bottom-6 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40`,"aria-label":`Scroll to top`,children:(0,K.jsx)(Mo,{className:`w-5 h-5`})}):null}function x7({setting:e,onClick:t,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:a,compareDisabled:o,t:s}){let c=v7(e.name),l=y7(e.setting_id);return(0,K.jsxs)(`div`,{className:`flex items-center gap-2 group`,children:[(0,K.jsx)(`button`,{onClick:t,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?`bg-blue-500/20 border border-blue-500/50`:o?`bg-bambu-dark/50 opacity-40 cursor-not-allowed`:`bg-bambu-dark hover:bg-bambu-dark-tertiary`} ${r&&!o?`cursor-pointer`:``}`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i&&a!==void 0&&(0,K.jsx)(`span`,{className:`flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium`,children:a+1}),!i&&l&&(0,K.jsx)(`span`,{className:`flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green`,title:s(`profiles.presets.myPreset`)}),(0,K.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),c.filamentType&&e.type===`filament`&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.filamentType}),c.layerHeight&&e.type===`process`&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.layerHeight}),c.printer&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.printer})]})}),(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`opacity-0 group-hover:opacity-100 text-bambu-gray hover:text-white transition-all p-1`,title:s(`profiles.presets.duplicate`),children:(0,K.jsx)(Ds,{className:`w-4 h-4`})})]})}function S7(e,t=0){let n=` `.repeat(t);if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`){if(e.includes(`\\n`)||e.includes(` +`)),i(!0),setTimeout(()=>i(!1),2e3)},className:`flex items-center gap-2`,children:[(0,K.jsx)(Ds,{className:`w-4 h-4`}),n(r?`common.copied`:`common.copy`)]}),(0,K.jsx)($,{variant:`primary`,size:`sm`,onClick:t,className:`flex-1`,children:n(`settings.twoFa.savedCodes`)})]})]})}function Tze({onDone:e}){let{t}=G(),n=Qa(),{showToast:r}=xd(),[i,a]=(0,y.useState)(`qr`),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)([]),[u,d]=(0,y.useState)(!1),{data:f,isLoading:p}=q({queryKey:[`totp-setup`],queryFn:()=>Q.setupTOTP(),staleTime:1/0}),m=J({mutationFn:e=>Q.enableTOTP(e),onSuccess:e=>{l(e.backup_codes),a(`backup`),n.invalidateQueries({queryKey:[`2fa-status`]})},onError:()=>r(t(`settings.twoFa.invalidCode`),`error`)});return p||!f?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,K.jsx)(Cl,{className:`w-6 h-6 animate-spin text-bambu-green`})}):i===`qr`?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:t(`settings.twoFa.setupInstructions`)}),(0,K.jsx)(`div`,{className:`flex justify-center`,children:(0,K.jsx)(`img`,{src:`data:image/png;base64,${f.qr_code_b64}`,alt:`TOTP QR Code`,className:`w-48 h-48 rounded-lg`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:t(`settings.twoFa.manualEntry`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 bg-bambu-dark-secondary rounded-lg px-3 py-2`,children:[(0,K.jsx)(`code`,{className:`text-white text-xs font-mono flex-1 break-all`,children:u?f.secret:`••••••••••••••••`}),(0,K.jsx)(`button`,{onClick:()=>d(!u),className:`text-bambu-gray hover:text-white`,children:u?(0,K.jsx)(Ws,{className:`w-4 h-4`}):(0,K.jsx)(Gs,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(f.secret)},className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(Ds,{className:`w-4 h-4`})})]})]}),(0,K.jsx)($,{variant:`primary`,className:`w-full`,onClick:()=>a(`confirm`),children:t(`settings.twoFa.scannedContinue`)})]}):i===`confirm`?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:t(`settings.twoFa.enterCodeToConfirm`)}),(0,K.jsx)(n7,{value:o,onChange:s,placeholder:`000000`}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>a(`qr`),className:`flex-1`,children:t(`common.back`)}),(0,K.jsx)($,{variant:`primary`,className:`flex-1`,disabled:o.length!==6||m.isPending,onClick:()=>m.mutate(o),children:m.isPending?t(`common.saving`):t(`settings.twoFa.activate`)})]})]}):(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`h3`,{className:`text-white font-medium`,children:t(`settings.twoFa.backupCodesTitle`)}),(0,K.jsx)(r7,{codes:c,onDone:e})]})}function Eze(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),{user:r}=sd(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(``),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(``),[T,E]=(0,y.useState)(!1),{data:D,isLoading:O}=q({queryKey:[`2fa-status`],queryFn:()=>Q.get2FAStatus()}),{data:k}=q({queryKey:[`oidc-links`],queryFn:()=>Q.getOIDCLinks()}),A=J({mutationFn:()=>Q.enableEmailOTP(),onSuccess:e=>{_(e.setup_token),n(e.message,`success`)},onError:t=>{let r=t.message??``;r.toLowerCase().includes(`smtp`)?n(e(`settings.twoFa.smtpRequired`),`error`):n(r,`error`)}}),j=J({mutationFn:()=>Q.confirmEnableEmailOTP(g,v),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),_(null),b(``),n(e(`settings.twoFa.emailOtpEnabled`),`success`)},onError:e=>n(e.message,`error`)}),M=J({mutationFn:e=>Q.disableEmailOTP(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),S(!1),w(``),n(e(`settings.twoFa.emailOtpDisabled`),`success`)},onError:e=>n(e.message,`error`)}),N=J({mutationFn:e=>Q.disableTOTP(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),s(!1),d(``),n(e(`settings.twoFa.totpDisabled`),`success`)},onError:()=>n(e(`settings.twoFa.invalidCode`),`error`)}),P=J({mutationFn:e=>Q.regenerateBackupCodes(e),onSuccess:e=>{t.invalidateQueries({queryKey:[`2fa-status`]}),l(!1),p(``),h(e.backup_codes)},onError:()=>n(e(`settings.twoFa.invalidCode`),`error`)}),F=J({mutationFn:e=>Q.deleteOIDCLink(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-links`]}),n(e(`settings.twoFa.oidcUnlinked`),`success`)},onError:e=>n(e.message,`error`)});if(O)return(0,K.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,K.jsx)(Cl,{className:`w-6 h-6 animate-spin text-bambu-green`})});let I=!!r?.email;return(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(pd,{id:`card-2fa-totp`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${D?.totp_enabled?`bg-green-500/20`:`bg-gray-500/20`}`,children:(0,K.jsx)(Yl,{className:`w-5 h-5 ${D?.totp_enabled?`text-green-400`:`text-gray-400`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.totpTitle`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.twoFa.totpDesc`)})]}),(0,K.jsx)(`div`,{className:`ml-auto`,children:D?.totp_enabled?(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-green-400 text-sm font-medium`,children:[(0,K.jsx)(Bl,{className:`w-4 h-4`}),` `,e(`common.enabled`)]}):(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray text-sm`,children:[(0,K.jsx)(Vl,{className:`w-4 h-4`}),` `,e(`common.disabled`)]})})]})}),(0,K.jsx)(hd,{children:i?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`h4`,{className:`text-white font-medium`,children:e(`settings.twoFa.setupAuthApp`)}),(0,K.jsx)(`button`,{onClick:()=>{a(!1),t.removeQueries({queryKey:[`totp-setup`]})},className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsx)(Tze,{onDone:()=>{a(!1),t.removeQueries({queryKey:[`totp-setup`]})}})]}):o?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.disableConfirmHint`)}),(0,K.jsx)(n7,{value:u,onChange:d,placeholder:`000000 or XXXXXXXX`,maxLength:8}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>{s(!1),d(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,K.jsx)($,{variant:`danger`,className:`flex-1`,disabled:u.length<6||N.isPending,onClick:()=>N.mutate(u),children:N.isPending?e(`common.saving`):e(`settings.twoFa.disableTotp`)})]})]}):c?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.regenBackupHint`)}),(0,K.jsx)(n7,{value:f,onChange:p,placeholder:`000000 or XXXXXXXX`,maxLength:8}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>{l(!1),p(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,K.jsx)($,{variant:`primary`,className:`flex-1`,disabled:f.length<6||P.isPending,onClick:()=>P.mutate(f),children:P.isPending?e(`common.saving`):e(`settings.twoFa.regenBackup`)})]})]}):m?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`h4`,{className:`text-white font-medium`,children:e(`settings.twoFa.newBackupCodes`)}),(0,K.jsx)(r7,{codes:m,onDone:()=>h(null)})]}):(0,K.jsx)(`div`,{className:`space-y-3`,children:D?.totp_enabled?(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray-light`,children:[(0,K.jsx)(jc,{className:`w-4 h-4`}),e(`settings.twoFa.backupCodesRemaining`,{count:D.backup_codes_remaining})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>l(!0),className:`flex items-center gap-2`,children:[(0,K.jsx)(Cl,{className:`w-4 h-4`}),e(`settings.twoFa.regenBackup`)]}),(0,K.jsxs)($,{variant:`danger`,size:`sm`,onClick:()=>s(!0),className:`flex items-center gap-2`,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`settings.twoFa.disableTotp`)]})]}):(0,K.jsxs)($,{variant:`primary`,onClick:()=>a(!0),className:`flex items-center gap-2`,children:[(0,K.jsx)(Yl,{className:`w-4 h-4`}),e(`settings.twoFa.setupTotp`)]})})})]}),(0,K.jsxs)(pd,{id:`card-2fa-emailotp`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${D?.email_otp_enabled?`bg-green-500/20`:`bg-gray-500/20`}`,children:(0,K.jsx)(Gc,{className:`w-5 h-5 ${D?.email_otp_enabled?`text-green-400`:`text-gray-400`}`})}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.emailOtpTitle`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:I?e(`settings.twoFa.emailOtpDesc`,{email:r?.email}):e(`settings.twoFa.emailOtpNoEmail`)})]}),(0,K.jsx)(`div`,{className:`ml-auto`,children:D?.email_otp_enabled?(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-green-400 text-sm font-medium`,children:[(0,K.jsx)(Bl,{className:`w-4 h-4`}),` `,e(`common.enabled`)]}):(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray text-sm`,children:[(0,K.jsx)(Vl,{className:`w-4 h-4`}),` `,e(`common.disabled`)]})})]})}),(0,K.jsx)(hd,{children:I?g?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.emailSetupEnterCode`)}),(0,K.jsx)(n7,{value:v,onChange:b,placeholder:`000000`}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>{_(null),b(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,K.jsx)($,{variant:`primary`,className:`flex-1`,disabled:v.length!==6||j.isPending,onClick:()=>j.mutate(),children:j.isPending?e(`common.saving`):e(`settings.twoFa.verifyAndEnable`)})]})]}):x?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.emailDisablePasswordHint`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{type:T?`text`:`password`,value:C,onChange:e=>w(e.target.value),placeholder:e(`settings.twoFa.passwordPlaceholder`),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>E(!T),className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:T?(0,K.jsx)(Ws,{className:`w-5 h-5`}):(0,K.jsx)(Gs,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>{S(!1),w(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,K.jsx)($,{variant:`danger`,className:`flex-1`,disabled:!C||M.isPending,onClick:()=>M.mutate(C),children:M.isPending?e(`common.saving`):e(`settings.twoFa.disableEmailOtp`)})]})]}):(0,K.jsx)(`div`,{className:`flex gap-3`,children:D?.email_otp_enabled?(0,K.jsxs)($,{variant:`danger`,size:`sm`,onClick:()=>S(!0),className:`flex items-center gap-2`,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`settings.twoFa.disableEmailOtp`)]}):(0,K.jsxs)($,{variant:`primary`,disabled:!I||A.isPending,onClick:()=>A.mutate(),className:`flex items-center gap-2`,children:[(0,K.jsx)(Gc,{className:`w-4 h-4`}),A.isPending?e(`common.saving`):e(`settings.twoFa.enableEmailOtp`)]})}):(0,K.jsx)(`p`,{className:`text-amber-400 text-sm`,children:e(`settings.twoFa.addEmailFirst`)})})]}),k&&k.length>0&&(0,K.jsxs)(pd,{id:`card-2fa-linked`,children:[(0,K.jsxs)(md,{children:[(0,K.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.linkedAccounts`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.twoFa.linkedAccountsDesc`)})]}),(0,K.jsx)(hd,{children:(0,K.jsx)(`div`,{className:`space-y-3`,children:k.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between py-2 border-b border-bambu-dark-tertiary last:border-0`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white text-sm font-medium`,children:e.provider_name}),e.provider_email&&(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:e.provider_email})]}),(0,K.jsx)($,{variant:`danger`,size:`sm`,onClick:()=>F.mutate(e.provider_id),disabled:F.isPending,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]},e.id))})})]})]})}var Dze={name:``,issuer_url:``,client_id:``,client_secret:``,scopes:`openid email profile`,is_enabled:!0,auto_create_users:!1,auto_link_existing_accounts:!1,email_claim:`email`,require_email_verified:!0,icon_url:void 0,default_group_id:null};function i7({initial:e,isEdit:t=!1,groups:n=[],onSave:r,onCancel:i,isPending:a}){let{t:o}=G(),[s,c]=(0,y.useState)(e),[l,u]=(0,y.useState)(!1),d=(e,t)=>c(n=>({...n,[e]:t})),f=`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors text-sm`,p=`block text-sm font-medium text-white mb-1`,m=()=>{let e={...s};t&&!l&&delete e.client_secret,r(e)},h=s.auto_link_existing_accounts===!0,g=s.require_email_verified??!0,_;return _=h?o(`settings.oidc.form.requireEmailVerifiedAutoLink`):g?o(`settings.oidc.form.requireEmailVerifiedDesc`):(0,K.jsx)(`span`,{className:`text-red-400`,children:o(`settings.oidc.form.requireEmailVerifiedWarning`)}),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.name`),` `,(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsx)(`input`,{className:f,value:s.name,onChange:e=>d(`name`,e.target.value),placeholder:`Google`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.issuerUrl`),` `,(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsx)(`input`,{className:f,value:s.issuer_url,onChange:e=>d(`issuer_url`,e.target.value),placeholder:`https://accounts.google.com`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.clientId`),` `,(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsx)(`input`,{className:f,value:s.client_id,onChange:e=>d(`client_id`,e.target.value),placeholder:`your-client-id`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.clientSecret`),!t&&(0,K.jsx)(`span`,{className:`text-red-400`,children:` *`}),t&&(0,K.jsxs)(`span`,{className:`text-bambu-gray text-xs ml-1`,children:[`(`,o(`settings.oidc.form.secretHint`),`)`]})]}),(0,K.jsx)(`input`,{className:f,type:`password`,value:l?s.client_secret:``,placeholder:t&&!l?`••••••••`:o(`settings.oidc.form.secretPlaceholder`),onChange:e=>{u(!0),d(`client_secret`,e.target.value)}})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:p,children:o(`settings.oidc.form.scopes`)}),(0,K.jsx)(`input`,{className:f,value:s.scopes,onChange:e=>d(`scopes`,e.target.value),placeholder:`openid email profile`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:p,children:o(`settings.oidc.form.iconUrl`)}),(0,K.jsx)(`input`,{className:f,value:s.icon_url??``,onChange:e=>d(`icon_url`,e.target.value===``?null:e.target.value),placeholder:`https://...`})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-6 pt-2`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(y5,{checked:s.is_enabled??!0,onChange:e=>d(`is_enabled`,e)}),(0,K.jsx)(`span`,{className:`text-white text-sm`,children:o(`settings.oidc.form.enabled`)})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(y5,{checked:s.auto_create_users??!1,onChange:e=>d(`auto_create_users`,e)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autoCreate`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autoCreateDesc`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,K.jsx)(y5,{checked:s.auto_link_existing_accounts??!1,onChange:e=>d(`auto_link_existing_accounts`,e)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autoLink`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autoLinkDesc`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,K.jsx)(y5,{checked:g,onChange:e=>d(`require_email_verified`,e),disabled:h}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.requireEmailVerified`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:_})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:p,children:o(`settings.oidc.form.emailClaim`)}),(0,K.jsx)(`input`,{className:f,value:s.email_claim,onChange:e=>d(`email_claim`,e.target.value||`email`),placeholder:o(`settings.oidc.form.emailClaimPlaceholder`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:o(`settings.oidc.form.emailClaimDesc`)}),h&&s.email_claim!==`email`&&(0,K.jsx)(`p`,{className:`text-yellow-400 text-xs mt-1`,children:o(`settings.oidc.form.emailClaimCustomClaimAutoLinkWarning`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:p,children:o(`settings.oidc.form.defaultGroup`)}),(0,K.jsxs)(`select`,{className:f,value:s.default_group_id??``,onChange:e=>d(`default_group_id`,e.target.value?Number(e.target.value):null),children:[(0,K.jsx)(`option`,{value:``,children:o(`settings.oidc.form.defaultGroupViewersFallback`)}),n.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:o(`settings.oidc.form.defaultGroupDesc`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:i,className:`flex-1`,children:o(`common.cancel`)}),(0,K.jsx)($,{variant:`primary`,className:`flex-1`,disabled:!s.name||!s.issuer_url||!s.client_id||!t&&!s.client_secret||t&&l&&!s.client_secret||a,onClick:m,children:o(a?`common.saving`:`common.save`)})]})]})}function Oze({provider:e}){let[t,n]=(0,y.useState)(!1);return e.has_icon&&!t?(0,K.jsx)(`img`,{src:Q.oidcProviderIconUrl(e.id),alt:e.name,className:`w-8 h-8 rounded object-contain`,onError:()=>n(!0)}):(0,K.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,K.jsx)(hc,{className:`w-4 h-4 text-bambu-gray`})})}function kze(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),{data:l,isLoading:u}=q({queryKey:[`oidc-providers-all`],queryFn:()=>Q.getOIDCProvidersAll()}),{data:d=[]}=q({queryKey:[`groups`],queryFn:()=>Q.getGroups()}),f=J({mutationFn:e=>Q.createOIDCProvider(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),i(!1),n(e(`settings.oidc.created`),`success`)},onError:e=>n(e.message,`error`)}),p=J({mutationFn:({id:e,data:t})=>Q.updateOIDCProvider(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),o(null),n(e(`settings.oidc.updated`),`success`)},onError:e=>n(e.message,`error`)}),m=J({mutationFn:e=>Q.deleteOIDCProvider(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),c(null),n(e(`settings.oidc.deleted`),`success`)},onError:e=>n(e.message,`error`)}),h=J({mutationFn:e=>Q.refreshOIDCProviderIcon(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),t.invalidateQueries({queryKey:[`oidc-providers`]}),n(e(`settings.oidc.iconRefreshed`),`success`)},onError:t=>n(t.message||e(`settings.oidc.iconFetchFailed`),`error`)}),g=J({mutationFn:e=>Q.deleteOIDCProviderIcon(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),t.invalidateQueries({queryKey:[`oidc-providers`]}),n(e(`settings.oidc.iconRemoved`),`success`)},onError:e=>n(e.message,`error`)}),_=e=>p.mutate({id:e.id,data:{is_enabled:!e.is_enabled}});return u?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,K.jsx)(Cl,{className:`w-6 h-6 animate-spin text-bambu-green`})}):(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(pd,{id:`card-oidc`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.oidc.title`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.oidc.desc`)})]}),!r&&(0,K.jsxs)($,{variant:`primary`,size:`sm`,onClick:()=>i(!0),className:`flex items-center gap-2`,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),e(`settings.oidc.addProvider`)]})]})}),r&&(0,K.jsx)(hd,{children:(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,K.jsx)(`h4`,{className:`text-white font-medium mb-4`,children:e(`settings.oidc.newProvider`)}),(0,K.jsx)(i7,{initial:Dze,groups:d,onSave:e=>f.mutate(e),onCancel:()=>i(!1),isPending:f.isPending})]})})]}),l&&l.length===0&&!r&&(0,K.jsx)(pd,{id:`card-oidc-empty`,children:(0,K.jsx)(hd,{children:(0,K.jsxs)(`div`,{className:`text-center py-8 space-y-3`,children:[(0,K.jsx)(hc,{className:`w-12 h-12 text-bambu-gray mx-auto`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.oidc.empty`)}),(0,K.jsxs)($,{variant:`primary`,size:`sm`,onClick:()=>i(!0),className:`inline-flex items-center gap-2`,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),e(`settings.oidc.addProvider`)]})]})})}),l?.map(t=>(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(Oze,{provider:t}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h4`,{className:`text-white font-medium`,children:t.name}),t.is_enabled?(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-green-400 bg-green-400/10 px-2 py-0.5 rounded-full`,children:[(0,K.jsx)($o,{className:`w-3 h-3`}),` `,e(`common.enabled`)]}):(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-0.5 rounded-full`,children:[(0,K.jsx)(Pu,{className:`w-3 h-3`}),` `,e(`common.disabled`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-bambu-gray text-xs mt-0.5`,children:[(0,K.jsx)(Us,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{children:t.issuer_url})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.icon_url&&(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>h.mutate(t.id),disabled:h.isPending,title:e(`settings.oidc.refreshIcon`),"data-testid":`refresh-icon-${t.id}`,children:(0,K.jsx)(Cl,{className:`w-4 h-4 ${h.isPending?`animate-spin`:``}`})}),t.has_icon&&(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>g.mutate(t.id),disabled:g.isPending,title:e(`settings.oidc.removeIcon`),"data-testid":`remove-icon-${t.id}`,children:(0,K.jsx)(Ec,{className:`w-4 h-4`})}),(0,K.jsx)(y5,{checked:t.is_enabled,onChange:()=>_(t),disabled:p.isPending}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>o(a===t.id?null:t.id),children:(0,K.jsx)(fl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`danger`,size:`sm`,onClick:()=>c(t),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]})}),a===t.id&&(0,K.jsx)(hd,{children:(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,K.jsx)(i7,{isEdit:!0,groups:d,initial:{name:t.name,issuer_url:t.issuer_url,client_id:t.client_id,client_secret:``,scopes:t.scopes,is_enabled:t.is_enabled,auto_create_users:t.auto_create_users,auto_link_existing_accounts:t.auto_link_existing_accounts,email_claim:t.email_claim,require_email_verified:t.require_email_verified,icon_url:t.icon_url??void 0,default_group_id:t.default_group_id??null},onSave:e=>p.mutate({id:t.id,data:e}),onCancel:()=>o(null),isPending:p.isPending})})}),a!==t.id&&(0,K.jsx)(hd,{children:(0,K.jsxs)(`dl`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-x-6 gap-y-2 text-sm`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.clientId`)}),(0,K.jsx)(`dd`,{className:`text-white font-mono truncate`,children:t.client_id})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.scopes`)}),(0,K.jsx)(`dd`,{className:`text-white`,children:t.scopes})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.autoCreate`)}),(0,K.jsx)(`dd`,{className:t.auto_create_users?`text-green-400`:`text-bambu-gray`,children:t.auto_create_users?e(`common.yes`):e(`common.no`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.autoLink`)}),(0,K.jsx)(`dd`,{className:t.auto_link_existing_accounts?`text-green-400`:`text-bambu-gray`,children:t.auto_link_existing_accounts?e(`common.yes`):e(`common.no`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.emailClaim`)}),(0,K.jsx)(`dd`,{className:`text-white font-mono`,children:t.email_claim})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.requireEmailVerified`)}),(0,K.jsx)(`dd`,{className:t.require_email_verified?`text-green-400`:`text-red-400`,children:t.require_email_verified?e(`common.yes`):e(`common.no`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.defaultGroup`)}),(0,K.jsx)(`dd`,{className:`text-white`,children:t.default_group_id?d.find(e=>e.id===t.default_group_id)?.name??e(`settings.oidc.form.defaultGroupViewersFallback`):e(`settings.oidc.form.defaultGroupViewersFallback`)})]})]})})]},t.id)),s&&(0,K.jsx)(Ed,{title:e(`settings.oidc.deleteTitle`),message:e(`settings.oidc.deleteMessage`,{name:s.name}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:()=>m.mutate(s.id),onCancel:()=>c(null)})]})}var a7=new Map;function o7(e){a7.set(e.anchor,e)}function Aze(){return Array.from(a7.values())}o7({labelKey:`settings.encryption.title`,labelFallback:`MFA Encryption Status`,tab:`users`,subTab:`security`,keywords:`mfa encryption status security backup totp oidc fernet`,anchor:`card-mfa-encryption`});function jze(){let{t:e}=G(),{data:t,isLoading:n,isError:r,refetch:i}=q({queryKey:[`encryptionStatus`],queryFn:()=>Q.getEncryptionStatus(),refetchInterval:e=>{if(!e.state.error)return 3e4;let t=e.state.fetchFailureCount??0;return t<=3?Math.min(5e3*Math.max(1,t),3e4):!1}});if(n)return(0,K.jsxs)(pd,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Hl,{className:`text-bambu-gray`,size:20}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,K.jsx)(hd,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,"data-testid":`encryption-loading`,children:[(0,K.jsx)(X,{className:`animate-spin`,size:16}),(0,K.jsx)(`span`,{children:e(`common.loading`)})]})})]});if(r||!t)return(0,K.jsxs)(pd,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Hl,{className:`text-bambu-gray`,size:20}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,K.jsxs)(hd,{children:[(0,K.jsx)(`div`,{className:`text-red-400`,"data-testid":`encryption-error`,children:e(`common.errorLoading`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>i(),className:`mt-2 text-sm text-blue-400 underline hover:text-blue-300`,"data-testid":`encryption-retry-button`,children:e(`common.retry`)})]})]});let a=t.legacy_plaintext_rows.oidc_providers+t.legacy_plaintext_rows.user_totp,o=t.encrypted_rows.oidc_providers+t.encrypted_rows.user_totp,s,c,l,u;t.decryption_broken?(s=`bg-red-500/20 border-red-500/50 text-red-400`,c=(0,K.jsx)(ms,{className:`text-red-400`,size:20}),l=e(`settings.encryption.decryptionBrokenTitle`),u=e(`settings.encryption.decryptionBrokenError`,{count:o})):t.key_source===`generated`?(s=`bg-amber-500/10 border-amber-500/30 text-amber-400`,c=(0,K.jsx)(Bl,{className:`text-amber-400`,size:20}),l=e(`settings.encryption.enabledGenerated`),u=e(`settings.encryption.backupHint`)):a>0?(s=`bg-amber-500/10 border-amber-500/30 text-amber-400`,c=(0,K.jsx)(vu,{className:`text-amber-400`,size:20}),l=t.key_source===`env`?e(`settings.encryption.enabledFromEnv`):e(`settings.encryption.enabledFromFile`),u=e(`settings.encryption.legacyRowsWarning`,{count:a})):t.key_configured?(s=`bg-green-500/20 border-green-500/30 text-green-400`,c=(0,K.jsx)(Bl,{className:`text-green-400`,size:20}),l=t.key_source===`env`?e(`settings.encryption.enabledFromEnv`):e(`settings.encryption.enabledFromFile`),u=e(`settings.encryption.allEncrypted`)):(s=`bg-gray-500/20 border-gray-500/30 text-gray-400`,c=(0,K.jsx)(Vl,{className:`text-gray-400`,size:20}),l=e(`settings.encryption.notConfigured`),u=e(`settings.encryption.notConfiguredDesc`));let d=t.key_source===`generated`&&a>0;return(0,K.jsxs)(pd,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c,(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,K.jsxs)(hd,{children:[(0,K.jsxs)(`div`,{className:`p-3 border rounded-lg ${s}`,"data-testid":`encryption-status`,children:[(0,K.jsx)(`p`,{className:`font-medium mb-1`,children:l}),(0,K.jsx)(`p`,{className:`text-sm`,children:u})]}),d&&(0,K.jsx)(`div`,{className:`mt-2 p-3 border rounded-lg bg-amber-500/10 border-amber-500/30 text-amber-400`,"data-testid":`encryption-legacy-warning`,children:(0,K.jsx)(`p`,{className:`text-sm`,children:e(`settings.encryption.legacyRowsWarning`,{count:a})})}),t.migration_error_count>0&&(0,K.jsx)(`div`,{className:`mt-2 p-3 border rounded-lg bg-amber-500/10 border-amber-500/30 text-amber-400`,"data-testid":`encryption-migration-warning`,children:(0,K.jsx)(`p`,{className:`text-sm`,children:e(`settings.encryption.migrationErrorWarning`,{count:t.migration_error_count})})}),(0,K.jsxs)(`div`,{className:`mt-4 grid grid-cols-2 gap-4 text-sm`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.encryption.encryptedRowsLabel`)}),(0,K.jsxs)(`p`,{className:`font-medium`,children:[`OIDC: `,t.encrypted_rows.oidc_providers,` · TOTP: `,t.encrypted_rows.user_totp]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.encryption.legacyRowsLabel`)}),(0,K.jsxs)(`p`,{className:`font-medium`,children:[`OIDC: `,t.legacy_plaintext_rows.oidc_providers,` · TOTP: `,t.legacy_plaintext_rows.user_totp]})]})]})]})]})}var Mze={get:`bg-blue-500/20 text-blue-400 border-blue-500/30`,post:`bg-green-500/20 text-green-400 border-green-500/30`,put:`bg-yellow-500/20 text-yellow-400 border-yellow-500/30`,patch:`bg-orange-500/20 text-orange-400 border-orange-500/30`,delete:`bg-red-500/20 text-red-400 border-red-500/30`};function Nze(e,t){let n=t.replace(`#/`,``).split(`/`),r=e;for(let e of n)r=r[e];return r}function s7(e,t,n=0){if(n>5)return`...`;if(t.$ref)return s7(e,Nze(e,t.$ref),n+1);if(t.allOf){let r={};for(let i of t.allOf){let t=s7(e,i,n+1);typeof t==`object`&&t&&Object.assign(r,t)}return r}if(t.example!==void 0)return t.example;if(t.default!==void 0)return t.default;switch(t.type){case`string`:return t.enum?t.enum[0]:`string`;case`integer`:case`number`:return 0;case`boolean`:return!1;case`array`:return t.items?[s7(e,t.items,n+1)]:[];case`object`:if(t.properties){let r={};for(let[i,a]of Object.entries(t.properties))r[i]=s7(e,a,n+1);return r}return{};default:return null}}function Pze({path:e,method:t,spec:n,schema:r,apiKey:i}){let[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)({}),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!1);(0,y.useEffect)(()=>{if(a&&n.parameters){let e={};for(let t of n.parameters)t.schema?.default!==void 0&&(e[t.name]=String(t.schema.default));c(t=>({...e,...t}))}},[a,n.parameters]),(0,y.useEffect)(()=>{if(a&&n.requestBody?.content?.[`application/json`]?.schema&&!l){let e=n.requestBody.content[`application/json`].schema,t=s7(r,e);u(JSON.stringify(t,null,2))}},[a,n.requestBody,r,l]);let _=(()=>{let e=[];for(let t of n.parameters||[])if(t.in===`path`||t.required){let n=s[t.name];(n===void 0||n===``)&&e.push(t.name)}return e})(),v=async()=>{if(_.length>0){f({status:0,statusText:`Validation Error`,headers:{},body:`Missing required parameters: ${_.join(`, `)}`,duration:0});return}m(!0),f(null);try{let r=e,a=new URLSearchParams;for(let e of n.parameters||[]){let t=s[e.name];t!==void 0&&t!==``&&(e.in===`path`?r=r.replace(`{${e.name}}`,encodeURIComponent(t)):e.in===`query`&&a.append(e.name,t))}let o=a.toString(),c=`${r}${o?`?${o}`:``}`,u={"Content-Type":`application/json`};i&&(u[`X-API-Key`]=i);let d={method:t.toUpperCase(),headers:u};[`post`,`put`,`patch`].includes(t)&&l&&(d.body=l);let p=performance.now(),m=await fetch(c,d),h=Math.round(performance.now()-p),g={};m.headers.forEach((e,t)=>{g[t]=e});let _;_=m.headers.get(`content-type`)?.includes(`application/json`)?await m.json():await m.text(),f({status:m.status,statusText:m.statusText,headers:g,body:_,duration:h})}catch(e){f({status:0,statusText:`Network Error`,headers:{},body:e instanceof Error?e.message:`Unknown error`,duration:0})}finally{m(!1)}},b=async()=>{if(d){let e=typeof d.body==`string`?d.body:JSON.stringify(d.body,null,2);try{await navigator.clipboard.writeText(e),g(!0),setTimeout(()=>g(!1),2e3)}catch{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.left=`-999999px`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t),g(!0),setTimeout(()=>g(!1),2e3)}}},x=(n.parameters||[]).filter(e=>e.in===`path`),S=(n.parameters||[]).filter(e=>e.in===`query`),C=[`post`,`put`,`patch`].includes(t)&&n.requestBody;return(0,K.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`button`,{onClick:()=>o(!a),className:`w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left`,children:[a?(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}):(0,K.jsx)(ts,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${Mze[t]||`bg-gray-500/20 text-gray-400`}`,children:t}),(0,K.jsx)(`code`,{className:`text-sm text-white font-mono flex-1 truncate`,children:e}),n.summary&&(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray truncate max-w-[40%]`,children:n.summary})]}),a&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50`,children:[n.description&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n.description}),x.length>0&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Path Parameters`}),(0,K.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`label`,{className:`text-sm text-bambu-gray w-32 flex-shrink-0`,children:[e.name,e.required&&(0,K.jsx)(`span`,{className:`text-red-400 ml-1`,children:`*`})]}),(0,K.jsx)(`input`,{type:`text`,value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),placeholder:e.description||e.schema?.type||`value`,className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`})]},e.name))})]}),S.length>0&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Query Parameters`}),(0,K.jsx)(`div`,{className:`space-y-2`,children:S.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`label`,{className:`text-sm text-bambu-gray w-32 flex-shrink-0`,children:[e.name,e.required&&(0,K.jsx)(`span`,{className:`text-red-400 ml-1`,children:`*`})]}),e.schema?.enum?(0,K.jsxs)(`select`,{value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:``,children:`-- Select --`}),e.schema.enum.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}):(0,K.jsx)(`input`,{type:`text`,value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),placeholder:e.description||e.schema?.type||`value`,className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`})]},e.name))})]}),C&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Request Body`}),(0,K.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),rows:8,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono focus:border-bambu-green focus:outline-none resize-y`,placeholder:`JSON request body...`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)($,{onClick:v,disabled:p,children:[p?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hl,{className:`w-4 h-4`}),`Execute`]}),_.length>0&&(0,K.jsxs)(`span`,{className:`text-xs text-yellow-400 flex items-center gap-1`,children:[(0,K.jsx)(ss,{className:`w-3 h-3`}),`Fill in: `,_.join(`, `)]})]}),d&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`h4`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[`Response`,(0,K.jsxs)(`span`,{className:`px-2 py-0.5 text-xs rounded ${d.status>=200&&d.status<300?`bg-green-500/20 text-green-400`:d.status>=400?`bg-red-500/20 text-red-400`:`bg-yellow-500/20 text-yellow-400`}`,children:[d.status,` `,d.statusText]}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[d.duration,`ms`]})]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:b,children:h?(0,K.jsx)(ls,{className:`w-3 h-3 text-green-400`}):(0,K.jsx)(Ds,{className:`w-3 h-3`})})]}),(0,K.jsx)(`pre`,{className:`p-3 bg-bambu-dark rounded-lg text-sm font-mono text-white overflow-auto max-h-96 border border-bambu-dark-tertiary`,children:typeof d.body==`string`?d.body:JSON.stringify(d.body,null,2)})]})]})]})}function Fze({apiKey:e=``}){let[t,n]=(0,y.useState)(null),[r,i]=(0,y.useState)(!0),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(new Set),[l,u]=(0,y.useState)(``);if((0,y.useEffect)(()=>{async function e(){try{let e=await fetch(`/openapi.json`);if(!e.ok)throw Error(`Failed to fetch OpenAPI schema`);n(await e.json())}catch(e){o(e instanceof Error?e.message:`Unknown error`)}finally{i(!1)}}e()},[]),r)return(0,K.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(a||!t)return(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-8`,children:(0,K.jsxs)(`div`,{className:`text-center text-red-400`,children:[(0,K.jsx)(ss,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,K.jsx)(`p`,{children:`Failed to load API schema`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:a})]})})});let d={};for(let[e,n]of Object.entries(t.paths))for(let[t,r]of Object.entries(n)){if(t===`parameters`)continue;let n=r.tags||[`Other`];for(let i of n)d[i]||(d[i]=[]),d[i].push({path:e,method:t,spec:r})}let f=Object.entries(d).map(([e,t])=>l?{tag:e,endpoints:t.filter(({path:e,method:t,spec:n})=>{let r=l.toLowerCase();return e.toLowerCase().includes(r)||t.toLowerCase().includes(r)||(n.summary?.toLowerCase()||``).includes(r)||(n.description?.toLowerCase()||``).includes(r)})}:{tag:e,endpoints:t}).filter(({endpoints:e})=>e.length>0).sort((e,t)=>e.tag.localeCompare(t.tag)),p=e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,K.jsx)(`div`,{className:`flex-1`,children:(0,K.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`Search endpoints...`,className:`w-full max-w-md px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>{c(new Set(f.map(e=>e.tag)))},children:`Expand All`}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>{c(new Set)},children:`Collapse All`}),(0,K.jsxs)(`a`,{href:`/docs`,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-sm text-bambu-green hover:underline`,children:[(0,K.jsx)(Us,{className:`w-4 h-4`}),`Swagger UI`]})]})]}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[f.reduce((e,t)=>e+t.endpoints.length,0),` endpoints in `,f.length,` categories`]}),(0,K.jsx)(`div`,{className:`space-y-3`,children:f.map(({tag:n,endpoints:r})=>(0,K.jsxs)(pd,{children:[(0,K.jsx)(`button`,{onClick:()=>p(n),className:`w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[s.has(n)?(0,K.jsx)(es,{className:`w-5 h-5 text-bambu-gray`}):(0,K.jsx)(ts,{className:`w-5 h-5 text-bambu-gray`}),(0,K.jsx)(`h3`,{className:`text-base font-semibold text-white capitalize`,children:n.replace(/-/g,` `)}),(0,K.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray`,children:r.length})]})}),s.has(n)&&(0,K.jsx)(hd,{className:`pt-0 space-y-2`,children:r.map(({path:n,method:r,spec:i})=>(0,K.jsx)(Pze,{path:n,method:r,spec:i,schema:t,apiKey:e},`${r}-${n}`))})]},n))})]})}var Ize=[`general`,`plugs`,`notifications`,`queue`,`filament`,`network`,`apikeys`,`virtual-printer`,`spoolbuddy`,`failure-detection`,`users`,`backup`];o7({labelKey:`settings.general`,tab:`general`,keywords:`language date time format printer model printers cards`,anchor:`card-general`}),o7({labelKey:`settings.appearance`,tab:`general`,keywords:`theme dark light mode colors`,anchor:`card-appearance`}),o7({labelKey:`settings.archiveSettings`,tab:`general`,keywords:`archive auto save thumbnails captures`,anchor:`card-archive`}),o7({labelKey:`settings.camera`,tab:`general`,keywords:`camera external video stream`,anchor:`card-camera`}),o7({labelKey:`settings.costTracking`,tab:`general`,keywords:`currency filament cost energy kwh price`,anchor:`card-cost`}),o7({labelKey:`settings.fileManager`,tab:`general`,keywords:`file manager archive mode disk warning storage`,anchor:`card-filemanager`}),o7({labelKey:`settings.updates`,tab:`general`,keywords:`updates version firmware beta check`,anchor:`card-updates`}),o7({labelKey:`settings.dataManagement`,tab:`general`,keywords:`data reset clear logs notifications preferences`,anchor:`card-data`}),o7({labelKey:`settings.smartPlugs`,tab:`plugs`,keywords:`smart plug energy power automation tapo kasa tplink shelly`,anchor:`card-plugs`}),o7({labelKey:`settings.providers`,tab:`notifications`,keywords:`telegram discord email notification providers webhook`,anchor:`card-providers`}),o7({labelKey:`settings.messageTemplates`,tab:`notifications`,keywords:`message templates notification text edit`,anchor:`card-templates`}),o7({labelKey:`settings.defaultPrintOptions`,labelFallback:`Default Print Options`,tab:`queue`,keywords:`print bed leveling flow calibration vibration first layer timelapse`,anchor:`card-print-options`}),o7({labelKey:`settings.tempFanPresetsTitle`,labelFallback:`Temperature & Fan Presets`,tab:`queue`,keywords:`temperature fan presets nozzle bed chamber quick buttons popover`,anchor:`card-temp-fan-presets`}),o7({labelKey:`settings.staggeredStart`,labelFallback:`Staggered Start`,tab:`queue`,keywords:`staggered batch delay start queue group`,anchor:`card-staggered`}),o7({labelKey:`settings.plateClear`,labelFallback:`Plate-Clear Confirmation`,tab:`queue`,keywords:`plate clear confirm auto queue`,anchor:`card-plate`}),o7({labelKey:`settings.gcodeInjection`,labelFallback:`G-code Injection`,tab:`queue`,keywords:`gcode injection start end autoprint farmloop swapmod autoclear printflow`,anchor:`card-gcode`}),o7({labelKey:`settings.slicerCard`,labelFallback:`Slicer`,tab:`queue`,keywords:`slicer orcaslicer bambustudio orca bambu api sidecar url docker preferred`,anchor:`card-slicer`}),o7({labelKey:`settings.queueDrying`,tab:`queue`,keywords:`drying presets temperature time humidity ams`,anchor:`card-drying`}),o7({labelKey:`settings.filamentChecks`,tab:`filament`,keywords:`filament check warning runout remaining`,anchor:`card-filamentchecks`}),o7({labelKey:`settings.printModal`,tab:`filament`,keywords:`print modal custom mapping`,anchor:`card-printmodal`}),o7({labelKey:`settings.amsDisplayThresholds`,tab:`filament`,keywords:`ams humidity temperature threshold history retention`,anchor:`card-amsthresholds`}),o7({labelKey:`settings.externalUrl`,tab:`network`,keywords:`external url reverse proxy public notification link`,anchor:`card-externalurl`}),o7({labelKey:`settings.ftpRetry`,tab:`network`,keywords:`ftp retry upload retries backoff`,anchor:`card-ftpretry`}),o7({labelKey:`settings.homeAssistant`,tab:`network`,keywords:`home assistant ha hass mqtt integration`,anchor:`card-ha`}),o7({labelKey:`settings.mqttPublishing`,tab:`network`,keywords:`mqtt publish broker topic`,anchor:`card-mqtt`}),o7({labelKey:`settings.prometheusMetrics`,tab:`network`,keywords:`prometheus metrics grafana monitoring bearer token`,anchor:`card-prometheus`}),o7({labelKey:`settings.createNewApiKey`,tab:`apikeys`,keywords:`api key create permission scope`,anchor:`card-createapi`}),o7({labelKey:`settings.webhookEndpoints`,tab:`apikeys`,keywords:`webhook endpoint post http`,anchor:`card-webhooks`}),o7({labelKey:`settings.apiBrowser`,tab:`apikeys`,keywords:`api browser endpoint documentation test`,anchor:`card-apibrowser`}),o7({labelKey:`cameraTokens.title`,tab:`apikeys`,keywords:`camera token long-lived home assistant frigate kiosk stream`,anchor:`card-camera-tokens`}),o7({labelKey:`settings.tabs.virtualPrinter`,tab:`virtual-printer`,keywords:`virtual printer proxy archive slicer bambustudio orcaslicer ip bind`,anchor:`card-vp`}),o7({labelKey:`settings.tabs.spoolbuddy`,tab:`spoolbuddy`,keywords:`spoolbuddy device scale nfc rfid kiosk unregister`,anchor:`card-spoolbuddy`}),o7({labelKey:`settings.currentUser`,tab:`users`,subTab:`users`,keywords:`current user profile password change`,anchor:`card-currentuser`}),o7({labelKey:`settings.users`,tab:`users`,subTab:`users`,keywords:`users accounts list`,anchor:`card-users`}),o7({labelKey:`settings.groups`,tab:`users`,subTab:`users`,keywords:`groups roles permissions administrators operators viewers`,anchor:`card-groups`}),o7({labelKey:`settings.sessionPolicy.title`,labelFallback:`Session Policy`,tab:`users`,subTab:`users`,keywords:`session timeout expiry logout remember me jwt token lifetime`,anchor:`card-session-policy`}),o7({labelKey:`settings.email.smtpSettings`,labelFallback:`SMTP Configuration`,tab:`users`,subTab:`email`,keywords:`smtp email send server port password auth starttls ssl`,anchor:`card-smtp`}),o7({labelKey:`settings.ldap.title`,labelFallback:`LDAP Authentication`,tab:`users`,subTab:`ldap`,keywords:`ldap active directory ad authentication bind dn search base group mapping`,anchor:`card-ldap`}),o7({labelKey:`settings.tabs.backup`,tab:`backup`,keywords:`backup github restore download cloud sync profiles archives`,anchor:`card-backup`}),o7({labelKey:`externalLinks.sidebarLayout`,labelFallback:`Sidebar`,tab:`general`,keywords:`sidebar layout links pages hide show external custom navigation url add`,anchor:`card-sidebar-links`}),o7({labelKey:`settings.filamentTracking`,tab:`filament`,keywords:`spoolman filament tracking inventory sync remote integration`,anchor:`card-spoolman`}),o7({labelKey:`settings.catalog.spoolCatalog`,labelFallback:`Spool Catalog`,tab:`filament`,keywords:`spool catalog entries brand material reset import export`,anchor:`card-spool-catalog`}),o7({labelKey:`settings.colorCatalog.title`,labelFallback:`Color Catalog`,tab:`filament`,keywords:`color catalog hex swatch palette sync reset`,anchor:`card-color-catalog`}),o7({labelKey:`settings.tabs.failureDetection`,labelFallback:`Failure Detection`,tab:`failure-detection`,keywords:`failure detection ai ml obico spaghetti detect monitoring`,anchor:`card-fd-ml`}),o7({labelKey:`failureDetection.perPrinterTitle`,labelFallback:`Per-Printer Settings`,tab:`failure-detection`,keywords:`failure detection per printer enable per-printer sensitivity`,anchor:`card-fd-perprinter`}),o7({labelKey:`failureDetection.statusTitle`,labelFallback:`Detection Status`,tab:`failure-detection`,keywords:`failure detection status running connection`,anchor:`card-fd-status`}),o7({labelKey:`failureDetection.historyTitle`,labelFallback:`Detection History`,tab:`failure-detection`,keywords:`failure detection history log events`,anchor:`card-fd-history`}),o7({labelKey:`settings.email.advancedAuth`,labelFallback:`Advanced Email Authentication`,tab:`users`,subTab:`email`,keywords:`email authentication advanced password reset self-service forgot`,anchor:`card-email-advanced-auth`}),o7({labelKey:`settings.email.testConnection`,labelFallback:`Test SMTP Connection`,tab:`users`,subTab:`email`,keywords:`email smtp test connection send check`,anchor:`card-email-test`}),o7({labelKey:`settings.twoFa.totpTitle`,labelFallback:`Authenticator App (TOTP)`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa totp authenticator app google authy otp`,anchor:`card-2fa-totp`}),o7({labelKey:`settings.twoFa.emailOtpTitle`,labelFallback:`Email One-Time Codes`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa email otp one time code`,anchor:`card-2fa-emailotp`}),o7({labelKey:`settings.twoFa.linkedAccounts`,labelFallback:`Linked Accounts`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa linked accounts sso oidc provider google github`,anchor:`card-2fa-linked`}),o7({labelKey:`settings.oidc.title`,labelFallback:`Single Sign-On (OIDC)`,tab:`users`,subTab:`oidc`,keywords:`sso oidc openid single sign-on pocketid authentik keycloak google okta azure provider`,anchor:`card-oidc`}),o7({labelKey:`settings.ldap.serverConfig`,labelFallback:`LDAP Server Configuration`,tab:`users`,subTab:`ldap`,keywords:`ldap server url bind dn user search base group filter tls`,anchor:`card-ldap-server`}),o7({labelKey:`backup.githubBackup`,labelFallback:`GitHub Backup`,tab:`backup`,keywords:`github backup cloud remote sync profiles token`,anchor:`card-backup-github`}),o7({labelKey:`backup.history`,labelFallback:`Backup History`,tab:`backup`,keywords:`backup history log runs github commits`,anchor:`card-backup-history`}),o7({labelKey:`backup.localBackup`,labelFallback:`Local Backup`,tab:`backup`,keywords:`local backup download zip manual export`,anchor:`card-backup-local`}),o7({labelKey:`backup.scheduledBackup`,labelFallback:`Scheduled Backups`,tab:`backup`,keywords:`scheduled backup automatic hourly daily weekly retention local path`,anchor:`card-backup-scheduled`});var Lze={database:`bg-blue-600`,library_files:`bg-green-500`,library_thumbnails:`bg-teal-500`,library_other:`bg-emerald-700`,archive_timelapses:`bg-red-500`,archive_thumbnails:`bg-amber-500`,archive_files:`bg-sky-500`,virtual_printer_uploads:`bg-purple-500`,virtual_printer_upload_cache:`bg-fuchsia-500`,virtual_printer_certs:`bg-violet-500`,virtual_printer_other:`bg-purple-700`,downloads:`bg-cyan-500`,plate_calibration:`bg-lime-500`,logs:`bg-orange-500`,other_data:`bg-yellow-500`},c7=[`bg-blue-500`,`bg-green-500`,`bg-yellow-500`,`bg-red-500`,`bg-orange-500`,`bg-teal-500`,`bg-cyan-500`,`bg-purple-500`],l7=(e,t)=>Lze[e]||c7[t%c7.length];function Rze(){let e=Qa(),t=Yn(),[n,r]=Oi(),{t:i,i18n:a}=G(),{showToast:o}=xd(),{authEnabled:s,user:c,isAdmin:l,refreshAuth:u,hasPermission:d}=sd(),{mode:f,resolvedMode:p,darkStyle:m,darkBackground:h,darkAccent:g,lightStyle:_,lightBackground:v,lightAccent:b,setMode:x,setDarkStyle:S,setDarkBackground:C,setDarkAccent:w,setLightStyle:T,setLightBackground:E,setLightAccent:D}=ud(),[O,k]=(0,y.useState)(null),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(null),[B,V]=(0,y.useState)(``),[ee,H]=(0,y.useState)(``),[te,ne]=(0,y.useState)(!1),[re,U]=(0,y.useState)(Jf()),ie=n.get(`tab`),ae=ie===`email`,[W,oe]=(0,y.useState)(ae?`users`:ie&&Ize.includes(ie)?ie:`general`),[se,ce]=(0,y.useState)(ae?`email`:`users`),le=e=>{oe(e),e===`users`&&ce(`users`),e===`general`?n.delete(`tab`):n.set(`tab`,e),r(n,{replace:!0})},[ue,de]=(0,y.useState)(!1),[fe,pe]=(0,y.useState)(``),[me,he]=(0,y.useState)({can_queue:!0,can_control_printer:!1,can_read_status:!0,can_manage_library:!0,can_manage_inventory:!0,can_access_cloud:!1,can_update_energy_cost:!1}),[ge,_e]=(0,y.useState)(null),[ve,ye]=(0,y.useState)(!1),[be,xe]=(0,y.useState)(null),[Se,Ce]=(0,y.useState)(``),[we,Te]=(0,y.useState)(!1),[Ee,De]=(0,y.useState)(!1),[Oe,ke]=(0,y.useState)(null),[Ae,je]=(0,y.useState)(!1),[Me,Ne]=(0,y.useState)(!1),[Pe,Fe]=(0,y.useState)(!1),[Ie,Le]=(0,y.useState)({currentPassword:``,newPassword:``,confirmPassword:``}),[Re,ze]=(0,y.useState)(!1),[Be,Ve]=(0,y.useState)(!1),[He,Ue]=(0,y.useState)(!1),[We,Ge]=(0,y.useState)(`local`),[Ke,qe]=(0,y.useState)(!1),[Je,Ye]=(0,y.useState)(null),[Xe,Ze]=(0,y.useState)(null),[Qe,$e]=(0,y.useState)(null),[et,tt]=(0,y.useState)(!1),[nt,rt]=(0,y.useState)({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),[it,at]=(0,y.useState)(null),[ot,st]=(0,y.useState)(null),[ct,lt]=(0,y.useState)(!1),[ut,dt]=(0,y.useState)({}),[ft,pt]=(0,y.useState)({}),mt=e=>{U(e),Yf(e),o(i(`settings.toast.settingsSaved`),`success`)},{data:ht,isLoading:gt}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:_t,isLoading:vt,isFetching:yt}=q({queryKey:[`storage-usage`],queryFn:()=>Q.getStorageUsage(),enabled:W===`general`,staleTime:1/0,refetchInterval:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1}),bt=async()=>{Ve(!0);try{let t=await Q.getStorageUsage({refresh:!0});e.setQueryData([`storage-usage`],t)}catch(e){o(e instanceof Error?e.message:`Failed to refresh storage usage`,`error`)}finally{Ve(!1)}},{data:xt,isLoading:St}=q({queryKey:[`smart-plugs`],queryFn:Q.getSmartPlugs}),{data:wt,isLoading:Tt}=q({queryKey:[`smart-plugs-energy`,xt?.map(e=>e.id)],queryFn:async()=>{if(!xt||xt.length===0)return null;let e=await Promise.all(xt.filter(e=>e.enabled).map(async e=>{try{return{plug:e,status:await Q.getSmartPlugStatus(e.id)}}catch{return{plug:e,status:null}}})),t=0,n=0,r=0,i=0,a=0;for(let{plug:o,status:s}of e){let e=o.plug_type===`mqtt`&&s?.energy?.power!=null;(s?.reachable||e)&&s?.energy&&(a++,s.energy?.power!=null&&(t+=s.energy.power),s.energy?.today!=null&&(n+=s.energy.today),s.energy?.yesterday!=null&&(r+=s.energy.yesterday),s.energy?.total!=null&&(i+=s.energy.total))}return{totalPower:t,totalToday:n,totalYesterday:r,totalLifetime:i,reachableCount:a,totalPlugs:xt.filter(e=>e.enabled).length}},enabled:W===`plugs`&&!!xt&&xt.length>0,refetchInterval:W===`plugs`?1e4:!1}),{data:Et,isLoading:Dt}=q({queryKey:[`notification-providers`],queryFn:Q.getNotificationProviders}),{data:Ot,isLoading:kt}=q({queryKey:[`api-keys`],queryFn:Q.getAPIKeys}),At=J({mutationFn:e=>Q.createAPIKey(e),onSuccess:t=>{_e(t.key||null),de(!1),pe(``),e.invalidateQueries({queryKey:[`api-keys`]}),o(i(`settings.toast.apiKeyCreated`))},onError:e=>{o(`Failed to create API key: ${e.message}`,`error`)}}),jt=J({mutationFn:e=>Q.deleteAPIKey(e),onSuccess:(t,n)=>{e.setQueryData([`api-keys`],e=>(e??[]).filter(e=>e.id!==n)),o(i(`settings.toast.apiKeyDeleted`))},onError:e=>{o(`Failed to delete API key: ${e.message}`,`error`)}}),{data:Mt}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:Nt,isLoading:Pt}=q({queryKey:[`notification-templates`],queryFn:Q.getNotificationTemplates}),{data:Ft}=q({queryKey:[`virtual-printer-settings`],queryFn:Zu.getSettings,refetchInterval:1e4}),It=Ft?.status?.running??!1,{data:Lt}=q({queryKey:[`spoolbuddy-devices`],queryFn:()=>nd.getDevices(),refetchInterval:15e3}),Rt=Lt?.length??0,zt=Lt?.some(e=>e.online)??!1,{data:Bt}=q({queryKey:[`obico-status`],queryFn:Q.getObicoStatus,refetchInterval:15e3}),Vt=!!(Bt?.is_running&&Bt?.enabled),{data:Ht}=q({queryKey:[`ffmpeg-status`],queryFn:Q.checkFfmpeg}),{data:Ut}=q({queryKey:[`version`],queryFn:Q.getVersion}),Wt=!s||d(`library:purge`),{data:Gt}=q({queryKey:[`library-trash-settings`],queryFn:()=>Q.getLibraryTrashSettings(),enabled:Wt}),Kt=J({mutationFn:e=>Q.updateLibraryTrashSettings(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`library-trash-settings`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>o(e.message||i(`libraryAutoPurge.saveFailed`),`error`)}),qt=e=>{Gt&&Kt.mutate({retention_days:Gt.retention_days,auto_purge_enabled:Gt.auto_purge_enabled,auto_purge_days:Gt.auto_purge_days,auto_purge_include_never_printed:Gt.auto_purge_include_never_printed,...e})},Jt=!s||d(`archives:purge`),{data:Yt}=q({queryKey:[`archive-purge-settings`],queryFn:()=>Q.getArchivePurgeSettings(),enabled:Jt}),Xt=J({mutationFn:e=>Q.updateArchivePurgeSettings(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`archive-purge-settings`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>o(e.message||i(`archiveAutoPurge.saveFailed`),`error`)}),Zt=e=>{Yt&&Xt.mutate({enabled:Yt.enabled,days:Yt.days,purge_stats:Yt.purge_stats,...e})},{data:Qt,refetch:$t,isRefetching:en}=q({queryKey:[`updateCheck`],queryFn:Q.checkForUpdates,enabled:ht?.check_updates!==!1,staleTime:300*1e3}),{data:tn,refetch:nn}=q({queryKey:[`updateStatus`],queryFn:Q.getUpdateStatus,refetchInterval:e=>{let t=e.state.data;return t?.status===`downloading`||t?.status===`installing`?1e3:!1}}),{data:rn}=q({queryKey:[`mqtt-status`],queryFn:Q.getMQTTStatus,refetchInterval:W===`network`?5e3:!1}),{data:an}=q({queryKey:[`github-backup-status`],queryFn:Q.getGitHubBackupStatus}),{data:on}=q({queryKey:[`cloud-status`],queryFn:Q.getCloudStatus}),{data:sn={advanced_auth_enabled:!1,smtp_configured:!1}}=q({queryKey:[`advancedAuthStatus`],queryFn:()=>Q.getAdvancedAuthStatus()}),{data:cn}=q({queryKey:[`ldapStatus`],queryFn:()=>Q.getLDAPStatus()}),{data:ln}=q({queryKey:[`twoFAStatus`],queryFn:()=>Q.get2FAStatus()}),{data:un=[]}=q({queryKey:[`oidcProvidersAll`],queryFn:()=>Q.getOIDCProvidersAll(),enabled:l}),{data:dn=[],isLoading:fn}=q({queryKey:[`users`],queryFn:()=>Q.getUsers(),enabled:s&&d(`users:read`)}),{data:pn=[],isLoading:mn}=q({queryKey:[`groups`],queryFn:()=>Q.getGroups(),enabled:s&&d(`groups:read`)}),hn=J({mutationFn:e=>Q.createUser(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),e.invalidateQueries({queryKey:[`groups`]}),Ue(!1),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`settings.toast.userCreated`))},onError:e=>{o(e.message,`error`)}}),gn=J({mutationFn:({id:e,data:t})=>Q.updateUser(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),e.invalidateQueries({queryKey:[`groups`]}),qe(!1),Ye(null),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`settings.toast.userUpdated`))},onError:e=>{o(e.message,`error`)}}),_n=J({mutationFn:({id:e,deleteItems:t})=>Q.deleteUser(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),o(i(`settings.toast.userDeleted`)),Ze(null),$e(null)},onError:e=>{o(e.message,`error`)}}),vn=J({mutationFn:e=>Q.resetUserPassword({user_id:e}),onSuccess:e=>{o(e.message,`success`)},onError:e=>{o(e.message,`error`)}}),yn=async e=>{Ze(e),tt(!0);try{$e(await Q.getUserItemsCount(e))}catch{$e({archives:0,queue_items:0,library_files:0})}finally{tt(!1)}},bn=J({mutationFn:e=>Q.deleteGroup(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`groups`]}),o(i(`settings.toast.groupDeleted`))},onError:e=>{o(e.message,`error`)}}),xn=()=>{let e=sn?.advanced_auth_enabled||!1;if(!nt.username){o(i(`settings.toast.fillRequiredFields`),`error`);return}if(e&&!nt.email){o(`Email is required when advanced authentication is enabled`,`error`);return}if(!e){if(!nt.password){o(i(`settings.toast.fillRequiredFields`),`error`);return}if(nt.password!==nt.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}let e=m5(nt.password);if(e){o(i({tooShort:`settings.toast.passwordTooShort`,needsUppercase:`settings.toast.passwordNeedsUppercase`,needsLowercase:`settings.toast.passwordNeedsLowercase`,needsDigit:`settings.toast.passwordNeedsDigit`,needsSpecial:`settings.toast.passwordNeedsSpecial`}[e]),`error`);return}}hn.mutate({username:nt.username,password:e?void 0:nt.password,email:nt.email||void 0,role:nt.role,group_ids:nt.group_ids.length>0?nt.group_ids:void 0})},Sn=e=>{if(nt.password){if(nt.password!==nt.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}let e=m5(nt.password);if(e){o(i({tooShort:`settings.toast.passwordTooShort`,needsUppercase:`settings.toast.passwordNeedsUppercase`,needsLowercase:`settings.toast.passwordNeedsLowercase`,needsDigit:`settings.toast.passwordNeedsDigit`,needsSpecial:`settings.toast.passwordNeedsSpecial`}[e]),`error`);return}}let t={username:nt.username||void 0,password:nt.password||void 0,email:nt.email||void 0,role:nt.role,group_ids:nt.group_ids};t.password||delete t.password,gn.mutate({id:e,data:t})},Cn=e=>{Ye(e.id),rt({username:e.username,password:``,email:e.email||``,confirmPassword:``,role:e.role,group_ids:e.groups?.map(e=>e.id)||[]}),qe(!0)},wn=e=>{rt(t=>({...t,group_ids:t.group_ids.includes(e)?t.group_ids.filter(t=>t!==e):[...t.group_ids,e]}))},Tn=J({mutationFn:Q.applyUpdate,onSuccess:e=>{e.is_ha_addon||e.is_docker||e.is_windows_installer?o(e.message,`error`):nn()}}),[En,Dn]=(0,y.useState)(null),On=J({mutationFn:Q.testAllNotificationProviders,onSuccess:t=>{Dn(t),e.invalidateQueries({queryKey:[`notification-providers`]}),t.failed===0?o(`All ${t.tested} providers tested successfully!`,`success`):o(`${t.success}/${t.tested} providers succeeded`,t.failed>0?`error`:`success`)},onError:e=>{o(`Failed to test providers: ${e.message}`,`error`)}}),kn=J({mutationFn:async e=>{if(!xt)return{success:0,failed:0};let t=xt.filter(e=>e.enabled),n=await Promise.all(t.map(async t=>{try{return await Q.controlSmartPlug(t.id,e),{success:!0}}catch{return{success:!1}}}));return{success:n.filter(e=>e.success).length,failed:n.filter(e=>!e.success).length}},onSuccess:(t,n)=>{e.invalidateQueries({queryKey:[`smart-plugs`]}),e.invalidateQueries({queryKey:[`smart-plugs-energy`]}),t.failed===0?o(`All ${t.success} plugs turned ${n}`,`success`):o(`${t.success} plugs turned ${n}, ${t.failed} failed`,`error`)},onError:e=>{o(`Failed: ${e.message}`,`error`)}}),An=(0,y.useRef)(null),jn=(0,y.useRef)(null),Mn=(0,y.useRef)(!1),Nn=(0,y.useRef)(!0);(0,y.useEffect)(()=>{ht&&!O&&(k({...ht,external_url:ht.external_url||window.location.origin}),setTimeout(()=>{Nn.current=!1},100))},[ht,O]);let Pn=J({mutationFn:Q.updateSettings,onSuccess:t=>{e.setQueryData([`settings`],t),e.invalidateQueries({queryKey:[`archiveStats`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>{o(`Failed to save: ${e.message}`,`error`)},onSettled:()=>{Mn.current=!1}}),Fn=J({mutationFn:({id:e,data:t})=>Q.updatePrinter(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`printers`]}),o(i(`settings.toast.cameraSettingsSaved`),`success`)},onError:e=>{o(`Failed to update printer: ${e.message}`,`error`)}});(0,y.useEffect)(()=>{if(!(Nn.current||!O||!ht)&&!(s&&!d(`settings:update`))&&(ht.auto_archive!==O.auto_archive||ht.save_thumbnails!==O.save_thumbnails||ht.capture_finish_photo!==O.capture_finish_photo||ht.default_filament_cost!==O.default_filament_cost||ht.currency!==O.currency||ht.energy_cost_per_kwh!==O.energy_cost_per_kwh||ht.energy_tracking_mode!==O.energy_tracking_mode||ht.check_updates!==O.check_updates||(ht.check_printer_firmware??!0)!==(O.check_printer_firmware??!0)||(ht.include_beta_updates??!1)!==(O.include_beta_updates??!1)||ht.notification_language!==O.notification_language||(ht.bed_cooled_threshold??35)!==(O.bed_cooled_threshold??35)||ht.ams_humidity_good!==O.ams_humidity_good||ht.ams_humidity_fair!==O.ams_humidity_fair||ht.ams_temp_good!==O.ams_temp_good||ht.ams_temp_fair!==O.ams_temp_fair||ht.ams_history_retention_days!==O.ams_history_retention_days||ht.disable_filament_warnings!==O.disable_filament_warnings||ht.prefer_lowest_filament!==O.prefer_lowest_filament||(ht.queue_drying_enabled??!1)!==(O.queue_drying_enabled??!1)||(ht.queue_drying_block??!1)!==(O.queue_drying_block??!1)||(ht.ambient_drying_enabled??!1)!==(O.ambient_drying_enabled??!1)||(ht.drying_presets??``)!==(O.drying_presets??``)||ht.per_printer_mapping_expanded!==O.per_printer_mapping_expanded||ht.date_format!==O.date_format||ht.time_format!==O.time_format||ht.default_printer_id!==O.default_printer_id||ht.ftp_retry_enabled!==O.ftp_retry_enabled||ht.ftp_retry_count!==O.ftp_retry_count||ht.ftp_retry_delay!==O.ftp_retry_delay||ht.ftp_timeout!==O.ftp_timeout||ht.mqtt_enabled!==O.mqtt_enabled||ht.mqtt_broker!==O.mqtt_broker||ht.mqtt_port!==O.mqtt_port||ht.mqtt_username!==O.mqtt_username||ht.mqtt_password!==O.mqtt_password||ht.mqtt_topic_prefix!==O.mqtt_topic_prefix||ht.mqtt_use_tls!==O.mqtt_use_tls||ht.external_url!==O.external_url||ht.ha_enabled!==O.ha_enabled||ht.ha_url!==O.ha_url||ht.ha_token!==O.ha_token||(ht.library_archive_mode??`ask`)!==(O.library_archive_mode??`ask`)||Number(ht.library_disk_warning_gb??5)!==Number(O.library_disk_warning_gb??5)||(ht.camera_view_mode??`window`)!==(O.camera_view_mode??`window`)||(ht.preferred_slicer??`bambu_studio`)!==(O.preferred_slicer??`bambu_studio`)||(ht.open_in_slicer??null)!==(O.open_in_slicer??null)||(ht.use_slicer_api??!1)!==(O.use_slicer_api??!1)||(ht.orcaslicer_api_url??``)!==(O.orcaslicer_api_url??``)||(ht.bambu_studio_api_url??``)!==(O.bambu_studio_api_url??``)||ht.prometheus_enabled!==O.prometheus_enabled||ht.prometheus_token!==O.prometheus_token||(ht.user_notifications_enabled??!0)!==(O.user_notifications_enabled??!0)||(ht.default_bed_levelling??!0)!==(O.default_bed_levelling??!0)||(ht.default_flow_cali??!1)!==(O.default_flow_cali??!1)||(ht.default_vibration_cali??!0)!==(O.default_vibration_cali??!0)||(ht.default_layer_inspect??!1)!==(O.default_layer_inspect??!1)||(ht.default_timelapse??!1)!==(O.default_timelapse??!1)||(ht.default_nozzle_offset_cali??!0)!==(O.default_nozzle_offset_cali??!0)||(ht.stagger_group_size??2)!==(O.stagger_group_size??2)||(ht.stagger_interval_minutes??5)!==(O.stagger_interval_minutes??5)||(ht.require_plate_clear??!1)!==(O.require_plate_clear??!1)||(ht.nozzle_temp_presets??``)!==(O.nozzle_temp_presets??``)||(ht.bed_temp_presets??``)!==(O.bed_temp_presets??``)||(ht.chamber_temp_presets??``)!==(O.chamber_temp_presets??``)||(ht.fan_speed_presets??``)!==(O.fan_speed_presets??``)||(ht.session_max_hours??24)!==(O.session_max_hours??24))&&!Mn.current)return An.current&&clearTimeout(An.current),An.current=setTimeout(()=>{if(Mn.current)return;Mn.current=!0;let e={auto_archive:O.auto_archive,save_thumbnails:O.save_thumbnails,capture_finish_photo:O.capture_finish_photo,default_filament_cost:O.default_filament_cost,currency:O.currency,energy_cost_per_kwh:O.energy_cost_per_kwh,energy_tracking_mode:O.energy_tracking_mode,check_updates:O.check_updates,check_printer_firmware:O.check_printer_firmware,include_beta_updates:O.include_beta_updates,notification_language:O.notification_language,bed_cooled_threshold:O.bed_cooled_threshold,ams_humidity_good:O.ams_humidity_good,ams_humidity_fair:O.ams_humidity_fair,ams_temp_good:O.ams_temp_good,ams_temp_fair:O.ams_temp_fair,ams_history_retention_days:O.ams_history_retention_days,disable_filament_warnings:O.disable_filament_warnings,prefer_lowest_filament:O.prefer_lowest_filament,queue_drying_enabled:O.queue_drying_enabled,queue_drying_block:O.queue_drying_block,ambient_drying_enabled:O.ambient_drying_enabled,drying_presets:O.drying_presets,per_printer_mapping_expanded:O.per_printer_mapping_expanded,date_format:O.date_format,time_format:O.time_format,default_printer_id:O.default_printer_id,ftp_retry_enabled:O.ftp_retry_enabled,ftp_retry_count:O.ftp_retry_count,ftp_retry_delay:O.ftp_retry_delay,ftp_timeout:O.ftp_timeout,mqtt_enabled:O.mqtt_enabled,mqtt_broker:O.mqtt_broker,mqtt_port:O.mqtt_port,mqtt_username:O.mqtt_username,mqtt_password:O.mqtt_password,mqtt_topic_prefix:O.mqtt_topic_prefix,mqtt_use_tls:O.mqtt_use_tls,external_url:O.external_url,ha_enabled:O.ha_enabled,ha_url:O.ha_url,ha_token:O.ha_token,library_archive_mode:O.library_archive_mode,library_disk_warning_gb:O.library_disk_warning_gb,camera_view_mode:O.camera_view_mode,preferred_slicer:O.preferred_slicer,open_in_slicer:O.open_in_slicer,use_slicer_api:O.use_slicer_api,orcaslicer_api_url:O.orcaslicer_api_url,bambu_studio_api_url:O.bambu_studio_api_url,prometheus_enabled:O.prometheus_enabled,prometheus_token:O.prometheus_token,user_notifications_enabled:O.user_notifications_enabled,default_bed_levelling:O.default_bed_levelling,default_flow_cali:O.default_flow_cali,default_vibration_cali:O.default_vibration_cali,default_layer_inspect:O.default_layer_inspect,default_timelapse:O.default_timelapse,default_nozzle_offset_cali:O.default_nozzle_offset_cali,stagger_group_size:O.stagger_group_size,stagger_interval_minutes:O.stagger_interval_minutes,require_plate_clear:O.require_plate_clear,nozzle_temp_presets:O.nozzle_temp_presets,bed_temp_presets:O.bed_temp_presets,chamber_temp_presets:O.chamber_temp_presets,fan_speed_presets:O.fan_speed_presets,session_max_hours:O.session_max_hours};Pn.mutate(e)},500),()=>{An.current&&clearTimeout(An.current)}},[O,ht,Pn,s,d,o,i]);let In=(0,y.useCallback)((e,t)=>{if(s&&!d(`settings:update`)){o(i(`settings.toast.noPermissionUpdate`),`error`);return}k(n=>n?{...n,[e]:t}:null)},[s,d,o,i]),Ln=async(e,t,n)=>{if(!t){o(i(`settings.toast.enterCameraUrl`),`error`);return}pt(t=>({...t,[e]:!0})),dt(t=>({...t,[e]:null}));try{let r=await Q.testExternalCamera(e,t,n);dt(t=>({...t,[e]:r})),r.success?o(i(`settings.toast.cameraConnected`,{resolution:r.resolution||``}),`success`):o(r.error||i(`settings.toast.connectionFailed`),`error`)}catch(t){let n=t instanceof Error?t.message:i(`settings.toast.testFailed`);dt(t=>({...t,[e]:{success:!1,error:n}})),o(n,`error`)}finally{pt(t=>({...t,[e]:!1}))}},[Rn,zn]=(0,y.useState)({}),Bn=(0,y.useRef)({}),Vn=(0,y.useRef)(new Set),[Hn,Un]=(0,y.useState)({}),Wn=(0,y.useRef)({}),Gn=(0,y.useRef)(new Set);(0,y.useEffect)(()=>{if(Mt){let e={},t={};Mt.forEach(n=>{n.external_camera_url&&!Vn.current.has(n.id)&&(e[n.id]=n.external_camera_url,Vn.current.add(n.id)),n.external_camera_snapshot_url&&!Gn.current.has(n.id)&&(t[n.id]=n.external_camera_snapshot_url,Gn.current.add(n.id))}),Object.keys(e).length>0&&zn(t=>({...t,...e})),Object.keys(t).length>0&&Un(e=>({...e,...t}))}},[Mt]);let Kn=(e,t)=>{zn(n=>({...n,[e]:t})),Bn.current[e]&&clearTimeout(Bn.current[e]),Bn.current[e]=setTimeout(()=>{Fn.mutate({id:e,data:{external_camera_url:t||null}})},800)},qn=(e,t)=>{Un(n=>({...n,[e]:t})),Wn.current[e]&&clearTimeout(Wn.current[e]),Wn.current[e]=setTimeout(()=>{Fn.mutate({id:e,data:{external_camera_snapshot_url:t||null}})},800)},Jn=(e,t)=>{let n={};t.type!==void 0&&(n.external_camera_type=t.type||null),t.enabled!==void 0&&(n.external_camera_enabled=t.enabled),t.rotation!==void 0&&(n.camera_rotation=t.rotation),Fn.mutate({id:e,data:n})};if(gt||!O)return(0,K.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})});let Xn=Aze().map(e=>({...e,label:i(e.labelKey,e.labelFallback??e.labelKey)})),Zn=ee.trim().toLowerCase(),Qn=Zn?Xn.filter(e=>e.label.toLowerCase().includes(Zn)||e.keywords.toLowerCase().includes(Zn)).slice(0,8):[],$n=e=>{le(e.tab),e.subTab&&ce(e.subTab),H(``),setTimeout(()=>{let t=document.getElementById(e.anchor);t&&(t.scrollIntoView({behavior:`smooth`,block:`start`}),t.classList.add(`ring-2`,`ring-bambu-green`),setTimeout(()=>t.classList.remove(`ring-2`,`ring-bambu-green`),1500))},50)};return(0,K.jsx)(fd,{density:`dense`,children:(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`mb-4 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3`,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)(Rl,{className:`w-7 h-7 text-bambu-green`}),i(`settings.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i(`settings.configureBambuddy`)})]}),(0,K.jsxs)(`div`,{className:`relative sm:w-72`,children:[(0,K.jsx)(Nl,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none`}),(0,K.jsx)(`input`,{type:`text`,value:ee,onChange:e=>H(e.target.value),placeholder:i(`settings.searchPlaceholder`,`Search settings…`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),ee&&(0,K.jsx)(`button`,{onClick:()=>H(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white`,"aria-label":`Clear`,children:(0,K.jsx)(Pu,{className:`w-3.5 h-3.5`})}),Qn.length>0&&(0,K.jsx)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 overflow-hidden`,children:Qn.map(e=>(0,K.jsxs)(`button`,{onClick:()=>$n(e),className:`w-full px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:e.label}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[i(`settings.tabs.${e.tab===`virtual-printer`?`virtualPrinter`:e.tab===`failure-detection`?`failureDetection`:e.tab}`),e.subTab?` › ${i(`settings.tabs.${e.subTab}`,e.subTab)}`:``]})]},e.anchor))}),Zn&&Qn.length===0&&(0,K.jsx)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 p-3`,children:(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray italic`,children:i(`settings.noSearchResults`,`No matching settings.`)})})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,K.jsxs)(`nav`,{className:`flex flex-wrap gap-1 border-b border-bambu-dark-tertiary lg:flex-col lg:flex-nowrap lg:gap-0 lg:border-b-0 lg:border-r lg:w-48 lg:flex-shrink-0 lg:self-start lg:sticky lg:top-4`,children:[(0,K.jsxs)(`button`,{onClick:()=>le(`general`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`general`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(Rl,{className:`w-4 h-4`}),i(`settings.tabs.general`)]}),(0,K.jsxs)(`button`,{onClick:()=>le(`plugs`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`plugs`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(gl,{className:`w-4 h-4`}),i(`settings.tabs.smartPlugs`),xt&&xt.length>0&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:xt.length})]}),(0,K.jsxs)(`button`,{onClick:()=>le(`notifications`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`notifications`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(Io,{className:`w-4 h-4`}),i(`settings.tabs.notifications`),Et&&Et.length>0&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:Et.length})]}),(0,K.jsxs)(`button`,{onClick:()=>le(`queue`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`queue`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(Rc,{className:`w-4 h-4`}),i(`settings.tabs.queue`,`Workflow`)]}),(0,K.jsxs)(`button`,{onClick:()=>le(`filament`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`filament`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(As,{className:`w-4 h-4`}),i(`settings.tabs.filament`)]}),(0,K.jsxs)(`button`,{onClick:()=>le(`network`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`network`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(ju,{className:`w-4 h-4`}),i(`settings.tabs.network`),(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${rn?.enabled?`bg-green-400`:`bg-gray-500`}`})]}),(0,K.jsxs)(`button`,{onClick:()=>le(`apikeys`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`apikeys`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(jc,{className:`w-4 h-4`}),i(`settings.tabs.apiKeys`),Ot&&Ot.length>0&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:Ot.length})]}),(0,K.jsxs)(`button`,{onClick:()=>le(`virtual-printer`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`virtual-printer`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(bl,{className:`w-4 h-4`}),i(`settings.tabs.virtualPrinter`),(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${It?`bg-green-400`:`bg-gray-500`}`})]}),(0,K.jsxs)(`button`,{onClick:()=>le(`spoolbuddy`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`spoolbuddy`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(kl,{className:`w-4 h-4`}),i(`settings.tabs.spoolbuddy`),Rt>0&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:Rt}),(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${zt?`bg-green-400`:`bg-gray-500`}`})]}),(0,K.jsxs)(`button`,{onClick:()=>le(`failure-detection`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`failure-detection`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(Al,{className:`w-4 h-4`}),i(`settings.tabs.failureDetection`),(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${Vt?`bg-green-400`:`bg-gray-500`}`})]}),(0,K.jsxs)(`button`,{onClick:()=>le(`users`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`users`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(wu,{className:`w-4 h-4`}),i(`settings.tabs.users`),s&&(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,K.jsxs)(`button`,{onClick:()=>le(`backup`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${W===`backup`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(js,{className:`w-4 h-4`}),i(`settings.tabs.backup`),(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${on?.is_authenticated&&an?.configured&&an?.enabled||ht?.local_backup_enabled?`bg-green-400`:`bg-gray-500`}`})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[W===`general`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`a`,{href:`https://bambuddy.cool/sponsors.html?from=app-settings`,target:`_blank`,rel:`noopener noreferrer`,className:`group block mb-4 lg:mb-6 rounded-xl border border-bambu-green/30 bg-gradient-to-br from-bambu-green/15 via-bambu-green/5 to-transparent hover:border-bambu-green/50 hover:from-bambu-green/20 transition-colors`,children:(0,K.jsxs)(`div`,{className:`flex flex-col md:flex-row items-start md:items-center gap-4 p-4 md:p-5`,children:[(0,K.jsx)(`div`,{className:`p-3 rounded-lg bg-bambu-green/20 text-bambu-green flex-shrink-0`,children:(0,K.jsx)(Cc,{className:`w-6 h-6`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-base font-semibold text-white`,children:i(`sponsors.sectionTitle`,`Independent & community-funded`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-0.5`,children:i(`sponsors.tagline`,`Bambuddy is free and stays that way because people choose to support it. No VC, no cloud lock-in.`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 rounded-lg bg-bambu-green/20 text-bambu-green group-hover:bg-bambu-green/30 text-sm font-medium whitespace-nowrap self-start md:self-auto`,children:[i(`sponsors.viewSupporters`,`View supporters`),(0,K.jsx)(Us,{className:`w-4 h-4`})]})]})}),(0,K.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,K.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,K.jsxs)(pd,{id:`card-general`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.general`)})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,K.jsx)(hc,{className:`w-4 h-4 inline mr-1`}),i(`settings.language`)]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`select`,{value:a.language,onChange:e=>{let t=e.target.value;if(s&&!d(`settings:update`)){o(i(`settings.toast.noPermissionUpdate`),`error`);return}a.changeLanguage(t),Pn.mutate({language:t})},className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:Ct.map(e=>(0,K.jsxs)(`option`,{value:e.code,children:[e.nativeName,` (`,e.name,`)`]},e.code))}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.languageDescription`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultView`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`select`,{value:re,onChange:e=>mt(e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:qf.map(e=>(0,K.jsx)(`option`,{value:e.to,children:i(e.labelKey)},e.id))}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.defaultViewDescription`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.dateFormat`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:O.date_format||`system`,onChange:e=>In(`date_format`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,K.jsx)(`option`,{value:`system`,children:i(`settings.systemDefault`)}),(0,K.jsx)(`option`,{value:`us`,children:i(`settings.dateFormatUs`)}),(0,K.jsx)(`option`,{value:`eu`,children:i(`settings.dateFormatEu`)}),(0,K.jsx)(`option`,{value:`iso`,children:i(`settings.dateFormatIso`)})]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.timeFormat`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:O.time_format||`system`,onChange:e=>In(`time_format`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,K.jsx)(`option`,{value:`system`,children:i(`settings.systemDefault`)}),(0,K.jsx)(`option`,{value:`12h`,children:i(`settings.timeFormat12`)}),(0,K.jsx)(`option`,{value:`24h`,children:i(`settings.timeFormat24`)})]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultPrinter`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:O.default_printer_id??``,onChange:e=>In(`default_printer_id`,e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,K.jsx)(`option`,{value:``,children:i(`settings.noDefaultPrinter`)}),Mt?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.defaultPrinterDescription`)})]})]})]}),(0,K.jsxs)(pd,{id:`card-appearance`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(ll,{className:`w-5 h-5`}),i(`settings.appearance`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsxs)(`label`,{className:`text-sm text-bambu-gray`,children:[i(`settings.theme`),`:`]}),(0,K.jsx)(`div`,{className:`flex gap-1`,children:[{id:`dark`,label:i(`settings.themeDark`)},{id:`light`,label:i(`settings.themeLight`)},{id:`system`,label:i(`settings.themeSystem`)}].map(({id:e,label:t})=>(0,K.jsx)(`button`,{onClick:()=>{x(e),o(i(`settings.toast.settingsSaved`),`success`)},className:`px-3 py-1 text-xs rounded-lg border transition-colors ${f===e?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-gray-300 dark:border-bambu-dark-tertiary text-gray-500 dark:text-bambu-gray hover:text-gray-900 dark:hover:text-white cursor-pointer`}`,children:t},e))})]}),(0,K.jsxs)(`div`,{className:`space-y-3 p-4 rounded-lg border ${p===`dark`?`border-bambu-green bg-bambu-green/5`:`border-bambu-dark-tertiary`}`,children:[(0,K.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[i(`settings.darkMode`),p===`dark`&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.active`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.background`)}),(0,K.jsxs)(`select`,{value:h,onChange:e=>{C(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`neutral`,children:i(`settings.bgNeutral`)}),(0,K.jsx)(`option`,{value:`warm`,children:i(`settings.bgWarm`)}),(0,K.jsx)(`option`,{value:`cool`,children:i(`settings.bgCool`)}),(0,K.jsx)(`option`,{value:`oled`,children:i(`settings.bgOled`)}),(0,K.jsx)(`option`,{value:`slate`,children:i(`settings.bgSlate`)}),(0,K.jsx)(`option`,{value:`forest`,children:i(`settings.bgForest`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.accent`)}),(0,K.jsxs)(`select`,{value:g,onChange:e=>{w(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`green`,children:i(`settings.accentGreen`)}),(0,K.jsx)(`option`,{value:`teal`,children:i(`settings.accentTeal`)}),(0,K.jsx)(`option`,{value:`blue`,children:i(`settings.accentBlue`)}),(0,K.jsx)(`option`,{value:`orange`,children:i(`settings.accentOrange`)}),(0,K.jsx)(`option`,{value:`purple`,children:i(`settings.accentPurple`)}),(0,K.jsx)(`option`,{value:`red`,children:i(`settings.accentRed`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.style`)}),(0,K.jsxs)(`select`,{value:m,onChange:e=>{S(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`classic`,children:i(`settings.styleClassic`)}),(0,K.jsx)(`option`,{value:`glow`,children:i(`settings.styleGlow`)}),(0,K.jsx)(`option`,{value:`vibrant`,children:i(`settings.styleVibrant`)})]})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3 p-4 rounded-lg border ${p===`light`?`border-bambu-green bg-bambu-green/5`:`border-bambu-dark-tertiary`}`,children:[(0,K.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[i(`settings.lightMode`),p===`light`&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.active`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.background`)}),(0,K.jsxs)(`select`,{value:v,onChange:e=>{E(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`neutral`,children:i(`settings.bgNeutral`)}),(0,K.jsx)(`option`,{value:`warm`,children:i(`settings.bgWarm`)}),(0,K.jsx)(`option`,{value:`cool`,children:i(`settings.bgCool`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.accent`)}),(0,K.jsxs)(`select`,{value:b,onChange:e=>{D(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`green`,children:i(`settings.accentGreen`)}),(0,K.jsx)(`option`,{value:`teal`,children:i(`settings.accentTeal`)}),(0,K.jsx)(`option`,{value:`blue`,children:i(`settings.accentBlue`)}),(0,K.jsx)(`option`,{value:`orange`,children:i(`settings.accentOrange`)}),(0,K.jsx)(`option`,{value:`purple`,children:i(`settings.accentPurple`)}),(0,K.jsx)(`option`,{value:`red`,children:i(`settings.accentRed`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.style`)}),(0,K.jsxs)(`select`,{value:_,onChange:e=>{T(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`classic`,children:i(`settings.styleClassic`)}),(0,K.jsx)(`option`,{value:`glow`,children:i(`settings.styleGlow`)}),(0,K.jsx)(`option`,{value:`vibrant`,children:i(`settings.styleVibrant`)})]})]})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.themeToggleHint`)})]})]}),(0,K.jsxs)(pd,{id:`card-archive`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.archiveSettings`)})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.autoArchivePrints`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoArchiveDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.auto_archive,onChange:e=>In(`auto_archive`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.saveThumbnails`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.saveThumbnailsDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.save_thumbnails,onChange:e=>In(`save_thumbnails`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.captureFinishPhoto`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.captureFinishPhotoDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.capture_finish_photo,onChange:e=>In(`capture_finish_photo`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),O.capture_finish_photo&&Ht&&!Ht.installed&&(0,K.jsxs)(`div`,{className:`flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg`,children:[(0,K.jsx)(vu,{className:`w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`text-sm`,children:[(0,K.jsx)(`p`,{className:`text-yellow-500 font-medium`,children:i(`settings.ffmpegNotInstalled`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i(`settings.ffmpegRequired`)})]})]}),Jt&&Yt&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`archiveAutoPurge.enableLabel`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`archiveAutoPurge.enableDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:Yt.enabled,onChange:e=>Zt({enabled:e.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`archiveAutoPurge.ageLabel`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,min:7,max:3650,disabled:!Yt.enabled,value:Yt.days,onChange:e=>Zt({days:Math.max(7,Math.min(3650,parseInt(e.target.value||`0`,10)||0))}),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`archiveAutoPurge.days`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`archiveAutoPurge.ageDescription`)})]}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,disabled:!Yt.enabled,checked:Yt.purge_stats,onChange:e=>Zt({purge_stats:e.target.checked}),className:`mt-0.5 shrink-0 disabled:opacity-50`}),(0,K.jsxs)(`span`,{className:`text-sm`,children:[(0,K.jsx)(`span`,{className:`text-white block`,children:i(`archiveAutoPurge.purgeStatsLabel`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray block mt-0.5`,children:i(`archiveAutoPurge.purgeStatsDescription`)})]})]})]})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-md`,children:[(0,K.jsxs)(pd,{id:`card-camera`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Tu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.camera`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.cameraViewMode`)}),(0,K.jsxs)(`select`,{value:O.camera_view_mode??`window`,onChange:e=>In(`camera_view_mode`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`window`,children:i(`settings.newWindow`)}),(0,K.jsx)(`option`,{value:`embedded`,children:i(`settings.embeddedOverlay`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:O.camera_view_mode===`embedded`?i(`settings.cameraOverlayDescription`):i(`settings.cameraWindowDescription`)})]}),(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 mt-4`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-2`,children:i(`settings.externalCameras`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:i(`settings.externalCamerasDescription`)}),Mt&&Mt.length>0?(0,K.jsx)(`div`,{className:`space-y-3`,children:Mt.map(e=>(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.external_camera_enabled,onChange:t=>Jn(e.id,{enabled:t.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.external_camera_enabled&&(0,K.jsxs)(`div`,{className:`space-y-2 mt-2`,children:[(0,K.jsx)(`input`,{type:`text`,placeholder:e.external_camera_type===`usb`?i(`settings.cameraPlaceholderUsb`):i(`settings.cameraPlaceholderUrl`),value:Rn[e.id]??e.external_camera_url??``,onChange:t=>Kn(e.id,t.target.value),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`select`,{value:e.external_camera_type||`mjpeg`,onChange:t=>Jn(e.id,{type:t.target.value}),className:`flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`mjpeg`,children:i(`settings.cameraTypeMjpeg`)}),(0,K.jsx)(`option`,{value:`rtsp`,children:i(`settings.cameraTypeRtsp`)}),(0,K.jsx)(`option`,{value:`snapshot`,children:i(`settings.cameraTypeSnapshot`)}),(0,K.jsx)(`option`,{value:`usb`,children:i(`settings.cameraTypeUsb`)})]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>Ln(e.id,Rn[e.id]??e.external_camera_url??``,e.external_camera_type||`mjpeg`),disabled:ft[e.id]||!(Rn[e.id]??e.external_camera_url),children:ft[e.id]?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):i(`settings.test`)})]}),ut[e.id]&&(0,K.jsx)(`div`,{className:`text-xs flex items-center gap-1 ${ut[e.id]?.success?`text-green-500`:`text-red-500`}`,children:ut[e.id]?.success?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ls,{className:`w-3 h-3`}),i(`settings.connected`),ut[e.id]?.resolution&&` (${ut[e.id]?.resolution})`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ms,{className:`w-3 h-3`}),ut[e.id]?.error||i(`settings.toast.connectionFailed`)]})}),(e.external_camera_type===`mjpeg`||e.external_camera_type===`rtsp`||e.external_camera_type===`usb`)&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:i(`settings.cameraSnapshotUrl`,`Snapshot URL (optional)`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,placeholder:i(`settings.cameraSnapshotUrlPlaceholder`,`http://192.168.1.61:1984/api/frame.jpeg?src=printer`),value:Hn[e.id]??e.external_camera_snapshot_url??``,onChange:t=>qn(e.id,t.target.value),className:`flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>Ln(e.id,Hn[e.id]??e.external_camera_snapshot_url??``,`snapshot`),disabled:ft[e.id]||!(Hn[e.id]??e.external_camera_snapshot_url),children:ft[e.id]?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):i(`settings.test`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray opacity-75`,children:i(`settings.cameraSnapshotUrlHelp`,`Single-frame URL used for notification thumbnails, finish photos, timelapse and plate detection. Leave blank to capture from the live stream above. Useful for go2rtc (/api/frame.jpeg) and IP cameras with a dedicated snapshot endpoint.`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:i(`settings.cameraRotation`)}),(0,K.jsxs)(`select`,{value:e.camera_rotation||0,onChange:t=>Jn(e.id,{rotation:parseInt(t.target.value)}),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:0,children:`0°`}),(0,K.jsx)(`option`,{value:90,children:`90°`}),(0,K.jsx)(`option`,{value:180,children:`180°`}),(0,K.jsx)(`option`,{value:270,children:`270°`})]})]})]})]},e.id))}):(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray italic`,children:i(`settings.noPrintersConfigured`)})]})]})]}),(0,K.jsxs)(pd,{id:`card-cost`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.costTracking`)})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.currency`)}),(0,K.jsx)(`select`,{value:O.currency,onChange:e=>In(`currency`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:Xd.map(e=>(0,K.jsx)(`option`,{value:e.code,children:e.label},e.code))})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultFilamentCost`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:Yd(O.currency)}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:O.default_filament_cost,onChange:e=>In(`default_filament_cost`,parseFloat(e.target.value)||0),style:{paddingLeft:`${Math.max(2,Yd(O.currency).length*.6+1)}rem`},className:`w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.electricityCost`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:Yd(O.currency)}),(0,K.jsx)(`input`,{type:`number`,step:`0.001`,min:`0`,value:O.energy_cost_per_kwh,onChange:e=>In(`energy_cost_per_kwh`,parseFloat(e.target.value)||0),style:{paddingLeft:`${Math.max(2,Yd(O.currency).length*.6+1)}rem`},className:`w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.energyDisplayMode`)}),(0,K.jsxs)(`select`,{value:O.energy_tracking_mode||`total`,onChange:e=>In(`energy_tracking_mode`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`print`,children:i(`settings.printsOnly`)}),(0,K.jsx)(`option`,{value:`total`,children:i(`settings.totalConsumption`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:O.energy_tracking_mode===`print`?i(`settings.energyModePrintDescription`):i(`settings.energyModeTotalDescription`)})]})]})]}),(0,K.jsxs)(pd,{id:`card-filemanager`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Zs,{className:`w-5 h-5 text-bambu-green`}),i(`settings.fileManager`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.createArchiveEntry`)}),(0,K.jsxs)(`select`,{value:O.library_archive_mode??`ask`,onChange:e=>In(`library_archive_mode`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`always`,children:i(`settings.archiveMode.always`)}),(0,K.jsx)(`option`,{value:`never`,children:i(`settings.archiveMode.never`)}),(0,K.jsx)(`option`,{value:`ask`,children:i(`settings.archiveMode.ask`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.createArchiveEntryDescription`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.lowDiskSpaceWarning`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,min:`0.5`,max:`100`,step:`0.5`,value:O.library_disk_warning_gb??5,onChange:e=>In(`library_disk_warning_gb`,parseFloat(e.target.value)||5),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`GB`})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.lowDiskSpaceDescription`)})]}),Wt&&Gt&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`libraryAutoPurge.enableLabel`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`libraryAutoPurge.enableDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:Gt.auto_purge_enabled,onChange:e=>qt({auto_purge_enabled:e.target.checked}),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`libraryAutoPurge.ageLabel`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,min:7,max:3650,disabled:!Gt.auto_purge_enabled,value:Gt.auto_purge_days,onChange:e=>qt({auto_purge_days:Math.max(7,Math.min(3650,parseInt(e.target.value||`0`,10)||0))}),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`libraryAutoPurge.days`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`libraryAutoPurge.ageDescription`)})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-white cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,disabled:!Gt.auto_purge_enabled,checked:Gt.auto_purge_include_never_printed,onChange:e=>qt({auto_purge_include_never_printed:e.target.checked}),className:`rounded border-gray-300 disabled:opacity-50`}),i(`libraryAutoPurge.includeNeverPrinted`)]})]})]})]}),(0,K.jsxs)(pd,{id:`card-data`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.dataManagement`)})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.clearNotificationLogs`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.clearNotificationLogsDescription`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>Te(!0),children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),i(`common.clear`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.resetUiPreferences`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.resetUiPreferencesDescription`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>De(!0),children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),i(`settings.reset`)]})]}),(0,K.jsxs)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.storageUsage`,`Storage Usage`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.storageUsageDescription`,`Breakdown of data usage by category`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:bt,disabled:yt||Be,children:[(0,K.jsx)(Cl,{className:`w-4 h-4 ${yt||Be?`animate-spin`:``}`}),i(`common.refresh`,`Refresh`)]})]}),(0,K.jsx)(`div`,{className:`mt-3`,children:vt?(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`}),i(`common.loading`,`Loading`)]}):_t?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`w-full h-3 bg-bambu-dark rounded-full overflow-hidden flex`,children:_t.categories.filter(e=>e.bytes>0).map((e,t)=>(0,K.jsx)(`div`,{className:`${l7(e.key,t)} h-full`,style:{width:`${e.percent_of_total}%`},title:`${e.label}: ${e.formatted}`},e.key))}),(0,K.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-3`,children:_t.categories.filter(e=>e.bytes>0).map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full ${l7(e.key,t)}`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e.label}),(0,K.jsx)(`span`,{className:`text-white`,children:e.formatted}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_of_total.toFixed(1),`%)`]})]},e.key))}),(0,K.jsxs)(`div`,{className:`mt-2 text-xs text-bambu-gray`,children:[i(`settings.storageUsageTotal`,`Total`),`: `,(0,K.jsx)(`span`,{className:`text-white`,children:_t.total_formatted}),_t.scan_errors>0&&(0,K.jsxs)(`span`,{className:`ml-2 text-amber-400`,children:[i(`settings.storageUsageErrors`,`Scan errors`),`: `,_t.scan_errors]})]}),_t.other_breakdown?.length>0&&(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:i(`settings.storageUsageOtherBreakdown`,`Other breakdown`)}),(0,K.jsx)(`div`,{className:`space-y-2`,children:_t.other_breakdown.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-white`,children:e.label}),(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded-full border ${e.kind===`system`?`border-slate-500 text-slate-300`:`border-bambu-green text-bambu-green`}`,children:e.kind===`system`?i(`settings.storageUsageSystem`,`System`):i(`settings.storageUsageData`,`Data`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`text-white`,children:e.formatted}),(0,K.jsxs)(`span`,{children:[`(`,e.percent_of_total.toFixed(1),`%)`]})]})]},`${e.bucket}-${e.kind}`))})]})]}):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.storageUsageUnavailable`,`Storage usage data is unavailable`)})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.backupRestore`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.backupRestoreDescription`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>le(`backup`),children:[(0,K.jsx)(js,{className:`w-4 h-4`}),i(`settings.goToBackup`)]})]})]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-sm`,children:[(0,K.jsxs)(pd,{id:`card-updates`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.updates`)})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider`,children:i(`settings.printerFirmware`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.checkPrinterFirmware`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.checkFirmwareDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.check_printer_firmware??!0,onChange:e=>In(`check_printer_firmware`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,K.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider mb-4`,children:i(`settings.bambuddySoftware`)})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.checkForUpdatesLabel`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoCheckDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.check_updates,onChange:e=>In(`check_updates`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between ${O.check_updates?``:`opacity-50`}`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.includeBetaUpdates`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.includeBetaUpdatesDesc`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.include_beta_updates??!1,onChange:e=>In(`include_beta_updates`,e.target.checked),disabled:!O.check_updates,className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.currentVersion`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`v`,Ut?.version||`...`]})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>$t(),disabled:en,children:[en?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),i(`settings.checkNow`)]})]}),Qt?.update_available?(0,K.jsxs)(`div`,{className:`mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`p`,{className:`text-bambu-green font-medium`,children:[`Update available: v`,Qt.latest_version]}),Qt.release_name&&Qt.release_name!==Qt.latest_version&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:Qt.release_name})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[Qt.release_notes&&(0,K.jsx)(`button`,{onClick:()=>je(!0),className:`text-bambu-gray hover:text-white transition-colors text-sm underline`,children:i(`settings.releaseNotes`)}),Qt.release_url&&(0,K.jsx)(`a`,{href:Qt.release_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-white transition-colors`,title:i(`settings.viewReleaseOnGitHub`),children:(0,K.jsx)(Us,{className:`w-4 h-4`})})]})]}),tn?.status===`downloading`||tn?.status===`installing`?(0,K.jsxs)(`div`,{className:`mt-3`,children:[(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`}),(0,K.jsx)(`span`,{children:tn.message})]}),(0,K.jsx)(`div`,{className:`mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,K.jsx)(`div`,{className:`bg-bambu-green h-2 rounded-full transition-all duration-300`,style:{width:`${tn.progress}%`}})})]}):tn?.status===`complete`?(0,K.jsx)(`div`,{className:`mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green`,children:tn.message}):tn?.status===`error`?(0,K.jsx)(`div`,{className:`mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400`,children:tn.error||tn.message}):Qt?.is_ha_addon?(0,K.jsx)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.updateViaHomeAssistant`)})}):Qt?.is_docker?(0,K.jsxs)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:i(`settings.updateViaDocker`)}),(0,K.jsx)(`code`,{className:`block text-xs bg-bambu-dark p-2 rounded text-bambu-green font-mono`,children:`docker compose pull && docker compose up -d`})]}):Qt?.update_method===`windows_installer`?(0,K.jsxs)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:i(`settings.updateViaWindowsInstaller`)}),(0,K.jsxs)(`a`,{href:Qt.installer_download_url||Qt.release_url||`https://github.com/maziggy/bambuddy/releases/tag/v${Qt.latest_version}`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center font-medium rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-bambu-dark disabled:opacity-50 bg-bambu-green hover:bg-bambu-green-light text-white focus:ring-bambu-green px-4 py-2 text-sm gap-2 min-h-[44px] md:min-h-0`,children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),i(`settings.downloadWindowsInstaller`,{version:Qt.latest_version})]})]}):(0,K.jsxs)($,{className:`mt-3`,onClick:()=>Tn.mutate(),disabled:Tn.isPending,children:[Tn.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Is,{className:`w-4 h-4`}),i(`settings.installUpdate`)]})]}):Qt?.error?(0,K.jsx)(`div`,{className:`mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400`,children:i(`settings.failedToCheckUpdates`,{error:Qt.error})}):Qt&&!Qt.update_available?(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:i(`settings.latestVersionRunning`)}):null]})]})]}),(0,K.jsx)(oze,{})]})]})]}),W===`network`&&O&&(0,K.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-6`,children:[(0,K.jsxs)(`div`,{className:`flex-1 lg:max-w-xl space-y-3`,children:[(0,K.jsxs)(pd,{id:`card-externalurl`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(hc,{className:`w-5 h-5 text-blue-400`}),i(`settings.externalUrl`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.externalUrlDescription`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.bambuddyUrl`)}),(0,K.jsx)(`input`,{type:`text`,value:O.external_url??``,onChange:e=>In(`external_url`,e.target.value),placeholder:`http://192.168.1.100:8000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.externalUrlHint`)})]})]})]}),(0,K.jsxs)(pd,{id:`card-ftpretry`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Cl,{className:`w-5 h-5 text-blue-400`}),i(`settings.ftpRetry`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.ftpRetryDescription`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.enableRetry`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoRetryDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.ftp_retry_enabled??!0,onChange:e=>In(`ftp_retry_enabled`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),O.ftp_retry_enabled&&(0,K.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.retryAttempts`)}),(0,K.jsxs)(`div`,{className:`relative w-44`,children:[(0,K.jsx)(`select`,{value:O.ftp_retry_count??3,onChange:e=>In(`ftp_retry_count`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[1,2,3,4,5,6,7,8,9,10].map(e=>(0,K.jsx)(`option`,{value:e,children:i(`settings.time`,{count:e})},e))}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.retryDelay`)}),(0,K.jsxs)(`div`,{className:`relative w-44`,children:[(0,K.jsx)(`select`,{value:O.ftp_retry_delay??2,onChange:e=>In(`ftp_retry_delay`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[1,2,3,5,10,15,20,30].map(e=>(0,K.jsx)(`option`,{value:e,children:i(`settings.second`,{count:e})},e))}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.connectionTimeout`)}),(0,K.jsxs)(`div`,{className:`relative w-44`,children:[(0,K.jsx)(`select`,{value:O.ftp_timeout??30,onChange:e=>In(`ftp_timeout`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[10,15,20,30,45,60,90,120,180,300].map(e=>(0,K.jsx)(`option`,{value:e,children:i(`settings.nSeconds`,{count:e})},e))}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.increaseForWeakWifi`)})]})]})]})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 lg:max-w-xl space-y-3`,children:[(0,K.jsxs)(pd,{id:`card-ha`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Tc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.homeAssistant`)]}),O.ha_enabled&&ot&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${ot.success?`bg-green-400`:`bg-red-400`}`}),(0,K.jsx)(`span`,{className:`text-sm ${ot.success?`text-green-400`:`text-red-400`}`,children:ot.success?i(`settings.connected`):i(`settings.disconnected`)})]})]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.homeAssistantFullDescription`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.enableHomeAssistant`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.homeAssistantDescription`)}),O.ha_env_managed&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1 mt-1`,children:[(0,K.jsx)(Hc,{className:`w-3 h-3 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.autoEnabledViaEnv`)})]})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.ha_enabled??!1,onChange:e=>In(`ha_enabled`,e.target.checked),disabled:O.ha_env_managed,className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green ${O.ha_env_managed?`opacity-60 cursor-not-allowed`:``}`})]})]}),O.ha_enabled&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.homeAssistantUrl`),O.ha_url_from_env&&(0,K.jsx)(`span`,{className:`ml-2 text-xs text-bambu-green`,children:i(`settings.environmentManagedLabel`)})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{type:`text`,value:O.ha_url??``,onChange:e=>In(`ha_url`,e.target.value),placeholder:`http://192.168.1.100:8123`,disabled:O.ha_url_from_env,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${O.ha_url_from_env?`opacity-60 cursor-not-allowed`:``}`}),O.ha_url_from_env&&(0,K.jsx)(Hc,{className:`absolute right-3 top-2.5 w-4 h-4 text-bambu-gray`})]}),O.ha_url_from_env&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.urlFromEnvReadOnly`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.longLivedAccessToken`),O.ha_token_from_env&&(0,K.jsx)(`span`,{className:`ml-2 text-xs text-bambu-green`,children:i(`settings.environmentManagedLabel`)})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{type:`password`,value:O.ha_token??``,onChange:e=>In(`ha_token`,e.target.value),placeholder:`eyJ0eXAiOiJKV1QiLC...`,disabled:O.ha_token_from_env,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${O.ha_token_from_env?`opacity-60 cursor-not-allowed`:``}`}),O.ha_token_from_env&&(0,K.jsx)(Hc,{className:`absolute right-3 top-2.5 w-4 h-4 text-bambu-gray`})]}),O.ha_token_from_env?(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.tokenFromEnvReadOnly`)}):(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.haTokenHint`)})]}),O.ha_url&&O.ha_token&&(0,K.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)($,{variant:`secondary`,size:`sm`,disabled:ct,onClick:async()=>{lt(!0),st(null);try{st(await Q.testHAConnection(O.ha_url,O.ha_token))}catch(e){st({success:!1,message:null,error:e instanceof Error?e.message:i(`common.unknownError`)})}finally{lt(!1)}},children:[ct?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(ju,{className:`w-4 h-4`}),i(`settings.testConnection`)]})})]})]})]}),(0,K.jsxs)(pd,{id:`card-mqtt`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(ju,{className:`w-5 h-5 text-blue-400`}),i(`settings.mqttPublishing`)]}),rn?.enabled&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${rn.connected?`bg-green-400`:`bg-red-400`}`}),(0,K.jsx)(`span`,{className:`text-sm ${rn.connected?`text-green-400`:`text-red-400`}`,children:rn.connected?i(`settings.connected`):i(`settings.disconnected`)})]})]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.mqttDescription`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.enableMqtt`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.mqttEnableDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.mqtt_enabled??!1,onChange:e=>In(`mqtt_enabled`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),O.mqtt_enabled&&(0,K.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.brokerHostname`)}),(0,K.jsx)(`input`,{type:`text`,value:O.mqtt_broker??``,onChange:e=>In(`mqtt_broker`,e.target.value),placeholder:`mqtt.example.com or 192.168.1.100`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex items-end gap-4`,children:[(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.port`)}),(0,K.jsx)(`input`,{type:`number`,min:`1`,max:`65535`,value:O.mqtt_port??1883,onChange:e=>In(`mqtt_port`,Math.min(65535,Math.max(1,parseInt(e.target.value)||1883))),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 pb-2`,children:[(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.mqtt_use_tls??!1,onChange:e=>{let t=e.target.checked;In(`mqtt_use_tls`,t);let n=O.mqtt_port??1883;t&&n===1883?In(`mqtt_port`,8883):!t&&n===8883&&In(`mqtt_port`,1883)},className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]}),(0,K.jsx)(`span`,{className:`text-white text-sm`,children:i(`settings.useTls`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.usernameOptional`)}),(0,K.jsx)(`input`,{type:`text`,value:O.mqtt_username??``,onChange:e=>In(`mqtt_username`,e.target.value),placeholder:i(`settings.leaveEmptyForAnonymous`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.passwordOptional`)}),(0,K.jsx)(`input`,{type:`password`,value:O.mqtt_password??``,onChange:e=>In(`mqtt_password`,e.target.value),placeholder:i(`settings.leaveEmptyForAnonymous`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.topicPrefix`)}),(0,K.jsx)(`input`,{type:`text`,value:O.mqtt_topic_prefix??`bambuddy`,onChange:e=>In(`mqtt_topic_prefix`,e.target.value),placeholder:`bambuddy`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.topicPrefixHint`,{prefix:O.mqtt_topic_prefix||`bambuddy`})})]}),rn&&(0,K.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${rn.connected?`bg-green-400`:`bg-red-400`}`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:rn.connected?(0,K.jsxs)(K.Fragment,{children:[i(`settings.mqttConnectedTo`),` `,(0,K.jsxs)(`span`,{className:`text-white`,children:[rn.broker,`:`,rn.port]})]}):i(`settings.spoolmanDisconnected`)})]})})]})]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 lg:max-w-md space-y-3`,children:(0,K.jsxs)(pd,{id:`card-prometheus`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(_u,{className:`w-5 h-5 text-orange-400`}),i(`settings.prometheusMetrics`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.prometheusEndpointDescription`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.enableMetricsEndpoint`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.prometheusDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.prometheus_enabled??!1,onChange:e=>In(`prometheus_enabled`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),O.prometheus_enabled&&(0,K.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.bearerTokenOptional`)}),(0,K.jsx)(`input`,{type:`password`,value:O.prometheus_token??``,onChange:e=>In(`prometheus_token`,e.target.value),placeholder:i(`settings.leaveEmptyForNoAuth`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.bearerTokenHint`)})]}),(0,K.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white mb-2`,children:i(`settings.availableMetrics`)}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray space-y-1`,children:[(0,K.jsxs)(`p`,{children:[(0,K.jsx)(`code`,{className:`text-orange-400`,children:`bambuddy_printer_connected`}),` - `,i(`settings.metricsConnectionStatus`)]}),(0,K.jsxs)(`p`,{children:[(0,K.jsx)(`code`,{className:`text-orange-400`,children:`bambuddy_printer_state`}),` - `,i(`settings.metricsPrinterState`)]}),(0,K.jsxs)(`p`,{children:[(0,K.jsx)(`code`,{className:`text-orange-400`,children:`bambuddy_print_progress`}),` - `,i(`settings.metricsPrintProgress`)]}),(0,K.jsxs)(`p`,{children:[(0,K.jsx)(`code`,{className:`text-orange-400`,children:`bambuddy_bed_temp_celsius`}),` - `,i(`settings.metricsBedTemp`)]}),(0,K.jsxs)(`p`,{children:[(0,K.jsx)(`code`,{className:`text-orange-400`,children:`bambuddy_nozzle_temp_celsius`}),` - `,i(`settings.metricsNozzleTemp`)]}),(0,K.jsxs)(`p`,{children:[(0,K.jsx)(`code`,{className:`text-orange-400`,children:`bambuddy_prints_total`}),` - `,i(`settings.metricsPrintsTotal`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray/70 italic`,children:i(`settings.metricsMore`)})]})]})]})]})]})})]}),ot&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[ot.success?(0,K.jsx)(ls,{className:`w-8 h-8 text-green-400`}):(0,K.jsx)(ms,{className:`w-8 h-8 text-red-400`}),(0,K.jsx)(`h3`,{className:`text-lg font-medium text-white`,children:ot.success?i(`settings.connectionSuccessful`):i(`settings.connectionFailed`)})]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:ot.success?ot.message||i(`settings.haConnectionSuccess`):ot.error||i(`settings.haConnectionFailed`)}),(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsx)($,{variant:`primary`,onClick:()=>st(null),children:i(`settings.ok`)})})]})}),W===`plugs`&&(0,K.jsxs)(`div`,{id:`card-plugs`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between mb-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(gl,{className:`w-5 h-5 text-bambu-green`}),i(`settings.smartPlugs`)]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.smartPlugsDescription`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 pt-1 shrink-0`,children:[xt&&xt.filter(e=>e.enabled).length>1&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,className:`whitespace-nowrap`,onClick:()=>ke(`on`),disabled:kn.isPending,title:i(`settings.turnAllPlugsOn`),children:[kn.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(yl,{className:`w-4 h-4 text-bambu-green`}),i(`settings.allOn`)]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,className:`whitespace-nowrap`,onClick:()=>ke(`off`),disabled:kn.isPending,title:i(`settings.turnAllPlugsOff`),children:[kn.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(vl,{className:`w-4 h-4 text-red-400`}),i(`settings.allOff`)]})]}),(0,K.jsxs)($,{className:`whitespace-nowrap`,onClick:()=>{N(null),j(!0)},children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.addSmartPlug`)]})]})]}),xt&&xt.length>0&&(0,K.jsxs)(pd,{className:`mb-6`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Iu,{className:`w-4 h-4 text-yellow-400`}),i(`settings.energySummary`),Tt&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin text-bambu-gray ml-2`})]})}),(0,K.jsx)(hd,{children:wt?(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,K.jsx)(Iu,{className:`w-3 h-3`}),i(`settings.currentPower`)]}),(0,K.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[wt.totalPower.toFixed(1),(0,K.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`W`})]}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.plugsOnline`,{reachable:wt.reachableCount,total:wt.totalPlugs})})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,K.jsx)(qo,{className:`w-3 h-3`}),i(`settings.today`)]}),(0,K.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[wt.totalToday.toFixed(3),(0,K.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(O?.energy_cost_per_kwh??0)>0&&(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,(wt.totalToday*(O?.energy_cost_per_kwh??0)).toFixed(2),` `,Yd(O?.currency||`USD`)]})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,K.jsx)(_u,{className:`w-3 h-3`}),i(`settings.yesterday`)]}),(0,K.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[wt.totalYesterday.toFixed(3),(0,K.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(O?.energy_cost_per_kwh??0)>0&&(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,(wt.totalYesterday*(O?.energy_cost_per_kwh??0)).toFixed(2),` `,Yd(O?.currency||`USD`)]})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,K.jsx)(Ns,{className:`w-3 h-3`}),i(`settings.total`)]}),(0,K.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[wt.totalLifetime.toFixed(1),(0,K.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(O?.energy_cost_per_kwh??0)>0&&(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,(wt.totalLifetime*(O?.energy_cost_per_kwh??0)).toFixed(2),` `,Yd(O?.currency||`USD`)]})]})]}):Tt?null:(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.enablePlugsForSummary`)})})]}),St?(0,K.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):xt&&xt.length>0?(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:xt.map(e=>(0,K.jsx)(wRe,{plug:e,onEdit:e=>{N(e),j(!0)}},e.id))}):(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-12`,children:(0,K.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,K.jsx)(gl,{className:`w-16 h-16 mx-auto mb-4 opacity-30`}),(0,K.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.noSmartPlugsTitle`)}),(0,K.jsx)(`p`,{className:`text-sm mb-4`,children:i(`settings.noSmartPlugsDescription`)}),(0,K.jsxs)($,{onClick:()=>{N(null),j(!0)},children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.addFirstSmartPlug`)]})]})})})]}),W===`notifications`&&(0,K.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-providers`,children:[(0,K.jsx)(Io,{className:`w-5 h-5 text-bambu-green`}),i(`settings.providers`)]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>ne(!0),children:[(0,K.jsx)(wc,{className:`w-4 h-4`}),i(`settings.log`)]}),Et&&Et.length>0&&(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>{Dn(null),On.mutate()},disabled:On.isPending,children:[On.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Pl,{className:`w-4 h-4`}),i(`settings.testAll`)]}),(0,K.jsxs)($,{size:`sm`,onClick:()=>{L(null),F(!0)},children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.addNotificationProvider`)]})]})]}),(0,K.jsx)(pd,{className:`mb-4`,children:(0,K.jsx)(hd,{className:`py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.notificationLanguage`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.notificationLanguageDescription`)})]}),(0,K.jsx)(`select`,{value:O.notification_language||`en`,onChange:e=>In(`notification_language`,e.target.value),className:`px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green`,children:Ct.map(e=>(0,K.jsx)(`option`,{value:e.code,children:e.nativeName},e.code))})]})})}),(0,K.jsx)(pd,{className:`mb-4`,children:(0,K.jsx)(hd,{className:`py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.bedCooledThreshold`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.bedCooledThresholdDescription`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`input`,{type:`number`,min:20,max:80,step:1,value:O.bed_cooled_threshold??35,onChange:e=>In(`bed_cooled_threshold`,Number(e.target.value)),className:`w-16 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm text-center focus:outline-none focus:ring-1 focus:ring-bambu-green`}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`°C`})]})]})})}),(0,K.jsx)(pd,{className:`mb-4`,children:(0,K.jsx)(hd,{className:`py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between ${sn?.advanced_auth_enabled?``:`opacity-50`}`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.userNotificationsEnabled`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:sn?.advanced_auth_enabled?i(`settings.userNotificationsEnabledDescription`):i(`settings.userNotificationsDisabledHint`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,className:`sr-only peer`,checked:O.user_notifications_enabled??!0,disabled:!sn?.advanced_auth_enabled,onChange:e=>In(`user_notifications_enabled`,e.target.checked)}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green peer-disabled:cursor-not-allowed`})]})]})})}),En&&(0,K.jsx)(pd,{className:`mb-4`,children:(0,K.jsxs)(hd,{className:`py-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium text-white`,children:i(`settings.testResults`)}),(0,K.jsx)(`button`,{onClick:()=>Dn(null),className:`text-bambu-gray hover:text-white text-xs`,children:i(`common.dismiss`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm mb-2`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-green`,children:[(0,K.jsx)(ls,{className:`w-4 h-4`}),i(`settings.testPassedCount`,{count:En.success})]}),En.failed>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-red-400`,children:[(0,K.jsx)(ms,{className:`w-4 h-4`}),i(`settings.testFailedCount`,{count:En.failed})]})]}),En.results.filter(e=>!e.success).length>0&&(0,K.jsx)(`div`,{className:`space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary`,children:En.results.filter(e=>!e.success).map(e=>(0,K.jsxs)(`div`,{className:`text-xs text-red-400`,children:[(0,K.jsxs)(`span`,{className:`font-medium`,children:[e.provider_name,`:`]}),` `,e.message]},e.provider_id))})]})}),Dt?(0,K.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})}):Et&&Et.length>0?(0,K.jsx)(`div`,{className:`space-y-3`,children:Et.map(e=>(0,K.jsx)(ERe,{provider:e,onEdit:e=>{L(e),F(!0)}},e.id))}):(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-8`,children:(0,K.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,K.jsx)(Io,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,K.jsx)(`p`,{className:`text-sm font-medium text-white mb-2`,children:i(`settings.noProvidersTitle`)}),(0,K.jsx)(`p`,{className:`text-xs mb-3`,children:i(`settings.noProvidersDescription`)}),(0,K.jsxs)($,{size:`sm`,onClick:()=>{L(null),F(!0)},children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.addProvider`)]})]})})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-2`,id:`card-templates`,children:[(0,K.jsx)(Zs,{className:`w-5 h-5 text-bambu-green`}),i(`settings.messageTemplates`)]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:i(`settings.messageTemplatesDescription`)}),(0,K.jsxs)(`div`,{className:`relative mb-3`,children:[(0,K.jsx)(Nl,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none`}),(0,K.jsx)(`input`,{type:`text`,value:B,onChange:e=>V(e.target.value),placeholder:i(`settings.filterTemplates`,`Filter templates…`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),B&&(0,K.jsx)(`button`,{onClick:()=>V(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white`,"aria-label":`Clear filter`,children:(0,K.jsx)(Pu,{className:`w-3.5 h-3.5`})})]}),Pt?(0,K.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})}):Nt&&Nt.length>0?(()=>{let e=B.trim().toLowerCase(),t=[...Nt].sort((e,t)=>e.name.localeCompare(t.name)).filter(t=>!e||t.name.toLowerCase().includes(e)||(t.title_template||``).toLowerCase().includes(e));return t.length===0?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic text-center py-6`,children:i(`settings.noTemplatesMatch`,`No templates match your filter.`)}):(0,K.jsx)(`div`,{className:`space-y-2`,children:t.map(e=>(0,K.jsx)(pd,{className:`cursor-pointer hover:border-bambu-green/50 transition-colors`,onClick:()=>z(e),children:(0,K.jsx)(hd,{className:`py-2.5 px-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium text-sm truncate`,children:e.name}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs truncate mt-0.5`,children:e.title_template})]}),(0,K.jsx)(`button`,{className:`p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2`,onClick:t=>{t.stopPropagation(),z(e)},children:(0,K.jsx)(fl,{className:`w-4 h-4 text-bambu-gray`})})]})})},e.id))})})():(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-8`,children:(0,K.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,K.jsx)(Zs,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,K.jsx)(`p`,{className:`text-sm`,children:i(`settings.noTemplatesAvailable`)})]})})})]})]}),W===`apikeys`&&(0,K.jsxs)(`div`,{className:d(`api_keys:read`)?`grid grid-cols-1 xl:grid-cols-2 gap-4`:`grid grid-cols-1 gap-4`,children:[(0,K.jsxs)(`div`,{children:[d(`api_keys:read`)&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-6`,children:[(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-createapi`,children:[(0,K.jsx)(jc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.apiKeys`)]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.apiKeysDescription`)})]}),(0,K.jsxs)($,{size:`sm`,onClick:()=>de(!0),className:`flex-shrink-0`,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.createKey`)]})]}),ge&&(0,K.jsx)(pd,{className:`mb-6 border-bambu-green`,children:(0,K.jsx)(hd,{className:`py-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(ls,{className:`w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium mb-1`,children:i(`settings.apiKeyCreated`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:i(`settings.apiKeyCopyWarning`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 bg-bambu-dark rounded-lg p-2`,children:[(0,K.jsx)(`code`,{className:`flex-1 text-sm text-bambu-green font-mono break-all`,children:ge}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(ge);else{let e=document.createElement(`textarea`);e.value=ge,e.style.position=`fixed`,e.style.left=`-999999px`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e)}o(i(`settings.toast.keyCopied`))}catch{o(i(`settings.toast.copyFailed`),`error`)}},children:(0,K.jsx)(Ds,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 mt-3`,children:[(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>{Ce(ge),o(i(`settings.toast.keyAddedToBrowser`))},children:i(`settings.useInApiBrowser`)}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>ye(!0),children:[(0,K.jsx)(xl,{className:`w-4 h-4`}),i(`settings.apiKeyQrButton`)]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>{ye(!1),_e(null)},children:i(`common.dismiss`)})]})]})]})})}),ve&&ge&&(0,K.jsx)(URe,{apiKey:ge,baseUrl:O?.external_url||void 0,onClose:()=>ye(!1)}),ue&&(0,K.jsxs)(pd,{className:`mb-6`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h3`,{className:`text-base font-semibold text-white`,children:i(`settings.createNewApiKey`)})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.keyName`)}),(0,K.jsx)(`input`,{type:`text`,value:fe,onChange:e=>pe(e.target.value),placeholder:i(`settings.keyNamePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:i(`common.permissions`)}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:me.can_read_status,onChange:e=>he(t=>({...t,can_read_status:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white`,children:i(`settings.readStatus`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.readStatusDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:me.can_queue,onChange:e=>he(t=>({...t,can_queue:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white`,children:i(`settings.manageQueue`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageQueueDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:me.can_control_printer,onChange:e=>he(t=>({...t,can_control_printer:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white`,children:i(`settings.controlPrinter`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.controlPrinterDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:me.can_manage_library,onChange:e=>he(t=>({...t,can_manage_library:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white`,children:i(`settings.manageLibrary`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageLibraryDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:me.can_manage_inventory,onChange:e=>he(t=>({...t,can_manage_inventory:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white`,children:i(`settings.manageInventory`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageInventoryDescription`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:me.can_access_cloud,onChange:e=>he(t=>({...t,can_access_cloud:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white`,children:i(`settings.cloudAccess`,`Allow cloud access`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.cloudAccessDescription`,`Read Bambu Cloud presets and filaments on your behalf. Requires you to be signed into Bambu Cloud.`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:me.can_update_energy_cost,onChange:e=>he(t=>({...t,can_update_energy_cost:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-white`,children:i(`settings.updateEnergyCost`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.updateEnergyCostDescription`)})]})]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 pt-2`,children:[(0,K.jsxs)($,{onClick:()=>At.mutate({name:fe||i(`settings.unnamedKey`),...me}),disabled:At.isPending,children:[At.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.createKey`)]}),(0,K.jsx)($,{variant:`secondary`,onClick:()=>de(!1),children:i(`common.cancel`)})]})]})]}),kt?(0,K.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):Ot&&Ot.length>0?(0,K.jsx)(`div`,{className:`space-y-3`,children:Ot.map(e=>(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(jc,{className:`w-5 h-5 ${e.enabled?`text-bambu-green`:`text-bambu-gray`}`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e.name}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[e.key_prefix,`••••••••`,e.last_used&&` · ${i(`settings.lastUsed`)}: ${hf(e.last_used)}`]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex gap-1 text-xs flex-wrap justify-end`,children:[e.can_read_status&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded`,children:i(`settings.read`)}),e.can_queue&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded`,children:i(`queue.title`)}),e.can_control_printer&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded`,children:i(`settings.control`)}),e.can_manage_library&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-cyan-500/20 text-cyan-400 rounded`,children:i(`settings.libraryBadge`)}),e.can_manage_inventory&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-pink-500/20 text-pink-400 rounded`,children:i(`settings.inventoryBadge`)}),e.can_access_cloud&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-purple-500/20 text-purple-400 rounded`,children:i(`settings.cloudBadge`,`Cloud`)}),e.can_update_energy_cost&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-amber-500/20 text-amber-400 rounded`,children:i(`settings.energyCostBadge`)}),e.user_id===null&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-yellow-500/20 text-yellow-400 rounded`,title:i(`settings.legacyKeyTooltip`,`Created before per-user ownership; recreate to use cloud access`),children:i(`settings.legacyKey`,`Legacy`)})]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>xe(e.id),children:(0,K.jsx)(hu,{className:`w-4 h-4 text-red-400`})})]})]})})},e.id))}):(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-12`,children:(0,K.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,K.jsx)(jc,{className:`w-16 h-16 mx-auto mb-4 opacity-30`}),(0,K.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.apiKeysEmptyTitle`)}),(0,K.jsx)(`p`,{className:`text-sm mb-4`,children:i(`settings.apiKeysEmptyDescription`)}),(0,K.jsxs)($,{onClick:()=>de(!0),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.createFirstKey`)]})]})})}),(0,K.jsxs)(pd,{className:`mt-6`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h3`,{className:`text-base font-semibold text-white`,id:`card-webhooks`,children:i(`settings.webhookEndpoints`)})}),(0,K.jsxs)(hd,{className:`space-y-3 text-sm`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:i(`settings.webhookApiKeyHint`)}),(0,K.jsxs)(`div`,{className:`space-y-2 font-mono text-xs`,children:[(0,K.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,K.jsx)(`span`,{className:`text-blue-400`,children:`GET`}),` `,(0,K.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/status`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.getAllStatus`)]})]}),(0,K.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,K.jsx)(`span`,{className:`text-blue-400`,children:`GET`}),` `,(0,K.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/status/:id`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.getSpecificStatus`)]})]}),(0,K.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,K.jsx)(`span`,{className:`text-green-400`,children:`POST`}),` `,(0,K.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/queue`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.addToQueue`)]})]}),(0,K.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,K.jsx)(`span`,{className:`text-orange-400`,children:`POST`}),` `,(0,K.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/pause`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.pausePrint`)]})]}),(0,K.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,K.jsx)(`span`,{className:`text-orange-400`,children:`POST`}),` `,(0,K.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/resume`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.resumePrint`)]})]}),(0,K.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,K.jsx)(`span`,{className:`text-red-400`,children:`POST`}),` `,(0,K.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/stop`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.stopPrint`)]})]})]})]})]})]}),(0,K.jsxs)(pd,{className:`mt-6`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-camera-tokens`,children:[(0,K.jsx)(Tu,{className:`w-4 h-4 text-bambu-green`}),i(`cameraTokens.title`,`Camera API Tokens`)]})}),(0,K.jsx)(hd,{children:(0,K.jsx)(CRe,{})})]})]}),d(`api_keys:read`)&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-apibrowser`,children:[(0,K.jsx)(hc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.apiBrowser`)]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.apiBrowserDescription`)})]}),(0,K.jsx)(pd,{className:`mb-4`,children:(0,K.jsxs)(hd,{className:`py-3`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:i(`settings.apiKeyForTesting`)}),(0,K.jsx)(`input`,{type:`text`,value:Se,onChange:e=>Ce(e.target.value),placeholder:i(`settings.apiKeyPlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:i(`settings.apiKeyHint`)})]})}),(0,K.jsx)(Fze,{apiKey:Se})]})]}),W===`virtual-printer`&&(0,K.jsx)(`div`,{id:`card-vp`,children:(0,K.jsx)(fze,{})}),W===`spoolbuddy`&&(0,K.jsx)(`div`,{id:`card-spoolbuddy`,children:(0,K.jsx)(mze,{})}),W===`queue`&&O&&(0,K.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,K.jsxs)(`div`,{className:`lg:w-1/2 space-y-3`,children:[(0,K.jsxs)(pd,{id:`card-print-options`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Rc,{className:`w-4 h-4 text-bambu-green`}),i(`settings.defaultPrintOptions`,`Default Print Options`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.defaultPrintOptionsDescription`,`Set default values for print options when starting new prints. These can be overridden per print in the print dialog.`)}),[{key:`default_bed_levelling`,label:i(`settings.defaultBedLevelling`,`Bed Levelling`),desc:i(`settings.defaultBedLevellingDesc`,`Auto-level bed before print`),fallback:!0,dualNozzleOnly:!1},{key:`default_flow_cali`,label:i(`settings.defaultFlowCali`,`Flow Calibration`),desc:i(`settings.defaultFlowCaliDesc`,`Calibrate extrusion flow`),fallback:!1,dualNozzleOnly:!1},{key:`default_vibration_cali`,label:i(`settings.defaultVibrationCali`,`Vibration Calibration`),desc:i(`settings.defaultVibrationCaliDesc`,`Reduce ringing artifacts`),fallback:!0,dualNozzleOnly:!1},{key:`default_layer_inspect`,label:i(`settings.defaultLayerInspect`,`First Layer Inspection`),desc:i(`settings.defaultLayerInspectDesc`,`AI inspection of first layer`),fallback:!1,dualNozzleOnly:!1},{key:`default_timelapse`,label:i(`settings.defaultTimelapse`,`Timelapse`),desc:i(`settings.defaultTimelapseDesc`,`Record timelapse video`),fallback:!1,dualNozzleOnly:!1},{key:`default_nozzle_offset_cali`,label:i(`settings.defaultNozzleOffsetCali`,`Nozzle Offset Calibration`),desc:i(`settings.defaultNozzleOffsetCaliDesc`,`Calibrate nozzle offsets between extruders`),fallback:!0,dualNozzleOnly:!0}].filter(({dualNozzleOnly:e})=>!e||(Mt||[]).some(e=>e.nozzle_count===2)).map(({key:e,label:t,desc:n,fallback:r})=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:t}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:n})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O[e]??r,onChange:t=>In(e,t.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]},e))]})]}),(0,K.jsxs)(pd,{id:`card-temp-fan-presets`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(pu,{className:`w-4 h-4 text-bambu-green`}),i(`settings.tempFanPresetsTitle`,`Temperature & Fan Presets`)]})}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.tempFanPresetsDescription`,`Customize the quick-select values shown in printer-card temperature and fan-speed popovers. The Off button is always shown.`)}),ap.map(e=>{let t=op(O?.[e.key]??``,e.defaults,e.lo,e.hi),n=e.unit===`C`?`°C`:`%`;return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,K.jsxs)(`label`,{className:`text-sm text-white`,children:[i(`settings.${{nozzle_temp_presets:`tempFanPresetsNozzle`,bed_temp_presets:`tempFanPresetsBed`,chamber_temp_presets:`tempFanPresetsChamber`,fan_speed_presets:`tempFanPresetsFan`}[e.key]}`,{nozzle_temp_presets:`Nozzle temperature`,bed_temp_presets:`Bed temperature`,chamber_temp_presets:`Chamber temperature`,fan_speed_presets:`Fan speed`}[e.key]),` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[`(`,n,` · `,e.lo,`–`,e.hi,`)`]})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>In(e.key,``),title:i(`settings.tempFanPresetsReset`,`Reset to defaults`),className:`text-bambu-gray hover:text-white transition-colors p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(Tl,{className:`w-3.5 h-3.5`})})]}),(0,K.jsx)(`div`,{className:`flex gap-2`,children:[0,1,2].map(n=>(0,K.jsx)(`input`,{type:`number`,min:e.lo,max:e.hi,value:t[n],onChange:r=>{let i=[t[0],t[1],t[2]],a=parseInt(r.target.value,10);i[n]=Math.max(e.lo,Math.min(e.hi,Number.isFinite(a)?a:e.lo)),In(e.key,JSON.stringify(i))},className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`},n))})]},e.key)})]})]}),(0,K.jsxs)(pd,{id:`card-staggered`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Nc,{className:`w-4 h-4 text-bambu-green`}),i(`settings.staggeredStart`,`Staggered Start`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.staggeredStartDescription`,`Default group size and interval when staggering multi-printer batch starts. Can be overridden per batch in the print modal.`)}),(0,K.jsxs)(`div`,{className:`flex gap-4`,children:[(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.staggerGroupSize`,`Group size`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:50,value:O.stagger_group_size??2,onChange:e=>In(`stagger_group_size`,Math.max(1,Math.min(50,parseInt(e.target.value)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.staggerGroupSizeHelp`,`Printers to start simultaneously per group`)})]}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.staggerInterval`,`Interval (minutes)`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:60,value:O.stagger_interval_minutes??5,onChange:e=>In(`stagger_interval_minutes`,Math.max(1,Math.min(60,parseInt(e.target.value)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.staggerIntervalHelp`,`Delay between each group starting`)})]})]})]})]}),(0,K.jsxs)(pd,{id:`card-plate`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Hl,{className:`w-4 h-4 text-bambu-green`}),i(`settings.plateClear`,`Plate-Clear Confirmation`)]})}),(0,K.jsx)(hd,{className:`space-y-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:i(`settings.requirePlateClear`,`Require plate-clear confirmation`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.requirePlateClearDescription`,`When enabled, the scheduler waits for per-printer plate-clear confirmation before starting queued prints on printers with finished jobs. Disabling this also hides the plate status badge and the "Mark plate as cleared" button on printer cards.`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.require_plate_clear??!1,onChange:e=>In(`require_plate_clear`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})})]}),(0,K.jsxs)(pd,{id:`card-gcode`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(xs,{className:`w-4 h-4 text-bambu-green`}),i(`settings.gcodeInjection`,`G-code Injection`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.gcodeInjectionDescription`,`Configure custom G-code to inject at the start and/or end of prints for auto-print systems like Farmloop, SwapMod, AutoClear, and Printflow 3D. Snippets are configured per printer model and applied when "Inject G-code" is enabled on a queue item.`)}),(()=>{let e=(()=>{try{return O.gcode_snippets?JSON.parse(O.gcode_snippets):{}}catch{return{}}})(),t=[...new Set((Mt||[]).filter(e=>e.model).map(e=>e.model))].sort(),n=(t,n,r)=>{let i={...e};i[t]||(i[t]={start_gcode:``,end_gcode:``}),i[t][n]=r,!i[t].start_gcode&&!i[t].end_gcode&&delete i[t];let a=Object.keys(i).length>0?JSON.stringify(i):``;k(e=>e?{...e,gcode_snippets:a}:null),jn.current=a},r=()=>{jn.current!==null&&(Pn.mutate({gcode_snippets:jn.current}),jn.current=null)};return t.length===0?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:i(`settings.gcodeInjectionNoPrinters`,`No printers found. Add printers to configure G-code snippets.`)}):t.map(t=>{let a=e[t]||{start_gcode:``,end_gcode:``},o=!!(a.start_gcode||a.end_gcode);return(0,K.jsx)(Mf,{defaultOpen:o,className:`border border-bambu-dark-tertiary rounded-lg px-3 py-2`,summary:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t}),o&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:i(`settings.gcodeConfigured`,`Configured`)})]}),children:(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.gcodeStartLabel`,`Start G-code`)}),(0,K.jsx)(`textarea`,{value:a.start_gcode,onChange:e=>n(t,`start_gcode`,e.target.value),onBlur:r,placeholder:i(`settings.gcodeStartPlaceholder`,`G-code prepended before the print starts...`),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.gcodeEndLabel`,`End G-code`)}),(0,K.jsx)(`textarea`,{value:a.end_gcode,onChange:e=>n(t,`end_gcode`,e.target.value),onBlur:r,placeholder:i(`settings.gcodeEndPlaceholder`,`G-code appended after the print ends...`),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y`})]})]})},t)})})()]})]})]}),(0,K.jsxs)(`div`,{className:`lg:w-1/2 space-y-3`,children:[(0,K.jsxs)(pd,{id:`card-slicer`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(ws,{className:`w-4 h-4 text-bambu-green`}),i(`settings.slicerCard`,`Slicer`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.preferredSlicer`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:O.preferred_slicer??`bambu_studio`,onChange:e=>In(`preferred_slicer`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,K.jsx)(`option`,{value:`bambu_studio`,children:i(`settings.slicerBambuStudio`)}),(0,K.jsx)(`option`,{value:`orcaslicer`,children:i(`settings.slicerOrcaSlicer`)})]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.preferredSlicerDescription`)}),(O.preferred_slicer??`bambu_studio`)===`orcaslicer`&&(0,K.jsx)(`div`,{role:`alert`,className:`text-xs text-amber-200 bg-amber-900/20 border border-amber-700/40 rounded p-2 mt-2`,children:i(`settings.orcaslicerKnownIssuesWarning`,`OrcaSlicer 2.3.2 / 2.4.0-dev have known CLI bugs that block slicing many Bambu-authored 3MFs — see upstream issues #12426 (segfault on painted multi-extruder files) and #13386 (parameter-range strict-validation reject). Bambu Studio is recommended until the upstream fixes land.`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.openInSlicerLabel`,`Open in Slicer`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:O.open_in_slicer??``,onChange:e=>In(`open_in_slicer`,e.target.value===``?null:e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,K.jsx)(`option`,{value:``,children:i(`settings.openInSlicerInherit`,`Same as API slicer`)}),(0,K.jsx)(`option`,{value:`bambu_studio`,children:i(`settings.slicerBambuStudio`)}),(0,K.jsx)(`option`,{value:`orcaslicer`,children:i(`settings.slicerOrcaSlicer`)})]}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.openInSlicerDescription`,`Desktop slicer used by the 'Open in Slicer' button. Leave on 'Same as API slicer' to inherit, or pick a different slicer to use locally.`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.useSlicerApi`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.useSlicerApiDescription`)})]}),(0,K.jsxs)(`label`,{className:`flex items-center cursor-pointer shrink-0`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.use_slicer_api??!1,onChange:e=>In(`use_slicer_api`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`relative w-11 h-6 bg-bambu-dark-tertiary rounded-full peer peer-checked:bg-bambu-green peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-bambu-green/50 transition-colors after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-transform peer-checked:after:translate-x-5`})]})]}),(O.use_slicer_api??!1)&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:(O.preferred_slicer??`bambu_studio`)===`orcaslicer`?i(`settings.orcaslicerApiUrl`,`OrcaSlicer sidecar URL`):i(`settings.bambuStudioApiUrl`,`Bambu Studio sidecar URL`)}),(0,K.jsx)(`input`,{type:`text`,value:((O.preferred_slicer??`bambu_studio`)===`orcaslicer`?O.orcaslicer_api_url:O.bambu_studio_api_url)??``,onChange:e=>In((O.preferred_slicer??`bambu_studio`)===`orcaslicer`?`orcaslicer_api_url`:`bambu_studio_api_url`,e.target.value),placeholder:(O.preferred_slicer??`bambu_studio`)===`orcaslicer`?`http://localhost:3003`:`http://localhost:3001`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none placeholder:text-bambu-gray/40`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.slicerApiUrlDescription`,`URL of the slicer-API sidecar container. Leave blank to use the SLICER_API_URL / BAMBU_STUDIO_API_URL env var defaults.`)})]})]})]}),(O.use_slicer_api??!1)&&(0,K.jsx)(_Re,{}),(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-drying`,children:[(0,K.jsx)(ec,{className:`w-4 h-4 text-amber-400`}),i(`settings.queueDrying`)]})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.queueDryingDescription`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.queueDryingEnabled`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.queueDryingEnabledDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.queue_drying_enabled??!1,onChange:e=>In(`queue_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),O.queue_drying_enabled&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.queueDryingBlock`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.queueDryingBlockDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.queue_drying_block??!1,onChange:e=>In(`queue_drying_block`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-amber-500`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.ambientDryingEnabled`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.ambientDryingEnabledDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.ambient_drying_enabled??!1,onChange:e=>In(`ambient_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white font-medium`,children:i(`settings.dryingPresets`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.dryingPresetsDescription`)}),(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`,children:i(`settings.dryingFilament`)}),(0,K.jsx)(`th`,{className:`text-center py-1.5`,colSpan:2,children:`AMS 2 Pro`}),(0,K.jsx)(`th`,{className:`text-center py-1.5`,colSpan:2,children:`AMS-HT`})]})}),(0,K.jsx)(`tbody`,{children:(()=>{let e={PLA:{n3f:45,n3s:45,n3f_hours:12,n3s_hours:12},PETG:{n3f:65,n3s:65,n3f_hours:12,n3s_hours:12},TPU:{n3f:65,n3s:75,n3f_hours:12,n3s_hours:18},ABS:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},ASA:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:12},PC:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PVA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:18}},t={...e};try{if(O.drying_presets){let n=JSON.parse(O.drying_presets);typeof n==`object`&&n&&(t={...e,...n})}}catch{}let n=(e,n,r)=>{let i={...t,[e]:{...t[e],[n]:r}};In(`drying_presets`,JSON.stringify(i))};return Object.entries(t).map(([e,t])=>(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50`,children:[(0,K.jsx)(`td`,{className:`py-1.5 pr-2 text-white font-medium`,children:e}),(0,K.jsx)(`td`,{className:`py-1 px-1`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,K.jsx)(`input`,{type:`number`,min:30,max:65,value:t.n3f,onChange:t=>n(e,`n3f`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})}),(0,K.jsx)(`td`,{className:`py-1 px-1`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`input`,{type:`number`,min:1,max:24,value:t.n3f_hours,onChange:t=>n(e,`n3f_hours`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`h`})]})}),(0,K.jsx)(`td`,{className:`py-1 px-1`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,K.jsx)(`input`,{type:`number`,min:30,max:85,value:t.n3s,onChange:t=>n(e,`n3s`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})}),(0,K.jsx)(`td`,{className:`py-1 px-1`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`input`,{type:`number`,min:1,max:24,value:t.n3s_hours,onChange:t=>n(e,`n3s_hours`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`h`})]})})]},e))})()})]})})]})]})]})]})]}),W===`filament`&&O&&(0,K.jsx)(K.Fragment,{children:(0,K.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,K.jsxs)(`div`,{className:`lg:w-1/3 space-y-3`,children:[(0,K.jsx)(qRe,{}),(0,K.jsxs)(pd,{id:`card-filamentchecks`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.filamentChecks`)})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.disableFilamentWarnings`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.disableFilamentWarningsDesc`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.disable_filament_warnings,onChange:e=>In(`disable_filament_warnings`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.preferLowestFilament`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.preferLowestFilamentDesc`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:i(`settings.preferLowestFilamentBackupNote`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.prefer_lowest_filament,onChange:e=>In(`prefer_lowest_filament`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]})]}),(0,K.jsxs)(pd,{id:`card-printmodal`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.printModal`)})}),(0,K.jsx)(hd,{className:`space-y-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.expandCustomMapping`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.expandCustomMappingDescription`)})]}),(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:O.per_printer_mapping_expanded??!1,onChange:e=>In(`per_printer_mapping_expanded`,e.target.checked),className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})})]}),(0,K.jsxs)(pd,{id:`card-amsthresholds`,children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.amsDisplayThresholds`)})}),(0,K.jsxs)(hd,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.amsThresholdsDescription`)}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,K.jsx)(Rs,{className:`w-4 h-4 text-blue-400`}),(0,K.jsx)(`span`,{className:`font-medium`,children:i(`settings.humidity`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.goodGreen`),` ≤`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,min:`0`,max:`100`,value:O.ams_humidity_good??40,onChange:e=>In(`ams_humidity_good`,parseInt(e.target.value)||40),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.fairOrange`),` ≤`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,min:`0`,max:`100`,value:O.ams_humidity_fair??60,onChange:e=>In(`ams_humidity_fair`,parseInt(e.target.value)||60),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.aboveFairBad`)}),(0,K.jsx)(`p`,{className:`text-xs text-amber-400/70`,children:i(`settings.fairAlsoDryingThreshold`)})]}),(0,K.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,K.jsx)(pu,{className:`w-4 h-4 text-orange-400`}),(0,K.jsx)(`span`,{className:`font-medium`,children:i(`settings.temperature`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.goodBlue`),` ≤`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,step:`0.5`,min:`0`,max:`60`,value:O.ams_temp_good??28,onChange:e=>In(`ams_temp_good`,parseFloat(e.target.value)||28),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.fairOrange`),` ≤`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,step:`0.5`,min:`0`,max:`60`,value:O.ams_temp_fair??35,onChange:e=>In(`ams_temp_fair`,parseFloat(e.target.value)||35),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.aboveFairHot`)})]}),(0,K.jsxs)(`div`,{className:`space-y-3 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,K.jsx)(js,{className:`w-4 h-4 text-purple-400`}),(0,K.jsx)(`span`,{className:`font-medium`,children:i(`settings.historyRetention`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.keepSensorHistory`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,min:`1`,max:`365`,value:O.ams_history_retention_days??30,onChange:e=>In(`ams_history_retention_days`,parseInt(e.target.value)||30),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`common.days`)})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.historyRetentionDescription`)})]})]})]})]}),(0,K.jsxs)(`div`,{className:`lg:w-2/3 space-y-3`,children:[(0,K.jsx)(JRe,{}),(0,K.jsx)(ize,{})]})]})}),be!==null&&(0,K.jsx)(Ed,{title:i(`settings.deleteApiKeyTitle`),message:i(`settings.deleteApiKeyMessage`),confirmText:i(`settings.deleteKey`),variant:`danger`,onConfirm:()=>{jt.mutate(be),xe(null)},onCancel:()=>xe(null)}),A&&(0,K.jsx)(TRe,{plug:M,onClose:()=>{j(!1),N(null)}}),P&&(0,K.jsx)(ORe,{provider:I,onClose:()=>{F(!1),L(null)}}),R&&(0,K.jsx)(kRe,{template:R,onClose:()=>z(null)}),te&&(0,K.jsx)(jRe,{onClose:()=>ne(!1)}),we&&(0,K.jsx)(Ed,{title:i(`settings.clearNotificationLogs`),message:i(`settings.clearLogsMessage`),confirmText:i(`settings.clearLogs`),variant:`warning`,onConfirm:async()=>{Te(!1);try{o((await Q.clearNotificationLogs(30)).message,`success`)}catch{o(i(`settings.toast.clearLogsFailed`),`error`)}},onCancel:()=>Te(!1)}),Ee&&(0,K.jsx)(Ed,{title:i(`settings.resetUiPreferences`),message:i(`settings.resetUiPreferencesMessage`),confirmText:i(`settings.resetPreferences`),variant:`default`,onConfirm:()=>{De(!1),localStorage.clear(),o(i(`settings.toast.uiPreferencesReset`),`success`),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>De(!1)}),Oe&&(0,K.jsx)(Ed,{title:`Turn All Plugs ${Oe===`on`?`On`:`Off`}`,message:`This will turn ${Oe===`on`?`ON`:`OFF`} all ${xt?.filter(e=>e.enabled).length||0} enabled smart plugs. ${Oe===`off`?`Any running printers may be affected!`:``}`,confirmText:`Turn All ${Oe===`on`?`On`:`Off`}`,variant:Oe===`off`?`danger`:`warning`,onConfirm:()=>{let e=Oe;ke(null),kn.mutate(e)},onCancel:()=>ke(null)}),Ae&&Qt?.release_notes&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>je(!1),children:(0,K.jsxs)(pd,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(md,{className:`flex flex-row items-center justify-between shrink-0`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[`Release Notes - v`,Qt.latest_version]}),Qt.release_name&&Qt.release_name!==Qt.latest_version&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:Qt.release_name})]}),(0,K.jsx)(`button`,{onClick:()=>je(!1),className:`p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsx)(hd,{className:`overflow-y-auto flex-1`,children:(0,K.jsx)(`pre`,{className:`text-sm text-bambu-gray whitespace-pre-wrap font-sans`,children:Qt.release_notes})}),(0,K.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2`,children:[Qt.release_url&&(0,K.jsx)(`a`,{href:Qt.release_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex-1`,children:(0,K.jsxs)($,{variant:`secondary`,className:`w-full`,children:[(0,K.jsx)(Us,{className:`w-4 h-4`}),`View on GitHub`]})}),(0,K.jsx)($,{onClick:()=>je(!1),className:`flex-1`,children:`Close`})]})]})}),W===`users`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`button`,{onClick:()=>ce(`users`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${se===`users`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(wu,{className:`w-4 h-4`}),i(`settings.tabs.users`)]}),(0,K.jsxs)(`button`,{onClick:()=>ce(`email`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${se===`email`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(Gc,{className:`w-4 h-4`}),i(`settings.tabs.emailAuth`)||`Email Authentication`,sn?.advanced_auth_enabled&&(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,K.jsxs)(`button`,{onClick:()=>ce(`ldap`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${se===`ldap`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(Hl,{className:`w-4 h-4`}),i(`settings.tabs.ldap`)||`LDAP`,cn?.ldap_enabled&&(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,K.jsxs)(`button`,{onClick:()=>ce(`twofa`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${se===`twofa`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(Hl,{className:`w-4 h-4`}),i(`settings.tabs.twoFa`),(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${ln?.totp_enabled||ln?.email_otp_enabled?`bg-green-400`:`bg-bambu-gray/40`}`})]}),l&&(0,K.jsxs)(`button`,{onClick:()=>ce(`oidc`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${se===`oidc`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(hc,{className:`w-4 h-4`}),i(`settings.tabs.oidc`),(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full ${un.some(e=>e.is_enabled)?`bg-green-400`:`bg-bambu-gray/40`}`})]}),l&&(0,K.jsxs)(`button`,{onClick:()=>ce(`security`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${se===`security`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,K.jsx)(Hl,{className:`w-4 h-4`}),i(`settings.tabs.security`)]})]}),se===`users`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${s?`bg-green-500/20`:`bg-gray-500/20`}`,children:s?(0,K.jsx)(Hc,{className:`w-5 h-5 text-green-400`}):(0,K.jsx)(Vc,{className:`w-5 h-5 text-gray-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-white font-medium`,children:i(`settings.authentication`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(s?`settings.authEnabledDescription`:`settings.authDisabledDescription`)})]})]}),s?c?.is_admin&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>Ne(!0),children:[(0,K.jsx)(Vc,{className:`w-4 h-4`}),i(`common.disable`)]}):(0,K.jsxs)($,{onClick:()=>t(`/setup`),children:[(0,K.jsx)(Hc,{className:`w-4 h-4`}),i(`common.enable`)]})]})})}),sn?.advanced_auth_enabled&&(0,K.jsx)(pd,{className:`border-blue-500/30 bg-blue-500/5`,children:(0,K.jsx)(hd,{className:`py-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0`,children:(0,K.jsx)(Gc,{className:`w-5 h-5 text-blue-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-white font-medium`,children:i(`settings.email.advancedAuthEnabled`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.email.advancedAuthEnabledDesc`)})]})]})})}),s&&(0,K.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-6`,children:[(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(pd,{id:`card-session-policy`,children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Hc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.sessionPolicy.title`)]})}),(0,K.jsxs)(hd,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:i(`settings.sessionPolicy.description`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2 mb-4`,children:[[{hours:24,labelKey:`settings.sessionPolicy.preset24h`},{hours:168,labelKey:`settings.sessionPolicy.preset7d`},{hours:720,labelKey:`settings.sessionPolicy.preset30d`}].map(e=>{let t=(O?.session_max_hours??24)===e.hours;return(0,K.jsx)(`button`,{type:`button`,onClick:()=>In(`session_max_hours`,e.hours),disabled:s&&!d(`settings:update`),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors ${t?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark`} disabled:opacity-50 disabled:cursor-not-allowed`,children:i(e.labelKey)},e.hours)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`input`,{type:`number`,min:1,max:720,value:O?.session_max_hours??24,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||In(`session_max_hours`,Math.max(1,Math.min(720,t)))},disabled:s&&!d(`settings:update`),"aria-label":i(`settings.sessionPolicy.customHoursLabel`),className:`w-20 px-2 py-2 bg-bambu-dark-tertiary text-white text-sm rounded-lg border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:i(`settings.sessionPolicy.hoursSuffix`)})]})]}),(O?.session_max_hours??24)>24&&(0,K.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-yellow-400 flex-shrink-0 mt-0.5`}),(0,K.jsx)(`p`,{className:`text-xs text-yellow-200`,children:i(`settings.sessionPolicy.warning`)})]})]})]}),c&&(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-currentuser`,children:[(0,K.jsx)(wu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.currentUser`)]}),c.auth_source!==`ldap`&&(0,K.jsxs)($,{size:`sm`,variant:`ghost`,onClick:()=>Fe(!0),children:[(0,K.jsx)(jc,{className:`w-4 h-4`}),i(`settings.changePassword`)]})]})}),(0,K.jsx)(hd,{children:(0,K.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium text-lg`,children:c.username}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-2`,children:[c.is_admin&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300`,children:i(`settings.admin`)}),c.groups?.map(e=>(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium ${e.name===`Administrators`?`bg-purple-500/20 text-purple-300`:e.name===`Operators`?`bg-blue-500/20 text-blue-300`:e.name===`Viewers`?`bg-green-500/20 text-green-300`:`bg-gray-500/20 text-gray-300`}`,children:e.name},e.id))]})]})})})]}),(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-users`,children:[(0,K.jsx)(wu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.users`)]}),d(`users:create`)&&(0,K.jsxs)($,{size:`sm`,onClick:()=>{Ue(!0),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.addUser`)]})]})}),(0,K.jsx)(hd,{children:fn?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})}):dn.length===0?(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-8`,children:i(`settings.noUsersFound`)}):(0,K.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:dn.map(e=>(0,K.jsxs)(`div`,{className:`py-3 flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.username}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:[e.auth_source===`ldap`&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-cyan-500/20 text-cyan-300`,children:`LDAP`}),e.is_admin&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300`,children:i(`settings.admin`)}),e.groups?.map(e=>(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium ${e.name===`Administrators`?`bg-purple-500/20 text-purple-300`:e.name===`Operators`?`bg-blue-500/20 text-blue-300`:e.name===`Viewers`?`bg-green-500/20 text-green-300`:`bg-gray-500/20 text-gray-300`}`,children:e.name},e.id))]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 ml-4`,children:[d(`users:update`)&&(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>Cn(e),children:(0,K.jsx)(fl,{className:`w-4 h-4`})}),d(`users:delete`)&&e.id!==c?.id&&(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>yn(e.id),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]},e.id))})})]})]}),(0,K.jsx)(`div`,{children:(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-groups`,children:[(0,K.jsx)(Hl,{className:`w-5 h-5 text-bambu-green`}),i(`settings.groups`)]}),d(`groups:create`)&&(0,K.jsxs)($,{size:`sm`,onClick:()=>t(`/groups/new`),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.addGroup`)]})]})}),(0,K.jsx)(hd,{children:mn?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})}):pn.length===0?(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-8`,children:i(`settings.noGroupsFound`)}):(0,K.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:pn.map(e=>(0,K.jsxs)(`div`,{className:`py-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Hl,{className:`w-4 h-4 ${e.name===`Administrators`?`text-purple-400`:e.name===`Operators`?`text-blue-400`:e.name===`Viewers`?`text-green-400`:`text-bambu-gray`}`}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:e.name}),e.is_system&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400`,children:i(`settings.system`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[d(`groups:update`)&&(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>t(`/groups/${e.id}/edit`),children:(0,K.jsx)(fl,{className:`w-4 h-4`})}),d(`groups:delete`)&&!e.is_system&&(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>at(e.id),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1 ml-6`,children:e.description||i(`settings.noDescription`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:i(`settings.userCount`,{count:e.user_count})}),(0,K.jsx)(`span`,{children:i(`settings.permissionCount`,{count:e.permissions.length})})]})]},e.id))})})]})})]}),!s&&(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`py-6`,children:(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(Vc,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,K.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.authDisabledTitle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 max-w-md mx-auto`,children:i(`settings.authDisabledMessage`)}),(0,K.jsxs)(`ul`,{className:`space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto`,children:[(0,K.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(ls,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,K.jsx)(`span`,{children:i(`settings.authDisabledFeature1`)})]}),(0,K.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(ls,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,K.jsx)(`span`,{children:i(`settings.authDisabledFeature2`)})]}),(0,K.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(ls,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,K.jsx)(`span`,{children:i(`settings.authDisabledFeature3`)})]})]}),(0,K.jsxs)($,{onClick:()=>t(`/setup`),children:[(0,K.jsx)(Hc,{className:`w-4 h-4`}),i(`settings.enableAuthentication`)]})]})})})]}),se===`email`&&(0,K.jsx)(`div`,{className:`max-w-5xl`,id:`card-smtp`,children:(0,K.jsx)(Sze,{})}),se===`ldap`&&(0,K.jsx)(`div`,{className:`max-w-5xl`,id:`card-ldap`,children:(0,K.jsx)(wze,{})}),se===`twofa`&&(0,K.jsx)(`div`,{className:`max-w-2xl`,children:(0,K.jsx)(Eze,{})}),se===`oidc`&&l&&(0,K.jsx)(`div`,{className:`max-w-3xl`,children:(0,K.jsx)(kze,{})}),se===`security`&&l&&(0,K.jsx)(`div`,{className:`max-w-3xl`,children:(0,K.jsx)(jze,{})})]}),He&&!sn?.advanced_auth_enabled&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black flex items-center justify-center z-50 p-4`,onClick:()=>{Ue(!1),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,K.jsxs)(pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(wu,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.createUser`)})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{Ue(!1),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]})}),(0,K.jsxs)(hd,{children:[cn?.ldap_enabled&&(0,K.jsxs)(`div`,{className:`mb-4 flex items-center gap-1 p-1 bg-bambu-dark-secondary rounded-lg`,role:`tablist`,"aria-label":i(`users.modal.tabsAriaLabel`),children:[(0,K.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":We===`local`,onClick:()=>Ge(`local`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${We===`local`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:i(`users.modal.localTab`)}),(0,K.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":We===`ldap`,onClick:()=>Ge(`ldap`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${We===`ldap`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:i(`users.modal.ldapTab`)})]}),We===`ldap`&&cn?.ldap_enabled?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(z5,{onSuccess:e=>{Ue(!1),Ge(`local`),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`users.toast.ldapProvisioned`,{username:e.username}))}}),(0,K.jsx)(`div`,{className:`mt-6 flex justify-end`,children:(0,K.jsx)($,{variant:`secondary`,onClick:()=>{Ue(!1),Ge(`local`),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`common.cancel`)})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.username`)}),(0,K.jsx)(`input`,{type:`text`,value:nt.username,onChange:e=>rt({...nt,username:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterUsername`),autoComplete:`username`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.password`)}),(0,K.jsx)(`input`,{type:`password`,value:nt.password,onChange:e=>rt({...nt,password:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterPassword`),autoComplete:`new-password`,minLength:8}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:i(`settings.passwordRequirements`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.confirmPassword`)}),(0,K.jsx)(`input`,{type:`password`,value:nt.confirmPassword,onChange:e=>rt({...nt,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${nt.confirmPassword&&nt.password!==nt.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmPasswordPlaceholder`),autoComplete:`new-password`,minLength:6}),nt.confirmPassword&&nt.password!==nt.confirmPassword&&(0,K.jsx)(`p`,{className:`text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.groups`)}),(0,K.jsxs)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[pn.map(e=>(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:nt.group_ids.includes(e.id),onChange:()=>wn(e.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:e.name}),e.is_system&&(0,K.jsx)(`span`,{className:`text-xs text-yellow-400`,children:i(`settings.systemBadge`)})]},e.id)),pn.length===0&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.noGroupsAvailable`)})]})]})]}),(0,K.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>{Ue(!1),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`common.cancel`)}),(0,K.jsx)($,{onClick:xn,disabled:hn.isPending||!nt.username||!nt.password||nt.password!==nt.confirmPassword||m5(nt.password)!==null,children:hn.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),i(`settings.creating`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),i(`settings.createUser`)]})})]})]})]})]})}),He&&sn?.advanced_auth_enabled&&(0,K.jsx)(KRe,{formData:nt,setFormData:rt,groups:pn,onClose:()=>{Ue(!1),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},onCreate:xn,isCreating:hn.isPending,isCreateButtonDisabled:hn.isPending||!nt.username||!nt.email,ldapEnabled:cn?.ldap_enabled,onLdapProvisioned:e=>{Ue(!1),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`users.toast.ldapProvisioned`,{username:e.username}))}}),Ke&&Je!==null&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black flex items-center justify-center z-50 p-4`,onClick:()=>{qe(!1),Ye(null),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,K.jsxs)(pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(fl,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.editUser`)})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{qe(!1),Ye(null),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]})}),(0,K.jsxs)(hd,{children:[(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`settings.username`),` `,sn?.advanced_auth_enabled&&(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsx)(`input`,{type:`text`,value:nt.username,onChange:e=>rt({...nt,username:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterUsername`),autoComplete:`username`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`users.form.email`)||`Email`,` `,sn?.advanced_auth_enabled?(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`}):(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,i(`users.form.optional`)||`optional`,`)`]})]}),(0,K.jsx)(`input`,{type:`email`,value:nt.email,onChange:e=>rt({...nt,email:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`users.form.emailPlaceholder`)||`user@example.com`,required:sn?.advanced_auth_enabled})]}),!sn?.advanced_auth_enabled&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`users.form.password`)||`Password`,` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,i(`users.form.leaveBlankToKeep`)||`leave blank to keep current`,`)`]})]}),(0,K.jsx)(`input`,{type:`password`,value:nt.password,onChange:e=>rt({...nt,password:e.target.value,confirmPassword:``}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterNewPassword`),autoComplete:`new-password`,minLength:8}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:i(`settings.passwordRequirements`)})]}),nt.password&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.confirmPassword`)}),(0,K.jsx)(`input`,{type:`password`,value:nt.confirmPassword,onChange:e=>rt({...nt,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${nt.confirmPassword&&nt.password!==nt.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmNewPassword`),autoComplete:`new-password`,minLength:6}),nt.confirmPassword&&nt.password!==nt.confirmPassword&&(0,K.jsx)(`p`,{className:`text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]})]}),sn?.advanced_auth_enabled&&(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`users.form.passwordManagedByAdvancedAuth`)||`Password is managed by Advanced Authentication. Use "Reset Password" to send a new password to the user via email.`}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>Je&&vn.mutate(Je),disabled:vn.isPending||!nt.email,className:`w-full`,children:vn.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),i(`users.form.resettingPassword`)||`Resetting Password...`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),i(`users.form.resetPassword`)||`Reset Password`]})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`users.form.groups`)||`Groups`}),(0,K.jsx)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:pn.map(e=>(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:nt.group_ids.includes(e.id),onChange:()=>wn(e.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:e.name}),e.is_system&&(0,K.jsxs)(`span`,{className:`text-xs text-yellow-400`,children:[`(`,i(`users.system`)||`System`,`)`]})]},e.id))})]})]}),(0,K.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>{qe(!1),Ye(null),rt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`users.modal.cancel`)||`Cancel`}),(0,K.jsx)($,{onClick:()=>Sn(Je),disabled:gn.isPending||!nt.username||sn?.advanced_auth_enabled&&!nt.email||!!(!sn?.advanced_auth_enabled&&nt.password&&(nt.password!==nt.confirmPassword||m5(nt.password)!==null)),children:gn.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),i(`users.modal.saving`)||`Saving...`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),i(`users.modal.saveChanges`)||`Save Changes`]})})]})]})]})}),Xe!==null&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,onClick:()=>{Ze(null),$e(null)},children:(0,K.jsxs)(pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-red-400`,children:[(0,K.jsx)(hu,{className:`w-5 h-5`}),(0,K.jsx)(`h3`,{className:`text-lg font-semibold`,children:i(`settings.deleteUserTitle`)})]})}),(0,K.jsx)(hd,{className:`space-y-3`,children:et?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,K.jsx)(`div`,{className:`animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent`})}):Qe&&Qe.archives+Qe.queue_items+Qe.library_files>0?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.userHasCreated`)}),(0,K.jsxs)(`ul`,{className:`list-disc list-inside text-bambu-gray space-y-1`,children:[Qe.archives>0&&(0,K.jsxs)(`li`,{children:[Qe.archives,` archive`,Qe.archives===1?``:`s`]}),Qe.queue_items>0&&(0,K.jsxs)(`li`,{children:[Qe.queue_items,` queue item`,Qe.queue_items===1?``:`s`]}),Qe.library_files>0&&(0,K.jsxs)(`li`,{children:[Qe.library_files,` library file`,Qe.library_files===1?``:`s`]})]}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:i(`settings.userItemsQuestion`)}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)($,{variant:`danger`,onClick:()=>_n.mutate({id:Xe,deleteItems:!0}),disabled:_n.isPending,className:`justify-center`,children:i(`settings.deleteUserAndItems`)}),(0,K.jsx)($,{variant:`secondary`,onClick:()=>_n.mutate({id:Xe,deleteItems:!1}),disabled:_n.isPending,className:`justify-center`,children:i(`settings.deleteUserKeepItems`)}),(0,K.jsx)($,{variant:`ghost`,onClick:()=>{Ze(null),$e(null)},disabled:_n.isPending,className:`justify-center`,children:i(`common.cancel`)})]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-white`,children:i(`settings.deleteUserConfirm`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:i(`settings.actionCannotBeUndone`)}),(0,K.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,K.jsx)($,{variant:`ghost`,onClick:()=>{Ze(null),$e(null)},disabled:_n.isPending,children:i(`common.cancel`)}),(0,K.jsx)($,{variant:`danger`,onClick:()=>_n.mutate({id:Xe,deleteItems:!1}),disabled:_n.isPending,children:i(`settings.deleteUserTitle`)})]})]})})]})}),it!==null&&(0,K.jsx)(Ed,{title:i(`settings.deleteGroupTitle`),message:i(`settings.deleteGroupMessage`),confirmText:i(`settings.deleteGroup`),variant:`danger`,onConfirm:()=>{bn.mutate(it),at(null)},onCancel:()=>at(null)}),W===`failure-detection`&&(0,K.jsx)(`div`,{id:`card-failure-detection`,children:(0,K.jsx)(yze,{})}),W===`backup`&&(0,K.jsxs)(`div`,{id:`card-backup`,children:[(0,K.jsxs)(`div`,{className:`mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg flex items-start gap-2`,children:[(0,K.jsx)(Hl,{className:`text-amber-400 flex-shrink-0 mt-0.5`,size:16}),(0,K.jsx)(`p`,{className:`text-sm text-amber-400`,children:i(`backup.includesEncryptionKey`)})]}),(0,K.jsx)(vze,{})]}),Me&&(0,K.jsx)(Ed,{title:i(`settings.disableAuthenticationTitle`),message:i(`settings.disableAuthenticationMessage`),confirmText:i(`settings.disableAuthentication`),variant:`danger`,onConfirm:async()=>{try{await Q.disableAuth(),o(i(`settings.toast.authDisabled`),`success`),await u(),Ne(!1),window.location.href=`/`}catch(e){o(e instanceof Error?e.message:i(`settings.toast.authDisableFailed`),`error`)}},onCancel:()=>Ne(!1)}),Pe&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>{Fe(!1),Le({currentPassword:``,newPassword:``,confirmPassword:``})},children:(0,K.jsxs)(pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(jc,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.changePassword`)})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{Fe(!1),Le({currentPassword:``,newPassword:``,confirmPassword:``})},children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]})}),(0,K.jsxs)(hd,{children:[(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`Current Password`}),(0,K.jsx)(`input`,{type:`password`,value:Ie.currentPassword,onChange:e=>Le({...Ie,currentPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterCurrentPassword`),autoComplete:`current-password`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`New Password`}),(0,K.jsx)(`input`,{type:`password`,value:Ie.newPassword,onChange:e=>Le({...Ie,newPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterNewPasswordMin6`),autoComplete:`new-password`,minLength:6})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`Confirm New Password`}),(0,K.jsx)(`input`,{type:`password`,value:Ie.confirmPassword,onChange:e=>Le({...Ie,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${Ie.confirmPassword&&Ie.newPassword!==Ie.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmNewPassword`),autoComplete:`new-password`,minLength:6}),Ie.confirmPassword&&Ie.newPassword!==Ie.confirmPassword&&(0,K.jsx)(`p`,{className:`text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]})]}),(0,K.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>{Fe(!1),Le({currentPassword:``,newPassword:``,confirmPassword:``})},children:i(`common.cancel`)}),(0,K.jsx)($,{onClick:async()=>{if(Ie.newPassword!==Ie.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}if(Ie.newPassword.length<6){o(i(`settings.toast.passwordTooShort`),`error`);return}ze(!0);try{await Q.changePassword(Ie.currentPassword,Ie.newPassword),o(i(`settings.toast.passwordChanged`),`success`),Fe(!1),Le({currentPassword:``,newPassword:``,confirmPassword:``})}catch(e){o(e instanceof Error?e.message:`Failed to change password`,`error`)}finally{ze(!1)}},disabled:Re||!Ie.currentPassword||!Ie.newPassword||Ie.newPassword!==Ie.confirmPassword||Ie.newPassword.length<6,children:Re?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),i(`settings.changing`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(jc,{className:`w-4 h-4`}),i(`settings.changePassword`)]})})]})]})]})})]})]})]})})}var u7=e=>(Math.trunc(parseFloat(e)*1e3)/1e3).toFixed(3),zze=e=>e.startsWith(`HH`)?`HF`:`S`,Bze=e=>{let t=e.match(/^([A-Z]{2}\d{2})/);return t?t[1]:`HH00`},d7=e=>{for(let t of[`High Flow_`,`High Flow `,`Standard_`,`Standard `,`HF_`,`HF `,`S_`,`S `])if(e.startsWith(t))return e.slice(t.length);let t=e.indexOf(`_`);return t>0?e.slice(t+1):e};function f7({profile:e,onEdit:t,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:a,note:o}){let s=zze(e.nozzle_id),c=e.nozzle_diameter;return(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,K.jsx)(`button`,{onClick:a,className:`text-bambu-gray hover:text-white transition-colors p-1`,children:i?(0,K.jsx)($l,{className:`w-4 h-4 text-bambu-green`}):(0,K.jsx)(tu,{className:`w-4 h-4`})}),(0,K.jsxs)(`button`,{onClick:()=>{r&&a?a():t()},className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?`ring-1 ring-bambu-green`:``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-green font-mono text-sm font-bold whitespace-nowrap`,children:u7(e.k_value)}),(0,K.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name||`Unnamed`}),o&&(0,K.jsx)(`span`,{title:`Has note`,children:(0,K.jsx)(iu,{className:`w-3 h-3 text-yellow-500`})}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:[s,` `,c]})]}),o&&(0,K.jsxs)(`div`,{className:`text-xs mt-0.5 truncate text-yellow-500/70`,title:o,children:[`Note: `,o.length>50?o.substring(0,50)+`...`:o]})]}),!r&&n&&(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`text-bambu-gray hover:text-white transition-colors p-1`,title:`Copy profile`,children:(0,K.jsx)(Ds,{className:`w-4 h-4`})})]})}function p7({profile:e,printerId:t,nozzleDiameter:n,existingProfiles:r=[],builtinFilaments:i=[],isDualNozzle:a=!1,initialNote:o=``,initialNoteKey:s=null,onClose:c,onSave:l,onSaveNote:u,hasPermission:d}){let{t:f}=G(),{showToast:p}=xd(),[m,h]=(0,y.useState)(e?.name||``),[g,_]=(0,y.useState)(e?.k_value?u7(e.k_value):`0.020`),[v,b]=(0,y.useState)(e?.filament_id||``),[x,S]=(0,y.useState)(e?.nozzle_id?Bze(e.nozzle_id):`HH00`),[C,w]=(0,y.useState)(e?.nozzle_diameter||n),[T,E]=(0,y.useState)(e?[e.extruder_id]:a?[0,1]:[0]),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)({current:0,total:0}),[j,M]=(0,y.useState)(o),N=y.useMemo(()=>{let e=new Map;for(let t of i)e.set(t.filament_id,t.name);let t=new Map;for(let n of r)if(n.filament_id&&!t.has(n.filament_id)){let r=e.get(n.filament_id)||d7(n.name||``);t.set(n.filament_id,{id:n.filament_id,name:r||n.filament_id})}return Array.from(t.values()).sort((e,t)=>e.name.localeCompare(t.name))},[r,i]),P=J({mutationFn:e=>(console.log(`[KProfile] Calling API...`),Q.setKProfile(t,e)),onSuccess:t=>{if(console.log(`[KProfile] Save success:`,t),p(f(`kProfiles.toast.profileSaved`)),u&&j!==o){let t;t=j===``&&s?s:e&&e.slot_id>0?e.setting_id||`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`:`name_${m}_${v}`,u(t,j)}O(!0),setTimeout(()=>{O(!1),l()},2500)},onError:e=>{console.error(`[KProfile] Save error:`,e),p(e.message,`error`),O(!1)}}),F=J({mutationFn:e=>(console.log(`[KProfile] Deleting profile...`),Q.deleteKProfile(t,e)),onSuccess:e=>{console.log(`[KProfile] Delete success:`,e),p(f(`kProfiles.toast.profileDeleted`)),O(!0),setTimeout(()=>{O(!1),c()},4e3)},onError:e=>{console.error(`[KProfile] Delete error:`,e),p(e.message,`error`),O(!1)}}),[I,L]=(0,y.useState)(!1),R=()=>{e&&F.mutate({slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id})};return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:[(0,K.jsxs)(pd,{className:`w-full max-w-md relative`,children:[D&&(0,K.jsxs)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg`,children:[(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin mb-3`}),(0,K.jsx)(`p`,{className:`text-white font-medium`,children:k.total>1?f(`kProfiles.modal.savingExtruder`,{current:k.current,total:k.total}):f(`kProfiles.modal.syncing`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm mt-1`,children:f(`kProfiles.modal.pleaseWait`)})]}),(0,K.jsxs)(hd,{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.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:f(e?`kProfiles.modal.editTitle`:`kProfiles.modal.addTitle`)}),(0,K.jsx)(`button`,{onClick:c,className:`text-bambu-gray hover:text-white transition-colors`,disabled:D,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),a&&!e&&T.length===0){p(f(`kProfiles.toast.selectAtLeastOneExtruder`),`error`);return}let r=parseFloat(g).toFixed(6),i=`${x}-${C}`;if(e||T.length===1){let t={name:m,k_value:r,filament_id:v,nozzle_id:i,nozzle_diameter:C,extruder_id:e?e.extruder_id:T[0],setting_id:e?.setting_id,slot_id:e?.slot_id??0};console.log(`[KProfile] Saving profile:`,t),P.mutate(t);return}O(!0),A({current:1,total:T.length});let o=T.map(e=>({name:m,k_value:r,filament_id:v,nozzle_id:i,nozzle_diameter:C,extruder_id:e,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${o.length} profiles in batch:`,o);try{await Q.setKProfilesBatch(t,o),p(f(`kProfiles.toast.profilesSaved`,{count:T.length})),u&&j&&u(`name_${m}_${v}`,j)}catch(e){console.error(`[KProfile] Failed to save batch:`,e),p(f(`kProfiles.toast.failedToSaveBatch`),`error`),O(!1),A({current:0,total:0});return}A({current:T.length,total:T.length}),setTimeout(()=>{O(!1),A({current:0,total:0}),l()},3e3)},className:`p-4 space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(`kProfiles.modal.profileName`)}),(0,K.jsx)(`input`,{type:`text`,value:m,onChange:e=>h(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,placeholder:f(`kProfiles.modal.profileNamePlaceholder`),required:!e})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(`kProfiles.modal.kValue`)}),(0,K.jsx)(`input`,{type:`text`,inputMode:`decimal`,value:g,onChange:e=>{let t=e.target.value;(t===``||/^\d*\.?\d*$/.test(t))&&_(t)},onBlur:e=>{let t=parseFloat(e.target.value);isNaN(t)||_((Math.trunc(t*1e3)/1e3).toFixed(3))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono`,placeholder:f(`kProfiles.modal.kValuePlaceholder`),required:!0}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:f(`kProfiles.modal.kValueHelp`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(`kProfiles.modal.filament`)}),(0,K.jsxs)(`select`,{value:v,onChange:t=>{let n=t.target.value;if(b(n),!e&&n&&!m){let e=N.find(e=>e.id===n);e&&h(`${x===`HH00`?`HF`:`S`} ${e.name}`)}},disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,required:!e,children:[(0,K.jsx)(`option`,{value:``,children:f(`kProfiles.modal.selectFilament`)}),e?.filament_id&&(0,K.jsx)(`option`,{value:e.filament_id,children:N.find(t=>t.id===e.filament_id)?.name||e.filament_id},e.filament_id),!e&&N.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),!e&&N.length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:f(`kProfiles.modal.noFilamentsHelp`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(`kProfiles.modal.flowType`)}),(0,K.jsxs)(`select`,{value:x,onChange:t=>{let n=t.target.value;if(S(n),!e&&v&&!m){let e=N.find(e=>e.id===v);e&&h(`${n===`HS00`?`HF`:`S`} ${e.name}`)}},disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,K.jsx)(`option`,{value:`HH00`,children:f(`kProfiles.modal.highFlow`)}),(0,K.jsx)(`option`,{value:`HS00`,children:f(`kProfiles.modal.standard`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(`kProfiles.modal.nozzleSize`)}),(0,K.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,K.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,K.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,K.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,K.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]})]}),a&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(e?`kProfiles.modal.extruder`:`kProfiles.modal.extruders`)}),e?(0,K.jsx)(`div`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:e.extruder_id===1?f(`kProfiles.modal.left`):f(`kProfiles.modal.right`)}):(0,K.jsxs)(`div`,{className:`flex gap-4`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:T.includes(1),onChange:e=>{e.target.checked?E([...T,1]):E(T.filter(e=>e!==1))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,K.jsx)(`span`,{className:`text-white`,children:f(`kProfiles.modal.left`)})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:T.includes(0),onChange:e=>{e.target.checked?E([...T,0]):E(T.filter(e=>e!==0))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,K.jsx)(`span`,{className:`text-white`,children:f(`kProfiles.modal.right`)})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(`kProfiles.modal.notes`)}),(0,K.jsx)(`textarea`,{value:j,onChange:e=>M(e.target.value),placeholder:f(`kProfiles.modal.notesPlaceholder`),rows:2,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:f(`kProfiles.modal.notesHelp`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 pt-4`,children:[e&&(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:()=>L(!0),disabled:F.isPending||D||!d(`kprofiles:delete`),title:d(`kprofiles:delete`)?void 0:f(`kProfiles.permission.noDelete`),className:`text-red-500 hover:bg-red-500/10`,children:F.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hu,{className:`w-4 h-4`})}),(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:c,disabled:D,className:`flex-1`,children:f(`common.cancel`)}),(0,K.jsxs)($,{type:`submit`,disabled:P.isPending||D||!d(e?`kprofiles:update`:`kprofiles:create`),title:d(e?`kprofiles:update`:`kprofiles:create`)?void 0:f(e?`kProfiles.permission.noUpdate`:`kProfiles.permission.noCreate`),className:`flex-1`,children:[P.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(uc,{className:`w-4 h-4`}),f(`common.save`)]})]})]})]})]}),I&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-[60]`,children:(0,K.jsx)(pd,{className:`w-full max-w-sm`,children:(0,K.jsxs)(hd,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,K.jsx)(hu,{className:`w-5 h-5 text-red-500`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:f(`kProfiles.deleteConfirm.title`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:f(`kProfiles.deleteConfirm.cannotUndo`)})]})]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:f(`kProfiles.deleteConfirm.message`,{name:e?.name})}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>L(!1),className:`flex-1`,children:f(`common.cancel`)}),(0,K.jsxs)($,{onClick:()=>{L(!1),R()},disabled:F.isPending,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[F.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hu,{className:`w-4 h-4`}),f(`common.delete`)]})]})]})})})]})}var m7={NOZZLE_DIAMETER:`bambusy_kprofiles_nozzle`,SORT_OPTION:`bambusy_kprofiles_sort`};function Vze(){let{t:e}=G(),{showToast:t}=xd(),{hasPermission:n}=sd(),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(()=>localStorage.getItem(m7.NOZZLE_DIAMETER)||`0.4`),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(`all`),[b,x]=(0,y.useState)(()=>localStorage.getItem(m7.SORT_OPTION)||`name`),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(new Set),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),A=(0,y.useCallback)(e=>`${e.slot_id}_${e.extruder_id}`,[]);(0,y.useEffect)(()=>{localStorage.setItem(m7.NOZZLE_DIAMETER,a)},[a]),(0,y.useEffect)(()=>{localStorage.setItem(m7.SORT_OPTION,b)},[b]);let{data:j,isLoading:M}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:N,isLoading:P,isFetching:F,error:I,refetch:L}=q({queryKey:[`kprofiles`,r,a],queryFn:async()=>{console.log(`[KProfiles] Fetching profiles for printer`,r,`nozzle`,a);let e=await Q.getKProfiles(r,a);return console.log(`[KProfiles] Received profiles:`,e?.profiles?.length||0,`profiles`),e},enabled:!!r,retry:!1,staleTime:0,gcTime:0,refetchOnMount:`always`}),{data:R}=q({queryKey:[`kprofiles`,r,`0.4`],queryFn:()=>Q.getKProfiles(r,`0.4`),enabled:!!r,staleTime:6e4}),{data:z}=q({queryKey:[`builtinFilaments`],queryFn:()=>Q.getBuiltinFilaments(),staleTime:3e5}),{data:B}=q({queryKey:[`filamentIdMap`],queryFn:()=>Q.getFilamentIdMap(),staleTime:3e5}),{data:V,refetch:ee}=q({queryKey:[`kprofile-notes`,r],queryFn:()=>Q.getKProfileNotes(r),enabled:!!r,staleTime:3e4}),H=I?.message?.includes(`not connected`);(0,y.useEffect)(()=>{if(!r&&j&&j.length>0){let e=j.find(e=>e.is_active);e&&i(e.id)}},[r,j]),(0,y.useEffect)(()=>{if(r){let e=setTimeout(()=>{L()},150);return()=>clearTimeout(e)}},[r,a]);let te=j?.filter(e=>e.is_active)||[],ne=y.useMemo(()=>{let e=new Map;if(z)for(let t of z)e.set(t.filament_id,t.name);if(B)for(let[t,n]of Object.entries(B))e.has(t)||e.set(t,n);return e},[z,B]),re=y.useMemo(()=>Array.from(ne.entries()).map(([e,t])=>({filament_id:e,name:t})),[ne]),U=y.useCallback(e=>ne.get(e.filament_id)||d7(e.name),[ne]),ie=y.useMemo(()=>N?.profiles?N.profiles.filter(e=>{let t=p.toLowerCase(),n=!t||e.name.toLowerCase().includes(t)||e.filament_id.toLowerCase().includes(t),r=h===`all`||h===`left`&&e.extruder_id===1||h===`right`&&e.extruder_id===0,i=_===`all`||_===`hf`&&e.nozzle_id.startsWith(`HH`)||_===`s`&&e.nozzle_id.startsWith(`HS`);return n&&r&&i}).sort((e,t)=>{switch(b){case`k_value`:return parseFloat(e.k_value)-parseFloat(t.k_value);case`filament`:return U(e).localeCompare(U(t));default:return e.name.localeCompare(t.name)}}):[],[N?.profiles,p,h,_,b,U]),ae=j?.find(e=>e.id===r),W=ae?.nozzle_count===2;(0,y.useEffect)(()=>{let e=e=>{e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||s||l||d||(e.key===`r`||e.key===`R`?(e.preventDefault(),L()):e.key===`n`||e.key===`N`?(e.preventDefault(),u(!0)):e.key===`Escape`&&S&&(e.preventDefault(),C(!1),T(new Set)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[s,l,d,S,L]);let oe=(0,y.useCallback)(()=>{if(!N?.profiles||N.profiles.length===0){t(e(`kProfiles.toast.noProfilesToExport`),`error`);return}let n={version:1,exported_at:new Date().toISOString(),printer:ae?.name||`Unknown`,nozzle_diameter:a,profiles:N.profiles.map(e=>({name:e.name,k_value:e.k_value,filament_id:e.filament_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,extruder_id:e.extruder_id}))},r=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),i=URL.createObjectURL(r),o=document.createElement(`a`);o.href=i,o.download=`kprofiles_${ae?.name||`printer`}_${a}mm_${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(i),t(e(`kProfiles.toast.exportedProfiles`,{count:N.profiles.length}))},[N?.profiles,ae,a,t,e]),se=(0,y.useCallback)(()=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async n=>{let i=n.target.files?.[0];if(i)try{let n=await i.text(),o=JSON.parse(n);if(!o.profiles||!Array.isArray(o.profiles)){t(e(`kProfiles.toast.invalidFileFormat`),`error`);return}let s=0;for(let e of o.profiles)if(!(!e.name||!e.k_value||!e.filament_id))try{await Q.setKProfile(r,{name:e.name,k_value:parseFloat(e.k_value).toFixed(6),filament_id:e.filament_id,nozzle_id:e.nozzle_id||`HH00-${a}`,nozzle_diameter:e.nozzle_diameter||a,extruder_id:e.extruder_id??0,slot_id:0}),s++,await new Promise(e=>setTimeout(e,500))}catch(t){console.error(`Failed to import profile:`,e.name,t)}t(e(`kProfiles.toast.importedProfiles`,{count:s,total:o.profiles.length})),L()}catch(n){console.error(`Import error:`,n),t(e(`kProfiles.toast.failedToParseImport`),`error`)}},n.click()},[r,a,t,L,e]),ce=(0,y.useCallback)(e=>{T(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),le=(0,y.useCallback)(()=>{T(new Set(ie.map(e=>A(e))))},[ie,A]),ue=(0,y.useCallback)(()=>{w.size!==0&&D(!0)},[w.size]),de=(0,y.useCallback)(async()=>{let n=ie.filter(e=>w.has(A(e)));k(!0);let i=0;for(let e of n)try{await Q.deleteKProfile(r,{slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id}),i++,await new Promise(e=>setTimeout(e,300))}catch(t){console.error(`Failed to delete profile:`,e.name,t)}t(e(`kProfiles.toast.profilesDeleted`,{count:i})),k(!1),D(!1),C(!1),T(new Set),L()},[r,w,ie,t,L,A,e]),fe=(0,y.useCallback)(e=>{let t=[];return e.setting_id&&t.push(e.setting_id),t.push(`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`),t.push(`name_${e.name}_${e.filament_id}`),t},[]),pe=(0,y.useCallback)(async(n,i)=>{if(r)try{await Q.setKProfileNote(r,n,i),ee()}catch(n){console.error(`Failed to save note:`,n),t(e(`kProfiles.toast.failedToSaveNote`),`error`)}},[r,ee,t,e]),me=(0,y.useCallback)(e=>{if(!V?.notes)return{note:``,key:null};let t=fe(e);for(let e of t)if(V.notes[e])return{note:V.notes[e],key:e};return{note:``,key:null}},[V,fe]),he=(0,y.useCallback)(e=>me(e).note,[me]);return M?(0,K.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):!j||j.length===0?(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`py-12 text-center`,children:[(0,K.jsx)(ss,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noPrintersConfigured`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.addPrinterInSettings`)})]})}):te.length===0?(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`py-12 text-center`,children:[(0,K.jsx)(bl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noActivePrinters`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.enablePrinterConnection`)})]})}):(0,K.jsxs)(K.Fragment,{children:[F&&!P&&(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40`,children:[(0,K.jsx)(X,{className:`w-10 h-10 text-bambu-green animate-spin mb-3`}),(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`kProfiles.loadingProfiles`)})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-6`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-48`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.printer`)}),(0,K.jsx)(`select`,{value:r||``,onChange:e=>i(parseInt(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:te.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,K.jsxs)(`div`,{className:`w-32`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.nozzle`)}),(0,K.jsxs)(`select`,{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`,children:[(0,K.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,K.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,K.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,K.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:()=>L(),disabled:F||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noRead`),children:[(0,K.jsx)(Cl,{className:`w-4 h-4 ${F?`animate-spin`:``}`}),e(`kProfiles.refresh`)]}),(0,K.jsxs)($,{onClick:()=>u(!0),disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noCreate`),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),e(`kProfiles.addProfile`)]})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-48 relative`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:e(`kProfiles.searchPlaceholder`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),W&&(0,K.jsx)(`div`,{className:`w-36`,children:(0,K.jsxs)(`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:`all`,children:e(`kProfiles.allExtruders`)}),(0,K.jsx)(`option`,{value:`left`,children:e(`kProfiles.leftOnly`)}),(0,K.jsx)(`option`,{value:`right`,children:e(`kProfiles.rightOnly`)})]})}),(0,K.jsx)(`div`,{className:`w-32`,children:(0,K.jsxs)(`select`,{value:_,onChange:e=>v(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:`all`,children:e(`kProfiles.allFlow`)}),(0,K.jsx)(`option`,{value:`hf`,children:e(`kProfiles.hfOnly`)}),(0,K.jsx)(`option`,{value:`s`,children:e(`kProfiles.sOnly`)})]})}),(0,K.jsx)(`div`,{className:`w-32`,children:(0,K.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`name`,children:e(`kProfiles.sortName`)}),(0,K.jsx)(`option`,{value:`k_value`,children:e(`kProfiles.sortKValue`)}),(0,K.jsx)(`option`,{value:`filament`,children:e(`kProfiles.sortFilament`)})]})})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-6`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:oe,disabled:!N?.profiles?.length||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noExport`),children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),e(`kProfiles.export`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:se,disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noImport`),children:[(0,K.jsx)(Su,{className:`w-4 h-4`}),e(`kProfiles.import`)]}),(0,K.jsx)(`div`,{className:`flex-1`}),S?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`secondary`,onClick:le,children:[(0,K.jsx)($l,{className:`w-4 h-4`}),e(`kProfiles.selectAll`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:ue,disabled:w.size===0||!n(`kprofiles:delete`),className:`text-red-500 hover:bg-red-500/10`,title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`kProfiles.delete`),` (`,w.size,`)`]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>{C(!1),T(new Set)},children:[(0,K.jsx)(Pu,{className:`w-4 h-4`}),e(`common.cancel`)]})]}):(0,K.jsxs)($,{variant:`secondary`,onClick:()=>C(!0),disabled:!ie.length||!n(`kprofiles:delete`),title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,K.jsx)($l,{className:`w-4 h-4`}),e(`kProfiles.select`)]})]}),P?(0,K.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):H?(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`py-12 text-center`,children:[(0,K.jsx)(Au,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.printerOffline`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.printerOfflineDesc`)}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>L(),children:[(0,K.jsx)(Cl,{className:`w-4 h-4`}),e(`common.refresh`)]})]})}):ie.length>0?W?(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.leftExtruder`)}),(0,K.jsx)(`div`,{className:`space-y-1`,children:ie.filter(e=>e.extruder_id===1).map(e=>(0,K.jsx)(f7,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>ce(A(e)),note:he(e)},A(e)))})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.rightExtruder`)}),(0,K.jsx)(`div`,{className:`space-y-1`,children:ie.filter(e=>e.extruder_id===0).map(e=>(0,K.jsx)(f7,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>ce(A(e)),note:he(e)},A(e)))})]})]}):(0,K.jsx)(`div`,{className:`space-y-1`,children:ie.map(e=>(0,K.jsx)(f7,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>ce(A(e)),note:he(e)},A(e)))}):p||h!==`all`||_!==`all`?(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`py-12 text-center`,children:[(0,K.jsx)(Nl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noMatchingProfiles`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.noMatchingProfilesDesc`)})]})}):(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`py-12 text-center`,children:[(0,K.jsx)(uc,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noKProfiles`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.noKProfilesDesc`,{diameter:a})}),(0,K.jsxs)($,{onClick:()=>u(!0),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),e(`kProfiles.createFirstProfile`)]})]})}),s&&r&&(()=>{let{note:e,key:t}=me(s);return(0,K.jsx)(p7,{profile:s,printerId:r,nozzleDiameter:a,existingProfiles:R?.profiles||N?.profiles,builtinFilaments:re,isDualNozzle:W,initialNote:e,initialNoteKey:t,onSaveNote:pe,hasPermission:n,onClose:()=>{console.log(`[KProfiles] Edit modal onClose - refetching profiles...`),c(null),L()},onSave:()=>{c(null),L()}})})(),l&&r&&(0,K.jsx)(p7,{printerId:r,nozzleDiameter:a,existingProfiles:R?.profiles||N?.profiles,builtinFilaments:re,isDualNozzle:W,onSaveNote:pe,hasPermission:n,onClose:()=>{u(!1),L()},onSave:()=>{u(!1),L()}}),d&&r&&(0,K.jsx)(p7,{printerId:r,nozzleDiameter:a,existingProfiles:R?.profiles||N?.profiles,builtinFilaments:re,isDualNozzle:W,onSaveNote:pe,hasPermission:n,profile:{...d,slot_id:0,name:`${d.name} (Copy)`},onClose:()=>{f(null),L()},onSave:()=>{f(null),L()}}),E&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(pd,{className:`w-full max-w-sm`,children:(0,K.jsxs)(hd,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,K.jsx)(hu,{className:`w-5 h-5 text-red-500`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e(`kProfiles.bulkDelete.title`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`kProfiles.bulkDelete.cannotUndo`)})]})]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:e(`kProfiles.bulkDelete.message`,{count:w.size})}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>D(!1),disabled:O,className:`flex-1`,children:e(`common.cancel`)}),(0,K.jsxs)($,{onClick:de,disabled:O,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[O?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`common.delete`)]})]})]})})})]})}var h7=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`PVA`,`HIPS`,`PP`,`PET`,`NYLON`],Hze={PLA:`E8E8E8`,PETG:`4A90D9`,ABS:`E67E22`,ASA:`D35400`,TPU:`9B59B6`,PC:`BDC3C7`,PA:`2ECC71`,NYLON:`2ECC71`,PVA:`F1C40F`,HIPS:`95A5A6`,PP:`ECF0F1`,PET:`3498DB`};function Uze(e){let t=e.toUpperCase();for(let e of h7)if(RegExp(`\\b${e}\\b`).test(t))return e;return null}function Wze(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase();for(let e of h7){let r=n.indexOf(e);if(r>0){let e=t.slice(0,r).trim();if(e&&e.length>1)return e}}return null}function g7({preset:e,onDelete:t,onExpand:n,isExpanded:r}){let{t:i}=G(),{hasPermission:a}=sd(),o=e.filament_type||Uze(e.name),s=e.filament_vendor||Wze(e.name),c=null,l=!1;if(e.default_filament_colour)try{let t=JSON.parse(e.default_filament_colour),n=Array.isArray(t)?t[0]:t;typeof n==`string`&&/^#?[0-9a-fA-F]{6,8}$/.test(n.replace(`#`,``))&&(c=n.replace(`#`,``).slice(0,6),l=!0)}catch{let t=e.default_filament_colour;/^#?[0-9a-fA-F]{6,8}$/.test(t.replace(`#`,``))&&(c=t.replace(`#`,``).slice(0,6),l=!0)}return!c&&o&&(c=Hze[o.toUpperCase()]||null),(0,K.jsx)(pd,{className:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors`,children:(0,K.jsxs)(hd,{className:`p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[e.preset_type===`filament`&&(0,K.jsx)(`div`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0 ${!l&&!c?`opacity-25`:l?``:`opacity-50`}`,style:{backgroundColor:c?`#${c}`:`#666`}}),(0,K.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[o&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:o}),s&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:s}),(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400`,children:i(`profiles.localProfiles.badge`)})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[a(`settings:update`)&&(0,K.jsx)(`button`,{onClick:()=>t(e.id),className:`p-1 text-bambu-gray hover:text-red-400 transition-colors`,title:i(`profiles.localProfiles.delete`),children:(0,K.jsx)(hu,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{onClick:()=>n(r?null:e.id),className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:r?(0,K.jsx)(rs,{className:`w-3.5 h-3.5`}):(0,K.jsx)(es,{className:`w-3.5 h-3.5`})})]})]}),r&&(0,K.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5`,children:[o&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.filamentType`)}),(0,K.jsx)(`span`,{className:`text-white`,children:o})]}),s&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.vendor`)}),(0,K.jsx)(`span`,{className:`text-white`,children:s})]}),e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.nozzleTemp`)}),(0,K.jsxs)(`span`,{className:`text-white`,children:[e.nozzle_temp_min,`–`,e.nozzle_temp_max,`°C`]})]}),e.filament_cost&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.cost`)}),(0,K.jsx)(`span`,{className:`text-white`,children:e.filament_cost})]}),e.filament_density&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.density`)}),(0,K.jsxs)(`span`,{className:`text-white`,children:[e.filament_density,` g/cm³`]})]}),e.pressure_advance&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.pressureAdvance`)}),(0,K.jsx)(`span`,{className:`text-white`,children:e.pressure_advance})]}),e.compatible_printers&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.compatiblePrinters`)}),(0,K.jsx)(`span`,{className:`text-white truncate ml-2`,children:(()=>{try{return JSON.parse(e.compatible_printers).join(`, `)}catch{return e.compatible_printers}})()})]}),e.inherits&&e.inherits!==e.name&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.inheritsFrom`)}),(0,K.jsx)(`span`,{className:`text-white truncate ml-2`,children:e.inherits})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.source`)}),(0,K.jsx)(`span`,{className:`text-white capitalize`,children:e.source})]})]})]})})}function Gze(){let{t:e}=G(),{hasPermission:t}=sd(),n=Qa(),{showToast:r}=xd(),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null),{data:f,isLoading:p}=q({queryKey:[`localPresets`],queryFn:()=>Q.getLocalPresets()}),m=J({mutationFn:async e=>{let t=[];for(let n of Array.from(e)){let e=new FormData;e.append(`file`,n),t.push(await Q.importLocalPresets(e))}return t},onSuccess:t=>{n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]});let i=0,a=0,o=0;for(let e of t)i+=e.imported,a+=e.skipped,o+=e.errors.length;i>0&&r(e(`profiles.localProfiles.toast.importSuccess`,{count:i})),a>0&&r(e(`profiles.localProfiles.toast.importSkipped`,{count:a}),`warning`),o>0&&r(e(`profiles.localProfiles.toast.importError`,{count:o}),`error`)},onError:e=>{r(e.message,`error`)}}),h=J({mutationFn:e=>Q.deleteLocalPreset(e),onSuccess:(t,i)=>{n.setQueryData([`localPresets`],e=>e&&{filament:e.filament.filter(e=>e.id!==i),printer:e.printer.filter(e=>e.id!==i),process:e.process.filter(e=>e.id!==i)}),n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]}),d(null),r(e(`profiles.localProfiles.toast.deleted`))}}),g=(0,y.useCallback)(e=>{!e||e.length===0||m.mutate(e)},[m]),_=(0,y.useCallback)(e=>{e.preventDefault(),l(!1),g(e.dataTransfer.files)},[g]),v=(0,y.useCallback)(e=>{if(!i)return e;let t=i.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.filament_type?.toLowerCase().includes(t)||e.filament_vendor?.toLowerCase().includes(t))},[i]),b=(0,y.useMemo)(()=>v(f?.filament||[]),[f?.filament,v]),x=(0,y.useMemo)(()=>v(f?.printer||[]),[f?.printer,v]),S=(0,y.useMemo)(()=>v(f?.process||[]),[f?.process,v]),C=b.length+x.length+S.length,w=(f?.filament?.length??0)+(f?.printer?.length??0)+(f?.process?.length??0)>0;return p?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,K.jsxs)(`div`,{className:`space-y-6`,children:[t(`settings:update`)&&(0,K.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),l(!0)},onDragLeave:()=>l(!1),onDrop:_,className:`relative border-2 border-dashed rounded-lg p-6 text-center transition-colors ${c?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,K.jsx)(`input`,{type:`file`,accept:`.json,.zip,.orca_filament,.bbscfg,.bbsflmt`,multiple:!0,className:`absolute inset-0 w-full h-full opacity-0 cursor-pointer`,onChange:e=>g(e.target.files)}),m.isPending?(0,K.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,K.jsx)(X,{className:`w-5 h-5 text-bambu-green animate-spin`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.importing`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Su,{className:`w-8 h-8 text-bambu-gray mx-auto mb-2`}),(0,K.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`profiles.localProfiles.import`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`profiles.localProfiles.importDesc`)})]})]}),w&&(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:e(`profiles.localProfiles.search`),className:`w-full pl-9 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})]}),!w&&!p&&(0,K.jsxs)(`div`,{className:`text-center py-12`,children:[(0,K.jsx)(yc,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noPresets`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:e(`profiles.localProfiles.importDesc`)})]}),w&&C===0&&!p&&(0,K.jsxs)(`div`,{className:`text-center py-12`,children:[(0,K.jsx)(Nl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noSearchResults`)})]}),C>0&&(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`,children:[b.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,K.jsx)(Ls,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.filament`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,b.length,`)`]})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:b.map(e=>(0,K.jsx)(g7,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]}),S.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,K.jsx)(Nc,{className:`w-4 h-4 text-blue-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.process`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,S.length,`)`]})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:S.map(e=>(0,K.jsx)(g7,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]}),x.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,K.jsx)(Ll,{className:`w-4 h-4 text-orange-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.printer`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,x.length,`)`]})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>(0,K.jsx)(g7,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]})]}),u!==null&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,K.jsx)(ss,{className:`w-5 h-5 text-red-400`}),(0,K.jsx)(`h3`,{className:`text-white font-medium`,children:e(`profiles.localProfiles.deleteConfirmTitle`)})]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`profiles.localProfiles.deleteConfirm`)}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>d(null),children:e(`profiles.localProfiles.cancel`)}),(0,K.jsxs)($,{variant:`danger`,size:`sm`,onClick:()=>h.mutate(u),disabled:h.isPending,children:[h.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hu,{className:`w-4 h-4`}),e(`profiles.localProfiles.delete`)]})]})]})})]})}function Kze(e){let t=e.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),n=e.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),r=e.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),i=e.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:t?t[1].trim():null,nozzle:n?(n[1]||n[2])+`mm`:null,layerHeight:r?r[1]+`mm`:null,filamentType:i?i[1].toUpperCase():null}}function qze({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,t:a}){let[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(`all`),[u,d]=(0,y.useState)(`all`),[f,p]=(0,y.useState)(`all`),[m,h]=(0,y.useState)(`all`),[g,_]=(0,y.useState)(`all`),[v,b]=(0,y.useState)(null),x=(0,y.useMemo)(()=>[...e.filament.map(e=>({...e,type:`filament`})),...e.printer.map(e=>({...e,type:`printer`})),...e.process.map(e=>({...e,type:`process`}))].map(e=>({...e,meta:Kze(e.name)})),[e]),S=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return x.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[x,i]),C=(0,y.useMemo)(()=>u===`all`?null:i.find(e=>e.id.toString()===u)?.model||null,[u,i]),w=(0,y.useMemo)(()=>x.filter(e=>c===`all`||e.type===c).filter(e=>{if(u===`all`||!C)return!0;let t=e.meta.printer?.toLowerCase()||``,n=C.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>f===`all`||e.meta.nozzle===f).filter(e=>m===`all`||e.meta.filamentType===m).filter(e=>g===`all`||e.meta.layerHeight===g).filter(e=>o===``||e.name.toLowerCase().includes(o.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[x,c,u,C,f,m,g,o]),T=()=>{l(`all`),d(`all`),p(`all`),h(`all`),_(`all`),s(``)},E=c!==`all`||u!==`all`||f!==`all`||m!==`all`||g!==`all`||o!==``,D=e.filament.length+e.printer.length+e.process.length,O=e=>w.filter(t=>t.type===e);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:a(`profiles.cloudView.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,K.jsx)(`div`,{className:`flex gap-2`,children:(0,K.jsxs)($,{variant:`secondary`,onClick:n,disabled:r,children:[(0,K.jsx)(Cl,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),a(`profiles.cloudView.refresh`)]})})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(lc,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(b7,{label:a(`profiles.cloudView.filters.type`),value:c,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`),count:D},{value:`filament`,label:a(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:a(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:a(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>l(e)}),S.printers.length>0&&(0,K.jsx)(b7,{label:a(`profiles.cloudView.filters.printer`),value:u,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.printers.map(e=>({value:e.id,label:e.name}))],onChange:d}),S.nozzles.length>0&&(0,K.jsx)(b7,{label:a(`profiles.cloudView.filters.nozzle`),value:f,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.nozzles.map(e=>({value:e,label:e}))],onChange:p}),S.filaments.length>0&&(c===`all`||c===`filament`)&&(0,K.jsx)(b7,{label:a(`profiles.cloudView.filters.filament`),value:m,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.filaments.map(e=>({value:e,label:e}))],onChange:h}),S.layerHeights.length>0&&(c===`all`||c===`process`)&&(0,K.jsx)(b7,{label:a(`profiles.cloudView.filters.layer`),value:g,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.layerHeights.map(e=>({value:e,label:e}))],onChange:_}),E&&(0,K.jsx)(`button`,{onClick:T,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:a(`profiles.cloudView.clearFilters`)})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),a(`profiles.cloudView.lastSynced`),` `,bf(t.toISOString(),`system`,a)]}),(0,K.jsx)(`span`,{children:a(`profiles.cloudView.showingCount`,{showing:w.length,total:D})})]}),w.length===0?(0,K.jsxs)(`div`,{className:`text-center py-16`,children:[(0,K.jsx)(Nc,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:a(`profiles.cloudView.noPresetsFound`)}),E&&(0,K.jsx)(`button`,{onClick:T,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:a(`profiles.cloudView.clearFilters`)})]}):(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,K.jsx)(_7,{icon:(0,K.jsx)(Ls,{className:`w-4 h-4 text-amber-400`}),title:a(`profiles.cloudView.columns.filament`),presets:O(`filament`),emptyText:a(`profiles.cloudView.noFilamentPresets`),onSelect:b}),(0,K.jsx)(_7,{icon:(0,K.jsx)(Ll,{className:`w-4 h-4 text-blue-400`}),title:a(`profiles.cloudView.columns.process`),presets:O(`process`),emptyText:a(`profiles.cloudView.noProcessPresets`),onSelect:b}),(0,K.jsx)(_7,{icon:(0,K.jsx)(bl,{className:`w-4 h-4 text-purple-400`}),title:a(`profiles.cloudView.columns.printer`),presets:O(`printer`),emptyText:a(`profiles.cloudView.noPrinterPresets`),onSelect:b})]}),v&&(0,K.jsx)(Yze,{setting:v,onClose:()=>b(null),t:a})]})}function _7({icon:e,title:t,presets:n,emptyText:r,onSelect:i}){return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[e,(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:t}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,n.length,`)`]})]}),(0,K.jsx)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:n.length===0?(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:r}):n.map(e=>(0,K.jsx)(Jze,{preset:e,onClick:()=>i(e)},e.setting_id))})]})}function Jze({preset:e,onClick:t}){return(0,K.jsx)(`button`,{onClick:t,className:`w-full text-left px-3 py-2 rounded bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),e.meta.filamentType&&e.type===`filament`&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.filamentType}),e.meta.layerHeight&&e.type===`process`&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.layerHeight}),e.meta.printer&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.printer})]})})}function Yze({setting:e,onClose:t,t:n}){let{data:r,isLoading:i,error:a}=q({queryKey:[`orcaCloudProfileDetail`,e.setting_id],queryFn:()=>Q.orcaCloudGetProfile(e.setting_id),retry:!1});return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4`,onClick:t,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl max-w-4xl w-full max-h-[90vh] flex flex-col`,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`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-bold text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.type})]}),(0,K.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white p-1`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:i?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):a?(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:a.message}):r?(0,K.jsx)(`pre`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark p-3 rounded overflow-x-auto whitespace-pre`,children:JSON.stringify(r.setting,null,2)}):(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:n(`profiles.cloudView.noPresetsFound`)})})]})})}function Xze(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),{hasPermission:r}=sd(),i=r(`orca_cloud:auth`),[a,o]=(0,y.useState)(`picker`),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(null),{data:b,isLoading:x}=q({queryKey:[`orcaCloudStatus`],queryFn:Q.orcaCloudStatus}),S=!!b?.connected,{data:C,isLoading:w,refetch:T,isRefetching:E,error:D,dataUpdatedAt:O}=q({queryKey:[`orcaCloudProfiles`],queryFn:Q.orcaCloudListProfiles,enabled:S,retry:!1,staleTime:1e3*60*5}),{data:k=[]}=q({queryKey:[`printers`],queryFn:Q.getPrinters,enabled:S}),[A,j]=(0,y.useState)();(0,y.useEffect)(()=>{O&&j(new Date(O))},[O]);let M=J({mutationFn:e=>Q.orcaCloudStartAuth(e),onSuccess:e=>{c(e.auth_url),u(``),f(null),o(`paste`),window.open(e.auth_url,`_blank`,`noopener,noreferrer`)},onError:t=>{n(t.message||e(`profiles.orcaCloud.errors.startFailed`),`error`)}}),N=J({mutationFn:e=>Q.orcaCloudFinishAuth(e),onSuccess:r=>{c(null),u(``),f(null),o(`picker`),t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.invalidateQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.toast.connected`,{email:r.email||``}))},onError:t=>{f(t.message||e(`profiles.orcaCloud.errors.finishFailed`))}}),P=J({mutationFn:({email:e,password:t})=>Q.orcaCloudPasswordLogin(e,t),onSuccess:r=>{m(``),g(``),v(null),o(`picker`),t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.invalidateQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.toast.connected`,{email:r.email||``}))},onError:t=>{v(t.message||e(`profiles.orcaCloud.errors.passwordFailed`))}}),F=J({mutationFn:Q.orcaCloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.removeQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.toast.disconnected`))}});return x?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,K.jsxs)(`div`,{children:[S&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`profiles.orcaCloud.connectedAs`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:b?.email})]})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>F.mutate(),disabled:F.isPending||!i,title:i?void 0:e(`profiles.orcaCloud.noLogoutPermission`),children:[(0,K.jsx)(Wc,{className:`w-4 h-4`}),e(`profiles.orcaCloud.logout`)]})]}),S?w?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):D?(0,K.jsxs)(`div`,{className:`text-center py-16`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:D.message}),(0,K.jsx)($,{onClick:()=>T(),children:e(`profiles.orcaCloud.retry`)})]}):C?(0,K.jsx)(qze,{settings:C,lastSyncTime:A,onRefresh:()=>T(),isRefreshing:E,printers:k,t:e}):null:(0,K.jsx)(Zze,{mode:a,authUrl:s,pastedUrl:l,setPastedUrl:u,pasteError:d,passwordEmail:p,setPasswordEmail:m,passwordValue:h,setPasswordValue:g,passwordError:_,onPickProvider:e=>M.mutate(e),onPickPassword:()=>{o(`password`),v(null)},onSubmitPaste:t=>{t.preventDefault(),f(null);let n=l.trim();if(!n){f(e(`profiles.orcaCloud.errors.emptyPaste`));return}if(!n.includes(`code=`)){f(e(`profiles.orcaCloud.errors.noCode`));return}N.mutate(n)},onSubmitPassword:t=>{t.preventDefault(),v(null);let n=p.trim();if(!n||!h){v(e(`profiles.orcaCloud.errors.passwordEmpty`));return}P.mutate({email:n,password:h})},onBack:()=>{o(`picker`),c(null),u(``),f(null),m(``),g(``),v(null)},isStarting:M.isPending,isFinishing:N.isPending,isPasswordLoading:P.isPending,canManage:i,t:e})]})}function Zze(e){return e.mode===`paste`&&e.authUrl?(0,K.jsx)($ze,{...e,authUrl:e.authUrl}):e.mode===`password`?(0,K.jsx)(eBe,{...e}):(0,K.jsx)(Qze,{...e})}function Qze({onPickProvider:e,onPickPassword:t,isStarting:n,canManage:r,t:i}){return(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-8 text-center`,children:[(0,K.jsx)(ys,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,K.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:i(`profiles.orcaCloud.connect.title`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray mb-6 max-w-xl mx-auto`,children:i(`profiles.orcaCloud.connect.description`)}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 max-w-sm mx-auto`,children:[(0,K.jsxs)($,{onClick:t,disabled:n||!r,title:r?void 0:i(`profiles.orcaCloud.noConnectPermission`),children:[(0,K.jsx)(Gc,{className:`w-4 h-4`}),i(`profiles.orcaCloud.providers.email`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>e(`google`),disabled:n||!r,title:r?void 0:i(`profiles.orcaCloud.noConnectPermission`),children:[n?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Us,{className:`w-4 h-4`}),i(`profiles.orcaCloud.providers.google`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>e(`github`),disabled:n||!r,title:r?void 0:i(`profiles.orcaCloud.noConnectPermission`),children:[(0,K.jsx)(Us,{className:`w-4 h-4`}),i(`profiles.orcaCloud.providers.github`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>e(`apple`),disabled:n||!r,title:r?void 0:i(`profiles.orcaCloud.noConnectPermission`),children:[(0,K.jsx)(Us,{className:`w-4 h-4`}),i(`profiles.orcaCloud.providers.apple`)]})]})]})})}function $ze({authUrl:e,pastedUrl:t,setPastedUrl:n,pasteError:r,onSubmitPaste:i,onBack:a,isFinishing:o,t:s}){return(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-6`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:a,className:`text-bambu-gray hover:text-white text-sm flex items-center gap-1 mb-4`,children:[(0,K.jsx)(Do,{className:`w-4 h-4`}),s(`profiles.orcaCloud.back`)]}),(0,K.jsx)(`h2`,{className:`text-xl font-bold text-white mb-4`,children:s(`profiles.orcaCloud.paste.title`)}),(0,K.jsxs)(`ol`,{className:`space-y-3 mb-6`,children:[(0,K.jsxs)(`li`,{className:`flex gap-3`,children:[(0,K.jsx)(`span`,{className:`flex-shrink-0 w-7 h-7 rounded-full bg-bambu-dark-tertiary text-white text-sm font-bold flex items-center justify-center`,children:`1`}),(0,K.jsx)(`p`,{className:`text-base text-white pt-0.5`,children:s(`profiles.orcaCloud.paste.step1`)})]}),(0,K.jsxs)(`li`,{className:`flex gap-3`,children:[(0,K.jsx)(`span`,{className:`flex-shrink-0 w-7 h-7 rounded-full bg-amber-500/20 text-amber-400 text-sm font-bold flex items-center justify-center`,children:`2`}),(0,K.jsx)(`div`,{className:`flex-1 p-3 bg-amber-500/10 border border-amber-500/40 rounded`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(vu,{className:`w-5 h-5 text-amber-400 flex-shrink-0 mt-0.5`}),(0,K.jsx)(`p`,{className:`text-base text-white font-medium`,children:s(`profiles.orcaCloud.paste.step2`)})]})})]}),(0,K.jsxs)(`li`,{className:`flex gap-3`,children:[(0,K.jsx)(`span`,{className:`flex-shrink-0 w-7 h-7 rounded-full bg-bambu-dark-tertiary text-white text-sm font-bold flex items-center justify-center`,children:`3`}),(0,K.jsx)(`p`,{className:`text-base text-white pt-0.5`,children:s(`profiles.orcaCloud.paste.step3`)})]})]}),(0,K.jsxs)(`div`,{className:`mb-4 p-3 bg-bambu-dark rounded border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:s(`profiles.orcaCloud.paste.signInUrl`)}),(0,K.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green text-sm break-all hover:underline`,children:e})]}),(0,K.jsxs)(`form`,{onSubmit:i,children:[(0,K.jsx)(`label`,{htmlFor:`orca-callback-url`,className:`block text-sm text-bambu-gray mb-2`,children:s(`profiles.orcaCloud.paste.label`)}),(0,K.jsx)(`textarea`,{id:`orca-callback-url`,value:t,onChange:e=>n(e.target.value),placeholder:s(`profiles.orcaCloud.paste.placeholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono resize-none focus:outline-none focus:border-bambu-green`,rows:3,disabled:o}),r&&(0,K.jsxs)(`p`,{className:`mt-2 text-sm text-red-400 flex items-center gap-2`,children:[(0,K.jsx)(ss,{className:`w-4 h-4`}),r]}),(0,K.jsx)(`div`,{className:`mt-4 flex items-center gap-3`,children:(0,K.jsxs)($,{type:`submit`,disabled:o||!t.trim(),children:[o?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)($o,{className:`w-4 h-4`}),s(`profiles.orcaCloud.paste.submit`)]})})]})]})})}function eBe({passwordEmail:e,setPasswordEmail:t,passwordValue:n,setPasswordValue:r,passwordError:i,onSubmitPassword:a,onBack:o,isPasswordLoading:s,t:c}){return(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-6 max-w-md mx-auto`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:o,className:`text-bambu-gray hover:text-white text-sm flex items-center gap-1 mb-4`,children:[(0,K.jsx)(Do,{className:`w-4 h-4`}),c(`profiles.orcaCloud.back`)]}),(0,K.jsx)(`h2`,{className:`text-xl font-bold text-white mb-4`,children:c(`profiles.orcaCloud.password.title`)}),(0,K.jsxs)(`form`,{onSubmit:a,className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`orca-password-email`,className:`block text-sm text-bambu-gray mb-1`,children:c(`profiles.orcaCloud.password.email`)}),(0,K.jsx)(`input`,{id:`orca-password-email`,type:`email`,value:e,onChange:e=>t(e.target.value),placeholder:c(`profiles.orcaCloud.password.emailPlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,disabled:s,autoComplete:`email`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`orca-password-value`,className:`block text-sm text-bambu-gray mb-1`,children:c(`profiles.orcaCloud.password.password`)}),(0,K.jsx)(`input`,{id:`orca-password-value`,type:`password`,value:n,onChange:e=>r(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,disabled:s,autoComplete:`current-password`})]}),i&&(0,K.jsxs)(`p`,{className:`text-sm text-red-400 flex items-center gap-2`,children:[(0,K.jsx)(ss,{className:`w-4 h-4`}),i]}),(0,K.jsxs)($,{type:`submit`,disabled:s||!e.trim()||!n,children:[s?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)($o,{className:`w-4 h-4`}),c(`profiles.orcaCloud.password.submit`)]})]})]})})}function v7(e,t){let n=`${e} ${t||``}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=r?r[1].trim():null,a=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=a?(a[1]||a[2])+`mm`:null,s=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=s?s[1]+`mm`:null,l=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:i,nozzle:o,layerHeight:c,filamentType:l?l[1].toUpperCase():null}}function y7(e){return/^(P[FPM]US|PF\d|PP\d)/.test(e)}function tBe({onSuccess:e,t}){let{showToast:n}=xd(),[r,i]=(0,y.useState)(`email`),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(`global`),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(null),b=J({mutationFn:()=>Q.cloudLogin(a,s,p),onSuccess:r=>{r.success?(n(t(`profiles.login.toast.loggedIn`)),e()):r.needs_verification?(g(r.verification_type||`email`),v(r.tfa_key||null),r.verification_type===`totp`?n(t(`profiles.login.toast.enterTotp`)):n(t(`profiles.login.toast.codeSent`)),i(`code`)):n(r.message,`error`)},onError:e=>n(e.message,`error`)}),x=J({mutationFn:()=>Q.cloudVerify(a,l,_||void 0,p),onSuccess:r=>{r.success?(n(t(`profiles.login.toast.loggedIn`)),e()):n(r.message,`error`)},onError:e=>n(e.message,`error`)}),S=J({mutationFn:()=>Q.cloudSetToken(d,p),onSuccess:()=>{n(t(`profiles.login.toast.tokenSet`)),e()},onError:e=>n(e.message,`error`)}),C=e=>{e.preventDefault(),r===`email`?b.mutate():r===`code`?x.mutate():r===`token`&&S.mutate()},w=b.isPending||x.isPending||S.isPending;return(0,K.jsx)(pd,{className:`max-w-md mx-auto`,children:(0,K.jsxs)(hd,{children:[(0,K.jsxs)(`div`,{className:`text-center mb-6`,children:[(0,K.jsx)(`div`,{className:`inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3`,children:(0,K.jsx)(ys,{className:`w-6 h-6 text-bambu-green`})}),(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:t(`profiles.login.title`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:t(`profiles.login.subtitle`)})]}),(0,K.jsxs)(`form`,{onSubmit:C,className:`space-y-4`,children:[r===`email`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.email`)}),(0,K.jsx)(`input`,{type:`email`,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 placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`your@email.com`,required:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.password`)}),(0,K.jsx)(`input`,{type:`password`,value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`••••••••`,required:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,K.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,K.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),r===`code`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(h===`totp`?`profiles.login.totpCode`:`profiles.login.verificationCode`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:h===`totp`?t(`profiles.login.enterTotpHint`):t(`profiles.login.checkEmail`,{email:a})}),(0,K.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none`,placeholder:`000000`,maxLength:6,required:!0})]}),r===`token`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.accessToken`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:t(`profiles.login.accessTokenHint`)}),(0,K.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none`,placeholder:`eyJ...`,rows:4,required:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,K.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,K.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[r===`code`&&(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:()=>i(`email`),className:`flex-1`,children:t(`profiles.login.back`)}),(0,K.jsxs)($,{type:`submit`,disabled:w,className:`flex-1`,children:[w?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Uc,{className:`w-4 h-4`}),t(r===`email`?`profiles.login.loginButton`:r===`code`?`profiles.login.verifyButton`:`profiles.login.setTokenButton`)]})]}),r===`email`&&(0,K.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>i(`token`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,K.jsx)(jc,{className:`w-4 h-4`}),t(`profiles.login.useToken`)]})}),r===`token`&&(0,K.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>i(`email`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,K.jsx)(Uc,{className:`w-4 h-4`}),t(`profiles.login.useEmail`)]})})]})]})})}function b7({label:e,value:t,options:n,onChange:r}){let[i,a]=(0,y.useState)(!1),o=n.find(e=>e.value===t);return(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[e,`:`]}),(0,K.jsx)(`span`,{children:o?.label||`All`}),(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?`rotate-180`:``}`})]}),i&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>a(!1)}),(0,K.jsx)(`div`,{className:`absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto`,children:n.map(e=>(0,K.jsxs)(`button`,{onClick:()=>{r(e.value),a(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${t===e.value?`text-bambu-green`:`text-white`}`,children:[(0,K.jsx)(`span`,{children:e.label}),e.count!==void 0&&(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e.count})]},e.value))})]})]})}function nBe(){let[e,t]=(0,y.useState)(!1);return(0,y.useEffect)(()=>{let e=()=>{t(window.scrollY>300)};return window.addEventListener(`scroll`,e),()=>window.removeEventListener(`scroll`,e)},[]),e?(0,K.jsx)(`button`,{onClick:()=>{window.scrollTo({top:0,behavior:`smooth`})},className:`fixed bottom-6 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40`,"aria-label":`Scroll to top`,children:(0,K.jsx)(Mo,{className:`w-5 h-5`})}):null}function x7({setting:e,onClick:t,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:a,compareDisabled:o,t:s}){let c=v7(e.name),l=y7(e.setting_id);return(0,K.jsxs)(`div`,{className:`flex items-center gap-2 group`,children:[(0,K.jsx)(`button`,{onClick:t,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?`bg-blue-500/20 border border-blue-500/50`:o?`bg-bambu-dark/50 opacity-40 cursor-not-allowed`:`bg-bambu-dark hover:bg-bambu-dark-tertiary`} ${r&&!o?`cursor-pointer`:``}`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i&&a!==void 0&&(0,K.jsx)(`span`,{className:`flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium`,children:a+1}),!i&&l&&(0,K.jsx)(`span`,{className:`flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green`,title:s(`profiles.presets.myPreset`)}),(0,K.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),c.filamentType&&e.type===`filament`&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.filamentType}),c.layerHeight&&e.type===`process`&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.layerHeight}),c.printer&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.printer})]})}),(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`opacity-0 group-hover:opacity-100 text-bambu-gray hover:text-white transition-all p-1`,title:s(`profiles.presets.duplicate`),children:(0,K.jsx)(Ds,{className:`w-4 h-4`})})]})}function S7(e,t=0){let n=` `.repeat(t);if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`){if(e.includes(`\\n`)||e.includes(` `)){let t=e.replace(/\\n/g,` `).replace(/\\"/g,`"`).replace(/\\t/g,` `).split(` `);if(t.length>1)return`""" @@ -8718,10 +8718,10 @@ ${t.slice(l+2)}`,d+=1;else break}t.push({indent:l,number:parseInt(s,10),content: `+n+`]`;if(typeof e==`object`){let r=Object.entries(e);return r.length===0?`{}`:`{ `+r.map(([e,r])=>n+` `+JSON.stringify(e)+`: `+S7(r,t+1)).join(`, `)+` -`+n+`}`}return String(e)}function nBe({setting:e,onClose:t,onDeleted:n,onDuplicate:r,onEdit:i,hasPermission:a,t:o}){let{showToast:s}=xd(),c=Qa(),[l,u]=(0,y.useState)(!1),{data:d,isLoading:f}=q({queryKey:[`cloudSettingDetail`,e.setting_id],queryFn:()=>Q.getCloudSettingDetail(e.setting_id)}),p=J({mutationFn:()=>Q.deleteCloudSetting(e.setting_id),onSuccess:()=>{s(o(`profiles.presets.toast.deleted`)),c.invalidateQueries({queryKey:[`cloudSettings`]}),n()},onError:e=>s(e.message,`error`)}),m=y7(e.setting_id),h=v7(e.name,d?.setting?.inherits);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)(pd,{className:`w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden`,children:(0,K.jsxs)(hd,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white truncate`,children:e.name}),m&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full`,children:o(`profiles.presets.editable`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`capitalize`,children:o(`profiles.presets.types.${e.type}`)}),h.printer&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{children:`•`}),(0,K.jsx)(`span`,{children:h.printer})]})]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4`,children:f?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):d?(0,K.jsx)(`pre`,{className:`text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full`,children:S7(d)}):(0,K.jsx)(`div`,{className:`text-center py-16 text-bambu-gray`,children:o(`profiles.presets.failedToLoadDetails`)})}),l?(0,K.jsxs)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 text-red-400`,children:[(0,K.jsx)(vu,{className:`w-5 h-5`}),(0,K.jsx)(`span`,{className:`font-medium`,children:o(`profiles.presets.deleteConfirm`)})]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:o(`profiles.presets.deleteWarning`,{name:e.name})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>u(!1),disabled:p.isPending,className:`flex-1`,children:o(`common.cancel`)}),(0,K.jsxs)($,{variant:`danger`,onClick:()=>p.mutate(),disabled:p.isPending,className:`flex-1`,children:[p.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hu,{className:`w-4 h-4`}),o(`common.delete`)]})]})]}):(0,K.jsx)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,className:`flex-1`,children:o(`common.close`)}),(0,K.jsxs)($,{variant:`secondary`,onClick:r,disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noDuplicatePermission`),children:[(0,K.jsx)(Ds,{className:`w-4 h-4`}),o(`profiles.presets.duplicate`)]}),m&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`secondary`,onClick:i,disabled:f||!d||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noEditPermission`),children:[(0,K.jsx)(pl,{className:`w-4 h-4`}),o(`common.edit`)]}),(0,K.jsx)($,{variant:`danger`,onClick:()=>u(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noDeletePermission`),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]})})]})})})}function C7(){try{let e=localStorage.getItem(`bambusy_preset_templates`);return e?JSON.parse(e):[]}catch{return[]}}function w7(e){localStorage.setItem(`bambusy_preset_templates`,JSON.stringify(e))}function rBe({onClose:e,onApply:t,t:n}){let{showToast:r}=xd(),[i,a]=(0,y.useState)(C7),[o,s]=(0,y.useState)(`all`),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(`{}`),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(null),x=o===`all`?i:i.filter(e=>e.type===o),S=e=>{a(e),w7(e)},C=e=>{S(i.filter(t=>t.id!==e)),b(null),r(n(`profiles.templates.toast.deleted`))},w=e=>{l(e.id),d(e.name),p(e.description),h(JSON.stringify(e.settings,null,2)),_(null)},T=()=>{if(!(!c||!u.trim()))try{let e=JSON.parse(m);S(i.map(t=>t.id===c?{...t,name:u.trim(),description:f.trim(),settings:e}:t)),l(null),r(n(`profiles.templates.toast.updated`))}catch(e){_(e.message)}},E=()=>{l(null),d(``),p(``),h(`{}`),_(null)},D=e=>{S(i.map(t=>t.id===e?{...t,showInModal:!t.showInModal}:t))},O={filament:{label:n(`profiles.presets.types.filament`),icon:Ls,color:`text-amber-400`},print:{label:n(`profiles.presets.types.process`),icon:Ll,color:`text-blue-400`},printer:{label:n(`profiles.presets.types.printer`),icon:bl,color:`text-purple-400`}},k=v?i.find(e=>e.id===v):null;return(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&(v?b(null):c?E():e())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[v,c,e]),(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:[k&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-60`,children:(0,K.jsx)(pd,{className:`w-full max-w-md`,children:(0,K.jsxs)(hd,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,K.jsx)(`div`,{className:`p-2 bg-red-500/20 rounded-lg`,children:(0,K.jsx)(vu,{className:`w-6 h-6 text-red-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:n(`profiles.templates.deleteTitle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.deleteWarning`)})]})]}),(0,K.jsx)(`p`,{className:`text-white mb-6`,children:n(`profiles.templates.deleteConfirm`,{name:k.name})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>b(null),className:`flex-1`,children:n(`common.cancel`)}),(0,K.jsxs)($,{onClick:()=>C(v),className:`flex-1 bg-red-500 hover:bg-red-600`,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),n(`common.delete`)]})]})]})})}),(0,K.jsx)(pd,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,children:(0,K.jsxs)(hd,{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.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Ql,{className:`w-5 h-5 text-amber-400`}),n(`profiles.templates.title`)]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.typeFilter`)}),[`all`,`filament`,`print`,`printer`].map(e=>(0,K.jsx)(`button`,{onClick:()=>s(e),className:`px-3 py-1 text-sm rounded-lg transition-colors ${o===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:e===`all`?n(`common.all`):O[e].label},e))]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:x.length===0?(0,K.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,K.jsx)(Ql,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,K.jsx)(`p`,{children:n(`profiles.templates.noTemplates`)}),(0,K.jsx)(`p`,{className:`text-sm mt-1`,children:n(`profiles.templates.createFirst`)})]}):(0,K.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>{let r=O[e.type],i=r.icon;return c===e.id?(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-green`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mb-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:n(`profiles.templates.namePlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:n(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray mb-1 block`,children:n(`profiles.templates.settingsJson`)}),(0,K.jsx)(`textarea`,{value:m,onChange:e=>{h(e.target.value),_(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${g?`border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`}),g&&(0,K.jsx)(`p`,{className:`text-xs text-red-400 mt-1`,children:g})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{size:`sm`,onClick:T,disabled:!u.trim(),children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),`Save`]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:E,children:`Cancel`})]})]},e.id):(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors`,children:[(0,K.jsx)(i,{className:`w-5 h-5 ${r.color} flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description})]}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded`,children:n(`profiles.templates.fieldsCount`,{count:Object.keys(e.settings).length})}),(0,K.jsx)(`button`,{onClick:()=>D(e.id),className:`p-1 transition-colors ${e.showInModal?`text-bambu-green hover:text-bambu-green/70`:`text-bambu-gray hover:text-white`}`,title:e.showInModal?n(`profiles.templates.shownInModals`):n(`profiles.templates.hiddenInModals`),children:e.showInModal?(0,K.jsx)(Gs,{className:`w-4 h-4`}):(0,K.jsx)(Ws,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>t(e),className:`px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors`,children:n(`profiles.templates.apply`)}),(0,K.jsx)(`button`,{onClick:()=>w(e),className:`p-1 text-bambu-gray hover:text-white`,title:n(`common.edit`),children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>b(e.id),className:`p-1 text-bambu-gray hover:text-red-400`,title:n(`common.delete`),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]},e.id)})})})]})})]})}function T7({onClose:e,leftPreset:t,rightPreset:n,leftLabel:r,rightLabel:i,t:a}){let[o,s]=(0,y.useState)(`changes`),[c,l]=(0,y.useState)(``),u=(0,y.useMemo)(()=>{let e=new Set([...Object.keys(t),...Object.keys(n)]),r=[];for(let i of e){if(i===`inherits`||i===`version`)continue;let e=t[i],a=n[i],o=i in t,s=i in n,c;c=!o&&s?`added`:o&&!s?`removed`:JSON.stringify(e)===JSON.stringify(a)?`same`:`changed`,r.push({key:i,left:e,right:a,status:c})}return r.sort((e,t)=>{let n={changed:0,added:1,removed:2,same:3};return n[e.status]===n[t.status]?e.key.localeCompare(t.key):n[e.status]-n[t.status]})},[t,n]),d=(0,y.useMemo)(()=>{let e=[...u];if(o===`changes`&&(e=e.filter(e=>e.status!==`same`)),c){let t=c.toLowerCase();e=e.filter(e=>e.key.toLowerCase().includes(t)||String(e.left).toLowerCase().includes(t)||String(e.right).toLowerCase().includes(t))}return e},[u,o,c]),f=(0,y.useMemo)(()=>({added:u.filter(e=>e.status===`added`).length,removed:u.filter(e=>e.status===`removed`).length,changed:u.filter(e=>e.status===`changed`).length,same:u.filter(e=>e.status===`same`).length}),[u]),p=e=>{if(e===void 0)return`—`;if(e===null)return`null`;if(Array.isArray(e))return e.length===0?`[]`:e.length===1?String(e[0]):e.join(`, `);if(typeof e==`object`)return JSON.stringify(e);let t=String(e);if(t.includes(`\\n`)||t.length>100){let e=t.split(`\\n`).length;if(e>1)return`[${e} lines of G-code/script]`;if(t.length>100)return t.substring(0,100)+`…`}return t};return(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(pd,{className:`w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden`,children:(0,K.jsxs)(hd,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(pc,{className:`w-5 h-5 text-blue-400`}),a(`profiles.diff.title`)]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark`,children:[(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.left`)}),(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:r})]}),(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.right`)}),(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:i})]})]}),(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-green-400`,children:[(0,K.jsx)(_l,{className:`w-3.5 h-3.5`}),f.added,` `,a(`profiles.diff.added`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-red-400`,children:[(0,K.jsx)(el,{className:`w-3.5 h-3.5`}),f.removed,` `,a(`profiles.diff.removed`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-amber-400`,children:[(0,K.jsx)(ko,{className:`w-3.5 h-3.5`}),f.changed,` `,a(`profiles.diff.changed`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[(0,K.jsx)(Vs,{className:`w-3.5 h-3.5`}),f.same,` `,a(`profiles.diff.same`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:a(`profiles.diff.searchFields`),className:`pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48`})]}),f.same>0&&(0,K.jsxs)(`div`,{className:`flex rounded overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>s(`changes`),className:`px-3 py-1.5 text-sm transition-colors ${o===`changes`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`profiles.diff.changes`)}),(0,K.jsx)(`button`,{onClick:()=>s(`all`),className:`px-3 py-1.5 text-sm transition-colors ${o===`all`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`common.all`)})]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:d.length===0?(0,K.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,K.jsx)(Vs,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,K.jsx)(`p`,{children:a(o===`changes`?`profiles.diff.noDifferences`:`profiles.diff.noFieldsMatch`)})]}):(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{className:`sticky top-0 bg-bambu-dark-secondary`,children:(0,K.jsxs)(`tr`,{className:`text-sm text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:a(`profiles.diff.field`)}),(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:r}),(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:i})]})}),(0,K.jsx)(`tbody`,{children:d.map(e=>{let t={added:`bg-green-500/10`,removed:`bg-red-500/10`,changed:`bg-amber-500/10`,same:``}[e.status],n={added:(0,K.jsx)(_l,{className:`w-3.5 h-3.5 text-green-400`}),removed:(0,K.jsx)(el,{className:`w-3.5 h-3.5 text-red-400`}),changed:(0,K.jsx)(ko,{className:`w-3.5 h-3.5 text-amber-400`}),same:(0,K.jsx)(Vs,{className:`w-3.5 h-3.5 text-bambu-gray-dark`})}[e.status];return(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary ${t}`,children:[(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n,(0,K.jsx)(`span`,{className:`text-sm text-white font-mono`,children:e.key})]})}),(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`removed`?`text-red-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:p(e.left)})}),(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`added`?`text-green-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:p(e.right)})})]},e.key)})})]})})]})})})}function iBe({onClose:e,initialData:t,allPresets:n,t:r}){let{showToast:i}=xd(),a=Qa(),o=!!t?.setting_id,[s,c]=(0,y.useState)(`common`),[l,u]=(0,y.useState)(t?.type||`filament`),[d,f]=(0,y.useState)(t?.name?o?t.name:`${t.name} (Copy)`:``),[p,m]=(0,y.useState)(t?.base_id||``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(t?.setting||{inherits:``}),[b,x]=(0,y.useState)(JSON.stringify(t?.setting||{inherits:``},null,2)),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(C7),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(!0),[ee,H]=(0,y.useState)(null),[te,ne]=(0,y.useState)(!1),re=(0,y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer})[l]||[],[n,l]),U=(0,y.useMemo)(()=>re.filter(e=>y7(e.setting_id)),[re]),{data:ie}=q({queryKey:[`cloudFields`,l],queryFn:()=>Q.getCloudFields(l===`print`?`process`:l),staleTime:1e3*60*60}),{data:ae}=q({queryKey:[`allPresetDetails`,l,U.map(e=>e.setting_id).join(`,`)],queryFn:async()=>{let e={};for(let t=0;t{try{let t=await Q.getCloudSettingDetail(e.setting_id);return{id:e.setting_id,detail:t}}catch{return null}}))).forEach(t=>{t&&(e[t.id]=t.detail)})}return e},enabled:U.length>0,staleTime:1e3*60*10}),{data:W,isLoading:oe}=q({queryKey:[`cloudSettingDetail`,p],queryFn:()=>Q.getCloudSettingDetail(p),enabled:!!p});(0,y.useEffect)(()=>{s!==`json`&&x(JSON.stringify(_,null,2))},[_,s]);let se=(0,y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer}[l]||[]).filter(e=>!y7(e.setting_id)).sort((e,t)=>e.name.localeCompare(t.name)),[n,l]);(0,y.useEffect)(()=>{if(!p)return;let e=se.find(e=>e.setting_id===p);e&&(g(e.name),o||(v({inherits:e.name}),x(JSON.stringify({inherits:e.name},null,2))))},[p,se,o]);let ce=(0,y.useMemo)(()=>{let e=ie?.fields||[],t=new Set(e.map(e=>e.key)),n=new Set,i=new Set([`inherits`,`updated_time`,`compatible_printers`,`compatible_prints`]);ae&&Object.values(ae).forEach(e=>{e?.setting&&Object.keys(e.setting).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)})}),Object.keys(_).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)});let a=Array.from(n).sort().map(e=>({key:e,label:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),type:`text`,category:`discovered`,description:r(`profiles.presets.discoveredFromPresets`)}));return[...e,...a]},[ie,ae,_,r]),le=ce.filter(e=>e.label.toLowerCase().includes(w.toLowerCase())||e.key.toLowerCase().includes(w.toLowerCase())),ue=()=>{if(O.trim()){let e=O.trim().toLowerCase().replace(/\s+/g,`_`);de(e,``),k(``),j(!1),i(r(`profiles.presets.toast.fieldAdded`,{key:e}))}},de=(e,t)=>{v(n=>{let r={...n};return t===``||t===void 0?delete r[e]:r[e]=t,r})},fe=e=>{v(t=>({...t,...e.settings})),H(e.name),i(r(`profiles.templates.toast.applied`))},pe=()=>{if(!I.trim())return;let e={..._};if(delete e.inherits,Object.keys(e).length===0){i(r(`profiles.presets.noOverridesToSave`),`error`);return}let t={id:Date.now().toString(),name:I.trim(),description:R.trim()||r(`profiles.presets.customTemplate`),type:l,settings:e,showInModal:B},n=[...M,t];N(n),w7(n),F(!1),L(``),z(``),V(!0),i(r(`profiles.templates.toast.created`))},me=(0,y.useMemo)(()=>M.filter(e=>e.type===l&&e.showInModal),[l,M]),he=e=>{x(e);try{v(JSON.parse(e)),C(null)}catch(e){C(e.message)}},ge=e=>{e.preventDefault(),D(!1);let t=e.dataTransfer.files[0];if(t&&t.name.endsWith(`.json`)){let e=new FileReader;e.onload=e=>{try{let t=e.target?.result,n=JSON.parse(t),a=n.setting||n;v(e=>({...e,...a})),x(JSON.stringify({..._,...a},null,2)),i(r(`profiles.presets.fileImported`))}catch{i(r(`profiles.presets.invalidJsonFile`),`error`)}},e.readAsText(t)}},_e=J({mutationFn:()=>{let e={..._},t=l===`filament`?`filament_settings_id`:l===`print`?`print_settings_id`:`printer_settings_id`;e[t]=`"${d}"`;let n={type:l,name:d,base_id:p,setting:e};return Q.createCloudSetting(n)},onSuccess:async()=>{i(r(`profiles.presets.toast.created`)),await a.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>i(e.message,`error`)}),ve=J({mutationFn:()=>{if(!t?.setting_id)throw Error(r(`profiles.presets.noSettingId`));return Q.updateCloudSetting(t.setting_id,{name:d,setting:_})},onSuccess:async()=>{i(r(`profiles.presets.toast.updated`)),a.removeQueries({queryKey:[`cloudSettingDetail`]}),await a.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>i(e.message,`error`)}),ye=o?ve:_e,be=W?.setting?.inherits,xe=be?se.find(e=>e.name===be):void 0,{data:Se}=q({queryKey:[`cloudSettingDetail`,xe?.setting_id],queryFn:()=>Q.getCloudSettingDetail(xe.setting_id),enabled:!!xe?.setting_id}),Ce=(0,y.useMemo)(()=>{let e=Se?.setting||{},t=W?.setting||{},n=p&&ae?.[p]?.setting?ae[p].setting:{};return{...e,...t,...n}},[p,W,Se,ae]),we=e=>{if(e==null)return``;if(Array.isArray(e)){let t=[...new Set(e.map(e=>String(e)))];return t.length===1?t[0]:e.join(`, `)}return String(e)},Te=e=>{let t=_[e.key],n=Ce[e.key],i=we(n),a=oe?r(`common.loading`):i||``,o=`w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`;if(e.type===`boolean`){let r=t===`1`||t===void 0&&n===`1`;return(0,K.jsx)(`button`,{type:`button`,onClick:()=>de(e.key,t===`1`?`0`:`1`),className:`w-8 h-5 rounded-full transition-colors ${r?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${r?`translate-x-3.5`:`translate-x-0.5`}`})})}return e.type===`select`?(0,K.jsxs)(`select`,{value:t||``,onChange:t=>de(e.key,t.target.value),className:o,children:[(0,K.jsx)(`option`,{value:``,children:a}),e.options?.map(e=>(0,K.jsx)(`option`,{value:e.value,children:e.label},e.value))]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:e.type===`number`?`number`:`text`,value:t===void 0?``:String(t),onChange:t=>de(e.key,t.target.value),step:e.step,min:e.min,max:e.max,placeholder:a,className:o}),e.unit&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.unit})]})},Ee=(0,y.useMemo)(()=>W?.setting?W.setting:{},[W]);return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onDragOver:e=>{e.preventDefault(),D(!0)},onDragLeave:()=>D(!1),onDrop:ge,children:[te&&p&&(0,K.jsx)(T7,{onClose:()=>ne(!1),leftPreset:Ee,rightPreset:_,leftLabel:r(`profiles.presets.baseLabel`,{name:h||p}),rightLabel:r(`profiles.presets.currentLabel`,{name:d||r(`profiles.presets.newPreset`)}),t:r}),(0,K.jsx)(pd,{className:`w-full max-w-6xl max-h-[90vh] flex flex-col overflow-y-auto`,children:(0,K.jsxs)(hd,{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.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:r(o?`profiles.presets.editPreset`:t?`profiles.presets.duplicatePreset`:`profiles.presets.createNewPreset`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`profiles.presets.customizeSettings`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[p&&(0,K.jsxs)(`button`,{onClick:()=>ne(!0),className:`flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:r(`profiles.presets.compareWithBase`),children:[(0,K.jsx)(pc,{className:`w-4 h-4`}),r(`profiles.presets.compare`)]}),(0,K.jsx)(`button`,{onClick:e,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]})]}),E&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10`,children:(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(Su,{className:`w-12 h-12 text-bambu-green mx-auto mb-2`}),(0,K.jsx)(`p`,{className:`text-bambu-green font-medium`,children:r(`profiles.presets.dropJsonToImport`)})]})}),(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 max-[640px]:grid-cols-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`common.type`)}),(0,K.jsxs)(`select`,{value:l,onChange:e=>{u(e.target.value),m(``)},className:`w-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:`filament`,children:r(`profiles.presets.types.filament`)}),(0,K.jsx)(`option`,{value:`print`,children:r(`profiles.presets.types.process`)}),(0,K.jsx)(`option`,{value:`printer`,children:r(`profiles.presets.types.printer`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.basePreset`)}),(0,K.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:``,children:r(`profiles.presets.selectBasePreset`)}),se.map(e=>(0,K.jsx)(`option`,{value:e.setting_id,children:e.name},e.setting_id))]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.presetName`)}),(0,K.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(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(`profiles.presets.myCustomPreset`)})]})]}),h&&(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,K.jsxs)(`p`,{className:`flex items-center gap-1`,children:[(0,K.jsx)($o,{className:`w-3 h-3 text-bambu-green`}),r(`profiles.presets.inheritsFrom`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:h}),oe&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin ml-1`})]})})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary max-[640px]:flex-wrap max-[640px]:items-center`,children:[(0,K.jsxs)(`button`,{onClick:()=>c(`common`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`common`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Jl,{className:`w-4 h-4`}),r(`profiles.presets.tabs.common`)]}),(0,K.jsxs)(`button`,{onClick:()=>c(`fields`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`fields`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Bc,{className:`w-4 h-4`}),r(`profiles.presets.tabs.allFields`)]}),(0,K.jsxs)(`button`,{onClick:()=>c(`json`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`json`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(xs,{className:`w-4 h-4`}),`JSON`,S&&(0,K.jsx)(ss,{className:`w-3 h-3 text-red-400`})]}),(0,K.jsx)(`div`,{className:`flex-1 max-[640px]:hidden`}),(0,K.jsxs)(`button`,{onClick:()=>{let e=new Blob([JSON.stringify({name:d,type:l,base_id:p,setting:_},null,2)],{type:`application/json`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${d||`preset`}.json`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t),i(r(`profiles.presets.toast.exported`))},className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.exportToJson`),children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),r(`common.download`)]}),(0,K.jsxs)(`button`,{onClick:()=>document.getElementById(`file-import`)?.click(),className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.importFromJson`),children:[(0,K.jsx)(Su,{className:`w-4 h-4`}),r(`common.upload`)]}),(0,K.jsx)(`input`,{id:`file-import`,type:`file`,accept:`.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];if(t){let e=new FileReader;e.onload=e=>{try{let t=JSON.parse(e.target?.result),n=t.setting||t;v(e=>({...e,...n})),i(r(`profiles.presets.fileImported`))}catch{i(r(`profiles.presets.invalidJson`),`error`)}},e.readAsText(t)}}})]}),(0,K.jsxs)(`div`,{className:`flex-1 p-4`,children:[s===`common`&&(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,K.jsx)(Ql,{className:`w-4 h-4 text-amber-400`}),r(`profiles.templates.title`)]}),Object.keys(_).filter(e=>e!==`inherits`).length>0&&(0,K.jsxs)(`button`,{onClick:()=>F(!P),className:`text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors`,children:[(0,K.jsx)(Ol,{className:`w-3 h-3`}),r(`profiles.presets.saveAsTemplate`)]})]}),P&&(0,K.jsxs)(`div`,{className:`mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 mb-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:I,onChange:e=>L(e.target.value),placeholder:r(`profiles.templates.namePlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),placeholder:r(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{size:`sm`,onClick:pe,disabled:!I.trim(),children:[(0,K.jsx)(Ol,{className:`w-3 h-3`}),r(`common.save`)]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>F(!1),children:r(`common.cancel`)})]}),(0,K.jsxs)(`button`,{onClick:()=>V(!B),className:`flex items-center gap-1.5 text-xs transition-colors ${B?`text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[B?(0,K.jsx)(Gs,{className:`w-3.5 h-3.5`}):(0,K.jsx)(Ws,{className:`w-3.5 h-3.5`}),r(B?`profiles.templates.shownInModals`:`profiles.templates.hiddenInModals`)]})]})]}),ee&&(0,K.jsxs)(`div`,{className:`mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2`,children:[(0,K.jsx)($o,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-green`,children:[r(`profiles.presets.templateApplied`),` `,(0,K.jsx)(`span`,{className:`font-medium`,children:ee})]}),(0,K.jsx)(`button`,{onClick:()=>H(null),className:`ml-auto text-bambu-green/70 hover:text-bambu-green`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[me.map(e=>(0,K.jsxs)(`button`,{onClick:()=>fe(e),className:`p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e.description})]},e.id)),me.length===0&&(0,K.jsx)(`p`,{className:`col-span-3 text-center text-bambu-gray text-sm py-4`,children:r(`profiles.presets.noTemplatesSelected`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark mt-2 text-center`,children:r(`profiles.presets.manageTemplatesHint`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.commonSettings`)}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-3`,children:ce.slice(0,10).map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 max-[640px]:flex-col max-[640px]:items-start`,children:[(0,K.jsx)(`label`,{className:`text-sm text-bambu-gray flex-shrink-0`,children:e.label}),(0,K.jsx)(`div`,{className:`w-48 max-[640px]:w-full`,children:Te(e)})]},e.key))})]}),Object.keys(_).length>1&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.currentOverrides`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Object.entries(_).filter(([e])=>e!==`inherits`).map(([e,t])=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded`,children:[e,`: `,String(t).slice(0,20),(0,K.jsx)(`button`,{onClick:()=>de(e,void 0),className:`hover:text-white`,children:(0,K.jsx)(Pu,{className:`w-3 h-3`})})]},e))})]})]}),s===`fields`&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,style:{height:`400px`},children:[(0,K.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.availableFields`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:ae?r(`profiles.templates.fieldsCount`,{count:ce.length}):r(`common.loading`)})]}),(0,K.jsxs)(`div`,{className:`relative mb-3 flex-shrink-0`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:r(`profiles.presets.searchFieldsPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-1 pr-2 min-h-0`,children:[le.filter(e=>!(e.key in _)).map(e=>{let t=Ce[e.key],n=we(t);return(0,K.jsxs)(`div`,{onClick:()=>{v(t=>({...t,[e.key]:n||``}))},className:`flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.label}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark truncate`,children:e.key})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[n&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate`,title:n,children:[n.slice(0,20),n.length>20?`...`:``]}),(0,K.jsx)(`div`,{className:`w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors`,children:(0,K.jsx)(_l,{className:`w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors`})})]})]},e.key)}),le.filter(e=>!(e.key in _)).length===0&&(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-4 text-sm`,children:r(w?`profiles.presets.noMatchingFields`:`profiles.presets.allFieldsAdded`)})]}),(0,K.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:A?(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),onKeyDown:e=>e.key===`Enter`&&ue(),placeholder:`custom_field_name`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)($,{size:`sm`,onClick:ue,disabled:!O.trim(),children:(0,K.jsx)(_l,{className:`w-4 h-4`})}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>{j(!1),k(``)},children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}):(0,K.jsxs)(`button`,{onClick:()=>j(!0),className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),r(`profiles.presets.addCustomField`)]})})]}),(0,K.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.yourOverrides`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:r(`profiles.templates.fieldsCount`,{count:Object.keys(_).filter(e=>e!==`inherits`).length})})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-2 pr-2 min-h-0`,children:[Object.entries(_).filter(([e])=>e!==`inherits`).map(([e,t])=>{let n=ce.find(t=>t.key===e);return(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:n?.label||e}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark`,children:e})]}),(0,K.jsx)(`button`,{onClick:()=>de(e,void 0),className:`p-1 text-bambu-gray hover:text-red-400 transition-colors`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}),n?Te(n):(0,K.jsx)(`input`,{type:`text`,value:String(t),onChange:t=>de(e,t.target.value),className:`w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]},e)}),Object.keys(_).filter(e=>e!==`inherits`).length===0&&(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(Jl,{className:`w-8 h-8 mx-auto mb-2 opacity-50`}),(0,K.jsx)(`p`,{className:`text-sm`,children:r(`profiles.presets.noOverridesYet`)}),(0,K.jsx)(`p`,{className:`text-xs mt-1`,children:r(`profiles.presets.clickFieldsToAdd`)})]})]}),Object.keys(_).filter(e=>e!==`inherits`).length>0&&(0,K.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:(0,K.jsxs)(`button`,{onClick:()=>{F(!0),c(`common`)},className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),r(`profiles.presets.saveAsTemplate`)]})})]})]}),s===`json`&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[S&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-red-400 text-sm`,children:[(0,K.jsx)(ss,{className:`w-4 h-4`}),S]}),(0,K.jsx)(`textarea`,{value:b,onChange:e=>he(e.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${S?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,spellCheck:!1}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`profiles.presets.jsonTip`)})]})]}),(0,K.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:e,className:`flex-1`,children:r(`common.cancel`)}),(0,K.jsxs)($,{onClick:()=>ye.mutate(),disabled:ye.isPending||!d.trim()||!o&&!p||!!S,className:`flex-1`,children:[ye.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):o?(0,K.jsx)(Ol,{className:`w-4 h-4`}):(0,K.jsx)(_l,{className:`w-4 h-4`}),r(o?`common.save`:t?`common.duplicate`:`common.create`)]})]})]})})]})}function aBe({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,hasPermission:a,t:o}){let[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`all`),[d,f]=(0,y.useState)(`all`),[p,m]=(0,y.useState)(`all`),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(`all`),[b,x]=(0,y.useState)(`all`),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(null),[A,j]=(0,y.useState)(null),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)([null,null]),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(null),ee=Qa(),H=(0,y.useMemo)(()=>[...e.filament.map(e=>({...e,type:`filament`})),...e.printer.map(e=>({...e,type:`printer`})),...e.process.map(e=>({...e,type:`process`}))].map(e=>({...e,meta:v7(e.name)})),[e]),te=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return H.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[H,i]),ne=(0,y.useMemo)(()=>p===`all`?null:i.find(e=>e.id.toString()===p)?.model||null,[p,i]),re=(0,y.useMemo)(()=>H.filter(e=>l===`all`||e.type===l).filter(e=>{if(d===`all`)return!0;let t=y7(e.setting_id);return d===`custom`?t:!t}).filter(e=>{if(p===`all`||!ne)return!0;let t=e.meta.printer?.toLowerCase()||``,n=ne.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>h===`all`||e.meta.nozzle===h).filter(e=>_===`all`||e.meta.filamentType===_).filter(e=>b===`all`||e.meta.layerHeight===b).filter(e=>s===``||e.name.toLowerCase().includes(s.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[H,l,d,p,ne,h,_,b,s]),U=e=>{if(P){let t=I[0]?.setting_id===e.setting_id,n=I[1]?.setting_id===e.setting_id;if(t)L([I[1],null]);else if(n)L([I[0],null]);else if(!I[0])L([e,null]);else if(I[1]){if(I[0].type!==e.type)return;L([I[0],e])}else{if(I[0].type!==e.type)return;L([I[0],e])}}else C(e)},ie=e=>{if(I[0]?.setting_id===e.setting_id)return 0;if(I[1]?.setting_id===e.setting_id)return 1},ae=async e=>{try{let t=await Q.getCloudSettingDetail(e.setting_id);k({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{}}),C(null)}catch(e){console.error(`Failed to fetch preset details for duplication:`,e)}},W=async e=>{try{ee.removeQueries({queryKey:[`cloudSettingDetail`,e.setting_id]});let t=await Q.getCloudSettingDetail(e.setting_id);j({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{},setting_id:e.setting_id}),C(null)}catch(e){console.error(`Failed to fetch preset details for editing:`,e)}},oe=()=>{u(`all`),f(`all`),m(`all`),g(`all`),v(`all`),x(`all`),c(``)},se=l!==`all`||d!==`all`||p!==`all`||h!==`all`||_!==`all`||b!==`all`||s!==``,ce=e.filament.length+e.printer.length+e.process.length;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:o(`profiles.cloudView.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[(0,K.jsxs)($,{variant:P?`primary`:`secondary`,onClick:()=>{P?(F(!1),L([null,null])):F(!0)},children:[(0,K.jsx)(pc,{className:`w-4 h-4`}),o(P?`common.cancel`:`profiles.presets.compare`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>D(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noTemplatesPermission`),children:[(0,K.jsx)(Ql,{className:`w-4 h-4`}),o(`profiles.cloudView.templates`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:n,disabled:r||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noRefreshPermission`),children:[(0,K.jsx)(Cl,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),o(`profiles.cloudView.refresh`)]}),(0,K.jsxs)($,{onClick:()=>T(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noCreatePermission`),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),o(`profiles.cloudView.newPreset`)]})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(lc,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(b7,{label:o(`profiles.cloudView.filters.type`),value:l,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`),count:ce},{value:`filament`,label:o(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:o(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:o(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>u(e)}),(0,K.jsx)(b7,{label:o(`profiles.cloudView.filters.owner`),value:d,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},{value:`custom`,label:o(`profiles.cloudView.filters.myPresets`)},{value:`builtin`,label:o(`profiles.cloudView.filters.builtIn`)}],onChange:e=>f(e)}),te.printers.length>0&&(0,K.jsx)(b7,{label:o(`profiles.cloudView.filters.printer`),value:p,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...te.printers.map(e=>({value:e.id,label:e.name}))],onChange:m}),te.nozzles.length>0&&(0,K.jsx)(b7,{label:o(`profiles.cloudView.filters.nozzle`),value:h,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...te.nozzles.map(e=>({value:e,label:e}))],onChange:g}),te.filaments.length>0&&(l===`all`||l===`filament`)&&(0,K.jsx)(b7,{label:o(`profiles.cloudView.filters.filament`),value:_,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...te.filaments.map(e=>({value:e,label:e}))],onChange:v}),te.layerHeights.length>0&&(l===`all`||l===`process`)&&(0,K.jsx)(b7,{label:o(`profiles.cloudView.filters.layer`),value:b,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...te.layerHeights.map(e=>({value:e,label:e}))],onChange:x}),se&&(0,K.jsx)(`button`,{onClick:oe,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:o(`profiles.cloudView.clearFilters`)})]})]}),P&&(0,K.jsx)(`div`,{className:`mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(pc,{className:`w-5 h-5 text-blue-400`}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:o(`profiles.cloudView.compareMode`)}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:I[0]?o(`profiles.cloudView.selectAnotherPreset`,{type:I[0].type}):o(`profiles.cloudView.clickTwoPresets`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${I[0]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:I[0]?I[0].name:o(`profiles.cloudView.selectFirst`)}),(0,K.jsx)(ko,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${I[1]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:I[1]?I[1].name:o(`profiles.cloudView.selectSecond`)})]}),I[0]&&I[1]&&(0,K.jsxs)($,{size:`sm`,onClick:async()=>{try{let[e,t]=await Promise.all([Q.getCloudSettingDetail(I[0].setting_id),Q.getCloudSettingDetail(I[1].setting_id)]);V([e.setting||{},t.setting||{}]),z(!0)}catch{}},children:[(0,K.jsx)(pc,{className:`w-4 h-4`}),o(`profiles.cloudView.compareNow`)]})]})]})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),o(`profiles.cloudView.lastSynced`),` `,bf(t.toISOString(),`system`,o)]}),(0,K.jsx)(`span`,{children:o(`profiles.cloudView.showingCount`,{showing:re.length,total:ce})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),(0,K.jsxs)(`span`,{children:[`= `,o(`profiles.presets.myPreset`)]})]})]}),re.length===0?(0,K.jsxs)(`div`,{className:`text-center py-16`,children:[(0,K.jsx)(Nc,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:o(`profiles.cloudView.noPresetsFound`)}),se&&(0,K.jsx)(`button`,{onClick:oe,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:o(`profiles.cloudView.clearFilters`)})]}):(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(Ls,{className:`w-4 h-4 text-amber-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.filament`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,re.filter(e=>e.type===`filament`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[re.filter(e=>e.type===`filament`).map(e=>(0,K.jsx)(x7,{setting:e,onClick:()=>U(e),onDuplicate:()=>ae(e),compareMode:P,isCompareSelected:ie(e)!==void 0,compareIndex:ie(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),re.filter(e=>e.type===`filament`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noFilamentPresets`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(Ll,{className:`w-4 h-4 text-blue-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.process`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,re.filter(e=>e.type===`process`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[re.filter(e=>e.type===`process`).map(e=>(0,K.jsx)(x7,{setting:e,onClick:()=>U(e),onDuplicate:()=>ae(e),compareMode:P,isCompareSelected:ie(e)!==void 0,compareIndex:ie(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),re.filter(e=>e.type===`process`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noProcessPresets`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(bl,{className:`w-4 h-4 text-purple-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.printer`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,re.filter(e=>e.type===`printer`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[re.filter(e=>e.type===`printer`).map(e=>(0,K.jsx)(x7,{setting:e,onClick:()=>U(e),onDuplicate:()=>ae(e),compareMode:P,isCompareSelected:ie(e)!==void 0,compareIndex:ie(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),re.filter(e=>e.type===`printer`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noPrinterPresets`)})]})]})]}),S&&(0,K.jsx)(nBe,{setting:S,onClose:()=>C(null),onDeleted:()=>C(null),onDuplicate:()=>ae(S),onEdit:()=>W(S),hasPermission:a,t:o}),(w||O||A||M)&&(0,K.jsx)(iBe,{onClose:()=>{T(!1),k(null),j(null),N(null)},initialData:A||O||(M?{type:M.type,name:``,base_id:``,setting:M.setting}:void 0),allPresets:e,t:o}),E&&(0,K.jsx)(rBe,{onClose:()=>D(!1),onApply:e=>{N({type:e.type,setting:e.settings}),D(!1)},t:o}),R&&B&&I[0]&&I[1]&&(0,K.jsx)(T7,{onClose:()=>{z(!1),V(null)},leftPreset:B[0],rightPreset:B[1],leftLabel:I[0].name,rightLabel:I[1].name,t:o})]})}function oBe(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),{hasPermission:r}=sd(),[i,a]=(0,y.useState)(`cloud`),[o,s]=(0,y.useState)(),{data:c,isLoading:l}=q({queryKey:[`cloudStatus`],queryFn:Q.getCloudStatus}),{data:u=[]}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:d,isLoading:f,refetch:p,dataUpdatedAt:m}=q({queryKey:[`cloudSettings`],queryFn:()=>Q.getCloudSettings(),enabled:!!c?.is_authenticated,retry:!1,staleTime:1e3*60*5});(0,y.useEffect)(()=>{m&&s(new Date(m))},[m]);let h=J({mutationFn:Q.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]}),t.removeQueries({queryKey:[`cloudSettings`]}),n(e(`profiles.toast.loggedOut`))}});return l?(0,K.jsx)(`div`,{className:`p-4 md:p-8 flex items-center justify-center min-h-[400px]`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(ys,{className:`w-7 h-7 text-bambu-green`}),e(`profiles.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`profiles.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary mb-6`,children:[(0,K.jsxs)(`button`,{onClick:()=>a(`cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(ys,{className:`w-4 h-4`}),e(`profiles.tabs.bambuCloud`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`orca_cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`orca_cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(ys,{className:`w-4 h-4`}),e(`profiles.tabs.orcaCloud`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`local`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`local`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(yc,{className:`w-4 h-4`}),e(`profiles.tabs.local`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`kprofiles`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`kprofiles`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(uc,{className:`w-4 h-4`}),e(`profiles.tabs.kprofiles`)]})]}),i===`cloud`&&(0,K.jsxs)(K.Fragment,{children:[c?.is_authenticated&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`profiles.connectedAs`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:c.email}),c.region&&(0,K.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:c.region===`china`?e(`profiles.login.regionChina`):e(`profiles.login.regionGlobal`)})]})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>h.mutate(),disabled:h.isPending||!r(`cloud:auth`),title:r(`cloud:auth`)?void 0:e(`profiles.noLogoutPermission`),children:[(0,K.jsx)(Wc,{className:`w-4 h-4`}),e(`profiles.logout`)]})]}),c?.is_authenticated?f?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):d?(0,K.jsx)(aBe,{settings:d,lastSyncTime:o,onRefresh:()=>p(),isRefreshing:f,printers:u,hasPermission:r,t:e}):(0,K.jsxs)(`div`,{className:`text-center py-16`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`profiles.failedToLoad`)}),(0,K.jsx)($,{onClick:()=>p(),children:e(`profiles.retry`)})]}):(0,K.jsx)(eBe,{onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]})},t:e})]}),i===`orca_cloud`&&(0,K.jsx)(Yze,{}),i===`local`&&(0,K.jsx)(Wze,{}),i===`kprofiles`&&(0,K.jsx)(Bze,{}),(0,K.jsx)(tBe,{})]})}function sBe(e,t){let n=(t||``).toUpperCase().replace(/[- ]/g,``),r=n.includes(`X1`),i=n.includes(`P1`),a=n.includes(`A1MINI`),o=n.includes(`A1`)&&!a,s=n.includes(`H2D`),c=n.includes(`H2C`),l=n.includes(`H2S`),u=s||c||l,d=n.includes(`P2S`),f=n.includes(`X2D`),p=d||f;switch(e){case`Lubricate Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Clean Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Lubricate Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Nozzle/Hotend`:return r||i?`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`:a||o?`https://wiki.bambulab.com/en/a1-mini/troubleshooting/nozzle-clog`:u?`https://wiki.bambulab.com/en/h2/maintenance/nozzl-cold-pull-maintenance-and-cleaning`:p?`https://wiki.bambulab.com/en/p2s/maintenance/cold-pull-maintenance-hotend`:`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`;case`Check Belt Tension`:return r?`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`:i?`https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance`:a?`https://wiki.bambulab.com/en/a1-mini/maintenance/belt_tension`:o?`https://wiki.bambulab.com/en/a1/maintenance/belt_tension`:s?`https://wiki.bambulab.com/en/h2/maintenance/belt-tension`:c?`https://wiki.bambulab.com/en/h2c/maintenance/belt-tension`:l?`https://wiki.bambulab.com/en/h2s/maintenance/belt-tension`:p?`https://wiki.bambulab.com/en/p2s/maintenance/belt-tension`:`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`;case`Clean Carbon Rods`:return r||i?`https://wiki.bambulab.com/en/general/carbon-rods-clearance`:null;case`Clean Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Build Plate`:return`https://wiki.bambulab.com/en/filament-acc/acc/pei-plate-clean-guide`;case`Check PTFE Tube`:return r||i?`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`:a||o?`https://wiki.bambulab.com/en/a1-mini/maintenance/ptfe-tube`:s?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:l?`https://wiki.bambulab.com/en/h2s/maintenance/replace-ptfe-tube-on-h2s-printer`:c?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`;case`Replace HEPA Filter`:case`HEPA Filter`:case`Replace Carbon Filter`:case`Carbon Filter`:return u?`https://wiki.bambulab.com/en/h2/maintenance/replace-smoke-purifier-air-filte`:`https://wiki.bambulab.com/en/x1/maintenance/replace-carbon-filter`;case`Lubricate Left Nozzle Rail`:case`Left Nozzle Rail`:return u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;default:return null}}var E7={Droplet:Ls,Flame:ec,Ruler:Dl,Sparkles:Ql,Square:tu,Cable:Uo,Wrench:Nu,Calendar:qo,Timer:mu,Cog:ws,Fan:Ks,Zap:Iu,Wind:Mu,Thermometer:pu,Layers:Nc,Box:Bo,Target:cu,RefreshCw:Cl,Settings:Rl,Filter:lc,CircleDot:ds};function D7(e){return e&&E7[e]||Nu}function O7(e,t,n){if(t===`days`){if(e<1)return n?n(`common.today`):`Today`;if(e===1)return n?n(`maintenance.day`):`1 day`;if(e<7){let t=Math.round(e);return n?n(`maintenance.days`,{count:t}):`${t} days`}if(e<180){let t=Math.round(e/7);return t===1?n?n(`maintenance.week`):`1 week`:n?n(`maintenance.weeks`,{count:t}):`${t} weeks`}let t=Math.round(e/30);return t===1?n?n(`maintenance.month`):`1 month`:n?n(`maintenance.months`,{count:t}):`${t} months`}else{if(e<1)return`${Math.round(e*60)}m`;if(e<24)return`${e<10?e.toFixed(1):Math.round(e)}h`;let t=e/24;if(t<7)return`${t<2?t.toFixed(1):Math.round(t)}d`;let n=t/7;return n<12?`${n<2?n.toFixed(1):Math.round(n)}w`:`${Math.round(n/4)}mo`}}function k7(e,t,n){return t===`days`?e===1?n?n(`maintenance.day`):`1 day`:e===7?n?n(`maintenance.week`):`1 week`:e===14?n?n(`maintenance.weeks`,{count:2}):`2 weeks`:e===30?n?n(`maintenance.month`):`1 month`:e===60?n?n(`maintenance.months`,{count:2}):`2 months`:e===90?n?n(`maintenance.months`,{count:3}):`3 months`:e===180?n?n(`maintenance.months`,{count:6}):`6 months`:e===365?n?n(`maintenance.year`):`1 year`:n?n(`maintenance.days`,{count:e}):`${e} days`:`${e}h`}function cBe({item:e,onPerform:t,onToggle:n,hasPermission:r,t:i}){let a=D7(e.maintenance_type_icon),o=e.interval_type||`hours`,s=(()=>{if(o===`days`){let t=e.days_since_maintenance??0;return Math.max(0,Math.min(100,t/e.interval_hours*100))}return Math.max(0,Math.min(100,(e.interval_hours-e.hours_until_due)/e.interval_hours*100))})(),c=()=>e.enabled?e.is_due?`text-red-400`:e.is_warning?`text-amber-400`:`text-bambu-green`:`text-bambu-gray`;return(0,K.jsx)(`div`,{className:`rounded-xl border p-4 transition-all ${e.enabled?e.is_due?`bg-red-500/5 border-red-500/20`:e.is_warning?`bg-amber-500/5 border-amber-500/20`:`bg-bambu-dark-secondary border-bambu-dark-tertiary`:`bg-bambu-dark-secondary/50`}`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3 max-[550px]:flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`relative p-2.5 rounded-lg shrink-0 ${e.is_due?`bg-red-500/20`:e.is_warning?`bg-amber-500/20`:e.enabled?`bg-bambu-dark`:`bg-bambu-dark/50`}`,children:[(0,K.jsx)(a,{className:`w-5 h-5 ${c()}`}),e.enabled&&(e.is_due||e.is_warning)&&(0,K.jsx)(`span`,{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${e.is_due?`bg-red-500`:`bg-amber-500`} animate-pulse`})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`font-medium truncate ${e.enabled?`text-white`:`text-bambu-gray`}`,children:e.maintenance_type_name}),o===`days`&&(0,K.jsx)(`span`,{title:i(`maintenance.timeBasedInterval`),children:(0,K.jsx)(qo,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})}),(()=>{let t=e.maintenance_type_wiki_url||sBe(e.maintenance_type_name,e.printer_model);return t?(0,K.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-bambu-green transition-colors shrink-0`,title:i(`maintenance.viewDocumentation`),onClick:e=>e.stopPropagation(),children:(0,K.jsx)(Us,{className:`w-3.5 h-3.5`})}):null})()]}),(0,K.jsx)(`div`,{className:`mt-2 mb-1.5`,children:(0,K.jsx)(`div`,{className:`w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500 ${e.enabled?e.is_due?`bg-red-500`:e.is_warning?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-gray/30`}`,style:{width:`${s}%`}})})}),(0,K.jsxs)(`div`,{className:`text-xs flex items-center gap-1 ${c()}`,children:[e.is_due&&(0,K.jsx)(vu,{className:`w-3 h-3`}),e.is_warning&&!e.is_due&&(0,K.jsx)(_s,{className:`w-3 h-3`}),!e.is_due&&!e.is_warning&&e.enabled&&(0,K.jsx)($o,{className:`w-3 h-3`}),(()=>{if(!e.enabled)return i(`common.disabled`);if(o===`days`){let t=e.days_until_due??0;return e.is_due?i(`maintenance.overdueBy`,{duration:O7(Math.abs(t),`days`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:O7(t,`days`,i)}):i(`maintenance.timeLeft`,{duration:O7(t,`days`,i)})}else return e.is_due?i(`maintenance.overdueBy`,{duration:O7(Math.abs(e.hours_until_due),`hours`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:O7(e.hours_until_due,`hours`,i)}):i(`maintenance.timeLeft`,{duration:O7(e.hours_until_due,`hours`,i)})})()]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 max-[550px]:w-full max-[550px]:justify-end max-[550px]:mt-1`,children:[(0,K.jsx)(`span`,{title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionUpdate`),children:(0,K.jsx)(y5,{checked:e.enabled,onChange:t=>n(e.id,t),disabled:!r(`maintenance:update`)})}),(0,K.jsxs)($,{size:`sm`,variant:e.is_due?`primary`:`secondary`,onClick:()=>t(e.id),disabled:!e.enabled||!r(`maintenance:update`),title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionPerform`),className:`!px-3`,children:[(0,K.jsx)(Tl,{className:`w-3.5 h-3.5`}),i(`common.reset`)]})]})]})})}function lBe({overview:e,onPerform:t,onToggle:n,onSetHours:r,hasPermission:i,t:a}){let[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(e.total_print_hours.toFixed(1)),f=[...e.maintenance_items].sort((e,t)=>e.is_due&&!t.is_due?-1:!e.is_due&&t.is_due?1:e.is_warning&&!t.is_warning?-1:!e.is_warning&&t.is_warning?1:e.maintenance_type_id-t.maintenance_type_id),p=f.find(e=>e.enabled&&(e.is_due||e.is_warning)),m=()=>{let t=parseFloat(u);!isNaN(t)&&t>=0&&(r(e.printer_id,t),l(!1))};return(0,K.jsxs)(pd,{className:`overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`p-5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:e.printer_name}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.due_count>0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-red-500/20 text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)(vu,{className:`w-3 h-3`}),a(`maintenance.overdueCount`,{count:e.due_count})]}),e.warning_count>0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-amber-500/20 text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),a(`maintenance.dueSoonCount`,{count:e.warning_count})]}),e.due_count===0&&e.warning_count===0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)($o,{className:`w-3 h-3`}),a(`maintenance.allGood`)]})]})]}),(0,K.jsxs)(`button`,{onClick:()=>s(!o),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors`,children:[o?(0,K.jsx)(rs,{className:`w-4 h-4`}):(0,K.jsx)(es,{className:`w-4 h-4`}),a(o?`common.collapse`:`common.expand`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-6 mt-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 bg-bambu-dark/50 rounded-lg`,children:(0,K.jsx)(mu,{className:`w-4 h-4 text-bambu-gray`})}),c?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&l(!1)},className:`w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`,min:`0`,step:`1`,autoFocus:!0}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`common.hours`)}),(0,K.jsx)($,{size:`sm`,onClick:m,children:a(`common.save`)}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>l(!1),children:a(`common.cancel`)})]}):(0,K.jsxs)(`button`,{onClick:()=>{i(`maintenance:update`)&&(d(Math.round(e.total_print_hours).toString()),l(!0))},className:`group ${i(`maintenance:update`)?``:`cursor-not-allowed opacity-60`}`,title:i(`maintenance:update`)?void 0:a(`maintenance.noPermissionEditHours`),children:[(0,K.jsxs)(`div`,{className:`text-sm font-medium text-white ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``} transition-colors flex items-center gap-1`,children:[Math.round(e.total_print_hours),` `,a(`common.hours`),(0,K.jsx)(dl,{className:`w-3 h-3 text-bambu-gray ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``}`})]}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:a(`maintenance.totalPrintTime`)})]})]}),(0,K.jsx)(`div`,{className:`w-px h-10 bg-bambu-dark-tertiary`}),p&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${p.is_due?`bg-red-500/20`:`bg-amber-500/20`}`,children:(0,K.jsx)(D7(p.maintenance_type_icon),{className:`w-4 h-4 ${p.is_due?`text-red-400`:`text-amber-400`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-sm font-medium ${p.is_due?`text-red-400`:`text-amber-400`}`,children:p.maintenance_type_name}),(0,K.jsx)(`div`,{className:`text-xs ${p.is_due?`text-red-400/70`:`text-amber-400/70`}`,children:p.is_due?a(`common.overdue`):a(`maintenance.dueSoon`)})]})]})]})]}),o&&(0,K.jsx)(hd,{className:`pt-0 border-t border-bambu-dark-tertiary`,children:(0,K.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4`,children:f.map(e=>(0,K.jsx)(cBe,{item:e,onPerform:t,onToggle:n,hasPermission:i,t:a},e.id))})})]})}function uBe({overview:e,types:t,onUpdateInterval:n,onAddType:r,onUpdateType:i,onDeleteType:a,onRestoreDefaults:o,isRestoringDefaults:s,onAssignType:c,onRemoveItem:l,hasPermission:u,t:d}){let[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(``),[g,_]=(0,y.useState)(`hours`),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(`100`),[T,E]=(0,y.useState)(`hours`),[D,O]=(0,y.useState)(`Wrench`),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(new Set),[N,P]=(0,y.useState)(null),[F,I]=(0,y.useState)(null),L=(0,y.useMemo)(()=>e?e.map(e=>({id:e.printer_id,name:e.printer_name})):[],[e]),R=t=>e?e.filter(e=>e.maintenance_items.some(e=>e.maintenance_type_id===t)).map(e=>({printerId:e.printer_id,printerName:e.printer_name,itemId:e.maintenance_items.find(e=>e.maintenance_type_id===t)?.id})):[],z=t=>{if(!e)return[];let n=new Set(R(t).map(e=>e.printerId));return L.filter(e=>!n.has(e.id))},[B,V]=(0,y.useState)(null),[ee,H]=(0,y.useState)(``),[te,ne]=(0,y.useState)(``),[re,U]=(0,y.useState)(`hours`),[ie,ae]=(0,y.useState)(`Wrench`),[W,oe]=(0,y.useState)(``),se=e=>{V(e),H(e.name),ne(e.default_interval_hours.toString()),U(e.interval_type||`hours`),ae(e.icon||`Wrench`),oe(e.wiki_url||``)},ce=()=>{B&&ee.trim()&&parseFloat(te)>0&&(i(B.id,{name:ee.trim(),default_interval_hours:parseFloat(te),interval_type:re,icon:ie,wiki_url:W.trim()||null}),V(null))},le=(e,t,r)=>{let i=parseFloat(m);!isNaN(i)&&i>0&&n(e,{custom_interval_hours:Math.abs(i-t)<.01?null:i,custom_interval_type:g===r?null:g}),p(null)},ue=e=>{e.preventDefault(),x.trim()&&parseFloat(C)>0&&j.size>0&&(r({name:x.trim(),default_interval_hours:parseFloat(C),interval_type:T,icon:D,wiki_url:k.trim()||null},Array.from(j)),S(``),w(`100`),E(`hours`),A(``),M(new Set),b(!1))},de=e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},fe=e?.map(e=>({printerId:e.printer_id,printerName:e.printer_name,items:e.maintenance_items.sort((e,t)=>e.maintenance_type_id-t.maintenance_type_id)})).sort((e,t)=>e.printerName.localeCompare(t.printerName))||[],pe=t.filter(e=>e.is_system),me=t.filter(e=>!e.is_system);return(0,K.jsxs)(`div`,{className:`space-y-8`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.maintenanceTypes`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.maintenanceTypesDescription`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:o,disabled:!u(`maintenance:delete`)||s,title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),children:d(`maintenance.restoreDefaults`)}),(0,K.jsxs)($,{onClick:()=>b(!v),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionEditTypes`),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),d(`maintenance.addCustomType`)]})]})]}),v&&(0,K.jsx)(pd,{className:`mb-6`,children:(0,K.jsx)(hd,{className:`py-4`,children:(0,K.jsxs)(`form`,{onSubmit:ue,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4`,children:[(0,K.jsxs)(`div`,{className:`lg:col-span-2`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`common.name`)}),(0,K.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.exampleName`),autoFocus:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalType`)}),(0,K.jsxs)(`select`,{value:T,onChange:e=>{E(e.target.value),e.target.value===`days`?w(`30`):w(`100`)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalValue`,{type:T===`days`?d(`maintenance.calendarDays`).toLowerCase():d(`common.hours`)})}),(0,K.jsx)(`input`,{type:`number`,value:C,onChange:e=>w(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]})]}),(0,K.jsx)(`div`,{className:`mt-4 flex items-end justify-between`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.icon`)}),(0,K.jsx)(`div`,{className:`flex gap-1`,children:Object.keys(E7).map(e=>{let t=E7[e];return(0,K.jsx)(`button`,{type:`button`,onClick:()=>O(e),className:`p-2 rounded-lg transition-colors ${D===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(t,{className:`w-4 h-4`})},e)})})]})}),(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.documentationLink`)}),(0,K.jsx)(`input`,{type:`url`,value:k,onChange:e=>A(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:`https://wiki.bambulab.com/...`})]}),(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.assignToPrinters`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:L.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>de(e.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${j.has(e.id)?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))}),j.size===0&&(0,K.jsx)(`p`,{className:`text-xs text-orange-400 mt-1`,children:d(`maintenance.selectAtLeastOnePrinter`)})]}),(0,K.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:()=>{b(!1),M(new Set)},children:d(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!x.trim()||j.size===0,children:d(`maintenance.addType`)})]})]})})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:[pe.map(e=>{let t=D7(e.icon),n=e.interval_type||`hours`;return(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg`,children:(0,K.jsx)(t,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,K.jsx)(qo,{className:`w-3 h-3`}):(0,K.jsx)(mu,{className:`w-3 h-3`}),k7(e.default_interval_hours,n,d)]})]}),(0,K.jsx)(`button`,{onClick:()=>{u(`maintenance:delete`)&&I(e)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})},e.id)}),me.map(e=>{let t=D7(e.icon),n=e.interval_type||`hours`;if(B?.id===e.id)return(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green`,children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:ee,onChange:e=>H(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`common.name`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`select`,{value:re,onChange:e=>U(e.target.value),className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,K.jsx)(`input`,{type:`number`,value:te,onChange:e=>ne(e.target.value),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(E7).map(e=>{let t=E7[e];return(0,K.jsx)(`button`,{type:`button`,onClick:()=>ae(e),className:`p-1.5 rounded transition-colors ${ie===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:(0,K.jsx)(t,{className:`w-3.5 h-3.5`})},e)})}),(0,K.jsx)(`input`,{type:`url`,value:W,onChange:e=>oe(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.documentationLink`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{size:`sm`,onClick:ce,disabled:!ee.trim(),children:d(`common.save`)}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>V(null),children:d(`common.cancel`)})]})]})},e.id);let r=R(e.id),i=z(e.id),o=N===e.id;return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2.5 bg-bambu-green/20 rounded-lg`,children:(0,K.jsx)(t,{className:`w-5 h-5 text-bambu-green`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded`,children:d(`maintenance.custom`)})]}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,K.jsx)(qo,{className:`w-3 h-3`}):(0,K.jsx)(mu,{className:`w-3 h-3`}),k7(e.default_interval_hours,n,d)]})]}),(0,K.jsxs)(`button`,{onClick:()=>P(o?null:e.id),className:`px-2 py-1 rounded-lg border transition-colors flex items-center gap-1 ${r.length>0?`border-bambu-green/50 bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20`:`border-orange-400/50 bg-orange-400/10 text-orange-400 hover:bg-orange-400/20`}`,title:d(`maintenance.printersAssignedClick`,{count:r.length}),children:[(0,K.jsx)(bl,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{className:`text-xs font-medium`,children:r.length}),(0,K.jsx)(es,{className:`w-3 h-3 transition-transform ${o?`rotate-180`:``}`})]}),(0,K.jsx)(`button`,{onClick:()=>se(e),disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors ${u(`maintenance:update`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(dl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{confirm(d(`maintenance.deleteTypeConfirm`,{name:e.name}))&&a(e.id)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]}),o&&(0,K.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:d(`maintenance.assignedToPrinters`)}),r.length===0?(0,K.jsx)(`p`,{className:`text-xs text-orange-400`,children:d(`maintenance.noPrintersAssigned`)}):(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-2`,children:r.map(e=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark rounded text-xs text-white`,children:[e.printerName,(0,K.jsx)(`button`,{onClick:()=>e.itemId&&l(e.itemId),disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?d(`maintenance.removeFromPrinter`):d(`maintenance.noPermissionRemovePrinter`),className:`ml-1 ${u(`maintenance:delete`)?`hover:text-red-400`:`opacity-50 cursor-not-allowed`}`,children:`×`})]},e.printerId))}),i.length>0&&(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:d(`maintenance.addPrinterShort`)}),i.map(t=>(0,K.jsxs)(`button`,{onClick:()=>c(t.id,e.id),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionAssignPrinter`),className:`px-2 py-1 bg-bambu-dark rounded text-xs transition-colors ${u(`maintenance:create`)?`hover:bg-bambu-green/20 text-bambu-gray hover:text-bambu-green`:`opacity-50 cursor-not-allowed text-bambu-gray`}`,children:[`+ `,t.name]},t.id))]})]})]},e.id)})]})]}),fe.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.intervalOverrides`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]}),(0,K.jsx)(`div`,{className:`space-y-4`,children:fe.map(e=>(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`py-4`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e.printerName}),(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2`,children:e.items.map(e=>{let n=D7(e.maintenance_type_icon),r=t.find(t=>t.id===e.maintenance_type_id),i=r?.default_interval_hours||e.interval_hours,a=r?.interval_type||`hours`,o=e.interval_type||`hours`,s=f===e.id;return(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(n,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray flex-1 truncate`,children:e.maintenance_type_name}),s?(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[g===`days`?(0,K.jsx)(qo,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}):(0,K.jsx)(mu,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,K.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,K.jsx)(`input`,{type:`number`,value:m,onChange:e=>h(e.target.value),onKeyDown:t=>{t.key===`Enter`&&le(e.id,i,a),t.key===`Escape`&&p(null)},className:`w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,min:`1`}),(0,K.jsx)($,{size:`sm`,onClick:()=>le(e.id,i,a),children:`OK`})]}):(0,K.jsxs)(`button`,{onClick:()=>{u(`maintenance:update`)&&(p(e.id),h(e.interval_hours.toString()),_(o))},disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditIntervals`),className:`px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs font-medium text-white transition-colors flex items-center gap-1 ${u(`maintenance:update`)?`hover:bg-bambu-dark-secondary hover:border-bambu-green`:`opacity-50 cursor-not-allowed`}`,children:[o===`days`?(0,K.jsx)(qo,{className:`w-3 h-3`}):(0,K.jsx)(mu,{className:`w-3 h-3`}),k7(e.interval_hours,o,d),(0,K.jsx)(dl,{className:`w-3 h-3 text-bambu-gray`})]})]},e.id)})})]})},e.printerId))})]}),fe.length===0&&(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`text-center py-12`,children:[(0,K.jsx)(_s,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray/30`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:d(`common.noPrinters`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]})}),F&&(0,K.jsx)(Ed,{title:d(`maintenance.deleteSystemTypeTitle`),message:d(`maintenance.deleteSystemTypeMessage`,{name:F.name}),confirmText:d(`common.delete`),cancelText:d(`common.cancel`),variant:`danger`,cancelVariant:`primary`,cardClassName:`bg-red-950/70 border border-red-800/70`,onConfirm:()=>{a(F.id),I(null)},onCancel:()=>I(null)})]})}function dBe(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),{hasPermission:r}=sd(),[i,a]=(0,y.useState)(`status`),{data:o,isLoading:s}=q({queryKey:[`maintenanceOverview`],queryFn:Q.getMaintenanceOverview}),{data:c}=q({queryKey:[`maintenanceTypes`],queryFn:Q.getMaintenanceTypes}),l=J({mutationFn:({id:e,notes:t})=>Q.performMaintenance(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.maintenanceComplete`))},onError:e=>{n(e.message,`error`)}}),u=J({mutationFn:({id:e,data:t})=>Q.updateMaintenanceItem(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]})},onError:e=>{n(e.message,`error`)}}),d=J({mutationFn:({id:e,data:t})=>Q.updateMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onError:e=>{n(e.message,`error`)}}),f=J({mutationFn:Q.deleteMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeDeleted`))},onError:e=>{n(e.message,`error`)}}),p=J({mutationFn:Q.restoreDefaultMaintenanceTypes,onSuccess:r=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.defaultsRestored`,{count:r.restored}))},onError:e=>{n(e.message,`error`)}}),m=J({mutationFn:({printerId:e,hours:t})=>Q.setPrinterHours(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.printHoursUpdated`))},onError:e=>{n(e.message,`error`)}}),h=J({mutationFn:({printerId:e,typeId:t})=>Q.assignMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerAssigned`))},onError:e=>{n(e.message,`error`)}}),g=J({mutationFn:Q.removeMaintenanceItem,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerRemoved`))},onError:e=>{n(e.message,`error`)}}),_=e=>{l.mutate({id:e})},v=(e,t)=>{u.mutate({id:e,data:{enabled:t}})},b=(e,t)=>{m.mutate({printerId:e,hours:t})};if(s)return(0,K.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})});let x=o?.reduce((e,t)=>e+t.due_count,0)||0,S=o?.reduce((e,t)=>e+t.warning_count,0)||0;return(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(Nu,{className:`w-7 h-7 text-bambu-green`}),e(`maintenance.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i===`status`?(0,K.jsxs)(K.Fragment,{children:[x>0&&(0,K.jsx)(`span`,{className:`text-red-400`,children:e(`maintenance.dueCount`,{count:x})}),x>0&&S>0&&` · `,S>0&&(0,K.jsx)(`span`,{className:`text-amber-400`,children:e(`maintenance.warningCount`,{count:S})}),x===0&&S===0&&(0,K.jsx)(`span`,{className:`text-bambu-green`,children:e(`maintenance.allOk`)})]}):e(`maintenance.configureSettings`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-1 mb-6 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`status`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i===`status`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.statusTab`)}),(0,K.jsx)(`button`,{onClick:()=>a(`settings`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i===`settings`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.settingsTab`)})]}),i===`status`?(0,K.jsx)(`div`,{className:`space-y-6`,children:o&&o.length>0?[...o].sort((e,t)=>{let n=e.due_count*10+e.warning_count,r=t.due_count*10+t.warning_count;return n===r?e.printer_name.localeCompare(t.printer_name):r-n}).map(t=>(0,K.jsx)(lBe,{overview:t,onPerform:_,onToggle:v,onSetHours:b,hasPermission:r,t:e},t.printer_id)):(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`text-center py-16`,children:[(0,K.jsx)(Nu,{className:`w-16 h-16 mx-auto mb-4 text-bambu-gray/30`}),(0,K.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:e(`common.noPrinters`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`maintenance.configureSettings`)})]})})}):(0,K.jsx)(uBe,{overview:o,types:c||[],onUpdateInterval:(e,t)=>u.mutate({id:e,data:t}),onAddType:async(r,i)=>{let a=await Q.createMaintenanceType(r);for(let e of i)await Q.assignMaintenanceType(e,a.id);t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onUpdateType:(e,t)=>d.mutate({id:e,data:t}),onDeleteType:e=>f.mutate(e),onRestoreDefaults:()=>p.mutate(),isRestoringDefaults:p.isPending,onAssignType:(e,t)=>h.mutate({printerId:e,typeId:t}),onRemoveItem:e=>g.mutate(e),hasPermission:r,t:e})]})}var A7=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#06b6d4`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#6b7280`];function j7({project:e,onClose:t,onSave:n,isLoading:r,currencySymbol:i,t:a}){let[o,s]=(0,y.useState)(e?.name||``),[c,l]=(0,y.useState)(e?.description||``),[u,d]=(0,y.useState)(e?.color||A7[0]),[f,p]=(0,y.useState)(e?.target_count?.toString()||``),[m,h]=(0,y.useState)(e?.target_parts_count?.toString()||``),[g,_]=(0,y.useState)(e?.status||`active`),[v,b]=(0,y.useState)(e?.tags||``),[x,S]=(0,y.useState)(e?.due_date?.split(`T`)[0]||``),[C,w]=(0,y.useState)(e?.priority||`normal`),[T,E]=(0,y.useState)(e?.budget?.toString()||``),[D,O]=(0,y.useState)(e?.url||``),[k,A]=(0,y.useState)(null),j=Qa(),[M,N]=(0,y.useState)(e?.cover_image_filename||null),P=(0,y.useRef)(null),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)(0);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 w-full max-w-md border border-bambu-dark-tertiary flex flex-col max-h-[calc(100vh-2rem)]`,children:[(0,K.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e?`projects.editProject`:`projects.newProject`)})}),(0,K.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let r=D.trim();if(r&&!/^https?:\/\//i.test(r)){A(a(`projects.urlInvalid`));return}A(null),n({name:o.trim(),description:c.trim()||void 0,color:u,target_count:f?parseInt(f,10):void 0,target_parts_count:m?parseInt(m,10):void 0,tags:v.trim()||void 0,due_date:x||void 0,priority:C,budget:T.trim()?parseFloat(T):null,url:e?r||null:r||void 0,...e&&{status:g}})},className:`flex flex-col flex-1 min-h-0`,children:[(0,K.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,K.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.namePlaceholder`),required:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.description`)}),(0,K.jsx)(`textarea`,{value:c,onChange:e=>l(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none`,placeholder:a(`projects.descriptionPlaceholder`),rows:2})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.urlLabel`)}),(0,K.jsx)(`input`,{type:`url`,value:D,onChange:e=>{O(e.target.value),k&&A(null)},className:`w-full bg-bambu-dark border rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none ${k?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,placeholder:a(`projects.urlPlaceholder`),maxLength:2048}),k&&(0,K.jsx)(`p`,{className:`text-xs text-red-400 mt-1`,children:k})]}),e&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.coverImageLabel`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-20 h-20 rounded bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden flex items-center justify-center flex-shrink-0`,children:M?(0,K.jsx)(`img`,{src:`${Q.getProjectCoverImageUrl(e.id)}?v=${L}`,alt:a(`projects.coverImageAlt`),className:`w-full h-full object-cover`}):(0,K.jsx)(Dc,{className:`w-6 h-6 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(`input`,{ref:P,type:`file`,accept:`image/jpeg,image/png,image/gif,image/webp`,onChange:async t=>{let n=t.target.files?.[0];if(!(!n||!e)){I(!0);try{N((await Q.uploadProjectCoverImage(e.id,n)).filename),R(e=>e+1),j.invalidateQueries({queryKey:[`projects`]})}catch{}finally{I(!1),P.current&&(P.current.value=``)}}},className:`hidden`}),(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:()=>P.current?.click(),disabled:F,children:[F?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Su,{className:`w-4 h-4 mr-1`}),a(M?`projects.coverImageReplace`:`projects.coverImageUpload`)]}),M&&(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:async()=>{if(e){I(!0);try{await Q.deleteProjectCoverImage(e.id),N(null),R(e=>e+1),j.invalidateQueries({queryKey:[`projects`]})}finally{I(!1)}}},disabled:F,children:[(0,K.jsx)(Pu,{className:`w-4 h-4 mr-1`}),a(`projects.coverImageRemove`)]})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.color`)}),(0,K.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:A7.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>d(e),className:`w-8 h-8 rounded-full transition-transform ${u===e?`ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110`:``}`,style:{backgroundColor:e}},e))})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetPlates`)}),(0,K.jsx)(`input`,{type:`number`,value:f,onChange:e=>p(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetPlatesPlaceholder`),min:`1`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetPlatesHelp`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetParts`)}),(0,K.jsx)(`input`,{type:`number`,value:m,onChange:e=>h(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetPartsPlaceholder`),min:`1`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetPartsHelp`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.tagsLabel`)}),(0,K.jsx)(`input`,{type:`text`,value:v,onChange:e=>b(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.tagsPlaceholder`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.dueDate`)}),(0,K.jsx)(`input`,{type:`date`,value:x,onChange:e=>S(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.priority`)}),(0,K.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsx)(`option`,{value:`low`,children:a(`projects.priorityLow`)}),(0,K.jsx)(`option`,{value:`normal`,children:a(`projects.priorityNormal`)}),(0,K.jsx)(`option`,{value:`high`,children:a(`projects.priorityHigh`)}),(0,K.jsx)(`option`,{value:`urgent`,children:a(`projects.priorityUrgent`)})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projectDetail.cost.budget`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray pointer-events-none`,children:i}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:T,onChange:e=>E(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded pl-8 pr-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:`0.00`})]})]}),e&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.status`)}),(0,K.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsx)(`option`,{value:`active`,children:a(`projects.statusActive`)}),(0,K.jsx)(`option`,{value:`completed`,children:a(`projects.statusCompleted`)}),(0,K.jsx)(`option`,{value:`archived`,children:a(`projects.statusArchived`)})]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,children:a(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!o.trim()||r,children:r?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):a(e?`common.save`:`projects.create`)})]})]})]})})}function fBe({projectId:e,altText:t}){let n=(0,y.useRef)(null),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(null);return(0,K.jsxs)(`div`,{ref:n,className:`relative flex-shrink-0`,onMouseEnter:()=>{if(!n.current)return;let e=n.current.getBoundingClientRect(),t=window.innerWidth,r=window.innerHeight,a=e.right+8;a+384>t-8&&(a=e.left-384-8);let s=e.top;s+384>r-8&&(s=r-384-8),s<8&&(s=8),o({left:a,top:s}),i(!0)},onMouseLeave:()=>i(!1),onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-lg overflow-hidden bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,K.jsx)(`img`,{src:Q.getProjectCoverImageUrl(e),alt:t,className:`w-full h-full object-cover`,loading:`lazy`})}),r&&a&&(0,Zf.createPortal)((0,K.jsx)(`div`,{className:`fixed z-[100] w-96 h-96 rounded-lg overflow-hidden border border-bambu-dark-tertiary shadow-2xl bg-bambu-dark pointer-events-none`,style:{left:a.left,top:a.top},"aria-hidden":`true`,children:(0,K.jsx)(`img`,{src:Q.getProjectCoverImageUrl(e),alt:``,className:`w-full h-full object-contain`,loading:`lazy`})}),document.body)]})}function pBe({project:e,onClick:t,onEdit:n,onDelete:r,hasPermission:i,t:a}){let o=e.target_count?Math.round(e.archive_count/e.target_count*100):0,s=e.target_parts_count?Math.round(e.completed_count/e.target_parts_count*100):0,c=e.status===`completed`,l=e.status===`archived`,[u,d]=(0,y.useState)(!1),f=c?{icon:us,color:`text-bambu-green`,bg:`bg-bambu-green/10`}:l?{icon:wo,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`}:e.queue_count>0?{icon:_s,color:`text-blue-400`,bg:`bg-blue-400/10`}:{icon:nc,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`};return(0,K.jsxs)(`div`,{className:`group relative bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary hover:border-bambu-green/50 hover:shadow-lg hover:shadow-bambu-green/5 transition-all duration-300 cursor-pointer overflow-hidden`,onClick:t,children:[(0,K.jsx)(`div`,{className:`absolute top-0 left-0 w-1.5 h-full`,style:{backgroundColor:e.color||`#6b7280`,boxShadow:`0 0 12px ${e.color||`#6b7280`}40`}}),(0,K.jsxs)(`div`,{className:`p-5 pl-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[e.cover_image_filename?(0,K.jsx)(fBe,{projectId:e.id,altText:a(`projects.coverImageAlt`)}):(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${f.bg} flex-shrink-0`,children:(0,K.jsx)(f.icon,{className:`w-5 h-5 ${f.color}`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.jsx)(`h3`,{className:`font-semibold text-white truncate`,children:e.name}),e.url&&(0,K.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),title:e.url,"aria-label":a(`projects.openExternalUrl`),className:`inline-flex items-center justify-center w-6 h-6 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-green hover:bg-bambu-green/10 hover:border-bambu-green transition-colors flex-shrink-0`,children:(0,K.jsx)(Us,{className:`w-3.5 h-3.5`})}),e.target_parts_count?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${s>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.completed_count,`/`,e.target_parts_count,` `,a(`projects.parts`)]}):e.target_count?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${o>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.archive_count,`/`,e.target_count,` `,a(`projects.plates`)]}):e.completed_count>0?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium bg-bambu-dark text-bambu-gray`,children:[e.completed_count,` `,a(`projects.parts`)]}):null,c&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap`,children:a(`projects.done`)}),l&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap`,children:a(`projects.statusArchived`)})]}),e.description&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1 line-clamp-1`,children:e.description}),e.archives&&e.archives.length>0&&(()=>{let t=e.archives.map(e=>e.filament_type).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(Boolean),n=[...new Set(t)],r=e.archives.map(e=>e.filament_color).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(e=>e.startsWith(`#`)||/^[0-9A-Fa-f]{6}$/.test(e)),i=[...new Set(r)];return n.length===0&&i.length===0?null:(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[n.slice(0,3).map(e=>(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 bg-bambu-dark text-bambu-gray rounded`,children:e},e)),i.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[i.slice(0,5).map(e=>(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e.startsWith(`#`)?e:`#${e}`},title:e},e)),i.length>5&&(0,K.jsxs)(`span`,{className:`text-[10px] text-bambu-gray ml-0.5`,children:[`+`,i.length-5]})]})]})})()]})]}),(0,K.jsxs)(`div`,{className:`relative`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`button`,{className:`p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors opacity-0 group-hover:opacity-100`,onClick:()=>d(!u),children:(0,K.jsx)(zs,{className:`w-4 h-4`})}),u&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>d(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 top-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,K.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${i(`projects:update`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{i(`projects:update`)&&(n(),d(!1))},disabled:!i(`projects:update`),title:i(`projects:update`)?void 0:a(`projects.noEditPermission`),children:[(0,K.jsx)(dl,{className:`w-4 h-4`}),a(`common.edit`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${i(`projects:delete`)?`text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{i(`projects:delete`)&&(r(),d(!1))},disabled:!i(`projects:delete`),title:i(`projects:delete`)?void 0:a(`projects.noDeletePermission`),children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),a(`common.delete`)]})]})]})]})]}),(0,K.jsx)(`div`,{className:`mb-4`,children:e.target_count||e.target_parts_count?(0,K.jsxs)(`div`,{className:`space-y-3`,children:[e.target_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:a(`projects.plates`)}),(0,K.jsxs)(`span`,{className:o>=100?`text-bambu-green font-medium`:`text-white`,children:[e.archive_count,` / `,e.target_count]})]}),(0,K.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(o,100)}%`,background:o>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${o>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.target_parts_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:a(`projects.parts`)}),(0,K.jsxs)(`span`,{className:s>=100?`text-bambu-green font-medium`:`text-white`,children:[e.completed_count,` / `,e.target_parts_count]})]}),(0,K.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(s,100)}%`,background:s>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${s>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`text-xs text-red-400`,children:[e.failed_count,` `,a(`projects.failed`)]})]}):e.completed_count>0||e.failed_count>0?(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-xs`,children:[e.completed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,K.jsx)(wo,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.completed_count,` `,a(`projects.completed`)]})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-400`,children:[(0,K.jsx)(vu,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.failed_count,` `,a(`projects.failed`)]})]}),e.queue_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-blue-400`,children:[(0,K.jsx)(_s,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.queue_count,` `,a(`projects.inQueue`)]})]})]}):(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray/60 italic`,children:a(`projects.noPrintsYet`)})}),e.archives&&e.archives.length>0&&(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`div`,{className:`grid grid-cols-4 gap-1.5`,children:e.archives.slice(0,4).map(e=>(0,K.jsxs)(`div`,{className:`relative aspect-square rounded-lg bg-bambu-dark overflow-hidden border border-bambu-dark-tertiary`,title:e.print_name||`Unknown`,children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:e.print_name||``,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray/50`,children:(0,K.jsx)(cl,{className:`w-6 h-6`})}),e.status===`failed`&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-red-500/40 flex items-center justify-center`,children:(0,K.jsx)(vu,{className:`w-4 h-4 text-white`})})]},e.id))}),e.archive_count>4&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5 text-center`,children:a(`common.more`,{count:e.archive_count-4})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-xs text-bambu-gray`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:a(`projects.printJobs`),children:[(0,K.jsx)(Nc,{className:`w-3.5 h-3.5 text-blue-400`}),(0,K.jsxs)(`span`,{children:[e.archive_count,` `,a(`projects.plates`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:a(`projects.partsPrinted`),children:[(0,K.jsx)(cl,{className:`w-3.5 h-3.5 text-bambu-green`}),(0,K.jsxs)(`span`,{children:[e.completed_count,` `,a(`projects.parts`)]})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-400`,title:a(`projects.failedParts`),children:[(0,K.jsx)(vu,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{children:e.failed_count})]}),e.queue_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-yellow-400`,title:a(`projects.inQueue`),children:[(0,K.jsx)(zc,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{children:e.queue_count})]})]}),(0,K.jsx)(ts,{className:`w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors`})]})]})]})}function mBe(){let{t:e}=G(),t=Yn(),n=Qa(),{showToast:r}=xd(),{hasPermission:i}=sd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(),[l,u]=(0,y.useState)(`active`),[d,f]=(0,y.useState)(null),{data:p}=q({queryKey:[`settings`],queryFn:Q.getSettings}),m=Yd(p?.currency||`USD`),{data:h,isLoading:g}=q({queryKey:[`projects`,l===`all`?void 0:l],queryFn:()=>Q.getProjects(l===`all`?void 0:l)}),_=J({mutationFn:e=>Q.createProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),o(!1),r(e(`projects.toast.created`),`success`)},onError:e=>{r(e.message,`error`)}}),v=J({mutationFn:({id:e,data:t})=>Q.updateProject(e,t),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),o(!1),c(void 0),r(e(`projects.toast.updated`),`success`)},onError:e=>{r(e.message,`error`)}}),b=J({mutationFn:e=>Q.deleteProject(e),onSuccess:()=>{f(null),r(e(`projects.toast.deleted`),`success`),setTimeout(()=>window.location.reload(),100)},onError:e=>{f(null),r(e.message,`error`)}}),x=J({mutationFn:e=>Q.importProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),r(e(`projects.toast.imported`),`success`)},onError:e=>{r(e.message,`error`)}}),S=(0,y.useRef)(null),C=async()=>{try{let t=await Q.getProjects(),n=await Promise.all(t.map(async e=>await Q.exportProjectJson(e.id))),i=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`bambuddy_projects_${new Date().toISOString().split(`T`)[0]}.json`,o.click(),URL.revokeObjectURL(a),r(e(`projects.toast.exported`),`success`)}catch(e){r(e.message,`error`)}},w=()=>{S.current?.click()},T=async t=>{let i=t.target.files?.[0];if(i){try{if(i.name.toLowerCase().endsWith(`.zip`))await Q.importProjectFile(i),n.invalidateQueries({queryKey:[`projects`]}),r(e(`projects.toast.imported`),`success`);else{let t=await i.text(),n=JSON.parse(t),a=Array.isArray(n)?n:[n];for(let e of a)await x.mutateAsync(e);a.length>1&&r(e(`projects.toast.multipleImported`,{count:a.length}),`success`)}}catch(t){r(`${e(`projects.toast.importFailed`)}: ${t.message}`,`error`)}t.target.value=``}},E=e=>{s?v.mutate({id:s.id,data:e}):_.mutate(e)},D=e=>{c(e),o(!0)},O=e=>{t(`/projects/${e.id}`)},k=e=>{f(e)},A=()=>{d!==null&&b.mutate(d)},j=h?.reduce((e,t)=>(e[t.status]=(e[t.status]||0)+1,e.all=(e.all||0)+1,e),{})||{};return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,K.jsx)(`input`,{ref:S,type:`file`,accept:`.json,.zip`,onChange:T,className:`hidden`}),(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4`,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)(nc,{className:`w-7 h-7 text-bambu-green`}),e(`projects.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`projects.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:w,disabled:!i(`projects:create`),title:i(`projects:create`)?e(`projects.importProject`):e(`projects.noImportPermission`),children:[(0,K.jsx)(Su,{className:`w-4 h-4 mr-2`}),e(`projects.import`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:C,disabled:!i(`projects:read`),title:i(`projects:read`)?e(`projects.exportAll`):e(`projects.noExportPermission`),children:[(0,K.jsx)(Is,{className:`w-4 h-4 mr-2`}),e(`projects.export`)]}),(0,K.jsxs)($,{onClick:()=>o(!0),className:`sm:w-auto w-full`,disabled:!i(`projects:create`),title:i(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,K.jsx)(_l,{className:`w-4 h-4 mr-2`}),e(`projects.newProject`)]})]})]}),(0,K.jsx)(`div`,{className:`flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit`,children:[{key:`active`,label:e(`projects.statusActive`),icon:_s},{key:`completed`,label:e(`projects.statusCompleted`),icon:us},{key:`archived`,label:e(`projects.statusArchived`),icon:wo},{key:`all`,label:e(`common.all`),icon:nc}].map(({key:e,label:t,icon:n})=>(0,K.jsxs)(`button`,{onClick:()=>u(e),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${l===e?`bg-bambu-card text-white shadow-sm`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(n,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:t}),j[e]>0&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${l===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary`}`,children:j[e]})]},e))}),g?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`projects.loading`)})]})}):h?.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 px-4`,children:[(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,K.jsx)(nc,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,K.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:l===`all`?e(`projects.noProjects`):e(`projects.noProjectsFiltered`,{status:l})}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:l===`all`?e(`projects.createFirst`):e(`projects.noProjectsFilteredHelp`,{status:l})}),l===`all`&&(0,K.jsxs)($,{onClick:()=>o(!0),disabled:!i(`projects:create`),title:i(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,K.jsx)(_l,{className:`w-4 h-4 mr-2`}),e(`projects.createFirstButton`)]})]}):(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8`,children:h?.map(t=>(0,K.jsx)(pBe,{project:t,onClick:()=>O(t),onEdit:()=>D(t),onDelete:()=>k(t.id),hasPermission:i,t:e},t.id))}),d!==null&&(0,K.jsx)(Ed,{title:e(`projects.deleteProject`),message:e(`projects.deleteConfirm`),confirmText:e(`projects.deleteProject`),variant:`danger`,onConfirm:A,onCancel:()=>f(null)}),a&&(0,K.jsx)(j7,{project:s,onClose:()=>{o(!1),c(void 0)},onSave:E,isLoading:_.isPending||v.isPending,currencySymbol:m,t:e})]})}function hBe(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)}function gBe(e){return e>=1e3?`${(e/1e3).toFixed(2)}kg`:`${Math.round(e)}g`}function _Be({status:e,t}){let n={active:`bg-bambu-green/20 text-bambu-green`,completed:`bg-blue-500/20 text-blue-400`,archived:`bg-bambu-gray/20 text-bambu-gray`},r=n[e]||n.active,i={active:t(`projectDetail.status.active`),completed:t(`projectDetail.status.completed`),archived:t(`projectDetail.status.archived`)};return(0,K.jsx)(`span`,{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:i[e]||e.charAt(0).toUpperCase()+e.slice(1)})}function M7({icon:e,label:t,value:n,subValue:r,hint:i,color:a=`text-bambu-gray`}){return(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,title:i,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${a}`,children:(0,K.jsx)(e,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,K.jsx)(`p`,{className:`text-xl font-semibold text-white`,children:n}),r&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:r})]})]})})})}function vBe({archives:e,t}){return e.length===0?(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(cl,{className:`w-12 h-12 mx-auto mb-2 opacity-50`}),(0,K.jsx)(`p`,{children:t(`projectDetail.noPrints`)})]}):(0,K.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3`,children:e.map(e=>(0,K.jsxs)(bi,{to:`/archives?search=${encodeURIComponent(e.print_name||``)}`,className:`group relative aspect-square rounded-lg bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden hover:border-bambu-green transition-colors`,children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:e.print_name||`Print`,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,K.jsx)(cl,{className:`w-8 h-8`})}),e.status===`failed`&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-red-500/30 flex items-center justify-center`,children:(0,K.jsx)(ms,{className:`w-8 h-8 text-white`})}),e.status===`completed`&&(0,K.jsx)(`div`,{className:`absolute top-1 right-1`,children:(0,K.jsx)(ls,{className:`w-4 h-4 text-bambu-green`})}),(0,K.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,K.jsx)(`p`,{className:`text-xs text-white truncate`,children:e.print_name||`Unknown`})})]},e.id))})}function yBe({priority:e,t}){let n={low:{color:`bg-gray-500/20 text-gray-400`,label:t(`projectDetail.priority.low`)},normal:{color:`bg-blue-500/20 text-blue-400`,label:t(`projectDetail.priority.normal`)},high:{color:`bg-orange-500/20 text-orange-400`,label:t(`projectDetail.priority.high`)},urgent:{color:`bg-red-500/20 text-red-400`,label:t(`projectDetail.priority.urgent`)}},{color:r,label:i}=n[e]||n.normal;return(0,K.jsxs)(`span`,{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[e===`urgent`&&(0,K.jsx)(vu,{className:`w-3 h-3`}),i]})}function N7(e,t){if(!e)return null;let n=mf(e);if(!n)return null;let r=new Date,i=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return i<0?{color:`text-red-400`,label:t(`projectDetail.dueDate.overdue`)}:i===0?{color:`text-orange-400`,label:t(`projectDetail.dueDate.today`)}:i<=3?{color:`text-yellow-400`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}:{color:`text-bambu-gray`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}}function bBe(){let{id:e}=er(),t=Yn(),{t:n}=G(),r=Qa(),{showToast:i}=xd(),{hasPermission:a}=sd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null),g=parseInt(e||`0`,10),{data:_,isLoading:v,error:b}=q({queryKey:[`project`,g],queryFn:()=>Q.getProject(g),enabled:g>0}),{data:x,isLoading:S}=q({queryKey:[`project-archives`,g],queryFn:()=>Q.getProjectArchives(g),enabled:g>0}),{data:C,isLoading:w}=q({queryKey:[`project-bom`,g],queryFn:()=>Q.getProjectBOM(g),enabled:g>0}),{data:T,isLoading:E}=q({queryKey:[`project-timeline`,g],queryFn:()=>Q.getProjectTimeline(g,20),enabled:g>0}),{data:D}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:O}=q({queryKey:[`project-folders`,g],queryFn:()=>Q.getLibraryFoldersByProject(g),enabled:g>0}),{data:k,isLoading:A}=q({queryKey:[`project-files`,g],queryFn:()=>Q.getLibraryFiles(null,!1,g),enabled:g>0}),j=(0,y.useMemo)(()=>{let e=new Map;for(let t of k??[])if(t.folder_id!=null){let n=e.get(t.folder_id)??[];n.push(t),e.set(t.folder_id,n)}return e},[k]),M=Yd(D?.currency||`USD`),N=D?.time_format||`system`,P=J({mutationFn:e=>Q.updateProject(g,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project`,g]}),r.invalidateQueries({queryKey:[`projects`]}),s(!1),l(!1),i(n(`projectDetail.toast.projectUpdated`),`success`)},onError:e=>{i(e.message,`error`)}}),F=()=>{d(_?.notes||``),l(!0)},I=()=>{P.mutate({notes:u})},L=()=>{l(!1),d(``)},[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(1),[ee,H]=(0,y.useState)(``),[te,ne]=(0,y.useState)(``),[re,U]=(0,y.useState)(``),[ie,ae]=(0,y.useState)(!1),[W,oe]=(0,y.useState)(!1),[se,ce]=(0,y.useState)(null),[le,ue]=(0,y.useState)(``),[de,fe]=(0,y.useState)(1),[pe,me]=(0,y.useState)(``),[he,ge]=(0,y.useState)(``),[_e,ve]=(0,y.useState)(``),[ye,be]=(0,y.useState)({isOpen:!1,title:``,message:``,onConfirm:()=>{}}),xe=J({mutationFn:e=>Q.createBOMItem(g,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,g]}),r.invalidateQueries({queryKey:[`project`,g]}),z(``),V(1),H(``),ne(``),U(``),ae(!1),i(n(`projectDetail.toast.partAdded`),`success`)},onError:e=>i(e.message,`error`)}),Se=J({mutationFn:({itemId:e,data:t})=>Q.updateBOMItem(g,e,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,g]}),r.invalidateQueries({queryKey:[`project`,g]}),ce(null)},onError:e=>i(e.message,`error`)}),Ce=J({mutationFn:e=>Q.deleteBOMItem(g,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,g]}),r.invalidateQueries({queryKey:[`project`,g]}),i(n(`projectDetail.toast.partRemoved`),`success`)},onError:e=>i(e.message,`error`)}),we=e=>{e.preventDefault(),R.trim()&&xe.mutate({name:R.trim(),quantity_needed:B,unit_price:ee?parseFloat(ee):void 0,sourcing_url:te.trim()||void 0,remarks:re.trim()||void 0})},Te=e=>{let t=e.is_complete?0:e.quantity_needed;Se.mutate({itemId:e.id,data:{quantity_acquired:t}})},Ee=(e,t)=>{be({isOpen:!0,title:n(`projectDetail.bom.deletePart`),message:n(`projectDetail.bom.deleteConfirm`,{name:t}),onConfirm:()=>{be(e=>({...e,isOpen:!1})),Ce.mutate(e)}})},De=e=>{ce(e),ue(e.name),fe(e.quantity_needed),me(e.unit_price?.toString()||``),ge(e.sourcing_url||``),ve(e.remarks||``)},Oe=e=>{e.preventDefault(),!(!se||!le.trim())&&Se.mutate({itemId:se.id,data:{name:le.trim(),quantity_needed:de,unit_price:pe?parseFloat(pe):void 0,sourcing_url:he.trim()||void 0,remarks:_e.trim()||void 0}})},ke=()=>{ce(null)},Ae=async()=>{try{let{blob:e,filename:t}=await Q.exportProjectZip(Number(g)),r=URL.createObjectURL(e),a=document.createElement(`a`);a.href=r,a.download=t||`${_?.name||`project`}_${new Date().toISOString().split(`T`)[0]}.zip`,a.click(),URL.revokeObjectURL(r),i(n(`projectDetail.toast.projectExported`),`success`)}catch(e){i(e.message,`error`)}},je=J({mutationFn:()=>Q.createTemplateFromProject(g),onSuccess:()=>{r.invalidateQueries({queryKey:[`projects`]}),i(n(`projectDetail.toast.templateCreated`),`success`)},onError:e=>i(e.message,`error`)}),Me=e=>gf(e,N,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`});if(v)return(0,K.jsx)(`div`,{className:`flex items-center justify-center py-24`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})});if(b||!_)return(0,K.jsxs)(`div`,{className:`text-center py-24`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:b?`${n(`common.error`)}: ${b.message}`:n(`projectDetail.notFound`)}),(0,K.jsx)($,{variant:`secondary`,className:`mt-4`,onClick:()=>t(`/projects`),children:n(`projectDetail.backToProjects`)})]});let Ne=_.stats,Pe=Ne?.progress_percent??0,Fe=Ne?.parts_progress_percent??0;return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(bi,{to:`/projects`,className:`hover:text-white transition-colors`,children:n(`nav.projects`)}),(0,K.jsx)(ts,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-white`,children:_.name})]}),(0,K.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(`button`,{onClick:()=>t(`/projects`),className:`p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors`,children:(0,K.jsx)(Do,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-4 h-4 rounded-full shrink-0`,style:{backgroundColor:_.color||`#6b7280`}}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:_.name}),_.description&&(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:_.description})]})]}),(0,K.jsx)(_Be,{status:_.status,t:n})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:Ae,disabled:!a(`projects:read`),title:a(`projects:read`)?n(`projectDetail.exportProject`):n(`projectDetail.noExportPermission`),children:[(0,K.jsx)(Is,{className:`w-4 h-4 mr-2`}),n(`projectDetail.export`)]}),(0,K.jsxs)($,{onClick:()=>s(!0),disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.noEditPermission`),children:[(0,K.jsx)(dl,{className:`w-4 h-4 mr-2`}),n(`common.edit`)]})]})]}),(_.target_count||_.target_parts_count)&&(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-4 space-y-4`,children:[_.target_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.platesProgress`)}),(0,K.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Ne?.total_archives||0,` / `,_.target_count,` `,n(`projectDetail.progress.printJobs`)]})]}),(0,K.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(Pe,100)}%`,backgroundColor:Pe>=100?`#22c55e`:_.color||`#6b7280`}})}),(0,K.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:Pe.toFixed(0)})}),Ne?.remaining_prints!=null&&Ne.remaining_prints>0&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Ne.remaining_prints})})]})]}),_.target_parts_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.partsProgress`)}),(0,K.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Ne?.completed_prints||0,` / `,_.target_parts_count,` `,n(`projectDetail.progress.parts`)]})]}),(0,K.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(Fe,100)}%`,backgroundColor:Fe>=100?`#22c55e`:_.color||`#6b7280`}})}),(0,K.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:Fe.toFixed(0)})}),Ne?.remaining_parts!=null&&Ne.remaining_parts>0&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Ne.remaining_parts})})]})]})]})}),Ne&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark text-bambu-green`,children:(0,K.jsx)(cl,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.printJobs`)}),(0,K.jsxs)(`p`,{className:`text-xl font-semibold text-white`,children:[Ne.total_archives,` `,(0,K.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:n(`projectDetail.stats.total`)})]}),Ne.failed_prints>0&&(0,K.jsx)(`p`,{className:`text-sm text-status-error`,children:n(`projectDetail.stats.failed`,{count:Ne.failed_prints})}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:Ne.completed_prints})})]})]})})}),(0,K.jsx)(M7,{icon:_s,label:n(`projectDetail.stats.printTime`),value:Sf(Ne.total_print_time_hours),color:`text-yellow-400`}),(0,K.jsx)(M7,{icon:bl,label:n(`projectDetail.stats.filamentUsed`),value:gBe(Ne.total_filament_grams),color:`text-purple-400`})]}),Ne&&(()=>{let e=Ne.estimated_cost+Ne.total_energy_cost+Ne.bom_cost;return Ne.estimated_cost>0||e>0||_.budget!==null})()&&(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white mb-3`,children:n(`projectDetail.cost.title`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.filamentCost`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[M,Ne.estimated_cost.toFixed(2)]})]}),Ne.total_energy_kwh>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.energy`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Ne.total_energy_kwh.toFixed(3),` kWh`,Ne.total_energy_cost>0&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray ml-1`,children:[`(`,M,Ne.total_energy_cost.toFixed(2),`)`]})]})]}),(()=>{let e=Ne.estimated_cost+Ne.total_energy_cost+Ne.bom_cost;return e<=0?null:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[M,e.toFixed(2)]}),Ne.bom_cost>0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.cost.includesBom`)})]})})(),_.budget!==null&&(()=>{let e=Ne.estimated_cost+Ne.total_energy_cost+Ne.bom_cost,t=_.budget-e;return(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.budget`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[n(`projectDetail.cost.total`),`: `,(0,K.jsxs)(`span`,{className:`text-white font-semibold`,children:[M,_.budget.toFixed(2)]})]}),(0,K.jsxs)(`p`,{className:`text-sm ${t>=0?`text-bambu-green`:`text-red-400`}`,children:[n(`projectDetail.cost.remaining`),`: `,(0,K.jsxs)(`span`,{className:`font-semibold`,children:[M,t.toFixed(2)]})]})]})})()]})]})}),_.children&&_.children.length>0&&(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-4`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,K.jsx)(oc,{className:`w-5 h-5`}),n(`projectDetail.subProjects.title`,{count:_.children.length})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:_.children.map(e=>(0,K.jsxs)(bi,{to:`/projects/${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full`,style:{backgroundColor:e.color||`#6b7280`}}),(0,K.jsx)(`span`,{className:`text-white`,children:e.name}),(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded ${e.status===`completed`?`bg-status-ok/20 text-status-ok`:e.status===`archived`?`bg-bambu-gray/20 text-bambu-gray`:`bg-blue-500/20 text-blue-400`}`,children:e.status})]}),e.progress_percent!==null&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.progress_percent.toFixed(0),`%`]})]},e.id))})]})}),_.parent_id&&_.parent_name&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(Nc,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.partOf`)}),(0,K.jsx)(bi,{to:`/projects/${_.parent_id}`,className:`text-bambu-green hover:underline`,children:_.parent_name})]}),(_.tags||_.due_date||_.priority!==`normal`)&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[_.priority&&_.priority!==`normal`&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.priorityLabel`)}),(0,K.jsx)(yBe,{priority:_.priority,t:n})]}),_.due_date&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(qo,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:hf(_.due_date,{year:`numeric`,month:`short`,day:`numeric`})}),N7(_.due_date,n)&&(0,K.jsxs)(`span`,{className:`text-xs ${N7(_.due_date,n).color}`,children:[`(`,N7(_.due_date,n).label,`)`]})]}),_.tags&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(su,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:_.tags.split(`,`).map((e,t)=>(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded`,children:e.trim()},t))})]})]}),(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Zs,{className:`w-5 h-5`}),n(`projectDetail.notes.title`)]}),c?(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:L,disabled:P.isPending,children:[(0,K.jsx)(Pu,{className:`w-4 h-4 mr-1`}),n(`common.cancel`)]}),(0,K.jsxs)($,{size:`sm`,onClick:I,disabled:P.isPending,children:[P.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-1`}):(0,K.jsx)(Ol,{className:`w-4 h-4 mr-1`}),n(`common.save`)]})]}):(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:F,disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.notes.noEditPermission`),children:[(0,K.jsx)(dl,{className:`w-4 h-4 mr-1`}),n(`common.edit`)]})]}),c?(0,K.jsx)(Z3,{content:u,onChange:d,placeholder:n(`projectDetail.notes.placeholder`)}):_.notes?(0,K.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:HJ.sanitize(_.notes)}}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.notes.empty`)})]})}),(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(rc,{className:`w-5 h-5`}),n(`projectDetail.files.title`)]})}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:[(0,K.jsx)(bi,{to:`/files`,className:`text-bambu-green hover:underline`,children:n(`projectDetail.files.linkFolders`)}),` `,n(`projectDetail.files.forQuickAccess`)]}),O&&O.length>0?(0,K.jsx)(`div`,{className:`space-y-4`,children:O.map(e=>{let t=j.get(e.id)??[],r=A;return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(bi,{to:`/files?folder=${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors mb-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,K.jsx)(rc,{className:`w-5 h-5 text-bambu-green shrink-0`}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`projectDetail.files.fileCount`,{count:e.file_count})})]})]}),(0,K.jsx)(ts,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),r?(0,K.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-bambu-gray text-sm`,children:(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`})}):t.length===0?(0,K.jsx)(`p`,{className:`text-bambu-gray/60 text-xs italic px-3`,children:n(`projectDetail.files.noFiles`)}):(0,K.jsx)(`div`,{className:`space-y-1 pl-3`,children:t.map(e=>{let t=hBe(e.filename);return(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 shrink-0 rounded bg-bambu-dark overflow-hidden flex items-center justify-center`,children:e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getLibraryFileThumbnailUrl(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,K.jsx)(qs,{className:`w-5 h-5 text-bambu-gray/40`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-500/20 text-blue-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:e.file_type.toUpperCase()})]}),t&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,K.jsx)(`button`,{onClick:()=>p(e),title:n(`projectDetail.files.print`),className:`p-1.5 rounded hover:bg-bambu-green/20 text-bambu-green transition-colors`,children:(0,K.jsx)(hl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>h(e),title:n(`projectDetail.files.addToQueue`),className:`p-1.5 rounded hover:bg-blue-500/20 text-blue-400 transition-colors`,children:(0,K.jsx)(Ko,{className:`w-4 h-4`})})]})]},e.id)})})]},e.id)})}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.files.empty`)})]})}),(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Ul,{className:`w-5 h-5`}),n(`projectDetail.bom.title`),Ne&&Ne.bom_total_items>0&&(0,K.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n(`projectDetail.bom.acquired`,{completed:Ne.bom_completed_items,total:Ne.bom_total_items}),`)`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[C&&C.some(e=>e.is_complete)&&(0,K.jsx)(`button`,{onClick:()=>oe(!W),className:`text-xs px-2 py-1 rounded transition-colors ${W?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:n(W?`projectDetail.bom.showAll`:`projectDetail.bom.hideDone`)}),!ie&&(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>ae(!0),disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.bom.noAddPermission`),children:[(0,K.jsx)(_l,{className:`w-4 h-4 mr-1`}),n(`projectDetail.bom.addPart`)]})]})]}),ie&&(0,K.jsxs)(`form`,{onSubmit:we,className:`bg-bambu-dark rounded-lg p-4 mb-4 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partNamePlaceholder`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:B,onChange:e=>V(parseInt(e.target.value)||1),className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:`1`,placeholder:n(`projectDetail.bom.qty`)}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,value:ee,onChange:e=>H(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:M})})]})]}),(0,K.jsx)(`input`,{type:`url`,value:te,onChange:e=>ne(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,K.jsx)(`input`,{type:`text`,value:re,onChange:e=>U(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>ae(!1),children:n(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,size:`sm`,disabled:!R.trim()||xe.isPending,children:xe.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):n(`projectDetail.bom.addPart`)})]})]}),w?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):C&&C.length>0?(0,K.jsxs)(`div`,{className:`space-y-2`,children:[C.filter(e=>!W||!e.is_complete).map(e=>(0,K.jsx)(`div`,{className:`p-3 rounded-lg transition-colors ${e.is_complete?`bg-status-ok/10`:`bg-bambu-dark`}`,children:se?.id===e.id?(0,K.jsxs)(`form`,{onSubmit:Oe,className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:le,onChange:e=>ue(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partName`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:de,onChange:e=>fe(parseInt(e.target.value)||1),className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:`1`,placeholder:n(`projectDetail.bom.qty`)}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,value:pe,onChange:e=>me(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:M})})]})]}),(0,K.jsx)(`input`,{type:`url`,value:he,onChange:e=>ge(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,K.jsx)(`input`,{type:`text`,value:_e,onChange:e=>ve(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,size:`sm`,onClick:ke,children:n(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,size:`sm`,disabled:!le.trim()||Se.isPending,children:Se.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]})]}):(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&Te(e),disabled:Se.isPending||!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.bom.noUpdatePermission`),className:`w-5 h-5 mt-0.5 rounded border-2 flex items-center justify-center transition-colors shrink-0 ${e.is_complete?`bg-status-ok border-status-ok text-white`:a(`projects:update`)?`border-bambu-gray hover:border-bambu-green`:`border-bambu-gray/50 cursor-not-allowed`}`,children:e.is_complete&&(0,K.jsx)(ls,{className:`w-3 h-3`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsxs)(`p`,{className:`text-sm font-medium ${e.is_complete?`text-bambu-gray line-through`:`text-white`}`,children:[e.name,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal ml-2`,children:[`x`,e.quantity_needed]})]}),e.unit_price!==null&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-green whitespace-nowrap`,children:[M,(e.unit_price*e.quantity_needed).toFixed(2)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&De(e),disabled:!a(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${a(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`projects:update`)?n(`common.edit`):n(`projectDetail.bom.noEditPermission`),children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&Ee(e.id,e.name),disabled:!a(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${a(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`projects:update`)?n(`common.delete`):n(`projectDetail.bom.noDeletePermission`),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]}),e.sourcing_url&&(0,K.jsxs)(`a`,{href:e.sourcing_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 mt-1 text-xs text-blue-400 hover:text-blue-300 transition-colors`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(Us,{className:`w-3 h-3 shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.sourcing_url).hostname.replace(`www.`,``)}catch{return e.sourcing_url}})()})]}),e.remarks&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray/80 italic`,children:e.remarks})]})]})},e.id)),Ne&&Ne.bom_cost>0&&(0,K.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.bom.totalCost`)}),(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[M,Ne.bom_cost.toFixed(2)]})]})]}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.bom.empty`)})]})}),(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(wc,{className:`w-5 h-5`}),n(`projectDetail.timeline.title`)]})}),E?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):T&&T.length>0?(0,K.jsx)(`div`,{className:`space-y-3`,children:T.slice(0,10).map((e,t)=>(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsxs)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0 ${e.event_type===`print_completed`?`bg-status-ok/20 text-status-ok`:e.event_type===`print_failed`?`bg-status-error/20 text-status-error`:e.event_type===`print_started`?`bg-yellow-500/20 text-yellow-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e.event_type===`print_completed`&&(0,K.jsx)(ls,{className:`w-4 h-4`}),e.event_type===`print_failed`&&(0,K.jsx)(ms,{className:`w-4 h-4`}),e.event_type===`print_started`&&(0,K.jsx)(bl,{className:`w-4 h-4`}),e.event_type===`queued`&&(0,K.jsx)(zc,{className:`w-4 h-4`}),e.event_type===`project_created`&&(0,K.jsx)(_l,{className:`w-4 h-4`})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:e.title}),e.description&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:Me(e.timestamp)})]})]},t))}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.timeline.empty`)})]})}),!_.is_template&&(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>je.mutate(),disabled:je.isPending||!a(`projects:create`),title:a(`projects:create`)?void 0:n(`projectDetail.template.noCreatePermission`),children:[je.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-2`}):(0,K.jsx)(Ds,{className:`w-4 h-4 mr-2`}),n(`projectDetail.template.saveAsTemplate`)]})}),Ne&&(Ne.queued_prints>0||Ne.in_progress_prints>0)&&(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(zc,{className:`w-5 h-5`}),n(`projectDetail.queue.title`)]}),(0,K.jsx)(bi,{to:`/queue?project=${g}`,className:`text-sm text-bambu-green hover:underline`,children:n(`projectDetail.queue.viewAll`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[Ne.in_progress_prints>0&&(0,K.jsx)(`span`,{className:`text-yellow-400`,children:n(`projectDetail.queue.printing`,{count:Ne.in_progress_prints})}),Ne.queued_prints>0&&(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.queue.queued`,{count:Ne.queued_prints})})]})]})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-4`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(cl,{className:`w-5 h-5`}),n(`projectDetail.prints.title`,{count:x?.length||0})]})}),S?(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-green`})}):(0,K.jsx)(vBe,{archives:x||[],t:n})]}),o&&(0,K.jsx)(j7,{t:n,currencySymbol:M,project:{..._,archive_count:Ne?.total_archives||0,total_items:Ne?.total_items||0,completed_count:Ne?.completed_prints||0,failed_count:Ne?.failed_prints||0,queue_count:Ne?.queued_prints||0,progress_percent:Ne?.progress_percent||null,archives:[]},onClose:()=>s(!1),onSave:e=>P.mutate(e),isLoading:P.isPending}),ye.isOpen&&(0,K.jsx)(Ed,{title:ye.title,message:ye.message,confirmText:n(`common.delete`),variant:`danger`,onConfirm:ye.onConfirm,onCancel:()=>be(e=>({...e,isOpen:!1}))}),f&&(0,K.jsx)(sq,{mode:`reprint`,libraryFileId:f.id,archiveName:f.print_name||f.filename,projectId:g,onClose:()=>p(null),onSuccess:()=>{p(null),r.invalidateQueries({queryKey:[`archives`]})}}),m&&(0,K.jsx)(sq,{mode:`add-to-queue`,libraryFileId:m.id,archiveName:m.print_name||m.filename,projectId:g,onClose:()=>h(null),onSuccess:()=>{h(null),r.invalidateQueries({queryKey:[`queue`]})}})]})}function xBe({archiveId:e,libraryFileId:t,title:n,fileType:r,onClose:i,onSliceWithBambuddy:a}){let{t:o}=G(),{data:s}=q({queryKey:[`settings`],queryFn:Q.getSettings}),c=s?.open_in_slicer||s?.preferred_slicer||`bambu_studio`,l=t!=null,[u,d]=(0,y.useState)(null),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(!0),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(null),[C,w]=(0,y.useState)(0),[T,E]=(0,y.useState)(!1),[D,O]=(0,y.useState)(null),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(!1),N=(0,y.useRef)(null),P=(0,y.useRef)(null),F=.35;(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,y.useEffect)(()=>{if(h(!0),l){let e=(r||``).toLowerCase(),t=e===`3mf`||e===`gcode.3mf`,n=t||e===`stl`,i=t||e===`gcode`;p({has_model:n,has_gcode:i,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),d(n?`3d`:i?`gcode`:null),h(!1);return}if(!e){p(null),d(null),h(!1);return}Q.getArchiveCapabilities(e).then(e=>{p(e),e.has_model?d(`3d`):e.has_gcode&&d(`gcode`),h(!1)}).catch(()=>{p({has_model:!0,has_gcode:!1,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),d(`3d`),h(!1)})},[e,r,l]),(0,y.useEffect)(()=>{if(b(!0),S(null),w(0),l){let e=(r||``).toLowerCase();if(!t||!(e===`3mf`||e===`gcode.3mf`)){_(null),b(!1);return}Q.getLibraryFilePlates(t).then(e=>_(e)).catch(()=>_(null)).finally(()=>b(!1));return}if(!e){_(null),b(!1);return}Q.getArchivePlates(e).then(e=>_(e)).catch(()=>_(null)).finally(()=>b(!1))},[e,r,l,t]);let I=(0,y.useMemo)(()=>g?.plates??[],[g]),L=(g?.is_multi_plate??!1)&&I.length>1,R=T&&L,z=x==null?null:I.find(e=>e.index===x)??null,B=e=>e.object_count??e.objects?.length??0,V=I.reduce((e,t)=>e+B(t),0),ee=z?B(z):V,H=z?o(`modelViewer.plateNumber`,{number:z.index}):o(`modelViewer.allPlates`),te=I.length>0,ne=(0,y.useRef)(null),re=(0,y.useRef)(null),[U,ie]=(0,y.useState)(10),[ae,W]=(0,y.useState)(3),oe=I.length>U,se=Math.max(1,Math.ceil(I.length/U)),ce=oe?I.slice(C*U,(C+1)*U):I;(0,y.useEffect)(()=>{if(!R){ie(10),W(3);return}let e=ne.current,t=re.current;if(!e||!t)return;let n=0,r=()=>{let n=t.clientWidth,r=Math.floor(n/210),i=Math.max(3,Math.min(5,r||3));W(e=>e===i?e:i);let a=window.getComputedStyle(e),o=Number.parseFloat(a.rowGap||`0`),s=e.querySelector(`button`)?.getBoundingClientRect().height??44,c=t.clientHeight,l=Math.max(1,Math.floor((c+o)/(s+o)))*i,u=Math.max(1,l-1);ie(e=>e===u?e:u)},i=()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(r)};i();let a=new ResizeObserver(i);return a.observe(t),a.observe(e),()=>{n&&cancelAnimationFrame(n),a.disconnect()}},[R,I.length]),(0,y.useEffect)(()=>{if(!oe){w(0);return}w(e=>Math.min(e,se-1))},[I.length,oe,se]),(0,y.useEffect)(()=>{if(!oe||x==null)return;let e=I.findIndex(e=>e.index===x);if(e<0)return;let t=Math.floor(e/U);w(e=>e===t?e:t)},[I,U,x,oe]),(0,y.useEffect)(()=>{if(!R){O(null),M(!1);return}if(j)return;let e=N.current,t=P.current;if(!e||!t)return;let n=e.clientHeight;if(!n)return;let r=Math.max(240,n*F),i=Math.max(160,n-10-r),a=Math.min(t.scrollHeight,i);O(Math.max(160,a))},[R,j,I.length,C,10,160,240,F]),(0,y.useEffect)(()=>{if(!k)return;let e=e=>{let t=N.current;if(!t)return;let n=t.getBoundingClientRect(),r=n.height;if(!r)return;let i=Math.max(240,r*F),a=Math.max(160,r-10-i);O(Math.min(a,Math.max(160,e.clientY-n.top)))},t=()=>{A(!1),M(!0)};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),document.body.style.cursor=`row-resize`,document.body.style.userSelect=`none`,()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[k,10,160,240,F]);let le=l?(r||``).toLowerCase()===`3mf`:!0,ue=(()=>{let e=(r||``).toLowerCase();return e===`3mf`||e===`stl`||e===`step`||e===`stp`})(),de=!!(l&&s?.use_slicer_api&&a&&ue);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 ${T?`p-0`:`p-8`}`,onClick:i,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary w-full flex flex-col ${T?`h-full max-w-none rounded-none`:`h-[80vh] max-w-4xl rounded-xl`}`,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-3 min-w-0 flex-1 mr-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:n}),te&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary/70 px-2 py-1 rounded whitespace-nowrap`,children:[H,`: `,o(`modelViewer.objectCount`,{count:ee})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[de?(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:a,children:[(0,K.jsx)(ws,{className:`w-4 h-4`}),o(`slice.action`)]}):(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:async()=>{if(!le)return;let r=n||`model`;try{if(l){let{token:e}=await Q.createLibrarySlicerToken(t),n=Q.getLibrarySlicerDownloadUrl(t,e,r);Uq(`${window.location.origin}${n}`,c)}else{let{token:t}=await Q.createArchiveSlicerToken(e),n=Q.getArchiveSlicerDownloadUrl(e,t,r);Uq(`${window.location.origin}${n}`,c)}}catch{Uq(l?`${window.location.origin}${Q.getLibraryFileDownloadUrl(t)}`:`${window.location.origin}${Q.getArchiveForSlicer(e,r)}`,c)}},disabled:!le,children:[(0,K.jsx)(Us,{className:`w-4 h-4`}),o(`modelViewer.openInSlicer`)]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>E(e=>!e),title:T?`Exit fullscreen`:`Enter fullscreen`,children:T?(0,K.jsx)(Qc,{className:`w-4 h-4`}):(0,K.jsx)(Jc,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:i,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]})]}),f&&(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`button`,{onClick:()=>f.has_model&&d(`3d`),disabled:!f.has_model,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${u===`3d`?`text-bambu-green border-b-2 border-bambu-green`:f.has_model?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,K.jsx)(Bo,{className:`w-4 h-4`}),o(`modelViewer.tabs.model`),!f.has_model&&(0,K.jsxs)(`span`,{className:`text-xs`,children:[`(`,o(`modelViewer.notAvailable`),`)`]})]}),(0,K.jsxs)(`button`,{onClick:()=>f.has_gcode&&d(`gcode`),disabled:!f.has_gcode,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${u===`gcode`?`text-bambu-green border-b-2 border-bambu-green`:f.has_gcode?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,K.jsx)(bs,{className:`w-4 h-4`}),o(`modelViewer.tabs.gcode`),!f.has_gcode&&(0,K.jsxs)(`span`,{className:`text-xs`,children:[`(`,o(`modelViewer.notSliced`),`)`]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-hidden p-4`,children:m?(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})}):u===`3d`&&f?(0,K.jsxs)(`div`,{ref:N,className:`w-full h-full flex flex-col ${R?`gap-0 min-h-0`:`gap-3`}`,children:[L&&(0,K.jsxs)(`div`,{ref:P,style:R&&D!=null?{height:D}:void 0,className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3 ${R?`flex flex-col shrink-0`:``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:[(0,K.jsx)(Nc,{className:`w-4 h-4`}),o(`modelViewer.plates`),v&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`})]}),(0,K.jsxs)(`div`,{className:R?`flex flex-col min-h-0 flex-1`:void 0,children:[(0,K.jsx)(`div`,{ref:re,className:R?`min-h-0 overflow-hidden pr-1 flex-1`:void 0,children:(0,K.jsxs)(`div`,{ref:ne,className:R?`grid gap-2`:`grid grid-cols-2 md:grid-cols-3 gap-2`,style:R?{gridTemplateColumns:`repeat(${ae}, minmax(0, 1fr))`}:void 0,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>S(null),className:`flex items-center rounded-lg border text-left transition-colors ${R?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${x==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:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${R?`w-8 h-8`:`w-10 h-10`}`,children:(0,K.jsx)(Nc,{className:`${R?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`${R?`text-xs`:`text-sm`} text-white font-medium truncate`,children:o(`modelViewer.allPlates`)}),(0,K.jsx)(`p`,{className:`${R?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:o(`modelViewer.plateCount`,{count:I.length})})]}),x==null&&(0,K.jsx)($o,{className:`${R?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]}),ce.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>S(e.index),className:`flex items-center rounded-lg border text-left transition-colors ${R?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${x===e.index?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[e.has_thumbnail&&e.thumbnail_url?(0,K.jsx)(`img`,{src:e.thumbnail_url,alt:`Plate ${e.index}`,className:`${R?`w-8 h-8`:`w-10 h-10`} rounded object-cover bg-bambu-dark-tertiary`}):(0,K.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${R?`w-8 h-8`:`w-10 h-10`}`,children:(0,K.jsx)(Nc,{className:`${R?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`${R?`text-xs`:`text-sm`} text-white font-medium truncate`,children:e.name||o(`modelViewer.plateNumber`,{number:e.index})}),(0,K.jsx)(`p`,{className:`${R?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:o(`modelViewer.objectCount`,{count:e.object_count??e.objects?.length??0})})]}),x===e.index&&(0,K.jsx)($o,{className:`${R?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]},e.index))]})}),(z||oe)&&(0,K.jsxs)(`div`,{className:`mt-auto pt-3 flex items-center gap-4 text-xs text-bambu-gray overflow-x-auto`,children:[z&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 whitespace-nowrap`,children:[(0,K.jsx)(`span`,{children:o(`modelViewer.plateNumber`,{number:z.index})}),z.print_time_seconds!=null&&(0,K.jsx)(`span`,{children:o(`modelViewer.eta`,{minutes:Math.round(z.print_time_seconds/60)})}),z.filament_used_grams!=null&&(0,K.jsxs)(`span`,{children:[z.filament_used_grams.toFixed(1),` g`]}),z.filaments.length>0&&(0,K.jsx)(`span`,{children:o(`modelViewer.filamentCount`,{count:z.filaments.length})})]}),oe&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 whitespace-nowrap ${z?`ml-auto`:``}`,children:[(0,K.jsx)(`span`,{children:o(`modelViewer.pagination.pageOf`,{current:C+1,total:se})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e=>Math.max(e-1,0)),disabled:C===0,className:`px-2 py-1 rounded border text-xs ${C===0?`border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:o(`modelViewer.pagination.prev`)}),(()=>{let e=Math.max(0,C-2),t=Math.min(se,e+5);t-e<5&&(e=Math.max(0,t-5));let n=Array.from({length:t-e},(t,n)=>e+n);return(0,K.jsxs)(K.Fragment,{children:[e>0&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(0),className:`px-2 py-1 rounded border text-xs ${C===0?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:`1`}),e>1&&(0,K.jsx)(`span`,{className:`px-1`,children:`…`}),n.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e),className:`px-2 py-1 rounded border text-xs ${C===e?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:e+1},e)),tw(se-1),className:`px-2 py-1 rounded border text-xs ${C===se-1?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:se})]})})(),(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e=>Math.min(e+1,se-1)),disabled:C>=se-1,className:`px-2 py-1 rounded border text-xs ${C>=se-1?`border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:o(`modelViewer.pagination.next`)})]})]})]})]})]}),R&&(0,K.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,onMouseDown:e=>{e.preventDefault(),A(!0),M(!0)},className:`h-2 cursor-row-resize flex items-center justify-center ${k?`bg-bambu-dark-tertiary`:`bg-bambu-dark-secondary/60 hover:bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`div`,{className:`w-12 h-1 rounded-full bg-bambu-gray/50`})}),(0,K.jsx)(`div`,{className:`flex-1 ${R?`min-h-0`:``}`,children:(0,K.jsx)(ny,{url:l?Q.getLibraryFileDownloadUrl(t):f.has_source?Q.getSource3mfDownloadUrl(e):Q.getArchiveDownload(e),fileType:r,buildVolume:f.build_volume,filamentColors:f.filament_colors,selectedPlateId:x,className:`w-full h-full`})})]}):u===`gcode`&&f?(0,K.jsx)(ET,{gcodeUrl:l?Q.getLibraryFileGcodeUrl(t):Q.getArchiveGcode(e),filamentColors:f.filament_colors,className:`w-full h-full`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:o(`modelViewer.noPreview`)})})]})})}var SBe=90;function CBe({onClose:e}){let{t}=G(),n=Qa(),{showToast:r}=xd(),[i,a]=(0,y.useState)(SBe),[o,s]=(0,y.useState)(!0),[c,l]=(0,y.useState)(i);(0,y.useEffect)(()=>{let e=window.setTimeout(()=>l(i),300);return()=>window.clearTimeout(e)},[i]);let u=q({queryKey:[`library-purge-preview`,c,o],queryFn:()=>Q.previewLibraryPurge(c,o),enabled:c>=1}),d=J({mutationFn:()=>Q.executeLibraryPurge(i,o),onSuccess:i=>{r(t(`libraryPurge.toast.success`,{count:i.moved_to_trash}),`success`),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]}),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),e()},onError:e=>r(e.message||t(`libraryPurge.toast.failed`),`error`)});(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!d.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,d.isPending]);let f=u.data,p=f?.count??0,m=f?.total_bytes??0,h=p>0&&!d.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)(hu,{className:`w-5 h-5`}),t(`libraryPurge.title`)]}),(0,K.jsx)(`button`,{onClick:e,className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-200`,"aria-label":t(`common.close`),disabled:d.isPending,children:(0,K.jsx)(Pu,{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:t(`libraryPurge.description`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`purge-days`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:t(`libraryPurge.ageLabel`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`input`,{id:`purge-days`,type:`number`,min:1,max:3650,value:i,onChange:e=>a(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:t(`libraryPurge.days`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`rounded border-gray-300`}),t(`libraryPurge.includeNeverPrinted`)]}),(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:t(`libraryPurge.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:t(`libraryPurge.effect1`)}),(0,K.jsx)(`li`,{children:t(`libraryPurge.effect2`)}),(0,K.jsx)(`li`,{children:t(`libraryPurge.effect3`)}),(0,K.jsx)(`li`,{children:t(`libraryPurge.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:u.isLoading||u.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`}),` `,t(`libraryPurge.previewLoading`)]}):u.isError?(0,K.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:u.error?.message??t(`libraryPurge.previewFailed`)}):(0,K.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:t(`libraryPurge.previewSummary`,{count:p,size:yd(m)})}),f?.sample_filenames&&f.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:[f.sample_filenames.map(e=>(0,K.jsx)(`li`,{className:`truncate`,children:e},e)),p>f.sample_filenames.length&&(0,K.jsx)(`li`,{className:`list-none italic text-gray-500`,children:t(`libraryPurge.andMore`,{count:p-f.sample_filenames.length})})]})]})}),(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)(vu,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,K.jsx)(`span`,{children:t(`libraryPurge.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:d.isPending,children:t(`common.cancel`)}),(0,K.jsx)($,{variant:`danger`,disabled:!h,onClick:()=>d.mutate(),children:d.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-1`}),t(`libraryPurge.purging`)]}):t(`libraryPurge.confirmCta`,{count:p})})]})]})})}function wBe({parentId:e,onClose:t,onSave:n,isLoading:r,t:i}){let[a,o]=(0,y.useState)(``);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 w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`fileManager.newFolder`)})}),(0,K.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),n({name:a.trim(),parent_id:e})},className:`p-4 space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:i(`fileManager.folderName`)}),(0,K.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:i(`fileManager.folderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!a.trim()||r,children:r?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):i(`common.create`)})]})]})]})})}function TBe({onClose:e,onSave:t,isLoading:n,t:r}){let[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(!0),[u,d]=(0,y.useState)(!1);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 w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(ac,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.linkExternalFolder`)]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`fileManager.linkExternalFolderDescription`)})]}),(0,K.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),t({name:i.trim(),external_path:o.trim(),readonly:c,show_hidden:u})},className:`p-4 space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.folderName`)}),(0,K.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:r(`fileManager.externalFolderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.externalPath`)}),(0,K.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green font-mono text-sm`,placeholder:`/mnt/nas/3d-prints`,required:!0}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`fileManager.externalPathHelp`)})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.readOnly`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,r(`fileManager.readOnlyHelp`),`)`]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>d(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.showHiddenFiles`)})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:e,children:r(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!i.trim()||!o.trim()||n,children:n?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):r(`fileManager.linkFolder`)})]})]})]})})}var EBe=`<>:"/\\|?*`;function DBe(e){for(let t of e)if(EBe.includes(t)||t.charCodeAt(0)<32)return t;return null}function OBe({type:e,currentName:t,onClose:n,onSave:r,isLoading:i,t:a}){let o=e===`file`?t.match(/(\.gcode\.3mf|\.3mf|\.gcode)$/i)?.[1]??``:``,s=e===`file`&&o?t.slice(0,-o.length):t,[c,l]=(0,y.useState)(s),u=e===`file`?DBe(c):null,d=u?a(`fileManager.invalidFilenameChar`,{char:u}):null;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 w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e===`file`?`fileManager.renameFile`:`fileManager.renameFolder`)})}),(0,K.jsxs)(`form`,{onSubmit:n=>{if(n.preventDefault(),d)return;let i=e===`file`?c.trim()+o:c.trim();c.trim()&&i!==t&&r(i)},className:`p-4 space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,K.jsxs)(`div`,{className:`flex items-center bg-bambu-dark border rounded focus-within:border-bambu-green ${d?`border-red-500`:`border-bambu-dark-tertiary`}`,children:[(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`flex-1 bg-transparent px-3 py-2 text-white placeholder-bambu-gray focus:outline-none min-w-0`,autoFocus:!0,required:!0}),o&&(0,K.jsx)(`span`,{className:`pr-3 text-bambu-gray text-sm select-none whitespace-nowrap`,children:o})]}),d&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-400`,children:d})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:n,children:a(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!c.trim()||c.trim()===s||!!d||i,children:i?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):a(`common.rename`)})]})]})]})})}function kBe({folders:e,selectedFiles:t,currentFolderId:n,onClose:r,onMove:i,isLoading:a,t:o}){let[s,c]=(0,y.useState)(null),l=(e,t=0)=>{let n=[];for(let r of e)n.push({id:r.id,name:r.name,depth:t}),r.children.length>0&&n.push(...l(r.children,t+1));return n},u=[{id:null,name:o(`fileManager.rootNoFolder`),depth:0},...l(e)];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 w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:o(`fileManager.moveFiles`,{count:t.length})})}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,K.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1`,children:u.map(e=>(0,K.jsxs)(`button`,{onClick:()=>c(e.id),disabled:e.id===n,className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:e.id===n?`opacity-50 cursor-not-allowed text-bambu-gray`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${12+e.depth*16}px`},children:[(0,K.jsx)(rc,{className:`w-4 h-4`}),e.name,e.id===n&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray ml-auto`,children:[`(`,o(`fileManager.current`),`)`]})]},e.id??`root`))}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:r,children:o(`common.cancel`)}),(0,K.jsx)($,{onClick:()=>i(s),disabled:a,children:a?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):o(`common.move`)})]})]})]})})}function ABe({folder:e,onClose:t,onLink:n,isLoading:r,t:i}){let[a,o]=(0,y.useState)(`project`),[s,c]=(0,y.useState)(e.project_id||e.archive_id||null);(0,y.useState)(()=>{e.archive_id&&o(`archive`)});let{data:l}=q({queryKey:[`projects`],queryFn:()=>Q.getProjects(),select:e=>[...e].sort((e,t)=>e.name.localeCompare(t.name))}),{data:u}=q({queryKey:[`archives-for-link`],queryFn:()=>Q.getArchives(void 0,void 0,100)}),d=()=>{n(a===`project`?{project_id:s,archive_id:0}:{project_id:0,archive_id:s})},f=()=>{n({project_id:0,archive_id:0})},p=e.project_id||e.archive_id;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 w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Ic,{className:`w-5 h-5 text-bambu-green`}),i(`fileManager.linkFolder`)]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,K.jsx)(Pu,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`fileManager.linkFolderDescription`,{name:e.name})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`button`,{onClick:()=>{o(`project`),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a===`project`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(Vo,{className:`w-4 h-4`}),i(`fileManager.project`)]}),(0,K.jsxs)(`button`,{onClick:()=>{o(`archive`),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a===`archive`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(wo,{className:`w-4 h-4`}),i(`fileManager.archive`)]})]}),(0,K.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2`,children:a===`project`?l&&l.length>0?l.map(e=>(0,K.jsxs)(`button`,{onClick:()=>c(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#00ae42`}}),(0,K.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id)):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noProjectsFound`)}):u&&u.length>0?u.map(e=>(0,K.jsxs)(`button`,{onClick:()=>c(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,K.jsx)(qs,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:e.print_name||e.filename})]},e.id)):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noArchivesFound`)})})]}),(0,K.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-between`,children:[p&&(0,K.jsxs)($,{variant:`danger`,onClick:f,disabled:r,children:[(0,K.jsx)(xu,{className:`w-4 h-4 mr-2`}),i(`fileManager.unlink`)]}),(0,K.jsxs)(`div`,{className:`flex gap-2 ${p?``:`ml-auto`}`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,K.jsx)($,{onClick:d,disabled:!s||r,children:r?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):i(`fileManager.link`)})]})]})]})})}function P7({folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o=0,wrapNames:s=!1,defaultExpanded:c=!0,hasPermission:l,t:u}){let[d,f]=(0,y.useState)(c),[p,m]=(0,y.useState)(!1),h=e.children.length>0,g=e.project_id||e.archive_id,_=e.is_external;return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`group flex items-center gap-1 px-2 py-1.5 rounded cursor-pointer transition-colors ${t===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${8+o*12}px`},onClick:()=>n(e.id),children:[h?(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),f(!d)},className:`p-0.5 hover:bg-bambu-dark-tertiary rounded`,children:(0,K.jsx)(ts,{className:`w-3.5 h-3.5 transition-transform ${d?`rotate-90`:``}`})}):(0,K.jsx)(`div`,{className:`w-4.5`}),_?(0,K.jsx)(ac,{className:`w-4 h-4 text-purple-400 flex-shrink-0`}):(0,K.jsx)(rc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm flex-1 min-w-0 ${s?`break-all`:`truncate`}`,title:e.name,children:e.name}),g&&(0,K.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400 hover:bg-blue-500/30 transition-colors`,title:`${e.project_name?`Project: ${e.project_name}`:`Archive: ${e.archive_name}`} (click to change)`,children:[(0,K.jsx)(Ic,{className:`w-3 h-3`}),e.project_name?(0,K.jsx)(Vo,{className:`w-3 h-3`}):(0,K.jsx)(wo,{className:`w-3 h-3`})]}),_&&e.external_readonly&&(0,K.jsx)(`span`,{title:u(`fileManager.readOnly`),children:(0,K.jsx)(Hc,{className:`w-3 h-3 text-amber-400 flex-shrink-0`})}),e.file_count>0&&(0,K.jsx)(`span`,{className:`flex-shrink-0 text-xs text-bambu-gray`,children:e.file_count}),!g&&!_&&(0,K.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary`,title:u(`fileManager.linkToProjectOrArchive`),children:(0,K.jsx)(Ic,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green`})}),(0,K.jsx)(`div`,{className:`flex-shrink-0 flex items-center gap-0.5 transition-opacity ${s?``:`opacity-0 group-hover:opacity-100`}`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{onClick:()=>m(!p),className:`p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(zs,{className:`w-3.5 h-3.5 text-bambu-gray`})}),p&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>m(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${l(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{l(`library:update_all`)&&(a(e),m(!1))},disabled:!l(`library:update_all`),title:l(`library:update_all`)?void 0:u(`fileManager.noPermissionRenameFolder`),children:[(0,K.jsx)(pl,{className:`w-3.5 h-3.5`}),u(`common.rename`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${l(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{l(`library:update_all`)&&(i(e),m(!1))},disabled:!l(`library:update_all`),title:l(`library:update_all`)?void 0:u(`fileManager.noPermissionLinkFolder`),children:[(0,K.jsx)(Ic,{className:`w-3.5 h-3.5`}),u(g?`fileManager.changeLink`:`fileManager.linkTo`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${l(`library:delete_all`)?`text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{l(`library:delete_all`)&&(r(e.id),m(!1))},disabled:!l(`library:delete_all`),title:l(`library:delete_all`)?void 0:u(`fileManager.noPermissionDeleteFolder`),children:[(0,K.jsx)(hu,{className:`w-3.5 h-3.5`}),u(`common.delete`)]})]})]})]})})]}),h&&d&&(0,K.jsx)(`div`,{children:e.children.map(e=>(0,K.jsx)(P7,{folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o+1,wrapNames:s,defaultExpanded:c,hasPermission:l,t:u},e.id))})]})}function F7(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)}function I7(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)?!1:t.endsWith(`.stl`)||t.endsWith(`.3mf`)||t.endsWith(`.step`)||t.endsWith(`.stp`)}function jBe({file:e,isSelected:t,isMobile:n,onSelect:r,onDelete:i,onDownload:a,onAddToQueue:o,onPrint:s,onSlice:c,useSlicerApi:l,onPreview3d:u,onRename:d,onGenerateThumbnail:f,thumbnailVersion:p,hasPermission:m,canModify:h,authEnabled:g,t:_}){let[v,b]=(0,y.useState)(!1);return(0,K.jsxs)(`div`,{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer overflow-hidden ${t?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,onClick:()=>r(e.id),children:[(0,K.jsxs)(`div`,{className:`aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden`,children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:`${Q.getLibraryFileThumbnailUrl(e.id)}${p?(Q.getLibraryFileThumbnailUrl(e.id).includes(`?`)?`&`:`?`)+`v=${p}`:``}`,alt:e.filename,className:`w-full h-full object-cover`}):(0,K.jsx)(qs,{className:`w-12 h-12 text-bambu-gray/30`}),(0,K.jsx)(`div`,{className:`absolute top-2 right-2 text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/90 text-white`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-500/90 text-white`:e.file_type===`stl`?`bg-purple-500/90 text-white`:`bg-bambu-gray/90 text-white`}`,children:e.file_type.toUpperCase()})]}),(0,K.jsxs)(`div`,{className:`p-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mt-1 text-xs text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:yd(e.file_size)}),e.print_time_seconds&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),yf(e.print_time_seconds)]})]}),e.sliced_for_model&&(0,K.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,K.jsx)(bl,{className:`w-3 h-3`}),e.sliced_for_model]}),e.print_count>0&&(0,K.jsx)(`div`,{className:`mt-1 text-xs text-bambu-green`,children:_(`fileManager.printedCount`,{count:e.print_count})}),g&&e.created_by_username&&(0,K.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,K.jsx)(Cu,{className:`w-3 h-3`}),e.created_by_username]})]}),(0,K.jsxs)(`div`,{className:`absolute bottom-2 right-2 transition-opacity ${n?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`button`,{onClick:()=>b(!v),className:`p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(zs,{className:`w-4 h-4 text-bambu-gray`})}),v&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>b(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 bottom-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[140px]`,children:[s&&F7(e.filename)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${m(`printers:control`)?`text-bambu-green hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{m(`printers:control`)&&(s(e),b(!1))},disabled:!m(`printers:control`),title:m(`printers:control`)?void 0:_(`fileManager.noPermissionPrint`),children:[(0,K.jsx)(bl,{className:`w-3.5 h-3.5`}),_(`common.print`)]}),o&&F7(e.filename)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${m(`queue:create`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{m(`queue:create`)&&(o(e.id),b(!1))},disabled:!m(`queue:create`),title:m(`queue:create`)?void 0:_(`fileManager.noPermissionAddToQueue`),children:[(0,K.jsx)(_s,{className:`w-3.5 h-3.5`}),_(`fileManager.schedulePrint`)]}),c&&l&&I7(e.filename)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${m(`library:upload`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{m(`library:upload`)&&(c(e),b(!1))},disabled:!m(`library:upload`),title:m(`library:upload`)?void 0:_(`fileManager.noPermissionSlice`),children:[(0,K.jsx)(ws,{className:`w-3.5 h-3.5`}),_(`slice.action`)]}),u&&(e.file_type===`3mf`||e.file_type===`gcode`||e.file_type===`stl`||e.file_type===`gcode.3mf`)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${m(`library:read`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{m(`library:read`)&&(u(e),b(!1))},disabled:!m(`library:read`),title:m(`library:read`)?void 0:`You do not have permission to preview files`,children:[(0,K.jsx)(Bo,{className:`w-3.5 h-3.5`}),`3D Preview`]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${m(`library:read`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{m(`library:read`)&&(a(e.id),b(!1))},disabled:!m(`library:read`),title:m(`library:read`)?void 0:_(`fileManager.noPermissionDownload`),children:[(0,K.jsx)(Is,{className:`w-3.5 h-3.5`}),_(`common.download`)]}),d&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${h(`library`,`update`,e.created_by_id)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{h(`library`,`update`,e.created_by_id)&&(d(e),b(!1))},disabled:!h(`library`,`update`,e.created_by_id),title:h(`library`,`update`,e.created_by_id)?void 0:_(`fileManager.noPermissionRenameFile`),children:[(0,K.jsx)(pl,{className:`w-3.5 h-3.5`}),_(`common.rename`)]}),f&&e.file_type===`stl`&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${h(`library`,`update`,e.created_by_id)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{h(`library`,`update`,e.created_by_id)&&(f(e),b(!1))},disabled:!h(`library`,`update`,e.created_by_id),title:h(`library`,`update`,e.created_by_id)?void 0:_(`fileManager.noPermissionGenerateThumbnail`),children:[(0,K.jsx)(Dc,{className:`w-3.5 h-3.5`}),_(`fileManager.generateThumbnail`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${h(`library`,`delete`,e.created_by_id)?`text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{h(`library`,`delete`,e.created_by_id)&&(i(e.id),b(!1))},disabled:!h(`library`,`delete`,e.created_by_id),title:h(`library`,`delete`,e.created_by_id)?void 0:_(`fileManager.noPermissionDeleteFile`),children:[(0,K.jsx)(hu,{className:`w-3.5 h-3.5`}),_(`common.delete`)]})]})]})]}),(0,K.jsx)(`div`,{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${t?`bg-bambu-green border-bambu-green`:`border-white/30 bg-black/30 ${n?`opacity-100`:`opacity-0 group-hover:opacity-100`}`}`,children:t&&(0,K.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})})]})}function MBe(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),{hasPermission:r,hasAnyPermission:i,canModify:a,authEnabled:o}=sd(),[s]=Oi(),c=Yn(),l=s.get(`folder`),[u,d]=(0,y.useState)(l?parseInt(l,10):null),[f,p]=(0,y.useState)(`internal`),[m,h]=(0,y.useState)([]),[g,_]=(0,y.useState)(!1),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(!1),[D,O]=(0,y.useState)(null),[k,A]=(0,y.useState)(null),[j,M]=(0,y.useState)(null),[N,P]=(0,y.useState)(null),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(null),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)({}),[H,te]=(0,y.useState)(null),[ne,re]=(0,y.useState)(()=>localStorage.getItem(`library-view-mode`)||`grid`),[U,ie]=(0,y.useState)(()=>localStorage.getItem(`library-wrap-folders`)===`true`),[ae,W]=(0,y.useState)(()=>localStorage.getItem(`library-collapse-folders`)===`true`),[oe,se]=(0,y.useState)(()=>{let e=localStorage.getItem(`library-sidebar-width`);return e?parseInt(e,10):256}),[ce,le]=(0,y.useState)(!1),ue=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!ce)return;document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let e=e=>{if(!ue.current)return;let t=ue.current.parentElement?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left;se(Math.min(500,Math.max(200,n)))},t=()=>{le(!1),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`library-sidebar-width`,String(oe))};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.userSelect=``,document.body.style.cursor=``}},[ce,oe]);let[de,fe]=(0,y.useState)(``),[pe,me]=(0,y.useState)(`all`),[he,ge]=(0,y.useState)(``),[_e,ve]=(0,y.useState)(()=>localStorage.getItem(`library-sort-field`)||`name`),[ye,be]=(0,y.useState)(()=>localStorage.getItem(`library-sort-direction`)||`asc`),xe=Gq();(0,y.useEffect)(()=>{let e=s.get(`folder`);e&&d(parseInt(e,10))},[s]);let{data:Se}=q({queryKey:[`settings`],queryFn:()=>Q.getSettings()}),{data:Ce,isLoading:we}=q({queryKey:[`library-folders`],queryFn:()=>Q.getLibraryFolders()}),{data:Te}=q({queryKey:[`library-trash-count`],queryFn:async()=>{try{return(await Q.listLibraryTrash(1,0)).total}catch{return 0}},staleTime:3e4}),{data:Ee,isLoading:De}=q({queryKey:[`library-files`,u,f],queryFn:()=>Q.getLibraryFiles(u,!1,void 0,u===null?f:void 0)}),{data:Oe}=q({queryKey:[`library-stats`],queryFn:()=>Q.getLibraryStats()}),{data:ke}=q({queryKey:[`users`],queryFn:()=>Q.getUsers()}),Ae=(0,y.useMemo)(()=>{if(!Ee)return[];let e=new Set(Ee.map(e=>e.file_type));return Array.from(e).sort()},[Ee]),je=(0,y.useMemo)(()=>{if(!Ee)return[];let e=[...Ee];if(de.trim()){let t=de.toLowerCase();e=e.filter(e=>e.filename.toLowerCase().includes(t)||e.print_name&&e.print_name.toLowerCase().includes(t))}if(pe!==`all`&&(e=e.filter(e=>e.file_type===pe)),he.trim()){let t=he.toLowerCase();e=e.filter(e=>e.created_by_username&&e.created_by_username.toLowerCase().includes(t))}return e.sort((e,t)=>{let n=0;switch(_e){case`name`:n=(e.print_name||e.filename).localeCompare(t.print_name||t.filename);break;case`date`:n=(mf(e.created_at)?.getTime()??0)-(mf(t.created_at)?.getTime()??0);break;case`size`:n=e.file_size-t.file_size;break;case`type`:n=e.file_type.localeCompare(t.file_type);break;case`prints`:n=e.print_count-t.print_count;break}return ye===`asc`?n:-n}),e},[Ee,de,pe,he,_e,ye]),Me=(0,y.useMemo)(()=>{if(!Oe||!Se)return!1;let e=(Se.library_disk_warning_gb||5)*1024*1024*1024;return Oe.disk_free_bytesQ.createLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),_(!1),n(e(`fileManager.toast.folderCreated`),`success`)},onError:e=>n(e.message,`error`)}),Pe=J({mutationFn:async e=>{let t=await Q.createExternalFolder(e);return await Q.scanExternalFolder(t.id),t},onSuccess:r=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),b(!1),d(r.id),n(e(`fileManager.toast.externalFolderLinked`),`success`)},onError:e=>n(e.message,`error`)}),Fe=J({mutationFn:e=>Q.scanExternalFolder(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),n(e(`fileManager.toast.folderScanned`,{added:r.added,removed:r.removed}),`success`)},onError:e=>n(e.message,`error`)}),Ie=J({mutationFn:e=>Q.deleteLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),u===k?.id&&d(null),A(null),n(e(`fileManager.toast.folderDeleted`),`success`)},onError:e=>{A(null),n(e.message,`error`)}}),Le=J({mutationFn:e=>Q.deleteLibraryFile(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),h(e=>e.filter(e=>e!==k?.id)),A(null),n(e(`fileManager.toast.fileDeleted`),`success`)},onError:e=>{A(null),n(e.message,`error`)}}),Re=J({mutationFn:e=>Q.bulkDeleteLibrary(e,[]),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),n(e(`fileManager.toast.filesDeleted`,{count:i.length}),`success`),h([]),A(null)},onError:e=>{A(null),n(e.message,`error`)}}),ze=J({mutationFn:({fileIds:e,folderId:t})=>Q.moveLibraryFiles(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),h([]),S(!1),n(e(`fileManager.toast.filesMoved`),`success`)},onError:e=>n(e.message,`error`)}),Be=J({mutationFn:({id:e,data:t})=>Q.updateLibraryFolder(e,t),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`project-folders`]}),t.invalidateQueries({queryKey:[`archive-folders`]}),O(null),n(i.data.project_id===0&&i.data.archive_id===0?e(`fileManager.toast.folderUnlinked`):e(`fileManager.toast.folderLinked`),`success`)},onError:e=>n(e.message,`error`)}),Ve=J({mutationFn:({id:e,filename:t})=>Q.updateLibraryFile(e,{filename:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),B(null),n(e(`fileManager.toast.fileRenamed`),`success`)},onError:e=>{B(null),n(e.message,`error`)}}),He=J({mutationFn:({id:e,name:t})=>Q.updateLibraryFolder(e,{name:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),B(null),n(e(`fileManager.toast.folderRenamed`),`success`)},onError:e=>{B(null),n(e.message,`error`)}}),Ue=J({mutationFn:()=>Q.batchGenerateStlThumbnails({all_missing:!0}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let e=Date.now(),t={};r.results.forEach(n=>{n.success&&(t[n.file_id]=e)}),ee(e=>({...e,...t}))}r.succeeded>0&&r.failed===0?n(e(`fileManager.toast.thumbnailsGenerated`,{count:r.succeeded}),`success`):r.succeeded>0&&r.failed>0?n(e(`fileManager.toast.thumbnailsGeneratedPartial`,{succeeded:r.succeeded,failed:r.failed}),`success`):r.processed===0?n(e(`fileManager.toast.noStlMissingThumbnails`),`info`):n(e(`fileManager.toast.failedToGenerateThumbnails`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),We=J({mutationFn:e=>Q.batchGenerateStlThumbnails({file_ids:[e]}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let t=r.results[0]?.file_id;t&&ee(e=>({...e,[t]:Date.now()})),n(e(`fileManager.toast.thumbnailGenerated`),`success`)}else n(e(`fileManager.toast.failedToGenerateThumbnail`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),Ge=(0,y.useCallback)(e=>{let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.includes(`.gcode.`)},[]),Ke=(0,y.useMemo)(()=>Ee?Ee.filter(e=>m.includes(e.id)&&Ge(e.filename)):[],[Ee,m,Ge]),qe=(0,y.useCallback)(e=>{h(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),Je=(0,y.useCallback)(()=>{je.length>0&&h(je.map(e=>e.id))},[je]),Ye=(0,y.useCallback)(()=>{h([])},[]),Xe=()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]})},Ze=e=>{Q.downloadLibraryFile(e).catch(e=>{console.error(`Library file download failed:`,e)})},Qe=()=>{k&&(k.type===`file`?Le.mutate(k.id):k.type===`folder`?Ie.mutate(k.id):k.type===`bulk`&&Re.mutate(m))},$e=Ie.isPending||Le.isPending||Re.isPending,et=e=>{re(e),localStorage.setItem(`library-view-mode`,e)},tt=we||De,nt=(0,y.useMemo)(()=>{if(!u||!Ce)return null;let e=t=>{for(let n of t){if(n.id===u)return n;let t=e(n.children);if(t)return t}return null};return e(Ce)},[u,Ce]);return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-[calc(100vh-64px)] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4 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)(rc,{className:`w-7 h-7 text-bambu-green`}),e(`fileManager.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`fileManager.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center bg-bambu-dark rounded-lg p-1`,children:[(0,K.jsx)(`button`,{onClick:()=>et(`grid`),className:`p-1.5 rounded transition-colors ${ne===`grid`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.gridView`),children:(0,K.jsx)(Pc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>et(`list`),className:`p-1.5 rounded transition-colors ${ne===`list`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.listView`),children:(0,K.jsx)(Bc,{className:`w-4 h-4`})})]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>Ue.mutate(),disabled:Ue.isPending||!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.generateThumbnailsForMissing`):e(`fileManager.noPermissionGenerateThumbnail`),children:[Ue.isPending?(0,K.jsx)(X,{className:`w-4 h-4 mr-2 animate-spin`}):(0,K.jsx)(Dc,{className:`w-4 h-4 mr-2`}),e(`fileManager.generateThumbnails`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>b(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?e(`fileManager.linkExternalFolder`):e(`fileManager.noPermissionCreateFolder`),children:[(0,K.jsx)(ac,{className:`w-4 h-4 mr-2`}),e(`fileManager.linkExternal`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>_(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionCreateFolder`),children:[(0,K.jsx)(ic,{className:`w-4 h-4 mr-2`}),e(`fileManager.newFolder`)]}),r(`library:purge`)&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>E(!0),title:e(`libraryPurge.headerTooltip`),children:[(0,K.jsx)(hu,{className:`w-4 h-4 mr-2`}),e(`libraryPurge.headerButton`)]}),i(`library:delete_own`,`library:delete_all`)&&(0,K.jsxs)(bi,{to:`/files/trash`,className:`inline-flex items-center px-3 py-1.5 text-sm rounded bg-bambu-dark-secondary text-bambu-gray hover:text-white hover:bg-bambu-dark transition-colors`,title:e(`libraryTrash.headerTooltip`),children:[(0,K.jsx)(hu,{className:`w-4 h-4 mr-2`}),e(`libraryTrash.headerButton`),typeof Te==`number`&&Te>0&&(0,K.jsx)(`span`,{className:`ml-1.5 px-1.5 py-0.5 text-xs rounded-full bg-bambu-green/20 text-bambu-green`,children:Te})]}),(0,K.jsxs)($,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,K.jsx)(Su,{className:`w-4 h-4 mr-2`}),e(`common.upload`)]})]})]}),Me&&Oe&&Se&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg`,children:[(0,K.jsx)(vu,{className:`w-5 h-5 text-amber-500 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-amber-500 font-medium`,children:e(`fileManager.lowDiskSpaceWarning`)}),(0,K.jsx)(`p`,{className:`text-xs text-amber-500/80`,children:e(`fileManager.lowDiskSpaceDetails`,{free:yd(Oe.disk_free_bytes),total:yd(Oe.disk_total_bytes),threshold:Se.library_disk_warning_gb})})]})]}),Oe&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 sm:gap-6 mb-6 p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(Qs,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.files`),`:`]}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:Oe.total_files})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(rc,{className:`w-4 h-4 text-blue-400`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.folders`),`:`]}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:Oe.total_folders})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(yc,{className:`w-4 h-4 text-amber-400`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.size`),`:`]}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:yd(Oe.total_size_bytes)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm sm:ml-auto`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.free`),`:`]}),(0,K.jsx)(`span`,{className:`font-medium ${Me?`text-amber-500`:`text-white`}`,children:yd(Oe.disk_free_bytes)})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0`,children:[(0,K.jsx)(`div`,{className:`lg:hidden`,children:(0,K.jsxs)(`select`,{value:u===null?`__top:${f}`:String(u),onChange:e=>{let t=e.target.value;t.startsWith(`__top:`)?(d(null),p(t.slice(6))):d(parseInt(t,10))},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg px-3 py-2.5 text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsxs)(`option`,{value:`__top:internal`,children:[`📁 `,e(`fileManager.allFiles`)]}),Ce?.some(e=>e.is_external)&&(0,K.jsxs)(`option`,{value:`__top:external`,children:[`🔗 `,e(`fileManager.allExternal`)]}),Ce&&(()=>{let e=(t,n=0)=>{let r=[];for(let i of t)r.push({id:i.id,name:i.name,fileCount:i.file_count,depth:n}),i.children.length>0&&r.push(...e(i.children,n+1));return r};return e(Ce).map(e=>(0,K.jsxs)(`option`,{value:e.id,children:[`│ `.repeat(e.depth),`📂 `,e.name,` `,e.fileCount>0?`(${e.fileCount})`:``]},e.id))})()]})}),(0,K.jsxs)(`div`,{ref:ue,className:`hidden lg:flex flex-shrink-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden flex-col relative`,style:{width:`${oe}px`},children:[(0,K.jsx)(`div`,{className:`absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group/resize flex items-center justify-center transition-colors ${ce?`bg-bambu-green`:`hover:bg-bambu-green/50`}`,onMouseDown:e=>{e.preventDefault(),le(!0)},onDoubleClick:()=>{se(256),localStorage.setItem(`library-sidebar-width`,`256`)},title:e(`fileManager.dragToResizeTooltip`),children:(0,K.jsxs)(`div`,{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${ce?`opacity-100`:``}`,children:[(0,K.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,K.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,K.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`})]})}),(0,K.jsxs)(`div`,{className:`p-3 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,K.jsx)(`h2`,{className:`text-sm font-medium text-white`,children:e(`fileManager.folders`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>{let e=!ae;W(e),localStorage.setItem(`library-collapse-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${ae?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(ae?`fileManager.expandFoldersByDefault`:`fileManager.collapseFoldersByDefault`),children:e(`fileManager.collapse`)}),(0,K.jsx)(`button`,{onClick:()=>{let e=!U;ie(e),localStorage.setItem(`library-wrap-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${U?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(U?`fileManager.disableTextWrapping`:`fileManager.enableTextWrapping`),children:e(`fileManager.wrap`)})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&f===`internal`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),p(`internal`)},children:[(0,K.jsx)(qs,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allFiles`)})]}),Ce?.some(e=>e.is_external)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&f===`external`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),p(`external`)},children:[(0,K.jsx)(ac,{className:`w-4 h-4 text-purple-400`}),(0,K.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allExternal`)})]}),Ce?.map(t=>(0,K.jsx)(P7,{folder:t,selectedFolderId:u,onSelect:d,onDelete:e=>A({type:`folder`,id:e}),onLink:O,onRename:e=>B({type:`folder`,id:e.id,name:e.name}),wrapNames:U,defaultExpanded:!ae,hasPermission:r,t:e},`${t.id}-${ae?`c`:`e`}`))]})]}),(0,K.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:[nt?.is_external&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg`,children:[(0,K.jsx)(ac,{className:`w-5 h-5 text-purple-400 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium text-purple-300`,children:e(`fileManager.externalFolder`)}),nt.external_readonly&&(0,K.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400 flex items-center gap-1`,children:[(0,K.jsx)(Hc,{className:`w-3 h-3`}),e(`fileManager.readOnly`)]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate font-mono`,title:nt.external_path||``,children:nt.external_path})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>u&&Fe.mutate(u),disabled:Fe.isPending,title:e(`fileManager.scanFolder`),children:[Fe.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`fileManager.scanFolder`)})]})]}),Ee&&Ee.length>0&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-4 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-0 z-10 lg:static`,children:[(0,K.jsxs)(`div`,{className:`relative w-full sm:w-auto sm:flex-1 sm:max-w-xs`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.searchFiles`),value:de,onChange:e=>fe(e.target.value),className:`w-full pl-9 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(lc,{className:`w-4 h-4 text-bambu-gray hidden sm:block`}),(0,K.jsxs)(`select`,{value:pe,onChange:e=>me(e.target.value),className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsx)(`option`,{value:`all`,children:e(`fileManager.allTypes`)}),Ae.map(e=>(0,K.jsx)(`option`,{value:e,children:e.toUpperCase()},e))]})]}),o&&(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.filterByUser`,{defaultValue:`Filter by user`}),value:he,onChange:e=>ge(e.target.value),list:`usernames-list`,className:`w-32 sm:w-40 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green ${he?`pr-7`:``}`,style:he?{WebkitAppearance:`none`,MozAppearance:`textfield`}:void 0}),he&&(0,K.jsx)(`button`,{onClick:()=>ge(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10`,children:(0,K.jsx)(Pu,{className:`w-3 h-3`})}),(0,K.jsx)(`datalist`,{id:`usernames-list`,children:ke?.map(e=>(0,K.jsx)(`option`,{value:e.username},e.id))})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`select`,{value:_e,onChange:e=>{let t=e.target.value;ve(t),localStorage.setItem(`library-sort-field`,t)},className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsx)(`option`,{value:`name`,children:e(`common.name`)}),(0,K.jsx)(`option`,{value:`date`,children:e(`common.date`)}),(0,K.jsx)(`option`,{value:`size`,children:e(`fileManager.size`)}),(0,K.jsx)(`option`,{value:`type`,children:e(`common.type`)}),(0,K.jsx)(`option`,{value:`prints`,children:e(`fileManager.prints`)})]}),(0,K.jsx)(`button`,{onClick:()=>be(e=>{let t=e===`asc`?`desc`:`asc`;return localStorage.setItem(`library-sort-direction`,t),t}),className:`p-1.5 rounded bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,title:e(ye===`asc`?`fileManager.ascending`:`fileManager.descending`),children:ye===`asc`?(0,K.jsx)(jo,{className:`w-4 h-4 text-white`}):(0,K.jsx)(To,{className:`w-4 h-4 text-white`})})]}),(de||pe!==`all`||he)&&(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray hidden sm:inline`,children:e(`fileManager.resultsCount`,{showing:je.length,total:Ee.length})})]}),je.length>0&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 p-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-[52px] z-10 lg:static`,children:[m.length===je.length&&m.length>0?(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:Ye,children:[(0,K.jsx)(tu,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.deselectAll`)})]}):(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:Je,children:[(0,K.jsx)($l,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.selectAll`)})]}),m.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:e(`fileManager.selected`,{count:m.length})}),(0,K.jsx)(`div`,{className:`hidden sm:block flex-1`}),(0,K.jsxs)(`div`,{className:`w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0`,children:[Ke.length===1&&(0,K.jsxs)($,{variant:`primary`,size:`sm`,onClick:()=>P(Ke[0]),disabled:!r(`printers:control`),title:r(`printers:control`)?void 0:e(`fileManager.noPermissionPrint`),children:[(0,K.jsx)(hl,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.print`)})]}),Ke.length===1&&(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>I(Ke[0]),disabled:!r(`queue:create`),title:r(`queue:create`)?void 0:e(`fileManager.noPermissionAddToQueue`),children:[(0,K.jsx)(_s,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.schedulePrint`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>S(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?void 0:e(`fileManager.noPermissionMoveFiles`),children:[(0,K.jsx)(rl,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.move`)})]}),(0,K.jsxs)($,{variant:`danger`,size:`sm`,onClick:()=>{m.length===1?A({type:`file`,id:m[0]}):A({type:`bulk`,id:0,count:m.length})},disabled:!i(`library:delete_own`,`library:delete_all`),title:i(`library:delete_own`,`library:delete_all`)?void 0:e(`fileManager.noPermissionDeleteFiles`),children:[(0,K.jsx)(hu,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.delete`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:Ye,children:[(0,K.jsx)(Pu,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.clear`)})]})]})]})]}),tt?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`fileManager.loadingFiles`)})]})}):Ee?.length===0?(0,K.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,K.jsx)(qs,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,K.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(u===null?f===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`:`fileManager.folderIsEmpty`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(u===null?f===`external`?`fileManager.externalEmptyDescription`:`fileManager.noFilesDescription`:`fileManager.folderEmptyDescription`)}),(0,K.jsxs)($,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,K.jsx)(_l,{className:`w-4 h-4 mr-2`}),e(`fileManager.uploadFiles`)]})]}):je.length===0?(0,K.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,K.jsx)(Nl,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,K.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(`fileManager.noMatchingFiles`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(`fileManager.noMatchingFilesDescription`)}),(0,K.jsx)($,{variant:`secondary`,onClick:()=>{fe(``),me(`all`)},children:e(`fileManager.clearFilters`)})]}):ne===`grid`?(0,K.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,K.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4`,children:je.map(t=>(0,K.jsx)(jBe,{file:t,isSelected:m.includes(t.id),isMobile:xe,t:e,onSelect:qe,onDelete:e=>A({type:`file`,id:e}),onDownload:Ze,onAddToQueue:e=>{let t=Ee?.find(t=>t.id===e);t&&I(t)},onPrint:M,onSlice:R,useSlicerApi:Se?.use_slicer_api??!1,onPreview3d:e=>{F7(e.filename)?c(`/gcode-viewer?library_file=${e.id}`):te(e)},onRename:e=>B({type:`file`,id:e.id,name:e.filename}),onGenerateThumbnail:e=>We.mutate(e.id),thumbnailVersion:V[t.id],hasPermission:r,canModify:a,authEnabled:o},t.id))})}):(0,K.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto`,children:[(0,K.jsxs)(`div`,{className:`hidden sm:grid ${o?`grid-cols-[auto_1fr_120px_100px_100px_100px_min-content]`:`grid-cols-[auto_1fr_100px_100px_100px_min-content]`} gap-4 px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary text-xs text-bambu-gray font-medium`,children:[(0,K.jsx)(`div`,{className:`w-6`}),(0,K.jsx)(`div`,{children:e(`common.name`)}),o&&(0,K.jsx)(`div`,{children:e(`fileManager.uploadedBy`,{defaultValue:`Uploaded By`})}),(0,K.jsx)(`div`,{children:e(`common.type`)}),(0,K.jsx)(`div`,{children:e(`fileManager.size`)}),(0,K.jsx)(`div`,{children:e(`fileManager.prints`)}),(0,K.jsx)(`div`,{})]}),je.map(t=>(0,K.jsxs)(`div`,{className:`grid ${o?`grid-cols-[auto_1fr_120px_100px_100px_100px_min-content]`:`grid-cols-[auto_1fr_100px_100px_100px_min-content]`} gap-4 px-4 py-3 items-center border-b border-bambu-dark-tertiary last:border-b-0 cursor-pointer hover:bg-bambu-dark/50 transition-colors ${m.includes(t.id)?`bg-bambu-green/10`:``}`,onClick:()=>qe(t.id),children:[(0,K.jsx)(`div`,{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${m.includes(t.id)?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:m.includes(t.id)&&(0,K.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`relative group/thumb`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden`,children:t.thumbnail_path?(0,K.jsx)(`img`,{src:`${Q.getLibraryFileThumbnailUrl(t.id)}${V[t.id]?(Q.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${V[t.id]}`:``}`,alt:``,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,K.jsx)(qs,{className:`w-5 h-5 text-bambu-gray/50`})})}),t.thumbnail_path&&(0,K.jsx)(`div`,{className:`absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block`,children:(0,K.jsx)(`div`,{className:`w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden`,children:(0,K.jsx)(`img`,{src:`${Q.getLibraryFileThumbnailUrl(t.id)}${V[t.id]?(Q.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${V[t.id]}`:``}`,alt:t.filename,className:`w-full h-full object-contain`})})})]}),(0,K.jsx)(`div`,{className:`min-w-0`,children:(0,K.jsx)(`div`,{className:`text-sm text-white truncate`,children:t.print_name||t.filename})})]}),o&&(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-1`,children:t.created_by_username?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Cu,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{className:`truncate`,children:t.created_by_username})]}):`-`}),(0,K.jsx)(`div`,{children:(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${t.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:t.file_type===`gcode`||t.file_type===`gcode.3mf`?`bg-blue-500/20 text-blue-400`:t.file_type===`stl`?`bg-purple-500/20 text-purple-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.file_type.toUpperCase()})}),(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:yd(t.file_size)}),(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:t.print_count>0?`${t.print_count}x`:`-`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[F7(t.filename)&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:()=>r(`printers:control`)&&M(t),className:`p-1.5 rounded transition-colors ${r(`printers:control`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`printers:control`)?e(`common.print`):e(`fileManager.noPermissionPrint`),disabled:!r(`printers:control`),children:(0,K.jsx)(bl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{r(`queue:create`)&&I(t)},className:`p-1.5 rounded transition-colors ${r(`queue:create`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`queue:create`)?e(`fileManager.schedulePrint`):e(`fileManager.noPermissionAddToQueue`),disabled:!r(`queue:create`),children:(0,K.jsx)(_s,{className:`w-4 h-4`})})]}),(Se?.use_slicer_api??!1)&&I7(t.filename)&&(0,K.jsx)(`button`,{onClick:()=>r(`library:upload`)&&R(t),className:`p-1.5 rounded transition-colors ${r(`library:upload`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:upload`)?e(`slice.action`):e(`fileManager.noPermissionSlice`),disabled:!r(`library:upload`),children:(0,K.jsx)(ws,{className:`w-4 h-4`})}),(t.file_type===`3mf`||t.file_type===`gcode`||t.file_type===`gcode.3mf`||t.file_type===`stl`)&&(0,K.jsx)(`button`,{onClick:()=>{r(`library:read`)&&(F7(t.filename)?c(`/gcode-viewer?library_file=${t.id}`):te(t))},className:`p-1.5 rounded transition-colors ${r(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:read`)?`3D Preview`:`You do not have permission to preview files`,disabled:!r(`library:read`),children:(0,K.jsx)(Bo,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>r(`library:read`)&&Ze(t.id),className:`p-1.5 rounded transition-colors ${r(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:read`)?e(`common.download`):e(`fileManager.noPermissionDownload`),disabled:!r(`library:read`),children:(0,K.jsx)(Is,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&B({type:`file`,id:t.id,name:t.filename}),className:`p-1.5 rounded transition-colors ${a(`library`,`update`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`update`,t.created_by_id)?e(`common.rename`):e(`fileManager.noPermissionRenameFile`),disabled:!a(`library`,`update`,t.created_by_id),children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),t.file_type===`stl`&&(0,K.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&We.mutate(t.id),className:`p-1.5 rounded transition-colors ${a(`library`,`update`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`update`,t.created_by_id)?e(`fileManager.generateThumbnail`):e(`fileManager.noPermissionGenerateThumbnail`),disabled:We.isPending||!a(`library`,`update`,t.created_by_id),children:(0,K.jsx)(Dc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(`library`,`delete`,t.created_by_id)&&A({type:`file`,id:t.id}),className:`p-1.5 rounded transition-colors ${a(`library`,`delete`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`delete`,t.created_by_id)?e(`common.delete`):e(`fileManager.noPermissionDeleteFile`),disabled:!a(`library`,`delete`,t.created_by_id),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]},t.id))]})})]})]}),g&&(0,K.jsx)(wBe,{parentId:u,onClose:()=>_(!1),onSave:e=>Ne.mutate(e),isLoading:Ne.isPending,t:e}),v&&(0,K.jsx)(TBe,{onClose:()=>b(!1),onSave:e=>Pe.mutate(e),isLoading:Pe.isPending,t:e}),x&&Ce&&(0,K.jsx)(kBe,{folders:Ce,selectedFiles:m,currentFolderId:u,onClose:()=>S(!1),onMove:e=>ze.mutate({fileIds:m,folderId:e}),isLoading:ze.isPending,t:e}),C&&(0,K.jsx)(kK,{folderId:u,onClose:()=>w(!1),onUploadComplete:Xe}),T&&(0,K.jsx)(CBe,{onClose:()=>E(!1)}),D&&(0,K.jsx)(ABe,{folder:D,onClose:()=>O(null),onLink:e=>Be.mutate({id:D.id,data:e}),isLoading:Be.isPending,t:e}),k&&(0,K.jsx)(Ed,{title:k.type===`folder`?e(`fileManager.deleteFolder`):k.type===`bulk`?e(`fileManager.deleteFilesCount`,{count:k.count}):e(`fileManager.deleteFile`),message:k.type===`folder`?e(`fileManager.deleteFolderConfirm`):k.type===`bulk`?e(`fileManager.deleteFilesConfirm`,{count:k.count}):e(`fileManager.deleteFileConfirm`),confirmText:e(`common.delete`),variant:`danger`,isLoading:$e,loadingText:e(`fileManager.deleting`),onConfirm:Qe,onCancel:()=>A(null)}),j&&(0,K.jsx)(sq,{mode:`reprint`,libraryFileId:j.id,archiveName:j.print_name||j.filename,onClose:()=>M(null),onSuccess:()=>{M(null),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`archives`]})}}),N&&(0,K.jsx)(sq,{mode:`reprint`,libraryFileId:N.id,archiveName:N.print_name||N.filename,onClose:()=>P(null),onSuccess:()=>{P(null),h([]),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`archives`]})}}),F&&(0,K.jsx)(sq,{mode:`add-to-queue`,libraryFileId:F.id,archiveName:F.print_name||F.filename,onClose:()=>I(null),onSuccess:()=>{I(null),h([]),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`archives`]})}}),L&&(0,K.jsx)(Bq,{source:{kind:`libraryFile`,id:L.id,filename:L.filename},onClose:()=>R(null)}),H&&(0,K.jsx)(xBe,{libraryFileId:H.id,title:H.print_name||H.filename,fileType:H.file_type,onClose:()=>te(null),onSliceWithBambuddy:I7(H.filename)&&r(`library:upload`)?()=>{let e=H;te(null),R(e)}:void 0}),z&&(0,K.jsx)(OBe,{type:z.type,currentName:z.name,onClose:()=>B(null),onSave:e=>{z.type===`file`?Ve.mutate({id:z.id,filename:e}):He.mutate({id:z.id,name:e})},isLoading:Ve.isPending||He.isPending,t:e})]})}function NBe(e){let t=mf(e);if(!t)return``;let n=Math.ceil((t.getTime()-Date.now())/(1e3*60*60*24));return n<=0?`any moment`:n===1?`1 day`:`${n} days`}function L7(e){let t=mf(e);return t?t.toLocaleString():e}function PBe(){let{t:e}=G(),t=Yn(),n=Qa(),{showToast:r}=xd(),{hasPermission:i,authEnabled:a}=sd(),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(new Set),u=!a||i(`library:purge`),d=q({queryKey:[`library-trash`],queryFn:()=>Q.listLibraryTrash(200,0)}),f=q({queryKey:[`library-trash-settings`],queryFn:()=>Q.getLibraryTrashSettings(),enabled:u}),[p,m]=(0,y.useState)(null);(0,y.useEffect)(()=>{f.data&&p===null&&m(f.data.retention_days)},[f.data,p]);let h=J({mutationFn:e=>{let t=f.data;return Q.updateLibraryTrashSettings({retention_days:e,auto_purge_enabled:t?.auto_purge_enabled??!1,auto_purge_days:t?.auto_purge_days??90,auto_purge_include_never_printed:t?.auto_purge_include_never_printed??!0})},onSuccess:t=>{r(e(`libraryTrash.toast.retentionSaved`,{days:t.retention_days}),`success`),n.invalidateQueries({queryKey:[`library-trash-settings`]}),n.invalidateQueries({queryKey:[`library-trash`]})},onError:t=>r(t.message||e(`libraryTrash.toast.retentionFailed`),`error`)}),g=J({mutationFn:e=>Q.restoreLibraryTrash(e),onSuccess:()=>{r(e(`libraryTrash.toast.restored`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>r(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),_=J({mutationFn:e=>Q.hardDeleteLibraryTrash(e),onSuccess:()=>{r(e(`libraryTrash.toast.purged`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),v=J({mutationFn:()=>Q.emptyLibraryTrash(),onSuccess:t=>{r(e(`libraryTrash.toast.emptied`,{count:t.deleted}),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.emptyFailed`),`error`)}),b=J({mutationFn:e=>Promise.all(e.map(e=>Q.restoreLibraryTrash(e))),onSuccess:(t,i)=>{r(e(`libraryTrash.toast.bulkRestored`,{count:i.length}),`success`),l(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>r(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),x=J({mutationFn:e=>Promise.all(e.map(e=>Q.hardDeleteLibraryTrash(e))),onSuccess:(t,i)=>{r(e(`libraryTrash.toast.bulkPurged`,{count:i.length}),`success`),l(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),S=(0,y.useMemo)(()=>d.data?.items??[],[d.data?.items]),C=d.data?.retention_days??30,w=(0,y.useMemo)(()=>S.reduce((e,t)=>e+t.file_size,0),[S]),T=S.length>0&&S.every(e=>c.has(e.id)),E=c.size>0&&!T,D=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,K.jsxs)(`div`,{className:`p-6 max-w-screen-2xl mx-auto`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-3 mb-4`,children:(0,K.jsxs)(bi,{to:`/files`,className:`inline-flex items-center gap-1 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200`,children:[(0,K.jsx)(Do,{className:`w-4 h-4`}),` `,e(`libraryTrash.backToFiles`)]})}),(0,K.jsxs)(`div`,{className:`flex items-start justify-between mb-6 gap-4 flex-wrap`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-gray-100`,children:e(`libraryTrash.title`)}),(0,K.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(u?`libraryTrash.subtitleAdmin`:`libraryTrash.subtitleUser`,{days:C})})]}),S.length>0&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>s({type:`empty`}),className:`text-red-600 dark:text-red-400`,children:[(0,K.jsx)(hu,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.emptyTrash`)]})]}),u&&f.data&&(0,K.jsxs)(`div`,{className:`mb-4 border border-gray-200 dark:border-gray-700 rounded-lg p-3 flex items-center gap-3 bg-gray-50 dark:bg-gray-800/40`,children:[(0,K.jsx)(`label`,{htmlFor:`retention-days`,className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e(`libraryTrash.retentionLabel`)}),(0,K.jsx)(`input`,{id:`retention-days`,type:`number`,min:1,max:365,value:p??f.data.retention_days,onChange:e=>m(Math.max(1,Math.min(365,parseInt(e.target.value||`0`,10)||0))),className:`w-20 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:e(`libraryTrash.days`)}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>p!=null&&h.mutate(p),disabled:h.isPending||p==null||p===f.data.retention_days,className:`ml-auto`,children:[(0,K.jsx)(Ol,{className:`w-4 h-4 mr-1`}),e(`common.save`)]})]}),d.isLoading?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),` `,e(`libraryTrash.loading`)]}):S.length===0?(0,K.jsx)(`div`,{className:`border border-dashed border-gray-300 dark:border-gray-700 rounded-lg p-12 text-center`,children:(0,K.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.empty`)})}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.summary`,{count:S.length,size:yd(w)})}),c.size>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.selectionCount`,{count:c.size})}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>b.mutate(Array.from(c)),disabled:b.isPending,children:[(0,K.jsx)(Tl,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkRestore`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>s({type:`bulkDelete`,count:c.size}),disabled:x.isPending,className:`text-red-600 dark:text-red-400`,children:[(0,K.jsx)(hu,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkPurge`)]})]})]}),(0,K.jsx)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-800 text-left text-gray-600 dark:text-gray-300`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`px-3 py-2 w-10`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:T,ref:e=>{e&&(e.indeterminate=E)},onChange:()=>{l(e=>e.size===S.length?new Set:new Set(S.map(e=>e.id)))},"aria-label":e(`libraryTrash.selectAll`),className:`rounded border-gray-300 cursor-pointer`})}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.filename`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.folder`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.size`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.deleted`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.autoPurge`)}),u&&(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.owner`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.actions`)})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-gray-800`,children:S.map(t=>(0,K.jsxs)(`tr`,{className:`hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:c.has(t.id),onChange:()=>D(t.id),"aria-label":e(`libraryTrash.selectOne`,{filename:t.filename}),className:`rounded border-gray-300 cursor-pointer`})}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-gray-900 dark:text-gray-100 truncate max-w-md`,title:t.filename,children:t.filename}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.folder_name??`—`}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-right text-gray-600 dark:text-gray-400 tabular-nums whitespace-nowrap`,children:yd(t.file_size)}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:L7(t.deleted_at)}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:(0,K.jsx)(`span`,{title:L7(t.auto_purge_at),children:e(`libraryTrash.autoPurgeIn`,{when:NBe(t.auto_purge_at)})})}),u&&(0,K.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.created_by_username??`—`}),(0,K.jsxs)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap`,children:[(0,K.jsxs)(`button`,{onClick:()=>g.mutate(t.id),disabled:g.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300`,children:[(0,K.jsx)(Tl,{className:`w-3.5 h-3.5`}),e(`libraryTrash.restore`)]}),(0,K.jsxs)(`button`,{onClick:()=>s({type:`delete`,id:t.id,filename:t.filename}),disabled:_.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300 ml-2`,children:[(0,K.jsx)(hu,{className:`w-3.5 h-3.5`}),e(`libraryTrash.purgeNow`)]})]})]},t.id))})]})})]}),o&&(0,K.jsx)(Ed,{onCancel:()=>s(null),onConfirm:()=>{o&&(o.type===`delete`?_.mutate(o.id):o.type===`bulkDelete`?x.mutate(Array.from(c)):v.mutate(),s(null))},title:o.type===`delete`?e(`libraryTrash.confirm.purgeTitle`):o.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeTitle`):e(`libraryTrash.confirm.emptyTitle`),message:o.type===`delete`?e(`libraryTrash.confirm.purgeBody`,{filename:o.filename}):o.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeBody`,{count:o.count}):e(`libraryTrash.confirm.emptyBody`,{count:S.length}),confirmText:e(`libraryTrash.confirm.cta`),variant:`danger`}),d.isError&&(0,K.jsxs)(`div`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:[d.error?.message??e(`libraryTrash.loadError`),(0,K.jsx)($,{variant:`secondary`,onClick:()=>t(`/files`),className:`ml-3`,children:e(`libraryTrash.backToFiles`)})]})]})}function FBe(e,t){let n=`token=${encodeURIComponent(t)}`,r=0;return e.querySelectorAll(`img[src*="/api/v1/"], video[src*="/api/v1/"]`).forEach(e=>{let t=e.getAttribute(`src`)||``;if(t.includes(n))return;let i=t.replace(/([?&])token=[^&]*(&|$)/,(e,t,n)=>n===`&`?t:``);e.src=`${i}${i.includes(`?`)?`&`:`?`}${n}`,r+=1}),r}function R7(){let{authEnabled:e,user:t,loading:n}=sd(),r=Qa(),i=(0,y.useRef)(!1),{data:a}=q({queryKey:[`camera-stream-token`,t?.id??null],queryFn:()=>Q.getCameraStreamToken(),enabled:!n&&(!e||t!==null),staleTime:3e3*1e3,refetchInterval:3e3*1e3});(0,y.useEffect)(()=>{let e=a?.token??null;return Wu(e),e&&FBe(document,e),()=>Wu(null)},[a?.token]),(0,y.useEffect)(()=>{if(!e)return;let t=e=>{let t=e.target;if(!(t instanceof HTMLImageElement||t instanceof HTMLVideoElement))return;let n=t.src||``,a=Gu();!a||!n.includes(`token=${encodeURIComponent(a)}`)||i.current||(i.current=!0,r.invalidateQueries({queryKey:[`camera-stream-token`]}),setTimeout(()=>{i.current=!1},5e3))};return document.addEventListener(`error`,t,!0),()=>document.removeEventListener(`error`,t,!0)},[e,r])}var z7=5,IBe=2e3,LBe=3e4,RBe=5e3;function zBe(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),{hasPermission:r,authEnabled:i,user:a}=sd(),{printerId:o}=er(),s=parseInt(o||`0`,10),[c]=Oi(),l=parseInt(c.get(`fps`)||`15`,10),u=Math.min(Math.max(isNaN(l)?15:l,1),30);R7();let{data:d}=q({queryKey:[`camera-stream-token`,a?.id??null],queryFn:()=>Q.getCameraStreamToken(),enabled:i?!!a:!0,staleTime:3e3*1e3}),f=d?.token??Gu(),[p,m]=(0,y.useState)(`stream`),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!0),[w,T]=(0,y.useState)(Date.now()),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(0),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(0),[I,L]=(0,y.useState)(1),[R,z]=(0,y.useState)({x:0,y:0}),[B,V]=(0,y.useState)(!1),[ee,H]=(0,y.useState)({x:0,y:0}),[te,ne]=(0,y.useState)(null),[re,U]=(0,y.useState)(null),ie=(0,y.useRef)(null),ae=(0,y.useRef)(null),W=(0,y.useRef)(null),oe=(0,y.useRef)(null),se=(0,y.useRef)(null),{data:ce}=q({queryKey:[`printer`,s],queryFn:()=>Q.getPrinter(s),enabled:s>0}),{data:le}=q({queryKey:[`printerStatus`,s],queryFn:()=>Q.getPrinterStatus(s),refetchInterval:3e4,enabled:s>0}),ue=J({mutationFn:e=>Q.setChamberLight(s,e),onMutate:async e=>{await t.cancelQueries({queryKey:[`printerStatus`,s]});let n=t.getQueryData([`printerStatus`,s]);return t.setQueryData([`printerStatus`,s],t=>({...t,chamber_light:e})),{previousStatus:n}},onSuccess:(e,t)=>{n(`Chamber light ${t?`on`:`off`}`)},onError:(r,i,a)=>{a?.previousStatus&&t.setQueryData([`printerStatus`,s],a.previousStatus),n(r.message||e(`printers.toast.failedToControlChamberLight`),`error`)}}),de=(le?.state===`RUNNING`||le?.state===`PAUSE`)&&(le?.printable_objects_count??0)>=2;(0,y.useEffect)(()=>(ce&&(document.title=`${ce.name} - Camera`),()=>{document.title=`Bambuddy`}),[ce]);let fe=(0,y.useRef)(!1);(0,y.useEffect)(()=>{let e=`/api/v1/printers/${s}/camera/stop`;fe.current=!1;let t=()=>{if(s>0&&!fe.current){fe.current=!0;let t={},n=Hu();n&&(t.Authorization=`Bearer ${n}`),fetch(e,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},n=()=>{t()};window.addEventListener(`beforeunload`,n);let r=ie.current;return()=>{window.removeEventListener(`beforeunload`,n),r&&(r.src=``),t()}},[s]),(0,y.useEffect)(()=>{if(S&&!E){let e=setTimeout(()=>{C(!1)},p===`stream`?3e3:2e4);return()=>clearTimeout(e)}},[p,S,w,E]),(0,y.useEffect)(()=>{let e=()=>{k(!!document.fullscreenElement),L(1),z({x:0,y:0}),p===`stream`&&!E&&(ie.current&&(ie.current.src=``),setTimeout(()=>{C(!0),T(Date.now())},200))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[p,E]),(0,y.useEffect)(()=>{let e,t=()=>{clearTimeout(e),e=setTimeout(()=>{localStorage.setItem(`cameraWindowState`,JSON.stringify({width:window.outerWidth,height:window.outerHeight,left:window.screenX,top:window.screenY}))},500)};return window.addEventListener(`resize`,t),()=>{clearTimeout(e),window.removeEventListener(`resize`,t)}},[]),(0,y.useEffect)(()=>()=>{W.current&&clearTimeout(W.current),oe.current&&clearInterval(oe.current),se.current&&clearInterval(se.current)},[]);let pe=(0,y.useCallback)(()=>{if(A>=z7){N(!1),x(!0);return}let e=Math.min(IBe*2**A,LBe);N(!0),F(Math.ceil(e/1e3)),oe.current=setInterval(()=>{F(e=>e<=1?(oe.current&&clearInterval(oe.current),0):e-1)},1e3),W.current=setTimeout(()=>{j(e=>e+1),N(!1),C(!0),x(!1),ie.current&&(ie.current.src=``),T(Date.now())},e)},[A]);(0,y.useEffect)(()=>{if(p!==`stream`||S||M||E){se.current&&=(clearInterval(se.current),null);return}return se.current=setInterval(async()=>{try{let e=await Q.getCameraStatus(s);(e.stalled||!e.active&&!b)&&(console.log(`Stream issue detected: stalled=${e.stalled}, active=${e.active}, reconnecting...`),se.current&&=(clearInterval(se.current),null),C(!1),pe())}catch{}},RBe),()=>{se.current&&=(clearInterval(se.current),null)}},[p,S,b,M,E,s,pe]);let me=()=>{C(!1),p===`stream`&&A{if(C(!1),x(!1),j(0),N(!1),W.current&&clearTimeout(W.current),oe.current&&clearInterval(oe.current),ie.current&&!localStorage.getItem(`cameraWindowState`)){let e=ie.current,t=e.naturalWidth,n=e.naturalHeight;if(t>0&&n>0){let e=window.outerWidth-window.innerWidth,r=window.outerHeight-window.innerHeight,i=t+16+e,a=n+45+16+r;try{window.resizeTo(i,a)}catch{}}}},ge=()=>{if(s>0){let e={},t=Hu();t&&(e.Authorization=`Bearer ${t}`),fetch(`/api/v1/printers/${s}/camera/stop`,{method:`POST`,headers:e}).catch(()=>{})}},_e=e=>{p===e||E||(D(!0),C(!0),x(!1),j(0),N(!1),L(1),z({x:0,y:0}),W.current&&clearTimeout(W.current),oe.current&&clearInterval(oe.current),ie.current&&(ie.current.src=``),p===`stream`&&ge(),setTimeout(()=>{m(e),T(Date.now()),D(!1)},100))},ve=()=>{E||(D(!0),C(!0),x(!1),j(0),N(!1),W.current&&clearTimeout(W.current),oe.current&&clearInterval(oe.current),ie.current&&(ie.current.src=``),p===`stream`&&ge(),setTimeout(()=>{T(Date.now()),D(!1)},100))},ye=()=>{ae.current&&(document.fullscreenElement?document.exitFullscreen():ae.current.requestFullscreen())},be=()=>{L(e=>Math.min(e+.5,4))},xe=()=>{L(e=>{let t=Math.max(e-.5,1);return t===1&&z({x:0,y:0}),t})},Se=e=>{e.preventDefault(),e.deltaY<0?be():xe()},Ce=e=>{I>1&&(e.preventDefault(),V(!0),H({x:e.clientX-R.x,y:e.clientY-R.y}))},we=(0,y.useCallback)(()=>{if(!ae.current)return{x:300,y:200};let e=ae.current.getBoundingClientRect(),t=e.width*(I-1)/2,n=e.height*(I-1)/2;return{x:Math.max(50,t),y:Math.max(50,n)}},[I]),Te=e=>{if(B&&I>1){let t=e.clientX-ee.x,n=e.clientY-ee.y,r=we();z({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Ee=()=>{V(!1)},De=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)},Oe=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},ke=e=>{e.touches.length===2?(e.preventDefault(),ne(De(e.touches)),U(Oe(e.touches))):e.touches.length===1&&I>1&&(e.preventDefault(),V(!0),H({x:e.touches[0].clientX-R.x,y:e.touches[0].clientY-R.y}))},Ae=e=>{if(e.touches.length===2&&te!==null){e.preventDefault();let t=De(e.touches),n=t/te;L(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&z({x:0,y:0}),t}),ne(t);let r=Oe(e.touches);if(re){let e=we();z(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-re.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-re.y)))}))}U(r)}else if(e.touches.length===1&&B&&I>1){e.preventDefault();let t=e.touches[0].clientX-ee.x,n=e.touches[0].clientY-ee.y,r=we();z({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},je=e=>{e.touches.length<2&&(ne(null),U(null)),e.touches.length===0&&V(!1)},Me=()=>{L(1),z({x:0,y:0})},Ne=E||i&&!f?``:(e=>f?`${e}&token=${encodeURIComponent(f)}`:Ku(e))(p===`stream`?`/api/v1/printers/${s}/camera/stream?fps=${u}&t=${w}`:`/api/v1/printers/${s}/camera/snapshot?t=${w}`),Pe=S||E||M;return s?(0,K.jsxs)(`div`,{ref:ae,className:`min-h-screen bg-black flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h1`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,K.jsx)(Jo,{className:`w-4 h-4`}),ce?.name||`Printer ${s}`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex bg-bambu-dark rounded p-0.5`,children:[(0,K.jsx)(`button`,{onClick:()=>_e(`stream`),disabled:Pe,className:`px-3 py-1 text-xs rounded transition-colors ${p===`stream`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.live`)}),(0,K.jsx)(`button`,{onClick:()=>_e(`snapshot`),disabled:Pe,className:`px-3 py-1 text-xs rounded transition-colors ${p===`snapshot`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.snapshot`)})]}),(0,K.jsx)(`button`,{onClick:()=>ue.mutate(!le?.chamber_light),disabled:!le?.connected||ue.isPending||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${le?.chamber_light?`bg-yellow-500/20 hover:bg-yellow-500/30`:`hover:bg-bambu-dark-tertiary`}`,title:r(`printers:control`)?e(`camera.chamberLight`):e(`printers.permission.noControl`),children:(0,K.jsx)(OT,{on:le?.chamber_light??!1,className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>g(!0),disabled:!de||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${de&&r(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:r(`printers:control`)?e(de?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):e(`printers.permission.noControl`),children:(0,K.jsx)(kT,{className:`w-4 h-4 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:ve,disabled:Pe,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:e(p===`stream`?`camera.restartStream`:`camera.refreshSnapshot`),children:(0,K.jsx)(Cl,{className:`w-4 h-4 text-bambu-gray ${Pe?`animate-spin`:``}`})}),(0,K.jsx)(`button`,{onClick:()=>v(!0),className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(`camera.diagnose.button`),children:(0,K.jsx)(ru,{className:`w-4 h-4 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:ye,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(O?`camera.exitFullscreen`:`camera.fullscreen`),children:O?(0,K.jsx)($c,{className:`w-4 h-4 text-bambu-gray`}):(0,K.jsx)(Yc,{className:`w-4 h-4 text-bambu-gray`})})]})]}),(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-2 overflow-hidden`,onWheel:Se,onMouseMove:Te,onMouseUp:Ee,onMouseLeave:Ee,onTouchStart:ke,onTouchMove:Ae,onTouchEnd:je,style:{touchAction:`none`},children:(0,K.jsxs)(`div`,{className:`relative w-full h-full flex items-center justify-center`,children:[(S||E)&&!M&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(Cl,{className:`w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(p===`stream`?`camera.connectingToCamera`:`camera.capturingSnapshot`)})]})}),M&&(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-4`,children:[(0,K.jsx)(Au,{className:`w-10 h-10 text-orange-400 mx-auto mb-3`}),(0,K.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.connectionLost`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:e(`camera.reconnecting`,{countdown:P,attempt:Math.min(A+1,z7),max:z7})}),(0,K.jsx)(`button`,{onClick:ve,className:`px-4 py-2 bg-bambu-green text-white text-sm rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.reconnectNow`)})]})}),b&&!M&&(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-4`,children:[(0,K.jsx)(vu,{className:`w-12 h-12 text-orange-400 mx-auto mb-3`}),(0,K.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.cameraUnavailable`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 max-w-md`,children:e(`camera.cameraUnavailableDesc`)}),(0,K.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,K.jsx)(`button`,{onClick:ve,className:`px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.retry`)}),(0,K.jsx)(`button`,{onClick:()=>v(!0),className:`px-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white rounded transition-colors`,children:e(`camera.diagnose.button`)})]})]})}),(0,K.jsx)(`img`,{ref:ie,src:Ne,alt:e(`camera.cameraStream`),className:`max-w-full max-h-full object-contain select-none`,style:{transform:`scale(${I}) translate(${R.x/I}px, ${R.y/I}px) rotate(${ce?.camera_rotation||0}deg)`,...ce?.camera_rotation===90||ce?.camera_rotation===270?{maxWidth:`100vh`,maxHeight:`100vw`}:{},cursor:I>1?B?`grabbing`:`grab`:`default`},onError:Ne?me:void 0,onLoad:Ne?he:void 0,onMouseDown:Ce,draggable:!1},w),(0,K.jsxs)(`div`,{className:`absolute bottom-4 left-4 flex items-center gap-1.5 bg-black/60 rounded-lg px-2 py-1.5`,children:[(0,K.jsx)(`button`,{onClick:xe,disabled:I<=1,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomOut`),children:(0,K.jsx)(Lu,{className:`w-4 h-4 text-white`})}),(0,K.jsxs)(`button`,{onClick:Me,className:`px-2 py-1 text-sm text-white hover:bg-white/10 rounded min-w-[48px]`,title:e(`camera.resetZoom`),children:[Math.round(I*100),`%`]}),(0,K.jsx)(`button`,{onClick:be,disabled:I>=4,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomIn`),children:(0,K.jsx)(Fu,{className:`w-4 h-4 text-white`})})]})]})}),(0,K.jsx)(AT,{printerId:s,isOpen:h,onClose:()=>g(!1)}),_&&(0,K.jsx)(jT,{printerId:s,printerName:ce?.name||null,onClose:()=>v(!1)})]}):(0,K.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,K.jsx)(`p`,{className:`text-white`,children:e(`camera.invalidPrinterId`)})})}function BBe(e,t,n){if(!e)return``;if(!t)return e;let r=t.match(/plate_(\d+)\.gcode/);return r&&parseInt(r[1],10)>1?`${e} — ${n(`printers.plateNumber`,`Plate {{number}}`,{number:r[1]})}`:e}function VBe(e){let t=e.get(`show`)?.split(`,`)||[`progress`,`layers`,`eta`,`filename`,`status`],n=parseInt(e.get(`fps`)||`15`,10),r=Math.min(Math.max(isNaN(n)?15:n,1),30),i=e.get(`camera`),a=i!==`false`&&i!==`0`;return{size:e.get(`size`)||`medium`,fps:r,showCamera:a,showProgress:t.includes(`progress`),showLayers:t.includes(`layers`),showEta:t.includes(`eta`),showFilename:t.includes(`filename`),showStatus:t.includes(`status`),showPrinter:t.includes(`printer`)}}function HBe(e,t){if(e.stg_cur_name)return e.stg_cur_name;switch(e.state){case`RUNNING`:return t(`streamOverlay.status.printing`);case`PAUSE`:return t(`streamOverlay.status.paused`);case`FINISH`:return t(`streamOverlay.status.finished`);case`FAILED`:return t(`streamOverlay.status.failed`);case`IDLE`:return t(`streamOverlay.status.idle`);default:return e.state||t(`streamOverlay.status.unknown`)}}function UBe(e){switch(e){case`small`:return{container:`p-3`,text:`text-sm`,textLarge:`text-lg`,progressHeight:`h-2`,icon:`w-3 h-3`,gap:`gap-2`,logoHeight:`h-12`};case`large`:return{container:`p-6`,text:`text-xl`,textLarge:`text-3xl`,progressHeight:`h-4`,icon:`w-6 h-6`,gap:`gap-4`,logoHeight:`h-24`};default:return{container:`p-4`,text:`text-base`,textLarge:`text-xl`,progressHeight:`h-3`,icon:`w-4 h-4`,gap:`gap-3`,logoHeight:`h-16`}}}function WBe(){let{printerId:e}=er(),[t]=Oi(),{t:n}=G(),r=Qa(),i=parseInt(e||`0`,10),[a,o]=(0,y.useState)(Date.now()),s=(0,y.useMemo)(()=>VBe(t),[t]),c=UBe(s.size),{data:l}=q({queryKey:[`printer`,i],queryFn:()=>Q.getPrinter(i),enabled:i>0}),{data:u}=q({queryKey:[`printerStatus`,i],queryFn:()=>Q.getPrinterStatus(i),enabled:i>0,refetchInterval:2e3}),{data:d}=q({queryKey:[`settings`],queryFn:Q.getSettings}),f=d?.time_format||`system`;(0,y.useEffect)(()=>{if(!i)return;let e=null,t=!1;return(async()=>{let n;try{n=(await Q.getWebSocketToken()).token}catch{}if(t)return;let a=window.location.protocol===`https:`?`wss:`:`ws:`,o=n?`?token=${encodeURIComponent(n)}`:``,s=`${a}//${window.location.host}/api/v1/ws${o}`;e=new WebSocket(s),e.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`printer_status`&&t.printer_id===i&&r.setQueryData([`printerStatus`,i],t.status)}catch{}},e.onerror=()=>{}})(),()=>{t=!0,e&&e.close()}},[i,r]),(0,y.useEffect)(()=>(document.title=l?`${l.name} - ${n(`streamOverlay.title`)}`:n(`streamOverlay.title`),()=>{document.title=`Bambuddy`}),[l,n]);let p=()=>{setTimeout(()=>{o(Date.now())},3e3)};if(!i)return(0,K.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,K.jsx)(`p`,{className:`text-white`,children:n(`streamOverlay.invalidPrinterId`)})});if(!u)return(0,K.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,K.jsx)(`p`,{className:`text-gray-400`,children:n(`common.loading`)})});let m=u.state===`RUNNING`||u.state===`PAUSE`,h=u.progress||0,g=Ku(`/api/v1/printers/${i}/camera/stream?fps=${s.fps}&t=${a}`);return(0,K.jsxs)(`div`,{className:`min-h-screen bg-black relative overflow-hidden`,children:[s.showCamera&&(0,K.jsx)(`img`,{src:g,alt:n(`streamOverlay.cameraStream`),className:`absolute inset-0 w-full h-full object-contain`,style:l?.camera_rotation?{transform:`rotate(${l.camera_rotation}deg)`}:void 0,onError:p},a),(0,K.jsx)(`a`,{href:`https://github.com/maziggy/bambuddy`,target:`_blank`,rel:`noopener noreferrer`,className:`absolute top-4 right-4 z-10`,children:(0,K.jsx)(`img`,{src:`/img/bambuddy_logo_dark_transparent.png`,alt:`Bambuddy`,className:`${c.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})}),(0,K.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/60 to-transparent`,children:(0,K.jsxs)(`div`,{className:`${c.container}`,children:[s.showPrinter&&l&&(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} mb-2`,children:[(0,K.jsx)(bl,{className:`${c.icon} text-white/70`}),(0,K.jsx)(`span`,{className:`${c.text} text-white font-medium`,children:l.name})]}),s.showFilename&&u.current_print&&(0,K.jsx)(`div`,{className:`${c.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:BBe(u.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),u.gcode_file,n)}),s.showStatus&&(0,K.jsx)(`div`,{className:`${c.text} text-white/70 mb-2`,children:HBe(u,n)}),s.showProgress&&m&&(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-1 ${c.text}`,children:[(0,K.jsx)(`span`,{className:`text-white/70`,children:n(`streamOverlay.progress`)}),(0,K.jsxs)(`span`,{className:`text-white font-bold`,children:[Math.round(h),`%`]})]}),(0,K.jsx)(`div`,{className:`w-full bg-white/20 rounded-full ${c.progressHeight}`,children:(0,K.jsx)(`div`,{className:`bg-bambu-green ${c.progressHeight} rounded-full transition-all duration-500`,style:{width:`${h}%`}})})]}),m&&(s.showLayers||s.showEta)&&(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} flex-wrap`,children:[s.showLayers&&u.layer_num!=null&&u.total_layers!=null&&u.total_layers>0&&(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,K.jsx)(Nc,{className:c.icon}),(0,K.jsxs)(`span`,{className:c.text,children:[(0,K.jsx)(`span`,{className:`text-white`,children:u.layer_num}),(0,K.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,K.jsx)(`span`,{children:u.total_layers})]})]}),s.showEta&&u.remaining_time!=null&&u.remaining_time>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,K.jsx)(mu,{className:c.icon}),(0,K.jsx)(`span`,{className:`${c.text} text-white`,children:yf(u.remaining_time*60)})]}),(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,K.jsx)(_s,{className:c.icon}),(0,K.jsxs)(`span`,{className:`${c.text} text-white`,children:[n(`streamOverlay.eta`),` `,vf(u.remaining_time,f,n)]})]})]})]}),!m&&(0,K.jsx)(`div`,{className:`${c.text} text-white/70 py-2`,children:u.connected?n(`streamOverlay.printerIdle`):n(`streamOverlay.printerOffline`)})]})})]})}function GBe(){let{t:e}=G(),{id:t}=er(),{mode:n}=ud(),{data:r,isLoading:i,error:a}=q({queryKey:[`external-link`,t],queryFn:()=>Q.getExternalLink(Number(t)),enabled:!!t});return i?(0,K.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):a||!r?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 text-bambu-gray`,children:[(0,K.jsx)(vu,{className:`w-12 h-12`}),(0,K.jsx)(`p`,{children:e(`common.linkNotFound`)})]}):(0,K.jsx)(`iframe`,{src:r.url,className:`h-full w-full border-0`,style:{colorScheme:n},title:r.name,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox`})}function B7(){let{id:e}=er(),t=Yn(),n=Qa(),{t:r}=G(),{showToast:i}=xd(),a=!!e,[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)([]),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(!1),{data:g,isLoading:_}=q({queryKey:[`group`,e],queryFn:()=>Q.getGroup(Number(e)),enabled:a}),{data:v,isLoading:b}=q({queryKey:[`permissions`],queryFn:()=>Q.getPermissions()});a&&g&&!m&&(s(g.name),l(g.description||``),d(g.permissions),h(!0));let x=J({mutationFn:e=>Q.createGroup(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`groups`]}),n.invalidateQueries({queryKey:[`group`]}),i(r(`groups.toast.created`)),t(`/settings?tab=users`)},onError:e=>{i(e.message,`error`)}}),S=J({mutationFn:t=>Q.updateGroup(Number(e),t),onSuccess:a=>{n.invalidateQueries({queryKey:[`groups`]}),a&&n.setQueryData([`group`,e],a),i(r(`groups.toast.updated`)),t(`/settings?tab=users`)},onError:e=>{i(e.message,`error`)}}),C=x.isPending||S.isPending,w=()=>{if(!o.trim()){i(r(`groups.toast.enterGroupName`),`error`);return}a?S.mutate({name:o===g?.name?void 0:o,description:c,permissions:u}):x.mutate({name:o,description:c||void 0,permissions:u})},T=e=>{d(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},E=(e,t)=>{let n=e.permissions.map(e=>e.value);d(e=>{let r=e.filter(e=>!n.includes(e));return t?[...r,...n]:r})},D=e=>e.permissions.every(e=>u.includes(e.value)),O=e=>{let t=e.permissions.filter(e=>u.includes(e.value)).length;return t>0&&t{v&&d(v.all_permissions)},A=()=>{d([])},j=f.toLowerCase(),M=(0,y.useMemo)(()=>v?j?v.categories.map(e=>({...e,permissions:e.permissions.filter(e=>e.label.toLowerCase().includes(j))})).filter(e=>e.permissions.length>0):v.categories:[],[v,j]),N=v?.all_permissions.length??0;return _||b?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,K.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`button`,{onClick:()=>t(`/settings?tab=users`),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Do,{className:`w-5 h-5`})}),(0,K.jsx)(`h1`,{className:`text-xl font-bold text-white`,children:r(a?`groups.editor.title`:`groups.editor.createTitle`)})]}),a&&g?.is_system&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-yellow-500/10 border border-yellow-500/20 text-yellow-400 text-sm`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 shrink-0`}),r(`groups.form.systemGroupWarning`)]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.groupName`)}),(0,K.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),disabled:a&&g?.is_system,className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-50`,placeholder:r(`groups.form.groupNamePlaceholder`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.description`)}),(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`groups.form.descriptionPlaceholder`)})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[r(`groups.editor.permissionsSelected`,{count:u.length}),` / `,N]}),(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:k,children:r(`groups.editor.selectAll`)}),(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:A,children:r(`groups.editor.clearAll`)})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:r(`groups.editor.search`),className:`pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors w-64`})]})]}),M.length===0?(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:r(`groups.editor.noResults`)}):(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:M.map(e=>{let t=v.categories.find(t=>t.name===e.name),n=t.permissions.filter(e=>u.includes(e.value)).length,r=t.permissions.length,i=D(t),a=O(t);return(0,K.jsxs)(pd,{children:[(0,K.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center justify-between px-4 py-3 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-t-xl`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>E(t,!i),className:`w-5 h-5 rounded border flex items-center justify-center transition-colors shrink-0 ${i?`bg-bambu-green border-bambu-green`:a?`bg-bambu-green/50 border-bambu-green`:`border-bambu-gray hover:border-white`}`,children:[i&&(0,K.jsx)($o,{className:`w-3 h-3 text-white`}),a&&!i&&(0,K.jsx)(el,{className:`w-3 h-3 text-white`})]}),(0,K.jsx)(Hl,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,K.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name})]}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray tabular-nums`,children:[n,`/`,r]})]}),(0,K.jsx)(`div`,{className:`p-3 space-y-1`,children:e.permissions.map(e=>(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:u.includes(e.value),onChange:()=>T(e.value),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary`}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.label})]},e.value))})]},e.name)})}),(0,K.jsx)(`div`,{className:`h-16`}),(0,K.jsxs)(`div`,{className:`fixed bottom-0 left-0 right-0 z-20 px-6 py-3 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-center justify-center gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>t(`/settings?tab=users`),children:r(`common.cancel`)}),(0,K.jsx)($,{onClick:w,disabled:C||!o.trim(),children:C?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),r(`common.saving`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),r(`common.save`)]})})]})]})}var KBe=1.65,V7=[`#1DB954`,`#3B82F6`,`#F59E0B`,`#EF4444`,`#8B5CF6`];function H7(e,t,n){return`${e}||${t??``}||${n??``}`}function U7(e,t){let n=new Date(e);return n.setDate(n.getDate()+Math.round(t)),n}function W7(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function G7(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function qBe(e){if(e.length<2)return null;let t=[...e].sort((e,t)=>new Date(e.created_at).getTime()-new Date(t.created_at).getTime()),n=Date.now(),r=Math.LN2/30,i=[];for(let e=1;ee+t.weight,0);if(a===0)return null;let o=i.reduce((e,t)=>e+t.rate*t.weight,0)/a,s=i.reduce((e,t)=>e+t.weight*(t.rate-o)**2,0)/a;return{rate:o,stdDev:Math.sqrt(s)}}function JBe(e){let t=e.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0);if(t===0)return null;let n=Date.now(),r=(n-e.reduce((e,t)=>{let n=new Date(t.created_at).getTime();return nQ.getAllUsageHistory(5e3),staleTime:6e4,enabled:o}),{data:w=[]}=q({queryKey:[`shopping-list`],queryFn:Q.getShoppingList,staleTime:3e4,enabled:o}),T=x?.forecast_global_lead_time_days??0,E=(0,y.useMemo)(()=>{let e=new Map;for(let t of S)e.set(H7(t.material,t.subtype,t.brand),t);return e},[S]),D=(0,y.useMemo)(()=>{let e=new Map;for(let t of C){let n=e.get(t.spool_id)??[];n.push(t),e.set(t.spool_id,n)}return e},[C]),O=(0,y.useMemo)(()=>{let t=new Map;for(let n of e){if(n.archived_at)continue;let e=H7(n.material,n.subtype,n.brand),r=t.get(e)??{key:e,material:n.material,subtype:n.subtype,brand:n.brand,spools:[]};r.spools.push(n),t.set(e,r)}return[...t.values()]},[e]),k=(0,y.useMemo)(()=>{let e=new Date;return e.setHours(0,0,0,0),O.map(t=>{let n=E.get(t.key)??null,r=n?.lead_time_days??0,i=Math.max(T,r),a=n?.safety_margin_value??14,o=n?.safety_margin_unit??`days`,s=t.spools.reduce((e,t)=>e+Math.max(0,t.label_weight-t.weight_used),0),c=t.spools.reduce((e,t)=>e+t.label_weight,0),l=t.spools.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0),u=[];for(let e of t.spools)u.push(...D.get(e.id)??[]);let d=null,f=null,p=`none`,m=qBe(u);if(m!==null)d=m.rate,f=m.stdDev,p=`history`;else{let e=JBe(t.spools);e!==null&&(d=e,p=`delta`)}let h=KBe*(f??(d===null?0:d*.2))*Math.sqrt(i)+(o===`g`?a:d===null?a*5:d*a),g=d===null?0:d*i+h,_=d&&d>0?Math.floor(s/d):null,v=_===null?null:U7(e,_),y=d&&d>0?Math.floor((s-g)/d):null,b=y===null?null:U7(e,Math.max(0,y)),x=_!==null&&i>0&&_<=i,S=!x&&y!==null&&y<=0;return{group:t,settings:n,totalRemainingG:s,totalLabelG:c,totalSpools:t.spools.length,totalUsedG:l,dailyRateG:d,dailyRateStdDev:f,rateTier:p,effectiveLeadTimeDays:i,safetyStockG:h,reorderPointG:g,daysRemaining:_,daysUntilROP:y,projectedEmptyDate:v,reorderTriggerDate:b,reorderAlert:S,stockBreakAlert:x}})},[O,E,D,T]),A=(0,y.useMemo)(()=>{let e=[...k];return e.sort((e,t)=>{let n=0,r=0;switch(u){case`material`:n=[e.group.material,e.group.subtype??``,e.group.brand??``].join(` `).toLowerCase(),r=[t.group.material,t.group.subtype??``,t.group.brand??``].join(` `).toLowerCase();break;case`used`:n=e.totalUsedG,r=t.totalUsedG;break;case`days_left`:n=e.daysRemaining??999999,r=t.daysRemaining??999999;break;case`stock`:n=e.totalRemainingG,r=t.totalRemainingG;break}let i=nr);return f===`asc`?i:-i}),e},[k,u,f]),j=(0,y.useMemo)(()=>k.filter(e=>!e.settings?.alerts_snoozed&&(e.stockBreakAlert||e.reorderAlert)),[k]),M=(0,y.useMemo)(()=>[...k].filter(e=>e.dailyRateG!==null).sort((e,t)=>t.totalUsedG-e.totalUsedG).slice(0,5),[k]);if(!o)return(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray gap-3`,children:[(0,K.jsx)(Hc,{className:`w-8 h-8 opacity-40`}),(0,K.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noReadAccess`)})]});function N(e){u===e?p(e=>e===`asc`?`desc`:`asc`):(d(e),p(e===`days_left`?`asc`:`desc`))}let P=w.length>0?w.length:null;return(0,K.jsxs)(`div`,{className:`space-y-5`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[j.length>0&&(0,K.jsxs)(`button`,{onClick:()=>l(e=>!e),className:`flex items-center gap-2 px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors ${j.some(e=>e.stockBreakAlert)?`bg-red-500/15 border-red-500/30 text-red-300 hover:bg-red-500/25`:`bg-yellow-500/15 border-yellow-500/30 text-yellow-300 hover:bg-yellow-500/25`}`,children:[(0,K.jsx)(vu,{className:`w-4 h-4`}),r(`forecast.alertCount`,{count:j.length}),c?(0,K.jsx)(rs,{className:`w-3.5 h-3.5`}):(0,K.jsx)(es,{className:`w-3.5 h-3.5`})]}),s&&(0,K.jsx)(eVe,{value:T,onSave:e=>{Q.updateSettings({forecast_global_lead_time_days:e}).then(()=>{t.invalidateQueries({queryKey:[`settings`]}),n(r(`forecast.globalLeadTimeSaved`),`success`)})}}),(0,K.jsxs)(`button`,{onClick:()=>_(e=>!e),className:`relative flex items-center gap-2 px-3 py-1.5 rounded-lg border border-bambu-dark-tertiary text-bambu-gray hover:bg-bambu-dark-tertiary text-sm transition-colors ml-auto`,children:[(0,K.jsx)(Ul,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:r(`forecast.shoppingList`)}),P&&(0,K.jsx)(`span`,{className:`absolute -top-1.5 -right-1.5 w-4 h-4 rounded-full bg-bambu-green text-white text-[10px] font-bold flex items-center justify-center`,children:P})]})]}),c&&j.length>0&&(0,K.jsx)(`div`,{className:`space-y-2`,children:j.map(e=>(0,K.jsx)(ZBe,{forecast:e,onCart:()=>h(e)},e.group.key))}),g&&(0,K.jsx)(iVe,{items:w,forecasts:k,globalLeadTime:T,canWrite:s,onClose:()=>_(!1),onRemove:e=>{Q.removeFromShoppingList(e).then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))},onClear:()=>{Q.clearShoppingList().then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))}}),M.length>0&&(0,K.jsx)($Be,{forecasts:M,days:v,onDaysChange:b}),k.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,K.jsx)(gu,{className:`w-10 h-10 mb-3 opacity-40`}),(0,K.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noSpools`)})]}):(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,K.jsx)(`th`,{className:`w-8 px-4 py-3`}),(0,K.jsx)(K7,{col:`material`,active:u,dir:f,onSort:N,children:r(`forecast.sku`)}),(0,K.jsx)(K7,{col:`stock`,active:u,dir:f,onSort:N,children:r(`forecast.stock`)}),(0,K.jsx)(K7,{col:`used`,active:u,dir:f,onSort:N,children:r(`forecast.dailyRate`)}),(0,K.jsx)(K7,{col:`days_left`,active:u,dir:f,onSort:N,children:r(`forecast.daysLeft`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.emptyBy`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.reorderBy`)}),(0,K.jsx)(`th`,{className:`w-24 px-4 py-3`})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:A.map(e=>(0,K.jsx)(tVe,{forecast:e,globalLeadTime:T,canWrite:s,onSaved:()=>t.invalidateQueries({queryKey:[`sku-settings`]}),onCart:()=>h(e),showToast:n},e.group.key))})]})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-4 py-3 text-xs text-bambu-gray border-t border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-green inline-block`}),r(`forecast.trendLegend`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-400 inline-block`}),r(`forecast.estimatedLegend`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-gray/40 inline-block`}),r(`forecast.noDataLegend`)]})]})]}),m&&(0,K.jsx)(oVe,{forecast:m,onClose:()=>h(null),onAdd:e=>{Q.addToShoppingList(e).then(()=>{t.invalidateQueries({queryKey:[`shopping-list`]}),n(r(`forecast.addedToCart`),`success`),h(null),_(!0)}).catch(()=>n(r(`forecast.failedAddItem`),`error`))}})]})}function K7({col:e,active:t,dir:n,onSort:r,children:i}){return(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide cursor-pointer select-none hover:text-white transition-colors`,onClick:()=>r(e),children:(0,K.jsxs)(`span`,{className:`inline-flex items-center`,children:[i,t===e?n===`asc`?(0,K.jsx)(Mo,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,K.jsx)(Eo,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,K.jsx)(Ao,{className:`w-3 h-3 ml-1 opacity-40`})]})})}function ZBe({forecast:e,onCart:t}){let{t:n}=G(),r=[e.group.brand,e.group.material,e.group.subtype].filter(Boolean).join(` `),i=e.stockBreakAlert;return(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg border text-sm ${i?`bg-red-500/10 border-red-500/30 text-red-300`:`bg-yellow-500/10 border-yellow-500/30 text-yellow-300`}`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`span`,{className:`font-medium`,children:r}),i?(0,K.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.stockBreakRisk`),` — `,n(`forecast.stockBreakDetail`,{days:e.daysRemaining,lt:e.effectiveLeadTimeDays})]}):(0,K.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.reorderNow`),` — `,n(`forecast.reorderTriggerPassed`,{date:e.reorderTriggerDate?W7(e.reorderTriggerDate):`—`})]})]}),(0,K.jsxs)(`button`,{onClick:t,className:`flex items-center gap-1.5 px-2.5 py-1 rounded border border-current text-xs opacity-70 hover:opacity-100 transition-opacity`,children:[(0,K.jsx)(Ul,{className:`w-3 h-3`}),` `,n(`forecast.order`)]})]})}var QBe=[{label:`1W`,value:7},{label:`1M`,value:30},{label:`6M`,value:180}];function $Be({forecasts:e,days:t,onDaysChange:n}){let{t:r}=G(),i=Array.from({length:t+1},(e,t)=>t),a=e.map((e,n)=>({key:e.group.key,label:[e.group.brand,e.group.material,e.group.subtype].filter(Boolean).join(` `),color:V7[n%V7.length],rop:e.reorderPointG,points:YBe(e,t)})),o=i.map(e=>{let t={day:e,label:G7(U7(new Date,e))};for(let n of a){let r=n.points.find(t=>t.day===e);t[n.key]=r?.stock??0}return t}),s=(()=>{for(let e=t;e>=0;e--)if(a.some(t=>o[e]?.[t.key]>0))return e;return t})(),c=o.slice(0,s+1),l=a.filter(e=>e.rop>0);return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,K.jsx)(gu,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:r(`forecast.chartTitle`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1 hidden sm:inline`,children:r(`forecast.dashedLinesROP`)}),(0,K.jsx)(`div`,{className:`ml-auto flex items-center bg-bambu-dark-tertiary rounded-lg p-0.5`,children:QBe.map(e=>(0,K.jsx)(`button`,{onClick:()=>n(e.value),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${t===e.value?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:e.label},e.value))})]}),(0,K.jsx)(RA,{width:`100%`,height:220,children:(0,K.jsxs)(WG,{data:c,margin:{top:4,right:8,bottom:0,left:0},children:[(0,K.jsx)(`defs`,{children:a.map(e=>(0,K.jsxs)(`linearGradient`,{id:`grad-${e.key}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,K.jsx)(`stop`,{offset:`5%`,stopColor:e.color,stopOpacity:.25}),(0,K.jsx)(`stop`,{offset:`95%`,stopColor:e.color,stopOpacity:.02})]},e.key))}),(0,K.jsx)(XU,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.5}),(0,K.jsx)(eG,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:10},interval:Math.max(0,Math.ceil(s/8)-1),axisLine:!1,tickLine:!1}),(0,K.jsx)(aG,{tick:{fill:`#6B7280`,fontSize:10},axisLine:!1,tickLine:!1,tickFormatter:e=>e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:48}),(0,K.jsx)(Xz,{contentStyle:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:12},labelStyle:{color:`#9CA3AF`},itemStyle:{color:`#E5E7EB`},formatter:(e,t)=>typeof e==`number`?`${e}g — ${a.find(e=>e.key===String(t))?.label??t}`:``}),(0,K.jsx)(Gj,{formatter:e=>(0,K.jsx)(`span`,{style:{color:`#9CA3AF`,fontSize:11},children:a.find(t=>t.key===e)?.label??e})}),a.map(e=>(0,K.jsx)(MW,{type:`monotone`,dataKey:e.key,stroke:e.color,strokeWidth:2,fill:`url(#grad-${e.key})`,dot:!1,activeDot:{r:3}},e.key)),l.map(e=>(0,K.jsx)(PU,{y:e.rop,stroke:e.color,strokeDasharray:`4 3`,strokeOpacity:.6},`rop-${e.key}`))]})})]})}function eVe({value:e,onSave:t}){let{t:n}=G(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(String(e));function s(){let e=parseInt(a,10);isNaN(e)||e<0||(t(e),i(!1))}return(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-tertiary/40 rounded-lg border border-bambu-dark-tertiary text-xs text-bambu-gray`,children:[(0,K.jsx)(kc,{className:`w-3.5 h-3.5 flex-shrink-0`,"aria-label":n(`forecast.globalLeadTimeHint`)}),(0,K.jsxs)(`span`,{className:`hidden sm:inline`,children:[n(`forecast.globalLeadTime`),`:`]}),r?(0,K.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault(),s()},children:[(0,K.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-14 px-1.5 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`d`}),(0,K.jsx)(`button`,{type:`submit`,className:`px-2 py-0.5 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80`,children:n(`forecast.save`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`text-xs text-bambu-gray hover:text-white`,children:`✕`})]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsxs)(`span`,{className:`font-semibold text-white`,children:[e,`d`]}),(0,K.jsx)(`button`,{onClick:()=>{o(String(e)),i(!0)},className:`p-0.5 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(fl,{className:`w-3 h-3`})})]})]})}function tVe({forecast:e,globalLeadTime:t,canWrite:n,onSaved:r,onCart:i,showToast:a}){let{t:o}=G(),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(String(e.settings?.lead_time_days??0)),[h,g]=(0,y.useState)(String(e.settings?.safety_margin_value??14)),[_,v]=(0,y.useState)(e.settings?.safety_margin_unit??`days`);(0,y.useEffect)(()=>{l||m(String(e.settings?.lead_time_days??0))},[e.settings?.lead_time_days,l]),(0,y.useEffect)(()=>{d||(g(String(e.settings?.safety_margin_value??14)),v(e.settings?.safety_margin_unit??`days`))},[e.settings?.safety_margin_value,e.settings?.safety_margin_unit,d]);let b=J({mutationFn:Q.upsertSkuSettings,onSuccess:()=>{r(),a(o(`forecast.settingsSaved`),`success`)},onError:()=>a(o(`forecast.failedSaveSettings`),`error`)}),x=e.settings?.alerts_snoozed??!1,S=[e.group.brand,e.group.material,e.group.subtype].filter(Boolean).join(` `),C=e.group.spools[0]?.rgba?Wd(e.group.spools[0].rgba):{backgroundColor:`#4B5563`},w=e.totalLabelG>0?Math.round(e.totalRemainingG/e.totalLabelG*100):0,T=x||e.daysRemaining===null?`text-bambu-gray`:e.stockBreakAlert?`text-red-400`:e.reorderAlert||e.daysRemaining<30?`text-yellow-400`:`text-green-400`;function E(t,n,r,i=x){b.mutate({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,lead_time_days:t,safety_margin_value:n,safety_margin_unit:r,alerts_snoozed:i})}function D(t){t.stopPropagation(),E(e.settings?.lead_time_days??0,e.settings?.safety_margin_value??14,e.settings?.safety_margin_unit??`days`,!x)}let O=e.rateTier===`history`?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-green/15 text-bambu-green`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),o(`forecast.trend`)]}):e.rateTier===`delta`?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-400/15 text-blue-400`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-blue-400`}),o(`forecast.estimated`)]}):(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray/60`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-gray/40`}),o(`forecast.noData`)]});return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`tr`,{className:`cursor-pointer hover:bg-bambu-dark-tertiary/40 transition-colors ${x?``:e.stockBreakAlert?`bg-red-500/5`:e.reorderAlert?`bg-yellow-500/5`:``} ${x?`opacity-50`:``}`,onClick:()=>c(e=>!e),children:[(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsx)(`span`,{className:`block w-3 h-3 rounded-full border border-black/20`,style:C})}),(0,K.jsxs)(`td`,{className:`px-4 py-3`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-white`,children:S}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:o(`forecast.spoolCount`,{count:e.totalSpools})})]}),(0,K.jsxs)(`td`,{className:`px-4 py-3 min-w-[120px]`,children:[(0,K.jsx)(`div`,{className:`h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden mb-1 w-24`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full ${w>50?`bg-bambu-green`:w>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(w,100)}%`}})}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(e.totalRemainingG),`g`]})]}),(0,K.jsxs)(`td`,{className:`px-4 py-3`,children:[(0,K.jsx)(`div`,{className:`text-sm text-white`,children:e.dailyRateG===null?`—`:`${e.dailyRateG.toFixed(1)}g/d`}),(0,K.jsx)(`div`,{className:`mt-0.5`,children:O})]}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-semibold ${T}`,children:e.daysRemaining===null?(0,K.jsx)(`span`,{className:`text-bambu-gray font-normal`,children:`—`}):`${e.daysRemaining}d`})}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.projectedEmptyDate?W7(e.projectedEmptyDate):`—`})}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-medium ${!x&&e.reorderAlert?`text-yellow-400`:`text-bambu-gray`}`,children:e.reorderTriggerDate?W7(e.reorderTriggerDate):`—`})}),(0,K.jsx)(`td`,{className:`px-4 py-3`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[n&&(0,K.jsx)(`button`,{onClick:i,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:o(`forecast.addToCart`),children:(0,K.jsx)(Ul,{className:`w-4 h-4`})}),!x&&(e.stockBreakAlert?(0,K.jsx)(vu,{className:`w-4 h-4 text-red-400`,"aria-label":o(`forecast.stockBreakRisk`)}):e.reorderAlert?(0,K.jsx)(vu,{className:`w-4 h-4 text-yellow-400`,"aria-label":o(`forecast.reorderNow`)}):e.daysRemaining===null?null:(0,K.jsx)($o,{className:`w-4 h-4 text-bambu-green/50`})),n&&(0,K.jsx)(`button`,{onClick:D,className:`p-1 rounded transition-colors ${x?`text-bambu-gray/70 hover:text-white`:`text-bambu-dark-tertiary hover:text-bambu-gray`}`,title:o(x?`forecast.alertsEnabled`:`forecast.alertsSnoozed`),children:(0,K.jsx)(Fo,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),c(e=>!e)},className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,children:s?(0,K.jsx)(rs,{className:`w-4 h-4`}):(0,K.jsx)(es,{className:`w-4 h-4`})})]})})]}),s&&(0,K.jsx)(`tr`,{className:`bg-bambu-dark-tertiary/10`,children:(0,K.jsx)(`td`,{colSpan:8,className:`px-6 py-4`,children:(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,K.jsx)(q7,{label:o(`forecast.effectiveLeadTime`),value:`${e.effectiveLeadTimeDays}d`,hint:o(`forecast.effectiveLeadTimeHint`,{global:t,sku:e.settings?.lead_time_days??0})}),(0,K.jsx)(q7,{label:o(`forecast.safetyMarginLabel`),value:`${Math.round(e.safetyStockG)}g`,hint:o(`forecast.safetyMarginHint`)}),(0,K.jsx)(q7,{label:o(`forecast.reorderPoint`),value:`${Math.round(e.reorderPointG)}g`,hint:o(`forecast.reorderPointHint`)})]}),n&&(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,K.jsx)(nVe,{label:o(`forecast.skuLeadTimeOverride`),hint:o(`forecast.skuLeadTimeHint`),unit:o(`forecast.leadTime`),editing:l,value:e.settings?.lead_time_days??0,inputValue:p,onInputChange:m,onEdit:()=>{m(String(e.settings?.lead_time_days??0)),u(!0)},onSave:()=>{let t=parseInt(p,10);!isNaN(t)&&t>=0&&(E(t,e.settings?.safety_margin_value??14,_),u(!1))},onCancel:()=>u(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`)}),(0,K.jsx)(rVe,{value:e.settings?.safety_margin_value??14,unit:_,editing:d,inputValue:h,dailyRateG:e.dailyRateG,onInputChange:g,onUnitChange:e=>v(e),onEdit:()=>{g(String(e.settings?.safety_margin_value??14)),v(e.settings?.safety_margin_unit??`days`),f(!0)},onSave:()=>{let t=parseInt(h,10);!isNaN(t)&&t>=0&&(E(e.settings?.lead_time_days??0,t,_),f(!1))},onCancel:()=>f(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`),safetyMarginLabel:o(`forecast.safetyMarginLabel`)})]}),e.group.spools.length>1&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:o(`forecast.individualSpools`)}),(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:`#`}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.remaining`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.used`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`forecast.labelWeight`)})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:e.group.spools.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used),n=e.label_weight>0?t/e.label_weight*100:0;return(0,K.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray/70`,children:[`#`,e.id]})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-24 h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full ${n>50?`bg-bambu-green`:n>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(n,100)}%`}})}),(0,K.jsxs)(`span`,{className:`text-sm text-white`,children:[Math.round(t),`g`]})]})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[Math.round(Math.max(0,e.weight_used-(e.weight_used_baseline??0))),`g`]})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.label_weight,`g`]})})]},e.id)})})]})})]})]})})})]})}function q7({label:e,value:t,hint:n}){return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3`,title:n,children:[(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mb-1`,children:e}),(0,K.jsx)(`div`,{className:`text-lg font-semibold text-white`,children:t})]})}function nVe({label:e,hint:t,unit:n,editing:r,value:i,inputValue:a,onInputChange:o,onEdit:s,onSave:c,onCancel:l,isPending:u,saveLabel:d=`Save`,cancelLabel:f=`Cancel`}){return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-white`,children:e}),(0,K.jsx)(`span`,{title:t,children:(0,K.jsx)(kc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),r?(0,K.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,K.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:u}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,K.jsx)(`button`,{type:`submit`,disabled:u,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:d}),(0,K.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:i}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,K.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(fl,{className:`w-3 h-3`})})]})]})}function rVe({value:e,unit:t,editing:n,inputValue:r,dailyRateG:i,onInputChange:a,onUnitChange:o,onEdit:s,onSave:c,onCancel:l,isPending:u,saveLabel:d=`Save`,cancelLabel:f=`Cancel`,safetyMarginLabel:p=`Safety Margin`}){let{t:m}=G(),h=t===`g`?e:i===null?null:Math.round(i*e),g=t===`days`?m(`forecast.safetyMarginHintDays`,{approx:h===null?``:m(`forecast.safetyMarginHintDaysApprox`,{g:h})}):m(`forecast.safetyMarginHintG`,{approx:i===null?``:m(`forecast.safetyMarginHintGApprox`,{days:Math.round(e/i)})});return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-white`,children:p}),(0,K.jsx)(`span`,{title:g,children:(0,K.jsx)(kc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),n?(0,K.jsxs)(`form`,{className:`flex items-center gap-2 flex-wrap`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,K.jsx)(`input`,{type:`number`,min:0,max:t===`g`?1e4:365,value:r,onChange:e=>a(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:u}),(0,K.jsxs)(`div`,{className:`flex bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded overflow-hidden text-xs`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>o(`days`),className:`px-2 py-1 transition-colors ${t===`days`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`days`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>o(`g`),className:`px-2 py-1 transition-colors ${t===`g`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`g`})]}),(0,K.jsx)(`button`,{type:`submit`,disabled:u,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:d}),(0,K.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:e}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t}),h!==null&&t===`days`&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray/60`,children:[`≈ `,h,`g`]}),t===`g`&&i!==null&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray/60`,children:[`≈ `,Math.round(e/i),`d`]}),(0,K.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(fl,{className:`w-3 h-3`})})]})]})}function iVe({items:e,forecasts:t,globalLeadTime:n,canWrite:r,onClose:i,onRemove:a,onClear:o}){let{t:s}=G(),c=Qa(),[l,u]=(0,y.useState)(`list`),d=J({mutationFn:async({id:e,status:t,item:n,avgSpoolG:r})=>{if(await Q.updateShoppingListStatus(e,t),t===`received`&&n){let t=r??1e3,i={material:n.material,subtype:n.subtype,brand:n.brand,label_weight:t,core_weight:0,core_weight_catalog_id:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,nozzle_temp_min:null,nozzle_temp_max:null,note:n.note??null,tag_uid:null,tray_uuid:null,data_origin:`manual`,tag_type:null,cost_per_kg:null,last_scale_weight:null,last_weighed_at:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,added_full:null,last_used:null,encode_time:null,category:`Stock`,low_stock_threshold_pct:null};await Q.bulkCreateSpools(i,n.quantity_spools),await Q.removeFromShoppingList(e)}},onSuccess:()=>{c.invalidateQueries({queryKey:[`shopping-list`]}),c.invalidateQueries({queryKey:[`spools`]})}}),f=(0,y.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.group.key,n);return e},[t]),p=(0,y.useMemo)(()=>e.map(e=>({item:e,forecast:f.get(H7(e.material,e.subtype,e.brand))??null})),[e,f]),m=(0,y.useMemo)(()=>p.filter(({forecast:e})=>!e||e.dailyRateG===null?!1:e.stockBreakAlert||e.daysRemaining!==null&&e.daysRemaining<=e.effectiveLeadTimeDays),[p]);function h(){let t=[s(`forecast.qty`),s(`forecast.material`),`Brand`,`Subtype`,`${s(`forecast.weight`)} (g)`,`${s(`forecast.leadTime`)} (d)`,s(`forecast.expectedRestock`),s(`forecast.status`),s(`forecast.note`)],r=e.map(e=>{let t=f.get(H7(e.material,e.subtype,e.brand))??null,r=t&&t.totalSpools>0?t.totalLabelG/t.totalSpools:1e3,i=Math.round(e.quantity_spools*r),a=t?.effectiveLeadTimeDays??n??0,o=a>0?W7(U7(new Date,a)):``;return[e.quantity_spools,e.material,e.brand??``,e.subtype??``,i,a||``,o,e.status,e.note??``].map(e=>`"${String(e).replace(/"/g,`""`)}"`).join(`,`)}),i=[t.join(`,`),...r].join(` -`),a=new Blob([i],{type:`text/csv`}),o=URL.createObjectURL(a),c=document.createElement(`a`);c.href=o,c.download=`shopping-list-${new Date().toISOString().slice(0,10)}.csv`,c.click(),setTimeout(()=>URL.revokeObjectURL(o),100)}return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(Ul,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:s(`forecast.shoppingList`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:s(`forecast.shoppingListItems`,{count:e.length})}),e.length>0&&(0,K.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-md p-0.5 ml-1`,children:[(0,K.jsxs)(`button`,{onClick:()=>u(`list`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${l===`list`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(cl,{className:`w-3 h-3`}),s(`forecast.listView`)]}),(0,K.jsxs)(`button`,{onClick:()=>u(`logistics`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${l===`logistics`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(Zo,{className:`w-3 h-3`}),s(`forecast.logisticsView`),m.length>0&&(0,K.jsx)(`span`,{className:`w-3.5 h-3.5 rounded-full bg-red-500 text-white text-[9px] font-bold flex items-center justify-center`,children:m.length})]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`button`,{onClick:h,className:`flex items-center gap-1.5 text-xs text-bambu-gray hover:text-white transition-colors px-2 py-1 rounded border border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`,children:[(0,K.jsx)(Is,{className:`w-3 h-3`}),s(`forecast.downloadCsv`)]}),r&&(0,K.jsx)(`button`,{onClick:o,className:`text-xs text-red-400 hover:text-red-300 transition-colors px-2 py-1 rounded border border-red-500/20 hover:bg-red-500/10`,children:s(`forecast.clearAll`)})]}),(0,K.jsx)(`button`,{onClick:i,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]})]}),e.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center py-8 text-bambu-gray`,children:[(0,K.jsx)(cl,{className:`w-8 h-8 mb-2 opacity-30`}),(0,K.jsx)(`p`,{className:`text-sm`,children:s(`forecast.shoppingListEmpty`)})]}):l===`list`?(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.qty`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.material`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.weight`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.leadTime`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.expectedRestock`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.status`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.note`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-right text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.actions`)})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:e.map(e=>{let t=[e.brand,e.material,e.subtype].filter(Boolean).join(` `),i=m.some(t=>t.item.id===e.id),o=f.get(H7(e.material,e.subtype,e.brand))??null,c=o&&o.totalSpools>0?o.totalLabelG/o.totalSpools:1e3,l=Math.round(e.quantity_spools*c),u=o?.effectiveLeadTimeDays??n??0,p=u>0?U7(new Date,u):null,h=e.status===`purchased`||e.status===`received`,g=e.status===`received`,_=d.isPending;return(0,K.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors ${i&&!h?`bg-red-500/5`:``}`,children:[(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsxs)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:[e.quantity_spools,`×`]})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:t}),i&&!h&&(0,K.jsx)(vu,{className:`w-3.5 h-3.5 text-red-400 flex-shrink-0`,"aria-label":s(`forecast.stockBreakBefore`)})]})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`text-sm text-white`,children:l>=1e3?`${(l/1e3).toFixed(1)}kg`:`${l}g`})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:u>0?`${u}d`:`—`})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:p?W7(p):`—`})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${g?`bg-bambu-green/20 text-bambu-green`:h?`bg-blue-400/20 text-blue-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:s(g?`forecast.received`:h?`forecast.purchased`:`forecast.pending`)})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.note||`—`})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`div`,{className:`flex items-center justify-end gap-1`,children:r&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:()=>d.mutate({id:e.id,status:h?`pending`:`purchased`}),disabled:_||g,title:s(h?`forecast.resetToPending`:`forecast.markPurchased`),className:`p-1 rounded transition-colors disabled:opacity-30 ${h?`text-blue-400 hover:text-bambu-gray`:`text-bambu-gray hover:text-blue-400`}`,children:h?(0,K.jsx)(Tl,{className:`w-3.5 h-3.5`}):(0,K.jsx)(ks,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{onClick:()=>d.mutate({id:e.id,status:`received`,item:e,avgSpoolG:c}),disabled:_||!h||g,title:s(`forecast.markReceived`),className:`p-1 rounded transition-colors text-bambu-gray hover:text-bambu-green disabled:opacity-30`,children:(0,K.jsx)(ol,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{onClick:()=>a(e.id),className:`p-1 text-bambu-gray hover:text-red-400 transition-colors`,title:s(`forecast.remove`),children:(0,K.jsx)(hu,{className:`w-3.5 h-3.5`})})]})})})]},e.id)})})]})}):(0,K.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:p.filter(({item:e})=>e.status!==`received`).map(({item:e,forecast:t})=>(0,K.jsx)(aVe,{item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:()=>a(e.id)},e.id))})]})}function aVe({item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:i}){let{t:a}=G(),o=[e.brand,e.material,e.subtype].filter(Boolean).join(` `),s=(0,y.useMemo)(()=>{if(!t||t.dailyRateG===null||t.dailyRateG<=0)return null;let n=t.dailyRateG,r=t.effectiveLeadTimeDays,i=t.totalSpools>0?t.totalLabelG/t.totalSpools:1e3,a=e.quantity_spools*i,o=Math.max(0,t.totalRemainingG-n*r),s=o+a,c=Math.ceil(s/n),l=Math.min(r+c+5,365),u=[];for(let e=0;e<=l;e++){let i=G7(U7(new Date,e));if(e===r)u.push({day:e,label:i,stock:Math.round(o),rop:Math.round(t.reorderPointG),safetyStock:Math.round(t.safetyStockG)}),u.push({day:e,label:i,stock:Math.round(s),rop:Math.round(t.reorderPointG),safetyStock:Math.round(t.safetyStockG),arrival:!0});else{let a=e{if(!t||t.dailyRateG===null||t.dailyRateG<=0)return null;let e=Math.floor(t.totalRemainingG/t.dailyRateG);return ee>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:44}),(0,K.jsx)(Xz,{contentStyle:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:11},labelStyle:{color:`#9CA3AF`},formatter:(e,t)=>typeof e==`number`?t===`stock`?`${e}g — ${a(`forecast.stock`)}`:t===`rop`?`${e}g — ${a(`forecast.reorderPoint`)}`:t===`safetyStock`?`${e}g — ${a(`forecast.safetyMarginLabel`)}`:`${e}`:``}),(0,K.jsx)(MW,{type:`linear`,dataKey:`stock`,stroke:`#1DB954`,strokeWidth:2,fill:`url(#cart-post-${e.id})`,dot:!1,activeDot:{r:3}}),t.reorderPointG>0&&(0,K.jsx)(PU,{y:t.reorderPointG,stroke:`#F59E0B`,strokeDasharray:`5 3`,strokeOpacity:.8,label:{value:`ROP`,position:`insideTopRight`,fill:`#F59E0B`,fontSize:9}}),t.safetyStockG>0&&(0,K.jsx)(PU,{y:t.safetyStockG,stroke:`#6B7280`,strokeDasharray:`3 3`,strokeOpacity:.6,label:{value:`SS`,position:`insideTopRight`,fill:`#6B7280`,fontSize:9}}),(0,K.jsx)(PU,{x:G7(U7(new Date,s.lt)),stroke:`#3B82F6`,strokeWidth:1.5,strokeDasharray:`4 3`,strokeOpacity:.9,label:{value:`+${s.arrivalG>=1e3?`${(s.arrivalG/1e3).toFixed(1)}kg`:`${Math.round(s.arrivalG)}g`} arrives (d${s.lt})`,position:`insideTopLeft`,fill:`#3B82F6`,fontSize:9}}),c!==null&&(0,K.jsx)(PU,{x:G7(U7(new Date,c)),stroke:`#EF4444`,strokeWidth:1.5,strokeOpacity:.9,label:{value:`OUT`,position:`insideTopLeft`,fill:`#EF4444`,fontSize:9}})]})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mt-2 text-[10px] text-bambu-gray`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-yellow-400 border-dashed`}),` `,a(`forecast.ropLabel`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`inline-block w-4 border-t border-bambu-gray border-dashed`}),` `,a(`forecast.safetyStockLegend`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-blue-400 border-dashed`}),` `,a(`forecast.stockArrivalLegend`)]}),l&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-red-400`,children:[(0,K.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-red-400`}),` `,a(`forecast.stockoutLegend`)]})]})]}):null]})}function oVe({forecast:e,onClose:t,onAdd:n}){let{t:r}=G(),i=[e.group.brand,e.group.material,e.group.subtype].filter(Boolean).join(` `),[a,o]=(0,y.useState)(`qty`),[s,c]=(0,y.useState)(`1`),[l,u]=(0,y.useState)(`30`),[d,f]=(0,y.useState)(``),p=(0,y.useMemo)(()=>{if(!e.dailyRateG||e.dailyRateG<=0)return null;let t=e.dailyRateG*Number(l),n=e.group.spools.length>0?e.group.spools.reduce((e,t)=>e+t.label_weight,0)/e.group.spools.length:1e3;return Math.ceil(t/n)},[e,l]),m=a===`qty`?parseInt(s,10)||1:p??1;function h(t){t.preventDefault(),n({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,quantity_spools:m,note:d||null})}return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-2xl border border-bambu-dark-tertiary w-full max-w-sm shadow-2xl`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-5 pt-5 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Ul,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-base font-semibold text-white`,children:r(`forecast.addToCartTitle`)})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`form`,{onSubmit:h,className:`p-5 space-y-4`,children:[(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:i}),(0,K.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>o(`qty`),className:`flex-1 py-1.5 text-xs font-medium rounded-md transition-colors ${a===`qty`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:r(`forecast.byQuantity`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>o(`duration`),className:`flex-1 py-1.5 text-xs font-medium rounded-md transition-colors ${a===`duration`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:r(`forecast.byDuration`)})]}),a===`qty`?(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.numberOfSpools`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:99,value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,autoFocus:!0})]}):(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.lastHowManyDays`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:365,value:l,onChange:e=>u(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,autoFocus:!0})]}),e.dailyRateG===null?(0,K.jsx)(`div`,{className:`text-xs text-yellow-400 px-1`,children:r(`forecast.noUsageQty`)}):(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary/50 rounded-lg`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`≈`}),(0,K.jsx)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:r(`forecast.spoolCount`,{count:p??0})}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`at `,e.dailyRateG.toFixed(1),`g/day`]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.noteOptional`)}),(0,K.jsx)(`input`,{type:`text`,maxLength:200,value:d,onChange:e=>f(e.target.value),placeholder:r(`forecast.notePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/40 focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,K.jsx)(`button`,{type:`submit`,className:`flex-1 py-2 bg-bambu-green text-white text-sm font-medium rounded-lg hover:bg-bambu-green/80 transition-colors`,children:r(`forecast.addNSpools`,{count:m})}),(0,K.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 text-sm text-bambu-gray hover:text-white border border-bambu-dark-tertiary rounded-lg transition-colors`,children:r(`forecast.cancel`)})]})]})]})})}var J7={material:``,subtype:``,brand:``,color_name:``,rgba:`808080FF`,extra_colors:``,effect_type:``,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:``,note:``,cost_per_kg:null,category:``,low_stock_threshold_pct:null,location_id:null,spoolman_filament_id:null},sVe=new Set([`material`,`subtype`,`brand`,`rgba`,`color_name`,`label_weight`]);function Y7(e,t=!1,n=!1){let r={};return t||n?(!e.material&&!e.spoolman_filament_id&&(r.material=`Material is required`),{isValid:Object.keys(r).length===0,errors:r}):(e.slicer_filament||(r.slicer_filament=`Slicer preset is required`),e.material||(r.material=`Material is required`),e.brand||(r.brand=`Brand is required`),e.subtype||(r.subtype=`Subtype is required`),{isValid:Object.keys(r).length===0,errors:r})}function X7({formData:e,updateField:t,cloudAuthenticated:n,loadingCloudPresets:r,presetInputValue:i,setPresetInputValue:a,selectedPresetOption:o,filamentOptions:s,availableBrands:c,availableMaterials:l,quickAdd:u,quantity:d,onQuantityChange:f,errors:p}){let{t:m}=G(),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(``),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(String(e.label_weight)),[M,N]=(0,y.useState)(!1),P=(0,y.useRef)(null),F=(0,y.useRef)(null),I=(0,y.useRef)(null),L=(0,y.useRef)(null);(0,y.useEffect)(()=>{let e=e=>{P.current&&!P.current.contains(e.target)&&g(!1),L.current&&!L.current.contains(e.target)&&C(!1),F.current&&!F.current.contains(e.target)&&v(!1),I.current&&!I.current.contains(e.target)&&x(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let R=(0,y.useMemo)(()=>{if(!i)return s;let e=i.toLowerCase();return s.filter(t=>t.displayName.toLowerCase().includes(e)||t.code.toLowerCase().includes(e))},[s,i]),z=(0,y.useMemo)(()=>{if(!w)return c;let e=w.toLowerCase();return c.filter(t=>t.toLowerCase().includes(e)).sort((t,n)=>{let r=t.toLowerCase()===e,i=n.toLowerCase()===e;return r&&!i?-1:!r&&i?1:t.localeCompare(n)})},[c,w]),B=(0,y.useMemo)(()=>{if(!E)return oK;let e=E.toLowerCase();return oK.filter(t=>t.toLowerCase().includes(e))},[E]),V=(0,y.useMemo)(()=>{if(!O)return l;let e=O.toLowerCase();return l.filter(t=>t.toLowerCase().includes(e)).sort((t,n)=>{let r=t.toLowerCase()===e,i=n.toLowerCase()===e;return r&&!i?-1:!r&&i?1:t.localeCompare(n)})},[O,l]);(0,y.useEffect)(()=>{M||j(String(e.label_weight))},[e.label_weight,M]);let ee=e=>{t(`slicer_filament`,e.code),a(e.displayName),g(!1);let n=uK(e.name);n.material&&t(`material`,n.material),n.brand&&t(`brand`,n.brand),n.variant&&t(`subtype`,n.variant)};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[!u&&(0,K.jsx)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:r?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}),` `,m(`inventory.loadingPresets`)]}):n?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ys,{className:`w-3 h-3 text-bambu-green`}),` `,m(`inventory.cloudConnected`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(vs,{className:`w-3 h-3`}),` `,m(`inventory.cloudNotConnected`)]})}),!u&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[m(`inventory.slicerPreset`),` *`]}),(0,K.jsxs)(`div`,{className:`relative`,ref:P,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),(0,K.jsx)(`input`,{type:`text`,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:m(`inventory.searchPresets`),value:i,onChange:e=>{a(e.target.value),g(!0)},onFocus:()=>{g(!0),a(``)}}),h&&(0,K.jsx)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:R.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:m(`inventory.noPresetsFound`)}):R.map(e=>(0,K.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary truncate ${o?.code===e.code?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>ee(e),children:e.displayName},`${e.code}::${e.name}`))})]}),o&&(0,K.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray`,children:[m(`inventory.selectedPreset`),`: `,(0,K.jsx)(`span`,{className:`font-mono text-bambu-green`,children:o.code})]}),p?.slicer_filament&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-400`,children:p.slicer_filament})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[m(`inventory.material`),` *`]}),(0,K.jsxs)(`div`,{className:`relative`,ref:L,children:[(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 text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:m(`inventory.selectMaterial`),value:S?O:e.material,onChange:e=>{k(e.target.value),C(!0)},onFocus:()=>{C(!0),k(``)}}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),S&&(0,K.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[V.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:m(`inventory.noResults`)}):V.map(n=>(0,K.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.material===n?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{t(`material`,n),C(!1),k(``)},children:n},n)),O&&!V.includes(O)&&(0,K.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{t(`material`,O),C(!1),k(``)},children:m(`inventory.useCustomMaterial`,{material:O})})]})]}),p?.material&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-400`,children:p.material})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[m(`inventory.brand`),!u&&` *`]}),(0,K.jsxs)(`div`,{className:`relative`,ref:F,children:[(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 text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:m(`inventory.searchBrand`),value:_?w:e.brand,onChange:e=>{T(e.target.value),v(!0)},onFocus:()=>{v(!0),T(``)}}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),_&&(0,K.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[z.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:m(`inventory.noResults`)}):z.map(n=>(0,K.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.brand===n?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{t(`brand`,n),v(!1),T(``)},children:n},n)),w&&!z.includes(w)&&(0,K.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{t(`brand`,w),v(!1),T(``)},children:m(`inventory.useCustomBrand`,{brand:w})})]})]}),p?.brand&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-400`,children:p.brand})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[m(`inventory.subtype`),!u&&` *`]}),(0,K.jsxs)(`div`,{className:`relative`,ref:I,children:[(0,K.jsx)(`input`,{type:`text`,value:b?E:e.subtype,onChange:e=>{D(e.target.value),x(!0)},onFocus:()=>{x(!0),D(``)},placeholder:`Basic, Matte, Silk...`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),b&&(0,K.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[B.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:m(`inventory.noResults`)}):B.map(n=>(0,K.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.subtype===n?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{t(`subtype`,n),x(!1),D(``)},children:n},n)),E&&!oK.some(e=>e.toLowerCase()===E.toLowerCase().trim())&&(0,K.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{t(`subtype`,E),x(!1),D(``)},children:m(`inventory.useCustomBrand`,{brand:E})})]})]}),p?.subtype&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-400`,children:p.subtype})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:m(`inventory.labelWeight`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{type:`number`,className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:A,min:0,onFocus:()=>N(!0),onChange:e=>j(e.target.value),onBlur:()=>{N(!1);let n=A.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0){j(String(e.label_weight));return}let i=Math.round(r);t(`label_weight`,i),j(String(i))}}),(0,K.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]})]}),u&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:m(`inventory.quantity`)}),(0,K.jsx)(`input`,{type:`number`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:d,min:1,max:100,onChange:e=>{f(Math.max(1,Math.min(100,parseInt(e.target.value)||1)))}})]})]})}function cVe(e){let t=e.split(/[\s,]+/).map(e=>e.trim().replace(/^#/,``)).filter(Boolean),n=[],r=[];for(let e of t)(e.length===6||e.length===8)&&/^[0-9a-fA-F]+$/.test(e)?n.push(e.toLowerCase()):r.push(e);return{value:n.join(`,`),invalid:r}}function Z7({formData:e,updateField:t,recentColors:n,onColorUsed:r,catalogColors:i}){let{t:a}=G(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(``),u=(e.rgba.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),d=u.substring(0,6),f=u.substring(6,8)===`00`,[p,m]=(0,y.useState)(f?u:d);(0,y.useEffect)(()=>{m(f?u:d)},[d,u,f]);let h=e=>u===(e.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),g=e=>Wd(e),_=(e,n,i,a)=>{let o=e.replace(`#`,``).toUpperCase();if(t(`rgba`,o.length===8?o:o+`FF`),t(`color_name`,n),i!==void 0){let e=i??``;w(e),E([]),D.current=e,t(`extra_colors`,e)}a!==void 0&&t(`effect_type`,a??``),r({name:n,hex:e})},v=(0,y.useMemo)(()=>{if(i.length===0)return[];let t=e.brand?.trim(),n=e.material?.toLowerCase().trim(),r=e.subtype?.toLowerCase().trim();if(!t&&!n)return[];let a=t?t.toLowerCase().split(/[\s\-_]+/).filter(e=>e.length>=2):[],o=e=>{if(a.length===0)return!0;let t=e.toLowerCase();return a.some(e=>t.includes(e))};if(t&&!n){let e=i.filter(e=>o(e.manufacturer));if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}))}let s=n&&r?`${n} ${r}`:``;if(s){let e=i.filter(e=>o(e.manufacturer)&&e.material?.toLowerCase()===s);if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}));let t=s.replace(/\+$/,``);if(t!==s){let e=i.filter(e=>o(e.manufacturer)&&e.material?.toLowerCase()===t);if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0}))}}if(n){let e=i.filter(e=>o(e.manufacturer)&&(!e.material||e.material.toLowerCase().startsWith(n)));if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}))}return[]},[i,e.brand,e.material,e.subtype]),b=(0,y.useMemo)(()=>{if(!c)return v;if(v.length===0)return[];let e=c.toLowerCase();return v.filter(t=>t.name.toLowerCase().includes(e)||(t.manufacturer?.toLowerCase().includes(e)??!1)||(t.material?.toLowerCase().includes(e)??!1))},[c,v]),x=v.length>0,S=(0,y.useMemo)(()=>c?cK.filter(e=>e.name.toLowerCase().includes(c.toLowerCase())):o?cK:sK,[c,o]),[C,w]=(0,y.useState)(e.extra_colors),[T,E]=(0,y.useState)([]),D=(0,y.useRef)(e.extra_colors);(0,y.useEffect)(()=>{e.extra_colors!==D.current&&(w(e.extra_colors),E([]),D.current=e.extra_colors)},[e.extra_colors]);let O=(0,y.useMemo)(()=>G5({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`bar`}),[e.rgba,e.extra_colors,e.effect_type,e.subtype]),k=e=>{if(w(e),!e.trim()){E([]),D.current=``,t(`extra_colors`,``);return}let{value:n,invalid:r}=cVe(e);E(r),D.current=n,t(`extra_colors`,n)};return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`div`,{className:`h-10 rounded-lg border border-bambu-dark-tertiary`,style:O,"data-testid":`color-preview-banner`}),n.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-bambu-gray shrink-0`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{children:a(`inventory.recentColors`)})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:n.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(e.hex),title:e.name},e.hex))})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),(0,K.jsx)(`input`,{type:`text`,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.searchColors`),value:c,onChange:e=>l(e.target.value)})]}),x?(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:c?a(`inventory.searchResults`):`${e.brand}${e.material?` ${e.material}`:``}`}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[b.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name,e.extra_colors,e.effect_type),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(e.hex),title:e.manufacturer&&e.material?`${e.name} (${e.manufacturer} — ${e.material})`:e.manufacturer?`${e.name} (${e.manufacturer})`:e.name,children:(0,K.jsx)(`span`,{className:`absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white`,children:e.manufacturer&&e.material?`${e.name} (${e.manufacturer} — ${e.material})`:e.manufacturer?`${e.name} (${e.manufacturer})`:e.name})},`${e.hex}-${e.name}-${e.manufacturer??``}`)),b.length===0&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:a(`inventory.noColorsFound`)})]})]}):(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:a(c?`inventory.searchResults`:o?`inventory.allColors`:`inventory.commonColors`)}),!c&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>s(!o),className:`flex items-center gap-1 hover:text-white transition-colors`,children:o?(0,K.jsxs)(K.Fragment,{children:[a(`inventory.showLess`),` `,(0,K.jsx)(rs,{className:`w-3 h-3`})]}):(0,K.jsxs)(K.Fragment,{children:[a(`inventory.showAll`),` `,(0,K.jsx)(es,{className:`w-3 h-3`})]})})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[S.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(e.hex),title:e.name,children:(0,K.jsx)(`span`,{className:`absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white`,children:e.name})},e.hex)),S.length===0&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:a(`inventory.noColorsFound`)})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.colorName`)}),(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 text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.colorNamePlaceholder`),value:e.color_name,onChange:e=>t(`color_name`,e.target.value)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.hexColor`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`,children:`#`}),(0,K.jsx)(`input`,{type:`text`,className:`w-full pl-7 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono uppercase focus:outline-none focus:border-bambu-green`,placeholder:`RRGGBB`,value:p.toUpperCase(),onChange:e=>{let n=e.target.value.replace(`#`,``).replace(/[^0-9A-Fa-f]/g,``).toUpperCase(),r=n.length>8?n.substring(0,8):n;m(r),r.length===6?t(`rgba`,r+`FF`):r.length===8&&t(`rgba`,r)},onBlur:()=>{if(p.length===7){let e=p+`0`;m(e),t(`rgba`,e)}else if(p.length>0&&p.length<6){let e=p.padEnd(6,`0`);m(e),t(`rgba`,e+`FF`)}}})]}),(0,K.jsx)(`input`,{type:`color`,className:`w-11 h-[38px] rounded-lg cursor-pointer border border-bambu-dark-tertiary shrink-0 bg-transparent`,value:`#${d}`,onChange:e=>{t(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`)},title:a(`inventory.pickColor`)})]})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-2 border-t border-bambu-dark-tertiary/50`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.extraColorsLabel`)}),(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 text-sm font-mono placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.extraColorsPlaceholder`),value:C,onChange:e=>k(e.target.value),"data-testid":`extra-colors-input`}),T.length>0&&(0,K.jsx)(`p`,{className:`text-xs text-red-400 mt-1`,children:a(`inventory.extraColorsInvalid`,{tokens:T.join(`, `)})}),!T.length&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:a(`inventory.extraColorsHint`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1 flex items-center gap-1.5`,children:[(0,K.jsx)(Ql,{className:`w-3.5 h-3.5`}),a(`inventory.colorEffectLabel`)]}),(0,K.jsxs)(`div`,{className:`flex gap-2 items-stretch`,children:[(0,K.jsx)(`select`,{className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:e.effect_type,onChange:e=>t(`effect_type`,e.target.value),"data-testid":`effect-type-select`,children:H5.map(e=>(0,K.jsx)(`option`,{value:e.value,children:a(e.labelKey)},e.value||`none`))}),(0,K.jsx)(K5,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`preview`,className:`w-10 h-10`,shape:`square`})]})]})]})]})}function lVe({catalog:e,value:t,onChange:n,catalogId:r,onCatalogIdChange:i}){let{t:a}=G(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(``),u=(0,y.useRef)(null),d=(0,y.useRef)(null);(0,y.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&s(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]),(0,y.useEffect)(()=>{if(e.length===0)return;let n=e.filter(e=>e.weight===t);if(r){let n=e.find(e=>e.id===r);if(n&&n.weight===t)return}n.length===1?i(n[0].id):n.length===0&&r!==null&&i(null)},[t,e,r,i]);let f=(0,y.useMemo)(()=>{if(!c)return e;let t=c.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.weight.toString().includes(t))},[e,c]),p=(0,y.useMemo)(()=>e.filter(e=>e.weight===t),[e,t]),m=(0,y.useMemo)(()=>{if(o)return c;if(r){let t=e.find(e=>e.id===r);if(t)return t.name}return p.length>0?p[0].name:``},[o,c,r,e,p]);return(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(kl,{className:`w-3.5 h-3.5 text-bambu-gray`}),a(`inventory.coreWeight`)]})}),(0,K.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 relative`,ref:u,children:[(0,K.jsx)(`input`,{ref:d,type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.searchSpoolWeight`),value:m,onFocus:()=>{s(!0),l(``)},onChange:e=>{l(e.target.value),s(!0)}}),o&&(0,K.jsx)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:f.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:a(`inventory.noResults`)}):f.map(e=>(0,K.jsxs)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex justify-between items-center ${(r?e.id===r:e.weight===t)?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{i(e.id),n(e.weight),s(!1),l(``)},children:[(0,K.jsx)(`span`,{className:`truncate`,children:e.name}),(0,K.jsxs)(`span`,{className:`font-mono text-xs text-bambu-gray ml-2 shrink-0`,children:[e.weight,`g`]})]},e.id))})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,K.jsx)(`input`,{type:`number`,className:`w-16 px-2 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm text-center font-mono focus:outline-none focus:border-bambu-green`,value:t,min:0,max:2e3,onChange:e=>{let t=parseInt(e.target.value);!isNaN(t)&&t>=0&&n(t)}}),(0,K.jsx)(`span`,{className:`text-bambu-gray text-sm`,children:`g`})]})]})]})}function Q7({formData:e,updateField:t,spoolCatalog:n,currencySymbol:r,availableCategories:i,availableLocations:a=[],onCreateLocation:o,globalLowStockThreshold:s,spoolmanMode:c=!1}){let{t:l}=G(),{showToast:u}=xd(),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(``),[S,C]=(0,y.useState)(!1),w=Math.max(0,e.label_weight-e.weight_used),T=e.core_weight+w;return(0,y.useEffect)(()=>{p||f(String(T))},[p,T]),(0,y.useEffect)(()=>{_||g(String(w))},[_,w]),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[c?(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray px-1`,children:l(`inventory.spoolWeightManagedBySpoolman`)}):(0,K.jsx)(lVe,{catalog:n,value:e.core_weight,onChange:e=>t(`core_weight`,e),catalogId:e.core_weight_catalog_id,onCatalogIdChange:e=>t(`core_weight_catalog_id`,e)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.currentWeight`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(`input`,{type:`number`,value:h,min:0,max:e.label_weight,onFocus:()=>v(!0),onChange:e=>{g(e.target.value)},onBlur:()=>{v(!1);let n=h.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0||r>e.label_weight){g(String(w));return}let i=Math.round(r);t(`weight_used`,Math.max(0,e.label_weight-i)),g(String(i))},className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,K.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:[`/ `,e.label_weight,`g`]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.measuredWeight`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(`input`,{type:`number`,value:d,min:0,onFocus:()=>m(!0),onChange:e=>{f(e.target.value)},onBlur:()=>{m(!1);let n=d.trim(),r=Number(n),i=e.core_weight,a=e.core_weight+e.label_weight;if(!n||!Number.isFinite(r)||ra){u(l(`inventory.measuredWeightError`,{min:i,max:a}),`error`),f(String(T));return}let o=Math.round(r),s=Math.max(0,Math.min(e.label_weight,o-e.core_weight));t(`weight_used`,Math.max(0,e.label_weight-s)),f(String(o))},className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,K.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:[`/ `,e.core_weight+e.label_weight,`g`]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.costPerKg`,`Cost per kg`)}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:r}),(0,K.jsx)(`input`,{type:`number`,value:e.cost_per_kg??``,min:0,step:.01,placeholder:`0.00`,onChange:e=>{t(`cost_per_kg`,e.target.value===``?null:parseFloat(e.target.value))},style:{paddingLeft:`${Math.max(2,r.length*.6+1)}rem`},className:`w-full py-2 pr-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`})]})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-category`,children:l(`inventory.category`)}),(0,K.jsx)(`input`,{id:`spool-category`,type:`text`,list:`spool-category-options`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:l(`inventory.categoryPlaceholder`),value:e.category,maxLength:50,onChange:e=>t(`category`,e.target.value)}),i.length>0&&(0,K.jsx)(`datalist`,{id:`spool-category-options`,children:i.map(e=>(0,K.jsx)(`option`,{value:e},e))})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-low-stock-threshold`,children:l(`inventory.lowStockThresholdOverride`)}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(`input`,{id:`spool-low-stock-threshold`,type:`number`,className:`w-full px-3 py-2 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`,placeholder:String(s),value:e.low_stock_threshold_pct??``,min:1,max:99,step:1,onChange:e=>{let n=e.target.value;if(n===``){t(`low_stock_threshold_pct`,null);return}let r=Number(n);Number.isFinite(r)&&t(`low_stock_threshold_pct`,Math.min(99,Math.max(1,Math.round(r))))}}),(0,K.jsx)(`span`,{className:`absolute right-3 top-1/2 -translate-y-1/2 text-xs text-bambu-gray pointer-events-none`,children:`%`})]})}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:l(`inventory.lowStockThresholdOverrideHelp`,{global:s})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.note`)}),(0,K.jsx)(`textarea`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green resize-none min-h-[80px]`,placeholder:l(`inventory.notePlaceholder`),value:e.note,onChange:e=>t(`note`,e.target.value)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-storage-location`,children:l(`inventory.storageLocation`)}),(0,K.jsxs)(`select`,{id:`spool-storage-location`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:e.location_id??``,onChange:e=>{let n=e.target.value;if(!n){t(`location_id`,null);return}t(`location_id`,Number(n))},children:[(0,K.jsx)(`option`,{value:``,children:l(`inventory.storageLocationNone`)}),a.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),o&&(0,K.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,maxLength:255,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:l(`locations.createPlaceholder`),value:b,onChange:e=>x(e.target.value)}),(0,K.jsx)(`button`,{type:`button`,className:`px-3 py-2 text-sm rounded-lg bg-bambu-dark-tertiary text-white hover:bg-bambu-gray-dark disabled:opacity-50`,disabled:!b.trim()||S,onClick:async()=>{let e=b.trim();if(!(!e||!o)){C(!0);try{let n=await o(e);n&&(t(`location_id`,n.id),x(``))}finally{C(!1)}}},children:l(`locations.addShort`)})]})]})]})}function uVe({filaments:e,isLoading:t,selectedId:n,onSelect:r}){let{t:i}=G(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(``),l=(0,y.useRef)(null),u=(0,y.useRef)(null),d=(0,y.useMemo)(()=>e.find(e=>e.id===n)??null,[e,n]);(0,y.useEffect)(()=>{let e=e=>{l.current&&!l.current.contains(e.target)&&(o(!1),c(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let f=(0,y.useMemo)(()=>{let t=s.toLowerCase().trim();return t?e.filter(e=>e.name.toLowerCase().includes(t)||(e.material?.toLowerCase().includes(t)??!1)||(e.vendor?.name.toLowerCase().includes(t)??!1)||(e.color_name?.toLowerCase().includes(t)??!1)):e},[e,s]);(0,y.useEffect)(()=>{a&&u.current?.focus()},[a]);let p=()=>{o(!0),c(``)},m=e=>{r(e),o(!1),c(``)},h=e=>e?`#${e.replace(`#`,``)}`:`#808080`;return(0,K.jsxs)(`div`,{ref:l,className:`relative`,children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:i(`inventory.pickFromSpoolmanCatalog`)}),(0,K.jsxs)(`button`,{type:`button`,onClick:p,className:`w-full flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-left focus:outline-none focus:border-bambu-green hover:border-bambu-gray transition-colors`,children:[t?(0,K.jsx)(X,{className:`w-4 h-4 text-bambu-gray animate-spin shrink-0`}):d?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:{backgroundColor:h(d.color_hex)},"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,K.jsxs)(`span`,{className:`text-white text-sm truncate flex-1`,children:[d.vendor?.name?`${d.vendor.name} — `:``,d.name]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(cl,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,K.jsx)(`span`,{className:`text-bambu-gray text-sm flex-1`,children:i(`inventory.spoolmanFilamentCatalog`)})]}),(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray shrink-0 ml-auto`})]}),a&&(0,K.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl`,children:[(0,K.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,K.jsx)(`input`,{ref:u,type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:i(`inventory.pickFromSpoolmanCatalog`),className:`w-full px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})}),(0,K.jsx)(`ul`,{className:`max-h-56 overflow-y-auto py-1`,children:t?(0,K.jsxs)(`li`,{className:`flex items-center justify-center gap-2 py-4 text-bambu-gray text-sm`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),(0,K.jsx)(`span`,{children:i(`common.loading`,`Loading…`)})]}):f.length===0?(0,K.jsx)(`li`,{className:`py-4 text-center text-bambu-gray text-sm`,children:i(`inventory.noSpoolmanFilaments`)}):f.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>m(e),className:`w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors ${e.id===n?`bg-bambu-dark-tertiary`:``}`,children:[(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:{backgroundColor:h(e.color_hex)},"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,K.jsxs)(`span`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`span`,{className:`block text-white text-sm truncate`,children:[e.vendor?.name?`${e.vendor.name} — `:``,e.name]}),(0,K.jsxs)(`span`,{className:`block text-bambu-gray text-xs truncate`,children:[[e.material,e.color_name].filter(Boolean).join(` · `),e.weight?` · ${e.weight}g`:``]})]})]})},e.id))})]})]})}function $7({formData:e,printersWithCalibrations:t,selectedProfiles:n,setSelectedProfiles:r,expandedPrinters:i,setExpandedPrinters:a}){let{t:o}=G(),s=e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},c=(e,t,n)=>{let i=`${e}:${t}:${n??`null`}`,a=`${e}:${n??`null`}`;r(e=>{let t=new Set(e);if(t.has(i))t.delete(i);else{for(let e of Array.from(t)){let n=e.split(`:`);`${n[0]}:${n[2]}`===a&&t.delete(e)}t.add(i)}return t})},l=()=>{let n=new Set;for(let{printer:r,calibrations:i}of t){if(!r.connected)continue;let t=i.filter(t=>vK(t,e)),a=new Map;for(let e of t){let t=`${e.extruder_id??`null`}`;a.has(t)||a.set(t,[]),a.get(t).push(e)}for(let[e,t]of a)if(t.length>0){let i=[...t].sort((e,t)=>t.k_value-e.k_value)[0];n.add(`${r.id}:${i.cali_idx}:${e}`)}}r(n)};if(!e.material)return(0,K.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:o(`inventory.selectMaterialFirst`)})});if(t.length===0)return(0,K.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:o(`inventory.noPrintersConfigured`)})});let u=t.reduce((t,{printer:n,calibrations:r})=>n.connected?t+r.filter(t=>vK(t,e)).length:t,0),d=(e,t)=>{let r=`${e.id}:${t.cali_idx}:${t.extruder_id??`null`}`,i=n.has(r);return(0,K.jsxs)(`label`,{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-all border ${i?`bg-bambu-green/10 border-bambu-green/30`:`bg-bambu-dark border-transparent hover:bg-bambu-dark/80`}`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:i,onChange:()=>c(String(e.id),t.cali_idx,t.extruder_id),className:`w-4 h-4 rounded border-bambu-dark-tertiary text-bambu-green focus:ring-bambu-green`}),(0,K.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,K.jsx)(`span`,{className:`text-sm font-medium ${i?`text-bambu-green`:`text-white`}`,children:t.name||t.filament_id})}),(0,K.jsx)(`div`,{className:`flex items-center gap-2 shrink-0`,children:(0,K.jsxs)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray`,children:[`K=`,t.k_value.toFixed(3)]})})]},`${t.cali_idx}-${t.extruder_id}`)};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[o(`inventory.matchingFilter`),`: `,e.brand||o(`inventory.anyBrand`),` / `,e.material,` / `,e.subtype||o(`inventory.anyVariant`)]}),u>0&&(0,K.jsxs)(`button`,{type:`button`,onClick:l,className:`flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors`,children:[(0,K.jsx)(Ql,{className:`w-3.5 h-3.5`}),o(`inventory.autoSelect`),` (`,u,`)`]})]}),(0,K.jsx)(`div`,{className:`space-y-3`,children:t.map(({printer:t,calibrations:n})=>{let r=i.has(String(t.id)),a=n.filter(t=>vK(t,e)),c=a.length,l=a.some(e=>e.extruder_id!==void 0&&e.extruder_id!==null&&e.extruder_id>0),u=a.filter(e=>e.extruder_id===1),f=a.filter(e=>e.extruder_id===0||e.extruder_id===void 0||e.extruder_id===null);return(0,K.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>s(String(t.id)),className:`w-full px-4 py-3 flex items-center justify-between bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[r?(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray`}):(0,K.jsx)(ts,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),c>0?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:[c,` `,o(c===1?`inventory.match`:`inventory.matches`)]}):(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray`,children:o(`inventory.noMatches`)})]}),(0,K.jsx)(`span`,{className:`text-xs px-2 py-1 rounded-full ${t.connected?`bg-green-500/20 text-green-500`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.connected?o(`inventory.connected`):o(`inventory.offline`)})]}),r&&(0,K.jsx)(`div`,{className:`px-4 py-3 space-y-3 bg-bambu-dark border-t border-bambu-dark-tertiary`,children:t.connected?c===0?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:o(`inventory.noKProfilesMatch`)}):l?(0,K.jsxs)(K.Fragment,{children:[u.length>0&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.leftNozzle`)}),(0,K.jsx)(`div`,{className:`space-y-2`,children:u.map(e=>d(t,e))})]}),f.length>0&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.rightNozzle`)}),(0,K.jsx)(`div`,{className:`space-y-2`,children:f.map(e=>d(t,e))})]})]}):(0,K.jsx)(`div`,{className:`space-y-2`,children:a.map(e=>d(t,e))}):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:o(`inventory.printerOffline`)})})]},t.id)})}),n.size>0&&(0,K.jsx)(`div`,{className:`p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:(0,K.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,K.jsx)(`span`,{className:`font-semibold`,children:n.size}),` `,o(`inventory.profilesSelected`)]})})]})}function dVe(e){let t=mf(e);return t?t.toLocaleDateString(`en-GB`,{day:`2-digit`,month:`2-digit`,year:`2-digit`})+` `+t.toLocaleTimeString(`en-GB`,{hour:`2-digit`,minute:`2-digit`}):``}var fVe={completed:`text-bambu-green`,failed:`text-red-400`,aborted:`text-yellow-400`};function pVe({spoolId:e}){let{t}=G(),n=Qa(),{showToast:r}=xd(),{data:i,isLoading:a}=q({queryKey:[`spool-usage`,e],queryFn:()=>Q.getSpoolUsageHistory(e)}),o=J({mutationFn:()=>Q.clearSpoolUsageHistory(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`spool-usage`,e]}),r(t(`inventory.historyCleared`),`success`)}});return a?(0,K.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,K.jsx)(X,{className:`w-5 h-5 animate-spin text-bambu-green`})}):!i||i.length===0?(0,K.jsxs)(`div`,{className:`text-center py-4 text-bambu-gray text-sm`,children:[(0,K.jsx)(_s,{className:`w-5 h-5 mx-auto mb-2 opacity-50`}),t(`inventory.noUsageHistory`)]}):(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t(`inventory.usageHistory`)}),(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>o.mutate(),disabled:o.isPending,className:`text-xs text-bambu-gray hover:text-red-400`,children:[(0,K.jsx)(hu,{className:`w-3 h-3 mr-1`}),t(`inventory.clearHistory`)]})]}),(0,K.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:i.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-2 rounded bg-bambu-dark/50 text-xs`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:dVe(e.created_at)}),e.print_name&&(0,K.jsx)(`span`,{className:`text-white ml-2 truncate`,title:e.print_name,children:e.print_name})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0 ml-2`,children:[(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[e.weight_used.toFixed(1),`g`]}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_used,`%)`]}),(0,K.jsx)(`span`,{className:fVe[e.status]||`text-bambu-gray`,children:e.status})]})]},e.id))})]})}var e9=[`inventory-locations`];function t9(e){return e.invalidateQueries({queryKey:e9})}function n9(e,t){return Promise.all([e.invalidateQueries({queryKey:[...t]}),t9(e)])}var r9={tag_uid:null,tray_uuid:null,tag_type:null,data_origin:null};function mVe({isOpen:e,onClose:t,spool:n,mode:r,printersWithCalibrations:i=[],currencySymbol:a,onSpoolsCreated:o,spoolmanMode:s=!1,spoolsQueryKey:c=[`inventory-spools`]}){let{t:l}=G(),u=Qa(),{showToast:d}=xd(),f=()=>n9(u,c),p=r===`edit`,m=r===`copy`,[h,g]=(0,y.useState)(J7),[_,v]=(0,y.useState)({}),[b,x]=(0,y.useState)(`filament`),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(1),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)([]),[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)([]),[B,V]=(0,y.useState)([]),[ee,H]=(0,y.useState)([]),[te,ne]=(0,y.useState)([]),[re,U]=(0,y.useState)([]),[ie,ae]=(0,y.useState)([]),[W,oe]=(0,y.useState)([]),[se,ce]=(0,y.useState)(new Set),[le,ue]=(0,y.useState)(new Set),de=i.length>0?i:W,fe=se.size,{data:pe=[],isLoading:me,error:he}=q({queryKey:[`spoolman-inventory-filaments`],queryFn:()=>Q.getSpoolmanInventoryFilaments(),enabled:s&&e,staleTime:6e4,retry:!1});(0,y.useEffect)(()=>{ae(mK())},[]),(0,y.useEffect)(()=>{let t=!1;return e&&((async()=>{N(!0);try{let[e,n]=await Promise.allSettled([(async()=>(await Q.getCloudStatus()).is_authenticated?{connected:!0,presets:await Q.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await Q.orcaCloudStatus()).connected?{connected:!0,presets:(await Q.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(t)return;let r=e.status===`fulfilled`&&e.value.connected,i=n.status===`fulfilled`&&n.value.connected,a=e.status===`fulfilled`?e.value.presets:[],o=n.status===`fulfilled`?n.value.presets:[];j(r||i),F([...a,...o])}catch(e){if(t)return;console.error(`Failed to fetch cloud presets:`,e),j(!1)}finally{t||N(!1)}})(),s||Q.getSpoolCatalog().then(z).catch(console.error),Q.getColorCatalog().then(U).catch(console.error),Q.getLocalPresets().then(e=>H(e.filament)).catch(console.error),Q.getBuiltinFilaments().then(ne).catch(console.error),Q.getLocations().then(e=>V(e.map(e=>({id:e.id,name:e.name})))).catch(console.error),i.length===0&&(async()=>{try{let e=await Q.getPrinters(),t=await Promise.all(e.map(e=>Q.getPrinterStatus(e.id).catch(()=>null))),n=[];for(let r=0;r({cali_idx:e.slot_id,filament_id:e.filament_id,setting_id:e.setting_id||``,name:e.name,k_value:parseFloat(e.k_value)||0,n_coef:parseFloat(e.n_coef)||0,extruder_id:e.extruder_id,nozzle_diameter:e.nozzle_diameter}))}catch{}n.push({printer:{...i,connected:a},calibrations:o})}oe(n)}catch(e){console.error(`Failed to fetch printer calibrations:`,e)}})()),()=>{t=!0}},[e,i.length]);let ge=(0,y.useMemo)(()=>fK(P,new Set,ee,te),[P,ee,te]),_e=(0,y.useMemo)(()=>{let e=dK(P,ee),t=re.map(e=>e.manufacturer?.trim()).filter(e=>!!e),n=new Set([...e,...t]);return Array.from(n).sort((e,t)=>e.localeCompare(t))},[P,ee,re]),ve=(0,y.useMemo)(()=>{let e=re.map(e=>e.material?.trim()).filter(e=>!!e),t=new Set([...aK,...e]);return Array.from(t).sort((e,t)=>e.localeCompare(t))},[re]),ye=(0,y.useMemo)(()=>{let e=[];for(let t of re){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of P){let n=uK(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of ee){let n=uK(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[P,re,ee]),be=(0,y.useMemo)(()=>{let e=new Map;for(let t of ye){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[ye]),xe=(0,y.useMemo)(()=>{let e=new Map;for(let t of ye){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[ye]),Se=(0,y.useMemo)(()=>{if(!h.material)return _e;let e=h.material.toLowerCase(),t=xe.get(e);return!t||t.size===0?_e:_e.filter(e=>t.has(e.toLowerCase()))},[_e,h.material,xe]),Ce=(0,y.useMemo)(()=>{if(!h.brand)return ve;let e=h.brand.toLowerCase(),t=be.get(e);return!t||t.size===0?ve:ve.filter(e=>t.has(e.toLowerCase()))},[ve,h.brand,be]),we=(0,y.useMemo)(()=>pK(h.slicer_filament,ge),[h.slicer_filament,ge]);(0,y.useEffect)(()=>{if(e){if(n){let e=n.rgba&&/^[0-9A-Fa-f]{8}$/.test(n.rgba)?n.rgba:`808080FF`;if(g({material:n.material||``,subtype:n.subtype||``,brand:n.brand||``,color_name:n.color_name_is_synthesized?``:n.color_name||``,rgba:e,extra_colors:n.extra_colors||``,effect_type:n.effect_type||``,label_weight:n.label_weight||1e3,core_weight:n.core_weight||250,core_weight_catalog_id:n.core_weight_catalog_id??null,weight_used:m?0:n.weight_used||0,slicer_filament:n.slicer_filament||``,note:n.note||``,cost_per_kg:n.cost_per_kg??null,category:n.category||``,low_stock_threshold_pct:n.low_stock_threshold_pct??null,location_id:n.location_id??null,spoolman_filament_id:null}),L(n.slicer_filament_name||n.slicer_filament||``),n.k_profiles&&n.k_profiles.length>0){let e=new Set;for(let t of n.k_profiles)t.cali_idx!==null&&t.cali_idx!==void 0&&e.add(`${t.printer_id}:${t.cali_idx}:${t.extruder??`null`}`);ce(e)}else ce(new Set)}else g(J7),L(``),ce(new Set),D(!1),k(1);v({}),x(`filament`),C(!1),T(!1)}},[e,n,r,m]),(0,y.useEffect)(()=>{if(!e||!n||w||h.location_id!=null)return;let t=n.storage_location?.trim();if(!t||B.length===0)return;let r=B.find(e=>e.name.toLowerCase()===t.toLowerCase());r&&g(e=>e.location_id===r.id?e:{...e,location_id:r.id})},[e,n,B,h.location_id,w]),(0,y.useEffect)(()=>{e&&de.length>0&&ue(new Set(de.map(e=>String(e.printer.id))))},[e,de]);let Te=(e,t)=>{let n=sVe.has(e);s&&n&&h.spoolman_filament_id!==null&&d(l(`inventory.spoolmanFilamentUnlinked`),`info`),g(r=>({...r,[e]:t,...s&&n&&r.spoolman_filament_id!==null?{spoolman_filament_id:null}:{}})),e===`weight_used`&&C(!0),e===`location_id`&&T(!0),_[e]&&v(t=>({...t,[e]:void 0}))},Ee=e=>{let t=e.material||``,n=e.name||``,r=t&&n.startsWith(t)?n.slice(t.length).trim():n,i=(e.color_hex??``).replace(`#`,``).toUpperCase(),a=/^[0-9A-F]{6}$/.test(i)?i:`808080`;g(n=>({...n,spoolman_filament_id:e.id,material:t,subtype:r,brand:e.vendor?.name||``,rgba:`${a}FF`,color_name:e.color_name||``,label_weight:e.weight??n.label_weight})),d(l(`inventory.spoolmanFilamentSelected`),`success`)},De=e=>{ae(t=>hK(e,t))},Oe=J({mutationFn:e=>s?Q.createSpoolmanInventorySpool(e):Q.createSpool(e),onSuccess:async e=>{e?.id&&!await Be(e.id)||(await f(),o&&o([e]),d(l(`inventory.spoolCreated`),`success`),t())},onError:e=>{e instanceof zu&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),ke=J({mutationFn:({data:e,qty:t})=>s?Q.bulkCreateSpoolmanInventorySpools(e,t):Q.bulkCreateSpools(e,t),onSuccess:async e=>{let n=s&&`created`in e?e:null,r=n?n.created:e;if(se.size>0)for(let e of r)await Be(e.id);await f(),o&&o(r),n&&n.failed_count>0?d(l(`inventory.spoolsPartiallyCreated`,{created:r.length,total:n.requested_count}),`warning`):d(l(`inventory.spoolsCreated`,{count:r.length}),`success`),t()},onError:e=>{e instanceof zu&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),Ae=J({mutationFn:e=>s?Q.updateSpoolmanInventorySpool(n.id,e):Q.updateSpool(n.id,e),onSuccess:async()=>{n?.id&&!await Be(n.id)||(await f(),d(l(`inventory.spoolUpdated`),`success`),t())},onError:e=>{e instanceof zu&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),je=J({mutationFn:()=>s?Q.updateSpoolmanInventorySpool(n.id,r9):Q.updateSpool(n.id,r9),onSuccess:async()=>{await f(),d(l(`inventory.rfidCleared`,`RFID tag cleared`),`success`),t()},onError:e=>{e instanceof zu&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.tagClearFailed`),`error`)}}),{data:Me}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),enabled:e&&p&&!s}),{data:Ne}=q({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:e&&p&&s}),Pe=(()=>{if(n)return s?Ne?.find(e=>e.spoolman_spool_id===n.id):Me?.find(e=>e.spool_id===n.id)})(),{data:Fe}=q({queryKey:[`inventory-spools`],queryFn:()=>Q.getSpools(!0),enabled:e}),{data:Ie}=q({queryKey:[`settings`],queryFn:Q.getSettings,enabled:e}),Le=(()=>{let e=new Set;for(let t of Fe??[]){let n=t.category?.trim();n&&e.add(n)}return Array.from(e).sort((e,t)=>e.localeCompare(t))})(),Re=Ie?.low_stock_threshold??20,ze=J({mutationFn:async()=>{if(!Pe)throw Error(`No assignment`);if(s){if(!n)throw Error(`No spool`);await Q.unassignSpoolmanSlot(n.id);return}await Q.unassignSpool(Pe.printer_id,Pe.ams_id,Pe.tray_id)},onSuccess:async()=>{s?(await u.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),await u.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})):await u.invalidateQueries({queryKey:[`spool-assignments`]}),d(l(`inventory.unassignSuccess`,`Spool unassigned`),`success`),t()},onError:e=>{d(e.message,`error`)}}),Be=async e=>{let t=s?Q.saveSpoolmanKProfiles:Q.saveSpoolKProfiles;if(se.size===0)try{return await t(e,[]),!0}catch(e){return console.error(`Failed to save K-profiles:`,e),d(l(`inventory.kProfileSaveFailed`),`warning`),!1}let n=[],r=0;for(let e of se){let[t,i,a]=e.split(`:`),o=parseInt(t),s=parseInt(i),c=a===`null`?0:parseInt(a),l=de.find(e=>e.printer.id===o);if(l){let e=l.calibrations.find(e=>e.cali_idx===s);e?n.push({printer_id:o,extruder:c,nozzle_diameter:e.nozzle_diameter||`0.4`,k_value:e.k_value,name:e.name||null,cali_idx:e.cali_idx,setting_id:e.setting_id||null}):r++}else r++}if(r>0)return console.error(`saveKProfiles: ${r} profile key(s) could not be resolved`,Array.from(se)),d(l(`inventory.kProfileSaveFailed`),`warning`),!1;if(n.length>0)try{return await t(e,n),!0}catch(e){return console.error(`Failed to save K-profiles:`,e),d(l(`inventory.kProfileSaveFailed`),`warning`),!1}return!0};if((0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let Ve=()=>{let e=Y7(h,E,s);if(!e.isValid){v(e.errors),(e.errors.slicer_filament||e.errors.material||e.errors.brand||e.errors.subtype)&&x(`filament`);return}let t=we?.displayName||I||null,n={material:h.material||null,subtype:h.subtype||null,brand:h.brand||null,color_name:h.color_name||null,rgba:h.rgba||null,extra_colors:h.extra_colors||null,effect_type:h.effect_type||null,label_weight:h.label_weight,...s?{}:{core_weight:h.core_weight,core_weight_catalog_id:h.core_weight_catalog_id},slicer_filament:h.slicer_filament||null,slicer_filament_name:t,nozzle_temp_min:null,nozzle_temp_max:null,note:h.note||null,cost_per_kg:h.cost_per_kg,category:h.category.trim()||null,low_stock_threshold_pct:h.low_stock_threshold_pct,...s?{spoolman_filament_id:h.spoolman_filament_id}:{}};(!p||S)&&(n.weight_used=h.weight_used),(!p||w)&&(n.location_id=h.location_id),p?Ae.mutate(n):O>1?ke.mutate({data:n,qty:O}):Oe.mutate(n)},He=Oe.isPending||ke.isPending||Ae.isPending||je.isPending||ze.isPending;return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,children:[(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)(`h2`,{className:`text-lg font-semibold text-white flex items-baseline gap-2`,children:[l(p?`inventory.editSpool`:m?`inventory.copySpool`:`inventory.addSpool`),p&&n&&(0,K.jsxs)(`span`,{className:`text-sm font-mono text-bambu-gray`,children:[`#`,n.id]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),r===`create`&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Iu,{className:`w-4 h-4 text-amber-400`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:l(`inventory.quickAdd`)})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{D(!E),E||x(`filament`)},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${E?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${E?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsxs)(`button`,{onClick:()=>x(`filament`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${b===`filament`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(ll,{className:`w-4 h-4`}),l(`inventory.filamentInfoTab`)]}),!E&&(0,K.jsxs)(`button`,{onClick:()=>x(`pa-profile`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${b===`pa-profile`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(Po,{className:`w-4 h-4`}),l(`inventory.paProfileTab`),fe>0&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:fe})]})]}),(0,K.jsx)(`div`,{className:`p-4 overflow-y-auto flex-1`,style:{scrollbarGutter:`stable`},children:b===`filament`?(0,K.jsxs)(`div`,{className:`space-y-6`,children:[s&&!p&&(0,K.jsx)(`div`,{children:he?(0,K.jsx)(`p`,{className:`text-sm text-red-400 px-1`,children:l(`inventory.spoolmanCatalogLoadFailed`)}):(0,K.jsx)(uVe,{filaments:pe,isLoading:me,selectedId:h.spoolman_filament_id,onSelect:Ee})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.filamentInfo`)}),(0,K.jsx)(X7,{formData:h,updateField:Te,cloudAuthenticated:A,loadingCloudPresets:M,presetInputValue:I,setPresetInputValue:L,selectedPresetOption:we,filamentOptions:ge,availableBrands:Se,availableMaterials:Ce,quickAdd:E,quantity:O,onQuantityChange:k,errors:_})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.color`)}),(0,K.jsx)(Z7,{formData:h,updateField:Te,recentColors:ie,onColorUsed:De,catalogColors:re})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.additional`)}),(0,K.jsx)(Q7,{formData:h,updateField:Te,spoolCatalog:R,currencySymbol:a,availableCategories:Le,availableLocations:B,onCreateLocation:async e=>{try{let t=await Q.createLocation({name:e});return V(e=>[...e,{id:t.id,name:t.name}].sort((e,t)=>e.name.localeCompare(t.name))),await t9(u),{id:t.id,name:t.name}}catch(e){return console.error(e),d((e instanceof Error?e.message:l(`locations.saveFailed`))||l(`locations.saveFailed`),`error`),null}},globalLowStockThreshold:Re,spoolmanMode:s})]}),p&&n&&!s&&(0,K.jsx)(`div`,{children:(0,K.jsx)(pVe,{spoolId:n.id})})]}):(0,K.jsx)($7,{formData:h,updateField:Te,printersWithCalibrations:de,selectedProfiles:se,setSelectedProfiles:ce,expandedPrinters:le,setExpandedPrinters:ue})}),(0,K.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[p&&(0,K.jsxs)(`div`,{className:`flex gap-2 mr-auto`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:()=>je.mutate(),disabled:He||!n?.tag_uid,children:[(0,K.jsx)(su,{className:`w-4 h-4`}),l(`inventory.clearRfid`,`Clear RFID Tag`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>ze.mutate(),disabled:He||!Pe,children:[(0,K.jsx)(xu,{className:`w-4 h-4`}),l(`inventory.unassignSpool`,`Unassign`)]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 ml-auto`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,children:l(`common.cancel`)}),(0,K.jsx)($,{onClick:Ve,disabled:He,children:He?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),l(`common.saving`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),l(p?`common.save`:m?`inventory.copySpool`:`inventory.addSpool`)]})})]})]})]})]})}function hVe({isOpen:e,onClose:t,columns:n,defaultColumns:r,onSave:i}){let{t:a}=G(),[o,s]=(0,y.useState)(n),[c,l]=(0,y.useState)(null),u=(0,y.useRef)(null);if((0,y.useEffect)(()=>{e&&s(n.map(e=>({...e})))},[e,n]),(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let d=e=>{s(t=>t.map((t,n)=>n===e?{...t,visible:!t.visible}:t))},f=(e,t)=>{t<0||t>=o.length||s(n=>{let r=[...n],[i]=r.splice(e,1);return r.splice(t,0,i),r})},p=(e,t)=>{u.current=t,l(t),e.dataTransfer.effectAllowed=`move`},m=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=u.current;n!==null&&n!==t&&(f(n,t),u.current=t,l(t))},h=e=>{e.preventDefault()},g=()=>{u.current=null,l(null)},_=()=>{s(r.map(e=>({...e})))},v=()=>{i(o),t()},b=o.filter(e=>e.visible).length;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,K.jsx)(pd,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(hd,{className:`p-6 flex flex-col min-h-0`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:a(`inventory.configureColumns`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:[a(`inventory.configureColumnsDesc`),(0,K.jsxs)(`span`,{className:`ml-2 text-bambu-gray/60`,children:[`(`,b,` `,a(`inventory.of`),` `,o.length,` `,a(`inventory.visible`),`)`]})]}),(0,K.jsx)(`div`,{className:`space-y-1 overflow-y-auto flex-1 min-h-0 pr-1`,children:o.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg border transition-colors ${c===t?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-tertiary/50`} ${e.visible?``:`opacity-50`}`,draggable:!0,onDragStart:e=>p(e,t),onDragOver:e=>m(e,t),onDrop:h,onDragEnd:g,children:[(0,K.jsx)(`div`,{className:`cursor-grab text-bambu-gray/50 hover:text-bambu-gray`,children:(0,K.jsx)(gc,{className:`w-4 h-4`})}),(0,K.jsx)(`span`,{className:`flex-1 font-medium text-sm text-white`,children:e.label}),(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,K.jsx)(`button`,{onClick:()=>f(t,t-1),disabled:t===0,className:`p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed`,title:a(`inventory.moveUp`),children:(0,K.jsx)(rs,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>f(t,t+1),disabled:t===o.length-1,className:`p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed`,title:a(`inventory.moveDown`),children:(0,K.jsx)(es,{className:`w-4 h-4`})})]}),(0,K.jsx)(`button`,{onClick:()=>d(t),className:`p-1.5 rounded transition-colors ${e.visible?`text-bambu-green hover:bg-bambu-green/10`:`text-bambu-gray/50 hover:bg-bambu-dark-secondary`}`,title:e.visible?a(`inventory.hideColumn`):a(`inventory.showColumn`),children:e.visible?(0,K.jsx)(Gs,{className:`w-4 h-4`}):(0,K.jsx)(Ws,{className:`w-4 h-4`})})]},e.id))}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:_,className:`mr-auto`,children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),a(`inventory.reset`)]}),(0,K.jsx)($,{variant:`secondary`,onClick:t,children:a(`inventory.cancel`)}),(0,K.jsx)($,{onClick:v,children:a(`inventory.applyChanges`)})]})]})})})}var gVe=[{value:`ams_holder_74x33`,i18nKey:`amsHolderSmall`,fallbackLabel:`AMS holder — small (74 × 33 mm)`,fallbackHint:`Single label per page; matches the printable label from MakerWorld model 752566 (AMS Filament Label Holder).`},{value:`ams_holder_75x55`,i18nKey:`amsHolderLarge`,fallbackLabel:`AMS holder — large (75 × 55 mm)`,fallbackHint:`Single label per page; fits the cardstock-insert variant of the AMS Filament Label Holder. Roomy enough for swatch, brand, material, ID, and QR code.`},{value:`box_40x30`,i18nKey:`box40x30`,fallbackLabel:`Box label (40 × 30 mm)`,fallbackHint:`Single label per page; common DK/Brother roll size, good for filament-bag and storage-bin labels.`},{value:`box_62x29`,i18nKey:`box`,fallbackLabel:`Box label (62 × 29 mm)`,fallbackHint:`Single label per page; sized for Brother PT/QL and Dymo small labels.`},{value:`avery_l7160`,i18nKey:`averyL7160`,fallbackLabel:`Avery L7160 — A4 sheet (38.1 × 63.5 mm × 21)`,fallbackHint:`EU sheet stock; 21 labels per A4 page.`},{value:`avery_5160`,i18nKey:`avery5160`,fallbackLabel:`Avery 5160 — US Letter sheet (25.4 × 66.7 mm × 30)`,fallbackHint:`US sheet stock; 30 labels per Letter page.`}];function _Ve(e){let t=window.URL.createObjectURL(e);if(!window.open(t,`_blank`)){let e=document.createElement(`a`);e.href=t,e.download=`bambuddy-labels.pdf`,document.body.appendChild(e),e.click(),document.body.removeChild(e)}setTimeout(()=>window.URL.revokeObjectURL(t),6e4)}function vVe(e){return Wd(e)}function yVe(e){return`${e.color_name??`${e.material}${e.subtype?` ${e.subtype}`:``}`}${e.brand?` · ${e.brand}`:``}`}function bVe(e){return[e.color_name,e.material,e.subtype,e.brand,`#${e.id}`].filter(Boolean).join(` `).toLowerCase()}function i9(e){if(!e)return[1,0];let t=e.replace(/^#/,``).slice(0,6);if(t.length!==6)return[1,0];let n=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);if([n,r,i].some(Number.isNaN))return[1,0];let a=n/255,o=r/255,s=i/255,c=Math.max(a,o,s),l=Math.min(a,o,s),u=(c+l)/2,d=c-l;if((d===0?0:d/(1-Math.abs(2*u-1)))<.1)return[1,u];let f=0;return f=c===a?(o-s)/d%6:c===o?(s-a)/d+2:(a-o)/d+4,f*=60,f<0&&(f+=360),[0,f]}function xVe({isOpen:e,onClose:t,availableSpools:n,initialSelectedIds:r,spoolmanMode:i}){let{t:a}=G(),{showToast:o}=xd(),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(new Set),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(`id`);(0,y.useEffect)(()=>{if(e){let e=new Set(n.map(e=>e.id));u(new Set(r.filter(t=>e.has(t)))),f(``),m(``),g(`id`),c(null)}},[e]);let _=(0,y.useMemo)(()=>{let e=[...n];return h===`color`?(e.sort((e,t)=>{let n=i9(e.rgba),r=i9(t.rgba);return n[0]===r[0]?n[1]===r[1]?e.id-t.id:n[1]-r[1]:n[0]-r[0]}),e):(e.sort((e,t)=>e.id-t.id),e)},[n,h]),v=(0,y.useMemo)(()=>{let e=new Set;for(let t of _)t.material&&e.add(t.material.toUpperCase());return[...e].sort()},[_]),b=(0,y.useMemo)(()=>{let e=d.trim().toLowerCase();return _.filter(t=>!(p&&(t.material||``).toUpperCase()!==p||e&&!bVe(t).includes(e)))},[_,d,p]),x=b.length>0&&b.every(e=>l.has(e.id));if(!e)return null;let S=l.size,C=S===0;function w(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function T(){u(e=>{let t=new Set(e);for(let e of b)t.add(e.id);return t})}function E(){u(e=>{let t=new Set(e);for(let e of b)t.delete(e.id);return t})}function D(){u(new Set)}async function O(e){if(C||s)return;let n=_.filter(e=>l.has(e.id)).map(e=>e.id);c(e);try{_Ve(i?await Q.printSpoolmanSpoolLabels({spool_ids:n,template:e}):await Q.printSpoolLabels({spool_ids:n,template:e})),t()}catch(e){o(a(`inventory.labels.error`,`Could not generate labels: {{msg}}`,{msg:e instanceof Error?e.message:String(e)}),`error`)}finally{c(null)}}return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-start sm:items-center justify-center p-4 overflow-y-auto`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-3xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] overflow-hidden flex flex-col my-auto`,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)(bl,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(`inventory.labels.title`,`Print spool labels`)}),S>0&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,a(`inventory.labels.selectedCount`,`{{count}} selected`,{count:S}),`)`]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,"aria-label":a(`common.close`,`Close`),children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-2 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{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:`search`,value:d,onChange:e=>f(e.target.value),placeholder:a(`inventory.labels.searchPlaceholder`,`Search name, brand, or #ID`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),v.length>1&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:a(`inventory.labels.filterByMaterial`,`Material:`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>m(``),className:`px-2 py-0.5 text-xs rounded-full border transition ${p===``?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:a(`inventory.labels.allMaterials`,`All`)}),v.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>m(e),className:`px-2 py-0.5 text-xs rounded-full border transition ${p===e?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:e},e))]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:a(`inventory.labels.sortBy.label`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>g(`id`),className:`px-2 py-0.5 text-xs rounded-full border transition ${h===`id`?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:a(`inventory.labels.sortBy.id`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>g(`color`),className:`px-2 py-0.5 text-xs rounded-full border transition ${h===`color`?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:a(`inventory.labels.sortBy.color`)})]})]}),(0,K.jsxs)(`div`,{className:`px-4 pt-3 pb-2 flex items-center justify-between gap-3 flex-wrap`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`inventory.labels.pickSpools`,`Pick which spools to print labels for:`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-xs`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:x?E:T,disabled:b.length===0,className:`text-bambu-green hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:x?a(`inventory.labels.deselectVisible`,`Deselect visible`):a(`inventory.labels.selectVisible`,`Select all visible ({{count}})`,{count:b.length})}),(0,K.jsx)(`button`,{type:`button`,onClick:D,disabled:S===0,className:`text-bambu-gray hover:text-white hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:a(`inventory.labels.clearAll`,`Clear all`)})]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto px-2 pb-2 min-h-0`,children:b.length===0?(0,K.jsx)(`div`,{className:`text-center text-sm text-bambu-gray py-6`,children:_.length===0?a(`inventory.labels.noSpoolsToShow`,`No spools to show. Adjust your filter and try again.`):a(`inventory.labels.noMatches`,`No spools match the current search or filter.`)}):(0,K.jsx)(`ul`,{className:`space-y-0.5`,children:b.map(e=>{let t=l.has(e.id);return(0,K.jsx)(`li`,{children:(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary/50 cursor-pointer`,children:[t?(0,K.jsx)($l,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,K.jsx)(tu,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,K.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>w(e.id),className:`sr-only`}),(0,K.jsx)(`span`,{className:`w-4 h-4 rounded border border-black/20 shrink-0`,style:vVe(e.rgba)}),(0,K.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-sm text-white`,children:yVe(e)}),(0,K.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]})},e.id)})})}),(0,K.jsx)(`div`,{className:`px-3 pt-2 pb-2 grid grid-cols-1 sm:grid-cols-2 gap-2 border-t border-bambu-dark-tertiary`,children:gVe.map(e=>{let t=s===e.value,n=a(`inventory.labels.templates.${e.i18nKey}.label`,e.fallbackLabel),r=a(`inventory.labels.templates.${e.i18nKey}.hint`,e.fallbackHint);return(0,K.jsxs)(`button`,{disabled:C||s!==null,onClick:()=>O(e.value),title:`${n} — ${r}`,className:`w-full text-left p-2.5 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-green hover:bg-bambu-green/10 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:border-bambu-dark-tertiary disabled:hover:bg-bambu-dark transition flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`font-medium text-white text-sm truncate`,children:n}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5 truncate`,children:r})]}),t&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin text-bambu-green shrink-0`})]},e.value)})}),(0,K.jsx)(`div`,{className:`flex justify-end gap-2 px-5 py-2 border-t border-bambu-dark-tertiary`,children:(0,K.jsx)($,{variant:`secondary`,onClick:t,disabled:s!==null,children:a(`common.cancel`,`Cancel`)})})]})]})}function SVe({onClose:e,onImported:t}){let{t:n}=G(),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),h=(0,y.useRef)(null),g=async e=>{i(e),c(null),m(null),u(!0);try{c(await Q.importSpoolsCsvPreview(e))}catch(e){m(e instanceof Error?e.message:n(`inventory.csv.previewError`,`Could not read the CSV file`))}finally{u(!1)}},_=e=>{let t=e.target.files?.[0];t&&g(t)},v=e=>{e.preventDefault(),o(!1);let t=e.dataTransfer.files?.[0];t&&g(t)},b=async()=>{if(r){f(!0),m(null);try{t((await Q.importSpoolsCsv(r)).created)}catch(e){m(e instanceof Error?e.message:n(`inventory.csv.importError`,`Import failed`)),f(!1)}}},x=e=>e===`valid`?(0,K.jsx)(ls,{className:`w-4 h-4 text-green-500 flex-shrink-0`}):e===`error`?(0,K.jsx)(ms,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,K.jsx)(fs,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),S=s?.valid_count??0;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 w-full max-w-3xl border border-bambu-dark-tertiary flex flex-col max-h-[90vh]`,children:[(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`inventory.csv.modalTitle`,`Import spools from CSV`)}),(0,K.jsx)(`button`,{onClick:e,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,K.jsx)(Pu,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,K.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),o(!0)},onDragLeave:e=>{e.preventDefault(),o(!1)},onDrop:v,onClick:()=>h.current?.click(),className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${a?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,children:[(0,K.jsx)(Su,{className:`w-9 h-9 mx-auto mb-2 ${a?`text-bambu-green`:`text-bambu-gray`}`}),r?(0,K.jsxs)(`p`,{className:`text-white font-medium flex items-center justify-center gap-2`,children:[(0,K.jsx)(Zs,{className:`w-4 h-4`}),` `,r.name]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.csv.selectFile`,`Choose a CSV file or drag it here`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:n(`inventory.csv.dragHint`,`Header: material (required), brand, subtype, color_name, rgba, …`)})]})]}),(0,K.jsx)(`input`,{ref:h,type:`file`,accept:`.csv,text/csv`,className:`hidden`,onChange:_}),l&&(0,K.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-bambu-gray py-4`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),n(`inventory.csv.parsing`,`Reading file…`)]}),p&&(0,K.jsxs)(`div`,{className:`p-3 bg-red-500/10 border border-red-500/30 rounded-lg flex items-start gap-3`,children:[(0,K.jsx)(ms,{className:`w-5 h-5 text-red-400 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`p`,{className:`text-sm text-red-300 break-words`,children:p})]}),s&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-sm`,children:[(0,K.jsx)(`span`,{className:`px-2 py-1 rounded bg-green-500/10 text-green-400`,children:n(`inventory.csv.validCount`,`{{count}} valid`,{count:s.valid_count})}),(0,K.jsx)(`span`,{className:`px-2 py-1 rounded bg-red-500/10 text-red-400`,children:n(`inventory.csv.errorCount`,`{{count}} error`,{count:s.error_count})}),(0,K.jsx)(`span`,{className:`px-2 py-1 rounded bg-bambu-dark text-bambu-gray`,children:n(`inventory.csv.skippedCount`,`{{count}} skipped`,{count:s.skipped_count})})]}),s.warnings.length>0&&(0,K.jsx)(`div`,{className:`p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg space-y-1`,children:s.warnings.map((e,t)=>(0,K.jsx)(`p`,{className:`text-xs text-yellow-300`,children:e},t))}),s.rows.length>0&&(0,K.jsx)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:(0,K.jsx)(`div`,{className:`max-h-72 overflow-y-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,K.jsxs)(`tr`,{className:`text-left text-bambu-gray`,children:[(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colRow`,`Row`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colStatus`,`Status`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.material`,`Material`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.brand`,`Brand`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colColor`,`Color`)})]})}),(0,K.jsx)(`tbody`,{children:s.rows.map(e=>(0,K.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:e.row_number}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[x(e.status),e.status===`error`&&e.reason&&(0,K.jsx)(`span`,{className:`text-xs text-red-400 break-words`,children:e.reason})]})}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.material||`—`}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.brand||`—`}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.rgba&&(0,K.jsx)(`span`,{className:`inline-block w-4 h-4 rounded-full border border-bambu-dark-tertiary flex-shrink-0`,style:Wd(e.rgba)}),(0,K.jsx)(`span`,{className:`text-white`,children:e.color_name||`—`}),e.resolved_color&&!e.cross_material_color&&(0,K.jsx)(`span`,{title:n(`inventory.csv.colorResolved`,`Color filled from catalog`),children:(0,K.jsx)(Ou,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`})}),e.cross_material_color&&(0,K.jsx)(`span`,{title:n(`inventory.csv.colorCrossMaterial`,`Color taken from a different material — no exact match in catalog`),children:(0,K.jsx)(vu,{className:`w-3.5 h-3.5 text-yellow-500 flex-shrink-0`})}),e.duplicate_of_existing&&(0,K.jsx)(`span`,{title:n(`inventory.csv.duplicateExisting`,`A spool with this material, brand and color already exists — it will still be imported as a new spool`),children:(0,K.jsx)(Ds,{className:`w-3.5 h-3.5 text-amber-400 flex-shrink-0`})})]})})]},e.row_number))})]})})})]})]}),(0,K.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:e,disabled:d,children:n(`common.cancel`)}),(0,K.jsx)($,{onClick:b,disabled:!s||S===0||d,children:d?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 mr-2 animate-spin`}),n(`inventory.csv.importing`,`Importing…`)]}):S>0?n(`inventory.csv.importValidRows`,`Import {{count}} valid rows`,{count:S}):n(`inventory.csv.noValidRows`,`No valid rows`)})]})]})})}function CVe({open:e,onClose:t,onPickLocation:n}){let{t:r}=G(),i=Qa(),{showToast:a}=xd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),{data:m=[],isLoading:h}=q({queryKey:e9,queryFn:Q.getLocations,enabled:e}),g=()=>{t9(i),i.invalidateQueries({queryKey:[`inventory-spools`]}),i.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},_=J({mutationFn:async()=>{let e=u.trim();if(!e)throw Error(r(`locations.nameRequired`));return c?Q.updateLocation(c.id,{name:e}):Q.createLocation({name:e})},onSuccess:()=>{a(r(c?`locations.updated`:`locations.created`),`success`),s(!1),l(null),d(``),g()},onError:e=>{a(e.message||r(`locations.saveFailed`),`error`)}}),v=J({mutationFn:e=>Q.deleteLocation(e),onSuccess:()=>{a(r(`locations.deleted`),`success`),p(null),g()},onError:e=>{a(e.message||r(`locations.deleteFailed`),`error`)}}),b=()=>{l(null),d(``),s(!0)},x=e=>{l(e),d(e.name),s(!0)},S=(0,y.useCallback)(()=>{_.isPending||(s(!1),l(null),d(``))},[_.isPending]);(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(_.isPending||v.isPending||(o?S():f||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,o,f,_.isPending,v.isPending,S,t]);let C=e=>{e.preventDefault(),_.mutate()};if(!e)return null;let w=`locations-modal-title`,T=`location-editor-title`;return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{_.isPending||v.isPending||t()}}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-2xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":w,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h2`,{id:w,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Kc,{className:`w-5 h-5 text-bambu-green`}),r(`locations.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:r(`locations.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)($,{onClick:b,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),r(`locations.add`)]}),(0,K.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":r(`common.close`),children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]})]}),(0,K.jsx)(`div`,{className:`overflow-y-auto`,children:h?(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-6 h-6 animate-spin mr-2`}),r(`common.loading`)]}):m.length===0?(0,K.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:r(`locations.empty`)}):(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:r(`locations.name`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium text-right`,children:r(`locations.spools`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:r(`common.actions`)})]})}),(0,K.jsx)(`tbody`,{children:m.map(e=>(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 hover:bg-bambu-dark-tertiary/30 cursor-pointer`,onClick:()=>{n&&(n(e.id),t())},children:[(0,K.jsx)(`td`,{className:`px-4 py-3 text-white font-medium`,children:e.name}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-right text-bambu-gray`,children:e.spool_count}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,K.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>x(e),title:r(`common.edit`),"aria-label":r(`locations.editAria`,{name:e.name,defaultValue:`Edit ${e.name}`}),children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-400 rounded disabled:opacity-40`,disabled:e.spool_count>0,onClick:()=>p(e),title:e.spool_count>0?r(`locations.deleteBlocked`):r(`common.delete`),"aria-label":r(`locations.deleteAria`,{name:e.name,defaultValue:`Delete ${e.name}`}),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),o&&(0,K.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:S}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":T,children:[(0,K.jsx)(`h3`,{id:T,className:`text-lg font-semibold text-white mb-4`,children:r(c?`locations.edit`:`locations.add`)}),(0,K.jsxs)(`form`,{onSubmit:C,children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`location-name`,children:r(`locations.name`)}),(0,K.jsx)(`input`,{id:`location-name`,type:`text`,maxLength:255,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green mb-4`,placeholder:r(`locations.createPlaceholder`),value:u,onChange:e=>d(e.target.value),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:S,children:r(`common.cancel`)}),(0,K.jsxs)($,{type:`submit`,disabled:_.isPending||!u.trim(),children:[_.isPending&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),r(`common.save`)]})]})]})]})]}),f&&(0,K.jsx)(Ed,{title:r(`locations.confirmDelete`,{name:f.name}),message:r(`locations.confirmDeleteMessage`),confirmText:r(`common.delete`),variant:`danger`,isLoading:v.isPending,onConfirm:()=>v.mutate(f.id),onCancel:()=>p(null)})]})}function wVe(e){let t=e[0],n=0,r=0,i=0;for(let t of e)n+=t.label_weight,r+=t.weight_used,i+=t.core_weight;return{...t,label_weight:n,weight_used:r,core_weight:i}}function a9(e){return`${e.material}|${e.subtype||``}|${e.brand||``}|${e.color_name||``}|${e.rgba||``}|${e.extra_colors||``}|${e.effect_type||``}|${e.label_weight}`}var o9=`bambuddy-inventory-columns`,s9=[{id:`id`,label:`#`,visible:!0},{id:`added_time`,label:`Added`,visible:!0},{id:`encode_time`,label:`Encoded`,visible:!1},{id:`last_used_time`,label:`Last Used`,visible:!1},{id:`rgba`,label:`Color`,visible:!0},{id:`material`,label:`Material`,visible:!0},{id:`subtype`,label:`Subtype`,visible:!0},{id:`color_name`,label:`Color Name`,visible:!1},{id:`brand`,label:`Brand`,visible:!0},{id:`slicer_filament`,label:`Slicer Filament`,visible:!1},{id:`location`,label:`Location`,visible:!0},{id:`storage_location`,label:`Storage Location`,visible:!1},{id:`label_weight`,label:`Label`,visible:!0},{id:`net`,label:`Net`,visible:!0},{id:`gross`,label:`Gross`,visible:!1},{id:`added_full`,label:`Full`,visible:!1},{id:`used`,label:`Used`,visible:!1},{id:`printed_total`,label:`Printed Total`,visible:!1},{id:`printed_since_weight`,label:`Printed Since Weight`,visible:!1},{id:`note`,label:`Note`,visible:!1},{id:`pa_k`,label:`PA(K)`,visible:!0},{id:`tag_id`,label:`Tag ID`,visible:!1},{id:`data_origin`,label:`Data Origin`,visible:!1},{id:`tag_type`,label:`Linked Tag Type`,visible:!1},{id:`stock`,label:`Stock`,visible:!1},{id:`remaining`,label:`Remaining`,visible:!0},{id:`spool_name`,label:`Spool`,visible:!1},{id:`cost_per_kg`,label:`Cost/kg`,visible:!1},{id:`weight_check`,label:`Weight Check`,visible:!1}];function TVe(){try{let e=localStorage.getItem(o9);if(e){let t=JSON.parse(e),n=new Set(s9.map(e=>e.id)),r=new Set(t.map(e=>e.id)),i=t.filter(e=>n.has(e.id)),a=s9.filter(e=>!r.has(e.id));return[...i,...a]}}catch{}return s9.map(e=>({...e}))}function EVe(e){try{localStorage.setItem(o9,JSON.stringify(e))}catch{}}function c9(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}var DVe={PLA:`bg-green-500/20 text-green-400`,ABS:`bg-red-500/20 text-red-400`,PETG:`bg-blue-500/20 text-blue-400`,TPU:`bg-purple-500/20 text-purple-400`,ASA:`bg-orange-500/20 text-orange-400`,PA:`bg-yellow-500/20 text-yellow-400`,PC:`bg-cyan-500/20 text-cyan-400`,PET:`bg-sky-500/20 text-sky-400`};function l9(e,t=`system`){if(!e)return`-`;let n=mf(e);return n?of(n,t):`-`}var OVe={id:()=>`#`,added_time:()=>`Added`,encode_time:()=>`Encoded`,last_used_time:()=>`Last Used`,rgba:e=>e(`inventory.color`),material:e=>e(`inventory.material`),subtype:e=>e(`inventory.subtype`),color_name:e=>e(`inventory.colorName`),brand:e=>e(`inventory.brand`),slicer_filament:e=>e(`inventory.slicerFilament`),location:()=>`Location`,storage_location:e=>e(`inventory.storageLocation`),label_weight:e=>e(`inventory.labelWeight`),net:e=>e(`inventory.net`),gross:()=>`Gross`,added_full:()=>`Full`,used:e=>e(`inventory.weightUsed`),printed_total:()=>`Printed Total`,printed_since_weight:()=>`Printed Since Weight`,note:e=>e(`inventory.note`),pa_k:()=>`PA(K)`,tag_id:()=>`Tag ID`,data_origin:()=>`Data Origin`,tag_type:()=>`Linked Tag Type`,stock:e=>e(`inventory.stock`),remaining:e=>e(`inventory.remaining`),spool_name:e=>e(`inventory.spoolName`),cost_per_kg:e=>e(`inventory.costPerKg`),weight_check:e=>e(`inventory.weightCheck`)},u9={id:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm font-medium text-white`,children:e.id}),added_time:({spool:e,dateFormat:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:l9(e.created_at,t)}),encode_time:({spool:e,dateFormat:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:l9(e.encode_time,t)}),last_used_time:({spool:e,dateFormat:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.last_used?l9(e.last_used,t):`Never`}),rgba:({spool:e})=>(0,K.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,K.jsx)(K5,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,effectSize:`table`,subtype:e.subtype})}),material:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-white`,children:e.material}),subtype:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.subtype||`-`}),color_name:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:Hd(e.color_name,e.rgba)||`-`}),brand:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`}),slicer_filament:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:e.slicer_filament||void 0,children:e.slicer_filament_name||e.slicer_filament||`-`}),location:({spool:e,assignmentMap:t})=>{let n=t[e.id];if(!n)return(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`});let r=n.printer_name||`Printer ${n.printer_id}`,i=n.ams_id===254||n.ams_id===255,a=!i&&n.ams_id>=128;return(0,K.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-purple-500/20 text-purple-400`,children:[r,` `,IK(n.ams_id,n.tray_id,a,i),n.ams_label?` (${n.ams_label})`:``]})},storage_location:({spool:e})=>e.storage_location?(0,K.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-blue-500/20 text-blue-400`,children:e.storage_location}):(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}),label_weight:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-white`,children:c9(e.label_weight)}),net:({remaining:e})=>(0,K.jsx)(`span`,{className:`text-sm text-white`,children:c9(e)}),gross:({spool:e,remaining:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:c9(t+e.core_weight)}),added_full:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.added_full==null?`-`:e.added_full?`Yes`:`No`}),used:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.weight_used>0?c9(e.weight_used):`-`}),printed_total:()=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),printed_since_weight:()=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),note:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray max-w-[150px] truncate block`,title:e.note||void 0,children:e.note||`-`}),pa_k:({spool:e})=>(e.k_profiles?.length??0)===0?(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,K.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-bambu-green/20 text-bambu-green`,children:`K`}),tag_id:({spool:e})=>{let t=e.tag_uid||e.tray_uuid;return t?(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray font-mono`,title:t,children:t.length>12?`${t.slice(0,6)}...${t.slice(-4)}`:t}):(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},data_origin:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.data_origin||`-`}),tag_type:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.tag_type||`-`}),stock:({spool:e,t})=>e.slicer_filament?(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,K.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-amber-500/20 text-amber-400`,children:t(`inventory.stock`)}),remaining:({remaining:e,pct:t})=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full ${t>50?`bg-bambu-green`:t>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(t,100)}%`}})}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e),`g`]})]}),spool_name:({spool:e,catalogMap:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:(e.core_weight_catalog_id==null?void 0:t[e.core_weight_catalog_id])?.name||`-`}),cost_per_kg:({spool:e,currencySymbol:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.cost_per_kg==null?`-`:`${t}${e.cost_per_kg.toFixed(2)}`}),weight_check:({spool:e,onSyncWeight:t})=>{let n=e.last_scale_weight;if(n==null)return(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,title:`No scale measurement`,children:`-`});let r=e.core_weight||0,i=Math.max(0,e.label_weight-e.weight_used)+r,a,o;n0?`+${Math.round(a)}`:`${Math.round(a)}`,c=o?`Scale: ${Math.round(n)}g\nCalculated: ${Math.round(i)}g\nDifference: ${s}g (within tolerance)`:`Scale: ${Math.round(n)}g\nCalculated: ${Math.round(i)}g\nDifference: ${s}g (mismatch!)`;return(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-sm font-medium ${o?`text-green-400`:`text-yellow-400`}`,title:c,children:[(0,K.jsxs)(`span`,{children:[Math.round(n),`g`]}),o?(0,K.jsx)($o,{className:`w-3 h-3`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(vu,{className:`w-3 h-3`}),t&&(0,K.jsx)(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),n.preventDefault(),t(e)},className:`p-1 hover:bg-bambu-green/20 rounded transition-colors text-bambu-green`,title:`Sync: trust scale weight and reset tracking`,children:(0,K.jsx)(Cl,{className:`w-3.5 h-3.5`})})]})]})}},d9={id:e=>e.id,added_time:e=>e.created_at||``,encode_time:e=>e.encode_time||``,last_used_time:e=>e.last_used||``,material:e=>(e.material||``).toLowerCase(),subtype:e=>(e.subtype||``).toLowerCase(),color_name:e=>(e.color_name||``).toLowerCase(),brand:e=>(e.brand||``).toLowerCase(),slicer_filament:e=>(e.slicer_filament_name||e.slicer_filament||``).toLowerCase(),location:(e,t)=>{let n=t[e.id];if(!n)return``;let r=n.ams_id===254||n.ams_id===255,i=!r&&n.ams_id>=128,a=n.ams_label?` (${n.ams_label})`:``;return`${n.printer_name||``} ${IK(n.ams_id,n.tray_id,i,r)}${a}`},storage_location:e=>(e.storage_location||``).toLowerCase(),label_weight:e=>e.label_weight,net:e=>Math.max(0,e.label_weight-e.weight_used),gross:e=>Math.max(0,e.label_weight-e.weight_used)+e.core_weight,used:e=>e.weight_used,remaining:e=>e.label_weight>0?Math.max(0,e.label_weight-e.weight_used)/e.label_weight:0,note:e=>(e.note||``).toLowerCase(),data_origin:e=>(e.data_origin||``).toLowerCase(),tag_type:e=>(e.tag_type||``).toLowerCase(),stock:e=>+!!e.slicer_filament,spool_name:e=>e.core_weight_catalog_id??0,cost_per_kg:e=>e.cost_per_kg??0,weight_check:e=>{if(e.last_scale_weight==null)return-1;let t=Math.max(0,e.label_weight-e.weight_used)+e.core_weight;return Math.abs(e.last_scale_weight-t)}},f9=`bambuddy-inventory-sort`;function kVe(){try{let e=localStorage.getItem(f9);if(e)return JSON.parse(e)}catch{}return null}function AVe(e){try{e?localStorage.setItem(f9,JSON.stringify(e)):localStorage.removeItem(f9)}catch{}}function jVe(){let{data:e}=q({queryKey:[`spoolman-settings`],queryFn:Q.getSpoolmanSettings,staleTime:300*1e3}),t=e!==void 0;return(0,K.jsx)(MVe,{spoolmanMode:e?.spoolman_enabled===`true`&&!!e?.spoolman_url,spoolmanModeReady:t})}function MVe({spoolmanMode:e=!1,spoolmanModeReady:t=!0}){let{t:n}=G(),r=Qa(),{showToast:i}=xd(),{hasPermission:a,loading:o}=sd(),s=!o&&a(`inventory:forecast_read`),[c,l]=Oi(),[u,d]=(0,y.useState)(null),f=(0,y.useRef)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(`active`),[E,D]=(0,y.useState)(`all`),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(``),[P,F]=(0,y.useState)(``),[I,L]=(0,y.useState)(`all`),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(`table`),[ee,H]=(0,y.useState)(kVe),[te,ne]=(0,y.useState)(TVe),[re,U]=(0,y.useState)(!1),[ie,ae]=(0,y.useState)(()=>{try{return localStorage.getItem(`bambuddy-inventory-group`)===`true`}catch{return!1}}),[W,oe]=(0,y.useState)(new Set),[se,ce]=(0,y.useState)(0),[le,ue]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`bambuddy-inventory-pageSize`);if(e){let t=Number(e);if([15,30,50,100,-1].includes(t))return t}}catch{}return 15}),{data:de}=q({queryKey:[`settings`],queryFn:Q.getSettings}),fe=de?.date_format||`system`,pe=e?[`spoolman-inventory-spools`]:[`inventory-spools`],me=()=>n9(r,pe),{data:he,isLoading:ge}=q({queryKey:pe,queryFn:()=>e?Q.getSpoolmanInventorySpools(!0):Q.getSpools(!0),refetchInterval:3e4}),_e=(0,y.useCallback)(async()=>{x(!0);try{await Q.exportSpoolsCsv()}catch(e){i(e instanceof Error?e.message:n(`inventory.csv.exportError`,`Export failed`),`error`)}finally{x(!1)}},[i,n]),ve=e?n(`inventory.csv.spoolmanHint`,`In Spoolman mode, use Spoolman's built-in CSV import/export.`):void 0,{data:ye=[]}=q({queryKey:e9,queryFn:Q.getLocations}),be=c.get(`location_id`),xe=be===`__none__`?`__none__`:be&&/^\d+$/.test(be)&&Number(be)>0?be:``,Se=c.get(`spool`),Ce=Se&&/^\d+$/.test(Se)&&Number(Se)>0?Number(Se):null,we=he?.find(e=>e.id===Ce)??null,Te=(0,y.useCallback)(()=>{f.current=!0,l(e=>(e.delete(`spool`),e),{replace:!0})},[l]),{data:Ee,isError:De,error:Oe}=q({queryKey:e?[`spoolman-inventory-spool`,Ce]:[`inventory-spool`,Ce],queryFn:()=>e?Q.getSpoolmanInventorySpool(Ce):Q.getSpool(Ce),enabled:t&&Ce!==null&&we===null,staleTime:1/0,retry:(e,t)=>e<2&&!(t instanceof zu&&t.status===404)});(0,y.useEffect)(()=>{if(!f.current){if(t&&Ce&&we){Te(),d({spool:we,mode:`edit`});return}if(Ee){Te(),d({spool:Ee,mode:`edit`});return}De&&(Te(),i(n(Oe instanceof zu&&Oe.status===404?`inventory.deepLinkSpoolNotFound`:`inventory.deepLinkFetchFailed`),`error`))}},[t,Ce,we,Ee,De,Oe,Te,i,n]);let{data:ke}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),refetchInterval:3e4}),{data:Ae=[],isError:je}=q({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:e,refetchInterval:3e4,staleTime:1e4,retry:1}),Me=(0,y.useRef)(!1);(0,y.useEffect)(()=>{je&&!Me.current?(Me.current=!0,i(n(`inventory.spoolmanUnreachable`),`error`)):je||(Me.current=!1)},[je,i,n]);let{data:Ne}=q({queryKey:[`spool-catalog`],queryFn:()=>Q.getSpoolCatalog()}),Pe=J({mutationFn:t=>e?Q.deleteSpoolmanInventorySpool(t):Q.deleteSpool(t),onSuccess:()=>{me(),i(n(`inventory.spoolDeleted`),`success`)},onError:e=>{e instanceof zu&&e.status===404?i(n(`inventory.deleteSpoolNotFound`),`error`):e instanceof zu&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.deleteFailed`),`error`)}}),Fe=J({mutationFn:t=>e?Q.archiveSpoolmanInventorySpool(t):Q.archiveSpool(t),onSuccess:()=>{me(),i(n(`inventory.spoolArchived`),`success`)},onError:e=>{e instanceof zu&&e.status===404?i(n(`inventory.archiveSpoolNotFound`),`error`):e instanceof zu&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.archiveFailed`),`error`)}}),Ie=J({mutationFn:t=>e?Q.restoreSpoolmanInventorySpool(t):Q.restoreSpool(t),onSuccess:()=>{me(),i(n(`inventory.spoolRestored`),`success`)},onError:e=>{e instanceof zu&&e.status===404?i(n(`inventory.restoreSpoolNotFound`),`error`):e instanceof zu&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.restoreFailed`),`error`)}}),Le=J({mutationFn:t=>e?Q.resetSpoolmanInventorySpoolConsumedCounter(t):Q.resetSpoolConsumedCounter(t),onSuccess:()=>{r.invalidateQueries({queryKey:pe}),i(n(`inventory.consumedCounterReset`),`success`)},onError:()=>{i(n(`inventory.resetConsumedCounterFailed`),`error`)}}),Re=J({mutationFn:t=>e?Q.bulkResetSpoolmanInventorySpoolConsumedCounter(t):Q.bulkResetSpoolConsumedCounter(t),onSuccess:e=>{r.invalidateQueries({queryKey:pe}),i(n(`inventory.allConsumedCountersReset`,{count:e.reset}),`success`)},onError:()=>{i(n(`inventory.resetConsumedCounterFailed`),`error`)}}),ze=(0,y.useMemo)(()=>(he??[]).map(e=>e.id),[he]),Be=async t=>{if(t.last_scale_weight!=null)try{e?await Q.syncSpoolmanSpoolWeight(t.id,t.last_scale_weight):await nd.updateSpoolWeight(t.id,t.last_scale_weight),r.invalidateQueries({queryKey:pe}),i(`Synced "${[t.brand,t.material,t.color_name].filter(Boolean).join(` `)}" to scale weight`,`success`)}catch(e){let t=e instanceof zu&&e.status===404,r=e instanceof zu&&e.status===503;i(n(t?`inventory.syncWeightSpoolNotFound`:r?`inventory.syncWeightSpoolmanUnreachable`:`inventory.syncWeightFailed`),`error`)}},Ve=de?.low_stock_threshold??20,[He,Ue]=(0,y.useState)(!1),[We,Ge]=(0,y.useState)(Ve.toString());(0,y.useEffect)(()=>{He||Ge(Ve.toString())},[Ve,He]);let Ke=J({mutationFn:e=>Q.updateSettings({low_stock_threshold:e}),onSuccess:()=>{r.invalidateQueries({queryKey:[`settings`]}),i(n(`common.saved`),`success`),Ue(!1)},onError:()=>{i(n(`inventory.lowStockThresholdError`),`error`)}}),qe=(0,y.useMemo)(()=>{if(!he)return null;let e=0,t=0,n=0,r=0,i={};for(let a of he){if(t+=Math.max(0,a.weight_used-(a.weight_used_baseline??0)),a.archived_at)continue;r++;let o=Math.max(0,a.label_weight-a.weight_used);e+=o,(a.label_weight>0?o/a.label_weight*100:0)<(a.low_stock_threshold_pct??Ve)&&n++;let s=a.material||`Unknown`;i[s]||(i[s]={count:0,weight:0}),i[s].count++,i[s].weight+=o}return{totalWeight:e,totalConsumed:t,lowStock:n,byMaterial:i,totalSpools:r}},[he,Ve]),Je=(ke?.length??0)+(e?Ae.length:0),Ye=Yd(de?.currency||`USD`),Xe=(0,y.useMemo)(()=>{let e={};for(let t of ke||[])e[t.spool_id]={printer_id:t.printer_id,printer_name:t.printer_name,ams_id:t.ams_id,tray_id:t.tray_id,ams_label:t.ams_label??null};for(let t of Ae)typeof t?.spoolman_spool_id!=`number`||t.spoolman_spool_id<=0||typeof t.printer_id!=`number`||typeof t.ams_id!=`number`||typeof t.tray_id!=`number`||e[t.spoolman_spool_id]||(e[t.spoolman_spool_id]={printer_id:t.printer_id,printer_name:t.printer_name??null,ams_id:t.ams_id,tray_id:t.tray_id,ams_label:t.ams_label??null});return e},[ke,Ae]),Ze=(0,y.useMemo)(()=>{let e={};for(let t of Ne||[])e[t.id]=t;return e},[Ne]),Qe=(0,y.useMemo)(()=>qe?Object.entries(qe.byMaterial).sort((e,t)=>t[1].weight-e[1].weight).slice(0,4):[],[qe]),$e=(0,y.useMemo)(()=>{let e=he||[];if(e=w===`active`?e.filter(e=>!e.archived_at):e.filter(e=>!!e.archived_at),E===`used`?e=e.filter(e=>e.weight_used>0):E===`new`?e=e.filter(e=>e.weight_used===0):E===`lowstock`&&(e=e.filter(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(e.label_weight>0?t/e.label_weight*100:0)<(e.low_stock_threshold_pct??Ve)})),O&&(e=e.filter(e=>e.material===O)),A&&(e=e.filter(e=>e.brand===A)),M&&(e=M===`__none__`?e.filter(e=>!e.category):e.filter(e=>e.category===M)),P){let t=Number(P);e=e.filter(e=>e.core_weight_catalog_id===t)}if(xe)if(xe===`__none__`)e=e.filter(e=>!e.location_id&&!e.storage_location?.trim());else{let t=Number(xe),n=ye.find(e=>e.id===t)?.name?.trim().toLowerCase();e=e.filter(e=>e.location_id==null?n?(e.storage_location||``).trim().toLowerCase()===n:!1:e.location_id===t)}return I===`stock`?e=e.filter(e=>!e.slicer_filament):I===`configured`&&(e=e.filter(e=>!!e.slicer_filament)),R&&(e=ZG(e,R)),e},[he,w,E,O,A,M,P,I,xe,R,Ve,ye]),et=()=>ce(0),tt=(0,y.useCallback)(e=>{l(t=>(t.delete(`location_id`),e&&t.set(`location_id`,e),t),{replace:!0}),et()},[l]),nt=[...new Set(he?.map(e=>e.material)||[])].sort(),rt=[...new Set(he?.map(e=>e.brand).filter(Boolean)||[])].sort(),it=[...new Set(he?.map(e=>e.category?.trim()).filter(Boolean)||[])].sort(),at=(he??[]).some(e=>!e.category),ot=[...new Set(he?.map(e=>e.core_weight_catalog_id).filter(e=>e!=null)||[])].sort((e,t)=>{let n=(Ze[e]?.name||``).toLowerCase(),r=(Ze[t]?.name||``).toLowerCase();return n.localeCompare(r)}),st=(he??[]).some(e=>!e.location_id&&!e.storage_location?.trim()),ct=w!==`active`||E!==`all`||!!O||!!A||!!M||!!P||!!xe||I!==`all`||!!R,lt=e=>{ne(e),EVe(e)},ut=(0,y.useMemo)(()=>te.filter(e=>e.visible).map(e=>e.id),[te]),dt=e=>{d9[e]&&(H(t=>{let n;return n=t?.column===e?t.direction===`asc`?{column:e,direction:`desc`}:null:{column:e,direction:`asc`},AVe(n),n}),et())},ft=(0,y.useMemo)(()=>{if(!ee)return $e;let e=d9[ee.column];return e?[...$e].sort((t,n)=>{let r=e(t,Xe),i=e(n,Xe);return ri?ee.direction===`asc`?1:-1:0}):$e},[$e,ee,Xe]),pt=(0,y.useMemo)(()=>{if(!ie)return ft.map(e=>({type:`single`,spool:e}));let e=new Map;for(let t of ft)if(!(t.weight_used>0||Xe[t.id])){let n=a9(t),r=e.get(n);r?r.push(t):e.set(n,[t])}let t=[],n=new Set;for(let r of ft){if(r.weight_used>0||Xe[r.id]){t.push({type:`single`,spool:r});continue}let i=a9(r);if(n.has(i))continue;n.add(i);let a=e.get(i);a.length===1?t.push({type:`single`,spool:a[0]}):t.push({type:`group`,key:i,spools:a,representative:a[0]})}return t},[ft,ie,Xe]),mt=le===-1,ht=pt.length,gt=mt?ht||1:le,_t=Math.max(1,Math.ceil(ht/gt)),vt=mt?0:Math.min(se,_t-1),yt=mt?pt:pt.slice(vt*gt,(vt+1)*gt),bt=()=>{let e=!ie;ae(e),oe(new Set),et();try{localStorage.setItem(`bambuddy-inventory-group`,String(e))}catch{}},xt=e=>{oe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},St=e=>{ue(e),ce(0);try{localStorage.setItem(`bambuddy-inventory-pageSize`,String(e))}catch{}};return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,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)(cl,{className:`w-7 h-7 text-bambu-green`}),n(`inventory.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:n(`inventory.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,disabled:e,onClick:()=>v(!0),title:ve,children:[(0,K.jsx)(Su,{className:`w-4 h-4`}),n(`inventory.csv.importButton`,`Import CSV`)]}),(0,K.jsxs)($,{variant:`secondary`,disabled:e||b,onClick:_e,title:ve,children:[b?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Is,{className:`w-4 h-4`}),n(`inventory.csv.exportButton`,`Export CSV`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>C(!0),children:[(0,K.jsx)(Kc,{className:`w-4 h-4`}),n(`locations.manage`)]}),(0,K.jsxs)($,{variant:`secondary`,disabled:$e.length===0,onClick:()=>g($e.map(e=>e.id)),title:$e.length===0?n(`inventory.labels.noSpoolsTitle`,`No spools to label`):n(`inventory.labels.bulkTitle`,`Pick spools to print labels for from the {{count}} currently shown`,{count:$e.length}),children:[(0,K.jsx)(bl,{className:`w-4 h-4`}),n(`inventory.labels.printLabels`,`Print labels…`)]}),(0,K.jsxs)($,{onClick:()=>d({spool:null,mode:`create`}),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})]}),qe&&!ge&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3`,children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsx)(cl,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalInventory`)})]}),(0,K.jsx)(`div`,{className:`text-xl font-bold text-white`,children:c9(qe.totalWeight,!0)}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[qe.totalSpools,` `,qe.totalSpools===1?n(`inventory.spool`):n(`inventory.spools`)]})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(gu,{className:`w-4 h-4 text-blue-400`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalConsumed`)})]}),qe.totalConsumed>0&&ze.length>0&&(0,K.jsx)(`button`,{onClick:()=>m({type:`reset-all-consumed-counters`}),className:`p-1 text-bambu-gray hover:text-red-400 rounded transition-colors`,title:n(`inventory.resetAllConsumedCountersTooltip`),"aria-label":n(`inventory.resetAllConsumedCounters`),children:(0,K.jsx)(Hs,{className:`w-3.5 h-3.5`})})]}),(0,K.jsx)(`div`,{className:`text-xl font-bold text-white`,children:c9(qe.totalConsumed,!0)}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.sinceTracking`)})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsx)(Nc,{className:`w-4 h-4 text-green-400`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.byMaterial`)})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1`,children:Qe.map(([e,t])=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${DVe[e]||`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e,` `,(0,K.jsx)(`span`,{className:`opacity-70`,children:c9(t.weight,!0)})]},e))})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsx)(bl,{className:`w-4 h-4 text-purple-400`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.inPrinter`)})]}),(0,K.jsx)(`div`,{className:`text-xl font-bold text-white`,children:Je}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.loadedInAms`)})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-yellow-400`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.lowStock`)})]}),(0,K.jsx)(`div`,{className:`text-xl font-bold ${qe.lowStock>0?`text-yellow-400`:`text-white`}`,children:qe.lowStock}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1 flex items-center gap-2`,children:He?(0,K.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=parseFloat(We);!isNaN(t)&&t>=.1&&t<=99.9?Ke.mutate(t):i(n(`inventory.lowStockThresholdError`),`error`)},className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`<`}),(0,K.jsx)(`input`,{type:`text`,inputMode:`decimal`,pattern:`^\\d{0,2}(\\.\\d?)?$`,maxLength:4,value:We,onChange:e=>{let t=e.target.value.replace(/[^\d.]/g,``);/^\d{0,2}(\.\d?)?$/.test(t)&&Ge(t)},className:`px-1.5 py-1 rounded border border-bambu-dark-tertiary text-xs text-white bg-bambu-dark-secondary focus:outline-none focus:border-bambu-green w-14 text-center`,onWheel:e=>e.currentTarget.blur(),disabled:Ke.isPending}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`%`}),(0,K.jsx)($,{type:`submit`,size:`sm`,disabled:Ke.isPending,children:n(`common.save`)}),(0,K.jsx)($,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>Ue(!1),disabled:Ke.isPending,children:n(`common.cancel`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`< `,Ve,`%`]}),(0,K.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:n(`common.edit`),onClick:()=>{Ge(Ve.toString()),Ue(!0)},children:(0,K.jsx)(fl,{className:`w-4 h-4`})})]})})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3 items-start sm:items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1 max-w-md ${B===`forecast`?`invisible pointer-events-none`:``}`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,K.jsx)(`input`,{type:`text`,value:R,onChange:e=>{z(e.target.value),et()},placeholder:n(`inventory.search`),className:`w-full pl-10 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`}),R&&(0,K.jsx)(`button`,{onClick:()=>{z(``),et()},className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[B===`table`&&(0,K.jsxs)(`button`,{onClick:()=>U(!0),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-bambu-gray border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,title:n(`inventory.configureColumns`),children:[(0,K.jsx)(Ts,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.columns`)})]}),B!==`forecast`&&(0,K.jsxs)(`button`,{onClick:bt,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium border rounded-lg transition-colors ${ie?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,title:n(`inventory.groupSimilar`),children:[(0,K.jsx)(_c,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.groupSimilar`)})]}),(0,K.jsxs)(`div`,{className:`flex bg-bambu-dark-primary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`button`,{onClick:()=>V(`table`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${B===`table`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(ou,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.table`)})]}),(0,K.jsxs)(`button`,{onClick:()=>V(`cards`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${B===`cards`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(Pc,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.cards`)})]}),(0,K.jsxs)(`button`,{onClick:()=>s&&V(`forecast`),disabled:!s,title:s?void 0:n(`forecast.noReadAccess`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${B===`forecast`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[s?(0,K.jsx)(_u,{className:`w-4 h-4`}):(0,K.jsx)(Hc,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:n(`forecast.title`)})]})]})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${B===`forecast`?`hidden`:``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,K.jsxs)(`button`,{onClick:()=>{T(`active`),et()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${w===`active`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(cl,{className:`w-3.5 h-3.5`}),n(`inventory.active`)]}),(0,K.jsxs)(`button`,{onClick:()=>{T(`archived`),et()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${w===`archived`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(wo,{className:`w-3.5 h-3.5`}),n(`inventory.archived`)]})]}),(0,K.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,K.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,K.jsx)(`button`,{onClick:()=>{D(`all`),et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${E===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,K.jsxs)(`button`,{onClick:()=>{D(`used`),et()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${E===`used`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(_s,{className:`w-3.5 h-3.5`}),n(`inventory.used`)]}),(0,K.jsx)(`button`,{onClick:()=>{D(`new`),et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${E===`new`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.new`)}),(0,K.jsxs)(`button`,{onClick:()=>{D(`lowstock`),et()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${E===`lowstock`?`bg-yellow-500/20 text-yellow-400`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(vu,{className:`w-3.5 h-3.5`}),n(`inventory.lowStock`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,K.jsx)(`button`,{onClick:()=>{L(`all`),et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,K.jsx)(`button`,{onClick:()=>{L(`stock`),et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`stock`?`bg-amber-500/20 text-amber-400`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.stock`)}),(0,K.jsx)(`button`,{onClick:()=>{L(`configured`),et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`configured`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.configured`)})]}),(0,K.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,K.jsxs)(`select`,{value:O,onChange:e=>{k(e.target.value),et()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${O?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(`option`,{value:``,children:n(`inventory.material`)}),nt.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),(0,K.jsxs)(`select`,{value:A,onChange:e=>{j(e.target.value),et()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${A?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(`option`,{value:``,children:n(`inventory.brand`)}),rt.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),(it.length>0||M)&&(0,K.jsxs)(`select`,{value:M,onChange:e=>{N(e.target.value),et()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${M?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(`option`,{value:``,children:n(`inventory.category`)}),it.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e)),at&&(0,K.jsx)(`option`,{value:`__none__`,children:n(`inventory.categoryNone`)})]}),ot.length>0&&(0,K.jsxs)(`select`,{value:P,onChange:e=>{F(e.target.value),et()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${P?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(`option`,{value:``,children:n(`inventory.spoolName`)}),ot.map(e=>(0,K.jsx)(`option`,{value:e,children:Ze[e]?.name||`#${e}`},e))]}),(ye.length>0||xe)&&(0,K.jsxs)(`select`,{value:xe,onChange:e=>{tt(e.target.value)},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${xe?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(`option`,{value:``,children:n(`inventory.storageLocation`)}),ye.map(e=>(0,K.jsx)(`option`,{value:String(e.id),children:e.name},e.id)),st&&(0,K.jsx)(`option`,{value:`__none__`,children:n(`inventory.storageLocationNone`)})]}),ct&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,K.jsxs)(`button`,{onClick:()=>{T(`active`),D(`all`),k(``),j(``),N(``),F(``),L(`all`),z(``),l(e=>(e.delete(`location_id`),e),{replace:!0}),et()},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:[(0,K.jsx)(Pu,{className:`w-3.5 h-3.5`}),n(`inventory.clearFilters`)]})]}),B!==`forecast`&&(0,K.jsxs)(`span`,{className:`ml-auto text-xs text-bambu-gray`,children:[ft.length,` `,ft.length===1?n(`inventory.spool`):n(`inventory.spools`),ie&&ht0?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:yt.map(e=>{if(e.type===`group`){let{key:t,spools:r,representative:i}=e,a=r.reduce((e,t)=>e+Math.max(0,t.label_weight-t.weight_used),0),o=G5({rgba:i.rgba,extraColors:i.extra_colors,effectType:i.effect_type,subtype:i.subtype,effectSize:`groupheader`}),s=W.has(t);return(0,K.jsxs)(`div`,{className:`col-span-full`,children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-green/30 hover:border-bambu-green transition-colors cursor-pointer`,onClick:()=>xt(t),children:[(0,K.jsx)(`div`,{className:`h-10 flex items-center px-4 gap-3`,style:o,children:(0,K.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:Hd(i.color_name,i.rgba)||`-`})}),(0,K.jsxs)(`div`,{className:`px-4 py-3 flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray transition-transform ${s?``:`-rotate-90`}`}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h3`,{className:`font-semibold text-white`,children:[i.material,i.subtype?` ${i.subtype}`:``]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i.brand||`-`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:n(`inventory.remaining`),children:c9(a)}),(0,K.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:n(`inventory.groupedSpools`,{count:r.length})})]})]})]}),s&&(0,K.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 mt-2 ml-4`,children:r.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(0,K.jsx)(p9,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,onClick:()=>d({spool:e,mode:`edit`}),onPrintLabel:()=>g([e.id]),onCopy:()=>d({spool:e,mode:`copy`}),t:n},e.id)})})]},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,K.jsx)(p9,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,onClick:()=>d({spool:t,mode:`edit`}),onPrintLabel:()=>g([t.id]),onCopy:()=>d({spool:t,mode:`copy`}),t:n},t.id)})}),(0,K.jsx)(NVe,{pageIndex:vt,pageSize:le,totalRows:ht,totalPages:_t,onPageChange:ce,onPageSizeChange:St,t:n})]}):(0,K.jsx)(h9,{hasFilters:ct,onAddSpool:()=>d({spool:null,mode:`create`}),t:n}):yt.length>0?(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[ut.map(e=>{let t=!!d9[e],r=ee?.column===e;return(0,K.jsx)(`th`,{className:`text-left py-3 px-4 text-xs font-medium uppercase tracking-wide select-none ${e===`remaining`?`min-w-[150px]`:``} ${t?`cursor-pointer hover:text-bambu-green transition-colors`:``} ${r?`text-bambu-green`:`text-bambu-gray`}`,onClick:t?()=>dt(e):void 0,children:(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[OVe[e]?.(n)??e,t&&(r?ee.direction===`asc`?(0,K.jsx)(Mo,{className:`w-3 h-3`}):(0,K.jsx)(Eo,{className:`w-3 h-3`}):(0,K.jsx)(Ao,{className:`w-3 h-3 opacity-30`}))]})},e)}),(0,K.jsx)(`th`,{className:`text-right py-3 px-4 text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:n(`common.actions`)})]})}),(0,K.jsx)(`tbody`,{children:yt.map(e=>{if(e.type===`group`){let{key:t,spools:r}=e,i=W.has(t),a=wVe(r),o=Math.max(0,a.label_weight-a.weight_used);return(0,K.jsx)(PVe,{spools:r,headerSpool:a,remaining:o,pct:a.label_weight>0?o/a.label_weight*100:0,isExpanded:i,onToggle:()=>xt(t),onEdit:e=>d({spool:e,mode:`edit`}),onCopy:e=>d({spool:e,mode:`copy`}),onArchive:e=>m({type:`archive`,spoolId:e}),onDelete:e=>m({type:`delete`,spoolId:e}),onPrintLabel:e=>g([e]),onResetConsumedCounter:e=>m({type:`reset-consumed-counter`,spoolId:e}),visibleColumns:ut,assignmentMap:Xe,catalogMap:Ze,currencySymbol:Ye,dateFormat:fe,t:n,onSyncWeight:Be},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,K.jsx)(m9,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,onEdit:()=>d({spool:t,mode:`edit`}),onCopy:()=>d({spool:t,mode:`copy`}),onRestore:()=>Ie.mutate(t.id),onArchive:()=>m({type:`archive`,spoolId:t.id}),onDelete:()=>m({type:`delete`,spoolId:t.id}),onPrintLabel:()=>g([t.id]),onResetConsumedCounter:()=>m({type:`reset-consumed-counter`,spoolId:t.id}),visibleColumns:ut,assignmentMap:Xe,catalogMap:Ze,currencySymbol:Ye,dateFormat:fe,t:n,onSyncWeight:Be},t.id)})})]})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 bg-bambu-dark-tertiary/50 border-t border-bambu-dark-tertiary text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:mt?`${ht} ${n(ht===1?`inventory.spool`:`inventory.spools`)}`:(0,K.jsxs)(K.Fragment,{children:[n(`inventory.showing`),` `,vt*gt+1,` `,n(`inventory.to`),` `,Math.min((vt+1)*gt,ht),` `,n(`inventory.of`),` `,ht,` `,n(`inventory.spools`)]})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`inventory.show`)}),(0,K.jsxs)(`select`,{value:le,onChange:e=>St(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[15,30,50,100].map(e=>(0,K.jsx)(`option`,{value:e,children:e},e)),(0,K.jsx)(`option`,{value:-1,children:n(`inventory.all`)})]}),!mt&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:()=>ce(0),disabled:vt===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,title:`First page`,children:(0,K.jsx)(is,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>ce(e=>Math.max(0,e-1)),disabled:vt===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(ns,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[n(`inventory.page`),` `,vt+1,` `,n(`inventory.of`),` `,_t]}),(0,K.jsx)(`button`,{onClick:()=>ce(e=>Math.min(_t-1,e+1)),disabled:vt>=_t-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(ts,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>ce(_t-1),disabled:vt>=_t-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,title:`Last page`,children:(0,K.jsx)(as,{className:`w-4 h-4`})})]})]})]})]}):(0,K.jsx)(h9,{hasFilters:ct,onAddSpool:()=>d({spool:null,mode:`create`}),t:n}),u!==null&&(0,K.jsx)(mVe,{isOpen:!0,onClose:()=>d(null),spool:u.spool,mode:u.mode,currencySymbol:Ye,spoolmanMode:e,spoolsQueryKey:pe}),p&&(0,K.jsx)(Ed,{title:p.type===`delete`?n(`common.delete`):p.type===`archive`?n(`inventory.archive`):p.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounter`):n(`inventory.resetAllConsumedCounters`),message:p.type===`delete`?n(`inventory.deleteConfirm`):p.type===`archive`?n(`inventory.archiveConfirm`):p.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounterConfirm`):n(`inventory.resetAllConsumedCountersConfirm`,{count:ze.length}),confirmText:p.type===`delete`?n(`common.delete`):p.type===`archive`?n(`inventory.archive`):n(`inventory.resetConsumedCounter`),variant:p.type===`archive`?`warning`:`danger`,onConfirm:()=>{p.type===`delete`?Pe.mutate(p.spoolId):p.type===`archive`?Fe.mutate(p.spoolId):p.type===`reset-consumed-counter`?Le.mutate(p.spoolId):Re.mutate(ze),m(null)},onCancel:()=>m(null)}),(0,K.jsx)(hVe,{isOpen:re,onClose:()=>U(!1),columns:te,defaultColumns:s9,onSave:lt}),(0,K.jsx)(xVe,{isOpen:h!==null,onClose:()=>g(null),availableSpools:$e,initialSelectedIds:h??[],spoolmanMode:e}),_&&(0,K.jsx)(SVe,{onClose:()=>v(!1),onImported:e=>{v(!1),r.invalidateQueries({queryKey:pe}),i(n(`inventory.csv.importSuccess`,`{{count}} spools imported`,{count:e}),`success`)}}),(0,K.jsx)(CVe,{open:S,onClose:()=>C(!1),onPickLocation:e=>tt(String(e))})]})}function NVe({pageIndex:e,pageSize:t,totalRows:n,totalPages:r,onPageChange:i,onPageSizeChange:a,t:o}){let s=t===-1;if(r<=1&&!s)return null;let c=s?n||1:t;return(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-2 text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:s?`${n} ${o(n===1?`inventory.spool`:`inventory.spools`)}`:(0,K.jsxs)(K.Fragment,{children:[o(`inventory.showing`),` `,e*c+1,` `,o(`inventory.to`),` `,Math.min((e+1)*c,n),` `,o(`inventory.of`),` `,n,` `,o(`inventory.spools`)]})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:o(`inventory.show`)}),(0,K.jsxs)(`select`,{value:t,onChange:e=>a(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[15,30,50,100].map(e=>(0,K.jsx)(`option`,{value:e,children:e},e)),(0,K.jsx)(`option`,{value:-1,children:o(`inventory.all`)})]}),!s&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:()=>i(0),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(is,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>i(Math.max(0,e-1)),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(ns,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[o(`inventory.page`),` `,e+1,` `,o(`inventory.of`),` `,r]}),(0,K.jsx)(`button`,{onClick:()=>i(Math.min(r-1,e+1)),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(ts,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>i(r-1),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(as,{className:`w-4 h-4`})})]})]})]})}function p9({spool:e,remaining:t,pct:n,onClick:r,onPrintLabel:i,onCopy:a,t:o}){let s=G5({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`card`});return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors cursor-pointer ${e.archived_at?`opacity-50`:``}`,onClick:r,children:[(0,K.jsxs)(`div`,{className:`h-14 flex items-center justify-center`,style:s,children:[(0,K.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:Hd(e.color_name,e.rgba)||`-`}),a&&(0,K.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},className:`p-1.5 bg-black/20 hover:bg-black/40 text-white rounded-full transition-colors`,title:o(`inventory.copySpool`),children:(0,K.jsx)(Ds,{className:`w-3.5 h-3.5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h3`,{className:`font-semibold text-white`,children:[e.material,e.subtype?` ${e.subtype}`:``]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i&&(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),i()},className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,title:o(`inventory.labels.printOne`),"aria-label":o(`inventory.labels.printOne`),children:(0,K.jsx)(bl,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[`#`,e.id]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray mb-1`,children:[(0,K.jsx)(`span`,{children:o(`inventory.remaining`)}),(0,K.jsxs)(`span`,{children:[Math.round(n),`%`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full ${n>50?`bg-bambu-green`:n>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(n,100)}%`}})}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(t),`g`]})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.labelWeight`),`: `]}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:c9(e.label_weight)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.weightUsed`),`: `]}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e.weight_used>0?c9(e.weight_used):`-`})]})]}),e.note&&(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray/60 pt-2 border-t border-bambu-dark-tertiary truncate`,title:e.note,children:e.note})]})]})}function m9({spool:e,remaining:t,pct:n,onEdit:r,onCopy:i,onRestore:a,onArchive:o,onDelete:s,onPrintLabel:c,onResetConsumedCounter:l,visibleColumns:u,assignmentMap:d,catalogMap:f,currencySymbol:p,dateFormat:m,t:h,onSyncWeight:g}){return(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer ${e.archived_at?`opacity-50`:``}`,onClick:r,children:[u.map(r=>(0,K.jsx)(`td`,{className:`py-3 px-4`,children:u9[r]?.({spool:e,remaining:t,pct:n,assignmentMap:d,catalogMap:f,currencySymbol:p,dateFormat:m,t:h,onSyncWeight:g})},r)),(0,K.jsx)(`td`,{className:`py-3 px-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`button`,{onClick:r,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:h(`common.edit`),children:(0,K.jsx)(fl,{className:`w-4 h-4`})}),i&&(0,K.jsx)(`button`,{onClick:i,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:h(`inventory.copySpool`),children:(0,K.jsx)(Ds,{className:`w-4 h-4`})}),c&&(0,K.jsx)(`button`,{onClick:c,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:h(`inventory.labels.printOne`),children:(0,K.jsx)(bl,{className:`w-4 h-4`})}),l&&e.weight_used>0&&(0,K.jsx)(`button`,{onClick:l,className:`p-1.5 text-bambu-gray hover:text-orange-400 rounded transition-colors`,title:h(`inventory.resetConsumedCounterTooltip`),children:(0,K.jsx)(Hs,{className:`w-4 h-4`})}),e.archived_at?(0,K.jsx)(`button`,{onClick:a,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:h(`inventory.restore`),children:(0,K.jsx)(Tl,{className:`w-4 h-4`})}):(0,K.jsx)(`button`,{onClick:o,className:`p-1.5 text-bambu-gray hover:text-yellow-400 rounded transition-colors`,title:h(`inventory.archive`),children:(0,K.jsx)(wo,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:s,className:`p-1.5 text-bambu-gray hover:text-red-400 rounded transition-colors`,title:h(`common.delete`),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})})]})}function PVe({spools:e,headerSpool:t,remaining:n,pct:r,isExpanded:i,onToggle:a,onEdit:o,onCopy:s,onArchive:c,onDelete:l,onPrintLabel:u,onResetConsumedCounter:d,visibleColumns:f,assignmentMap:p,catalogMap:m,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v}){return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer bg-bambu-green/5`,onClick:a,children:[f.map((a,o)=>(0,K.jsx)(`td`,{className:`py-3 px-4`,children:o===0?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?``:`-rotate-90`}`}),u9[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v})]}):a===`id`?(0,K.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:_(`inventory.groupedSpools`,{count:e.length})}):u9[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v})},a)),(0,K.jsx)(`td`,{className:`py-3 px-4`,children:(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.map(e=>`#${e.id}`).join(`, `)})})]}),i&&e.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(0,K.jsx)(m9,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,onEdit:()=>o(e),onCopy:s?()=>s(e):void 0,onRestore:()=>{},onArchive:()=>c(e.id),onDelete:()=>l(e.id),onPrintLabel:u?()=>u(e.id):void 0,onResetConsumedCounter:d?()=>d(e.id):void 0,visibleColumns:f,assignmentMap:p,catalogMap:m,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v},e.id)})]})}function h9({hasFilters:e,onAddSpool:t,t:n}){return(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 px-4`,children:[(0,K.jsxs)(`div`,{className:`relative mb-6`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 -m-4 bg-bambu-green/5 rounded-full blur-2xl`}),(0,K.jsxs)(`div`,{className:`relative flex items-center justify-center w-24 h-24 rounded-2xl bg-gradient-to-br from-bambu-dark-secondary to-bambu-dark-tertiary border border-bambu-dark-tertiary shadow-lg`,children:[(0,K.jsx)(`div`,{className:`absolute -top-1 -right-1 w-3 h-3 rounded-full bg-bambu-green/30`}),(0,K.jsx)(`div`,{className:`absolute -bottom-2 -left-2 w-2 h-2 rounded-full bg-bambu-green/20`}),e?(0,K.jsx)(Nl,{className:`w-10 h-10 text-bambu-gray/40`,strokeWidth:1.5}):(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`div`,{className:`w-14 h-14 rounded-full border-4 border-bambu-gray/20 flex items-center justify-center`,children:(0,K.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-bambu-gray/10 border-2 border-bambu-gray/20`})}),(0,K.jsx)(`div`,{className:`absolute -bottom-1 -right-1 w-6 h-6 rounded-full bg-bambu-green flex items-center justify-center shadow-md`,children:(0,K.jsx)(`span`,{className:`text-white text-lg font-bold leading-none`,children:`+`})})]})]})]}),(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2 text-center`,children:e?n(`inventory.noSpoolsMatch`):n(`inventory.noSpools`).split(`.`)[0]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray text-center max-w-sm mb-6`,children:n(e?`inventory.noSpoolsMatchDesc`:`inventory.noSpools`)}),!e&&(0,K.jsxs)($,{onClick:t,children:[(0,K.jsx)(cl,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})}function g9(e,t){let n=e?.[t];return typeof n==`string`?n:``}function FVe(e){return e.replace(/(https?:\/\/(?:makerworld|public-cdn)\.bblmw\.com\/[^\s"']+)/gi,e=>`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`)}function _9(e){return e?/^https?:\/\/(makerworld|public-cdn)\.bblmw\.com\//i.test(e)?`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`:e:``}function v9(e,t){let n=e?.[t];return typeof n==`number`?n:null}function IVe(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function y9(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])y9(r,t+1,n);return n}function LVe(e,t){return t(e<1?`makerworld.phaseResolving`:`makerworld.phaseDownloading`)}function RVe(e){let[t,n]=(0,y.useState)(0);return(0,y.useEffect)(()=>{if(!e){n(0);return}let t=Date.now(),r=()=>n(Math.floor((Date.now()-t)/1e3));r();let i=window.setInterval(r,1e3);return()=>window.clearInterval(i)},[e]),t}function zVe(){let{t:e}=G(),{hasPermission:t}=sd(),{showToast:n}=xd(),r=Qa(),i=t(`makerworld:import`),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)({}),S=q({queryKey:[`makerworld-status`],queryFn:()=>Q.getMakerworldStatus()}),C=q({queryKey:[`library-folders`],queryFn:()=>Q.getLibraryFolders()}),w=q({queryKey:[`makerworld-recent-imports`],queryFn:()=>Q.getMakerworldRecentImports(10)}),T=q({queryKey:[`settings`],queryFn:()=>Q.getSettings()}),E=T.data?.use_slicer_api??!1,D=T.data?.preferred_slicer||`bambu_studio`,O=T.data?.open_in_slicer||D,k=E?D:O,A=k===`orcaslicer`?`OrcaSlicer`:`Bambu Studio`,[j,M]=(0,y.useState)(null),N=(e,t)=>{M({kind:`libraryFile`,id:e,filename:t})},P=J({mutationFn:e=>Q.resolveMakerworldUrl(e),onSuccess:(e,t)=>{c(e),v(t),x({})},onError:t=>n(t.message||e(`makerworld.errors.resolveFailed`),`error`)});(0,y.useEffect)(()=>{s!==null&&a.trim()!==_.trim()&&(c(null),v(``),x({}))},[a,s,_]);let F=J({mutationFn:({instanceId:e,profileId:t})=>Q.importMakerworldInstance(s?.model_id??0,e,t,l),onSuccess:t=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),t.profile_id&&x(e=>({...e,[t.profile_id]:t})),n(t.was_existing?e(`makerworld.alreadyInLibrary`):e(`makerworld.importSuccess`,{filename:t.filename}),`success`)},onError:t=>n(t.message||e(`makerworld.errors.downloadFailed`),`error`)}),I=J({mutationFn:({libraryFileId:e})=>Q.deleteLibraryFile(e),onSuccess:(t,{profileId:i})=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),r.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),x(e=>{let t={...e};return delete t[i],t}),m(null),n(e(`makerworld.importDeleted`),`success`)},onError:t=>{m(null),n(t.message||e(`makerworld.errors.deleteFailed`),`error`)}}),L=J({mutationFn:({instanceId:e,profileId:t})=>Q.importMakerworldInstance(s?.model_id??0,e,t,l),onSuccess:async e=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),r.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),e.profile_id&&x(t=>({...t,[e.profile_id]:e})),E?N(e.library_file_id,e.filename):await H(e.library_file_id,e.filename,k)},onError:t=>n(t.message||e(`makerworld.errors.downloadFailed`),`error`)}),R=RVe(F.isPending||L.isPending),z=LVe(R,e),B=e=>{e?.preventDefault();let t=a.trim();t&&P.mutate(t)};(0,y.useEffect)(()=>{if(!h)return;let e=e=>{e.key===`Escape`?g(null):e.key===`ArrowLeft`?g(e=>e&&e.index>0?{...e,index:e.index-1}:e):e.key===`ArrowRight`&&g(e=>e&&e.indexwindow.removeEventListener(`keydown`,e)},[h]);let V=e=>{let t=(Array.isArray(e.pictures)?e.pictures:[]).filter(e=>typeof e==`object`&&!!e).map(e=>({name:g9(e,`name`)||`image`,url:g9(e,`url`)})).filter(e=>e.url);if(t.length>0)return t;let n=g9(e,`cover`);return n?[{name:`cover`,url:n}]:[]},ee=async()=>{if(!s)return;let e=s.instances.filter(e=>{let t=v9(e,`profileId`);return t!==null&&!b[t]});if(e.length!==0){f({current:0,total:e.length});try{for(let t=0;t{try{let{token:r}=await Q.createLibrarySlicerToken(e),i=Q.getLibrarySlicerDownloadUrl(e,r,t);Uq(`${window.location.origin}${i}`,n)}catch{let t=Q.getLibraryFileDownloadUrl(e);Uq(`${window.location.origin}${t}`,n)}},te=s?.design,ne=IVe(te,`designCreator`),re=s?.instances??[],U=(s?.already_imported_library_ids.length??0)>0,ie=S.data?.has_cloud_token??!1,ae=S.data?.can_download??!1,W=(0,y.useMemo)(()=>g9(te,`coverUrl`),[te]),oe=g9(te,`title`),se=g9(te,`summary`),ce=g9(te,`license`),le=v9(te,`downloadCount`);return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 max-w-screen-2xl space-y-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)(hc,{className:`w-7 h-7 text-bambu-green`}),e(`makerworld.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`makerworld.description`)})]}),(0,K.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[1fr_20rem]`,children:[(0,K.jsxs)(`div`,{className:`space-y-6 min-w-0`,children:[!ie&&(0,K.jsx)(pd,{className:`border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20`,children:(0,K.jsx)(hd,{children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3 py-2`,children:[(0,K.jsx)(ss,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0`}),(0,K.jsxs)(`div`,{className:`text-sm`,children:[(0,K.jsx)(`p`,{className:`font-medium text-amber-900 dark:text-amber-100`,children:e(`makerworld.signInRequiredTitle`)}),(0,K.jsxs)(`p`,{className:`text-amber-800 dark:text-amber-200 mt-1`,children:[e(`makerworld.signInRequiredBody`),` `,(0,K.jsx)(bi,{to:`/profiles`,className:`underline`,children:e(`makerworld.openCloudSettings`)})]})]})]})})}),(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`makerworld.pasteUrlHeader`)})}),(0,K.jsx)(hd,{children:(0,K.jsxs)(`form`,{onSubmit:B,className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:e(`makerworld.pasteUrlPlaceholder`),className:`flex-1 min-w-0 px-3 py-2 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,autoComplete:`off`}),(0,K.jsxs)($,{type:`submit`,variant:`primary`,disabled:!a.trim()||P.isPending,children:[P.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(ko,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.resolveButton`)})]})]})})]}),s&&(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{children:(0,K.jsxs)(`div`,{className:`flex gap-4 py-2`,children:[W&&(0,K.jsx)(`img`,{src:_9(W),alt:oe,className:`w-32 h-32 object-cover rounded`,loading:`lazy`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`h3`,{className:`text-xl font-semibold truncate`,children:oe||e(`makerworld.untitledModel`)}),ne&&(0,K.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(`makerworld.byCreator`,{name:g9(ne,`name`)})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-3 mt-2 text-xs text-gray-500 dark:text-gray-400`,children:[le!==null&&(0,K.jsx)(`span`,{children:e(`makerworld.downloadsCount`,{count:le})}),ce&&(0,K.jsxs)(`span`,{children:[e(`makerworld.licensePrefix`),`: `,ce]}),U&&(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400`,children:[(0,K.jsx)($o,{className:`w-3 h-3`}),` `,e(`makerworld.alreadyImported`)]})]}),se&&(0,K.jsx)(`div`,{className:`mt-3 text-sm prose prose-sm max-w-none dark:prose-invert line-clamp-3`,dangerouslySetInnerHTML:{__html:HJ.sanitize(FVe(se))}}),s&&(0,K.jsxs)(`a`,{href:`https://makerworld.com/models/${s.model_id}${s.profile_id?`#profileId-${s.profile_id}`:``}`,target:`_blank`,rel:`noopener noreferrer`,className:`mt-3 inline-flex items-center gap-1 text-xs text-brand-500 hover:underline`,children:[(0,K.jsx)(Us,{className:`w-3 h-3`}),` `,e(`makerworld.openOnMakerworld`)]})]})]})})}),s&&re.length>0&&(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`makerworld.platesHeader`,{count:re.length})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(`label`,{className:`text-xs text-gray-600 dark:text-gray-400`,children:e(`makerworld.importTo`)}),(0,K.jsxs)(`select`,{value:l??``,onChange:e=>u(e.target.value?Number(e.target.value):null),className:`text-sm px-2 py-1 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,disabled:d!==null,children:[(0,K.jsx)(`option`,{value:``,children:e(`makerworld.folderAuto`)}),(C.data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>y9(e)).map(({folder:e,depth:t})=>(0,K.jsx)(`option`,{value:e.id,children:`${`— `.repeat(t)}${e.name}`},e.id))]}),(0,K.jsx)($,{variant:`primary`,size:`sm`,disabled:!i||!ae||d!==null||F.isPending||L.isPending,onClick:ee,children:d===null?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.importAll`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),(0,K.jsxs)(`span`,{className:`ml-2`,children:[e(`makerworld.importAllProgress`,{current:d.current,total:d.total}),R>0&&` · ${z} · ${R}s`]})]})})]})]})}),(0,K.jsx)(hd,{children:(0,K.jsx)(`div`,{className:`grid gap-3`,children:re.map((t,n)=>{let r=v9(t,`id`),a=v9(t,`profileId`),o=g9(t,`title`),s=g9(t,`cover`),c=v9(t,`materialCnt`),l=t?.needAms===!0,u=v9(t,`downloadCount`),f=t?.compatibility??null,p=t?.otherCompatibility??null,h=f?.devProductName??null,_=Array.isArray(p)?p.map(e=>e?.devProductName??``).filter(Boolean):[];if(r==null)return null;let v=F.isPending&&F.variables?.instanceId===r,y=L.isPending&&L.variables?.instanceId===r,x=a===null?void 0:b[a];return(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border rounded border-gray-200 dark:border-gray-700`,children:[(0,K.jsxs)(`div`,{className:`flex gap-3 items-center`,children:[(()=>{let n=V(t),r=n.length>0;return(0,K.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&g({images:n,index:0}),className:`relative w-16 h-16 shrink-0 rounded overflow-hidden group`,"aria-label":e(`makerworld.openGallery`),children:[s?(0,K.jsx)(`img`,{src:_9(s),alt:``,className:`w-16 h-16 object-cover`,loading:`lazy`}):(0,K.jsx)(`div`,{className:`w-16 h-16 bg-gray-100 dark:bg-gray-800`}),n.length>1&&(0,K.jsxs)(`span`,{className:`absolute bottom-0.5 right-0.5 bg-black/70 text-white text-[10px] px-1.5 py-0.5 rounded flex items-center gap-1`,children:[(0,K.jsx)(Oc,{className:`w-2.5 h-2.5`}),n.length]})]})})(),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`font-medium truncate`,children:o||e(`makerworld.plateDefaultName`,{n:n+1})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-xs text-gray-500 dark:text-gray-400 mt-1`,children:[h&&(0,K.jsx)(`span`,{className:`font-medium text-gray-700 dark:text-gray-300`,children:e(`makerworld.slicedFor`,{printer:h,defaultValue:`Sliced for {{printer}}`})}),c!==null&&(0,K.jsx)(`span`,{children:e(`makerworld.materialCount`,{count:c})}),l&&(0,K.jsx)(`span`,{children:e(`makerworld.amsRequired`)}),u!==null&&(0,K.jsx)(`span`,{children:e(`makerworld.downloadsCount`,{count:u})})]}),_.length>0&&(0,K.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,title:_.join(`, `),children:e(`makerworld.alsoCompatible`,{printers:_.slice(0,6).join(`, `)+(_.length>6?`…`:``),defaultValue:`Also marked compatible: {{printers}}`})})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,disabled:!i||!ae||v||y||d!==null,onClick:()=>F.mutate({instanceId:r,profileId:a}),title:ae?void 0:e(`makerworld.signInRequiredTitle`),children:v?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),(0,K.jsxs)(`span`,{className:`ml-2`,children:[z,R>0&&` · ${R}s`]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.importToLibrary`)})]})}),(0,K.jsx)($,{variant:`primary`,size:`sm`,disabled:!i||!ae||v||y||d!==null,onClick:()=>L.mutate({instanceId:r,profileId:a}),title:ae?void 0:e(`makerworld.signInRequiredTitle`),children:y?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),(0,K.jsxs)(`span`,{className:`ml-2`,children:[z,R>0&&` · ${R}s`]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Us,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.sliceIn`,{slicer:A})})]})})]})]}),x&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 pl-20 text-xs`,children:[(0,K.jsx)($o,{className:`w-3.5 h-3.5 text-emerald-600 dark:text-emerald-400 shrink-0`}),(0,K.jsx)(`span`,{className:`text-emerald-700 dark:text-emerald-300`,children:x.was_existing?e(`makerworld.lastImportAlreadyInLibrary`):e(`makerworld.lastImportSuccess`)}),(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>{let e=x.folder_id?`/files?folder=${x.folder_id}`:`/files`;window.location.assign(e)},children:[(0,K.jsx)(rc,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.viewInLibrary`)})]}),E?(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>N(x.library_file_id,x.filename),children:[(0,K.jsx)(ws,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`slice.action`,`Slice`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>H(x.library_file_id,x.filename,`bambu_studio`),children:[(0,K.jsx)(Us,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.openInBambuStudio`)})]}),(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>H(x.library_file_id,x.filename,`orcaslicer`),children:[(0,K.jsx)(Us,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.openInOrcaSlicer`)})]})]}),(0,K.jsx)(`div`,{className:`ml-auto`,children:(0,K.jsx)($,{variant:`ghost`,size:`sm`,disabled:I.isPending&&I.variables?.profileId===a,onClick:()=>{a!==null&&m({libraryFileId:x.library_file_id,profileId:a,filename:x.filename})},title:e(`makerworld.deleteImport`),children:I.isPending&&I.variables?.profileId===a?(0,K.jsx)(X,{className:`w-3.5 h-3.5 animate-spin`}):(0,K.jsx)(hu,{className:`w-3.5 h-3.5 text-red-500`})})})]})]},r)})})})]})]}),(0,K.jsx)(`aside`,{className:`lg:sticky lg:top-6 lg:self-start min-w-0`,children:w.data&&w.data.length>0&&(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-base font-semibold`,children:e(`makerworld.recentImportsHeader`)})}),(0,K.jsx)(hd,{children:(0,K.jsx)(`div`,{className:`flex flex-col gap-2 max-h-[28rem] overflow-y-auto -mx-2 px-2`,children:w.data.map(t=>(0,K.jsxs)(`div`,{className:`flex gap-2 p-2 border rounded border-gray-200 dark:border-gray-700`,children:[t.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getLibraryFileThumbnailUrl(t.library_file_id),alt:``,className:`w-12 h-12 shrink-0 object-cover rounded bg-gray-100 dark:bg-gray-800`,loading:`lazy`}):(0,K.jsx)(`div`,{className:`w-12 h-12 shrink-0 rounded bg-gray-100 dark:bg-gray-800`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,K.jsx)(`p`,{className:`text-xs font-medium truncate`,title:t.filename,children:t.filename}),(0,K.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{let e=t.folder_id?`/files?folder=${t.folder_id}`:`/files`;window.location.assign(e)},title:e(`makerworld.viewInLibrary`),children:(0,K.jsx)(rc,{className:`w-3.5 h-3.5`})}),E?(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>N(t.library_file_id,t.filename),title:e(`slice.action`,`Slice`),children:(0,K.jsx)(ws,{className:`w-3.5 h-3.5`})}):(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>H(t.library_file_id,t.filename,`bambu_studio`),title:e(`makerworld.openInBambuStudio`),children:(0,K.jsx)(Us,{className:`w-3.5 h-3.5`})}),t.source_url&&(0,K.jsx)(`a`,{href:t.source_url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center h-7 w-7 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300`,title:e(`makerworld.openOnMakerworld`),children:(0,K.jsx)(hc,{className:`w-3.5 h-3.5`})})]})]})]},t.library_file_id))})})]})})]}),(0,K.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 pt-4 border-t border-gray-200 dark:border-gray-700`,children:e(`makerworld.disclaimer`)}),p&&(0,K.jsx)(Ed,{title:e(`makerworld.deleteImport`),message:e(`makerworld.confirmDelete`,{filename:p.filename}),confirmText:e(`makerworld.deleteImport`),variant:`danger`,isLoading:I.isPending,loadingText:e(`makerworld.importDeleting`),onCancel:()=>m(null),onConfirm:()=>I.mutate({libraryFileId:p.libraryFileId,profileId:p.profileId})}),j&&(0,K.jsx)(Bq,{source:j,onClose:()=>M(null)}),h&&(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:()=>g(null),role:`dialog`,"aria-modal":`true`,children:[(0,K.jsx)(`button`,{type:`button`,className:`absolute top-4 right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white`,onClick:e=>{e.stopPropagation(),g(null)},"aria-label":e(`common.close`,`Close`),children:(0,K.jsx)(Pu,{className:`w-5 h-5`})}),h.images.length>1&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{type:`button`,className:`absolute left-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:h.index===0,onClick:e=>{e.stopPropagation(),g(e=>e&&{...e,index:Math.max(0,e.index-1)})},"aria-label":e(`makerworld.galleryPrev`),children:(0,K.jsx)(ns,{className:`w-6 h-6`})}),(0,K.jsx)(`button`,{type:`button`,className:`absolute right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:h.index>=h.images.length-1,onClick:e=>{e.stopPropagation(),g(e=>e&&{...e,index:Math.min(e.images.length-1,e.index+1)})},"aria-label":e(`makerworld.galleryNext`),children:(0,K.jsx)(ts,{className:`w-6 h-6`})})]}),(0,K.jsx)(`img`,{src:_9(h.images[h.index].url),alt:h.images[h.index].name,className:`max-w-[90vw] max-h-[90vh] object-contain`,onClick:e=>e.stopPropagation()}),h.images.length>1&&(0,K.jsxs)(`div`,{className:`absolute bottom-6 left-1/2 -translate-x-1/2 text-white bg-black/60 px-3 py-1 rounded text-xs`,children:[h.index+1,` / `,h.images.length]})]})]})}var b9=[`DEBUG`,`INFO`,`WARNING`,`ERROR`],x9={DEBUG:`text-gray-400`,INFO:`text-blue-400`,WARNING:`text-yellow-400`,ERROR:`text-red-400`},BVe={DEBUG:Ho,INFO:kc,WARNING:vu,ERROR:ss};function VVe(){let e=Qa(),[t,n]=(0,y.useState)(!0),[r,i]=(0,y.useState)(new Set),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`ALL`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),p=(0,y.useRef)(null),{data:m,isLoading:h,refetch:g}=q({queryKey:[`application-logs`,s,a],queryFn:()=>td.getLogs({limit:200,level:s===`ALL`?void 0:s,search:a||void 0}),refetchInterval:d?2e3:!1,enabled:l});(0,y.useEffect)(()=>{l||f(!1)},[l]);let _=J({mutationFn:()=>td.clearLogs(),onSuccess:()=>{e.invalidateQueries({queryKey:[`application-logs`]})}});(0,y.useEffect)(()=>{t&&p.current&&m?.entries&&(p.current.scrollTop=p.current.scrollHeight)},[m?.entries,t]);let v=e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},b=e=>{let t=e.split(` `);return t.length>=2?t[1]:e},x=(0,y.useMemo)(()=>m?.entries??[],[m?.entries]),S=(0,y.useMemo)(()=>[...x].reverse(),[x]),C=({level:e})=>(0,K.jsx)(BVe[e]||kc,{className:`w-3.5 h-3.5 ${x9[e]||`text-gray-400`}`});return(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`button`,{onClick:()=>u(!l),className:`w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/50 transition-colors`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${d?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,K.jsx)(Ho,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{className:`text-left`,children:[(0,K.jsx)(`p`,{className:`font-medium text-white`,children:`Application Logs`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:d?`Live streaming - ${m?.filtered_count??0} entries`:`View and filter application logs`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[d&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 bg-bambu-green/20 rounded text-bambu-green text-xs`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 bg-bambu-green rounded-full animate-pulse`}),`Live`]}),l?(0,K.jsx)(rs,{className:`w-5 h-5 text-bambu-gray`}):(0,K.jsx)(es,{className:`w-5 h-5 text-bambu-gray`})]})]}),l&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary`,children:[(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 flex-wrap`,children:[d?(0,K.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),f(!1)},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-red-500/20 text-red-400 hover:bg-red-500/30 rounded transition-colors`,children:[(0,K.jsx)(tu,{className:`w-4 h-4`}),`Stop`]}):(0,K.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),f(!0),g()},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 rounded transition-colors`,children:[(0,K.jsx)(hl,{className:`w-4 h-4`}),`Start`]}),(0,K.jsxs)(`button`,{onClick:()=>_.mutate(),disabled:_.isPending||x.length===0,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50`,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),`Clear`]}),(0,K.jsx)(`button`,{onClick:()=>g(),disabled:h,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50`,children:(0,K.jsx)(Cl,{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:t,onChange:e=>n(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark-tertiary`}),`Auto-scroll`]}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[m?.filtered_count??0,`/`,m?.total_in_file??0]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Nl,{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:`Search message or logger name...`,value:a,onChange:e=>o(e.target.value),className:`w-full pl-8 pr-8 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),a&&(0,K.jsx)(`button`,{onClick:()=>o(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark-secondary rounded border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>c(`ALL`),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${s===`ALL`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`All`}),b9.map((e,t)=>(0,K.jsx)(`button`,{onClick:()=>c(e),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${t===b9.length-1?`rounded-r`:``} ${s===e?`${x9[e]} bg-bambu-dark-tertiary`:`text-bambu-gray hover:text-white`}`,children:e},e))]})]})]}),(0,K.jsx)(`div`,{ref:p,className:`overflow-auto font-mono text-xs bg-black min-h-[300px] max-h-[500px]`,children:x.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-[300px] text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`mb-2`,children:`No log entries found`}),(0,K.jsx)(`p`,{className:`text-sm`,children:`Log file may be empty or cleared`})]}):(0,K.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary/30`,children:S.map((e,t)=>{let n=r.has(t),i=e.message.includes(` +`+n+`}`}return String(e)}function rBe({setting:e,onClose:t,onDeleted:n,onDuplicate:r,onEdit:i,hasPermission:a,t:o}){let{showToast:s}=xd(),c=Qa(),[l,u]=(0,y.useState)(!1),{data:d,isLoading:f}=q({queryKey:[`cloudSettingDetail`,e.setting_id],queryFn:()=>Q.getCloudSettingDetail(e.setting_id)}),p=J({mutationFn:()=>Q.deleteCloudSetting(e.setting_id),onSuccess:()=>{s(o(`profiles.presets.toast.deleted`)),c.invalidateQueries({queryKey:[`cloudSettings`]}),n()},onError:e=>s(e.message,`error`)}),m=y7(e.setting_id),h=v7(e.name,d?.setting?.inherits);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)(pd,{className:`w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden`,children:(0,K.jsxs)(hd,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white truncate`,children:e.name}),m&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full`,children:o(`profiles.presets.editable`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`capitalize`,children:o(`profiles.presets.types.${e.type}`)}),h.printer&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{children:`•`}),(0,K.jsx)(`span`,{children:h.printer})]})]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4`,children:f?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):d?(0,K.jsx)(`pre`,{className:`text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full`,children:S7(d)}):(0,K.jsx)(`div`,{className:`text-center py-16 text-bambu-gray`,children:o(`profiles.presets.failedToLoadDetails`)})}),l?(0,K.jsxs)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 text-red-400`,children:[(0,K.jsx)(vu,{className:`w-5 h-5`}),(0,K.jsx)(`span`,{className:`font-medium`,children:o(`profiles.presets.deleteConfirm`)})]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:o(`profiles.presets.deleteWarning`,{name:e.name})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>u(!1),disabled:p.isPending,className:`flex-1`,children:o(`common.cancel`)}),(0,K.jsxs)($,{variant:`danger`,onClick:()=>p.mutate(),disabled:p.isPending,className:`flex-1`,children:[p.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(hu,{className:`w-4 h-4`}),o(`common.delete`)]})]})]}):(0,K.jsx)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,className:`flex-1`,children:o(`common.close`)}),(0,K.jsxs)($,{variant:`secondary`,onClick:r,disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noDuplicatePermission`),children:[(0,K.jsx)(Ds,{className:`w-4 h-4`}),o(`profiles.presets.duplicate`)]}),m&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`secondary`,onClick:i,disabled:f||!d||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noEditPermission`),children:[(0,K.jsx)(pl,{className:`w-4 h-4`}),o(`common.edit`)]}),(0,K.jsx)($,{variant:`danger`,onClick:()=>u(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noDeletePermission`),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]})})]})})})}function C7(){try{let e=localStorage.getItem(`bambusy_preset_templates`);return e?JSON.parse(e):[]}catch{return[]}}function w7(e){localStorage.setItem(`bambusy_preset_templates`,JSON.stringify(e))}function iBe({onClose:e,onApply:t,t:n}){let{showToast:r}=xd(),[i,a]=(0,y.useState)(C7),[o,s]=(0,y.useState)(`all`),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(`{}`),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(null),x=o===`all`?i:i.filter(e=>e.type===o),S=e=>{a(e),w7(e)},C=e=>{S(i.filter(t=>t.id!==e)),b(null),r(n(`profiles.templates.toast.deleted`))},w=e=>{l(e.id),d(e.name),p(e.description),h(JSON.stringify(e.settings,null,2)),_(null)},T=()=>{if(!(!c||!u.trim()))try{let e=JSON.parse(m);S(i.map(t=>t.id===c?{...t,name:u.trim(),description:f.trim(),settings:e}:t)),l(null),r(n(`profiles.templates.toast.updated`))}catch(e){_(e.message)}},E=()=>{l(null),d(``),p(``),h(`{}`),_(null)},D=e=>{S(i.map(t=>t.id===e?{...t,showInModal:!t.showInModal}:t))},O={filament:{label:n(`profiles.presets.types.filament`),icon:Ls,color:`text-amber-400`},print:{label:n(`profiles.presets.types.process`),icon:Ll,color:`text-blue-400`},printer:{label:n(`profiles.presets.types.printer`),icon:bl,color:`text-purple-400`}},k=v?i.find(e=>e.id===v):null;return(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&(v?b(null):c?E():e())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[v,c,e]),(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:[k&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-60`,children:(0,K.jsx)(pd,{className:`w-full max-w-md`,children:(0,K.jsxs)(hd,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,K.jsx)(`div`,{className:`p-2 bg-red-500/20 rounded-lg`,children:(0,K.jsx)(vu,{className:`w-6 h-6 text-red-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:n(`profiles.templates.deleteTitle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.deleteWarning`)})]})]}),(0,K.jsx)(`p`,{className:`text-white mb-6`,children:n(`profiles.templates.deleteConfirm`,{name:k.name})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>b(null),className:`flex-1`,children:n(`common.cancel`)}),(0,K.jsxs)($,{onClick:()=>C(v),className:`flex-1 bg-red-500 hover:bg-red-600`,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),n(`common.delete`)]})]})]})})}),(0,K.jsx)(pd,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,children:(0,K.jsxs)(hd,{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.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Ql,{className:`w-5 h-5 text-amber-400`}),n(`profiles.templates.title`)]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.typeFilter`)}),[`all`,`filament`,`print`,`printer`].map(e=>(0,K.jsx)(`button`,{onClick:()=>s(e),className:`px-3 py-1 text-sm rounded-lg transition-colors ${o===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:e===`all`?n(`common.all`):O[e].label},e))]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:x.length===0?(0,K.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,K.jsx)(Ql,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,K.jsx)(`p`,{children:n(`profiles.templates.noTemplates`)}),(0,K.jsx)(`p`,{className:`text-sm mt-1`,children:n(`profiles.templates.createFirst`)})]}):(0,K.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>{let r=O[e.type],i=r.icon;return c===e.id?(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-green`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mb-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:n(`profiles.templates.namePlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:n(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray mb-1 block`,children:n(`profiles.templates.settingsJson`)}),(0,K.jsx)(`textarea`,{value:m,onChange:e=>{h(e.target.value),_(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${g?`border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`}),g&&(0,K.jsx)(`p`,{className:`text-xs text-red-400 mt-1`,children:g})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{size:`sm`,onClick:T,disabled:!u.trim(),children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),`Save`]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:E,children:`Cancel`})]})]},e.id):(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors`,children:[(0,K.jsx)(i,{className:`w-5 h-5 ${r.color} flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description})]}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded`,children:n(`profiles.templates.fieldsCount`,{count:Object.keys(e.settings).length})}),(0,K.jsx)(`button`,{onClick:()=>D(e.id),className:`p-1 transition-colors ${e.showInModal?`text-bambu-green hover:text-bambu-green/70`:`text-bambu-gray hover:text-white`}`,title:e.showInModal?n(`profiles.templates.shownInModals`):n(`profiles.templates.hiddenInModals`),children:e.showInModal?(0,K.jsx)(Gs,{className:`w-4 h-4`}):(0,K.jsx)(Ws,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>t(e),className:`px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors`,children:n(`profiles.templates.apply`)}),(0,K.jsx)(`button`,{onClick:()=>w(e),className:`p-1 text-bambu-gray hover:text-white`,title:n(`common.edit`),children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>b(e.id),className:`p-1 text-bambu-gray hover:text-red-400`,title:n(`common.delete`),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]},e.id)})})})]})})]})}function T7({onClose:e,leftPreset:t,rightPreset:n,leftLabel:r,rightLabel:i,t:a}){let[o,s]=(0,y.useState)(`changes`),[c,l]=(0,y.useState)(``),u=(0,y.useMemo)(()=>{let e=new Set([...Object.keys(t),...Object.keys(n)]),r=[];for(let i of e){if(i===`inherits`||i===`version`)continue;let e=t[i],a=n[i],o=i in t,s=i in n,c;c=!o&&s?`added`:o&&!s?`removed`:JSON.stringify(e)===JSON.stringify(a)?`same`:`changed`,r.push({key:i,left:e,right:a,status:c})}return r.sort((e,t)=>{let n={changed:0,added:1,removed:2,same:3};return n[e.status]===n[t.status]?e.key.localeCompare(t.key):n[e.status]-n[t.status]})},[t,n]),d=(0,y.useMemo)(()=>{let e=[...u];if(o===`changes`&&(e=e.filter(e=>e.status!==`same`)),c){let t=c.toLowerCase();e=e.filter(e=>e.key.toLowerCase().includes(t)||String(e.left).toLowerCase().includes(t)||String(e.right).toLowerCase().includes(t))}return e},[u,o,c]),f=(0,y.useMemo)(()=>({added:u.filter(e=>e.status===`added`).length,removed:u.filter(e=>e.status===`removed`).length,changed:u.filter(e=>e.status===`changed`).length,same:u.filter(e=>e.status===`same`).length}),[u]),p=e=>{if(e===void 0)return`—`;if(e===null)return`null`;if(Array.isArray(e))return e.length===0?`[]`:e.length===1?String(e[0]):e.join(`, `);if(typeof e==`object`)return JSON.stringify(e);let t=String(e);if(t.includes(`\\n`)||t.length>100){let e=t.split(`\\n`).length;if(e>1)return`[${e} lines of G-code/script]`;if(t.length>100)return t.substring(0,100)+`…`}return t};return(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(pd,{className:`w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden`,children:(0,K.jsxs)(hd,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(pc,{className:`w-5 h-5 text-blue-400`}),a(`profiles.diff.title`)]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark`,children:[(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.left`)}),(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:r})]}),(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.right`)}),(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:i})]})]}),(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-green-400`,children:[(0,K.jsx)(_l,{className:`w-3.5 h-3.5`}),f.added,` `,a(`profiles.diff.added`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-red-400`,children:[(0,K.jsx)(el,{className:`w-3.5 h-3.5`}),f.removed,` `,a(`profiles.diff.removed`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-amber-400`,children:[(0,K.jsx)(ko,{className:`w-3.5 h-3.5`}),f.changed,` `,a(`profiles.diff.changed`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[(0,K.jsx)(Vs,{className:`w-3.5 h-3.5`}),f.same,` `,a(`profiles.diff.same`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:a(`profiles.diff.searchFields`),className:`pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48`})]}),f.same>0&&(0,K.jsxs)(`div`,{className:`flex rounded overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>s(`changes`),className:`px-3 py-1.5 text-sm transition-colors ${o===`changes`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`profiles.diff.changes`)}),(0,K.jsx)(`button`,{onClick:()=>s(`all`),className:`px-3 py-1.5 text-sm transition-colors ${o===`all`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`common.all`)})]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:d.length===0?(0,K.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,K.jsx)(Vs,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,K.jsx)(`p`,{children:a(o===`changes`?`profiles.diff.noDifferences`:`profiles.diff.noFieldsMatch`)})]}):(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{className:`sticky top-0 bg-bambu-dark-secondary`,children:(0,K.jsxs)(`tr`,{className:`text-sm text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:a(`profiles.diff.field`)}),(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:r}),(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:i})]})}),(0,K.jsx)(`tbody`,{children:d.map(e=>{let t={added:`bg-green-500/10`,removed:`bg-red-500/10`,changed:`bg-amber-500/10`,same:``}[e.status],n={added:(0,K.jsx)(_l,{className:`w-3.5 h-3.5 text-green-400`}),removed:(0,K.jsx)(el,{className:`w-3.5 h-3.5 text-red-400`}),changed:(0,K.jsx)(ko,{className:`w-3.5 h-3.5 text-amber-400`}),same:(0,K.jsx)(Vs,{className:`w-3.5 h-3.5 text-bambu-gray-dark`})}[e.status];return(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary ${t}`,children:[(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n,(0,K.jsx)(`span`,{className:`text-sm text-white font-mono`,children:e.key})]})}),(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`removed`?`text-red-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:p(e.left)})}),(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`added`?`text-green-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:p(e.right)})})]},e.key)})})]})})]})})})}function aBe({onClose:e,initialData:t,allPresets:n,t:r}){let{showToast:i}=xd(),a=Qa(),o=!!t?.setting_id,[s,c]=(0,y.useState)(`common`),[l,u]=(0,y.useState)(t?.type||`filament`),[d,f]=(0,y.useState)(t?.name?o?t.name:`${t.name} (Copy)`:``),[p,m]=(0,y.useState)(t?.base_id||``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(t?.setting||{inherits:``}),[b,x]=(0,y.useState)(JSON.stringify(t?.setting||{inherits:``},null,2)),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(C7),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(!0),[ee,H]=(0,y.useState)(null),[te,ne]=(0,y.useState)(!1),re=(0,y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer})[l]||[],[n,l]),U=(0,y.useMemo)(()=>re.filter(e=>y7(e.setting_id)),[re]),{data:ie}=q({queryKey:[`cloudFields`,l],queryFn:()=>Q.getCloudFields(l===`print`?`process`:l),staleTime:1e3*60*60}),{data:ae}=q({queryKey:[`allPresetDetails`,l,U.map(e=>e.setting_id).join(`,`)],queryFn:async()=>{let e={};for(let t=0;t{try{let t=await Q.getCloudSettingDetail(e.setting_id);return{id:e.setting_id,detail:t}}catch{return null}}))).forEach(t=>{t&&(e[t.id]=t.detail)})}return e},enabled:U.length>0,staleTime:1e3*60*10}),{data:W,isLoading:oe}=q({queryKey:[`cloudSettingDetail`,p],queryFn:()=>Q.getCloudSettingDetail(p),enabled:!!p});(0,y.useEffect)(()=>{s!==`json`&&x(JSON.stringify(_,null,2))},[_,s]);let se=(0,y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer}[l]||[]).filter(e=>!y7(e.setting_id)).sort((e,t)=>e.name.localeCompare(t.name)),[n,l]);(0,y.useEffect)(()=>{if(!p)return;let e=se.find(e=>e.setting_id===p);e&&(g(e.name),o||(v({inherits:e.name}),x(JSON.stringify({inherits:e.name},null,2))))},[p,se,o]);let ce=(0,y.useMemo)(()=>{let e=ie?.fields||[],t=new Set(e.map(e=>e.key)),n=new Set,i=new Set([`inherits`,`updated_time`,`compatible_printers`,`compatible_prints`]);ae&&Object.values(ae).forEach(e=>{e?.setting&&Object.keys(e.setting).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)})}),Object.keys(_).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)});let a=Array.from(n).sort().map(e=>({key:e,label:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),type:`text`,category:`discovered`,description:r(`profiles.presets.discoveredFromPresets`)}));return[...e,...a]},[ie,ae,_,r]),le=ce.filter(e=>e.label.toLowerCase().includes(w.toLowerCase())||e.key.toLowerCase().includes(w.toLowerCase())),ue=()=>{if(O.trim()){let e=O.trim().toLowerCase().replace(/\s+/g,`_`);de(e,``),k(``),j(!1),i(r(`profiles.presets.toast.fieldAdded`,{key:e}))}},de=(e,t)=>{v(n=>{let r={...n};return t===``||t===void 0?delete r[e]:r[e]=t,r})},fe=e=>{v(t=>({...t,...e.settings})),H(e.name),i(r(`profiles.templates.toast.applied`))},pe=()=>{if(!I.trim())return;let e={..._};if(delete e.inherits,Object.keys(e).length===0){i(r(`profiles.presets.noOverridesToSave`),`error`);return}let t={id:Date.now().toString(),name:I.trim(),description:R.trim()||r(`profiles.presets.customTemplate`),type:l,settings:e,showInModal:B},n=[...M,t];N(n),w7(n),F(!1),L(``),z(``),V(!0),i(r(`profiles.templates.toast.created`))},me=(0,y.useMemo)(()=>M.filter(e=>e.type===l&&e.showInModal),[l,M]),he=e=>{x(e);try{v(JSON.parse(e)),C(null)}catch(e){C(e.message)}},ge=e=>{e.preventDefault(),D(!1);let t=e.dataTransfer.files[0];if(t&&t.name.endsWith(`.json`)){let e=new FileReader;e.onload=e=>{try{let t=e.target?.result,n=JSON.parse(t),a=n.setting||n;v(e=>({...e,...a})),x(JSON.stringify({..._,...a},null,2)),i(r(`profiles.presets.fileImported`))}catch{i(r(`profiles.presets.invalidJsonFile`),`error`)}},e.readAsText(t)}},_e=J({mutationFn:()=>{let e={..._},t=l===`filament`?`filament_settings_id`:l===`print`?`print_settings_id`:`printer_settings_id`;e[t]=`"${d}"`;let n={type:l,name:d,base_id:p,setting:e};return Q.createCloudSetting(n)},onSuccess:async()=>{i(r(`profiles.presets.toast.created`)),await a.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>i(e.message,`error`)}),ve=J({mutationFn:()=>{if(!t?.setting_id)throw Error(r(`profiles.presets.noSettingId`));return Q.updateCloudSetting(t.setting_id,{name:d,setting:_})},onSuccess:async()=>{i(r(`profiles.presets.toast.updated`)),a.removeQueries({queryKey:[`cloudSettingDetail`]}),await a.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>i(e.message,`error`)}),ye=o?ve:_e,be=W?.setting?.inherits,xe=be?se.find(e=>e.name===be):void 0,{data:Se}=q({queryKey:[`cloudSettingDetail`,xe?.setting_id],queryFn:()=>Q.getCloudSettingDetail(xe.setting_id),enabled:!!xe?.setting_id}),Ce=(0,y.useMemo)(()=>{let e=Se?.setting||{},t=W?.setting||{},n=p&&ae?.[p]?.setting?ae[p].setting:{};return{...e,...t,...n}},[p,W,Se,ae]),we=e=>{if(e==null)return``;if(Array.isArray(e)){let t=[...new Set(e.map(e=>String(e)))];return t.length===1?t[0]:e.join(`, `)}return String(e)},Te=e=>{let t=_[e.key],n=Ce[e.key],i=we(n),a=oe?r(`common.loading`):i||``,o=`w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`;if(e.type===`boolean`){let r=t===`1`||t===void 0&&n===`1`;return(0,K.jsx)(`button`,{type:`button`,onClick:()=>de(e.key,t===`1`?`0`:`1`),className:`w-8 h-5 rounded-full transition-colors ${r?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${r?`translate-x-3.5`:`translate-x-0.5`}`})})}return e.type===`select`?(0,K.jsxs)(`select`,{value:t||``,onChange:t=>de(e.key,t.target.value),className:o,children:[(0,K.jsx)(`option`,{value:``,children:a}),e.options?.map(e=>(0,K.jsx)(`option`,{value:e.value,children:e.label},e.value))]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:e.type===`number`?`number`:`text`,value:t===void 0?``:String(t),onChange:t=>de(e.key,t.target.value),step:e.step,min:e.min,max:e.max,placeholder:a,className:o}),e.unit&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.unit})]})},Ee=(0,y.useMemo)(()=>W?.setting?W.setting:{},[W]);return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onDragOver:e=>{e.preventDefault(),D(!0)},onDragLeave:()=>D(!1),onDrop:ge,children:[te&&p&&(0,K.jsx)(T7,{onClose:()=>ne(!1),leftPreset:Ee,rightPreset:_,leftLabel:r(`profiles.presets.baseLabel`,{name:h||p}),rightLabel:r(`profiles.presets.currentLabel`,{name:d||r(`profiles.presets.newPreset`)}),t:r}),(0,K.jsx)(pd,{className:`w-full max-w-6xl max-h-[90vh] flex flex-col overflow-y-auto`,children:(0,K.jsxs)(hd,{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.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:r(o?`profiles.presets.editPreset`:t?`profiles.presets.duplicatePreset`:`profiles.presets.createNewPreset`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`profiles.presets.customizeSettings`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[p&&(0,K.jsxs)(`button`,{onClick:()=>ne(!0),className:`flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:r(`profiles.presets.compareWithBase`),children:[(0,K.jsx)(pc,{className:`w-4 h-4`}),r(`profiles.presets.compare`)]}),(0,K.jsx)(`button`,{onClick:e,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]})]}),E&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10`,children:(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(Su,{className:`w-12 h-12 text-bambu-green mx-auto mb-2`}),(0,K.jsx)(`p`,{className:`text-bambu-green font-medium`,children:r(`profiles.presets.dropJsonToImport`)})]})}),(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 max-[640px]:grid-cols-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`common.type`)}),(0,K.jsxs)(`select`,{value:l,onChange:e=>{u(e.target.value),m(``)},className:`w-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:`filament`,children:r(`profiles.presets.types.filament`)}),(0,K.jsx)(`option`,{value:`print`,children:r(`profiles.presets.types.process`)}),(0,K.jsx)(`option`,{value:`printer`,children:r(`profiles.presets.types.printer`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.basePreset`)}),(0,K.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:``,children:r(`profiles.presets.selectBasePreset`)}),se.map(e=>(0,K.jsx)(`option`,{value:e.setting_id,children:e.name},e.setting_id))]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.presetName`)}),(0,K.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(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(`profiles.presets.myCustomPreset`)})]})]}),h&&(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,K.jsxs)(`p`,{className:`flex items-center gap-1`,children:[(0,K.jsx)($o,{className:`w-3 h-3 text-bambu-green`}),r(`profiles.presets.inheritsFrom`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:h}),oe&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin ml-1`})]})})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary max-[640px]:flex-wrap max-[640px]:items-center`,children:[(0,K.jsxs)(`button`,{onClick:()=>c(`common`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`common`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Jl,{className:`w-4 h-4`}),r(`profiles.presets.tabs.common`)]}),(0,K.jsxs)(`button`,{onClick:()=>c(`fields`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`fields`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Bc,{className:`w-4 h-4`}),r(`profiles.presets.tabs.allFields`)]}),(0,K.jsxs)(`button`,{onClick:()=>c(`json`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`json`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(xs,{className:`w-4 h-4`}),`JSON`,S&&(0,K.jsx)(ss,{className:`w-3 h-3 text-red-400`})]}),(0,K.jsx)(`div`,{className:`flex-1 max-[640px]:hidden`}),(0,K.jsxs)(`button`,{onClick:()=>{let e=new Blob([JSON.stringify({name:d,type:l,base_id:p,setting:_},null,2)],{type:`application/json`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${d||`preset`}.json`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t),i(r(`profiles.presets.toast.exported`))},className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.exportToJson`),children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),r(`common.download`)]}),(0,K.jsxs)(`button`,{onClick:()=>document.getElementById(`file-import`)?.click(),className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.importFromJson`),children:[(0,K.jsx)(Su,{className:`w-4 h-4`}),r(`common.upload`)]}),(0,K.jsx)(`input`,{id:`file-import`,type:`file`,accept:`.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];if(t){let e=new FileReader;e.onload=e=>{try{let t=JSON.parse(e.target?.result),n=t.setting||t;v(e=>({...e,...n})),i(r(`profiles.presets.fileImported`))}catch{i(r(`profiles.presets.invalidJson`),`error`)}},e.readAsText(t)}}})]}),(0,K.jsxs)(`div`,{className:`flex-1 p-4`,children:[s===`common`&&(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,K.jsx)(Ql,{className:`w-4 h-4 text-amber-400`}),r(`profiles.templates.title`)]}),Object.keys(_).filter(e=>e!==`inherits`).length>0&&(0,K.jsxs)(`button`,{onClick:()=>F(!P),className:`text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors`,children:[(0,K.jsx)(Ol,{className:`w-3 h-3`}),r(`profiles.presets.saveAsTemplate`)]})]}),P&&(0,K.jsxs)(`div`,{className:`mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 mb-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:I,onChange:e=>L(e.target.value),placeholder:r(`profiles.templates.namePlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),placeholder:r(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{size:`sm`,onClick:pe,disabled:!I.trim(),children:[(0,K.jsx)(Ol,{className:`w-3 h-3`}),r(`common.save`)]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>F(!1),children:r(`common.cancel`)})]}),(0,K.jsxs)(`button`,{onClick:()=>V(!B),className:`flex items-center gap-1.5 text-xs transition-colors ${B?`text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[B?(0,K.jsx)(Gs,{className:`w-3.5 h-3.5`}):(0,K.jsx)(Ws,{className:`w-3.5 h-3.5`}),r(B?`profiles.templates.shownInModals`:`profiles.templates.hiddenInModals`)]})]})]}),ee&&(0,K.jsxs)(`div`,{className:`mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2`,children:[(0,K.jsx)($o,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-green`,children:[r(`profiles.presets.templateApplied`),` `,(0,K.jsx)(`span`,{className:`font-medium`,children:ee})]}),(0,K.jsx)(`button`,{onClick:()=>H(null),className:`ml-auto text-bambu-green/70 hover:text-bambu-green`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[me.map(e=>(0,K.jsxs)(`button`,{onClick:()=>fe(e),className:`p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e.description})]},e.id)),me.length===0&&(0,K.jsx)(`p`,{className:`col-span-3 text-center text-bambu-gray text-sm py-4`,children:r(`profiles.presets.noTemplatesSelected`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark mt-2 text-center`,children:r(`profiles.presets.manageTemplatesHint`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.commonSettings`)}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-3`,children:ce.slice(0,10).map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 max-[640px]:flex-col max-[640px]:items-start`,children:[(0,K.jsx)(`label`,{className:`text-sm text-bambu-gray flex-shrink-0`,children:e.label}),(0,K.jsx)(`div`,{className:`w-48 max-[640px]:w-full`,children:Te(e)})]},e.key))})]}),Object.keys(_).length>1&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.currentOverrides`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Object.entries(_).filter(([e])=>e!==`inherits`).map(([e,t])=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded`,children:[e,`: `,String(t).slice(0,20),(0,K.jsx)(`button`,{onClick:()=>de(e,void 0),className:`hover:text-white`,children:(0,K.jsx)(Pu,{className:`w-3 h-3`})})]},e))})]})]}),s===`fields`&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,style:{height:`400px`},children:[(0,K.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.availableFields`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:ae?r(`profiles.templates.fieldsCount`,{count:ce.length}):r(`common.loading`)})]}),(0,K.jsxs)(`div`,{className:`relative mb-3 flex-shrink-0`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:r(`profiles.presets.searchFieldsPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-1 pr-2 min-h-0`,children:[le.filter(e=>!(e.key in _)).map(e=>{let t=Ce[e.key],n=we(t);return(0,K.jsxs)(`div`,{onClick:()=>{v(t=>({...t,[e.key]:n||``}))},className:`flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.label}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark truncate`,children:e.key})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[n&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate`,title:n,children:[n.slice(0,20),n.length>20?`...`:``]}),(0,K.jsx)(`div`,{className:`w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors`,children:(0,K.jsx)(_l,{className:`w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors`})})]})]},e.key)}),le.filter(e=>!(e.key in _)).length===0&&(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-4 text-sm`,children:r(w?`profiles.presets.noMatchingFields`:`profiles.presets.allFieldsAdded`)})]}),(0,K.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:A?(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),onKeyDown:e=>e.key===`Enter`&&ue(),placeholder:`custom_field_name`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)($,{size:`sm`,onClick:ue,disabled:!O.trim(),children:(0,K.jsx)(_l,{className:`w-4 h-4`})}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>{j(!1),k(``)},children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}):(0,K.jsxs)(`button`,{onClick:()=>j(!0),className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),r(`profiles.presets.addCustomField`)]})})]}),(0,K.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.yourOverrides`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:r(`profiles.templates.fieldsCount`,{count:Object.keys(_).filter(e=>e!==`inherits`).length})})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-2 pr-2 min-h-0`,children:[Object.entries(_).filter(([e])=>e!==`inherits`).map(([e,t])=>{let n=ce.find(t=>t.key===e);return(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:n?.label||e}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark`,children:e})]}),(0,K.jsx)(`button`,{onClick:()=>de(e,void 0),className:`p-1 text-bambu-gray hover:text-red-400 transition-colors`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}),n?Te(n):(0,K.jsx)(`input`,{type:`text`,value:String(t),onChange:t=>de(e,t.target.value),className:`w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]},e)}),Object.keys(_).filter(e=>e!==`inherits`).length===0&&(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(Jl,{className:`w-8 h-8 mx-auto mb-2 opacity-50`}),(0,K.jsx)(`p`,{className:`text-sm`,children:r(`profiles.presets.noOverridesYet`)}),(0,K.jsx)(`p`,{className:`text-xs mt-1`,children:r(`profiles.presets.clickFieldsToAdd`)})]})]}),Object.keys(_).filter(e=>e!==`inherits`).length>0&&(0,K.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:(0,K.jsxs)(`button`,{onClick:()=>{F(!0),c(`common`)},className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),r(`profiles.presets.saveAsTemplate`)]})})]})]}),s===`json`&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[S&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-red-400 text-sm`,children:[(0,K.jsx)(ss,{className:`w-4 h-4`}),S]}),(0,K.jsx)(`textarea`,{value:b,onChange:e=>he(e.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${S?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,spellCheck:!1}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`profiles.presets.jsonTip`)})]})]}),(0,K.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:e,className:`flex-1`,children:r(`common.cancel`)}),(0,K.jsxs)($,{onClick:()=>ye.mutate(),disabled:ye.isPending||!d.trim()||!o&&!p||!!S,className:`flex-1`,children:[ye.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):o?(0,K.jsx)(Ol,{className:`w-4 h-4`}):(0,K.jsx)(_l,{className:`w-4 h-4`}),r(o?`common.save`:t?`common.duplicate`:`common.create`)]})]})]})})]})}function oBe({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,hasPermission:a,t:o}){let[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`all`),[d,f]=(0,y.useState)(`all`),[p,m]=(0,y.useState)(`all`),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(`all`),[b,x]=(0,y.useState)(`all`),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(null),[A,j]=(0,y.useState)(null),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)([null,null]),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(null),ee=Qa(),H=(0,y.useMemo)(()=>[...e.filament.map(e=>({...e,type:`filament`})),...e.printer.map(e=>({...e,type:`printer`})),...e.process.map(e=>({...e,type:`process`}))].map(e=>({...e,meta:v7(e.name)})),[e]),te=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return H.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[H,i]),ne=(0,y.useMemo)(()=>p===`all`?null:i.find(e=>e.id.toString()===p)?.model||null,[p,i]),re=(0,y.useMemo)(()=>H.filter(e=>l===`all`||e.type===l).filter(e=>{if(d===`all`)return!0;let t=y7(e.setting_id);return d===`custom`?t:!t}).filter(e=>{if(p===`all`||!ne)return!0;let t=e.meta.printer?.toLowerCase()||``,n=ne.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>h===`all`||e.meta.nozzle===h).filter(e=>_===`all`||e.meta.filamentType===_).filter(e=>b===`all`||e.meta.layerHeight===b).filter(e=>s===``||e.name.toLowerCase().includes(s.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[H,l,d,p,ne,h,_,b,s]),U=e=>{if(P){let t=I[0]?.setting_id===e.setting_id,n=I[1]?.setting_id===e.setting_id;if(t)L([I[1],null]);else if(n)L([I[0],null]);else if(!I[0])L([e,null]);else if(I[1]){if(I[0].type!==e.type)return;L([I[0],e])}else{if(I[0].type!==e.type)return;L([I[0],e])}}else C(e)},ie=e=>{if(I[0]?.setting_id===e.setting_id)return 0;if(I[1]?.setting_id===e.setting_id)return 1},ae=async e=>{try{let t=await Q.getCloudSettingDetail(e.setting_id);k({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{}}),C(null)}catch(e){console.error(`Failed to fetch preset details for duplication:`,e)}},W=async e=>{try{ee.removeQueries({queryKey:[`cloudSettingDetail`,e.setting_id]});let t=await Q.getCloudSettingDetail(e.setting_id);j({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{},setting_id:e.setting_id}),C(null)}catch(e){console.error(`Failed to fetch preset details for editing:`,e)}},oe=()=>{u(`all`),f(`all`),m(`all`),g(`all`),v(`all`),x(`all`),c(``)},se=l!==`all`||d!==`all`||p!==`all`||h!==`all`||_!==`all`||b!==`all`||s!==``,ce=e.filament.length+e.printer.length+e.process.length;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:o(`profiles.cloudView.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[(0,K.jsxs)($,{variant:P?`primary`:`secondary`,onClick:()=>{P?(F(!1),L([null,null])):F(!0)},children:[(0,K.jsx)(pc,{className:`w-4 h-4`}),o(P?`common.cancel`:`profiles.presets.compare`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>D(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noTemplatesPermission`),children:[(0,K.jsx)(Ql,{className:`w-4 h-4`}),o(`profiles.cloudView.templates`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:n,disabled:r||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noRefreshPermission`),children:[(0,K.jsx)(Cl,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),o(`profiles.cloudView.refresh`)]}),(0,K.jsxs)($,{onClick:()=>T(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noCreatePermission`),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),o(`profiles.cloudView.newPreset`)]})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(lc,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(b7,{label:o(`profiles.cloudView.filters.type`),value:l,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`),count:ce},{value:`filament`,label:o(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:o(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:o(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>u(e)}),(0,K.jsx)(b7,{label:o(`profiles.cloudView.filters.owner`),value:d,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},{value:`custom`,label:o(`profiles.cloudView.filters.myPresets`)},{value:`builtin`,label:o(`profiles.cloudView.filters.builtIn`)}],onChange:e=>f(e)}),te.printers.length>0&&(0,K.jsx)(b7,{label:o(`profiles.cloudView.filters.printer`),value:p,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...te.printers.map(e=>({value:e.id,label:e.name}))],onChange:m}),te.nozzles.length>0&&(0,K.jsx)(b7,{label:o(`profiles.cloudView.filters.nozzle`),value:h,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...te.nozzles.map(e=>({value:e,label:e}))],onChange:g}),te.filaments.length>0&&(l===`all`||l===`filament`)&&(0,K.jsx)(b7,{label:o(`profiles.cloudView.filters.filament`),value:_,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...te.filaments.map(e=>({value:e,label:e}))],onChange:v}),te.layerHeights.length>0&&(l===`all`||l===`process`)&&(0,K.jsx)(b7,{label:o(`profiles.cloudView.filters.layer`),value:b,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...te.layerHeights.map(e=>({value:e,label:e}))],onChange:x}),se&&(0,K.jsx)(`button`,{onClick:oe,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:o(`profiles.cloudView.clearFilters`)})]})]}),P&&(0,K.jsx)(`div`,{className:`mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(pc,{className:`w-5 h-5 text-blue-400`}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:o(`profiles.cloudView.compareMode`)}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:I[0]?o(`profiles.cloudView.selectAnotherPreset`,{type:I[0].type}):o(`profiles.cloudView.clickTwoPresets`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${I[0]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:I[0]?I[0].name:o(`profiles.cloudView.selectFirst`)}),(0,K.jsx)(ko,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${I[1]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:I[1]?I[1].name:o(`profiles.cloudView.selectSecond`)})]}),I[0]&&I[1]&&(0,K.jsxs)($,{size:`sm`,onClick:async()=>{try{let[e,t]=await Promise.all([Q.getCloudSettingDetail(I[0].setting_id),Q.getCloudSettingDetail(I[1].setting_id)]);V([e.setting||{},t.setting||{}]),z(!0)}catch{}},children:[(0,K.jsx)(pc,{className:`w-4 h-4`}),o(`profiles.cloudView.compareNow`)]})]})]})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),o(`profiles.cloudView.lastSynced`),` `,bf(t.toISOString(),`system`,o)]}),(0,K.jsx)(`span`,{children:o(`profiles.cloudView.showingCount`,{showing:re.length,total:ce})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),(0,K.jsxs)(`span`,{children:[`= `,o(`profiles.presets.myPreset`)]})]})]}),re.length===0?(0,K.jsxs)(`div`,{className:`text-center py-16`,children:[(0,K.jsx)(Nc,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:o(`profiles.cloudView.noPresetsFound`)}),se&&(0,K.jsx)(`button`,{onClick:oe,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:o(`profiles.cloudView.clearFilters`)})]}):(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(Ls,{className:`w-4 h-4 text-amber-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.filament`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,re.filter(e=>e.type===`filament`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[re.filter(e=>e.type===`filament`).map(e=>(0,K.jsx)(x7,{setting:e,onClick:()=>U(e),onDuplicate:()=>ae(e),compareMode:P,isCompareSelected:ie(e)!==void 0,compareIndex:ie(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),re.filter(e=>e.type===`filament`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noFilamentPresets`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(Ll,{className:`w-4 h-4 text-blue-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.process`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,re.filter(e=>e.type===`process`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[re.filter(e=>e.type===`process`).map(e=>(0,K.jsx)(x7,{setting:e,onClick:()=>U(e),onDuplicate:()=>ae(e),compareMode:P,isCompareSelected:ie(e)!==void 0,compareIndex:ie(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),re.filter(e=>e.type===`process`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noProcessPresets`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(bl,{className:`w-4 h-4 text-purple-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.printer`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,re.filter(e=>e.type===`printer`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[re.filter(e=>e.type===`printer`).map(e=>(0,K.jsx)(x7,{setting:e,onClick:()=>U(e),onDuplicate:()=>ae(e),compareMode:P,isCompareSelected:ie(e)!==void 0,compareIndex:ie(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),re.filter(e=>e.type===`printer`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noPrinterPresets`)})]})]})]}),S&&(0,K.jsx)(rBe,{setting:S,onClose:()=>C(null),onDeleted:()=>C(null),onDuplicate:()=>ae(S),onEdit:()=>W(S),hasPermission:a,t:o}),(w||O||A||M)&&(0,K.jsx)(aBe,{onClose:()=>{T(!1),k(null),j(null),N(null)},initialData:A||O||(M?{type:M.type,name:``,base_id:``,setting:M.setting}:void 0),allPresets:e,t:o}),E&&(0,K.jsx)(iBe,{onClose:()=>D(!1),onApply:e=>{N({type:e.type,setting:e.settings}),D(!1)},t:o}),R&&B&&I[0]&&I[1]&&(0,K.jsx)(T7,{onClose:()=>{z(!1),V(null)},leftPreset:B[0],rightPreset:B[1],leftLabel:I[0].name,rightLabel:I[1].name,t:o})]})}function sBe(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),{hasPermission:r}=sd(),[i,a]=(0,y.useState)(`cloud`),[o,s]=(0,y.useState)(),{data:c,isLoading:l}=q({queryKey:[`cloudStatus`],queryFn:Q.getCloudStatus}),{data:u=[]}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:d,isLoading:f,refetch:p,dataUpdatedAt:m}=q({queryKey:[`cloudSettings`],queryFn:()=>Q.getCloudSettings(),enabled:!!c?.is_authenticated,retry:!1,staleTime:1e3*60*5});(0,y.useEffect)(()=>{m&&s(new Date(m))},[m]);let h=J({mutationFn:Q.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]}),t.removeQueries({queryKey:[`cloudSettings`]}),n(e(`profiles.toast.loggedOut`))}});return l?(0,K.jsx)(`div`,{className:`p-4 md:p-8 flex items-center justify-center min-h-[400px]`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(ys,{className:`w-7 h-7 text-bambu-green`}),e(`profiles.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`profiles.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary mb-6`,children:[(0,K.jsxs)(`button`,{onClick:()=>a(`cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(ys,{className:`w-4 h-4`}),e(`profiles.tabs.bambuCloud`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`orca_cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`orca_cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(ys,{className:`w-4 h-4`}),e(`profiles.tabs.orcaCloud`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`local`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`local`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(yc,{className:`w-4 h-4`}),e(`profiles.tabs.local`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`kprofiles`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`kprofiles`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(uc,{className:`w-4 h-4`}),e(`profiles.tabs.kprofiles`)]})]}),i===`cloud`&&(0,K.jsxs)(K.Fragment,{children:[c?.is_authenticated&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`profiles.connectedAs`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:c.email}),c.region&&(0,K.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:c.region===`china`?e(`profiles.login.regionChina`):e(`profiles.login.regionGlobal`)})]})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>h.mutate(),disabled:h.isPending||!r(`cloud:auth`),title:r(`cloud:auth`)?void 0:e(`profiles.noLogoutPermission`),children:[(0,K.jsx)(Wc,{className:`w-4 h-4`}),e(`profiles.logout`)]})]}),c?.is_authenticated?f?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):d?(0,K.jsx)(oBe,{settings:d,lastSyncTime:o,onRefresh:()=>p(),isRefreshing:f,printers:u,hasPermission:r,t:e}):(0,K.jsxs)(`div`,{className:`text-center py-16`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`profiles.failedToLoad`)}),(0,K.jsx)($,{onClick:()=>p(),children:e(`profiles.retry`)})]}):(0,K.jsx)(tBe,{onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]})},t:e})]}),i===`orca_cloud`&&(0,K.jsx)(Xze,{}),i===`local`&&(0,K.jsx)(Gze,{}),i===`kprofiles`&&(0,K.jsx)(Vze,{}),(0,K.jsx)(nBe,{})]})}function cBe(e,t){let n=(t||``).toUpperCase().replace(/[- ]/g,``),r=n.includes(`X1`),i=n.includes(`P1`),a=n.includes(`A1MINI`),o=n.includes(`A1`)&&!a,s=n.includes(`H2D`),c=n.includes(`H2C`),l=n.includes(`H2S`),u=s||c||l,d=n.includes(`P2S`),f=n.includes(`X2D`),p=d||f;switch(e){case`Lubricate Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Clean Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Lubricate Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Nozzle/Hotend`:return r||i?`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`:a||o?`https://wiki.bambulab.com/en/a1-mini/troubleshooting/nozzle-clog`:u?`https://wiki.bambulab.com/en/h2/maintenance/nozzl-cold-pull-maintenance-and-cleaning`:p?`https://wiki.bambulab.com/en/p2s/maintenance/cold-pull-maintenance-hotend`:`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`;case`Check Belt Tension`:return r?`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`:i?`https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance`:a?`https://wiki.bambulab.com/en/a1-mini/maintenance/belt_tension`:o?`https://wiki.bambulab.com/en/a1/maintenance/belt_tension`:s?`https://wiki.bambulab.com/en/h2/maintenance/belt-tension`:c?`https://wiki.bambulab.com/en/h2c/maintenance/belt-tension`:l?`https://wiki.bambulab.com/en/h2s/maintenance/belt-tension`:p?`https://wiki.bambulab.com/en/p2s/maintenance/belt-tension`:`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`;case`Clean Carbon Rods`:return r||i?`https://wiki.bambulab.com/en/general/carbon-rods-clearance`:null;case`Clean Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Build Plate`:return`https://wiki.bambulab.com/en/filament-acc/acc/pei-plate-clean-guide`;case`Check PTFE Tube`:return r||i?`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`:a||o?`https://wiki.bambulab.com/en/a1-mini/maintenance/ptfe-tube`:s?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:l?`https://wiki.bambulab.com/en/h2s/maintenance/replace-ptfe-tube-on-h2s-printer`:c?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`;case`Replace HEPA Filter`:case`HEPA Filter`:case`Replace Carbon Filter`:case`Carbon Filter`:return u?`https://wiki.bambulab.com/en/h2/maintenance/replace-smoke-purifier-air-filte`:`https://wiki.bambulab.com/en/x1/maintenance/replace-carbon-filter`;case`Lubricate Left Nozzle Rail`:case`Left Nozzle Rail`:return u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;default:return null}}var E7={Droplet:Ls,Flame:ec,Ruler:Dl,Sparkles:Ql,Square:tu,Cable:Uo,Wrench:Nu,Calendar:qo,Timer:mu,Cog:ws,Fan:Ks,Zap:Iu,Wind:Mu,Thermometer:pu,Layers:Nc,Box:Bo,Target:cu,RefreshCw:Cl,Settings:Rl,Filter:lc,CircleDot:ds};function D7(e){return e&&E7[e]||Nu}function O7(e,t,n){if(t===`days`){if(e<1)return n?n(`common.today`):`Today`;if(e===1)return n?n(`maintenance.day`):`1 day`;if(e<7){let t=Math.round(e);return n?n(`maintenance.days`,{count:t}):`${t} days`}if(e<180){let t=Math.round(e/7);return t===1?n?n(`maintenance.week`):`1 week`:n?n(`maintenance.weeks`,{count:t}):`${t} weeks`}let t=Math.round(e/30);return t===1?n?n(`maintenance.month`):`1 month`:n?n(`maintenance.months`,{count:t}):`${t} months`}else{if(e<1)return`${Math.round(e*60)}m`;if(e<24)return`${e<10?e.toFixed(1):Math.round(e)}h`;let t=e/24;if(t<7)return`${t<2?t.toFixed(1):Math.round(t)}d`;let n=t/7;return n<12?`${n<2?n.toFixed(1):Math.round(n)}w`:`${Math.round(n/4)}mo`}}function k7(e,t,n){return t===`days`?e===1?n?n(`maintenance.day`):`1 day`:e===7?n?n(`maintenance.week`):`1 week`:e===14?n?n(`maintenance.weeks`,{count:2}):`2 weeks`:e===30?n?n(`maintenance.month`):`1 month`:e===60?n?n(`maintenance.months`,{count:2}):`2 months`:e===90?n?n(`maintenance.months`,{count:3}):`3 months`:e===180?n?n(`maintenance.months`,{count:6}):`6 months`:e===365?n?n(`maintenance.year`):`1 year`:n?n(`maintenance.days`,{count:e}):`${e} days`:`${e}h`}function lBe({item:e,onPerform:t,onToggle:n,hasPermission:r,t:i}){let a=D7(e.maintenance_type_icon),o=e.interval_type||`hours`,s=(()=>{if(o===`days`){let t=e.days_since_maintenance??0;return Math.max(0,Math.min(100,t/e.interval_hours*100))}return Math.max(0,Math.min(100,(e.interval_hours-e.hours_until_due)/e.interval_hours*100))})(),c=()=>e.enabled?e.is_due?`text-red-400`:e.is_warning?`text-amber-400`:`text-bambu-green`:`text-bambu-gray`;return(0,K.jsx)(`div`,{className:`rounded-xl border p-4 transition-all ${e.enabled?e.is_due?`bg-red-500/5 border-red-500/20`:e.is_warning?`bg-amber-500/5 border-amber-500/20`:`bg-bambu-dark-secondary border-bambu-dark-tertiary`:`bg-bambu-dark-secondary/50`}`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3 max-[550px]:flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`relative p-2.5 rounded-lg shrink-0 ${e.is_due?`bg-red-500/20`:e.is_warning?`bg-amber-500/20`:e.enabled?`bg-bambu-dark`:`bg-bambu-dark/50`}`,children:[(0,K.jsx)(a,{className:`w-5 h-5 ${c()}`}),e.enabled&&(e.is_due||e.is_warning)&&(0,K.jsx)(`span`,{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${e.is_due?`bg-red-500`:`bg-amber-500`} animate-pulse`})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`font-medium truncate ${e.enabled?`text-white`:`text-bambu-gray`}`,children:e.maintenance_type_name}),o===`days`&&(0,K.jsx)(`span`,{title:i(`maintenance.timeBasedInterval`),children:(0,K.jsx)(qo,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})}),(()=>{let t=e.maintenance_type_wiki_url||cBe(e.maintenance_type_name,e.printer_model);return t?(0,K.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-bambu-green transition-colors shrink-0`,title:i(`maintenance.viewDocumentation`),onClick:e=>e.stopPropagation(),children:(0,K.jsx)(Us,{className:`w-3.5 h-3.5`})}):null})()]}),(0,K.jsx)(`div`,{className:`mt-2 mb-1.5`,children:(0,K.jsx)(`div`,{className:`w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500 ${e.enabled?e.is_due?`bg-red-500`:e.is_warning?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-gray/30`}`,style:{width:`${s}%`}})})}),(0,K.jsxs)(`div`,{className:`text-xs flex items-center gap-1 ${c()}`,children:[e.is_due&&(0,K.jsx)(vu,{className:`w-3 h-3`}),e.is_warning&&!e.is_due&&(0,K.jsx)(_s,{className:`w-3 h-3`}),!e.is_due&&!e.is_warning&&e.enabled&&(0,K.jsx)($o,{className:`w-3 h-3`}),(()=>{if(!e.enabled)return i(`common.disabled`);if(o===`days`){let t=e.days_until_due??0;return e.is_due?i(`maintenance.overdueBy`,{duration:O7(Math.abs(t),`days`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:O7(t,`days`,i)}):i(`maintenance.timeLeft`,{duration:O7(t,`days`,i)})}else return e.is_due?i(`maintenance.overdueBy`,{duration:O7(Math.abs(e.hours_until_due),`hours`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:O7(e.hours_until_due,`hours`,i)}):i(`maintenance.timeLeft`,{duration:O7(e.hours_until_due,`hours`,i)})})()]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 max-[550px]:w-full max-[550px]:justify-end max-[550px]:mt-1`,children:[(0,K.jsx)(`span`,{title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionUpdate`),children:(0,K.jsx)(y5,{checked:e.enabled,onChange:t=>n(e.id,t),disabled:!r(`maintenance:update`)})}),(0,K.jsxs)($,{size:`sm`,variant:e.is_due?`primary`:`secondary`,onClick:()=>t(e.id),disabled:!e.enabled||!r(`maintenance:update`),title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionPerform`),className:`!px-3`,children:[(0,K.jsx)(Tl,{className:`w-3.5 h-3.5`}),i(`common.reset`)]})]})]})})}function uBe({overview:e,onPerform:t,onToggle:n,onSetHours:r,hasPermission:i,t:a}){let[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(e.total_print_hours.toFixed(1)),f=[...e.maintenance_items].sort((e,t)=>e.is_due&&!t.is_due?-1:!e.is_due&&t.is_due?1:e.is_warning&&!t.is_warning?-1:!e.is_warning&&t.is_warning?1:e.maintenance_type_id-t.maintenance_type_id),p=f.find(e=>e.enabled&&(e.is_due||e.is_warning)),m=()=>{let t=parseFloat(u);!isNaN(t)&&t>=0&&(r(e.printer_id,t),l(!1))};return(0,K.jsxs)(pd,{className:`overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`p-5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:e.printer_name}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.due_count>0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-red-500/20 text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)(vu,{className:`w-3 h-3`}),a(`maintenance.overdueCount`,{count:e.due_count})]}),e.warning_count>0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-amber-500/20 text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),a(`maintenance.dueSoonCount`,{count:e.warning_count})]}),e.due_count===0&&e.warning_count===0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)($o,{className:`w-3 h-3`}),a(`maintenance.allGood`)]})]})]}),(0,K.jsxs)(`button`,{onClick:()=>s(!o),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors`,children:[o?(0,K.jsx)(rs,{className:`w-4 h-4`}):(0,K.jsx)(es,{className:`w-4 h-4`}),a(o?`common.collapse`:`common.expand`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-6 mt-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 bg-bambu-dark/50 rounded-lg`,children:(0,K.jsx)(mu,{className:`w-4 h-4 text-bambu-gray`})}),c?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&l(!1)},className:`w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`,min:`0`,step:`1`,autoFocus:!0}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`common.hours`)}),(0,K.jsx)($,{size:`sm`,onClick:m,children:a(`common.save`)}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>l(!1),children:a(`common.cancel`)})]}):(0,K.jsxs)(`button`,{onClick:()=>{i(`maintenance:update`)&&(d(Math.round(e.total_print_hours).toString()),l(!0))},className:`group ${i(`maintenance:update`)?``:`cursor-not-allowed opacity-60`}`,title:i(`maintenance:update`)?void 0:a(`maintenance.noPermissionEditHours`),children:[(0,K.jsxs)(`div`,{className:`text-sm font-medium text-white ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``} transition-colors flex items-center gap-1`,children:[Math.round(e.total_print_hours),` `,a(`common.hours`),(0,K.jsx)(dl,{className:`w-3 h-3 text-bambu-gray ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``}`})]}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:a(`maintenance.totalPrintTime`)})]})]}),(0,K.jsx)(`div`,{className:`w-px h-10 bg-bambu-dark-tertiary`}),p&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${p.is_due?`bg-red-500/20`:`bg-amber-500/20`}`,children:(0,K.jsx)(D7(p.maintenance_type_icon),{className:`w-4 h-4 ${p.is_due?`text-red-400`:`text-amber-400`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-sm font-medium ${p.is_due?`text-red-400`:`text-amber-400`}`,children:p.maintenance_type_name}),(0,K.jsx)(`div`,{className:`text-xs ${p.is_due?`text-red-400/70`:`text-amber-400/70`}`,children:p.is_due?a(`common.overdue`):a(`maintenance.dueSoon`)})]})]})]})]}),o&&(0,K.jsx)(hd,{className:`pt-0 border-t border-bambu-dark-tertiary`,children:(0,K.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4`,children:f.map(e=>(0,K.jsx)(lBe,{item:e,onPerform:t,onToggle:n,hasPermission:i,t:a},e.id))})})]})}function dBe({overview:e,types:t,onUpdateInterval:n,onAddType:r,onUpdateType:i,onDeleteType:a,onRestoreDefaults:o,isRestoringDefaults:s,onAssignType:c,onRemoveItem:l,hasPermission:u,t:d}){let[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(``),[g,_]=(0,y.useState)(`hours`),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(`100`),[T,E]=(0,y.useState)(`hours`),[D,O]=(0,y.useState)(`Wrench`),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(new Set),[N,P]=(0,y.useState)(null),[F,I]=(0,y.useState)(null),L=(0,y.useMemo)(()=>e?e.map(e=>({id:e.printer_id,name:e.printer_name})):[],[e]),R=t=>e?e.filter(e=>e.maintenance_items.some(e=>e.maintenance_type_id===t)).map(e=>({printerId:e.printer_id,printerName:e.printer_name,itemId:e.maintenance_items.find(e=>e.maintenance_type_id===t)?.id})):[],z=t=>{if(!e)return[];let n=new Set(R(t).map(e=>e.printerId));return L.filter(e=>!n.has(e.id))},[B,V]=(0,y.useState)(null),[ee,H]=(0,y.useState)(``),[te,ne]=(0,y.useState)(``),[re,U]=(0,y.useState)(`hours`),[ie,ae]=(0,y.useState)(`Wrench`),[W,oe]=(0,y.useState)(``),se=e=>{V(e),H(e.name),ne(e.default_interval_hours.toString()),U(e.interval_type||`hours`),ae(e.icon||`Wrench`),oe(e.wiki_url||``)},ce=()=>{B&&ee.trim()&&parseFloat(te)>0&&(i(B.id,{name:ee.trim(),default_interval_hours:parseFloat(te),interval_type:re,icon:ie,wiki_url:W.trim()||null}),V(null))},le=(e,t,r)=>{let i=parseFloat(m);!isNaN(i)&&i>0&&n(e,{custom_interval_hours:Math.abs(i-t)<.01?null:i,custom_interval_type:g===r?null:g}),p(null)},ue=e=>{e.preventDefault(),x.trim()&&parseFloat(C)>0&&j.size>0&&(r({name:x.trim(),default_interval_hours:parseFloat(C),interval_type:T,icon:D,wiki_url:k.trim()||null},Array.from(j)),S(``),w(`100`),E(`hours`),A(``),M(new Set),b(!1))},de=e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},fe=e?.map(e=>({printerId:e.printer_id,printerName:e.printer_name,items:e.maintenance_items.sort((e,t)=>e.maintenance_type_id-t.maintenance_type_id)})).sort((e,t)=>e.printerName.localeCompare(t.printerName))||[],pe=t.filter(e=>e.is_system),me=t.filter(e=>!e.is_system);return(0,K.jsxs)(`div`,{className:`space-y-8`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.maintenanceTypes`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.maintenanceTypesDescription`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:o,disabled:!u(`maintenance:delete`)||s,title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),children:d(`maintenance.restoreDefaults`)}),(0,K.jsxs)($,{onClick:()=>b(!v),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionEditTypes`),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),d(`maintenance.addCustomType`)]})]})]}),v&&(0,K.jsx)(pd,{className:`mb-6`,children:(0,K.jsx)(hd,{className:`py-4`,children:(0,K.jsxs)(`form`,{onSubmit:ue,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4`,children:[(0,K.jsxs)(`div`,{className:`lg:col-span-2`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`common.name`)}),(0,K.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.exampleName`),autoFocus:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalType`)}),(0,K.jsxs)(`select`,{value:T,onChange:e=>{E(e.target.value),e.target.value===`days`?w(`30`):w(`100`)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalValue`,{type:T===`days`?d(`maintenance.calendarDays`).toLowerCase():d(`common.hours`)})}),(0,K.jsx)(`input`,{type:`number`,value:C,onChange:e=>w(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]})]}),(0,K.jsx)(`div`,{className:`mt-4 flex items-end justify-between`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.icon`)}),(0,K.jsx)(`div`,{className:`flex gap-1`,children:Object.keys(E7).map(e=>{let t=E7[e];return(0,K.jsx)(`button`,{type:`button`,onClick:()=>O(e),className:`p-2 rounded-lg transition-colors ${D===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(t,{className:`w-4 h-4`})},e)})})]})}),(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.documentationLink`)}),(0,K.jsx)(`input`,{type:`url`,value:k,onChange:e=>A(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:`https://wiki.bambulab.com/...`})]}),(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.assignToPrinters`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:L.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>de(e.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${j.has(e.id)?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))}),j.size===0&&(0,K.jsx)(`p`,{className:`text-xs text-orange-400 mt-1`,children:d(`maintenance.selectAtLeastOnePrinter`)})]}),(0,K.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:()=>{b(!1),M(new Set)},children:d(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!x.trim()||j.size===0,children:d(`maintenance.addType`)})]})]})})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:[pe.map(e=>{let t=D7(e.icon),n=e.interval_type||`hours`;return(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg`,children:(0,K.jsx)(t,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,K.jsx)(qo,{className:`w-3 h-3`}):(0,K.jsx)(mu,{className:`w-3 h-3`}),k7(e.default_interval_hours,n,d)]})]}),(0,K.jsx)(`button`,{onClick:()=>{u(`maintenance:delete`)&&I(e)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})},e.id)}),me.map(e=>{let t=D7(e.icon),n=e.interval_type||`hours`;if(B?.id===e.id)return(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green`,children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:ee,onChange:e=>H(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`common.name`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`select`,{value:re,onChange:e=>U(e.target.value),className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,K.jsx)(`input`,{type:`number`,value:te,onChange:e=>ne(e.target.value),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(E7).map(e=>{let t=E7[e];return(0,K.jsx)(`button`,{type:`button`,onClick:()=>ae(e),className:`p-1.5 rounded transition-colors ${ie===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:(0,K.jsx)(t,{className:`w-3.5 h-3.5`})},e)})}),(0,K.jsx)(`input`,{type:`url`,value:W,onChange:e=>oe(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.documentationLink`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{size:`sm`,onClick:ce,disabled:!ee.trim(),children:d(`common.save`)}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>V(null),children:d(`common.cancel`)})]})]})},e.id);let r=R(e.id),i=z(e.id),o=N===e.id;return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2.5 bg-bambu-green/20 rounded-lg`,children:(0,K.jsx)(t,{className:`w-5 h-5 text-bambu-green`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded`,children:d(`maintenance.custom`)})]}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,K.jsx)(qo,{className:`w-3 h-3`}):(0,K.jsx)(mu,{className:`w-3 h-3`}),k7(e.default_interval_hours,n,d)]})]}),(0,K.jsxs)(`button`,{onClick:()=>P(o?null:e.id),className:`px-2 py-1 rounded-lg border transition-colors flex items-center gap-1 ${r.length>0?`border-bambu-green/50 bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20`:`border-orange-400/50 bg-orange-400/10 text-orange-400 hover:bg-orange-400/20`}`,title:d(`maintenance.printersAssignedClick`,{count:r.length}),children:[(0,K.jsx)(bl,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{className:`text-xs font-medium`,children:r.length}),(0,K.jsx)(es,{className:`w-3 h-3 transition-transform ${o?`rotate-180`:``}`})]}),(0,K.jsx)(`button`,{onClick:()=>se(e),disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors ${u(`maintenance:update`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(dl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{confirm(d(`maintenance.deleteTypeConfirm`,{name:e.name}))&&a(e.id)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]}),o&&(0,K.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:d(`maintenance.assignedToPrinters`)}),r.length===0?(0,K.jsx)(`p`,{className:`text-xs text-orange-400`,children:d(`maintenance.noPrintersAssigned`)}):(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-2`,children:r.map(e=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark rounded text-xs text-white`,children:[e.printerName,(0,K.jsx)(`button`,{onClick:()=>e.itemId&&l(e.itemId),disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?d(`maintenance.removeFromPrinter`):d(`maintenance.noPermissionRemovePrinter`),className:`ml-1 ${u(`maintenance:delete`)?`hover:text-red-400`:`opacity-50 cursor-not-allowed`}`,children:`×`})]},e.printerId))}),i.length>0&&(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:d(`maintenance.addPrinterShort`)}),i.map(t=>(0,K.jsxs)(`button`,{onClick:()=>c(t.id,e.id),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionAssignPrinter`),className:`px-2 py-1 bg-bambu-dark rounded text-xs transition-colors ${u(`maintenance:create`)?`hover:bg-bambu-green/20 text-bambu-gray hover:text-bambu-green`:`opacity-50 cursor-not-allowed text-bambu-gray`}`,children:[`+ `,t.name]},t.id))]})]})]},e.id)})]})]}),fe.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.intervalOverrides`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]}),(0,K.jsx)(`div`,{className:`space-y-4`,children:fe.map(e=>(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`py-4`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e.printerName}),(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2`,children:e.items.map(e=>{let n=D7(e.maintenance_type_icon),r=t.find(t=>t.id===e.maintenance_type_id),i=r?.default_interval_hours||e.interval_hours,a=r?.interval_type||`hours`,o=e.interval_type||`hours`,s=f===e.id;return(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(n,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray flex-1 truncate`,children:e.maintenance_type_name}),s?(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[g===`days`?(0,K.jsx)(qo,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}):(0,K.jsx)(mu,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,K.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,K.jsx)(`input`,{type:`number`,value:m,onChange:e=>h(e.target.value),onKeyDown:t=>{t.key===`Enter`&&le(e.id,i,a),t.key===`Escape`&&p(null)},className:`w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,min:`1`}),(0,K.jsx)($,{size:`sm`,onClick:()=>le(e.id,i,a),children:`OK`})]}):(0,K.jsxs)(`button`,{onClick:()=>{u(`maintenance:update`)&&(p(e.id),h(e.interval_hours.toString()),_(o))},disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditIntervals`),className:`px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs font-medium text-white transition-colors flex items-center gap-1 ${u(`maintenance:update`)?`hover:bg-bambu-dark-secondary hover:border-bambu-green`:`opacity-50 cursor-not-allowed`}`,children:[o===`days`?(0,K.jsx)(qo,{className:`w-3 h-3`}):(0,K.jsx)(mu,{className:`w-3 h-3`}),k7(e.interval_hours,o,d),(0,K.jsx)(dl,{className:`w-3 h-3 text-bambu-gray`})]})]},e.id)})})]})},e.printerId))})]}),fe.length===0&&(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`text-center py-12`,children:[(0,K.jsx)(_s,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray/30`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:d(`common.noPrinters`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]})}),F&&(0,K.jsx)(Ed,{title:d(`maintenance.deleteSystemTypeTitle`),message:d(`maintenance.deleteSystemTypeMessage`,{name:F.name}),confirmText:d(`common.delete`),cancelText:d(`common.cancel`),variant:`danger`,cancelVariant:`primary`,cardClassName:`bg-red-950/70 border border-red-800/70`,onConfirm:()=>{a(F.id),I(null)},onCancel:()=>I(null)})]})}function fBe(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),{hasPermission:r}=sd(),[i,a]=(0,y.useState)(`status`),{data:o,isLoading:s}=q({queryKey:[`maintenanceOverview`],queryFn:Q.getMaintenanceOverview}),{data:c}=q({queryKey:[`maintenanceTypes`],queryFn:Q.getMaintenanceTypes}),l=J({mutationFn:({id:e,notes:t})=>Q.performMaintenance(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.maintenanceComplete`))},onError:e=>{n(e.message,`error`)}}),u=J({mutationFn:({id:e,data:t})=>Q.updateMaintenanceItem(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]})},onError:e=>{n(e.message,`error`)}}),d=J({mutationFn:({id:e,data:t})=>Q.updateMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onError:e=>{n(e.message,`error`)}}),f=J({mutationFn:Q.deleteMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeDeleted`))},onError:e=>{n(e.message,`error`)}}),p=J({mutationFn:Q.restoreDefaultMaintenanceTypes,onSuccess:r=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.defaultsRestored`,{count:r.restored}))},onError:e=>{n(e.message,`error`)}}),m=J({mutationFn:({printerId:e,hours:t})=>Q.setPrinterHours(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.printHoursUpdated`))},onError:e=>{n(e.message,`error`)}}),h=J({mutationFn:({printerId:e,typeId:t})=>Q.assignMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerAssigned`))},onError:e=>{n(e.message,`error`)}}),g=J({mutationFn:Q.removeMaintenanceItem,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerRemoved`))},onError:e=>{n(e.message,`error`)}}),_=e=>{l.mutate({id:e})},v=(e,t)=>{u.mutate({id:e,data:{enabled:t}})},b=(e,t)=>{m.mutate({printerId:e,hours:t})};if(s)return(0,K.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})});let x=o?.reduce((e,t)=>e+t.due_count,0)||0,S=o?.reduce((e,t)=>e+t.warning_count,0)||0;return(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(Nu,{className:`w-7 h-7 text-bambu-green`}),e(`maintenance.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i===`status`?(0,K.jsxs)(K.Fragment,{children:[x>0&&(0,K.jsx)(`span`,{className:`text-red-400`,children:e(`maintenance.dueCount`,{count:x})}),x>0&&S>0&&` · `,S>0&&(0,K.jsx)(`span`,{className:`text-amber-400`,children:e(`maintenance.warningCount`,{count:S})}),x===0&&S===0&&(0,K.jsx)(`span`,{className:`text-bambu-green`,children:e(`maintenance.allOk`)})]}):e(`maintenance.configureSettings`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-1 mb-6 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`status`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i===`status`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.statusTab`)}),(0,K.jsx)(`button`,{onClick:()=>a(`settings`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i===`settings`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.settingsTab`)})]}),i===`status`?(0,K.jsx)(`div`,{className:`space-y-6`,children:o&&o.length>0?[...o].sort((e,t)=>{let n=e.due_count*10+e.warning_count,r=t.due_count*10+t.warning_count;return n===r?e.printer_name.localeCompare(t.printer_name):r-n}).map(t=>(0,K.jsx)(uBe,{overview:t,onPerform:_,onToggle:v,onSetHours:b,hasPermission:r,t:e},t.printer_id)):(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`text-center py-16`,children:[(0,K.jsx)(Nu,{className:`w-16 h-16 mx-auto mb-4 text-bambu-gray/30`}),(0,K.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:e(`common.noPrinters`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`maintenance.configureSettings`)})]})})}):(0,K.jsx)(dBe,{overview:o,types:c||[],onUpdateInterval:(e,t)=>u.mutate({id:e,data:t}),onAddType:async(r,i)=>{let a=await Q.createMaintenanceType(r);for(let e of i)await Q.assignMaintenanceType(e,a.id);t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onUpdateType:(e,t)=>d.mutate({id:e,data:t}),onDeleteType:e=>f.mutate(e),onRestoreDefaults:()=>p.mutate(),isRestoringDefaults:p.isPending,onAssignType:(e,t)=>h.mutate({printerId:e,typeId:t}),onRemoveItem:e=>g.mutate(e),hasPermission:r,t:e})]})}var A7=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#06b6d4`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#6b7280`];function j7({project:e,onClose:t,onSave:n,isLoading:r,currencySymbol:i,t:a}){let[o,s]=(0,y.useState)(e?.name||``),[c,l]=(0,y.useState)(e?.description||``),[u,d]=(0,y.useState)(e?.color||A7[0]),[f,p]=(0,y.useState)(e?.target_count?.toString()||``),[m,h]=(0,y.useState)(e?.target_parts_count?.toString()||``),[g,_]=(0,y.useState)(e?.status||`active`),[v,b]=(0,y.useState)(e?.tags||``),[x,S]=(0,y.useState)(e?.due_date?.split(`T`)[0]||``),[C,w]=(0,y.useState)(e?.priority||`normal`),[T,E]=(0,y.useState)(e?.budget?.toString()||``),[D,O]=(0,y.useState)(e?.url||``),[k,A]=(0,y.useState)(null),j=Qa(),[M,N]=(0,y.useState)(e?.cover_image_filename||null),P=(0,y.useRef)(null),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)(0);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 w-full max-w-md border border-bambu-dark-tertiary flex flex-col max-h-[calc(100vh-2rem)]`,children:[(0,K.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e?`projects.editProject`:`projects.newProject`)})}),(0,K.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let r=D.trim();if(r&&!/^https?:\/\//i.test(r)){A(a(`projects.urlInvalid`));return}A(null),n({name:o.trim(),description:c.trim()||void 0,color:u,target_count:f?parseInt(f,10):void 0,target_parts_count:m?parseInt(m,10):void 0,tags:v.trim()||void 0,due_date:x||void 0,priority:C,budget:T.trim()?parseFloat(T):null,url:e?r||null:r||void 0,...e&&{status:g}})},className:`flex flex-col flex-1 min-h-0`,children:[(0,K.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,K.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.namePlaceholder`),required:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.description`)}),(0,K.jsx)(`textarea`,{value:c,onChange:e=>l(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none`,placeholder:a(`projects.descriptionPlaceholder`),rows:2})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.urlLabel`)}),(0,K.jsx)(`input`,{type:`url`,value:D,onChange:e=>{O(e.target.value),k&&A(null)},className:`w-full bg-bambu-dark border rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none ${k?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,placeholder:a(`projects.urlPlaceholder`),maxLength:2048}),k&&(0,K.jsx)(`p`,{className:`text-xs text-red-400 mt-1`,children:k})]}),e&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.coverImageLabel`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-20 h-20 rounded bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden flex items-center justify-center flex-shrink-0`,children:M?(0,K.jsx)(`img`,{src:`${Q.getProjectCoverImageUrl(e.id)}?v=${L}`,alt:a(`projects.coverImageAlt`),className:`w-full h-full object-cover`}):(0,K.jsx)(Dc,{className:`w-6 h-6 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(`input`,{ref:P,type:`file`,accept:`image/jpeg,image/png,image/gif,image/webp`,onChange:async t=>{let n=t.target.files?.[0];if(!(!n||!e)){I(!0);try{N((await Q.uploadProjectCoverImage(e.id,n)).filename),R(e=>e+1),j.invalidateQueries({queryKey:[`projects`]})}catch{}finally{I(!1),P.current&&(P.current.value=``)}}},className:`hidden`}),(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:()=>P.current?.click(),disabled:F,children:[F?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Su,{className:`w-4 h-4 mr-1`}),a(M?`projects.coverImageReplace`:`projects.coverImageUpload`)]}),M&&(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:async()=>{if(e){I(!0);try{await Q.deleteProjectCoverImage(e.id),N(null),R(e=>e+1),j.invalidateQueries({queryKey:[`projects`]})}finally{I(!1)}}},disabled:F,children:[(0,K.jsx)(Pu,{className:`w-4 h-4 mr-1`}),a(`projects.coverImageRemove`)]})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.color`)}),(0,K.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:A7.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>d(e),className:`w-8 h-8 rounded-full transition-transform ${u===e?`ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110`:``}`,style:{backgroundColor:e}},e))})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetPlates`)}),(0,K.jsx)(`input`,{type:`number`,value:f,onChange:e=>p(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetPlatesPlaceholder`),min:`1`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetPlatesHelp`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetParts`)}),(0,K.jsx)(`input`,{type:`number`,value:m,onChange:e=>h(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetPartsPlaceholder`),min:`1`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetPartsHelp`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.tagsLabel`)}),(0,K.jsx)(`input`,{type:`text`,value:v,onChange:e=>b(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.tagsPlaceholder`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.dueDate`)}),(0,K.jsx)(`input`,{type:`date`,value:x,onChange:e=>S(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.priority`)}),(0,K.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsx)(`option`,{value:`low`,children:a(`projects.priorityLow`)}),(0,K.jsx)(`option`,{value:`normal`,children:a(`projects.priorityNormal`)}),(0,K.jsx)(`option`,{value:`high`,children:a(`projects.priorityHigh`)}),(0,K.jsx)(`option`,{value:`urgent`,children:a(`projects.priorityUrgent`)})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projectDetail.cost.budget`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray pointer-events-none`,children:i}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:T,onChange:e=>E(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded pl-8 pr-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:`0.00`})]})]}),e&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.status`)}),(0,K.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsx)(`option`,{value:`active`,children:a(`projects.statusActive`)}),(0,K.jsx)(`option`,{value:`completed`,children:a(`projects.statusCompleted`)}),(0,K.jsx)(`option`,{value:`archived`,children:a(`projects.statusArchived`)})]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,children:a(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!o.trim()||r,children:r?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):a(e?`common.save`:`projects.create`)})]})]})]})})}function pBe({projectId:e,altText:t}){let n=(0,y.useRef)(null),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(null);return(0,K.jsxs)(`div`,{ref:n,className:`relative flex-shrink-0`,onMouseEnter:()=>{if(!n.current)return;let e=n.current.getBoundingClientRect(),t=window.innerWidth,r=window.innerHeight,a=e.right+8;a+384>t-8&&(a=e.left-384-8);let s=e.top;s+384>r-8&&(s=r-384-8),s<8&&(s=8),o({left:a,top:s}),i(!0)},onMouseLeave:()=>i(!1),onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-lg overflow-hidden bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,K.jsx)(`img`,{src:Q.getProjectCoverImageUrl(e),alt:t,className:`w-full h-full object-cover`,loading:`lazy`})}),r&&a&&(0,Zf.createPortal)((0,K.jsx)(`div`,{className:`fixed z-[100] w-96 h-96 rounded-lg overflow-hidden border border-bambu-dark-tertiary shadow-2xl bg-bambu-dark pointer-events-none`,style:{left:a.left,top:a.top},"aria-hidden":`true`,children:(0,K.jsx)(`img`,{src:Q.getProjectCoverImageUrl(e),alt:``,className:`w-full h-full object-contain`,loading:`lazy`})}),document.body)]})}function mBe({project:e,onClick:t,onEdit:n,onDelete:r,hasPermission:i,t:a}){let o=e.target_count?Math.round(e.archive_count/e.target_count*100):0,s=e.target_parts_count?Math.round(e.completed_count/e.target_parts_count*100):0,c=e.status===`completed`,l=e.status===`archived`,[u,d]=(0,y.useState)(!1),f=c?{icon:us,color:`text-bambu-green`,bg:`bg-bambu-green/10`}:l?{icon:wo,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`}:e.queue_count>0?{icon:_s,color:`text-blue-400`,bg:`bg-blue-400/10`}:{icon:nc,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`};return(0,K.jsxs)(`div`,{className:`group relative bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary hover:border-bambu-green/50 hover:shadow-lg hover:shadow-bambu-green/5 transition-all duration-300 cursor-pointer overflow-hidden`,onClick:t,children:[(0,K.jsx)(`div`,{className:`absolute top-0 left-0 w-1.5 h-full`,style:{backgroundColor:e.color||`#6b7280`,boxShadow:`0 0 12px ${e.color||`#6b7280`}40`}}),(0,K.jsxs)(`div`,{className:`p-5 pl-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[e.cover_image_filename?(0,K.jsx)(pBe,{projectId:e.id,altText:a(`projects.coverImageAlt`)}):(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${f.bg} flex-shrink-0`,children:(0,K.jsx)(f.icon,{className:`w-5 h-5 ${f.color}`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.jsx)(`h3`,{className:`font-semibold text-white truncate`,children:e.name}),e.url&&(0,K.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),title:e.url,"aria-label":a(`projects.openExternalUrl`),className:`inline-flex items-center justify-center w-6 h-6 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-green hover:bg-bambu-green/10 hover:border-bambu-green transition-colors flex-shrink-0`,children:(0,K.jsx)(Us,{className:`w-3.5 h-3.5`})}),e.target_parts_count?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${s>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.completed_count,`/`,e.target_parts_count,` `,a(`projects.parts`)]}):e.target_count?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${o>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.archive_count,`/`,e.target_count,` `,a(`projects.plates`)]}):e.completed_count>0?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium bg-bambu-dark text-bambu-gray`,children:[e.completed_count,` `,a(`projects.parts`)]}):null,c&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap`,children:a(`projects.done`)}),l&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap`,children:a(`projects.statusArchived`)})]}),e.description&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1 line-clamp-1`,children:e.description}),e.archives&&e.archives.length>0&&(()=>{let t=e.archives.map(e=>e.filament_type).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(Boolean),n=[...new Set(t)],r=e.archives.map(e=>e.filament_color).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(e=>e.startsWith(`#`)||/^[0-9A-Fa-f]{6}$/.test(e)),i=[...new Set(r)];return n.length===0&&i.length===0?null:(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[n.slice(0,3).map(e=>(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 bg-bambu-dark text-bambu-gray rounded`,children:e},e)),i.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[i.slice(0,5).map(e=>(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e.startsWith(`#`)?e:`#${e}`},title:e},e)),i.length>5&&(0,K.jsxs)(`span`,{className:`text-[10px] text-bambu-gray ml-0.5`,children:[`+`,i.length-5]})]})]})})()]})]}),(0,K.jsxs)(`div`,{className:`relative`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`button`,{className:`p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors opacity-0 group-hover:opacity-100`,onClick:()=>d(!u),children:(0,K.jsx)(zs,{className:`w-4 h-4`})}),u&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>d(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 top-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,K.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${i(`projects:update`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{i(`projects:update`)&&(n(),d(!1))},disabled:!i(`projects:update`),title:i(`projects:update`)?void 0:a(`projects.noEditPermission`),children:[(0,K.jsx)(dl,{className:`w-4 h-4`}),a(`common.edit`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${i(`projects:delete`)?`text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{i(`projects:delete`)&&(r(),d(!1))},disabled:!i(`projects:delete`),title:i(`projects:delete`)?void 0:a(`projects.noDeletePermission`),children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),a(`common.delete`)]})]})]})]})]}),(0,K.jsx)(`div`,{className:`mb-4`,children:e.target_count||e.target_parts_count?(0,K.jsxs)(`div`,{className:`space-y-3`,children:[e.target_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:a(`projects.plates`)}),(0,K.jsxs)(`span`,{className:o>=100?`text-bambu-green font-medium`:`text-white`,children:[e.archive_count,` / `,e.target_count]})]}),(0,K.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(o,100)}%`,background:o>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${o>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.target_parts_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:a(`projects.parts`)}),(0,K.jsxs)(`span`,{className:s>=100?`text-bambu-green font-medium`:`text-white`,children:[e.completed_count,` / `,e.target_parts_count]})]}),(0,K.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(s,100)}%`,background:s>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${s>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`text-xs text-red-400`,children:[e.failed_count,` `,a(`projects.failed`)]})]}):e.completed_count>0||e.failed_count>0?(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-xs`,children:[e.completed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,K.jsx)(wo,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.completed_count,` `,a(`projects.completed`)]})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-400`,children:[(0,K.jsx)(vu,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.failed_count,` `,a(`projects.failed`)]})]}),e.queue_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-blue-400`,children:[(0,K.jsx)(_s,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.queue_count,` `,a(`projects.inQueue`)]})]})]}):(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray/60 italic`,children:a(`projects.noPrintsYet`)})}),e.archives&&e.archives.length>0&&(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`div`,{className:`grid grid-cols-4 gap-1.5`,children:e.archives.slice(0,4).map(e=>(0,K.jsxs)(`div`,{className:`relative aspect-square rounded-lg bg-bambu-dark overflow-hidden border border-bambu-dark-tertiary`,title:e.print_name||`Unknown`,children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:e.print_name||``,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray/50`,children:(0,K.jsx)(cl,{className:`w-6 h-6`})}),e.status===`failed`&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-red-500/40 flex items-center justify-center`,children:(0,K.jsx)(vu,{className:`w-4 h-4 text-white`})})]},e.id))}),e.archive_count>4&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5 text-center`,children:a(`common.more`,{count:e.archive_count-4})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-xs text-bambu-gray`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:a(`projects.printJobs`),children:[(0,K.jsx)(Nc,{className:`w-3.5 h-3.5 text-blue-400`}),(0,K.jsxs)(`span`,{children:[e.archive_count,` `,a(`projects.plates`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:a(`projects.partsPrinted`),children:[(0,K.jsx)(cl,{className:`w-3.5 h-3.5 text-bambu-green`}),(0,K.jsxs)(`span`,{children:[e.completed_count,` `,a(`projects.parts`)]})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-400`,title:a(`projects.failedParts`),children:[(0,K.jsx)(vu,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{children:e.failed_count})]}),e.queue_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-yellow-400`,title:a(`projects.inQueue`),children:[(0,K.jsx)(zc,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{children:e.queue_count})]})]}),(0,K.jsx)(ts,{className:`w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors`})]})]})]})}function hBe(){let{t:e}=G(),t=Yn(),n=Qa(),{showToast:r}=xd(),{hasPermission:i}=sd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(),[l,u]=(0,y.useState)(`active`),[d,f]=(0,y.useState)(null),{data:p}=q({queryKey:[`settings`],queryFn:Q.getSettings}),m=Yd(p?.currency||`USD`),{data:h,isLoading:g}=q({queryKey:[`projects`,l===`all`?void 0:l],queryFn:()=>Q.getProjects(l===`all`?void 0:l)}),_=J({mutationFn:e=>Q.createProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),o(!1),r(e(`projects.toast.created`),`success`)},onError:e=>{r(e.message,`error`)}}),v=J({mutationFn:({id:e,data:t})=>Q.updateProject(e,t),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),o(!1),c(void 0),r(e(`projects.toast.updated`),`success`)},onError:e=>{r(e.message,`error`)}}),b=J({mutationFn:e=>Q.deleteProject(e),onSuccess:()=>{f(null),r(e(`projects.toast.deleted`),`success`),setTimeout(()=>window.location.reload(),100)},onError:e=>{f(null),r(e.message,`error`)}}),x=J({mutationFn:e=>Q.importProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),r(e(`projects.toast.imported`),`success`)},onError:e=>{r(e.message,`error`)}}),S=(0,y.useRef)(null),C=async()=>{try{let t=await Q.getProjects(),n=await Promise.all(t.map(async e=>await Q.exportProjectJson(e.id))),i=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`bambuddy_projects_${new Date().toISOString().split(`T`)[0]}.json`,o.click(),URL.revokeObjectURL(a),r(e(`projects.toast.exported`),`success`)}catch(e){r(e.message,`error`)}},w=()=>{S.current?.click()},T=async t=>{let i=t.target.files?.[0];if(i){try{if(i.name.toLowerCase().endsWith(`.zip`))await Q.importProjectFile(i),n.invalidateQueries({queryKey:[`projects`]}),r(e(`projects.toast.imported`),`success`);else{let t=await i.text(),n=JSON.parse(t),a=Array.isArray(n)?n:[n];for(let e of a)await x.mutateAsync(e);a.length>1&&r(e(`projects.toast.multipleImported`,{count:a.length}),`success`)}}catch(t){r(`${e(`projects.toast.importFailed`)}: ${t.message}`,`error`)}t.target.value=``}},E=e=>{s?v.mutate({id:s.id,data:e}):_.mutate(e)},D=e=>{c(e),o(!0)},O=e=>{t(`/projects/${e.id}`)},k=e=>{f(e)},A=()=>{d!==null&&b.mutate(d)},j=h?.reduce((e,t)=>(e[t.status]=(e[t.status]||0)+1,e.all=(e.all||0)+1,e),{})||{};return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,K.jsx)(`input`,{ref:S,type:`file`,accept:`.json,.zip`,onChange:T,className:`hidden`}),(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4`,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)(nc,{className:`w-7 h-7 text-bambu-green`}),e(`projects.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`projects.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:w,disabled:!i(`projects:create`),title:i(`projects:create`)?e(`projects.importProject`):e(`projects.noImportPermission`),children:[(0,K.jsx)(Su,{className:`w-4 h-4 mr-2`}),e(`projects.import`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:C,disabled:!i(`projects:read`),title:i(`projects:read`)?e(`projects.exportAll`):e(`projects.noExportPermission`),children:[(0,K.jsx)(Is,{className:`w-4 h-4 mr-2`}),e(`projects.export`)]}),(0,K.jsxs)($,{onClick:()=>o(!0),className:`sm:w-auto w-full`,disabled:!i(`projects:create`),title:i(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,K.jsx)(_l,{className:`w-4 h-4 mr-2`}),e(`projects.newProject`)]})]})]}),(0,K.jsx)(`div`,{className:`flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit`,children:[{key:`active`,label:e(`projects.statusActive`),icon:_s},{key:`completed`,label:e(`projects.statusCompleted`),icon:us},{key:`archived`,label:e(`projects.statusArchived`),icon:wo},{key:`all`,label:e(`common.all`),icon:nc}].map(({key:e,label:t,icon:n})=>(0,K.jsxs)(`button`,{onClick:()=>u(e),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${l===e?`bg-bambu-card text-white shadow-sm`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(n,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:t}),j[e]>0&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${l===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary`}`,children:j[e]})]},e))}),g?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`projects.loading`)})]})}):h?.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 px-4`,children:[(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,K.jsx)(nc,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,K.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:l===`all`?e(`projects.noProjects`):e(`projects.noProjectsFiltered`,{status:l})}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:l===`all`?e(`projects.createFirst`):e(`projects.noProjectsFilteredHelp`,{status:l})}),l===`all`&&(0,K.jsxs)($,{onClick:()=>o(!0),disabled:!i(`projects:create`),title:i(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,K.jsx)(_l,{className:`w-4 h-4 mr-2`}),e(`projects.createFirstButton`)]})]}):(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8`,children:h?.map(t=>(0,K.jsx)(mBe,{project:t,onClick:()=>O(t),onEdit:()=>D(t),onDelete:()=>k(t.id),hasPermission:i,t:e},t.id))}),d!==null&&(0,K.jsx)(Ed,{title:e(`projects.deleteProject`),message:e(`projects.deleteConfirm`),confirmText:e(`projects.deleteProject`),variant:`danger`,onConfirm:A,onCancel:()=>f(null)}),a&&(0,K.jsx)(j7,{project:s,onClose:()=>{o(!1),c(void 0)},onSave:E,isLoading:_.isPending||v.isPending,currencySymbol:m,t:e})]})}function gBe(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)}function _Be(e){return e>=1e3?`${(e/1e3).toFixed(2)}kg`:`${Math.round(e)}g`}function vBe({status:e,t}){let n={active:`bg-bambu-green/20 text-bambu-green`,completed:`bg-blue-500/20 text-blue-400`,archived:`bg-bambu-gray/20 text-bambu-gray`},r=n[e]||n.active,i={active:t(`projectDetail.status.active`),completed:t(`projectDetail.status.completed`),archived:t(`projectDetail.status.archived`)};return(0,K.jsx)(`span`,{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:i[e]||e.charAt(0).toUpperCase()+e.slice(1)})}function M7({icon:e,label:t,value:n,subValue:r,hint:i,color:a=`text-bambu-gray`}){return(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,title:i,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${a}`,children:(0,K.jsx)(e,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,K.jsx)(`p`,{className:`text-xl font-semibold text-white`,children:n}),r&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:r})]})]})})})}function yBe({archives:e,t}){return e.length===0?(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(cl,{className:`w-12 h-12 mx-auto mb-2 opacity-50`}),(0,K.jsx)(`p`,{children:t(`projectDetail.noPrints`)})]}):(0,K.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3`,children:e.map(e=>(0,K.jsxs)(bi,{to:`/archives?search=${encodeURIComponent(e.print_name||``)}`,className:`group relative aspect-square rounded-lg bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden hover:border-bambu-green transition-colors`,children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:e.print_name||`Print`,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,K.jsx)(cl,{className:`w-8 h-8`})}),e.status===`failed`&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-red-500/30 flex items-center justify-center`,children:(0,K.jsx)(ms,{className:`w-8 h-8 text-white`})}),e.status===`completed`&&(0,K.jsx)(`div`,{className:`absolute top-1 right-1`,children:(0,K.jsx)(ls,{className:`w-4 h-4 text-bambu-green`})}),(0,K.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,K.jsx)(`p`,{className:`text-xs text-white truncate`,children:e.print_name||`Unknown`})})]},e.id))})}function bBe({priority:e,t}){let n={low:{color:`bg-gray-500/20 text-gray-400`,label:t(`projectDetail.priority.low`)},normal:{color:`bg-blue-500/20 text-blue-400`,label:t(`projectDetail.priority.normal`)},high:{color:`bg-orange-500/20 text-orange-400`,label:t(`projectDetail.priority.high`)},urgent:{color:`bg-red-500/20 text-red-400`,label:t(`projectDetail.priority.urgent`)}},{color:r,label:i}=n[e]||n.normal;return(0,K.jsxs)(`span`,{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[e===`urgent`&&(0,K.jsx)(vu,{className:`w-3 h-3`}),i]})}function N7(e,t){if(!e)return null;let n=mf(e);if(!n)return null;let r=new Date,i=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return i<0?{color:`text-red-400`,label:t(`projectDetail.dueDate.overdue`)}:i===0?{color:`text-orange-400`,label:t(`projectDetail.dueDate.today`)}:i<=3?{color:`text-yellow-400`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}:{color:`text-bambu-gray`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}}function xBe(){let{id:e}=er(),t=Yn(),{t:n}=G(),r=Qa(),{showToast:i}=xd(),{hasPermission:a}=sd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null),g=parseInt(e||`0`,10),{data:_,isLoading:v,error:b}=q({queryKey:[`project`,g],queryFn:()=>Q.getProject(g),enabled:g>0}),{data:x,isLoading:S}=q({queryKey:[`project-archives`,g],queryFn:()=>Q.getProjectArchives(g),enabled:g>0}),{data:C,isLoading:w}=q({queryKey:[`project-bom`,g],queryFn:()=>Q.getProjectBOM(g),enabled:g>0}),{data:T,isLoading:E}=q({queryKey:[`project-timeline`,g],queryFn:()=>Q.getProjectTimeline(g,20),enabled:g>0}),{data:D}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:O}=q({queryKey:[`project-folders`,g],queryFn:()=>Q.getLibraryFoldersByProject(g),enabled:g>0}),{data:k,isLoading:A}=q({queryKey:[`project-files`,g],queryFn:()=>Q.getLibraryFiles(null,!1,g),enabled:g>0}),j=(0,y.useMemo)(()=>{let e=new Map;for(let t of k??[])if(t.folder_id!=null){let n=e.get(t.folder_id)??[];n.push(t),e.set(t.folder_id,n)}return e},[k]),M=Yd(D?.currency||`USD`),N=D?.time_format||`system`,P=J({mutationFn:e=>Q.updateProject(g,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project`,g]}),r.invalidateQueries({queryKey:[`projects`]}),s(!1),l(!1),i(n(`projectDetail.toast.projectUpdated`),`success`)},onError:e=>{i(e.message,`error`)}}),F=()=>{d(_?.notes||``),l(!0)},I=()=>{P.mutate({notes:u})},L=()=>{l(!1),d(``)},[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(1),[ee,H]=(0,y.useState)(``),[te,ne]=(0,y.useState)(``),[re,U]=(0,y.useState)(``),[ie,ae]=(0,y.useState)(!1),[W,oe]=(0,y.useState)(!1),[se,ce]=(0,y.useState)(null),[le,ue]=(0,y.useState)(``),[de,fe]=(0,y.useState)(1),[pe,me]=(0,y.useState)(``),[he,ge]=(0,y.useState)(``),[_e,ve]=(0,y.useState)(``),[ye,be]=(0,y.useState)({isOpen:!1,title:``,message:``,onConfirm:()=>{}}),xe=J({mutationFn:e=>Q.createBOMItem(g,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,g]}),r.invalidateQueries({queryKey:[`project`,g]}),z(``),V(1),H(``),ne(``),U(``),ae(!1),i(n(`projectDetail.toast.partAdded`),`success`)},onError:e=>i(e.message,`error`)}),Se=J({mutationFn:({itemId:e,data:t})=>Q.updateBOMItem(g,e,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,g]}),r.invalidateQueries({queryKey:[`project`,g]}),ce(null)},onError:e=>i(e.message,`error`)}),Ce=J({mutationFn:e=>Q.deleteBOMItem(g,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,g]}),r.invalidateQueries({queryKey:[`project`,g]}),i(n(`projectDetail.toast.partRemoved`),`success`)},onError:e=>i(e.message,`error`)}),we=e=>{e.preventDefault(),R.trim()&&xe.mutate({name:R.trim(),quantity_needed:B,unit_price:ee?parseFloat(ee):void 0,sourcing_url:te.trim()||void 0,remarks:re.trim()||void 0})},Te=e=>{let t=e.is_complete?0:e.quantity_needed;Se.mutate({itemId:e.id,data:{quantity_acquired:t}})},Ee=(e,t)=>{be({isOpen:!0,title:n(`projectDetail.bom.deletePart`),message:n(`projectDetail.bom.deleteConfirm`,{name:t}),onConfirm:()=>{be(e=>({...e,isOpen:!1})),Ce.mutate(e)}})},De=e=>{ce(e),ue(e.name),fe(e.quantity_needed),me(e.unit_price?.toString()||``),ge(e.sourcing_url||``),ve(e.remarks||``)},Oe=e=>{e.preventDefault(),!(!se||!le.trim())&&Se.mutate({itemId:se.id,data:{name:le.trim(),quantity_needed:de,unit_price:pe?parseFloat(pe):void 0,sourcing_url:he.trim()||void 0,remarks:_e.trim()||void 0}})},ke=()=>{ce(null)},Ae=async()=>{try{let{blob:e,filename:t}=await Q.exportProjectZip(Number(g)),r=URL.createObjectURL(e),a=document.createElement(`a`);a.href=r,a.download=t||`${_?.name||`project`}_${new Date().toISOString().split(`T`)[0]}.zip`,a.click(),URL.revokeObjectURL(r),i(n(`projectDetail.toast.projectExported`),`success`)}catch(e){i(e.message,`error`)}},je=J({mutationFn:()=>Q.createTemplateFromProject(g),onSuccess:()=>{r.invalidateQueries({queryKey:[`projects`]}),i(n(`projectDetail.toast.templateCreated`),`success`)},onError:e=>i(e.message,`error`)}),Me=e=>gf(e,N,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`});if(v)return(0,K.jsx)(`div`,{className:`flex items-center justify-center py-24`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})});if(b||!_)return(0,K.jsxs)(`div`,{className:`text-center py-24`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:b?`${n(`common.error`)}: ${b.message}`:n(`projectDetail.notFound`)}),(0,K.jsx)($,{variant:`secondary`,className:`mt-4`,onClick:()=>t(`/projects`),children:n(`projectDetail.backToProjects`)})]});let Ne=_.stats,Pe=Ne?.progress_percent??0,Fe=Ne?.parts_progress_percent??0;return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(bi,{to:`/projects`,className:`hover:text-white transition-colors`,children:n(`nav.projects`)}),(0,K.jsx)(ts,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-white`,children:_.name})]}),(0,K.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(`button`,{onClick:()=>t(`/projects`),className:`p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors`,children:(0,K.jsx)(Do,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-4 h-4 rounded-full shrink-0`,style:{backgroundColor:_.color||`#6b7280`}}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:_.name}),_.description&&(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:_.description})]})]}),(0,K.jsx)(vBe,{status:_.status,t:n})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:Ae,disabled:!a(`projects:read`),title:a(`projects:read`)?n(`projectDetail.exportProject`):n(`projectDetail.noExportPermission`),children:[(0,K.jsx)(Is,{className:`w-4 h-4 mr-2`}),n(`projectDetail.export`)]}),(0,K.jsxs)($,{onClick:()=>s(!0),disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.noEditPermission`),children:[(0,K.jsx)(dl,{className:`w-4 h-4 mr-2`}),n(`common.edit`)]})]})]}),(_.target_count||_.target_parts_count)&&(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-4 space-y-4`,children:[_.target_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.platesProgress`)}),(0,K.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Ne?.total_archives||0,` / `,_.target_count,` `,n(`projectDetail.progress.printJobs`)]})]}),(0,K.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(Pe,100)}%`,backgroundColor:Pe>=100?`#22c55e`:_.color||`#6b7280`}})}),(0,K.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:Pe.toFixed(0)})}),Ne?.remaining_prints!=null&&Ne.remaining_prints>0&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Ne.remaining_prints})})]})]}),_.target_parts_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.partsProgress`)}),(0,K.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Ne?.completed_prints||0,` / `,_.target_parts_count,` `,n(`projectDetail.progress.parts`)]})]}),(0,K.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(Fe,100)}%`,backgroundColor:Fe>=100?`#22c55e`:_.color||`#6b7280`}})}),(0,K.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:Fe.toFixed(0)})}),Ne?.remaining_parts!=null&&Ne.remaining_parts>0&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Ne.remaining_parts})})]})]})]})}),Ne&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{className:`p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark text-bambu-green`,children:(0,K.jsx)(cl,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.printJobs`)}),(0,K.jsxs)(`p`,{className:`text-xl font-semibold text-white`,children:[Ne.total_archives,` `,(0,K.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:n(`projectDetail.stats.total`)})]}),Ne.failed_prints>0&&(0,K.jsx)(`p`,{className:`text-sm text-status-error`,children:n(`projectDetail.stats.failed`,{count:Ne.failed_prints})}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:Ne.completed_prints})})]})]})})}),(0,K.jsx)(M7,{icon:_s,label:n(`projectDetail.stats.printTime`),value:Sf(Ne.total_print_time_hours),color:`text-yellow-400`}),(0,K.jsx)(M7,{icon:bl,label:n(`projectDetail.stats.filamentUsed`),value:_Be(Ne.total_filament_grams),color:`text-purple-400`})]}),Ne&&(()=>{let e=Ne.estimated_cost+Ne.total_energy_cost+Ne.bom_cost;return Ne.estimated_cost>0||e>0||_.budget!==null})()&&(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white mb-3`,children:n(`projectDetail.cost.title`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.filamentCost`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[M,Ne.estimated_cost.toFixed(2)]})]}),Ne.total_energy_kwh>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.energy`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Ne.total_energy_kwh.toFixed(3),` kWh`,Ne.total_energy_cost>0&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray ml-1`,children:[`(`,M,Ne.total_energy_cost.toFixed(2),`)`]})]})]}),(()=>{let e=Ne.estimated_cost+Ne.total_energy_cost+Ne.bom_cost;return e<=0?null:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[M,e.toFixed(2)]}),Ne.bom_cost>0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.cost.includesBom`)})]})})(),_.budget!==null&&(()=>{let e=Ne.estimated_cost+Ne.total_energy_cost+Ne.bom_cost,t=_.budget-e;return(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.budget`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[n(`projectDetail.cost.total`),`: `,(0,K.jsxs)(`span`,{className:`text-white font-semibold`,children:[M,_.budget.toFixed(2)]})]}),(0,K.jsxs)(`p`,{className:`text-sm ${t>=0?`text-bambu-green`:`text-red-400`}`,children:[n(`projectDetail.cost.remaining`),`: `,(0,K.jsxs)(`span`,{className:`font-semibold`,children:[M,t.toFixed(2)]})]})]})})()]})]})}),_.children&&_.children.length>0&&(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-4`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,K.jsx)(oc,{className:`w-5 h-5`}),n(`projectDetail.subProjects.title`,{count:_.children.length})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:_.children.map(e=>(0,K.jsxs)(bi,{to:`/projects/${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full`,style:{backgroundColor:e.color||`#6b7280`}}),(0,K.jsx)(`span`,{className:`text-white`,children:e.name}),(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded ${e.status===`completed`?`bg-status-ok/20 text-status-ok`:e.status===`archived`?`bg-bambu-gray/20 text-bambu-gray`:`bg-blue-500/20 text-blue-400`}`,children:e.status})]}),e.progress_percent!==null&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.progress_percent.toFixed(0),`%`]})]},e.id))})]})}),_.parent_id&&_.parent_name&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(Nc,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.partOf`)}),(0,K.jsx)(bi,{to:`/projects/${_.parent_id}`,className:`text-bambu-green hover:underline`,children:_.parent_name})]}),(_.tags||_.due_date||_.priority!==`normal`)&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[_.priority&&_.priority!==`normal`&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.priorityLabel`)}),(0,K.jsx)(bBe,{priority:_.priority,t:n})]}),_.due_date&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(qo,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:hf(_.due_date,{year:`numeric`,month:`short`,day:`numeric`})}),N7(_.due_date,n)&&(0,K.jsxs)(`span`,{className:`text-xs ${N7(_.due_date,n).color}`,children:[`(`,N7(_.due_date,n).label,`)`]})]}),_.tags&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(su,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:_.tags.split(`,`).map((e,t)=>(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded`,children:e.trim()},t))})]})]}),(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Zs,{className:`w-5 h-5`}),n(`projectDetail.notes.title`)]}),c?(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:L,disabled:P.isPending,children:[(0,K.jsx)(Pu,{className:`w-4 h-4 mr-1`}),n(`common.cancel`)]}),(0,K.jsxs)($,{size:`sm`,onClick:I,disabled:P.isPending,children:[P.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-1`}):(0,K.jsx)(Ol,{className:`w-4 h-4 mr-1`}),n(`common.save`)]})]}):(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:F,disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.notes.noEditPermission`),children:[(0,K.jsx)(dl,{className:`w-4 h-4 mr-1`}),n(`common.edit`)]})]}),c?(0,K.jsx)(Z3,{content:u,onChange:d,placeholder:n(`projectDetail.notes.placeholder`)}):_.notes?(0,K.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:HJ.sanitize(_.notes)}}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.notes.empty`)})]})}),(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(rc,{className:`w-5 h-5`}),n(`projectDetail.files.title`)]})}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:[(0,K.jsx)(bi,{to:`/files`,className:`text-bambu-green hover:underline`,children:n(`projectDetail.files.linkFolders`)}),` `,n(`projectDetail.files.forQuickAccess`)]}),O&&O.length>0?(0,K.jsx)(`div`,{className:`space-y-4`,children:O.map(e=>{let t=j.get(e.id)??[],r=A;return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(bi,{to:`/files?folder=${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors mb-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,K.jsx)(rc,{className:`w-5 h-5 text-bambu-green shrink-0`}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`projectDetail.files.fileCount`,{count:e.file_count})})]})]}),(0,K.jsx)(ts,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),r?(0,K.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-bambu-gray text-sm`,children:(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`})}):t.length===0?(0,K.jsx)(`p`,{className:`text-bambu-gray/60 text-xs italic px-3`,children:n(`projectDetail.files.noFiles`)}):(0,K.jsx)(`div`,{className:`space-y-1 pl-3`,children:t.map(e=>{let t=gBe(e.filename);return(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 shrink-0 rounded bg-bambu-dark overflow-hidden flex items-center justify-center`,children:e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getLibraryFileThumbnailUrl(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,K.jsx)(qs,{className:`w-5 h-5 text-bambu-gray/40`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-500/20 text-blue-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:e.file_type.toUpperCase()})]}),t&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,K.jsx)(`button`,{onClick:()=>p(e),title:n(`projectDetail.files.print`),className:`p-1.5 rounded hover:bg-bambu-green/20 text-bambu-green transition-colors`,children:(0,K.jsx)(hl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>h(e),title:n(`projectDetail.files.addToQueue`),className:`p-1.5 rounded hover:bg-blue-500/20 text-blue-400 transition-colors`,children:(0,K.jsx)(Ko,{className:`w-4 h-4`})})]})]},e.id)})})]},e.id)})}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.files.empty`)})]})}),(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Ul,{className:`w-5 h-5`}),n(`projectDetail.bom.title`),Ne&&Ne.bom_total_items>0&&(0,K.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n(`projectDetail.bom.acquired`,{completed:Ne.bom_completed_items,total:Ne.bom_total_items}),`)`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[C&&C.some(e=>e.is_complete)&&(0,K.jsx)(`button`,{onClick:()=>oe(!W),className:`text-xs px-2 py-1 rounded transition-colors ${W?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:n(W?`projectDetail.bom.showAll`:`projectDetail.bom.hideDone`)}),!ie&&(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>ae(!0),disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.bom.noAddPermission`),children:[(0,K.jsx)(_l,{className:`w-4 h-4 mr-1`}),n(`projectDetail.bom.addPart`)]})]})]}),ie&&(0,K.jsxs)(`form`,{onSubmit:we,className:`bg-bambu-dark rounded-lg p-4 mb-4 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partNamePlaceholder`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:B,onChange:e=>V(parseInt(e.target.value)||1),className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:`1`,placeholder:n(`projectDetail.bom.qty`)}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,value:ee,onChange:e=>H(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:M})})]})]}),(0,K.jsx)(`input`,{type:`url`,value:te,onChange:e=>ne(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,K.jsx)(`input`,{type:`text`,value:re,onChange:e=>U(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>ae(!1),children:n(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,size:`sm`,disabled:!R.trim()||xe.isPending,children:xe.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):n(`projectDetail.bom.addPart`)})]})]}),w?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):C&&C.length>0?(0,K.jsxs)(`div`,{className:`space-y-2`,children:[C.filter(e=>!W||!e.is_complete).map(e=>(0,K.jsx)(`div`,{className:`p-3 rounded-lg transition-colors ${e.is_complete?`bg-status-ok/10`:`bg-bambu-dark`}`,children:se?.id===e.id?(0,K.jsxs)(`form`,{onSubmit:Oe,className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:le,onChange:e=>ue(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partName`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:de,onChange:e=>fe(parseInt(e.target.value)||1),className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:`1`,placeholder:n(`projectDetail.bom.qty`)}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,value:pe,onChange:e=>me(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:M})})]})]}),(0,K.jsx)(`input`,{type:`url`,value:he,onChange:e=>ge(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,K.jsx)(`input`,{type:`text`,value:_e,onChange:e=>ve(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,size:`sm`,onClick:ke,children:n(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,size:`sm`,disabled:!le.trim()||Se.isPending,children:Se.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]})]}):(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&Te(e),disabled:Se.isPending||!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.bom.noUpdatePermission`),className:`w-5 h-5 mt-0.5 rounded border-2 flex items-center justify-center transition-colors shrink-0 ${e.is_complete?`bg-status-ok border-status-ok text-white`:a(`projects:update`)?`border-bambu-gray hover:border-bambu-green`:`border-bambu-gray/50 cursor-not-allowed`}`,children:e.is_complete&&(0,K.jsx)(ls,{className:`w-3 h-3`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsxs)(`p`,{className:`text-sm font-medium ${e.is_complete?`text-bambu-gray line-through`:`text-white`}`,children:[e.name,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal ml-2`,children:[`x`,e.quantity_needed]})]}),e.unit_price!==null&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-green whitespace-nowrap`,children:[M,(e.unit_price*e.quantity_needed).toFixed(2)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&De(e),disabled:!a(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${a(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`projects:update`)?n(`common.edit`):n(`projectDetail.bom.noEditPermission`),children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&Ee(e.id,e.name),disabled:!a(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${a(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`projects:update`)?n(`common.delete`):n(`projectDetail.bom.noDeletePermission`),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]}),e.sourcing_url&&(0,K.jsxs)(`a`,{href:e.sourcing_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 mt-1 text-xs text-blue-400 hover:text-blue-300 transition-colors`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(Us,{className:`w-3 h-3 shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.sourcing_url).hostname.replace(`www.`,``)}catch{return e.sourcing_url}})()})]}),e.remarks&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray/80 italic`,children:e.remarks})]})]})},e.id)),Ne&&Ne.bom_cost>0&&(0,K.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.bom.totalCost`)}),(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[M,Ne.bom_cost.toFixed(2)]})]})]}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.bom.empty`)})]})}),(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(wc,{className:`w-5 h-5`}),n(`projectDetail.timeline.title`)]})}),E?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):T&&T.length>0?(0,K.jsx)(`div`,{className:`space-y-3`,children:T.slice(0,10).map((e,t)=>(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsxs)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0 ${e.event_type===`print_completed`?`bg-status-ok/20 text-status-ok`:e.event_type===`print_failed`?`bg-status-error/20 text-status-error`:e.event_type===`print_started`?`bg-yellow-500/20 text-yellow-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e.event_type===`print_completed`&&(0,K.jsx)(ls,{className:`w-4 h-4`}),e.event_type===`print_failed`&&(0,K.jsx)(ms,{className:`w-4 h-4`}),e.event_type===`print_started`&&(0,K.jsx)(bl,{className:`w-4 h-4`}),e.event_type===`queued`&&(0,K.jsx)(zc,{className:`w-4 h-4`}),e.event_type===`project_created`&&(0,K.jsx)(_l,{className:`w-4 h-4`})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:e.title}),e.description&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:Me(e.timestamp)})]})]},t))}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.timeline.empty`)})]})}),!_.is_template&&(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>je.mutate(),disabled:je.isPending||!a(`projects:create`),title:a(`projects:create`)?void 0:n(`projectDetail.template.noCreatePermission`),children:[je.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-2`}):(0,K.jsx)(Ds,{className:`w-4 h-4 mr-2`}),n(`projectDetail.template.saveAsTemplate`)]})}),Ne&&(Ne.queued_prints>0||Ne.in_progress_prints>0)&&(0,K.jsx)(pd,{children:(0,K.jsxs)(hd,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(zc,{className:`w-5 h-5`}),n(`projectDetail.queue.title`)]}),(0,K.jsx)(bi,{to:`/queue?project=${g}`,className:`text-sm text-bambu-green hover:underline`,children:n(`projectDetail.queue.viewAll`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[Ne.in_progress_prints>0&&(0,K.jsx)(`span`,{className:`text-yellow-400`,children:n(`projectDetail.queue.printing`,{count:Ne.in_progress_prints})}),Ne.queued_prints>0&&(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.queue.queued`,{count:Ne.queued_prints})})]})]})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-4`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(cl,{className:`w-5 h-5`}),n(`projectDetail.prints.title`,{count:x?.length||0})]})}),S?(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-green`})}):(0,K.jsx)(yBe,{archives:x||[],t:n})]}),o&&(0,K.jsx)(j7,{t:n,currencySymbol:M,project:{..._,archive_count:Ne?.total_archives||0,total_items:Ne?.total_items||0,completed_count:Ne?.completed_prints||0,failed_count:Ne?.failed_prints||0,queue_count:Ne?.queued_prints||0,progress_percent:Ne?.progress_percent||null,archives:[]},onClose:()=>s(!1),onSave:e=>P.mutate(e),isLoading:P.isPending}),ye.isOpen&&(0,K.jsx)(Ed,{title:ye.title,message:ye.message,confirmText:n(`common.delete`),variant:`danger`,onConfirm:ye.onConfirm,onCancel:()=>be(e=>({...e,isOpen:!1}))}),f&&(0,K.jsx)(sq,{mode:`reprint`,libraryFileId:f.id,archiveName:f.print_name||f.filename,projectId:g,onClose:()=>p(null),onSuccess:()=>{p(null),r.invalidateQueries({queryKey:[`archives`]})}}),m&&(0,K.jsx)(sq,{mode:`add-to-queue`,libraryFileId:m.id,archiveName:m.print_name||m.filename,projectId:g,onClose:()=>h(null),onSuccess:()=>{h(null),r.invalidateQueries({queryKey:[`queue`]})}})]})}function SBe({archiveId:e,libraryFileId:t,title:n,fileType:r,onClose:i,onSliceWithBambuddy:a}){let{t:o}=G(),{data:s}=q({queryKey:[`settings`],queryFn:Q.getSettings}),c=s?.open_in_slicer||s?.preferred_slicer||`bambu_studio`,l=t!=null,[u,d]=(0,y.useState)(null),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(!0),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(null),[C,w]=(0,y.useState)(0),[T,E]=(0,y.useState)(!1),[D,O]=(0,y.useState)(null),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(!1),N=(0,y.useRef)(null),P=(0,y.useRef)(null),F=.35;(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,y.useEffect)(()=>{if(h(!0),l){let e=(r||``).toLowerCase(),t=e===`3mf`||e===`gcode.3mf`,n=t||e===`stl`,i=t||e===`gcode`;p({has_model:n,has_gcode:i,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),d(n?`3d`:i?`gcode`:null),h(!1);return}if(!e){p(null),d(null),h(!1);return}Q.getArchiveCapabilities(e).then(e=>{p(e),e.has_model?d(`3d`):e.has_gcode&&d(`gcode`),h(!1)}).catch(()=>{p({has_model:!0,has_gcode:!1,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),d(`3d`),h(!1)})},[e,r,l]),(0,y.useEffect)(()=>{if(b(!0),S(null),w(0),l){let e=(r||``).toLowerCase();if(!t||!(e===`3mf`||e===`gcode.3mf`)){_(null),b(!1);return}Q.getLibraryFilePlates(t).then(e=>_(e)).catch(()=>_(null)).finally(()=>b(!1));return}if(!e){_(null),b(!1);return}Q.getArchivePlates(e).then(e=>_(e)).catch(()=>_(null)).finally(()=>b(!1))},[e,r,l,t]);let I=(0,y.useMemo)(()=>g?.plates??[],[g]),L=(g?.is_multi_plate??!1)&&I.length>1,R=T&&L,z=x==null?null:I.find(e=>e.index===x)??null,B=e=>e.object_count??e.objects?.length??0,V=I.reduce((e,t)=>e+B(t),0),ee=z?B(z):V,H=z?o(`modelViewer.plateNumber`,{number:z.index}):o(`modelViewer.allPlates`),te=I.length>0,ne=(0,y.useRef)(null),re=(0,y.useRef)(null),[U,ie]=(0,y.useState)(10),[ae,W]=(0,y.useState)(3),oe=I.length>U,se=Math.max(1,Math.ceil(I.length/U)),ce=oe?I.slice(C*U,(C+1)*U):I;(0,y.useEffect)(()=>{if(!R){ie(10),W(3);return}let e=ne.current,t=re.current;if(!e||!t)return;let n=0,r=()=>{let n=t.clientWidth,r=Math.floor(n/210),i=Math.max(3,Math.min(5,r||3));W(e=>e===i?e:i);let a=window.getComputedStyle(e),o=Number.parseFloat(a.rowGap||`0`),s=e.querySelector(`button`)?.getBoundingClientRect().height??44,c=t.clientHeight,l=Math.max(1,Math.floor((c+o)/(s+o)))*i,u=Math.max(1,l-1);ie(e=>e===u?e:u)},i=()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(r)};i();let a=new ResizeObserver(i);return a.observe(t),a.observe(e),()=>{n&&cancelAnimationFrame(n),a.disconnect()}},[R,I.length]),(0,y.useEffect)(()=>{if(!oe){w(0);return}w(e=>Math.min(e,se-1))},[I.length,oe,se]),(0,y.useEffect)(()=>{if(!oe||x==null)return;let e=I.findIndex(e=>e.index===x);if(e<0)return;let t=Math.floor(e/U);w(e=>e===t?e:t)},[I,U,x,oe]),(0,y.useEffect)(()=>{if(!R){O(null),M(!1);return}if(j)return;let e=N.current,t=P.current;if(!e||!t)return;let n=e.clientHeight;if(!n)return;let r=Math.max(240,n*F),i=Math.max(160,n-10-r),a=Math.min(t.scrollHeight,i);O(Math.max(160,a))},[R,j,I.length,C,10,160,240,F]),(0,y.useEffect)(()=>{if(!k)return;let e=e=>{let t=N.current;if(!t)return;let n=t.getBoundingClientRect(),r=n.height;if(!r)return;let i=Math.max(240,r*F),a=Math.max(160,r-10-i);O(Math.min(a,Math.max(160,e.clientY-n.top)))},t=()=>{A(!1),M(!0)};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),document.body.style.cursor=`row-resize`,document.body.style.userSelect=`none`,()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[k,10,160,240,F]);let le=l?(r||``).toLowerCase()===`3mf`:!0,ue=(()=>{let e=(r||``).toLowerCase();return e===`3mf`||e===`stl`||e===`step`||e===`stp`})(),de=!!(l&&s?.use_slicer_api&&a&&ue);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 ${T?`p-0`:`p-8`}`,onClick:i,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary w-full flex flex-col ${T?`h-full max-w-none rounded-none`:`h-[80vh] max-w-4xl rounded-xl`}`,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-3 min-w-0 flex-1 mr-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:n}),te&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary/70 px-2 py-1 rounded whitespace-nowrap`,children:[H,`: `,o(`modelViewer.objectCount`,{count:ee})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[de?(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:a,children:[(0,K.jsx)(ws,{className:`w-4 h-4`}),o(`slice.action`)]}):(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:async()=>{if(!le)return;let r=n||`model`;try{if(l){let{token:e}=await Q.createLibrarySlicerToken(t),n=Q.getLibrarySlicerDownloadUrl(t,e,r);Uq(`${window.location.origin}${n}`,c)}else{let{token:t}=await Q.createArchiveSlicerToken(e),n=Q.getArchiveSlicerDownloadUrl(e,t,r);Uq(`${window.location.origin}${n}`,c)}}catch{Uq(l?`${window.location.origin}${Q.getLibraryFileDownloadUrl(t)}`:`${window.location.origin}${Q.getArchiveForSlicer(e,r)}`,c)}},disabled:!le,children:[(0,K.jsx)(Us,{className:`w-4 h-4`}),o(`modelViewer.openInSlicer`)]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>E(e=>!e),title:T?`Exit fullscreen`:`Enter fullscreen`,children:T?(0,K.jsx)(Qc,{className:`w-4 h-4`}):(0,K.jsx)(Jc,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:i,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]})]}),f&&(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`button`,{onClick:()=>f.has_model&&d(`3d`),disabled:!f.has_model,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${u===`3d`?`text-bambu-green border-b-2 border-bambu-green`:f.has_model?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,K.jsx)(Bo,{className:`w-4 h-4`}),o(`modelViewer.tabs.model`),!f.has_model&&(0,K.jsxs)(`span`,{className:`text-xs`,children:[`(`,o(`modelViewer.notAvailable`),`)`]})]}),(0,K.jsxs)(`button`,{onClick:()=>f.has_gcode&&d(`gcode`),disabled:!f.has_gcode,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${u===`gcode`?`text-bambu-green border-b-2 border-bambu-green`:f.has_gcode?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,K.jsx)(bs,{className:`w-4 h-4`}),o(`modelViewer.tabs.gcode`),!f.has_gcode&&(0,K.jsxs)(`span`,{className:`text-xs`,children:[`(`,o(`modelViewer.notSliced`),`)`]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-hidden p-4`,children:m?(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})}):u===`3d`&&f?(0,K.jsxs)(`div`,{ref:N,className:`w-full h-full flex flex-col ${R?`gap-0 min-h-0`:`gap-3`}`,children:[L&&(0,K.jsxs)(`div`,{ref:P,style:R&&D!=null?{height:D}:void 0,className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3 ${R?`flex flex-col shrink-0`:``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:[(0,K.jsx)(Nc,{className:`w-4 h-4`}),o(`modelViewer.plates`),v&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`})]}),(0,K.jsxs)(`div`,{className:R?`flex flex-col min-h-0 flex-1`:void 0,children:[(0,K.jsx)(`div`,{ref:re,className:R?`min-h-0 overflow-hidden pr-1 flex-1`:void 0,children:(0,K.jsxs)(`div`,{ref:ne,className:R?`grid gap-2`:`grid grid-cols-2 md:grid-cols-3 gap-2`,style:R?{gridTemplateColumns:`repeat(${ae}, minmax(0, 1fr))`}:void 0,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>S(null),className:`flex items-center rounded-lg border text-left transition-colors ${R?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${x==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:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${R?`w-8 h-8`:`w-10 h-10`}`,children:(0,K.jsx)(Nc,{className:`${R?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`${R?`text-xs`:`text-sm`} text-white font-medium truncate`,children:o(`modelViewer.allPlates`)}),(0,K.jsx)(`p`,{className:`${R?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:o(`modelViewer.plateCount`,{count:I.length})})]}),x==null&&(0,K.jsx)($o,{className:`${R?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]}),ce.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>S(e.index),className:`flex items-center rounded-lg border text-left transition-colors ${R?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${x===e.index?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[e.has_thumbnail&&e.thumbnail_url?(0,K.jsx)(`img`,{src:e.thumbnail_url,alt:`Plate ${e.index}`,className:`${R?`w-8 h-8`:`w-10 h-10`} rounded object-cover bg-bambu-dark-tertiary`}):(0,K.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${R?`w-8 h-8`:`w-10 h-10`}`,children:(0,K.jsx)(Nc,{className:`${R?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`${R?`text-xs`:`text-sm`} text-white font-medium truncate`,children:e.name||o(`modelViewer.plateNumber`,{number:e.index})}),(0,K.jsx)(`p`,{className:`${R?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:o(`modelViewer.objectCount`,{count:e.object_count??e.objects?.length??0})})]}),x===e.index&&(0,K.jsx)($o,{className:`${R?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]},e.index))]})}),(z||oe)&&(0,K.jsxs)(`div`,{className:`mt-auto pt-3 flex items-center gap-4 text-xs text-bambu-gray overflow-x-auto`,children:[z&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 whitespace-nowrap`,children:[(0,K.jsx)(`span`,{children:o(`modelViewer.plateNumber`,{number:z.index})}),z.print_time_seconds!=null&&(0,K.jsx)(`span`,{children:o(`modelViewer.eta`,{minutes:Math.round(z.print_time_seconds/60)})}),z.filament_used_grams!=null&&(0,K.jsxs)(`span`,{children:[z.filament_used_grams.toFixed(1),` g`]}),z.filaments.length>0&&(0,K.jsx)(`span`,{children:o(`modelViewer.filamentCount`,{count:z.filaments.length})})]}),oe&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 whitespace-nowrap ${z?`ml-auto`:``}`,children:[(0,K.jsx)(`span`,{children:o(`modelViewer.pagination.pageOf`,{current:C+1,total:se})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e=>Math.max(e-1,0)),disabled:C===0,className:`px-2 py-1 rounded border text-xs ${C===0?`border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:o(`modelViewer.pagination.prev`)}),(()=>{let e=Math.max(0,C-2),t=Math.min(se,e+5);t-e<5&&(e=Math.max(0,t-5));let n=Array.from({length:t-e},(t,n)=>e+n);return(0,K.jsxs)(K.Fragment,{children:[e>0&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(0),className:`px-2 py-1 rounded border text-xs ${C===0?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:`1`}),e>1&&(0,K.jsx)(`span`,{className:`px-1`,children:`…`}),n.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e),className:`px-2 py-1 rounded border text-xs ${C===e?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:e+1},e)),tw(se-1),className:`px-2 py-1 rounded border text-xs ${C===se-1?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:se})]})})(),(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e=>Math.min(e+1,se-1)),disabled:C>=se-1,className:`px-2 py-1 rounded border text-xs ${C>=se-1?`border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:o(`modelViewer.pagination.next`)})]})]})]})]})]}),R&&(0,K.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,onMouseDown:e=>{e.preventDefault(),A(!0),M(!0)},className:`h-2 cursor-row-resize flex items-center justify-center ${k?`bg-bambu-dark-tertiary`:`bg-bambu-dark-secondary/60 hover:bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`div`,{className:`w-12 h-1 rounded-full bg-bambu-gray/50`})}),(0,K.jsx)(`div`,{className:`flex-1 ${R?`min-h-0`:``}`,children:(0,K.jsx)(ny,{url:l?Q.getLibraryFileDownloadUrl(t):f.has_source?Q.getSource3mfDownloadUrl(e):Q.getArchiveDownload(e),fileType:r,buildVolume:f.build_volume,filamentColors:f.filament_colors,selectedPlateId:x,className:`w-full h-full`})})]}):u===`gcode`&&f?(0,K.jsx)(ET,{gcodeUrl:l?Q.getLibraryFileGcodeUrl(t):Q.getArchiveGcode(e),filamentColors:f.filament_colors,className:`w-full h-full`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:o(`modelViewer.noPreview`)})})]})})}var CBe=90;function wBe({onClose:e}){let{t}=G(),n=Qa(),{showToast:r}=xd(),[i,a]=(0,y.useState)(CBe),[o,s]=(0,y.useState)(!0),[c,l]=(0,y.useState)(i);(0,y.useEffect)(()=>{let e=window.setTimeout(()=>l(i),300);return()=>window.clearTimeout(e)},[i]);let u=q({queryKey:[`library-purge-preview`,c,o],queryFn:()=>Q.previewLibraryPurge(c,o),enabled:c>=1}),d=J({mutationFn:()=>Q.executeLibraryPurge(i,o),onSuccess:i=>{r(t(`libraryPurge.toast.success`,{count:i.moved_to_trash}),`success`),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]}),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),e()},onError:e=>r(e.message||t(`libraryPurge.toast.failed`),`error`)});(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!d.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,d.isPending]);let f=u.data,p=f?.count??0,m=f?.total_bytes??0,h=p>0&&!d.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)(hu,{className:`w-5 h-5`}),t(`libraryPurge.title`)]}),(0,K.jsx)(`button`,{onClick:e,className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-200`,"aria-label":t(`common.close`),disabled:d.isPending,children:(0,K.jsx)(Pu,{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:t(`libraryPurge.description`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`purge-days`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:t(`libraryPurge.ageLabel`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`input`,{id:`purge-days`,type:`number`,min:1,max:3650,value:i,onChange:e=>a(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:t(`libraryPurge.days`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`rounded border-gray-300`}),t(`libraryPurge.includeNeverPrinted`)]}),(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:t(`libraryPurge.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:t(`libraryPurge.effect1`)}),(0,K.jsx)(`li`,{children:t(`libraryPurge.effect2`)}),(0,K.jsx)(`li`,{children:t(`libraryPurge.effect3`)}),(0,K.jsx)(`li`,{children:t(`libraryPurge.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:u.isLoading||u.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`}),` `,t(`libraryPurge.previewLoading`)]}):u.isError?(0,K.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:u.error?.message??t(`libraryPurge.previewFailed`)}):(0,K.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:t(`libraryPurge.previewSummary`,{count:p,size:yd(m)})}),f?.sample_filenames&&f.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:[f.sample_filenames.map(e=>(0,K.jsx)(`li`,{className:`truncate`,children:e},e)),p>f.sample_filenames.length&&(0,K.jsx)(`li`,{className:`list-none italic text-gray-500`,children:t(`libraryPurge.andMore`,{count:p-f.sample_filenames.length})})]})]})}),(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)(vu,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,K.jsx)(`span`,{children:t(`libraryPurge.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:d.isPending,children:t(`common.cancel`)}),(0,K.jsx)($,{variant:`danger`,disabled:!h,onClick:()=>d.mutate(),children:d.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-1`}),t(`libraryPurge.purging`)]}):t(`libraryPurge.confirmCta`,{count:p})})]})]})})}function TBe({parentId:e,onClose:t,onSave:n,isLoading:r,t:i}){let[a,o]=(0,y.useState)(``);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 w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`fileManager.newFolder`)})}),(0,K.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),n({name:a.trim(),parent_id:e})},className:`p-4 space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:i(`fileManager.folderName`)}),(0,K.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:i(`fileManager.folderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!a.trim()||r,children:r?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):i(`common.create`)})]})]})]})})}function EBe({onClose:e,onSave:t,isLoading:n,t:r}){let[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(!0),[u,d]=(0,y.useState)(!1);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 w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(ac,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.linkExternalFolder`)]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`fileManager.linkExternalFolderDescription`)})]}),(0,K.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),t({name:i.trim(),external_path:o.trim(),readonly:c,show_hidden:u})},className:`p-4 space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.folderName`)}),(0,K.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:r(`fileManager.externalFolderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.externalPath`)}),(0,K.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green font-mono text-sm`,placeholder:`/mnt/nas/3d-prints`,required:!0}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`fileManager.externalPathHelp`)})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.readOnly`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,r(`fileManager.readOnlyHelp`),`)`]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>d(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.showHiddenFiles`)})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:e,children:r(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!i.trim()||!o.trim()||n,children:n?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):r(`fileManager.linkFolder`)})]})]})]})})}var DBe=`<>:"/\\|?*`;function OBe(e){for(let t of e)if(DBe.includes(t)||t.charCodeAt(0)<32)return t;return null}function kBe({type:e,currentName:t,onClose:n,onSave:r,isLoading:i,t:a}){let o=e===`file`?t.match(/(\.gcode\.3mf|\.3mf|\.gcode)$/i)?.[1]??``:``,s=e===`file`&&o?t.slice(0,-o.length):t,[c,l]=(0,y.useState)(s),u=e===`file`?OBe(c):null,d=u?a(`fileManager.invalidFilenameChar`,{char:u}):null;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 w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e===`file`?`fileManager.renameFile`:`fileManager.renameFolder`)})}),(0,K.jsxs)(`form`,{onSubmit:n=>{if(n.preventDefault(),d)return;let i=e===`file`?c.trim()+o:c.trim();c.trim()&&i!==t&&r(i)},className:`p-4 space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,K.jsxs)(`div`,{className:`flex items-center bg-bambu-dark border rounded focus-within:border-bambu-green ${d?`border-red-500`:`border-bambu-dark-tertiary`}`,children:[(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`flex-1 bg-transparent px-3 py-2 text-white placeholder-bambu-gray focus:outline-none min-w-0`,autoFocus:!0,required:!0}),o&&(0,K.jsx)(`span`,{className:`pr-3 text-bambu-gray text-sm select-none whitespace-nowrap`,children:o})]}),d&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-400`,children:d})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:n,children:a(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!c.trim()||c.trim()===s||!!d||i,children:i?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):a(`common.rename`)})]})]})]})})}function ABe({folders:e,selectedFiles:t,currentFolderId:n,onClose:r,onMove:i,isLoading:a,t:o}){let[s,c]=(0,y.useState)(null),l=(e,t=0)=>{let n=[];for(let r of e)n.push({id:r.id,name:r.name,depth:t}),r.children.length>0&&n.push(...l(r.children,t+1));return n},u=[{id:null,name:o(`fileManager.rootNoFolder`),depth:0},...l(e)];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 w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:o(`fileManager.moveFiles`,{count:t.length})})}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,K.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1`,children:u.map(e=>(0,K.jsxs)(`button`,{onClick:()=>c(e.id),disabled:e.id===n,className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:e.id===n?`opacity-50 cursor-not-allowed text-bambu-gray`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${12+e.depth*16}px`},children:[(0,K.jsx)(rc,{className:`w-4 h-4`}),e.name,e.id===n&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray ml-auto`,children:[`(`,o(`fileManager.current`),`)`]})]},e.id??`root`))}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:r,children:o(`common.cancel`)}),(0,K.jsx)($,{onClick:()=>i(s),disabled:a,children:a?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):o(`common.move`)})]})]})]})})}function jBe({folder:e,onClose:t,onLink:n,isLoading:r,t:i}){let[a,o]=(0,y.useState)(`project`),[s,c]=(0,y.useState)(e.project_id||e.archive_id||null);(0,y.useState)(()=>{e.archive_id&&o(`archive`)});let{data:l}=q({queryKey:[`projects`],queryFn:()=>Q.getProjects(),select:e=>[...e].sort((e,t)=>e.name.localeCompare(t.name))}),{data:u}=q({queryKey:[`archives-for-link`],queryFn:()=>Q.getArchives(void 0,void 0,100)}),d=()=>{n(a===`project`?{project_id:s,archive_id:0}:{project_id:0,archive_id:s})},f=()=>{n({project_id:0,archive_id:0})},p=e.project_id||e.archive_id;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 w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Ic,{className:`w-5 h-5 text-bambu-green`}),i(`fileManager.linkFolder`)]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,K.jsx)(Pu,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`fileManager.linkFolderDescription`,{name:e.name})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`button`,{onClick:()=>{o(`project`),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a===`project`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(Vo,{className:`w-4 h-4`}),i(`fileManager.project`)]}),(0,K.jsxs)(`button`,{onClick:()=>{o(`archive`),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a===`archive`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(wo,{className:`w-4 h-4`}),i(`fileManager.archive`)]})]}),(0,K.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2`,children:a===`project`?l&&l.length>0?l.map(e=>(0,K.jsxs)(`button`,{onClick:()=>c(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#00ae42`}}),(0,K.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id)):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noProjectsFound`)}):u&&u.length>0?u.map(e=>(0,K.jsxs)(`button`,{onClick:()=>c(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,K.jsx)(qs,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:e.print_name||e.filename})]},e.id)):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noArchivesFound`)})})]}),(0,K.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-between`,children:[p&&(0,K.jsxs)($,{variant:`danger`,onClick:f,disabled:r,children:[(0,K.jsx)(xu,{className:`w-4 h-4 mr-2`}),i(`fileManager.unlink`)]}),(0,K.jsxs)(`div`,{className:`flex gap-2 ${p?``:`ml-auto`}`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,K.jsx)($,{onClick:d,disabled:!s||r,children:r?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):i(`fileManager.link`)})]})]})]})})}function P7({folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o=0,wrapNames:s=!1,defaultExpanded:c=!0,hasPermission:l,t:u}){let[d,f]=(0,y.useState)(c),[p,m]=(0,y.useState)(!1),h=e.children.length>0,g=e.project_id||e.archive_id,_=e.is_external;return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`group flex items-center gap-1 px-2 py-1.5 rounded cursor-pointer transition-colors ${t===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${8+o*12}px`},onClick:()=>n(e.id),children:[h?(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),f(!d)},className:`p-0.5 hover:bg-bambu-dark-tertiary rounded`,children:(0,K.jsx)(ts,{className:`w-3.5 h-3.5 transition-transform ${d?`rotate-90`:``}`})}):(0,K.jsx)(`div`,{className:`w-4.5`}),_?(0,K.jsx)(ac,{className:`w-4 h-4 text-purple-400 flex-shrink-0`}):(0,K.jsx)(rc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm flex-1 min-w-0 ${s?`break-all`:`truncate`}`,title:e.name,children:e.name}),g&&(0,K.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400 hover:bg-blue-500/30 transition-colors`,title:`${e.project_name?`Project: ${e.project_name}`:`Archive: ${e.archive_name}`} (click to change)`,children:[(0,K.jsx)(Ic,{className:`w-3 h-3`}),e.project_name?(0,K.jsx)(Vo,{className:`w-3 h-3`}):(0,K.jsx)(wo,{className:`w-3 h-3`})]}),_&&e.external_readonly&&(0,K.jsx)(`span`,{title:u(`fileManager.readOnly`),children:(0,K.jsx)(Hc,{className:`w-3 h-3 text-amber-400 flex-shrink-0`})}),e.file_count>0&&(0,K.jsx)(`span`,{className:`flex-shrink-0 text-xs text-bambu-gray`,children:e.file_count}),!g&&!_&&(0,K.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary`,title:u(`fileManager.linkToProjectOrArchive`),children:(0,K.jsx)(Ic,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green`})}),(0,K.jsx)(`div`,{className:`flex-shrink-0 flex items-center gap-0.5 transition-opacity ${s?``:`opacity-0 group-hover:opacity-100`}`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{onClick:()=>m(!p),className:`p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(zs,{className:`w-3.5 h-3.5 text-bambu-gray`})}),p&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>m(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${l(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{l(`library:update_all`)&&(a(e),m(!1))},disabled:!l(`library:update_all`),title:l(`library:update_all`)?void 0:u(`fileManager.noPermissionRenameFolder`),children:[(0,K.jsx)(pl,{className:`w-3.5 h-3.5`}),u(`common.rename`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${l(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{l(`library:update_all`)&&(i(e),m(!1))},disabled:!l(`library:update_all`),title:l(`library:update_all`)?void 0:u(`fileManager.noPermissionLinkFolder`),children:[(0,K.jsx)(Ic,{className:`w-3.5 h-3.5`}),u(g?`fileManager.changeLink`:`fileManager.linkTo`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${l(`library:delete_all`)?`text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{l(`library:delete_all`)&&(r(e.id),m(!1))},disabled:!l(`library:delete_all`),title:l(`library:delete_all`)?void 0:u(`fileManager.noPermissionDeleteFolder`),children:[(0,K.jsx)(hu,{className:`w-3.5 h-3.5`}),u(`common.delete`)]})]})]})]})})]}),h&&d&&(0,K.jsx)(`div`,{children:e.children.map(e=>(0,K.jsx)(P7,{folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o+1,wrapNames:s,defaultExpanded:c,hasPermission:l,t:u},e.id))})]})}function F7(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)}function I7(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)?!1:t.endsWith(`.stl`)||t.endsWith(`.3mf`)||t.endsWith(`.step`)||t.endsWith(`.stp`)}function MBe({file:e,isSelected:t,isMobile:n,onSelect:r,onDelete:i,onDownload:a,onAddToQueue:o,onPrint:s,onSlice:c,useSlicerApi:l,onPreview3d:u,onRename:d,onGenerateThumbnail:f,thumbnailVersion:p,hasPermission:m,canModify:h,authEnabled:g,t:_}){let[v,b]=(0,y.useState)(!1);return(0,K.jsxs)(`div`,{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer overflow-hidden ${t?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,onClick:()=>r(e.id),children:[(0,K.jsxs)(`div`,{className:`aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden`,children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:`${Q.getLibraryFileThumbnailUrl(e.id)}${p?(Q.getLibraryFileThumbnailUrl(e.id).includes(`?`)?`&`:`?`)+`v=${p}`:``}`,alt:e.filename,className:`w-full h-full object-cover`}):(0,K.jsx)(qs,{className:`w-12 h-12 text-bambu-gray/30`}),(0,K.jsx)(`div`,{className:`absolute top-2 right-2 text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/90 text-white`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-500/90 text-white`:e.file_type===`stl`?`bg-purple-500/90 text-white`:`bg-bambu-gray/90 text-white`}`,children:e.file_type.toUpperCase()})]}),(0,K.jsxs)(`div`,{className:`p-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mt-1 text-xs text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:yd(e.file_size)}),e.print_time_seconds&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),yf(e.print_time_seconds)]})]}),e.sliced_for_model&&(0,K.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,K.jsx)(bl,{className:`w-3 h-3`}),e.sliced_for_model]}),e.print_count>0&&(0,K.jsx)(`div`,{className:`mt-1 text-xs text-bambu-green`,children:_(`fileManager.printedCount`,{count:e.print_count})}),g&&e.created_by_username&&(0,K.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,K.jsx)(Cu,{className:`w-3 h-3`}),e.created_by_username]})]}),(0,K.jsxs)(`div`,{className:`absolute bottom-2 right-2 transition-opacity ${n?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`button`,{onClick:()=>b(!v),className:`p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(zs,{className:`w-4 h-4 text-bambu-gray`})}),v&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>b(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 bottom-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[140px]`,children:[s&&F7(e.filename)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${m(`printers:control`)?`text-bambu-green hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{m(`printers:control`)&&(s(e),b(!1))},disabled:!m(`printers:control`),title:m(`printers:control`)?void 0:_(`fileManager.noPermissionPrint`),children:[(0,K.jsx)(bl,{className:`w-3.5 h-3.5`}),_(`common.print`)]}),o&&F7(e.filename)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${m(`queue:create`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{m(`queue:create`)&&(o(e.id),b(!1))},disabled:!m(`queue:create`),title:m(`queue:create`)?void 0:_(`fileManager.noPermissionAddToQueue`),children:[(0,K.jsx)(_s,{className:`w-3.5 h-3.5`}),_(`fileManager.schedulePrint`)]}),c&&l&&I7(e.filename)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${m(`library:upload`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{m(`library:upload`)&&(c(e),b(!1))},disabled:!m(`library:upload`),title:m(`library:upload`)?void 0:_(`fileManager.noPermissionSlice`),children:[(0,K.jsx)(ws,{className:`w-3.5 h-3.5`}),_(`slice.action`)]}),u&&(e.file_type===`3mf`||e.file_type===`gcode`||e.file_type===`stl`||e.file_type===`gcode.3mf`)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${m(`library:read`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{m(`library:read`)&&(u(e),b(!1))},disabled:!m(`library:read`),title:m(`library:read`)?void 0:`You do not have permission to preview files`,children:[(0,K.jsx)(Bo,{className:`w-3.5 h-3.5`}),`3D Preview`]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${m(`library:read`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{m(`library:read`)&&(a(e.id),b(!1))},disabled:!m(`library:read`),title:m(`library:read`)?void 0:_(`fileManager.noPermissionDownload`),children:[(0,K.jsx)(Is,{className:`w-3.5 h-3.5`}),_(`common.download`)]}),d&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${h(`library`,`update`,e.created_by_id)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{h(`library`,`update`,e.created_by_id)&&(d(e),b(!1))},disabled:!h(`library`,`update`,e.created_by_id),title:h(`library`,`update`,e.created_by_id)?void 0:_(`fileManager.noPermissionRenameFile`),children:[(0,K.jsx)(pl,{className:`w-3.5 h-3.5`}),_(`common.rename`)]}),f&&e.file_type===`stl`&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${h(`library`,`update`,e.created_by_id)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{h(`library`,`update`,e.created_by_id)&&(f(e),b(!1))},disabled:!h(`library`,`update`,e.created_by_id),title:h(`library`,`update`,e.created_by_id)?void 0:_(`fileManager.noPermissionGenerateThumbnail`),children:[(0,K.jsx)(Dc,{className:`w-3.5 h-3.5`}),_(`fileManager.generateThumbnail`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${h(`library`,`delete`,e.created_by_id)?`text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{h(`library`,`delete`,e.created_by_id)&&(i(e.id),b(!1))},disabled:!h(`library`,`delete`,e.created_by_id),title:h(`library`,`delete`,e.created_by_id)?void 0:_(`fileManager.noPermissionDeleteFile`),children:[(0,K.jsx)(hu,{className:`w-3.5 h-3.5`}),_(`common.delete`)]})]})]})]}),(0,K.jsx)(`div`,{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${t?`bg-bambu-green border-bambu-green`:`border-white/30 bg-black/30 ${n?`opacity-100`:`opacity-0 group-hover:opacity-100`}`}`,children:t&&(0,K.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})})]})}function NBe(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),{hasPermission:r,hasAnyPermission:i,canModify:a,authEnabled:o}=sd(),[s]=Oi(),c=Yn(),l=s.get(`folder`),[u,d]=(0,y.useState)(l?parseInt(l,10):null),[f,p]=(0,y.useState)(`internal`),[m,h]=(0,y.useState)([]),[g,_]=(0,y.useState)(!1),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(!1),[D,O]=(0,y.useState)(null),[k,A]=(0,y.useState)(null),[j,M]=(0,y.useState)(null),[N,P]=(0,y.useState)(null),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(null),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)({}),[H,te]=(0,y.useState)(null),[ne,re]=(0,y.useState)(()=>localStorage.getItem(`library-view-mode`)||`grid`),[U,ie]=(0,y.useState)(()=>localStorage.getItem(`library-wrap-folders`)===`true`),[ae,W]=(0,y.useState)(()=>localStorage.getItem(`library-collapse-folders`)===`true`),[oe,se]=(0,y.useState)(()=>{let e=localStorage.getItem(`library-sidebar-width`);return e?parseInt(e,10):256}),[ce,le]=(0,y.useState)(!1),ue=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!ce)return;document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let e=e=>{if(!ue.current)return;let t=ue.current.parentElement?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left;se(Math.min(500,Math.max(200,n)))},t=()=>{le(!1),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`library-sidebar-width`,String(oe))};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.userSelect=``,document.body.style.cursor=``}},[ce,oe]);let[de,fe]=(0,y.useState)(``),[pe,me]=(0,y.useState)(`all`),[he,ge]=(0,y.useState)(``),[_e,ve]=(0,y.useState)(()=>localStorage.getItem(`library-sort-field`)||`name`),[ye,be]=(0,y.useState)(()=>localStorage.getItem(`library-sort-direction`)||`asc`),xe=Gq();(0,y.useEffect)(()=>{let e=s.get(`folder`);e&&d(parseInt(e,10))},[s]);let{data:Se}=q({queryKey:[`settings`],queryFn:()=>Q.getSettings()}),{data:Ce,isLoading:we}=q({queryKey:[`library-folders`],queryFn:()=>Q.getLibraryFolders()}),{data:Te}=q({queryKey:[`library-trash-count`],queryFn:async()=>{try{return(await Q.listLibraryTrash(1,0)).total}catch{return 0}},staleTime:3e4}),{data:Ee,isLoading:De}=q({queryKey:[`library-files`,u,f],queryFn:()=>Q.getLibraryFiles(u,!1,void 0,u===null?f:void 0)}),{data:Oe}=q({queryKey:[`library-stats`],queryFn:()=>Q.getLibraryStats()}),{data:ke}=q({queryKey:[`users`],queryFn:()=>Q.getUsers()}),Ae=(0,y.useMemo)(()=>{if(!Ee)return[];let e=new Set(Ee.map(e=>e.file_type));return Array.from(e).sort()},[Ee]),je=(0,y.useMemo)(()=>{if(!Ee)return[];let e=[...Ee];if(de.trim()){let t=de.toLowerCase();e=e.filter(e=>e.filename.toLowerCase().includes(t)||e.print_name&&e.print_name.toLowerCase().includes(t))}if(pe!==`all`&&(e=e.filter(e=>e.file_type===pe)),he.trim()){let t=he.toLowerCase();e=e.filter(e=>e.created_by_username&&e.created_by_username.toLowerCase().includes(t))}return e.sort((e,t)=>{let n=0;switch(_e){case`name`:n=(e.print_name||e.filename).localeCompare(t.print_name||t.filename);break;case`date`:n=(mf(e.created_at)?.getTime()??0)-(mf(t.created_at)?.getTime()??0);break;case`size`:n=e.file_size-t.file_size;break;case`type`:n=e.file_type.localeCompare(t.file_type);break;case`prints`:n=e.print_count-t.print_count;break}return ye===`asc`?n:-n}),e},[Ee,de,pe,he,_e,ye]),Me=(0,y.useMemo)(()=>{if(!Oe||!Se)return!1;let e=(Se.library_disk_warning_gb||5)*1024*1024*1024;return Oe.disk_free_bytesQ.createLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),_(!1),n(e(`fileManager.toast.folderCreated`),`success`)},onError:e=>n(e.message,`error`)}),Pe=J({mutationFn:async e=>{let t=await Q.createExternalFolder(e);return await Q.scanExternalFolder(t.id),t},onSuccess:r=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),b(!1),d(r.id),n(e(`fileManager.toast.externalFolderLinked`),`success`)},onError:e=>n(e.message,`error`)}),Fe=J({mutationFn:e=>Q.scanExternalFolder(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),n(e(`fileManager.toast.folderScanned`,{added:r.added,removed:r.removed}),`success`)},onError:e=>n(e.message,`error`)}),Ie=J({mutationFn:e=>Q.deleteLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),u===k?.id&&d(null),A(null),n(e(`fileManager.toast.folderDeleted`),`success`)},onError:e=>{A(null),n(e.message,`error`)}}),Le=J({mutationFn:e=>Q.deleteLibraryFile(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),h(e=>e.filter(e=>e!==k?.id)),A(null),n(e(`fileManager.toast.fileDeleted`),`success`)},onError:e=>{A(null),n(e.message,`error`)}}),Re=J({mutationFn:e=>Q.bulkDeleteLibrary(e,[]),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),n(e(`fileManager.toast.filesDeleted`,{count:i.length}),`success`),h([]),A(null)},onError:e=>{A(null),n(e.message,`error`)}}),ze=J({mutationFn:({fileIds:e,folderId:t})=>Q.moveLibraryFiles(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),h([]),S(!1),n(e(`fileManager.toast.filesMoved`),`success`)},onError:e=>n(e.message,`error`)}),Be=J({mutationFn:({id:e,data:t})=>Q.updateLibraryFolder(e,t),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`project-folders`]}),t.invalidateQueries({queryKey:[`archive-folders`]}),O(null),n(i.data.project_id===0&&i.data.archive_id===0?e(`fileManager.toast.folderUnlinked`):e(`fileManager.toast.folderLinked`),`success`)},onError:e=>n(e.message,`error`)}),Ve=J({mutationFn:({id:e,filename:t})=>Q.updateLibraryFile(e,{filename:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),B(null),n(e(`fileManager.toast.fileRenamed`),`success`)},onError:e=>{B(null),n(e.message,`error`)}}),He=J({mutationFn:({id:e,name:t})=>Q.updateLibraryFolder(e,{name:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),B(null),n(e(`fileManager.toast.folderRenamed`),`success`)},onError:e=>{B(null),n(e.message,`error`)}}),Ue=J({mutationFn:()=>Q.batchGenerateStlThumbnails({all_missing:!0}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let e=Date.now(),t={};r.results.forEach(n=>{n.success&&(t[n.file_id]=e)}),ee(e=>({...e,...t}))}r.succeeded>0&&r.failed===0?n(e(`fileManager.toast.thumbnailsGenerated`,{count:r.succeeded}),`success`):r.succeeded>0&&r.failed>0?n(e(`fileManager.toast.thumbnailsGeneratedPartial`,{succeeded:r.succeeded,failed:r.failed}),`success`):r.processed===0?n(e(`fileManager.toast.noStlMissingThumbnails`),`info`):n(e(`fileManager.toast.failedToGenerateThumbnails`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),We=J({mutationFn:e=>Q.batchGenerateStlThumbnails({file_ids:[e]}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let t=r.results[0]?.file_id;t&&ee(e=>({...e,[t]:Date.now()})),n(e(`fileManager.toast.thumbnailGenerated`),`success`)}else n(e(`fileManager.toast.failedToGenerateThumbnail`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),Ge=(0,y.useCallback)(e=>{let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.includes(`.gcode.`)},[]),Ke=(0,y.useMemo)(()=>Ee?Ee.filter(e=>m.includes(e.id)&&Ge(e.filename)):[],[Ee,m,Ge]),qe=(0,y.useCallback)(e=>{h(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),Je=(0,y.useCallback)(()=>{je.length>0&&h(je.map(e=>e.id))},[je]),Ye=(0,y.useCallback)(()=>{h([])},[]),Xe=()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]})},Ze=e=>{Q.downloadLibraryFile(e).catch(e=>{console.error(`Library file download failed:`,e)})},Qe=()=>{k&&(k.type===`file`?Le.mutate(k.id):k.type===`folder`?Ie.mutate(k.id):k.type===`bulk`&&Re.mutate(m))},$e=Ie.isPending||Le.isPending||Re.isPending,et=e=>{re(e),localStorage.setItem(`library-view-mode`,e)},tt=we||De,nt=(0,y.useMemo)(()=>{if(!u||!Ce)return null;let e=t=>{for(let n of t){if(n.id===u)return n;let t=e(n.children);if(t)return t}return null};return e(Ce)},[u,Ce]);return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-[calc(100vh-64px)] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4 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)(rc,{className:`w-7 h-7 text-bambu-green`}),e(`fileManager.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`fileManager.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center bg-bambu-dark rounded-lg p-1`,children:[(0,K.jsx)(`button`,{onClick:()=>et(`grid`),className:`p-1.5 rounded transition-colors ${ne===`grid`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.gridView`),children:(0,K.jsx)(Pc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>et(`list`),className:`p-1.5 rounded transition-colors ${ne===`list`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.listView`),children:(0,K.jsx)(Bc,{className:`w-4 h-4`})})]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>Ue.mutate(),disabled:Ue.isPending||!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.generateThumbnailsForMissing`):e(`fileManager.noPermissionGenerateThumbnail`),children:[Ue.isPending?(0,K.jsx)(X,{className:`w-4 h-4 mr-2 animate-spin`}):(0,K.jsx)(Dc,{className:`w-4 h-4 mr-2`}),e(`fileManager.generateThumbnails`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>b(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?e(`fileManager.linkExternalFolder`):e(`fileManager.noPermissionCreateFolder`),children:[(0,K.jsx)(ac,{className:`w-4 h-4 mr-2`}),e(`fileManager.linkExternal`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>_(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionCreateFolder`),children:[(0,K.jsx)(ic,{className:`w-4 h-4 mr-2`}),e(`fileManager.newFolder`)]}),r(`library:purge`)&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>E(!0),title:e(`libraryPurge.headerTooltip`),children:[(0,K.jsx)(hu,{className:`w-4 h-4 mr-2`}),e(`libraryPurge.headerButton`)]}),i(`library:delete_own`,`library:delete_all`)&&(0,K.jsxs)(bi,{to:`/files/trash`,className:`inline-flex items-center px-3 py-1.5 text-sm rounded bg-bambu-dark-secondary text-bambu-gray hover:text-white hover:bg-bambu-dark transition-colors`,title:e(`libraryTrash.headerTooltip`),children:[(0,K.jsx)(hu,{className:`w-4 h-4 mr-2`}),e(`libraryTrash.headerButton`),typeof Te==`number`&&Te>0&&(0,K.jsx)(`span`,{className:`ml-1.5 px-1.5 py-0.5 text-xs rounded-full bg-bambu-green/20 text-bambu-green`,children:Te})]}),(0,K.jsxs)($,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,K.jsx)(Su,{className:`w-4 h-4 mr-2`}),e(`common.upload`)]})]})]}),Me&&Oe&&Se&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg`,children:[(0,K.jsx)(vu,{className:`w-5 h-5 text-amber-500 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-amber-500 font-medium`,children:e(`fileManager.lowDiskSpaceWarning`)}),(0,K.jsx)(`p`,{className:`text-xs text-amber-500/80`,children:e(`fileManager.lowDiskSpaceDetails`,{free:yd(Oe.disk_free_bytes),total:yd(Oe.disk_total_bytes),threshold:Se.library_disk_warning_gb})})]})]}),Oe&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 sm:gap-6 mb-6 p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(Qs,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.files`),`:`]}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:Oe.total_files})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(rc,{className:`w-4 h-4 text-blue-400`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.folders`),`:`]}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:Oe.total_folders})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(yc,{className:`w-4 h-4 text-amber-400`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.size`),`:`]}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:yd(Oe.total_size_bytes)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm sm:ml-auto`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.free`),`:`]}),(0,K.jsx)(`span`,{className:`font-medium ${Me?`text-amber-500`:`text-white`}`,children:yd(Oe.disk_free_bytes)})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0`,children:[(0,K.jsx)(`div`,{className:`lg:hidden`,children:(0,K.jsxs)(`select`,{value:u===null?`__top:${f}`:String(u),onChange:e=>{let t=e.target.value;t.startsWith(`__top:`)?(d(null),p(t.slice(6))):d(parseInt(t,10))},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg px-3 py-2.5 text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsxs)(`option`,{value:`__top:internal`,children:[`📁 `,e(`fileManager.allFiles`)]}),Ce?.some(e=>e.is_external)&&(0,K.jsxs)(`option`,{value:`__top:external`,children:[`🔗 `,e(`fileManager.allExternal`)]}),Ce&&(()=>{let e=(t,n=0)=>{let r=[];for(let i of t)r.push({id:i.id,name:i.name,fileCount:i.file_count,depth:n}),i.children.length>0&&r.push(...e(i.children,n+1));return r};return e(Ce).map(e=>(0,K.jsxs)(`option`,{value:e.id,children:[`│ `.repeat(e.depth),`📂 `,e.name,` `,e.fileCount>0?`(${e.fileCount})`:``]},e.id))})()]})}),(0,K.jsxs)(`div`,{ref:ue,className:`hidden lg:flex flex-shrink-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden flex-col relative`,style:{width:`${oe}px`},children:[(0,K.jsx)(`div`,{className:`absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group/resize flex items-center justify-center transition-colors ${ce?`bg-bambu-green`:`hover:bg-bambu-green/50`}`,onMouseDown:e=>{e.preventDefault(),le(!0)},onDoubleClick:()=>{se(256),localStorage.setItem(`library-sidebar-width`,`256`)},title:e(`fileManager.dragToResizeTooltip`),children:(0,K.jsxs)(`div`,{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${ce?`opacity-100`:``}`,children:[(0,K.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,K.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,K.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`})]})}),(0,K.jsxs)(`div`,{className:`p-3 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,K.jsx)(`h2`,{className:`text-sm font-medium text-white`,children:e(`fileManager.folders`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>{let e=!ae;W(e),localStorage.setItem(`library-collapse-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${ae?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(ae?`fileManager.expandFoldersByDefault`:`fileManager.collapseFoldersByDefault`),children:e(`fileManager.collapse`)}),(0,K.jsx)(`button`,{onClick:()=>{let e=!U;ie(e),localStorage.setItem(`library-wrap-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${U?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(U?`fileManager.disableTextWrapping`:`fileManager.enableTextWrapping`),children:e(`fileManager.wrap`)})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&f===`internal`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),p(`internal`)},children:[(0,K.jsx)(qs,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allFiles`)})]}),Ce?.some(e=>e.is_external)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&f===`external`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),p(`external`)},children:[(0,K.jsx)(ac,{className:`w-4 h-4 text-purple-400`}),(0,K.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allExternal`)})]}),Ce?.map(t=>(0,K.jsx)(P7,{folder:t,selectedFolderId:u,onSelect:d,onDelete:e=>A({type:`folder`,id:e}),onLink:O,onRename:e=>B({type:`folder`,id:e.id,name:e.name}),wrapNames:U,defaultExpanded:!ae,hasPermission:r,t:e},`${t.id}-${ae?`c`:`e`}`))]})]}),(0,K.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:[nt?.is_external&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg`,children:[(0,K.jsx)(ac,{className:`w-5 h-5 text-purple-400 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium text-purple-300`,children:e(`fileManager.externalFolder`)}),nt.external_readonly&&(0,K.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400 flex items-center gap-1`,children:[(0,K.jsx)(Hc,{className:`w-3 h-3`}),e(`fileManager.readOnly`)]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate font-mono`,title:nt.external_path||``,children:nt.external_path})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>u&&Fe.mutate(u),disabled:Fe.isPending,title:e(`fileManager.scanFolder`),children:[Fe.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`fileManager.scanFolder`)})]})]}),Ee&&Ee.length>0&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-4 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-0 z-10 lg:static`,children:[(0,K.jsxs)(`div`,{className:`relative w-full sm:w-auto sm:flex-1 sm:max-w-xs`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.searchFiles`),value:de,onChange:e=>fe(e.target.value),className:`w-full pl-9 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(lc,{className:`w-4 h-4 text-bambu-gray hidden sm:block`}),(0,K.jsxs)(`select`,{value:pe,onChange:e=>me(e.target.value),className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsx)(`option`,{value:`all`,children:e(`fileManager.allTypes`)}),Ae.map(e=>(0,K.jsx)(`option`,{value:e,children:e.toUpperCase()},e))]})]}),o&&(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.filterByUser`,{defaultValue:`Filter by user`}),value:he,onChange:e=>ge(e.target.value),list:`usernames-list`,className:`w-32 sm:w-40 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green ${he?`pr-7`:``}`,style:he?{WebkitAppearance:`none`,MozAppearance:`textfield`}:void 0}),he&&(0,K.jsx)(`button`,{onClick:()=>ge(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10`,children:(0,K.jsx)(Pu,{className:`w-3 h-3`})}),(0,K.jsx)(`datalist`,{id:`usernames-list`,children:ke?.map(e=>(0,K.jsx)(`option`,{value:e.username},e.id))})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`select`,{value:_e,onChange:e=>{let t=e.target.value;ve(t),localStorage.setItem(`library-sort-field`,t)},className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsx)(`option`,{value:`name`,children:e(`common.name`)}),(0,K.jsx)(`option`,{value:`date`,children:e(`common.date`)}),(0,K.jsx)(`option`,{value:`size`,children:e(`fileManager.size`)}),(0,K.jsx)(`option`,{value:`type`,children:e(`common.type`)}),(0,K.jsx)(`option`,{value:`prints`,children:e(`fileManager.prints`)})]}),(0,K.jsx)(`button`,{onClick:()=>be(e=>{let t=e===`asc`?`desc`:`asc`;return localStorage.setItem(`library-sort-direction`,t),t}),className:`p-1.5 rounded bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,title:e(ye===`asc`?`fileManager.ascending`:`fileManager.descending`),children:ye===`asc`?(0,K.jsx)(jo,{className:`w-4 h-4 text-white`}):(0,K.jsx)(To,{className:`w-4 h-4 text-white`})})]}),(de||pe!==`all`||he)&&(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray hidden sm:inline`,children:e(`fileManager.resultsCount`,{showing:je.length,total:Ee.length})})]}),je.length>0&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 p-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-[52px] z-10 lg:static`,children:[m.length===je.length&&m.length>0?(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:Ye,children:[(0,K.jsx)(tu,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.deselectAll`)})]}):(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:Je,children:[(0,K.jsx)($l,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.selectAll`)})]}),m.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:e(`fileManager.selected`,{count:m.length})}),(0,K.jsx)(`div`,{className:`hidden sm:block flex-1`}),(0,K.jsxs)(`div`,{className:`w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0`,children:[Ke.length===1&&(0,K.jsxs)($,{variant:`primary`,size:`sm`,onClick:()=>P(Ke[0]),disabled:!r(`printers:control`),title:r(`printers:control`)?void 0:e(`fileManager.noPermissionPrint`),children:[(0,K.jsx)(hl,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.print`)})]}),Ke.length===1&&(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>I(Ke[0]),disabled:!r(`queue:create`),title:r(`queue:create`)?void 0:e(`fileManager.noPermissionAddToQueue`),children:[(0,K.jsx)(_s,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.schedulePrint`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>S(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?void 0:e(`fileManager.noPermissionMoveFiles`),children:[(0,K.jsx)(rl,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.move`)})]}),(0,K.jsxs)($,{variant:`danger`,size:`sm`,onClick:()=>{m.length===1?A({type:`file`,id:m[0]}):A({type:`bulk`,id:0,count:m.length})},disabled:!i(`library:delete_own`,`library:delete_all`),title:i(`library:delete_own`,`library:delete_all`)?void 0:e(`fileManager.noPermissionDeleteFiles`),children:[(0,K.jsx)(hu,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.delete`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:Ye,children:[(0,K.jsx)(Pu,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.clear`)})]})]})]})]}),tt?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`fileManager.loadingFiles`)})]})}):Ee?.length===0?(0,K.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,K.jsx)(qs,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,K.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(u===null?f===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`:`fileManager.folderIsEmpty`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(u===null?f===`external`?`fileManager.externalEmptyDescription`:`fileManager.noFilesDescription`:`fileManager.folderEmptyDescription`)}),(0,K.jsxs)($,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,K.jsx)(_l,{className:`w-4 h-4 mr-2`}),e(`fileManager.uploadFiles`)]})]}):je.length===0?(0,K.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,K.jsx)(Nl,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,K.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(`fileManager.noMatchingFiles`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(`fileManager.noMatchingFilesDescription`)}),(0,K.jsx)($,{variant:`secondary`,onClick:()=>{fe(``),me(`all`)},children:e(`fileManager.clearFilters`)})]}):ne===`grid`?(0,K.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,K.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4`,children:je.map(t=>(0,K.jsx)(MBe,{file:t,isSelected:m.includes(t.id),isMobile:xe,t:e,onSelect:qe,onDelete:e=>A({type:`file`,id:e}),onDownload:Ze,onAddToQueue:e=>{let t=Ee?.find(t=>t.id===e);t&&I(t)},onPrint:M,onSlice:R,useSlicerApi:Se?.use_slicer_api??!1,onPreview3d:e=>{F7(e.filename)?c(`/gcode-viewer?library_file=${e.id}`):te(e)},onRename:e=>B({type:`file`,id:e.id,name:e.filename}),onGenerateThumbnail:e=>We.mutate(e.id),thumbnailVersion:V[t.id],hasPermission:r,canModify:a,authEnabled:o},t.id))})}):(0,K.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto`,children:[(0,K.jsxs)(`div`,{className:`hidden sm:grid ${o?`grid-cols-[auto_1fr_120px_100px_100px_100px_min-content]`:`grid-cols-[auto_1fr_100px_100px_100px_min-content]`} gap-4 px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary text-xs text-bambu-gray font-medium`,children:[(0,K.jsx)(`div`,{className:`w-6`}),(0,K.jsx)(`div`,{children:e(`common.name`)}),o&&(0,K.jsx)(`div`,{children:e(`fileManager.uploadedBy`,{defaultValue:`Uploaded By`})}),(0,K.jsx)(`div`,{children:e(`common.type`)}),(0,K.jsx)(`div`,{children:e(`fileManager.size`)}),(0,K.jsx)(`div`,{children:e(`fileManager.prints`)}),(0,K.jsx)(`div`,{})]}),je.map(t=>(0,K.jsxs)(`div`,{className:`grid ${o?`grid-cols-[auto_1fr_120px_100px_100px_100px_min-content]`:`grid-cols-[auto_1fr_100px_100px_100px_min-content]`} gap-4 px-4 py-3 items-center border-b border-bambu-dark-tertiary last:border-b-0 cursor-pointer hover:bg-bambu-dark/50 transition-colors ${m.includes(t.id)?`bg-bambu-green/10`:``}`,onClick:()=>qe(t.id),children:[(0,K.jsx)(`div`,{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${m.includes(t.id)?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:m.includes(t.id)&&(0,K.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`relative group/thumb`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden`,children:t.thumbnail_path?(0,K.jsx)(`img`,{src:`${Q.getLibraryFileThumbnailUrl(t.id)}${V[t.id]?(Q.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${V[t.id]}`:``}`,alt:``,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,K.jsx)(qs,{className:`w-5 h-5 text-bambu-gray/50`})})}),t.thumbnail_path&&(0,K.jsx)(`div`,{className:`absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block`,children:(0,K.jsx)(`div`,{className:`w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden`,children:(0,K.jsx)(`img`,{src:`${Q.getLibraryFileThumbnailUrl(t.id)}${V[t.id]?(Q.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${V[t.id]}`:``}`,alt:t.filename,className:`w-full h-full object-contain`})})})]}),(0,K.jsx)(`div`,{className:`min-w-0`,children:(0,K.jsx)(`div`,{className:`text-sm text-white truncate`,children:t.print_name||t.filename})})]}),o&&(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-1`,children:t.created_by_username?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Cu,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{className:`truncate`,children:t.created_by_username})]}):`-`}),(0,K.jsx)(`div`,{children:(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${t.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:t.file_type===`gcode`||t.file_type===`gcode.3mf`?`bg-blue-500/20 text-blue-400`:t.file_type===`stl`?`bg-purple-500/20 text-purple-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.file_type.toUpperCase()})}),(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:yd(t.file_size)}),(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:t.print_count>0?`${t.print_count}x`:`-`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[F7(t.filename)&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:()=>r(`printers:control`)&&M(t),className:`p-1.5 rounded transition-colors ${r(`printers:control`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`printers:control`)?e(`common.print`):e(`fileManager.noPermissionPrint`),disabled:!r(`printers:control`),children:(0,K.jsx)(bl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{r(`queue:create`)&&I(t)},className:`p-1.5 rounded transition-colors ${r(`queue:create`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`queue:create`)?e(`fileManager.schedulePrint`):e(`fileManager.noPermissionAddToQueue`),disabled:!r(`queue:create`),children:(0,K.jsx)(_s,{className:`w-4 h-4`})})]}),(Se?.use_slicer_api??!1)&&I7(t.filename)&&(0,K.jsx)(`button`,{onClick:()=>r(`library:upload`)&&R(t),className:`p-1.5 rounded transition-colors ${r(`library:upload`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:upload`)?e(`slice.action`):e(`fileManager.noPermissionSlice`),disabled:!r(`library:upload`),children:(0,K.jsx)(ws,{className:`w-4 h-4`})}),(t.file_type===`3mf`||t.file_type===`gcode`||t.file_type===`gcode.3mf`||t.file_type===`stl`)&&(0,K.jsx)(`button`,{onClick:()=>{r(`library:read`)&&(F7(t.filename)?c(`/gcode-viewer?library_file=${t.id}`):te(t))},className:`p-1.5 rounded transition-colors ${r(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:read`)?`3D Preview`:`You do not have permission to preview files`,disabled:!r(`library:read`),children:(0,K.jsx)(Bo,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>r(`library:read`)&&Ze(t.id),className:`p-1.5 rounded transition-colors ${r(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:read`)?e(`common.download`):e(`fileManager.noPermissionDownload`),disabled:!r(`library:read`),children:(0,K.jsx)(Is,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&B({type:`file`,id:t.id,name:t.filename}),className:`p-1.5 rounded transition-colors ${a(`library`,`update`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`update`,t.created_by_id)?e(`common.rename`):e(`fileManager.noPermissionRenameFile`),disabled:!a(`library`,`update`,t.created_by_id),children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),t.file_type===`stl`&&(0,K.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&We.mutate(t.id),className:`p-1.5 rounded transition-colors ${a(`library`,`update`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`update`,t.created_by_id)?e(`fileManager.generateThumbnail`):e(`fileManager.noPermissionGenerateThumbnail`),disabled:We.isPending||!a(`library`,`update`,t.created_by_id),children:(0,K.jsx)(Dc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(`library`,`delete`,t.created_by_id)&&A({type:`file`,id:t.id}),className:`p-1.5 rounded transition-colors ${a(`library`,`delete`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`delete`,t.created_by_id)?e(`common.delete`):e(`fileManager.noPermissionDeleteFile`),disabled:!a(`library`,`delete`,t.created_by_id),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})]},t.id))]})})]})]}),g&&(0,K.jsx)(TBe,{parentId:u,onClose:()=>_(!1),onSave:e=>Ne.mutate(e),isLoading:Ne.isPending,t:e}),v&&(0,K.jsx)(EBe,{onClose:()=>b(!1),onSave:e=>Pe.mutate(e),isLoading:Pe.isPending,t:e}),x&&Ce&&(0,K.jsx)(ABe,{folders:Ce,selectedFiles:m,currentFolderId:u,onClose:()=>S(!1),onMove:e=>ze.mutate({fileIds:m,folderId:e}),isLoading:ze.isPending,t:e}),C&&(0,K.jsx)(kK,{folderId:u,onClose:()=>w(!1),onUploadComplete:Xe}),T&&(0,K.jsx)(wBe,{onClose:()=>E(!1)}),D&&(0,K.jsx)(jBe,{folder:D,onClose:()=>O(null),onLink:e=>Be.mutate({id:D.id,data:e}),isLoading:Be.isPending,t:e}),k&&(0,K.jsx)(Ed,{title:k.type===`folder`?e(`fileManager.deleteFolder`):k.type===`bulk`?e(`fileManager.deleteFilesCount`,{count:k.count}):e(`fileManager.deleteFile`),message:k.type===`folder`?e(`fileManager.deleteFolderConfirm`):k.type===`bulk`?e(`fileManager.deleteFilesConfirm`,{count:k.count}):e(`fileManager.deleteFileConfirm`),confirmText:e(`common.delete`),variant:`danger`,isLoading:$e,loadingText:e(`fileManager.deleting`),onConfirm:Qe,onCancel:()=>A(null)}),j&&(0,K.jsx)(sq,{mode:`reprint`,libraryFileId:j.id,archiveName:j.print_name||j.filename,onClose:()=>M(null),onSuccess:()=>{M(null),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`archives`]})}}),N&&(0,K.jsx)(sq,{mode:`reprint`,libraryFileId:N.id,archiveName:N.print_name||N.filename,onClose:()=>P(null),onSuccess:()=>{P(null),h([]),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`archives`]})}}),F&&(0,K.jsx)(sq,{mode:`add-to-queue`,libraryFileId:F.id,archiveName:F.print_name||F.filename,onClose:()=>I(null),onSuccess:()=>{I(null),h([]),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`archives`]})}}),L&&(0,K.jsx)(Bq,{source:{kind:`libraryFile`,id:L.id,filename:L.filename},onClose:()=>R(null)}),H&&(0,K.jsx)(SBe,{libraryFileId:H.id,title:H.print_name||H.filename,fileType:H.file_type,onClose:()=>te(null),onSliceWithBambuddy:I7(H.filename)&&r(`library:upload`)?()=>{let e=H;te(null),R(e)}:void 0}),z&&(0,K.jsx)(kBe,{type:z.type,currentName:z.name,onClose:()=>B(null),onSave:e=>{z.type===`file`?Ve.mutate({id:z.id,filename:e}):He.mutate({id:z.id,name:e})},isLoading:Ve.isPending||He.isPending,t:e})]})}function PBe(e){let t=mf(e);if(!t)return``;let n=Math.ceil((t.getTime()-Date.now())/(1e3*60*60*24));return n<=0?`any moment`:n===1?`1 day`:`${n} days`}function L7(e){let t=mf(e);return t?t.toLocaleString():e}function FBe(){let{t:e}=G(),t=Yn(),n=Qa(),{showToast:r}=xd(),{hasPermission:i,authEnabled:a}=sd(),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(new Set),u=!a||i(`library:purge`),d=q({queryKey:[`library-trash`],queryFn:()=>Q.listLibraryTrash(200,0)}),f=q({queryKey:[`library-trash-settings`],queryFn:()=>Q.getLibraryTrashSettings(),enabled:u}),[p,m]=(0,y.useState)(null);(0,y.useEffect)(()=>{f.data&&p===null&&m(f.data.retention_days)},[f.data,p]);let h=J({mutationFn:e=>{let t=f.data;return Q.updateLibraryTrashSettings({retention_days:e,auto_purge_enabled:t?.auto_purge_enabled??!1,auto_purge_days:t?.auto_purge_days??90,auto_purge_include_never_printed:t?.auto_purge_include_never_printed??!0})},onSuccess:t=>{r(e(`libraryTrash.toast.retentionSaved`,{days:t.retention_days}),`success`),n.invalidateQueries({queryKey:[`library-trash-settings`]}),n.invalidateQueries({queryKey:[`library-trash`]})},onError:t=>r(t.message||e(`libraryTrash.toast.retentionFailed`),`error`)}),g=J({mutationFn:e=>Q.restoreLibraryTrash(e),onSuccess:()=>{r(e(`libraryTrash.toast.restored`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>r(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),_=J({mutationFn:e=>Q.hardDeleteLibraryTrash(e),onSuccess:()=>{r(e(`libraryTrash.toast.purged`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),v=J({mutationFn:()=>Q.emptyLibraryTrash(),onSuccess:t=>{r(e(`libraryTrash.toast.emptied`,{count:t.deleted}),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.emptyFailed`),`error`)}),b=J({mutationFn:e=>Promise.all(e.map(e=>Q.restoreLibraryTrash(e))),onSuccess:(t,i)=>{r(e(`libraryTrash.toast.bulkRestored`,{count:i.length}),`success`),l(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>r(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),x=J({mutationFn:e=>Promise.all(e.map(e=>Q.hardDeleteLibraryTrash(e))),onSuccess:(t,i)=>{r(e(`libraryTrash.toast.bulkPurged`,{count:i.length}),`success`),l(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),S=(0,y.useMemo)(()=>d.data?.items??[],[d.data?.items]),C=d.data?.retention_days??30,w=(0,y.useMemo)(()=>S.reduce((e,t)=>e+t.file_size,0),[S]),T=S.length>0&&S.every(e=>c.has(e.id)),E=c.size>0&&!T,D=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,K.jsxs)(`div`,{className:`p-6 max-w-screen-2xl mx-auto`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-3 mb-4`,children:(0,K.jsxs)(bi,{to:`/files`,className:`inline-flex items-center gap-1 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200`,children:[(0,K.jsx)(Do,{className:`w-4 h-4`}),` `,e(`libraryTrash.backToFiles`)]})}),(0,K.jsxs)(`div`,{className:`flex items-start justify-between mb-6 gap-4 flex-wrap`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-gray-100`,children:e(`libraryTrash.title`)}),(0,K.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(u?`libraryTrash.subtitleAdmin`:`libraryTrash.subtitleUser`,{days:C})})]}),S.length>0&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>s({type:`empty`}),className:`text-red-600 dark:text-red-400`,children:[(0,K.jsx)(hu,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.emptyTrash`)]})]}),u&&f.data&&(0,K.jsxs)(`div`,{className:`mb-4 border border-gray-200 dark:border-gray-700 rounded-lg p-3 flex items-center gap-3 bg-gray-50 dark:bg-gray-800/40`,children:[(0,K.jsx)(`label`,{htmlFor:`retention-days`,className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e(`libraryTrash.retentionLabel`)}),(0,K.jsx)(`input`,{id:`retention-days`,type:`number`,min:1,max:365,value:p??f.data.retention_days,onChange:e=>m(Math.max(1,Math.min(365,parseInt(e.target.value||`0`,10)||0))),className:`w-20 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:e(`libraryTrash.days`)}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>p!=null&&h.mutate(p),disabled:h.isPending||p==null||p===f.data.retention_days,className:`ml-auto`,children:[(0,K.jsx)(Ol,{className:`w-4 h-4 mr-1`}),e(`common.save`)]})]}),d.isLoading?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),` `,e(`libraryTrash.loading`)]}):S.length===0?(0,K.jsx)(`div`,{className:`border border-dashed border-gray-300 dark:border-gray-700 rounded-lg p-12 text-center`,children:(0,K.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.empty`)})}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.summary`,{count:S.length,size:yd(w)})}),c.size>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.selectionCount`,{count:c.size})}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>b.mutate(Array.from(c)),disabled:b.isPending,children:[(0,K.jsx)(Tl,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkRestore`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>s({type:`bulkDelete`,count:c.size}),disabled:x.isPending,className:`text-red-600 dark:text-red-400`,children:[(0,K.jsx)(hu,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkPurge`)]})]})]}),(0,K.jsx)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-800 text-left text-gray-600 dark:text-gray-300`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`px-3 py-2 w-10`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:T,ref:e=>{e&&(e.indeterminate=E)},onChange:()=>{l(e=>e.size===S.length?new Set:new Set(S.map(e=>e.id)))},"aria-label":e(`libraryTrash.selectAll`),className:`rounded border-gray-300 cursor-pointer`})}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.filename`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.folder`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.size`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.deleted`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.autoPurge`)}),u&&(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.owner`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.actions`)})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-gray-800`,children:S.map(t=>(0,K.jsxs)(`tr`,{className:`hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:c.has(t.id),onChange:()=>D(t.id),"aria-label":e(`libraryTrash.selectOne`,{filename:t.filename}),className:`rounded border-gray-300 cursor-pointer`})}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-gray-900 dark:text-gray-100 truncate max-w-md`,title:t.filename,children:t.filename}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.folder_name??`—`}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-right text-gray-600 dark:text-gray-400 tabular-nums whitespace-nowrap`,children:yd(t.file_size)}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:L7(t.deleted_at)}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:(0,K.jsx)(`span`,{title:L7(t.auto_purge_at),children:e(`libraryTrash.autoPurgeIn`,{when:PBe(t.auto_purge_at)})})}),u&&(0,K.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.created_by_username??`—`}),(0,K.jsxs)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap`,children:[(0,K.jsxs)(`button`,{onClick:()=>g.mutate(t.id),disabled:g.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300`,children:[(0,K.jsx)(Tl,{className:`w-3.5 h-3.5`}),e(`libraryTrash.restore`)]}),(0,K.jsxs)(`button`,{onClick:()=>s({type:`delete`,id:t.id,filename:t.filename}),disabled:_.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300 ml-2`,children:[(0,K.jsx)(hu,{className:`w-3.5 h-3.5`}),e(`libraryTrash.purgeNow`)]})]})]},t.id))})]})})]}),o&&(0,K.jsx)(Ed,{onCancel:()=>s(null),onConfirm:()=>{o&&(o.type===`delete`?_.mutate(o.id):o.type===`bulkDelete`?x.mutate(Array.from(c)):v.mutate(),s(null))},title:o.type===`delete`?e(`libraryTrash.confirm.purgeTitle`):o.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeTitle`):e(`libraryTrash.confirm.emptyTitle`),message:o.type===`delete`?e(`libraryTrash.confirm.purgeBody`,{filename:o.filename}):o.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeBody`,{count:o.count}):e(`libraryTrash.confirm.emptyBody`,{count:S.length}),confirmText:e(`libraryTrash.confirm.cta`),variant:`danger`}),d.isError&&(0,K.jsxs)(`div`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:[d.error?.message??e(`libraryTrash.loadError`),(0,K.jsx)($,{variant:`secondary`,onClick:()=>t(`/files`),className:`ml-3`,children:e(`libraryTrash.backToFiles`)})]})]})}function IBe(e,t){let n=`token=${encodeURIComponent(t)}`,r=0;return e.querySelectorAll(`img[src*="/api/v1/"], video[src*="/api/v1/"]`).forEach(e=>{let t=e.getAttribute(`src`)||``;if(t.includes(n))return;let i=t.replace(/([?&])token=[^&]*(&|$)/,(e,t,n)=>n===`&`?t:``);e.src=`${i}${i.includes(`?`)?`&`:`?`}${n}`,r+=1}),r}function R7(){let{authEnabled:e,user:t,loading:n}=sd(),r=Qa(),i=(0,y.useRef)(!1),{data:a}=q({queryKey:[`camera-stream-token`,t?.id??null],queryFn:()=>Q.getCameraStreamToken(),enabled:!n&&(!e||t!==null),staleTime:3e3*1e3,refetchInterval:3e3*1e3});(0,y.useEffect)(()=>{let e=a?.token??null;return Wu(e),e&&IBe(document,e),()=>Wu(null)},[a?.token]),(0,y.useEffect)(()=>{if(!e)return;let t=e=>{let t=e.target;if(!(t instanceof HTMLImageElement||t instanceof HTMLVideoElement))return;let n=t.src||``,a=Gu();!a||!n.includes(`token=${encodeURIComponent(a)}`)||i.current||(i.current=!0,r.invalidateQueries({queryKey:[`camera-stream-token`]}),setTimeout(()=>{i.current=!1},5e3))};return document.addEventListener(`error`,t,!0),()=>document.removeEventListener(`error`,t,!0)},[e,r])}var z7=5,LBe=2e3,RBe=3e4,zBe=5e3;function BBe(){let{t:e}=G(),t=Qa(),{showToast:n}=xd(),{hasPermission:r,authEnabled:i,user:a}=sd(),{printerId:o}=er(),s=parseInt(o||`0`,10),[c]=Oi(),l=parseInt(c.get(`fps`)||`15`,10),u=Math.min(Math.max(isNaN(l)?15:l,1),30);R7();let{data:d}=q({queryKey:[`camera-stream-token`,a?.id??null],queryFn:()=>Q.getCameraStreamToken(),enabled:i?!!a:!0,staleTime:3e3*1e3}),f=d?.token??Gu(),[p,m]=(0,y.useState)(`stream`),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!0),[w,T]=(0,y.useState)(Date.now()),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(0),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(0),[I,L]=(0,y.useState)(1),[R,z]=(0,y.useState)({x:0,y:0}),[B,V]=(0,y.useState)(!1),[ee,H]=(0,y.useState)({x:0,y:0}),[te,ne]=(0,y.useState)(null),[re,U]=(0,y.useState)(null),ie=(0,y.useRef)(null),ae=(0,y.useRef)(null),W=(0,y.useRef)(null),oe=(0,y.useRef)(null),se=(0,y.useRef)(null),{data:ce}=q({queryKey:[`printer`,s],queryFn:()=>Q.getPrinter(s),enabled:s>0}),{data:le}=q({queryKey:[`printerStatus`,s],queryFn:()=>Q.getPrinterStatus(s),refetchInterval:3e4,enabled:s>0}),ue=J({mutationFn:e=>Q.setChamberLight(s,e),onMutate:async e=>{await t.cancelQueries({queryKey:[`printerStatus`,s]});let n=t.getQueryData([`printerStatus`,s]);return t.setQueryData([`printerStatus`,s],t=>({...t,chamber_light:e})),{previousStatus:n}},onSuccess:(e,t)=>{n(`Chamber light ${t?`on`:`off`}`)},onError:(r,i,a)=>{a?.previousStatus&&t.setQueryData([`printerStatus`,s],a.previousStatus),n(r.message||e(`printers.toast.failedToControlChamberLight`),`error`)}}),de=(le?.state===`RUNNING`||le?.state===`PAUSE`)&&(le?.printable_objects_count??0)>=2;(0,y.useEffect)(()=>(ce&&(document.title=`${ce.name} - Camera`),()=>{document.title=`Bambuddy`}),[ce]);let fe=(0,y.useRef)(!1);(0,y.useEffect)(()=>{let e=`/api/v1/printers/${s}/camera/stop`;fe.current=!1;let t=()=>{if(s>0&&!fe.current){fe.current=!0;let t={},n=Hu();n&&(t.Authorization=`Bearer ${n}`),fetch(e,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},n=()=>{t()};window.addEventListener(`beforeunload`,n);let r=ie.current;return()=>{window.removeEventListener(`beforeunload`,n),r&&(r.src=``),t()}},[s]),(0,y.useEffect)(()=>{if(S&&!E){let e=setTimeout(()=>{C(!1)},p===`stream`?3e3:2e4);return()=>clearTimeout(e)}},[p,S,w,E]),(0,y.useEffect)(()=>{let e=()=>{k(!!document.fullscreenElement),L(1),z({x:0,y:0}),p===`stream`&&!E&&(ie.current&&(ie.current.src=``),setTimeout(()=>{C(!0),T(Date.now())},200))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[p,E]),(0,y.useEffect)(()=>{let e,t=()=>{clearTimeout(e),e=setTimeout(()=>{localStorage.setItem(`cameraWindowState`,JSON.stringify({width:window.outerWidth,height:window.outerHeight,left:window.screenX,top:window.screenY}))},500)};return window.addEventListener(`resize`,t),()=>{clearTimeout(e),window.removeEventListener(`resize`,t)}},[]),(0,y.useEffect)(()=>()=>{W.current&&clearTimeout(W.current),oe.current&&clearInterval(oe.current),se.current&&clearInterval(se.current)},[]);let pe=(0,y.useCallback)(()=>{if(A>=z7){N(!1),x(!0);return}let e=Math.min(LBe*2**A,RBe);N(!0),F(Math.ceil(e/1e3)),oe.current=setInterval(()=>{F(e=>e<=1?(oe.current&&clearInterval(oe.current),0):e-1)},1e3),W.current=setTimeout(()=>{j(e=>e+1),N(!1),C(!0),x(!1),ie.current&&(ie.current.src=``),T(Date.now())},e)},[A]);(0,y.useEffect)(()=>{if(p!==`stream`||S||M||E){se.current&&=(clearInterval(se.current),null);return}return se.current=setInterval(async()=>{try{let e=await Q.getCameraStatus(s);(e.stalled||!e.active&&!b)&&(console.log(`Stream issue detected: stalled=${e.stalled}, active=${e.active}, reconnecting...`),se.current&&=(clearInterval(se.current),null),C(!1),pe())}catch{}},zBe),()=>{se.current&&=(clearInterval(se.current),null)}},[p,S,b,M,E,s,pe]);let me=()=>{C(!1),p===`stream`&&A{if(C(!1),x(!1),j(0),N(!1),W.current&&clearTimeout(W.current),oe.current&&clearInterval(oe.current),ie.current&&!localStorage.getItem(`cameraWindowState`)){let e=ie.current,t=e.naturalWidth,n=e.naturalHeight;if(t>0&&n>0){let e=window.outerWidth-window.innerWidth,r=window.outerHeight-window.innerHeight,i=t+16+e,a=n+45+16+r;try{window.resizeTo(i,a)}catch{}}}},ge=()=>{if(s>0){let e={},t=Hu();t&&(e.Authorization=`Bearer ${t}`),fetch(`/api/v1/printers/${s}/camera/stop`,{method:`POST`,headers:e}).catch(()=>{})}},_e=e=>{p===e||E||(D(!0),C(!0),x(!1),j(0),N(!1),L(1),z({x:0,y:0}),W.current&&clearTimeout(W.current),oe.current&&clearInterval(oe.current),ie.current&&(ie.current.src=``),p===`stream`&&ge(),setTimeout(()=>{m(e),T(Date.now()),D(!1)},100))},ve=()=>{E||(D(!0),C(!0),x(!1),j(0),N(!1),W.current&&clearTimeout(W.current),oe.current&&clearInterval(oe.current),ie.current&&(ie.current.src=``),p===`stream`&&ge(),setTimeout(()=>{T(Date.now()),D(!1)},100))},ye=()=>{ae.current&&(document.fullscreenElement?document.exitFullscreen():ae.current.requestFullscreen())},be=()=>{L(e=>Math.min(e+.5,4))},xe=()=>{L(e=>{let t=Math.max(e-.5,1);return t===1&&z({x:0,y:0}),t})},Se=e=>{e.preventDefault(),e.deltaY<0?be():xe()},Ce=e=>{I>1&&(e.preventDefault(),V(!0),H({x:e.clientX-R.x,y:e.clientY-R.y}))},we=(0,y.useCallback)(()=>{if(!ae.current)return{x:300,y:200};let e=ae.current.getBoundingClientRect(),t=e.width*(I-1)/2,n=e.height*(I-1)/2;return{x:Math.max(50,t),y:Math.max(50,n)}},[I]),Te=e=>{if(B&&I>1){let t=e.clientX-ee.x,n=e.clientY-ee.y,r=we();z({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Ee=()=>{V(!1)},De=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)},Oe=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},ke=e=>{e.touches.length===2?(e.preventDefault(),ne(De(e.touches)),U(Oe(e.touches))):e.touches.length===1&&I>1&&(e.preventDefault(),V(!0),H({x:e.touches[0].clientX-R.x,y:e.touches[0].clientY-R.y}))},Ae=e=>{if(e.touches.length===2&&te!==null){e.preventDefault();let t=De(e.touches),n=t/te;L(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&z({x:0,y:0}),t}),ne(t);let r=Oe(e.touches);if(re){let e=we();z(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-re.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-re.y)))}))}U(r)}else if(e.touches.length===1&&B&&I>1){e.preventDefault();let t=e.touches[0].clientX-ee.x,n=e.touches[0].clientY-ee.y,r=we();z({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},je=e=>{e.touches.length<2&&(ne(null),U(null)),e.touches.length===0&&V(!1)},Me=()=>{L(1),z({x:0,y:0})},Ne=E||i&&!f?``:(e=>f?`${e}&token=${encodeURIComponent(f)}`:Ku(e))(p===`stream`?`/api/v1/printers/${s}/camera/stream?fps=${u}&t=${w}`:`/api/v1/printers/${s}/camera/snapshot?t=${w}`),Pe=S||E||M;return s?(0,K.jsxs)(`div`,{ref:ae,className:`min-h-screen bg-black flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h1`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,K.jsx)(Jo,{className:`w-4 h-4`}),ce?.name||`Printer ${s}`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex bg-bambu-dark rounded p-0.5`,children:[(0,K.jsx)(`button`,{onClick:()=>_e(`stream`),disabled:Pe,className:`px-3 py-1 text-xs rounded transition-colors ${p===`stream`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.live`)}),(0,K.jsx)(`button`,{onClick:()=>_e(`snapshot`),disabled:Pe,className:`px-3 py-1 text-xs rounded transition-colors ${p===`snapshot`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.snapshot`)})]}),(0,K.jsx)(`button`,{onClick:()=>ue.mutate(!le?.chamber_light),disabled:!le?.connected||ue.isPending||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${le?.chamber_light?`bg-yellow-500/20 hover:bg-yellow-500/30`:`hover:bg-bambu-dark-tertiary`}`,title:r(`printers:control`)?e(`camera.chamberLight`):e(`printers.permission.noControl`),children:(0,K.jsx)(OT,{on:le?.chamber_light??!1,className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>g(!0),disabled:!de||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${de&&r(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:r(`printers:control`)?e(de?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):e(`printers.permission.noControl`),children:(0,K.jsx)(kT,{className:`w-4 h-4 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:ve,disabled:Pe,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:e(p===`stream`?`camera.restartStream`:`camera.refreshSnapshot`),children:(0,K.jsx)(Cl,{className:`w-4 h-4 text-bambu-gray ${Pe?`animate-spin`:``}`})}),(0,K.jsx)(`button`,{onClick:()=>v(!0),className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(`camera.diagnose.button`),children:(0,K.jsx)(ru,{className:`w-4 h-4 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:ye,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(O?`camera.exitFullscreen`:`camera.fullscreen`),children:O?(0,K.jsx)($c,{className:`w-4 h-4 text-bambu-gray`}):(0,K.jsx)(Yc,{className:`w-4 h-4 text-bambu-gray`})})]})]}),(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-2 overflow-hidden`,onWheel:Se,onMouseMove:Te,onMouseUp:Ee,onMouseLeave:Ee,onTouchStart:ke,onTouchMove:Ae,onTouchEnd:je,style:{touchAction:`none`},children:(0,K.jsxs)(`div`,{className:`relative w-full h-full flex items-center justify-center`,children:[(S||E)&&!M&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(Cl,{className:`w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(p===`stream`?`camera.connectingToCamera`:`camera.capturingSnapshot`)})]})}),M&&(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-4`,children:[(0,K.jsx)(Au,{className:`w-10 h-10 text-orange-400 mx-auto mb-3`}),(0,K.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.connectionLost`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:e(`camera.reconnecting`,{countdown:P,attempt:Math.min(A+1,z7),max:z7})}),(0,K.jsx)(`button`,{onClick:ve,className:`px-4 py-2 bg-bambu-green text-white text-sm rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.reconnectNow`)})]})}),b&&!M&&(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-4`,children:[(0,K.jsx)(vu,{className:`w-12 h-12 text-orange-400 mx-auto mb-3`}),(0,K.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.cameraUnavailable`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 max-w-md`,children:e(`camera.cameraUnavailableDesc`)}),(0,K.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,K.jsx)(`button`,{onClick:ve,className:`px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.retry`)}),(0,K.jsx)(`button`,{onClick:()=>v(!0),className:`px-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white rounded transition-colors`,children:e(`camera.diagnose.button`)})]})]})}),(0,K.jsx)(`img`,{ref:ie,src:Ne,alt:e(`camera.cameraStream`),className:`max-w-full max-h-full object-contain select-none`,style:{transform:`scale(${I}) translate(${R.x/I}px, ${R.y/I}px) rotate(${ce?.camera_rotation||0}deg)`,...ce?.camera_rotation===90||ce?.camera_rotation===270?{maxWidth:`100vh`,maxHeight:`100vw`}:{},cursor:I>1?B?`grabbing`:`grab`:`default`},onError:Ne?me:void 0,onLoad:Ne?he:void 0,onMouseDown:Ce,draggable:!1},w),(0,K.jsxs)(`div`,{className:`absolute bottom-4 left-4 flex items-center gap-1.5 bg-black/60 rounded-lg px-2 py-1.5`,children:[(0,K.jsx)(`button`,{onClick:xe,disabled:I<=1,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomOut`),children:(0,K.jsx)(Lu,{className:`w-4 h-4 text-white`})}),(0,K.jsxs)(`button`,{onClick:Me,className:`px-2 py-1 text-sm text-white hover:bg-white/10 rounded min-w-[48px]`,title:e(`camera.resetZoom`),children:[Math.round(I*100),`%`]}),(0,K.jsx)(`button`,{onClick:be,disabled:I>=4,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomIn`),children:(0,K.jsx)(Fu,{className:`w-4 h-4 text-white`})})]})]})}),(0,K.jsx)(AT,{printerId:s,isOpen:h,onClose:()=>g(!1)}),_&&(0,K.jsx)(jT,{printerId:s,printerName:ce?.name||null,onClose:()=>v(!1)})]}):(0,K.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,K.jsx)(`p`,{className:`text-white`,children:e(`camera.invalidPrinterId`)})})}function VBe(e,t,n){if(!e)return``;if(!t)return e;let r=t.match(/plate_(\d+)\.gcode/);return r&&parseInt(r[1],10)>1?`${e} — ${n(`printers.plateNumber`,`Plate {{number}}`,{number:r[1]})}`:e}function HBe(e){let t=e.get(`show`)?.split(`,`)||[`progress`,`layers`,`eta`,`filename`,`status`],n=parseInt(e.get(`fps`)||`15`,10),r=Math.min(Math.max(isNaN(n)?15:n,1),30),i=e.get(`camera`),a=i!==`false`&&i!==`0`;return{size:e.get(`size`)||`medium`,fps:r,showCamera:a,showProgress:t.includes(`progress`),showLayers:t.includes(`layers`),showEta:t.includes(`eta`),showFilename:t.includes(`filename`),showStatus:t.includes(`status`),showPrinter:t.includes(`printer`)}}function UBe(e,t){if(e.stg_cur_name)return e.stg_cur_name;switch(e.state){case`RUNNING`:return t(`streamOverlay.status.printing`);case`PAUSE`:return t(`streamOverlay.status.paused`);case`FINISH`:return t(`streamOverlay.status.finished`);case`FAILED`:return t(`streamOverlay.status.failed`);case`IDLE`:return t(`streamOverlay.status.idle`);default:return e.state||t(`streamOverlay.status.unknown`)}}function WBe(e){switch(e){case`small`:return{container:`p-3`,text:`text-sm`,textLarge:`text-lg`,progressHeight:`h-2`,icon:`w-3 h-3`,gap:`gap-2`,logoHeight:`h-12`};case`large`:return{container:`p-6`,text:`text-xl`,textLarge:`text-3xl`,progressHeight:`h-4`,icon:`w-6 h-6`,gap:`gap-4`,logoHeight:`h-24`};default:return{container:`p-4`,text:`text-base`,textLarge:`text-xl`,progressHeight:`h-3`,icon:`w-4 h-4`,gap:`gap-3`,logoHeight:`h-16`}}}function GBe(){let{printerId:e}=er(),[t]=Oi(),{t:n}=G(),r=Qa(),i=parseInt(e||`0`,10),[a,o]=(0,y.useState)(Date.now()),s=(0,y.useMemo)(()=>HBe(t),[t]),c=WBe(s.size),{data:l}=q({queryKey:[`printer`,i],queryFn:()=>Q.getPrinter(i),enabled:i>0}),{data:u}=q({queryKey:[`printerStatus`,i],queryFn:()=>Q.getPrinterStatus(i),enabled:i>0,refetchInterval:2e3}),{data:d}=q({queryKey:[`settings`],queryFn:Q.getSettings}),f=d?.time_format||`system`;(0,y.useEffect)(()=>{if(!i)return;let e=null,t=!1;return(async()=>{let n;try{n=(await Q.getWebSocketToken()).token}catch{}if(t)return;let a=window.location.protocol===`https:`?`wss:`:`ws:`,o=n?`?token=${encodeURIComponent(n)}`:``,s=`${a}//${window.location.host}/api/v1/ws${o}`;e=new WebSocket(s),e.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`printer_status`&&t.printer_id===i&&r.setQueryData([`printerStatus`,i],t.status)}catch{}},e.onerror=()=>{}})(),()=>{t=!0,e&&e.close()}},[i,r]),(0,y.useEffect)(()=>(document.title=l?`${l.name} - ${n(`streamOverlay.title`)}`:n(`streamOverlay.title`),()=>{document.title=`Bambuddy`}),[l,n]);let p=()=>{setTimeout(()=>{o(Date.now())},3e3)};if(!i)return(0,K.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,K.jsx)(`p`,{className:`text-white`,children:n(`streamOverlay.invalidPrinterId`)})});if(!u)return(0,K.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,K.jsx)(`p`,{className:`text-gray-400`,children:n(`common.loading`)})});let m=u.state===`RUNNING`||u.state===`PAUSE`,h=u.progress||0,g=Ku(`/api/v1/printers/${i}/camera/stream?fps=${s.fps}&t=${a}`);return(0,K.jsxs)(`div`,{className:`min-h-screen bg-black relative overflow-hidden`,children:[s.showCamera&&(0,K.jsx)(`img`,{src:g,alt:n(`streamOverlay.cameraStream`),className:`absolute inset-0 w-full h-full object-contain`,style:l?.camera_rotation?{transform:`rotate(${l.camera_rotation}deg)`}:void 0,onError:p},a),(0,K.jsx)(`a`,{href:`https://github.com/maziggy/bambuddy`,target:`_blank`,rel:`noopener noreferrer`,className:`absolute top-4 right-4 z-10`,children:(0,K.jsx)(`img`,{src:`/img/bambuddy_logo_dark_transparent.png`,alt:`Bambuddy`,className:`${c.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})}),(0,K.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/60 to-transparent`,children:(0,K.jsxs)(`div`,{className:`${c.container}`,children:[s.showPrinter&&l&&(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} mb-2`,children:[(0,K.jsx)(bl,{className:`${c.icon} text-white/70`}),(0,K.jsx)(`span`,{className:`${c.text} text-white font-medium`,children:l.name})]}),s.showFilename&&u.current_print&&(0,K.jsx)(`div`,{className:`${c.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:VBe(u.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),u.gcode_file,n)}),s.showStatus&&(0,K.jsx)(`div`,{className:`${c.text} text-white/70 mb-2`,children:UBe(u,n)}),s.showProgress&&m&&(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-1 ${c.text}`,children:[(0,K.jsx)(`span`,{className:`text-white/70`,children:n(`streamOverlay.progress`)}),(0,K.jsxs)(`span`,{className:`text-white font-bold`,children:[Math.round(h),`%`]})]}),(0,K.jsx)(`div`,{className:`w-full bg-white/20 rounded-full ${c.progressHeight}`,children:(0,K.jsx)(`div`,{className:`bg-bambu-green ${c.progressHeight} rounded-full transition-all duration-500`,style:{width:`${h}%`}})})]}),m&&(s.showLayers||s.showEta)&&(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} flex-wrap`,children:[s.showLayers&&u.layer_num!=null&&u.total_layers!=null&&u.total_layers>0&&(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,K.jsx)(Nc,{className:c.icon}),(0,K.jsxs)(`span`,{className:c.text,children:[(0,K.jsx)(`span`,{className:`text-white`,children:u.layer_num}),(0,K.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,K.jsx)(`span`,{children:u.total_layers})]})]}),s.showEta&&u.remaining_time!=null&&u.remaining_time>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,K.jsx)(mu,{className:c.icon}),(0,K.jsx)(`span`,{className:`${c.text} text-white`,children:yf(u.remaining_time*60)})]}),(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,K.jsx)(_s,{className:c.icon}),(0,K.jsxs)(`span`,{className:`${c.text} text-white`,children:[n(`streamOverlay.eta`),` `,vf(u.remaining_time,f,n)]})]})]})]}),!m&&(0,K.jsx)(`div`,{className:`${c.text} text-white/70 py-2`,children:u.connected?n(`streamOverlay.printerIdle`):n(`streamOverlay.printerOffline`)})]})})]})}function KBe(){let{t:e}=G(),{id:t}=er(),{mode:n}=ud(),{data:r,isLoading:i,error:a}=q({queryKey:[`external-link`,t],queryFn:()=>Q.getExternalLink(Number(t)),enabled:!!t});return i?(0,K.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):a||!r?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 text-bambu-gray`,children:[(0,K.jsx)(vu,{className:`w-12 h-12`}),(0,K.jsx)(`p`,{children:e(`common.linkNotFound`)})]}):(0,K.jsx)(`iframe`,{src:r.url,className:`h-full w-full border-0`,style:{colorScheme:n},title:r.name,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox`})}function B7(){let{id:e}=er(),t=Yn(),n=Qa(),{t:r}=G(),{showToast:i}=xd(),a=!!e,[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)([]),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(!1),{data:g,isLoading:_}=q({queryKey:[`group`,e],queryFn:()=>Q.getGroup(Number(e)),enabled:a}),{data:v,isLoading:b}=q({queryKey:[`permissions`],queryFn:()=>Q.getPermissions()});a&&g&&!m&&(s(g.name),l(g.description||``),d(g.permissions),h(!0));let x=J({mutationFn:e=>Q.createGroup(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`groups`]}),n.invalidateQueries({queryKey:[`group`]}),i(r(`groups.toast.created`)),t(`/settings?tab=users`)},onError:e=>{i(e.message,`error`)}}),S=J({mutationFn:t=>Q.updateGroup(Number(e),t),onSuccess:a=>{n.invalidateQueries({queryKey:[`groups`]}),a&&n.setQueryData([`group`,e],a),i(r(`groups.toast.updated`)),t(`/settings?tab=users`)},onError:e=>{i(e.message,`error`)}}),C=x.isPending||S.isPending,w=()=>{if(!o.trim()){i(r(`groups.toast.enterGroupName`),`error`);return}a?S.mutate({name:o===g?.name?void 0:o,description:c,permissions:u}):x.mutate({name:o,description:c||void 0,permissions:u})},T=e=>{d(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},E=(e,t)=>{let n=e.permissions.map(e=>e.value);d(e=>{let r=e.filter(e=>!n.includes(e));return t?[...r,...n]:r})},D=e=>e.permissions.every(e=>u.includes(e.value)),O=e=>{let t=e.permissions.filter(e=>u.includes(e.value)).length;return t>0&&t{v&&d(v.all_permissions)},A=()=>{d([])},j=f.toLowerCase(),M=(0,y.useMemo)(()=>v?j?v.categories.map(e=>({...e,permissions:e.permissions.filter(e=>e.label.toLowerCase().includes(j))})).filter(e=>e.permissions.length>0):v.categories:[],[v,j]),N=v?.all_permissions.length??0;return _||b?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,K.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`button`,{onClick:()=>t(`/settings?tab=users`),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Do,{className:`w-5 h-5`})}),(0,K.jsx)(`h1`,{className:`text-xl font-bold text-white`,children:r(a?`groups.editor.title`:`groups.editor.createTitle`)})]}),a&&g?.is_system&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-yellow-500/10 border border-yellow-500/20 text-yellow-400 text-sm`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 shrink-0`}),r(`groups.form.systemGroupWarning`)]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.groupName`)}),(0,K.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),disabled:a&&g?.is_system,className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-50`,placeholder:r(`groups.form.groupNamePlaceholder`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.description`)}),(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`groups.form.descriptionPlaceholder`)})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[r(`groups.editor.permissionsSelected`,{count:u.length}),` / `,N]}),(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:k,children:r(`groups.editor.selectAll`)}),(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:A,children:r(`groups.editor.clearAll`)})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:r(`groups.editor.search`),className:`pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors w-64`})]})]}),M.length===0?(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:r(`groups.editor.noResults`)}):(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:M.map(e=>{let t=v.categories.find(t=>t.name===e.name),n=t.permissions.filter(e=>u.includes(e.value)).length,r=t.permissions.length,i=D(t),a=O(t);return(0,K.jsxs)(pd,{children:[(0,K.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center justify-between px-4 py-3 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-t-xl`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>E(t,!i),className:`w-5 h-5 rounded border flex items-center justify-center transition-colors shrink-0 ${i?`bg-bambu-green border-bambu-green`:a?`bg-bambu-green/50 border-bambu-green`:`border-bambu-gray hover:border-white`}`,children:[i&&(0,K.jsx)($o,{className:`w-3 h-3 text-white`}),a&&!i&&(0,K.jsx)(el,{className:`w-3 h-3 text-white`})]}),(0,K.jsx)(Hl,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,K.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name})]}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray tabular-nums`,children:[n,`/`,r]})]}),(0,K.jsx)(`div`,{className:`p-3 space-y-1`,children:e.permissions.map(e=>(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:u.includes(e.value),onChange:()=>T(e.value),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary`}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.label})]},e.value))})]},e.name)})}),(0,K.jsx)(`div`,{className:`h-16`}),(0,K.jsxs)(`div`,{className:`fixed bottom-0 left-0 right-0 z-20 px-6 py-3 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-center justify-center gap-3`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>t(`/settings?tab=users`),children:r(`common.cancel`)}),(0,K.jsx)($,{onClick:w,disabled:C||!o.trim(),children:C?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),r(`common.saving`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),r(`common.save`)]})})]})]})}var qBe=1.65,V7=[`#1DB954`,`#3B82F6`,`#F59E0B`,`#EF4444`,`#8B5CF6`];function H7(e,t,n){return`${e}||${t??``}||${n??``}`}function U7(e,t){let n=new Date(e);return n.setDate(n.getDate()+Math.round(t)),n}function W7(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function G7(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function JBe(e){if(e.length<2)return null;let t=[...e].sort((e,t)=>new Date(e.created_at).getTime()-new Date(t.created_at).getTime()),n=Date.now(),r=Math.LN2/30,i=[];for(let e=1;ee+t.weight,0);if(a===0)return null;let o=i.reduce((e,t)=>e+t.rate*t.weight,0)/a,s=i.reduce((e,t)=>e+t.weight*(t.rate-o)**2,0)/a;return{rate:o,stdDev:Math.sqrt(s)}}function YBe(e){let t=e.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0);if(t===0)return null;let n=Date.now(),r=(n-e.reduce((e,t)=>{let n=new Date(t.created_at).getTime();return nQ.getAllUsageHistory(5e3),staleTime:6e4,enabled:o}),{data:w=[]}=q({queryKey:[`shopping-list`],queryFn:Q.getShoppingList,staleTime:3e4,enabled:o}),T=x?.forecast_global_lead_time_days??0,E=(0,y.useMemo)(()=>{let e=new Map;for(let t of S)e.set(H7(t.material,t.subtype,t.brand),t);return e},[S]),D=(0,y.useMemo)(()=>{let e=new Map;for(let t of C){let n=e.get(t.spool_id)??[];n.push(t),e.set(t.spool_id,n)}return e},[C]),O=(0,y.useMemo)(()=>{let t=new Map;for(let n of e){if(n.archived_at)continue;let e=H7(n.material,n.subtype,n.brand),r=t.get(e)??{key:e,material:n.material,subtype:n.subtype,brand:n.brand,spools:[]};r.spools.push(n),t.set(e,r)}return[...t.values()]},[e]),k=(0,y.useMemo)(()=>{let e=new Date;return e.setHours(0,0,0,0),O.map(t=>{let n=E.get(t.key)??null,r=n?.lead_time_days??0,i=Math.max(T,r),a=n?.safety_margin_value??14,o=n?.safety_margin_unit??`days`,s=t.spools.reduce((e,t)=>e+Math.max(0,t.label_weight-t.weight_used),0),c=t.spools.reduce((e,t)=>e+t.label_weight,0),l=t.spools.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0),u=[];for(let e of t.spools)u.push(...D.get(e.id)??[]);let d=null,f=null,p=`none`,m=JBe(u);if(m!==null)d=m.rate,f=m.stdDev,p=`history`;else{let e=YBe(t.spools);e!==null&&(d=e,p=`delta`)}let h=qBe*(f??(d===null?0:d*.2))*Math.sqrt(i)+(o===`g`?a:d===null?a*5:d*a),g=d===null?0:d*i+h,_=d&&d>0?Math.floor(s/d):null,v=_===null?null:U7(e,_),y=d&&d>0?Math.floor((s-g)/d):null,b=y===null?null:U7(e,Math.max(0,y)),x=_!==null&&i>0&&_<=i,S=!x&&y!==null&&y<=0;return{group:t,settings:n,totalRemainingG:s,totalLabelG:c,totalSpools:t.spools.length,totalUsedG:l,dailyRateG:d,dailyRateStdDev:f,rateTier:p,effectiveLeadTimeDays:i,safetyStockG:h,reorderPointG:g,daysRemaining:_,daysUntilROP:y,projectedEmptyDate:v,reorderTriggerDate:b,reorderAlert:S,stockBreakAlert:x}})},[O,E,D,T]),A=(0,y.useMemo)(()=>{let e=[...k];return e.sort((e,t)=>{let n=0,r=0;switch(u){case`material`:n=[e.group.material,e.group.subtype??``,e.group.brand??``].join(` `).toLowerCase(),r=[t.group.material,t.group.subtype??``,t.group.brand??``].join(` `).toLowerCase();break;case`used`:n=e.totalUsedG,r=t.totalUsedG;break;case`days_left`:n=e.daysRemaining??999999,r=t.daysRemaining??999999;break;case`stock`:n=e.totalRemainingG,r=t.totalRemainingG;break}let i=nr);return f===`asc`?i:-i}),e},[k,u,f]),j=(0,y.useMemo)(()=>k.filter(e=>!e.settings?.alerts_snoozed&&(e.stockBreakAlert||e.reorderAlert)),[k]),M=(0,y.useMemo)(()=>[...k].filter(e=>e.dailyRateG!==null).sort((e,t)=>t.totalUsedG-e.totalUsedG).slice(0,5),[k]);if(!o)return(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray gap-3`,children:[(0,K.jsx)(Hc,{className:`w-8 h-8 opacity-40`}),(0,K.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noReadAccess`)})]});function N(e){u===e?p(e=>e===`asc`?`desc`:`asc`):(d(e),p(e===`days_left`?`asc`:`desc`))}let P=w.length>0?w.length:null;return(0,K.jsxs)(`div`,{className:`space-y-5`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[j.length>0&&(0,K.jsxs)(`button`,{onClick:()=>l(e=>!e),className:`flex items-center gap-2 px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors ${j.some(e=>e.stockBreakAlert)?`bg-red-500/15 border-red-500/30 text-red-300 hover:bg-red-500/25`:`bg-yellow-500/15 border-yellow-500/30 text-yellow-300 hover:bg-yellow-500/25`}`,children:[(0,K.jsx)(vu,{className:`w-4 h-4`}),r(`forecast.alertCount`,{count:j.length}),c?(0,K.jsx)(rs,{className:`w-3.5 h-3.5`}):(0,K.jsx)(es,{className:`w-3.5 h-3.5`})]}),s&&(0,K.jsx)(tVe,{value:T,onSave:e=>{Q.updateSettings({forecast_global_lead_time_days:e}).then(()=>{t.invalidateQueries({queryKey:[`settings`]}),n(r(`forecast.globalLeadTimeSaved`),`success`)})}}),(0,K.jsxs)(`button`,{onClick:()=>_(e=>!e),className:`relative flex items-center gap-2 px-3 py-1.5 rounded-lg border border-bambu-dark-tertiary text-bambu-gray hover:bg-bambu-dark-tertiary text-sm transition-colors ml-auto`,children:[(0,K.jsx)(Ul,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:r(`forecast.shoppingList`)}),P&&(0,K.jsx)(`span`,{className:`absolute -top-1.5 -right-1.5 w-4 h-4 rounded-full bg-bambu-green text-white text-[10px] font-bold flex items-center justify-center`,children:P})]})]}),c&&j.length>0&&(0,K.jsx)(`div`,{className:`space-y-2`,children:j.map(e=>(0,K.jsx)(QBe,{forecast:e,onCart:()=>h(e)},e.group.key))}),g&&(0,K.jsx)(aVe,{items:w,forecasts:k,globalLeadTime:T,canWrite:s,onClose:()=>_(!1),onRemove:e=>{Q.removeFromShoppingList(e).then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))},onClear:()=>{Q.clearShoppingList().then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))}}),M.length>0&&(0,K.jsx)(eVe,{forecasts:M,days:v,onDaysChange:b}),k.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,K.jsx)(gu,{className:`w-10 h-10 mb-3 opacity-40`}),(0,K.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noSpools`)})]}):(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,K.jsx)(`th`,{className:`w-8 px-4 py-3`}),(0,K.jsx)(K7,{col:`material`,active:u,dir:f,onSort:N,children:r(`forecast.sku`)}),(0,K.jsx)(K7,{col:`stock`,active:u,dir:f,onSort:N,children:r(`forecast.stock`)}),(0,K.jsx)(K7,{col:`used`,active:u,dir:f,onSort:N,children:r(`forecast.dailyRate`)}),(0,K.jsx)(K7,{col:`days_left`,active:u,dir:f,onSort:N,children:r(`forecast.daysLeft`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.emptyBy`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.reorderBy`)}),(0,K.jsx)(`th`,{className:`w-24 px-4 py-3`})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:A.map(e=>(0,K.jsx)(nVe,{forecast:e,globalLeadTime:T,canWrite:s,onSaved:()=>t.invalidateQueries({queryKey:[`sku-settings`]}),onCart:()=>h(e),showToast:n},e.group.key))})]})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-4 py-3 text-xs text-bambu-gray border-t border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-green inline-block`}),r(`forecast.trendLegend`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-400 inline-block`}),r(`forecast.estimatedLegend`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-gray/40 inline-block`}),r(`forecast.noDataLegend`)]})]})]}),m&&(0,K.jsx)(sVe,{forecast:m,onClose:()=>h(null),onAdd:e=>{Q.addToShoppingList(e).then(()=>{t.invalidateQueries({queryKey:[`shopping-list`]}),n(r(`forecast.addedToCart`),`success`),h(null),_(!0)}).catch(()=>n(r(`forecast.failedAddItem`),`error`))}})]})}function K7({col:e,active:t,dir:n,onSort:r,children:i}){return(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide cursor-pointer select-none hover:text-white transition-colors`,onClick:()=>r(e),children:(0,K.jsxs)(`span`,{className:`inline-flex items-center`,children:[i,t===e?n===`asc`?(0,K.jsx)(Mo,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,K.jsx)(Eo,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,K.jsx)(Ao,{className:`w-3 h-3 ml-1 opacity-40`})]})})}function QBe({forecast:e,onCart:t}){let{t:n}=G(),r=[e.group.brand,e.group.material,e.group.subtype].filter(Boolean).join(` `),i=e.stockBreakAlert;return(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg border text-sm ${i?`bg-red-500/10 border-red-500/30 text-red-300`:`bg-yellow-500/10 border-yellow-500/30 text-yellow-300`}`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`span`,{className:`font-medium`,children:r}),i?(0,K.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.stockBreakRisk`),` — `,n(`forecast.stockBreakDetail`,{days:e.daysRemaining,lt:e.effectiveLeadTimeDays})]}):(0,K.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.reorderNow`),` — `,n(`forecast.reorderTriggerPassed`,{date:e.reorderTriggerDate?W7(e.reorderTriggerDate):`—`})]})]}),(0,K.jsxs)(`button`,{onClick:t,className:`flex items-center gap-1.5 px-2.5 py-1 rounded border border-current text-xs opacity-70 hover:opacity-100 transition-opacity`,children:[(0,K.jsx)(Ul,{className:`w-3 h-3`}),` `,n(`forecast.order`)]})]})}var $Be=[{label:`1W`,value:7},{label:`1M`,value:30},{label:`6M`,value:180}];function eVe({forecasts:e,days:t,onDaysChange:n}){let{t:r}=G(),i=Array.from({length:t+1},(e,t)=>t),a=e.map((e,n)=>({key:e.group.key,label:[e.group.brand,e.group.material,e.group.subtype].filter(Boolean).join(` `),color:V7[n%V7.length],rop:e.reorderPointG,points:XBe(e,t)})),o=i.map(e=>{let t={day:e,label:G7(U7(new Date,e))};for(let n of a){let r=n.points.find(t=>t.day===e);t[n.key]=r?.stock??0}return t}),s=(()=>{for(let e=t;e>=0;e--)if(a.some(t=>o[e]?.[t.key]>0))return e;return t})(),c=o.slice(0,s+1),l=a.filter(e=>e.rop>0);return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,K.jsx)(gu,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:r(`forecast.chartTitle`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1 hidden sm:inline`,children:r(`forecast.dashedLinesROP`)}),(0,K.jsx)(`div`,{className:`ml-auto flex items-center bg-bambu-dark-tertiary rounded-lg p-0.5`,children:$Be.map(e=>(0,K.jsx)(`button`,{onClick:()=>n(e.value),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${t===e.value?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:e.label},e.value))})]}),(0,K.jsx)(RA,{width:`100%`,height:220,children:(0,K.jsxs)(WG,{data:c,margin:{top:4,right:8,bottom:0,left:0},children:[(0,K.jsx)(`defs`,{children:a.map(e=>(0,K.jsxs)(`linearGradient`,{id:`grad-${e.key}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,K.jsx)(`stop`,{offset:`5%`,stopColor:e.color,stopOpacity:.25}),(0,K.jsx)(`stop`,{offset:`95%`,stopColor:e.color,stopOpacity:.02})]},e.key))}),(0,K.jsx)(XU,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.5}),(0,K.jsx)(eG,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:10},interval:Math.max(0,Math.ceil(s/8)-1),axisLine:!1,tickLine:!1}),(0,K.jsx)(aG,{tick:{fill:`#6B7280`,fontSize:10},axisLine:!1,tickLine:!1,tickFormatter:e=>e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:48}),(0,K.jsx)(Xz,{contentStyle:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:12},labelStyle:{color:`#9CA3AF`},itemStyle:{color:`#E5E7EB`},formatter:(e,t)=>typeof e==`number`?`${e}g — ${a.find(e=>e.key===String(t))?.label??t}`:``}),(0,K.jsx)(Gj,{formatter:e=>(0,K.jsx)(`span`,{style:{color:`#9CA3AF`,fontSize:11},children:a.find(t=>t.key===e)?.label??e})}),a.map(e=>(0,K.jsx)(MW,{type:`monotone`,dataKey:e.key,stroke:e.color,strokeWidth:2,fill:`url(#grad-${e.key})`,dot:!1,activeDot:{r:3}},e.key)),l.map(e=>(0,K.jsx)(PU,{y:e.rop,stroke:e.color,strokeDasharray:`4 3`,strokeOpacity:.6},`rop-${e.key}`))]})})]})}function tVe({value:e,onSave:t}){let{t:n}=G(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(String(e));function s(){let e=parseInt(a,10);isNaN(e)||e<0||(t(e),i(!1))}return(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-tertiary/40 rounded-lg border border-bambu-dark-tertiary text-xs text-bambu-gray`,children:[(0,K.jsx)(kc,{className:`w-3.5 h-3.5 flex-shrink-0`,"aria-label":n(`forecast.globalLeadTimeHint`)}),(0,K.jsxs)(`span`,{className:`hidden sm:inline`,children:[n(`forecast.globalLeadTime`),`:`]}),r?(0,K.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault(),s()},children:[(0,K.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-14 px-1.5 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`d`}),(0,K.jsx)(`button`,{type:`submit`,className:`px-2 py-0.5 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80`,children:n(`forecast.save`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`text-xs text-bambu-gray hover:text-white`,children:`✕`})]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsxs)(`span`,{className:`font-semibold text-white`,children:[e,`d`]}),(0,K.jsx)(`button`,{onClick:()=>{o(String(e)),i(!0)},className:`p-0.5 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(fl,{className:`w-3 h-3`})})]})]})}function nVe({forecast:e,globalLeadTime:t,canWrite:n,onSaved:r,onCart:i,showToast:a}){let{t:o}=G(),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(String(e.settings?.lead_time_days??0)),[h,g]=(0,y.useState)(String(e.settings?.safety_margin_value??14)),[_,v]=(0,y.useState)(e.settings?.safety_margin_unit??`days`);(0,y.useEffect)(()=>{l||m(String(e.settings?.lead_time_days??0))},[e.settings?.lead_time_days,l]),(0,y.useEffect)(()=>{d||(g(String(e.settings?.safety_margin_value??14)),v(e.settings?.safety_margin_unit??`days`))},[e.settings?.safety_margin_value,e.settings?.safety_margin_unit,d]);let b=J({mutationFn:Q.upsertSkuSettings,onSuccess:()=>{r(),a(o(`forecast.settingsSaved`),`success`)},onError:()=>a(o(`forecast.failedSaveSettings`),`error`)}),x=e.settings?.alerts_snoozed??!1,S=[e.group.brand,e.group.material,e.group.subtype].filter(Boolean).join(` `),C=e.group.spools[0]?.rgba?Wd(e.group.spools[0].rgba):{backgroundColor:`#4B5563`},w=e.totalLabelG>0?Math.round(e.totalRemainingG/e.totalLabelG*100):0,T=x||e.daysRemaining===null?`text-bambu-gray`:e.stockBreakAlert?`text-red-400`:e.reorderAlert||e.daysRemaining<30?`text-yellow-400`:`text-green-400`;function E(t,n,r,i=x){b.mutate({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,lead_time_days:t,safety_margin_value:n,safety_margin_unit:r,alerts_snoozed:i})}function D(t){t.stopPropagation(),E(e.settings?.lead_time_days??0,e.settings?.safety_margin_value??14,e.settings?.safety_margin_unit??`days`,!x)}let O=e.rateTier===`history`?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-green/15 text-bambu-green`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),o(`forecast.trend`)]}):e.rateTier===`delta`?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-400/15 text-blue-400`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-blue-400`}),o(`forecast.estimated`)]}):(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray/60`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-gray/40`}),o(`forecast.noData`)]});return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`tr`,{className:`cursor-pointer hover:bg-bambu-dark-tertiary/40 transition-colors ${x?``:e.stockBreakAlert?`bg-red-500/5`:e.reorderAlert?`bg-yellow-500/5`:``} ${x?`opacity-50`:``}`,onClick:()=>c(e=>!e),children:[(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsx)(`span`,{className:`block w-3 h-3 rounded-full border border-black/20`,style:C})}),(0,K.jsxs)(`td`,{className:`px-4 py-3`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-white`,children:S}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:o(`forecast.spoolCount`,{count:e.totalSpools})})]}),(0,K.jsxs)(`td`,{className:`px-4 py-3 min-w-[120px]`,children:[(0,K.jsx)(`div`,{className:`h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden mb-1 w-24`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full ${w>50?`bg-bambu-green`:w>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(w,100)}%`}})}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(e.totalRemainingG),`g`]})]}),(0,K.jsxs)(`td`,{className:`px-4 py-3`,children:[(0,K.jsx)(`div`,{className:`text-sm text-white`,children:e.dailyRateG===null?`—`:`${e.dailyRateG.toFixed(1)}g/d`}),(0,K.jsx)(`div`,{className:`mt-0.5`,children:O})]}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-semibold ${T}`,children:e.daysRemaining===null?(0,K.jsx)(`span`,{className:`text-bambu-gray font-normal`,children:`—`}):`${e.daysRemaining}d`})}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.projectedEmptyDate?W7(e.projectedEmptyDate):`—`})}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-medium ${!x&&e.reorderAlert?`text-yellow-400`:`text-bambu-gray`}`,children:e.reorderTriggerDate?W7(e.reorderTriggerDate):`—`})}),(0,K.jsx)(`td`,{className:`px-4 py-3`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[n&&(0,K.jsx)(`button`,{onClick:i,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:o(`forecast.addToCart`),children:(0,K.jsx)(Ul,{className:`w-4 h-4`})}),!x&&(e.stockBreakAlert?(0,K.jsx)(vu,{className:`w-4 h-4 text-red-400`,"aria-label":o(`forecast.stockBreakRisk`)}):e.reorderAlert?(0,K.jsx)(vu,{className:`w-4 h-4 text-yellow-400`,"aria-label":o(`forecast.reorderNow`)}):e.daysRemaining===null?null:(0,K.jsx)($o,{className:`w-4 h-4 text-bambu-green/50`})),n&&(0,K.jsx)(`button`,{onClick:D,className:`p-1 rounded transition-colors ${x?`text-bambu-gray/70 hover:text-white`:`text-bambu-dark-tertiary hover:text-bambu-gray`}`,title:o(x?`forecast.alertsEnabled`:`forecast.alertsSnoozed`),children:(0,K.jsx)(Fo,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),c(e=>!e)},className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,children:s?(0,K.jsx)(rs,{className:`w-4 h-4`}):(0,K.jsx)(es,{className:`w-4 h-4`})})]})})]}),s&&(0,K.jsx)(`tr`,{className:`bg-bambu-dark-tertiary/10`,children:(0,K.jsx)(`td`,{colSpan:8,className:`px-6 py-4`,children:(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,K.jsx)(q7,{label:o(`forecast.effectiveLeadTime`),value:`${e.effectiveLeadTimeDays}d`,hint:o(`forecast.effectiveLeadTimeHint`,{global:t,sku:e.settings?.lead_time_days??0})}),(0,K.jsx)(q7,{label:o(`forecast.safetyMarginLabel`),value:`${Math.round(e.safetyStockG)}g`,hint:o(`forecast.safetyMarginHint`)}),(0,K.jsx)(q7,{label:o(`forecast.reorderPoint`),value:`${Math.round(e.reorderPointG)}g`,hint:o(`forecast.reorderPointHint`)})]}),n&&(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,K.jsx)(rVe,{label:o(`forecast.skuLeadTimeOverride`),hint:o(`forecast.skuLeadTimeHint`),unit:o(`forecast.leadTime`),editing:l,value:e.settings?.lead_time_days??0,inputValue:p,onInputChange:m,onEdit:()=>{m(String(e.settings?.lead_time_days??0)),u(!0)},onSave:()=>{let t=parseInt(p,10);!isNaN(t)&&t>=0&&(E(t,e.settings?.safety_margin_value??14,_),u(!1))},onCancel:()=>u(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`)}),(0,K.jsx)(iVe,{value:e.settings?.safety_margin_value??14,unit:_,editing:d,inputValue:h,dailyRateG:e.dailyRateG,onInputChange:g,onUnitChange:e=>v(e),onEdit:()=>{g(String(e.settings?.safety_margin_value??14)),v(e.settings?.safety_margin_unit??`days`),f(!0)},onSave:()=>{let t=parseInt(h,10);!isNaN(t)&&t>=0&&(E(e.settings?.lead_time_days??0,t,_),f(!1))},onCancel:()=>f(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`),safetyMarginLabel:o(`forecast.safetyMarginLabel`)})]}),e.group.spools.length>1&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:o(`forecast.individualSpools`)}),(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:`#`}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.remaining`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.used`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`forecast.labelWeight`)})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:e.group.spools.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used),n=e.label_weight>0?t/e.label_weight*100:0;return(0,K.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray/70`,children:[`#`,e.id]})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-24 h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full ${n>50?`bg-bambu-green`:n>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(n,100)}%`}})}),(0,K.jsxs)(`span`,{className:`text-sm text-white`,children:[Math.round(t),`g`]})]})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[Math.round(Math.max(0,e.weight_used-(e.weight_used_baseline??0))),`g`]})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.label_weight,`g`]})})]},e.id)})})]})})]})]})})})]})}function q7({label:e,value:t,hint:n}){return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3`,title:n,children:[(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mb-1`,children:e}),(0,K.jsx)(`div`,{className:`text-lg font-semibold text-white`,children:t})]})}function rVe({label:e,hint:t,unit:n,editing:r,value:i,inputValue:a,onInputChange:o,onEdit:s,onSave:c,onCancel:l,isPending:u,saveLabel:d=`Save`,cancelLabel:f=`Cancel`}){return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-white`,children:e}),(0,K.jsx)(`span`,{title:t,children:(0,K.jsx)(kc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),r?(0,K.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,K.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:u}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,K.jsx)(`button`,{type:`submit`,disabled:u,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:d}),(0,K.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:i}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,K.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(fl,{className:`w-3 h-3`})})]})]})}function iVe({value:e,unit:t,editing:n,inputValue:r,dailyRateG:i,onInputChange:a,onUnitChange:o,onEdit:s,onSave:c,onCancel:l,isPending:u,saveLabel:d=`Save`,cancelLabel:f=`Cancel`,safetyMarginLabel:p=`Safety Margin`}){let{t:m}=G(),h=t===`g`?e:i===null?null:Math.round(i*e),g=t===`days`?m(`forecast.safetyMarginHintDays`,{approx:h===null?``:m(`forecast.safetyMarginHintDaysApprox`,{g:h})}):m(`forecast.safetyMarginHintG`,{approx:i===null?``:m(`forecast.safetyMarginHintGApprox`,{days:Math.round(e/i)})});return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-white`,children:p}),(0,K.jsx)(`span`,{title:g,children:(0,K.jsx)(kc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),n?(0,K.jsxs)(`form`,{className:`flex items-center gap-2 flex-wrap`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,K.jsx)(`input`,{type:`number`,min:0,max:t===`g`?1e4:365,value:r,onChange:e=>a(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:u}),(0,K.jsxs)(`div`,{className:`flex bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded overflow-hidden text-xs`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>o(`days`),className:`px-2 py-1 transition-colors ${t===`days`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`days`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>o(`g`),className:`px-2 py-1 transition-colors ${t===`g`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`g`})]}),(0,K.jsx)(`button`,{type:`submit`,disabled:u,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:d}),(0,K.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:e}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t}),h!==null&&t===`days`&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray/60`,children:[`≈ `,h,`g`]}),t===`g`&&i!==null&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray/60`,children:[`≈ `,Math.round(e/i),`d`]}),(0,K.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(fl,{className:`w-3 h-3`})})]})]})}function aVe({items:e,forecasts:t,globalLeadTime:n,canWrite:r,onClose:i,onRemove:a,onClear:o}){let{t:s}=G(),c=Qa(),[l,u]=(0,y.useState)(`list`),d=J({mutationFn:async({id:e,status:t,item:n,avgSpoolG:r})=>{if(await Q.updateShoppingListStatus(e,t),t===`received`&&n){let t=r??1e3,i={material:n.material,subtype:n.subtype,brand:n.brand,label_weight:t,core_weight:0,core_weight_catalog_id:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,nozzle_temp_min:null,nozzle_temp_max:null,note:n.note??null,tag_uid:null,tray_uuid:null,data_origin:`manual`,tag_type:null,cost_per_kg:null,last_scale_weight:null,last_weighed_at:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,added_full:null,last_used:null,encode_time:null,category:`Stock`,low_stock_threshold_pct:null};await Q.bulkCreateSpools(i,n.quantity_spools),await Q.removeFromShoppingList(e)}},onSuccess:()=>{c.invalidateQueries({queryKey:[`shopping-list`]}),c.invalidateQueries({queryKey:[`spools`]})}}),f=(0,y.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.group.key,n);return e},[t]),p=(0,y.useMemo)(()=>e.map(e=>({item:e,forecast:f.get(H7(e.material,e.subtype,e.brand))??null})),[e,f]),m=(0,y.useMemo)(()=>p.filter(({forecast:e})=>!e||e.dailyRateG===null?!1:e.stockBreakAlert||e.daysRemaining!==null&&e.daysRemaining<=e.effectiveLeadTimeDays),[p]);function h(){let t=[s(`forecast.qty`),s(`forecast.material`),`Brand`,`Subtype`,`${s(`forecast.weight`)} (g)`,`${s(`forecast.leadTime`)} (d)`,s(`forecast.expectedRestock`),s(`forecast.status`),s(`forecast.note`)],r=e.map(e=>{let t=f.get(H7(e.material,e.subtype,e.brand))??null,r=t&&t.totalSpools>0?t.totalLabelG/t.totalSpools:1e3,i=Math.round(e.quantity_spools*r),a=t?.effectiveLeadTimeDays??n??0,o=a>0?W7(U7(new Date,a)):``;return[e.quantity_spools,e.material,e.brand??``,e.subtype??``,i,a||``,o,e.status,e.note??``].map(e=>`"${String(e).replace(/"/g,`""`)}"`).join(`,`)}),i=[t.join(`,`),...r].join(` +`),a=new Blob([i],{type:`text/csv`}),o=URL.createObjectURL(a),c=document.createElement(`a`);c.href=o,c.download=`shopping-list-${new Date().toISOString().slice(0,10)}.csv`,c.click(),setTimeout(()=>URL.revokeObjectURL(o),100)}return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(Ul,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:s(`forecast.shoppingList`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:s(`forecast.shoppingListItems`,{count:e.length})}),e.length>0&&(0,K.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-md p-0.5 ml-1`,children:[(0,K.jsxs)(`button`,{onClick:()=>u(`list`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${l===`list`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(cl,{className:`w-3 h-3`}),s(`forecast.listView`)]}),(0,K.jsxs)(`button`,{onClick:()=>u(`logistics`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${l===`logistics`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(Zo,{className:`w-3 h-3`}),s(`forecast.logisticsView`),m.length>0&&(0,K.jsx)(`span`,{className:`w-3.5 h-3.5 rounded-full bg-red-500 text-white text-[9px] font-bold flex items-center justify-center`,children:m.length})]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`button`,{onClick:h,className:`flex items-center gap-1.5 text-xs text-bambu-gray hover:text-white transition-colors px-2 py-1 rounded border border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`,children:[(0,K.jsx)(Is,{className:`w-3 h-3`}),s(`forecast.downloadCsv`)]}),r&&(0,K.jsx)(`button`,{onClick:o,className:`text-xs text-red-400 hover:text-red-300 transition-colors px-2 py-1 rounded border border-red-500/20 hover:bg-red-500/10`,children:s(`forecast.clearAll`)})]}),(0,K.jsx)(`button`,{onClick:i,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]})]}),e.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center py-8 text-bambu-gray`,children:[(0,K.jsx)(cl,{className:`w-8 h-8 mb-2 opacity-30`}),(0,K.jsx)(`p`,{className:`text-sm`,children:s(`forecast.shoppingListEmpty`)})]}):l===`list`?(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.qty`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.material`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.weight`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.leadTime`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.expectedRestock`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.status`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.note`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-right text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.actions`)})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:e.map(e=>{let t=[e.brand,e.material,e.subtype].filter(Boolean).join(` `),i=m.some(t=>t.item.id===e.id),o=f.get(H7(e.material,e.subtype,e.brand))??null,c=o&&o.totalSpools>0?o.totalLabelG/o.totalSpools:1e3,l=Math.round(e.quantity_spools*c),u=o?.effectiveLeadTimeDays??n??0,p=u>0?U7(new Date,u):null,h=e.status===`purchased`||e.status===`received`,g=e.status===`received`,_=d.isPending;return(0,K.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors ${i&&!h?`bg-red-500/5`:``}`,children:[(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsxs)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:[e.quantity_spools,`×`]})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:t}),i&&!h&&(0,K.jsx)(vu,{className:`w-3.5 h-3.5 text-red-400 flex-shrink-0`,"aria-label":s(`forecast.stockBreakBefore`)})]})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`text-sm text-white`,children:l>=1e3?`${(l/1e3).toFixed(1)}kg`:`${l}g`})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:u>0?`${u}d`:`—`})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:p?W7(p):`—`})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${g?`bg-bambu-green/20 text-bambu-green`:h?`bg-blue-400/20 text-blue-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:s(g?`forecast.received`:h?`forecast.purchased`:`forecast.pending`)})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.note||`—`})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`div`,{className:`flex items-center justify-end gap-1`,children:r&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:()=>d.mutate({id:e.id,status:h?`pending`:`purchased`}),disabled:_||g,title:s(h?`forecast.resetToPending`:`forecast.markPurchased`),className:`p-1 rounded transition-colors disabled:opacity-30 ${h?`text-blue-400 hover:text-bambu-gray`:`text-bambu-gray hover:text-blue-400`}`,children:h?(0,K.jsx)(Tl,{className:`w-3.5 h-3.5`}):(0,K.jsx)(ks,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{onClick:()=>d.mutate({id:e.id,status:`received`,item:e,avgSpoolG:c}),disabled:_||!h||g,title:s(`forecast.markReceived`),className:`p-1 rounded transition-colors text-bambu-gray hover:text-bambu-green disabled:opacity-30`,children:(0,K.jsx)(ol,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{onClick:()=>a(e.id),className:`p-1 text-bambu-gray hover:text-red-400 transition-colors`,title:s(`forecast.remove`),children:(0,K.jsx)(hu,{className:`w-3.5 h-3.5`})})]})})})]},e.id)})})]})}):(0,K.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:p.filter(({item:e})=>e.status!==`received`).map(({item:e,forecast:t})=>(0,K.jsx)(oVe,{item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:()=>a(e.id)},e.id))})]})}function oVe({item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:i}){let{t:a}=G(),o=[e.brand,e.material,e.subtype].filter(Boolean).join(` `),s=(0,y.useMemo)(()=>{if(!t||t.dailyRateG===null||t.dailyRateG<=0)return null;let n=t.dailyRateG,r=t.effectiveLeadTimeDays,i=t.totalSpools>0?t.totalLabelG/t.totalSpools:1e3,a=e.quantity_spools*i,o=Math.max(0,t.totalRemainingG-n*r),s=o+a,c=Math.ceil(s/n),l=Math.min(r+c+5,365),u=[];for(let e=0;e<=l;e++){let i=G7(U7(new Date,e));if(e===r)u.push({day:e,label:i,stock:Math.round(o),rop:Math.round(t.reorderPointG),safetyStock:Math.round(t.safetyStockG)}),u.push({day:e,label:i,stock:Math.round(s),rop:Math.round(t.reorderPointG),safetyStock:Math.round(t.safetyStockG),arrival:!0});else{let a=e{if(!t||t.dailyRateG===null||t.dailyRateG<=0)return null;let e=Math.floor(t.totalRemainingG/t.dailyRateG);return ee>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:44}),(0,K.jsx)(Xz,{contentStyle:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:11},labelStyle:{color:`#9CA3AF`},formatter:(e,t)=>typeof e==`number`?t===`stock`?`${e}g — ${a(`forecast.stock`)}`:t===`rop`?`${e}g — ${a(`forecast.reorderPoint`)}`:t===`safetyStock`?`${e}g — ${a(`forecast.safetyMarginLabel`)}`:`${e}`:``}),(0,K.jsx)(MW,{type:`linear`,dataKey:`stock`,stroke:`#1DB954`,strokeWidth:2,fill:`url(#cart-post-${e.id})`,dot:!1,activeDot:{r:3}}),t.reorderPointG>0&&(0,K.jsx)(PU,{y:t.reorderPointG,stroke:`#F59E0B`,strokeDasharray:`5 3`,strokeOpacity:.8,label:{value:`ROP`,position:`insideTopRight`,fill:`#F59E0B`,fontSize:9}}),t.safetyStockG>0&&(0,K.jsx)(PU,{y:t.safetyStockG,stroke:`#6B7280`,strokeDasharray:`3 3`,strokeOpacity:.6,label:{value:`SS`,position:`insideTopRight`,fill:`#6B7280`,fontSize:9}}),(0,K.jsx)(PU,{x:G7(U7(new Date,s.lt)),stroke:`#3B82F6`,strokeWidth:1.5,strokeDasharray:`4 3`,strokeOpacity:.9,label:{value:`+${s.arrivalG>=1e3?`${(s.arrivalG/1e3).toFixed(1)}kg`:`${Math.round(s.arrivalG)}g`} arrives (d${s.lt})`,position:`insideTopLeft`,fill:`#3B82F6`,fontSize:9}}),c!==null&&(0,K.jsx)(PU,{x:G7(U7(new Date,c)),stroke:`#EF4444`,strokeWidth:1.5,strokeOpacity:.9,label:{value:`OUT`,position:`insideTopLeft`,fill:`#EF4444`,fontSize:9}})]})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mt-2 text-[10px] text-bambu-gray`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-yellow-400 border-dashed`}),` `,a(`forecast.ropLabel`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`inline-block w-4 border-t border-bambu-gray border-dashed`}),` `,a(`forecast.safetyStockLegend`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-blue-400 border-dashed`}),` `,a(`forecast.stockArrivalLegend`)]}),l&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-red-400`,children:[(0,K.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-red-400`}),` `,a(`forecast.stockoutLegend`)]})]})]}):null]})}function sVe({forecast:e,onClose:t,onAdd:n}){let{t:r}=G(),i=[e.group.brand,e.group.material,e.group.subtype].filter(Boolean).join(` `),[a,o]=(0,y.useState)(`qty`),[s,c]=(0,y.useState)(`1`),[l,u]=(0,y.useState)(`30`),[d,f]=(0,y.useState)(``),p=(0,y.useMemo)(()=>{if(!e.dailyRateG||e.dailyRateG<=0)return null;let t=e.dailyRateG*Number(l),n=e.group.spools.length>0?e.group.spools.reduce((e,t)=>e+t.label_weight,0)/e.group.spools.length:1e3;return Math.ceil(t/n)},[e,l]),m=a===`qty`?parseInt(s,10)||1:p??1;function h(t){t.preventDefault(),n({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,quantity_spools:m,note:d||null})}return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-2xl border border-bambu-dark-tertiary w-full max-w-sm shadow-2xl`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-5 pt-5 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Ul,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-base font-semibold text-white`,children:r(`forecast.addToCartTitle`)})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`form`,{onSubmit:h,className:`p-5 space-y-4`,children:[(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:i}),(0,K.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>o(`qty`),className:`flex-1 py-1.5 text-xs font-medium rounded-md transition-colors ${a===`qty`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:r(`forecast.byQuantity`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>o(`duration`),className:`flex-1 py-1.5 text-xs font-medium rounded-md transition-colors ${a===`duration`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:r(`forecast.byDuration`)})]}),a===`qty`?(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.numberOfSpools`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:99,value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,autoFocus:!0})]}):(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.lastHowManyDays`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:365,value:l,onChange:e=>u(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,autoFocus:!0})]}),e.dailyRateG===null?(0,K.jsx)(`div`,{className:`text-xs text-yellow-400 px-1`,children:r(`forecast.noUsageQty`)}):(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary/50 rounded-lg`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`≈`}),(0,K.jsx)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:r(`forecast.spoolCount`,{count:p??0})}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`at `,e.dailyRateG.toFixed(1),`g/day`]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.noteOptional`)}),(0,K.jsx)(`input`,{type:`text`,maxLength:200,value:d,onChange:e=>f(e.target.value),placeholder:r(`forecast.notePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/40 focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,K.jsx)(`button`,{type:`submit`,className:`flex-1 py-2 bg-bambu-green text-white text-sm font-medium rounded-lg hover:bg-bambu-green/80 transition-colors`,children:r(`forecast.addNSpools`,{count:m})}),(0,K.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 text-sm text-bambu-gray hover:text-white border border-bambu-dark-tertiary rounded-lg transition-colors`,children:r(`forecast.cancel`)})]})]})]})})}var J7={material:``,subtype:``,brand:``,color_name:``,rgba:`808080FF`,extra_colors:``,effect_type:``,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:``,note:``,cost_per_kg:null,category:``,low_stock_threshold_pct:null,location_id:null,spoolman_filament_id:null},cVe=new Set([`material`,`subtype`,`brand`,`rgba`,`color_name`,`label_weight`]);function Y7(e,t=!1,n=!1){let r={};return t||n?(!e.material&&!e.spoolman_filament_id&&(r.material=`Material is required`),{isValid:Object.keys(r).length===0,errors:r}):(e.slicer_filament||(r.slicer_filament=`Slicer preset is required`),e.material||(r.material=`Material is required`),e.brand||(r.brand=`Brand is required`),e.subtype||(r.subtype=`Subtype is required`),{isValid:Object.keys(r).length===0,errors:r})}function X7({formData:e,updateField:t,cloudAuthenticated:n,loadingCloudPresets:r,presetInputValue:i,setPresetInputValue:a,selectedPresetOption:o,filamentOptions:s,availableBrands:c,availableMaterials:l,quickAdd:u,quantity:d,onQuantityChange:f,errors:p}){let{t:m}=G(),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(``),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(String(e.label_weight)),[M,N]=(0,y.useState)(!1),P=(0,y.useRef)(null),F=(0,y.useRef)(null),I=(0,y.useRef)(null),L=(0,y.useRef)(null);(0,y.useEffect)(()=>{let e=e=>{P.current&&!P.current.contains(e.target)&&g(!1),L.current&&!L.current.contains(e.target)&&C(!1),F.current&&!F.current.contains(e.target)&&v(!1),I.current&&!I.current.contains(e.target)&&x(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let R=(0,y.useMemo)(()=>{if(!i)return s;let e=i.toLowerCase();return s.filter(t=>t.displayName.toLowerCase().includes(e)||t.code.toLowerCase().includes(e))},[s,i]),z=(0,y.useMemo)(()=>{if(!w)return c;let e=w.toLowerCase();return c.filter(t=>t.toLowerCase().includes(e)).sort((t,n)=>{let r=t.toLowerCase()===e,i=n.toLowerCase()===e;return r&&!i?-1:!r&&i?1:t.localeCompare(n)})},[c,w]),B=(0,y.useMemo)(()=>{if(!E)return oK;let e=E.toLowerCase();return oK.filter(t=>t.toLowerCase().includes(e))},[E]),V=(0,y.useMemo)(()=>{if(!O)return l;let e=O.toLowerCase();return l.filter(t=>t.toLowerCase().includes(e)).sort((t,n)=>{let r=t.toLowerCase()===e,i=n.toLowerCase()===e;return r&&!i?-1:!r&&i?1:t.localeCompare(n)})},[O,l]);(0,y.useEffect)(()=>{M||j(String(e.label_weight))},[e.label_weight,M]);let ee=e=>{t(`slicer_filament`,e.code),a(e.displayName),g(!1);let n=uK(e.name);n.material&&t(`material`,n.material),n.brand&&t(`brand`,n.brand),n.variant&&t(`subtype`,n.variant)};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[!u&&(0,K.jsx)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:r?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}),` `,m(`inventory.loadingPresets`)]}):n?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ys,{className:`w-3 h-3 text-bambu-green`}),` `,m(`inventory.cloudConnected`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(vs,{className:`w-3 h-3`}),` `,m(`inventory.cloudNotConnected`)]})}),!u&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[m(`inventory.slicerPreset`),` *`]}),(0,K.jsxs)(`div`,{className:`relative`,ref:P,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),(0,K.jsx)(`input`,{type:`text`,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:m(`inventory.searchPresets`),value:i,onChange:e=>{a(e.target.value),g(!0)},onFocus:()=>{g(!0),a(``)}}),h&&(0,K.jsx)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:R.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:m(`inventory.noPresetsFound`)}):R.map(e=>(0,K.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary truncate ${o?.code===e.code?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>ee(e),children:e.displayName},`${e.code}::${e.name}`))})]}),o&&(0,K.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray`,children:[m(`inventory.selectedPreset`),`: `,(0,K.jsx)(`span`,{className:`font-mono text-bambu-green`,children:o.code})]}),p?.slicer_filament&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-400`,children:p.slicer_filament})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[m(`inventory.material`),` *`]}),(0,K.jsxs)(`div`,{className:`relative`,ref:L,children:[(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 text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:m(`inventory.selectMaterial`),value:S?O:e.material,onChange:e=>{k(e.target.value),C(!0)},onFocus:()=>{C(!0),k(``)}}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),S&&(0,K.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[V.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:m(`inventory.noResults`)}):V.map(n=>(0,K.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.material===n?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{t(`material`,n),C(!1),k(``)},children:n},n)),O&&!V.includes(O)&&(0,K.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{t(`material`,O),C(!1),k(``)},children:m(`inventory.useCustomMaterial`,{material:O})})]})]}),p?.material&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-400`,children:p.material})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[m(`inventory.brand`),!u&&` *`]}),(0,K.jsxs)(`div`,{className:`relative`,ref:F,children:[(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 text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:m(`inventory.searchBrand`),value:_?w:e.brand,onChange:e=>{T(e.target.value),v(!0)},onFocus:()=>{v(!0),T(``)}}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),_&&(0,K.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[z.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:m(`inventory.noResults`)}):z.map(n=>(0,K.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.brand===n?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{t(`brand`,n),v(!1),T(``)},children:n},n)),w&&!z.includes(w)&&(0,K.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{t(`brand`,w),v(!1),T(``)},children:m(`inventory.useCustomBrand`,{brand:w})})]})]}),p?.brand&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-400`,children:p.brand})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[m(`inventory.subtype`),!u&&` *`]}),(0,K.jsxs)(`div`,{className:`relative`,ref:I,children:[(0,K.jsx)(`input`,{type:`text`,value:b?E:e.subtype,onChange:e=>{D(e.target.value),x(!0)},onFocus:()=>{x(!0),D(``)},placeholder:`Basic, Matte, Silk...`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`}),(0,K.jsx)(es,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),b&&(0,K.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[B.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:m(`inventory.noResults`)}):B.map(n=>(0,K.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.subtype===n?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{t(`subtype`,n),x(!1),D(``)},children:n},n)),E&&!oK.some(e=>e.toLowerCase()===E.toLowerCase().trim())&&(0,K.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{t(`subtype`,E),x(!1),D(``)},children:m(`inventory.useCustomBrand`,{brand:E})})]})]}),p?.subtype&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-400`,children:p.subtype})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:m(`inventory.labelWeight`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{type:`number`,className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:A,min:0,onFocus:()=>N(!0),onChange:e=>j(e.target.value),onBlur:()=>{N(!1);let n=A.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0){j(String(e.label_weight));return}let i=Math.round(r);t(`label_weight`,i),j(String(i))}}),(0,K.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]})]}),u&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:m(`inventory.quantity`)}),(0,K.jsx)(`input`,{type:`number`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:d,min:1,max:100,onChange:e=>{f(Math.max(1,Math.min(100,parseInt(e.target.value)||1)))}})]})]})}function lVe(e){let t=e.split(/[\s,]+/).map(e=>e.trim().replace(/^#/,``)).filter(Boolean),n=[],r=[];for(let e of t)(e.length===6||e.length===8)&&/^[0-9a-fA-F]+$/.test(e)?n.push(e.toLowerCase()):r.push(e);return{value:n.join(`,`),invalid:r}}function Z7({formData:e,updateField:t,recentColors:n,onColorUsed:r,catalogColors:i}){let{t:a}=G(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(``),u=(e.rgba.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),d=u.substring(0,6),f=u.substring(6,8)===`00`,[p,m]=(0,y.useState)(f?u:d);(0,y.useEffect)(()=>{m(f?u:d)},[d,u,f]);let h=e=>u===(e.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),g=e=>Wd(e),_=(e,n,i,a)=>{let o=e.replace(`#`,``).toUpperCase();if(t(`rgba`,o.length===8?o:o+`FF`),t(`color_name`,n),i!==void 0){let e=i??``;w(e),E([]),D.current=e,t(`extra_colors`,e)}a!==void 0&&t(`effect_type`,a??``),r({name:n,hex:e})},v=(0,y.useMemo)(()=>{if(i.length===0)return[];let t=e.brand?.trim(),n=e.material?.toLowerCase().trim(),r=e.subtype?.toLowerCase().trim();if(!t&&!n)return[];let a=t?t.toLowerCase().split(/[\s\-_]+/).filter(e=>e.length>=2):[],o=e=>{if(a.length===0)return!0;let t=e.toLowerCase();return a.some(e=>t.includes(e))};if(t&&!n){let e=i.filter(e=>o(e.manufacturer));if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}))}let s=n&&r?`${n} ${r}`:``;if(s){let e=i.filter(e=>o(e.manufacturer)&&e.material?.toLowerCase()===s);if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}));let t=s.replace(/\+$/,``);if(t!==s){let e=i.filter(e=>o(e.manufacturer)&&e.material?.toLowerCase()===t);if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0}))}}if(n){let e=i.filter(e=>o(e.manufacturer)&&(!e.material||e.material.toLowerCase().startsWith(n)));if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}))}return[]},[i,e.brand,e.material,e.subtype]),b=(0,y.useMemo)(()=>{if(!c)return v;if(v.length===0)return[];let e=c.toLowerCase();return v.filter(t=>t.name.toLowerCase().includes(e)||(t.manufacturer?.toLowerCase().includes(e)??!1)||(t.material?.toLowerCase().includes(e)??!1))},[c,v]),x=v.length>0,S=(0,y.useMemo)(()=>c?cK.filter(e=>e.name.toLowerCase().includes(c.toLowerCase())):o?cK:sK,[c,o]),[C,w]=(0,y.useState)(e.extra_colors),[T,E]=(0,y.useState)([]),D=(0,y.useRef)(e.extra_colors);(0,y.useEffect)(()=>{e.extra_colors!==D.current&&(w(e.extra_colors),E([]),D.current=e.extra_colors)},[e.extra_colors]);let O=(0,y.useMemo)(()=>G5({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`bar`}),[e.rgba,e.extra_colors,e.effect_type,e.subtype]),k=e=>{if(w(e),!e.trim()){E([]),D.current=``,t(`extra_colors`,``);return}let{value:n,invalid:r}=lVe(e);E(r),D.current=n,t(`extra_colors`,n)};return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`div`,{className:`h-10 rounded-lg border border-bambu-dark-tertiary`,style:O,"data-testid":`color-preview-banner`}),n.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-bambu-gray shrink-0`,children:[(0,K.jsx)(_s,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{children:a(`inventory.recentColors`)})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:n.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(e.hex),title:e.name},e.hex))})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),(0,K.jsx)(`input`,{type:`text`,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.searchColors`),value:c,onChange:e=>l(e.target.value)})]}),x?(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:c?a(`inventory.searchResults`):`${e.brand}${e.material?` ${e.material}`:``}`}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[b.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name,e.extra_colors,e.effect_type),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(e.hex),title:e.manufacturer&&e.material?`${e.name} (${e.manufacturer} — ${e.material})`:e.manufacturer?`${e.name} (${e.manufacturer})`:e.name,children:(0,K.jsx)(`span`,{className:`absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white`,children:e.manufacturer&&e.material?`${e.name} (${e.manufacturer} — ${e.material})`:e.manufacturer?`${e.name} (${e.manufacturer})`:e.name})},`${e.hex}-${e.name}-${e.manufacturer??``}`)),b.length===0&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:a(`inventory.noColorsFound`)})]})]}):(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:a(c?`inventory.searchResults`:o?`inventory.allColors`:`inventory.commonColors`)}),!c&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>s(!o),className:`flex items-center gap-1 hover:text-white transition-colors`,children:o?(0,K.jsxs)(K.Fragment,{children:[a(`inventory.showLess`),` `,(0,K.jsx)(rs,{className:`w-3 h-3`})]}):(0,K.jsxs)(K.Fragment,{children:[a(`inventory.showAll`),` `,(0,K.jsx)(es,{className:`w-3 h-3`})]})})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[S.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(e.hex),title:e.name,children:(0,K.jsx)(`span`,{className:`absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white`,children:e.name})},e.hex)),S.length===0&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:a(`inventory.noColorsFound`)})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.colorName`)}),(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 text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.colorNamePlaceholder`),value:e.color_name,onChange:e=>t(`color_name`,e.target.value)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.hexColor`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`,children:`#`}),(0,K.jsx)(`input`,{type:`text`,className:`w-full pl-7 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono uppercase focus:outline-none focus:border-bambu-green`,placeholder:`RRGGBB`,value:p.toUpperCase(),onChange:e=>{let n=e.target.value.replace(`#`,``).replace(/[^0-9A-Fa-f]/g,``).toUpperCase(),r=n.length>8?n.substring(0,8):n;m(r),r.length===6?t(`rgba`,r+`FF`):r.length===8&&t(`rgba`,r)},onBlur:()=>{if(p.length===7){let e=p+`0`;m(e),t(`rgba`,e)}else if(p.length>0&&p.length<6){let e=p.padEnd(6,`0`);m(e),t(`rgba`,e+`FF`)}}})]}),(0,K.jsx)(`input`,{type:`color`,className:`w-11 h-[38px] rounded-lg cursor-pointer border border-bambu-dark-tertiary shrink-0 bg-transparent`,value:`#${d}`,onChange:e=>{t(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`)},title:a(`inventory.pickColor`)})]})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-2 border-t border-bambu-dark-tertiary/50`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.extraColorsLabel`)}),(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 text-sm font-mono placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.extraColorsPlaceholder`),value:C,onChange:e=>k(e.target.value),"data-testid":`extra-colors-input`}),T.length>0&&(0,K.jsx)(`p`,{className:`text-xs text-red-400 mt-1`,children:a(`inventory.extraColorsInvalid`,{tokens:T.join(`, `)})}),!T.length&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:a(`inventory.extraColorsHint`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1 flex items-center gap-1.5`,children:[(0,K.jsx)(Ql,{className:`w-3.5 h-3.5`}),a(`inventory.colorEffectLabel`)]}),(0,K.jsxs)(`div`,{className:`flex gap-2 items-stretch`,children:[(0,K.jsx)(`select`,{className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:e.effect_type,onChange:e=>t(`effect_type`,e.target.value),"data-testid":`effect-type-select`,children:H5.map(e=>(0,K.jsx)(`option`,{value:e.value,children:a(e.labelKey)},e.value||`none`))}),(0,K.jsx)(K5,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`preview`,className:`w-10 h-10`,shape:`square`})]})]})]})]})}function uVe({catalog:e,value:t,onChange:n,catalogId:r,onCatalogIdChange:i}){let{t:a}=G(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(``),u=(0,y.useRef)(null),d=(0,y.useRef)(null);(0,y.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&s(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]),(0,y.useEffect)(()=>{if(e.length===0)return;let n=e.filter(e=>e.weight===t);if(r){let n=e.find(e=>e.id===r);if(n&&n.weight===t)return}n.length===1?i(n[0].id):n.length===0&&r!==null&&i(null)},[t,e,r,i]);let f=(0,y.useMemo)(()=>{if(!c)return e;let t=c.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.weight.toString().includes(t))},[e,c]),p=(0,y.useMemo)(()=>e.filter(e=>e.weight===t),[e,t]),m=(0,y.useMemo)(()=>{if(o)return c;if(r){let t=e.find(e=>e.id===r);if(t)return t.name}return p.length>0?p[0].name:``},[o,c,r,e,p]);return(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(kl,{className:`w-3.5 h-3.5 text-bambu-gray`}),a(`inventory.coreWeight`)]})}),(0,K.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 relative`,ref:u,children:[(0,K.jsx)(`input`,{ref:d,type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.searchSpoolWeight`),value:m,onFocus:()=>{s(!0),l(``)},onChange:e=>{l(e.target.value),s(!0)}}),o&&(0,K.jsx)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:f.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:a(`inventory.noResults`)}):f.map(e=>(0,K.jsxs)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex justify-between items-center ${(r?e.id===r:e.weight===t)?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{i(e.id),n(e.weight),s(!1),l(``)},children:[(0,K.jsx)(`span`,{className:`truncate`,children:e.name}),(0,K.jsxs)(`span`,{className:`font-mono text-xs text-bambu-gray ml-2 shrink-0`,children:[e.weight,`g`]})]},e.id))})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,K.jsx)(`input`,{type:`number`,className:`w-16 px-2 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm text-center font-mono focus:outline-none focus:border-bambu-green`,value:t,min:0,max:2e3,onChange:e=>{let t=parseInt(e.target.value);!isNaN(t)&&t>=0&&n(t)}}),(0,K.jsx)(`span`,{className:`text-bambu-gray text-sm`,children:`g`})]})]})]})}function Q7({formData:e,updateField:t,spoolCatalog:n,currencySymbol:r,availableCategories:i,availableLocations:a=[],onCreateLocation:o,globalLowStockThreshold:s,spoolmanMode:c=!1}){let{t:l}=G(),{showToast:u}=xd(),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(``),[S,C]=(0,y.useState)(!1),w=Math.max(0,e.label_weight-e.weight_used),T=e.core_weight+w;return(0,y.useEffect)(()=>{p||f(String(T))},[p,T]),(0,y.useEffect)(()=>{_||g(String(w))},[_,w]),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[c?(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray px-1`,children:l(`inventory.spoolWeightManagedBySpoolman`)}):(0,K.jsx)(uVe,{catalog:n,value:e.core_weight,onChange:e=>t(`core_weight`,e),catalogId:e.core_weight_catalog_id,onCatalogIdChange:e=>t(`core_weight_catalog_id`,e)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.currentWeight`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(`input`,{type:`number`,value:h,min:0,max:e.label_weight,onFocus:()=>v(!0),onChange:e=>{g(e.target.value)},onBlur:()=>{v(!1);let n=h.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0||r>e.label_weight){g(String(w));return}let i=Math.round(r);t(`weight_used`,Math.max(0,e.label_weight-i)),g(String(i))},className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,K.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:[`/ `,e.label_weight,`g`]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.measuredWeight`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(`input`,{type:`number`,value:d,min:0,onFocus:()=>m(!0),onChange:e=>{f(e.target.value)},onBlur:()=>{m(!1);let n=d.trim(),r=Number(n),i=e.core_weight,a=e.core_weight+e.label_weight;if(!n||!Number.isFinite(r)||ra){u(l(`inventory.measuredWeightError`,{min:i,max:a}),`error`),f(String(T));return}let o=Math.round(r),s=Math.max(0,Math.min(e.label_weight,o-e.core_weight));t(`weight_used`,Math.max(0,e.label_weight-s)),f(String(o))},className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,K.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:[`/ `,e.core_weight+e.label_weight,`g`]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.costPerKg`,`Cost per kg`)}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:r}),(0,K.jsx)(`input`,{type:`number`,value:e.cost_per_kg??``,min:0,step:.01,placeholder:`0.00`,onChange:e=>{t(`cost_per_kg`,e.target.value===``?null:parseFloat(e.target.value))},style:{paddingLeft:`${Math.max(2,r.length*.6+1)}rem`},className:`w-full py-2 pr-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`})]})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-category`,children:l(`inventory.category`)}),(0,K.jsx)(`input`,{id:`spool-category`,type:`text`,list:`spool-category-options`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:l(`inventory.categoryPlaceholder`),value:e.category,maxLength:50,onChange:e=>t(`category`,e.target.value)}),i.length>0&&(0,K.jsx)(`datalist`,{id:`spool-category-options`,children:i.map(e=>(0,K.jsx)(`option`,{value:e},e))})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-low-stock-threshold`,children:l(`inventory.lowStockThresholdOverride`)}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(`input`,{id:`spool-low-stock-threshold`,type:`number`,className:`w-full px-3 py-2 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`,placeholder:String(s),value:e.low_stock_threshold_pct??``,min:1,max:99,step:1,onChange:e=>{let n=e.target.value;if(n===``){t(`low_stock_threshold_pct`,null);return}let r=Number(n);Number.isFinite(r)&&t(`low_stock_threshold_pct`,Math.min(99,Math.max(1,Math.round(r))))}}),(0,K.jsx)(`span`,{className:`absolute right-3 top-1/2 -translate-y-1/2 text-xs text-bambu-gray pointer-events-none`,children:`%`})]})}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:l(`inventory.lowStockThresholdOverrideHelp`,{global:s})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.note`)}),(0,K.jsx)(`textarea`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green resize-none min-h-[80px]`,placeholder:l(`inventory.notePlaceholder`),value:e.note,onChange:e=>t(`note`,e.target.value)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-storage-location`,children:l(`inventory.storageLocation`)}),(0,K.jsxs)(`select`,{id:`spool-storage-location`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:e.location_id??``,onChange:e=>{let n=e.target.value;if(!n){t(`location_id`,null);return}t(`location_id`,Number(n))},children:[(0,K.jsx)(`option`,{value:``,children:l(`inventory.storageLocationNone`)}),a.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),o&&(0,K.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,maxLength:255,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:l(`locations.createPlaceholder`),value:b,onChange:e=>x(e.target.value)}),(0,K.jsx)(`button`,{type:`button`,className:`px-3 py-2 text-sm rounded-lg bg-bambu-dark-tertiary text-white hover:bg-bambu-gray-dark disabled:opacity-50`,disabled:!b.trim()||S,onClick:async()=>{let e=b.trim();if(!(!e||!o)){C(!0);try{let n=await o(e);n&&(t(`location_id`,n.id),x(``))}finally{C(!1)}}},children:l(`locations.addShort`)})]})]})]})}function dVe({filaments:e,isLoading:t,selectedId:n,onSelect:r}){let{t:i}=G(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(``),l=(0,y.useRef)(null),u=(0,y.useRef)(null),d=(0,y.useMemo)(()=>e.find(e=>e.id===n)??null,[e,n]);(0,y.useEffect)(()=>{let e=e=>{l.current&&!l.current.contains(e.target)&&(o(!1),c(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let f=(0,y.useMemo)(()=>{let t=s.toLowerCase().trim();return t?e.filter(e=>e.name.toLowerCase().includes(t)||(e.material?.toLowerCase().includes(t)??!1)||(e.vendor?.name.toLowerCase().includes(t)??!1)||(e.color_name?.toLowerCase().includes(t)??!1)):e},[e,s]);(0,y.useEffect)(()=>{a&&u.current?.focus()},[a]);let p=()=>{o(!0),c(``)},m=e=>{r(e),o(!1),c(``)},h=e=>e?`#${e.replace(`#`,``)}`:`#808080`;return(0,K.jsxs)(`div`,{ref:l,className:`relative`,children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:i(`inventory.pickFromSpoolmanCatalog`)}),(0,K.jsxs)(`button`,{type:`button`,onClick:p,className:`w-full flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-left focus:outline-none focus:border-bambu-green hover:border-bambu-gray transition-colors`,children:[t?(0,K.jsx)(X,{className:`w-4 h-4 text-bambu-gray animate-spin shrink-0`}):d?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:{backgroundColor:h(d.color_hex)},"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,K.jsxs)(`span`,{className:`text-white text-sm truncate flex-1`,children:[d.vendor?.name?`${d.vendor.name} — `:``,d.name]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(cl,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,K.jsx)(`span`,{className:`text-bambu-gray text-sm flex-1`,children:i(`inventory.spoolmanFilamentCatalog`)})]}),(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray shrink-0 ml-auto`})]}),a&&(0,K.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl`,children:[(0,K.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,K.jsx)(`input`,{ref:u,type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:i(`inventory.pickFromSpoolmanCatalog`),className:`w-full px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})}),(0,K.jsx)(`ul`,{className:`max-h-56 overflow-y-auto py-1`,children:t?(0,K.jsxs)(`li`,{className:`flex items-center justify-center gap-2 py-4 text-bambu-gray text-sm`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),(0,K.jsx)(`span`,{children:i(`common.loading`,`Loading…`)})]}):f.length===0?(0,K.jsx)(`li`,{className:`py-4 text-center text-bambu-gray text-sm`,children:i(`inventory.noSpoolmanFilaments`)}):f.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>m(e),className:`w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors ${e.id===n?`bg-bambu-dark-tertiary`:``}`,children:[(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:{backgroundColor:h(e.color_hex)},"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,K.jsxs)(`span`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`span`,{className:`block text-white text-sm truncate`,children:[e.vendor?.name?`${e.vendor.name} — `:``,e.name]}),(0,K.jsxs)(`span`,{className:`block text-bambu-gray text-xs truncate`,children:[[e.material,e.color_name].filter(Boolean).join(` · `),e.weight?` · ${e.weight}g`:``]})]})]})},e.id))})]})]})}function $7({formData:e,printersWithCalibrations:t,selectedProfiles:n,setSelectedProfiles:r,expandedPrinters:i,setExpandedPrinters:a}){let{t:o}=G(),s=e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},c=(e,t,n)=>{let i=`${e}:${t}:${n??`null`}`,a=`${e}:${n??`null`}`;r(e=>{let t=new Set(e);if(t.has(i))t.delete(i);else{for(let e of Array.from(t)){let n=e.split(`:`);`${n[0]}:${n[2]}`===a&&t.delete(e)}t.add(i)}return t})},l=()=>{let n=new Set;for(let{printer:r,calibrations:i}of t){if(!r.connected)continue;let t=i.filter(t=>vK(t,e)),a=new Map;for(let e of t){let t=`${e.extruder_id??`null`}`;a.has(t)||a.set(t,[]),a.get(t).push(e)}for(let[e,t]of a)if(t.length>0){let i=[...t].sort((e,t)=>t.k_value-e.k_value)[0];n.add(`${r.id}:${i.cali_idx}:${e}`)}}r(n)};if(!e.material)return(0,K.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:o(`inventory.selectMaterialFirst`)})});if(t.length===0)return(0,K.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:o(`inventory.noPrintersConfigured`)})});let u=t.reduce((t,{printer:n,calibrations:r})=>n.connected?t+r.filter(t=>vK(t,e)).length:t,0),d=(e,t)=>{let r=`${e.id}:${t.cali_idx}:${t.extruder_id??`null`}`,i=n.has(r);return(0,K.jsxs)(`label`,{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-all border ${i?`bg-bambu-green/10 border-bambu-green/30`:`bg-bambu-dark border-transparent hover:bg-bambu-dark/80`}`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:i,onChange:()=>c(String(e.id),t.cali_idx,t.extruder_id),className:`w-4 h-4 rounded border-bambu-dark-tertiary text-bambu-green focus:ring-bambu-green`}),(0,K.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,K.jsx)(`span`,{className:`text-sm font-medium ${i?`text-bambu-green`:`text-white`}`,children:t.name||t.filament_id})}),(0,K.jsx)(`div`,{className:`flex items-center gap-2 shrink-0`,children:(0,K.jsxs)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray`,children:[`K=`,t.k_value.toFixed(3)]})})]},`${t.cali_idx}-${t.extruder_id}`)};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[o(`inventory.matchingFilter`),`: `,e.brand||o(`inventory.anyBrand`),` / `,e.material,` / `,e.subtype||o(`inventory.anyVariant`)]}),u>0&&(0,K.jsxs)(`button`,{type:`button`,onClick:l,className:`flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors`,children:[(0,K.jsx)(Ql,{className:`w-3.5 h-3.5`}),o(`inventory.autoSelect`),` (`,u,`)`]})]}),(0,K.jsx)(`div`,{className:`space-y-3`,children:t.map(({printer:t,calibrations:n})=>{let r=i.has(String(t.id)),a=n.filter(t=>vK(t,e)),c=a.length,l=a.some(e=>e.extruder_id!==void 0&&e.extruder_id!==null&&e.extruder_id>0),u=a.filter(e=>e.extruder_id===1),f=a.filter(e=>e.extruder_id===0||e.extruder_id===void 0||e.extruder_id===null);return(0,K.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>s(String(t.id)),className:`w-full px-4 py-3 flex items-center justify-between bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[r?(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray`}):(0,K.jsx)(ts,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),c>0?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:[c,` `,o(c===1?`inventory.match`:`inventory.matches`)]}):(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray`,children:o(`inventory.noMatches`)})]}),(0,K.jsx)(`span`,{className:`text-xs px-2 py-1 rounded-full ${t.connected?`bg-green-500/20 text-green-500`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.connected?o(`inventory.connected`):o(`inventory.offline`)})]}),r&&(0,K.jsx)(`div`,{className:`px-4 py-3 space-y-3 bg-bambu-dark border-t border-bambu-dark-tertiary`,children:t.connected?c===0?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:o(`inventory.noKProfilesMatch`)}):l?(0,K.jsxs)(K.Fragment,{children:[u.length>0&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.leftNozzle`)}),(0,K.jsx)(`div`,{className:`space-y-2`,children:u.map(e=>d(t,e))})]}),f.length>0&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.rightNozzle`)}),(0,K.jsx)(`div`,{className:`space-y-2`,children:f.map(e=>d(t,e))})]})]}):(0,K.jsx)(`div`,{className:`space-y-2`,children:a.map(e=>d(t,e))}):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:o(`inventory.printerOffline`)})})]},t.id)})}),n.size>0&&(0,K.jsx)(`div`,{className:`p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:(0,K.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,K.jsx)(`span`,{className:`font-semibold`,children:n.size}),` `,o(`inventory.profilesSelected`)]})})]})}function fVe(e){let t=mf(e);return t?t.toLocaleDateString(`en-GB`,{day:`2-digit`,month:`2-digit`,year:`2-digit`})+` `+t.toLocaleTimeString(`en-GB`,{hour:`2-digit`,minute:`2-digit`}):``}var pVe={completed:`text-bambu-green`,failed:`text-red-400`,aborted:`text-yellow-400`};function mVe({spoolId:e}){let{t}=G(),n=Qa(),{showToast:r}=xd(),{data:i,isLoading:a}=q({queryKey:[`spool-usage`,e],queryFn:()=>Q.getSpoolUsageHistory(e)}),o=J({mutationFn:()=>Q.clearSpoolUsageHistory(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`spool-usage`,e]}),r(t(`inventory.historyCleared`),`success`)}});return a?(0,K.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,K.jsx)(X,{className:`w-5 h-5 animate-spin text-bambu-green`})}):!i||i.length===0?(0,K.jsxs)(`div`,{className:`text-center py-4 text-bambu-gray text-sm`,children:[(0,K.jsx)(_s,{className:`w-5 h-5 mx-auto mb-2 opacity-50`}),t(`inventory.noUsageHistory`)]}):(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t(`inventory.usageHistory`)}),(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>o.mutate(),disabled:o.isPending,className:`text-xs text-bambu-gray hover:text-red-400`,children:[(0,K.jsx)(hu,{className:`w-3 h-3 mr-1`}),t(`inventory.clearHistory`)]})]}),(0,K.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:i.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-2 rounded bg-bambu-dark/50 text-xs`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:fVe(e.created_at)}),e.print_name&&(0,K.jsx)(`span`,{className:`text-white ml-2 truncate`,title:e.print_name,children:e.print_name})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0 ml-2`,children:[(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[e.weight_used.toFixed(1),`g`]}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_used,`%)`]}),(0,K.jsx)(`span`,{className:pVe[e.status]||`text-bambu-gray`,children:e.status})]})]},e.id))})]})}var e9=[`inventory-locations`];function t9(e){return e.invalidateQueries({queryKey:e9})}function n9(e,t){return Promise.all([e.invalidateQueries({queryKey:[...t]}),t9(e)])}var r9={tag_uid:null,tray_uuid:null,tag_type:null,data_origin:null};function hVe({isOpen:e,onClose:t,spool:n,mode:r,printersWithCalibrations:i=[],currencySymbol:a,onSpoolsCreated:o,spoolmanMode:s=!1,spoolsQueryKey:c=[`inventory-spools`]}){let{t:l}=G(),u=Qa(),{showToast:d}=xd(),f=()=>n9(u,c),p=r===`edit`,m=r===`copy`,[h,g]=(0,y.useState)(J7),[_,v]=(0,y.useState)({}),[b,x]=(0,y.useState)(`filament`),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(1),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)([]),[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)([]),[B,V]=(0,y.useState)([]),[ee,H]=(0,y.useState)([]),[te,ne]=(0,y.useState)([]),[re,U]=(0,y.useState)([]),[ie,ae]=(0,y.useState)([]),[W,oe]=(0,y.useState)([]),[se,ce]=(0,y.useState)(new Set),[le,ue]=(0,y.useState)(new Set),de=i.length>0?i:W,fe=se.size,{data:pe=[],isLoading:me,error:he}=q({queryKey:[`spoolman-inventory-filaments`],queryFn:()=>Q.getSpoolmanInventoryFilaments(),enabled:s&&e,staleTime:6e4,retry:!1});(0,y.useEffect)(()=>{ae(mK())},[]),(0,y.useEffect)(()=>{let t=!1;return e&&((async()=>{N(!0);try{let[e,n]=await Promise.allSettled([(async()=>(await Q.getCloudStatus()).is_authenticated?{connected:!0,presets:await Q.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await Q.orcaCloudStatus()).connected?{connected:!0,presets:(await Q.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(t)return;let r=e.status===`fulfilled`&&e.value.connected,i=n.status===`fulfilled`&&n.value.connected,a=e.status===`fulfilled`?e.value.presets:[],o=n.status===`fulfilled`?n.value.presets:[];j(r||i),F([...a,...o])}catch(e){if(t)return;console.error(`Failed to fetch cloud presets:`,e),j(!1)}finally{t||N(!1)}})(),s||Q.getSpoolCatalog().then(z).catch(console.error),Q.getColorCatalog().then(U).catch(console.error),Q.getLocalPresets().then(e=>H(e.filament)).catch(console.error),Q.getBuiltinFilaments().then(ne).catch(console.error),Q.getLocations().then(e=>V(e.map(e=>({id:e.id,name:e.name})))).catch(console.error),i.length===0&&(async()=>{try{let e=await Q.getPrinters(),t=await Promise.all(e.map(e=>Q.getPrinterStatus(e.id).catch(()=>null))),n=[];for(let r=0;r({cali_idx:e.slot_id,filament_id:e.filament_id,setting_id:e.setting_id||``,name:e.name,k_value:parseFloat(e.k_value)||0,n_coef:parseFloat(e.n_coef)||0,extruder_id:e.extruder_id,nozzle_diameter:e.nozzle_diameter}))}catch{}n.push({printer:{...i,connected:a},calibrations:o})}oe(n)}catch(e){console.error(`Failed to fetch printer calibrations:`,e)}})()),()=>{t=!0}},[e,i.length]);let ge=(0,y.useMemo)(()=>fK(P,new Set,ee,te),[P,ee,te]),_e=(0,y.useMemo)(()=>{let e=dK(P,ee),t=re.map(e=>e.manufacturer?.trim()).filter(e=>!!e),n=new Set([...e,...t]);return Array.from(n).sort((e,t)=>e.localeCompare(t))},[P,ee,re]),ve=(0,y.useMemo)(()=>{let e=re.map(e=>e.material?.trim()).filter(e=>!!e),t=new Set([...aK,...e]);return Array.from(t).sort((e,t)=>e.localeCompare(t))},[re]),ye=(0,y.useMemo)(()=>{let e=[];for(let t of re){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of P){let n=uK(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of ee){let n=uK(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[P,re,ee]),be=(0,y.useMemo)(()=>{let e=new Map;for(let t of ye){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[ye]),xe=(0,y.useMemo)(()=>{let e=new Map;for(let t of ye){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[ye]),Se=(0,y.useMemo)(()=>{if(!h.material)return _e;let e=h.material.toLowerCase(),t=xe.get(e);return!t||t.size===0?_e:_e.filter(e=>t.has(e.toLowerCase()))},[_e,h.material,xe]),Ce=(0,y.useMemo)(()=>{if(!h.brand)return ve;let e=h.brand.toLowerCase(),t=be.get(e);return!t||t.size===0?ve:ve.filter(e=>t.has(e.toLowerCase()))},[ve,h.brand,be]),we=(0,y.useMemo)(()=>pK(h.slicer_filament,ge),[h.slicer_filament,ge]);(0,y.useEffect)(()=>{if(e){if(n){let e=n.rgba&&/^[0-9A-Fa-f]{8}$/.test(n.rgba)?n.rgba:`808080FF`;if(g({material:n.material||``,subtype:n.subtype||``,brand:n.brand||``,color_name:n.color_name_is_synthesized?``:n.color_name||``,rgba:e,extra_colors:n.extra_colors||``,effect_type:n.effect_type||``,label_weight:n.label_weight||1e3,core_weight:n.core_weight||250,core_weight_catalog_id:n.core_weight_catalog_id??null,weight_used:m?0:n.weight_used||0,slicer_filament:n.slicer_filament||``,note:n.note||``,cost_per_kg:n.cost_per_kg??null,category:n.category||``,low_stock_threshold_pct:n.low_stock_threshold_pct??null,location_id:n.location_id??null,spoolman_filament_id:null}),L(n.slicer_filament_name||n.slicer_filament||``),n.k_profiles&&n.k_profiles.length>0){let e=new Set;for(let t of n.k_profiles)t.cali_idx!==null&&t.cali_idx!==void 0&&e.add(`${t.printer_id}:${t.cali_idx}:${t.extruder??`null`}`);ce(e)}else ce(new Set)}else g(J7),L(``),ce(new Set),D(!1),k(1);v({}),x(`filament`),C(!1),T(!1)}},[e,n,r,m]),(0,y.useEffect)(()=>{if(!e||!n||w||h.location_id!=null)return;let t=n.storage_location?.trim();if(!t||B.length===0)return;let r=B.find(e=>e.name.toLowerCase()===t.toLowerCase());r&&g(e=>e.location_id===r.id?e:{...e,location_id:r.id})},[e,n,B,h.location_id,w]),(0,y.useEffect)(()=>{e&&de.length>0&&ue(new Set(de.map(e=>String(e.printer.id))))},[e,de]);let Te=(e,t)=>{let n=cVe.has(e);s&&n&&h.spoolman_filament_id!==null&&d(l(`inventory.spoolmanFilamentUnlinked`),`info`),g(r=>({...r,[e]:t,...s&&n&&r.spoolman_filament_id!==null?{spoolman_filament_id:null}:{}})),e===`weight_used`&&C(!0),e===`location_id`&&T(!0),_[e]&&v(t=>({...t,[e]:void 0}))},Ee=e=>{let t=e.material||``,n=e.name||``,r=t&&n.startsWith(t)?n.slice(t.length).trim():n,i=(e.color_hex??``).replace(`#`,``).toUpperCase(),a=/^[0-9A-F]{6}$/.test(i)?i:`808080`;g(n=>({...n,spoolman_filament_id:e.id,material:t,subtype:r,brand:e.vendor?.name||``,rgba:`${a}FF`,color_name:e.color_name||``,label_weight:e.weight??n.label_weight})),d(l(`inventory.spoolmanFilamentSelected`),`success`)},De=e=>{ae(t=>hK(e,t))},Oe=J({mutationFn:e=>s?Q.createSpoolmanInventorySpool(e):Q.createSpool(e),onSuccess:async e=>{e?.id&&!await Be(e.id)||(await f(),o&&o([e]),d(l(`inventory.spoolCreated`),`success`),t())},onError:e=>{e instanceof zu&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),ke=J({mutationFn:({data:e,qty:t})=>s?Q.bulkCreateSpoolmanInventorySpools(e,t):Q.bulkCreateSpools(e,t),onSuccess:async e=>{let n=s&&`created`in e?e:null,r=n?n.created:e;if(se.size>0)for(let e of r)await Be(e.id);await f(),o&&o(r),n&&n.failed_count>0?d(l(`inventory.spoolsPartiallyCreated`,{created:r.length,total:n.requested_count}),`warning`):d(l(`inventory.spoolsCreated`,{count:r.length}),`success`),t()},onError:e=>{e instanceof zu&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),Ae=J({mutationFn:e=>s?Q.updateSpoolmanInventorySpool(n.id,e):Q.updateSpool(n.id,e),onSuccess:async()=>{n?.id&&!await Be(n.id)||(await f(),d(l(`inventory.spoolUpdated`),`success`),t())},onError:e=>{e instanceof zu&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),je=J({mutationFn:()=>s?Q.updateSpoolmanInventorySpool(n.id,r9):Q.updateSpool(n.id,r9),onSuccess:async()=>{await f(),d(l(`inventory.rfidCleared`,`RFID tag cleared`),`success`),t()},onError:e=>{e instanceof zu&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.tagClearFailed`),`error`)}}),{data:Me}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),enabled:e&&p&&!s}),{data:Ne}=q({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:e&&p&&s}),Pe=(()=>{if(n)return s?Ne?.find(e=>e.spoolman_spool_id===n.id):Me?.find(e=>e.spool_id===n.id)})(),{data:Fe}=q({queryKey:[`inventory-spools`],queryFn:()=>Q.getSpools(!0),enabled:e}),{data:Ie}=q({queryKey:[`settings`],queryFn:Q.getSettings,enabled:e}),Le=(()=>{let e=new Set;for(let t of Fe??[]){let n=t.category?.trim();n&&e.add(n)}return Array.from(e).sort((e,t)=>e.localeCompare(t))})(),Re=Ie?.low_stock_threshold??20,ze=J({mutationFn:async()=>{if(!Pe)throw Error(`No assignment`);if(s){if(!n)throw Error(`No spool`);await Q.unassignSpoolmanSlot(n.id);return}await Q.unassignSpool(Pe.printer_id,Pe.ams_id,Pe.tray_id)},onSuccess:async()=>{s?(await u.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),await u.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})):await u.invalidateQueries({queryKey:[`spool-assignments`]}),d(l(`inventory.unassignSuccess`,`Spool unassigned`),`success`),t()},onError:e=>{d(e.message,`error`)}}),Be=async e=>{let t=s?Q.saveSpoolmanKProfiles:Q.saveSpoolKProfiles;if(se.size===0)try{return await t(e,[]),!0}catch(e){return console.error(`Failed to save K-profiles:`,e),d(l(`inventory.kProfileSaveFailed`),`warning`),!1}let n=[],r=0;for(let e of se){let[t,i,a]=e.split(`:`),o=parseInt(t),s=parseInt(i),c=a===`null`?0:parseInt(a),l=de.find(e=>e.printer.id===o);if(l){let e=l.calibrations.find(e=>e.cali_idx===s);e?n.push({printer_id:o,extruder:c,nozzle_diameter:e.nozzle_diameter||`0.4`,k_value:e.k_value,name:e.name||null,cali_idx:e.cali_idx,setting_id:e.setting_id||null}):r++}else r++}if(r>0)return console.error(`saveKProfiles: ${r} profile key(s) could not be resolved`,Array.from(se)),d(l(`inventory.kProfileSaveFailed`),`warning`),!1;if(n.length>0)try{return await t(e,n),!0}catch(e){return console.error(`Failed to save K-profiles:`,e),d(l(`inventory.kProfileSaveFailed`),`warning`),!1}return!0};if((0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let Ve=()=>{let e=Y7(h,E,s);if(!e.isValid){v(e.errors),(e.errors.slicer_filament||e.errors.material||e.errors.brand||e.errors.subtype)&&x(`filament`);return}let t=we?.displayName||I||null,n={material:h.material||null,subtype:h.subtype||null,brand:h.brand||null,color_name:h.color_name||null,rgba:h.rgba||null,extra_colors:h.extra_colors||null,effect_type:h.effect_type||null,label_weight:h.label_weight,...s?{}:{core_weight:h.core_weight,core_weight_catalog_id:h.core_weight_catalog_id},slicer_filament:h.slicer_filament||null,slicer_filament_name:t,nozzle_temp_min:null,nozzle_temp_max:null,note:h.note||null,cost_per_kg:h.cost_per_kg,category:h.category.trim()||null,low_stock_threshold_pct:h.low_stock_threshold_pct,...s?{spoolman_filament_id:h.spoolman_filament_id}:{}};(!p||S)&&(n.weight_used=h.weight_used),(!p||w)&&(n.location_id=h.location_id),p?Ae.mutate(n):O>1?ke.mutate({data:n,qty:O}):Oe.mutate(n)},He=Oe.isPending||ke.isPending||Ae.isPending||je.isPending||ze.isPending;return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,children:[(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)(`h2`,{className:`text-lg font-semibold text-white flex items-baseline gap-2`,children:[l(p?`inventory.editSpool`:m?`inventory.copySpool`:`inventory.addSpool`),p&&n&&(0,K.jsxs)(`span`,{className:`text-sm font-mono text-bambu-gray`,children:[`#`,n.id]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),r===`create`&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Iu,{className:`w-4 h-4 text-amber-400`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:l(`inventory.quickAdd`)})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{D(!E),E||x(`filament`)},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${E?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${E?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsxs)(`button`,{onClick:()=>x(`filament`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${b===`filament`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(ll,{className:`w-4 h-4`}),l(`inventory.filamentInfoTab`)]}),!E&&(0,K.jsxs)(`button`,{onClick:()=>x(`pa-profile`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${b===`pa-profile`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(Po,{className:`w-4 h-4`}),l(`inventory.paProfileTab`),fe>0&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:fe})]})]}),(0,K.jsx)(`div`,{className:`p-4 overflow-y-auto flex-1`,style:{scrollbarGutter:`stable`},children:b===`filament`?(0,K.jsxs)(`div`,{className:`space-y-6`,children:[s&&!p&&(0,K.jsx)(`div`,{children:he?(0,K.jsx)(`p`,{className:`text-sm text-red-400 px-1`,children:l(`inventory.spoolmanCatalogLoadFailed`)}):(0,K.jsx)(dVe,{filaments:pe,isLoading:me,selectedId:h.spoolman_filament_id,onSelect:Ee})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.filamentInfo`)}),(0,K.jsx)(X7,{formData:h,updateField:Te,cloudAuthenticated:A,loadingCloudPresets:M,presetInputValue:I,setPresetInputValue:L,selectedPresetOption:we,filamentOptions:ge,availableBrands:Se,availableMaterials:Ce,quickAdd:E,quantity:O,onQuantityChange:k,errors:_})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.color`)}),(0,K.jsx)(Z7,{formData:h,updateField:Te,recentColors:ie,onColorUsed:De,catalogColors:re})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.additional`)}),(0,K.jsx)(Q7,{formData:h,updateField:Te,spoolCatalog:R,currencySymbol:a,availableCategories:Le,availableLocations:B,onCreateLocation:async e=>{try{let t=await Q.createLocation({name:e});return V(e=>[...e,{id:t.id,name:t.name}].sort((e,t)=>e.name.localeCompare(t.name))),await t9(u),{id:t.id,name:t.name}}catch(e){return console.error(e),d((e instanceof Error?e.message:l(`locations.saveFailed`))||l(`locations.saveFailed`),`error`),null}},globalLowStockThreshold:Re,spoolmanMode:s})]}),p&&n&&!s&&(0,K.jsx)(`div`,{children:(0,K.jsx)(mVe,{spoolId:n.id})})]}):(0,K.jsx)($7,{formData:h,updateField:Te,printersWithCalibrations:de,selectedProfiles:se,setSelectedProfiles:ce,expandedPrinters:le,setExpandedPrinters:ue})}),(0,K.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[p&&(0,K.jsxs)(`div`,{className:`flex gap-2 mr-auto`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:()=>je.mutate(),disabled:He||!n?.tag_uid,children:[(0,K.jsx)(su,{className:`w-4 h-4`}),l(`inventory.clearRfid`,`Clear RFID Tag`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>ze.mutate(),disabled:He||!Pe,children:[(0,K.jsx)(xu,{className:`w-4 h-4`}),l(`inventory.unassignSpool`,`Unassign`)]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 ml-auto`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,children:l(`common.cancel`)}),(0,K.jsx)($,{onClick:Ve,disabled:He,children:He?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),l(`common.saving`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),l(p?`common.save`:m?`inventory.copySpool`:`inventory.addSpool`)]})})]})]})]})]})}function gVe({isOpen:e,onClose:t,columns:n,defaultColumns:r,onSave:i}){let{t:a}=G(),[o,s]=(0,y.useState)(n),[c,l]=(0,y.useState)(null),u=(0,y.useRef)(null);if((0,y.useEffect)(()=>{e&&s(n.map(e=>({...e})))},[e,n]),(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let d=e=>{s(t=>t.map((t,n)=>n===e?{...t,visible:!t.visible}:t))},f=(e,t)=>{t<0||t>=o.length||s(n=>{let r=[...n],[i]=r.splice(e,1);return r.splice(t,0,i),r})},p=(e,t)=>{u.current=t,l(t),e.dataTransfer.effectAllowed=`move`},m=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=u.current;n!==null&&n!==t&&(f(n,t),u.current=t,l(t))},h=e=>{e.preventDefault()},g=()=>{u.current=null,l(null)},_=()=>{s(r.map(e=>({...e})))},v=()=>{i(o),t()},b=o.filter(e=>e.visible).length;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,K.jsx)(pd,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(hd,{className:`p-6 flex flex-col min-h-0`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:a(`inventory.configureColumns`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:[a(`inventory.configureColumnsDesc`),(0,K.jsxs)(`span`,{className:`ml-2 text-bambu-gray/60`,children:[`(`,b,` `,a(`inventory.of`),` `,o.length,` `,a(`inventory.visible`),`)`]})]}),(0,K.jsx)(`div`,{className:`space-y-1 overflow-y-auto flex-1 min-h-0 pr-1`,children:o.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg border transition-colors ${c===t?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-tertiary/50`} ${e.visible?``:`opacity-50`}`,draggable:!0,onDragStart:e=>p(e,t),onDragOver:e=>m(e,t),onDrop:h,onDragEnd:g,children:[(0,K.jsx)(`div`,{className:`cursor-grab text-bambu-gray/50 hover:text-bambu-gray`,children:(0,K.jsx)(gc,{className:`w-4 h-4`})}),(0,K.jsx)(`span`,{className:`flex-1 font-medium text-sm text-white`,children:e.label}),(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,K.jsx)(`button`,{onClick:()=>f(t,t-1),disabled:t===0,className:`p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed`,title:a(`inventory.moveUp`),children:(0,K.jsx)(rs,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>f(t,t+1),disabled:t===o.length-1,className:`p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed`,title:a(`inventory.moveDown`),children:(0,K.jsx)(es,{className:`w-4 h-4`})})]}),(0,K.jsx)(`button`,{onClick:()=>d(t),className:`p-1.5 rounded transition-colors ${e.visible?`text-bambu-green hover:bg-bambu-green/10`:`text-bambu-gray/50 hover:bg-bambu-dark-secondary`}`,title:e.visible?a(`inventory.hideColumn`):a(`inventory.showColumn`),children:e.visible?(0,K.jsx)(Gs,{className:`w-4 h-4`}):(0,K.jsx)(Ws,{className:`w-4 h-4`})})]},e.id))}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:_,className:`mr-auto`,children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),a(`inventory.reset`)]}),(0,K.jsx)($,{variant:`secondary`,onClick:t,children:a(`inventory.cancel`)}),(0,K.jsx)($,{onClick:v,children:a(`inventory.applyChanges`)})]})]})})})}var _Ve=[{value:`ams_holder_74x33`,i18nKey:`amsHolderSmall`,fallbackLabel:`AMS holder — small (74 × 33 mm)`,fallbackHint:`Single label per page; matches the printable label from MakerWorld model 752566 (AMS Filament Label Holder).`},{value:`ams_holder_75x55`,i18nKey:`amsHolderLarge`,fallbackLabel:`AMS holder — large (75 × 55 mm)`,fallbackHint:`Single label per page; fits the cardstock-insert variant of the AMS Filament Label Holder. Roomy enough for swatch, brand, material, ID, and QR code.`},{value:`box_40x30`,i18nKey:`box40x30`,fallbackLabel:`Box label (40 × 30 mm)`,fallbackHint:`Single label per page; common DK/Brother roll size, good for filament-bag and storage-bin labels.`},{value:`box_62x29`,i18nKey:`box`,fallbackLabel:`Box label (62 × 29 mm)`,fallbackHint:`Single label per page; sized for Brother PT/QL and Dymo small labels.`},{value:`avery_l7160`,i18nKey:`averyL7160`,fallbackLabel:`Avery L7160 — A4 sheet (38.1 × 63.5 mm × 21)`,fallbackHint:`EU sheet stock; 21 labels per A4 page.`},{value:`avery_5160`,i18nKey:`avery5160`,fallbackLabel:`Avery 5160 — US Letter sheet (25.4 × 66.7 mm × 30)`,fallbackHint:`US sheet stock; 30 labels per Letter page.`}];function vVe(e){let t=window.URL.createObjectURL(e);if(!window.open(t,`_blank`)){let e=document.createElement(`a`);e.href=t,e.download=`bambuddy-labels.pdf`,document.body.appendChild(e),e.click(),document.body.removeChild(e)}setTimeout(()=>window.URL.revokeObjectURL(t),6e4)}function yVe(e){return Wd(e)}function bVe(e){return`${e.color_name??`${e.material}${e.subtype?` ${e.subtype}`:``}`}${e.brand?` · ${e.brand}`:``}`}function xVe(e){return[e.color_name,e.material,e.subtype,e.brand,`#${e.id}`].filter(Boolean).join(` `).toLowerCase()}function i9(e){if(!e)return[1,0];let t=e.replace(/^#/,``).slice(0,6);if(t.length!==6)return[1,0];let n=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);if([n,r,i].some(Number.isNaN))return[1,0];let a=n/255,o=r/255,s=i/255,c=Math.max(a,o,s),l=Math.min(a,o,s),u=(c+l)/2,d=c-l;if((d===0?0:d/(1-Math.abs(2*u-1)))<.1)return[1,u];let f=0;return f=c===a?(o-s)/d%6:c===o?(s-a)/d+2:(a-o)/d+4,f*=60,f<0&&(f+=360),[0,f]}function SVe({isOpen:e,onClose:t,availableSpools:n,initialSelectedIds:r,spoolmanMode:i}){let{t:a}=G(),{showToast:o}=xd(),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(new Set),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(`id`);(0,y.useEffect)(()=>{if(e){let e=new Set(n.map(e=>e.id));u(new Set(r.filter(t=>e.has(t)))),f(``),m(``),g(`id`),c(null)}},[e]);let _=(0,y.useMemo)(()=>{let e=[...n];return h===`color`?(e.sort((e,t)=>{let n=i9(e.rgba),r=i9(t.rgba);return n[0]===r[0]?n[1]===r[1]?e.id-t.id:n[1]-r[1]:n[0]-r[0]}),e):(e.sort((e,t)=>e.id-t.id),e)},[n,h]),v=(0,y.useMemo)(()=>{let e=new Set;for(let t of _)t.material&&e.add(t.material.toUpperCase());return[...e].sort()},[_]),b=(0,y.useMemo)(()=>{let e=d.trim().toLowerCase();return _.filter(t=>!(p&&(t.material||``).toUpperCase()!==p||e&&!xVe(t).includes(e)))},[_,d,p]),x=b.length>0&&b.every(e=>l.has(e.id));if(!e)return null;let S=l.size,C=S===0;function w(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function T(){u(e=>{let t=new Set(e);for(let e of b)t.add(e.id);return t})}function E(){u(e=>{let t=new Set(e);for(let e of b)t.delete(e.id);return t})}function D(){u(new Set)}async function O(e){if(C||s)return;let n=_.filter(e=>l.has(e.id)).map(e=>e.id);c(e);try{vVe(i?await Q.printSpoolmanSpoolLabels({spool_ids:n,template:e}):await Q.printSpoolLabels({spool_ids:n,template:e})),t()}catch(e){o(a(`inventory.labels.error`,`Could not generate labels: {{msg}}`,{msg:e instanceof Error?e.message:String(e)}),`error`)}finally{c(null)}}return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-start sm:items-center justify-center p-4 overflow-y-auto`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-3xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] overflow-hidden flex flex-col my-auto`,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)(bl,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(`inventory.labels.title`,`Print spool labels`)}),S>0&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,a(`inventory.labels.selectedCount`,`{{count}} selected`,{count:S}),`)`]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,"aria-label":a(`common.close`,`Close`),children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-2 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{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:`search`,value:d,onChange:e=>f(e.target.value),placeholder:a(`inventory.labels.searchPlaceholder`,`Search name, brand, or #ID`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),v.length>1&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:a(`inventory.labels.filterByMaterial`,`Material:`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>m(``),className:`px-2 py-0.5 text-xs rounded-full border transition ${p===``?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:a(`inventory.labels.allMaterials`,`All`)}),v.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>m(e),className:`px-2 py-0.5 text-xs rounded-full border transition ${p===e?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:e},e))]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:a(`inventory.labels.sortBy.label`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>g(`id`),className:`px-2 py-0.5 text-xs rounded-full border transition ${h===`id`?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:a(`inventory.labels.sortBy.id`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>g(`color`),className:`px-2 py-0.5 text-xs rounded-full border transition ${h===`color`?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:a(`inventory.labels.sortBy.color`)})]})]}),(0,K.jsxs)(`div`,{className:`px-4 pt-3 pb-2 flex items-center justify-between gap-3 flex-wrap`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`inventory.labels.pickSpools`,`Pick which spools to print labels for:`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-xs`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:x?E:T,disabled:b.length===0,className:`text-bambu-green hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:x?a(`inventory.labels.deselectVisible`,`Deselect visible`):a(`inventory.labels.selectVisible`,`Select all visible ({{count}})`,{count:b.length})}),(0,K.jsx)(`button`,{type:`button`,onClick:D,disabled:S===0,className:`text-bambu-gray hover:text-white hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:a(`inventory.labels.clearAll`,`Clear all`)})]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto px-2 pb-2 min-h-0`,children:b.length===0?(0,K.jsx)(`div`,{className:`text-center text-sm text-bambu-gray py-6`,children:_.length===0?a(`inventory.labels.noSpoolsToShow`,`No spools to show. Adjust your filter and try again.`):a(`inventory.labels.noMatches`,`No spools match the current search or filter.`)}):(0,K.jsx)(`ul`,{className:`space-y-0.5`,children:b.map(e=>{let t=l.has(e.id);return(0,K.jsx)(`li`,{children:(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary/50 cursor-pointer`,children:[t?(0,K.jsx)($l,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,K.jsx)(tu,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,K.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>w(e.id),className:`sr-only`}),(0,K.jsx)(`span`,{className:`w-4 h-4 rounded border border-black/20 shrink-0`,style:yVe(e.rgba)}),(0,K.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-sm text-white`,children:bVe(e)}),(0,K.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]})},e.id)})})}),(0,K.jsx)(`div`,{className:`px-3 pt-2 pb-2 grid grid-cols-1 sm:grid-cols-2 gap-2 border-t border-bambu-dark-tertiary`,children:_Ve.map(e=>{let t=s===e.value,n=a(`inventory.labels.templates.${e.i18nKey}.label`,e.fallbackLabel),r=a(`inventory.labels.templates.${e.i18nKey}.hint`,e.fallbackHint);return(0,K.jsxs)(`button`,{disabled:C||s!==null,onClick:()=>O(e.value),title:`${n} — ${r}`,className:`w-full text-left p-2.5 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-green hover:bg-bambu-green/10 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:border-bambu-dark-tertiary disabled:hover:bg-bambu-dark transition flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`font-medium text-white text-sm truncate`,children:n}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5 truncate`,children:r})]}),t&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin text-bambu-green shrink-0`})]},e.value)})}),(0,K.jsx)(`div`,{className:`flex justify-end gap-2 px-5 py-2 border-t border-bambu-dark-tertiary`,children:(0,K.jsx)($,{variant:`secondary`,onClick:t,disabled:s!==null,children:a(`common.cancel`,`Cancel`)})})]})]})}function CVe({onClose:e,onImported:t}){let{t:n}=G(),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),h=(0,y.useRef)(null),g=async e=>{i(e),c(null),m(null),u(!0);try{c(await Q.importSpoolsCsvPreview(e))}catch(e){m(e instanceof Error?e.message:n(`inventory.csv.previewError`,`Could not read the CSV file`))}finally{u(!1)}},_=e=>{let t=e.target.files?.[0];t&&g(t)},v=e=>{e.preventDefault(),o(!1);let t=e.dataTransfer.files?.[0];t&&g(t)},b=async()=>{if(r){f(!0),m(null);try{t((await Q.importSpoolsCsv(r)).created)}catch(e){m(e instanceof Error?e.message:n(`inventory.csv.importError`,`Import failed`)),f(!1)}}},x=e=>e===`valid`?(0,K.jsx)(ls,{className:`w-4 h-4 text-green-500 flex-shrink-0`}):e===`error`?(0,K.jsx)(ms,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,K.jsx)(fs,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),S=s?.valid_count??0;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 w-full max-w-3xl border border-bambu-dark-tertiary flex flex-col max-h-[90vh]`,children:[(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`inventory.csv.modalTitle`,`Import spools from CSV`)}),(0,K.jsx)(`button`,{onClick:e,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,K.jsx)(Pu,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,K.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),o(!0)},onDragLeave:e=>{e.preventDefault(),o(!1)},onDrop:v,onClick:()=>h.current?.click(),className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${a?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,children:[(0,K.jsx)(Su,{className:`w-9 h-9 mx-auto mb-2 ${a?`text-bambu-green`:`text-bambu-gray`}`}),r?(0,K.jsxs)(`p`,{className:`text-white font-medium flex items-center justify-center gap-2`,children:[(0,K.jsx)(Zs,{className:`w-4 h-4`}),` `,r.name]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.csv.selectFile`,`Choose a CSV file or drag it here`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:n(`inventory.csv.dragHint`,`Header: material (required), brand, subtype, color_name, rgba, …`)})]})]}),(0,K.jsx)(`input`,{ref:h,type:`file`,accept:`.csv,text/csv`,className:`hidden`,onChange:_}),l&&(0,K.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-bambu-gray py-4`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),n(`inventory.csv.parsing`,`Reading file…`)]}),p&&(0,K.jsxs)(`div`,{className:`p-3 bg-red-500/10 border border-red-500/30 rounded-lg flex items-start gap-3`,children:[(0,K.jsx)(ms,{className:`w-5 h-5 text-red-400 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`p`,{className:`text-sm text-red-300 break-words`,children:p})]}),s&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-sm`,children:[(0,K.jsx)(`span`,{className:`px-2 py-1 rounded bg-green-500/10 text-green-400`,children:n(`inventory.csv.validCount`,`{{count}} valid`,{count:s.valid_count})}),(0,K.jsx)(`span`,{className:`px-2 py-1 rounded bg-red-500/10 text-red-400`,children:n(`inventory.csv.errorCount`,`{{count}} error`,{count:s.error_count})}),(0,K.jsx)(`span`,{className:`px-2 py-1 rounded bg-bambu-dark text-bambu-gray`,children:n(`inventory.csv.skippedCount`,`{{count}} skipped`,{count:s.skipped_count})})]}),s.warnings.length>0&&(0,K.jsx)(`div`,{className:`p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg space-y-1`,children:s.warnings.map((e,t)=>(0,K.jsx)(`p`,{className:`text-xs text-yellow-300`,children:e},t))}),s.rows.length>0&&(0,K.jsx)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:(0,K.jsx)(`div`,{className:`max-h-72 overflow-y-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,K.jsxs)(`tr`,{className:`text-left text-bambu-gray`,children:[(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colRow`,`Row`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colStatus`,`Status`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.material`,`Material`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.brand`,`Brand`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colColor`,`Color`)})]})}),(0,K.jsx)(`tbody`,{children:s.rows.map(e=>(0,K.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:e.row_number}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[x(e.status),e.status===`error`&&e.reason&&(0,K.jsx)(`span`,{className:`text-xs text-red-400 break-words`,children:e.reason})]})}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.material||`—`}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.brand||`—`}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.rgba&&(0,K.jsx)(`span`,{className:`inline-block w-4 h-4 rounded-full border border-bambu-dark-tertiary flex-shrink-0`,style:Wd(e.rgba)}),(0,K.jsx)(`span`,{className:`text-white`,children:e.color_name||`—`}),e.resolved_color&&!e.cross_material_color&&(0,K.jsx)(`span`,{title:n(`inventory.csv.colorResolved`,`Color filled from catalog`),children:(0,K.jsx)(Ou,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`})}),e.cross_material_color&&(0,K.jsx)(`span`,{title:n(`inventory.csv.colorCrossMaterial`,`Color taken from a different material — no exact match in catalog`),children:(0,K.jsx)(vu,{className:`w-3.5 h-3.5 text-yellow-500 flex-shrink-0`})}),e.duplicate_of_existing&&(0,K.jsx)(`span`,{title:n(`inventory.csv.duplicateExisting`,`A spool with this material, brand and color already exists — it will still be imported as a new spool`),children:(0,K.jsx)(Ds,{className:`w-3.5 h-3.5 text-amber-400 flex-shrink-0`})})]})})]},e.row_number))})]})})})]})]}),(0,K.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:e,disabled:d,children:n(`common.cancel`)}),(0,K.jsx)($,{onClick:b,disabled:!s||S===0||d,children:d?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 mr-2 animate-spin`}),n(`inventory.csv.importing`,`Importing…`)]}):S>0?n(`inventory.csv.importValidRows`,`Import {{count}} valid rows`,{count:S}):n(`inventory.csv.noValidRows`,`No valid rows`)})]})]})})}function wVe({open:e,onClose:t,onPickLocation:n}){let{t:r}=G(),i=Qa(),{showToast:a}=xd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),{data:m=[],isLoading:h}=q({queryKey:e9,queryFn:Q.getLocations,enabled:e}),g=()=>{t9(i),i.invalidateQueries({queryKey:[`inventory-spools`]}),i.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},_=J({mutationFn:async()=>{let e=u.trim();if(!e)throw Error(r(`locations.nameRequired`));return c?Q.updateLocation(c.id,{name:e}):Q.createLocation({name:e})},onSuccess:()=>{a(r(c?`locations.updated`:`locations.created`),`success`),s(!1),l(null),d(``),g()},onError:e=>{a(e.message||r(`locations.saveFailed`),`error`)}}),v=J({mutationFn:e=>Q.deleteLocation(e),onSuccess:()=>{a(r(`locations.deleted`),`success`),p(null),g()},onError:e=>{a(e.message||r(`locations.deleteFailed`),`error`)}}),b=()=>{l(null),d(``),s(!0)},x=e=>{l(e),d(e.name),s(!0)},S=(0,y.useCallback)(()=>{_.isPending||(s(!1),l(null),d(``))},[_.isPending]);(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(_.isPending||v.isPending||(o?S():f||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,o,f,_.isPending,v.isPending,S,t]);let C=e=>{e.preventDefault(),_.mutate()};if(!e)return null;let w=`locations-modal-title`,T=`location-editor-title`;return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{_.isPending||v.isPending||t()}}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-2xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":w,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h2`,{id:w,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Kc,{className:`w-5 h-5 text-bambu-green`}),r(`locations.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:r(`locations.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)($,{onClick:b,children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),r(`locations.add`)]}),(0,K.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":r(`common.close`),children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]})]}),(0,K.jsx)(`div`,{className:`overflow-y-auto`,children:h?(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-6 h-6 animate-spin mr-2`}),r(`common.loading`)]}):m.length===0?(0,K.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:r(`locations.empty`)}):(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:r(`locations.name`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium text-right`,children:r(`locations.spools`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:r(`common.actions`)})]})}),(0,K.jsx)(`tbody`,{children:m.map(e=>(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 hover:bg-bambu-dark-tertiary/30 cursor-pointer`,onClick:()=>{n&&(n(e.id),t())},children:[(0,K.jsx)(`td`,{className:`px-4 py-3 text-white font-medium`,children:e.name}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-right text-bambu-gray`,children:e.spool_count}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,K.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>x(e),title:r(`common.edit`),"aria-label":r(`locations.editAria`,{name:e.name,defaultValue:`Edit ${e.name}`}),children:(0,K.jsx)(pl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-400 rounded disabled:opacity-40`,disabled:e.spool_count>0,onClick:()=>p(e),title:e.spool_count>0?r(`locations.deleteBlocked`):r(`common.delete`),"aria-label":r(`locations.deleteAria`,{name:e.name,defaultValue:`Delete ${e.name}`}),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),o&&(0,K.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:S}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":T,children:[(0,K.jsx)(`h3`,{id:T,className:`text-lg font-semibold text-white mb-4`,children:r(c?`locations.edit`:`locations.add`)}),(0,K.jsxs)(`form`,{onSubmit:C,children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`location-name`,children:r(`locations.name`)}),(0,K.jsx)(`input`,{id:`location-name`,type:`text`,maxLength:255,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green mb-4`,placeholder:r(`locations.createPlaceholder`),value:u,onChange:e=>d(e.target.value),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:S,children:r(`common.cancel`)}),(0,K.jsxs)($,{type:`submit`,disabled:_.isPending||!u.trim(),children:[_.isPending&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),r(`common.save`)]})]})]})]})]}),f&&(0,K.jsx)(Ed,{title:r(`locations.confirmDelete`,{name:f.name}),message:r(`locations.confirmDeleteMessage`),confirmText:r(`common.delete`),variant:`danger`,isLoading:v.isPending,onConfirm:()=>v.mutate(f.id),onCancel:()=>p(null)})]})}function TVe(e){let t=e[0],n=0,r=0,i=0;for(let t of e)n+=t.label_weight,r+=t.weight_used,i+=t.core_weight;return{...t,label_weight:n,weight_used:r,core_weight:i}}function a9(e){return`${e.material}|${e.subtype||``}|${e.brand||``}|${e.color_name||``}|${e.rgba||``}|${e.extra_colors||``}|${e.effect_type||``}|${e.label_weight}`}var o9=`bambuddy-inventory-columns`,s9=[{id:`id`,label:`#`,visible:!0},{id:`added_time`,label:`Added`,visible:!0},{id:`encode_time`,label:`Encoded`,visible:!1},{id:`last_used_time`,label:`Last Used`,visible:!1},{id:`rgba`,label:`Color`,visible:!0},{id:`material`,label:`Material`,visible:!0},{id:`subtype`,label:`Subtype`,visible:!0},{id:`color_name`,label:`Color Name`,visible:!1},{id:`brand`,label:`Brand`,visible:!0},{id:`slicer_filament`,label:`Slicer Filament`,visible:!1},{id:`location`,label:`Location`,visible:!0},{id:`storage_location`,label:`Storage Location`,visible:!1},{id:`label_weight`,label:`Label`,visible:!0},{id:`net`,label:`Net`,visible:!0},{id:`gross`,label:`Gross`,visible:!1},{id:`added_full`,label:`Full`,visible:!1},{id:`used`,label:`Used`,visible:!1},{id:`printed_total`,label:`Printed Total`,visible:!1},{id:`printed_since_weight`,label:`Printed Since Weight`,visible:!1},{id:`note`,label:`Note`,visible:!1},{id:`pa_k`,label:`PA(K)`,visible:!0},{id:`tag_id`,label:`Tag ID`,visible:!1},{id:`data_origin`,label:`Data Origin`,visible:!1},{id:`tag_type`,label:`Linked Tag Type`,visible:!1},{id:`stock`,label:`Stock`,visible:!1},{id:`remaining`,label:`Remaining`,visible:!0},{id:`spool_name`,label:`Spool`,visible:!1},{id:`cost_per_kg`,label:`Cost/kg`,visible:!1},{id:`weight_check`,label:`Weight Check`,visible:!1}];function EVe(){try{let e=localStorage.getItem(o9);if(e){let t=JSON.parse(e),n=new Set(s9.map(e=>e.id)),r=new Set(t.map(e=>e.id)),i=t.filter(e=>n.has(e.id)),a=s9.filter(e=>!r.has(e.id));return[...i,...a]}}catch{}return s9.map(e=>({...e}))}function DVe(e){try{localStorage.setItem(o9,JSON.stringify(e))}catch{}}function c9(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}var OVe={PLA:`bg-green-500/20 text-green-400`,ABS:`bg-red-500/20 text-red-400`,PETG:`bg-blue-500/20 text-blue-400`,TPU:`bg-purple-500/20 text-purple-400`,ASA:`bg-orange-500/20 text-orange-400`,PA:`bg-yellow-500/20 text-yellow-400`,PC:`bg-cyan-500/20 text-cyan-400`,PET:`bg-sky-500/20 text-sky-400`};function l9(e,t=`system`){if(!e)return`-`;let n=mf(e);return n?of(n,t):`-`}var kVe={id:()=>`#`,added_time:()=>`Added`,encode_time:()=>`Encoded`,last_used_time:()=>`Last Used`,rgba:e=>e(`inventory.color`),material:e=>e(`inventory.material`),subtype:e=>e(`inventory.subtype`),color_name:e=>e(`inventory.colorName`),brand:e=>e(`inventory.brand`),slicer_filament:e=>e(`inventory.slicerFilament`),location:()=>`Location`,storage_location:e=>e(`inventory.storageLocation`),label_weight:e=>e(`inventory.labelWeight`),net:e=>e(`inventory.net`),gross:()=>`Gross`,added_full:()=>`Full`,used:e=>e(`inventory.weightUsed`),printed_total:()=>`Printed Total`,printed_since_weight:()=>`Printed Since Weight`,note:e=>e(`inventory.note`),pa_k:()=>`PA(K)`,tag_id:()=>`Tag ID`,data_origin:()=>`Data Origin`,tag_type:()=>`Linked Tag Type`,stock:e=>e(`inventory.stock`),remaining:e=>e(`inventory.remaining`),spool_name:e=>e(`inventory.spoolName`),cost_per_kg:e=>e(`inventory.costPerKg`),weight_check:e=>e(`inventory.weightCheck`)},u9={id:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm font-medium text-white`,children:e.id}),added_time:({spool:e,dateFormat:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:l9(e.created_at,t)}),encode_time:({spool:e,dateFormat:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:l9(e.encode_time,t)}),last_used_time:({spool:e,dateFormat:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.last_used?l9(e.last_used,t):`Never`}),rgba:({spool:e})=>(0,K.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,K.jsx)(K5,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,effectSize:`table`,subtype:e.subtype})}),material:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-white`,children:e.material}),subtype:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.subtype||`-`}),color_name:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:Hd(e.color_name,e.rgba)||`-`}),brand:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`}),slicer_filament:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:e.slicer_filament||void 0,children:e.slicer_filament_name||e.slicer_filament||`-`}),location:({spool:e,assignmentMap:t})=>{let n=t[e.id];if(!n)return(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`});let r=n.printer_name||`Printer ${n.printer_id}`,i=n.ams_id===254||n.ams_id===255,a=!i&&n.ams_id>=128;return(0,K.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-purple-500/20 text-purple-400`,children:[r,` `,IK(n.ams_id,n.tray_id,a,i),n.ams_label?` (${n.ams_label})`:``]})},storage_location:({spool:e})=>e.storage_location?(0,K.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-blue-500/20 text-blue-400`,children:e.storage_location}):(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}),label_weight:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-white`,children:c9(e.label_weight)}),net:({remaining:e})=>(0,K.jsx)(`span`,{className:`text-sm text-white`,children:c9(e)}),gross:({spool:e,remaining:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:c9(t+e.core_weight)}),added_full:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.added_full==null?`-`:e.added_full?`Yes`:`No`}),used:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.weight_used>0?c9(e.weight_used):`-`}),printed_total:()=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),printed_since_weight:()=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),note:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray max-w-[150px] truncate block`,title:e.note||void 0,children:e.note||`-`}),pa_k:({spool:e})=>(e.k_profiles?.length??0)===0?(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,K.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-bambu-green/20 text-bambu-green`,children:`K`}),tag_id:({spool:e})=>{let t=e.tag_uid||e.tray_uuid;return t?(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray font-mono`,title:t,children:t.length>12?`${t.slice(0,6)}...${t.slice(-4)}`:t}):(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},data_origin:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.data_origin||`-`}),tag_type:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.tag_type||`-`}),stock:({spool:e,t})=>e.slicer_filament?(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,K.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-amber-500/20 text-amber-400`,children:t(`inventory.stock`)}),remaining:({remaining:e,pct:t})=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full ${t>50?`bg-bambu-green`:t>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(t,100)}%`}})}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e),`g`]})]}),spool_name:({spool:e,catalogMap:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:(e.core_weight_catalog_id==null?void 0:t[e.core_weight_catalog_id])?.name||`-`}),cost_per_kg:({spool:e,currencySymbol:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.cost_per_kg==null?`-`:`${t}${e.cost_per_kg.toFixed(2)}`}),weight_check:({spool:e,onSyncWeight:t})=>{let n=e.last_scale_weight;if(n==null)return(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,title:`No scale measurement`,children:`-`});let r=e.core_weight||0,i=Math.max(0,e.label_weight-e.weight_used)+r,a,o;n0?`+${Math.round(a)}`:`${Math.round(a)}`,c=o?`Scale: ${Math.round(n)}g\nCalculated: ${Math.round(i)}g\nDifference: ${s}g (within tolerance)`:`Scale: ${Math.round(n)}g\nCalculated: ${Math.round(i)}g\nDifference: ${s}g (mismatch!)`;return(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-sm font-medium ${o?`text-green-400`:`text-yellow-400`}`,title:c,children:[(0,K.jsxs)(`span`,{children:[Math.round(n),`g`]}),o?(0,K.jsx)($o,{className:`w-3 h-3`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(vu,{className:`w-3 h-3`}),t&&(0,K.jsx)(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),n.preventDefault(),t(e)},className:`p-1 hover:bg-bambu-green/20 rounded transition-colors text-bambu-green`,title:`Sync: trust scale weight and reset tracking`,children:(0,K.jsx)(Cl,{className:`w-3.5 h-3.5`})})]})]})}},d9={id:e=>e.id,added_time:e=>e.created_at||``,encode_time:e=>e.encode_time||``,last_used_time:e=>e.last_used||``,material:e=>(e.material||``).toLowerCase(),subtype:e=>(e.subtype||``).toLowerCase(),color_name:e=>(e.color_name||``).toLowerCase(),brand:e=>(e.brand||``).toLowerCase(),slicer_filament:e=>(e.slicer_filament_name||e.slicer_filament||``).toLowerCase(),location:(e,t)=>{let n=t[e.id];if(!n)return``;let r=n.ams_id===254||n.ams_id===255,i=!r&&n.ams_id>=128,a=n.ams_label?` (${n.ams_label})`:``;return`${n.printer_name||``} ${IK(n.ams_id,n.tray_id,i,r)}${a}`},storage_location:e=>(e.storage_location||``).toLowerCase(),label_weight:e=>e.label_weight,net:e=>Math.max(0,e.label_weight-e.weight_used),gross:e=>Math.max(0,e.label_weight-e.weight_used)+e.core_weight,used:e=>e.weight_used,remaining:e=>e.label_weight>0?Math.max(0,e.label_weight-e.weight_used)/e.label_weight:0,note:e=>(e.note||``).toLowerCase(),data_origin:e=>(e.data_origin||``).toLowerCase(),tag_type:e=>(e.tag_type||``).toLowerCase(),stock:e=>+!!e.slicer_filament,spool_name:e=>e.core_weight_catalog_id??0,cost_per_kg:e=>e.cost_per_kg??0,weight_check:e=>{if(e.last_scale_weight==null)return-1;let t=Math.max(0,e.label_weight-e.weight_used)+e.core_weight;return Math.abs(e.last_scale_weight-t)}},f9=`bambuddy-inventory-sort`;function AVe(){try{let e=localStorage.getItem(f9);if(e)return JSON.parse(e)}catch{}return null}function jVe(e){try{e?localStorage.setItem(f9,JSON.stringify(e)):localStorage.removeItem(f9)}catch{}}function MVe(){let{data:e}=q({queryKey:[`spoolman-settings`],queryFn:Q.getSpoolmanSettings,staleTime:300*1e3}),t=e!==void 0;return(0,K.jsx)(NVe,{spoolmanMode:e?.spoolman_enabled===`true`&&!!e?.spoolman_url,spoolmanModeReady:t})}function NVe({spoolmanMode:e=!1,spoolmanModeReady:t=!0}){let{t:n}=G(),r=Qa(),{showToast:i}=xd(),{hasPermission:a,loading:o}=sd(),s=!o&&a(`inventory:forecast_read`),[c,l]=Oi(),[u,d]=(0,y.useState)(null),f=(0,y.useRef)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(`active`),[E,D]=(0,y.useState)(`all`),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(``),[P,F]=(0,y.useState)(``),[I,L]=(0,y.useState)(`all`),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(`table`),[ee,H]=(0,y.useState)(AVe),[te,ne]=(0,y.useState)(EVe),[re,U]=(0,y.useState)(!1),[ie,ae]=(0,y.useState)(()=>{try{return localStorage.getItem(`bambuddy-inventory-group`)===`true`}catch{return!1}}),[W,oe]=(0,y.useState)(new Set),[se,ce]=(0,y.useState)(0),[le,ue]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`bambuddy-inventory-pageSize`);if(e){let t=Number(e);if([15,30,50,100,-1].includes(t))return t}}catch{}return 15}),{data:de}=q({queryKey:[`settings`],queryFn:Q.getSettings}),fe=de?.date_format||`system`,pe=e?[`spoolman-inventory-spools`]:[`inventory-spools`],me=()=>n9(r,pe),{data:he,isLoading:ge}=q({queryKey:pe,queryFn:()=>e?Q.getSpoolmanInventorySpools(!0):Q.getSpools(!0),refetchInterval:3e4}),_e=(0,y.useCallback)(async()=>{x(!0);try{await Q.exportSpoolsCsv()}catch(e){i(e instanceof Error?e.message:n(`inventory.csv.exportError`,`Export failed`),`error`)}finally{x(!1)}},[i,n]),ve=e?n(`inventory.csv.spoolmanHint`,`In Spoolman mode, use Spoolman's built-in CSV import/export.`):void 0,{data:ye=[]}=q({queryKey:e9,queryFn:Q.getLocations}),be=c.get(`location_id`),xe=be===`__none__`?`__none__`:be&&/^\d+$/.test(be)&&Number(be)>0?be:``,Se=c.get(`spool`),Ce=Se&&/^\d+$/.test(Se)&&Number(Se)>0?Number(Se):null,we=he?.find(e=>e.id===Ce)??null,Te=(0,y.useCallback)(()=>{f.current=!0,l(e=>(e.delete(`spool`),e),{replace:!0})},[l]),{data:Ee,isError:De,error:Oe}=q({queryKey:e?[`spoolman-inventory-spool`,Ce]:[`inventory-spool`,Ce],queryFn:()=>e?Q.getSpoolmanInventorySpool(Ce):Q.getSpool(Ce),enabled:t&&Ce!==null&&we===null,staleTime:1/0,retry:(e,t)=>e<2&&!(t instanceof zu&&t.status===404)});(0,y.useEffect)(()=>{if(!f.current){if(t&&Ce&&we){Te(),d({spool:we,mode:`edit`});return}if(Ee){Te(),d({spool:Ee,mode:`edit`});return}De&&(Te(),i(n(Oe instanceof zu&&Oe.status===404?`inventory.deepLinkSpoolNotFound`:`inventory.deepLinkFetchFailed`),`error`))}},[t,Ce,we,Ee,De,Oe,Te,i,n]);let{data:ke}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),refetchInterval:3e4}),{data:Ae=[],isError:je}=q({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:e,refetchInterval:3e4,staleTime:1e4,retry:1}),Me=(0,y.useRef)(!1);(0,y.useEffect)(()=>{je&&!Me.current?(Me.current=!0,i(n(`inventory.spoolmanUnreachable`),`error`)):je||(Me.current=!1)},[je,i,n]);let{data:Ne}=q({queryKey:[`spool-catalog`],queryFn:()=>Q.getSpoolCatalog()}),Pe=J({mutationFn:t=>e?Q.deleteSpoolmanInventorySpool(t):Q.deleteSpool(t),onSuccess:()=>{me(),i(n(`inventory.spoolDeleted`),`success`)},onError:e=>{e instanceof zu&&e.status===404?i(n(`inventory.deleteSpoolNotFound`),`error`):e instanceof zu&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.deleteFailed`),`error`)}}),Fe=J({mutationFn:t=>e?Q.archiveSpoolmanInventorySpool(t):Q.archiveSpool(t),onSuccess:()=>{me(),i(n(`inventory.spoolArchived`),`success`)},onError:e=>{e instanceof zu&&e.status===404?i(n(`inventory.archiveSpoolNotFound`),`error`):e instanceof zu&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.archiveFailed`),`error`)}}),Ie=J({mutationFn:t=>e?Q.restoreSpoolmanInventorySpool(t):Q.restoreSpool(t),onSuccess:()=>{me(),i(n(`inventory.spoolRestored`),`success`)},onError:e=>{e instanceof zu&&e.status===404?i(n(`inventory.restoreSpoolNotFound`),`error`):e instanceof zu&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.restoreFailed`),`error`)}}),Le=J({mutationFn:t=>e?Q.resetSpoolmanInventorySpoolConsumedCounter(t):Q.resetSpoolConsumedCounter(t),onSuccess:()=>{r.invalidateQueries({queryKey:pe}),i(n(`inventory.consumedCounterReset`),`success`)},onError:()=>{i(n(`inventory.resetConsumedCounterFailed`),`error`)}}),Re=J({mutationFn:t=>e?Q.bulkResetSpoolmanInventorySpoolConsumedCounter(t):Q.bulkResetSpoolConsumedCounter(t),onSuccess:e=>{r.invalidateQueries({queryKey:pe}),i(n(`inventory.allConsumedCountersReset`,{count:e.reset}),`success`)},onError:()=>{i(n(`inventory.resetConsumedCounterFailed`),`error`)}}),ze=(0,y.useMemo)(()=>(he??[]).map(e=>e.id),[he]),Be=async t=>{if(t.last_scale_weight!=null)try{e?await Q.syncSpoolmanSpoolWeight(t.id,t.last_scale_weight):await nd.updateSpoolWeight(t.id,t.last_scale_weight),r.invalidateQueries({queryKey:pe}),i(`Synced "${[t.brand,t.material,t.color_name].filter(Boolean).join(` `)}" to scale weight`,`success`)}catch(e){let t=e instanceof zu&&e.status===404,r=e instanceof zu&&e.status===503;i(n(t?`inventory.syncWeightSpoolNotFound`:r?`inventory.syncWeightSpoolmanUnreachable`:`inventory.syncWeightFailed`),`error`)}},Ve=de?.low_stock_threshold??20,[He,Ue]=(0,y.useState)(!1),[We,Ge]=(0,y.useState)(Ve.toString());(0,y.useEffect)(()=>{He||Ge(Ve.toString())},[Ve,He]);let Ke=J({mutationFn:e=>Q.updateSettings({low_stock_threshold:e}),onSuccess:()=>{r.invalidateQueries({queryKey:[`settings`]}),i(n(`common.saved`),`success`),Ue(!1)},onError:()=>{i(n(`inventory.lowStockThresholdError`),`error`)}}),qe=(0,y.useMemo)(()=>{if(!he)return null;let e=0,t=0,n=0,r=0,i={};for(let a of he){if(t+=Math.max(0,a.weight_used-(a.weight_used_baseline??0)),a.archived_at)continue;r++;let o=Math.max(0,a.label_weight-a.weight_used);e+=o,(a.label_weight>0?o/a.label_weight*100:0)<(a.low_stock_threshold_pct??Ve)&&n++;let s=a.material||`Unknown`;i[s]||(i[s]={count:0,weight:0}),i[s].count++,i[s].weight+=o}return{totalWeight:e,totalConsumed:t,lowStock:n,byMaterial:i,totalSpools:r}},[he,Ve]),Je=(ke?.length??0)+(e?Ae.length:0),Ye=Yd(de?.currency||`USD`),Xe=(0,y.useMemo)(()=>{let e={};for(let t of ke||[])e[t.spool_id]={printer_id:t.printer_id,printer_name:t.printer_name,ams_id:t.ams_id,tray_id:t.tray_id,ams_label:t.ams_label??null};for(let t of Ae)typeof t?.spoolman_spool_id!=`number`||t.spoolman_spool_id<=0||typeof t.printer_id!=`number`||typeof t.ams_id!=`number`||typeof t.tray_id!=`number`||e[t.spoolman_spool_id]||(e[t.spoolman_spool_id]={printer_id:t.printer_id,printer_name:t.printer_name??null,ams_id:t.ams_id,tray_id:t.tray_id,ams_label:t.ams_label??null});return e},[ke,Ae]),Ze=(0,y.useMemo)(()=>{let e={};for(let t of Ne||[])e[t.id]=t;return e},[Ne]),Qe=(0,y.useMemo)(()=>qe?Object.entries(qe.byMaterial).sort((e,t)=>t[1].weight-e[1].weight).slice(0,4):[],[qe]),$e=(0,y.useMemo)(()=>{let e=he||[];if(e=w===`active`?e.filter(e=>!e.archived_at):e.filter(e=>!!e.archived_at),E===`used`?e=e.filter(e=>e.weight_used>0):E===`new`?e=e.filter(e=>e.weight_used===0):E===`lowstock`&&(e=e.filter(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(e.label_weight>0?t/e.label_weight*100:0)<(e.low_stock_threshold_pct??Ve)})),O&&(e=e.filter(e=>e.material===O)),A&&(e=e.filter(e=>e.brand===A)),M&&(e=M===`__none__`?e.filter(e=>!e.category):e.filter(e=>e.category===M)),P){let t=Number(P);e=e.filter(e=>e.core_weight_catalog_id===t)}if(xe)if(xe===`__none__`)e=e.filter(e=>!e.location_id&&!e.storage_location?.trim());else{let t=Number(xe),n=ye.find(e=>e.id===t)?.name?.trim().toLowerCase();e=e.filter(e=>e.location_id==null?n?(e.storage_location||``).trim().toLowerCase()===n:!1:e.location_id===t)}return I===`stock`?e=e.filter(e=>!e.slicer_filament):I===`configured`&&(e=e.filter(e=>!!e.slicer_filament)),R&&(e=ZG(e,R)),e},[he,w,E,O,A,M,P,I,xe,R,Ve,ye]),et=()=>ce(0),tt=(0,y.useCallback)(e=>{l(t=>(t.delete(`location_id`),e&&t.set(`location_id`,e),t),{replace:!0}),et()},[l]),nt=[...new Set(he?.map(e=>e.material)||[])].sort(),rt=[...new Set(he?.map(e=>e.brand).filter(Boolean)||[])].sort(),it=[...new Set(he?.map(e=>e.category?.trim()).filter(Boolean)||[])].sort(),at=(he??[]).some(e=>!e.category),ot=[...new Set(he?.map(e=>e.core_weight_catalog_id).filter(e=>e!=null)||[])].sort((e,t)=>{let n=(Ze[e]?.name||``).toLowerCase(),r=(Ze[t]?.name||``).toLowerCase();return n.localeCompare(r)}),st=(he??[]).some(e=>!e.location_id&&!e.storage_location?.trim()),ct=w!==`active`||E!==`all`||!!O||!!A||!!M||!!P||!!xe||I!==`all`||!!R,lt=e=>{ne(e),DVe(e)},ut=(0,y.useMemo)(()=>te.filter(e=>e.visible).map(e=>e.id),[te]),dt=e=>{d9[e]&&(H(t=>{let n;return n=t?.column===e?t.direction===`asc`?{column:e,direction:`desc`}:null:{column:e,direction:`asc`},jVe(n),n}),et())},ft=(0,y.useMemo)(()=>{if(!ee)return $e;let e=d9[ee.column];return e?[...$e].sort((t,n)=>{let r=e(t,Xe),i=e(n,Xe);return ri?ee.direction===`asc`?1:-1:0}):$e},[$e,ee,Xe]),pt=(0,y.useMemo)(()=>{if(!ie)return ft.map(e=>({type:`single`,spool:e}));let e=new Map;for(let t of ft)if(!(t.weight_used>0||Xe[t.id])){let n=a9(t),r=e.get(n);r?r.push(t):e.set(n,[t])}let t=[],n=new Set;for(let r of ft){if(r.weight_used>0||Xe[r.id]){t.push({type:`single`,spool:r});continue}let i=a9(r);if(n.has(i))continue;n.add(i);let a=e.get(i);a.length===1?t.push({type:`single`,spool:a[0]}):t.push({type:`group`,key:i,spools:a,representative:a[0]})}return t},[ft,ie,Xe]),mt=le===-1,ht=pt.length,gt=mt?ht||1:le,_t=Math.max(1,Math.ceil(ht/gt)),vt=mt?0:Math.min(se,_t-1),yt=mt?pt:pt.slice(vt*gt,(vt+1)*gt),bt=()=>{let e=!ie;ae(e),oe(new Set),et();try{localStorage.setItem(`bambuddy-inventory-group`,String(e))}catch{}},xt=e=>{oe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},St=e=>{ue(e),ce(0);try{localStorage.setItem(`bambuddy-inventory-pageSize`,String(e))}catch{}};return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,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)(cl,{className:`w-7 h-7 text-bambu-green`}),n(`inventory.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:n(`inventory.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,disabled:e,onClick:()=>v(!0),title:ve,children:[(0,K.jsx)(Su,{className:`w-4 h-4`}),n(`inventory.csv.importButton`,`Import CSV`)]}),(0,K.jsxs)($,{variant:`secondary`,disabled:e||b,onClick:_e,title:ve,children:[b?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Is,{className:`w-4 h-4`}),n(`inventory.csv.exportButton`,`Export CSV`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>C(!0),children:[(0,K.jsx)(Kc,{className:`w-4 h-4`}),n(`locations.manage`)]}),(0,K.jsxs)($,{variant:`secondary`,disabled:$e.length===0,onClick:()=>g($e.map(e=>e.id)),title:$e.length===0?n(`inventory.labels.noSpoolsTitle`,`No spools to label`):n(`inventory.labels.bulkTitle`,`Pick spools to print labels for from the {{count}} currently shown`,{count:$e.length}),children:[(0,K.jsx)(bl,{className:`w-4 h-4`}),n(`inventory.labels.printLabels`,`Print labels…`)]}),(0,K.jsxs)($,{onClick:()=>d({spool:null,mode:`create`}),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})]}),qe&&!ge&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3`,children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsx)(cl,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalInventory`)})]}),(0,K.jsx)(`div`,{className:`text-xl font-bold text-white`,children:c9(qe.totalWeight,!0)}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[qe.totalSpools,` `,qe.totalSpools===1?n(`inventory.spool`):n(`inventory.spools`)]})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(gu,{className:`w-4 h-4 text-blue-400`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalConsumed`)})]}),qe.totalConsumed>0&&ze.length>0&&(0,K.jsx)(`button`,{onClick:()=>m({type:`reset-all-consumed-counters`}),className:`p-1 text-bambu-gray hover:text-red-400 rounded transition-colors`,title:n(`inventory.resetAllConsumedCountersTooltip`),"aria-label":n(`inventory.resetAllConsumedCounters`),children:(0,K.jsx)(Hs,{className:`w-3.5 h-3.5`})})]}),(0,K.jsx)(`div`,{className:`text-xl font-bold text-white`,children:c9(qe.totalConsumed,!0)}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.sinceTracking`)})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsx)(Nc,{className:`w-4 h-4 text-green-400`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.byMaterial`)})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1`,children:Qe.map(([e,t])=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${OVe[e]||`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e,` `,(0,K.jsx)(`span`,{className:`opacity-70`,children:c9(t.weight,!0)})]},e))})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsx)(bl,{className:`w-4 h-4 text-purple-400`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.inPrinter`)})]}),(0,K.jsx)(`div`,{className:`text-xl font-bold text-white`,children:Je}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.loadedInAms`)})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-yellow-400`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.lowStock`)})]}),(0,K.jsx)(`div`,{className:`text-xl font-bold ${qe.lowStock>0?`text-yellow-400`:`text-white`}`,children:qe.lowStock}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1 flex items-center gap-2`,children:He?(0,K.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=parseFloat(We);!isNaN(t)&&t>=.1&&t<=99.9?Ke.mutate(t):i(n(`inventory.lowStockThresholdError`),`error`)},className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`<`}),(0,K.jsx)(`input`,{type:`text`,inputMode:`decimal`,pattern:`^\\d{0,2}(\\.\\d?)?$`,maxLength:4,value:We,onChange:e=>{let t=e.target.value.replace(/[^\d.]/g,``);/^\d{0,2}(\.\d?)?$/.test(t)&&Ge(t)},className:`px-1.5 py-1 rounded border border-bambu-dark-tertiary text-xs text-white bg-bambu-dark-secondary focus:outline-none focus:border-bambu-green w-14 text-center`,onWheel:e=>e.currentTarget.blur(),disabled:Ke.isPending}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`%`}),(0,K.jsx)($,{type:`submit`,size:`sm`,disabled:Ke.isPending,children:n(`common.save`)}),(0,K.jsx)($,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>Ue(!1),disabled:Ke.isPending,children:n(`common.cancel`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`< `,Ve,`%`]}),(0,K.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:n(`common.edit`),onClick:()=>{Ge(Ve.toString()),Ue(!0)},children:(0,K.jsx)(fl,{className:`w-4 h-4`})})]})})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3 items-start sm:items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1 max-w-md ${B===`forecast`?`invisible pointer-events-none`:``}`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,K.jsx)(`input`,{type:`text`,value:R,onChange:e=>{z(e.target.value),et()},placeholder:n(`inventory.search`),className:`w-full pl-10 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`}),R&&(0,K.jsx)(`button`,{onClick:()=>{z(``),et()},className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[B===`table`&&(0,K.jsxs)(`button`,{onClick:()=>U(!0),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-bambu-gray border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,title:n(`inventory.configureColumns`),children:[(0,K.jsx)(Ts,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.columns`)})]}),B!==`forecast`&&(0,K.jsxs)(`button`,{onClick:bt,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium border rounded-lg transition-colors ${ie?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,title:n(`inventory.groupSimilar`),children:[(0,K.jsx)(_c,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.groupSimilar`)})]}),(0,K.jsxs)(`div`,{className:`flex bg-bambu-dark-primary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`button`,{onClick:()=>V(`table`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${B===`table`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(ou,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.table`)})]}),(0,K.jsxs)(`button`,{onClick:()=>V(`cards`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${B===`cards`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(Pc,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.cards`)})]}),(0,K.jsxs)(`button`,{onClick:()=>s&&V(`forecast`),disabled:!s,title:s?void 0:n(`forecast.noReadAccess`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${B===`forecast`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[s?(0,K.jsx)(_u,{className:`w-4 h-4`}):(0,K.jsx)(Hc,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:n(`forecast.title`)})]})]})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${B===`forecast`?`hidden`:``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,K.jsxs)(`button`,{onClick:()=>{T(`active`),et()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${w===`active`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(cl,{className:`w-3.5 h-3.5`}),n(`inventory.active`)]}),(0,K.jsxs)(`button`,{onClick:()=>{T(`archived`),et()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${w===`archived`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(wo,{className:`w-3.5 h-3.5`}),n(`inventory.archived`)]})]}),(0,K.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,K.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,K.jsx)(`button`,{onClick:()=>{D(`all`),et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${E===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,K.jsxs)(`button`,{onClick:()=>{D(`used`),et()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${E===`used`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(_s,{className:`w-3.5 h-3.5`}),n(`inventory.used`)]}),(0,K.jsx)(`button`,{onClick:()=>{D(`new`),et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${E===`new`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.new`)}),(0,K.jsxs)(`button`,{onClick:()=>{D(`lowstock`),et()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${E===`lowstock`?`bg-yellow-500/20 text-yellow-400`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(vu,{className:`w-3.5 h-3.5`}),n(`inventory.lowStock`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,K.jsx)(`button`,{onClick:()=>{L(`all`),et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,K.jsx)(`button`,{onClick:()=>{L(`stock`),et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`stock`?`bg-amber-500/20 text-amber-400`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.stock`)}),(0,K.jsx)(`button`,{onClick:()=>{L(`configured`),et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`configured`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.configured`)})]}),(0,K.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,K.jsxs)(`select`,{value:O,onChange:e=>{k(e.target.value),et()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${O?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(`option`,{value:``,children:n(`inventory.material`)}),nt.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),(0,K.jsxs)(`select`,{value:A,onChange:e=>{j(e.target.value),et()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${A?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(`option`,{value:``,children:n(`inventory.brand`)}),rt.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),(it.length>0||M)&&(0,K.jsxs)(`select`,{value:M,onChange:e=>{N(e.target.value),et()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${M?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(`option`,{value:``,children:n(`inventory.category`)}),it.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e)),at&&(0,K.jsx)(`option`,{value:`__none__`,children:n(`inventory.categoryNone`)})]}),ot.length>0&&(0,K.jsxs)(`select`,{value:P,onChange:e=>{F(e.target.value),et()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${P?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(`option`,{value:``,children:n(`inventory.spoolName`)}),ot.map(e=>(0,K.jsx)(`option`,{value:e,children:Ze[e]?.name||`#${e}`},e))]}),(ye.length>0||xe)&&(0,K.jsxs)(`select`,{value:xe,onChange:e=>{tt(e.target.value)},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${xe?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(`option`,{value:``,children:n(`inventory.storageLocation`)}),ye.map(e=>(0,K.jsx)(`option`,{value:String(e.id),children:e.name},e.id)),st&&(0,K.jsx)(`option`,{value:`__none__`,children:n(`inventory.storageLocationNone`)})]}),ct&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,K.jsxs)(`button`,{onClick:()=>{T(`active`),D(`all`),k(``),j(``),N(``),F(``),L(`all`),z(``),l(e=>(e.delete(`location_id`),e),{replace:!0}),et()},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:[(0,K.jsx)(Pu,{className:`w-3.5 h-3.5`}),n(`inventory.clearFilters`)]})]}),B!==`forecast`&&(0,K.jsxs)(`span`,{className:`ml-auto text-xs text-bambu-gray`,children:[ft.length,` `,ft.length===1?n(`inventory.spool`):n(`inventory.spools`),ie&&ht0?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:yt.map(e=>{if(e.type===`group`){let{key:t,spools:r,representative:i}=e,a=r.reduce((e,t)=>e+Math.max(0,t.label_weight-t.weight_used),0),o=G5({rgba:i.rgba,extraColors:i.extra_colors,effectType:i.effect_type,subtype:i.subtype,effectSize:`groupheader`}),s=W.has(t);return(0,K.jsxs)(`div`,{className:`col-span-full`,children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-green/30 hover:border-bambu-green transition-colors cursor-pointer`,onClick:()=>xt(t),children:[(0,K.jsx)(`div`,{className:`h-10 flex items-center px-4 gap-3`,style:o,children:(0,K.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:Hd(i.color_name,i.rgba)||`-`})}),(0,K.jsxs)(`div`,{className:`px-4 py-3 flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray transition-transform ${s?``:`-rotate-90`}`}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h3`,{className:`font-semibold text-white`,children:[i.material,i.subtype?` ${i.subtype}`:``]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i.brand||`-`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:n(`inventory.remaining`),children:c9(a)}),(0,K.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:n(`inventory.groupedSpools`,{count:r.length})})]})]})]}),s&&(0,K.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 mt-2 ml-4`,children:r.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(0,K.jsx)(p9,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,onClick:()=>d({spool:e,mode:`edit`}),onPrintLabel:()=>g([e.id]),onCopy:()=>d({spool:e,mode:`copy`}),t:n},e.id)})})]},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,K.jsx)(p9,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,onClick:()=>d({spool:t,mode:`edit`}),onPrintLabel:()=>g([t.id]),onCopy:()=>d({spool:t,mode:`copy`}),t:n},t.id)})}),(0,K.jsx)(PVe,{pageIndex:vt,pageSize:le,totalRows:ht,totalPages:_t,onPageChange:ce,onPageSizeChange:St,t:n})]}):(0,K.jsx)(h9,{hasFilters:ct,onAddSpool:()=>d({spool:null,mode:`create`}),t:n}):yt.length>0?(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[ut.map(e=>{let t=!!d9[e],r=ee?.column===e;return(0,K.jsx)(`th`,{className:`text-left py-3 px-4 text-xs font-medium uppercase tracking-wide select-none ${e===`remaining`?`min-w-[150px]`:``} ${t?`cursor-pointer hover:text-bambu-green transition-colors`:``} ${r?`text-bambu-green`:`text-bambu-gray`}`,onClick:t?()=>dt(e):void 0,children:(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[kVe[e]?.(n)??e,t&&(r?ee.direction===`asc`?(0,K.jsx)(Mo,{className:`w-3 h-3`}):(0,K.jsx)(Eo,{className:`w-3 h-3`}):(0,K.jsx)(Ao,{className:`w-3 h-3 opacity-30`}))]})},e)}),(0,K.jsx)(`th`,{className:`text-right py-3 px-4 text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:n(`common.actions`)})]})}),(0,K.jsx)(`tbody`,{children:yt.map(e=>{if(e.type===`group`){let{key:t,spools:r}=e,i=W.has(t),a=TVe(r),o=Math.max(0,a.label_weight-a.weight_used);return(0,K.jsx)(FVe,{spools:r,headerSpool:a,remaining:o,pct:a.label_weight>0?o/a.label_weight*100:0,isExpanded:i,onToggle:()=>xt(t),onEdit:e=>d({spool:e,mode:`edit`}),onCopy:e=>d({spool:e,mode:`copy`}),onArchive:e=>m({type:`archive`,spoolId:e}),onDelete:e=>m({type:`delete`,spoolId:e}),onPrintLabel:e=>g([e]),onResetConsumedCounter:e=>m({type:`reset-consumed-counter`,spoolId:e}),visibleColumns:ut,assignmentMap:Xe,catalogMap:Ze,currencySymbol:Ye,dateFormat:fe,t:n,onSyncWeight:Be},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,K.jsx)(m9,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,onEdit:()=>d({spool:t,mode:`edit`}),onCopy:()=>d({spool:t,mode:`copy`}),onRestore:()=>Ie.mutate(t.id),onArchive:()=>m({type:`archive`,spoolId:t.id}),onDelete:()=>m({type:`delete`,spoolId:t.id}),onPrintLabel:()=>g([t.id]),onResetConsumedCounter:()=>m({type:`reset-consumed-counter`,spoolId:t.id}),visibleColumns:ut,assignmentMap:Xe,catalogMap:Ze,currencySymbol:Ye,dateFormat:fe,t:n,onSyncWeight:Be},t.id)})})]})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 bg-bambu-dark-tertiary/50 border-t border-bambu-dark-tertiary text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:mt?`${ht} ${n(ht===1?`inventory.spool`:`inventory.spools`)}`:(0,K.jsxs)(K.Fragment,{children:[n(`inventory.showing`),` `,vt*gt+1,` `,n(`inventory.to`),` `,Math.min((vt+1)*gt,ht),` `,n(`inventory.of`),` `,ht,` `,n(`inventory.spools`)]})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`inventory.show`)}),(0,K.jsxs)(`select`,{value:le,onChange:e=>St(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[15,30,50,100].map(e=>(0,K.jsx)(`option`,{value:e,children:e},e)),(0,K.jsx)(`option`,{value:-1,children:n(`inventory.all`)})]}),!mt&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:()=>ce(0),disabled:vt===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,title:`First page`,children:(0,K.jsx)(is,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>ce(e=>Math.max(0,e-1)),disabled:vt===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(ns,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[n(`inventory.page`),` `,vt+1,` `,n(`inventory.of`),` `,_t]}),(0,K.jsx)(`button`,{onClick:()=>ce(e=>Math.min(_t-1,e+1)),disabled:vt>=_t-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(ts,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>ce(_t-1),disabled:vt>=_t-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,title:`Last page`,children:(0,K.jsx)(as,{className:`w-4 h-4`})})]})]})]})]}):(0,K.jsx)(h9,{hasFilters:ct,onAddSpool:()=>d({spool:null,mode:`create`}),t:n}),u!==null&&(0,K.jsx)(hVe,{isOpen:!0,onClose:()=>d(null),spool:u.spool,mode:u.mode,currencySymbol:Ye,spoolmanMode:e,spoolsQueryKey:pe}),p&&(0,K.jsx)(Ed,{title:p.type===`delete`?n(`common.delete`):p.type===`archive`?n(`inventory.archive`):p.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounter`):n(`inventory.resetAllConsumedCounters`),message:p.type===`delete`?n(`inventory.deleteConfirm`):p.type===`archive`?n(`inventory.archiveConfirm`):p.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounterConfirm`):n(`inventory.resetAllConsumedCountersConfirm`,{count:ze.length}),confirmText:p.type===`delete`?n(`common.delete`):p.type===`archive`?n(`inventory.archive`):n(`inventory.resetConsumedCounter`),variant:p.type===`archive`?`warning`:`danger`,onConfirm:()=>{p.type===`delete`?Pe.mutate(p.spoolId):p.type===`archive`?Fe.mutate(p.spoolId):p.type===`reset-consumed-counter`?Le.mutate(p.spoolId):Re.mutate(ze),m(null)},onCancel:()=>m(null)}),(0,K.jsx)(gVe,{isOpen:re,onClose:()=>U(!1),columns:te,defaultColumns:s9,onSave:lt}),(0,K.jsx)(SVe,{isOpen:h!==null,onClose:()=>g(null),availableSpools:$e,initialSelectedIds:h??[],spoolmanMode:e}),_&&(0,K.jsx)(CVe,{onClose:()=>v(!1),onImported:e=>{v(!1),r.invalidateQueries({queryKey:pe}),i(n(`inventory.csv.importSuccess`,`{{count}} spools imported`,{count:e}),`success`)}}),(0,K.jsx)(wVe,{open:S,onClose:()=>C(!1),onPickLocation:e=>tt(String(e))})]})}function PVe({pageIndex:e,pageSize:t,totalRows:n,totalPages:r,onPageChange:i,onPageSizeChange:a,t:o}){let s=t===-1;if(r<=1&&!s)return null;let c=s?n||1:t;return(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-2 text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:s?`${n} ${o(n===1?`inventory.spool`:`inventory.spools`)}`:(0,K.jsxs)(K.Fragment,{children:[o(`inventory.showing`),` `,e*c+1,` `,o(`inventory.to`),` `,Math.min((e+1)*c,n),` `,o(`inventory.of`),` `,n,` `,o(`inventory.spools`)]})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:o(`inventory.show`)}),(0,K.jsxs)(`select`,{value:t,onChange:e=>a(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[15,30,50,100].map(e=>(0,K.jsx)(`option`,{value:e,children:e},e)),(0,K.jsx)(`option`,{value:-1,children:o(`inventory.all`)})]}),!s&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:()=>i(0),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(is,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>i(Math.max(0,e-1)),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(ns,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[o(`inventory.page`),` `,e+1,` `,o(`inventory.of`),` `,r]}),(0,K.jsx)(`button`,{onClick:()=>i(Math.min(r-1,e+1)),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(ts,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>i(r-1),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(as,{className:`w-4 h-4`})})]})]})]})}function p9({spool:e,remaining:t,pct:n,onClick:r,onPrintLabel:i,onCopy:a,t:o}){let s=G5({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`card`});return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors cursor-pointer ${e.archived_at?`opacity-50`:``}`,onClick:r,children:[(0,K.jsxs)(`div`,{className:`h-14 flex items-center justify-center`,style:s,children:[(0,K.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:Hd(e.color_name,e.rgba)||`-`}),a&&(0,K.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},className:`p-1.5 bg-black/20 hover:bg-black/40 text-white rounded-full transition-colors`,title:o(`inventory.copySpool`),children:(0,K.jsx)(Ds,{className:`w-3.5 h-3.5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h3`,{className:`font-semibold text-white`,children:[e.material,e.subtype?` ${e.subtype}`:``]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i&&(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),i()},className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,title:o(`inventory.labels.printOne`),"aria-label":o(`inventory.labels.printOne`),children:(0,K.jsx)(bl,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[`#`,e.id]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray mb-1`,children:[(0,K.jsx)(`span`,{children:o(`inventory.remaining`)}),(0,K.jsxs)(`span`,{children:[Math.round(n),`%`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full ${n>50?`bg-bambu-green`:n>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(n,100)}%`}})}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(t),`g`]})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.labelWeight`),`: `]}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:c9(e.label_weight)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.weightUsed`),`: `]}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e.weight_used>0?c9(e.weight_used):`-`})]})]}),e.note&&(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray/60 pt-2 border-t border-bambu-dark-tertiary truncate`,title:e.note,children:e.note})]})]})}function m9({spool:e,remaining:t,pct:n,onEdit:r,onCopy:i,onRestore:a,onArchive:o,onDelete:s,onPrintLabel:c,onResetConsumedCounter:l,visibleColumns:u,assignmentMap:d,catalogMap:f,currencySymbol:p,dateFormat:m,t:h,onSyncWeight:g}){return(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer ${e.archived_at?`opacity-50`:``}`,onClick:r,children:[u.map(r=>(0,K.jsx)(`td`,{className:`py-3 px-4`,children:u9[r]?.({spool:e,remaining:t,pct:n,assignmentMap:d,catalogMap:f,currencySymbol:p,dateFormat:m,t:h,onSyncWeight:g})},r)),(0,K.jsx)(`td`,{className:`py-3 px-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`button`,{onClick:r,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:h(`common.edit`),children:(0,K.jsx)(fl,{className:`w-4 h-4`})}),i&&(0,K.jsx)(`button`,{onClick:i,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:h(`inventory.copySpool`),children:(0,K.jsx)(Ds,{className:`w-4 h-4`})}),c&&(0,K.jsx)(`button`,{onClick:c,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:h(`inventory.labels.printOne`),children:(0,K.jsx)(bl,{className:`w-4 h-4`})}),l&&e.weight_used>0&&(0,K.jsx)(`button`,{onClick:l,className:`p-1.5 text-bambu-gray hover:text-orange-400 rounded transition-colors`,title:h(`inventory.resetConsumedCounterTooltip`),children:(0,K.jsx)(Hs,{className:`w-4 h-4`})}),e.archived_at?(0,K.jsx)(`button`,{onClick:a,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:h(`inventory.restore`),children:(0,K.jsx)(Tl,{className:`w-4 h-4`})}):(0,K.jsx)(`button`,{onClick:o,className:`p-1.5 text-bambu-gray hover:text-yellow-400 rounded transition-colors`,title:h(`inventory.archive`),children:(0,K.jsx)(wo,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:s,className:`p-1.5 text-bambu-gray hover:text-red-400 rounded transition-colors`,title:h(`common.delete`),children:(0,K.jsx)(hu,{className:`w-4 h-4`})})]})})]})}function FVe({spools:e,headerSpool:t,remaining:n,pct:r,isExpanded:i,onToggle:a,onEdit:o,onCopy:s,onArchive:c,onDelete:l,onPrintLabel:u,onResetConsumedCounter:d,visibleColumns:f,assignmentMap:p,catalogMap:m,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v}){return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer bg-bambu-green/5`,onClick:a,children:[f.map((a,o)=>(0,K.jsx)(`td`,{className:`py-3 px-4`,children:o===0?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(es,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?``:`-rotate-90`}`}),u9[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v})]}):a===`id`?(0,K.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:_(`inventory.groupedSpools`,{count:e.length})}):u9[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v})},a)),(0,K.jsx)(`td`,{className:`py-3 px-4`,children:(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.map(e=>`#${e.id}`).join(`, `)})})]}),i&&e.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(0,K.jsx)(m9,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,onEdit:()=>o(e),onCopy:s?()=>s(e):void 0,onRestore:()=>{},onArchive:()=>c(e.id),onDelete:()=>l(e.id),onPrintLabel:u?()=>u(e.id):void 0,onResetConsumedCounter:d?()=>d(e.id):void 0,visibleColumns:f,assignmentMap:p,catalogMap:m,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v},e.id)})]})}function h9({hasFilters:e,onAddSpool:t,t:n}){return(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 px-4`,children:[(0,K.jsxs)(`div`,{className:`relative mb-6`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 -m-4 bg-bambu-green/5 rounded-full blur-2xl`}),(0,K.jsxs)(`div`,{className:`relative flex items-center justify-center w-24 h-24 rounded-2xl bg-gradient-to-br from-bambu-dark-secondary to-bambu-dark-tertiary border border-bambu-dark-tertiary shadow-lg`,children:[(0,K.jsx)(`div`,{className:`absolute -top-1 -right-1 w-3 h-3 rounded-full bg-bambu-green/30`}),(0,K.jsx)(`div`,{className:`absolute -bottom-2 -left-2 w-2 h-2 rounded-full bg-bambu-green/20`}),e?(0,K.jsx)(Nl,{className:`w-10 h-10 text-bambu-gray/40`,strokeWidth:1.5}):(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`div`,{className:`w-14 h-14 rounded-full border-4 border-bambu-gray/20 flex items-center justify-center`,children:(0,K.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-bambu-gray/10 border-2 border-bambu-gray/20`})}),(0,K.jsx)(`div`,{className:`absolute -bottom-1 -right-1 w-6 h-6 rounded-full bg-bambu-green flex items-center justify-center shadow-md`,children:(0,K.jsx)(`span`,{className:`text-white text-lg font-bold leading-none`,children:`+`})})]})]})]}),(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2 text-center`,children:e?n(`inventory.noSpoolsMatch`):n(`inventory.noSpools`).split(`.`)[0]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray text-center max-w-sm mb-6`,children:n(e?`inventory.noSpoolsMatchDesc`:`inventory.noSpools`)}),!e&&(0,K.jsxs)($,{onClick:t,children:[(0,K.jsx)(cl,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})}function g9(e,t){let n=e?.[t];return typeof n==`string`?n:``}function IVe(e){return e.replace(/(https?:\/\/(?:makerworld|public-cdn)\.bblmw\.com\/[^\s"']+)/gi,e=>`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`)}function _9(e){return e?/^https?:\/\/(makerworld|public-cdn)\.bblmw\.com\//i.test(e)?`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`:e:``}function v9(e,t){let n=e?.[t];return typeof n==`number`?n:null}function LVe(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function y9(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])y9(r,t+1,n);return n}function RVe(e,t){return t(e<1?`makerworld.phaseResolving`:`makerworld.phaseDownloading`)}function zVe(e){let[t,n]=(0,y.useState)(0);return(0,y.useEffect)(()=>{if(!e){n(0);return}let t=Date.now(),r=()=>n(Math.floor((Date.now()-t)/1e3));r();let i=window.setInterval(r,1e3);return()=>window.clearInterval(i)},[e]),t}function BVe(){let{t:e}=G(),{hasPermission:t}=sd(),{showToast:n}=xd(),r=Qa(),i=t(`makerworld:import`),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)({}),S=q({queryKey:[`makerworld-status`],queryFn:()=>Q.getMakerworldStatus()}),C=q({queryKey:[`library-folders`],queryFn:()=>Q.getLibraryFolders()}),w=q({queryKey:[`makerworld-recent-imports`],queryFn:()=>Q.getMakerworldRecentImports(10)}),T=q({queryKey:[`settings`],queryFn:()=>Q.getSettings()}),E=T.data?.use_slicer_api??!1,D=T.data?.preferred_slicer||`bambu_studio`,O=T.data?.open_in_slicer||D,k=E?D:O,A=k===`orcaslicer`?`OrcaSlicer`:`Bambu Studio`,[j,M]=(0,y.useState)(null),N=(e,t)=>{M({kind:`libraryFile`,id:e,filename:t})},P=J({mutationFn:e=>Q.resolveMakerworldUrl(e),onSuccess:(e,t)=>{c(e),v(t),x({})},onError:t=>n(t.message||e(`makerworld.errors.resolveFailed`),`error`)});(0,y.useEffect)(()=>{s!==null&&a.trim()!==_.trim()&&(c(null),v(``),x({}))},[a,s,_]);let F=J({mutationFn:({instanceId:e,profileId:t})=>Q.importMakerworldInstance(s?.model_id??0,e,t,l),onSuccess:t=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),t.profile_id&&x(e=>({...e,[t.profile_id]:t})),n(t.was_existing?e(`makerworld.alreadyInLibrary`):e(`makerworld.importSuccess`,{filename:t.filename}),`success`)},onError:t=>n(t.message||e(`makerworld.errors.downloadFailed`),`error`)}),I=J({mutationFn:({libraryFileId:e})=>Q.deleteLibraryFile(e),onSuccess:(t,{profileId:i})=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),r.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),x(e=>{let t={...e};return delete t[i],t}),m(null),n(e(`makerworld.importDeleted`),`success`)},onError:t=>{m(null),n(t.message||e(`makerworld.errors.deleteFailed`),`error`)}}),L=J({mutationFn:({instanceId:e,profileId:t})=>Q.importMakerworldInstance(s?.model_id??0,e,t,l),onSuccess:async e=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),r.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),e.profile_id&&x(t=>({...t,[e.profile_id]:e})),E?N(e.library_file_id,e.filename):await H(e.library_file_id,e.filename,k)},onError:t=>n(t.message||e(`makerworld.errors.downloadFailed`),`error`)}),R=zVe(F.isPending||L.isPending),z=RVe(R,e),B=e=>{e?.preventDefault();let t=a.trim();t&&P.mutate(t)};(0,y.useEffect)(()=>{if(!h)return;let e=e=>{e.key===`Escape`?g(null):e.key===`ArrowLeft`?g(e=>e&&e.index>0?{...e,index:e.index-1}:e):e.key===`ArrowRight`&&g(e=>e&&e.indexwindow.removeEventListener(`keydown`,e)},[h]);let V=e=>{let t=(Array.isArray(e.pictures)?e.pictures:[]).filter(e=>typeof e==`object`&&!!e).map(e=>({name:g9(e,`name`)||`image`,url:g9(e,`url`)})).filter(e=>e.url);if(t.length>0)return t;let n=g9(e,`cover`);return n?[{name:`cover`,url:n}]:[]},ee=async()=>{if(!s)return;let e=s.instances.filter(e=>{let t=v9(e,`profileId`);return t!==null&&!b[t]});if(e.length!==0){f({current:0,total:e.length});try{for(let t=0;t{try{let{token:r}=await Q.createLibrarySlicerToken(e),i=Q.getLibrarySlicerDownloadUrl(e,r,t);Uq(`${window.location.origin}${i}`,n)}catch{let t=Q.getLibraryFileDownloadUrl(e);Uq(`${window.location.origin}${t}`,n)}},te=s?.design,ne=LVe(te,`designCreator`),re=s?.instances??[],U=(s?.already_imported_library_ids.length??0)>0,ie=S.data?.has_cloud_token??!1,ae=S.data?.can_download??!1,W=(0,y.useMemo)(()=>g9(te,`coverUrl`),[te]),oe=g9(te,`title`),se=g9(te,`summary`),ce=g9(te,`license`),le=v9(te,`downloadCount`);return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 max-w-screen-2xl space-y-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)(hc,{className:`w-7 h-7 text-bambu-green`}),e(`makerworld.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`makerworld.description`)})]}),(0,K.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[1fr_20rem]`,children:[(0,K.jsxs)(`div`,{className:`space-y-6 min-w-0`,children:[!ie&&(0,K.jsx)(pd,{className:`border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20`,children:(0,K.jsx)(hd,{children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3 py-2`,children:[(0,K.jsx)(ss,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0`}),(0,K.jsxs)(`div`,{className:`text-sm`,children:[(0,K.jsx)(`p`,{className:`font-medium text-amber-900 dark:text-amber-100`,children:e(`makerworld.signInRequiredTitle`)}),(0,K.jsxs)(`p`,{className:`text-amber-800 dark:text-amber-200 mt-1`,children:[e(`makerworld.signInRequiredBody`),` `,(0,K.jsx)(bi,{to:`/profiles`,className:`underline`,children:e(`makerworld.openCloudSettings`)})]})]})]})})}),(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`makerworld.pasteUrlHeader`)})}),(0,K.jsx)(hd,{children:(0,K.jsxs)(`form`,{onSubmit:B,className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:e(`makerworld.pasteUrlPlaceholder`),className:`flex-1 min-w-0 px-3 py-2 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,autoComplete:`off`}),(0,K.jsxs)($,{type:`submit`,variant:`primary`,disabled:!a.trim()||P.isPending,children:[P.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(ko,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.resolveButton`)})]})]})})]}),s&&(0,K.jsx)(pd,{children:(0,K.jsx)(hd,{children:(0,K.jsxs)(`div`,{className:`flex gap-4 py-2`,children:[W&&(0,K.jsx)(`img`,{src:_9(W),alt:oe,className:`w-32 h-32 object-cover rounded`,loading:`lazy`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`h3`,{className:`text-xl font-semibold truncate`,children:oe||e(`makerworld.untitledModel`)}),ne&&(0,K.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(`makerworld.byCreator`,{name:g9(ne,`name`)})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-3 mt-2 text-xs text-gray-500 dark:text-gray-400`,children:[le!==null&&(0,K.jsx)(`span`,{children:e(`makerworld.downloadsCount`,{count:le})}),ce&&(0,K.jsxs)(`span`,{children:[e(`makerworld.licensePrefix`),`: `,ce]}),U&&(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400`,children:[(0,K.jsx)($o,{className:`w-3 h-3`}),` `,e(`makerworld.alreadyImported`)]})]}),se&&(0,K.jsx)(`div`,{className:`mt-3 text-sm prose prose-sm max-w-none dark:prose-invert line-clamp-3`,dangerouslySetInnerHTML:{__html:HJ.sanitize(IVe(se))}}),s&&(0,K.jsxs)(`a`,{href:`https://makerworld.com/models/${s.model_id}${s.profile_id?`#profileId-${s.profile_id}`:``}`,target:`_blank`,rel:`noopener noreferrer`,className:`mt-3 inline-flex items-center gap-1 text-xs text-brand-500 hover:underline`,children:[(0,K.jsx)(Us,{className:`w-3 h-3`}),` `,e(`makerworld.openOnMakerworld`)]})]})]})})}),s&&re.length>0&&(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`makerworld.platesHeader`,{count:re.length})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(`label`,{className:`text-xs text-gray-600 dark:text-gray-400`,children:e(`makerworld.importTo`)}),(0,K.jsxs)(`select`,{value:l??``,onChange:e=>u(e.target.value?Number(e.target.value):null),className:`text-sm px-2 py-1 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,disabled:d!==null,children:[(0,K.jsx)(`option`,{value:``,children:e(`makerworld.folderAuto`)}),(C.data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>y9(e)).map(({folder:e,depth:t})=>(0,K.jsx)(`option`,{value:e.id,children:`${`— `.repeat(t)}${e.name}`},e.id))]}),(0,K.jsx)($,{variant:`primary`,size:`sm`,disabled:!i||!ae||d!==null||F.isPending||L.isPending,onClick:ee,children:d===null?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.importAll`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),(0,K.jsxs)(`span`,{className:`ml-2`,children:[e(`makerworld.importAllProgress`,{current:d.current,total:d.total}),R>0&&` · ${z} · ${R}s`]})]})})]})]})}),(0,K.jsx)(hd,{children:(0,K.jsx)(`div`,{className:`grid gap-3`,children:re.map((t,n)=>{let r=v9(t,`id`),a=v9(t,`profileId`),o=g9(t,`title`),s=g9(t,`cover`),c=v9(t,`materialCnt`),l=t?.needAms===!0,u=v9(t,`downloadCount`),f=t?.compatibility??null,p=t?.otherCompatibility??null,h=f?.devProductName??null,_=Array.isArray(p)?p.map(e=>e?.devProductName??``).filter(Boolean):[];if(r==null)return null;let v=F.isPending&&F.variables?.instanceId===r,y=L.isPending&&L.variables?.instanceId===r,x=a===null?void 0:b[a];return(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border rounded border-gray-200 dark:border-gray-700`,children:[(0,K.jsxs)(`div`,{className:`flex gap-3 items-center`,children:[(()=>{let n=V(t),r=n.length>0;return(0,K.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&g({images:n,index:0}),className:`relative w-16 h-16 shrink-0 rounded overflow-hidden group`,"aria-label":e(`makerworld.openGallery`),children:[s?(0,K.jsx)(`img`,{src:_9(s),alt:``,className:`w-16 h-16 object-cover`,loading:`lazy`}):(0,K.jsx)(`div`,{className:`w-16 h-16 bg-gray-100 dark:bg-gray-800`}),n.length>1&&(0,K.jsxs)(`span`,{className:`absolute bottom-0.5 right-0.5 bg-black/70 text-white text-[10px] px-1.5 py-0.5 rounded flex items-center gap-1`,children:[(0,K.jsx)(Oc,{className:`w-2.5 h-2.5`}),n.length]})]})})(),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`font-medium truncate`,children:o||e(`makerworld.plateDefaultName`,{n:n+1})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-xs text-gray-500 dark:text-gray-400 mt-1`,children:[h&&(0,K.jsx)(`span`,{className:`font-medium text-gray-700 dark:text-gray-300`,children:e(`makerworld.slicedFor`,{printer:h,defaultValue:`Sliced for {{printer}}`})}),c!==null&&(0,K.jsx)(`span`,{children:e(`makerworld.materialCount`,{count:c})}),l&&(0,K.jsx)(`span`,{children:e(`makerworld.amsRequired`)}),u!==null&&(0,K.jsx)(`span`,{children:e(`makerworld.downloadsCount`,{count:u})})]}),_.length>0&&(0,K.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,title:_.join(`, `),children:e(`makerworld.alsoCompatible`,{printers:_.slice(0,6).join(`, `)+(_.length>6?`…`:``),defaultValue:`Also marked compatible: {{printers}}`})})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,disabled:!i||!ae||v||y||d!==null,onClick:()=>F.mutate({instanceId:r,profileId:a}),title:ae?void 0:e(`makerworld.signInRequiredTitle`),children:v?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),(0,K.jsxs)(`span`,{className:`ml-2`,children:[z,R>0&&` · ${R}s`]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Is,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.importToLibrary`)})]})}),(0,K.jsx)($,{variant:`primary`,size:`sm`,disabled:!i||!ae||v||y||d!==null,onClick:()=>L.mutate({instanceId:r,profileId:a}),title:ae?void 0:e(`makerworld.signInRequiredTitle`),children:y?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),(0,K.jsxs)(`span`,{className:`ml-2`,children:[z,R>0&&` · ${R}s`]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Us,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.sliceIn`,{slicer:A})})]})})]})]}),x&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 pl-20 text-xs`,children:[(0,K.jsx)($o,{className:`w-3.5 h-3.5 text-emerald-600 dark:text-emerald-400 shrink-0`}),(0,K.jsx)(`span`,{className:`text-emerald-700 dark:text-emerald-300`,children:x.was_existing?e(`makerworld.lastImportAlreadyInLibrary`):e(`makerworld.lastImportSuccess`)}),(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>{let e=x.folder_id?`/files?folder=${x.folder_id}`:`/files`;window.location.assign(e)},children:[(0,K.jsx)(rc,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.viewInLibrary`)})]}),E?(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>N(x.library_file_id,x.filename),children:[(0,K.jsx)(ws,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`slice.action`,`Slice`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>H(x.library_file_id,x.filename,`bambu_studio`),children:[(0,K.jsx)(Us,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.openInBambuStudio`)})]}),(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>H(x.library_file_id,x.filename,`orcaslicer`),children:[(0,K.jsx)(Us,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.openInOrcaSlicer`)})]})]}),(0,K.jsx)(`div`,{className:`ml-auto`,children:(0,K.jsx)($,{variant:`ghost`,size:`sm`,disabled:I.isPending&&I.variables?.profileId===a,onClick:()=>{a!==null&&m({libraryFileId:x.library_file_id,profileId:a,filename:x.filename})},title:e(`makerworld.deleteImport`),children:I.isPending&&I.variables?.profileId===a?(0,K.jsx)(X,{className:`w-3.5 h-3.5 animate-spin`}):(0,K.jsx)(hu,{className:`w-3.5 h-3.5 text-red-500`})})})]})]},r)})})})]})]}),(0,K.jsx)(`aside`,{className:`lg:sticky lg:top-6 lg:self-start min-w-0`,children:w.data&&w.data.length>0&&(0,K.jsxs)(pd,{children:[(0,K.jsx)(md,{children:(0,K.jsx)(`h2`,{className:`text-base font-semibold`,children:e(`makerworld.recentImportsHeader`)})}),(0,K.jsx)(hd,{children:(0,K.jsx)(`div`,{className:`flex flex-col gap-2 max-h-[28rem] overflow-y-auto -mx-2 px-2`,children:w.data.map(t=>(0,K.jsxs)(`div`,{className:`flex gap-2 p-2 border rounded border-gray-200 dark:border-gray-700`,children:[t.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getLibraryFileThumbnailUrl(t.library_file_id),alt:``,className:`w-12 h-12 shrink-0 object-cover rounded bg-gray-100 dark:bg-gray-800`,loading:`lazy`}):(0,K.jsx)(`div`,{className:`w-12 h-12 shrink-0 rounded bg-gray-100 dark:bg-gray-800`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,K.jsx)(`p`,{className:`text-xs font-medium truncate`,title:t.filename,children:t.filename}),(0,K.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{let e=t.folder_id?`/files?folder=${t.folder_id}`:`/files`;window.location.assign(e)},title:e(`makerworld.viewInLibrary`),children:(0,K.jsx)(rc,{className:`w-3.5 h-3.5`})}),E?(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>N(t.library_file_id,t.filename),title:e(`slice.action`,`Slice`),children:(0,K.jsx)(ws,{className:`w-3.5 h-3.5`})}):(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>H(t.library_file_id,t.filename,`bambu_studio`),title:e(`makerworld.openInBambuStudio`),children:(0,K.jsx)(Us,{className:`w-3.5 h-3.5`})}),t.source_url&&(0,K.jsx)(`a`,{href:t.source_url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center h-7 w-7 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300`,title:e(`makerworld.openOnMakerworld`),children:(0,K.jsx)(hc,{className:`w-3.5 h-3.5`})})]})]})]},t.library_file_id))})})]})})]}),(0,K.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 pt-4 border-t border-gray-200 dark:border-gray-700`,children:e(`makerworld.disclaimer`)}),p&&(0,K.jsx)(Ed,{title:e(`makerworld.deleteImport`),message:e(`makerworld.confirmDelete`,{filename:p.filename}),confirmText:e(`makerworld.deleteImport`),variant:`danger`,isLoading:I.isPending,loadingText:e(`makerworld.importDeleting`),onCancel:()=>m(null),onConfirm:()=>I.mutate({libraryFileId:p.libraryFileId,profileId:p.profileId})}),j&&(0,K.jsx)(Bq,{source:j,onClose:()=>M(null)}),h&&(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:()=>g(null),role:`dialog`,"aria-modal":`true`,children:[(0,K.jsx)(`button`,{type:`button`,className:`absolute top-4 right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white`,onClick:e=>{e.stopPropagation(),g(null)},"aria-label":e(`common.close`,`Close`),children:(0,K.jsx)(Pu,{className:`w-5 h-5`})}),h.images.length>1&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{type:`button`,className:`absolute left-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:h.index===0,onClick:e=>{e.stopPropagation(),g(e=>e&&{...e,index:Math.max(0,e.index-1)})},"aria-label":e(`makerworld.galleryPrev`),children:(0,K.jsx)(ns,{className:`w-6 h-6`})}),(0,K.jsx)(`button`,{type:`button`,className:`absolute right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:h.index>=h.images.length-1,onClick:e=>{e.stopPropagation(),g(e=>e&&{...e,index:Math.min(e.images.length-1,e.index+1)})},"aria-label":e(`makerworld.galleryNext`),children:(0,K.jsx)(ts,{className:`w-6 h-6`})})]}),(0,K.jsx)(`img`,{src:_9(h.images[h.index].url),alt:h.images[h.index].name,className:`max-w-[90vw] max-h-[90vh] object-contain`,onClick:e=>e.stopPropagation()}),h.images.length>1&&(0,K.jsxs)(`div`,{className:`absolute bottom-6 left-1/2 -translate-x-1/2 text-white bg-black/60 px-3 py-1 rounded text-xs`,children:[h.index+1,` / `,h.images.length]})]})]})}var b9=[`DEBUG`,`INFO`,`WARNING`,`ERROR`],x9={DEBUG:`text-gray-400`,INFO:`text-blue-400`,WARNING:`text-yellow-400`,ERROR:`text-red-400`},VVe={DEBUG:Ho,INFO:kc,WARNING:vu,ERROR:ss};function HVe(){let e=Qa(),[t,n]=(0,y.useState)(!0),[r,i]=(0,y.useState)(new Set),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`ALL`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),p=(0,y.useRef)(null),{data:m,isLoading:h,refetch:g}=q({queryKey:[`application-logs`,s,a],queryFn:()=>td.getLogs({limit:200,level:s===`ALL`?void 0:s,search:a||void 0}),refetchInterval:d?2e3:!1,enabled:l});(0,y.useEffect)(()=>{l||f(!1)},[l]);let _=J({mutationFn:()=>td.clearLogs(),onSuccess:()=>{e.invalidateQueries({queryKey:[`application-logs`]})}});(0,y.useEffect)(()=>{t&&p.current&&m?.entries&&(p.current.scrollTop=p.current.scrollHeight)},[m?.entries,t]);let v=e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},b=e=>{let t=e.split(` `);return t.length>=2?t[1]:e},x=(0,y.useMemo)(()=>m?.entries??[],[m?.entries]),S=(0,y.useMemo)(()=>[...x].reverse(),[x]),C=({level:e})=>(0,K.jsx)(VVe[e]||kc,{className:`w-3.5 h-3.5 ${x9[e]||`text-gray-400`}`});return(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`button`,{onClick:()=>u(!l),className:`w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/50 transition-colors`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${d?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,K.jsx)(Ho,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{className:`text-left`,children:[(0,K.jsx)(`p`,{className:`font-medium text-white`,children:`Application Logs`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:d?`Live streaming - ${m?.filtered_count??0} entries`:`View and filter application logs`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[d&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 bg-bambu-green/20 rounded text-bambu-green text-xs`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 bg-bambu-green rounded-full animate-pulse`}),`Live`]}),l?(0,K.jsx)(rs,{className:`w-5 h-5 text-bambu-gray`}):(0,K.jsx)(es,{className:`w-5 h-5 text-bambu-gray`})]})]}),l&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary`,children:[(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 flex-wrap`,children:[d?(0,K.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),f(!1)},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-red-500/20 text-red-400 hover:bg-red-500/30 rounded transition-colors`,children:[(0,K.jsx)(tu,{className:`w-4 h-4`}),`Stop`]}):(0,K.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),f(!0),g()},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 rounded transition-colors`,children:[(0,K.jsx)(hl,{className:`w-4 h-4`}),`Start`]}),(0,K.jsxs)(`button`,{onClick:()=>_.mutate(),disabled:_.isPending||x.length===0,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50`,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),`Clear`]}),(0,K.jsx)(`button`,{onClick:()=>g(),disabled:h,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50`,children:(0,K.jsx)(Cl,{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:t,onChange:e=>n(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark-tertiary`}),`Auto-scroll`]}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[m?.filtered_count??0,`/`,m?.total_in_file??0]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Nl,{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:`Search message or logger name...`,value:a,onChange:e=>o(e.target.value),className:`w-full pl-8 pr-8 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),a&&(0,K.jsx)(`button`,{onClick:()=>o(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark-secondary rounded border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>c(`ALL`),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${s===`ALL`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`All`}),b9.map((e,t)=>(0,K.jsx)(`button`,{onClick:()=>c(e),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${t===b9.length-1?`rounded-r`:``} ${s===e?`${x9[e]} bg-bambu-dark-tertiary`:`text-bambu-gray hover:text-white`}`,children:e},e))]})]})]}),(0,K.jsx)(`div`,{ref:p,className:`overflow-auto font-mono text-xs bg-black min-h-[300px] max-h-[500px]`,children:x.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-[300px] text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`mb-2`,children:`No log entries found`}),(0,K.jsx)(`p`,{className:`text-sm`,children:`Log file may be empty or cleared`})]}):(0,K.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary/30`,children:S.map((e,t)=>{let n=r.has(t),i=e.message.includes(` `);return(0,K.jsx)(`div`,{className:`p-2 cursor-pointer hover:bg-bambu-dark-secondary/50 transition-colors ${n?`bg-bambu-dark-secondary/30`:``}`,onClick:()=>i&&v(t),children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray/70 shrink-0 w-20`,children:b(e.timestamp)}),(0,K.jsx)(`span`,{className:`shrink-0`,children:(0,K.jsx)(C,{level:e.level})}),(0,K.jsxs)(`span`,{className:`text-purple-400/80 shrink-0 max-w-[200px] truncate`,title:e.logger_name,children:[`[`,e.logger_name,`]`]}),(0,K.jsx)(`span`,{className:`flex-1 ${x9[e.level]||`text-white/80`} ${!n&&i?`truncate`:``}`,children:n?(0,K.jsx)(`pre`,{className:`whitespace-pre-wrap break-all`,children:e.message}):e.message.split(` -`)[0]}),i&&(0,K.jsx)(`span`,{className:`text-bambu-gray/50 shrink-0`,children:n?(0,K.jsx)(rs,{className:`w-3.5 h-3.5`}):(0,K.jsx)(es,{className:`w-3.5 h-3.5`})})]})},t)})})}),(0,K.jsx)(`div`,{className:`flex items-center justify-between p-3 border-t border-bambu-dark-tertiary text-sm text-bambu-gray`,children:d?(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`}),`Auto-refreshing every 2 seconds`]}):(0,K.jsx)(`span`,{children:`Click Start to enable live log streaming`})})]})]})}function HVe(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(2)} GB`}function S9({icon:e,label:t,value:n,subValue:r,color:i=`text-bambu-green`}){return(0,K.jsxs)(`div`,{className:`flex items-start gap-3 p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary ${i}`,children:(0,K.jsx)(e,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,K.jsx)(`p`,{className:`text-lg font-semibold text-white truncate`,children:n}),r&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:r})]})]})}function C9({percent:e,color:t=`bg-bambu-green`}){return(0,K.jsx)(`div`,{className:`w-full h-2 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full ${t} transition-all duration-300`,style:{width:`${Math.min(100,e)}%`}})})}function w9({title:e,icon:t,children:n}){return(0,K.jsxs)(pd,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,K.jsx)(t,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e})]}),n]})}function UVe(){let{t:e}=G(),t=Qa(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),{data:u,isLoading:d,refetch:f,isFetching:p}=q({queryKey:[`systemInfo`],queryFn:Q.getSystemInfo,refetchInterval:3e4}),{data:m}=q({queryKey:[`debugLogging`],queryFn:td.getDebugLoggingState,staleTime:10*1e3,refetchInterval:10*1e3}),{data:h}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:g}=q({queryKey:[`library-stats`],queryFn:Q.getLibraryStats}),{data:_}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:v,refetch:b,isFetching:x}=q({queryKey:[`systemHealth`],queryFn:Q.getSystemHealth,staleTime:60*1e3}),S=h?.time_format||`system`,C=async()=>{s(!0);try{let e=await td.setDebugLogging(!m?.enabled);t.setQueryData([`debugLogging`],e)}catch(e){console.error(`Failed to toggle debug logging:`,e)}finally{s(!1)}},w=async()=>{r(null),a(!0);try{await td.downloadSupportBundle()}catch(e){r(e instanceof Error?e.message:`Failed to download support bundle`)}finally{a(!1)}};if(d)return(0,K.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(!u)return(0,K.jsx)(`div`,{className:`p-6 text-center text-bambu-gray`,children:e(`system.failedToLoad`,`Failed to load system information`)});let T=u.storage.disk_percent_used>90?`bg-red-500`:u.storage.disk_percent_used>75?`bg-yellow-500`:`bg-bambu-green`,E=u.memory.percent_used>90?`bg-red-500`:u.memory.percent_used>75?`bg-yellow-500`:`bg-bambu-green`;return(0,K.jsxs)(`div`,{className:`p-6 space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`system.title`,`System Information`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`system.subtitle`,`Monitor system resources and database statistics`)})]}),(0,K.jsxs)(`button`,{onClick:()=>f(),disabled:p,className:`flex items-center gap-2 px-4 py-2 bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary rounded-lg transition-colors disabled:opacity-50`,children:[(0,K.jsx)(Cl,{className:`w-4 h-4 ${p?`animate-spin`:``}`}),e(`common.refresh`,`Refresh`)]})]}),(0,K.jsx)(w9,{title:e(`system.application`,`Application`),icon:Il,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,K.jsx)(S9,{icon:Il,label:e(`system.version`,`Version`),value:`v${u.app.version}`}),(0,K.jsx)(S9,{icon:_s,label:e(`system.uptime`,`System Uptime`),value:u.system.uptime_formatted}),(0,K.jsx)(S9,{icon:Il,label:e(`system.hostname`,`Hostname`),value:u.system.hostname})]})}),(0,K.jsx)(w9,{title:e(`support.title`,`Support & Troubleshooting`),icon:xc,children:(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`support.description`,`Enable debug logging to capture detailed information, then download a support bundle to share when reporting issues.`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${m?.enabled?`bg-amber-500/20 text-amber-500`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,K.jsx)(Ho,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.debugLogging`,`Debug Logging`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[m?.enabled?e(`support.debugLoggingEnabled`,`Capturing detailed logs`):e(`support.debugLoggingDisabled`,`Normal logging level`),m?.enabled&&m.duration_seconds!==null&&(0,K.jsxs)(`span`,{className:`text-amber-400 ml-2`,children:[`(`,Math.floor(m.duration_seconds/60),`m `,m.duration_seconds%60,`s)`]})]})]})]}),(0,K.jsxs)(`button`,{onClick:C,disabled:o,className:`px-4 py-2 rounded-lg font-medium transition-colors flex items-center gap-2 ${m?.enabled?`bg-amber-500/20 text-amber-400 hover:bg-amber-500/30`:`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`} disabled:opacity-50`,children:[o&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),m?.enabled?e(`support.disableDebug`,`Disable`):e(`support.enableDebug`,`Enable`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-green`,children:(0,K.jsx)(Is,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.supportBundle`,`Support Bundle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`support.supportBundleDescription`,`Download system info and logs as a ZIP file`)})]})]}),(0,K.jsxs)(`button`,{onClick:w,disabled:i||!m?.enabled,className:`px-4 py-2 rounded-lg font-medium bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 transition-colors flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed`,title:m?.enabled?void 0:e(`support.enableDebugFirst`,`Enable debug logging first`),children:[i&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),i?e(`support.bundleGenerating`,`Generating...`):e(`common.download`,`Download`)]})]}),i&&(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark-tertiary/40 rounded-lg space-y-1`,children:[(0,K.jsxs)(`p`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,K.jsx)(X,{className:`w-3.5 h-3.5 animate-spin text-bambu-green`}),e(`support.bundleGenerating`,`Generating...`)]}),(0,K.jsxs)(`ul`,{className:`text-xs text-bambu-gray list-disc list-inside space-y-0.5 pl-1`,children:[(0,K.jsx)(`li`,{children:e(`support.bundleStepConnection`,`Running printer connectivity checks`)}),(0,K.jsx)(`li`,{children:e(`support.bundleStepVirtualPrinters`,`Running virtual-printer setup checks`)}),(0,K.jsx)(`li`,{children:e(`support.bundleStepLogScan`,`Scanning recent logs for known issues`)}),(0,K.jsx)(`li`,{children:e(`support.bundleStepBuild`,`Building the support bundle ZIP`)})]})]}),n&&(0,K.jsx)(`div`,{className:`p-3 bg-red-500/20 border border-red-500/30 rounded-lg text-red-400 text-sm`,children:n}),!m?.enabled&&(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark-tertiary/50 rounded-lg`,children:(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`text-amber-400 font-medium`,children:e(`support.instructions`,`To report an issue:`)}),(0,K.jsx)(`br`,{}),`1. `,e(`support.step1`,`Enable debug logging`),(0,K.jsx)(`br`,{}),`2. `,e(`support.step2`,`Reproduce the issue`),(0,K.jsx)(`br`,{}),`3. `,e(`support.step3`,`Download the support bundle`),(0,K.jsx)(`br`,{}),`4. `,e(`support.step4`,`Attach the ZIP file to your issue report`)]})}),(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e(`support.privacyTitle`,`What's in the support bundle?`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 text-sm`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-bambu-green font-medium mb-1`,children:e(`support.collected`,`Collected:`)}),(0,K.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem1`,`App version and debug mode`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem2`,`OS, architecture, Python version`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem3`,`Database statistics (counts only)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem4`,`Printer models and nozzle counts`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem5`,`Non-sensitive settings (themes, formats)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem6`,`Debug logs (sanitized)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem7`,`Printer connectivity and firmware versions`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem8`,`Integration status (Spoolman, MQTT, HA)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem9`,`Network interfaces (subnets only)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem10`,`Python package versions`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem11`,`Database health checks`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem12`,`Docker environment details`)]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-red-400 font-medium mb-1`,children:e(`support.notCollected`,`NOT collected:`)}),(0,K.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem1`,`Printer names and serial numbers`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem2`,`Access codes and passwords`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem3`,`Email addresses`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem4`,`API keys and tokens`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem5`,`Webhook URLs`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem6`,`Your hostname or username`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem7`,`IP addresses`)]})]})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:e(`support.privacyNote`,`Email addresses in logs are replaced with [EMAIL], printer names with [PRINTER], serial numbers with [SERIAL], and IP addresses with [IP].`)})]}),(0,K.jsx)(VVe,{})]})}),(0,K.jsxs)(w9,{title:e(`diagnostic.sectionTitle`,`Connection Diagnostic`),icon:ru,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`diagnostic.sectionDescription`,`Check why a printer won't connect or won't print — port reachability, LAN developer mode, Docker network mode, and credentials.`)}),_&&_.length>0?(0,K.jsx)(`div`,{className:`space-y-2`,children:_.map(t=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:t.ip_address})]}),(0,K.jsxs)(`button`,{onClick:()=>l(t),className:`flex items-center gap-2 px-3 py-1.5 text-sm bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary text-white rounded-lg transition-colors flex-shrink-0`,children:[(0,K.jsx)(ru,{className:`w-4 h-4`}),e(`diagnostic.runButton`,`Run diagnostic`)]})]},t.id))}):(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`diagnostic.noPrinters`,`No printers configured.`)})]}),(0,K.jsxs)(w9,{title:e(`systemHealth.sectionTitle`),icon:Sc,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-3 mb-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`systemHealth.sectionDescription`)}),(0,K.jsxs)(`button`,{onClick:()=>b(),disabled:x,className:`flex items-center gap-2 px-3 py-1.5 text-sm bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary text-white rounded-lg transition-colors flex-shrink-0 disabled:opacity-50`,children:[(0,K.jsx)(Cl,{className:`w-4 h-4 ${x?`animate-spin`:``}`}),e(`systemHealth.rescan`)]})]}),v?(0,K.jsx)(jf,{result:v}):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`)})]}),(0,K.jsxs)(w9,{title:e(`system.database`,`Database`),icon:js,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mb-4`,children:[(0,K.jsx)(S9,{icon:js,label:e(`system.dbEngine`,`Database Engine`),value:u.database.engine||`SQLite`}),(0,K.jsx)(S9,{icon:js,label:e(`system.dbVersion`,`Version`),value:u.database.version||`unknown`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4 mb-4`,children:[(0,K.jsx)(S9,{icon:wo,label:e(`system.totalArchives`,`Total Archives`),value:u.database.archives}),(0,K.jsx)(S9,{icon:us,label:e(`system.completed`,`Completed`),value:u.database.archives_completed,color:`text-green-500`}),(0,K.jsx)(S9,{icon:ms,label:e(`system.failed`,`Failed`),value:u.database.archives_failed,color:`text-red-500`}),(0,K.jsx)(S9,{icon:X,label:e(`system.printing`,`Printing`),value:u.database.archives_printing,color:`text-yellow-500`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsx)(S9,{icon:bl,label:e(`system.printers`,`Printers`),value:u.database.printers}),(0,K.jsx)(S9,{icon:ll,label:e(`system.filaments`,`Filaments`),value:u.database.filaments}),(0,K.jsx)(S9,{icon:nc,label:e(`system.projects`,`Projects`),value:u.database.projects}),(0,K.jsx)(S9,{icon:gl,label:e(`system.smartPlugs`,`Smart Plugs`),value:u.database.smart_plugs})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mt-4`,children:[(0,K.jsx)(S9,{icon:_s,label:e(`system.totalPrintTime`,`Total Print Time`),value:u.database.total_print_time_formatted}),(0,K.jsx)(S9,{icon:wo,label:e(`system.totalFilament`,`Total Filament Used`),value:`${u.database.total_filament_kg} kg`,subValue:`${u.database.total_filament_grams.toLocaleString()} g`})]})]}),(0,K.jsxs)(w9,{title:e(`system.connectedPrinters`,`Connected Printers`),icon:bl,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 mb-4`,children:[(0,K.jsx)(`div`,{className:`text-3xl font-bold text-bambu-green`,children:u.printers.connected}),(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:e(`system.ofTotal`,`of {{total}} printers connected`,{total:u.printers.total})})]}),u.printers.connected_list.length>0?(0,K.jsx)(`div`,{className:`space-y-2`,children:u.printers.connected_list.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green`}),(0,K.jsx)(`span`,{className:`font-medium text-white`,children:e.name})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:e.model}),(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded ${e.state===`RUNNING`?`bg-bambu-green/20 text-bambu-green`:e.state===`IDLE`?`bg-blue-500/20 text-blue-400`:`bg-bambu-dark-tertiary`}`,children:e.state})]})]},e.id))}):(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`system.noPrintersConnected`,`No printers connected`)})]}),(0,K.jsx)(w9,{title:e(`system.storage`,`Storage`),icon:yc,children:(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.diskUsage`,`Disk Usage`)}),(0,K.jsxs)(`span`,{className:`text-white`,children:[u.storage.disk_used_formatted,` / `,u.storage.disk_total_formatted]})]}),(0,K.jsx)(C9,{percent:u.storage.disk_percent_used,color:T}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[u.storage.disk_free_formatted,` `,e(`system.free`,`free`),` (`,(100-u.storage.disk_percent_used).toFixed(1),`%)`]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,K.jsx)(S9,{icon:wo,label:e(`system.archiveStorage`,`Archive Storage`),value:u.storage.archive_size_formatted}),(0,K.jsx)(S9,{icon:js,label:e(`system.databaseSize`,`Database Size`),value:u.storage.database_size_formatted}),g&&(0,K.jsx)(S9,{icon:rc,label:e(`system.fileManagerStorage`,`File Manager`),value:HVe(g.total_size_bytes),subValue:`${g.total_files} files, ${g.total_folders} folders`})]})]})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,K.jsx)(w9,{title:e(`system.memory`,`Memory`),icon:Xc,children:(0,K.jsx)(`div`,{className:`space-y-4`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.memoryUsage`,`Memory Usage`)}),(0,K.jsxs)(`span`,{className:`text-white`,children:[u.memory.used_formatted,` / `,u.memory.total_formatted]})]}),(0,K.jsx)(C9,{percent:u.memory.percent_used,color:E}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[u.memory.available_formatted,` `,e(`system.available`,`available`)]})]})})}),(0,K.jsx)(w9,{title:e(`system.cpu`,`CPU`),icon:Os,children:(0,K.jsx)(`div`,{className:`space-y-4`,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsx)(S9,{icon:Os,label:e(`system.cores`,`Cores`),value:u.cpu.count,subValue:`${u.cpu.count_logical} logical`}),(0,K.jsx)(S9,{icon:Os,label:e(`system.usage`,`Usage`),value:`${u.cpu.percent}%`})]})})})]}),(0,K.jsx)(w9,{title:e(`system.systemDetails`,`System Details`),icon:Il,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsx)(S9,{icon:Il,label:e(`system.os`,`Operating System`),value:u.system.platform,subValue:u.system.platform_release}),(0,K.jsx)(S9,{icon:Os,label:e(`system.architecture`,`Architecture`),value:u.system.architecture}),(0,K.jsx)(S9,{icon:Il,label:e(`system.python`,`Python`),value:u.system.python_version}),(0,K.jsx)(S9,{icon:_s,label:e(`system.bootTime`,`Boot Time`),value:gf(u.system.boot_time,S)})]})}),c&&(0,K.jsx)(Df,{printerId:c.id,printerName:c.name,onClose:()=>l(null)})]})}var T9=`auth_remember_me`,E9=`auth_post_login_redirect`;function D9(e){return e?`persistent`:`session`}function WVe(){try{let e=sessionStorage.getItem(T9)===`1`;return sessionStorage.removeItem(T9),e}catch(e){return console.warn(`consumeSavedRememberMe: sessionStorage unavailable, Remember Me preference lost across OIDC redirect`,e),!1}}function O9(e){return!e||!e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`/login`)?null:e}function GVe(e){let t=O9(e);if(t)try{sessionStorage.setItem(E9,t)}catch(e){console.warn(`stashPostLoginRedirect: sessionStorage unavailable, post-login target will be lost across OIDC redirect`,e)}}function KVe(){try{let e=sessionStorage.getItem(E9);return sessionStorage.removeItem(E9),O9(e)}catch(e){return console.warn(`consumePostLoginRedirect: sessionStorage unavailable`,e),null}}function qVe({provider:e,onClick:t,disabled:n}){let{t:r}=G(),[i,a]=(0,y.useState)(!1);return(0,K.jsxs)(`button`,{type:`button`,onClick:t,disabled:n,className:`w-full flex items-center justify-center gap-3 py-3 px-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary hover:border-bambu-green/50 rounded-lg text-white font-medium transition-colors disabled:opacity-50`,children:[e.has_icon&&!i?(0,K.jsx)(`img`,{src:Q.oidcProviderIconUrl(e.id),alt:``,className:`w-5 h-5 object-contain`,onError:()=>a(!0)}):(0,K.jsx)(Hl,{className:`w-5 h-5 text-bambu-green`}),r(`login.twoFA.signInWith`,{provider:e.name})]})}function JVe(){let e=Yn(),t=Kn(),[n]=Oi(),{t:r}=G(),{login:i,loginWithToken:a}=sd(),{showToast:o}=xd(),{mode:s}=ud();function c(){let e=t.state?.from;if(e?.pathname){let t=O9(`${e.pathname}${e.search??``}`);if(t)return t}return KVe()??`/`}let[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(`credentials`),[b,x]=(0,y.useState)(``),[S,C]=(0,y.useState)([]),[w,T]=(0,y.useState)(`totp`),[E,D]=(0,y.useState)(``),[O,k]=(0,y.useState)(!1),A=(0,y.useRef)(null),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)(``),[F,I]=(0,y.useState)(``),[L,R]=(0,y.useState)(``),{data:z}=q({queryKey:[`advancedAuthStatus`],queryFn:()=>Q.getAdvancedAuthStatus()}),{data:B}=q({queryKey:[`oidcProviders`],queryFn:()=>Q.getOIDCProviders()});(0,y.useEffect)(()=>{let t=window.location.hash,n=t.startsWith(`#reset_token=`)?t.slice(13):null;n&&(P(n),v(`reset-password`),e(`/login`,{replace:!0}))},[]),(0,y.useEffect)(()=>{let t=window.location.hash,i=t.startsWith(`#oidc_token=`)?t.slice(12):null,s=n.get(`oidc_error`);if(!i&&!s)return;let l=WVe();if(s){o({oidc_provider_error:r(`login.oidcErrors.providerError`),missing_parameters:r(`login.oidcErrors.missingParameters`),invalid_state:r(`login.oidcErrors.invalidState`),state_expired:r(`login.oidcErrors.stateExpired`),provider_not_found:r(`login.oidcErrors.providerNotFound`),discovery_failed:r(`login.oidcErrors.discoveryFailed`),invalid_discovery_document:r(`login.oidcErrors.invalidDiscovery`),token_exchange_network_error:r(`login.oidcErrors.networkError`),token_exchange_bad_response:r(`login.oidcErrors.badResponse`),no_id_token:r(`login.oidcErrors.noIdToken`),token_validation_failed:r(`login.oidcErrors.validationFailed`),nonce_mismatch:r(`login.oidcErrors.nonceMismatch`),missing_sub_claim:r(`login.oidcErrors.missingSubClaim`),no_linked_account:r(`login.oidcErrors.noLinkedAccount`),account_inactive:r(`login.oidcErrors.accountInactive`),user_resolution_failed:r(`login.oidcErrors.userResolutionFailed`),internal_error:r(`login.oidcErrors.internalError`)}[s]??(s.startsWith(`token_exchange_`)?r(`login.oidcErrors.tokenExchangeFailed`):r(`login.oidcLoginFailed`)),`error`),e(`/login`,{replace:!0});return}i&&Q.exchangeOIDCToken(i).then(t=>{if(t.requires_2fa&&t.pre_auth_token){M(l),x(t.pre_auth_token);let n=t.two_fa_methods??[];C(n),n.includes(`totp`)?T(`totp`):n.includes(`email`)?T(`email`):T(`backup`),v(`2fa`),e(`/login`,{replace:!0})}else t.access_token&&t.user?(a(t.access_token,t.user,D9(l)),o(r(`login.loginSuccess`)),e(c(),{replace:!0})):(o(r(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0}))}).catch(t=>{console.error(`OIDC token exchange failed`,t),o(r(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0})})},[n]);let V=J({mutationFn:()=>i(l,d,D9(j)),onSuccess:t=>{if(t.requires_2fa&&t.pre_auth_token){x(t.pre_auth_token);let e=t.two_fa_methods??[];C(e),e.includes(`totp`)?T(`totp`):e.includes(`email`)?T(`email`):T(`backup`),v(`2fa`)}else t.access_token&&t.user&&(o(r(`login.loginSuccess`)),e(c(),{replace:!0}))},onError:e=>{o(e.message||r(`login.loginFailed`),`error`)}}),ee=J({mutationFn:e=>Q.forgotPassword({email:e}),onSuccess:e=>{o(e.message,`success`),m(!1),g(``)},onError:e=>{o(e.message,`error`)}}),H=J({mutationFn:()=>Q.forgotPasswordConfirm(N,F),onSuccess:e=>{o(e.message,`success`),v(`credentials`),P(``),I(``),R(``)},onError:e=>{o(e.message||r(`login.resetPassword.resetFailed`),`error`)}}),te=J({mutationFn:()=>Q.sendEmailOTP(b),onSuccess:e=>{k(!0),e.pre_auth_token&&x(e.pre_auth_token),o(e.message,`success`)},onError:e=>{o(e.message||r(`login.twoFA.sendCodeFailed`),`error`)}}),ne=J({mutationFn:()=>Q.verify2FA({pre_auth_token:b,code:E,method:w}),onSuccess:t=>{t.access_token&&t.user?(a(t.access_token,t.user,D9(j)),o(r(`login.loginSuccess`)),e(c(),{replace:!0})):(console.error(`2FA verify: unexpected response shape`,t),o(r(`login.loginFailed`),`error`))},onError:e=>{o(e.message||r(`login.twoFA.invalidCode`),`error`),D(``)}}),re=J({mutationFn:e=>Q.getOIDCAuthorizeUrl(e),onSuccess:e=>{if(j)try{sessionStorage.setItem(T9,`1`)}catch(e){console.warn(`setItem auth_remember_me failed, Remember Me will not carry through OIDC redirect`,e)}let n=t.state?.from;n?.pathname&&GVe(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url},onError:e=>{o(e.message||r(`login.oidcLoginFailed`),`error`)}}),U=e=>{if(e.preventDefault(),!l||!d){o(r(`login.enterCredentials`),`error`);return}V.mutate()},ie=e=>{if(e.preventDefault(),!E.trim()){o(r(`login.twoFA.enterCode`),`error`);return}ne.mutate()},ae=e=>{if(e.preventDefault(),!h){o(r(`login.enterEmail`),`error`);return}ee.mutate(h)},W=e=>{T(e),D(``),k(!1),setTimeout(()=>A.current?.focus(),0)};return _===`reset-password`?(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,K.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,K.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,K.jsx)(jc,{className:`w-7 h-7 text-bambu-green`})})}),(0,K.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:r(`login.resetPassword.title`)}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.resetPassword.subtitle`)})]}),(0,K.jsxs)(`form`,{onSubmit:e=>{if(e.preventDefault(),F!==L){o(r(`login.resetPassword.passwordsDoNotMatch`),`error`);return}if(F.length<8){o(r(`login.resetPassword.passwordTooShort`),`error`);return}H.mutate()},className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`new-password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.resetPassword.newPassword`)}),(0,K.jsx)(`input`,{id:`new-password`,type:`password`,required:!0,value:F,onChange:e=>I(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.resetPassword.newPasswordPlaceholder`),autoFocus:!0,autoComplete:`new-password`,minLength:8})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.resetPassword.confirmPassword`)}),(0,K.jsx)(`input`,{id:`confirm-password`,type:`password`,required:!0,value:L,onChange:e=>R(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.resetPassword.confirmPasswordPlaceholder`),autoComplete:`new-password`})]}),(0,K.jsx)(`button`,{type:`submit`,disabled:H.isPending||!F||!L,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:H.isPending?r(`login.resetPassword.saving`):r(`login.resetPassword.submit`)})]}),(0,K.jsx)(`div`,{className:`text-center`,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>{v(`credentials`),P(``),I(``),R(``)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.resetPassword.backToLogin`)})})]})}):_===`2fa`?(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,K.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,K.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,K.jsx)(Hl,{className:`w-7 h-7 text-bambu-green`})})}),(0,K.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:r(`login.twoFA.title`)}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.twoFA.subtitle`)})]}),S.length>1&&(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[S.includes(`totp`)&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>W(`totp`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${w===`totp`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,K.jsx)(Yl,{className:`w-4 h-4`}),r(`login.twoFA.methodAuthenticator`)]}),S.includes(`email`)&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>W(`email`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${w===`email`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,K.jsx)(Gc,{className:`w-4 h-4`}),r(`login.twoFA.methodEmail`)]}),S.includes(`backup`)&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>W(`backup`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${w===`backup`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,K.jsx)(jc,{className:`w-4 h-4`}),r(`login.twoFA.methodBackup`)]})]}),(0,K.jsxs)(`form`,{onSubmit:ie,className:`space-y-4`,children:[w===`totp`&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(`login.twoFA.instructionsTotp`)}),w===`email`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(O?`login.twoFA.instructionsEmail`:`login.twoFA.instructionsEmailNotSent`)}),!O&&(0,K.jsx)($,{type:`button`,variant:`secondary`,className:`w-full`,onClick:()=>te.mutate(),disabled:te.isPending,children:te.isPending?r(`login.twoFA.sendingCode`):r(`login.twoFA.sendCodeButton`)}),O&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{k(!1),te.mutate()},className:`text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.twoFA.resendCode`)})]}),w===`backup`&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(`login.twoFA.instructionsBackup`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`twofa-code`,className:`block text-sm font-medium text-white mb-2`,children:r(w===`backup`?`login.twoFA.backupCodeLabel`:`login.twoFA.codeLabel`)}),(0,K.jsx)(`input`,{ref:A,id:`twofa-code`,type:`text`,inputMode:w===`backup`?`text`:`numeric`,autoComplete:`one-time-code`,value:E,onChange:e=>D(e.target.value.trim()),disabled:w===`email`&&!O,className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray text-center tracking-widest text-xl font-mono focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-40`,placeholder:r(w===`backup`?`login.twoFA.backupCodePlaceholder`:`login.twoFA.codePlaceholder`),maxLength:w===`backup`?8:6,autoFocus:!0})]}),(0,K.jsx)(`button`,{type:`submit`,disabled:ne.isPending||!E.trim()||w===`email`&&!O,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:ne.isPending?r(`login.twoFA.verifyingButton`):r(`login.twoFA.verifyButton`)})]}),(0,K.jsx)(`div`,{className:`text-center`,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>{v(`credentials`),x(``),D(``),k(!1)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.twoFA.backToLogin`)})})]})}):(0,K.jsxs)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:[(0,K.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,K.jsx)(`img`,{src:s===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,K.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:r(`login.title`)}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.subtitle`)})]}),(0,K.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:U,children:[(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-white mb-2`,children:z?.advanced_auth_enabled?r(`login.usernameOrEmail`):r(`login.username`)}),(0,K.jsx)(`input`,{id:`username`,type:`text`,required:!0,value:l,onChange:e=>u(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:z?.advanced_auth_enabled?r(`login.usernameOrEmailPlaceholder`):r(`login.usernamePlaceholder`),autoComplete:`username`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.password`)||`Password`}),(0,K.jsx)(`input`,{id:`password`,type:`password`,required:!0,value:d,onChange:e=>f(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.passwordPlaceholder`),autoComplete:`current-password`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{id:`remember-me`,type:`checkbox`,checked:j,onChange:e=>M(e.target.checked),className:`h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,K.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:r(`login.rememberMe`)})]}),(0,K.jsx)(`div`,{children:(0,K.jsx)(`button`,{type:`submit`,disabled:V.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:V.isPending?r(`login.signingIn`):r(`login.signIn`)})}),(0,K.jsx)(`div`,{className:`text-center`,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>m(!0),className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.forgotPassword`)})})]}),B&&B.length>0&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,K.jsx)(`div`,{className:`w-full border-t border-bambu-dark-tertiary`})}),(0,K.jsx)(`div`,{className:`relative flex justify-center text-sm`,children:(0,K.jsx)(`span`,{className:`px-2 bg-bambu-dark-secondary text-bambu-gray`,children:r(`login.twoFA.orContinueWith`)})})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:B.map(e=>(0,K.jsx)(qVe,{provider:e,onClick:()=>re.mutate(e.id),disabled:re.isPending},e.id))})]})]}),p&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>m(!1),children:(0,K.jsxs)(pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Gc,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`login.forgotPasswordTitle`)})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{m(!1),g(``)},children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]})}),(0,K.jsx)(hd,{children:z?.advanced_auth_enabled?(0,K.jsxs)(`form`,{onSubmit:ae,className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:r(`login.forgotPasswordEmailMessage`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`forgot-email`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.emailAddress`)}),(0,K.jsx)(`input`,{id:`forgot-email`,type:`email`,required:!0,value:h,onChange:e=>g(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.emailPlaceholder`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,className:`flex-1`,onClick:()=>{m(!1),g(``)},children:r(`login.cancel`)}),(0,K.jsx)($,{type:`submit`,className:`flex-1`,disabled:ee.isPending,children:ee.isPending?r(`login.sending`):r(`login.sendResetEmail`)})]})]}):(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:r(`login.forgotPasswordMessage`)}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4 space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white font-medium`,children:r(`login.howToReset`)}),(0,K.jsxs)(`ol`,{className:`text-sm text-bambu-gray space-y-1 list-decimal list-inside`,children:[(0,K.jsx)(`li`,{children:r(`login.resetStep1`)}),(0,K.jsx)(`li`,{children:r(`login.resetStep2`)}),(0,K.jsx)(`li`,{children:r(`login.resetStep3`)}),(0,K.jsx)(`li`,{children:r(`login.resetStep4`)})]})]}),(0,K.jsx)($,{variant:`secondary`,className:`w-full`,onClick:()=>m(!1),children:r(`login.gotIt`)})]})})]})})]})}function YVe(){let e=Yn(),{t}=G(),{showToast:n}=xd(),{mode:r}=ud(),{refreshAuth:i}=sd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),p=J({mutationFn:()=>Q.setupAuth({auth_enabled:a,admin_username:a?s:void 0,admin_password:a?l:void 0}),onSuccess:async r=>{await i(),r.auth_enabled?r.admin_created?(n(t(`setup.toast.authEnabledAdminCreated`)),e(`/login`)):(n(t(`setup.toast.authEnabledExistingAdmins`)),e(`/login`)):(n(t(`setup.toast.setupCompleted`)),e(`/`))},onError:e=>{n(e.message,`error`)}});return(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,K.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,K.jsx)(`img`,{src:r===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,K.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:t(`setup.title`)}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:t(`setup.subtitle`)})]}),(0,K.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:e=>{if(e.preventDefault(),a&&(s||l)){if(!s||!l){n(t(`setup.toast.enterBothCredentials`),`error`);return}if(l!==d){n(t(`setup.toast.passwordsDoNotMatch`),`error`);return}if(l.length<6){n(t(`setup.toast.passwordTooShort`),`error`);return}}p.mutate()},children:[(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center p-4 bg-bambu-dark-secondary/50 rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`input`,{id:`auth-enabled`,type:`checkbox`,checked:a,onChange:e=>o(e.target.checked),className:`h-4 w-4 text-bambu-green focus:ring-bambu-green border-bambu-dark-tertiary rounded bg-bambu-dark-secondary`}),(0,K.jsx)(`label`,{htmlFor:`auth-enabled`,className:`ml-3 block text-sm font-medium text-white`,children:t(`setup.enableAuth`)})]}),a&&(0,K.jsxs)(`div`,{className:`space-y-4 mt-4`,children:[(0,K.jsx)(`div`,{className:`p-3 bg-bambu-dark-secondary/50 border border-bambu-dark-tertiary rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(kc,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`text-sm text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium mb-1`,children:t(`setup.adminAccount`)}),(0,K.jsx)(`p`,{children:t(`setup.adminAccountDesc`)})]})]})}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{htmlFor:`admin-username`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminUsername`),` `,(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,K.jsx)(`input`,{id:`admin-username`,type:`text`,value:s,onChange:e=>c(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.adminUsernamePlaceholder`),autoComplete:`username`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{htmlFor:`admin-password`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminPassword`),` `,(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,K.jsx)(`input`,{id:`admin-password`,type:`password`,value:l,onChange:e=>u(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.adminPasswordPlaceholder`),minLength:6,autoComplete:`new-password`})]}),l&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:t(`setup.confirmPassword`)}),(0,K.jsx)(`input`,{id:`confirm-password`,type:`password`,value:d,onChange:e=>f(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.confirmPasswordPlaceholder`),minLength:6,autoComplete:`new-password`})]})]})]}),(0,K.jsx)(`div`,{children:(0,K.jsx)(`button`,{type:`submit`,disabled:p.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:p.isPending?t(`setup.settingUp`):t(`setup.completeSetup`)})})]})]})})}function XVe(){let{t:e}=G(),{user:t}=sd(),{showToast:n}=xd(),r=Qa(),i=Yn(),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(!0),[l,u]=(0,y.useState)(!0),[d,f]=(0,y.useState)(!0),[p,m]=(0,y.useState)(!1),{data:h,isLoading:g}=q({queryKey:[`advancedAuthStatus`],queryFn:Q.getAdvancedAuthStatus,staleTime:300*1e3}),{data:_,isLoading:v}=q({queryKey:[`settings`],queryFn:Q.getSettings,staleTime:300*1e3}),{data:b,isLoading:x}=q({queryKey:[`user-email-preferences`],queryFn:()=>Q.getUserEmailPreferences()});(0,y.useEffect)(()=>{(h&&!h.advanced_auth_enabled||_&&!_.user_notifications_enabled)&&i(`/settings`,{replace:!0})},[h,_,i]),(0,y.useEffect)(()=>{b&&(o(b.notify_print_start),c(b.notify_print_complete),u(b.notify_print_failed),f(b.notify_print_stopped),m(!1))},[b]);let S=J({mutationFn:()=>Q.updateUserEmailPreferences({notify_print_start:a,notify_print_complete:s,notify_print_failed:l,notify_print_stopped:d}),onSuccess:()=>{r.invalidateQueries({queryKey:[`user-email-preferences`]}),m(!1),n(e(`notifications.userEmail.saveSuccess`),`success`)},onError:t=>{n(t.message||e(`notifications.userEmail.saveError`),`error`)}}),C=(e,t)=>{e(!t),m(!0)};return x||g||v?(0,K.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,K.jsxs)(`div`,{className:`p-4 md:p-6 max-w-2xl mx-auto`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-6`,children:[(0,K.jsx)(Io,{className:`w-7 h-7 text-bambu-green`}),(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`notifications.userEmail.title`)})]}),(0,K.jsx)(pd,{className:`mb-6 border-blue-500/30 bg-blue-500/5`,children:(0,K.jsx)(hd,{className:`py-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0`,children:(0,K.jsx)(Gc,{className:`w-5 h-5 text-blue-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-white font-medium`,children:e(`notifications.userEmail.emailNotifications`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.emailNotificationsDesc`)}),t?.email?(0,K.jsxs)(`p`,{className:`text-sm text-blue-400 mt-2`,children:[e(`notifications.userEmail.sendingTo`),`: `,(0,K.jsx)(`strong`,{children:t.email})]}):(0,K.jsx)(`p`,{className:`text-sm text-yellow-400 mt-2`,children:e(`notifications.userEmail.noEmailWarning`)})]})]})})}),(0,K.jsxs)(pd,{className:`mb-6`,children:[(0,K.jsxs)(md,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`notifications.userEmail.printJobNotifications`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.printJobNotificationsDesc`)})]}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${a?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(us,{className:`w-5 h-5 ${a?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStarts`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStartsDesc`)})]})]}),(0,K.jsx)(`button`,{onClick:()=>C(o,a),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${a?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":a,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${a?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${s?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(us,{className:`w-5 h-5 ${s?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobFinishes`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobFinishesDesc`)})]})]}),(0,K.jsx)(`button`,{onClick:()=>C(c,s),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${s?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":s,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${s?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(us,{className:`w-5 h-5 ${l?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printErrors`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printErrorsDesc`)})]})]}),(0,K.jsx)(`button`,{onClick:()=>C(u,l),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${l?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":l,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${l?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${d?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(us,{className:`w-5 h-5 ${d?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStops`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStopsDesc`)})]})]}),(0,K.jsx)(`button`,{onClick:()=>C(f,d),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${d?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":d,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${d?`translate-x-6`:`translate-x-1`}`})})]})]})]}),(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsx)($,{onClick:()=>S.mutate(),disabled:!p||S.isPending||!t?.email,children:S.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),e(`common.saving`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),e(`common.save`)]})})})]})}function ZVe(){let e=Yn(),[t]=Oi(),{t:n}=G();if(window!==window.top)return(0,K.jsxs)(`div`,{style:{padding:32,color:`#f88`},children:[`GCode viewer static files not found. Check that the`,` `,(0,K.jsx)(`code`,{children:`gcode_viewer/`}),` directory exists and restart uvicorn.`]});let r=t.has(`archive`),i=t.has(`library_file`),a=r?`/archives`:i?`/files`:`/`,o=n(r?`gcodeViewer.backToArchives`:i?`gcodeViewer.backToFiles`:`gcodeViewer.back`),s=()=>{window.history.length>1?e(-1):e(a)},c=`/gcode-viewer/${window.location.search}`;return(0,K.jsxs)(`div`,{style:{height:`calc(100vh - 3.5rem)`,display:`flex`,flexDirection:`column`},children:[(0,K.jsx)(`div`,{className:`flex items-center gap-2 px-4 py-2 border-b border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:s,className:`inline-flex items-center gap-1.5 text-sm text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white transition-colors`,children:[(0,K.jsx)(Do,{className:`w-4 h-4`}),o]})}),(0,K.jsx)(`iframe`,{src:c,title:`GCode Viewer`,style:{display:`block`,width:`100%`,flex:1,border:`none`}})]})}function QVe(){let e=(0,y.useRef)(null),t=(0,y.useRef)(null),n=Qa(),[r,i]=(0,y.useState)(!1),a=(0,y.useRef)(new Map),{showToast:o}=xd(),{t:s}=G(),c=(0,y.useRef)(new Set),l=(0,y.useRef)(null),u=(0,y.useRef)(new Map),d=(0,y.useRef)(null),f=(0,y.useRef)([]),p=(0,y.useRef)(!1),m=(0,y.useRef)(()=>{}),h=(0,y.useCallback)(()=>{if(p.current||f.current.length===0)return;p.current=!0;let e=()=>{let t=f.current.shift();t?requestAnimationFrame(()=>{m.current(t),f.current.length>0?setTimeout(e,16):p.current=!1}):p.current=!1};e()},[]),g=(0,y.useCallback)(async()=>{if(e.current?.readyState===WebSocket.OPEN)return;let n;try{n=(await Q.getWebSocketToken()).token}catch{}let r=window.location.protocol===`https:`?`wss:`:`ws:`,a=n?`?token=${encodeURIComponent(n)}`:``,o=`${r}//${window.location.host}/api/v1/ws${a}`,s=new WebSocket(o),c=null;s.onopen=()=>{console.log(`[WebSocket] Connected`),i(!0),c=window.setInterval(()=>{s.readyState===WebSocket.OPEN&&s.send(JSON.stringify({type:`ping`}))},3e4)},s.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`printer_status`&&t.printer_id!==void 0&&t.data?m.current(t):(f.current.push(t),h())}catch{}},s.onclose=n=>{console.log(`[WebSocket] Closed`,n.code,n.reason),c&&=(clearInterval(c),null),i(!1),e.current=null,t.current=window.setTimeout(()=>{g()},3e3)},s.onerror=e=>{console.error(`[WebSocket] Error`,e),s.close()},e.current=s},[h]),_=(0,y.useCallback)((e,t)=>{let r=u.current.get(e)||{};u.current.set(e,{...r,...t}),d.current||=window.setTimeout(()=>{let e=new Map(u.current);u.current.clear(),d.current=null,requestAnimationFrame(()=>{e.forEach((e,t)=>{n.setQueryData([`printerStatus`,t],t=>{let n={...t,...e};return n.wifi_signal==null&&t?.wifi_signal!=null&&(n.wifi_signal=t.wifi_signal),n})})})},100)},[n]),v=(0,y.useCallback)(e=>{c.current.add(e),l.current&&clearTimeout(l.current),l.current=window.setTimeout(()=>{let e=Array.from(c.current);c.current.clear(),l.current=null;let t=0;e.forEach(e=>{setTimeout(()=>{requestAnimationFrame(()=>{n.invalidateQueries({queryKey:[e]})})},t),t+=500})},3e3)},[n]),b=(0,y.useCallback)(e=>{switch(e.type){case`printer_status`:e.printer_id!==void 0&&e.data&&_(e.printer_id,e.data);break;case`print_start`:e.printer_id!==void 0&&n.invalidateQueries({queryKey:[`printerStatus`,e.printer_id]});break;case`missing_spool_assignment`:{if(e.printer_id===void 0||!Array.isArray(e.missing_slots))break;let t=e.missing_slots.map(e=>e&&typeof e.slot==`string`?e.slot:`Unknown`).filter(e=>e.length>0);if(t.length===0){a.current.delete(e.printer_id);break}let n=t.join(`|`);if(a.current.get(e.printer_id)===n)break;a.current.set(e.printer_id,n),o(s(`printers.toast.missingSpoolAssignment`,{printer:e.printer_name||`Printer ${e.printer_id}`,slots:t.join(`, `)}),`warning`);break}case`print_complete`:v(`archives`),v(`archiveStats`);break;case`archive_created`:v(`archives`),v(`archiveStats`);break;case`archive_updated`:v(`archives`);break;case`pong`:break;case`plate_not_empty`:window.dispatchEvent(new CustomEvent(`plate-not-empty`,{detail:{printer_id:e.printer_id,printer_name:e.printer_name,message:e.message}}));break;case`inventory_changed`:v(`inventory-spools`),v(`spoolman-inventory-spools`),v(e9[0]);break;case`spool_assignment_changed`:v(`spool-assignments`),v(`slotPresets`);break;case`spool_auto_assigned`:v(`inventory-spools`),v(`spool-assignments`);break;case`spool_usage_logged`:v(`inventory-spools`);break;case`unknown_tag`:window.dispatchEvent(new CustomEvent(`unknown-tag`,{detail:{printer_id:e.printer_id,ams_id:e.ams_id,tray_id:e.tray_id,tag_uid:e.tag_uid,tray_uuid:e.tray_uuid}}));break;case`background_dispatch`:window.dispatchEvent(new CustomEvent(`background-dispatch`,{detail:e.data||{}}));break;case`spoolbuddy_weight`:window.dispatchEvent(new CustomEvent(`spoolbuddy-weight`,{detail:e}));break;case`spoolbuddy_tag_matched`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-matched`,{detail:e})),v(`inventory-spools`);break;case`spoolbuddy_unknown_tag`:window.dispatchEvent(new CustomEvent(`spoolbuddy-unknown-tag`,{detail:e}));break;case`spoolbuddy_tag_removed`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-removed`,{detail:e}));break;case`spoolbuddy_tag_written`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-written`,{detail:e})),v(`inventory-spools`);break;case`spoolbuddy_tag_write_failed`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-write-failed`,{detail:e}));break;case`spoolbuddy_online`:window.dispatchEvent(new CustomEvent(`spoolbuddy-online`,{detail:e})),v(`spoolbuddy-devices`),v(`spoolbuddy-update-check`);break;case`spoolbuddy_offline`:window.dispatchEvent(new CustomEvent(`spoolbuddy-offline`,{detail:e})),v(`spoolbuddy-devices`);break;case`spoolbuddy_update`:v(`spoolbuddy-devices`),v(`spoolbuddy-update-check`);break}},[n,v,_,o,s]);return(0,y.useEffect)(()=>{m.current=b},[b]),(0,y.useEffect)(()=>(g(),()=>{t.current&&clearTimeout(t.current),l.current&&clearTimeout(l.current),d.current&&clearTimeout(d.current),e.current&&e.current.close()}),[g]),{isConnected:r,sendMessage:(0,y.useCallback)(t=>{e.current?.readyState===WebSocket.OPEN&&e.current.send(JSON.stringify(t))},[])}}function $Ve({children:e}){let{authEnabled:t,user:n,loading:r}=sd(),{data:i}=q({queryKey:[`color-catalog-map`],queryFn:async()=>(await Q.getColorNameMap()).colors,staleTime:1/0,gcTime:1/0,retry:2,enabled:!r&&(!t||n!==null)});return(0,y.useEffect)(()=>{i&&Ld(i)},[i]),(0,K.jsx)(K.Fragment,{children:e})}function eHe({selectedPrinterId:e,onPrinterChange:t,deviceOnline:n}){let{t:r}=G(),[i,a]=(0,y.useState)(new Date),{data:o=[]}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters()}),s=po({queries:o.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),refetchInterval:1e4}))}),c=(0,y.useMemo)(()=>o.filter((e,t)=>s[t]?.data?.connected),[o,s]);(0,y.useEffect)(()=>{let n=c.some(t=>t.id===e);(!e||!n)&&c.length>0&&t(c[0].id)},[c,e,t]);let{data:l}=q({queryKey:[`settings`],queryFn:Q.getSettings});return(0,y.useEffect)(()=>{let e=setInterval(()=>a(new Date),1e3);return()=>clearInterval(e)},[]),(0,K.jsxs)(`div`,{className:`h-12 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary flex items-center px-3 gap-4 shrink-0`,children:[(0,K.jsx)(`div`,{className:`flex items-center shrink-0`,children:(0,K.jsx)(`img`,{src:`/img/spoolbuddy_logo_dark_small.png`,alt:`SpoolBuddy`,width:113,height:28,className:`h-7 w-auto`})}),(0,K.jsx)(`div`,{className:`flex-1 flex justify-center`,children:(0,K.jsx)(`select`,{value:e??``,onChange:e=>t(Number(e.target.value)),className:`bg-bambu-dark text-white text-base px-4 py-2 rounded border border-bambu-dark-tertiary focus:outline-none focus:border-bambu-green min-w-[180px]`,children:c.length===0?(0,K.jsx)(`option`,{value:``,children:r(`spoolbuddy.status.noPrinters`,`No printers online`)}):c.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,K.jsx)(`div`,{className:`flex items-center`,title:n?r(`spoolbuddy.status.backend`,`Backend`):r(`spoolbuddy.status.offline`,`Offline`),children:n?(0,K.jsx)(`div`,{className:`flex items-end gap-0.5 h-4`,children:[1,2,3,4].map(e=>(0,K.jsx)(`div`,{className:`w-1 rounded-sm ${e<=4?`bg-white`:`bg-bambu-dark-tertiary`}`,style:{height:`${e*4}px`}},e))}):(0,K.jsx)(Au,{className:`w-5 h-5 text-red-400`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full ${n?`bg-bambu-green shadow-[0_0_6px_rgba(34,197,94,0.5)]`:`bg-bambu-gray`}`}),(0,K.jsx)(`span`,{className:`text-sm text-white/50`,children:n?r(`spoolbuddy.status.backend`,`Backend`):r(`spoolbuddy.status.offline`,`Offline`)})]}),(0,K.jsx)(`span`,{className:`text-white/50 text-base font-mono min-w-[50px] text-right`,children:_f(i,l?.time_format||`system`)})]})]})}var tHe=[{to:`/spoolbuddy`,labelKey:`spoolbuddy.nav.dashboard`,fallback:`Dashboard`,icon:(0,K.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6`})})},{to:`/spoolbuddy/ams`,labelKey:`spoolbuddy.nav.ams`,fallback:`AMS`,icon:(0,K.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10`})})},{to:`/spoolbuddy/write-tag`,labelKey:`spoolbuddy.nav.writeTag`,fallback:`Write`,icon:(0,K.jsxs)(`svg`,{className:`w-6 h-6`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,children:[(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0`}),(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})},{to:`/spoolbuddy/inventory`,labelKey:`spoolbuddy.nav.inventory`,fallback:`Inventory`,icon:(0,K.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4`})})},{to:`/spoolbuddy/settings`,labelKey:`spoolbuddy.nav.settings`,fallback:`Settings`,icon:(0,K.jsxs)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:[(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z`}),(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 12a3 3 0 11-6 0 3 3 0 016 0z`})]})}];function nHe(){let{t:e}=G();return(0,K.jsx)(`nav`,{className:`h-14 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-stretch shrink-0`,children:tHe.map(t=>(0,K.jsxs)(xi,{to:t.to,end:t.to===`/spoolbuddy`,className:({isActive:e})=>`flex-1 flex flex-col items-center justify-center gap-1 transition-colors ${e?`text-bambu-green bg-bambu-dark`:`text-white/50 hover:text-white/70 hover:bg-bambu-dark-tertiary`}`,children:[t.icon,(0,K.jsx)(`span`,{className:`text-xs font-medium`,children:e(t.labelKey,t.fallback)})]},t.to))})}function rHe({alert:e}){let{t}=G(),n=e?e.type===`error`?`bg-red-500`:e.type===`warning`?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-green`;return(0,K.jsxs)(`div`,{className:`h-9 bg-bambu-dark-secondary border-t-2 ${e?e.type===`error`?`border-red-500`:e.type===`warning`?`border-amber-500`:`border-bambu-dark-tertiary`:`border-bambu-dark-tertiary`} flex items-center px-3 gap-3 shrink-0`,children:[(0,K.jsx)(`div`,{className:`w-3.5 h-3.5 rounded-full ${n}`}),(0,K.jsx)(`div`,{className:`flex-1 text-sm text-white/50 truncate`,children:e?(0,K.jsx)(`span`,{children:e.message}):(0,K.jsx)(`span`,{className:`text-bambu-green`,children:t(`spoolbuddy.status.systemReady`,`System Ready`)})})]})}function iHe({isOpen:e,onClose:t,deviceId:n,deviceOnline:r}){let{t:i}=G(),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(new Map),{data:d=[]}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters(),enabled:e}),{data:f=[]}=q({queryKey:[`smart-plugs`],queryFn:()=>Q.getSmartPlugs(),enabled:e}),p=d.map(e=>{let t=f.find(t=>t.printer_id===e.id&&t.plug_type!==`mqtt`&&t.enabled);if(!t)return null;let n=l.get(t.id);return{plug:t,printer:e,status:n?{state:n.state,reachable:!0,device_name:null,energy:null}:null,loading:n?.loading??!1}}).filter(Boolean);(0,y.useEffect)(()=>{!e||f.length===0||f.filter(e=>e.printer_id!==null&&e.plug_type!==`mqtt`&&e.enabled).forEach(async e=>{try{let t=await Q.getSmartPlugStatus(e.id);u(n=>{let r=new Map(n);return r.set(e.id,{loading:!1,state:t.state}),r})}catch{u(t=>{let n=new Map(t);return n.set(e.id,{loading:!1,state:null}),n})}})},[e,f]),(0,y.useEffect)(()=>{e||(o(null),c(!1))},[e]);let m=(0,y.useCallback)(async e=>{u(t=>{let n=new Map(t),r=n.get(e.id);return n.set(e.id,{loading:!0,state:r?.state??null}),n});try{await Q.controlSmartPlug(e.id,`toggle`);let t=await Q.getSmartPlugStatus(e.id);u(n=>{let r=new Map(n);return r.set(e.id,{loading:!1,state:t.state}),r})}catch{u(t=>{let n=new Map(t),r=n.get(e.id);return n.set(e.id,{loading:!1,state:r?.state??null}),n})}},[]),h=(0,y.useCallback)(async e=>{if(n){c(!0);try{await nd.systemCommand(n,e),setTimeout(()=>t(),500)}catch{c(!1)}}},[n,t]),g=(0,y.useCallback)(()=>{a&&(a.type===`system`?h(a.command):m(a.plug),o(null))},[a,h,m]);if(!e)return null;let _=e=>e===`ON`||e===`on`;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/50`,onPointerDown:t}),(0,K.jsxs)(`div`,{className:`fixed top-0 left-0 right-0 z-50 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-b-2xl shadow-2xl animate-slide-down`,children:[(0,K.jsx)(`div`,{className:`flex justify-center pt-2 pb-1`,children:(0,K.jsx)(`div`,{className:`w-10 h-1 rounded-full bg-zinc-600`})}),(0,K.jsxs)(`div`,{className:`px-4 pb-4 max-h-[80vh] overflow-y-auto`,children:[p.length>0&&(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`h3`,{className:`text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2`,children:i(`spoolbuddy.quickMenu.printerPower`,`Printer Power`)}),(0,K.jsx)(`div`,{className:`space-y-1`,children:p.map(({plug:e,printer:t,loading:n})=>{let r=l.get(e.id),i=_(r?.state??null);return(0,K.jsxs)(`button`,{onClick:()=>o({type:`plug`,plug:e,printer:t,currentState:r?.state??null}),disabled:n,className:`w-full flex items-center gap-2 px-3 py-1.5 rounded-lg bg-zinc-800/60 hover:bg-zinc-700/60 transition-colors min-h-[36px]`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${i?`bg-green-500`:`bg-zinc-600`}`}),n&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin text-zinc-400 shrink-0`}),(0,K.jsx)(`span`,{className:`flex-1 text-sm text-zinc-200 text-left truncate`,children:t.name}),(0,K.jsx)(`span`,{className:`text-xs font-medium ${i?`text-green-400`:`text-zinc-500`}`,children:r?.state??`—`})]},e.id)})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2`,children:i(`spoolbuddy.quickMenu.systemControls`,`System`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsx)(k9,{icon:(0,K.jsx)(El,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.restartDaemon`,`Restart Daemon`),onClick:()=>o({type:`system`,command:`restart_daemon`}),disabled:!n||!r||s}),(0,K.jsx)(k9,{icon:(0,K.jsx)(tl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.restartBrowser`,`Restart Browser`),onClick:()=>o({type:`system`,command:`restart_browser`}),disabled:!n||!r||s}),(0,K.jsx)(k9,{icon:(0,K.jsx)(El,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.reboot`,`Reboot`),onClick:()=>o({type:`system`,command:`reboot`}),disabled:!n||!r||s,variant:`warning`}),(0,K.jsx)(k9,{icon:(0,K.jsx)(vl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.shutdown`,`Shutdown`),onClick:()=>o({type:`system`,command:`shutdown`}),disabled:!n||!r||s,variant:`danger`})]})]}),(0,K.jsx)(`div`,{className:`flex justify-center mt-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-zinc-600`,children:[(0,K.jsx)(es,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{children:i(`spoolbuddy.quickMenu.swipeToClose`,`Swipe down to close`)})]})})]})]}),a&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/60`,children:(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-2xl p-5 mx-4 max-w-sm w-full border border-zinc-700`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100 mb-2`,children:i(`spoolbuddy.quickMenu.confirmTitle`,`Confirm`)}),(0,K.jsx)(`p`,{className:`text-sm text-zinc-400 mb-5`,children:a.type===`plug`?_(a.currentState)?i(`spoolbuddy.quickMenu.confirmPlugOff`,`Turn off {{name}}?`,{name:a.printer.name}):i(`spoolbuddy.quickMenu.confirmPlugOn`,`Turn on {{name}}?`,{name:a.printer.name}):a.command===`shutdown`?i(`spoolbuddy.quickMenu.confirmShutdown`,`Are you sure you want to shut down the SpoolBuddy? You will need physical access to turn it back on.`):a.command===`reboot`?i(`spoolbuddy.quickMenu.confirmReboot`,`Are you sure you want to reboot the SpoolBuddy?`):a.command===`restart_daemon`?i(`spoolbuddy.quickMenu.confirmRestartDaemon`,`Restart the SpoolBuddy daemon? NFC and scale will be temporarily unavailable.`):i(`spoolbuddy.quickMenu.confirmRestartBrowser`,`Restart the kiosk browser? The display will briefly go blank.`)}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)(`button`,{onClick:()=>o(null),className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:i(`common.cancel`,`Cancel`)}),(0,K.jsx)(`button`,{onClick:g,disabled:s,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium text-white transition-colors min-h-[44px] ${a.type===`plug`?_(a.currentState)?`bg-red-600 hover:bg-red-700`:`bg-green-600 hover:bg-green-700`:a.command===`shutdown`?`bg-red-600 hover:bg-red-700`:a.command===`reboot`?`bg-amber-600 hover:bg-amber-700`:`bg-blue-600 hover:bg-blue-700`} disabled:opacity-50`,children:s?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mx-auto`}):a.type===`plug`?_(a.currentState)?i(`spoolbuddy.quickMenu.turnOff`,`Turn Off`):i(`spoolbuddy.quickMenu.turnOn`,`Turn On`):i(`spoolbuddy.quickMenu.confirm`,`Confirm`)})]})]})})]})}function k9({icon:e,label:t,onClick:n,disabled:r,variant:i=`default`}){return(0,K.jsxs)(`button`,{onClick:n,disabled:r,className:`flex items-center gap-2.5 p-3 rounded-xl transition-colors min-h-[48px] disabled:opacity-40 ${{default:`bg-zinc-800/60 hover:bg-zinc-700/60 text-zinc-300`,warning:`bg-amber-900/30 hover:bg-amber-900/50 text-amber-400`,danger:`bg-red-900/30 hover:bg-red-900/50 text-red-400`}[i]}`,children:[e,(0,K.jsx)(`span`,{className:`text-sm font-medium`,children:t})]})}var aHe={weight:null,weightStable:!1,rawAdc:null,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null,deviceOnline:!1,deviceId:null};function oHe(e,t){switch(t.type){case`WEIGHT_UPDATE`:return{...e,weight:t.weight,weightStable:t.stable,rawAdc:t.rawAdc,deviceId:t.deviceId,deviceOnline:!0};case`TAG_MATCHED`:return{...e,matchedSpool:t.spool,unknownTagUid:null,unknownTrayUuid:null,deviceId:t.deviceId};case`UNKNOWN_TAG`:return{...e,matchedSpool:null,unknownTagUid:t.tagUid,unknownTrayUuid:t.trayUuid??null,deviceId:t.deviceId};case`TAG_REMOVED`:return{...e,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null};case`DEVICE_ONLINE`:return{...e,deviceOnline:!0,deviceId:t.deviceId};case`DEVICE_OFFLINE`:return{...e,deviceOnline:!1,weight:null,weightStable:!1,rawAdc:null};default:return e}}function sHe(){let[e,t]=(0,y.useReducer)(oHe,aHe),n=(0,y.useCallback)(e=>{let n=e.detail;t({type:`WEIGHT_UPDATE`,weight:n.weight_grams??n.data?.weight_grams,stable:n.stable??n.data?.stable??!1,rawAdc:n.raw_adc??n.data?.raw_adc??null,deviceId:n.device_id??n.data?.device_id??``})},[]),r=(0,y.useCallback)(e=>{let n=e.detail,r=n.spool??n.data?.spool;r&&t({type:`TAG_MATCHED`,spool:{id:r.id,tag_uid:n.tag_uid??n.data?.tag_uid??``,material:r.material??``,subtype:r.subtype??null,color_name:r.color_name??null,rgba:r.rgba??null,brand:r.brand??null,label_weight:r.label_weight??0,core_weight:r.core_weight??0,weight_used:r.weight_used??0},deviceId:n.device_id??n.data?.device_id??``})},[]),i=(0,y.useCallback)(e=>{let n=e.detail;t({type:`UNKNOWN_TAG`,tagUid:n.tag_uid??n.data?.tag_uid??``,trayUuid:n.tray_uuid??n.data?.tray_uuid??null,deviceId:n.device_id??n.data?.device_id??``})},[]),a=(0,y.useCallback)(e=>{let n=e.detail;t({type:`TAG_REMOVED`,deviceId:n.device_id??n.data?.device_id??``})},[]),o=(0,y.useCallback)(e=>{let n=e.detail;t({type:`DEVICE_ONLINE`,deviceId:n.device_id??n.data?.device_id??``})},[]),s=(0,y.useCallback)(e=>{let n=e.detail;t({type:`DEVICE_OFFLINE`,deviceId:n.device_id??n.data?.device_id??``})},[]);(0,y.useEffect)(()=>(window.addEventListener(`spoolbuddy-weight`,n),window.addEventListener(`spoolbuddy-tag-matched`,r),window.addEventListener(`spoolbuddy-unknown-tag`,i),window.addEventListener(`spoolbuddy-tag-removed`,a),window.addEventListener(`spoolbuddy-online`,o),window.addEventListener(`spoolbuddy-offline`,s),()=>{window.removeEventListener(`spoolbuddy-weight`,n),window.removeEventListener(`spoolbuddy-tag-matched`,r),window.removeEventListener(`spoolbuddy-unknown-tag`,i),window.removeEventListener(`spoolbuddy-tag-removed`,a),window.removeEventListener(`spoolbuddy-online`,o),window.removeEventListener(`spoolbuddy-offline`,s)}),[n,r,i,a,o,s]);let c=e.matchedSpool?Math.max(0,e.matchedSpool.label_weight-e.matchedSpool.weight_used):null,l=e.weight!==null&&e.matchedSpool?Math.max(0,e.weight-e.matchedSpool.core_weight):null;return{...e,remainingWeight:c,netWeight:l}}var cHe=l(o(((e,t)=>{(function(n,r){typeof e==`object`&&typeof t==`object`?t.exports=r(f()):typeof define==`function`&&define.amd?define([`react`],r):typeof e==`object`?e.ReactSimpleKeyboard=r(f()):n.ReactSimpleKeyboard=r(n.React)})(e,(function(e){return function(){var t={981:function(){typeof Element>`u`||`remove`in Element.prototype||(Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)}),typeof self<`u`&&`document`in self&&((!(`classList`in document.createElement(`_`))||document.createElementNS&&!(`classList`in document.createElementNS(`http://www.w3.org/2000/svg`,`g`)))&&function(e){if(`Element`in e){var t=`classList`,n=`prototype`,r=e.Element[n],i=Object,a=String[n].trim||function(){return this.replace(/^\s+|\s+$/g,``)},o=Array[n].indexOf||function(e){for(var t=0,n=this.length;t1?arguments[1]:void 0)}},7916:function(e,t,n){var r=n(6080),i=n(9565),a=n(8981),o=n(6319),s=n(4209),c=n(3517),l=n(6198),u=n(4659),d=n(4527),f=n(81),p=n(851),m=Array;e.exports=function(e){var t=a(e),n=c(this),h=arguments.length,g=h>1?arguments[1]:void 0,_=g!==void 0;_&&(g=r(g,h>2?arguments[2]:void 0));var v,y,b,x,S,C,w=p(t),T=0;if(!w||this===m&&s(w))for(v=l(t),y=n?new this(v):m(v);v>T;T++)C=_?g(t[T],T):t[T],u(y,T,C);else for(y=n?new this:[],S=(x=f(t,w)).next;!(b=i(S,x)).done;T++)C=_?o(x,g,[b.value,T],!0):b.value,u(y,T,C);return d(y,T),y}},9617:function(e,t,n){var r=n(5397),i=n(5610),a=n(6198),o=function(e){return function(t,n,o){var s=r(t),c=a(s);if(c===0)return!e&&-1;var l,u=i(o,c);if(e&&n!=n){for(;c>u;)if((l=s[u++])!=l)return!0}else for(;c>u;u++)if((e||u in s)&&s[u]===n)return e||u||0;return!e&&-1}};e.exports={includes:o(!0),indexOf:o(!1)}},9213:function(e,t,n){var r=n(6080),i=n(7055),a=n(8981),o=n(6198),s=n(1469),c=n(4659),l=function(e){var t=e===1,n=e===2,l=e===3,u=e===4,d=e===6,f=e===7,p=e===5||d;return function(m,h,g){for(var _,v,y=a(m),b=i(y),x=o(b),S=r(h,g),C=0,w=0,T=t?s(m,x):n||f?s(m,0):void 0;x>C;C++)if((p||C in b)&&(v=S(_=b[C],C,y),e))if(t)c(T,C,v);else if(v)switch(e){case 3:return!0;case 5:return _;case 6:return C;case 2:c(T,w++,_)}else switch(e){case 4:return!1;case 7:c(T,w++,_)}return d?-1:l||u?u:T}};e.exports={forEach:l(0),map:l(1),filter:l(2),some:l(3),every:l(4),find:l(5),findIndex:l(6),filterReject:l(7)}},597:function(e,t,n){var r=n(9039),i=n(8227),a=n(9519),o=i(`species`);e.exports=function(e){return a>=51||!r((function(){var t=[];return(t.constructor={})[o]=function(){return{foo:1}},t[e](Boolean).foo!==1}))}},4598:function(e,t,n){var r=n(9039);e.exports=function(e,t){var n=[][e];return!!n&&r((function(){n.call(null,t||function(){return 1},1)}))}},926:function(e,t,n){var r=n(9306),i=n(8981),a=n(7055),o=n(6198),s=TypeError,c=`Reduce of empty array with no initial value`,l=function(e){return function(t,n,l,u){var d=i(t),f=a(d),p=o(d);if(r(n),p===0&&l<2)throw new s(c);var m=e?p-1:0,h=e?-1:1;if(l<2)for(;;){if(m in f){u=f[m],m+=h;break}if(m+=h,e?m<0:p<=m)throw new s(c)}for(;e?m>=0:p>m;m+=h)m in f&&(u=n(u,f[m],m,d));return u}};e.exports={left:l(!1),right:l(!0)}},4527:function(e,t,n){var r=n(3724),i=n(4376),a=TypeError,o=Object.getOwnPropertyDescriptor;e.exports=r&&!function(){if(this!==void 0)return!0;try{Object.defineProperty([],"length",{writable:!1}).length=1}catch(e){return e instanceof TypeError}}()?function(e,t){if(i(e)&&!o(e,`length`).writable)throw new a(`Cannot set read only .length`);return e.length=t}:function(e,t){return e.length=t}},7680:function(e,t,n){e.exports=n(9504)([].slice)},4488:function(e,t,n){var r=n(7680),i=Math.floor,a=function(e,t){var n=e.length;if(n<8)for(var o,s,c=1;c0;)e[s]=e[--s];s!==c++&&(e[s]=o)}else for(var l=i(n/2),u=a(r(e,0,l),t),d=a(r(e,l),t),f=u.length,p=d.length,m=0,h=0;m9007199254740991)throw t(`Maximum allowed index exceeded`);return e}},7400:function(e){e.exports={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0}},9296:function(e,t,n){var r=n(4055)(`span`).classList,i=r&&r.constructor&&r.constructor.prototype;e.exports=i===Object.prototype?void 0:i},8727:function(e){e.exports=[`constructor`,`hasOwnProperty`,`isPrototypeOf`,`propertyIsEnumerable`,`toLocaleString`,`toString`,`valueOf`]},3709:function(e,t,n){var r=n(2839).match(/firefox\/(\d+)/i);e.exports=!!r&&+r[1]},3763:function(e,t,n){var r=n(2839);e.exports=/MSIE|Trident/.test(r)},6193:function(e,t,n){e.exports=n(4215)===`NODE`},2839:function(e,t,n){var r=n(4576).navigator,i=r&&r.userAgent;e.exports=i?String(i):``},9519:function(e,t,n){var r,i,a=n(4576),o=n(2839),s=a.process,c=a.Deno,l=s&&s.versions||c&&c.version,u=l&&l.v8;u&&(i=(r=u.split(`.`))[0]>0&&r[0]<4?1:+(r[0]+r[1])),!i&&o&&(!(r=o.match(/Edge\/(\d+)/))||r[1]>=74)&&(r=o.match(/Chrome\/(\d+)/))&&(i=+r[1]),e.exports=i},3607:function(e,t,n){var r=n(2839).match(/AppleWebKit\/(\d+)\./);e.exports=!!r&&+r[1]},4215:function(e,t,n){var r=n(4576),i=n(2839),a=n(2195),o=function(e){return i.slice(0,e.length)===e};e.exports=o(`Bun/`)?`BUN`:o(`Cloudflare-Workers`)?`CLOUDFLARE`:o(`Deno/`)?`DENO`:o(`Node.js/`)?`NODE`:r.Bun&&typeof Bun.version==`string`?`BUN`:r.Deno&&typeof Deno.version==`object`?`DENO`:a(r.process)===`process`?`NODE`:r.window&&r.document?`BROWSER`:`REST`},6518:function(e,t,n){var r=n(4576),i=n(7347).f,a=n(6699),o=n(6840),s=n(9433),c=n(7740),l=n(2796);e.exports=function(e,t){var n,u,d,f,p,m=e.target,h=e.global,g=e.stat;if(n=h?r:g?r[m]||s(m,{}):r[m]&&r[m].prototype)for(u in t){if(f=t[u],d=e.dontCallGetSet?(p=i(n,u))&&p.value:n[u],!l(h?u:m+(g?`.`:`#`)+u,e.forced)&&d!==void 0){if(typeof f==typeof d)continue;c(f,d)}(e.sham||d&&d.sham)&&a(f,`sham`,!0),o(n,u,f,e)}}},9039:function(e){e.exports=function(e){try{return!!e()}catch{return!0}}},9228:function(e,t,n){n(7495);var r=n(9565),i=n(6840),a=n(7323),o=n(9039),s=n(8227),c=n(6699),l=s(`species`),u=RegExp.prototype;e.exports=function(e,t,n,d){var f=s(e),p=!o((function(){var t={};return t[f]=function(){return 7},``[e](t)!==7})),m=p&&!o((function(){var t=!1,n=/a/;if(e===`split`){var r={};r[l]=function(){return n},(n={constructor:r,flags:``})[f]=/./[f]}return n.exec=function(){return t=!0,null},n[f](``),!t}));if(!p||!m||n){var h=/./[f],g=t(f,``[e],(function(e,t,n,i,o){var s=t.exec;return s===a||s===u.exec?p&&!o?{done:!0,value:r(h,t,n,i)}:{done:!0,value:r(e,n,t,i)}:{done:!1}}));i(String.prototype,e,g[0]),i(u,f,g[1])}d&&c(u[f],`sham`,!0)}},8745:function(e,t,n){var r=n(616),i=Function.prototype,a=i.apply,o=i.call;e.exports=typeof Reflect==`object`&&Reflect.apply||(r?o.bind(a):function(){return o.apply(a,arguments)})},6080:function(e,t,n){var r=n(7476),i=n(9306),a=n(616),o=r(r.bind);e.exports=function(e,t){return i(e),t===void 0?e:a?o(e,t):function(){return e.apply(t,arguments)}}},616:function(e,t,n){e.exports=!n(9039)((function(){var e=function(){}.bind();return typeof e!=`function`||e.hasOwnProperty(`prototype`)}))},566:function(e,t,n){var r=n(9504),i=n(9306),a=n(34),o=n(9297),s=n(7680),c=n(616),l=Function,u=r([].concat),d=r([].join),f={};e.exports=c?l.bind:function(e){var t=i(this),n=t.prototype,r=s(arguments,1),c=function(){var n=u(r,s(arguments));return this instanceof c?function(e,t,n){if(!o(f,t)){for(var r=[],i=0;i]*>)/g,u=/\$([$&'`]|\d{1,2})/g;e.exports=function(e,t,n,r,d,f){var p=n+e.length,m=r.length,h=u;return d!==void 0&&(d=i(d),h=l),s(f,h,(function(i,s){var l;switch(o(s,0)){case`$`:return`$`;case`&`:return e;case"`":return c(t,0,n);case`'`:return c(t,p);case`<`:l=d[c(s,1,-1)];break;default:var u=+s;if(u===0)return i;if(u>m){var f=a(u/10);return f===0?i:f<=m?r[f-1]===void 0?o(s,1):r[f-1]+o(s,1):i}l=r[u-1]}return l===void 0?``:l}))}},4576:function(e,t,n){var r=function(e){return e&&e.Math===Math&&e};e.exports=r(typeof globalThis==`object`&&globalThis)||r(typeof window==`object`&&window)||r(typeof self==`object`&&self)||r(typeof n.g==`object`&&n.g)||r(typeof this==`object`&&this)||function(){return this}()||Function(`return this`)()},9297:function(e,t,n){var r=n(9504),i=n(8981),a=r({}.hasOwnProperty);e.exports=Object.hasOwn||function(e,t){return a(i(e),t)}},421:function(e){e.exports={}},397:function(e,t,n){e.exports=n(7751)(`document`,`documentElement`)},5917:function(e,t,n){var r=n(3724),i=n(9039),a=n(4055);e.exports=!r&&!i((function(){return Object.defineProperty(a(`div`),"a",{get:function(){return 7}}).a!==7}))},7055:function(e,t,n){var r=n(9504),i=n(9039),a=n(2195),o=Object,s=r(``.split);e.exports=i((function(){return!o(`z`).propertyIsEnumerable(0)}))?function(e){return a(e)===`String`?s(e,``):o(e)}:o},3167:function(e,t,n){var r=n(4901),i=n(34),a=n(2967);e.exports=function(e,t,n){var o,s;return a&&r(o=t.constructor)&&o!==n&&i(s=o.prototype)&&s!==n.prototype&&a(e,s),e}},3706:function(e,t,n){var r=n(9504),i=n(4901),a=n(7629),o=r(Function.toString);i(a.inspectSource)||(a.inspectSource=function(e){return o(e)}),e.exports=a.inspectSource},1181:function(e,t,n){var r,i,a,o=n(8622),s=n(4576),c=n(34),l=n(6699),u=n(9297),d=n(7629),f=n(6119),p=n(421),m=`Object already initialized`,h=s.TypeError,g=s.WeakMap;if(o||d.state){var _=d.state||=new g;_.get=_.get,_.has=_.has,_.set=_.set,r=function(e,t){if(_.has(e))throw new h(m);return t.facade=e,_.set(e,t),t},i=function(e){return _.get(e)||{}},a=function(e){return _.has(e)}}else{var v=f(`state`);p[v]=!0,r=function(e,t){if(u(e,v))throw new h(m);return t.facade=e,l(e,v,t),t},i=function(e){return u(e,v)?e[v]:{}},a=function(e){return u(e,v)}}e.exports={set:r,get:i,has:a,enforce:function(e){return a(e)?i(e):r(e,{})},getterFor:function(e){return function(t){var n;if(!c(t)||(n=i(t)).type!==e)throw new h(`Incompatible receiver, `+e+` required`);return n}}}},4209:function(e,t,n){var r=n(8227),i=n(6269),a=r(`iterator`),o=Array.prototype;e.exports=function(e){return e!==void 0&&(i.Array===e||o[a]===e)}},4376:function(e,t,n){var r=n(2195);e.exports=Array.isArray||function(e){return r(e)===`Array`}},4901:function(e){var t=typeof document==`object`&&document.all;e.exports=t===void 0&&t!==void 0?function(e){return typeof e==`function`||e===t}:function(e){return typeof e==`function`}},3517:function(e,t,n){var r=n(9504),i=n(9039),a=n(4901),o=n(6955),s=n(7751),c=n(3706),l=function(){},u=s(`Reflect`,`construct`),d=/^\s*(?:class|function)\b/,f=r(d.exec),p=!d.test(l),m=function(e){if(!a(e))return!1;try{return u(l,[],e),!0}catch{return!1}},h=function(e){if(!a(e))return!1;switch(o(e)){case`AsyncFunction`:case`GeneratorFunction`:case`AsyncGeneratorFunction`:return!1}try{return p||!!f(d,c(e))}catch{return!0}};h.sham=!0,e.exports=!u||i((function(){var e;return m(m.call)||!m(Object)||!m((function(){e=!0}))||e}))?h:m},2796:function(e,t,n){var r=n(9039),i=n(4901),a=/#|\.prototype\./,o=function(e,t){var n=c[s(e)];return n===u||n!==l&&(i(t)?r(t):!!t)},s=o.normalize=function(e){return String(e).replace(a,`.`).toLowerCase()},c=o.data={},l=o.NATIVE=`N`,u=o.POLYFILL=`P`;e.exports=o},2087:function(e,t,n){var r=n(34),i=Math.floor;e.exports=Number.isInteger||function(e){return!r(e)&&isFinite(e)&&i(e)===e}},4117:function(e){e.exports=function(e){return e==null}},34:function(e,t,n){var r=n(4901);e.exports=function(e){return typeof e==`object`?e!==null:r(e)}},3925:function(e,t,n){var r=n(34);e.exports=function(e){return r(e)||e===null}},6395:function(e){e.exports=!1},5810:function(e,t,n){var r=n(34),i=n(1181).get;e.exports=function(e){if(!r(e))return!1;var t=i(e);return!!t&&t.type===`RawJSON`}},788:function(e,t,n){var r=n(34),i=n(2195),a=n(8227)(`match`);e.exports=function(e){var t;return r(e)&&((t=e[a])===void 0?i(e)===`RegExp`:!!t)}},757:function(e,t,n){var r=n(7751),i=n(4901),a=n(1625),o=n(7040),s=Object;e.exports=o?function(e){return typeof e==`symbol`}:function(e){var t=r(`Symbol`);return i(t)&&a(t.prototype,s(e))}},9539:function(e,t,n){var r=n(9565),i=n(8551),a=n(5966);e.exports=function(e,t,n){var o,s;i(e);try{if(!(o=a(e,`return`))){if(t===`throw`)throw n;return n}o=r(o,e)}catch(e){s=!0,o=e}if(t===`throw`)throw n;if(s)throw o;return i(o),n}},3994:function(e,t,n){var r=n(7657).IteratorPrototype,i=n(2360),a=n(6980),o=n(687),s=n(6269),c=function(){return this};e.exports=function(e,t,n,l){var u=t+` Iterator`;return e.prototype=i(r,{next:a(+!l,n)}),o(e,u,!1,!0),s[u]=c,e}},1088:function(e,t,n){var r=n(6518),i=n(9565),a=n(6395),o=n(350),s=n(4901),c=n(3994),l=n(2787),u=n(2967),d=n(687),f=n(6699),p=n(6840),m=n(8227),h=n(6269),g=n(7657),_=o.PROPER,v=o.CONFIGURABLE,y=g.IteratorPrototype,b=g.BUGGY_SAFARI_ITERATORS,x=m(`iterator`),S=`keys`,C=`values`,w=`entries`,T=function(){return this};e.exports=function(e,t,n,o,m,g,E){c(n,t,o);var D,O,k,A=function(e){if(e===m&&F)return F;if(!b&&e&&e in N)return N[e];switch(e){case S:case C:case w:return function(){return new n(this,e)}}return function(){return new n(this)}},j=t+` Iterator`,M=!1,N=e.prototype,P=N[x]||N[`@@iterator`]||m&&N[m],F=!b&&P||A(m),I=t===`Array`&&N.entries||P;if(I&&(D=l(I.call(new e)))!==Object.prototype&&D.next&&(a||l(D)===y||(u?u(D,y):s(D[x])||p(D,x,T)),d(D,j,!0,!0),a&&(h[j]=T)),_&&m===C&&P&&P.name!==C&&(!a&&v?f(N,`name`,C):(M=!0,F=function(){return i(P,this)})),m)if(O={values:A(C),keys:g?F:A(S),entries:A(w)},E)for(k in O)(b||M||!(k in N))&&p(N,k,O[k]);else r({target:t,proto:!0,forced:b||M},O);return a&&!E||N[x]===F||p(N,x,F,{name:m}),h[t]=F,O}},7657:function(e,t,n){var r,i,a,o=n(9039),s=n(4901),c=n(34),l=n(2360),u=n(2787),d=n(6840),f=n(8227),p=n(6395),m=f(`iterator`),h=!1;[].keys&&(`next`in(a=[].keys())?(i=u(u(a)))!==Object.prototype&&(r=i):h=!0),!c(r)||o((function(){var e={};return r[m].call(e)!==e}))?r={}:p&&(r=l(r)),s(r[m])||d(r,m,(function(){return this})),e.exports={IteratorPrototype:r,BUGGY_SAFARI_ITERATORS:h}},6269:function(e){e.exports={}},6198:function(e,t,n){var r=n(8014);e.exports=function(e){return r(e.length)}},283:function(e,t,n){var r=n(9504),i=n(9039),a=n(4901),o=n(9297),s=n(3724),c=n(350).CONFIGURABLE,l=n(3706),u=n(1181),d=u.enforce,f=u.get,p=String,m=Object.defineProperty,h=r(``.slice),g=r(``.replace),_=r([].join),v=s&&!i((function(){return m((function(){}),`length`,{value:8}).length!==8})),y=String(String).split(`String`),b=e.exports=function(e,t,n){h(p(t),0,7)===`Symbol(`&&(t=`[`+g(p(t),/^Symbol\(([^)]*)\).*$/,`$1`)+`]`),n&&n.getter&&(t=`get `+t),n&&n.setter&&(t=`set `+t),(!o(e,`name`)||c&&e.name!==t)&&(s?m(e,`name`,{value:t,configurable:!0}):e.name=t),v&&n&&o(n,`arity`)&&e.length!==n.arity&&m(e,`length`,{value:n.arity});try{n&&o(n,`constructor`)&&n.constructor?s&&m(e,`prototype`,{writable:!1}):e.prototype&&=void 0}catch{}var r=d(e);return o(r,`source`)||(r.source=_(y,typeof t==`string`?t:``)),e};Function.prototype.toString=b((function(){return a(this)&&f(this).source||l(this)}),`toString`)},741:function(e){var t=Math.ceil,n=Math.floor;e.exports=Math.trunc||function(e){var r=+e;return(r>0?n:t)(r)}},7819:function(e,t,n){e.exports=!n(9039)((function(){var e=`9007199254740993`,t=JSON.rawJSON(e);return!JSON.isRawJSON(t)||JSON.stringify(t)!==e}))},5749:function(e,t,n){var r=n(788),i=TypeError;e.exports=function(e){if(r(e))throw new i(`The method doesn't accept regular expressions`);return e}},4213:function(e,t,n){var r=n(3724),i=n(9504),a=n(9565),o=n(9039),s=n(1072),c=n(3717),l=n(8773),u=n(8981),d=n(7055),f=Object.assign,p=Object.defineProperty,m=i([].concat);e.exports=!f||o((function(){if(r&&f({b:1},f(p({},`a`,{enumerable:!0,get:function(){p(this,`b`,{value:3,enumerable:!1})}}),{b:2})).b!==1)return!0;var e={},t={},n=Symbol(`assign detection`),i=`abcdefghijklmnopqrst`;return e[n]=7,i.split(``).forEach((function(e){t[e]=e})),f({},e)[n]!==7||s(f({},t)).join(``)!==i}))?function(e,t){for(var n=u(e),i=arguments.length,o=1,f=c.f,p=l.f;i>o;)for(var h,g=d(arguments[o++]),_=f?m(s(g),f(g)):s(g),v=_.length,y=0;v>y;)h=_[y++],r&&!a(p,g,h)||(n[h]=g[h]);return n}:f},2360:function(e,t,n){var r,i=n(8551),a=n(6801),o=n(8727),s=n(421),c=n(397),l=n(4055),u=n(6119),d=`prototype`,f=`script`,p=u(`IE_PROTO`),m=function(){},h=function(e){return`<`+f+`>`+e+``},g=function(e){e.write(h(``)),e.close();var t=e.parentWindow.Object;return e=null,t},_=function(){try{r=new ActiveXObject(`htmlfile`)}catch{}var e,t,n;_=typeof document<`u`?document.domain&&r?g(r):(t=l(`iframe`),n=`java`+f+`:`,t.style.display=`none`,c.appendChild(t),t.src=String(n),(e=t.contentWindow.document).open(),e.write(h(`document.F=Object`)),e.close(),e.F):g(r);for(var i=o.length;i--;)delete _[d][o[i]];return _()};s[p]=!0,e.exports=Object.create||function(e,t){var n;return e===null?n=_():(m[d]=i(e),n=new m,m[d]=null,n[p]=e),t===void 0?n:a.f(n,t)}},6801:function(e,t,n){var r=n(3724),i=n(8686),a=n(4913),o=n(8551),s=n(5397),c=n(1072);t.f=r&&!i?Object.defineProperties:function(e,t){o(e);for(var n,r=s(t),i=c(t),l=i.length,u=0;l>u;)a.f(e,n=i[u++],r[n]);return e}},4913:function(e,t,n){var r=n(3724),i=n(5917),a=n(8686),o=n(8551),s=n(6969),c=TypeError,l=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=`enumerable`,f=`configurable`,p=`writable`;t.f=r?a?function(e,t,n){if(o(e),t=s(t),o(n),typeof e==`function`&&t===`prototype`&&`value`in n&&p in n&&!n[p]){var r=u(e,t);r&&r[p]&&(e[t]=n.value,n={configurable:f in n?n[f]:r[f],enumerable:d in n?n[d]:r[d],writable:!1})}return l(e,t,n)}:l:function(e,t,n){if(o(e),t=s(t),o(n),i)try{return l(e,t,n)}catch{}if(`get`in n||`set`in n)throw new c(`Accessors not supported`);return`value`in n&&(e[t]=n.value),e}},7347:function(e,t,n){var r=n(3724),i=n(9565),a=n(8773),o=n(6980),s=n(5397),c=n(6969),l=n(9297),u=n(5917),d=Object.getOwnPropertyDescriptor;t.f=r?d:function(e,t){if(e=s(e),t=c(t),u)try{return d(e,t)}catch{}if(l(e,t))return o(!i(a.f,e,t),e[t])}},298:function(e,t,n){var r=n(2195),i=n(5397),a=n(8480).f,o=n(7680),s=typeof window==`object`&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];e.exports.f=function(e){return s&&r(e)===`Window`?function(e){try{return a(e)}catch{return o(s)}}(e):a(i(e))}},8480:function(e,t,n){var r=n(1828),i=n(8727).concat(`length`,`prototype`);t.f=Object.getOwnPropertyNames||function(e){return r(e,i)}},3717:function(e,t){t.f=Object.getOwnPropertySymbols},2787:function(e,t,n){var r=n(9297),i=n(4901),a=n(8981),o=n(6119),s=n(2211),c=o(`IE_PROTO`),l=Object,u=l.prototype;e.exports=s?l.getPrototypeOf:function(e){var t=a(e);if(r(t,c))return t[c];var n=t.constructor;return i(n)&&t instanceof n?n.prototype:t instanceof l?u:null}},1625:function(e,t,n){e.exports=n(9504)({}.isPrototypeOf)},1828:function(e,t,n){var r=n(9504),i=n(9297),a=n(5397),o=n(9617).indexOf,s=n(421),c=r([].push);e.exports=function(e,t){var n,r=a(e),l=0,u=[];for(n in r)!i(s,n)&&i(r,n)&&c(u,n);for(;t.length>l;)i(r,n=t[l++])&&(~o(u,n)||c(u,n));return u}},1072:function(e,t,n){var r=n(1828),i=n(8727);e.exports=Object.keys||function(e){return r(e,i)}},8773:function(e,t){var n={}.propertyIsEnumerable,r=Object.getOwnPropertyDescriptor;t.f=r&&!n.call({1:2},1)?function(e){var t=r(this,e);return!!t&&t.enumerable}:n},2551:function(e,t,n){var r=n(6395),i=n(4576),a=n(9039),o=n(3607);e.exports=r||!a((function(){if(!(o&&o<535)){var e=Math.random();__defineSetter__.call(null,e,(function(){})),delete i[e]}}))},2967:function(e,t,n){var r=n(6706),i=n(34),a=n(7750),o=n(3506);e.exports=Object.setPrototypeOf||(`__proto__`in{}?function(){var e,t=!1,n={};try{(e=r(Object.prototype,`__proto__`,`set`))(n,[]),t=n instanceof Array}catch{}return function(n,r){return a(n),o(r),i(n)&&(t?e(n,r):n.__proto__=r),n}}():void 0)},3179:function(e,t,n){var r=n(2140),i=n(6955);e.exports=r?{}.toString:function(){return`[object `+i(this)+`]`}},4270:function(e,t,n){var r=n(9565),i=n(4901),a=n(34),o=TypeError;e.exports=function(e,t){var n,s;if(t===`string`&&i(n=e.toString)&&!a(s=r(n,e))||i(n=e.valueOf)&&!a(s=r(n,e))||t!==`string`&&i(n=e.toString)&&!a(s=r(n,e)))return s;throw new o(`Can't convert object to primitive value`)}},5031:function(e,t,n){var r=n(7751),i=n(9504),a=n(8480),o=n(3717),s=n(8551),c=i([].concat);e.exports=r(`Reflect`,`ownKeys`)||function(e){var t=a.f(s(e)),n=o.f;return n?c(t,n(e)):t}},8235:function(e,t,n){var r=n(9504),i=n(9297),a=SyntaxError,o=parseInt,s=String.fromCharCode,c=r(``.charAt),l=r(``.slice),u=r(/./.exec),d={'\\"':`"`,"\\\\":`\\`,"\\/":`/`,"\\b":`\b`,"\\f":`\f`,"\\n":` +`)[0]}),i&&(0,K.jsx)(`span`,{className:`text-bambu-gray/50 shrink-0`,children:n?(0,K.jsx)(rs,{className:`w-3.5 h-3.5`}):(0,K.jsx)(es,{className:`w-3.5 h-3.5`})})]})},t)})})}),(0,K.jsx)(`div`,{className:`flex items-center justify-between p-3 border-t border-bambu-dark-tertiary text-sm text-bambu-gray`,children:d?(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`}),`Auto-refreshing every 2 seconds`]}):(0,K.jsx)(`span`,{children:`Click Start to enable live log streaming`})})]})]})}function UVe(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(2)} GB`}function S9({icon:e,label:t,value:n,subValue:r,color:i=`text-bambu-green`}){return(0,K.jsxs)(`div`,{className:`flex items-start gap-3 p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary ${i}`,children:(0,K.jsx)(e,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,K.jsx)(`p`,{className:`text-lg font-semibold text-white truncate`,children:n}),r&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:r})]})]})}function C9({percent:e,color:t=`bg-bambu-green`}){return(0,K.jsx)(`div`,{className:`w-full h-2 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full ${t} transition-all duration-300`,style:{width:`${Math.min(100,e)}%`}})})}function w9({title:e,icon:t,children:n}){return(0,K.jsxs)(pd,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,K.jsx)(t,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e})]}),n]})}function WVe(){let{t:e}=G(),t=Qa(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),{data:u,isLoading:d,refetch:f,isFetching:p}=q({queryKey:[`systemInfo`],queryFn:Q.getSystemInfo,refetchInterval:3e4}),{data:m}=q({queryKey:[`debugLogging`],queryFn:td.getDebugLoggingState,staleTime:10*1e3,refetchInterval:10*1e3}),{data:h}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:g}=q({queryKey:[`library-stats`],queryFn:Q.getLibraryStats}),{data:_}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:v,refetch:b,isFetching:x}=q({queryKey:[`systemHealth`],queryFn:Q.getSystemHealth,staleTime:60*1e3}),S=h?.time_format||`system`,C=async()=>{s(!0);try{let e=await td.setDebugLogging(!m?.enabled);t.setQueryData([`debugLogging`],e)}catch(e){console.error(`Failed to toggle debug logging:`,e)}finally{s(!1)}},w=async()=>{r(null),a(!0);try{await td.downloadSupportBundle()}catch(e){r(e instanceof Error?e.message:`Failed to download support bundle`)}finally{a(!1)}};if(d)return(0,K.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(!u)return(0,K.jsx)(`div`,{className:`p-6 text-center text-bambu-gray`,children:e(`system.failedToLoad`,`Failed to load system information`)});let T=u.storage.disk_percent_used>90?`bg-red-500`:u.storage.disk_percent_used>75?`bg-yellow-500`:`bg-bambu-green`,E=u.memory.percent_used>90?`bg-red-500`:u.memory.percent_used>75?`bg-yellow-500`:`bg-bambu-green`;return(0,K.jsxs)(`div`,{className:`p-6 space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`system.title`,`System Information`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`system.subtitle`,`Monitor system resources and database statistics`)})]}),(0,K.jsxs)(`button`,{onClick:()=>f(),disabled:p,className:`flex items-center gap-2 px-4 py-2 bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary rounded-lg transition-colors disabled:opacity-50`,children:[(0,K.jsx)(Cl,{className:`w-4 h-4 ${p?`animate-spin`:``}`}),e(`common.refresh`,`Refresh`)]})]}),(0,K.jsx)(w9,{title:e(`system.application`,`Application`),icon:Il,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,K.jsx)(S9,{icon:Il,label:e(`system.version`,`Version`),value:`v${u.app.version}`}),(0,K.jsx)(S9,{icon:_s,label:e(`system.uptime`,`System Uptime`),value:u.system.uptime_formatted}),(0,K.jsx)(S9,{icon:Il,label:e(`system.hostname`,`Hostname`),value:u.system.hostname})]})}),(0,K.jsx)(w9,{title:e(`support.title`,`Support & Troubleshooting`),icon:xc,children:(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`support.description`,`Enable debug logging to capture detailed information, then download a support bundle to share when reporting issues.`)}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${m?.enabled?`bg-amber-500/20 text-amber-500`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,K.jsx)(Ho,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.debugLogging`,`Debug Logging`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[m?.enabled?e(`support.debugLoggingEnabled`,`Capturing detailed logs`):e(`support.debugLoggingDisabled`,`Normal logging level`),m?.enabled&&m.duration_seconds!==null&&(0,K.jsxs)(`span`,{className:`text-amber-400 ml-2`,children:[`(`,Math.floor(m.duration_seconds/60),`m `,m.duration_seconds%60,`s)`]})]})]})]}),(0,K.jsxs)(`button`,{onClick:C,disabled:o,className:`px-4 py-2 rounded-lg font-medium transition-colors flex items-center gap-2 ${m?.enabled?`bg-amber-500/20 text-amber-400 hover:bg-amber-500/30`:`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`} disabled:opacity-50`,children:[o&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),m?.enabled?e(`support.disableDebug`,`Disable`):e(`support.enableDebug`,`Enable`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-green`,children:(0,K.jsx)(Is,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.supportBundle`,`Support Bundle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`support.supportBundleDescription`,`Download system info and logs as a ZIP file`)})]})]}),(0,K.jsxs)(`button`,{onClick:w,disabled:i||!m?.enabled,className:`px-4 py-2 rounded-lg font-medium bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 transition-colors flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed`,title:m?.enabled?void 0:e(`support.enableDebugFirst`,`Enable debug logging first`),children:[i&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),i?e(`support.bundleGenerating`,`Generating...`):e(`common.download`,`Download`)]})]}),i&&(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark-tertiary/40 rounded-lg space-y-1`,children:[(0,K.jsxs)(`p`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,K.jsx)(X,{className:`w-3.5 h-3.5 animate-spin text-bambu-green`}),e(`support.bundleGenerating`,`Generating...`)]}),(0,K.jsxs)(`ul`,{className:`text-xs text-bambu-gray list-disc list-inside space-y-0.5 pl-1`,children:[(0,K.jsx)(`li`,{children:e(`support.bundleStepConnection`,`Running printer connectivity checks`)}),(0,K.jsx)(`li`,{children:e(`support.bundleStepVirtualPrinters`,`Running virtual-printer setup checks`)}),(0,K.jsx)(`li`,{children:e(`support.bundleStepLogScan`,`Scanning recent logs for known issues`)}),(0,K.jsx)(`li`,{children:e(`support.bundleStepBuild`,`Building the support bundle ZIP`)})]})]}),n&&(0,K.jsx)(`div`,{className:`p-3 bg-red-500/20 border border-red-500/30 rounded-lg text-red-400 text-sm`,children:n}),!m?.enabled&&(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark-tertiary/50 rounded-lg`,children:(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`text-amber-400 font-medium`,children:e(`support.instructions`,`To report an issue:`)}),(0,K.jsx)(`br`,{}),`1. `,e(`support.step1`,`Enable debug logging`),(0,K.jsx)(`br`,{}),`2. `,e(`support.step2`,`Reproduce the issue`),(0,K.jsx)(`br`,{}),`3. `,e(`support.step3`,`Download the support bundle`),(0,K.jsx)(`br`,{}),`4. `,e(`support.step4`,`Attach the ZIP file to your issue report`)]})}),(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e(`support.privacyTitle`,`What's in the support bundle?`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 text-sm`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-bambu-green font-medium mb-1`,children:e(`support.collected`,`Collected:`)}),(0,K.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem1`,`App version and debug mode`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem2`,`OS, architecture, Python version`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem3`,`Database statistics (counts only)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem4`,`Printer models and nozzle counts`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem5`,`Non-sensitive settings (themes, formats)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem6`,`Debug logs (sanitized)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem7`,`Printer connectivity and firmware versions`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem8`,`Integration status (Spoolman, MQTT, HA)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem9`,`Network interfaces (subnets only)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem10`,`Python package versions`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem11`,`Database health checks`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem12`,`Docker environment details`)]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-red-400 font-medium mb-1`,children:e(`support.notCollected`,`NOT collected:`)}),(0,K.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem1`,`Printer names and serial numbers`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem2`,`Access codes and passwords`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem3`,`Email addresses`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem4`,`API keys and tokens`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem5`,`Webhook URLs`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem6`,`Your hostname or username`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem7`,`IP addresses`)]})]})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:e(`support.privacyNote`,`Email addresses in logs are replaced with [EMAIL], printer names with [PRINTER], serial numbers with [SERIAL], and IP addresses with [IP].`)})]}),(0,K.jsx)(HVe,{})]})}),(0,K.jsxs)(w9,{title:e(`diagnostic.sectionTitle`,`Connection Diagnostic`),icon:ru,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`diagnostic.sectionDescription`,`Check why a printer won't connect or won't print — port reachability, LAN developer mode, Docker network mode, and credentials.`)}),_&&_.length>0?(0,K.jsx)(`div`,{className:`space-y-2`,children:_.map(t=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:t.ip_address})]}),(0,K.jsxs)(`button`,{onClick:()=>l(t),className:`flex items-center gap-2 px-3 py-1.5 text-sm bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary text-white rounded-lg transition-colors flex-shrink-0`,children:[(0,K.jsx)(ru,{className:`w-4 h-4`}),e(`diagnostic.runButton`,`Run diagnostic`)]})]},t.id))}):(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`diagnostic.noPrinters`,`No printers configured.`)})]}),(0,K.jsxs)(w9,{title:e(`systemHealth.sectionTitle`),icon:Sc,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-3 mb-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`systemHealth.sectionDescription`)}),(0,K.jsxs)(`button`,{onClick:()=>b(),disabled:x,className:`flex items-center gap-2 px-3 py-1.5 text-sm bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary text-white rounded-lg transition-colors flex-shrink-0 disabled:opacity-50`,children:[(0,K.jsx)(Cl,{className:`w-4 h-4 ${x?`animate-spin`:``}`}),e(`systemHealth.rescan`)]})]}),v?(0,K.jsx)(jf,{result:v}):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`)})]}),(0,K.jsxs)(w9,{title:e(`system.database`,`Database`),icon:js,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mb-4`,children:[(0,K.jsx)(S9,{icon:js,label:e(`system.dbEngine`,`Database Engine`),value:u.database.engine||`SQLite`}),(0,K.jsx)(S9,{icon:js,label:e(`system.dbVersion`,`Version`),value:u.database.version||`unknown`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4 mb-4`,children:[(0,K.jsx)(S9,{icon:wo,label:e(`system.totalArchives`,`Total Archives`),value:u.database.archives}),(0,K.jsx)(S9,{icon:us,label:e(`system.completed`,`Completed`),value:u.database.archives_completed,color:`text-green-500`}),(0,K.jsx)(S9,{icon:ms,label:e(`system.failed`,`Failed`),value:u.database.archives_failed,color:`text-red-500`}),(0,K.jsx)(S9,{icon:X,label:e(`system.printing`,`Printing`),value:u.database.archives_printing,color:`text-yellow-500`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsx)(S9,{icon:bl,label:e(`system.printers`,`Printers`),value:u.database.printers}),(0,K.jsx)(S9,{icon:ll,label:e(`system.filaments`,`Filaments`),value:u.database.filaments}),(0,K.jsx)(S9,{icon:nc,label:e(`system.projects`,`Projects`),value:u.database.projects}),(0,K.jsx)(S9,{icon:gl,label:e(`system.smartPlugs`,`Smart Plugs`),value:u.database.smart_plugs})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mt-4`,children:[(0,K.jsx)(S9,{icon:_s,label:e(`system.totalPrintTime`,`Total Print Time`),value:u.database.total_print_time_formatted}),(0,K.jsx)(S9,{icon:wo,label:e(`system.totalFilament`,`Total Filament Used`),value:`${u.database.total_filament_kg} kg`,subValue:`${u.database.total_filament_grams.toLocaleString()} g`})]})]}),(0,K.jsxs)(w9,{title:e(`system.connectedPrinters`,`Connected Printers`),icon:bl,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 mb-4`,children:[(0,K.jsx)(`div`,{className:`text-3xl font-bold text-bambu-green`,children:u.printers.connected}),(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:e(`system.ofTotal`,`of {{total}} printers connected`,{total:u.printers.total})})]}),u.printers.connected_list.length>0?(0,K.jsx)(`div`,{className:`space-y-2`,children:u.printers.connected_list.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green`}),(0,K.jsx)(`span`,{className:`font-medium text-white`,children:e.name})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:e.model}),(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded ${e.state===`RUNNING`?`bg-bambu-green/20 text-bambu-green`:e.state===`IDLE`?`bg-blue-500/20 text-blue-400`:`bg-bambu-dark-tertiary`}`,children:e.state})]})]},e.id))}):(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`system.noPrintersConnected`,`No printers connected`)})]}),(0,K.jsx)(w9,{title:e(`system.storage`,`Storage`),icon:yc,children:(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.diskUsage`,`Disk Usage`)}),(0,K.jsxs)(`span`,{className:`text-white`,children:[u.storage.disk_used_formatted,` / `,u.storage.disk_total_formatted]})]}),(0,K.jsx)(C9,{percent:u.storage.disk_percent_used,color:T}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[u.storage.disk_free_formatted,` `,e(`system.free`,`free`),` (`,(100-u.storage.disk_percent_used).toFixed(1),`%)`]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,K.jsx)(S9,{icon:wo,label:e(`system.archiveStorage`,`Archive Storage`),value:u.storage.archive_size_formatted}),(0,K.jsx)(S9,{icon:js,label:e(`system.databaseSize`,`Database Size`),value:u.storage.database_size_formatted}),g&&(0,K.jsx)(S9,{icon:rc,label:e(`system.fileManagerStorage`,`File Manager`),value:UVe(g.total_size_bytes),subValue:`${g.total_files} files, ${g.total_folders} folders`})]})]})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,K.jsx)(w9,{title:e(`system.memory`,`Memory`),icon:Xc,children:(0,K.jsx)(`div`,{className:`space-y-4`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.memoryUsage`,`Memory Usage`)}),(0,K.jsxs)(`span`,{className:`text-white`,children:[u.memory.used_formatted,` / `,u.memory.total_formatted]})]}),(0,K.jsx)(C9,{percent:u.memory.percent_used,color:E}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[u.memory.available_formatted,` `,e(`system.available`,`available`)]})]})})}),(0,K.jsx)(w9,{title:e(`system.cpu`,`CPU`),icon:Os,children:(0,K.jsx)(`div`,{className:`space-y-4`,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsx)(S9,{icon:Os,label:e(`system.cores`,`Cores`),value:u.cpu.count,subValue:`${u.cpu.count_logical} logical`}),(0,K.jsx)(S9,{icon:Os,label:e(`system.usage`,`Usage`),value:`${u.cpu.percent}%`})]})})})]}),(0,K.jsx)(w9,{title:e(`system.systemDetails`,`System Details`),icon:Il,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsx)(S9,{icon:Il,label:e(`system.os`,`Operating System`),value:u.system.platform,subValue:u.system.platform_release}),(0,K.jsx)(S9,{icon:Os,label:e(`system.architecture`,`Architecture`),value:u.system.architecture}),(0,K.jsx)(S9,{icon:Il,label:e(`system.python`,`Python`),value:u.system.python_version}),(0,K.jsx)(S9,{icon:_s,label:e(`system.bootTime`,`Boot Time`),value:gf(u.system.boot_time,S)})]})}),c&&(0,K.jsx)(Df,{printerId:c.id,printerName:c.name,onClose:()=>l(null)})]})}var T9=`auth_remember_me`,E9=`auth_post_login_redirect`;function D9(e){return e?`persistent`:`session`}function GVe(){try{let e=sessionStorage.getItem(T9)===`1`;return sessionStorage.removeItem(T9),e}catch(e){return console.warn(`consumeSavedRememberMe: sessionStorage unavailable, Remember Me preference lost across OIDC redirect`,e),!1}}function O9(e){return!e||!e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`/login`)?null:e}function KVe(e){let t=O9(e);if(t)try{sessionStorage.setItem(E9,t)}catch(e){console.warn(`stashPostLoginRedirect: sessionStorage unavailable, post-login target will be lost across OIDC redirect`,e)}}function qVe(){try{let e=sessionStorage.getItem(E9);return sessionStorage.removeItem(E9),O9(e)}catch(e){return console.warn(`consumePostLoginRedirect: sessionStorage unavailable`,e),null}}function JVe({provider:e,onClick:t,disabled:n}){let{t:r}=G(),[i,a]=(0,y.useState)(!1);return(0,K.jsxs)(`button`,{type:`button`,onClick:t,disabled:n,className:`w-full flex items-center justify-center gap-3 py-3 px-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary hover:border-bambu-green/50 rounded-lg text-white font-medium transition-colors disabled:opacity-50`,children:[e.has_icon&&!i?(0,K.jsx)(`img`,{src:Q.oidcProviderIconUrl(e.id),alt:``,className:`w-5 h-5 object-contain`,onError:()=>a(!0)}):(0,K.jsx)(Hl,{className:`w-5 h-5 text-bambu-green`}),r(`login.twoFA.signInWith`,{provider:e.name})]})}function YVe(){let e=Yn(),t=Kn(),[n]=Oi(),{t:r}=G(),{login:i,loginWithToken:a}=sd(),{showToast:o}=xd(),{mode:s}=ud();function c(){let e=t.state?.from;if(e?.pathname){let t=O9(`${e.pathname}${e.search??``}`);if(t)return t}return qVe()??`/`}let[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(`credentials`),[b,x]=(0,y.useState)(``),[S,C]=(0,y.useState)([]),[w,T]=(0,y.useState)(`totp`),[E,D]=(0,y.useState)(``),[O,k]=(0,y.useState)(!1),A=(0,y.useRef)(null),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)(``),[F,I]=(0,y.useState)(``),[L,R]=(0,y.useState)(``),{data:z}=q({queryKey:[`advancedAuthStatus`],queryFn:()=>Q.getAdvancedAuthStatus()}),{data:B}=q({queryKey:[`oidcProviders`],queryFn:()=>Q.getOIDCProviders()});(0,y.useEffect)(()=>{let t=window.location.hash,n=t.startsWith(`#reset_token=`)?t.slice(13):null;n&&(P(n),v(`reset-password`),e(`/login`,{replace:!0}))},[]),(0,y.useEffect)(()=>{let t=window.location.hash,i=t.startsWith(`#oidc_token=`)?t.slice(12):null,s=n.get(`oidc_error`);if(!i&&!s)return;let l=GVe();if(s){o({oidc_provider_error:r(`login.oidcErrors.providerError`),missing_parameters:r(`login.oidcErrors.missingParameters`),invalid_state:r(`login.oidcErrors.invalidState`),state_expired:r(`login.oidcErrors.stateExpired`),provider_not_found:r(`login.oidcErrors.providerNotFound`),discovery_failed:r(`login.oidcErrors.discoveryFailed`),invalid_discovery_document:r(`login.oidcErrors.invalidDiscovery`),token_exchange_network_error:r(`login.oidcErrors.networkError`),token_exchange_bad_response:r(`login.oidcErrors.badResponse`),no_id_token:r(`login.oidcErrors.noIdToken`),token_validation_failed:r(`login.oidcErrors.validationFailed`),nonce_mismatch:r(`login.oidcErrors.nonceMismatch`),missing_sub_claim:r(`login.oidcErrors.missingSubClaim`),no_linked_account:r(`login.oidcErrors.noLinkedAccount`),account_inactive:r(`login.oidcErrors.accountInactive`),user_resolution_failed:r(`login.oidcErrors.userResolutionFailed`),internal_error:r(`login.oidcErrors.internalError`)}[s]??(s.startsWith(`token_exchange_`)?r(`login.oidcErrors.tokenExchangeFailed`):r(`login.oidcLoginFailed`)),`error`),e(`/login`,{replace:!0});return}i&&Q.exchangeOIDCToken(i).then(t=>{if(t.requires_2fa&&t.pre_auth_token){M(l),x(t.pre_auth_token);let n=t.two_fa_methods??[];C(n),n.includes(`totp`)?T(`totp`):n.includes(`email`)?T(`email`):T(`backup`),v(`2fa`),e(`/login`,{replace:!0})}else t.access_token&&t.user?(a(t.access_token,t.user,D9(l)),o(r(`login.loginSuccess`)),e(c(),{replace:!0})):(o(r(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0}))}).catch(t=>{console.error(`OIDC token exchange failed`,t),o(r(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0})})},[n]);let V=J({mutationFn:()=>i(l,d,D9(j)),onSuccess:t=>{if(t.requires_2fa&&t.pre_auth_token){x(t.pre_auth_token);let e=t.two_fa_methods??[];C(e),e.includes(`totp`)?T(`totp`):e.includes(`email`)?T(`email`):T(`backup`),v(`2fa`)}else t.access_token&&t.user&&(o(r(`login.loginSuccess`)),e(c(),{replace:!0}))},onError:e=>{o(e.message||r(`login.loginFailed`),`error`)}}),ee=J({mutationFn:e=>Q.forgotPassword({email:e}),onSuccess:e=>{o(e.message,`success`),m(!1),g(``)},onError:e=>{o(e.message,`error`)}}),H=J({mutationFn:()=>Q.forgotPasswordConfirm(N,F),onSuccess:e=>{o(e.message,`success`),v(`credentials`),P(``),I(``),R(``)},onError:e=>{o(e.message||r(`login.resetPassword.resetFailed`),`error`)}}),te=J({mutationFn:()=>Q.sendEmailOTP(b),onSuccess:e=>{k(!0),e.pre_auth_token&&x(e.pre_auth_token),o(e.message,`success`)},onError:e=>{o(e.message||r(`login.twoFA.sendCodeFailed`),`error`)}}),ne=J({mutationFn:()=>Q.verify2FA({pre_auth_token:b,code:E,method:w}),onSuccess:t=>{t.access_token&&t.user?(a(t.access_token,t.user,D9(j)),o(r(`login.loginSuccess`)),e(c(),{replace:!0})):(console.error(`2FA verify: unexpected response shape`,t),o(r(`login.loginFailed`),`error`))},onError:e=>{o(e.message||r(`login.twoFA.invalidCode`),`error`),D(``)}}),re=J({mutationFn:e=>Q.getOIDCAuthorizeUrl(e),onSuccess:e=>{if(j)try{sessionStorage.setItem(T9,`1`)}catch(e){console.warn(`setItem auth_remember_me failed, Remember Me will not carry through OIDC redirect`,e)}let n=t.state?.from;n?.pathname&&KVe(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url},onError:e=>{o(e.message||r(`login.oidcLoginFailed`),`error`)}}),U=e=>{if(e.preventDefault(),!l||!d){o(r(`login.enterCredentials`),`error`);return}V.mutate()},ie=e=>{if(e.preventDefault(),!E.trim()){o(r(`login.twoFA.enterCode`),`error`);return}ne.mutate()},ae=e=>{if(e.preventDefault(),!h){o(r(`login.enterEmail`),`error`);return}ee.mutate(h)},W=e=>{T(e),D(``),k(!1),setTimeout(()=>A.current?.focus(),0)};return _===`reset-password`?(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,K.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,K.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,K.jsx)(jc,{className:`w-7 h-7 text-bambu-green`})})}),(0,K.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:r(`login.resetPassword.title`)}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.resetPassword.subtitle`)})]}),(0,K.jsxs)(`form`,{onSubmit:e=>{if(e.preventDefault(),F!==L){o(r(`login.resetPassword.passwordsDoNotMatch`),`error`);return}if(F.length<8){o(r(`login.resetPassword.passwordTooShort`),`error`);return}H.mutate()},className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`new-password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.resetPassword.newPassword`)}),(0,K.jsx)(`input`,{id:`new-password`,type:`password`,required:!0,value:F,onChange:e=>I(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.resetPassword.newPasswordPlaceholder`),autoFocus:!0,autoComplete:`new-password`,minLength:8})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.resetPassword.confirmPassword`)}),(0,K.jsx)(`input`,{id:`confirm-password`,type:`password`,required:!0,value:L,onChange:e=>R(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.resetPassword.confirmPasswordPlaceholder`),autoComplete:`new-password`})]}),(0,K.jsx)(`button`,{type:`submit`,disabled:H.isPending||!F||!L,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:H.isPending?r(`login.resetPassword.saving`):r(`login.resetPassword.submit`)})]}),(0,K.jsx)(`div`,{className:`text-center`,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>{v(`credentials`),P(``),I(``),R(``)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.resetPassword.backToLogin`)})})]})}):_===`2fa`?(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,K.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,K.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,K.jsx)(Hl,{className:`w-7 h-7 text-bambu-green`})})}),(0,K.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:r(`login.twoFA.title`)}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.twoFA.subtitle`)})]}),S.length>1&&(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[S.includes(`totp`)&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>W(`totp`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${w===`totp`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,K.jsx)(Yl,{className:`w-4 h-4`}),r(`login.twoFA.methodAuthenticator`)]}),S.includes(`email`)&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>W(`email`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${w===`email`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,K.jsx)(Gc,{className:`w-4 h-4`}),r(`login.twoFA.methodEmail`)]}),S.includes(`backup`)&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>W(`backup`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${w===`backup`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,K.jsx)(jc,{className:`w-4 h-4`}),r(`login.twoFA.methodBackup`)]})]}),(0,K.jsxs)(`form`,{onSubmit:ie,className:`space-y-4`,children:[w===`totp`&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(`login.twoFA.instructionsTotp`)}),w===`email`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(O?`login.twoFA.instructionsEmail`:`login.twoFA.instructionsEmailNotSent`)}),!O&&(0,K.jsx)($,{type:`button`,variant:`secondary`,className:`w-full`,onClick:()=>te.mutate(),disabled:te.isPending,children:te.isPending?r(`login.twoFA.sendingCode`):r(`login.twoFA.sendCodeButton`)}),O&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{k(!1),te.mutate()},className:`text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.twoFA.resendCode`)})]}),w===`backup`&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(`login.twoFA.instructionsBackup`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`twofa-code`,className:`block text-sm font-medium text-white mb-2`,children:r(w===`backup`?`login.twoFA.backupCodeLabel`:`login.twoFA.codeLabel`)}),(0,K.jsx)(`input`,{ref:A,id:`twofa-code`,type:`text`,inputMode:w===`backup`?`text`:`numeric`,autoComplete:`one-time-code`,value:E,onChange:e=>D(e.target.value.trim()),disabled:w===`email`&&!O,className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray text-center tracking-widest text-xl font-mono focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-40`,placeholder:r(w===`backup`?`login.twoFA.backupCodePlaceholder`:`login.twoFA.codePlaceholder`),maxLength:w===`backup`?8:6,autoFocus:!0})]}),(0,K.jsx)(`button`,{type:`submit`,disabled:ne.isPending||!E.trim()||w===`email`&&!O,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:ne.isPending?r(`login.twoFA.verifyingButton`):r(`login.twoFA.verifyButton`)})]}),(0,K.jsx)(`div`,{className:`text-center`,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>{v(`credentials`),x(``),D(``),k(!1)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.twoFA.backToLogin`)})})]})}):(0,K.jsxs)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:[(0,K.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,K.jsx)(`img`,{src:s===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,K.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:r(`login.title`)}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.subtitle`)})]}),(0,K.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:U,children:[(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-white mb-2`,children:z?.advanced_auth_enabled?r(`login.usernameOrEmail`):r(`login.username`)}),(0,K.jsx)(`input`,{id:`username`,type:`text`,required:!0,value:l,onChange:e=>u(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:z?.advanced_auth_enabled?r(`login.usernameOrEmailPlaceholder`):r(`login.usernamePlaceholder`),autoComplete:`username`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.password`)||`Password`}),(0,K.jsx)(`input`,{id:`password`,type:`password`,required:!0,value:d,onChange:e=>f(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.passwordPlaceholder`),autoComplete:`current-password`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{id:`remember-me`,type:`checkbox`,checked:j,onChange:e=>M(e.target.checked),className:`h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,K.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:r(`login.rememberMe`)})]}),(0,K.jsx)(`div`,{children:(0,K.jsx)(`button`,{type:`submit`,disabled:V.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:V.isPending?r(`login.signingIn`):r(`login.signIn`)})}),(0,K.jsx)(`div`,{className:`text-center`,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>m(!0),className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.forgotPassword`)})})]}),B&&B.length>0&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,K.jsx)(`div`,{className:`w-full border-t border-bambu-dark-tertiary`})}),(0,K.jsx)(`div`,{className:`relative flex justify-center text-sm`,children:(0,K.jsx)(`span`,{className:`px-2 bg-bambu-dark-secondary text-bambu-gray`,children:r(`login.twoFA.orContinueWith`)})})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:B.map(e=>(0,K.jsx)(JVe,{provider:e,onClick:()=>re.mutate(e.id),disabled:re.isPending},e.id))})]})]}),p&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>m(!1),children:(0,K.jsxs)(pd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(md,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Gc,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`login.forgotPasswordTitle`)})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{m(!1),g(``)},children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]})}),(0,K.jsx)(hd,{children:z?.advanced_auth_enabled?(0,K.jsxs)(`form`,{onSubmit:ae,className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:r(`login.forgotPasswordEmailMessage`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`forgot-email`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.emailAddress`)}),(0,K.jsx)(`input`,{id:`forgot-email`,type:`email`,required:!0,value:h,onChange:e=>g(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.emailPlaceholder`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,className:`flex-1`,onClick:()=>{m(!1),g(``)},children:r(`login.cancel`)}),(0,K.jsx)($,{type:`submit`,className:`flex-1`,disabled:ee.isPending,children:ee.isPending?r(`login.sending`):r(`login.sendResetEmail`)})]})]}):(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:r(`login.forgotPasswordMessage`)}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4 space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white font-medium`,children:r(`login.howToReset`)}),(0,K.jsxs)(`ol`,{className:`text-sm text-bambu-gray space-y-1 list-decimal list-inside`,children:[(0,K.jsx)(`li`,{children:r(`login.resetStep1`)}),(0,K.jsx)(`li`,{children:r(`login.resetStep2`)}),(0,K.jsx)(`li`,{children:r(`login.resetStep3`)}),(0,K.jsx)(`li`,{children:r(`login.resetStep4`)})]})]}),(0,K.jsx)($,{variant:`secondary`,className:`w-full`,onClick:()=>m(!1),children:r(`login.gotIt`)})]})})]})})]})}function XVe(){let e=Yn(),{t}=G(),{showToast:n}=xd(),{mode:r}=ud(),{refreshAuth:i}=sd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),p=J({mutationFn:()=>Q.setupAuth({auth_enabled:a,admin_username:a?s:void 0,admin_password:a?l:void 0}),onSuccess:async r=>{await i(),r.auth_enabled?r.admin_created?(n(t(`setup.toast.authEnabledAdminCreated`)),e(`/login`)):(n(t(`setup.toast.authEnabledExistingAdmins`)),e(`/login`)):(n(t(`setup.toast.setupCompleted`)),e(`/`))},onError:e=>{n(e.message,`error`)}});return(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,K.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,K.jsx)(`img`,{src:r===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,K.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:t(`setup.title`)}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:t(`setup.subtitle`)})]}),(0,K.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:e=>{if(e.preventDefault(),a&&(s||l)){if(!s||!l){n(t(`setup.toast.enterBothCredentials`),`error`);return}if(l!==d){n(t(`setup.toast.passwordsDoNotMatch`),`error`);return}if(l.length<6){n(t(`setup.toast.passwordTooShort`),`error`);return}}p.mutate()},children:[(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center p-4 bg-bambu-dark-secondary/50 rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`input`,{id:`auth-enabled`,type:`checkbox`,checked:a,onChange:e=>o(e.target.checked),className:`h-4 w-4 text-bambu-green focus:ring-bambu-green border-bambu-dark-tertiary rounded bg-bambu-dark-secondary`}),(0,K.jsx)(`label`,{htmlFor:`auth-enabled`,className:`ml-3 block text-sm font-medium text-white`,children:t(`setup.enableAuth`)})]}),a&&(0,K.jsxs)(`div`,{className:`space-y-4 mt-4`,children:[(0,K.jsx)(`div`,{className:`p-3 bg-bambu-dark-secondary/50 border border-bambu-dark-tertiary rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(kc,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`text-sm text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium mb-1`,children:t(`setup.adminAccount`)}),(0,K.jsx)(`p`,{children:t(`setup.adminAccountDesc`)})]})]})}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{htmlFor:`admin-username`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminUsername`),` `,(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,K.jsx)(`input`,{id:`admin-username`,type:`text`,value:s,onChange:e=>c(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.adminUsernamePlaceholder`),autoComplete:`username`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{htmlFor:`admin-password`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminPassword`),` `,(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,K.jsx)(`input`,{id:`admin-password`,type:`password`,value:l,onChange:e=>u(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.adminPasswordPlaceholder`),minLength:6,autoComplete:`new-password`})]}),l&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:t(`setup.confirmPassword`)}),(0,K.jsx)(`input`,{id:`confirm-password`,type:`password`,value:d,onChange:e=>f(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.confirmPasswordPlaceholder`),minLength:6,autoComplete:`new-password`})]})]})]}),(0,K.jsx)(`div`,{children:(0,K.jsx)(`button`,{type:`submit`,disabled:p.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:p.isPending?t(`setup.settingUp`):t(`setup.completeSetup`)})})]})]})})}function ZVe(){let{t:e}=G(),{user:t}=sd(),{showToast:n}=xd(),r=Qa(),i=Yn(),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(!0),[l,u]=(0,y.useState)(!0),[d,f]=(0,y.useState)(!0),[p,m]=(0,y.useState)(!1),{data:h,isLoading:g}=q({queryKey:[`advancedAuthStatus`],queryFn:Q.getAdvancedAuthStatus,staleTime:300*1e3}),{data:_,isLoading:v}=q({queryKey:[`settings`],queryFn:Q.getSettings,staleTime:300*1e3}),{data:b,isLoading:x}=q({queryKey:[`user-email-preferences`],queryFn:()=>Q.getUserEmailPreferences()});(0,y.useEffect)(()=>{(h&&!h.advanced_auth_enabled||_&&!_.user_notifications_enabled)&&i(`/settings`,{replace:!0})},[h,_,i]),(0,y.useEffect)(()=>{b&&(o(b.notify_print_start),c(b.notify_print_complete),u(b.notify_print_failed),f(b.notify_print_stopped),m(!1))},[b]);let S=J({mutationFn:()=>Q.updateUserEmailPreferences({notify_print_start:a,notify_print_complete:s,notify_print_failed:l,notify_print_stopped:d}),onSuccess:()=>{r.invalidateQueries({queryKey:[`user-email-preferences`]}),m(!1),n(e(`notifications.userEmail.saveSuccess`),`success`)},onError:t=>{n(t.message||e(`notifications.userEmail.saveError`),`error`)}}),C=(e,t)=>{e(!t),m(!0)};return x||g||v?(0,K.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,K.jsxs)(`div`,{className:`p-4 md:p-6 max-w-2xl mx-auto`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-6`,children:[(0,K.jsx)(Io,{className:`w-7 h-7 text-bambu-green`}),(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`notifications.userEmail.title`)})]}),(0,K.jsx)(pd,{className:`mb-6 border-blue-500/30 bg-blue-500/5`,children:(0,K.jsx)(hd,{className:`py-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0`,children:(0,K.jsx)(Gc,{className:`w-5 h-5 text-blue-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-white font-medium`,children:e(`notifications.userEmail.emailNotifications`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.emailNotificationsDesc`)}),t?.email?(0,K.jsxs)(`p`,{className:`text-sm text-blue-400 mt-2`,children:[e(`notifications.userEmail.sendingTo`),`: `,(0,K.jsx)(`strong`,{children:t.email})]}):(0,K.jsx)(`p`,{className:`text-sm text-yellow-400 mt-2`,children:e(`notifications.userEmail.noEmailWarning`)})]})]})})}),(0,K.jsxs)(pd,{className:`mb-6`,children:[(0,K.jsxs)(md,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`notifications.userEmail.printJobNotifications`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.printJobNotificationsDesc`)})]}),(0,K.jsxs)(hd,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${a?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(us,{className:`w-5 h-5 ${a?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStarts`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStartsDesc`)})]})]}),(0,K.jsx)(`button`,{onClick:()=>C(o,a),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${a?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":a,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${a?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${s?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(us,{className:`w-5 h-5 ${s?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobFinishes`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobFinishesDesc`)})]})]}),(0,K.jsx)(`button`,{onClick:()=>C(c,s),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${s?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":s,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${s?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(us,{className:`w-5 h-5 ${l?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printErrors`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printErrorsDesc`)})]})]}),(0,K.jsx)(`button`,{onClick:()=>C(u,l),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${l?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":l,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${l?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${d?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(us,{className:`w-5 h-5 ${d?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStops`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStopsDesc`)})]})]}),(0,K.jsx)(`button`,{onClick:()=>C(f,d),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${d?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":d,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${d?`translate-x-6`:`translate-x-1`}`})})]})]})]}),(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsx)($,{onClick:()=>S.mutate(),disabled:!p||S.isPending||!t?.email,children:S.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),e(`common.saving`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),e(`common.save`)]})})})]})}function QVe(){let e=Yn(),[t]=Oi(),{t:n}=G();if(window!==window.top)return(0,K.jsxs)(`div`,{style:{padding:32,color:`#f88`},children:[`GCode viewer static files not found. Check that the`,` `,(0,K.jsx)(`code`,{children:`gcode_viewer/`}),` directory exists and restart uvicorn.`]});let r=t.has(`archive`),i=t.has(`library_file`),a=r?`/archives`:i?`/files`:`/`,o=n(r?`gcodeViewer.backToArchives`:i?`gcodeViewer.backToFiles`:`gcodeViewer.back`),s=()=>{window.history.length>1?e(-1):e(a)},c=`/gcode-viewer/${window.location.search}`;return(0,K.jsxs)(`div`,{style:{height:`calc(100vh - 3.5rem)`,display:`flex`,flexDirection:`column`},children:[(0,K.jsx)(`div`,{className:`flex items-center gap-2 px-4 py-2 border-b border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:s,className:`inline-flex items-center gap-1.5 text-sm text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white transition-colors`,children:[(0,K.jsx)(Do,{className:`w-4 h-4`}),o]})}),(0,K.jsx)(`iframe`,{src:c,title:`GCode Viewer`,style:{display:`block`,width:`100%`,flex:1,border:`none`}})]})}function $Ve(){let e=(0,y.useRef)(null),t=(0,y.useRef)(null),n=Qa(),[r,i]=(0,y.useState)(!1),a=(0,y.useRef)(new Map),{showToast:o}=xd(),{t:s}=G(),c=(0,y.useRef)(new Set),l=(0,y.useRef)(null),u=(0,y.useRef)(new Map),d=(0,y.useRef)(null),f=(0,y.useRef)([]),p=(0,y.useRef)(!1),m=(0,y.useRef)(()=>{}),h=(0,y.useCallback)(()=>{if(p.current||f.current.length===0)return;p.current=!0;let e=()=>{let t=f.current.shift();t?requestAnimationFrame(()=>{m.current(t),f.current.length>0?setTimeout(e,16):p.current=!1}):p.current=!1};e()},[]),g=(0,y.useCallback)(async()=>{if(e.current?.readyState===WebSocket.OPEN)return;let n;try{n=(await Q.getWebSocketToken()).token}catch{}let r=window.location.protocol===`https:`?`wss:`:`ws:`,a=n?`?token=${encodeURIComponent(n)}`:``,o=`${r}//${window.location.host}/api/v1/ws${a}`,s=new WebSocket(o),c=null;s.onopen=()=>{console.log(`[WebSocket] Connected`),i(!0),c=window.setInterval(()=>{s.readyState===WebSocket.OPEN&&s.send(JSON.stringify({type:`ping`}))},3e4)},s.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`printer_status`&&t.printer_id!==void 0&&t.data?m.current(t):(f.current.push(t),h())}catch{}},s.onclose=n=>{console.log(`[WebSocket] Closed`,n.code,n.reason),c&&=(clearInterval(c),null),i(!1),e.current=null,t.current=window.setTimeout(()=>{g()},3e3)},s.onerror=e=>{console.error(`[WebSocket] Error`,e),s.close()},e.current=s},[h]),_=(0,y.useCallback)((e,t)=>{let r=u.current.get(e)||{};u.current.set(e,{...r,...t}),d.current||=window.setTimeout(()=>{let e=new Map(u.current);u.current.clear(),d.current=null,requestAnimationFrame(()=>{e.forEach((e,t)=>{n.setQueryData([`printerStatus`,t],t=>{let n={...t,...e};return n.wifi_signal==null&&t?.wifi_signal!=null&&(n.wifi_signal=t.wifi_signal),n})})})},100)},[n]),v=(0,y.useCallback)(e=>{c.current.add(e),l.current&&clearTimeout(l.current),l.current=window.setTimeout(()=>{let e=Array.from(c.current);c.current.clear(),l.current=null;let t=0;e.forEach(e=>{setTimeout(()=>{requestAnimationFrame(()=>{n.invalidateQueries({queryKey:[e]})})},t),t+=500})},3e3)},[n]),b=(0,y.useCallback)(e=>{switch(e.type){case`printer_status`:e.printer_id!==void 0&&e.data&&_(e.printer_id,e.data);break;case`print_start`:e.printer_id!==void 0&&n.invalidateQueries({queryKey:[`printerStatus`,e.printer_id]});break;case`missing_spool_assignment`:{if(e.printer_id===void 0||!Array.isArray(e.missing_slots))break;let t=e.missing_slots.map(e=>e&&typeof e.slot==`string`?e.slot:`Unknown`).filter(e=>e.length>0);if(t.length===0){a.current.delete(e.printer_id);break}let n=t.join(`|`);if(a.current.get(e.printer_id)===n)break;a.current.set(e.printer_id,n),o(s(`printers.toast.missingSpoolAssignment`,{printer:e.printer_name||`Printer ${e.printer_id}`,slots:t.join(`, `)}),`warning`);break}case`print_complete`:v(`archives`),v(`archiveStats`);break;case`archive_created`:v(`archives`),v(`archiveStats`);break;case`archive_updated`:v(`archives`);break;case`pong`:break;case`plate_not_empty`:window.dispatchEvent(new CustomEvent(`plate-not-empty`,{detail:{printer_id:e.printer_id,printer_name:e.printer_name,message:e.message}}));break;case`inventory_changed`:v(`inventory-spools`),v(`spoolman-inventory-spools`),v(e9[0]);break;case`spool_assignment_changed`:v(`spool-assignments`),v(`slotPresets`);break;case`spool_auto_assigned`:v(`inventory-spools`),v(`spool-assignments`);break;case`spool_usage_logged`:v(`inventory-spools`);break;case`unknown_tag`:window.dispatchEvent(new CustomEvent(`unknown-tag`,{detail:{printer_id:e.printer_id,ams_id:e.ams_id,tray_id:e.tray_id,tag_uid:e.tag_uid,tray_uuid:e.tray_uuid}}));break;case`background_dispatch`:window.dispatchEvent(new CustomEvent(`background-dispatch`,{detail:e.data||{}}));break;case`spoolbuddy_weight`:window.dispatchEvent(new CustomEvent(`spoolbuddy-weight`,{detail:e}));break;case`spoolbuddy_tag_matched`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-matched`,{detail:e})),v(`inventory-spools`);break;case`spoolbuddy_unknown_tag`:window.dispatchEvent(new CustomEvent(`spoolbuddy-unknown-tag`,{detail:e}));break;case`spoolbuddy_tag_removed`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-removed`,{detail:e}));break;case`spoolbuddy_tag_written`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-written`,{detail:e})),v(`inventory-spools`);break;case`spoolbuddy_tag_write_failed`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-write-failed`,{detail:e}));break;case`spoolbuddy_online`:window.dispatchEvent(new CustomEvent(`spoolbuddy-online`,{detail:e})),v(`spoolbuddy-devices`),v(`spoolbuddy-update-check`);break;case`spoolbuddy_offline`:window.dispatchEvent(new CustomEvent(`spoolbuddy-offline`,{detail:e})),v(`spoolbuddy-devices`);break;case`spoolbuddy_update`:v(`spoolbuddy-devices`),v(`spoolbuddy-update-check`);break}},[n,v,_,o,s]);return(0,y.useEffect)(()=>{m.current=b},[b]),(0,y.useEffect)(()=>(g(),()=>{t.current&&clearTimeout(t.current),l.current&&clearTimeout(l.current),d.current&&clearTimeout(d.current),e.current&&e.current.close()}),[g]),{isConnected:r,sendMessage:(0,y.useCallback)(t=>{e.current?.readyState===WebSocket.OPEN&&e.current.send(JSON.stringify(t))},[])}}function eHe({children:e}){let{authEnabled:t,user:n,loading:r}=sd(),{data:i}=q({queryKey:[`color-catalog-map`],queryFn:async()=>(await Q.getColorNameMap()).colors,staleTime:1/0,gcTime:1/0,retry:2,enabled:!r&&(!t||n!==null)});return(0,y.useEffect)(()=>{i&&Ld(i)},[i]),(0,K.jsx)(K.Fragment,{children:e})}function tHe({selectedPrinterId:e,onPrinterChange:t,deviceOnline:n}){let{t:r}=G(),[i,a]=(0,y.useState)(new Date),{data:o=[]}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters()}),s=po({queries:o.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),refetchInterval:1e4}))}),c=(0,y.useMemo)(()=>o.filter((e,t)=>s[t]?.data?.connected),[o,s]);(0,y.useEffect)(()=>{let n=c.some(t=>t.id===e);(!e||!n)&&c.length>0&&t(c[0].id)},[c,e,t]);let{data:l}=q({queryKey:[`settings`],queryFn:Q.getSettings});return(0,y.useEffect)(()=>{let e=setInterval(()=>a(new Date),1e3);return()=>clearInterval(e)},[]),(0,K.jsxs)(`div`,{className:`h-12 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary flex items-center px-3 gap-4 shrink-0`,children:[(0,K.jsx)(`div`,{className:`flex items-center shrink-0`,children:(0,K.jsx)(`img`,{src:`/img/spoolbuddy_logo_dark_small.png`,alt:`SpoolBuddy`,width:113,height:28,className:`h-7 w-auto`})}),(0,K.jsx)(`div`,{className:`flex-1 flex justify-center`,children:(0,K.jsx)(`select`,{value:e??``,onChange:e=>t(Number(e.target.value)),className:`bg-bambu-dark text-white text-base px-4 py-2 rounded border border-bambu-dark-tertiary focus:outline-none focus:border-bambu-green min-w-[180px]`,children:c.length===0?(0,K.jsx)(`option`,{value:``,children:r(`spoolbuddy.status.noPrinters`,`No printers online`)}):c.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,K.jsx)(`div`,{className:`flex items-center`,title:n?r(`spoolbuddy.status.backend`,`Backend`):r(`spoolbuddy.status.offline`,`Offline`),children:n?(0,K.jsx)(`div`,{className:`flex items-end gap-0.5 h-4`,children:[1,2,3,4].map(e=>(0,K.jsx)(`div`,{className:`w-1 rounded-sm ${e<=4?`bg-white`:`bg-bambu-dark-tertiary`}`,style:{height:`${e*4}px`}},e))}):(0,K.jsx)(Au,{className:`w-5 h-5 text-red-400`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full ${n?`bg-bambu-green shadow-[0_0_6px_rgba(34,197,94,0.5)]`:`bg-bambu-gray`}`}),(0,K.jsx)(`span`,{className:`text-sm text-white/50`,children:n?r(`spoolbuddy.status.backend`,`Backend`):r(`spoolbuddy.status.offline`,`Offline`)})]}),(0,K.jsx)(`span`,{className:`text-white/50 text-base font-mono min-w-[50px] text-right`,children:_f(i,l?.time_format||`system`)})]})]})}var nHe=[{to:`/spoolbuddy`,labelKey:`spoolbuddy.nav.dashboard`,fallback:`Dashboard`,icon:(0,K.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6`})})},{to:`/spoolbuddy/ams`,labelKey:`spoolbuddy.nav.ams`,fallback:`AMS`,icon:(0,K.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10`})})},{to:`/spoolbuddy/write-tag`,labelKey:`spoolbuddy.nav.writeTag`,fallback:`Write`,icon:(0,K.jsxs)(`svg`,{className:`w-6 h-6`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,children:[(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0`}),(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})},{to:`/spoolbuddy/inventory`,labelKey:`spoolbuddy.nav.inventory`,fallback:`Inventory`,icon:(0,K.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4`})})},{to:`/spoolbuddy/settings`,labelKey:`spoolbuddy.nav.settings`,fallback:`Settings`,icon:(0,K.jsxs)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:[(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z`}),(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 12a3 3 0 11-6 0 3 3 0 016 0z`})]})}];function rHe(){let{t:e}=G();return(0,K.jsx)(`nav`,{className:`h-14 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-stretch shrink-0`,children:nHe.map(t=>(0,K.jsxs)(xi,{to:t.to,end:t.to===`/spoolbuddy`,className:({isActive:e})=>`flex-1 flex flex-col items-center justify-center gap-1 transition-colors ${e?`text-bambu-green bg-bambu-dark`:`text-white/50 hover:text-white/70 hover:bg-bambu-dark-tertiary`}`,children:[t.icon,(0,K.jsx)(`span`,{className:`text-xs font-medium`,children:e(t.labelKey,t.fallback)})]},t.to))})}function iHe({alert:e}){let{t}=G(),n=e?e.type===`error`?`bg-red-500`:e.type===`warning`?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-green`;return(0,K.jsxs)(`div`,{className:`h-9 bg-bambu-dark-secondary border-t-2 ${e?e.type===`error`?`border-red-500`:e.type===`warning`?`border-amber-500`:`border-bambu-dark-tertiary`:`border-bambu-dark-tertiary`} flex items-center px-3 gap-3 shrink-0`,children:[(0,K.jsx)(`div`,{className:`w-3.5 h-3.5 rounded-full ${n}`}),(0,K.jsx)(`div`,{className:`flex-1 text-sm text-white/50 truncate`,children:e?(0,K.jsx)(`span`,{children:e.message}):(0,K.jsx)(`span`,{className:`text-bambu-green`,children:t(`spoolbuddy.status.systemReady`,`System Ready`)})})]})}function aHe({isOpen:e,onClose:t,deviceId:n,deviceOnline:r}){let{t:i}=G(),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(new Map),{data:d=[]}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters(),enabled:e}),{data:f=[]}=q({queryKey:[`smart-plugs`],queryFn:()=>Q.getSmartPlugs(),enabled:e}),p=d.map(e=>{let t=f.find(t=>t.printer_id===e.id&&t.plug_type!==`mqtt`&&t.enabled);if(!t)return null;let n=l.get(t.id);return{plug:t,printer:e,status:n?{state:n.state,reachable:!0,device_name:null,energy:null}:null,loading:n?.loading??!1}}).filter(Boolean);(0,y.useEffect)(()=>{!e||f.length===0||f.filter(e=>e.printer_id!==null&&e.plug_type!==`mqtt`&&e.enabled).forEach(async e=>{try{let t=await Q.getSmartPlugStatus(e.id);u(n=>{let r=new Map(n);return r.set(e.id,{loading:!1,state:t.state}),r})}catch{u(t=>{let n=new Map(t);return n.set(e.id,{loading:!1,state:null}),n})}})},[e,f]),(0,y.useEffect)(()=>{e||(o(null),c(!1))},[e]);let m=(0,y.useCallback)(async e=>{u(t=>{let n=new Map(t),r=n.get(e.id);return n.set(e.id,{loading:!0,state:r?.state??null}),n});try{await Q.controlSmartPlug(e.id,`toggle`);let t=await Q.getSmartPlugStatus(e.id);u(n=>{let r=new Map(n);return r.set(e.id,{loading:!1,state:t.state}),r})}catch{u(t=>{let n=new Map(t),r=n.get(e.id);return n.set(e.id,{loading:!1,state:r?.state??null}),n})}},[]),h=(0,y.useCallback)(async e=>{if(n){c(!0);try{await nd.systemCommand(n,e),setTimeout(()=>t(),500)}catch{c(!1)}}},[n,t]),g=(0,y.useCallback)(()=>{a&&(a.type===`system`?h(a.command):m(a.plug),o(null))},[a,h,m]);if(!e)return null;let _=e=>e===`ON`||e===`on`;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/50`,onPointerDown:t}),(0,K.jsxs)(`div`,{className:`fixed top-0 left-0 right-0 z-50 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-b-2xl shadow-2xl animate-slide-down`,children:[(0,K.jsx)(`div`,{className:`flex justify-center pt-2 pb-1`,children:(0,K.jsx)(`div`,{className:`w-10 h-1 rounded-full bg-zinc-600`})}),(0,K.jsxs)(`div`,{className:`px-4 pb-4 max-h-[80vh] overflow-y-auto`,children:[p.length>0&&(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`h3`,{className:`text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2`,children:i(`spoolbuddy.quickMenu.printerPower`,`Printer Power`)}),(0,K.jsx)(`div`,{className:`space-y-1`,children:p.map(({plug:e,printer:t,loading:n})=>{let r=l.get(e.id),i=_(r?.state??null);return(0,K.jsxs)(`button`,{onClick:()=>o({type:`plug`,plug:e,printer:t,currentState:r?.state??null}),disabled:n,className:`w-full flex items-center gap-2 px-3 py-1.5 rounded-lg bg-zinc-800/60 hover:bg-zinc-700/60 transition-colors min-h-[36px]`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${i?`bg-green-500`:`bg-zinc-600`}`}),n&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin text-zinc-400 shrink-0`}),(0,K.jsx)(`span`,{className:`flex-1 text-sm text-zinc-200 text-left truncate`,children:t.name}),(0,K.jsx)(`span`,{className:`text-xs font-medium ${i?`text-green-400`:`text-zinc-500`}`,children:r?.state??`—`})]},e.id)})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2`,children:i(`spoolbuddy.quickMenu.systemControls`,`System`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsx)(k9,{icon:(0,K.jsx)(El,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.restartDaemon`,`Restart Daemon`),onClick:()=>o({type:`system`,command:`restart_daemon`}),disabled:!n||!r||s}),(0,K.jsx)(k9,{icon:(0,K.jsx)(tl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.restartBrowser`,`Restart Browser`),onClick:()=>o({type:`system`,command:`restart_browser`}),disabled:!n||!r||s}),(0,K.jsx)(k9,{icon:(0,K.jsx)(El,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.reboot`,`Reboot`),onClick:()=>o({type:`system`,command:`reboot`}),disabled:!n||!r||s,variant:`warning`}),(0,K.jsx)(k9,{icon:(0,K.jsx)(vl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.shutdown`,`Shutdown`),onClick:()=>o({type:`system`,command:`shutdown`}),disabled:!n||!r||s,variant:`danger`})]})]}),(0,K.jsx)(`div`,{className:`flex justify-center mt-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-zinc-600`,children:[(0,K.jsx)(es,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{children:i(`spoolbuddy.quickMenu.swipeToClose`,`Swipe down to close`)})]})})]})]}),a&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/60`,children:(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-2xl p-5 mx-4 max-w-sm w-full border border-zinc-700`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100 mb-2`,children:i(`spoolbuddy.quickMenu.confirmTitle`,`Confirm`)}),(0,K.jsx)(`p`,{className:`text-sm text-zinc-400 mb-5`,children:a.type===`plug`?_(a.currentState)?i(`spoolbuddy.quickMenu.confirmPlugOff`,`Turn off {{name}}?`,{name:a.printer.name}):i(`spoolbuddy.quickMenu.confirmPlugOn`,`Turn on {{name}}?`,{name:a.printer.name}):a.command===`shutdown`?i(`spoolbuddy.quickMenu.confirmShutdown`,`Are you sure you want to shut down the SpoolBuddy? You will need physical access to turn it back on.`):a.command===`reboot`?i(`spoolbuddy.quickMenu.confirmReboot`,`Are you sure you want to reboot the SpoolBuddy?`):a.command===`restart_daemon`?i(`spoolbuddy.quickMenu.confirmRestartDaemon`,`Restart the SpoolBuddy daemon? NFC and scale will be temporarily unavailable.`):i(`spoolbuddy.quickMenu.confirmRestartBrowser`,`Restart the kiosk browser? The display will briefly go blank.`)}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)(`button`,{onClick:()=>o(null),className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:i(`common.cancel`,`Cancel`)}),(0,K.jsx)(`button`,{onClick:g,disabled:s,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium text-white transition-colors min-h-[44px] ${a.type===`plug`?_(a.currentState)?`bg-red-600 hover:bg-red-700`:`bg-green-600 hover:bg-green-700`:a.command===`shutdown`?`bg-red-600 hover:bg-red-700`:a.command===`reboot`?`bg-amber-600 hover:bg-amber-700`:`bg-blue-600 hover:bg-blue-700`} disabled:opacity-50`,children:s?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mx-auto`}):a.type===`plug`?_(a.currentState)?i(`spoolbuddy.quickMenu.turnOff`,`Turn Off`):i(`spoolbuddy.quickMenu.turnOn`,`Turn On`):i(`spoolbuddy.quickMenu.confirm`,`Confirm`)})]})]})})]})}function k9({icon:e,label:t,onClick:n,disabled:r,variant:i=`default`}){return(0,K.jsxs)(`button`,{onClick:n,disabled:r,className:`flex items-center gap-2.5 p-3 rounded-xl transition-colors min-h-[48px] disabled:opacity-40 ${{default:`bg-zinc-800/60 hover:bg-zinc-700/60 text-zinc-300`,warning:`bg-amber-900/30 hover:bg-amber-900/50 text-amber-400`,danger:`bg-red-900/30 hover:bg-red-900/50 text-red-400`}[i]}`,children:[e,(0,K.jsx)(`span`,{className:`text-sm font-medium`,children:t})]})}var oHe={weight:null,weightStable:!1,rawAdc:null,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null,deviceOnline:!1,deviceId:null};function sHe(e,t){switch(t.type){case`WEIGHT_UPDATE`:return{...e,weight:t.weight,weightStable:t.stable,rawAdc:t.rawAdc,deviceId:t.deviceId,deviceOnline:!0};case`TAG_MATCHED`:return{...e,matchedSpool:t.spool,unknownTagUid:null,unknownTrayUuid:null,deviceId:t.deviceId};case`UNKNOWN_TAG`:return{...e,matchedSpool:null,unknownTagUid:t.tagUid,unknownTrayUuid:t.trayUuid??null,deviceId:t.deviceId};case`TAG_REMOVED`:return{...e,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null};case`DEVICE_ONLINE`:return{...e,deviceOnline:!0,deviceId:t.deviceId};case`DEVICE_OFFLINE`:return{...e,deviceOnline:!1,weight:null,weightStable:!1,rawAdc:null};default:return e}}function cHe(){let[e,t]=(0,y.useReducer)(sHe,oHe),n=(0,y.useCallback)(e=>{let n=e.detail;t({type:`WEIGHT_UPDATE`,weight:n.weight_grams??n.data?.weight_grams,stable:n.stable??n.data?.stable??!1,rawAdc:n.raw_adc??n.data?.raw_adc??null,deviceId:n.device_id??n.data?.device_id??``})},[]),r=(0,y.useCallback)(e=>{let n=e.detail,r=n.spool??n.data?.spool;r&&t({type:`TAG_MATCHED`,spool:{id:r.id,tag_uid:n.tag_uid??n.data?.tag_uid??``,material:r.material??``,subtype:r.subtype??null,color_name:r.color_name??null,rgba:r.rgba??null,brand:r.brand??null,label_weight:r.label_weight??0,core_weight:r.core_weight??0,weight_used:r.weight_used??0},deviceId:n.device_id??n.data?.device_id??``})},[]),i=(0,y.useCallback)(e=>{let n=e.detail;t({type:`UNKNOWN_TAG`,tagUid:n.tag_uid??n.data?.tag_uid??``,trayUuid:n.tray_uuid??n.data?.tray_uuid??null,deviceId:n.device_id??n.data?.device_id??``})},[]),a=(0,y.useCallback)(e=>{let n=e.detail;t({type:`TAG_REMOVED`,deviceId:n.device_id??n.data?.device_id??``})},[]),o=(0,y.useCallback)(e=>{let n=e.detail;t({type:`DEVICE_ONLINE`,deviceId:n.device_id??n.data?.device_id??``})},[]),s=(0,y.useCallback)(e=>{let n=e.detail;t({type:`DEVICE_OFFLINE`,deviceId:n.device_id??n.data?.device_id??``})},[]);(0,y.useEffect)(()=>(window.addEventListener(`spoolbuddy-weight`,n),window.addEventListener(`spoolbuddy-tag-matched`,r),window.addEventListener(`spoolbuddy-unknown-tag`,i),window.addEventListener(`spoolbuddy-tag-removed`,a),window.addEventListener(`spoolbuddy-online`,o),window.addEventListener(`spoolbuddy-offline`,s),()=>{window.removeEventListener(`spoolbuddy-weight`,n),window.removeEventListener(`spoolbuddy-tag-matched`,r),window.removeEventListener(`spoolbuddy-unknown-tag`,i),window.removeEventListener(`spoolbuddy-tag-removed`,a),window.removeEventListener(`spoolbuddy-online`,o),window.removeEventListener(`spoolbuddy-offline`,s)}),[n,r,i,a,o,s]);let c=e.matchedSpool?Math.max(0,e.matchedSpool.label_weight-e.matchedSpool.weight_used):null,l=e.weight!==null&&e.matchedSpool?Math.max(0,e.weight-e.matchedSpool.core_weight):null;return{...e,remainingWeight:c,netWeight:l}}var lHe=l(o(((e,t)=>{(function(n,r){typeof e==`object`&&typeof t==`object`?t.exports=r(f()):typeof define==`function`&&define.amd?define([`react`],r):typeof e==`object`?e.ReactSimpleKeyboard=r(f()):n.ReactSimpleKeyboard=r(n.React)})(e,(function(e){return function(){var t={981:function(){typeof Element>`u`||`remove`in Element.prototype||(Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)}),typeof self<`u`&&`document`in self&&((!(`classList`in document.createElement(`_`))||document.createElementNS&&!(`classList`in document.createElementNS(`http://www.w3.org/2000/svg`,`g`)))&&function(e){if(`Element`in e){var t=`classList`,n=`prototype`,r=e.Element[n],i=Object,a=String[n].trim||function(){return this.replace(/^\s+|\s+$/g,``)},o=Array[n].indexOf||function(e){for(var t=0,n=this.length;t1?arguments[1]:void 0)}},7916:function(e,t,n){var r=n(6080),i=n(9565),a=n(8981),o=n(6319),s=n(4209),c=n(3517),l=n(6198),u=n(4659),d=n(4527),f=n(81),p=n(851),m=Array;e.exports=function(e){var t=a(e),n=c(this),h=arguments.length,g=h>1?arguments[1]:void 0,_=g!==void 0;_&&(g=r(g,h>2?arguments[2]:void 0));var v,y,b,x,S,C,w=p(t),T=0;if(!w||this===m&&s(w))for(v=l(t),y=n?new this(v):m(v);v>T;T++)C=_?g(t[T],T):t[T],u(y,T,C);else for(y=n?new this:[],S=(x=f(t,w)).next;!(b=i(S,x)).done;T++)C=_?o(x,g,[b.value,T],!0):b.value,u(y,T,C);return d(y,T),y}},9617:function(e,t,n){var r=n(5397),i=n(5610),a=n(6198),o=function(e){return function(t,n,o){var s=r(t),c=a(s);if(c===0)return!e&&-1;var l,u=i(o,c);if(e&&n!=n){for(;c>u;)if((l=s[u++])!=l)return!0}else for(;c>u;u++)if((e||u in s)&&s[u]===n)return e||u||0;return!e&&-1}};e.exports={includes:o(!0),indexOf:o(!1)}},9213:function(e,t,n){var r=n(6080),i=n(7055),a=n(8981),o=n(6198),s=n(1469),c=n(4659),l=function(e){var t=e===1,n=e===2,l=e===3,u=e===4,d=e===6,f=e===7,p=e===5||d;return function(m,h,g){for(var _,v,y=a(m),b=i(y),x=o(b),S=r(h,g),C=0,w=0,T=t?s(m,x):n||f?s(m,0):void 0;x>C;C++)if((p||C in b)&&(v=S(_=b[C],C,y),e))if(t)c(T,C,v);else if(v)switch(e){case 3:return!0;case 5:return _;case 6:return C;case 2:c(T,w++,_)}else switch(e){case 4:return!1;case 7:c(T,w++,_)}return d?-1:l||u?u:T}};e.exports={forEach:l(0),map:l(1),filter:l(2),some:l(3),every:l(4),find:l(5),findIndex:l(6),filterReject:l(7)}},597:function(e,t,n){var r=n(9039),i=n(8227),a=n(9519),o=i(`species`);e.exports=function(e){return a>=51||!r((function(){var t=[];return(t.constructor={})[o]=function(){return{foo:1}},t[e](Boolean).foo!==1}))}},4598:function(e,t,n){var r=n(9039);e.exports=function(e,t){var n=[][e];return!!n&&r((function(){n.call(null,t||function(){return 1},1)}))}},926:function(e,t,n){var r=n(9306),i=n(8981),a=n(7055),o=n(6198),s=TypeError,c=`Reduce of empty array with no initial value`,l=function(e){return function(t,n,l,u){var d=i(t),f=a(d),p=o(d);if(r(n),p===0&&l<2)throw new s(c);var m=e?p-1:0,h=e?-1:1;if(l<2)for(;;){if(m in f){u=f[m],m+=h;break}if(m+=h,e?m<0:p<=m)throw new s(c)}for(;e?m>=0:p>m;m+=h)m in f&&(u=n(u,f[m],m,d));return u}};e.exports={left:l(!1),right:l(!0)}},4527:function(e,t,n){var r=n(3724),i=n(4376),a=TypeError,o=Object.getOwnPropertyDescriptor;e.exports=r&&!function(){if(this!==void 0)return!0;try{Object.defineProperty([],"length",{writable:!1}).length=1}catch(e){return e instanceof TypeError}}()?function(e,t){if(i(e)&&!o(e,`length`).writable)throw new a(`Cannot set read only .length`);return e.length=t}:function(e,t){return e.length=t}},7680:function(e,t,n){e.exports=n(9504)([].slice)},4488:function(e,t,n){var r=n(7680),i=Math.floor,a=function(e,t){var n=e.length;if(n<8)for(var o,s,c=1;c0;)e[s]=e[--s];s!==c++&&(e[s]=o)}else for(var l=i(n/2),u=a(r(e,0,l),t),d=a(r(e,l),t),f=u.length,p=d.length,m=0,h=0;m9007199254740991)throw t(`Maximum allowed index exceeded`);return e}},7400:function(e){e.exports={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0}},9296:function(e,t,n){var r=n(4055)(`span`).classList,i=r&&r.constructor&&r.constructor.prototype;e.exports=i===Object.prototype?void 0:i},8727:function(e){e.exports=[`constructor`,`hasOwnProperty`,`isPrototypeOf`,`propertyIsEnumerable`,`toLocaleString`,`toString`,`valueOf`]},3709:function(e,t,n){var r=n(2839).match(/firefox\/(\d+)/i);e.exports=!!r&&+r[1]},3763:function(e,t,n){var r=n(2839);e.exports=/MSIE|Trident/.test(r)},6193:function(e,t,n){e.exports=n(4215)===`NODE`},2839:function(e,t,n){var r=n(4576).navigator,i=r&&r.userAgent;e.exports=i?String(i):``},9519:function(e,t,n){var r,i,a=n(4576),o=n(2839),s=a.process,c=a.Deno,l=s&&s.versions||c&&c.version,u=l&&l.v8;u&&(i=(r=u.split(`.`))[0]>0&&r[0]<4?1:+(r[0]+r[1])),!i&&o&&(!(r=o.match(/Edge\/(\d+)/))||r[1]>=74)&&(r=o.match(/Chrome\/(\d+)/))&&(i=+r[1]),e.exports=i},3607:function(e,t,n){var r=n(2839).match(/AppleWebKit\/(\d+)\./);e.exports=!!r&&+r[1]},4215:function(e,t,n){var r=n(4576),i=n(2839),a=n(2195),o=function(e){return i.slice(0,e.length)===e};e.exports=o(`Bun/`)?`BUN`:o(`Cloudflare-Workers`)?`CLOUDFLARE`:o(`Deno/`)?`DENO`:o(`Node.js/`)?`NODE`:r.Bun&&typeof Bun.version==`string`?`BUN`:r.Deno&&typeof Deno.version==`object`?`DENO`:a(r.process)===`process`?`NODE`:r.window&&r.document?`BROWSER`:`REST`},6518:function(e,t,n){var r=n(4576),i=n(7347).f,a=n(6699),o=n(6840),s=n(9433),c=n(7740),l=n(2796);e.exports=function(e,t){var n,u,d,f,p,m=e.target,h=e.global,g=e.stat;if(n=h?r:g?r[m]||s(m,{}):r[m]&&r[m].prototype)for(u in t){if(f=t[u],d=e.dontCallGetSet?(p=i(n,u))&&p.value:n[u],!l(h?u:m+(g?`.`:`#`)+u,e.forced)&&d!==void 0){if(typeof f==typeof d)continue;c(f,d)}(e.sham||d&&d.sham)&&a(f,`sham`,!0),o(n,u,f,e)}}},9039:function(e){e.exports=function(e){try{return!!e()}catch{return!0}}},9228:function(e,t,n){n(7495);var r=n(9565),i=n(6840),a=n(7323),o=n(9039),s=n(8227),c=n(6699),l=s(`species`),u=RegExp.prototype;e.exports=function(e,t,n,d){var f=s(e),p=!o((function(){var t={};return t[f]=function(){return 7},``[e](t)!==7})),m=p&&!o((function(){var t=!1,n=/a/;if(e===`split`){var r={};r[l]=function(){return n},(n={constructor:r,flags:``})[f]=/./[f]}return n.exec=function(){return t=!0,null},n[f](``),!t}));if(!p||!m||n){var h=/./[f],g=t(f,``[e],(function(e,t,n,i,o){var s=t.exec;return s===a||s===u.exec?p&&!o?{done:!0,value:r(h,t,n,i)}:{done:!0,value:r(e,n,t,i)}:{done:!1}}));i(String.prototype,e,g[0]),i(u,f,g[1])}d&&c(u[f],`sham`,!0)}},8745:function(e,t,n){var r=n(616),i=Function.prototype,a=i.apply,o=i.call;e.exports=typeof Reflect==`object`&&Reflect.apply||(r?o.bind(a):function(){return o.apply(a,arguments)})},6080:function(e,t,n){var r=n(7476),i=n(9306),a=n(616),o=r(r.bind);e.exports=function(e,t){return i(e),t===void 0?e:a?o(e,t):function(){return e.apply(t,arguments)}}},616:function(e,t,n){e.exports=!n(9039)((function(){var e=function(){}.bind();return typeof e!=`function`||e.hasOwnProperty(`prototype`)}))},566:function(e,t,n){var r=n(9504),i=n(9306),a=n(34),o=n(9297),s=n(7680),c=n(616),l=Function,u=r([].concat),d=r([].join),f={};e.exports=c?l.bind:function(e){var t=i(this),n=t.prototype,r=s(arguments,1),c=function(){var n=u(r,s(arguments));return this instanceof c?function(e,t,n){if(!o(f,t)){for(var r=[],i=0;i]*>)/g,u=/\$([$&'`]|\d{1,2})/g;e.exports=function(e,t,n,r,d,f){var p=n+e.length,m=r.length,h=u;return d!==void 0&&(d=i(d),h=l),s(f,h,(function(i,s){var l;switch(o(s,0)){case`$`:return`$`;case`&`:return e;case"`":return c(t,0,n);case`'`:return c(t,p);case`<`:l=d[c(s,1,-1)];break;default:var u=+s;if(u===0)return i;if(u>m){var f=a(u/10);return f===0?i:f<=m?r[f-1]===void 0?o(s,1):r[f-1]+o(s,1):i}l=r[u-1]}return l===void 0?``:l}))}},4576:function(e,t,n){var r=function(e){return e&&e.Math===Math&&e};e.exports=r(typeof globalThis==`object`&&globalThis)||r(typeof window==`object`&&window)||r(typeof self==`object`&&self)||r(typeof n.g==`object`&&n.g)||r(typeof this==`object`&&this)||function(){return this}()||Function(`return this`)()},9297:function(e,t,n){var r=n(9504),i=n(8981),a=r({}.hasOwnProperty);e.exports=Object.hasOwn||function(e,t){return a(i(e),t)}},421:function(e){e.exports={}},397:function(e,t,n){e.exports=n(7751)(`document`,`documentElement`)},5917:function(e,t,n){var r=n(3724),i=n(9039),a=n(4055);e.exports=!r&&!i((function(){return Object.defineProperty(a(`div`),"a",{get:function(){return 7}}).a!==7}))},7055:function(e,t,n){var r=n(9504),i=n(9039),a=n(2195),o=Object,s=r(``.split);e.exports=i((function(){return!o(`z`).propertyIsEnumerable(0)}))?function(e){return a(e)===`String`?s(e,``):o(e)}:o},3167:function(e,t,n){var r=n(4901),i=n(34),a=n(2967);e.exports=function(e,t,n){var o,s;return a&&r(o=t.constructor)&&o!==n&&i(s=o.prototype)&&s!==n.prototype&&a(e,s),e}},3706:function(e,t,n){var r=n(9504),i=n(4901),a=n(7629),o=r(Function.toString);i(a.inspectSource)||(a.inspectSource=function(e){return o(e)}),e.exports=a.inspectSource},1181:function(e,t,n){var r,i,a,o=n(8622),s=n(4576),c=n(34),l=n(6699),u=n(9297),d=n(7629),f=n(6119),p=n(421),m=`Object already initialized`,h=s.TypeError,g=s.WeakMap;if(o||d.state){var _=d.state||=new g;_.get=_.get,_.has=_.has,_.set=_.set,r=function(e,t){if(_.has(e))throw new h(m);return t.facade=e,_.set(e,t),t},i=function(e){return _.get(e)||{}},a=function(e){return _.has(e)}}else{var v=f(`state`);p[v]=!0,r=function(e,t){if(u(e,v))throw new h(m);return t.facade=e,l(e,v,t),t},i=function(e){return u(e,v)?e[v]:{}},a=function(e){return u(e,v)}}e.exports={set:r,get:i,has:a,enforce:function(e){return a(e)?i(e):r(e,{})},getterFor:function(e){return function(t){var n;if(!c(t)||(n=i(t)).type!==e)throw new h(`Incompatible receiver, `+e+` required`);return n}}}},4209:function(e,t,n){var r=n(8227),i=n(6269),a=r(`iterator`),o=Array.prototype;e.exports=function(e){return e!==void 0&&(i.Array===e||o[a]===e)}},4376:function(e,t,n){var r=n(2195);e.exports=Array.isArray||function(e){return r(e)===`Array`}},4901:function(e){var t=typeof document==`object`&&document.all;e.exports=t===void 0&&t!==void 0?function(e){return typeof e==`function`||e===t}:function(e){return typeof e==`function`}},3517:function(e,t,n){var r=n(9504),i=n(9039),a=n(4901),o=n(6955),s=n(7751),c=n(3706),l=function(){},u=s(`Reflect`,`construct`),d=/^\s*(?:class|function)\b/,f=r(d.exec),p=!d.test(l),m=function(e){if(!a(e))return!1;try{return u(l,[],e),!0}catch{return!1}},h=function(e){if(!a(e))return!1;switch(o(e)){case`AsyncFunction`:case`GeneratorFunction`:case`AsyncGeneratorFunction`:return!1}try{return p||!!f(d,c(e))}catch{return!0}};h.sham=!0,e.exports=!u||i((function(){var e;return m(m.call)||!m(Object)||!m((function(){e=!0}))||e}))?h:m},2796:function(e,t,n){var r=n(9039),i=n(4901),a=/#|\.prototype\./,o=function(e,t){var n=c[s(e)];return n===u||n!==l&&(i(t)?r(t):!!t)},s=o.normalize=function(e){return String(e).replace(a,`.`).toLowerCase()},c=o.data={},l=o.NATIVE=`N`,u=o.POLYFILL=`P`;e.exports=o},2087:function(e,t,n){var r=n(34),i=Math.floor;e.exports=Number.isInteger||function(e){return!r(e)&&isFinite(e)&&i(e)===e}},4117:function(e){e.exports=function(e){return e==null}},34:function(e,t,n){var r=n(4901);e.exports=function(e){return typeof e==`object`?e!==null:r(e)}},3925:function(e,t,n){var r=n(34);e.exports=function(e){return r(e)||e===null}},6395:function(e){e.exports=!1},5810:function(e,t,n){var r=n(34),i=n(1181).get;e.exports=function(e){if(!r(e))return!1;var t=i(e);return!!t&&t.type===`RawJSON`}},788:function(e,t,n){var r=n(34),i=n(2195),a=n(8227)(`match`);e.exports=function(e){var t;return r(e)&&((t=e[a])===void 0?i(e)===`RegExp`:!!t)}},757:function(e,t,n){var r=n(7751),i=n(4901),a=n(1625),o=n(7040),s=Object;e.exports=o?function(e){return typeof e==`symbol`}:function(e){var t=r(`Symbol`);return i(t)&&a(t.prototype,s(e))}},9539:function(e,t,n){var r=n(9565),i=n(8551),a=n(5966);e.exports=function(e,t,n){var o,s;i(e);try{if(!(o=a(e,`return`))){if(t===`throw`)throw n;return n}o=r(o,e)}catch(e){s=!0,o=e}if(t===`throw`)throw n;if(s)throw o;return i(o),n}},3994:function(e,t,n){var r=n(7657).IteratorPrototype,i=n(2360),a=n(6980),o=n(687),s=n(6269),c=function(){return this};e.exports=function(e,t,n,l){var u=t+` Iterator`;return e.prototype=i(r,{next:a(+!l,n)}),o(e,u,!1,!0),s[u]=c,e}},1088:function(e,t,n){var r=n(6518),i=n(9565),a=n(6395),o=n(350),s=n(4901),c=n(3994),l=n(2787),u=n(2967),d=n(687),f=n(6699),p=n(6840),m=n(8227),h=n(6269),g=n(7657),_=o.PROPER,v=o.CONFIGURABLE,y=g.IteratorPrototype,b=g.BUGGY_SAFARI_ITERATORS,x=m(`iterator`),S=`keys`,C=`values`,w=`entries`,T=function(){return this};e.exports=function(e,t,n,o,m,g,E){c(n,t,o);var D,O,k,A=function(e){if(e===m&&F)return F;if(!b&&e&&e in N)return N[e];switch(e){case S:case C:case w:return function(){return new n(this,e)}}return function(){return new n(this)}},j=t+` Iterator`,M=!1,N=e.prototype,P=N[x]||N[`@@iterator`]||m&&N[m],F=!b&&P||A(m),I=t===`Array`&&N.entries||P;if(I&&(D=l(I.call(new e)))!==Object.prototype&&D.next&&(a||l(D)===y||(u?u(D,y):s(D[x])||p(D,x,T)),d(D,j,!0,!0),a&&(h[j]=T)),_&&m===C&&P&&P.name!==C&&(!a&&v?f(N,`name`,C):(M=!0,F=function(){return i(P,this)})),m)if(O={values:A(C),keys:g?F:A(S),entries:A(w)},E)for(k in O)(b||M||!(k in N))&&p(N,k,O[k]);else r({target:t,proto:!0,forced:b||M},O);return a&&!E||N[x]===F||p(N,x,F,{name:m}),h[t]=F,O}},7657:function(e,t,n){var r,i,a,o=n(9039),s=n(4901),c=n(34),l=n(2360),u=n(2787),d=n(6840),f=n(8227),p=n(6395),m=f(`iterator`),h=!1;[].keys&&(`next`in(a=[].keys())?(i=u(u(a)))!==Object.prototype&&(r=i):h=!0),!c(r)||o((function(){var e={};return r[m].call(e)!==e}))?r={}:p&&(r=l(r)),s(r[m])||d(r,m,(function(){return this})),e.exports={IteratorPrototype:r,BUGGY_SAFARI_ITERATORS:h}},6269:function(e){e.exports={}},6198:function(e,t,n){var r=n(8014);e.exports=function(e){return r(e.length)}},283:function(e,t,n){var r=n(9504),i=n(9039),a=n(4901),o=n(9297),s=n(3724),c=n(350).CONFIGURABLE,l=n(3706),u=n(1181),d=u.enforce,f=u.get,p=String,m=Object.defineProperty,h=r(``.slice),g=r(``.replace),_=r([].join),v=s&&!i((function(){return m((function(){}),`length`,{value:8}).length!==8})),y=String(String).split(`String`),b=e.exports=function(e,t,n){h(p(t),0,7)===`Symbol(`&&(t=`[`+g(p(t),/^Symbol\(([^)]*)\).*$/,`$1`)+`]`),n&&n.getter&&(t=`get `+t),n&&n.setter&&(t=`set `+t),(!o(e,`name`)||c&&e.name!==t)&&(s?m(e,`name`,{value:t,configurable:!0}):e.name=t),v&&n&&o(n,`arity`)&&e.length!==n.arity&&m(e,`length`,{value:n.arity});try{n&&o(n,`constructor`)&&n.constructor?s&&m(e,`prototype`,{writable:!1}):e.prototype&&=void 0}catch{}var r=d(e);return o(r,`source`)||(r.source=_(y,typeof t==`string`?t:``)),e};Function.prototype.toString=b((function(){return a(this)&&f(this).source||l(this)}),`toString`)},741:function(e){var t=Math.ceil,n=Math.floor;e.exports=Math.trunc||function(e){var r=+e;return(r>0?n:t)(r)}},7819:function(e,t,n){e.exports=!n(9039)((function(){var e=`9007199254740993`,t=JSON.rawJSON(e);return!JSON.isRawJSON(t)||JSON.stringify(t)!==e}))},5749:function(e,t,n){var r=n(788),i=TypeError;e.exports=function(e){if(r(e))throw new i(`The method doesn't accept regular expressions`);return e}},4213:function(e,t,n){var r=n(3724),i=n(9504),a=n(9565),o=n(9039),s=n(1072),c=n(3717),l=n(8773),u=n(8981),d=n(7055),f=Object.assign,p=Object.defineProperty,m=i([].concat);e.exports=!f||o((function(){if(r&&f({b:1},f(p({},`a`,{enumerable:!0,get:function(){p(this,`b`,{value:3,enumerable:!1})}}),{b:2})).b!==1)return!0;var e={},t={},n=Symbol(`assign detection`),i=`abcdefghijklmnopqrst`;return e[n]=7,i.split(``).forEach((function(e){t[e]=e})),f({},e)[n]!==7||s(f({},t)).join(``)!==i}))?function(e,t){for(var n=u(e),i=arguments.length,o=1,f=c.f,p=l.f;i>o;)for(var h,g=d(arguments[o++]),_=f?m(s(g),f(g)):s(g),v=_.length,y=0;v>y;)h=_[y++],r&&!a(p,g,h)||(n[h]=g[h]);return n}:f},2360:function(e,t,n){var r,i=n(8551),a=n(6801),o=n(8727),s=n(421),c=n(397),l=n(4055),u=n(6119),d=`prototype`,f=`script`,p=u(`IE_PROTO`),m=function(){},h=function(e){return`<`+f+`>`+e+``},g=function(e){e.write(h(``)),e.close();var t=e.parentWindow.Object;return e=null,t},_=function(){try{r=new ActiveXObject(`htmlfile`)}catch{}var e,t,n;_=typeof document<`u`?document.domain&&r?g(r):(t=l(`iframe`),n=`java`+f+`:`,t.style.display=`none`,c.appendChild(t),t.src=String(n),(e=t.contentWindow.document).open(),e.write(h(`document.F=Object`)),e.close(),e.F):g(r);for(var i=o.length;i--;)delete _[d][o[i]];return _()};s[p]=!0,e.exports=Object.create||function(e,t){var n;return e===null?n=_():(m[d]=i(e),n=new m,m[d]=null,n[p]=e),t===void 0?n:a.f(n,t)}},6801:function(e,t,n){var r=n(3724),i=n(8686),a=n(4913),o=n(8551),s=n(5397),c=n(1072);t.f=r&&!i?Object.defineProperties:function(e,t){o(e);for(var n,r=s(t),i=c(t),l=i.length,u=0;l>u;)a.f(e,n=i[u++],r[n]);return e}},4913:function(e,t,n){var r=n(3724),i=n(5917),a=n(8686),o=n(8551),s=n(6969),c=TypeError,l=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=`enumerable`,f=`configurable`,p=`writable`;t.f=r?a?function(e,t,n){if(o(e),t=s(t),o(n),typeof e==`function`&&t===`prototype`&&`value`in n&&p in n&&!n[p]){var r=u(e,t);r&&r[p]&&(e[t]=n.value,n={configurable:f in n?n[f]:r[f],enumerable:d in n?n[d]:r[d],writable:!1})}return l(e,t,n)}:l:function(e,t,n){if(o(e),t=s(t),o(n),i)try{return l(e,t,n)}catch{}if(`get`in n||`set`in n)throw new c(`Accessors not supported`);return`value`in n&&(e[t]=n.value),e}},7347:function(e,t,n){var r=n(3724),i=n(9565),a=n(8773),o=n(6980),s=n(5397),c=n(6969),l=n(9297),u=n(5917),d=Object.getOwnPropertyDescriptor;t.f=r?d:function(e,t){if(e=s(e),t=c(t),u)try{return d(e,t)}catch{}if(l(e,t))return o(!i(a.f,e,t),e[t])}},298:function(e,t,n){var r=n(2195),i=n(5397),a=n(8480).f,o=n(7680),s=typeof window==`object`&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];e.exports.f=function(e){return s&&r(e)===`Window`?function(e){try{return a(e)}catch{return o(s)}}(e):a(i(e))}},8480:function(e,t,n){var r=n(1828),i=n(8727).concat(`length`,`prototype`);t.f=Object.getOwnPropertyNames||function(e){return r(e,i)}},3717:function(e,t){t.f=Object.getOwnPropertySymbols},2787:function(e,t,n){var r=n(9297),i=n(4901),a=n(8981),o=n(6119),s=n(2211),c=o(`IE_PROTO`),l=Object,u=l.prototype;e.exports=s?l.getPrototypeOf:function(e){var t=a(e);if(r(t,c))return t[c];var n=t.constructor;return i(n)&&t instanceof n?n.prototype:t instanceof l?u:null}},1625:function(e,t,n){e.exports=n(9504)({}.isPrototypeOf)},1828:function(e,t,n){var r=n(9504),i=n(9297),a=n(5397),o=n(9617).indexOf,s=n(421),c=r([].push);e.exports=function(e,t){var n,r=a(e),l=0,u=[];for(n in r)!i(s,n)&&i(r,n)&&c(u,n);for(;t.length>l;)i(r,n=t[l++])&&(~o(u,n)||c(u,n));return u}},1072:function(e,t,n){var r=n(1828),i=n(8727);e.exports=Object.keys||function(e){return r(e,i)}},8773:function(e,t){var n={}.propertyIsEnumerable,r=Object.getOwnPropertyDescriptor;t.f=r&&!n.call({1:2},1)?function(e){var t=r(this,e);return!!t&&t.enumerable}:n},2551:function(e,t,n){var r=n(6395),i=n(4576),a=n(9039),o=n(3607);e.exports=r||!a((function(){if(!(o&&o<535)){var e=Math.random();__defineSetter__.call(null,e,(function(){})),delete i[e]}}))},2967:function(e,t,n){var r=n(6706),i=n(34),a=n(7750),o=n(3506);e.exports=Object.setPrototypeOf||(`__proto__`in{}?function(){var e,t=!1,n={};try{(e=r(Object.prototype,`__proto__`,`set`))(n,[]),t=n instanceof Array}catch{}return function(n,r){return a(n),o(r),i(n)&&(t?e(n,r):n.__proto__=r),n}}():void 0)},3179:function(e,t,n){var r=n(2140),i=n(6955);e.exports=r?{}.toString:function(){return`[object `+i(this)+`]`}},4270:function(e,t,n){var r=n(9565),i=n(4901),a=n(34),o=TypeError;e.exports=function(e,t){var n,s;if(t===`string`&&i(n=e.toString)&&!a(s=r(n,e))||i(n=e.valueOf)&&!a(s=r(n,e))||t!==`string`&&i(n=e.toString)&&!a(s=r(n,e)))return s;throw new o(`Can't convert object to primitive value`)}},5031:function(e,t,n){var r=n(7751),i=n(9504),a=n(8480),o=n(3717),s=n(8551),c=i([].concat);e.exports=r(`Reflect`,`ownKeys`)||function(e){var t=a.f(s(e)),n=o.f;return n?c(t,n(e)):t}},8235:function(e,t,n){var r=n(9504),i=n(9297),a=SyntaxError,o=parseInt,s=String.fromCharCode,c=r(``.charAt),l=r(``.slice),u=r(/./.exec),d={'\\"':`"`,"\\\\":`\\`,"\\/":`/`,"\\b":`\b`,"\\f":`\f`,"\\n":` `,"\\r":`\r`,"\\t":` `},f=/^[\da-f]{4}$/i,p=/^[\u0000-\u001F]$/;e.exports=function(e,t){for(var n=!0,r=``;t0&&(!p.multiline||p.multiline&&v(T,p.lastIndex-1)!==` `)&&(A=`(?: `+A+`)`,M=` `+M,j++),n=RegExp(`^(?:`+A+`)`,k)),w&&(n=RegExp(`^`+A+`$(?!\\s)`,k)),S&&(r=p.lastIndex),i=a(g,O?n:p,M),O?i?(i.input=x(i.input,j),i[0]=x(i[0],j),i.index=p.lastIndex,p.lastIndex+=i[0].length):p.lastIndex=0:S&&i&&(p.lastIndex=p.global?i.index+i[0].length:r),w&&i&&i.length>1&&a(h,i[0],n,(function(){for(o=1;ob)`,`g`);return e.exec(`b`).groups.a!==`b`||`b`.replace(e,`$c`)!==`bc`}))},7750:function(e,t,n){var r=n(4117),i=TypeError;e.exports=function(e){if(r(e))throw new i(`Can't call method on `+e);return e}},7633:function(e,t,n){var r=n(7751),i=n(2106),a=n(8227),o=n(3724),s=a(`species`);e.exports=function(e){var t=r(e);o&&t&&!t[s]&&i(t,s,{configurable:!0,get:function(){return this}})}},687:function(e,t,n){var r=n(4913).f,i=n(9297),a=n(8227)(`toStringTag`);e.exports=function(e,t,n){e&&!n&&(e=e.prototype),e&&!i(e,a)&&r(e,a,{configurable:!0,value:t})}},6119:function(e,t,n){var r=n(5745),i=n(3392),a=r(`keys`);e.exports=function(e){return a[e]||(a[e]=i(e))}},7629:function(e,t,n){var r=n(6395),i=n(4576),a=n(9433),o=`__core-js_shared__`,s=e.exports=i[o]||a(o,{});(s.versions||=[]).push({version:`3.48.0`,mode:r?`pure`:`global`,copyright:`© 2013–2025 Denis Pushkarev (zloirock.ru), 2025–2026 CoreJS Company (core-js.io). All rights reserved.`,license:`https://github.com/zloirock/core-js/blob/v3.48.0/LICENSE`,source:`https://github.com/zloirock/core-js`})},5745:function(e,t,n){var r=n(7629);e.exports=function(e,t){return r[e]||(r[e]=t||{})}},2293:function(e,t,n){var r=n(8551),i=n(5548),a=n(4117),o=n(8227)(`species`);e.exports=function(e,t){var n,s=r(e).constructor;return s===void 0||a(n=r(s)[o])?t:i(n)}},8183:function(e,t,n){var r=n(9504),i=n(1291),a=n(655),o=n(7750),s=r(``.charAt),c=r(``.charCodeAt),l=r(``.slice),u=function(e){return function(t,n){var r,u,d=a(o(t)),f=i(n),p=d.length;return f<0||f>=p?e?``:void 0:(r=c(d,f))<55296||r>56319||f+1===p||(u=c(d,f+1))<56320||u>57343?e?s(d,f):r:e?l(d,f,f+2):u-56320+(r-55296<<10)+65536}};e.exports={codeAt:u(!1),charAt:u(!0)}},706:function(e,t,n){var r=n(350).PROPER,i=n(9039),a=n(7452);e.exports=function(e){return i((function(){return!!a[e]()||`​…᠎`[e]()!==`​…᠎`||r&&a[e].name!==e}))}},3802:function(e,t,n){var r=n(9504),i=n(7750),a=n(655),o=n(7452),s=r(``.replace),c=RegExp(`^[`+o+`]+`),l=RegExp(`(^|[^`+o+`])[`+o+`]+$`),u=function(e){return function(t){var n=a(i(t));return 1&e&&(n=s(n,c,``)),2&e&&(n=s(n,l,`$1`)),n}};e.exports={start:u(1),end:u(2),trim:u(3)}},4495:function(e,t,n){var r=n(9519),i=n(9039),a=n(4576).String;e.exports=!!Object.getOwnPropertySymbols&&!i((function(){var e=Symbol(`symbol detection`);return!a(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&r&&r<41}))},8242:function(e,t,n){var r=n(9565),i=n(7751),a=n(8227),o=n(6840);e.exports=function(){var e=i(`Symbol`),t=e&&e.prototype,n=t&&t.valueOf,s=a(`toPrimitive`);t&&!t[s]&&o(t,s,(function(e){return r(n,this)}),{arity:1})}},1296:function(e,t,n){e.exports=n(4495)&&!!Symbol.for&&!!Symbol.keyFor},1240:function(e,t,n){e.exports=n(9504)(1.1.valueOf)},5610:function(e,t,n){var r=n(1291),i=Math.max,a=Math.min;e.exports=function(e,t){var n=r(e);return n<0?i(n+t,0):a(n,t)}},5397:function(e,t,n){var r=n(7055),i=n(7750);e.exports=function(e){return r(i(e))}},1291:function(e,t,n){var r=n(741);e.exports=function(e){var t=+e;return t!=t||t===0?0:r(t)}},8014:function(e,t,n){var r=n(1291),i=Math.min;e.exports=function(e){var t=r(e);return t>0?i(t,9007199254740991):0}},8981:function(e,t,n){var r=n(7750),i=Object;e.exports=function(e){return i(r(e))}},2777:function(e,t,n){var r=n(9565),i=n(34),a=n(757),o=n(5966),s=n(4270),c=n(8227),l=TypeError,u=c(`toPrimitive`);e.exports=function(e,t){if(!i(e)||a(e))return e;var n,c=o(e,u);if(c){if(t===void 0&&(t=`default`),n=r(c,e,t),!i(n)||a(n))return n;throw new l(`Can't convert object to primitive value`)}return t===void 0&&(t=`number`),s(e,t)}},6969:function(e,t,n){var r=n(2777),i=n(757);e.exports=function(e){var t=r(e,`string`);return i(t)?t:t+``}},2140:function(e,t,n){var r={};r[n(8227)(`toStringTag`)]=`z`,e.exports=String(r)===`[object z]`},655:function(e,t,n){var r=n(6955),i=String;e.exports=function(e){if(r(e)===`Symbol`)throw TypeError(`Cannot convert a Symbol value to a string`);return i(e)}},6823:function(e){var t=String;e.exports=function(e){try{return t(e)}catch{return`Object`}}},3392:function(e,t,n){var r=n(9504),i=0,a=Math.random(),o=r(1.1.toString);e.exports=function(e){return`Symbol(`+(e===void 0?``:e)+`)_`+o(++i+a,36)}},7040:function(e,t,n){e.exports=n(4495)&&!Symbol.sham&&typeof Symbol.iterator==`symbol`},8686:function(e,t,n){var r=n(3724),i=n(9039);e.exports=r&&i((function(){return Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype!==42}))},8622:function(e,t,n){var r=n(4576),i=n(4901),a=r.WeakMap;e.exports=i(a)&&/native code/.test(String(a))},511:function(e,t,n){var r=n(9167),i=n(9297),a=n(1951),o=n(4913).f;e.exports=function(e){var t=r.Symbol||={};i(t,e)||o(t,e,{value:a.f(e)})}},1951:function(e,t,n){t.f=n(8227)},8227:function(e,t,n){var r=n(4576),i=n(5745),a=n(9297),o=n(3392),s=n(4495),c=n(7040),l=r.Symbol,u=i(`wks`),d=c?l.for||l:l&&l.withoutSetter||o;e.exports=function(e){return a(u,e)||(u[e]=s&&a(l,e)?l[e]:d(`Symbol.`+e)),u[e]}},7452:function(e){e.exports=` @@ -8729,5 +8729,5 @@ ${t.slice(l+2)}`,d+=1;else break}t.push({indent:l,number:parseInt(s,10),content: In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}()}function a(e,t){if(e){if(typeof e==`string`)return o(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}function o(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n`u`||`remove`in Element.prototype||(Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)}),typeof self<`u`&&`document`in self&&((!(`classList`in document.createElement(`_`))||document.createElementNS&&!(`classList`in document.createElementNS(`http://www.w3.org/2000/svg`,`g`)))&&function(e){if(`Element`in e){var t=`classList`,n=`prototype`,r=e.Element[n],i=Object,a=String[n].trim||function(){return this.replace(/^\s+|\s+$/g,``)},o=Array[n].indexOf||function(e){for(var t=0,n=this.length;t2&&arguments[2]!==void 0&&arguments[2]?Object.assign({},this.getDefaultDiplay(),t):t||this.getDefaultDiplay())[e]||e}},{key:`getUpdatedInput`,value:function(e,t,n){var r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:n,i=arguments.length>4&&arguments[4]!==void 0&&arguments[4],a=this.getOptions(),o=[n,r,i],s=t;return(e===`{bksp}`||e===`{backspace}`)&&s.length>0?s=this.removeAt.apply(this,[s].concat(o)):(e===`{delete}`||e===`{forwarddelete}`)&&s.length>0?s=this.removeForwardsAt.apply(this,[s].concat(o)):e===`{space}`?s=this.addStringAt.apply(this,[s,` `].concat(o)):e!==`{tab}`||typeof a.tabCharOnTab==`boolean`&&!1===a.tabCharOnTab?e!==`{enter}`&&e!==`{numpadenter}`||!a.newLineOnEnter?e.includes(`numpad`)&&Number.isInteger(Number(e[e.length-2]))?s=this.addStringAt.apply(this,[s,e[e.length-2]].concat(o)):e===`{numpaddivide}`?s=this.addStringAt.apply(this,[s,`/`].concat(o)):e===`{numpadmultiply}`?s=this.addStringAt.apply(this,[s,`*`].concat(o)):e===`{numpadsubtract}`?s=this.addStringAt.apply(this,[s,`-`].concat(o)):e===`{numpadadd}`?s=this.addStringAt.apply(this,[s,`+`].concat(o)):e===`{numpaddecimal}`?s=this.addStringAt.apply(this,[s,`.`].concat(o)):e===`{`||e===`}`?s=this.addStringAt.apply(this,[s,e].concat(o)):e.includes(`{`)||e.includes(`}`)||(s=this.addStringAt.apply(this,[s,e].concat(o))):s=this.addStringAt.apply(this,[s,` `].concat(o)):s=this.addStringAt.apply(this,[s,` `].concat(o)),a.debug&&console.log(`Input will be: `+s),s}},{key:`updateCaretPos`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0&&arguments[1],n=this.updateCaretPosAction(e,t);this.dispatch((function(e){e.setCaretPosition(n)}))}},{key:`updateCaretPosAction`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0&&arguments[1],n=this.getOptions(),r=this.getCaretPosition();return r!=null&&(t?r>0&&(r-=e):r+=e),n.debug&&console.log(`Caret at:`,r),r}},{key:`addStringAt`,value:function(e,t){var n,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:e.length,i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:e.length,a=arguments.length>4&&arguments[4]!==void 0&&arguments[4];return r||r===0?(n=[e.slice(0,r),t,e.slice(i)].join(``),this.isMaxLengthReached()||a&&this.updateCaretPos(t.length)):n=e+t,n}},{key:`removeAt`,value:function(e){var t,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:e.length,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:e.length,i=arguments.length>3&&arguments[3]!==void 0&&arguments[3];if(n===0&&r===0)return e;if(n===r){var a=/([\uD800-\uDBFF][\uDC00-\uDFFF])/g;n&&n>=0?e.substring(n-2,n).match(a)?(t=e.substr(0,n-2)+e.substr(n),i&&this.updateCaretPos(2,!0)):(t=e.substr(0,n-1)+e.substr(n),i&&this.updateCaretPos(1,!0)):e.slice(-2).match(a)?(t=e.slice(0,-2),i&&this.updateCaretPos(2,!0)):(t=e.slice(0,-1),i&&this.updateCaretPos(1,!0))}else t=e.slice(0,n)+e.slice(r),i&&this.dispatch((function(e){e.setCaretPosition(n)}));return t}},{key:`removeForwardsAt`,value:function(e){var t,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:e.length,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:e.length,i=arguments.length>3&&arguments[3]!==void 0&&arguments[3];return e!=null&&e.length&&n!==null?(n===r?t=e.substring(n,n+2).match(/([\uD800-\uDBFF][\uDC00-\uDFFF])/g)?e.substr(0,n)+e.substr(n+2):e.substr(0,n)+e.substr(n+1):(t=e.slice(0,n)+e.slice(r),i&&this.dispatch((function(e){e.setCaretPosition(n)}))),t):e}},{key:`handleMaxLength`,value:function(e,t){var n=this.getOptions(),r=n.maxLength,i=e[n.inputName||`default`],a=t.length-1>=r;if(t.length<=i.length)return!1;if(Number.isInteger(r))return n.debug&&console.log(`maxLength (num) reached:`,a),a?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1);if(s(r)===`object`){var o=t.length-1>=r[n.inputName||`default`];return n.debug&&console.log(`maxLength (obj) reached:`,o),o?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1)}}},{key:`isMaxLengthReached`,value:function(){return!!this.maxLengthReached}},{key:`isTouchDevice`,value:function(){return`ontouchstart`in window||navigator.maxTouchPoints}},{key:`pointerEventsSupported`,value:function(){return!!window.PointerEvent}},{key:`camelCase`,value:function(e){return e?e.toLowerCase().trim().split(/[.\-_\s]/g).reduce((function(e,t){return t.length?e+t[0].toUpperCase()+t.slice(1):e})):``}},{key:`chunkArray`,value:function(e,t){return i(Array(Math.ceil(e.length/t))).map((function(n,r){return e.slice(t*r,t+t*r)}))}},{key:`escapeRegex`,value:function(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,`\\$&`)}},{key:`getRtlOffset`,value:function(e,t){var n=e,r=t.indexOf(`‫`);return r=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw TypeError(`Invalid attempt to iterate non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o,s=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){c=!0,o=e},f:function(){try{s||n.return==null||n.return()}finally{if(c)throw o}}}}(Object.getOwnPropertyNames(e.prototype));try{for(r.s();!(n=r.n()).done;){var i=n.value;i===`constructor`||i===`bindMethods`||(t[i]=t[i].bind(t))}}catch(e){r.e(e)}finally{r.f()}}}],t&&c(e.prototype,t),n&&c(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}();l(d,`noop`,(function(){}));var f=d;function p(e){return p=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},p(e)}function m(e,t){for(var n=0;n1?t?.toLowerCase():t}},{key:`keyCodeToKey`,value:function(e){return{8:`Backspace`,9:`Tab`,13:`Enter`,16:`Shift`,17:`Ctrl`,18:`Alt`,19:`Pause`,20:`CapsLock`,27:`Esc`,32:`Space`,33:`PageUp`,34:`PageDown`,35:`End`,36:`Home`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`,45:`Insert`,46:`Delete`,48:`0`,49:`1`,50:`2`,51:`3`,52:`4`,53:`5`,54:`6`,55:`7`,56:`8`,57:`9`,65:`A`,66:`B`,67:`C`,68:`D`,69:`E`,70:`F`,71:`G`,72:`H`,73:`I`,74:`J`,75:`K`,76:`L`,77:`M`,78:`N`,79:`O`,80:`P`,81:`Q`,82:`R`,83:`S`,84:`T`,85:`U`,86:`V`,87:`W`,88:`X`,89:`Y`,90:`Z`,91:`Meta`,96:`Numpad0`,97:`Numpad1`,98:`Numpad2`,99:`Numpad3`,100:`Numpad4`,101:`Numpad5`,102:`Numpad6`,103:`Numpad7`,104:`Numpad8`,105:`Numpad9`,106:`NumpadMultiply`,107:`NumpadAdd`,109:`NumpadSubtract`,110:`NumpadDecimal`,111:`NumpadDivide`,112:`F1`,113:`F2`,114:`F3`,115:`F4`,116:`F5`,117:`F6`,118:`F7`,119:`F8`,120:`F9`,121:`F10`,122:`F11`,123:`F12`,144:`NumLock`,145:`ScrollLock`,186:`;`,187:`=`,188:`,`,189:`-`,190:`.`,191:`/`,192:"`",219:`[`,220:`\\`,221:`]`,222:`'`}[e]||``}}],t&&m(e.prototype,t),n&&m(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}();function v(e){return v=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},v(e)}function y(e,t){for(var n=0;n0&&arguments[0]!==void 0?arguments[0]:r())},c.appendChild(t)}));var l=a>0,u=document.createElement(`div`);u.classList.add(`hg-candidate-box-prev`),l&&u.classList.add(`hg-candidate-box-btn-active`);var d=function(){l&&n.renderPage({candidateListPages:r,targetElement:i,pageIndex:a-1,nbPages:o,onItemSelected:s})};this.options.useTouchEvents?u.ontouchstart=d:u.onclick=d,this.candidateBoxElement.appendChild(u),this.candidateBoxElement.appendChild(c);var f=ae.length)&&(t=e.length);for(var n=0,r=Array(t);n1&&arguments[1]!==void 0?arguments[1]:e;this.caretPosition=e,this.caretPositionEnd=t}},{key:`getInputCandidates`,value:function(e){var t=this,n=this.options,r=n.layoutCandidates,i=n.layoutCandidatesCaseSensitiveMatch;if(!r||T(r)!==`object`)return{};var a=Object.keys(r).filter((function(n){var r=e.substring(0,t.getCaretPositionEnd()||0)||e,a=RegExp(`${t.utilities.escapeRegex(n)}\$`,i?`g`:`gi`);return!!C(r.matchAll(a)).length}));if(a.length>1){var o=a.sort((function(e,t){return t.length-e.length}))[0];return{candidateKey:o,candidateValue:r[o]}}if(a.length){var s=a[0];return{candidateKey:s,candidateValue:r[s]}}return{}}},{key:`showCandidatesBox`,value:function(e,t,n){var r=this;this.candidateBox&&this.candidateBox.show({candidateValue:t,targetElement:n,onSelect:function(t,n){var i=r.options,a=i.layoutCandidatesCaseSensitiveMatch,o=i.disableCandidateNormalization,s=i.enableLayoutCandidatesKeyPress,c=t;o||(c=t.normalize(`NFD`)),typeof r.options.beforeInputUpdate==`function`&&r.options.beforeInputUpdate(r);var l=r.getInput(r.options.inputName,!0),u=r.getCaretPositionEnd()||0,d=l.substring(0,u||0)||l,f=RegExp(`${r.utilities.escapeRegex(e)}\$`,a?`g`:`gi`),p=d.replace(f,c),m=l.replace(d,p),h=p.length-d.length,g=(u||l.length)+h;g<0&&(g=0),r.setInput(m,r.options.inputName,!0),r.setCaretPosition(g),s&&typeof r.options.onKeyPress==`function`&&r.options.onKeyPress(t,n),typeof r.options.onChange==`function`&&r.options.onChange(r.getInput(r.options.inputName,!0),n),typeof r.options.onChangeAll==`function`&&r.options.onChangeAll(r.getAllInputs(),n)}})}},{key:`handleButtonClicked`,value:function(e,t){var n=this.options,r=n.inputName,i=r===void 0?this.defaultName:r,a=n.debug;if(e!==`{//}`){this.input[i]||(this.input[i]=``),typeof this.options.beforeInputUpdate==`function`&&this.options.beforeInputUpdate(this);var o=this.utilities.getUpdatedInput(e,this.input[i],this.caretPosition,this.caretPositionEnd);if(this.utilities.isStandardButton(e)&&this.activeInputElement&&this.input[i]&&this.input[i]===o&&this.caretPosition===0&&this.caretPositionEnd===o.length)return this.setInput(``,this.options.inputName,!0),this.setCaretPosition(0),this.activeInputElement.value=``,this.activeInputElement.setSelectionRange(0,0),void this.handleButtonClicked(e,t);if(typeof this.options.onKeyPress==`function`&&this.options.onKeyPress(e,t),this.input[i]!==o&&(!this.options.inputPattern||this.options.inputPattern&&this.inputPatternIsValid(o))){if(this.options.maxLength&&this.utilities.handleMaxLength(this.input,o))return;var s=this.utilities.getUpdatedInput(e,this.input[i],this.caretPosition,this.caretPositionEnd,!0);if(this.setInput(s,this.options.inputName,!0),a&&console.log(`Input changed:`,this.getAllInputs()),this.options.debug&&console.log(`Caret at: `,this.getCaretPosition(),this.getCaretPositionEnd(),`(${this.keyboardDOMClass})`,t?.type),this.options.syncInstanceInputs&&this.syncInstanceInputs(),typeof this.options.onChange==`function`&&this.options.onChange(this.getInput(this.options.inputName,!0),t),typeof this.options.onChangeAll==`function`&&this.options.onChangeAll(this.getAllInputs(),t),t!=null&&t.target&&this.options.enableLayoutCandidates){var c,l=this.getInputCandidates(o),u=l.candidateKey,d=l.candidateValue;u&&d?this.showCandidatesBox(u,d,this.keyboardDOM):(c=this.candidateBox)==null||c.destroy()}}this.caretPositionEnd&&this.caretPosition!==this.caretPositionEnd&&(this.setCaretPosition(this.caretPositionEnd,this.caretPositionEnd),this.activeInputElement&&this.activeInputElement.setSelectionRange(this.caretPositionEnd,this.caretPositionEnd),this.options.debug&&console.log(`Caret position aligned`,this.caretPosition)),a&&console.log(`Key pressed:`,e)}}},{key:`getMouseHold`,value:function(){return this.isMouseHold}},{key:`setMouseHold`,value:function(e){this.options.syncInstanceInputs?this.dispatch((function(t){t.isMouseHold=e})):this.isMouseHold=e}},{key:`handleButtonMouseDown`,value:function(e,t){var n=this;t&&(this.options.preventMouseDownDefault&&t.preventDefault(),this.options.stopMouseDownPropagation&&t.stopPropagation(),t.target.classList.add(this.activeButtonClass)),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdTimeout&&clearTimeout(this.holdTimeout),this.setMouseHold(!0),this.options.disableButtonHold||(this.holdTimeout=window.setTimeout((function(){(n.getMouseHold()&&(!e.includes(`{`)&&!e.includes(`}`)||e===`{delete}`||e===`{backspace}`||e===`{bksp}`||e===`{space}`||e===`{tab}`)||e===`{arrowright}`||e===`{arrowleft}`||e===`{arrowup}`||e===`{arrowdown}`)&&(n.options.debug&&console.log(`Button held:`,e),n.handleButtonHold(e)),clearTimeout(n.holdTimeout)}),500))}},{key:`handleButtonMouseUp`,value:function(e,t){var n=this;t&&(this.options.preventMouseUpDefault&&t.preventDefault&&t.preventDefault(),this.options.stopMouseUpPropagation&&t.stopPropagation&&t.stopPropagation(),!(t.target===this.keyboardDOM||t.target&&this.keyboardDOM.contains(t.target)||this.candidateBox&&this.candidateBox.candidateBoxElement&&(t.target===this.candidateBox.candidateBoxElement||t.target&&this.candidateBox.candidateBoxElement.contains(t.target)))&&this.candidateBox&&this.candidateBox.destroy()),this.recurseButtons((function(e){e.classList.remove(n.activeButtonClass)})),this.setMouseHold(!1),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),e&&typeof this.options.onKeyReleased==`function`&&this.options.onKeyReleased(e,t)}},{key:`handleKeyboardContainerMouseDown`,value:function(e){this.options.preventMouseDownDefault&&e.preventDefault()}},{key:`handleButtonHold`,value:function(e){var t=this;this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdInteractionTimeout=window.setTimeout((function(){t.getMouseHold()?(t.handleButtonClicked(e),t.handleButtonHold(e)):clearTimeout(t.holdInteractionTimeout)}),100)}},{key:`syncInstanceInputs`,value:function(){var e=this;this.dispatch((function(t){t.replaceInput(e.input),t.setCaretPosition(e.caretPosition,e.caretPositionEnd)}))}},{key:`clearInput`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName;this.input[e]=``,this.setCaretPosition(0),this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:`getInput`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName,t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return this.options.syncInstanceInputs&&!t&&this.syncInstanceInputs(),this.options.rtl?`‫`+this.input[e].replace(`‫`,``).replace(`‬`,``)+`‬`:this.input[e]}},{key:`getAllInputs`,value:function(){var e=this,t={};return Object.keys(this.input).forEach((function(n){t[n]=e.getInput(n,!0)})),t}},{key:`setInput`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.options.inputName||this.defaultName,n=arguments.length>2?arguments[2]:void 0;this.input[t]=e,!n&&this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:`replaceInput`,value:function(e){this.input=e}},{key:`setOptions`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=this.changedOptions(e);this.options=Object.assign(this.options,e),t.length&&(this.options.debug&&console.log(`changedOptions`,t),this.onSetOptions(t),this.render())}},{key:`changedOptions`,value:function(e){var t=this;return Object.keys(e).filter((function(n){return JSON.stringify(e[n])!==JSON.stringify(t.options[n])}))}},{key:`onSetOptions`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];e.includes(`layoutName`)&&this.candidateBox&&this.candidateBox.destroy(),(e.includes(`layoutCandidatesPageSize`)||e.includes(`layoutCandidates`))&&this.candidateBox&&(this.candidateBox.destroy(),this.candidateBox=new S({utilities:this.utilities,options:this.options}))}},{key:`resetRows`,value:function(){this.keyboardRowsDOM&&this.keyboardRowsDOM.remove(),this.keyboardDOM.className=this.keyboardDOMClass,this.keyboardDOM.setAttribute(`data-skInstance`,this.currentInstanceName),this.buttonElements={}}},{key:`dispatch`,value:function(e){if(!window.SimpleKeyboardInstances)throw console.warn(`SimpleKeyboardInstances is not defined. Dispatch cannot be called.`),Error(`INSTANCES_VAR_ERROR`);return Object.keys(window.SimpleKeyboardInstances).forEach((function(t){e(window.SimpleKeyboardInstances[t],t)}))}},{key:`addButtonTheme`,value:function(e,t){var n=this;t&&e&&(e.split(` `).forEach((function(r){t.split(` `).forEach((function(t){n.options.buttonTheme||(n.options.buttonTheme=[]);var i=!1;n.options.buttonTheme.map((function(e){if(e!=null&&e.class.split(` `).includes(t)){i=!0;var n=e.buttons.split(` `);n.includes(r)||(i=!0,n.push(r),e.buttons=n.join(` `))}return e})),i||n.options.buttonTheme.push({class:t,buttons:e})}))})),this.render())}},{key:`removeButtonTheme`,value:function(e,t){var n=this;if(!e&&!t)return this.options.buttonTheme=[],void this.render();e&&Array.isArray(this.options.buttonTheme)&&this.options.buttonTheme.length&&(e.split(` `).forEach((function(e){var r;(r=n.options)==null||(r=r.buttonTheme)==null||r.map((function(r,i){if(r&&t&&t.includes(r.class)||!t){var a,o=r?.buttons.split(` `).filter((function(t){return t!==e}));r&&o!=null&&o.length?r.buttons=o.join(` `):((a=n.options.buttonTheme)==null||a.splice(i,1),r=null)}return r}))})),this.render())}},{key:`getButtonElement`,value:function(e){var t,n=this.buttonElements[e];return n&&(t=n.length>1?n:n[0]),t}},{key:`inputPatternIsValid`,value:function(e){var t,n=this.options.inputPattern;if((t=n instanceof RegExp?n:n[this.options.inputName||this.defaultName])&&e){var r=t.test(e);return this.options.debug&&console.log(`inputPattern ("${t}"): ${r?`passed`:`did not pass!`}`),r}return!0}},{key:`setEventListeners`,value:function(){if(this.isFirstKeyboardInstance||!this.allKeyboardInstances){this.options.debug&&console.log(`Caret handling started (${this.keyboardDOMClass})`);var e=this.options.physicalKeyboardHighlightPreventDefault,t=e!==void 0&&e;document.addEventListener(`keyup`,this.handleKeyUp,t),document.addEventListener(`keydown`,this.handleKeyDown,t),document.addEventListener(`mouseup`,this.handleMouseUp),document.addEventListener(`touchend`,this.handleTouchEnd),this.options.updateCaretOnSelectionChange&&document.addEventListener(`selectionchange`,this.handleSelectionChange),document.addEventListener(`select`,this.handleSelect)}}},{key:`handleKeyUp`,value:function(e){this.caretEventHandler(e),this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyUp(e)}},{key:`handleKeyDown`,value:function(e){this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyDown(e)}},{key:`handleMouseUp`,value:function(e){this.caretEventHandler(e)}},{key:`handleTouchEnd`,value:function(e){this.caretEventHandler(e)}},{key:`handleSelect`,value:function(e){this.caretEventHandler(e)}},{key:`handleSelectionChange`,value:function(e){navigator.userAgent.includes(`Firefox`)||this.caretEventHandler(e)}},{key:`caretEventHandler`,value:function(e){var t,n=this;e.target.tagName&&(t=e.target.tagName.toLowerCase()),this.dispatch((function(r){var i=e.target===r.keyboardDOM||e.target&&r.keyboardDOM.contains(e.target);if(n.options.syncInstanceInputs&&Array.isArray(e.path)&&(i=e.path.some((function(e){var t;return e==null||(t=e.hasAttribute)==null?void 0:t.call(e,`data-skInstance`)}))),(t===`textarea`||t===`input`&&[`text`,`search`,`url`,`tel`,`password`].includes(e.target.type))&&!r.options.disableCaretPositioning){var a=e.target.selectionStart,o=e.target.selectionEnd;r.options.rtl&&(a=r.utilities.getRtlOffset(a,r.getInput()),o=r.utilities.getRtlOffset(o,r.getInput())),r.setCaretPosition(a,o),r.activeInputElement=e.target,r.options.debug&&console.log(`Caret at: `,r.getCaretPosition(),r.getCaretPositionEnd(),e&&e.target.tagName.toLowerCase(),`(${r.keyboardDOMClass})`,e?.type)}else !r.options.disableCaretPositioning&&i||e?.type===`selectionchange`||(r.setCaretPosition(null),r.activeInputElement=null,r.options.debug&&console.log(`Caret position reset due to "${e?.type}" event`,e))}))}},{key:`recurseButtons`,value:function(e){var t=this;e&&Object.keys(this.buttonElements).forEach((function(n){return t.buttonElements[n].forEach(e)}))}},{key:`destroy`,value:function(){this.options.debug&&console.log(`Destroying simple-keyboard instance: ${this.currentInstanceName}`);var e=this.options.physicalKeyboardHighlightPreventDefault,t=e!==void 0&&e;document.removeEventListener(`keyup`,this.handleKeyUp,t),document.removeEventListener(`keydown`,this.handleKeyDown,t),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`touchend`,this.handleTouchEnd),document.removeEventListener(`select`,this.handleSelect),this.options.updateCaretOnSelectionChange&&document.removeEventListener(`selectionchange`,this.handleSelectionChange),document.onpointerup=null,document.ontouchend=null,document.ontouchcancel=null,document.onmouseup=null,this.recurseButtons((function(e){e&&=(e.onpointerdown=null,e.onpointerup=null,e.onpointercancel=null,e.ontouchstart=null,e.ontouchend=null,e.ontouchcancel=null,e.onclick=null,e.onmousedown=null,e.onmouseup=null,e.remove(),null)})),this.keyboardDOM.onpointerdown=null,this.keyboardDOM.ontouchstart=null,this.keyboardDOM.onmousedown=null,this.resetRows(),this.candidateBox&&=(this.candidateBox.destroy(),null),this.activeInputElement=null,this.keyboardDOM.removeAttribute(`data-skInstance`),this.keyboardDOM.innerHTML=``,window.SimpleKeyboardInstances[this.currentInstanceName]=null,delete window.SimpleKeyboardInstances[this.currentInstanceName],this.initialized=!1}},{key:`getButtonThemeClasses`,value:function(e){var t=this.options.buttonTheme,n=[];return Array.isArray(t)&&t.forEach((function(t){if(t&&t.class&&typeof t.class==`string`&&t.buttons&&typeof t.buttons==`string`){var r=t.class.split(` `);t.buttons.split(` `).includes(e)&&(n=[].concat(C(n),C(r)))}else console.warn(`Incorrect "buttonTheme". Please check the documentation.`,t)})),n}},{key:`setDOMButtonAttributes`,value:function(e,t){var n=this.options.buttonAttributes;Array.isArray(n)&&n.forEach((function(n){n.attribute&&typeof n.attribute==`string`&&n.value&&typeof n.value==`string`?n.buttons&&typeof n.buttons==`string`?n.buttons.split(` `).includes(e)&&t(n.attribute,n.value):t(n.attribute,n.value):console.warn(`Incorrect "buttonAttributes". Please check the documentation.`,n)}))}},{key:`onTouchDeviceDetected`,value:function(){this.processAutoTouchEvents(),this.disableContextualWindow()}},{key:`disableContextualWindow`,value:function(){window.oncontextmenu=function(e){var t;if((t=e.target.classList)!=null&&t.contains(`hg-button`))return e.preventDefault(),e.stopPropagation(),!1}}},{key:`processAutoTouchEvents`,value:function(){this.options.autoUseTouchEvents&&(this.options.useTouchEvents=!0,this.options.debug&&console.log(`autoUseTouchEvents: Touch device detected, useTouchEvents enabled.`))}},{key:`onInit`,value:function(){this.options.debug&&console.log(`${this.keyboardDOMClass} Initialized`),this.setEventListeners(),typeof this.options.onInit==`function`&&this.options.onInit(this)}},{key:`beforeFirstRender`,value:function(){this.utilities.isTouchDevice()&&this.onTouchDeviceDetected(),typeof this.options.beforeFirstRender==`function`&&this.options.beforeFirstRender(this),this.isFirstKeyboardInstance&&this.utilities.pointerEventsSupported()&&!this.options.useTouchEvents&&!this.options.useMouseEvents&&this.options.debug&&console.log(`Using PointerEvents as it is supported by this browser`),this.options.useTouchEvents&&this.options.debug&&console.log(`useTouchEvents has been enabled. Only touch events will be used.`)}},{key:`beforeRender`,value:function(){typeof this.options.beforeRender==`function`&&this.options.beforeRender(this)}},{key:`onRender`,value:function(){typeof this.options.onRender==`function`&&this.options.onRender(this)}},{key:`onModulesLoaded`,value:function(){typeof this.options.onModulesLoaded==`function`&&this.options.onModulesLoaded(this)}},{key:`loadModules`,value:function(){var e=this;Array.isArray(this.options.modules)&&(this.options.modules.forEach((function(t){var n=e.utilities.isConstructor(t)?new t(e):t(e);n.init&&n.init(e)})),this.keyboardPluginClasses=`modules-loaded`,this.render(),this.onModulesLoaded())}},{key:`getModuleProp`,value:function(e,t){return!!this.modules[e]&&this.modules[e][t]}},{key:`getModulesList`,value:function(){return Object.keys(this.modules)}},{key:`parseRowDOMContainers`,value:function(e,t,n,r){var i=this,a=Array.from(e.children),o=0;return a.length&&n.forEach((function(n,s){var c=r[s];if(!(c&&c>n))return!1;var l=n-o,u=c-o,d=document.createElement(`div`);d.className+=`hg-button-container`;var f=`${i.options.layoutName}-r${t}c${s}`;d.setAttribute(`data-skUID`,f);var p=a.splice(l,u-l+1);o+=u-l,p.forEach((function(e){return d.appendChild(e)})),a.splice(l,0,d),e.innerHTML=``,a.forEach((function(t){return e.appendChild(t)})),i.options.debug&&console.log(`rowDOMContainer`,p,l,u,o+1)})),e}},{key:`render`,value:function(){var e=this;this.resetRows(),this.initialized||this.beforeFirstRender(),this.beforeRender();var t=`hg-layout-${this.options.layoutName}`,n=this.options.layout||{default:["` 1 2 3 4 5 6 7 8 9 0 - = {bksp}",`{tab} q w e r t y u i o p [ ] \\`,`{lock} a s d f g h j k l ; ' {enter}`,`{shift} z x c v b n m , . / {shift}`,`.com @ {space}`],shift:[`~ ! @ # $ % ^ & * ( ) _ + {bksp}`,`{tab} Q W E R T Y U I O P { } |`,`{lock} A S D F G H J K L : " {enter}`,`{shift} Z X C V B N M < > ? {shift}`,`.com @ {space}`]},r=this.options.useTouchEvents||!1,i=r?`hg-touch-events`:``,a=this.options.useMouseEvents||!1,o=this.options.disableRowButtonContainers;this.keyboardDOM.className=this.getKeyboardClassString(this.options.theme,t,this.keyboardPluginClasses,i),this.keyboardDOM.setAttribute(`data-skInstance`,this.currentInstanceName),this.keyboardRowsDOM=document.createElement(`div`),this.keyboardRowsDOM.className=`hg-rows`,n[this.options.layoutName||this.defaultName].forEach((function(t,n){var i=t.split(` `);e.options.excludeFromLayout&&e.options.excludeFromLayout[e.options.layoutName||e.defaultName]&&(i=i.filter((function(t){return e.options.excludeFromLayout&&!e.options.excludeFromLayout[e.options.layoutName||e.defaultName].includes(t)})));var s=document.createElement(`div`);s.className+=`hg-row`;var c=[],l=[];i.forEach((function(t,i){var u,d=!o&&typeof t==`string`&&t.length>1&&t.indexOf(`[`)===0,f=!o&&typeof t==`string`&&t.length>1&&t.indexOf(`]`)===t.length-1;d&&(c.push(i),t=t.replace(/\[/g,``)),f&&(l.push(i),t=t.replace(/\]/g,``));var p=e.utilities.getButtonClass(t),m=e.utilities.getButtonDisplayName(t,e.options.display,e.options.mergeDisplay),h=e.options.useButtonTag?`button`:`div`,g=document.createElement(h);g.className+=`hg-button ${p}`,(u=g.classList).add.apply(u,C(e.getButtonThemeClasses(t))),e.setDOMButtonAttributes(t,(function(e,t){g.setAttribute(e,t)})),e.activeButtonClass=`hg-activeButton`,!e.utilities.pointerEventsSupported()||r||a?r?(g.ontouchstart=function(n){e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.ontouchend=function(n){e.handleButtonMouseUp(t,n)},g.ontouchcancel=function(n){e.handleButtonMouseUp(t,n)}):(g.onclick=function(n){e.setMouseHold(!1),typeof e.options.onKeyReleased==`function`||e.options.useMouseEvents&&e.options.clickOnMouseDown||e.handleButtonClicked(t,n)},g.onmousedown=function(n){(typeof e.options.onKeyReleased==`function`||e.options.useMouseEvents&&e.options.clickOnMouseDown)&&!e.isMouseHold&&e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.onmouseup=function(n){e.handleButtonMouseUp(t,n)}):(g.onpointerdown=function(n){e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.onpointerup=function(n){e.handleButtonMouseUp(t,n)},g.onpointercancel=function(n){e.handleButtonMouseUp(t,n)}),g.setAttribute(`data-skBtn`,t);var _=`${e.options.layoutName}-r${n}b${i}`;g.setAttribute(`data-skBtnUID`,_);var v=document.createElement(`span`);v.innerHTML=m,g.appendChild(v),e.buttonElements[t]||(e.buttonElements[t]=[]),e.buttonElements[t].push(g),s.appendChild(g)})),s=e.parseRowDOMContainers(s,n,c,l),e.keyboardRowsDOM.appendChild(s)})),this.keyboardDOM.appendChild(this.keyboardRowsDOM),this.onRender(),this.initialized||(this.initialized=!0,!this.utilities.pointerEventsSupported()||r||a?r?(document.ontouchend=function(t){return e.handleButtonMouseUp(void 0,t)},document.ontouchcancel=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.ontouchstart=function(t){return e.handleKeyboardContainerMouseDown(t)}):r||(document.onmouseup=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.onmousedown=function(t){return e.handleKeyboardContainerMouseDown(t)}):(document.onpointerup=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.onpointerdown=function(t){return e.handleKeyboardContainerMouseDown(t)}),this.onInit())}}],t&&D(e.prototype,t),n&&D(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}(),j=A;return r}()},442:function(t){t.exports=e}},n={};function r(e){var i=n[e];if(i!==void 0)return i.exports;var a=n[e]={exports:{}};return t[e].call(a.exports,a,a.exports,r),a.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){typeof Symbol<`u`&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return function(){r.r(i),r.d(i,{KeyboardReact:function(){return u},default:function(){return d}}),r(981);var e=r(442),t=r(548),n=r.n(t);function a(e){return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t{e?.(t)},[t,e]);let d=(0,y.useCallback)(e=>{if(a.current)return;let t=e.target;if(!t.closest(`[data-vkb="false"]`)){if(t instanceof HTMLInputElement){if(!lHe.has(t.type))return}else if(!(t instanceof HTMLTextAreaElement))return;c.current=t,n(!0),s(`default`),l.current?.setInput?.(c.current.value),setTimeout(()=>{(t.closest(`.bg-zinc-800, .rounded-lg, [data-vkb-group]`)??t).scrollIntoView({behavior:`smooth`,block:`nearest`})},100)}},[]),f=(0,y.useCallback)(()=>{setTimeout(()=>{let e=document.activeElement;e&&(u.current?.contains(e)||e===c.current)||(n(!1),c.current=null)},150)},[]);(0,y.useEffect)(()=>(document.addEventListener(`focusin`,d),document.addEventListener(`focusout`,f),()=>{document.removeEventListener(`focusin`,d),document.removeEventListener(`focusout`,f)}),[d,f]);let p=(0,y.useCallback)(()=>{a.current=!0,i(!0),c.current?.blur(),c.current=null,setTimeout(()=>{n(!1),i(!1),a.current=!1},400)},[]),m=(0,y.useCallback)(e=>{let t=c.current;if(t){if(e===`{shift}`){s(e=>e==="default"?`shift`:`default`);return}if(e===`{lock}`){s(e=>e==="default"?`shift`:`default`);return}if(e===`{close}`){p();return}e===`{bksp}`?A9(t,t.value.slice(0,-1)):e===`{space}`?A9(t,t.value+` `):(A9(t,t.value+e),o===`shift`&&s(`default`)),t.focus(),l.current?.setInput?.(t.value)}},[o,p]);return t?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-[9998] bg-transparent`,onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),r||p()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation(),r||p()},onClick:e=>{e.preventDefault(),e.stopPropagation()}}),!r&&(0,K.jsx)(`div`,{ref:u,className:`relative z-[9999] shrink-0`,onMouseDown:e=>e.preventDefault(),onTouchStart:e=>{e.target.closest(`.hg-button`)||e.preventDefault()},children:(0,K.jsx)(cHe.default,{keyboardRef:e=>{l.current=e},layoutName:o,onKeyPress:m,theme:`simple-keyboard vkb-theme`,layout:{default:[`1 2 3 4 5 6 7 8 9 0 {bksp}`,`q w e r t y u i o p`,`{lock} a s d f g h j k l`,`{shift} z x c v b n m . @`,`{space} {close}`],shift:[`! @ # $ % ^ & * ( ) {bksp}`,`Q W E R T Y U I O P`,`{lock} A S D F G H J K L`,`{shift} Z X C V B N M , _`,`{space} {close}`]},display:{"{bksp}":`⌫`,"{close}":`✕ Close`,"{shift}":`⇧`,"{lock}":`⇪`,"{space}":` `}})})]}):null}function dHe(){qd();let[e,t]=(0,y.useState)(null),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(100),{i18n:o}=G(),s=Yn(),c=Kn(),l=sHe(),{setViewportSuppressed:u}=xd();(0,y.useEffect)(()=>(u(!0),()=>u(!1)),[u]);let{data:d}=q({queryKey:[`settings`],queryFn:Q.getSettings});(0,y.useEffect)(()=>{d?.language&&d.language!==o.language&&o.changeLanguage(d.language)},[d?.language,o]);let{data:f=[]}=q({queryKey:[`spoolbuddy-devices`],queryFn:()=>nd.getDevices(),refetchInterval:3e4}),p=f[0],m=l.deviceOnline||!!p?.online,h=(0,y.useMemo)(()=>({...l,deviceOnline:m}),[l,m]),g=(0,y.useRef)(!1);(0,y.useEffect)(()=>{p&&!g.current&&(a(p.display_brightness),g.current=!0)},[p]),(0,y.useEffect)(()=>{let e=document.documentElement,t=e.classList.contains(`dark`);return e.classList.add(`dark`),()=>{t||e.classList.remove(`dark`)}},[]);let{data:_}=q({queryKey:[`spoolbuddy-update-check`,p?.device_id],queryFn:()=>p?nd.checkDaemonUpdate(p.device_id):Promise.resolve(null),enabled:!!p,refetchInterval:300*1e3,staleTime:0}),v=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!m){let e=`SpoolBuddy device disconnected`;r({type:`warning`,message:e}),v.current=e}else if(_?.update_available&&_.latest_version){let e=`Update available: v${_.latest_version}`;r({type:`info`,message:e}),v.current=e}else v.current&&=(r(null),null)},[m,_?.update_available,_?.latest_version]);let b=!!(l.matchedSpool||l.unknownTagUid||l.unknownTrayUuid),x=(0,y.useRef)(!1);(0,y.useEffect)(()=>{b&&!x.current&&c.pathname!==`/spoolbuddy`&&s(`/spoolbuddy`),x.current=b},[b,c.pathname,s]);let{data:S=[]}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters()}),C=po({queries:S.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),refetchInterval:1e4,select:e=>({connected:e?.connected})}))}),w=(0,y.useMemo)(()=>S.filter((e,t)=>C[t]?.data?.connected),[S,C]),T=(0,y.useRef)(null),E=(0,y.useRef)(!1),D=(0,y.useRef)(null),O=(0,y.useCallback)(e=>{T.current={x:e.touches[0].clientX,y:e.touches[0].clientY},E.current=!1},[]),k=(0,y.useCallback)(n=>{if(!T.current)return;let r=n.changedTouches[0].clientX-T.current.x,i=n.changedTouches[0].clientY-T.current.y,a=T.current.y;if(T.current=null,E.current=!1,i>=50&&Math.abs(i)>Math.abs(r)&&a<120){N(!0);return}if(w.length<2||Math.abs(r)<50||Math.abs(i)>Math.abs(r))return;let o=w.findIndex(t=>t.id===e);t(w[r<0?(o+1)%w.length:(o-1+w.length)%w.length].id)},[w,e,t]);(0,y.useEffect)(()=>{let e=D.current;if(!e)return;let t=e=>{if(!T.current)return;let t=Math.abs(e.touches[0].clientX-T.current.x),n=Math.abs(e.touches[0].clientY-T.current.y);if(E.current){e.preventDefault();return}t>10&&t>n&&(E.current=!0,e.preventDefault())};return e.addEventListener(`touchmove`,t,{passive:!1}),()=>e.removeEventListener(`touchmove`,t)},[]);let[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{ref:D,"data-spoolbuddy-kiosk":!0,className:`w-screen h-screen bg-bambu-dark text-white flex flex-col overflow-hidden`,style:{...i<100?{filter:`brightness(${i/100})`}:void 0,overscrollBehaviorX:`none`},onTouchStart:O,onTouchEnd:k,children:[(0,K.jsx)(`button`,{onClick:()=>N(!0),className:`w-full h-1.5 bg-bambu-dark-secondary flex justify-center items-center shrink-0 touch-none`,"aria-label":`Open quick menu`,children:(0,K.jsx)(`div`,{className:`w-8 h-0.5 rounded-full bg-zinc-600`})}),(0,K.jsx)(eHe,{selectedPrinterId:e,onPrinterChange:t,deviceOnline:m}),(0,K.jsx)(`main`,{className:`flex-1 overflow-y-auto`,children:(0,K.jsx)(Tr,{context:{selectedPrinterId:e,setSelectedPrinterId:t,sbState:h,setAlert:r,displayBrightness:i,setDisplayBrightness:a}})}),!A&&(0,K.jsx)(rHe,{alert:n}),!A&&(0,K.jsx)(nHe,{}),(0,K.jsx)(uHe,{onVisibilityChange:j})]}),(0,K.jsx)(iHe,{isOpen:M,onClose:()=>N(!1),deviceId:p?.device_id??null,deviceOnline:m})]})}function j9({color:e,isEmpty:t,size:n=32}){return t?(0,K.jsx)(`div`,{className:`rounded-full border-2 border-dashed border-zinc-500 flex items-center justify-center`,style:{width:n,height:n},children:(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-zinc-600`})}):(0,K.jsxs)(`svg`,{width:n,height:n,viewBox:`0 0 32 32`,children:[(0,K.jsx)(`circle`,{cx:`16`,cy:`16`,r:`14`,fill:e,stroke:`white`,strokeWidth:`1.5`,strokeOpacity:`0.7`}),(0,K.jsx)(`circle`,{cx:`16`,cy:`16`,r:`11`,fill:e,style:{filter:`brightness(0.85)`}})]})}var fHe=`spoolbuddy-default-core-weight`;function M9(){try{let e=localStorage.getItem(fHe);if(e){let t=parseInt(e,10);if(t>=0&&t<=500)return t}}catch{}return 250}function pHe({spool:e,scaleWeight:t,onClose:n,onSyncWeight:r,onAssignToAms:i,isAssigned:a,onUnassignFromAms:o}){let{t:s}=G(),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(!1),f=Ud(e.rgba),p=e.core_weight&&e.core_weight>0?e.core_weight:M9(),m=t===null?null:Math.round(Math.max(0,t)),h=m===null?null:Math.round(Math.max(0,m-p)),g=Math.round(e.label_weight||1e3),_=h===null?null:Math.min(100,Math.round(h/g*100)),v=_===null?`#808080`:_>50?`#22c55e`:_>20?`#eab308`:`#ef4444`,b=Math.max(0,(e.label_weight||0)-(e.weight_used||0))+p,x=m===null?null:m-b,S=x===null?null:Math.abs(x)<=50,C=async()=>{if(t!==null){l(!0);try{await nd.updateSpoolWeight(e.id,Math.round(t)),d(!0),r?.(),setTimeout(()=>d(!1),3e3)}catch(e){console.error(`Failed to sync weight:`,e)}finally{l(!1)}}};return(0,K.jsxs)(`div`,{className:`flex flex-col items-center space-y-4 max-w-md`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-5`,children:[(0,K.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,K.jsx)(j9,{color:f,isEmpty:!1,size:100}),_!==null&&(0,K.jsxs)(`div`,{className:`absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg`,style:{backgroundColor:v},children:[_,`%`]})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:e.color_name||`Unknown color`}),(0,K.jsxs)(`span`,{className:`text-xs font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,K.jsxs)(`p`,{className:`text-sm text-zinc-400`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]}),h!==null&&(0,K.jsxs)(`div`,{className:`mt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-3xl font-bold font-mono text-zinc-100`,children:[h,`g`]}),(0,K.jsxs)(`span`,{className:`text-sm text-zinc-500`,children:[`/ `,g,`g`]})]}),(0,K.jsx)(`p`,{className:`text-xs text-zinc-500 mt-0.5`,children:s(`spoolbuddy.spool.remaining`,`Remaining`)}),(0,K.jsx)(`div`,{className:`mt-2 max-w-xs`,children:(0,K.jsx)(`div`,{className:`h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${_}%`,backgroundColor:v}})})})]})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.grossWeight`,`Gross weight`)}),(0,K.jsx)(`span`,{className:`font-mono text-zinc-300`,children:m===null?`—`:`${m}g`})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.spool.coreWeight`,`Core`)}),(0,K.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[p,`g`]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.spoolSize`,`Spool size`)}),(0,K.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[g,`g`]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.spool.scaleWeight`,`Scale`)}),m===null?(0,K.jsx)(`span`,{className:`text-zinc-500`,children:`—`}):(0,K.jsxs)(`span`,{className:`flex items-center gap-1 font-mono ${S?`text-green-500`:`text-yellow-500`}`,children:[m,`g`,S?(0,K.jsx)($o,{className:`w-3.5 h-3.5`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(vu,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`button`,{onClick:C,className:`p-1 hover:bg-green-500/20 rounded transition-colors text-green-500`,title:s(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`),children:(0,K.jsx)(Cl,{className:`w-4 h-4`})})]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.tagId`,`Tag`)}),(0,K.jsx)(`span`,{className:`font-mono text-xs text-zinc-400 truncate max-w-[120px]`,title:e.tag_uid||``,children:e.tag_uid?e.tag_uid.slice(-8):`—`})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[i&&(0,K.jsx)(`button`,{onClick:a?void 0:i,disabled:!!a,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px] disabled:opacity-50 disabled:cursor-not-allowed`,children:s(`spoolbuddy.modal.assignToAms`,`Assign to AMS`)}),o&&(0,K.jsxs)(`button`,{onClick:o,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-red-600/20 text-red-400 hover:bg-red-600/30 transition-colors min-h-[44px]`,children:[(0,K.jsx)(xu,{className:`w-4 h-4 inline mr-1`}),s(`inventory.unassignSpool`)]}),(0,K.jsx)(`button`,{onClick:C,disabled:t===null||c,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${u?`bg-green-600/20 text-green-400`:i?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed`:`bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed`}`,children:c?`...`:u?s(`spoolbuddy.dashboard.weightSynced`,`Synced!`):s(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`)}),n&&(0,K.jsx)(`button`,{onClick:n,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:s(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function mHe({tagUid:e,scaleWeight:t,coreWeight:n,onLinkSpool:r,onAddToInventory:i,onClose:a}){let{t:o}=G(),s=n??M9(),c=t===null?null:Math.round(Math.max(0,t)),l=c===null?null:Math.round(Math.max(0,c-s));return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-5`,children:[(0,K.jsx)(`div`,{className:`w-20 h-20 rounded-2xl bg-green-500/15 flex items-center justify-center`,children:(0,K.jsx)(`svg`,{className:`w-10 h-10 text-green-500`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z`})})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:o(`spoolbuddy.dashboard.newTag`,`New Tag Detected`)}),(0,K.jsx)(`p`,{className:`text-sm text-zinc-500 font-mono mt-1`,children:e})]}),c!==null&&(0,K.jsxs)(`div`,{className:`text-sm text-zinc-400`,children:[(0,K.jsxs)(`span`,{className:`font-mono font-semibold`,children:[c,`g`]}),` `,o(`spoolbuddy.dashboard.onScale`,`on scale`),l!==null&&l>0&&(0,K.jsxs)(`span`,{className:`text-zinc-500`,children:[` • ~`,l,`g filament`]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-2 justify-center`,children:[i&&(0,K.jsx)(`button`,{onClick:i,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:o(`spoolbuddy.modal.addToInventory`,`Add to Inventory`)}),r&&(0,K.jsxs)(`button`,{onClick:r,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:[(0,K.jsx)(`svg`,{className:`w-4 h-4 inline-block mr-1.5 -mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1`})}),o(`inventory.assignSpool`,`Assign Spool`)]}),a&&(0,K.jsx)(`button`,{onClick:a,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:o(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function hHe(e){return e?`#${e.slice(0,6)}`:`#808080`}function N9(e){return!e.tray_type||e.tray_type===``}function gHe(e){if(e.tray_type)return null;let t=e.state??null;return t===9||t===10?`physical`:`reset`}function _He(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function vHe({className:e}){return(0,K.jsx)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,K.jsx)(`path`,{d:`M17.8131 0.00538C18.4463 -0.15091 20.3648 3.14642 20.8264 3.84781C25.4187 10.816 35.3089 26.9368 35.9383 34.8694C37.4182 53.5822 11.882 61.3357 2.53721 45.3789C-1.73471 38.0791 0.016 32.2049 3.178 25.0232C6.99221 16.3662 12.6411 7.90372 17.8131 0.00538ZM18.3738 7.24807L17.5881 7.48441C14.4452 12.9431 10.917 18.2341 8.19369 23.9368C4.6808 31.29 1.18317 38.5479 7.69403 45.5657C17.3058 55.9228 34.9847 46.8808 31.4604 32.8681C29.2558 24.0969 22.4207 15.2913 18.3776 7.24807H18.3738Z`,fill:`#C3C2C1`})})}function yHe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 35 53`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`path`,{d:`M17.3165 0.0038C17.932 -0.14959 19.7971 3.08645 20.2458 3.77481C24.7103 10.6135 34.3251 26.4346 34.937 34.2198C36.3757 52.5848 11.5505 60.1942 2.46584 44.534C-1.68714 37.3735 0.0148 31.6085 3.08879 24.5603C6.79681 16.0605 12.2884 7.75907 17.3165 0.0038ZM17.8615 7.11561L17.0977 7.34755C14.0423 12.7048 10.6124 17.8974 7.96483 23.4941C4.54975 30.7107 1.14949 37.8337 7.47908 44.721C16.8233 54.8856 34.01 46.0117 30.5838 32.2595C28.4405 23.6512 21.7957 15.0093 17.8652 7.11561H17.8615Z`,fill:`#C3C2C1`}),(0,K.jsx)(`path`,{d:`M5.03547 30.112C9.64453 30.4936 11.632 35.7985 16.4154 35.791C19.6339 35.7873 20.2161 33.2283 22.3853 31.6197C31.6776 24.7286 33.5835 37.4894 27.9881 44.4254C18.1878 56.5653 -1.16063 44.6013 5.03917 30.1158L5.03547 30.112Z`,fill:`#1F8FEB`})]})}function bHe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`path`,{d:`M17.9625 4.48059L4.77216 26.3154L2.08228 40.2175L10.0224 50.8414H23.1594L33.3246 42.1693V30.2455L17.9625 4.48059Z`,fill:`#1F8FEB`}),(0,K.jsx)(`path`,{d:`M17.7948 0.00538C18.4273 -0.15091 20.3438 3.14642 20.8048 3.84781C25.3921 10.816 35.2715 26.9368 35.9001 34.8694C37.3784 53.5822 11.8702 61.3357 2.53562 45.3789C-1.73163 38.0829 0.0134 32.2087 3.1757 25.027C6.98574 16.3662 12.6284 7.90372 17.7948 0.00538ZM18.3549 7.24807L17.57 7.48441C14.4306 12.9431 10.9063 18.2341 8.1859 23.9368C4.67686 31.29 1.18305 38.5479 7.68679 45.5657C17.2881 55.9228 34.9476 46.8808 31.4271 32.8681C29.2249 24.0969 22.3974 15.2913 18.3587 7.24807H18.3549Z`,fill:`#C3C2C1`})]})}function xHe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`}),(0,K.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2.5`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function SHe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`rect`,{x:`4.5`,y:`8`,width:`3`,height:`4.5`,fill:`#d4a017`,rx:`0.5`}),(0,K.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#d4a017`}),(0,K.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function CHe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`rect`,{x:`4.5`,y:`3`,width:`3`,height:`9.5`,fill:`#c62828`,rx:`0.5`}),(0,K.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#c62828`}),(0,K.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function P9({humidity:e,goodThreshold:t=40,fairThreshold:n=60}){let r,i;return e<=t?(r=`#22a352`,i=vHe):e<=n?(r=`#d4a017`,i=yHe):(r=`#c62828`,i=bHe),(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,K.jsx)(i,{className:`w-3 h-3.5`}),(0,K.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`%`]})]})}function F9({temp:e,goodThreshold:t=28,fairThreshold:n=35}){let r,i;return e<=t?(r=`#22a352`,i=xHe):e<=n?(r=`#d4a017`,i=SHe):(r=`#c62828`,i=CHe),(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,K.jsx)(i,{className:`w-3 h-3.5`}),(0,K.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`°C`]})]})}function I9({side:e}){return(0,K.jsx)(`span`,{className:`inline-flex items-center justify-center w-4 h-4 text-[9px] font-bold rounded`,style:{backgroundColor:`#1a4d2e`,color:`#00ae42`},children:e})}function wHe({tray:e,slotIndex:t,isActive:n,fillOverride:r,spoolmanFill:i,onClick:a}){let o=N9(e),s=gHe(e),c=hHe(e.tray_color),l=e.remain!==null&&e.remain!==void 0&&e.remain>=0?e.remain:null,u=i??(r===0&&l!==null&&l>0?null:r)??l;return(0,K.jsxs)(`div`,{className:`relative flex flex-col items-center p-2.5 rounded-lg transition-all ${n?`ring-2 ring-bambu-green`:``} ${a?`cursor-pointer hover:bg-white/5`:``}`,onClick:a,title:a?`AMS Slot ${t+1}`:void 0,children:[(0,K.jsxs)(`div`,{className:`relative w-16 h-16 mb-1`,children:[o?(0,K.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full bg-gray-600`})}):(0,K.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:c}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:c,style:{filter:`brightness(0.85)`}}),(0,K.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),n&&(0,K.jsx)(`div`,{className:`absolute -bottom-1 left-1/2 -translate-x-1/2 w-2.5 h-2.5 bg-bambu-green rounded-full`})]}),(0,K.jsx)(`span`,{className:`text-sm text-white/70 truncate max-w-full`,title:s===`reset`?`Spool loaded — slot not configured`:void 0,children:o?s===`reset`?`?`:`Empty`:e.tray_type||`Unknown`}),!o&&u!==null&&u>=0&&(0,K.jsx)(`div`,{className:`w-full h-1 bg-bambu-dark-tertiary rounded-full overflow-hidden mt-1`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${u}%`,backgroundColor:RK(u)}})}),(0,K.jsx)(`span`,{className:`absolute top-1 right-1 text-xs text-white/30`,children:t+1})]})}function L9({unit:e,activeSlot:t,onConfigureSlot:n,isDualNozzle:r,nozzleSide:i,thresholds:a,fillOverrides:o,spoolmanFillOverrides:s}){let c=e.tray||[],l=e.is_ams_ht,u=l?1:4;return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-white font-medium text-base`,children:_He(e.id)}),r&&i&&(0,K.jsx)(I9,{side:i})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.temp!=null&&(0,K.jsx)(F9,{temp:e.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair}),e.humidity!=null&&(0,K.jsx)(P9,{humidity:e.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair})]})]}),(0,K.jsx)(`div`,{className:`grid ${l?`grid-cols-1 max-w-[100px] mx-auto`:`grid-cols-4`} gap-2`,children:Array.from({length:u}).map((r,i)=>{let a=c[i]||{id:i,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null};return(0,K.jsx)(wHe,{tray:a,slotIndex:i,isActive:t===i,fillOverride:o?.[`${e.id}-${i}`]??null,spoolmanFill:s?.[`${e.id}-${i}`]??null,onClick:n?()=>n(e.id,i,N9(a)?null:a):void 0},i)})})]})}function R9(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function z9(e){return!e.tray_type||e.tray_type===``}function THe(e){return e?`#${e.slice(0,6)}`:`#808080`}var B9=e=>(e??``).trim().toUpperCase();function EHe(e,t){let n=B9(e),r=B9(t);return!n||!r?`none`:n===r?`exact`:r.includes(n)||n.includes(r)?`partial`:`none`}function DHe(e,t){let n=B9(e),r=B9(t);return!n||!r?!1:n===r}function V9({isOpen:e,onClose:t,spool:n,printerId:r,spoolmanMode:i=!1}){let{t:a}=G(),o=Qa(),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null);(0,y.useEffect)(()=>{e&&(c(null),u(null),f(!1),m(null),g(null))},[e]);let _=(0,y.useCallback)(e=>{e.key===`Escape`&&t()},[t]);(0,y.useEffect)(()=>(e&&document.addEventListener(`keydown`,_),()=>document.removeEventListener(`keydown`,_)),[e,_]);let{data:v}=q({queryKey:[`printerStatus`,r],queryFn:()=>Q.getPrinterStatus(r),enabled:e&&r!==null,refetchInterval:5e3}),{data:b}=q({queryKey:[`printer`,r],queryFn:()=>Q.getPrinter(r),enabled:e&&r!==null}),{data:x}=q({queryKey:[`settings`],queryFn:()=>Q.getSettings(),enabled:e,staleTime:300*1e3}),{data:S}=q({queryKey:[`spool-assignments`,r],queryFn:()=>Q.getAssignments(r),enabled:e&&r!==null,staleTime:30*1e3}),{data:C=[]}=q({queryKey:[`spoolman-slot-assignments`,r],queryFn:()=>Q.getSpoolmanSlotAssignments(r??void 0),enabled:e&&!!i&&r!==null,staleTime:30*1e3}),w=i?C.find(e=>e.spoolman_spool_id===n.id):void 0,T=(0,y.useMemo)(()=>{let e={};if(!S)return e;for(let t of S){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[S]),E=x?{humidityGood:Number(x.ams_humidity_good)||40,humidityFair:Number(x.ams_humidity_fair)||60,tempGood:Number(x.ams_temp_good)||28,tempFair:Number(x.ams_temp_fair)||35}:void 0,D=v?.connected??!1,O=(0,y.useMemo)(()=>v?.ams??[],[v?.ams]),k=(0,y.useMemo)(()=>O.filter(e=>!e.is_ams_ht),[O]),A=(0,y.useMemo)(()=>O.filter(e=>e.is_ams_ht),[O]),j=(0,y.useMemo)(()=>[...v?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[v?.vt_tray]),M=b?.nozzle_count===2||v?.temperatures?.nozzle_2!==void 0,N=(0,y.useRef)({});(0,y.useEffect)(()=>{v?.ams_extruder_map&&Object.keys(v.ams_extruder_map).length>0&&(N.current=v.ams_extruder_map)},[v?.ams_extruder_map]);let P=v?.ams_extruder_map&&Object.keys(v.ams_extruder_map).length>0?v.ams_extruder_map:N.current,F=(0,y.useCallback)(e=>{if(!M)return null;let t=P[String(e)],n=e>=128?e-128:e;return(t===void 0?n:t)===1?`L`:`R`},[M,P]),I=J({mutationFn:async({amsId:e,trayId:t})=>{if(!r)throw Error(`No printer selected`);return i?await Q.assignSpoolmanSlot({spoolman_spool_id:n.id,printer_id:r,ams_id:e,tray_id:t}):await Q.assignSpool({spool_id:n.id,printer_id:r,ams_id:e,tray_id:t})},onSuccess:e=>{u(`success`);let n=e&&`pending_config`in e&&e.pending_config;c(n?a(`spoolbuddy.modal.assignPendingInsert`,`Assigned. Slot will configure when you insert the spool.`):a(`spoolbuddy.modal.assignSuccess`,`Assigned!`)),o.invalidateQueries({queryKey:[`slotPresets`]}),o.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),o.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),setTimeout(()=>t(),n?2500:1500)},onError:e=>{u(`error`),c(e instanceof Error?e.message:a(`spoolbuddy.modal.assignError`,`Failed to assign spool.`))}}),L=I.isPending,R=(0,y.useCallback)((e,t)=>{if(e===254||e===255){let n=e===254?254:254+t;return j.find(e=>(e.id??254)===n)||null}return O.find(t=>t.id===e)?.tray?.find(e=>e.id===t)||null},[O,j]),z=(0,y.useCallback)((e,t)=>e<=3?`${R9(e)} ${a(`ams.slot`,`Slot`)} ${t+1}`:e>=128&&e<=135?R9(e):e===254?a(`printers.extL`,`Ext-L`):M?a(`printers.extR`,`Ext-R`):a(`printers.ext`,`Ext`),[a,M]),B=(0,y.useCallback)((e,t)=>{u(`info`),c(a(`spoolbuddy.modal.assigning`,`Configuring slot...`)),I.mutate({amsId:e,trayId:t})},[I,a]),V=(0,y.useCallback)((e,t)=>{if(!L){if(!x?.disable_filament_warnings){let r=R(e,t);if(r&&!z9(r)){let i=r.tray_sub_brands||r.tray_type||``,a=EHe(n.material,i),o=n.slicer_filament_name||n.slicer_filament,s=r.tray_type||``,c=DHe(o,s);if(a!==`exact`){let r;r=a===`none`&&!c?`material_profile`:a===`partial`&&!c?`partial_profile`:a===`none`?`material`:`partial`;let l=z(e,t);g({amsId:e,trayId:t}),m({type:r,spoolMaterial:n.material||``,trayMaterial:i||``,spoolProfile:o||void 0,trayProfile:s||void 0,location:l}),f(!0);return}}}B(e,t)}},[L,x?.disable_filament_warnings,n,R,z,B]),ee=(0,y.useCallback)(()=>{h&&(f(!1),m(null),B(h.amsId,h.trayId),g(null))},[h,B]),H=(0,y.useMemo)(()=>{let e=[];for(let t of A){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=T[`${t.id}-0`]??null,i=n.remain!=null&&n.remain>=0?n.remain:null,a=r===0&&i!==null&&i>0?null:r;e.push({key:`ht-${t.id}`,label:R9(t.id),amsId:t.id,trayId:0,tray:n,isEmpty:z9(n),nozzleSide:F(t.id),effectiveFill:a??i})}for(let t of j){let n=t.id??254,r=n-254,i=T[`255-${r}`]??null,o=t.remain!=null&&t.remain>=0?t.remain:null,s=i===0&&o!==null&&o>0?null:i;e.push({key:`ext-${n}`,label:M?n===254?a(`printers.extL`,`Ext-L`):a(`printers.extR`,`Ext-R`):a(`printers.ext`,`Ext`),amsId:255,trayId:r,tray:t,isEmpty:z9(t),nozzleSide:M?n===254?`L`:`R`:null,effectiveFill:s??o})}return e},[A,j,M,a,F,T]);return e?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`fixed inset-0 z-[60] bg-bambu-dark flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-zinc-800 shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,K.jsx)(`div`,{className:`w-7 h-7 rounded-full shrink-0`,style:Wd(n.rgba)}),(0,K.jsx)(`div`,{className:`min-w-0`,children:(0,K.jsxs)(`h2`,{className:`text-sm font-semibold text-zinc-100 truncate`,children:[a(`spoolbuddy.modal.assignToAmsTitle`,`Assign to AMS`),(0,K.jsxs)(`span`,{className:`font-normal text-zinc-500 ml-2`,children:[n.color_name||`Unknown`,` • `,n.brand,` `,n.material,n.subtype&&` ${n.subtype}`]}),(0,K.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 ml-2 shrink-0`,children:[`#`,n.id]})]})})]}),(0,K.jsx)(`button`,{onClick:t,disabled:L,className:`p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-800 transition-colors shrink-0 disabled:opacity-50`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),s&&(0,K.jsxs)(`div`,{className:`mx-5 mt-3 p-3 rounded-lg flex items-center gap-3 border shrink-0 ${l===`info`?`bg-blue-500/10 border-blue-500/40`:l===`success`?`bg-green-500/10 border-green-500/40`:`bg-red-500/10 border-red-500/40`}`,children:[l===`info`&&(0,K.jsx)(X,{className:`w-4 h-4 text-blue-400 animate-spin shrink-0`}),l===`success`&&(0,K.jsx)(ls,{className:`w-4 h-4 text-green-400 shrink-0`}),l===`error`&&(0,K.jsx)(ms,{className:`w-4 h-4 text-red-400 shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm ${l===`info`?`text-blue-300`:l===`success`?`text-green-300`:`text-red-300`}`,children:s})]}),(0,K.jsx)(`div`,{className:`flex-1 flex flex-col gap-3 p-4 min-h-0 overflow-y-auto`,children:!D&&r?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,K.jsx)(`div`,{className:`text-center text-white/50`,children:(0,K.jsx)(`p`,{className:`text-lg mb-2`,children:a(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})})}):O.length===0&&j.length===0?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,K.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,K.jsx)(Nc,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,K.jsx)(`p`,{className:`text-lg mb-2`,children:a(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,K.jsx)(`p`,{className:`text-sm`,children:a(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,K.jsxs)(K.Fragment,{children:[k.length>0&&(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3 flex-1 min-h-0`,children:k.map(e=>(0,K.jsx)(L9,{unit:e,activeSlot:w?.ams_id===e.id?w.tray_id??null:null,onConfigureSlot:(t,n)=>V(e.id,n),isDualNozzle:M,nozzleSide:F(e.id),thresholds:E,fillOverrides:T},e.id))}),H.length>0&&(0,K.jsx)(`div`,{className:`flex gap-2 shrink-0`,children:H.map(({key:e,label:t,amsId:n,trayId:r,tray:i,isEmpty:a,nozzleSide:o,effectiveFill:s})=>{let c=THe(i.tray_color);return(0,K.jsxs)(`div`,{onClick:()=>V(n,r),className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-2 ${w&&w.ams_id===n&&w.tray_id===r?`ring-2 ring-bambu-green`:``} ${L?`opacity-50 pointer-events-none`:``}`,children:[(0,K.jsx)(`div`,{className:`relative w-10 h-10 shrink-0`,children:a?(0,K.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,K.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,K.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:c}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:c,style:{filter:`brightness(0.85)`}}),(0,K.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-white/50 font-medium`,children:t}),o&&(0,K.jsx)(I9,{side:o})]}),(0,K.jsx)(`div`,{className:`text-sm text-white/80 truncate`,children:a?`Empty`:i.tray_type||`?`})]}),!a&&s!=null&&s>=0&&(0,K.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden shrink-0 flex flex-col-reverse`,children:(0,K.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${s}%`,backgroundColor:RK(s)}})})]},e)})})]})}),(0,K.jsx)(`div`,{className:`flex justify-end gap-3 px-5 py-3 border-t border-zinc-800 shrink-0`,children:(0,K.jsx)(`button`,{onClick:t,disabled:L,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-800 text-zinc-300 hover:bg-zinc-700 transition-colors min-h-[44px] disabled:opacity-50`,children:l===`success`?a(`spoolbuddy.dashboard.close`,`Close`):a(`spoolbuddy.modal.cancel`,`Cancel`)})})]}),d&&p&&(()=>{let e=``;return p.type===`material`?e=a(`inventory.assignMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location}):p.type===`partial`?e=a(`inventory.assignPartialMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location}):p.type===`material_profile`?e=`${a(`inventory.assignMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location})}\n\n${a(`inventory.assignProfileMismatchMessage`,{spoolProfile:p.spoolProfile||a(`common.unknown`),trayProfile:p.trayProfile||a(`common.unknown`),location:p.location})}`:p.type===`partial_profile`&&(e=`${a(`inventory.assignPartialMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location})}\n\n${a(`inventory.assignProfileMismatchMessage`,{spoolProfile:p.spoolProfile||a(`common.unknown`),trayProfile:p.trayProfile||a(`common.unknown`),location:p.location})}`),e=`${e}\n\n${a(`inventory.assignReconfigureNote`)}`,(0,K.jsx)(Ed,{title:a(`inventory.assignMismatchTitle`),message:e,confirmText:a(`inventory.assignMismatchConfirm`),variant:`warning`,isLoading:I.isPending,onConfirm:ee,onCancel:()=>{I.isPending||(f(!1),g(null),m(null))}})})()]}):null}function OHe({isOpen:e,onClose:t,tagId:n,untaggedSpools:r,onLink:i}){let{t:a}=G(),[o,s]=(0,y.useState)(null),c=(0,y.useCallback)(()=>{s(null),t()},[t]),l=(0,y.useCallback)(e=>{e.key===`Escape`&&c()},[c]);return(0,y.useEffect)(()=>(e&&(document.addEventListener(`keydown`,l),document.body.style.overflow=`hidden`),()=>{document.removeEventListener(`keydown`,l),document.body.style.overflow=``}),[e,l]),e?(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in`,onClick:c,children:(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-xl shadow-2xl w-full max-w-lg mx-4 animate-slide-up`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-zinc-700`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-base font-semibold text-zinc-100`,children:a(`spoolbuddy.dashboard.linkTagTitle`,`Link Tag to Spool`)}),(0,K.jsx)(`p`,{className:`text-sm text-zinc-500 font-mono`,children:n})]}),(0,K.jsx)(`button`,{onClick:c,className:`p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-700 transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`px-5 py-4 space-y-3 max-h-[400px] overflow-y-auto`,children:[(0,K.jsx)(`p`,{className:`text-sm text-zinc-400`,children:a(`spoolbuddy.dashboard.selectSpool`,`Select a spool to link this tag to:`)}),r.length===0?(0,K.jsx)(`div`,{className:`text-center py-8 text-zinc-500`,children:a(`spoolbuddy.dashboard.noUntagged`,`No spools without tags found`)}):(0,K.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>s(e),className:`w-full flex items-center gap-3 p-3 rounded-lg border-2 transition-all text-left ${o?.id===e.id?`border-green-500 bg-green-500/10`:`border-zinc-700 hover:border-green-500/50 hover:bg-zinc-700/50`}`,children:[(0,K.jsx)(j9,{color:Ud(e.rgba),isEmpty:!1,size:40}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`font-medium text-zinc-100 truncate`,children:e.color_name||`Unknown color`}),(0,K.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,K.jsxs)(`div`,{className:`text-sm text-zinc-400 truncate`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]})]}),(0,K.jsxs)(`div`,{className:`text-sm font-mono text-zinc-500`,children:[Math.max(0,e.label_weight-e.weight_used),`g`]})]},e.id))})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 px-5 py-4 border-t border-zinc-700`,children:[(0,K.jsx)(`button`,{onClick:c,className:`px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:a(`common.cancel`,`Cancel`)}),(0,K.jsx)(`button`,{onClick:()=>{o&&(i(o),s(null))},disabled:!o,className:`px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors min-h-[44px]`,children:a(`spoolbuddy.dashboard.linkTag`,`Link Tag`)})]})]})}):null}function H9(e){return e?e.replace(/[^0-9a-f]/gi,``).toUpperCase():``}function kHe(e,t){let n=H9(e),r=H9(t);return!n||!r?!1:n===r?!0:n.endsWith(r)||r.endsWith(n)}var U9=[`#00AE42`,`#FF6B35`,`#3B82F6`,`#EF4444`,`#A855F7`,`#FBBF24`,`#14B8A6`,`#EC4899`,`#F97316`,`#22C55E`];function AHe(){let{t:e}=G(),[t,n]=(0,y.useState)(0);(0,y.useEffect)(()=>{let e=setInterval(()=>{n(e=>(e+1)%U9.length)},5e3);return()=>clearInterval(e)},[]);let r=U9[t];return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,K.jsxs)(`div`,{className:`relative mb-6 flex items-center justify-center`,style:{width:160,height:160},children:[(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:[0,1].map(e=>(0,K.jsx)(`div`,{className:`absolute rounded-full border spoolbuddy-optimized-ping`,style:{width:80,height:80,borderColor:`${r}4D`,transition:`border-color 140ms linear`,animationDelay:`${e*.8}s`}},e))}),(0,K.jsxs)(`div`,{className:`relative overflow-hidden rounded-full`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 rounded-full opacity-30 spoolbuddy-spool-glow`,style:{background:`radial-gradient(circle, ${r} 0%, transparent 70%)`}}),(0,K.jsx)(`div`,{className:`relative`,style:{transition:`opacity 140ms linear`},children:(0,K.jsx)(j9,{color:r,isEmpty:!1,size:100})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xl font-medium text-zinc-300`,children:e(`spoolbuddy.dashboard.readyToScan`,`Ready to scan`)}),(0,K.jsx)(`p`,{className:`text-sm text-zinc-500`,children:e(`spoolbuddy.dashboard.idleMessage`,`Place a spool on the scale to identify it`)})]}),(0,K.jsxs)(`div`,{className:`mt-6 flex items-center gap-2 text-sm text-zinc-600`,children:[(0,K.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`})}),(0,K.jsx)(`span`,{children:e(`spoolbuddy.dashboard.nfcHint`,`NFC tag will be read automatically`)})]})]})}function jHe(){let{t:e}=G();return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,K.jsx)(`div`,{className:`relative mb-6 flex items-center justify-center`,style:{width:160,height:160},children:(0,K.jsx)(`div`,{className:`w-24 h-24 rounded-full bg-zinc-800 flex items-center justify-center`,children:(0,K.jsx)(`svg`,{className:`w-12 h-12 text-zinc-600`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,d:`M18.364 5.636a9 9 0 010 12.728m0 0l-12.728-12.728m12.728 12.728L5.636 5.636m12.728 0a9 9 0 00-12.728 0m0 12.728a9 9 0 010-12.728`})})})}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-lg font-medium text-zinc-500`,children:e(`spoolbuddy.status.deviceOffline`,`Device Offline`)}),(0,K.jsx)(`p`,{className:`text-sm text-zinc-600`,children:e(`spoolbuddy.status.connectDisplay`,`Connect the SpoolBuddy display to scan spools`)})]}),(0,K.jsxs)(`div`,{className:`mt-6 flex items-center gap-2 text-xs text-zinc-600`,children:[(0,K.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M8.111 16.404a5.5 5.5 0 017.778 0M12 20h.01m-7.08-7.071c3.904-3.905 10.236-3.905 14.14 0M1.394 9.393c5.857-5.857 15.355-5.857 21.213 0`})}),(0,K.jsx)(`span`,{children:e(`spoolbuddy.status.waitingConnection`,`Waiting for device connection...`)})]})]})}function MHe(){let{sbState:e,selectedPrinterId:t}=Qn(),{t:n}=G(),{showToast:r}=xd(),{data:i}=q({queryKey:[`spoolman-settings`],queryFn:Q.getSpoolmanSettings,staleTime:300*1e3}),a=i?.spoolman_enabled===`true`&&!!i?.spoolman_url,{data:o=[],refetch:s}=q({queryKey:a?[`spoolman-inventory-spools`]:[`inventory-spools`],queryFn:()=>a?Q.getSpoolmanInventorySpools(!1):Q.getSpools(!1),enabled:i!==void 0}),{data:c=[]}=q({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:a,staleTime:3*1e3,refetchInterval:3*1e3,refetchIntervalInBackground:!1}),{data:l=[]}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters()}),u=po({queries:l.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),refetchInterval:1e4,select:e=>({connected:e?.connected,awaiting_plate_clear:e?.awaiting_plate_clear===!0})}))}),d=l.map((e,t)=>({printer:e,pending:u[t]?.data?.awaiting_plate_clear===!0})).filter(e=>e.pending),f=Qa(),p=J({mutationFn:e=>Q.clearPlate(e),onSuccess:(e,t)=>{f.setQueryData([`printerStatus`,t],e=>e&&{...e,awaiting_plate_clear:!1}),r(n(`spoolbuddy.dashboard.plateClearedToast`,`Plate marked as cleared`),`success`)},onError:()=>{r(n(`spoolbuddy.dashboard.plateClearFailed`,`Could not mark plate as cleared`),`error`)}}),m=J({mutationFn:e=>Q.unassignSpoolmanSlot(e),onSuccess:()=>{f.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),f.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},onError:()=>r(n(`inventory.unassignFailed`,`Failed to unassign spool`),`error`)}),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(null),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(null),M=e.matchedSpool?.tag_uid??e.unknownTagUid??null,N=e.weight,P=e.weightStable,F=(0,y.useRef)(null);N===null?F.current=null:(F.current===null||Math.abs(N-F.current)>=3||P)&&(F.current=N);let I=F.current,L=(0,y.useMemo)(()=>{if(e.matchedSpool?.id){let t=o.find(t=>t.id===e.matchedSpool?.id);if(t)return t}return h&&(o.find(e=>kHe(e.tag_uid,h))||A)||null},[h,e.matchedSpool,o,A]),R=(0,y.useMemo)(()=>{if(L&&!A)return L;let t=e.matchedSpool;return t?{id:t.id,tag_uid:t.tag_uid,material:t.material,subtype:t.subtype,color_name:t.color_name,rgba:t.rgba,brand:t.brand,label_weight:t.label_weight,core_weight:t.core_weight,weight_used:t.weight_used}:null},[L,A,e.matchedSpool]),z=a&&R!=null?c.some(e=>e.spoolman_spool_id===R.id):!1,B=(0,y.useMemo)(()=>a?o.filter(e=>!e.tag_uid&&!e.tray_uuid&&!e.archived_at):o.filter(e=>!e.tag_uid&&!e.archived_at),[o,a]);(0,y.useEffect)(()=>{if(M){let e=b===M;(h!==null&&h!==M||!e&&h!==M)&&(g(M),v(null),x(null),j(null)),!e&&N!==null&&P&&v(Math.round(Math.max(0,N)))}else b&&(g(null),x(null),v(null),j(null))},[M,N,P,h,b]);let V=()=>{x(h)},ee=async t=>{if(h)try{if(a){let i=e.unknownTagUid||void 0,a=!e.unknownTagUid&&e.unknownTrayUuid?e.unknownTrayUuid:void 0;if(!i&&!a){r(n(`spoolman.linkFailed`),`error`);return}let o=await Q.linkTagToSpoolmanSpool(t.id,{tray_uuid:a,tag_uid:i});if(!o){r(n(`spoolman.linkFailed`),`error`);return}let{id:s,material:c,subtype:l,color_name:u,rgba:d,brand:f,label_weight:p,core_weight:m,weight_used:h}=o;j({id:s,material:c,subtype:l,color_name:u,rgba:d,brand:f,label_weight:p,core_weight:m,weight_used:h}),r(n(`spoolman.linkSuccess`),`success`)}else await Q.linkTagToSpool(t.id,{tag_uid:h,tag_type:`generic`,data_origin:`nfc_link`});s()}catch(e){console.error(`Failed to link tag:`,e),r(n(`spoolman.linkFailed`),`error`)}finally{C(!1)}},H=async()=>{if(h){k(!0);try{let t=te??_;if(a){let n=await Q.createSpoolmanInventorySpool({material:`PLA`,subtype:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,brand:null,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,cost_per_kg:null,last_scale_weight:t===null?null:Math.round(t),last_weighed_at:t===null?null:new Date().toISOString(),category:null,low_stock_threshold_pct:null});await Q.linkTagToSpoolmanSpool(n.id,{tag_uid:e.unknownTagUid||void 0,tray_uuid:!e.unknownTagUid&&e.unknownTrayUuid?e.unknownTrayUuid:void 0})}else await Q.createSpool({material:`PLA`,subtype:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,brand:null,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:h,tray_uuid:null,data_origin:`spoolbuddy`,tag_type:`generic`,cost_per_kg:null,last_scale_weight:t===null?null:Math.round(t),last_weighed_at:t===null?null:new Date().toISOString(),category:null,low_stock_threshold_pct:null})}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`Failed to quick-add spool:`,t),r(t||n(`spoolbuddy.errors.quickAddFailed`,`Failed to add spool`),`error`)}finally{D(!1),k(!1),s()}}},te=N!==null&&(M===h||M===null&&h!==null)?N:null,ne=o.length,re=new Set(o.map(e=>e.material)).size,U=new Set(o.filter(e=>e.brand).map(e=>e.brand)).size;return(0,K.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-6 px-4 py-1.5 bg-zinc-800/50 rounded-xl border border-zinc-700/50 mb-3 shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:ne}),(0,K.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.inventory.spools`,`Spools`)})]}),(0,K.jsx)(`div`,{className:`w-px h-5 bg-zinc-700`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:re}),(0,K.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.material`,`Materials`)})]}),(0,K.jsx)(`div`,{className:`w-px h-5 bg-zinc-700`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:U}),(0,K.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.brand`,`Brands`)})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 flex gap-4 min-h-0`,children:[(0,K.jsxs)(`div`,{className:`w-5/12 flex flex-col min-h-0`,children:[(0,K.jsxs)(`div`,{className:`border border-dashed border-zinc-700/50 rounded-xl p-4`,children:[(0,K.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-3`,children:n(`spoolbuddy.dashboard.device`,`Device`)}),(0,K.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full ${e.deviceOnline?`bg-green-500`:`bg-red-500`}`}),(0,K.jsx)(`span`,{className:`text-base text-zinc-400`,children:e.deviceOnline?n(`spoolbuddy.status.online`,`Online`):n(`spoolbuddy.status.offline`,`Disconnected`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`svg`,{className:`w-4 h-4 ${e.deviceOnline?`text-green-500`:`text-zinc-500`}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M3 6l3 1m0 0l-3 9a5.002 5.002 0 006.001 0M6 7l3 9M6 7l6-2m6 2l3-1m-3 1l-3 9a5.002 5.002 0 006.001 0M18 7l3 9m-3-9l-6-2m0-2v2m0 16V5m0 16H9m3 0h3`})}),(0,K.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.scaleWeight`,`Scale`)})]}),(0,K.jsx)(`span`,{className:`text-lg font-mono font-semibold text-zinc-100`,children:I===null?`—`:`${Math.abs(I)<=20?0:Math.round(Math.max(0,I))}g`})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`svg`,{className:`w-4 h-4 ${e.deviceOnline?`text-green-500`:`text-zinc-500`}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z`})}),(0,K.jsx)(`span`,{className:`text-sm text-zinc-500`,children:`NFC`})]}),(0,K.jsx)(`span`,{className:`text-sm font-medium ${M?`text-green-500`:`text-zinc-500`}`,children:M?n(`spoolbuddy.dashboard.tagDetected`,`Tag detected`):n(`spoolbuddy.dashboard.noTag`,`No tag`)})]})]})]}),l.length>0&&(0,K.jsxs)(`div`,{className:`mt-3 border border-dashed border-zinc-700/50 rounded-xl p-4`,children:[(0,K.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-2.5`,children:n(`spoolbuddy.dashboard.printers`,`Printers`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2 overflow-hidden`,children:l.map((e,t)=>{let n=u[t]?.data?.connected??!1;return(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2.5 py-1 bg-zinc-800/50 rounded-lg`,title:`${e.name} — ${n?`Online`:`Offline`}`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${n?`bg-green-500`:`bg-zinc-600`}`}),(0,K.jsx)(`span`,{className:`text-xs text-zinc-400 truncate max-w-[100px]`,children:e.name})]},e.id)})}),d.length>0&&(0,K.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,"data-testid":`plate-clear-section`,"aria-label":n(`spoolbuddy.dashboard.plateReadyLabel`,`Plates ready to clear`),children:d.map(({printer:e})=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>p.mutate(e.id),disabled:p.isPending,"data-testid":`plate-clear-button-${e.id}`,title:n(`spoolbuddy.dashboard.plateReady`,`Plate ready: {{name}}`,{name:e.name}),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-amber-500/10 hover:bg-amber-500/20 active:bg-amber-500/30 border border-amber-500/30 text-amber-200 transition-colors disabled:opacity-60 disabled:cursor-wait`,children:[(0,K.jsxs)(`svg`,{className:`w-3 h-3 shrink-0`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,K.jsx)(`path`,{d:`M12 9v4`}),(0,K.jsx)(`path`,{d:`M12 17h.01`}),(0,K.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`})]}),(0,K.jsx)(`span`,{className:`text-xs truncate max-w-[100px]`,children:e.name}),(0,K.jsx)(`span`,{className:`text-xs opacity-70`,"aria-hidden":`true`,children:`·`}),(0,K.jsx)(`span`,{className:`text-xs font-medium`,children:n(`spoolbuddy.dashboard.plateClearAction`,`Clear`)})]},e.id))})]})]}),(0,K.jsx)(`div`,{className:`w-7/12 min-h-0`,children:(0,K.jsxs)(`div`,{className:`border border-dashed border-zinc-700/50 rounded-xl p-6 h-full flex flex-col`,children:[(0,K.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-4 shrink-0`,children:n(`spoolbuddy.dashboard.currentSpool`,`Current Spool`)}),(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:e.deviceOnline?(L||e.matchedSpool)&&h&&b!==h?(0,K.jsx)(pHe,{spool:(()=>{let t=L??e.matchedSpool;return{id:t.id,tag_uid:h,material:t.material,subtype:t.subtype,color_name:t.color_name,rgba:t.rgba,brand:t.brand,label_weight:t.label_weight,core_weight:t.core_weight,weight_used:t.weight_used}})(),scaleWeight:te??_,onSyncWeight:()=>s(),onAssignToAms:()=>T(!0),isAssigned:z,onUnassignFromAms:z&&L?.id!=null?()=>m.mutate(L.id):void 0,onClose:V}):M&&h&&!L&&!e.matchedSpool&&b!==h?(0,K.jsx)(mHe,{tagUid:h,scaleWeight:te??_,onLinkSpool:B.length>0?()=>C(!0):void 0,onAddToInventory:()=>D(!0),onClose:V}):(0,K.jsx)(AHe,{}):(0,K.jsx)(jHe,{})})]})})]}),R&&!A&&h&&(0,K.jsx)(V9,{isOpen:w,onClose:()=>T(!1),spool:R,printerId:t,spoolmanMode:a}),h&&(0,K.jsx)(OHe,{isOpen:S,onClose:()=>C(!1),tagId:h,untaggedSpools:B,onLink:ee}),E&&h&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,children:(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-2xl p-6 mx-4 max-w-sm w-full border border-zinc-700`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100 mb-3`,children:n(`spoolbuddy.modal.addToInventory`,`Add to Inventory`)}),(0,K.jsxs)(`div`,{className:`flex gap-2.5 p-3 bg-amber-500/10 border border-amber-500/20 rounded-lg mb-4`,children:[(0,K.jsx)(`svg`,{className:`w-5 h-5 text-amber-500 shrink-0 mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`})}),(0,K.jsx)(`p`,{className:`text-sm text-amber-200/80`,children:n(`spoolbuddy.modal.quickAddHint`,`For best results, add the spool in the Bambuddy web interface first (with material, color, brand), then use "Assign Spool" here to assign the NFC tag.`)})]}),(0,K.jsx)(`p`,{className:`text-sm text-zinc-400 mb-1`,children:n(`spoolbuddy.modal.quickAddDesc`,`This will create a basic PLA spool entry with this NFC tag. You can edit the details later in Bambuddy.`)}),(0,K.jsx)(`p`,{className:`text-xs text-zinc-500 font-mono mb-5`,children:h}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)(`button`,{onClick:()=>D(!1),className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:n(`common.cancel`,`Cancel`)}),(0,K.jsx)(`button`,{onClick:H,disabled:O,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-50 transition-colors min-h-[44px]`,children:O?n(`common.saving`,`Saving...`):n(`spoolbuddy.modal.addAnyway`,`Add Anyway`)})]})]})})]})}function W9(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function NHe(e){return e?{O1D:`H2D`,O1E:`H2D Pro`,O2D:`H2D Pro`,O1C:`H2C`,O1C2:`H2C`,O1S:`H2S`,"BL-P001":`X1C`,"BL-P002":`X1`,"BL-P003":`X1E`,N6:`X2D`,N9:`A2L`,C11:`P1S`,C12:`P1P`,C13:`P2S`,N2S:`A1`,N1:`A1 Mini`,X1C:`X1C`,X1:`X1`,X1E:`X1E`,X2D:`X2D`,P1S:`P1S`,P1P:`P1P`,P2S:`P2S`,A1:`A1`,"A1 Mini":`A1 Mini`,A2L:`A2L`,H2D:`H2D`,"H2D Pro":`H2D Pro`,H2C:`H2C`,H2S:`H2S`}[e]||e:``}function G9(e){return!e.tray_type||e.tray_type===``}function PHe(e){return e?`#${e.slice(0,6)}`:`#808080`}function FHe(){let{selectedPrinterId:e,setAlert:t}=Qn(),{t:n}=G(),r=Qa(),{showToast:i}=xd(),{data:a}=q({queryKey:[`printerStatus`,e],queryFn:()=>Q.getPrinterStatus(e),enabled:e!==null,staleTime:30*1e3}),{data:o}=q({queryKey:[`printer`,e],queryFn:()=>Q.getPrinter(e),enabled:e!==null,staleTime:60*1e3}),{data:s}=q({queryKey:[`slotPresets`,e],queryFn:()=>Q.getSlotPresets(e),enabled:e!==null,staleTime:120*1e3}),{data:c}=q({queryKey:[`settings`],queryFn:()=>Q.getSettings(),staleTime:300*1e3}),{data:l}=q({queryKey:[`spoolman-status`],queryFn:Q.getSpoolmanStatus,staleTime:60*1e3}),u=l?.enabled&&l?.connected,{data:d}=q({queryKey:[`linked-spools`],queryFn:Q.getLinkedSpools,enabled:!!u,staleTime:30*1e3}),f=d?.linked,{data:p=[]}=q({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:!!u,staleTime:30*1e3}),{data:m=[]}=q({queryKey:[`spoolman-inventory-spools`],queryFn:()=>Q.getSpoolmanInventorySpools(!1),enabled:!!u,staleTime:30*1e3}),{data:h}=q({queryKey:[`spool-assignments`,e],queryFn:()=>Q.getAssignments(e),enabled:e!==null,staleTime:30*1e3}),g=(0,y.useMemo)(()=>{let e={};if(!h)return e;for(let t of h){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[h]),_=o?.serial_number??``,v=(0,y.useCallback)((t,n,r)=>{if(e!==null&&p.length&&m.length){let r=p.find(r=>r.printer_id===e&&r.ams_id===t&&r.tray_id===n);if(r){let e=m.find(e=>e.id===r.spoolman_spool_id);if(e&&(e.label_weight??0)>0)return Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100)}}if(f&&_){let e=(r?.tray_uuid||r?.tag_uid||VK(_,t,n))?.toUpperCase(),i=zK(e?f[e]:void 0);if(i!==null)return i}return null},[f,_,e,p,m]),b=a?.connected??!1,x=(0,y.useRef)({});(0,y.useEffect)(()=>{e&&a?.ams&&a.ams.length>0&&(x.current[e]=a.ams)},[a?.ams,e]);let S=(0,y.useMemo)(()=>{let t=a?.ams;return t&&t.length>0?t:(e?x.current[e]:null)??[]},[a?.ams,e]),C=(0,y.useMemo)(()=>S.filter(e=>!e.is_ams_ht),[S]),w=(0,y.useMemo)(()=>S.filter(e=>e.is_ams_ht),[S]),T=(0,y.useMemo)(()=>{let e={};if(!f||!_)return e;for(let t of C)for(let n=0;n<(t.tray?.length??0);n++){let r=t.tray[n],i=v(t.id,n,G9(r)?null:r);i!==null&&(e[`${t.id}-${n}`]=i)}return e},[f,_,C,v]),E=(0,y.useRef)(void 0),D=a?.tray_now;D!==void 0&&D!==255?E.current=D:D===255&&(E.current=void 0);let O=D!==void 0&&D!==255?D:E.current,k=o?.nozzle_count===2||a?.temperatures?.nozzle_2!==void 0,A=(0,y.useMemo)(()=>[...a?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[a?.vt_tray]),j=c?{humidityGood:Number(c.ams_humidity_good)||40,humidityFair:Number(c.ams_humidity_fair)||60,tempGood:Number(c.ams_temp_good)||28,tempFair:Number(c.ams_temp_fair)||35}:void 0,M=(0,y.useRef)({});(0,y.useEffect)(()=>{a?.ams_extruder_map&&Object.keys(a.ams_extruder_map).length>0&&(M.current=a.ams_extruder_map)},[a?.ams_extruder_map]);let N=a?.ams_extruder_map&&Object.keys(a.ams_extruder_map).length>0?a.ams_extruder_map:M.current,P=(0,y.useCallback)(e=>{if(!k)return null;let t=N[String(e)],n=e>=128?e-128:e;return(t===void 0?n:t)===1?`L`:`R`},[k,N]),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(null),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)(null),H=(0,y.useCallback)((e,t)=>h?.find(n=>n.ams_id===Number(e)&&n.tray_id===Number(t)),[h]),te=(0,y.useCallback)((e,t,n)=>{if(!f||!_)return;let r=(n?.tray_uuid||n?.tag_uid||VK(_,e,t))?.toUpperCase();return r?f[r]:void 0},[f,_]),ne=J({mutationFn:({printerId:e,amsId:t,trayId:n})=>Q.unassignSpool(e,t,n),onSuccess:()=>{r.invalidateQueries({queryKey:[`spool-assignments`,e]}),r.invalidateQueries({queryKey:[`spool-assignments`]}),i(n(`inventory.unassignSuccess`,`Spool unassigned`),`success`),R(null)}}),re=J({mutationFn:e=>Q.unlinkSpool(e),onSuccess:e=>{i(n(`spoolman.unlinkSuccess`)||e?.message,`success`),r.invalidateQueries({queryKey:[`linked-spools`]}),r.invalidateQueries({queryKey:[`unlinked-spools`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),r.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),R(null)},onError:e=>{i(e.message||n(`spoolman.unlinkFailed`),`error`)}}),U=J({mutationFn:e=>Q.unassignSpoolmanSlot(e),onSuccess:()=>{i(n(`inventory.unassignSuccess`,`Spool unassigned`),`success`),r.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),r.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),r.invalidateQueries({queryKey:[`unlinked-spools`]}),r.invalidateQueries({queryKey:[`linked-spools`]}),R(null)},onError:e=>{i(e.message||n(`inventory.assignFailed`,`Failed to unassign spool`),`error`)}}),ie=(0,y.useCallback)(e=>O===void 0?null:e<=3&&Math.floor(O/4)===e?O%4:e>=128&&e<=135&&O===LK(e,0,!1)?0:null,[O]),ae=(0,y.useCallback)((e,t,n)=>{let r=LK(e,t,!1),i=s?.[r],a=N[String(e)],o=e>=128?e-128:e,c=a===void 0?o:a;R({amsId:e,trayId:t,trayCount:n&&e>=128?1:4,tray:n,trayType:n?.tray_type||void 0,trayColor:n?.tray_color||void 0,traySubBrands:n?.tray_sub_brands||void 0,trayInfoIdx:n?.tray_info_idx||void 0,extruderId:k?c:void 0,caliIdx:n?.cali_idx,savedPresetId:i?.preset_id,location:`${W9(e)} Slot ${t+1}`})},[s,N,k]),W=(0,y.useCallback)(e=>{let t=e.id??254,n=t-254,r=s?.[1020+n];R({amsId:255,trayId:n,trayCount:1,tray:G9(e)?null:e,trayType:e.tray_type||void 0,trayColor:e.tray_color||void 0,traySubBrands:e.tray_sub_brands||void 0,trayInfoIdx:e.tray_info_idx||void 0,extruderId:k?+(t===254):void 0,caliIdx:e.cali_idx,savedPresetId:r?.preset_id,location:k?t===254?`Ext-L`:`Ext-R`:`External`})},[s,k]),oe=(0,y.useCallback)(()=>{if(!L)return;let{tray:e,location:t,...n}=L;R(null),I(n)},[L]),se=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n,trayType:r,trayColor:i,location:a}=L;R(null),B({printerId:e,amsId:t,trayId:n,trayInfo:{type:r||``,material:r,color:i?.slice(0,6)||``,location:a}})},[L,e]),ce=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n,tray:r}=L,i=(r?.tray_uuid||r?.tag_uid||VK(_,t,n))?.toUpperCase()||``;R(null),ee({tagUid:r?.tag_uid||i,trayUuid:r?.tray_uuid||``,printerId:e,amsId:t,trayId:n})},[L,e,_]),le=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n}=L;ne.mutate({printerId:e,amsId:t,trayId:n})},[L,e,ne]);(0,y.useEffect)(()=>{if(!b&&e){t({type:`warning`,message:n(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)});return}for(let e of S){let n=e.tray||[];for(let r=0;r=0&&i.remain<15&&i.tray_type){let n=e.id===254||e.id===255,a=!n&&e.id>=128,o=IK(e.id,r,a,n);t({type:`warning`,message:`Low Filament: ${i.tray_type} (${o}) - ${i.remain}% remaining`});return}}}t(null)},[S,b,e,t,n]);let ue=(0,y.useMemo)(()=>{let e=[];for(let t of w){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=v(t.id,0,G9(n)?null:n),i=g[`${t.id}-0`]??null,a=n.remain!=null&&n.remain>=0?n.remain:null,o=i===0&&a!==null&&a>0?null:i;e.push({key:`ht-${t.id}`,label:W9(t.id),tray:n,isEmpty:G9(n),isActive:ie(t.id)===0,temp:t.temp,humidity:t.humidity,nozzleSide:P(t.id),effectiveFill:r??o??a,onClick:()=>ae(t.id,0,G9(n)?null:n)})}for(let t of A){let r=t.id??254,i=k&&O===254?r===254&&a?.active_extruder===1||r===255&&a?.active_extruder===0:O===r,o=r-254,s=v(255,o,G9(t)?null:t),c=g[`255-${o}`]??null,l=t.remain!=null&&t.remain>=0?t.remain:null,u=c===0&&l!==null&&l>0?null:c;e.push({key:`ext-${r}`,label:k?r===254?n(`printers.extL`,`Ext-L`):n(`printers.extR`,`Ext-R`):n(`printers.ext`,`Ext`),tray:t,isEmpty:G9(t),isActive:i,nozzleSide:null,effectiveFill:s??u??l,onClick:()=>W(t)})}return e},[w,A,k,O,a?.active_extruder,n,ie,P,ae,W,g,v]);return(0,K.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,K.jsx)(`div`,{className:`flex-1 min-h-0`,children:e?b?S.length===0&&A.length===0?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,K.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,K.jsx)(Nc,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,K.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,K.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,K.jsxs)(`div`,{className:`flex flex-col gap-3 h-full`,children:[(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:C.map(e=>(0,K.jsx)(L9,{unit:e,activeSlot:ie(e.id),onConfigureSlot:ae,isDualNozzle:k,nozzleSide:P(e.id),thresholds:j,fillOverrides:g,spoolmanFillOverrides:T},e.id))}),ue.length>0&&(0,K.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-3`,children:ue.map(({key:e,label:t,tray:n,isEmpty:r,isActive:i,temp:a,humidity:o,nozzleSide:s,effectiveFill:c,onClick:l})=>{let u=PHe(n.tray_color);return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-3 ${i?`ring-2 ring-bambu-green`:``}`,onClick:l,children:[(0,K.jsxs)(`div`,{className:`relative w-10 h-10 flex-shrink-0`,children:[r?(0,K.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,K.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,K.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:u}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:u,style:{filter:`brightness(0.85)`}}),(0,K.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),i&&(0,K.jsx)(`div`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1.5 h-1.5 bg-bambu-green rounded-full`})]}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-white/50 font-medium truncate`,children:t}),s&&(0,K.jsx)(I9,{side:s})]}),(0,K.jsx)(`div`,{className:`text-sm text-white/80 truncate`,children:r?`Empty`:n.tray_type||`?`}),(a!=null||o!=null)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[a!=null&&(0,K.jsx)(F9,{temp:a,goodThreshold:j?.tempGood,fairThreshold:j?.tempFair}),o!=null&&(0,K.jsx)(P9,{humidity:o,goodThreshold:j?.humidityGood,fairThreshold:j?.humidityFair})]})]}),!r&&c!=null&&c>=0&&(0,K.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0 flex flex-col-reverse`,children:(0,K.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${c}%`,backgroundColor:RK(c)}})})]},e)})})]}):(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,K.jsx)(`div`,{className:`text-center text-white/50`,children:(0,K.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})})}):(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,K.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,K.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.noPrinter`,`No printer selected`)}),(0,K.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.ams.selectPrinter`,`Select a printer from the top bar`)})]})})}),F&&e&&(0,K.jsx)(DK,{isOpen:!!F,onClose:()=>I(null),printerId:e,slotInfo:F,printerModel:NHe(o?.model??null)||void 0,fullScreen:!0,onSuccess:()=>{r.invalidateQueries({queryKey:[`slotPresets`,e]}),r.invalidateQueries({queryKey:[`printerStatus`,e]})}}),L&&e&&(()=>{let t=H(L.amsId,L.trayId),r=te(L.amsId,L.trayId,L.tray),i=u?p.find(t=>t.printer_id===e&&t.ams_id===L.amsId&&t.tray_id===L.trayId):void 0,a=i?m.find(e=>e.id===i.spoolman_spool_id)??null:null;return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:()=>R(null)}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-sm mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl`,children:[(0,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:[L.trayColor&&(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${L.trayColor.slice(0,6)}`}}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:L.location}),L.traySubBrands&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,L.traySubBrands,`)`]})]}),(0,K.jsx)(`button`,{onClick:()=>R(null),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-2`,children:[!u&&t?.spool&&(0,K.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`inventory.assignedSpool`,`Assigned spool`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.spool.rgba&&(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:Wd(t.spool.rgba)}),(0,K.jsxs)(`span`,{className:`text-sm text-white`,children:[t.spool.brand?`${t.spool.brand} `:``,t.spool.material,t.spool.color_name?` - ${t.spool.color_name}`:``]}),(0,K.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0 ml-auto`,children:[`#`,t.spool.id]})]})]}),u&&r&&!a&&(0,K.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`spoolman.linkedSpool`,`Linked spool`)}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,K.jsxs)(`span`,{className:`text-sm text-white`,children:[`Spoolman #`,r.id,r.remaining_weight==null?``:` (${Math.round(r.remaining_weight)}g)`]})})]}),u&&a&&(0,K.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`inventory.assignedSpool`,`Assigned spool`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a.rgba&&(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:Wd(a.rgba)}),(0,K.jsxs)(`span`,{className:`text-sm text-white`,children:[a.brand?`${a.brand} `:``,a.material,a.color_name?` - ${a.color_name}`:``]})]})]}),(0,K.jsxs)(`button`,{onClick:oe,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-blue transition-colors text-left`,children:[(0,K.jsx)(Ll,{className:`w-5 h-5 text-bambu-blue flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:n(`configureAmsSlot.title`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.configureDesc`,`Set filament preset, K-profile, and color`)})]})]}),!u&&(qK(L?.tray)?null:t?(0,K.jsxs)(`button`,{onClick:le,disabled:ne.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left`,children:[(0,K.jsx)(xu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`,`Unassign`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unassignDesc`,`Remove inventory spool from this slot`)})]})]}):(0,K.jsxs)(`button`,{onClick:se,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left`,children:[(0,K.jsx)(cl,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.assignSpool`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.assignDesc`,`Track a spool from your inventory`)})]})]})),u&&(r?.id?(0,K.jsxs)(`button`,{onClick:()=>re.mutate(r.id),disabled:re.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left active:opacity-50`,children:[(0,K.jsx)(xu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unlinkDesc`,`Remove Spoolman link from this slot`)})]})]}):a?(0,K.jsxs)(`button`,{onClick:()=>U.mutate(a.id),disabled:U.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left active:opacity-50`,children:[(0,K.jsx)(xu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unassignDesc`,`Remove inventory spool from this slot`)})]})]}):(0,K.jsxs)(`button`,{onClick:ce,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left`,children:[(0,K.jsx)(Ic,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.assignSpool`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.linkDesc`,`Link a Spoolman spool to this slot`)})]})]}))]})]})]})})(),z&&(0,K.jsx)(QG,{isOpen:!!z,onClose:()=>{B(null),r.invalidateQueries({queryKey:[`spool-assignments`,e]}),r.invalidateQueries({queryKey:[`spool-assignments`]})},printerId:z.printerId,amsId:z.amsId,trayId:z.trayId,trayInfo:z.trayInfo,spoolmanEnabled:!!u}),V&&(0,K.jsx)(XG,{isOpen:!!V,onClose:()=>ee(null),tagUid:V.tagUid,trayUuid:V.trayUuid,printerId:V.printerId,amsId:V.amsId,trayId:V.trayId})]})}function IHe({type:e,deviceId:t,onClose:n}){let{t:r}=G(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)(!1);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!i&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i,n]);let f=(0,y.useCallback)(async()=>{a(!0),s(``),l(``),d(!0);try{s(r(`spoolbuddy.diagnostic.queuing`,`Queuing diagnostic on device... -`)),await nd.queueDiagnostics(t,e);let n=null,i=0;for(;i<60&&!n;){await new Promise(e=>setTimeout(e,500));try{n=await nd.getDiagnosticResult(t,e);break}catch{i++,i%4==0&&s(e=>e+`.`)}}if(!n)throw Error(`Diagnostic timed out - device did not report results`);s(n.output),n.success||l(`Exit code: ${n.exit_code}`)}catch(e){l(e instanceof Error?e.message:`Unknown error`),s(``)}finally{a(!1)}},[e,t,r]);return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in`,onClick:n,children:(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg shadow-xl w-full max-w-2xl mx-4 max-h-[80vh] flex flex-col animate-slide-up`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex justify-between items-center p-4 border-b border-zinc-700`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e===`scale`?r(`spoolbuddy.diagnostic.scaleTitle`,`Scale Diagnostic`):e===`read_tag`?r(`spoolbuddy.diagnostic.readTagTitle`,`Read Tag Diagnostic`):r(`spoolbuddy.diagnostic.nfcTitle`,`NFC Reader Diagnostic`)}),(0,K.jsx)(`button`,{onClick:n,className:`text-zinc-400 hover:text-white transition-colors`,"aria-label":`Close`,children:(0,K.jsx)(Pu,{size:20})})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-auto p-4 bg-black/50 font-mono text-sm`,children:i?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-green-400`,children:[(0,K.jsx)(`div`,{className:`animate-spin w-4 h-4 border-2 border-green-400 border-t-transparent rounded-full`}),(0,K.jsx)(`span`,{children:r(`spoolbuddy.diagnostic.running`,`Running diagnostic on device...`)})]}):o?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`text-green-400 whitespace-pre-wrap break-words`,children:o}),c&&(0,K.jsxs)(`div`,{className:`text-red-400 mt-2`,children:[`❌ `,c]})]}):u?(0,K.jsx)(`div`,{children:c?(0,K.jsxs)(`div`,{className:`text-red-400`,children:[`ERROR: `,c]}):(0,K.jsx)(`span`,{className:`text-green-400`,children:r(`spoolbuddy.diagnostic.completed`,`Diagnostic completed successfully.`)})}):(0,K.jsxs)(`div`,{className:`text-zinc-500`,children:[r(`spoolbuddy.diagnostic.clickStart`,`Click "Run Diagnostic" to start the hardware diagnostic on`),` `,t,`.`]})}),(0,K.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-zinc-700 bg-zinc-800`,children:[(0,K.jsx)(`button`,{onClick:f,disabled:i,className:`flex-1 flex items-center justify-center gap-2 bg-green-600 hover:bg-green-700 disabled:bg-gray-600 disabled:cursor-not-allowed px-4 py-2 rounded font-semibold text-white transition-colors`,children:i?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`animate-spin w-4 h-4 border-2 border-white border-t-transparent rounded-full`}),r(`spoolbuddy.diagnostic.runningBtn`,`Running...`)]}):u?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(El,{size:16}),r(`spoolbuddy.diagnostic.runAgain`,`Run Again`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(hl,{size:16}),r(`spoolbuddy.diagnostic.runBtn`,`Run Diagnostic`)]})}),(0,K.jsx)(`button`,{onClick:n,className:`px-4 py-2 rounded bg-zinc-700 hover:bg-zinc-600 text-white font-semibold transition-colors`,children:r(`spoolbuddy.diagnostic.close`,`Close`)})]})]})})}function LHe(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m`:`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`}function RHe(e){if(!e)return`-`;let t=mf(e);return t?t.toLocaleDateString(void 0,{month:`short`,day:`numeric`})+` `+t.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`}):`-`}var zHe=[{label:`Off`,value:0},{label:`1m`,value:60},{label:`2m`,value:120},{label:`5m`,value:300},{label:`10m`,value:600},{label:`30m`,value:1800}];function BHe({device:e}){let{t}=G(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null);return(0,y.useEffect)(()=>{!i&&e.backend_url&&a(e.backend_url)},[e.backend_url,i]),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.nfcReader`,`NFC Reader`)}),(0,K.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.type`,`Type`)}),(0,K.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:e.nfc_reader_type||`N/A`})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.connection`,`Connection`)}),(0,K.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:e.nfc_connection||`N/A`})]}),(0,K.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.status.status`,`Status`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full ${e.nfc_ok?`bg-green-500`:e.nfc_reader_type?`bg-red-500`:`bg-zinc-600`}`}),(0,K.jsx)(`span`,{className:e.nfc_ok?`text-green-400`:e.nfc_reader_type?`text-red-400`:`text-zinc-500`,children:e.nfc_ok?t(`spoolbuddy.status.nfcReady`,`Ready`):e.nfc_reader_type?t(`common.error`,`Error`):t(`spoolbuddy.settings.notConnected`,`N/A`)})]})]})]})]}),(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.deviceInfo`,`Device Info`)}),(0,K.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.hostname`,`Host`)}),(0,K.jsx)(`span`,{className:`text-zinc-300 truncate ml-2`,children:e.hostname})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:`IP`}),(0,K.jsx)(`span`,{className:`text-zinc-300`,children:e.ip_address})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.uptime`,`Uptime`)}),(0,K.jsx)(`span`,{className:`text-zinc-300`,children:LHe(e.uptime_s)})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:`ID`}),(0,K.jsx)(`span`,{className:`text-zinc-400 font-mono truncate ml-2`,children:e.device_id})]})]})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 space-y-2`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300`,children:t(`spoolbuddy.settings.systemConfig`,`Backend & Auth`)}),(0,K.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),placeholder:`http://192.168.1.100:5000`,className:`w-full px-2 py-1.5 rounded bg-zinc-900 border border-zinc-700 text-zinc-100 text-xs`}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`password`,value:o,onChange:e=>s(e.target.value),placeholder:t(`spoolbuddy.settings.apiTokenPlaceholder`,`API token`),className:`flex-1 px-2 py-1.5 rounded bg-zinc-900 border border-zinc-700 text-zinc-100 text-xs`}),(0,K.jsx)(`button`,{onClick:async()=>{if(!i.trim()){d({type:`error`,text:t(`spoolbuddy.settings.systemFieldsRequired`,`Backend URL is required.`)});return}l(!0),d(null);try{await nd.updateSystemConfig(e.device_id,i.trim(),o.trim()||void 0),d({type:`ok`,text:t(`spoolbuddy.settings.systemQueued`,`Config queued.`)})}catch(e){d({type:`error`,text:e instanceof Error?e.message:t(`common.error`,`Error`)})}finally{l(!1)}},disabled:c,className:`px-3 py-1.5 rounded bg-green-700 hover:bg-green-600 disabled:bg-zinc-700 text-xs font-medium text-zinc-100`,children:t(`spoolbuddy.settings.saveConfig`,`Save`)})]}),u&&(0,K.jsx)(`div`,{className:`text-xs ${u.type===`ok`?`text-green-400`:`text-red-400`}`,children:u.text})]}),(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 flex flex-col gap-2`,children:[(0,K.jsxs)(`button`,{onClick:()=>r(`nfc`),className:`flex-1 bg-blue-700 hover:bg-blue-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,K.jsx)(Ou,{className:`w-4 h-4 text-blue-300 shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs font-medium text-blue-100`,children:t(`spoolbuddy.settings.nfcDiagnostic`,`NFC Diagnostic`)})]}),(0,K.jsxs)(`button`,{onClick:()=>r(`scale`),className:`flex-1 bg-yellow-700 hover:bg-yellow-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,K.jsx)(Iu,{className:`w-4 h-4 text-yellow-300 shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs font-medium text-yellow-100`,children:t(`spoolbuddy.settings.scaleDiagnostic`,`Scale Diagnostic`)})]}),(0,K.jsxs)(`button`,{onClick:()=>r(`read_tag`),className:`flex-1 bg-emerald-700 hover:bg-emerald-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,K.jsx)(Zs,{className:`w-4 h-4 text-emerald-300 shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs font-medium text-emerald-100`,children:t(`spoolbuddy.settings.readTagDiagnostic`,`Read Tag`)})]})]})]}),n&&e&&(0,K.jsx)(IHe,{type:n,deviceId:e.device_id,onClose:()=>r(null)})]})}function VHe({device:e,onBrightnessChange:t}){let{t:n}=G(),[r,i]=(0,y.useState)(e.display_brightness),[a,o]=(0,y.useState)(e.display_blank_timeout),[s,c]=(0,y.useState)(!1),l=(0,y.useRef)(void 0),u=(0,y.useRef)(void 0);(0,y.useEffect)(()=>{i(e.display_brightness),o(e.display_blank_timeout)},[e.display_brightness,e.display_blank_timeout]);let d=(0,y.useCallback)(()=>{c(!0),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>c(!1),1500)},[]),f=(0,y.useCallback)((t,n)=>{l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{nd.updateDisplay(e.device_id,t,n).then(()=>d()).catch(e=>console.error(`Failed to update display:`,e))},300)},[e.device_id,d]),p=e=>{i(e),t(e),f(e,a)},m=e=>{o(e),f(r,e)};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300`,children:n(`spoolbuddy.settings.brightness`,`Brightness`)}),s&&(0,K.jsxs)(`span`,{className:`text-xs text-green-400 flex items-center gap-1 animate-pulse`,children:[(0,K.jsx)(`svg`,{className:`w-3 h-3`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:3,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}),n(`spoolbuddy.settings.saved`,`Saved`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`svg`,{className:`w-4 h-4 text-zinc-500 flex-shrink-0`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z`})}),(0,K.jsx)(`input`,{type:`range`,min:0,max:100,value:r,onChange:e=>p(parseInt(e.target.value)),className:`flex-1 h-2 bg-zinc-700 rounded-lg appearance-none cursor-pointer accent-green-500`}),(0,K.jsxs)(`span`,{className:`text-sm font-mono text-zinc-400 w-10 text-right`,children:[r,`%`]})]}),!e.has_backlight&&(0,K.jsx)(`p`,{className:`text-xs text-zinc-600 mt-2`,children:n(`spoolbuddy.settings.noBacklight`,`No DSI backlight detected. Brightness control requires a DSI display.`)})]}),(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1`,children:n(`spoolbuddy.settings.screenBlank`,`Screen Blank Timeout`)}),(0,K.jsx)(`p`,{className:`text-xs text-zinc-500 mb-3`,children:n(`spoolbuddy.settings.screenBlankDesc`,`Screen turns off after inactivity. Touch to wake.`)}),(0,K.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:zHe.map(e=>(0,K.jsx)(`button`,{onClick:()=>m(e.value),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors min-h-[40px] ${a===e.value?`bg-green-600 text-white`:`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`}`,children:e.label},e.value))})]}),(0,K.jsx)(`p`,{className:`text-xs text-zinc-600 text-center`,children:n(`spoolbuddy.settings.displayNote`,`Brightness is applied as a software filter.`)})]})}function HHe({step:e,labels:t}){return(0,K.jsxs)(`div`,{className:`flex flex-col items-center w-16 shrink-0 pt-1`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold ${e===`tare`?`bg-green-600 text-white`:`bg-green-600/20 text-green-400`}`,children:e===`weight`?(0,K.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:3,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}):`1`}),(0,K.jsx)(`span`,{className:`text-[10px] mt-0.5 ${e===`tare`?`text-green-400 font-medium`:`text-green-400/60`}`,children:t.tare}),(0,K.jsx)(`div`,{className:`w-px h-5 my-1 ${e===`weight`?`bg-green-600/40`:`bg-zinc-700`}`}),(0,K.jsx)(`div`,{className:`flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold ${e===`weight`?`bg-green-600 text-white`:`bg-zinc-700 text-zinc-500`}`,children:`2`}),(0,K.jsx)(`span`,{className:`text-[10px] mt-0.5 ${e===`weight`?`text-green-400 font-medium`:`text-zinc-600`}`,children:t.weight})]})}function UHe({device:e,weight:t,weightStable:n,rawAdc:r}){let{t:i}=G(),a=Qa(),[o,s]=(0,y.useState)(`idle`),[c,l]=(0,y.useState)(`500`),[u,d]=(0,y.useState)(null),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),v=(0,y.useRef)(null);(0,y.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]);let b=(0,y.useCallback)(e=>{v.current&&clearTimeout(v.current),v.current=setTimeout(()=>h(null),e)},[]);(0,y.useEffect)(()=>{if(!g)return;let e=()=>Date.now()-g.startedAtMs,t=setInterval(()=>{a.invalidateQueries({queryKey:[`spoolbuddy-devices`]})},1e3),n=setTimeout(()=>{_(null),h({type:`error`,msg:i(`spoolbuddy.settings.tareTimedOut`,`Tare timed out — is the SpoolBuddy daemon running?`)}),b(5e3)},Math.max(0,15e3-e()));return()=>{clearInterval(t),clearTimeout(n)}},[g,a,i,b]),(0,y.useEffect)(()=>{g&&(e?.last_calibrated_at??null)!==g.snapshot&&(_(null),h({type:`ok`,msg:i(`spoolbuddy.settings.tareComplete`,`Tare complete!`)}),b(3e3))},[e?.last_calibrated_at,g,i,b]);let x=e=>{e===`backspace`?l(e=>e.slice(0,-1)||``):e===`.`&&!c.includes(`.`)?l(e=>e+`.`):e>=`0`&&e<=`9`&&l(t=>t===`0`?e:t+e)};return o===`idle`?(0,K.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 mb-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,K.jsx)(`span`,{className:`text-lg font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`})]}),(0,K.jsxs)(`div`,{className:`text-xs text-zinc-500 text-right`,children:[(0,K.jsxs)(`span`,{children:[i(`spoolbuddy.settings.tareOffset`,`Tare`),`: `,e.tare_offset]}),(0,K.jsx)(`span`,{className:`mx-1.5`,children:`·`}),(0,K.jsxs)(`span`,{children:[i(`spoolbuddy.settings.calFactor`,`Factor`),`: `,e.calibration_factor.toFixed(2)]})]})]}),e.last_calibrated_at&&(0,K.jsxs)(`div`,{className:`text-xs text-zinc-600 mt-1`,children:[i(`spoolbuddy.settings.lastCalibrated`,`Last calibrated`),`: `,RHe(e.last_calibrated_at)]})]}),m&&(0,K.jsx)(`div`,{className:`rounded-lg px-3 py-2 mb-3 text-sm ${m.type===`ok`?`bg-green-900/30 text-green-300 border border-green-800`:`bg-red-900/30 text-red-300 border border-red-800`}`,children:m.msg}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`button`,{onClick:async()=>{p(!0),h(null),v.current&&=(clearTimeout(v.current),null);let t=e?.last_calibrated_at??null;try{await nd.tare(e.device_id),h({type:`ok`,msg:i(`spoolbuddy.settings.tareSet`,`Tare command sent. Waiting for device...`)}),_({snapshot:t,startedAtMs:Date.now()})}catch{h({type:`error`,msg:i(`spoolbuddy.settings.tareFailed`,`Failed to send tare command`)}),b(5e3)}finally{p(!1)}},disabled:f,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px] flex items-center justify-center gap-2`,children:[f&&(0,K.jsxs)(`svg`,{className:`w-4 h-4 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,K.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,K.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),i(`spoolbuddy.weight.tare`,`Tare`)]}),(0,K.jsx)(`button`,{onClick:()=>{s(`tare`),h(null)},className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:i(`spoolbuddy.weight.calibrate`,`Calibrate`)})]})]}):(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)(HHe,{step:o,labels:{tare:i(`spoolbuddy.weight.tare`,`Tare`),weight:i(`spoolbuddy.settings.knownWeight`,`Known weight`)}}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 bg-zinc-800 rounded-lg px-3 py-1.5 mb-1.5`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,K.jsx)(`span`,{className:`text-sm font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`}),(0,K.jsx)(`span`,{className:`text-xs ml-auto ${n?`text-green-400`:`text-amber-400`}`,children:n?i(`spoolbuddy.settings.stable`,`Stable`):i(`spoolbuddy.settings.settling`,`Settling...`)})]}),m&&(0,K.jsx)(`div`,{className:`rounded-lg px-3 py-1.5 mb-1.5 text-xs ${m.type===`ok`?`bg-green-900/30 text-green-300 border border-green-800`:`bg-red-900/30 text-red-300 border border-red-800`}`,children:m.msg}),o===`tare`?(0,K.jsx)(`p`,{className:`text-sm text-zinc-300 mb-3`,children:i(`spoolbuddy.settings.calStep1`,`Remove all items from the scale and press Set Zero.`)}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs text-zinc-400 shrink-0`,children:i(`spoolbuddy.settings.knownWeight`,`Known weight`)}),(0,K.jsxs)(`div`,{className:`flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1 text-right text-lg font-mono text-zinc-100`,children:[c||`0`,(0,K.jsx)(`span`,{className:`text-zinc-500 ml-1`,children:`g`})]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-4 gap-1 mb-1.5`,children:[`7`,`8`,`9`,`backspace`,`4`,`5`,`6`,`.`,`1`,`2`,`3`,`0`].map(e=>(0,K.jsx)(`button`,{onClick:()=>x(e),className:`rounded text-lg font-medium transition-colors h-[48px] active:scale-95 ${e===`backspace`?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`:`bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700`}`,children:e===`backspace`?`⌫`:e},e))})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>{s(`idle`),h(null)},className:`flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors h-[40px]`,children:i(`common.cancel`,`Cancel`)}),(0,K.jsxs)(`button`,{onClick:async()=>{if(o===`tare`){p(!0),h(null);try{d(r),await nd.tare(e.device_id),h({type:`ok`,msg:i(`spoolbuddy.settings.zeroSet`,`Zero point set. Place known weight on scale.`)}),s(`weight`)}catch{h({type:`error`,msg:i(`spoolbuddy.settings.tareFailed`,`Failed to send tare command`)})}finally{p(!1)}}else if(o===`weight`){let t=parseFloat(c);if(r===null||!t||t<=0)return;p(!0),h(null);try{await nd.setCalibrationFactor(e.device_id,t,r,u??void 0),h({type:`ok`,msg:i(`spoolbuddy.settings.calibrationDone`,`Calibration complete!`)}),b(3e3),s(`idle`)}catch{h({type:`error`,msg:i(`spoolbuddy.settings.calibrationFailed`,`Calibration failed`)}),b(5e3)}finally{p(!1)}}},disabled:f,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors h-[40px] flex items-center justify-center gap-2`,children:[f&&(0,K.jsxs)(`svg`,{className:`w-4 h-4 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,K.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,K.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),o===`tare`?i(`spoolbuddy.settings.setZero`,`Set Zero`):i(`spoolbuddy.settings.calibrateNow`,`Calibrate`)]})]})]})]})}function WHe({device:e}){let{t}=G(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),u=e.update_status===`pending`||e.update_status===`updating`;(0,y.useEffect)(()=>{u&&n===`applying`&&r(null)},[u,n]),(0,y.useEffect)(()=>{let e=()=>{u&&setTimeout(()=>window.location.reload(),1e3)};return window.addEventListener(`spoolbuddy-online`,e),()=>window.removeEventListener(`spoolbuddy-online`,e)},[u]);let{data:d,refetch:f}=q({queryKey:[`spoolbuddy-update-check`,e.device_id],queryFn:()=>nd.checkDaemonUpdate(e.device_id),staleTime:0}),{data:p}=q({queryKey:[`spoolbuddy-ssh-key`],queryFn:()=>nd.getSSHPublicKey(),enabled:o,staleTime:1/0}),m=async()=>{r(`checking`),a(null);try{await f()}finally{r(null)}},h=async()=>{r(`applying`),a(null);try{await nd.triggerUpdate(e.device_id)}catch(e){a(e instanceof Error?e.message:`Failed to trigger update`),r(null)}},g=n!=null||u,_=()=>{p?.public_key&&(navigator.clipboard.writeText(p.public_key),l(!0),setTimeout(()=>l(!1),2e3))},v=e.firmware_version||(d?.current_version&&d.current_version!==`0.0.0`?d.current_version:null);return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between items-center text-sm`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.currentVersion`,`Current Version`)}),(0,K.jsx)(`span`,{className:`text-zinc-200 font-mono`,children:v||(0,K.jsx)(`span`,{className:`text-zinc-500 italic text-xs`,children:t(`spoolbuddy.settings.versionPending`,`Waiting for daemon...`)})})]}),g?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`svg`,{className:`w-4 h-4 animate-spin text-green-400 flex-shrink-0`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,K.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,K.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),(0,K.jsx)(`span`,{className:`text-green-300 text-xs`,children:n===`checking`?t(`spoolbuddy.settings.checking`,`Checking for updates...`):e.update_message||t(`spoolbuddy.settings.updateWaiting`,`Updating...`)})]}):e.update_status===`error`?(0,K.jsx)(`p`,{className:`text-xs text-red-300`,children:e.update_message||t(`spoolbuddy.settings.updateFailed`,`Update failed`)}):i?(0,K.jsx)(`p`,{className:`text-xs text-red-300`,children:i}):d?.update_available?(0,K.jsxs)(`p`,{className:`text-xs text-green-300`,children:[t(`spoolbuddy.settings.updateAvailable`,`Update available`),`: `,v,` → `,d.latest_version]}):null,!g&&(d?.update_available?(0,K.jsx)(`button`,{onClick:h,disabled:!e.online,className:`w-full px-3 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors`,children:e.online?t(`spoolbuddy.settings.applyUpdate`,`Apply Update`):t(`spoolbuddy.settings.deviceOffline`,`Device Offline`)}):(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{onClick:m,className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors`,children:t(`spoolbuddy.settings.checkUpdates`,`Check for Updates`)}),(0,K.jsx)(`button`,{onClick:h,disabled:!e.online,className:`px-3 py-2 rounded-lg text-xs font-medium bg-zinc-700 text-zinc-400 hover:bg-zinc-600 hover:text-zinc-200 disabled:opacity-40 transition-colors`,children:t(`spoolbuddy.settings.forceUpdate`,`Force Update`)})]}))]}),(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,K.jsxs)(`button`,{onClick:()=>s(!o),className:`w-full flex justify-between items-center text-xs`,children:[(0,K.jsx)(`span`,{className:`font-medium text-zinc-400`,children:t(`spoolbuddy.settings.sshSetup`,`SSH Setup`)}),(0,K.jsx)(`svg`,{className:`w-3 h-3 text-zinc-500 transition-transform ${o?`rotate-180`:``}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 9l-7 7-7-7`})})]}),o&&(0,K.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-zinc-500`,children:t(`spoolbuddy.settings.sshDescription`,`SSH key is deployed automatically. For manual setup, add this key to ~/.ssh/authorized_keys on the device.`)}),p?.public_key?(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`pre`,{className:`bg-zinc-900 rounded p-2 text-[10px] text-zinc-400 font-mono break-all whitespace-pre-wrap`,children:p.public_key}),(0,K.jsx)(`button`,{onClick:_,className:`absolute top-1 right-1 px-1.5 py-0.5 rounded text-[10px] bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors`,children:c?t(`common.copied`,`Copied!`):t(`common.copy`,`Copy`)})]}):(0,K.jsx)(`span`,{className:`text-[10px] text-zinc-500 italic`,children:t(`spoolbuddy.settings.sshKeyLoading`,`Loading...`)})]})]})]})}function K9({percent:e,color:t}){return(0,K.jsx)(`div`,{className:`w-full h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all ${t}`,style:{width:`${Math.min(100,Math.max(0,e))}%`}})})}function GHe(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`}function KHe({device:e}){let{t}=G(),n=e.system_stats;if(!n)return(0,K.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,K.jsx)(`p`,{className:`text-sm text-zinc-500`,children:t(`spoolbuddy.settings.systemStatsWaiting`,`Waiting for system stats...`)})});let r=n.memory,i=n.disk,a=(n.cpu_temp_c??0)>=80?`text-red-400`:(n.cpu_temp_c??0)>=65?`text-amber-400`:`text-green-400`,o=(r?.percent??0)>=90?`bg-red-500`:(r?.percent??0)>=70?`bg-amber-500`:`bg-green-500`,s=(i?.percent??0)>=90?`bg-red-500`:(i?.percent??0)>=70?`bg-amber-500`:`bg-green-500`;return(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:`CPU`}),(0,K.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.cores`,`Cores`)}),(0,K.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.cpu_count??`-`})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.loadAvg`,`Load Avg`)}),(0,K.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.load_avg?n.load_avg.join(` / `):`-`})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.temp`,`Temp`)}),(0,K.jsx)(`span`,{className:`font-mono font-medium ${a}`,children:n.cpu_temp_c==null?`-`:`${n.cpu_temp_c}\u00B0C`})]})]})]}),(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.memory`,`Memory`)}),r?(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(K9,{percent:r.percent??0,color:o}),(0,K.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.used`,`Used`)}),(0,K.jsxs)(`span`,{className:`text-zinc-300 font-mono`,children:[r.used_mb,` / `,r.total_mb,` MB`]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.available`,`Free`)}),(0,K.jsxs)(`span`,{className:`text-zinc-300 font-mono`,children:[r.available_mb,` MB`]})]})]})]}):(0,K.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`-`})]})]}),(0,K.jsx)(`div`,{className:`bg-zinc-800 rounded-lg px-3 py-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 shrink-0`,children:t(`spoolbuddy.settings.disk`,`Disk`)}),i?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`flex-1`,children:(0,K.jsx)(K9,{percent:i.percent??0,color:s})}),(0,K.jsxs)(`span`,{className:`text-xs text-zinc-300 font-mono shrink-0`,children:[i.used_gb,` / `,i.total_gb,` GB`]})]}):(0,K.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`-`})]})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1.5`,children:t(`spoolbuddy.settings.osInfo`,`OS`)}),(0,K.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[n.os?.os&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.distro`,`Distro`)}),(0,K.jsx)(`span`,{className:`text-zinc-300 truncate ml-2`,children:n.os.os})]}),n.os?.kernel&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.kernel`,`Kernel`)}),(0,K.jsx)(`span`,{className:`text-zinc-300 font-mono truncate ml-2`,children:n.os.kernel})]}),n.os?.arch&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.arch`,`Arch`)}),(0,K.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.os.arch})]})]})]}),(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1.5`,children:t(`spoolbuddy.settings.runtime`,`Runtime`)}),(0,K.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[n.os?.python&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:`Python`}),(0,K.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.os.python})]}),n.system_uptime_s!=null&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.systemUptime`,`Uptime`)}),(0,K.jsx)(`span`,{className:`text-zinc-300`,children:GHe(n.system_uptime_s)})]})]})]})]})]})}function qHe(){let{sbState:e,setDisplayBrightness:t}=Qn(),{t:n}=G(),[r,i]=(0,y.useState)(`device`),{data:a=[]}=q({queryKey:[`spoolbuddy-devices`],queryFn:()=>nd.getDevices(),refetchInterval:1e4}),o=e.deviceId?a.find(t=>t.device_id===e.deviceId)??a[0]:a[0],s=[{id:`device`,label:n(`spoolbuddy.settings.tabDevice`,`Device`)},{id:`display`,label:n(`spoolbuddy.settings.tabDisplay`,`Display`)},{id:`scale`,label:n(`spoolbuddy.settings.tabScale`,`Scale`)},{id:`updates`,label:n(`spoolbuddy.settings.tabUpdates`,`Updates`)},{id:`system`,label:n(`spoolbuddy.settings.tabSystem`,`System`)}];return(0,K.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,K.jsx)(`h1`,{className:`text-xl font-semibold text-zinc-100 mb-3`,children:n(`spoolbuddy.nav.settings`,`Settings`)}),(0,K.jsx)(`div`,{className:`flex gap-1 bg-zinc-800/50 rounded-lg p-1 mb-4`,children:s.map(e=>(0,K.jsx)(`button`,{onClick:()=>i(e.id),className:`flex-1 px-2 py-2 rounded-md text-sm font-medium transition-colors min-h-[36px] ${r===e.id?`bg-zinc-700 text-zinc-100`:`text-zinc-500 hover:text-zinc-300`}`,children:e.label},e.id))}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:o?(0,K.jsxs)(K.Fragment,{children:[r===`device`&&(0,K.jsx)(BHe,{device:o}),r===`display`&&(0,K.jsx)(VHe,{device:o,onBrightnessChange:t}),r===`scale`&&(0,K.jsx)(UHe,{device:o,weight:e.weight,weightStable:e.weightStable,rawAdc:e.rawAdc}),r===`updates`&&(0,K.jsx)(WHe,{device:o}),r===`system`&&(0,K.jsx)(KHe,{device:o})]}):(0,K.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,K.jsx)(`div`,{className:`text-center text-zinc-500`,children:(0,K.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.settings.noDevice`,`No SpoolBuddy device found`)})})})})]})}function JHe({device:e,weight:t,weightStable:n,rawAdc:r}){let{t:i}=G(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(`idle`),[l,u]=(0,y.useState)(`500`),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(!1),h=e=>{e===`backspace`?u(e=>e.slice(0,-1)||``):e===`.`&&!l.includes(`.`)?u(e=>e+`.`):e>=`0`&&e<=`9`&&u(t=>t===`0`?e:t+e)};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-zinc-400`,children:i(`spoolbuddy.settings.currentWeight`,`Current weight`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,K.jsx)(`span`,{className:`text-lg font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 mt-3 text-xs`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:i(`spoolbuddy.settings.tareOffset`,`Tare offset`)}),(0,K.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.tare_offset})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:i(`spoolbuddy.settings.calFactor`,`Cal. factor`)}),(0,K.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.calibration_factor.toFixed(2)})]})]})]}),s===`idle`?(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{onClick:async()=>{m(!0);try{await nd.tare(e.device_id)}catch(e){console.error(`Failed to tare:`,e)}finally{m(!1)}},disabled:p,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px]`,children:p?`...`:i(`spoolbuddy.weight.tare`,`Tare`)}),(0,K.jsx)(`button`,{onClick:()=>{c(`tare`)},className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:i(`spoolbuddy.weight.calibrate`,`Calibrate`)})]}):(0,K.jsxs)(`div`,{className:`bg-zinc-800 border border-zinc-700 rounded-lg p-3 space-y-2`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-zinc-200`,children:s===`tare`?i(`spoolbuddy.settings.calStep1`,`Step 1: Remove all items from the scale`):i(`spoolbuddy.settings.calStep2`,`Step 2: Place known weight on scale`)}),s===`weight`&&(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-zinc-400`,children:i(`spoolbuddy.settings.knownWeight`,`Known weight (g)`)}),(0,K.jsxs)(`div`,{className:`flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1.5 text-right text-base font-mono text-zinc-100`,children:[l||`0`,(0,K.jsx)(`span`,{className:`text-zinc-500 ml-1`,children:`g`})]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-4 gap-1`,children:[`7`,`8`,`9`,`backspace`,`4`,`5`,`6`,`.`,`1`,`2`,`3`,`0`].map(e=>(0,K.jsx)(`button`,{onClick:()=>h(e),className:`py-2 rounded text-sm font-medium transition-colors min-h-[36px] ${e===`backspace`?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`:`bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700`}`,children:e===`backspace`?`⌫`:e},e))})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>c(`idle`),className:`flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[40px]`,children:i(`common.cancel`,`Cancel`)}),(0,K.jsx)(`button`,{onClick:async()=>{if(s===`tare`){o(!0);try{f(r),await nd.tare(e.device_id),c(`weight`)}catch(e){console.error(`Failed to tare:`,e)}finally{o(!1)}}else if(s===`weight`){let t=parseFloat(l);if(r===null||!t||t<=0)return;o(!0);try{await nd.setCalibrationFactor(e.device_id,t,r,d??void 0),c(`idle`)}catch(e){console.error(`Failed to calibrate:`,e)}finally{o(!1)}}},disabled:a,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors min-h-[40px]`,children:a?`...`:s===`tare`?i(`spoolbuddy.settings.setZero`,`Set Zero`):i(`spoolbuddy.settings.calibrateNow`,`Calibrate`)})]})]})]})}function YHe(){let{sbState:e}=Qn(),{t}=G(),n=Yn(),{data:r=[]}=q({queryKey:[`spoolbuddy-devices`],queryFn:()=>nd.getDevices(),refetchInterval:1e4}),i=e.deviceId?r.find(t=>t.device_id===e.deviceId)??r[0]:r[0];return(0,K.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,K.jsx)(`button`,{onClick:()=>n(`/spoolbuddy/settings`),className:`p-1.5 rounded-lg text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800 transition-colors`,children:(0,K.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 19l-7-7 7-7`})})}),(0,K.jsx)(`h1`,{className:`text-xl font-semibold text-zinc-100`,children:t(`spoolbuddy.settings.scaleCalibration`,`Scale Calibration`)})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:i?(0,K.jsx)(JHe,{device:i,weight:e.weight,weightStable:e.weightStable,rawAdc:e.rawAdc}):(0,K.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,K.jsx)(`div`,{className:`text-center text-zinc-500`,children:(0,K.jsx)(`p`,{className:`text-sm`,children:t(`spoolbuddy.settings.noDevice`,`No SpoolBuddy device found`)})})})})]})}var XHe=[`PLA`,`PETG`,`ABS`,`ASA`,`TPU`,`PA`,`PC`,`PVA`,`HIPS`];function ZHe(){let{t:e}=G(),{showToast:t}=xd(),{sbState:n}=Qn(),[r,i]=(0,y.useState)(`existing`),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`idle`),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(null),{data:b}=q({queryKey:[`spoolman-settings`],queryFn:Q.getSpoolmanSettings,staleTime:300*1e3}),x=b!==void 0,S=b?.spoolman_enabled===`true`&&!!b?.spoolman_url,{data:C=[],refetch:w}=q({queryKey:[S?`spoolman-inventory-spools`:`inventory-spools`,`write-tag`],queryFn:()=>S?Q.getSpoolmanInventorySpools(!1):Q.getSpools(!1),refetchInterval:1e4,enabled:x}),{data:T=[]}=q({queryKey:[`spoolbuddy-devices`],queryFn:()=>nd.getDevices(),refetchInterval:5e3}),{data:E}=q({queryKey:[`settings`],queryFn:Q.getSettings}),D=T[0],O=n.deviceOnline,k=Yd(E?.currency||`USD`),A=(0,y.useMemo)(()=>{let e;if(r===`existing`)e=C.filter(e=>!e.tag_uid&&!e.archived_at);else if(r===`replace`)e=C.filter(e=>(e.tag_uid||e.tray_uuid)&&!e.archived_at);else return[];if(s){let t=s.toLowerCase();e=e.filter(e=>e.material?.toLowerCase().includes(t)||e.color_name?.toLowerCase().includes(t)||e.brand?.toLowerCase().includes(t)||e.subtype?.toLowerCase().includes(t))}return e},[C,r,s]),j=(0,y.useCallback)(e=>{let t=e.detail;(t.sak??t.data?.sak)===0&&(g(!0),v(t.tag_uid??t.data?.tag_uid??null))},[]),M=(0,y.useCallback)(e=>{let t=e.detail;g(!0),v(t.tag_uid??t.data?.tag_uid??null)},[]),N=(0,y.useCallback)(()=>{g(!1),v(null)},[]),P=(0,y.useCallback)(t=>{let n=t.detail;(n.spool_id===a?.id||n.data?.spool_id===a?.id)&&(u(`success`),f(e(`spoolbuddy.writeTag.writeSuccess`,`Tag written successfully!`)),w(),setTimeout(()=>{u(`idle`),o(null),f(``)},5e3))},[a,e,w]),F=(0,y.useCallback)(t=>{let n=t.detail;(n.spool_id===a?.id||n.data?.spool_id===a?.id)&&(u(`error`),f(n.message??n.data?.message??e(`spoolbuddy.writeTag.writeFailed`,`Write failed`)))},[a,e]);(0,y.useEffect)(()=>(window.addEventListener(`spoolbuddy-unknown-tag`,j),window.addEventListener(`spoolbuddy-tag-matched`,M),window.addEventListener(`spoolbuddy-tag-removed`,N),window.addEventListener(`spoolbuddy-tag-written`,P),window.addEventListener(`spoolbuddy-tag-write-failed`,F),()=>{window.removeEventListener(`spoolbuddy-unknown-tag`,j),window.removeEventListener(`spoolbuddy-tag-matched`,M),window.removeEventListener(`spoolbuddy-tag-removed`,N),window.removeEventListener(`spoolbuddy-tag-written`,P),window.removeEventListener(`spoolbuddy-tag-write-failed`,F)}),[j,M,N,P,F]),(0,y.useEffect)(()=>{o(null),u(`idle`),f(``),c(``)},[r]);let I=async()=>{if(!(!a||!D)){u(`writing`),f(e(`spoolbuddy.writeTag.waiting`,`Waiting for SpoolBuddy...`));try{let e=await nd.writeTag(D.device_id,a.id);if(e?.warnings?.length)for(let n of e.warnings)t(n,`warning`)}catch{u(`error`),f(e(`spoolbuddy.writeTag.queueFailed`,`Failed to queue write command`))}}},L=async()=>{if(D){try{await nd.cancelWrite(D.device_id)}catch{}u(`idle`),f(``)}},R=async()=>{if(!(!a||!q9(a))){m(!0),u(`idle`),f(``);try{S?await Q.linkTagToSpoolmanSpool(a.id,{tag_uid:``,tray_uuid:``}):await Q.linkTagToSpool(a.id,{tag_uid:``,tray_uuid:``,data_origin:`manual`}),await w(),o(null),u(`success`),f(e(`spoolbuddy.writeTag.untagSuccess`,`Tag removed from spool`)),setTimeout(()=>{u(`idle`),f(``)},2500)}catch{u(`error`),f(e(`spoolbuddy.writeTag.untagFailed`,`Failed to remove tag from spool`))}finally{m(!1)}}},z=(0,y.useCallback)(e=>{o(e),u(`idle`),f(``),w()},[w]),B=a&&O&&l!==`writing`&&l!==`success`;return(0,K.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,K.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary shrink-0`,children:[{key:`existing`,label:e(`spoolbuddy.writeTag.tabExisting`,`Existing Spool`)},{key:`new`,label:e(`spoolbuddy.writeTag.tabNew`,`New Spool`)},{key:`replace`,label:e(`spoolbuddy.writeTag.tabReplace`,`Replace Tag`)}].map(e=>(0,K.jsx)(`button`,{onClick:()=>i(e.key),className:`flex-1 py-3 text-sm font-medium transition-colors ${r===e.key?`text-bambu-green border-b-2 border-bambu-green bg-bambu-dark`:`text-zinc-400 hover:text-zinc-200 hover:bg-bambu-dark-tertiary`}`,children:e.label},e.key))}),(0,K.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,K.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden border-r border-bambu-dark-tertiary`,children:r===`new`?(0,K.jsx)($He,{currencySymbol:k,onCreated:z,selectedSpool:a,spoolmanMode:S,t:e}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`p-3 shrink-0`,children:(0,K.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:e(`spoolbuddy.writeTag.searchPlaceholder`,`Search by material, color, brand...`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3 space-y-2`,children:A.length===0?(0,K.jsx)(`div`,{className:`text-center text-zinc-500 py-8 text-sm`,children:r===`existing`?e(`spoolbuddy.writeTag.noUntaggedSpools`,`No spools without tags`):e(`spoolbuddy.writeTag.noTaggedSpools`,`No spools with tags`)}):A.map(e=>(0,K.jsx)(QHe,{spool:e,selected:a?.id===e.id,showTag:r===`replace`,onClick:()=>{o(e),u(`idle`),f(``)}},e.id))})]})}),(0,K.jsx)(`div`,{className:`w-[340px] flex flex-col items-center justify-center p-6 shrink-0`,children:(0,K.jsx)(eUe,{writeStatus:l,writeMessage:d,selectedSpool:a,tagOnReader:h,tagUid:_,deviceOnline:O,canWrite:!!B,isReplace:r===`replace`,canUntag:r===`replace`&&!!a&&q9(a),untagging:p,onWrite:I,onUntag:R,onCancel:L,onRetry:()=>{u(`idle`),f(``)},t:e})})]})]})}function q9(e){return!!(e.tag_uid||e.tray_uuid)}function QHe({spool:e,selected:t,showTag:n,onClick:r}){let i=Math.max(0,e.label_weight-e.weight_used),a=e.label_weight>0?Math.round(i/e.label_weight*100):0;return(0,K.jsxs)(`button`,{onClick:r,className:`w-full flex items-center gap-3 p-3 rounded-lg text-left transition-colors ${t?`bg-bambu-green/15 border border-bambu-green/50`:`bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-transparent`}`,children:[(0,K.jsx)(`div`,{className:`w-8 h-8 rounded-full shrink-0 border border-white/10`,style:e.rgba?Wd(e.rgba):{backgroundColor:`#666`}}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-sm font-medium text-white truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,K.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-zinc-400`,children:[e.color_name&&(0,K.jsx)(`span`,{children:e.color_name}),(0,K.jsxs)(`span`,{children:[i,`g / `,e.label_weight,`g (`,a,`%)`]})]}),n&&e.tag_uid&&(0,K.jsx)(`div`,{className:`text-xs text-zinc-500 mt-0.5 font-mono`,children:e.tag_uid})]}),t&&(0,K.jsx)(`svg`,{className:`w-5 h-5 text-bambu-green shrink-0`,fill:`currentColor`,viewBox:`0 0 20 20`,children:(0,K.jsx)(`path`,{fillRule:`evenodd`,d:`M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z`,clipRule:`evenodd`})})]})}function $He({currencySymbol:e,onCreated:t,selectedSpool:n,spoolmanMode:r,t:i}){let{data:a=[]}=q({queryKey:[r?`spoolman-inventory-spools`:`inventory-spools`,`write-tag-form`],queryFn:()=>r?Q.getSpoolmanInventorySpools(!0):Q.getSpools(!0)}),{data:o}=q({queryKey:[`settings`],queryFn:Q.getSettings}),[s,c]=(0,y.useState)(`simple`),[l,u]=(0,y.useState)(`filament`),[d,f]=(0,y.useState)(J7),[p,m]=(0,y.useState)({}),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)([]),[A,j]=(0,y.useState)([]),[M,N]=(0,y.useState)([]),[P,F]=(0,y.useState)([]),[I,L]=(0,y.useState)([]),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)([]),[ee,H]=(0,y.useState)([]),[te,ne]=(0,y.useState)(new Set),[re,U]=(0,y.useState)(new Set);(0,y.useEffect)(()=>{V(mK())},[]),(0,y.useEffect)(()=>{let e=!1;return(async()=>{if(s===`full`){D(!0);try{let[t,n]=await Promise.allSettled([(async()=>(await Q.getCloudStatus()).is_authenticated?{connected:!0,presets:await Q.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await Q.orcaCloudStatus()).connected?{connected:!0,presets:(await Q.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(e)return;let r=t.status===`fulfilled`&&t.value.connected,i=n.status===`fulfilled`&&n.value.connected,a=t.status===`fulfilled`?t.value.presets:[],o=n.status===`fulfilled`?n.value.presets:[];T(r||i),k([...a,...o])}catch{e||T(!1)}finally{e||D(!1)}Q.getSpoolCatalog().then(t=>{e||F(t)}).catch(()=>void 0),Q.getColorCatalog().then(t=>{e||L(t)}).catch(()=>void 0),Q.getLocalPresets().then(t=>{e||j(t.filament)}).catch(()=>void 0),Q.getBuiltinFilaments().then(t=>{e||N(t)}).catch(()=>void 0);try{let t=await Q.getPrinters(),n=await Promise.all(t.map(e=>Q.getPrinterStatus(e.id).catch(()=>null))),r=[];for(let e=0;e({cali_idx:e.slot_id,filament_id:e.filament_id,setting_id:e.setting_id||``,name:e.name,k_value:parseFloat(e.k_value)||0,n_coef:parseFloat(e.n_coef)||0,extruder_id:e.extruder_id,nozzle_diameter:e.nozzle_diameter}))}catch{}r.push({printer:{...i,connected:a},calibrations:o})}e||H(r)}catch{}}})(),()=>{e=!0}},[s]),(0,y.useEffect)(()=>{ee.length>0&&U(new Set(ee.map(e=>String(e.printer.id))))},[ee]);let ie=(0,y.useMemo)(()=>fK(O,new Set,A,M),[O,A,M]),ae=(0,y.useMemo)(()=>pK(d.slicer_filament,ie),[d.slicer_filament,ie]),W=(0,y.useMemo)(()=>{let e=dK(O,A),t=I.map(e=>e.manufacturer?.trim()).filter(e=>!!e);return Array.from(new Set([...e,...t])).sort((e,t)=>e.localeCompare(t))},[O,A,I]),oe=(0,y.useMemo)(()=>{let e=I.map(e=>e.material?.trim()).filter(e=>!!e);return Array.from(new Set([...aK,...e])).sort((e,t)=>e.localeCompare(t))},[I]),se=(0,y.useMemo)(()=>{let e=[];for(let t of I){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of O){let n=uK(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of A){let n=uK(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[O,I,A]),ce=(0,y.useMemo)(()=>{let e=new Map;for(let t of se){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[se]),le=(0,y.useMemo)(()=>{let e=new Map;for(let t of se){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[se]),ue=(0,y.useMemo)(()=>{if(!d.material)return W;let e=d.material.toLowerCase(),t=le.get(e);return!t||t.size===0?W:W.filter(e=>t.has(e.toLowerCase()))},[W,d.material,le]),de=(0,y.useMemo)(()=>{if(!d.brand)return oe;let e=d.brand.toLowerCase(),t=ce.get(e);return!t||t.size===0?oe:oe.filter(e=>t.has(e.toLowerCase()))},[oe,d.brand,ce]),fe=(e,t)=>{f(n=>({...n,[e]:t})),p[e]&&m(t=>({...t,[e]:void 0}))},pe=e=>{V(t=>hK(e,t))},me=async e=>{let t=r?Q.saveSpoolmanKProfiles:Q.saveSpoolKProfiles;if(te.size===0){try{await t(e,[])}catch{}return}let n=[];for(let e of te){let[t,r,i]=e.split(`:`),a=parseInt(t),o=parseInt(r),s=i===`null`?0:parseInt(i),c=ee.find(e=>e.printer.id===a);if(c){let e=c.calibrations.find(e=>e.cali_idx===o);e&&n.push({printer_id:a,extruder:s,nozzle_diameter:e.nozzle_diameter||`0.4`,k_value:e.k_value,name:e.name||null,cali_idx:e.cali_idx,setting_id:e.setting_id||null})}}n.length>0&&await t(e,n)},he=async()=>{C(null);let e=Y7(d,s===`simple`?!0:h);if(!e.isValid){m(e.errors),u(`filament`);return}let n=ae?.displayName||R||null,a={material:d.material,subtype:d.subtype||null,brand:d.brand||null,color_name:d.color_name||null,rgba:d.rgba||null,extra_colors:d.extra_colors||null,effect_type:d.effect_type||null,label_weight:d.label_weight,core_weight:d.core_weight,core_weight_catalog_id:d.core_weight_catalog_id,weight_used:d.weight_used,slicer_filament:d.slicer_filament||null,slicer_filament_name:n,nozzle_temp_min:null,nozzle_temp_max:null,note:d.note||null,cost_per_kg:d.cost_per_kg,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,last_scale_weight:null,last_weighed_at:null,category:d.category.trim()||null,low_stock_threshold_pct:d.low_stock_threshold_pct};x(!0);try{if(_>1){let e=r?await Q.bulkCreateSpoolmanInventorySpools(a,_):await Q.bulkCreateSpools(a,_),n=r&&e&&typeof e==`object`&&`created`in e?e.created:e;for(let e of n)await me(e.id);n.length>0&&t(n[0])}else{let e=r?await Q.createSpoolmanInventorySpool(a):await Q.createSpool(a);await me(e.id),t(e)}}catch{C(i(`spoolbuddy.writeTag.createFailed`,`Failed to create spool`))}finally{x(!1)}},ge=`#${(d.rgba||`808080FF`).slice(0,6)}`;return(0,K.jsxs)(`div`,{className:`p-3 space-y-3 overflow-y-auto h-full`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`span`,{className:`text-sm text-zinc-200`,children:i(`spoolbuddy.writeTag.viewMode`,`View`)}),(0,K.jsxs)(`div`,{className:`flex rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>c(`simple`),className:`px-3 py-1.5 text-xs font-medium ${s===`simple`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:i(`spoolbuddy.writeTag.simpleView`,`Simple`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>c(`full`),className:`px-3 py-1.5 text-xs font-medium ${s===`full`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:i(`spoolbuddy.writeTag.fullView`,`Full`)})]})]}),s===`simple`?n?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-6 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,K.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:n.rgba?Wd(n.rgba):{backgroundColor:`#666`}}),(0,K.jsxs)(`p`,{className:`text-white font-medium`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,K.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:n.color_name}),(0,K.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[n.label_weight,`g`]}),(0,K.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:i(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]}):(0,K.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.material`,`Material`)}),(0,K.jsx)(`select`,{value:d.material,onChange:e=>fe(`material`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,children:XHe.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))})]}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.colorName`,`Color Name`)}),(0,K.jsx)(`input`,{type:`text`,value:d.color_name,onChange:e=>fe(`color_name`,e.target.value),placeholder:`Jade White`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.color`,`Color`)}),(0,K.jsx)(`input`,{type:`color`,value:ge,onChange:e=>fe(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`),className:`w-10 h-9 bg-transparent border border-bambu-dark-tertiary rounded cursor-pointer`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.brand`,`Brand`)}),(0,K.jsx)(`input`,{type:`text`,value:d.brand,onChange:e=>fe(`brand`,e.target.value),placeholder:`Polymaker`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.weight`,`Weight (g)`)}),(0,K.jsx)(`input`,{type:`number`,value:d.label_weight,onChange:e=>fe(`label_weight`,parseInt(e.target.value)||0),min:0,max:1e4,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`})]}),(0,K.jsx)(`button`,{onClick:he,disabled:b||!d.material,className:`w-full py-2.5 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:b?i(`spoolbuddy.writeTag.creating`,`Creating...`):i(`spoolbuddy.writeTag.createSpool`,`Create Spool`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`span`,{className:`text-sm text-zinc-200`,children:i(`inventory.quickAdd`,`Quick Add`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${h?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`span`,{className:`inline-block h-4.5 w-4.5 rounded-full bg-white transition-transform ${h?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{className:`flex border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,K.jsx)(`button`,{onClick:()=>u(`filament`),className:`flex-1 py-2.5 text-sm font-medium ${l===`filament`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:i(`inventory.filamentInfoTab`,`Filament`)}),!h&&(0,K.jsx)(`button`,{onClick:()=>u(`pa-profile`),className:`flex-1 py-2.5 text-sm font-medium ${l===`pa-profile`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:i(`inventory.paProfileTab`,`PA Profile`)})]}),(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-3`,children:l===`filament`?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(X7,{formData:d,updateField:fe,cloudAuthenticated:w,loadingCloudPresets:E,presetInputValue:R,setPresetInputValue:z,selectedPresetOption:ae,filamentOptions:ie,availableBrands:ue,availableMaterials:de,quickAdd:h,quantity:_,onQuantityChange:v,errors:p}),(0,K.jsx)(Z7,{formData:d,updateField:fe,recentColors:B,onColorUsed:pe,catalogColors:I}),(0,K.jsx)(Q7,{formData:d,updateField:fe,spoolCatalog:P,currencySymbol:e,availableCategories:Array.from(new Set(a.map(e=>e.category?.trim()).filter(e=>!!e))).sort((e,t)=>e.localeCompare(t)),globalLowStockThreshold:o?.low_stock_threshold??20})]}):(0,K.jsx)($7,{formData:d,updateField:fe,printersWithCalibrations:ee,selectedProfiles:te,setSelectedProfiles:ne,expandedPrinters:re,setExpandedPrinters:U})})]}),S&&(0,K.jsx)(`div`,{className:`text-sm text-red-400 bg-red-900/20 border border-red-900/40 rounded-lg px-3 py-2`,children:S}),s===`full`&&(0,K.jsx)(`button`,{onClick:he,disabled:b,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:b?i(`spoolbuddy.writeTag.creating`,`Creating...`):i(`spoolbuddy.writeTag.createSpool`,`Create Spool`)}),s===`full`&&n&&(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-4 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,K.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:n.rgba?Wd(n.rgba):{backgroundColor:`#666`}}),(0,K.jsxs)(`p`,{className:`text-white font-medium`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,K.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:n.color_name}),(0,K.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[n.label_weight,`g`]}),(0,K.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:i(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]})]})}function eUe({writeStatus:e,writeMessage:t,selectedSpool:n,tagOnReader:r,tagUid:i,deviceOnline:a,canWrite:o,isReplace:s,canUntag:c,untagging:l,onWrite:u,onUntag:d,onCancel:f,onRetry:p,t:m}){if(e===`success`)return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,K.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-green-500/20 flex items-center justify-center`,children:(0,K.jsx)(`svg`,{className:`w-8 h-8 text-green-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 13l4 4L19 7`})})}),(0,K.jsx)(`p`,{className:`text-green-400 font-medium`,children:t}),n&&(0,K.jsxs)(`p`,{className:`text-zinc-400 text-sm`,children:[n.brand?`${n.brand} `:``,n.material,n.color_name?` - ${n.color_name}`:``]})]});if(e===`error`)return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,K.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,K.jsx)(`svg`,{className:`w-8 h-8 text-red-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})}),(0,K.jsx)(`p`,{className:`text-red-400 font-medium`,children:t}),(0,K.jsx)(`button`,{onClick:p,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-white text-sm rounded transition-colors`,children:m(`spoolbuddy.writeTag.tryAgain`,`Try Again`)})]});if(e===`writing`)return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,K.jsxs)(`div`,{className:`relative w-16 h-16`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-bambu-green/30 animate-ping`}),(0,K.jsx)(`div`,{className:`absolute inset-2 rounded-full border-2 border-bambu-green/50 animate-pulse`}),(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,K.jsx)(J9,{className:`w-8 h-8 text-bambu-green`})})]}),(0,K.jsx)(`p`,{className:`text-bambu-green font-medium`,children:m(`spoolbuddy.writeTag.writing`,`Writing tag...`)}),(0,K.jsx)(`p`,{className:`text-zinc-500 text-xs`,children:t}),(0,K.jsx)(`button`,{onClick:f,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-zinc-400 text-sm rounded transition-colors`,children:m(`spoolbuddy.writeTag.cancel`,`Cancel`)})]});if(!a)return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,K.jsx)(J9,{className:`w-12 h-12 text-zinc-600`}),(0,K.jsx)(`p`,{className:`text-zinc-500 text-sm`,children:m(`spoolbuddy.writeTag.deviceOffline`,`SpoolBuddy is offline`)})]});if(!n)return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,K.jsx)(J9,{className:`w-12 h-12 text-zinc-600`}),(0,K.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:m(`spoolbuddy.writeTag.selectSpool`,`Select a spool, then place a blank NTAG on the reader`)})]});let h=n.rgba?Wd(n.rgba):{backgroundColor:`#666`};return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4 w-full`,children:[(0,K.jsx)(`div`,{className:`relative w-16 h-16`,children:r?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`absolute inset-0 rounded-full bg-bambu-green/10`}),(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,K.jsx)(J9,{className:`w-8 h-8 text-bambu-green`})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-zinc-600 animate-pulse`}),(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,K.jsx)(J9,{className:`w-8 h-8 text-zinc-500`})})]})}),r?(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`p`,{className:`text-bambu-green text-sm font-medium`,children:m(`spoolbuddy.writeTag.tagReady`,`Tag detected — ready to write`)}),i&&(0,K.jsx)(`p`,{className:`text-zinc-500 text-xs font-mono`,children:i})]}):(0,K.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:m(`spoolbuddy.writeTag.placeTag`,`Place an NTAG on the reader`)}),(0,K.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-3 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-8 h-8 rounded-full border border-white/10 shrink-0`,style:h}),(0,K.jsxs)(`div`,{className:`text-left min-w-0`,children:[(0,K.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,K.jsx)(`p`,{className:`text-zinc-400 text-xs`,children:n.color_name})]})]}),(0,K.jsxs)(`div`,{className:`text-xs text-zinc-500`,children:[n.label_weight,`g`]})]}),s&&n.tag_uid&&(0,K.jsx)(`p`,{className:`text-yellow-500/80 text-xs`,children:m(`spoolbuddy.writeTag.replaceWarning`,`Old tag will be unlinked. New tag will replace it.`)}),(0,K.jsx)(`button`,{onClick:u,disabled:!o,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-40 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors text-sm`,children:s?m(`spoolbuddy.writeTag.replaceTag`,`Replace Tag`):m(`spoolbuddy.writeTag.writeTag`,`Write Tag`)}),s&&c&&(0,K.jsx)(`button`,{onClick:d,disabled:l,className:`w-full py-2.5 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary disabled:opacity-40 disabled:cursor-not-allowed text-zinc-200 rounded-lg transition-colors text-sm`,children:l?m(`spoolbuddy.writeTag.untagging`,`Removing tag...`):m(`spoolbuddy.writeTag.untagSpool`,`Untag Selected Spool`)})]})}function J9({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,children:[(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0`}),(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})}var tUe=`spoolbuddy-default-core-weight`;function nUe(){try{let e=localStorage.getItem(tUe);if(e){let t=parseInt(e,10);if(t>=0&&t<=500)return t}}catch{}return 250}function rUe({spool:e,liveScaleWeight:t,persistedGrossWeight:n,onClose:r,onSyncWeight:i,onAssignToAms:a,isAssigned:o,onUnassignFromAms:s,className:c}){let{t:l}=G(),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),{data:g}=q({queryKey:[`spool-k-profiles`,e.id],queryFn:()=>Q.getSpoolKProfiles(e.id),enabled:!e.k_profiles||e.k_profiles.length===0,staleTime:300*1e3}),_=e.k_profiles&&e.k_profiles.length>0?e.k_profiles:g,v=Ud(e.rgba),b=e.core_weight&&e.core_weight>0?e.core_weight:nUe(),x=t===null?null:Math.round(Math.max(0,t)),S=m??(n===void 0?x:n===null?null:Math.round(Math.max(0,n))),C=Math.round(Math.max(0,(e.label_weight||0)-(e.weight_used||0))),w=x!==null&&x>=10?Math.round(Math.max(0,x-b)):C,T=Math.round(e.label_weight||1e3),E=T>0?Math.min(100,Math.round(w/T*100)):null,D=E===null?`#808080`:E>50?`#22c55e`:E>20?`#eab308`:`#ef4444`,O=Math.max(0,(e.label_weight||0)-(e.weight_used||0))+b,k=x===null?null:x-O,A=k===null?null:Math.abs(k)<=50,j=S??Math.round(O),M=e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null?`${e.nozzle_temp_min}-${e.nozzle_temp_max}\u00B0C`:null,N=e.slicer_filament_name||e.slicer_filament||null,P=e.note?.trim()||null,F=_&&_.length>0?Array.from(new Set(_.map(e=>e.k_value.toFixed(3)))).join(`, `):null,I=async()=>{if(t===null)return;let n=Math.round(Math.max(0,t));d(!0);try{await nd.updateSpoolWeight(e.id,n),h(n),p(!0),i?.(),setTimeout(()=>p(!1),3e3)}catch(e){console.error(`Failed to sync weight:`,e)}finally{d(!1)}};return(0,K.jsxs)(`div`,{className:`flex flex-col items-center space-y-4 max-w-md ${c??``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-5`,children:[(0,K.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,K.jsx)(j9,{color:v,isEmpty:!1,size:100}),E!==null&&(0,K.jsxs)(`div`,{className:`absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg`,style:{backgroundColor:D},children:[E,`%`]})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:e.color_name||`Unknown color`}),(0,K.jsxs)(`span`,{className:`text-xs font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,K.jsxs)(`p`,{className:`text-sm text-zinc-400`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]}),(0,K.jsxs)(`div`,{className:`mt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-3xl font-bold font-mono text-zinc-100`,children:[w,`g`]}),(0,K.jsxs)(`span`,{className:`text-sm text-zinc-500`,children:[`/ `,T,`g`]})]}),(0,K.jsx)(`p`,{className:`text-xs text-zinc-500 mt-0.5`,children:l(`spoolbuddy.spool.remaining`,`Remaining`)}),(0,K.jsx)(`div`,{className:`mt-2 max-w-xs`,children:(0,K.jsx)(`div`,{className:`h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${E??0}%`,backgroundColor:D}})})})]})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.grossWeight`,`Gross weight`)}),(0,K.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[j,`g`]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.spool.coreWeight`,`Core`)}),(0,K.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[b,`g`]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.spoolSize`,`Spool size`)}),(0,K.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[T,`g`]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.spool.scaleWeight`,`Scale`)}),x===null?(0,K.jsx)(`span`,{className:`text-zinc-500`,children:`—`}):(0,K.jsxs)(`span`,{className:`flex items-center gap-1 font-mono ${A?`text-green-500`:`text-yellow-500`}`,children:[x,`g`,A?(0,K.jsx)($o,{className:`w-3.5 h-3.5`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(vu,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`button`,{onClick:I,className:`p-1 hover:bg-green-500/20 rounded transition-colors text-green-500`,title:l(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`),children:(0,K.jsx)(Cl,{className:`w-4 h-4`})})]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.tagId`,`Tag`)}),(0,K.jsx)(`span`,{className:`font-mono text-xs text-zinc-400 truncate max-w-[120px]`,title:e.tag_uid||``,children:e.tag_uid?e.tag_uid.slice(-8):`—`})]}),M&&(0,K.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.nozzleTemp`,`Nozzle`)}),(0,K.jsx)(`span`,{className:`font-mono text-zinc-300`,children:M})]}),e.cost_per_kg!=null&&e.cost_per_kg>0&&(0,K.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.costPerKg`,`Cost/kg`)}),(0,K.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[e.cost_per_kg.toFixed(2),`/kg`]})]}),F&&(0,K.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.kProfiles`,`K-Profile`)}),(0,K.jsx)(`span`,{className:`font-mono text-zinc-300 truncate max-w-[220px] text-right`,title:F,children:F})]}),N&&(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-xs text-zinc-500 mb-1`,children:l(`spoolbuddy.inventory.slicerFilament`,`Slicer Filament`)}),(0,K.jsx)(`p`,{className:`text-sm text-zinc-300 whitespace-pre-wrap break-words`,children:N})]}),P&&(0,K.jsxs)(`div`,{className:`col-span-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-zinc-500 mb-1`,children:l(`spoolbuddy.inventory.note`,`Note`)}),(0,K.jsx)(`p`,{className:`text-sm leading-5 text-zinc-300 whitespace-pre-wrap break-words max-h-[3.75rem] overflow-y-auto pr-1`,children:P})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[a&&(0,K.jsx)(`button`,{onClick:o?void 0:a,disabled:!!o,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px] disabled:opacity-50 disabled:cursor-not-allowed`,children:l(`spoolbuddy.modal.assignToAms`,`Assign to AMS`)}),s&&(0,K.jsxs)(`button`,{onClick:s,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-red-600/20 text-red-400 hover:bg-red-600/30 transition-colors min-h-[44px]`,children:[(0,K.jsx)(xu,{className:`w-4 h-4 inline mr-1`}),l(`inventory.unassignSpool`)]}),(0,K.jsx)(`button`,{onClick:I,disabled:t===null||u,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${f?`bg-green-600/20 text-green-400`:a?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed`:`bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed`}`,children:u?`...`:f?l(`spoolbuddy.dashboard.weightSynced`,`Synced!`):l(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`)}),r&&(0,K.jsx)(`button`,{onClick:r,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:l(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function iUe(e){return Ud(e.rgba)}function aUe(e){return Math.max(0,e.label_weight-e.weight_used)}function oUe(e){return e.label_weight<=0?0:Math.max(0,Math.min(100,(e.label_weight-e.weight_used)/e.label_weight*100))}function sUe(e){let t=[e.material];return e.subtype&&t.push(e.subtype),t.join(` `)}function Y9(e){let t=e.ams_id===254||e.ams_id===255,n=!t&&e.ams_id>=128;return IK(e.ams_id,e.tray_id,n,t)}function cUe({color:e,size:t=56}){return(0,K.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 56 56`,children:[(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:e}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:e,style:{filter:`brightness(0.85)`}}),(0,K.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}function lUe(){let{sbState:e,selectedPrinterId:t}=Qn(),{t:n}=G(),{showToast:r}=xd(),i=Qa(),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`all`),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!1),{data:p}=q({queryKey:[`spoolman-settings`],queryFn:Q.getSpoolmanSettings,staleTime:300*1e3}),m=p?.spoolman_enabled===`true`&&!!p?.spoolman_url,{data:h=[],isLoading:g,refetch:_}=q({queryKey:m?[`spoolman-inventory-spools`]:[`inventory-spools`],queryFn:()=>m?Q.getSpoolmanInventorySpools(!1):Q.getSpools(!1),enabled:p!==void 0,refetchInterval:3e4}),{data:v=[]}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),refetchInterval:3e4,enabled:!m}),{data:b=[]}=q({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Q.getSpoolmanSlotAssignments(),refetchInterval:3e4,enabled:m}),x=J({mutationFn:e=>Q.unassignSpoolmanSlot(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),i.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},onError:()=>r(n(`inventory.unassignFailed`,`Failed to unassign spool`),`error`)}),S=(0,y.useMemo)(()=>{if(m){let e={};return b.forEach(t=>{e[t.spoolman_spool_id]={ams_id:t.ams_id,tray_id:t.tray_id}}),e}let e={};return v.forEach(t=>{e[t.spool_id]={ams_id:t.ams_id,tray_id:t.tray_id,printer_name:t.printer_name}}),e},[m,v,b]),C=(0,y.useMemo)(()=>h.filter(e=>!e.archived_at),[h]),w=(0,y.useMemo)(()=>new Set(Object.keys(S).map(Number)),[S]),T=(0,y.useMemo)(()=>C.filter(e=>w.has(e.id)).length,[C,w]),E=(0,y.useMemo)(()=>{let e=new Set;return C.forEach(t=>e.add(t.material)),Array.from(e).sort()},[C]),D=(0,y.useMemo)(()=>{let e=C;return s===`in_ams`?e=e.filter(e=>w.has(e.id)):s!==`all`&&(e=e.filter(e=>e.material===s)),e=ZG(e,a.trim()),[...e].sort((e,t)=>{let n=+!w.has(e.id),r=+!w.has(t.id);return n===r?new Date(t.updated_at).getTime()-new Date(e.updated_at).getTime():n-r})},[C,s,a,w]);return(0,K.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`px-3 pt-3 pb-2 space-y-2.5`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-white/40`}),(0,K.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:n(`spoolbuddy.inventory.searchPlaceholder`,`Search spools...`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-white/30 focus:outline-none focus:border-bambu-green`}),a&&(0,K.jsx)(`button`,{onClick:()=>o(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-white/40 hover:text-white/60`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto no-scrollbar`,children:[(0,K.jsx)(X9,{active:s===`all`,onClick:()=>c(`all`),label:`${n(`spoolbuddy.inventory.all`,`All`)} (${C.length})`,green:!0}),T>0&&(0,K.jsx)(X9,{active:s===`in_ams`,onClick:()=>c(`in_ams`),label:`${n(`spoolbuddy.inventory.inAms`,`In AMS`)} (${T})`}),E.map(e=>(0,K.jsx)(X9,{active:s===e,onClick:()=>c(s===e?`all`:e),label:e},e))]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3`,children:g?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(`div`,{className:`w-8 h-8 border-2 border-bambu-green border-t-transparent rounded-full animate-spin`})}):D.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-white/30`,children:[(0,K.jsx)(cl,{className:`w-12 h-12 mb-3`}),(0,K.jsx)(`p`,{className:`text-sm`,children:a||s!==`all`?n(`spoolbuddy.inventory.noResults`,`No spools match your filters`):n(`spoolbuddy.inventory.empty`,`No spools in inventory`)})]}):(0,K.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(130px,1fr))] gap-2`,children:D.map(e=>(0,K.jsx)(uUe,{spool:e,assignment:S[e.id],onClick:()=>u(e.id)},e.id))})}),l!=null&&(()=>{let n=h.find(e=>e.id===l);return n?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(dUe,{spool:n,assignment:S[n.id],sbState:e,onSyncWeight:()=>{_()},onAssignToAms:()=>f(!0),onUnassignFromAms:m&&S[n.id]?()=>x.mutate(n.id):void 0,onClose:()=>{u(null),f(!1)}}),(0,K.jsx)(V9,{isOpen:d,onClose:()=>f(!1),spool:n,printerId:t,spoolmanMode:m})]}):null})()]})}function X9({active:e,onClick:t,label:n,green:r}){return(0,K.jsx)(`button`,{onClick:t,className:`px-4 py-1.5 rounded-full text-sm font-medium border whitespace-nowrap shrink-0 transition-colors ${e?r?`bg-bambu-green/20 text-bambu-green border-bambu-green/50`:`bg-white/10 text-white border-white/20`:`bg-transparent text-white/40 border-bambu-dark-tertiary hover:text-white/60`}`,children:n})}function uUe({spool:e,assignment:t,onClick:n}){let r=iUe(e),i=oUe(e),a=aUe(e),o=Hd(e.color_name,e.rgba);return(0,K.jsxs)(`button`,{onClick:n,className:`bg-bambu-dark-secondary rounded-xl p-3 flex flex-col items-center text-center gap-1.5 border border-transparent hover:border-bambu-green/50 transition-colors`,children:[(0,K.jsx)(cUe,{color:r,size:56}),(0,K.jsx)(`p`,{className:`text-xs font-semibold text-white leading-tight truncate w-full`,children:sUe(e)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 max-w-full`,children:[(0,K.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full shrink-0 border border-white/10`,style:Wd(e.rgba)}),(0,K.jsx)(`span`,{className:`text-[11px] text-white/50 truncate`,children:o||`-`})]}),(0,K.jsxs)(`div`,{className:`w-full space-y-0.5`,children:[(0,K.jsx)(`div`,{className:`h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full ${i>50?`bg-bambu-green`:i>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(i,100)}%`}})}),(0,K.jsxs)(`p`,{className:`text-[11px] text-white/40`,children:[Math.round(a),`g (`,Math.round(i),`%)`]})]}),t&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded text-[10px] font-bold bg-bambu-green/20 text-bambu-green`,children:Y9(t)})]})}function dUe({spool:e,assignment:t,sbState:n,onSyncWeight:r,onAssignToAms:i,onUnassignFromAms:a,onClose:o}){let s=n.deviceOnline&&n.weight!==null?Math.round(n.weight):null,c=e.last_scale_weight==null?null:Math.round(e.last_scale_weight);return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/70 flex items-center justify-center p-4`,onClick:o,children:(0,K.jsx)(`div`,{className:`w-full max-w-md bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-2xl p-4 overflow-y-auto max-h-[90vh]`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[t&&(0,K.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,K.jsx)(`span`,{className:`px-2.5 py-1 rounded-md text-xs font-bold bg-bambu-green/20 text-bambu-green`,children:Y9(t)}),t.printer_name&&(0,K.jsx)(`span`,{className:`text-xs text-zinc-400`,children:t.printer_name})]}),(0,K.jsx)(`div`,{className:`flex justify-center`,children:(0,K.jsx)(rUe,{spool:e,liveScaleWeight:s,persistedGrossWeight:c,onSyncWeight:r,onAssignToAms:i,isAssigned:!!t,onUnassignFromAms:a,onClose:o,className:`max-w-md`})})]})})})}var fUe=class extends y.Component{state={error:null,errorInfo:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.setState({errorInfo:t}),console.error(`React crash:`,e,t)}render(){return this.state.error?(0,K.jsxs)(`div`,{style:{padding:24,color:`#ef4444`,backgroundColor:`#18181b`,minHeight:`100vh`,fontFamily:`monospace`},children:[(0,K.jsx)(`h1`,{style:{fontSize:20,marginBottom:12},children:`UI Crash`}),(0,K.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,fontSize:14},children:this.state.error.message}),(0,K.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,fontSize:12,color:`#a1a1aa`,marginTop:12},children:this.state.error.stack}),(0,K.jsx)(`button`,{onClick:()=>{this.setState({error:null,errorInfo:null})},style:{marginTop:16,padding:`8px 16px`,backgroundColor:`#3b82f6`,color:`#fff`,border:`none`,borderRadius:8,cursor:`pointer`},children:`Retry`})]}):this.props.children}},pUe=new Ya({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function mUe(){return R7(),null}function Z9({children:e}){return QVe(),(0,K.jsx)(K.Fragment,{children:e})}function Q9({children:e}){let{authEnabled:t,loading:n,user:r}=sd(),i=Kn();return n?(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):t&&!r?(0,K.jsx)(wr,{to:`/login`,replace:!0,state:{from:i}}):(0,K.jsx)(K.Fragment,{children:e})}function $9({permission:e,children:t}){let{authEnabled:n,loading:r,user:i,hasPermission:a}=sd(),o=Kn();return r?(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):n?i?a(e)?(0,K.jsx)(K.Fragment,{children:t}):(0,K.jsx)(wr,{to:`/`,replace:!0}):(0,K.jsx)(wr,{to:`/login`,replace:!0,state:{from:o}}):(0,K.jsx)(K.Fragment,{children:t})}function hUe({children:e}){let{authEnabled:t,loading:n}=sd();return n?(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):t?(0,K.jsx)(wr,{to:`/login`,replace:!0}):(0,K.jsx)(K.Fragment,{children:e})}function gUe(){return(0,K.jsx)(fUe,{children:(0,K.jsx)(wd,{children:(0,K.jsx)($a,{client:pUe,children:(0,K.jsx)(od,{children:(0,K.jsx)(ld,{children:(0,K.jsx)($Ve,{children:(0,K.jsxs)(NEe,{children:[(0,K.jsx)(mUe,{}),(0,K.jsx)(_i,{children:(0,K.jsxs)(Or,{children:[(0,K.jsx)(Er,{path:`/setup`,element:(0,K.jsx)(hUe,{children:(0,K.jsx)(YVe,{})})}),(0,K.jsx)(Er,{path:`/login`,element:(0,K.jsx)(JVe,{})}),(0,K.jsx)(Er,{path:`/camera/:printerId`,element:(0,K.jsx)(zBe,{})}),(0,K.jsx)(Er,{path:`/overlay/:printerId`,element:(0,K.jsx)(WBe,{})}),(0,K.jsxs)(Er,{element:(0,K.jsx)(Q9,{children:(0,K.jsx)(Z9,{children:(0,K.jsx)(dHe,{})})}),children:[(0,K.jsx)(Er,{path:`spoolbuddy`,element:(0,K.jsx)(MHe,{})}),(0,K.jsx)(Er,{path:`spoolbuddy/ams`,element:(0,K.jsx)(FHe,{})}),(0,K.jsx)(Er,{path:`spoolbuddy/write-tag`,element:(0,K.jsx)(ZHe,{})}),(0,K.jsx)(Er,{path:`spoolbuddy/inventory`,element:(0,K.jsx)(lUe,{})}),(0,K.jsx)(Er,{path:`spoolbuddy/settings`,element:(0,K.jsx)(qHe,{})}),(0,K.jsx)(Er,{path:`spoolbuddy/calibration`,element:(0,K.jsx)(YHe,{})})]}),(0,K.jsxs)(Er,{element:(0,K.jsx)(Q9,{children:(0,K.jsx)(Z9,{children:(0,K.jsx)(Xf,{})})}),children:[(0,K.jsx)(Er,{index:!0,element:(0,K.jsx)(OEe,{})}),(0,K.jsx)(Er,{path:`archives`,element:(0,K.jsx)(QFe,{})}),(0,K.jsx)(Er,{path:`queue`,element:(0,K.jsx)(XLe,{})}),(0,K.jsx)(Er,{path:`stats`,element:(0,K.jsx)(hRe,{})}),(0,K.jsx)(Er,{path:`profiles`,element:(0,K.jsx)(oBe,{})}),(0,K.jsx)(Er,{path:`maintenance`,element:(0,K.jsx)(dBe,{})}),(0,K.jsx)(Er,{path:`projects`,element:(0,K.jsx)(mBe,{})}),(0,K.jsx)(Er,{path:`projects/:id`,element:(0,K.jsx)(bBe,{})}),(0,K.jsx)(Er,{path:`inventory`,element:(0,K.jsx)(jVe,{})}),(0,K.jsx)(Er,{path:`files`,element:(0,K.jsx)(MBe,{})}),(0,K.jsx)(Er,{path:`files/trash`,element:(0,K.jsx)(PBe,{})}),(0,K.jsx)(Er,{path:`makerworld`,element:(0,K.jsx)($9,{permission:`makerworld:view`,children:(0,K.jsx)(zVe,{})})}),(0,K.jsx)(Er,{path:`settings`,element:(0,K.jsx)($9,{permission:`settings:read`,children:(0,K.jsx)(Lze,{})})}),(0,K.jsx)(Er,{path:`groups/new`,element:(0,K.jsx)($9,{permission:`groups:create`,children:(0,K.jsx)(B7,{})})}),(0,K.jsx)(Er,{path:`groups/:id/edit`,element:(0,K.jsx)($9,{permission:`groups:update`,children:(0,K.jsx)(B7,{})})}),(0,K.jsx)(Er,{path:`users`,element:(0,K.jsx)(wr,{to:`/settings?tab=users`,replace:!0})}),(0,K.jsx)(Er,{path:`groups`,element:(0,K.jsx)(wr,{to:`/settings?tab=users`,replace:!0})}),(0,K.jsx)(Er,{path:`system`,element:(0,K.jsx)(UVe,{})}),(0,K.jsx)(Er,{path:`notifications`,element:(0,K.jsx)(XVe,{})}),(0,K.jsx)(Er,{path:`gcode-viewer`,element:(0,K.jsx)(ZVe,{})}),(0,K.jsx)(Er,{path:`external/:id`,element:(0,K.jsx)(GBe,{})}),(0,K.jsx)(Er,{path:`camera-tokens`,element:(0,K.jsx)(wr,{to:`/settings?tab=apikeys#card-camera-tokens`,replace:!0})})]})]})})]})})})})})})})}(0,b.createRoot)(document.getElementById(`root`)).render((0,K.jsx)(y.StrictMode,{children:(0,K.jsx)(gUe,{})})); \ No newline at end of file +In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}()}function w(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n1&&arguments[1]!==void 0?arguments[1]:e;this.caretPosition=e,this.caretPositionEnd=t}},{key:`getInputCandidates`,value:function(e){var t=this,n=this.options,r=n.layoutCandidates,i=n.layoutCandidatesCaseSensitiveMatch;if(!r||T(r)!==`object`)return{};var a=Object.keys(r).filter((function(n){var r=e.substring(0,t.getCaretPositionEnd()||0)||e,a=RegExp(`${t.utilities.escapeRegex(n)}\$`,i?`g`:`gi`);return!!C(r.matchAll(a)).length}));if(a.length>1){var o=a.sort((function(e,t){return t.length-e.length}))[0];return{candidateKey:o,candidateValue:r[o]}}if(a.length){var s=a[0];return{candidateKey:s,candidateValue:r[s]}}return{}}},{key:`showCandidatesBox`,value:function(e,t,n){var r=this;this.candidateBox&&this.candidateBox.show({candidateValue:t,targetElement:n,onSelect:function(t,n){var i=r.options,a=i.layoutCandidatesCaseSensitiveMatch,o=i.disableCandidateNormalization,s=i.enableLayoutCandidatesKeyPress,c=t;o||(c=t.normalize(`NFD`)),typeof r.options.beforeInputUpdate==`function`&&r.options.beforeInputUpdate(r);var l=r.getInput(r.options.inputName,!0),u=r.getCaretPositionEnd()||0,d=l.substring(0,u||0)||l,f=RegExp(`${r.utilities.escapeRegex(e)}\$`,a?`g`:`gi`),p=d.replace(f,c),m=l.replace(d,p),h=p.length-d.length,g=(u||l.length)+h;g<0&&(g=0),r.setInput(m,r.options.inputName,!0),r.setCaretPosition(g),s&&typeof r.options.onKeyPress==`function`&&r.options.onKeyPress(t,n),typeof r.options.onChange==`function`&&r.options.onChange(r.getInput(r.options.inputName,!0),n),typeof r.options.onChangeAll==`function`&&r.options.onChangeAll(r.getAllInputs(),n)}})}},{key:`handleButtonClicked`,value:function(e,t){var n=this.options,r=n.inputName,i=r===void 0?this.defaultName:r,a=n.debug;if(e!==`{//}`){this.input[i]||(this.input[i]=``),typeof this.options.beforeInputUpdate==`function`&&this.options.beforeInputUpdate(this);var o=this.utilities.getUpdatedInput(e,this.input[i],this.caretPosition,this.caretPositionEnd);if(this.utilities.isStandardButton(e)&&this.activeInputElement&&this.input[i]&&this.input[i]===o&&this.caretPosition===0&&this.caretPositionEnd===o.length)return this.setInput(``,this.options.inputName,!0),this.setCaretPosition(0),this.activeInputElement.value=``,this.activeInputElement.setSelectionRange(0,0),void this.handleButtonClicked(e,t);if(typeof this.options.onKeyPress==`function`&&this.options.onKeyPress(e,t),this.input[i]!==o&&(!this.options.inputPattern||this.options.inputPattern&&this.inputPatternIsValid(o))){if(this.options.maxLength&&this.utilities.handleMaxLength(this.input,o))return;var s=this.utilities.getUpdatedInput(e,this.input[i],this.caretPosition,this.caretPositionEnd,!0);if(this.setInput(s,this.options.inputName,!0),a&&console.log(`Input changed:`,this.getAllInputs()),this.options.debug&&console.log(`Caret at: `,this.getCaretPosition(),this.getCaretPositionEnd(),`(${this.keyboardDOMClass})`,t?.type),this.options.syncInstanceInputs&&this.syncInstanceInputs(),typeof this.options.onChange==`function`&&this.options.onChange(this.getInput(this.options.inputName,!0),t),typeof this.options.onChangeAll==`function`&&this.options.onChangeAll(this.getAllInputs(),t),t!=null&&t.target&&this.options.enableLayoutCandidates){var c,l=this.getInputCandidates(o),u=l.candidateKey,d=l.candidateValue;u&&d?this.showCandidatesBox(u,d,this.keyboardDOM):(c=this.candidateBox)==null||c.destroy()}}this.caretPositionEnd&&this.caretPosition!==this.caretPositionEnd&&(this.setCaretPosition(this.caretPositionEnd,this.caretPositionEnd),this.activeInputElement&&this.activeInputElement.setSelectionRange(this.caretPositionEnd,this.caretPositionEnd),this.options.debug&&console.log(`Caret position aligned`,this.caretPosition)),a&&console.log(`Key pressed:`,e)}}},{key:`getMouseHold`,value:function(){return this.isMouseHold}},{key:`setMouseHold`,value:function(e){this.options.syncInstanceInputs?this.dispatch((function(t){t.isMouseHold=e})):this.isMouseHold=e}},{key:`handleButtonMouseDown`,value:function(e,t){var n=this;t&&(this.options.preventMouseDownDefault&&t.preventDefault(),this.options.stopMouseDownPropagation&&t.stopPropagation(),t.target.classList.add(this.activeButtonClass)),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdTimeout&&clearTimeout(this.holdTimeout),this.setMouseHold(!0),this.options.disableButtonHold||(this.holdTimeout=window.setTimeout((function(){(n.getMouseHold()&&(!e.includes(`{`)&&!e.includes(`}`)||e===`{delete}`||e===`{backspace}`||e===`{bksp}`||e===`{space}`||e===`{tab}`)||e===`{arrowright}`||e===`{arrowleft}`||e===`{arrowup}`||e===`{arrowdown}`)&&(n.options.debug&&console.log(`Button held:`,e),n.handleButtonHold(e)),clearTimeout(n.holdTimeout)}),500))}},{key:`handleButtonMouseUp`,value:function(e,t){var n=this;t&&(this.options.preventMouseUpDefault&&t.preventDefault&&t.preventDefault(),this.options.stopMouseUpPropagation&&t.stopPropagation&&t.stopPropagation(),!(t.target===this.keyboardDOM||t.target&&this.keyboardDOM.contains(t.target)||this.candidateBox&&this.candidateBox.candidateBoxElement&&(t.target===this.candidateBox.candidateBoxElement||t.target&&this.candidateBox.candidateBoxElement.contains(t.target)))&&this.candidateBox&&this.candidateBox.destroy()),this.recurseButtons((function(e){e.classList.remove(n.activeButtonClass)})),this.setMouseHold(!1),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),e&&typeof this.options.onKeyReleased==`function`&&this.options.onKeyReleased(e,t)}},{key:`handleKeyboardContainerMouseDown`,value:function(e){this.options.preventMouseDownDefault&&e.preventDefault()}},{key:`handleButtonHold`,value:function(e){var t=this;this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdInteractionTimeout=window.setTimeout((function(){t.getMouseHold()?(t.handleButtonClicked(e),t.handleButtonHold(e)):clearTimeout(t.holdInteractionTimeout)}),100)}},{key:`syncInstanceInputs`,value:function(){var e=this;this.dispatch((function(t){t.replaceInput(e.input),t.setCaretPosition(e.caretPosition,e.caretPositionEnd)}))}},{key:`clearInput`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName;this.input[e]=``,this.setCaretPosition(0),this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:`getInput`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName,t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return this.options.syncInstanceInputs&&!t&&this.syncInstanceInputs(),this.options.rtl?`‫`+this.input[e].replace(`‫`,``).replace(`‬`,``)+`‬`:this.input[e]}},{key:`getAllInputs`,value:function(){var e=this,t={};return Object.keys(this.input).forEach((function(n){t[n]=e.getInput(n,!0)})),t}},{key:`setInput`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.options.inputName||this.defaultName,n=arguments.length>2?arguments[2]:void 0;this.input[t]=e,!n&&this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:`replaceInput`,value:function(e){this.input=e}},{key:`setOptions`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=this.changedOptions(e);this.options=Object.assign(this.options,e),t.length&&(this.options.debug&&console.log(`changedOptions`,t),this.onSetOptions(t),this.render())}},{key:`changedOptions`,value:function(e){var t=this;return Object.keys(e).filter((function(n){return JSON.stringify(e[n])!==JSON.stringify(t.options[n])}))}},{key:`onSetOptions`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];e.includes(`layoutName`)&&this.candidateBox&&this.candidateBox.destroy(),(e.includes(`layoutCandidatesPageSize`)||e.includes(`layoutCandidates`))&&this.candidateBox&&(this.candidateBox.destroy(),this.candidateBox=new S({utilities:this.utilities,options:this.options}))}},{key:`resetRows`,value:function(){this.keyboardRowsDOM&&this.keyboardRowsDOM.remove(),this.keyboardDOM.className=this.keyboardDOMClass,this.keyboardDOM.setAttribute(`data-skInstance`,this.currentInstanceName),this.buttonElements={}}},{key:`dispatch`,value:function(e){if(!window.SimpleKeyboardInstances)throw console.warn(`SimpleKeyboardInstances is not defined. Dispatch cannot be called.`),Error(`INSTANCES_VAR_ERROR`);return Object.keys(window.SimpleKeyboardInstances).forEach((function(t){e(window.SimpleKeyboardInstances[t],t)}))}},{key:`addButtonTheme`,value:function(e,t){var n=this;t&&e&&(e.split(` `).forEach((function(r){t.split(` `).forEach((function(t){n.options.buttonTheme||(n.options.buttonTheme=[]);var i=!1;n.options.buttonTheme.map((function(e){if(e!=null&&e.class.split(` `).includes(t)){i=!0;var n=e.buttons.split(` `);n.includes(r)||(i=!0,n.push(r),e.buttons=n.join(` `))}return e})),i||n.options.buttonTheme.push({class:t,buttons:e})}))})),this.render())}},{key:`removeButtonTheme`,value:function(e,t){var n=this;if(!e&&!t)return this.options.buttonTheme=[],void this.render();e&&Array.isArray(this.options.buttonTheme)&&this.options.buttonTheme.length&&(e.split(` `).forEach((function(e){var r;(r=n.options)==null||(r=r.buttonTheme)==null||r.map((function(r,i){if(r&&t&&t.includes(r.class)||!t){var a,o=r?.buttons.split(` `).filter((function(t){return t!==e}));r&&o!=null&&o.length?r.buttons=o.join(` `):((a=n.options.buttonTheme)==null||a.splice(i,1),r=null)}return r}))})),this.render())}},{key:`getButtonElement`,value:function(e){var t,n=this.buttonElements[e];return n&&(t=n.length>1?n:n[0]),t}},{key:`inputPatternIsValid`,value:function(e){var t,n=this.options.inputPattern;if((t=n instanceof RegExp?n:n[this.options.inputName||this.defaultName])&&e){var r=t.test(e);return this.options.debug&&console.log(`inputPattern ("${t}"): ${r?`passed`:`did not pass!`}`),r}return!0}},{key:`setEventListeners`,value:function(){if(this.isFirstKeyboardInstance||!this.allKeyboardInstances){this.options.debug&&console.log(`Caret handling started (${this.keyboardDOMClass})`);var e=this.options.physicalKeyboardHighlightPreventDefault,t=e!==void 0&&e;document.addEventListener(`keyup`,this.handleKeyUp,t),document.addEventListener(`keydown`,this.handleKeyDown,t),document.addEventListener(`mouseup`,this.handleMouseUp),document.addEventListener(`touchend`,this.handleTouchEnd),this.options.updateCaretOnSelectionChange&&document.addEventListener(`selectionchange`,this.handleSelectionChange),document.addEventListener(`select`,this.handleSelect)}}},{key:`handleKeyUp`,value:function(e){this.caretEventHandler(e),this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyUp(e)}},{key:`handleKeyDown`,value:function(e){this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyDown(e)}},{key:`handleMouseUp`,value:function(e){this.caretEventHandler(e)}},{key:`handleTouchEnd`,value:function(e){this.caretEventHandler(e)}},{key:`handleSelect`,value:function(e){this.caretEventHandler(e)}},{key:`handleSelectionChange`,value:function(e){navigator.userAgent.includes(`Firefox`)||this.caretEventHandler(e)}},{key:`caretEventHandler`,value:function(e){var t,n=this;e.target.tagName&&(t=e.target.tagName.toLowerCase()),this.dispatch((function(r){var i=e.target===r.keyboardDOM||e.target&&r.keyboardDOM.contains(e.target);if(n.options.syncInstanceInputs&&Array.isArray(e.path)&&(i=e.path.some((function(e){var t;return e==null||(t=e.hasAttribute)==null?void 0:t.call(e,`data-skInstance`)}))),(t===`textarea`||t===`input`&&[`text`,`search`,`url`,`tel`,`password`].includes(e.target.type))&&!r.options.disableCaretPositioning){var a=e.target.selectionStart,o=e.target.selectionEnd;r.options.rtl&&(a=r.utilities.getRtlOffset(a,r.getInput()),o=r.utilities.getRtlOffset(o,r.getInput())),r.setCaretPosition(a,o),r.activeInputElement=e.target,r.options.debug&&console.log(`Caret at: `,r.getCaretPosition(),r.getCaretPositionEnd(),e&&e.target.tagName.toLowerCase(),`(${r.keyboardDOMClass})`,e?.type)}else !r.options.disableCaretPositioning&&i||e?.type===`selectionchange`||(r.setCaretPosition(null),r.activeInputElement=null,r.options.debug&&console.log(`Caret position reset due to "${e?.type}" event`,e))}))}},{key:`recurseButtons`,value:function(e){var t=this;e&&Object.keys(this.buttonElements).forEach((function(n){return t.buttonElements[n].forEach(e)}))}},{key:`destroy`,value:function(){this.options.debug&&console.log(`Destroying simple-keyboard instance: ${this.currentInstanceName}`);var e=this.options.physicalKeyboardHighlightPreventDefault,t=e!==void 0&&e;document.removeEventListener(`keyup`,this.handleKeyUp,t),document.removeEventListener(`keydown`,this.handleKeyDown,t),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`touchend`,this.handleTouchEnd),document.removeEventListener(`select`,this.handleSelect),this.options.updateCaretOnSelectionChange&&document.removeEventListener(`selectionchange`,this.handleSelectionChange),document.onpointerup=null,document.ontouchend=null,document.ontouchcancel=null,document.onmouseup=null,this.recurseButtons((function(e){e&&=(e.onpointerdown=null,e.onpointerup=null,e.onpointercancel=null,e.ontouchstart=null,e.ontouchend=null,e.ontouchcancel=null,e.onclick=null,e.onmousedown=null,e.onmouseup=null,e.remove(),null)})),this.keyboardDOM.onpointerdown=null,this.keyboardDOM.ontouchstart=null,this.keyboardDOM.onmousedown=null,this.resetRows(),this.candidateBox&&=(this.candidateBox.destroy(),null),this.activeInputElement=null,this.keyboardDOM.removeAttribute(`data-skInstance`),this.keyboardDOM.innerHTML=``,window.SimpleKeyboardInstances[this.currentInstanceName]=null,delete window.SimpleKeyboardInstances[this.currentInstanceName],this.initialized=!1}},{key:`getButtonThemeClasses`,value:function(e){var t=this.options.buttonTheme,n=[];return Array.isArray(t)&&t.forEach((function(t){if(t&&t.class&&typeof t.class==`string`&&t.buttons&&typeof t.buttons==`string`){var r=t.class.split(` `);t.buttons.split(` `).includes(e)&&(n=[].concat(C(n),C(r)))}else console.warn(`Incorrect "buttonTheme". Please check the documentation.`,t)})),n}},{key:`setDOMButtonAttributes`,value:function(e,t){var n=this.options.buttonAttributes;Array.isArray(n)&&n.forEach((function(n){n.attribute&&typeof n.attribute==`string`&&n.value&&typeof n.value==`string`?n.buttons&&typeof n.buttons==`string`?n.buttons.split(` `).includes(e)&&t(n.attribute,n.value):t(n.attribute,n.value):console.warn(`Incorrect "buttonAttributes". Please check the documentation.`,n)}))}},{key:`onTouchDeviceDetected`,value:function(){this.processAutoTouchEvents(),this.disableContextualWindow()}},{key:`disableContextualWindow`,value:function(){window.oncontextmenu=function(e){var t;if((t=e.target.classList)!=null&&t.contains(`hg-button`))return e.preventDefault(),e.stopPropagation(),!1}}},{key:`processAutoTouchEvents`,value:function(){this.options.autoUseTouchEvents&&(this.options.useTouchEvents=!0,this.options.debug&&console.log(`autoUseTouchEvents: Touch device detected, useTouchEvents enabled.`))}},{key:`onInit`,value:function(){this.options.debug&&console.log(`${this.keyboardDOMClass} Initialized`),this.setEventListeners(),typeof this.options.onInit==`function`&&this.options.onInit(this)}},{key:`beforeFirstRender`,value:function(){this.utilities.isTouchDevice()&&this.onTouchDeviceDetected(),typeof this.options.beforeFirstRender==`function`&&this.options.beforeFirstRender(this),this.isFirstKeyboardInstance&&this.utilities.pointerEventsSupported()&&!this.options.useTouchEvents&&!this.options.useMouseEvents&&this.options.debug&&console.log(`Using PointerEvents as it is supported by this browser`),this.options.useTouchEvents&&this.options.debug&&console.log(`useTouchEvents has been enabled. Only touch events will be used.`)}},{key:`beforeRender`,value:function(){typeof this.options.beforeRender==`function`&&this.options.beforeRender(this)}},{key:`onRender`,value:function(){typeof this.options.onRender==`function`&&this.options.onRender(this)}},{key:`onModulesLoaded`,value:function(){typeof this.options.onModulesLoaded==`function`&&this.options.onModulesLoaded(this)}},{key:`loadModules`,value:function(){var e=this;Array.isArray(this.options.modules)&&(this.options.modules.forEach((function(t){var n=e.utilities.isConstructor(t)?new t(e):t(e);n.init&&n.init(e)})),this.keyboardPluginClasses=`modules-loaded`,this.render(),this.onModulesLoaded())}},{key:`getModuleProp`,value:function(e,t){return!!this.modules[e]&&this.modules[e][t]}},{key:`getModulesList`,value:function(){return Object.keys(this.modules)}},{key:`parseRowDOMContainers`,value:function(e,t,n,r){var i=this,a=Array.from(e.children),o=0;return a.length&&n.forEach((function(n,s){var c=r[s];if(!(c&&c>n))return!1;var l=n-o,u=c-o,d=document.createElement(`div`);d.className+=`hg-button-container`;var f=`${i.options.layoutName}-r${t}c${s}`;d.setAttribute(`data-skUID`,f);var p=a.splice(l,u-l+1);o+=u-l,p.forEach((function(e){return d.appendChild(e)})),a.splice(l,0,d),e.innerHTML=``,a.forEach((function(t){return e.appendChild(t)})),i.options.debug&&console.log(`rowDOMContainer`,p,l,u,o+1)})),e}},{key:`render`,value:function(){var e=this;this.resetRows(),this.initialized||this.beforeFirstRender(),this.beforeRender();var t=`hg-layout-${this.options.layoutName}`,n=this.options.layout||{default:["` 1 2 3 4 5 6 7 8 9 0 - = {bksp}",`{tab} q w e r t y u i o p [ ] \\`,`{lock} a s d f g h j k l ; ' {enter}`,`{shift} z x c v b n m , . / {shift}`,`.com @ {space}`],shift:[`~ ! @ # $ % ^ & * ( ) _ + {bksp}`,`{tab} Q W E R T Y U I O P { } |`,`{lock} A S D F G H J K L : " {enter}`,`{shift} Z X C V B N M < > ? {shift}`,`.com @ {space}`]},r=this.options.useTouchEvents||!1,i=r?`hg-touch-events`:``,a=this.options.useMouseEvents||!1,o=this.options.disableRowButtonContainers;this.keyboardDOM.className=this.getKeyboardClassString(this.options.theme,t,this.keyboardPluginClasses,i),this.keyboardDOM.setAttribute(`data-skInstance`,this.currentInstanceName),this.keyboardRowsDOM=document.createElement(`div`),this.keyboardRowsDOM.className=`hg-rows`,n[this.options.layoutName||this.defaultName].forEach((function(t,n){var i=t.split(` `);e.options.excludeFromLayout&&e.options.excludeFromLayout[e.options.layoutName||e.defaultName]&&(i=i.filter((function(t){return e.options.excludeFromLayout&&!e.options.excludeFromLayout[e.options.layoutName||e.defaultName].includes(t)})));var s=document.createElement(`div`);s.className+=`hg-row`;var c=[],l=[];i.forEach((function(t,i){var u,d=!o&&typeof t==`string`&&t.length>1&&t.indexOf(`[`)===0,f=!o&&typeof t==`string`&&t.length>1&&t.indexOf(`]`)===t.length-1;d&&(c.push(i),t=t.replace(/\[/g,``)),f&&(l.push(i),t=t.replace(/\]/g,``));var p=e.utilities.getButtonClass(t),m=e.utilities.getButtonDisplayName(t,e.options.display,e.options.mergeDisplay),h=e.options.useButtonTag?`button`:`div`,g=document.createElement(h);g.className+=`hg-button ${p}`,(u=g.classList).add.apply(u,C(e.getButtonThemeClasses(t))),e.setDOMButtonAttributes(t,(function(e,t){g.setAttribute(e,t)})),e.activeButtonClass=`hg-activeButton`,!e.utilities.pointerEventsSupported()||r||a?r?(g.ontouchstart=function(n){e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.ontouchend=function(n){e.handleButtonMouseUp(t,n)},g.ontouchcancel=function(n){e.handleButtonMouseUp(t,n)}):(g.onclick=function(n){e.setMouseHold(!1),typeof e.options.onKeyReleased==`function`||e.options.useMouseEvents&&e.options.clickOnMouseDown||e.handleButtonClicked(t,n)},g.onmousedown=function(n){(typeof e.options.onKeyReleased==`function`||e.options.useMouseEvents&&e.options.clickOnMouseDown)&&!e.isMouseHold&&e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.onmouseup=function(n){e.handleButtonMouseUp(t,n)}):(g.onpointerdown=function(n){e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.onpointerup=function(n){e.handleButtonMouseUp(t,n)},g.onpointercancel=function(n){e.handleButtonMouseUp(t,n)}),g.setAttribute(`data-skBtn`,t);var _=`${e.options.layoutName}-r${n}b${i}`;g.setAttribute(`data-skBtnUID`,_);var v=document.createElement(`span`);v.innerHTML=m,g.appendChild(v),e.buttonElements[t]||(e.buttonElements[t]=[]),e.buttonElements[t].push(g),s.appendChild(g)})),s=e.parseRowDOMContainers(s,n,c,l),e.keyboardRowsDOM.appendChild(s)})),this.keyboardDOM.appendChild(this.keyboardRowsDOM),this.onRender(),this.initialized||(this.initialized=!0,!this.utilities.pointerEventsSupported()||r||a?r?(document.ontouchend=function(t){return e.handleButtonMouseUp(void 0,t)},document.ontouchcancel=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.ontouchstart=function(t){return e.handleKeyboardContainerMouseDown(t)}):r||(document.onmouseup=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.onmousedown=function(t){return e.handleKeyboardContainerMouseDown(t)}):(document.onpointerup=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.onpointerdown=function(t){return e.handleKeyboardContainerMouseDown(t)}),this.onInit())}}],t&&D(e.prototype,t),n&&D(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}(),j=A;return r}()},442:function(t){t.exports=e}},n={};function r(e){var i=n[e];if(i!==void 0)return i.exports;var a=n[e]={exports:{}};return t[e].call(a.exports,a,a.exports,r),a.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){typeof Symbol<`u`&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return function(){r.r(i),r.d(i,{KeyboardReact:function(){return u},default:function(){return d}}),r(981);var e=r(442),t=r(548),n=r.n(t);function a(e){return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t{e?.(t)},[t,e]);let d=(0,y.useCallback)(e=>{if(a.current)return;let t=e.target;if(!t.closest(`[data-vkb="false"]`)){if(t instanceof HTMLInputElement){if(!uHe.has(t.type))return}else if(!(t instanceof HTMLTextAreaElement))return;c.current=t,n(!0),s(`default`),l.current?.setInput?.(c.current.value),setTimeout(()=>{(t.closest(`.bg-zinc-800, .rounded-lg, [data-vkb-group]`)??t).scrollIntoView({behavior:`smooth`,block:`nearest`})},100)}},[]),f=(0,y.useCallback)(()=>{setTimeout(()=>{let e=document.activeElement;e&&(u.current?.contains(e)||e===c.current)||(n(!1),c.current=null)},150)},[]);(0,y.useEffect)(()=>(document.addEventListener(`focusin`,d),document.addEventListener(`focusout`,f),()=>{document.removeEventListener(`focusin`,d),document.removeEventListener(`focusout`,f)}),[d,f]);let p=(0,y.useCallback)(()=>{a.current=!0,i(!0),c.current?.blur(),c.current=null,setTimeout(()=>{n(!1),i(!1),a.current=!1},400)},[]),m=(0,y.useCallback)(e=>{let t=c.current;if(t){if(e===`{shift}`){s(e=>e==="default"?`shift`:`default`);return}if(e===`{lock}`){s(e=>e==="default"?`shift`:`default`);return}if(e===`{close}`){p();return}e===`{bksp}`?A9(t,t.value.slice(0,-1)):e===`{space}`?A9(t,t.value+` `):(A9(t,t.value+e),o===`shift`&&s(`default`)),t.focus(),l.current?.setInput?.(t.value)}},[o,p]);return t?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-[9998] bg-transparent`,onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),r||p()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation(),r||p()},onClick:e=>{e.preventDefault(),e.stopPropagation()}}),!r&&(0,K.jsx)(`div`,{ref:u,className:`relative z-[9999] shrink-0`,onMouseDown:e=>e.preventDefault(),onTouchStart:e=>{e.target.closest(`.hg-button`)||e.preventDefault()},children:(0,K.jsx)(lHe.default,{keyboardRef:e=>{l.current=e},layoutName:o,onKeyPress:m,theme:`simple-keyboard vkb-theme`,layout:{default:[`1 2 3 4 5 6 7 8 9 0 {bksp}`,`q w e r t y u i o p`,`{lock} a s d f g h j k l`,`{shift} z x c v b n m . @`,`{space} {close}`],shift:[`! @ # $ % ^ & * ( ) {bksp}`,`Q W E R T Y U I O P`,`{lock} A S D F G H J K L`,`{shift} Z X C V B N M , _`,`{space} {close}`]},display:{"{bksp}":`⌫`,"{close}":`✕ Close`,"{shift}":`⇧`,"{lock}":`⇪`,"{space}":` `}})})]}):null}function fHe(){qd();let[e,t]=(0,y.useState)(null),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(100),{i18n:o}=G(),s=Yn(),c=Kn(),l=cHe(),{setViewportSuppressed:u}=xd();(0,y.useEffect)(()=>(u(!0),()=>u(!1)),[u]);let{data:d}=q({queryKey:[`settings`],queryFn:Q.getSettings});(0,y.useEffect)(()=>{d?.language&&d.language!==o.language&&o.changeLanguage(d.language)},[d?.language,o]);let{data:f=[]}=q({queryKey:[`spoolbuddy-devices`],queryFn:()=>nd.getDevices(),refetchInterval:3e4}),p=f[0],m=l.deviceOnline||!!p?.online,h=(0,y.useMemo)(()=>({...l,deviceOnline:m}),[l,m]),g=(0,y.useRef)(!1);(0,y.useEffect)(()=>{p&&!g.current&&(a(p.display_brightness),g.current=!0)},[p]),(0,y.useEffect)(()=>{let e=document.documentElement,t=e.classList.contains(`dark`);return e.classList.add(`dark`),()=>{t||e.classList.remove(`dark`)}},[]);let{data:_}=q({queryKey:[`spoolbuddy-update-check`,p?.device_id],queryFn:()=>p?nd.checkDaemonUpdate(p.device_id):Promise.resolve(null),enabled:!!p,refetchInterval:300*1e3,staleTime:0}),v=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!m){let e=`SpoolBuddy device disconnected`;r({type:`warning`,message:e}),v.current=e}else if(_?.update_available&&_.latest_version){let e=`Update available: v${_.latest_version}`;r({type:`info`,message:e}),v.current=e}else v.current&&=(r(null),null)},[m,_?.update_available,_?.latest_version]);let b=!!(l.matchedSpool||l.unknownTagUid||l.unknownTrayUuid),x=(0,y.useRef)(!1);(0,y.useEffect)(()=>{b&&!x.current&&c.pathname!==`/spoolbuddy`&&s(`/spoolbuddy`),x.current=b},[b,c.pathname,s]);let{data:S=[]}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters()}),C=po({queries:S.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),refetchInterval:1e4,select:e=>({connected:e?.connected})}))}),w=(0,y.useMemo)(()=>S.filter((e,t)=>C[t]?.data?.connected),[S,C]),T=(0,y.useRef)(null),E=(0,y.useRef)(!1),D=(0,y.useRef)(null),O=(0,y.useCallback)(e=>{T.current={x:e.touches[0].clientX,y:e.touches[0].clientY},E.current=!1},[]),k=(0,y.useCallback)(n=>{if(!T.current)return;let r=n.changedTouches[0].clientX-T.current.x,i=n.changedTouches[0].clientY-T.current.y,a=T.current.y;if(T.current=null,E.current=!1,i>=50&&Math.abs(i)>Math.abs(r)&&a<120){N(!0);return}if(w.length<2||Math.abs(r)<50||Math.abs(i)>Math.abs(r))return;let o=w.findIndex(t=>t.id===e);t(w[r<0?(o+1)%w.length:(o-1+w.length)%w.length].id)},[w,e,t]);(0,y.useEffect)(()=>{let e=D.current;if(!e)return;let t=e=>{if(!T.current)return;let t=Math.abs(e.touches[0].clientX-T.current.x),n=Math.abs(e.touches[0].clientY-T.current.y);if(E.current){e.preventDefault();return}t>10&&t>n&&(E.current=!0,e.preventDefault())};return e.addEventListener(`touchmove`,t,{passive:!1}),()=>e.removeEventListener(`touchmove`,t)},[]);let[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{ref:D,"data-spoolbuddy-kiosk":!0,className:`w-screen h-screen bg-bambu-dark text-white flex flex-col overflow-hidden`,style:{...i<100?{filter:`brightness(${i/100})`}:void 0,overscrollBehaviorX:`none`},onTouchStart:O,onTouchEnd:k,children:[(0,K.jsx)(`button`,{onClick:()=>N(!0),className:`w-full h-1.5 bg-bambu-dark-secondary flex justify-center items-center shrink-0 touch-none`,"aria-label":`Open quick menu`,children:(0,K.jsx)(`div`,{className:`w-8 h-0.5 rounded-full bg-zinc-600`})}),(0,K.jsx)(tHe,{selectedPrinterId:e,onPrinterChange:t,deviceOnline:m}),(0,K.jsx)(`main`,{className:`flex-1 overflow-y-auto`,children:(0,K.jsx)(Tr,{context:{selectedPrinterId:e,setSelectedPrinterId:t,sbState:h,setAlert:r,displayBrightness:i,setDisplayBrightness:a}})}),!A&&(0,K.jsx)(iHe,{alert:n}),!A&&(0,K.jsx)(rHe,{}),(0,K.jsx)(dHe,{onVisibilityChange:j})]}),(0,K.jsx)(aHe,{isOpen:M,onClose:()=>N(!1),deviceId:p?.device_id??null,deviceOnline:m})]})}function j9({color:e,isEmpty:t,size:n=32}){return t?(0,K.jsx)(`div`,{className:`rounded-full border-2 border-dashed border-zinc-500 flex items-center justify-center`,style:{width:n,height:n},children:(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-zinc-600`})}):(0,K.jsxs)(`svg`,{width:n,height:n,viewBox:`0 0 32 32`,children:[(0,K.jsx)(`circle`,{cx:`16`,cy:`16`,r:`14`,fill:e,stroke:`white`,strokeWidth:`1.5`,strokeOpacity:`0.7`}),(0,K.jsx)(`circle`,{cx:`16`,cy:`16`,r:`11`,fill:e,style:{filter:`brightness(0.85)`}})]})}var pHe=`spoolbuddy-default-core-weight`;function M9(){try{let e=localStorage.getItem(pHe);if(e){let t=parseInt(e,10);if(t>=0&&t<=500)return t}}catch{}return 250}function mHe({spool:e,scaleWeight:t,onClose:n,onSyncWeight:r,onAssignToAms:i,isAssigned:a,onUnassignFromAms:o}){let{t:s}=G(),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(!1),f=Ud(e.rgba),p=e.core_weight&&e.core_weight>0?e.core_weight:M9(),m=t===null?null:Math.round(Math.max(0,t)),h=m===null?null:Math.round(Math.max(0,m-p)),g=Math.round(e.label_weight||1e3),_=h===null?null:Math.min(100,Math.round(h/g*100)),v=_===null?`#808080`:_>50?`#22c55e`:_>20?`#eab308`:`#ef4444`,b=Math.max(0,(e.label_weight||0)-(e.weight_used||0))+p,x=m===null?null:m-b,S=x===null?null:Math.abs(x)<=50,C=async()=>{if(t!==null){l(!0);try{await nd.updateSpoolWeight(e.id,Math.round(t)),d(!0),r?.(),setTimeout(()=>d(!1),3e3)}catch(e){console.error(`Failed to sync weight:`,e)}finally{l(!1)}}};return(0,K.jsxs)(`div`,{className:`flex flex-col items-center space-y-4 max-w-md`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-5`,children:[(0,K.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,K.jsx)(j9,{color:f,isEmpty:!1,size:100}),_!==null&&(0,K.jsxs)(`div`,{className:`absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg`,style:{backgroundColor:v},children:[_,`%`]})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:e.color_name||`Unknown color`}),(0,K.jsxs)(`span`,{className:`text-xs font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,K.jsxs)(`p`,{className:`text-sm text-zinc-400`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]}),h!==null&&(0,K.jsxs)(`div`,{className:`mt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-3xl font-bold font-mono text-zinc-100`,children:[h,`g`]}),(0,K.jsxs)(`span`,{className:`text-sm text-zinc-500`,children:[`/ `,g,`g`]})]}),(0,K.jsx)(`p`,{className:`text-xs text-zinc-500 mt-0.5`,children:s(`spoolbuddy.spool.remaining`,`Remaining`)}),(0,K.jsx)(`div`,{className:`mt-2 max-w-xs`,children:(0,K.jsx)(`div`,{className:`h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${_}%`,backgroundColor:v}})})})]})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.grossWeight`,`Gross weight`)}),(0,K.jsx)(`span`,{className:`font-mono text-zinc-300`,children:m===null?`—`:`${m}g`})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.spool.coreWeight`,`Core`)}),(0,K.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[p,`g`]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.spoolSize`,`Spool size`)}),(0,K.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[g,`g`]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.spool.scaleWeight`,`Scale`)}),m===null?(0,K.jsx)(`span`,{className:`text-zinc-500`,children:`—`}):(0,K.jsxs)(`span`,{className:`flex items-center gap-1 font-mono ${S?`text-green-500`:`text-yellow-500`}`,children:[m,`g`,S?(0,K.jsx)($o,{className:`w-3.5 h-3.5`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(vu,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`button`,{onClick:C,className:`p-1 hover:bg-green-500/20 rounded transition-colors text-green-500`,title:s(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`),children:(0,K.jsx)(Cl,{className:`w-4 h-4`})})]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.tagId`,`Tag`)}),(0,K.jsx)(`span`,{className:`font-mono text-xs text-zinc-400 truncate max-w-[120px]`,title:e.tag_uid||``,children:e.tag_uid?e.tag_uid.slice(-8):`—`})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[i&&(0,K.jsx)(`button`,{onClick:a?void 0:i,disabled:!!a,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px] disabled:opacity-50 disabled:cursor-not-allowed`,children:s(`spoolbuddy.modal.assignToAms`,`Assign to AMS`)}),o&&(0,K.jsxs)(`button`,{onClick:o,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-red-600/20 text-red-400 hover:bg-red-600/30 transition-colors min-h-[44px]`,children:[(0,K.jsx)(xu,{className:`w-4 h-4 inline mr-1`}),s(`inventory.unassignSpool`)]}),(0,K.jsx)(`button`,{onClick:C,disabled:t===null||c,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${u?`bg-green-600/20 text-green-400`:i?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed`:`bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed`}`,children:c?`...`:u?s(`spoolbuddy.dashboard.weightSynced`,`Synced!`):s(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`)}),n&&(0,K.jsx)(`button`,{onClick:n,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:s(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function hHe({tagUid:e,scaleWeight:t,coreWeight:n,onLinkSpool:r,onAddToInventory:i,onClose:a}){let{t:o}=G(),s=n??M9(),c=t===null?null:Math.round(Math.max(0,t)),l=c===null?null:Math.round(Math.max(0,c-s));return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-5`,children:[(0,K.jsx)(`div`,{className:`w-20 h-20 rounded-2xl bg-green-500/15 flex items-center justify-center`,children:(0,K.jsx)(`svg`,{className:`w-10 h-10 text-green-500`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z`})})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:o(`spoolbuddy.dashboard.newTag`,`New Tag Detected`)}),(0,K.jsx)(`p`,{className:`text-sm text-zinc-500 font-mono mt-1`,children:e})]}),c!==null&&(0,K.jsxs)(`div`,{className:`text-sm text-zinc-400`,children:[(0,K.jsxs)(`span`,{className:`font-mono font-semibold`,children:[c,`g`]}),` `,o(`spoolbuddy.dashboard.onScale`,`on scale`),l!==null&&l>0&&(0,K.jsxs)(`span`,{className:`text-zinc-500`,children:[` • ~`,l,`g filament`]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-2 justify-center`,children:[i&&(0,K.jsx)(`button`,{onClick:i,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:o(`spoolbuddy.modal.addToInventory`,`Add to Inventory`)}),r&&(0,K.jsxs)(`button`,{onClick:r,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:[(0,K.jsx)(`svg`,{className:`w-4 h-4 inline-block mr-1.5 -mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1`})}),o(`inventory.assignSpool`,`Assign Spool`)]}),a&&(0,K.jsx)(`button`,{onClick:a,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:o(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function gHe(e){return e?`#${e.slice(0,6)}`:`#808080`}function N9(e){return!e.tray_type||e.tray_type===``}function _He(e){if(e.tray_type)return null;let t=e.state??null;return t===9||t===10?`physical`:`reset`}function vHe(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function yHe({className:e}){return(0,K.jsx)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,K.jsx)(`path`,{d:`M17.8131 0.00538C18.4463 -0.15091 20.3648 3.14642 20.8264 3.84781C25.4187 10.816 35.3089 26.9368 35.9383 34.8694C37.4182 53.5822 11.882 61.3357 2.53721 45.3789C-1.73471 38.0791 0.016 32.2049 3.178 25.0232C6.99221 16.3662 12.6411 7.90372 17.8131 0.00538ZM18.3738 7.24807L17.5881 7.48441C14.4452 12.9431 10.917 18.2341 8.19369 23.9368C4.6808 31.29 1.18317 38.5479 7.69403 45.5657C17.3058 55.9228 34.9847 46.8808 31.4604 32.8681C29.2558 24.0969 22.4207 15.2913 18.3776 7.24807H18.3738Z`,fill:`#C3C2C1`})})}function bHe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 35 53`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`path`,{d:`M17.3165 0.0038C17.932 -0.14959 19.7971 3.08645 20.2458 3.77481C24.7103 10.6135 34.3251 26.4346 34.937 34.2198C36.3757 52.5848 11.5505 60.1942 2.46584 44.534C-1.68714 37.3735 0.0148 31.6085 3.08879 24.5603C6.79681 16.0605 12.2884 7.75907 17.3165 0.0038ZM17.8615 7.11561L17.0977 7.34755C14.0423 12.7048 10.6124 17.8974 7.96483 23.4941C4.54975 30.7107 1.14949 37.8337 7.47908 44.721C16.8233 54.8856 34.01 46.0117 30.5838 32.2595C28.4405 23.6512 21.7957 15.0093 17.8652 7.11561H17.8615Z`,fill:`#C3C2C1`}),(0,K.jsx)(`path`,{d:`M5.03547 30.112C9.64453 30.4936 11.632 35.7985 16.4154 35.791C19.6339 35.7873 20.2161 33.2283 22.3853 31.6197C31.6776 24.7286 33.5835 37.4894 27.9881 44.4254C18.1878 56.5653 -1.16063 44.6013 5.03917 30.1158L5.03547 30.112Z`,fill:`#1F8FEB`})]})}function xHe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`path`,{d:`M17.9625 4.48059L4.77216 26.3154L2.08228 40.2175L10.0224 50.8414H23.1594L33.3246 42.1693V30.2455L17.9625 4.48059Z`,fill:`#1F8FEB`}),(0,K.jsx)(`path`,{d:`M17.7948 0.00538C18.4273 -0.15091 20.3438 3.14642 20.8048 3.84781C25.3921 10.816 35.2715 26.9368 35.9001 34.8694C37.3784 53.5822 11.8702 61.3357 2.53562 45.3789C-1.73163 38.0829 0.0134 32.2087 3.1757 25.027C6.98574 16.3662 12.6284 7.90372 17.7948 0.00538ZM18.3549 7.24807L17.57 7.48441C14.4306 12.9431 10.9063 18.2341 8.1859 23.9368C4.67686 31.29 1.18305 38.5479 7.68679 45.5657C17.2881 55.9228 34.9476 46.8808 31.4271 32.8681C29.2249 24.0969 22.3974 15.2913 18.3587 7.24807H18.3549Z`,fill:`#C3C2C1`})]})}function SHe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`}),(0,K.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2.5`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function CHe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`rect`,{x:`4.5`,y:`8`,width:`3`,height:`4.5`,fill:`#d4a017`,rx:`0.5`}),(0,K.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#d4a017`}),(0,K.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function wHe({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,K.jsx)(`rect`,{x:`4.5`,y:`3`,width:`3`,height:`9.5`,fill:`#c62828`,rx:`0.5`}),(0,K.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#c62828`}),(0,K.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function P9({humidity:e,goodThreshold:t=40,fairThreshold:n=60}){let r,i;return e<=t?(r=`#22a352`,i=yHe):e<=n?(r=`#d4a017`,i=bHe):(r=`#c62828`,i=xHe),(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,K.jsx)(i,{className:`w-3 h-3.5`}),(0,K.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`%`]})]})}function F9({temp:e,goodThreshold:t=28,fairThreshold:n=35}){let r,i;return e<=t?(r=`#22a352`,i=SHe):e<=n?(r=`#d4a017`,i=CHe):(r=`#c62828`,i=wHe),(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,K.jsx)(i,{className:`w-3 h-3.5`}),(0,K.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`°C`]})]})}function I9({side:e}){return(0,K.jsx)(`span`,{className:`inline-flex items-center justify-center w-4 h-4 text-[9px] font-bold rounded`,style:{backgroundColor:`#1a4d2e`,color:`#00ae42`},children:e})}function THe({tray:e,slotIndex:t,isActive:n,fillOverride:r,spoolmanFill:i,onClick:a}){let o=N9(e),s=_He(e),c=gHe(e.tray_color),l=e.remain!==null&&e.remain!==void 0&&e.remain>=0?e.remain:null,u=i??(r===0&&l!==null&&l>0?null:r)??l;return(0,K.jsxs)(`div`,{className:`relative flex flex-col items-center p-2.5 rounded-lg transition-all ${n?`ring-2 ring-bambu-green`:``} ${a?`cursor-pointer hover:bg-white/5`:``}`,onClick:a,title:a?`AMS Slot ${t+1}`:void 0,children:[(0,K.jsxs)(`div`,{className:`relative w-16 h-16 mb-1`,children:[o?(0,K.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full bg-gray-600`})}):(0,K.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:c}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:c,style:{filter:`brightness(0.85)`}}),(0,K.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),n&&(0,K.jsx)(`div`,{className:`absolute -bottom-1 left-1/2 -translate-x-1/2 w-2.5 h-2.5 bg-bambu-green rounded-full`})]}),(0,K.jsx)(`span`,{className:`text-sm text-white/70 truncate max-w-full`,title:s===`reset`?`Spool loaded — slot not configured`:void 0,children:o?s===`reset`?`?`:`Empty`:e.tray_type||`Unknown`}),!o&&u!==null&&u>=0&&(0,K.jsx)(`div`,{className:`w-full h-1 bg-bambu-dark-tertiary rounded-full overflow-hidden mt-1`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${u}%`,backgroundColor:RK(u)}})}),(0,K.jsx)(`span`,{className:`absolute top-1 right-1 text-xs text-white/30`,children:t+1})]})}function L9({unit:e,activeSlot:t,onConfigureSlot:n,isDualNozzle:r,nozzleSide:i,thresholds:a,fillOverrides:o,spoolmanFillOverrides:s}){let c=e.tray||[],l=e.is_ams_ht,u=l?1:4;return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-white font-medium text-base`,children:vHe(e.id)}),r&&i&&(0,K.jsx)(I9,{side:i})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.temp!=null&&(0,K.jsx)(F9,{temp:e.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair}),e.humidity!=null&&(0,K.jsx)(P9,{humidity:e.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair})]})]}),(0,K.jsx)(`div`,{className:`grid ${l?`grid-cols-1 max-w-[100px] mx-auto`:`grid-cols-4`} gap-2`,children:Array.from({length:u}).map((r,i)=>{let a=c[i]||{id:i,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null};return(0,K.jsx)(THe,{tray:a,slotIndex:i,isActive:t===i,fillOverride:o?.[`${e.id}-${i}`]??null,spoolmanFill:s?.[`${e.id}-${i}`]??null,onClick:n?()=>n(e.id,i,N9(a)?null:a):void 0},i)})})]})}function R9(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function z9(e){return!e.tray_type||e.tray_type===``}function EHe(e){return e?`#${e.slice(0,6)}`:`#808080`}var B9=e=>(e??``).trim().toUpperCase();function DHe(e,t){let n=B9(e),r=B9(t);return!n||!r?`none`:n===r?`exact`:r.includes(n)||n.includes(r)?`partial`:`none`}function OHe(e,t){let n=B9(e),r=B9(t);return!n||!r?!1:n===r}function V9({isOpen:e,onClose:t,spool:n,printerId:r,spoolmanMode:i=!1}){let{t:a}=G(),o=Qa(),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null);(0,y.useEffect)(()=>{e&&(c(null),u(null),f(!1),m(null),g(null))},[e]);let _=(0,y.useCallback)(e=>{e.key===`Escape`&&t()},[t]);(0,y.useEffect)(()=>(e&&document.addEventListener(`keydown`,_),()=>document.removeEventListener(`keydown`,_)),[e,_]);let{data:v}=q({queryKey:[`printerStatus`,r],queryFn:()=>Q.getPrinterStatus(r),enabled:e&&r!==null,refetchInterval:5e3}),{data:b}=q({queryKey:[`printer`,r],queryFn:()=>Q.getPrinter(r),enabled:e&&r!==null}),{data:x}=q({queryKey:[`settings`],queryFn:()=>Q.getSettings(),enabled:e,staleTime:300*1e3}),{data:S}=q({queryKey:[`spool-assignments`,r],queryFn:()=>Q.getAssignments(r),enabled:e&&r!==null,staleTime:30*1e3}),{data:C=[]}=q({queryKey:[`spoolman-slot-assignments`,r],queryFn:()=>Q.getSpoolmanSlotAssignments(r??void 0),enabled:e&&!!i&&r!==null,staleTime:30*1e3}),w=i?C.find(e=>e.spoolman_spool_id===n.id):void 0,T=(0,y.useMemo)(()=>{let e={};if(!S)return e;for(let t of S){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[S]),E=x?{humidityGood:Number(x.ams_humidity_good)||40,humidityFair:Number(x.ams_humidity_fair)||60,tempGood:Number(x.ams_temp_good)||28,tempFair:Number(x.ams_temp_fair)||35}:void 0,D=v?.connected??!1,O=(0,y.useMemo)(()=>v?.ams??[],[v?.ams]),k=(0,y.useMemo)(()=>O.filter(e=>!e.is_ams_ht),[O]),A=(0,y.useMemo)(()=>O.filter(e=>e.is_ams_ht),[O]),j=(0,y.useMemo)(()=>[...v?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[v?.vt_tray]),M=b?.nozzle_count===2||v?.temperatures?.nozzle_2!==void 0,N=(0,y.useRef)({});(0,y.useEffect)(()=>{v?.ams_extruder_map&&Object.keys(v.ams_extruder_map).length>0&&(N.current=v.ams_extruder_map)},[v?.ams_extruder_map]);let P=v?.ams_extruder_map&&Object.keys(v.ams_extruder_map).length>0?v.ams_extruder_map:N.current,F=(0,y.useCallback)(e=>{if(!M)return null;let t=P[String(e)],n=e>=128?e-128:e;return(t===void 0?n:t)===1?`L`:`R`},[M,P]),I=J({mutationFn:async({amsId:e,trayId:t})=>{if(!r)throw Error(`No printer selected`);return i?await Q.assignSpoolmanSlot({spoolman_spool_id:n.id,printer_id:r,ams_id:e,tray_id:t}):await Q.assignSpool({spool_id:n.id,printer_id:r,ams_id:e,tray_id:t})},onSuccess:e=>{u(`success`);let n=e&&`pending_config`in e&&e.pending_config;c(n?a(`spoolbuddy.modal.assignPendingInsert`,`Assigned. Slot will configure when you insert the spool.`):a(`spoolbuddy.modal.assignSuccess`,`Assigned!`)),o.invalidateQueries({queryKey:[`slotPresets`]}),o.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),o.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),setTimeout(()=>t(),n?2500:1500)},onError:e=>{u(`error`),c(e instanceof Error?e.message:a(`spoolbuddy.modal.assignError`,`Failed to assign spool.`))}}),L=I.isPending,R=(0,y.useCallback)((e,t)=>{if(e===254||e===255){let n=e===254?254:254+t;return j.find(e=>(e.id??254)===n)||null}return O.find(t=>t.id===e)?.tray?.find(e=>e.id===t)||null},[O,j]),z=(0,y.useCallback)((e,t)=>e<=3?`${R9(e)} ${a(`ams.slot`,`Slot`)} ${t+1}`:e>=128&&e<=135?R9(e):e===254?a(`printers.extL`,`Ext-L`):M?a(`printers.extR`,`Ext-R`):a(`printers.ext`,`Ext`),[a,M]),B=(0,y.useCallback)((e,t)=>{u(`info`),c(a(`spoolbuddy.modal.assigning`,`Configuring slot...`)),I.mutate({amsId:e,trayId:t})},[I,a]),V=(0,y.useCallback)((e,t)=>{if(!L){if(!x?.disable_filament_warnings){let r=R(e,t);if(r&&!z9(r)){let i=r.tray_sub_brands||r.tray_type||``,a=DHe(n.material,i),o=n.slicer_filament_name||n.slicer_filament,s=r.tray_type||``,c=OHe(o,s);if(a!==`exact`){let r;r=a===`none`&&!c?`material_profile`:a===`partial`&&!c?`partial_profile`:a===`none`?`material`:`partial`;let l=z(e,t);g({amsId:e,trayId:t}),m({type:r,spoolMaterial:n.material||``,trayMaterial:i||``,spoolProfile:o||void 0,trayProfile:s||void 0,location:l}),f(!0);return}}}B(e,t)}},[L,x?.disable_filament_warnings,n,R,z,B]),ee=(0,y.useCallback)(()=>{h&&(f(!1),m(null),B(h.amsId,h.trayId),g(null))},[h,B]),H=(0,y.useMemo)(()=>{let e=[];for(let t of A){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=T[`${t.id}-0`]??null,i=n.remain!=null&&n.remain>=0?n.remain:null,a=r===0&&i!==null&&i>0?null:r;e.push({key:`ht-${t.id}`,label:R9(t.id),amsId:t.id,trayId:0,tray:n,isEmpty:z9(n),nozzleSide:F(t.id),effectiveFill:a??i})}for(let t of j){let n=t.id??254,r=n-254,i=T[`255-${r}`]??null,o=t.remain!=null&&t.remain>=0?t.remain:null,s=i===0&&o!==null&&o>0?null:i;e.push({key:`ext-${n}`,label:M?n===254?a(`printers.extL`,`Ext-L`):a(`printers.extR`,`Ext-R`):a(`printers.ext`,`Ext`),amsId:255,trayId:r,tray:t,isEmpty:z9(t),nozzleSide:M?n===254?`L`:`R`:null,effectiveFill:s??o})}return e},[A,j,M,a,F,T]);return e?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`fixed inset-0 z-[60] bg-bambu-dark flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-zinc-800 shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,K.jsx)(`div`,{className:`w-7 h-7 rounded-full shrink-0`,style:Wd(n.rgba)}),(0,K.jsx)(`div`,{className:`min-w-0`,children:(0,K.jsxs)(`h2`,{className:`text-sm font-semibold text-zinc-100 truncate`,children:[a(`spoolbuddy.modal.assignToAmsTitle`,`Assign to AMS`),(0,K.jsxs)(`span`,{className:`font-normal text-zinc-500 ml-2`,children:[n.color_name||`Unknown`,` • `,n.brand,` `,n.material,n.subtype&&` ${n.subtype}`]}),(0,K.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 ml-2 shrink-0`,children:[`#`,n.id]})]})})]}),(0,K.jsx)(`button`,{onClick:t,disabled:L,className:`p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-800 transition-colors shrink-0 disabled:opacity-50`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),s&&(0,K.jsxs)(`div`,{className:`mx-5 mt-3 p-3 rounded-lg flex items-center gap-3 border shrink-0 ${l===`info`?`bg-blue-500/10 border-blue-500/40`:l===`success`?`bg-green-500/10 border-green-500/40`:`bg-red-500/10 border-red-500/40`}`,children:[l===`info`&&(0,K.jsx)(X,{className:`w-4 h-4 text-blue-400 animate-spin shrink-0`}),l===`success`&&(0,K.jsx)(ls,{className:`w-4 h-4 text-green-400 shrink-0`}),l===`error`&&(0,K.jsx)(ms,{className:`w-4 h-4 text-red-400 shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm ${l===`info`?`text-blue-300`:l===`success`?`text-green-300`:`text-red-300`}`,children:s})]}),(0,K.jsx)(`div`,{className:`flex-1 flex flex-col gap-3 p-4 min-h-0 overflow-y-auto`,children:!D&&r?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,K.jsx)(`div`,{className:`text-center text-white/50`,children:(0,K.jsx)(`p`,{className:`text-lg mb-2`,children:a(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})})}):O.length===0&&j.length===0?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,K.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,K.jsx)(Nc,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,K.jsx)(`p`,{className:`text-lg mb-2`,children:a(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,K.jsx)(`p`,{className:`text-sm`,children:a(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,K.jsxs)(K.Fragment,{children:[k.length>0&&(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3 flex-1 min-h-0`,children:k.map(e=>(0,K.jsx)(L9,{unit:e,activeSlot:w?.ams_id===e.id?w.tray_id??null:null,onConfigureSlot:(t,n)=>V(e.id,n),isDualNozzle:M,nozzleSide:F(e.id),thresholds:E,fillOverrides:T},e.id))}),H.length>0&&(0,K.jsx)(`div`,{className:`flex gap-2 shrink-0`,children:H.map(({key:e,label:t,amsId:n,trayId:r,tray:i,isEmpty:a,nozzleSide:o,effectiveFill:s})=>{let c=EHe(i.tray_color);return(0,K.jsxs)(`div`,{onClick:()=>V(n,r),className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-2 ${w&&w.ams_id===n&&w.tray_id===r?`ring-2 ring-bambu-green`:``} ${L?`opacity-50 pointer-events-none`:``}`,children:[(0,K.jsx)(`div`,{className:`relative w-10 h-10 shrink-0`,children:a?(0,K.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,K.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,K.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:c}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:c,style:{filter:`brightness(0.85)`}}),(0,K.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-white/50 font-medium`,children:t}),o&&(0,K.jsx)(I9,{side:o})]}),(0,K.jsx)(`div`,{className:`text-sm text-white/80 truncate`,children:a?`Empty`:i.tray_type||`?`})]}),!a&&s!=null&&s>=0&&(0,K.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden shrink-0 flex flex-col-reverse`,children:(0,K.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${s}%`,backgroundColor:RK(s)}})})]},e)})})]})}),(0,K.jsx)(`div`,{className:`flex justify-end gap-3 px-5 py-3 border-t border-zinc-800 shrink-0`,children:(0,K.jsx)(`button`,{onClick:t,disabled:L,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-800 text-zinc-300 hover:bg-zinc-700 transition-colors min-h-[44px] disabled:opacity-50`,children:l===`success`?a(`spoolbuddy.dashboard.close`,`Close`):a(`spoolbuddy.modal.cancel`,`Cancel`)})})]}),d&&p&&(()=>{let e=``;return p.type===`material`?e=a(`inventory.assignMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location}):p.type===`partial`?e=a(`inventory.assignPartialMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location}):p.type===`material_profile`?e=`${a(`inventory.assignMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location})}\n\n${a(`inventory.assignProfileMismatchMessage`,{spoolProfile:p.spoolProfile||a(`common.unknown`),trayProfile:p.trayProfile||a(`common.unknown`),location:p.location})}`:p.type===`partial_profile`&&(e=`${a(`inventory.assignPartialMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location})}\n\n${a(`inventory.assignProfileMismatchMessage`,{spoolProfile:p.spoolProfile||a(`common.unknown`),trayProfile:p.trayProfile||a(`common.unknown`),location:p.location})}`),e=`${e}\n\n${a(`inventory.assignReconfigureNote`)}`,(0,K.jsx)(Ed,{title:a(`inventory.assignMismatchTitle`),message:e,confirmText:a(`inventory.assignMismatchConfirm`),variant:`warning`,isLoading:I.isPending,onConfirm:ee,onCancel:()=>{I.isPending||(f(!1),g(null),m(null))}})})()]}):null}function kHe({isOpen:e,onClose:t,tagId:n,untaggedSpools:r,onLink:i}){let{t:a}=G(),[o,s]=(0,y.useState)(null),c=(0,y.useCallback)(()=>{s(null),t()},[t]),l=(0,y.useCallback)(e=>{e.key===`Escape`&&c()},[c]);return(0,y.useEffect)(()=>(e&&(document.addEventListener(`keydown`,l),document.body.style.overflow=`hidden`),()=>{document.removeEventListener(`keydown`,l),document.body.style.overflow=``}),[e,l]),e?(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in`,onClick:c,children:(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-xl shadow-2xl w-full max-w-lg mx-4 animate-slide-up`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-zinc-700`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-base font-semibold text-zinc-100`,children:a(`spoolbuddy.dashboard.linkTagTitle`,`Link Tag to Spool`)}),(0,K.jsx)(`p`,{className:`text-sm text-zinc-500 font-mono`,children:n})]}),(0,K.jsx)(`button`,{onClick:c,className:`p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-700 transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`px-5 py-4 space-y-3 max-h-[400px] overflow-y-auto`,children:[(0,K.jsx)(`p`,{className:`text-sm text-zinc-400`,children:a(`spoolbuddy.dashboard.selectSpool`,`Select a spool to link this tag to:`)}),r.length===0?(0,K.jsx)(`div`,{className:`text-center py-8 text-zinc-500`,children:a(`spoolbuddy.dashboard.noUntagged`,`No spools without tags found`)}):(0,K.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>s(e),className:`w-full flex items-center gap-3 p-3 rounded-lg border-2 transition-all text-left ${o?.id===e.id?`border-green-500 bg-green-500/10`:`border-zinc-700 hover:border-green-500/50 hover:bg-zinc-700/50`}`,children:[(0,K.jsx)(j9,{color:Ud(e.rgba),isEmpty:!1,size:40}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`font-medium text-zinc-100 truncate`,children:e.color_name||`Unknown color`}),(0,K.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,K.jsxs)(`div`,{className:`text-sm text-zinc-400 truncate`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]})]}),(0,K.jsxs)(`div`,{className:`text-sm font-mono text-zinc-500`,children:[Math.max(0,e.label_weight-e.weight_used),`g`]})]},e.id))})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 px-5 py-4 border-t border-zinc-700`,children:[(0,K.jsx)(`button`,{onClick:c,className:`px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:a(`common.cancel`,`Cancel`)}),(0,K.jsx)(`button`,{onClick:()=>{o&&(i(o),s(null))},disabled:!o,className:`px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors min-h-[44px]`,children:a(`spoolbuddy.dashboard.linkTag`,`Link Tag`)})]})]})}):null}function H9(e){return e?e.replace(/[^0-9a-f]/gi,``).toUpperCase():``}function AHe(e,t){let n=H9(e),r=H9(t);return!n||!r?!1:n===r?!0:n.endsWith(r)||r.endsWith(n)}var U9=[`#00AE42`,`#FF6B35`,`#3B82F6`,`#EF4444`,`#A855F7`,`#FBBF24`,`#14B8A6`,`#EC4899`,`#F97316`,`#22C55E`];function jHe(){let{t:e}=G(),[t,n]=(0,y.useState)(0);(0,y.useEffect)(()=>{let e=setInterval(()=>{n(e=>(e+1)%U9.length)},5e3);return()=>clearInterval(e)},[]);let r=U9[t];return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,K.jsxs)(`div`,{className:`relative mb-6 flex items-center justify-center`,style:{width:160,height:160},children:[(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:[0,1].map(e=>(0,K.jsx)(`div`,{className:`absolute rounded-full border spoolbuddy-optimized-ping`,style:{width:80,height:80,borderColor:`${r}4D`,transition:`border-color 140ms linear`,animationDelay:`${e*.8}s`}},e))}),(0,K.jsxs)(`div`,{className:`relative overflow-hidden rounded-full`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 rounded-full opacity-30 spoolbuddy-spool-glow`,style:{background:`radial-gradient(circle, ${r} 0%, transparent 70%)`}}),(0,K.jsx)(`div`,{className:`relative`,style:{transition:`opacity 140ms linear`},children:(0,K.jsx)(j9,{color:r,isEmpty:!1,size:100})})]})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xl font-medium text-zinc-300`,children:e(`spoolbuddy.dashboard.readyToScan`,`Ready to scan`)}),(0,K.jsx)(`p`,{className:`text-sm text-zinc-500`,children:e(`spoolbuddy.dashboard.idleMessage`,`Place a spool on the scale to identify it`)})]}),(0,K.jsxs)(`div`,{className:`mt-6 flex items-center gap-2 text-sm text-zinc-600`,children:[(0,K.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`})}),(0,K.jsx)(`span`,{children:e(`spoolbuddy.dashboard.nfcHint`,`NFC tag will be read automatically`)})]})]})}function MHe(){let{t:e}=G();return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,K.jsx)(`div`,{className:`relative mb-6 flex items-center justify-center`,style:{width:160,height:160},children:(0,K.jsx)(`div`,{className:`w-24 h-24 rounded-full bg-zinc-800 flex items-center justify-center`,children:(0,K.jsx)(`svg`,{className:`w-12 h-12 text-zinc-600`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,d:`M18.364 5.636a9 9 0 010 12.728m0 0l-12.728-12.728m12.728 12.728L5.636 5.636m12.728 0a9 9 0 00-12.728 0m0 12.728a9 9 0 010-12.728`})})})}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-lg font-medium text-zinc-500`,children:e(`spoolbuddy.status.deviceOffline`,`Device Offline`)}),(0,K.jsx)(`p`,{className:`text-sm text-zinc-600`,children:e(`spoolbuddy.status.connectDisplay`,`Connect the SpoolBuddy display to scan spools`)})]}),(0,K.jsxs)(`div`,{className:`mt-6 flex items-center gap-2 text-xs text-zinc-600`,children:[(0,K.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M8.111 16.404a5.5 5.5 0 017.778 0M12 20h.01m-7.08-7.071c3.904-3.905 10.236-3.905 14.14 0M1.394 9.393c5.857-5.857 15.355-5.857 21.213 0`})}),(0,K.jsx)(`span`,{children:e(`spoolbuddy.status.waitingConnection`,`Waiting for device connection...`)})]})]})}function NHe(){let{sbState:e,selectedPrinterId:t}=Qn(),{t:n}=G(),{showToast:r}=xd(),{data:i}=q({queryKey:[`spoolman-settings`],queryFn:Q.getSpoolmanSettings,staleTime:300*1e3}),a=i?.spoolman_enabled===`true`&&!!i?.spoolman_url,{data:o=[],refetch:s}=q({queryKey:a?[`spoolman-inventory-spools`]:[`inventory-spools`],queryFn:()=>a?Q.getSpoolmanInventorySpools(!1):Q.getSpools(!1),enabled:i!==void 0}),{data:c=[]}=q({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:a,staleTime:3*1e3,refetchInterval:3*1e3,refetchIntervalInBackground:!1}),{data:l=[]}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters()}),u=po({queries:l.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),refetchInterval:1e4,select:e=>({connected:e?.connected,awaiting_plate_clear:e?.awaiting_plate_clear===!0})}))}),d=l.map((e,t)=>({printer:e,pending:u[t]?.data?.awaiting_plate_clear===!0})).filter(e=>e.pending),f=Qa(),p=J({mutationFn:e=>Q.clearPlate(e),onSuccess:(e,t)=>{f.setQueryData([`printerStatus`,t],e=>e&&{...e,awaiting_plate_clear:!1}),r(n(`spoolbuddy.dashboard.plateClearedToast`,`Plate marked as cleared`),`success`)},onError:()=>{r(n(`spoolbuddy.dashboard.plateClearFailed`,`Could not mark plate as cleared`),`error`)}}),m=J({mutationFn:e=>Q.unassignSpoolmanSlot(e),onSuccess:()=>{f.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),f.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},onError:()=>r(n(`inventory.unassignFailed`,`Failed to unassign spool`),`error`)}),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(null),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(null),M=e.matchedSpool?.tag_uid??e.unknownTagUid??null,N=e.weight,P=e.weightStable,F=(0,y.useRef)(null);N===null?F.current=null:(F.current===null||Math.abs(N-F.current)>=3||P)&&(F.current=N);let I=F.current,L=(0,y.useMemo)(()=>{if(e.matchedSpool?.id){let t=o.find(t=>t.id===e.matchedSpool?.id);if(t)return t}return h&&(o.find(e=>AHe(e.tag_uid,h))||A)||null},[h,e.matchedSpool,o,A]),R=(0,y.useMemo)(()=>{if(L&&!A)return L;let t=e.matchedSpool;return t?{id:t.id,tag_uid:t.tag_uid,material:t.material,subtype:t.subtype,color_name:t.color_name,rgba:t.rgba,brand:t.brand,label_weight:t.label_weight,core_weight:t.core_weight,weight_used:t.weight_used}:null},[L,A,e.matchedSpool]),z=a&&R!=null?c.some(e=>e.spoolman_spool_id===R.id):!1,B=(0,y.useMemo)(()=>a?o.filter(e=>!e.tag_uid&&!e.tray_uuid&&!e.archived_at):o.filter(e=>!e.tag_uid&&!e.archived_at),[o,a]);(0,y.useEffect)(()=>{if(M){let e=b===M;(h!==null&&h!==M||!e&&h!==M)&&(g(M),v(null),x(null),j(null)),!e&&N!==null&&P&&v(Math.round(Math.max(0,N)))}else b&&(g(null),x(null),v(null),j(null))},[M,N,P,h,b]);let V=()=>{x(h)},ee=async t=>{if(h)try{if(a){let i=e.unknownTagUid||void 0,a=!e.unknownTagUid&&e.unknownTrayUuid?e.unknownTrayUuid:void 0;if(!i&&!a){r(n(`spoolman.linkFailed`),`error`);return}let o=await Q.linkTagToSpoolmanSpool(t.id,{tray_uuid:a,tag_uid:i});if(!o){r(n(`spoolman.linkFailed`),`error`);return}let{id:s,material:c,subtype:l,color_name:u,rgba:d,brand:f,label_weight:p,core_weight:m,weight_used:h}=o;j({id:s,material:c,subtype:l,color_name:u,rgba:d,brand:f,label_weight:p,core_weight:m,weight_used:h}),r(n(`spoolman.linkSuccess`),`success`)}else await Q.linkTagToSpool(t.id,{tag_uid:h,tag_type:`generic`,data_origin:`nfc_link`});s()}catch(e){console.error(`Failed to link tag:`,e),r(n(`spoolman.linkFailed`),`error`)}finally{C(!1)}},H=async()=>{if(h){k(!0);try{let t=te??_;if(a){let n=await Q.createSpoolmanInventorySpool({material:`PLA`,subtype:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,brand:null,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,cost_per_kg:null,last_scale_weight:t===null?null:Math.round(t),last_weighed_at:t===null?null:new Date().toISOString(),category:null,low_stock_threshold_pct:null});await Q.linkTagToSpoolmanSpool(n.id,{tag_uid:e.unknownTagUid||void 0,tray_uuid:!e.unknownTagUid&&e.unknownTrayUuid?e.unknownTrayUuid:void 0})}else await Q.createSpool({material:`PLA`,subtype:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,brand:null,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:h,tray_uuid:null,data_origin:`spoolbuddy`,tag_type:`generic`,cost_per_kg:null,last_scale_weight:t===null?null:Math.round(t),last_weighed_at:t===null?null:new Date().toISOString(),category:null,low_stock_threshold_pct:null})}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`Failed to quick-add spool:`,t),r(t||n(`spoolbuddy.errors.quickAddFailed`,`Failed to add spool`),`error`)}finally{D(!1),k(!1),s()}}},te=N!==null&&(M===h||M===null&&h!==null)?N:null,ne=o.length,re=new Set(o.map(e=>e.material)).size,U=new Set(o.filter(e=>e.brand).map(e=>e.brand)).size;return(0,K.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-6 px-4 py-1.5 bg-zinc-800/50 rounded-xl border border-zinc-700/50 mb-3 shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:ne}),(0,K.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.inventory.spools`,`Spools`)})]}),(0,K.jsx)(`div`,{className:`w-px h-5 bg-zinc-700`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:re}),(0,K.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.material`,`Materials`)})]}),(0,K.jsx)(`div`,{className:`w-px h-5 bg-zinc-700`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:U}),(0,K.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.brand`,`Brands`)})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 flex gap-4 min-h-0`,children:[(0,K.jsxs)(`div`,{className:`w-5/12 flex flex-col min-h-0`,children:[(0,K.jsxs)(`div`,{className:`border border-dashed border-zinc-700/50 rounded-xl p-4`,children:[(0,K.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-3`,children:n(`spoolbuddy.dashboard.device`,`Device`)}),(0,K.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full ${e.deviceOnline?`bg-green-500`:`bg-red-500`}`}),(0,K.jsx)(`span`,{className:`text-base text-zinc-400`,children:e.deviceOnline?n(`spoolbuddy.status.online`,`Online`):n(`spoolbuddy.status.offline`,`Disconnected`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`svg`,{className:`w-4 h-4 ${e.deviceOnline?`text-green-500`:`text-zinc-500`}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M3 6l3 1m0 0l-3 9a5.002 5.002 0 006.001 0M6 7l3 9M6 7l6-2m6 2l3-1m-3 1l-3 9a5.002 5.002 0 006.001 0M18 7l3 9m-3-9l-6-2m0-2v2m0 16V5m0 16H9m3 0h3`})}),(0,K.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.scaleWeight`,`Scale`)})]}),(0,K.jsx)(`span`,{className:`text-lg font-mono font-semibold text-zinc-100`,children:I===null?`—`:`${Math.abs(I)<=20?0:Math.round(Math.max(0,I))}g`})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`svg`,{className:`w-4 h-4 ${e.deviceOnline?`text-green-500`:`text-zinc-500`}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z`})}),(0,K.jsx)(`span`,{className:`text-sm text-zinc-500`,children:`NFC`})]}),(0,K.jsx)(`span`,{className:`text-sm font-medium ${M?`text-green-500`:`text-zinc-500`}`,children:M?n(`spoolbuddy.dashboard.tagDetected`,`Tag detected`):n(`spoolbuddy.dashboard.noTag`,`No tag`)})]})]})]}),l.length>0&&(0,K.jsxs)(`div`,{className:`mt-3 border border-dashed border-zinc-700/50 rounded-xl p-4`,children:[(0,K.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-2.5`,children:n(`spoolbuddy.dashboard.printers`,`Printers`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2 overflow-hidden`,children:l.map((e,t)=>{let n=u[t]?.data?.connected??!1;return(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2.5 py-1 bg-zinc-800/50 rounded-lg`,title:`${e.name} — ${n?`Online`:`Offline`}`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${n?`bg-green-500`:`bg-zinc-600`}`}),(0,K.jsx)(`span`,{className:`text-xs text-zinc-400 truncate max-w-[100px]`,children:e.name})]},e.id)})}),d.length>0&&(0,K.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,"data-testid":`plate-clear-section`,"aria-label":n(`spoolbuddy.dashboard.plateReadyLabel`,`Plates ready to clear`),children:d.map(({printer:e})=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>p.mutate(e.id),disabled:p.isPending,"data-testid":`plate-clear-button-${e.id}`,title:n(`spoolbuddy.dashboard.plateReady`,`Plate ready: {{name}}`,{name:e.name}),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-amber-500/10 hover:bg-amber-500/20 active:bg-amber-500/30 border border-amber-500/30 text-amber-200 transition-colors disabled:opacity-60 disabled:cursor-wait`,children:[(0,K.jsxs)(`svg`,{className:`w-3 h-3 shrink-0`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,K.jsx)(`path`,{d:`M12 9v4`}),(0,K.jsx)(`path`,{d:`M12 17h.01`}),(0,K.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`})]}),(0,K.jsx)(`span`,{className:`text-xs truncate max-w-[100px]`,children:e.name}),(0,K.jsx)(`span`,{className:`text-xs opacity-70`,"aria-hidden":`true`,children:`·`}),(0,K.jsx)(`span`,{className:`text-xs font-medium`,children:n(`spoolbuddy.dashboard.plateClearAction`,`Clear`)})]},e.id))})]})]}),(0,K.jsx)(`div`,{className:`w-7/12 min-h-0`,children:(0,K.jsxs)(`div`,{className:`border border-dashed border-zinc-700/50 rounded-xl p-6 h-full flex flex-col`,children:[(0,K.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-4 shrink-0`,children:n(`spoolbuddy.dashboard.currentSpool`,`Current Spool`)}),(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:e.deviceOnline?(L||e.matchedSpool)&&h&&b!==h?(0,K.jsx)(mHe,{spool:(()=>{let t=L??e.matchedSpool;return{id:t.id,tag_uid:h,material:t.material,subtype:t.subtype,color_name:t.color_name,rgba:t.rgba,brand:t.brand,label_weight:t.label_weight,core_weight:t.core_weight,weight_used:t.weight_used}})(),scaleWeight:te??_,onSyncWeight:()=>s(),onAssignToAms:()=>T(!0),isAssigned:z,onUnassignFromAms:z&&L?.id!=null?()=>m.mutate(L.id):void 0,onClose:V}):M&&h&&!L&&!e.matchedSpool&&b!==h?(0,K.jsx)(hHe,{tagUid:h,scaleWeight:te??_,onLinkSpool:B.length>0?()=>C(!0):void 0,onAddToInventory:()=>D(!0),onClose:V}):(0,K.jsx)(jHe,{}):(0,K.jsx)(MHe,{})})]})})]}),R&&!A&&h&&(0,K.jsx)(V9,{isOpen:w,onClose:()=>T(!1),spool:R,printerId:t,spoolmanMode:a}),h&&(0,K.jsx)(kHe,{isOpen:S,onClose:()=>C(!1),tagId:h,untaggedSpools:B,onLink:ee}),E&&h&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,children:(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-2xl p-6 mx-4 max-w-sm w-full border border-zinc-700`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100 mb-3`,children:n(`spoolbuddy.modal.addToInventory`,`Add to Inventory`)}),(0,K.jsxs)(`div`,{className:`flex gap-2.5 p-3 bg-amber-500/10 border border-amber-500/20 rounded-lg mb-4`,children:[(0,K.jsx)(`svg`,{className:`w-5 h-5 text-amber-500 shrink-0 mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`})}),(0,K.jsx)(`p`,{className:`text-sm text-amber-200/80`,children:n(`spoolbuddy.modal.quickAddHint`,`For best results, add the spool in the Bambuddy web interface first (with material, color, brand), then use "Assign Spool" here to assign the NFC tag.`)})]}),(0,K.jsx)(`p`,{className:`text-sm text-zinc-400 mb-1`,children:n(`spoolbuddy.modal.quickAddDesc`,`This will create a basic PLA spool entry with this NFC tag. You can edit the details later in Bambuddy.`)}),(0,K.jsx)(`p`,{className:`text-xs text-zinc-500 font-mono mb-5`,children:h}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)(`button`,{onClick:()=>D(!1),className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:n(`common.cancel`,`Cancel`)}),(0,K.jsx)(`button`,{onClick:H,disabled:O,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-50 transition-colors min-h-[44px]`,children:O?n(`common.saving`,`Saving...`):n(`spoolbuddy.modal.addAnyway`,`Add Anyway`)})]})]})})]})}function W9(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function PHe(e){return e?{O1D:`H2D`,O1E:`H2D Pro`,O2D:`H2D Pro`,O1C:`H2C`,O1C2:`H2C`,O1S:`H2S`,"BL-P001":`X1C`,"BL-P002":`X1`,"BL-P003":`X1E`,N6:`X2D`,N9:`A2L`,C11:`P1S`,C12:`P1P`,C13:`P2S`,N2S:`A1`,N1:`A1 Mini`,X1C:`X1C`,X1:`X1`,X1E:`X1E`,X2D:`X2D`,P1S:`P1S`,P1P:`P1P`,P2S:`P2S`,A1:`A1`,"A1 Mini":`A1 Mini`,A2L:`A2L`,H2D:`H2D`,"H2D Pro":`H2D Pro`,H2C:`H2C`,H2S:`H2S`}[e]||e:``}function G9(e){return!e.tray_type||e.tray_type===``}function FHe(e){return e?`#${e.slice(0,6)}`:`#808080`}function IHe(){let{selectedPrinterId:e,setAlert:t}=Qn(),{t:n}=G(),r=Qa(),{showToast:i}=xd(),{data:a}=q({queryKey:[`printerStatus`,e],queryFn:()=>Q.getPrinterStatus(e),enabled:e!==null,staleTime:30*1e3}),{data:o}=q({queryKey:[`printer`,e],queryFn:()=>Q.getPrinter(e),enabled:e!==null,staleTime:60*1e3}),{data:s}=q({queryKey:[`slotPresets`,e],queryFn:()=>Q.getSlotPresets(e),enabled:e!==null,staleTime:120*1e3}),{data:c}=q({queryKey:[`settings`],queryFn:()=>Q.getSettings(),staleTime:300*1e3}),{data:l}=q({queryKey:[`spoolman-status`],queryFn:Q.getSpoolmanStatus,staleTime:60*1e3}),u=l?.enabled&&l?.connected,{data:d}=q({queryKey:[`linked-spools`],queryFn:Q.getLinkedSpools,enabled:!!u,staleTime:30*1e3}),f=d?.linked,{data:p=[]}=q({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:!!u,staleTime:30*1e3}),{data:m=[]}=q({queryKey:[`spoolman-inventory-spools`],queryFn:()=>Q.getSpoolmanInventorySpools(!1),enabled:!!u,staleTime:30*1e3}),{data:h}=q({queryKey:[`spool-assignments`,e],queryFn:()=>Q.getAssignments(e),enabled:e!==null,staleTime:30*1e3}),g=(0,y.useMemo)(()=>{let e={};if(!h)return e;for(let t of h){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[h]),_=o?.serial_number??``,v=(0,y.useCallback)((t,n,r)=>{if(e!==null&&p.length&&m.length){let r=p.find(r=>r.printer_id===e&&r.ams_id===t&&r.tray_id===n);if(r){let e=m.find(e=>e.id===r.spoolman_spool_id);if(e&&(e.label_weight??0)>0)return Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100)}}if(f&&_){let e=(r?.tray_uuid||r?.tag_uid||VK(_,t,n))?.toUpperCase(),i=zK(e?f[e]:void 0);if(i!==null)return i}return null},[f,_,e,p,m]),b=a?.connected??!1,x=(0,y.useRef)({});(0,y.useEffect)(()=>{e&&a?.ams&&a.ams.length>0&&(x.current[e]=a.ams)},[a?.ams,e]);let S=(0,y.useMemo)(()=>{let t=a?.ams;return t&&t.length>0?t:(e?x.current[e]:null)??[]},[a?.ams,e]),C=(0,y.useMemo)(()=>S.filter(e=>!e.is_ams_ht),[S]),w=(0,y.useMemo)(()=>S.filter(e=>e.is_ams_ht),[S]),T=(0,y.useMemo)(()=>{let e={};if(!f||!_)return e;for(let t of C)for(let n=0;n<(t.tray?.length??0);n++){let r=t.tray[n],i=v(t.id,n,G9(r)?null:r);i!==null&&(e[`${t.id}-${n}`]=i)}return e},[f,_,C,v]),E=(0,y.useRef)(void 0),D=a?.tray_now;D!==void 0&&D!==255?E.current=D:D===255&&(E.current=void 0);let O=D!==void 0&&D!==255?D:E.current,k=o?.nozzle_count===2||a?.temperatures?.nozzle_2!==void 0,A=(0,y.useMemo)(()=>[...a?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[a?.vt_tray]),j=c?{humidityGood:Number(c.ams_humidity_good)||40,humidityFair:Number(c.ams_humidity_fair)||60,tempGood:Number(c.ams_temp_good)||28,tempFair:Number(c.ams_temp_fair)||35}:void 0,M=(0,y.useRef)({});(0,y.useEffect)(()=>{a?.ams_extruder_map&&Object.keys(a.ams_extruder_map).length>0&&(M.current=a.ams_extruder_map)},[a?.ams_extruder_map]);let N=a?.ams_extruder_map&&Object.keys(a.ams_extruder_map).length>0?a.ams_extruder_map:M.current,P=(0,y.useCallback)(e=>{if(!k)return null;let t=N[String(e)],n=e>=128?e-128:e;return(t===void 0?n:t)===1?`L`:`R`},[k,N]),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(null),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)(null),H=(0,y.useCallback)((e,t)=>h?.find(n=>n.ams_id===Number(e)&&n.tray_id===Number(t)),[h]),te=(0,y.useCallback)((e,t,n)=>{if(!f||!_)return;let r=(n?.tray_uuid||n?.tag_uid||VK(_,e,t))?.toUpperCase();return r?f[r]:void 0},[f,_]),ne=J({mutationFn:({printerId:e,amsId:t,trayId:n})=>Q.unassignSpool(e,t,n),onSuccess:()=>{r.invalidateQueries({queryKey:[`spool-assignments`,e]}),r.invalidateQueries({queryKey:[`spool-assignments`]}),i(n(`inventory.unassignSuccess`,`Spool unassigned`),`success`),R(null)}}),re=J({mutationFn:e=>Q.unlinkSpool(e),onSuccess:e=>{i(n(`spoolman.unlinkSuccess`)||e?.message,`success`),r.invalidateQueries({queryKey:[`linked-spools`]}),r.invalidateQueries({queryKey:[`unlinked-spools`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),r.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),R(null)},onError:e=>{i(e.message||n(`spoolman.unlinkFailed`),`error`)}}),U=J({mutationFn:e=>Q.unassignSpoolmanSlot(e),onSuccess:()=>{i(n(`inventory.unassignSuccess`,`Spool unassigned`),`success`),r.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),r.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),r.invalidateQueries({queryKey:[`unlinked-spools`]}),r.invalidateQueries({queryKey:[`linked-spools`]}),R(null)},onError:e=>{i(e.message||n(`inventory.assignFailed`,`Failed to unassign spool`),`error`)}}),ie=(0,y.useCallback)(e=>O===void 0?null:e<=3&&Math.floor(O/4)===e?O%4:e>=128&&e<=135&&O===LK(e,0,!1)?0:null,[O]),ae=(0,y.useCallback)((e,t,n)=>{let r=LK(e,t,!1),i=s?.[r],a=N[String(e)],o=e>=128?e-128:e,c=a===void 0?o:a;R({amsId:e,trayId:t,trayCount:n&&e>=128?1:4,tray:n,trayType:n?.tray_type||void 0,trayColor:n?.tray_color||void 0,traySubBrands:n?.tray_sub_brands||void 0,trayInfoIdx:n?.tray_info_idx||void 0,extruderId:k?c:void 0,caliIdx:n?.cali_idx,savedPresetId:i?.preset_id,location:`${W9(e)} Slot ${t+1}`})},[s,N,k]),W=(0,y.useCallback)(e=>{let t=e.id??254,n=t-254,r=s?.[1020+n];R({amsId:255,trayId:n,trayCount:1,tray:G9(e)?null:e,trayType:e.tray_type||void 0,trayColor:e.tray_color||void 0,traySubBrands:e.tray_sub_brands||void 0,trayInfoIdx:e.tray_info_idx||void 0,extruderId:k?+(t===254):void 0,caliIdx:e.cali_idx,savedPresetId:r?.preset_id,location:k?t===254?`Ext-L`:`Ext-R`:`External`})},[s,k]),oe=(0,y.useCallback)(()=>{if(!L)return;let{tray:e,location:t,...n}=L;R(null),I(n)},[L]),se=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n,trayType:r,trayColor:i,location:a}=L;R(null),B({printerId:e,amsId:t,trayId:n,trayInfo:{type:r||``,material:r,color:i?.slice(0,6)||``,location:a}})},[L,e]),ce=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n,tray:r}=L,i=(r?.tray_uuid||r?.tag_uid||VK(_,t,n))?.toUpperCase()||``;R(null),ee({tagUid:r?.tag_uid||i,trayUuid:r?.tray_uuid||``,printerId:e,amsId:t,trayId:n})},[L,e,_]),le=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n}=L;ne.mutate({printerId:e,amsId:t,trayId:n})},[L,e,ne]);(0,y.useEffect)(()=>{if(!b&&e){t({type:`warning`,message:n(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)});return}for(let e of S){let n=e.tray||[];for(let r=0;r=0&&i.remain<15&&i.tray_type){let n=e.id===254||e.id===255,a=!n&&e.id>=128,o=IK(e.id,r,a,n);t({type:`warning`,message:`Low Filament: ${i.tray_type} (${o}) - ${i.remain}% remaining`});return}}}t(null)},[S,b,e,t,n]);let ue=(0,y.useMemo)(()=>{let e=[];for(let t of w){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=v(t.id,0,G9(n)?null:n),i=g[`${t.id}-0`]??null,a=n.remain!=null&&n.remain>=0?n.remain:null,o=i===0&&a!==null&&a>0?null:i;e.push({key:`ht-${t.id}`,label:W9(t.id),tray:n,isEmpty:G9(n),isActive:ie(t.id)===0,temp:t.temp,humidity:t.humidity,nozzleSide:P(t.id),effectiveFill:r??o??a,onClick:()=>ae(t.id,0,G9(n)?null:n)})}for(let t of A){let r=t.id??254,i=k&&O===254?r===254&&a?.active_extruder===1||r===255&&a?.active_extruder===0:O===r,o=r-254,s=v(255,o,G9(t)?null:t),c=g[`255-${o}`]??null,l=t.remain!=null&&t.remain>=0?t.remain:null,u=c===0&&l!==null&&l>0?null:c;e.push({key:`ext-${r}`,label:k?r===254?n(`printers.extL`,`Ext-L`):n(`printers.extR`,`Ext-R`):n(`printers.ext`,`Ext`),tray:t,isEmpty:G9(t),isActive:i,nozzleSide:null,effectiveFill:s??u??l,onClick:()=>W(t)})}return e},[w,A,k,O,a?.active_extruder,n,ie,P,ae,W,g,v]);return(0,K.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,K.jsx)(`div`,{className:`flex-1 min-h-0`,children:e?b?S.length===0&&A.length===0?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,K.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,K.jsx)(Nc,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,K.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,K.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,K.jsxs)(`div`,{className:`flex flex-col gap-3 h-full`,children:[(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:C.map(e=>(0,K.jsx)(L9,{unit:e,activeSlot:ie(e.id),onConfigureSlot:ae,isDualNozzle:k,nozzleSide:P(e.id),thresholds:j,fillOverrides:g,spoolmanFillOverrides:T},e.id))}),ue.length>0&&(0,K.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-3`,children:ue.map(({key:e,label:t,tray:n,isEmpty:r,isActive:i,temp:a,humidity:o,nozzleSide:s,effectiveFill:c,onClick:l})=>{let u=FHe(n.tray_color);return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-3 ${i?`ring-2 ring-bambu-green`:``}`,onClick:l,children:[(0,K.jsxs)(`div`,{className:`relative w-10 h-10 flex-shrink-0`,children:[r?(0,K.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,K.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,K.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:u}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:u,style:{filter:`brightness(0.85)`}}),(0,K.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),i&&(0,K.jsx)(`div`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1.5 h-1.5 bg-bambu-green rounded-full`})]}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-white/50 font-medium truncate`,children:t}),s&&(0,K.jsx)(I9,{side:s})]}),(0,K.jsx)(`div`,{className:`text-sm text-white/80 truncate`,children:r?`Empty`:n.tray_type||`?`}),(a!=null||o!=null)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[a!=null&&(0,K.jsx)(F9,{temp:a,goodThreshold:j?.tempGood,fairThreshold:j?.tempFair}),o!=null&&(0,K.jsx)(P9,{humidity:o,goodThreshold:j?.humidityGood,fairThreshold:j?.humidityFair})]})]}),!r&&c!=null&&c>=0&&(0,K.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0 flex flex-col-reverse`,children:(0,K.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${c}%`,backgroundColor:RK(c)}})})]},e)})})]}):(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,K.jsx)(`div`,{className:`text-center text-white/50`,children:(0,K.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})})}):(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,K.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,K.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.noPrinter`,`No printer selected`)}),(0,K.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.ams.selectPrinter`,`Select a printer from the top bar`)})]})})}),F&&e&&(0,K.jsx)(DK,{isOpen:!!F,onClose:()=>I(null),printerId:e,slotInfo:F,printerModel:PHe(o?.model??null)||void 0,fullScreen:!0,onSuccess:()=>{r.invalidateQueries({queryKey:[`slotPresets`,e]}),r.invalidateQueries({queryKey:[`printerStatus`,e]})}}),L&&e&&(()=>{let t=H(L.amsId,L.trayId),r=te(L.amsId,L.trayId,L.tray),i=u?p.find(t=>t.printer_id===e&&t.ams_id===L.amsId&&t.tray_id===L.trayId):void 0,a=i?m.find(e=>e.id===i.spoolman_spool_id)??null:null;return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:()=>R(null)}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-sm mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl`,children:[(0,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:[L.trayColor&&(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${L.trayColor.slice(0,6)}`}}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:L.location}),L.traySubBrands&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,L.traySubBrands,`)`]})]}),(0,K.jsx)(`button`,{onClick:()=>R(null),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(Pu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-2`,children:[!u&&t?.spool&&(0,K.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`inventory.assignedSpool`,`Assigned spool`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.spool.rgba&&(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:Wd(t.spool.rgba)}),(0,K.jsxs)(`span`,{className:`text-sm text-white`,children:[t.spool.brand?`${t.spool.brand} `:``,t.spool.material,t.spool.color_name?` - ${t.spool.color_name}`:``]}),(0,K.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0 ml-auto`,children:[`#`,t.spool.id]})]})]}),u&&r&&!a&&(0,K.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`spoolman.linkedSpool`,`Linked spool`)}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,K.jsxs)(`span`,{className:`text-sm text-white`,children:[`Spoolman #`,r.id,r.remaining_weight==null?``:` (${Math.round(r.remaining_weight)}g)`]})})]}),u&&a&&(0,K.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`inventory.assignedSpool`,`Assigned spool`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a.rgba&&(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:Wd(a.rgba)}),(0,K.jsxs)(`span`,{className:`text-sm text-white`,children:[a.brand?`${a.brand} `:``,a.material,a.color_name?` - ${a.color_name}`:``]})]})]}),(0,K.jsxs)(`button`,{onClick:oe,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-blue transition-colors text-left`,children:[(0,K.jsx)(Ll,{className:`w-5 h-5 text-bambu-blue flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:n(`configureAmsSlot.title`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.configureDesc`,`Set filament preset, K-profile, and color`)})]})]}),!u&&(qK(L?.tray)?null:t?(0,K.jsxs)(`button`,{onClick:le,disabled:ne.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left`,children:[(0,K.jsx)(xu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`,`Unassign`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unassignDesc`,`Remove inventory spool from this slot`)})]})]}):(0,K.jsxs)(`button`,{onClick:se,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left`,children:[(0,K.jsx)(cl,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.assignSpool`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.assignDesc`,`Track a spool from your inventory`)})]})]})),u&&(r?.id?(0,K.jsxs)(`button`,{onClick:()=>re.mutate(r.id),disabled:re.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left active:opacity-50`,children:[(0,K.jsx)(xu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unlinkDesc`,`Remove Spoolman link from this slot`)})]})]}):a?(0,K.jsxs)(`button`,{onClick:()=>U.mutate(a.id),disabled:U.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left active:opacity-50`,children:[(0,K.jsx)(xu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unassignDesc`,`Remove inventory spool from this slot`)})]})]}):(0,K.jsxs)(`button`,{onClick:ce,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left`,children:[(0,K.jsx)(Ic,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.assignSpool`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.linkDesc`,`Link a Spoolman spool to this slot`)})]})]}))]})]})]})})(),z&&(0,K.jsx)(QG,{isOpen:!!z,onClose:()=>{B(null),r.invalidateQueries({queryKey:[`spool-assignments`,e]}),r.invalidateQueries({queryKey:[`spool-assignments`]})},printerId:z.printerId,amsId:z.amsId,trayId:z.trayId,trayInfo:z.trayInfo,spoolmanEnabled:!!u}),V&&(0,K.jsx)(XG,{isOpen:!!V,onClose:()=>ee(null),tagUid:V.tagUid,trayUuid:V.trayUuid,printerId:V.printerId,amsId:V.amsId,trayId:V.trayId})]})}function LHe({type:e,deviceId:t,onClose:n}){let{t:r}=G(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)(!1);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!i&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i,n]);let f=(0,y.useCallback)(async()=>{a(!0),s(``),l(``),d(!0);try{s(r(`spoolbuddy.diagnostic.queuing`,`Queuing diagnostic on device... +`)),await nd.queueDiagnostics(t,e);let n=null,i=0;for(;i<60&&!n;){await new Promise(e=>setTimeout(e,500));try{n=await nd.getDiagnosticResult(t,e);break}catch{i++,i%4==0&&s(e=>e+`.`)}}if(!n)throw Error(`Diagnostic timed out - device did not report results`);s(n.output),n.success||l(`Exit code: ${n.exit_code}`)}catch(e){l(e instanceof Error?e.message:`Unknown error`),s(``)}finally{a(!1)}},[e,t,r]);return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in`,onClick:n,children:(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg shadow-xl w-full max-w-2xl mx-4 max-h-[80vh] flex flex-col animate-slide-up`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex justify-between items-center p-4 border-b border-zinc-700`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e===`scale`?r(`spoolbuddy.diagnostic.scaleTitle`,`Scale Diagnostic`):e===`read_tag`?r(`spoolbuddy.diagnostic.readTagTitle`,`Read Tag Diagnostic`):r(`spoolbuddy.diagnostic.nfcTitle`,`NFC Reader Diagnostic`)}),(0,K.jsx)(`button`,{onClick:n,className:`text-zinc-400 hover:text-white transition-colors`,"aria-label":`Close`,children:(0,K.jsx)(Pu,{size:20})})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-auto p-4 bg-black/50 font-mono text-sm`,children:i?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-green-400`,children:[(0,K.jsx)(`div`,{className:`animate-spin w-4 h-4 border-2 border-green-400 border-t-transparent rounded-full`}),(0,K.jsx)(`span`,{children:r(`spoolbuddy.diagnostic.running`,`Running diagnostic on device...`)})]}):o?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`text-green-400 whitespace-pre-wrap break-words`,children:o}),c&&(0,K.jsxs)(`div`,{className:`text-red-400 mt-2`,children:[`❌ `,c]})]}):u?(0,K.jsx)(`div`,{children:c?(0,K.jsxs)(`div`,{className:`text-red-400`,children:[`ERROR: `,c]}):(0,K.jsx)(`span`,{className:`text-green-400`,children:r(`spoolbuddy.diagnostic.completed`,`Diagnostic completed successfully.`)})}):(0,K.jsxs)(`div`,{className:`text-zinc-500`,children:[r(`spoolbuddy.diagnostic.clickStart`,`Click "Run Diagnostic" to start the hardware diagnostic on`),` `,t,`.`]})}),(0,K.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-zinc-700 bg-zinc-800`,children:[(0,K.jsx)(`button`,{onClick:f,disabled:i,className:`flex-1 flex items-center justify-center gap-2 bg-green-600 hover:bg-green-700 disabled:bg-gray-600 disabled:cursor-not-allowed px-4 py-2 rounded font-semibold text-white transition-colors`,children:i?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`animate-spin w-4 h-4 border-2 border-white border-t-transparent rounded-full`}),r(`spoolbuddy.diagnostic.runningBtn`,`Running...`)]}):u?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(El,{size:16}),r(`spoolbuddy.diagnostic.runAgain`,`Run Again`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(hl,{size:16}),r(`spoolbuddy.diagnostic.runBtn`,`Run Diagnostic`)]})}),(0,K.jsx)(`button`,{onClick:n,className:`px-4 py-2 rounded bg-zinc-700 hover:bg-zinc-600 text-white font-semibold transition-colors`,children:r(`spoolbuddy.diagnostic.close`,`Close`)})]})]})})}function RHe(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m`:`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`}function zHe(e){if(!e)return`-`;let t=mf(e);return t?t.toLocaleDateString(void 0,{month:`short`,day:`numeric`})+` `+t.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`}):`-`}var BHe=[{label:`Off`,value:0},{label:`1m`,value:60},{label:`2m`,value:120},{label:`5m`,value:300},{label:`10m`,value:600},{label:`30m`,value:1800}];function VHe({device:e}){let{t}=G(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null);return(0,y.useEffect)(()=>{!i&&e.backend_url&&a(e.backend_url)},[e.backend_url,i]),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.nfcReader`,`NFC Reader`)}),(0,K.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.type`,`Type`)}),(0,K.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:e.nfc_reader_type||`N/A`})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.connection`,`Connection`)}),(0,K.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:e.nfc_connection||`N/A`})]}),(0,K.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.status.status`,`Status`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full ${e.nfc_ok?`bg-green-500`:e.nfc_reader_type?`bg-red-500`:`bg-zinc-600`}`}),(0,K.jsx)(`span`,{className:e.nfc_ok?`text-green-400`:e.nfc_reader_type?`text-red-400`:`text-zinc-500`,children:e.nfc_ok?t(`spoolbuddy.status.nfcReady`,`Ready`):e.nfc_reader_type?t(`common.error`,`Error`):t(`spoolbuddy.settings.notConnected`,`N/A`)})]})]})]})]}),(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.deviceInfo`,`Device Info`)}),(0,K.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.hostname`,`Host`)}),(0,K.jsx)(`span`,{className:`text-zinc-300 truncate ml-2`,children:e.hostname})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:`IP`}),(0,K.jsx)(`span`,{className:`text-zinc-300`,children:e.ip_address})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.uptime`,`Uptime`)}),(0,K.jsx)(`span`,{className:`text-zinc-300`,children:RHe(e.uptime_s)})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:`ID`}),(0,K.jsx)(`span`,{className:`text-zinc-400 font-mono truncate ml-2`,children:e.device_id})]})]})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 space-y-2`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300`,children:t(`spoolbuddy.settings.systemConfig`,`Backend & Auth`)}),(0,K.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),placeholder:`http://192.168.1.100:5000`,className:`w-full px-2 py-1.5 rounded bg-zinc-900 border border-zinc-700 text-zinc-100 text-xs`}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`password`,value:o,onChange:e=>s(e.target.value),placeholder:t(`spoolbuddy.settings.apiTokenPlaceholder`,`API token`),className:`flex-1 px-2 py-1.5 rounded bg-zinc-900 border border-zinc-700 text-zinc-100 text-xs`}),(0,K.jsx)(`button`,{onClick:async()=>{if(!i.trim()){d({type:`error`,text:t(`spoolbuddy.settings.systemFieldsRequired`,`Backend URL is required.`)});return}l(!0),d(null);try{await nd.updateSystemConfig(e.device_id,i.trim(),o.trim()||void 0),d({type:`ok`,text:t(`spoolbuddy.settings.systemQueued`,`Config queued.`)})}catch(e){d({type:`error`,text:e instanceof Error?e.message:t(`common.error`,`Error`)})}finally{l(!1)}},disabled:c,className:`px-3 py-1.5 rounded bg-green-700 hover:bg-green-600 disabled:bg-zinc-700 text-xs font-medium text-zinc-100`,children:t(`spoolbuddy.settings.saveConfig`,`Save`)})]}),u&&(0,K.jsx)(`div`,{className:`text-xs ${u.type===`ok`?`text-green-400`:`text-red-400`}`,children:u.text})]}),(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 flex flex-col gap-2`,children:[(0,K.jsxs)(`button`,{onClick:()=>r(`nfc`),className:`flex-1 bg-blue-700 hover:bg-blue-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,K.jsx)(Ou,{className:`w-4 h-4 text-blue-300 shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs font-medium text-blue-100`,children:t(`spoolbuddy.settings.nfcDiagnostic`,`NFC Diagnostic`)})]}),(0,K.jsxs)(`button`,{onClick:()=>r(`scale`),className:`flex-1 bg-yellow-700 hover:bg-yellow-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,K.jsx)(Iu,{className:`w-4 h-4 text-yellow-300 shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs font-medium text-yellow-100`,children:t(`spoolbuddy.settings.scaleDiagnostic`,`Scale Diagnostic`)})]}),(0,K.jsxs)(`button`,{onClick:()=>r(`read_tag`),className:`flex-1 bg-emerald-700 hover:bg-emerald-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,K.jsx)(Zs,{className:`w-4 h-4 text-emerald-300 shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs font-medium text-emerald-100`,children:t(`spoolbuddy.settings.readTagDiagnostic`,`Read Tag`)})]})]})]}),n&&e&&(0,K.jsx)(LHe,{type:n,deviceId:e.device_id,onClose:()=>r(null)})]})}function HHe({device:e,onBrightnessChange:t}){let{t:n}=G(),[r,i]=(0,y.useState)(e.display_brightness),[a,o]=(0,y.useState)(e.display_blank_timeout),[s,c]=(0,y.useState)(!1),l=(0,y.useRef)(void 0),u=(0,y.useRef)(void 0);(0,y.useEffect)(()=>{i(e.display_brightness),o(e.display_blank_timeout)},[e.display_brightness,e.display_blank_timeout]);let d=(0,y.useCallback)(()=>{c(!0),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>c(!1),1500)},[]),f=(0,y.useCallback)((t,n)=>{l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{nd.updateDisplay(e.device_id,t,n).then(()=>d()).catch(e=>console.error(`Failed to update display:`,e))},300)},[e.device_id,d]),p=e=>{i(e),t(e),f(e,a)},m=e=>{o(e),f(r,e)};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300`,children:n(`spoolbuddy.settings.brightness`,`Brightness`)}),s&&(0,K.jsxs)(`span`,{className:`text-xs text-green-400 flex items-center gap-1 animate-pulse`,children:[(0,K.jsx)(`svg`,{className:`w-3 h-3`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:3,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}),n(`spoolbuddy.settings.saved`,`Saved`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`svg`,{className:`w-4 h-4 text-zinc-500 flex-shrink-0`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z`})}),(0,K.jsx)(`input`,{type:`range`,min:0,max:100,value:r,onChange:e=>p(parseInt(e.target.value)),className:`flex-1 h-2 bg-zinc-700 rounded-lg appearance-none cursor-pointer accent-green-500`}),(0,K.jsxs)(`span`,{className:`text-sm font-mono text-zinc-400 w-10 text-right`,children:[r,`%`]})]}),!e.has_backlight&&(0,K.jsx)(`p`,{className:`text-xs text-zinc-600 mt-2`,children:n(`spoolbuddy.settings.noBacklight`,`No DSI backlight detected. Brightness control requires a DSI display.`)})]}),(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1`,children:n(`spoolbuddy.settings.screenBlank`,`Screen Blank Timeout`)}),(0,K.jsx)(`p`,{className:`text-xs text-zinc-500 mb-3`,children:n(`spoolbuddy.settings.screenBlankDesc`,`Screen turns off after inactivity. Touch to wake.`)}),(0,K.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:BHe.map(e=>(0,K.jsx)(`button`,{onClick:()=>m(e.value),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors min-h-[40px] ${a===e.value?`bg-green-600 text-white`:`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`}`,children:e.label},e.value))})]}),(0,K.jsx)(`p`,{className:`text-xs text-zinc-600 text-center`,children:n(`spoolbuddy.settings.displayNote`,`Brightness is applied as a software filter.`)})]})}function UHe({step:e,labels:t}){return(0,K.jsxs)(`div`,{className:`flex flex-col items-center w-16 shrink-0 pt-1`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold ${e===`tare`?`bg-green-600 text-white`:`bg-green-600/20 text-green-400`}`,children:e===`weight`?(0,K.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:3,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}):`1`}),(0,K.jsx)(`span`,{className:`text-[10px] mt-0.5 ${e===`tare`?`text-green-400 font-medium`:`text-green-400/60`}`,children:t.tare}),(0,K.jsx)(`div`,{className:`w-px h-5 my-1 ${e===`weight`?`bg-green-600/40`:`bg-zinc-700`}`}),(0,K.jsx)(`div`,{className:`flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold ${e===`weight`?`bg-green-600 text-white`:`bg-zinc-700 text-zinc-500`}`,children:`2`}),(0,K.jsx)(`span`,{className:`text-[10px] mt-0.5 ${e===`weight`?`text-green-400 font-medium`:`text-zinc-600`}`,children:t.weight})]})}function WHe({device:e,weight:t,weightStable:n,rawAdc:r}){let{t:i}=G(),a=Qa(),[o,s]=(0,y.useState)(`idle`),[c,l]=(0,y.useState)(`500`),[u,d]=(0,y.useState)(null),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),v=(0,y.useRef)(null);(0,y.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]);let b=(0,y.useCallback)(e=>{v.current&&clearTimeout(v.current),v.current=setTimeout(()=>h(null),e)},[]);(0,y.useEffect)(()=>{if(!g)return;let e=()=>Date.now()-g.startedAtMs,t=setInterval(()=>{a.invalidateQueries({queryKey:[`spoolbuddy-devices`]})},1e3),n=setTimeout(()=>{_(null),h({type:`error`,msg:i(`spoolbuddy.settings.tareTimedOut`,`Tare timed out — is the SpoolBuddy daemon running?`)}),b(5e3)},Math.max(0,15e3-e()));return()=>{clearInterval(t),clearTimeout(n)}},[g,a,i,b]),(0,y.useEffect)(()=>{g&&(e?.last_calibrated_at??null)!==g.snapshot&&(_(null),h({type:`ok`,msg:i(`spoolbuddy.settings.tareComplete`,`Tare complete!`)}),b(3e3))},[e?.last_calibrated_at,g,i,b]);let x=e=>{e===`backspace`?l(e=>e.slice(0,-1)||``):e===`.`&&!c.includes(`.`)?l(e=>e+`.`):e>=`0`&&e<=`9`&&l(t=>t===`0`?e:t+e)};return o===`idle`?(0,K.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 mb-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,K.jsx)(`span`,{className:`text-lg font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`})]}),(0,K.jsxs)(`div`,{className:`text-xs text-zinc-500 text-right`,children:[(0,K.jsxs)(`span`,{children:[i(`spoolbuddy.settings.tareOffset`,`Tare`),`: `,e.tare_offset]}),(0,K.jsx)(`span`,{className:`mx-1.5`,children:`·`}),(0,K.jsxs)(`span`,{children:[i(`spoolbuddy.settings.calFactor`,`Factor`),`: `,e.calibration_factor.toFixed(2)]})]})]}),e.last_calibrated_at&&(0,K.jsxs)(`div`,{className:`text-xs text-zinc-600 mt-1`,children:[i(`spoolbuddy.settings.lastCalibrated`,`Last calibrated`),`: `,zHe(e.last_calibrated_at)]})]}),m&&(0,K.jsx)(`div`,{className:`rounded-lg px-3 py-2 mb-3 text-sm ${m.type===`ok`?`bg-green-900/30 text-green-300 border border-green-800`:`bg-red-900/30 text-red-300 border border-red-800`}`,children:m.msg}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`button`,{onClick:async()=>{p(!0),h(null),v.current&&=(clearTimeout(v.current),null);let t=e?.last_calibrated_at??null;try{await nd.tare(e.device_id),h({type:`ok`,msg:i(`spoolbuddy.settings.tareSet`,`Tare command sent. Waiting for device...`)}),_({snapshot:t,startedAtMs:Date.now()})}catch{h({type:`error`,msg:i(`spoolbuddy.settings.tareFailed`,`Failed to send tare command`)}),b(5e3)}finally{p(!1)}},disabled:f,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px] flex items-center justify-center gap-2`,children:[f&&(0,K.jsxs)(`svg`,{className:`w-4 h-4 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,K.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,K.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),i(`spoolbuddy.weight.tare`,`Tare`)]}),(0,K.jsx)(`button`,{onClick:()=>{s(`tare`),h(null)},className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:i(`spoolbuddy.weight.calibrate`,`Calibrate`)})]})]}):(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)(UHe,{step:o,labels:{tare:i(`spoolbuddy.weight.tare`,`Tare`),weight:i(`spoolbuddy.settings.knownWeight`,`Known weight`)}}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 bg-zinc-800 rounded-lg px-3 py-1.5 mb-1.5`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,K.jsx)(`span`,{className:`text-sm font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`}),(0,K.jsx)(`span`,{className:`text-xs ml-auto ${n?`text-green-400`:`text-amber-400`}`,children:n?i(`spoolbuddy.settings.stable`,`Stable`):i(`spoolbuddy.settings.settling`,`Settling...`)})]}),m&&(0,K.jsx)(`div`,{className:`rounded-lg px-3 py-1.5 mb-1.5 text-xs ${m.type===`ok`?`bg-green-900/30 text-green-300 border border-green-800`:`bg-red-900/30 text-red-300 border border-red-800`}`,children:m.msg}),o===`tare`?(0,K.jsx)(`p`,{className:`text-sm text-zinc-300 mb-3`,children:i(`spoolbuddy.settings.calStep1`,`Remove all items from the scale and press Set Zero.`)}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs text-zinc-400 shrink-0`,children:i(`spoolbuddy.settings.knownWeight`,`Known weight`)}),(0,K.jsxs)(`div`,{className:`flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1 text-right text-lg font-mono text-zinc-100`,children:[c||`0`,(0,K.jsx)(`span`,{className:`text-zinc-500 ml-1`,children:`g`})]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-4 gap-1 mb-1.5`,children:[`7`,`8`,`9`,`backspace`,`4`,`5`,`6`,`.`,`1`,`2`,`3`,`0`].map(e=>(0,K.jsx)(`button`,{onClick:()=>x(e),className:`rounded text-lg font-medium transition-colors h-[48px] active:scale-95 ${e===`backspace`?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`:`bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700`}`,children:e===`backspace`?`⌫`:e},e))})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>{s(`idle`),h(null)},className:`flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors h-[40px]`,children:i(`common.cancel`,`Cancel`)}),(0,K.jsxs)(`button`,{onClick:async()=>{if(o===`tare`){p(!0),h(null);try{d(r),await nd.tare(e.device_id),h({type:`ok`,msg:i(`spoolbuddy.settings.zeroSet`,`Zero point set. Place known weight on scale.`)}),s(`weight`)}catch{h({type:`error`,msg:i(`spoolbuddy.settings.tareFailed`,`Failed to send tare command`)})}finally{p(!1)}}else if(o===`weight`){let t=parseFloat(c);if(r===null||!t||t<=0)return;p(!0),h(null);try{await nd.setCalibrationFactor(e.device_id,t,r,u??void 0),h({type:`ok`,msg:i(`spoolbuddy.settings.calibrationDone`,`Calibration complete!`)}),b(3e3),s(`idle`)}catch{h({type:`error`,msg:i(`spoolbuddy.settings.calibrationFailed`,`Calibration failed`)}),b(5e3)}finally{p(!1)}}},disabled:f,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors h-[40px] flex items-center justify-center gap-2`,children:[f&&(0,K.jsxs)(`svg`,{className:`w-4 h-4 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,K.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,K.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),o===`tare`?i(`spoolbuddy.settings.setZero`,`Set Zero`):i(`spoolbuddy.settings.calibrateNow`,`Calibrate`)]})]})]})]})}function GHe({device:e}){let{t}=G(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),u=e.update_status===`pending`||e.update_status===`updating`;(0,y.useEffect)(()=>{u&&n===`applying`&&r(null)},[u,n]),(0,y.useEffect)(()=>{let e=()=>{u&&setTimeout(()=>window.location.reload(),1e3)};return window.addEventListener(`spoolbuddy-online`,e),()=>window.removeEventListener(`spoolbuddy-online`,e)},[u]);let{data:d,refetch:f}=q({queryKey:[`spoolbuddy-update-check`,e.device_id],queryFn:()=>nd.checkDaemonUpdate(e.device_id),staleTime:0}),{data:p}=q({queryKey:[`spoolbuddy-ssh-key`],queryFn:()=>nd.getSSHPublicKey(),enabled:o,staleTime:1/0}),m=async()=>{r(`checking`),a(null);try{await f()}finally{r(null)}},h=async()=>{r(`applying`),a(null);try{await nd.triggerUpdate(e.device_id)}catch(e){a(e instanceof Error?e.message:`Failed to trigger update`),r(null)}},g=n!=null||u,_=()=>{p?.public_key&&(navigator.clipboard.writeText(p.public_key),l(!0),setTimeout(()=>l(!1),2e3))},v=e.firmware_version||(d?.current_version&&d.current_version!==`0.0.0`?d.current_version:null);return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between items-center text-sm`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.currentVersion`,`Current Version`)}),(0,K.jsx)(`span`,{className:`text-zinc-200 font-mono`,children:v||(0,K.jsx)(`span`,{className:`text-zinc-500 italic text-xs`,children:t(`spoolbuddy.settings.versionPending`,`Waiting for daemon...`)})})]}),g?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`svg`,{className:`w-4 h-4 animate-spin text-green-400 flex-shrink-0`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,K.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,K.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),(0,K.jsx)(`span`,{className:`text-green-300 text-xs`,children:n===`checking`?t(`spoolbuddy.settings.checking`,`Checking for updates...`):e.update_message||t(`spoolbuddy.settings.updateWaiting`,`Updating...`)})]}):e.update_status===`error`?(0,K.jsx)(`p`,{className:`text-xs text-red-300`,children:e.update_message||t(`spoolbuddy.settings.updateFailed`,`Update failed`)}):i?(0,K.jsx)(`p`,{className:`text-xs text-red-300`,children:i}):d?.update_available?(0,K.jsxs)(`p`,{className:`text-xs text-green-300`,children:[t(`spoolbuddy.settings.updateAvailable`,`Update available`),`: `,v,` → `,d.latest_version]}):null,!g&&(d?.update_available?(0,K.jsx)(`button`,{onClick:h,disabled:!e.online,className:`w-full px-3 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors`,children:e.online?t(`spoolbuddy.settings.applyUpdate`,`Apply Update`):t(`spoolbuddy.settings.deviceOffline`,`Device Offline`)}):(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{onClick:m,className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors`,children:t(`spoolbuddy.settings.checkUpdates`,`Check for Updates`)}),(0,K.jsx)(`button`,{onClick:h,disabled:!e.online,className:`px-3 py-2 rounded-lg text-xs font-medium bg-zinc-700 text-zinc-400 hover:bg-zinc-600 hover:text-zinc-200 disabled:opacity-40 transition-colors`,children:t(`spoolbuddy.settings.forceUpdate`,`Force Update`)})]}))]}),(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,K.jsxs)(`button`,{onClick:()=>s(!o),className:`w-full flex justify-between items-center text-xs`,children:[(0,K.jsx)(`span`,{className:`font-medium text-zinc-400`,children:t(`spoolbuddy.settings.sshSetup`,`SSH Setup`)}),(0,K.jsx)(`svg`,{className:`w-3 h-3 text-zinc-500 transition-transform ${o?`rotate-180`:``}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 9l-7 7-7-7`})})]}),o&&(0,K.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-zinc-500`,children:t(`spoolbuddy.settings.sshDescription`,`SSH key is deployed automatically. For manual setup, add this key to ~/.ssh/authorized_keys on the device.`)}),p?.public_key?(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`pre`,{className:`bg-zinc-900 rounded p-2 text-[10px] text-zinc-400 font-mono break-all whitespace-pre-wrap`,children:p.public_key}),(0,K.jsx)(`button`,{onClick:_,className:`absolute top-1 right-1 px-1.5 py-0.5 rounded text-[10px] bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors`,children:c?t(`common.copied`,`Copied!`):t(`common.copy`,`Copy`)})]}):(0,K.jsx)(`span`,{className:`text-[10px] text-zinc-500 italic`,children:t(`spoolbuddy.settings.sshKeyLoading`,`Loading...`)})]})]})]})}function K9({percent:e,color:t}){return(0,K.jsx)(`div`,{className:`w-full h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all ${t}`,style:{width:`${Math.min(100,Math.max(0,e))}%`}})})}function KHe(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`}function qHe({device:e}){let{t}=G(),n=e.system_stats;if(!n)return(0,K.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,K.jsx)(`p`,{className:`text-sm text-zinc-500`,children:t(`spoolbuddy.settings.systemStatsWaiting`,`Waiting for system stats...`)})});let r=n.memory,i=n.disk,a=(n.cpu_temp_c??0)>=80?`text-red-400`:(n.cpu_temp_c??0)>=65?`text-amber-400`:`text-green-400`,o=(r?.percent??0)>=90?`bg-red-500`:(r?.percent??0)>=70?`bg-amber-500`:`bg-green-500`,s=(i?.percent??0)>=90?`bg-red-500`:(i?.percent??0)>=70?`bg-amber-500`:`bg-green-500`;return(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:`CPU`}),(0,K.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.cores`,`Cores`)}),(0,K.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.cpu_count??`-`})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.loadAvg`,`Load Avg`)}),(0,K.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.load_avg?n.load_avg.join(` / `):`-`})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.temp`,`Temp`)}),(0,K.jsx)(`span`,{className:`font-mono font-medium ${a}`,children:n.cpu_temp_c==null?`-`:`${n.cpu_temp_c}\u00B0C`})]})]})]}),(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.memory`,`Memory`)}),r?(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(K9,{percent:r.percent??0,color:o}),(0,K.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.used`,`Used`)}),(0,K.jsxs)(`span`,{className:`text-zinc-300 font-mono`,children:[r.used_mb,` / `,r.total_mb,` MB`]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.available`,`Free`)}),(0,K.jsxs)(`span`,{className:`text-zinc-300 font-mono`,children:[r.available_mb,` MB`]})]})]})]}):(0,K.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`-`})]})]}),(0,K.jsx)(`div`,{className:`bg-zinc-800 rounded-lg px-3 py-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 shrink-0`,children:t(`spoolbuddy.settings.disk`,`Disk`)}),i?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`flex-1`,children:(0,K.jsx)(K9,{percent:i.percent??0,color:s})}),(0,K.jsxs)(`span`,{className:`text-xs text-zinc-300 font-mono shrink-0`,children:[i.used_gb,` / `,i.total_gb,` GB`]})]}):(0,K.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`-`})]})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1.5`,children:t(`spoolbuddy.settings.osInfo`,`OS`)}),(0,K.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[n.os?.os&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.distro`,`Distro`)}),(0,K.jsx)(`span`,{className:`text-zinc-300 truncate ml-2`,children:n.os.os})]}),n.os?.kernel&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.kernel`,`Kernel`)}),(0,K.jsx)(`span`,{className:`text-zinc-300 font-mono truncate ml-2`,children:n.os.kernel})]}),n.os?.arch&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.arch`,`Arch`)}),(0,K.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.os.arch})]})]})]}),(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1.5`,children:t(`spoolbuddy.settings.runtime`,`Runtime`)}),(0,K.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[n.os?.python&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:`Python`}),(0,K.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.os.python})]}),n.system_uptime_s!=null&&(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.systemUptime`,`Uptime`)}),(0,K.jsx)(`span`,{className:`text-zinc-300`,children:KHe(n.system_uptime_s)})]})]})]})]})]})}function JHe(){let{sbState:e,setDisplayBrightness:t}=Qn(),{t:n}=G(),[r,i]=(0,y.useState)(`device`),{data:a=[]}=q({queryKey:[`spoolbuddy-devices`],queryFn:()=>nd.getDevices(),refetchInterval:1e4}),o=e.deviceId?a.find(t=>t.device_id===e.deviceId)??a[0]:a[0],s=[{id:`device`,label:n(`spoolbuddy.settings.tabDevice`,`Device`)},{id:`display`,label:n(`spoolbuddy.settings.tabDisplay`,`Display`)},{id:`scale`,label:n(`spoolbuddy.settings.tabScale`,`Scale`)},{id:`updates`,label:n(`spoolbuddy.settings.tabUpdates`,`Updates`)},{id:`system`,label:n(`spoolbuddy.settings.tabSystem`,`System`)}];return(0,K.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,K.jsx)(`h1`,{className:`text-xl font-semibold text-zinc-100 mb-3`,children:n(`spoolbuddy.nav.settings`,`Settings`)}),(0,K.jsx)(`div`,{className:`flex gap-1 bg-zinc-800/50 rounded-lg p-1 mb-4`,children:s.map(e=>(0,K.jsx)(`button`,{onClick:()=>i(e.id),className:`flex-1 px-2 py-2 rounded-md text-sm font-medium transition-colors min-h-[36px] ${r===e.id?`bg-zinc-700 text-zinc-100`:`text-zinc-500 hover:text-zinc-300`}`,children:e.label},e.id))}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:o?(0,K.jsxs)(K.Fragment,{children:[r===`device`&&(0,K.jsx)(VHe,{device:o}),r===`display`&&(0,K.jsx)(HHe,{device:o,onBrightnessChange:t}),r===`scale`&&(0,K.jsx)(WHe,{device:o,weight:e.weight,weightStable:e.weightStable,rawAdc:e.rawAdc}),r===`updates`&&(0,K.jsx)(GHe,{device:o}),r===`system`&&(0,K.jsx)(qHe,{device:o})]}):(0,K.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,K.jsx)(`div`,{className:`text-center text-zinc-500`,children:(0,K.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.settings.noDevice`,`No SpoolBuddy device found`)})})})})]})}function YHe({device:e,weight:t,weightStable:n,rawAdc:r}){let{t:i}=G(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(`idle`),[l,u]=(0,y.useState)(`500`),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(!1),h=e=>{e===`backspace`?u(e=>e.slice(0,-1)||``):e===`.`&&!l.includes(`.`)?u(e=>e+`.`):e>=`0`&&e<=`9`&&u(t=>t===`0`?e:t+e)};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-zinc-400`,children:i(`spoolbuddy.settings.currentWeight`,`Current weight`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,K.jsx)(`span`,{className:`text-lg font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 mt-3 text-xs`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:i(`spoolbuddy.settings.tareOffset`,`Tare offset`)}),(0,K.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.tare_offset})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:i(`spoolbuddy.settings.calFactor`,`Cal. factor`)}),(0,K.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.calibration_factor.toFixed(2)})]})]})]}),s===`idle`?(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{onClick:async()=>{m(!0);try{await nd.tare(e.device_id)}catch(e){console.error(`Failed to tare:`,e)}finally{m(!1)}},disabled:p,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px]`,children:p?`...`:i(`spoolbuddy.weight.tare`,`Tare`)}),(0,K.jsx)(`button`,{onClick:()=>{c(`tare`)},className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:i(`spoolbuddy.weight.calibrate`,`Calibrate`)})]}):(0,K.jsxs)(`div`,{className:`bg-zinc-800 border border-zinc-700 rounded-lg p-3 space-y-2`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-zinc-200`,children:s===`tare`?i(`spoolbuddy.settings.calStep1`,`Step 1: Remove all items from the scale`):i(`spoolbuddy.settings.calStep2`,`Step 2: Place known weight on scale`)}),s===`weight`&&(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-zinc-400`,children:i(`spoolbuddy.settings.knownWeight`,`Known weight (g)`)}),(0,K.jsxs)(`div`,{className:`flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1.5 text-right text-base font-mono text-zinc-100`,children:[l||`0`,(0,K.jsx)(`span`,{className:`text-zinc-500 ml-1`,children:`g`})]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-4 gap-1`,children:[`7`,`8`,`9`,`backspace`,`4`,`5`,`6`,`.`,`1`,`2`,`3`,`0`].map(e=>(0,K.jsx)(`button`,{onClick:()=>h(e),className:`py-2 rounded text-sm font-medium transition-colors min-h-[36px] ${e===`backspace`?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`:`bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700`}`,children:e===`backspace`?`⌫`:e},e))})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>c(`idle`),className:`flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[40px]`,children:i(`common.cancel`,`Cancel`)}),(0,K.jsx)(`button`,{onClick:async()=>{if(s===`tare`){o(!0);try{f(r),await nd.tare(e.device_id),c(`weight`)}catch(e){console.error(`Failed to tare:`,e)}finally{o(!1)}}else if(s===`weight`){let t=parseFloat(l);if(r===null||!t||t<=0)return;o(!0);try{await nd.setCalibrationFactor(e.device_id,t,r,d??void 0),c(`idle`)}catch(e){console.error(`Failed to calibrate:`,e)}finally{o(!1)}}},disabled:a,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors min-h-[40px]`,children:a?`...`:s===`tare`?i(`spoolbuddy.settings.setZero`,`Set Zero`):i(`spoolbuddy.settings.calibrateNow`,`Calibrate`)})]})]})]})}function XHe(){let{sbState:e}=Qn(),{t}=G(),n=Yn(),{data:r=[]}=q({queryKey:[`spoolbuddy-devices`],queryFn:()=>nd.getDevices(),refetchInterval:1e4}),i=e.deviceId?r.find(t=>t.device_id===e.deviceId)??r[0]:r[0];return(0,K.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,K.jsx)(`button`,{onClick:()=>n(`/spoolbuddy/settings`),className:`p-1.5 rounded-lg text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800 transition-colors`,children:(0,K.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 19l-7-7 7-7`})})}),(0,K.jsx)(`h1`,{className:`text-xl font-semibold text-zinc-100`,children:t(`spoolbuddy.settings.scaleCalibration`,`Scale Calibration`)})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:i?(0,K.jsx)(YHe,{device:i,weight:e.weight,weightStable:e.weightStable,rawAdc:e.rawAdc}):(0,K.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,K.jsx)(`div`,{className:`text-center text-zinc-500`,children:(0,K.jsx)(`p`,{className:`text-sm`,children:t(`spoolbuddy.settings.noDevice`,`No SpoolBuddy device found`)})})})})]})}var ZHe=[`PLA`,`PETG`,`ABS`,`ASA`,`TPU`,`PA`,`PC`,`PVA`,`HIPS`];function QHe(){let{t:e}=G(),{showToast:t}=xd(),{sbState:n}=Qn(),[r,i]=(0,y.useState)(`existing`),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`idle`),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(null),{data:b}=q({queryKey:[`spoolman-settings`],queryFn:Q.getSpoolmanSettings,staleTime:300*1e3}),x=b!==void 0,S=b?.spoolman_enabled===`true`&&!!b?.spoolman_url,{data:C=[],refetch:w}=q({queryKey:[S?`spoolman-inventory-spools`:`inventory-spools`,`write-tag`],queryFn:()=>S?Q.getSpoolmanInventorySpools(!1):Q.getSpools(!1),refetchInterval:1e4,enabled:x}),{data:T=[]}=q({queryKey:[`spoolbuddy-devices`],queryFn:()=>nd.getDevices(),refetchInterval:5e3}),{data:E}=q({queryKey:[`settings`],queryFn:Q.getSettings}),D=T[0],O=n.deviceOnline,k=Yd(E?.currency||`USD`),A=(0,y.useMemo)(()=>{let e;if(r===`existing`)e=C.filter(e=>!e.tag_uid&&!e.archived_at);else if(r===`replace`)e=C.filter(e=>(e.tag_uid||e.tray_uuid)&&!e.archived_at);else return[];if(s){let t=s.toLowerCase();e=e.filter(e=>e.material?.toLowerCase().includes(t)||e.color_name?.toLowerCase().includes(t)||e.brand?.toLowerCase().includes(t)||e.subtype?.toLowerCase().includes(t))}return e},[C,r,s]),j=(0,y.useCallback)(e=>{let t=e.detail;(t.sak??t.data?.sak)===0&&(g(!0),v(t.tag_uid??t.data?.tag_uid??null))},[]),M=(0,y.useCallback)(e=>{let t=e.detail;g(!0),v(t.tag_uid??t.data?.tag_uid??null)},[]),N=(0,y.useCallback)(()=>{g(!1),v(null)},[]),P=(0,y.useCallback)(t=>{let n=t.detail;(n.spool_id===a?.id||n.data?.spool_id===a?.id)&&(u(`success`),f(e(`spoolbuddy.writeTag.writeSuccess`,`Tag written successfully!`)),w(),setTimeout(()=>{u(`idle`),o(null),f(``)},5e3))},[a,e,w]),F=(0,y.useCallback)(t=>{let n=t.detail;(n.spool_id===a?.id||n.data?.spool_id===a?.id)&&(u(`error`),f(n.message??n.data?.message??e(`spoolbuddy.writeTag.writeFailed`,`Write failed`)))},[a,e]);(0,y.useEffect)(()=>(window.addEventListener(`spoolbuddy-unknown-tag`,j),window.addEventListener(`spoolbuddy-tag-matched`,M),window.addEventListener(`spoolbuddy-tag-removed`,N),window.addEventListener(`spoolbuddy-tag-written`,P),window.addEventListener(`spoolbuddy-tag-write-failed`,F),()=>{window.removeEventListener(`spoolbuddy-unknown-tag`,j),window.removeEventListener(`spoolbuddy-tag-matched`,M),window.removeEventListener(`spoolbuddy-tag-removed`,N),window.removeEventListener(`spoolbuddy-tag-written`,P),window.removeEventListener(`spoolbuddy-tag-write-failed`,F)}),[j,M,N,P,F]),(0,y.useEffect)(()=>{o(null),u(`idle`),f(``),c(``)},[r]);let I=async()=>{if(!(!a||!D)){u(`writing`),f(e(`spoolbuddy.writeTag.waiting`,`Waiting for SpoolBuddy...`));try{let e=await nd.writeTag(D.device_id,a.id);if(e?.warnings?.length)for(let n of e.warnings)t(n,`warning`)}catch{u(`error`),f(e(`spoolbuddy.writeTag.queueFailed`,`Failed to queue write command`))}}},L=async()=>{if(D){try{await nd.cancelWrite(D.device_id)}catch{}u(`idle`),f(``)}},R=async()=>{if(!(!a||!q9(a))){m(!0),u(`idle`),f(``);try{S?await Q.linkTagToSpoolmanSpool(a.id,{tag_uid:``,tray_uuid:``}):await Q.linkTagToSpool(a.id,{tag_uid:``,tray_uuid:``,data_origin:`manual`}),await w(),o(null),u(`success`),f(e(`spoolbuddy.writeTag.untagSuccess`,`Tag removed from spool`)),setTimeout(()=>{u(`idle`),f(``)},2500)}catch{u(`error`),f(e(`spoolbuddy.writeTag.untagFailed`,`Failed to remove tag from spool`))}finally{m(!1)}}},z=(0,y.useCallback)(e=>{o(e),u(`idle`),f(``),w()},[w]),B=a&&O&&l!==`writing`&&l!==`success`;return(0,K.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,K.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary shrink-0`,children:[{key:`existing`,label:e(`spoolbuddy.writeTag.tabExisting`,`Existing Spool`)},{key:`new`,label:e(`spoolbuddy.writeTag.tabNew`,`New Spool`)},{key:`replace`,label:e(`spoolbuddy.writeTag.tabReplace`,`Replace Tag`)}].map(e=>(0,K.jsx)(`button`,{onClick:()=>i(e.key),className:`flex-1 py-3 text-sm font-medium transition-colors ${r===e.key?`text-bambu-green border-b-2 border-bambu-green bg-bambu-dark`:`text-zinc-400 hover:text-zinc-200 hover:bg-bambu-dark-tertiary`}`,children:e.label},e.key))}),(0,K.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,K.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden border-r border-bambu-dark-tertiary`,children:r===`new`?(0,K.jsx)(eUe,{currencySymbol:k,onCreated:z,selectedSpool:a,spoolmanMode:S,t:e}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`p-3 shrink-0`,children:(0,K.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:e(`spoolbuddy.writeTag.searchPlaceholder`,`Search by material, color, brand...`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3 space-y-2`,children:A.length===0?(0,K.jsx)(`div`,{className:`text-center text-zinc-500 py-8 text-sm`,children:r===`existing`?e(`spoolbuddy.writeTag.noUntaggedSpools`,`No spools without tags`):e(`spoolbuddy.writeTag.noTaggedSpools`,`No spools with tags`)}):A.map(e=>(0,K.jsx)($He,{spool:e,selected:a?.id===e.id,showTag:r===`replace`,onClick:()=>{o(e),u(`idle`),f(``)}},e.id))})]})}),(0,K.jsx)(`div`,{className:`w-[340px] flex flex-col items-center justify-center p-6 shrink-0`,children:(0,K.jsx)(tUe,{writeStatus:l,writeMessage:d,selectedSpool:a,tagOnReader:h,tagUid:_,deviceOnline:O,canWrite:!!B,isReplace:r===`replace`,canUntag:r===`replace`&&!!a&&q9(a),untagging:p,onWrite:I,onUntag:R,onCancel:L,onRetry:()=>{u(`idle`),f(``)},t:e})})]})]})}function q9(e){return!!(e.tag_uid||e.tray_uuid)}function $He({spool:e,selected:t,showTag:n,onClick:r}){let i=Math.max(0,e.label_weight-e.weight_used),a=e.label_weight>0?Math.round(i/e.label_weight*100):0;return(0,K.jsxs)(`button`,{onClick:r,className:`w-full flex items-center gap-3 p-3 rounded-lg text-left transition-colors ${t?`bg-bambu-green/15 border border-bambu-green/50`:`bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-transparent`}`,children:[(0,K.jsx)(`div`,{className:`w-8 h-8 rounded-full shrink-0 border border-white/10`,style:e.rgba?Wd(e.rgba):{backgroundColor:`#666`}}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-sm font-medium text-white truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,K.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-zinc-400`,children:[e.color_name&&(0,K.jsx)(`span`,{children:e.color_name}),(0,K.jsxs)(`span`,{children:[i,`g / `,e.label_weight,`g (`,a,`%)`]})]}),n&&e.tag_uid&&(0,K.jsx)(`div`,{className:`text-xs text-zinc-500 mt-0.5 font-mono`,children:e.tag_uid})]}),t&&(0,K.jsx)(`svg`,{className:`w-5 h-5 text-bambu-green shrink-0`,fill:`currentColor`,viewBox:`0 0 20 20`,children:(0,K.jsx)(`path`,{fillRule:`evenodd`,d:`M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z`,clipRule:`evenodd`})})]})}function eUe({currencySymbol:e,onCreated:t,selectedSpool:n,spoolmanMode:r,t:i}){let{data:a=[]}=q({queryKey:[r?`spoolman-inventory-spools`:`inventory-spools`,`write-tag-form`],queryFn:()=>r?Q.getSpoolmanInventorySpools(!0):Q.getSpools(!0)}),{data:o}=q({queryKey:[`settings`],queryFn:Q.getSettings}),[s,c]=(0,y.useState)(`simple`),[l,u]=(0,y.useState)(`filament`),[d,f]=(0,y.useState)(J7),[p,m]=(0,y.useState)({}),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)([]),[A,j]=(0,y.useState)([]),[M,N]=(0,y.useState)([]),[P,F]=(0,y.useState)([]),[I,L]=(0,y.useState)([]),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)([]),[ee,H]=(0,y.useState)([]),[te,ne]=(0,y.useState)(new Set),[re,U]=(0,y.useState)(new Set);(0,y.useEffect)(()=>{V(mK())},[]),(0,y.useEffect)(()=>{let e=!1;return(async()=>{if(s===`full`){D(!0);try{let[t,n]=await Promise.allSettled([(async()=>(await Q.getCloudStatus()).is_authenticated?{connected:!0,presets:await Q.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await Q.orcaCloudStatus()).connected?{connected:!0,presets:(await Q.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(e)return;let r=t.status===`fulfilled`&&t.value.connected,i=n.status===`fulfilled`&&n.value.connected,a=t.status===`fulfilled`?t.value.presets:[],o=n.status===`fulfilled`?n.value.presets:[];T(r||i),k([...a,...o])}catch{e||T(!1)}finally{e||D(!1)}Q.getSpoolCatalog().then(t=>{e||F(t)}).catch(()=>void 0),Q.getColorCatalog().then(t=>{e||L(t)}).catch(()=>void 0),Q.getLocalPresets().then(t=>{e||j(t.filament)}).catch(()=>void 0),Q.getBuiltinFilaments().then(t=>{e||N(t)}).catch(()=>void 0);try{let t=await Q.getPrinters(),n=await Promise.all(t.map(e=>Q.getPrinterStatus(e.id).catch(()=>null))),r=[];for(let e=0;e({cali_idx:e.slot_id,filament_id:e.filament_id,setting_id:e.setting_id||``,name:e.name,k_value:parseFloat(e.k_value)||0,n_coef:parseFloat(e.n_coef)||0,extruder_id:e.extruder_id,nozzle_diameter:e.nozzle_diameter}))}catch{}r.push({printer:{...i,connected:a},calibrations:o})}e||H(r)}catch{}}})(),()=>{e=!0}},[s]),(0,y.useEffect)(()=>{ee.length>0&&U(new Set(ee.map(e=>String(e.printer.id))))},[ee]);let ie=(0,y.useMemo)(()=>fK(O,new Set,A,M),[O,A,M]),ae=(0,y.useMemo)(()=>pK(d.slicer_filament,ie),[d.slicer_filament,ie]),W=(0,y.useMemo)(()=>{let e=dK(O,A),t=I.map(e=>e.manufacturer?.trim()).filter(e=>!!e);return Array.from(new Set([...e,...t])).sort((e,t)=>e.localeCompare(t))},[O,A,I]),oe=(0,y.useMemo)(()=>{let e=I.map(e=>e.material?.trim()).filter(e=>!!e);return Array.from(new Set([...aK,...e])).sort((e,t)=>e.localeCompare(t))},[I]),se=(0,y.useMemo)(()=>{let e=[];for(let t of I){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of O){let n=uK(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of A){let n=uK(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[O,I,A]),ce=(0,y.useMemo)(()=>{let e=new Map;for(let t of se){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[se]),le=(0,y.useMemo)(()=>{let e=new Map;for(let t of se){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[se]),ue=(0,y.useMemo)(()=>{if(!d.material)return W;let e=d.material.toLowerCase(),t=le.get(e);return!t||t.size===0?W:W.filter(e=>t.has(e.toLowerCase()))},[W,d.material,le]),de=(0,y.useMemo)(()=>{if(!d.brand)return oe;let e=d.brand.toLowerCase(),t=ce.get(e);return!t||t.size===0?oe:oe.filter(e=>t.has(e.toLowerCase()))},[oe,d.brand,ce]),fe=(e,t)=>{f(n=>({...n,[e]:t})),p[e]&&m(t=>({...t,[e]:void 0}))},pe=e=>{V(t=>hK(e,t))},me=async e=>{let t=r?Q.saveSpoolmanKProfiles:Q.saveSpoolKProfiles;if(te.size===0){try{await t(e,[])}catch{}return}let n=[];for(let e of te){let[t,r,i]=e.split(`:`),a=parseInt(t),o=parseInt(r),s=i===`null`?0:parseInt(i),c=ee.find(e=>e.printer.id===a);if(c){let e=c.calibrations.find(e=>e.cali_idx===o);e&&n.push({printer_id:a,extruder:s,nozzle_diameter:e.nozzle_diameter||`0.4`,k_value:e.k_value,name:e.name||null,cali_idx:e.cali_idx,setting_id:e.setting_id||null})}}n.length>0&&await t(e,n)},he=async()=>{C(null);let e=Y7(d,s===`simple`?!0:h);if(!e.isValid){m(e.errors),u(`filament`);return}let n=ae?.displayName||R||null,a={material:d.material,subtype:d.subtype||null,brand:d.brand||null,color_name:d.color_name||null,rgba:d.rgba||null,extra_colors:d.extra_colors||null,effect_type:d.effect_type||null,label_weight:d.label_weight,core_weight:d.core_weight,core_weight_catalog_id:d.core_weight_catalog_id,weight_used:d.weight_used,slicer_filament:d.slicer_filament||null,slicer_filament_name:n,nozzle_temp_min:null,nozzle_temp_max:null,note:d.note||null,cost_per_kg:d.cost_per_kg,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,last_scale_weight:null,last_weighed_at:null,category:d.category.trim()||null,low_stock_threshold_pct:d.low_stock_threshold_pct};x(!0);try{if(_>1){let e=r?await Q.bulkCreateSpoolmanInventorySpools(a,_):await Q.bulkCreateSpools(a,_),n=r&&e&&typeof e==`object`&&`created`in e?e.created:e;for(let e of n)await me(e.id);n.length>0&&t(n[0])}else{let e=r?await Q.createSpoolmanInventorySpool(a):await Q.createSpool(a);await me(e.id),t(e)}}catch{C(i(`spoolbuddy.writeTag.createFailed`,`Failed to create spool`))}finally{x(!1)}},ge=`#${(d.rgba||`808080FF`).slice(0,6)}`;return(0,K.jsxs)(`div`,{className:`p-3 space-y-3 overflow-y-auto h-full`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`span`,{className:`text-sm text-zinc-200`,children:i(`spoolbuddy.writeTag.viewMode`,`View`)}),(0,K.jsxs)(`div`,{className:`flex rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>c(`simple`),className:`px-3 py-1.5 text-xs font-medium ${s===`simple`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:i(`spoolbuddy.writeTag.simpleView`,`Simple`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>c(`full`),className:`px-3 py-1.5 text-xs font-medium ${s===`full`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:i(`spoolbuddy.writeTag.fullView`,`Full`)})]})]}),s===`simple`?n?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-6 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,K.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:n.rgba?Wd(n.rgba):{backgroundColor:`#666`}}),(0,K.jsxs)(`p`,{className:`text-white font-medium`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,K.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:n.color_name}),(0,K.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[n.label_weight,`g`]}),(0,K.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:i(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]}):(0,K.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.material`,`Material`)}),(0,K.jsx)(`select`,{value:d.material,onChange:e=>fe(`material`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,children:ZHe.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))})]}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.colorName`,`Color Name`)}),(0,K.jsx)(`input`,{type:`text`,value:d.color_name,onChange:e=>fe(`color_name`,e.target.value),placeholder:`Jade White`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.color`,`Color`)}),(0,K.jsx)(`input`,{type:`color`,value:ge,onChange:e=>fe(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`),className:`w-10 h-9 bg-transparent border border-bambu-dark-tertiary rounded cursor-pointer`})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.brand`,`Brand`)}),(0,K.jsx)(`input`,{type:`text`,value:d.brand,onChange:e=>fe(`brand`,e.target.value),placeholder:`Polymaker`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.weight`,`Weight (g)`)}),(0,K.jsx)(`input`,{type:`number`,value:d.label_weight,onChange:e=>fe(`label_weight`,parseInt(e.target.value)||0),min:0,max:1e4,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`})]}),(0,K.jsx)(`button`,{onClick:he,disabled:b||!d.material,className:`w-full py-2.5 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:b?i(`spoolbuddy.writeTag.creating`,`Creating...`):i(`spoolbuddy.writeTag.createSpool`,`Create Spool`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`span`,{className:`text-sm text-zinc-200`,children:i(`inventory.quickAdd`,`Quick Add`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${h?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`span`,{className:`inline-block h-4.5 w-4.5 rounded-full bg-white transition-transform ${h?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{className:`flex border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,K.jsx)(`button`,{onClick:()=>u(`filament`),className:`flex-1 py-2.5 text-sm font-medium ${l===`filament`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:i(`inventory.filamentInfoTab`,`Filament`)}),!h&&(0,K.jsx)(`button`,{onClick:()=>u(`pa-profile`),className:`flex-1 py-2.5 text-sm font-medium ${l===`pa-profile`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:i(`inventory.paProfileTab`,`PA Profile`)})]}),(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-3`,children:l===`filament`?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(X7,{formData:d,updateField:fe,cloudAuthenticated:w,loadingCloudPresets:E,presetInputValue:R,setPresetInputValue:z,selectedPresetOption:ae,filamentOptions:ie,availableBrands:ue,availableMaterials:de,quickAdd:h,quantity:_,onQuantityChange:v,errors:p}),(0,K.jsx)(Z7,{formData:d,updateField:fe,recentColors:B,onColorUsed:pe,catalogColors:I}),(0,K.jsx)(Q7,{formData:d,updateField:fe,spoolCatalog:P,currencySymbol:e,availableCategories:Array.from(new Set(a.map(e=>e.category?.trim()).filter(e=>!!e))).sort((e,t)=>e.localeCompare(t)),globalLowStockThreshold:o?.low_stock_threshold??20})]}):(0,K.jsx)($7,{formData:d,updateField:fe,printersWithCalibrations:ee,selectedProfiles:te,setSelectedProfiles:ne,expandedPrinters:re,setExpandedPrinters:U})})]}),S&&(0,K.jsx)(`div`,{className:`text-sm text-red-400 bg-red-900/20 border border-red-900/40 rounded-lg px-3 py-2`,children:S}),s===`full`&&(0,K.jsx)(`button`,{onClick:he,disabled:b,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:b?i(`spoolbuddy.writeTag.creating`,`Creating...`):i(`spoolbuddy.writeTag.createSpool`,`Create Spool`)}),s===`full`&&n&&(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-4 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,K.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:n.rgba?Wd(n.rgba):{backgroundColor:`#666`}}),(0,K.jsxs)(`p`,{className:`text-white font-medium`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,K.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:n.color_name}),(0,K.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[n.label_weight,`g`]}),(0,K.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:i(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]})]})}function tUe({writeStatus:e,writeMessage:t,selectedSpool:n,tagOnReader:r,tagUid:i,deviceOnline:a,canWrite:o,isReplace:s,canUntag:c,untagging:l,onWrite:u,onUntag:d,onCancel:f,onRetry:p,t:m}){if(e===`success`)return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,K.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-green-500/20 flex items-center justify-center`,children:(0,K.jsx)(`svg`,{className:`w-8 h-8 text-green-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 13l4 4L19 7`})})}),(0,K.jsx)(`p`,{className:`text-green-400 font-medium`,children:t}),n&&(0,K.jsxs)(`p`,{className:`text-zinc-400 text-sm`,children:[n.brand?`${n.brand} `:``,n.material,n.color_name?` - ${n.color_name}`:``]})]});if(e===`error`)return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,K.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,K.jsx)(`svg`,{className:`w-8 h-8 text-red-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})}),(0,K.jsx)(`p`,{className:`text-red-400 font-medium`,children:t}),(0,K.jsx)(`button`,{onClick:p,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-white text-sm rounded transition-colors`,children:m(`spoolbuddy.writeTag.tryAgain`,`Try Again`)})]});if(e===`writing`)return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,K.jsxs)(`div`,{className:`relative w-16 h-16`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-bambu-green/30 animate-ping`}),(0,K.jsx)(`div`,{className:`absolute inset-2 rounded-full border-2 border-bambu-green/50 animate-pulse`}),(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,K.jsx)(J9,{className:`w-8 h-8 text-bambu-green`})})]}),(0,K.jsx)(`p`,{className:`text-bambu-green font-medium`,children:m(`spoolbuddy.writeTag.writing`,`Writing tag...`)}),(0,K.jsx)(`p`,{className:`text-zinc-500 text-xs`,children:t}),(0,K.jsx)(`button`,{onClick:f,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-zinc-400 text-sm rounded transition-colors`,children:m(`spoolbuddy.writeTag.cancel`,`Cancel`)})]});if(!a)return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,K.jsx)(J9,{className:`w-12 h-12 text-zinc-600`}),(0,K.jsx)(`p`,{className:`text-zinc-500 text-sm`,children:m(`spoolbuddy.writeTag.deviceOffline`,`SpoolBuddy is offline`)})]});if(!n)return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,K.jsx)(J9,{className:`w-12 h-12 text-zinc-600`}),(0,K.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:m(`spoolbuddy.writeTag.selectSpool`,`Select a spool, then place a blank NTAG on the reader`)})]});let h=n.rgba?Wd(n.rgba):{backgroundColor:`#666`};return(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4 w-full`,children:[(0,K.jsx)(`div`,{className:`relative w-16 h-16`,children:r?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`absolute inset-0 rounded-full bg-bambu-green/10`}),(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,K.jsx)(J9,{className:`w-8 h-8 text-bambu-green`})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-zinc-600 animate-pulse`}),(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,K.jsx)(J9,{className:`w-8 h-8 text-zinc-500`})})]})}),r?(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`p`,{className:`text-bambu-green text-sm font-medium`,children:m(`spoolbuddy.writeTag.tagReady`,`Tag detected — ready to write`)}),i&&(0,K.jsx)(`p`,{className:`text-zinc-500 text-xs font-mono`,children:i})]}):(0,K.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:m(`spoolbuddy.writeTag.placeTag`,`Place an NTAG on the reader`)}),(0,K.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-3 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-8 h-8 rounded-full border border-white/10 shrink-0`,style:h}),(0,K.jsxs)(`div`,{className:`text-left min-w-0`,children:[(0,K.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,K.jsx)(`p`,{className:`text-zinc-400 text-xs`,children:n.color_name})]})]}),(0,K.jsxs)(`div`,{className:`text-xs text-zinc-500`,children:[n.label_weight,`g`]})]}),s&&n.tag_uid&&(0,K.jsx)(`p`,{className:`text-yellow-500/80 text-xs`,children:m(`spoolbuddy.writeTag.replaceWarning`,`Old tag will be unlinked. New tag will replace it.`)}),(0,K.jsx)(`button`,{onClick:u,disabled:!o,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-40 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors text-sm`,children:s?m(`spoolbuddy.writeTag.replaceTag`,`Replace Tag`):m(`spoolbuddy.writeTag.writeTag`,`Write Tag`)}),s&&c&&(0,K.jsx)(`button`,{onClick:d,disabled:l,className:`w-full py-2.5 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary disabled:opacity-40 disabled:cursor-not-allowed text-zinc-200 rounded-lg transition-colors text-sm`,children:l?m(`spoolbuddy.writeTag.untagging`,`Removing tag...`):m(`spoolbuddy.writeTag.untagSpool`,`Untag Selected Spool`)})]})}function J9({className:e}){return(0,K.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,children:[(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0`}),(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})}var nUe=`spoolbuddy-default-core-weight`;function rUe(){try{let e=localStorage.getItem(nUe);if(e){let t=parseInt(e,10);if(t>=0&&t<=500)return t}}catch{}return 250}function iUe({spool:e,liveScaleWeight:t,persistedGrossWeight:n,onClose:r,onSyncWeight:i,onAssignToAms:a,isAssigned:o,onUnassignFromAms:s,className:c}){let{t:l}=G(),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),{data:g}=q({queryKey:[`spool-k-profiles`,e.id],queryFn:()=>Q.getSpoolKProfiles(e.id),enabled:!e.k_profiles||e.k_profiles.length===0,staleTime:300*1e3}),_=e.k_profiles&&e.k_profiles.length>0?e.k_profiles:g,v=Ud(e.rgba),b=e.core_weight&&e.core_weight>0?e.core_weight:rUe(),x=t===null?null:Math.round(Math.max(0,t)),S=m??(n===void 0?x:n===null?null:Math.round(Math.max(0,n))),C=Math.round(Math.max(0,(e.label_weight||0)-(e.weight_used||0))),w=x!==null&&x>=10?Math.round(Math.max(0,x-b)):C,T=Math.round(e.label_weight||1e3),E=T>0?Math.min(100,Math.round(w/T*100)):null,D=E===null?`#808080`:E>50?`#22c55e`:E>20?`#eab308`:`#ef4444`,O=Math.max(0,(e.label_weight||0)-(e.weight_used||0))+b,k=x===null?null:x-O,A=k===null?null:Math.abs(k)<=50,j=S??Math.round(O),M=e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null?`${e.nozzle_temp_min}-${e.nozzle_temp_max}\u00B0C`:null,N=e.slicer_filament_name||e.slicer_filament||null,P=e.note?.trim()||null,F=_&&_.length>0?Array.from(new Set(_.map(e=>e.k_value.toFixed(3)))).join(`, `):null,I=async()=>{if(t===null)return;let n=Math.round(Math.max(0,t));d(!0);try{await nd.updateSpoolWeight(e.id,n),h(n),p(!0),i?.(),setTimeout(()=>p(!1),3e3)}catch(e){console.error(`Failed to sync weight:`,e)}finally{d(!1)}};return(0,K.jsxs)(`div`,{className:`flex flex-col items-center space-y-4 max-w-md ${c??``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-5`,children:[(0,K.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,K.jsx)(j9,{color:v,isEmpty:!1,size:100}),E!==null&&(0,K.jsxs)(`div`,{className:`absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg`,style:{backgroundColor:D},children:[E,`%`]})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:e.color_name||`Unknown color`}),(0,K.jsxs)(`span`,{className:`text-xs font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,K.jsxs)(`p`,{className:`text-sm text-zinc-400`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]}),(0,K.jsxs)(`div`,{className:`mt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-3xl font-bold font-mono text-zinc-100`,children:[w,`g`]}),(0,K.jsxs)(`span`,{className:`text-sm text-zinc-500`,children:[`/ `,T,`g`]})]}),(0,K.jsx)(`p`,{className:`text-xs text-zinc-500 mt-0.5`,children:l(`spoolbuddy.spool.remaining`,`Remaining`)}),(0,K.jsx)(`div`,{className:`mt-2 max-w-xs`,children:(0,K.jsx)(`div`,{className:`h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${E??0}%`,backgroundColor:D}})})})]})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full`,children:[(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.grossWeight`,`Gross weight`)}),(0,K.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[j,`g`]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.spool.coreWeight`,`Core`)}),(0,K.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[b,`g`]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.spoolSize`,`Spool size`)}),(0,K.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[T,`g`]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.spool.scaleWeight`,`Scale`)}),x===null?(0,K.jsx)(`span`,{className:`text-zinc-500`,children:`—`}):(0,K.jsxs)(`span`,{className:`flex items-center gap-1 font-mono ${A?`text-green-500`:`text-yellow-500`}`,children:[x,`g`,A?(0,K.jsx)($o,{className:`w-3.5 h-3.5`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(vu,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`button`,{onClick:I,className:`p-1 hover:bg-green-500/20 rounded transition-colors text-green-500`,title:l(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`),children:(0,K.jsx)(Cl,{className:`w-4 h-4`})})]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.tagId`,`Tag`)}),(0,K.jsx)(`span`,{className:`font-mono text-xs text-zinc-400 truncate max-w-[120px]`,title:e.tag_uid||``,children:e.tag_uid?e.tag_uid.slice(-8):`—`})]}),M&&(0,K.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.nozzleTemp`,`Nozzle`)}),(0,K.jsx)(`span`,{className:`font-mono text-zinc-300`,children:M})]}),e.cost_per_kg!=null&&e.cost_per_kg>0&&(0,K.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.costPerKg`,`Cost/kg`)}),(0,K.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[e.cost_per_kg.toFixed(2),`/kg`]})]}),F&&(0,K.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,K.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.kProfiles`,`K-Profile`)}),(0,K.jsx)(`span`,{className:`font-mono text-zinc-300 truncate max-w-[220px] text-right`,title:F,children:F})]}),N&&(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-xs text-zinc-500 mb-1`,children:l(`spoolbuddy.inventory.slicerFilament`,`Slicer Filament`)}),(0,K.jsx)(`p`,{className:`text-sm text-zinc-300 whitespace-pre-wrap break-words`,children:N})]}),P&&(0,K.jsxs)(`div`,{className:`col-span-2`,children:[(0,K.jsx)(`p`,{className:`text-xs text-zinc-500 mb-1`,children:l(`spoolbuddy.inventory.note`,`Note`)}),(0,K.jsx)(`p`,{className:`text-sm leading-5 text-zinc-300 whitespace-pre-wrap break-words max-h-[3.75rem] overflow-y-auto pr-1`,children:P})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[a&&(0,K.jsx)(`button`,{onClick:o?void 0:a,disabled:!!o,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px] disabled:opacity-50 disabled:cursor-not-allowed`,children:l(`spoolbuddy.modal.assignToAms`,`Assign to AMS`)}),s&&(0,K.jsxs)(`button`,{onClick:s,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-red-600/20 text-red-400 hover:bg-red-600/30 transition-colors min-h-[44px]`,children:[(0,K.jsx)(xu,{className:`w-4 h-4 inline mr-1`}),l(`inventory.unassignSpool`)]}),(0,K.jsx)(`button`,{onClick:I,disabled:t===null||u,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${f?`bg-green-600/20 text-green-400`:a?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed`:`bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed`}`,children:u?`...`:f?l(`spoolbuddy.dashboard.weightSynced`,`Synced!`):l(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`)}),r&&(0,K.jsx)(`button`,{onClick:r,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:l(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function aUe(e){return Ud(e.rgba)}function oUe(e){return Math.max(0,e.label_weight-e.weight_used)}function sUe(e){return e.label_weight<=0?0:Math.max(0,Math.min(100,(e.label_weight-e.weight_used)/e.label_weight*100))}function cUe(e){let t=[e.material];return e.subtype&&t.push(e.subtype),t.join(` `)}function Y9(e){let t=e.ams_id===254||e.ams_id===255,n=!t&&e.ams_id>=128;return IK(e.ams_id,e.tray_id,n,t)}function lUe({color:e,size:t=56}){return(0,K.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 56 56`,children:[(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:e}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:e,style:{filter:`brightness(0.85)`}}),(0,K.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,K.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}function uUe(){let{sbState:e,selectedPrinterId:t}=Qn(),{t:n}=G(),{showToast:r}=xd(),i=Qa(),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`all`),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!1),{data:p}=q({queryKey:[`spoolman-settings`],queryFn:Q.getSpoolmanSettings,staleTime:300*1e3}),m=p?.spoolman_enabled===`true`&&!!p?.spoolman_url,{data:h=[],isLoading:g,refetch:_}=q({queryKey:m?[`spoolman-inventory-spools`]:[`inventory-spools`],queryFn:()=>m?Q.getSpoolmanInventorySpools(!1):Q.getSpools(!1),enabled:p!==void 0,refetchInterval:3e4}),{data:v=[]}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),refetchInterval:3e4,enabled:!m}),{data:b=[]}=q({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Q.getSpoolmanSlotAssignments(),refetchInterval:3e4,enabled:m}),x=J({mutationFn:e=>Q.unassignSpoolmanSlot(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),i.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},onError:()=>r(n(`inventory.unassignFailed`,`Failed to unassign spool`),`error`)}),S=(0,y.useMemo)(()=>{if(m){let e={};return b.forEach(t=>{e[t.spoolman_spool_id]={ams_id:t.ams_id,tray_id:t.tray_id}}),e}let e={};return v.forEach(t=>{e[t.spool_id]={ams_id:t.ams_id,tray_id:t.tray_id,printer_name:t.printer_name}}),e},[m,v,b]),C=(0,y.useMemo)(()=>h.filter(e=>!e.archived_at),[h]),w=(0,y.useMemo)(()=>new Set(Object.keys(S).map(Number)),[S]),T=(0,y.useMemo)(()=>C.filter(e=>w.has(e.id)).length,[C,w]),E=(0,y.useMemo)(()=>{let e=new Set;return C.forEach(t=>e.add(t.material)),Array.from(e).sort()},[C]),D=(0,y.useMemo)(()=>{let e=C;return s===`in_ams`?e=e.filter(e=>w.has(e.id)):s!==`all`&&(e=e.filter(e=>e.material===s)),e=ZG(e,a.trim()),[...e].sort((e,t)=>{let n=+!w.has(e.id),r=+!w.has(t.id);return n===r?new Date(t.updated_at).getTime()-new Date(e.updated_at).getTime():n-r})},[C,s,a,w]);return(0,K.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`px-3 pt-3 pb-2 space-y-2.5`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Nl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-white/40`}),(0,K.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:n(`spoolbuddy.inventory.searchPlaceholder`,`Search spools...`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-white/30 focus:outline-none focus:border-bambu-green`}),a&&(0,K.jsx)(`button`,{onClick:()=>o(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-white/40 hover:text-white/60`,children:(0,K.jsx)(Pu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto no-scrollbar`,children:[(0,K.jsx)(X9,{active:s===`all`,onClick:()=>c(`all`),label:`${n(`spoolbuddy.inventory.all`,`All`)} (${C.length})`,green:!0}),T>0&&(0,K.jsx)(X9,{active:s===`in_ams`,onClick:()=>c(`in_ams`),label:`${n(`spoolbuddy.inventory.inAms`,`In AMS`)} (${T})`}),E.map(e=>(0,K.jsx)(X9,{active:s===e,onClick:()=>c(s===e?`all`:e),label:e},e))]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3`,children:g?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(`div`,{className:`w-8 h-8 border-2 border-bambu-green border-t-transparent rounded-full animate-spin`})}):D.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-white/30`,children:[(0,K.jsx)(cl,{className:`w-12 h-12 mb-3`}),(0,K.jsx)(`p`,{className:`text-sm`,children:a||s!==`all`?n(`spoolbuddy.inventory.noResults`,`No spools match your filters`):n(`spoolbuddy.inventory.empty`,`No spools in inventory`)})]}):(0,K.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(130px,1fr))] gap-2`,children:D.map(e=>(0,K.jsx)(dUe,{spool:e,assignment:S[e.id],onClick:()=>u(e.id)},e.id))})}),l!=null&&(()=>{let n=h.find(e=>e.id===l);return n?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(fUe,{spool:n,assignment:S[n.id],sbState:e,onSyncWeight:()=>{_()},onAssignToAms:()=>f(!0),onUnassignFromAms:m&&S[n.id]?()=>x.mutate(n.id):void 0,onClose:()=>{u(null),f(!1)}}),(0,K.jsx)(V9,{isOpen:d,onClose:()=>f(!1),spool:n,printerId:t,spoolmanMode:m})]}):null})()]})}function X9({active:e,onClick:t,label:n,green:r}){return(0,K.jsx)(`button`,{onClick:t,className:`px-4 py-1.5 rounded-full text-sm font-medium border whitespace-nowrap shrink-0 transition-colors ${e?r?`bg-bambu-green/20 text-bambu-green border-bambu-green/50`:`bg-white/10 text-white border-white/20`:`bg-transparent text-white/40 border-bambu-dark-tertiary hover:text-white/60`}`,children:n})}function dUe({spool:e,assignment:t,onClick:n}){let r=aUe(e),i=sUe(e),a=oUe(e),o=Hd(e.color_name,e.rgba);return(0,K.jsxs)(`button`,{onClick:n,className:`bg-bambu-dark-secondary rounded-xl p-3 flex flex-col items-center text-center gap-1.5 border border-transparent hover:border-bambu-green/50 transition-colors`,children:[(0,K.jsx)(lUe,{color:r,size:56}),(0,K.jsx)(`p`,{className:`text-xs font-semibold text-white leading-tight truncate w-full`,children:cUe(e)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 max-w-full`,children:[(0,K.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full shrink-0 border border-white/10`,style:Wd(e.rgba)}),(0,K.jsx)(`span`,{className:`text-[11px] text-white/50 truncate`,children:o||`-`})]}),(0,K.jsxs)(`div`,{className:`w-full space-y-0.5`,children:[(0,K.jsx)(`div`,{className:`h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full ${i>50?`bg-bambu-green`:i>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(i,100)}%`}})}),(0,K.jsxs)(`p`,{className:`text-[11px] text-white/40`,children:[Math.round(a),`g (`,Math.round(i),`%)`]})]}),t&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded text-[10px] font-bold bg-bambu-green/20 text-bambu-green`,children:Y9(t)})]})}function fUe({spool:e,assignment:t,sbState:n,onSyncWeight:r,onAssignToAms:i,onUnassignFromAms:a,onClose:o}){let s=n.deviceOnline&&n.weight!==null?Math.round(n.weight):null,c=e.last_scale_weight==null?null:Math.round(e.last_scale_weight);return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/70 flex items-center justify-center p-4`,onClick:o,children:(0,K.jsx)(`div`,{className:`w-full max-w-md bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-2xl p-4 overflow-y-auto max-h-[90vh]`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[t&&(0,K.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,K.jsx)(`span`,{className:`px-2.5 py-1 rounded-md text-xs font-bold bg-bambu-green/20 text-bambu-green`,children:Y9(t)}),t.printer_name&&(0,K.jsx)(`span`,{className:`text-xs text-zinc-400`,children:t.printer_name})]}),(0,K.jsx)(`div`,{className:`flex justify-center`,children:(0,K.jsx)(iUe,{spool:e,liveScaleWeight:s,persistedGrossWeight:c,onSyncWeight:r,onAssignToAms:i,isAssigned:!!t,onUnassignFromAms:a,onClose:o,className:`max-w-md`})})]})})})}var pUe=class extends y.Component{state={error:null,errorInfo:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.setState({errorInfo:t}),console.error(`React crash:`,e,t)}render(){return this.state.error?(0,K.jsxs)(`div`,{style:{padding:24,color:`#ef4444`,backgroundColor:`#18181b`,minHeight:`100vh`,fontFamily:`monospace`},children:[(0,K.jsx)(`h1`,{style:{fontSize:20,marginBottom:12},children:`UI Crash`}),(0,K.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,fontSize:14},children:this.state.error.message}),(0,K.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,fontSize:12,color:`#a1a1aa`,marginTop:12},children:this.state.error.stack}),(0,K.jsx)(`button`,{onClick:()=>{this.setState({error:null,errorInfo:null})},style:{marginTop:16,padding:`8px 16px`,backgroundColor:`#3b82f6`,color:`#fff`,border:`none`,borderRadius:8,cursor:`pointer`},children:`Retry`})]}):this.props.children}},mUe=new Ya({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function hUe(){return R7(),null}function Z9({children:e}){return $Ve(),(0,K.jsx)(K.Fragment,{children:e})}function Q9({children:e}){let{authEnabled:t,loading:n,user:r}=sd(),i=Kn();return n?(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):t&&!r?(0,K.jsx)(wr,{to:`/login`,replace:!0,state:{from:i}}):(0,K.jsx)(K.Fragment,{children:e})}function $9({permission:e,children:t}){let{authEnabled:n,loading:r,user:i,hasPermission:a}=sd(),o=Kn();return r?(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):n?i?a(e)?(0,K.jsx)(K.Fragment,{children:t}):(0,K.jsx)(wr,{to:`/`,replace:!0}):(0,K.jsx)(wr,{to:`/login`,replace:!0,state:{from:o}}):(0,K.jsx)(K.Fragment,{children:t})}function gUe({children:e}){let{authEnabled:t,loading:n}=sd();return n?(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):t?(0,K.jsx)(wr,{to:`/login`,replace:!0}):(0,K.jsx)(K.Fragment,{children:e})}function _Ue(){return(0,K.jsx)(pUe,{children:(0,K.jsx)(wd,{children:(0,K.jsx)($a,{client:mUe,children:(0,K.jsx)(od,{children:(0,K.jsx)(ld,{children:(0,K.jsx)(eHe,{children:(0,K.jsxs)(PEe,{children:[(0,K.jsx)(hUe,{}),(0,K.jsx)(_i,{children:(0,K.jsxs)(Or,{children:[(0,K.jsx)(Er,{path:`/setup`,element:(0,K.jsx)(gUe,{children:(0,K.jsx)(XVe,{})})}),(0,K.jsx)(Er,{path:`/login`,element:(0,K.jsx)(YVe,{})}),(0,K.jsx)(Er,{path:`/camera/:printerId`,element:(0,K.jsx)(BBe,{})}),(0,K.jsx)(Er,{path:`/overlay/:printerId`,element:(0,K.jsx)(GBe,{})}),(0,K.jsxs)(Er,{element:(0,K.jsx)(Q9,{children:(0,K.jsx)(Z9,{children:(0,K.jsx)(fHe,{})})}),children:[(0,K.jsx)(Er,{path:`spoolbuddy`,element:(0,K.jsx)(NHe,{})}),(0,K.jsx)(Er,{path:`spoolbuddy/ams`,element:(0,K.jsx)(IHe,{})}),(0,K.jsx)(Er,{path:`spoolbuddy/write-tag`,element:(0,K.jsx)(QHe,{})}),(0,K.jsx)(Er,{path:`spoolbuddy/inventory`,element:(0,K.jsx)(uUe,{})}),(0,K.jsx)(Er,{path:`spoolbuddy/settings`,element:(0,K.jsx)(JHe,{})}),(0,K.jsx)(Er,{path:`spoolbuddy/calibration`,element:(0,K.jsx)(XHe,{})})]}),(0,K.jsxs)(Er,{element:(0,K.jsx)(Q9,{children:(0,K.jsx)(Z9,{children:(0,K.jsx)(Xf,{})})}),children:[(0,K.jsx)(Er,{index:!0,element:(0,K.jsx)(kEe,{})}),(0,K.jsx)(Er,{path:`archives`,element:(0,K.jsx)($Fe,{})}),(0,K.jsx)(Er,{path:`queue`,element:(0,K.jsx)(ZLe,{})}),(0,K.jsx)(Er,{path:`stats`,element:(0,K.jsx)(gRe,{})}),(0,K.jsx)(Er,{path:`profiles`,element:(0,K.jsx)(sBe,{})}),(0,K.jsx)(Er,{path:`maintenance`,element:(0,K.jsx)(fBe,{})}),(0,K.jsx)(Er,{path:`projects`,element:(0,K.jsx)(hBe,{})}),(0,K.jsx)(Er,{path:`projects/:id`,element:(0,K.jsx)(xBe,{})}),(0,K.jsx)(Er,{path:`inventory`,element:(0,K.jsx)(MVe,{})}),(0,K.jsx)(Er,{path:`files`,element:(0,K.jsx)(NBe,{})}),(0,K.jsx)(Er,{path:`files/trash`,element:(0,K.jsx)(FBe,{})}),(0,K.jsx)(Er,{path:`makerworld`,element:(0,K.jsx)($9,{permission:`makerworld:view`,children:(0,K.jsx)(BVe,{})})}),(0,K.jsx)(Er,{path:`settings`,element:(0,K.jsx)($9,{permission:`settings:read`,children:(0,K.jsx)(Rze,{})})}),(0,K.jsx)(Er,{path:`groups/new`,element:(0,K.jsx)($9,{permission:`groups:create`,children:(0,K.jsx)(B7,{})})}),(0,K.jsx)(Er,{path:`groups/:id/edit`,element:(0,K.jsx)($9,{permission:`groups:update`,children:(0,K.jsx)(B7,{})})}),(0,K.jsx)(Er,{path:`users`,element:(0,K.jsx)(wr,{to:`/settings?tab=users`,replace:!0})}),(0,K.jsx)(Er,{path:`groups`,element:(0,K.jsx)(wr,{to:`/settings?tab=users`,replace:!0})}),(0,K.jsx)(Er,{path:`system`,element:(0,K.jsx)(WVe,{})}),(0,K.jsx)(Er,{path:`notifications`,element:(0,K.jsx)(ZVe,{})}),(0,K.jsx)(Er,{path:`gcode-viewer`,element:(0,K.jsx)(QVe,{})}),(0,K.jsx)(Er,{path:`external/:id`,element:(0,K.jsx)(KBe,{})}),(0,K.jsx)(Er,{path:`camera-tokens`,element:(0,K.jsx)(wr,{to:`/settings?tab=apikeys#card-camera-tokens`,replace:!0})})]})]})})]})})})})})})})}(0,b.createRoot)(document.getElementById(`root`)).render((0,K.jsx)(y.StrictMode,{children:(0,K.jsx)(_Ue,{})})); \ No newline at end of file diff --git a/static/index.html b/static/index.html index 7cac059e0..cb5e29578 100644 --- a/static/index.html +++ b/static/index.html @@ -26,7 +26,7 @@ - +