diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3089e8e4f..e7a5e0986 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,8 @@ All notable changes to Bambuddy will be documented in this file.
## [0.2.5b1] - Unreleased
### Fixed
+- **Assign-spool picker note now visible on mobile (#793 follow-up, reporter @EmcetPL)** — The original fix for #793 added the spool note as an HTML `title=` tooltip on each picker button in `AssignSpoolModal.tsx` (lines 417 + 492). `title=` only surfaces on hover, which doesn't exist on touch devices — a phone user tapping a card just selects it, the note never appears. Users who store their tracking ID in the note field were blind on mobile. **Fix.** Render the note as a small muted truncated line directly under the weight on both the internal-inventory branch and the Spoolman branch: `text-[10px] text-bambu-gray/70 mt-1 truncate`, kept inside the `truthy &&` guard so empty notes don't add a blank row. The existing `title={spool.note}` is preserved on the new `
` element so desktop hover and mobile-browser long-press still surface the full untruncated text for notes that overflow the truncate. Keeps the 2-col mobile grid density unchanged (one extra `text-[10px]` line is ~12 px), no new state, no popover/modal, no new touch target. Mirrored across both branches per the inventory-parity rule so internal and Spoolman pickers stay shape-equal. Frontend `npm run build` clean. `npx vitest run AssignSpoolModal.test.tsx AssignToAmsModal.test.tsx` 23/23 green. **Scope.** No backend change. No new permission. No new i18n key (the note text is user-authored, not translatable).
+
- **API keys with Manage Library permission can now rename / delete / move library files (#1832, reporter @MorganMLGman)** — `require_ownership_permission` gates API keys on `all_perm` only (line 1668) — the comment block at line 1659 says OWN and ALL "both map to the same scope flag" for queue / archives / etc., so checking `all_perm` is the correct gate. Library deliberately broke that invariant by putting `LIBRARY_UPDATE_ALL` / `LIBRARY_DELETE_ALL` in `_APIKEY_DENIED_PERMISSIONS` while only the OWN variants were allowlisted under `can_manage_library`. Net effect: every library curation route (DELETE `/library/files/{id}`, PUT `/library/files/{id}` rename, POST `/library/files/move`) returned `403 "API keys cannot be used for administrative operations"` for keys with `can_manage_library=True`, contradicting the wiki docs that explicitly list "rename and delete your own library entries" under that scope. Only `POST /library/files/{id}/slice` worked (it doesn't go through `require_ownership_permission`). The "ALL stays admin-only because it crosses the user boundary" comment was internally inconsistent: API keys have no per-row ownership identity (`user=None`), so the route's `file.created_by_id != user.id` ownership check would `AttributeError` on a key acting under OWN anyway — the only path that ever worked was `can_modify_all=True`, which `all_perm` denial blocked outright. **Fix.** Fold `LIBRARY_UPDATE_ALL` and `LIBRARY_DELETE_ALL` into `_APIKEY_SCOPE_BY_PERMISSION` mapping to `can_manage_library` (matching the `can_queue` precedent — both `QUEUE_UPDATE_OWN` and `QUEUE_UPDATE_ALL` map to `can_queue` for the same per-key-identity reason). Remove both from `_APIKEY_DENIED_PERMISSIONS`. `LIBRARY_PURGE` deliberately stays denied — it bypasses the soft-delete window and is genuinely destructive, the kind of cross-boundary op the denylist exists for. **Tests.** 5 new cases in `TestLibraryPermissions` pinning the route-level contract — `test_apikey_with_manage_library_can_delete_file`, `test_apikey_with_manage_library_can_rename_file`, `test_apikey_with_manage_library_can_move_file`, `test_apikey_without_manage_library_still_blocked` (regression guard that the fix widens the allowed-permission set, not the per-key scope check), and `test_apikey_with_manage_library_still_cannot_purge` (LIBRARY_PURGE stays admin-only). The matrix drift-detection in `test_auth_apikey_rbac.py` updated to include `LIBRARY_UPDATE_OWN`, `LIBRARY_UPDATE_ALL`, `LIBRARY_DELETE_ALL` under `can_manage_library` and removes `LIBRARY_DELETE_ALL` from `_ADMIN_CASES`. `pytest -n 30 backend/tests/unit backend/tests/integration` green (6494). Ruff clean. **Scope.** No DB migration. No schema change. No frontend change. The wiki entry for API key permissions at `/features/api-keys/#available-permissions` now matches actual behaviour.
- **HMS Action buttons now reach the printer (#1830, H2D/H2C wrong-plate verification)** — The HMS Actions feature shipped in #1743 looked correct at the publish layer but the firmware silently dropped the commands at the printer, so clicking "Stop printing", "Problem solved and resume", or "Ignore and resume" did nothing visible on the live H2D — the modal kept reappearing, the print stayed paused, and the route still returned `200 OK`. Three independent bugs combined into one user-facing failure. **(1) Wrong command shape for resume / stop.** `hms_resume()` and `hms_stop()` sent the documented-but-not-actually-used `{"err": , "param": "reserve", "job_id": , ...}` shape that BambuStudio never produces. Bambu firmware rejects this silently — verified by injecting candidate shapes on `device//request` against a live H2D paused on a wrong-plate HMS: the `err`-bearing shape held PAUSE → PAUSE for the full window, the plain `{"print":{"command":"stop","param":"","sequence_id":"0"}}` transitioned PAUSE → FAILED in 1.7s, the same plain `resume` transitioned PAUSE → RUNNING in <2s. Fix: both helpers send the plain shape now, no `err`, no `job_id`, no `param:"reserve"`. **(2) `IGNORE_RESUME` mapped to the wrong command for paused prints.** The original mapping dispatched `idle_ignore` for both `IGNORE_RESUME` and `NO_REMINDER_NEXT_TIME`. `idle_ignore` is BambuStudio's "dismiss this warning" command and only works for non-pause warnings — verified against the H2D, idle_ignore on a paused print is silently rejected regardless of `err`. `hms_ignore()` now branches on `self.state.gcode_state == "PAUSE"`: paused → dispatch plain `resume` (which is what the button actually means on a paused print), running/idle → keep `idle_ignore` with the `type=0/1` persistence flag. `DONT_REMIND_NEXT_TIME` on PAUSE degrades to resume too — the "don't remind" flag can't ride along on a resume but the user's clicked-action intent (continue printing) is honoured. **(3) 64-bit `hms[]`-array faults truncated to a non-matching `err` (#1830 §(1)).** The hms[] parser at line 2740 built the short code as `f"{(attr >> 16) & 0xFFFF:04X}_{code & 0xFFFF:04X}"`, discarding 32 of the 64 bits of the fault identifier. For codes whose full form is e.g. `0C00_0300_0002_000C`, the truncated `0C00000C` doesn't match what the firmware compares against in `idle_ignore`. New `HMSError.full_code` field carries the canonical hex identifier — 16 chars `f"{attr:08X}{code:08X}"` for hms[]-sourced faults, 8 chars `f"{print_error:08X}"` for print_error-sourced faults (which are already 32-bit). Catalog lookup tries the 16-char form first and falls back to the 8-char short code so existing entries keep matching. Frontend echoes `error.full_code` back as `HmsActionBody.print_error` instead of recomputing the short code; the schema's pattern relaxes to `^[0-9A-Fa-f]{8}([0-9A-Fa-f]{8})?$` to accept both lengths. **(4) Masking failure — publish-success returned as printer-ack (#1830 §(3)).** `execute_hms_action` returned True the moment the publish succeeded, so any of the three bugs above produced `200 OK` while the printer ignored the command and the modal kept popping. The `/hms/execute-action` route now snapshots `(gcode_state, print_error, hms_errors count)` before dispatch, awaits `HMS_ACTION_ACK_WAIT_SECONDS` (default 2.5s, module-level so tests override), and returns `502 "Printer did not acknowledge HMS action within 2.5s"` if none of those moved. Every accepted HMS action mutates at least one of the three, so this is a clean signal. **Empirical verification.** A test harness on `device/0948BB540200427/request` confirmed each shape against the live H2D: a print sent with deliberately-wrong build plate raises `print_error=0x05008051` ("Detected build plate is not the same as the Gcode file"), the printer enters `gcode_state=PAUSE`, and the new command shapes transition out correctly. The current Bambuddy code (before this fix) failed to act on every button. **Tests.** `test_hms_actions.py` shape assertions rewritten — `test_resume_is_plain_no_err_no_job_id`, `test_stop_is_plain_no_err_no_job_id`, `test_ignore_resume_dispatches_resume_when_print_paused`, `test_ignore_resume_uses_idle_ignore_when_not_paused`, `test_dont_remind_dispatches_resume_when_paused`, `test_dont_remind_uses_idle_ignore_type_one_when_not_paused`, `test_idle_ignore_accepts_16_char_full_code`. New `TestHMSFullCode` class in `test_bambu_mqtt.py` pins the parser contract — `test_hms_array_path_populates_16_char_full_code`, `test_print_error_path_populates_8_char_full_code`, `test_hms_array_catalog_lookup_tries_16_char_first`, `test_hms_array_catalog_falls_back_to_8_char`. New integration cases in `test_printers_api.py` — `test_execute_hms_action_no_printer_ack_returns_502`, `test_execute_hms_action_accepts_16_char_full_code`. The malformed-input test now covers 9- and 15-char rejections (the relaxed pattern accepts 8 OR 16, nothing in between). `pytest -n 30 backend/tests/unit/services/test_hms_actions.py backend/tests/unit/services/test_bambu_mqtt.py backend/tests/unit/services/test_printer_manager.py backend/tests/integration/test_printers_api.py` green (509 + 181). `ruff check` clean. Frontend `npm run build` clean. **Scope.** No DB migration. No new permission. No new i18n key — the frontend toast on action failure already uses the existing `hmsErrors.actionFailed` string, which now gets the more accurate "Printer did not acknowledge" message instead of "Failed to send action". The `HMSError.full_code` field defaults to `""` so old in-memory state surviving a backend upgrade (without an MQTT reconnect) degrades to the existing 8-char short code via the frontend's `||` fallback.
diff --git a/frontend/src/components/AssignSpoolModal.tsx b/frontend/src/components/AssignSpoolModal.tsx
index 66335289a..cd8209294 100644
--- a/frontend/src/components/AssignSpoolModal.tsx
+++ b/frontend/src/components/AssignSpoolModal.tsx
@@ -438,6 +438,11 @@ export function AssignSpoolModal({ isOpen, onClose, printerId, amsId, trayId, tr
{Math.max(0, Math.round(spool.label_weight - spool.weight_used))} / {spool.label_weight}g
)}
+ {spool.note && (
+
+ {spool.note}
+
+ )}
))}
@@ -513,6 +518,11 @@ export function AssignSpoolModal({ isOpen, onClose, printerId, amsId, trayId, tr
{Math.max(0, Math.round(spool.label_weight - spool.weight_used))} / {spool.label_weight}g
)}
+ {spool.note && (
+
+ {spool.note}
+
+ )}
))}
diff --git a/static/assets/index-CfzVLrcT.js b/static/assets/index-CoslqvGC.js
similarity index 98%
rename from static/assets/index-CfzVLrcT.js
rename to static/assets/index-CoslqvGC.js
index 64c8094c7..560ee858f 100644
--- a/static/assets/index-CfzVLrcT.js
+++ b/static/assets/index-CoslqvGC.js
@@ -8508,7 +8508,7 @@ void main() {
border-l-[5px] border-l-transparent
border-r-[5px] border-r-transparent
border-t-[5px] border-t-bambu-dark-tertiary
- `})]}),document.body)]})}function OU({isOpen:e,onClose:t,tagUid:n,trayUuid:r,printerId:i,amsId:a,trayId:o}){let{t:s}=$e(),c=no(),{showToast:l}=Ed(),[u,d]=(0,y.useState)(``),f=r||n,{data:p,isLoading:m}=q({queryKey:[`unlinked-spools`],queryFn:Q.getUnlinkedSpools,enabled:e}),h=(0,y.useMemo)(()=>p?p.filter(e=>{if(!u)return!0;let t=u.toLowerCase();return e.filament_name&&e.filament_name.toLowerCase().includes(t)||e.filament_vendor&&e.filament_vendor.toLowerCase().includes(t)||e.filament_material&&e.filament_material.toLowerCase().includes(t)||String(e.id).includes(t)}):[],[p,u]),g=J({mutationFn:e=>Q.linkSpool(e,{spoolTag:f,printerId:i,amsId:a,trayId:o}),onSuccess:()=>{c.invalidateQueries({queryKey:[`unlinked-spools`]}),c.invalidateQueries({queryKey:[`linked-spools`]}),c.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),l(s(`spoolman.linkSuccess`),`success`),t()},onError:e=>{l(e.message||s(`spoolman.linkFailed`),`error`)}});return e?(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 bg-bambu-dark-secondary rounded-xl shadow-xl w-full max-w-md mx-4 max-h-[80vh] flex flex-col border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-white/10`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Vc,{className:`w-5 h-5 text-bambu-green`}),s(`spoolman.selectSpool`)]}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[`AMS `,a,` T`,o,` · Printer #`,i]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(Bu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 border-b border-white/10`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Rl,{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:u,onChange:e=>d(e.target.value),placeholder:s(`inventory.searchSpools`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark rounded-lg border border-white/10 text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),(r||n)&&(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-2 font-mono truncate`,title:r||n,children:[`Tag: `,r||n]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 min-h-0`,children:m?(0,K.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):h.length===0?(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-8 text-sm`,children:s(`inventory.noSpoolsMatch`)}):h.map(e=>(0,K.jsxs)(`button`,{onClick:()=>g.mutate(e.id),disabled:g.isPending||!f,className:`w-full flex items-center gap-3 p-3 rounded-lg hover:bg-white/5 transition-colors text-left`,children:[(0,K.jsx)(`span`,{className:`w-6 h-6 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.filament_color_hex?`#${e.filament_color_hex}`:`#808080`}}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm text-white font-medium truncate`,children:e.filament_name||s(`spoolman.spoolId`)}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray truncate`,children:[e.filament_vendor?`${e.filament_vendor} · `:``,e.filament_material||`Unknown`,` · #`,e.id]})]}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.remaining_weight==null?`—`:`${Math.round(e.remaining_weight)}g`})]},e.id))}),(0,K.jsx)(`div`,{className:`p-4 border-t border-white/10 flex justify-end`,children:(0,K.jsx)($,{variant:`ghost`,onClick:t,children:s(`inventory.cancel`)||`Cancel`})})]})]}):null}function BOe(e,t){if(!t)return!0;let n=t.toLowerCase();return String(e.id).includes(n)||e.material.toLowerCase().includes(n)||(e.brand?.toLowerCase().includes(n)??!1)||(e.color_name?.toLowerCase().includes(n)??!1)||(e.subtype?.toLowerCase().includes(n)??!1)||(e.note?.toLowerCase().includes(n)??!1)||(e.slicer_filament_name?.toLowerCase().includes(n)??!1)||(e.storage_location?.toLowerCase().includes(n)??!1)}function kU(e,t){return t?e.filter(e=>BOe(e,t)):e}function AU({isOpen:e,onClose:t,printerId:n,amsId:r,trayId:i,trayInfo:a,spoolmanEnabled:o}){let{t:s}=$e(),c=no(),{showToast:l}=Ed(),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null);(0,y.useEffect)(()=>{p(null),h(null)},[u]);let[g,_]=(0,y.useState)(``),[v,b]=(0,y.useState)(null),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(null);(0,y.useEffect)(()=>{e&&d(!1)},[e]);let{data:T,isLoading:E}=q({queryKey:[`inventory-spools`,`assign-modal`],queryFn:()=>Q.getSpools(!0),enabled:e&&!o}),{data:D}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),enabled:e}),{data:O}=q({queryKey:[`settings`],queryFn:()=>Q.getSettings(),enabled:e}),{data:k,isLoading:A}=q({queryKey:[`spoolman-inventory-spools`,`assign-modal`],queryFn:()=>Q.getSpoolmanInventorySpools(!1),enabled:e&&!!o}),{data:j}=q({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:e&&!!o}),M=(0,y.useMemo)(()=>j?new Set(j.filter(e=>!(e.printer_id===n&&e.ams_id===r&&e.tray_id===i)).map(e=>e.spoolman_spool_id)):new Set,[j,n,r,i]),N=()=>{Q.refreshPrinterStatus(n).catch(()=>{}),c.invalidateQueries({queryKey:[`printerStatus`,n]})},P=J({mutationFn:e=>Q.assignSpool({spool_id:e,printer_id:n,ams_id:r,tray_id:i}),onSuccess:e=>{c.setQueryData([`spool-assignments`],t=>{let a=(t||[]).filter(e=>!(e.printer_id===n&&e.ams_id===r&&e.tray_id===i));return a.push(e),a}),c.invalidateQueries({queryKey:[`spool-assignments`]}),N(),l(s(e.pending_config?`inventory.assignPendingInsert`:`inventory.assignSuccess`),`success`),S(!1),b(null),w(null),t()},onError:e=>{l(`${s(`inventory.assignFailed`)}: ${e.message}`,`error`)}}),F=J({mutationFn:e=>Q.assignSpoolmanSlot({spoolman_spool_id:e,printer_id:n,ams_id:r,tray_id:i}),onSuccess:()=>{c.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),c.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),N(),l(s(`inventory.assignSuccess`),`success`),t()},onError:e=>{l(`${s(`inventory.assignFailed`)}: ${e.message}`,`error`)}}),I=e=>(e??``).trim().toUpperCase(),L=(e,t)=>{let n=I(e),r=I(t);return!n||!r?`none`:n===r?`exact`:r.includes(n)||n.includes(r)?`partial`:`none`},R=e=>e.split(`@`)[0].trim(),z=(e,t)=>{let n=R(I(e)),r=R(I(t));return!n||!r?!1:n===r};if(!e)return null;let B=new Set((D||[]).filter(e=>!(e.printer_id===n&&e.ams_id===r&&e.tray_id===i)).map(e=>e.spool_id)),V=T?.filter(e=>!e.archived_at&&(u||!B.has(e.id))),ee=V;if(!u){let e=R(I(a?.profile)),t=I(a?.material||a?.type);(e||t)&&(ee=ee?.filter(n=>{let r=R(I(n.slicer_filament_name||n.slicer_filament)),i=I(n.material);return e&&r&&r===e?!0:t&&i?i===t||t.includes(i)||i.includes(t):!r&&!i}))}g&&ee&&(ee=kU(ee,g));let te=()=>{if(m!==null){F.mutate(m);return}if(!f)return;let e=T?.find(e=>e.id===f);if(!e){l(s(`inventory.assignFailed`),`error`);return}if(!O?.disable_filament_warnings&&a){let t=a.material||a.type,n=L(e.material,t),r=e.slicer_filament_name||e.slicer_filament,i=a.profile||a.type,o=z(r,i);if(n!==`exact`){let a;a=n===`none`&&!o?`material_profile`:n===`partial`&&!o?`partial_profile`:n===`none`?`material`:`partial`,b(f),w({type:a,spoolMaterial:e.material||``,trayMaterial:t||``,spoolProfile:r||void 0,trayProfile:i||void 0}),S(!0);return}}P.mutate(f)},H=()=>{v&&(P.mutate(v),S(!1),b(null))};return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`fixed inset-0 z-[100] 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-2xl 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)(pl,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:s(`inventory.assignSpool`)})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(Bu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto`,children:[a&&(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:[s(`inventory.selectSpool`),`:`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a.color&&(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${a.color}`}}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:a.type||s(`ams.emptySlot`)}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,a.location,`)`]})]})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Rl,{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:g,onChange:e=>_(e.target.value),placeholder:s(`inventory.searchSpools`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[!o&&(E?(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`})}):ee&&ee.length>0?(0,K.jsx)(`div`,{className:`max-h-96 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2`,children:ee.map(e=>(0,K.jsxs)(`button`,{onClick:()=>{p(e.id),h(null)},title:e.note||void 0,className:`p-2.5 rounded-lg border text-left transition-colors ${f===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,K.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[e.rgba&&(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:Yd(e.rgba)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:e.color_name||``})]}),e.label_weight&&(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[Math.max(0,Math.round(e.label_weight-e.weight_used)),` / `,e.label_weight,`g`]})]},e.id))}):V&&V.length===0?(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(`p`,{children:s(`inventory.noAvailableSpools`)}),T&&(0,K.jsxs)(`p`,{className:`text-[10px] mt-2 opacity-60`,children:[T.length,` fetched · `,T.filter(e=>e.archived_at).length,` archived ·`,` `,T.filter(e=>B.has(e.id)).length,` assigned to other slots`]})]}):(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(`p`,{children:s(`inventory.noSpoolsMatch`)}),V&&(0,K.jsxs)(`p`,{className:`text-[10px] mt-2 opacity-60`,children:[V.length,` unassigned spools — `,V.length-(ee?.length??0),` filtered by tray match. Try "Show all spools".`]})]})),o&&(0,K.jsx)(K.Fragment,{children:A?(0,K.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,K.jsx)(X,{className:`w-5 h-5 text-bambu-green animate-spin`})}):k&&k.filter(e=>!e.archived_at&&!M.has(e.id)).length>0?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide pt-1`,children:s(`inventory.spoolmanSpools`)}),(0,K.jsx)(`div`,{className:`max-h-64 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2`,children:kU(k.filter(e=>!e.archived_at&&!M.has(e.id)),g).map(e=>(0,K.jsxs)(`button`,{onClick:()=>{h(e.id),p(null)},title:e.note||void 0,className:`p-2.5 rounded-lg border text-left transition-colors ${m===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,K.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[e.rgba&&(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:Yd(e.rgba)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:e.color_name||``})]}),e.label_weight&&(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[Math.max(0,Math.round(e.label_weight-e.weight_used)),` / `,e.label_weight,`g`]})]},`spoolman-${e.id}`))})]}):null})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between items-center p-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{id:`disable-filtering-toggle`,type:`checkbox`,checked:u,onChange:()=>d(e=>!e),className:`accent-bambu-green w-4 h-4 rounded focus:ring-0 border-bambu-dark-tertiary`}),(0,K.jsx)(`label`,{htmlFor:`disable-filtering-toggle`,className:`text-xs text-bambu-gray select-none cursor-pointer`,children:s(`inventory.showAllSpools`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,children:s(`common.cancel`)}),(0,K.jsx)($,{onClick:te,disabled:!f&&m===null||P.isPending||F.isPending,children:P.isPending||F.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),s(`inventory.assigning`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(pl,{className:`w-4 h-4`}),s(`inventory.assignSpool`)]})})]})]}),P.isError&&(0,K.jsx)(`div`,{className:`mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400`,children:P.error.message})]})]}),x&&a&&f&&C&&(()=>{let e=``;return C.type===`material`?e=s(`inventory.assignMismatchMessage`,{spoolMaterial:C.spoolMaterial,trayMaterial:C.trayMaterial,location:a.location}):C.type===`partial`?e=s(`inventory.assignPartialMismatchMessage`,{spoolMaterial:C.spoolMaterial,trayMaterial:C.trayMaterial,location:a.location}):C.type===`material_profile`?e=`${s(`inventory.assignMismatchMessage`,{spoolMaterial:C.spoolMaterial,trayMaterial:C.trayMaterial,location:a.location})}\n\n${s(`inventory.assignProfileMismatchMessage`,{spoolProfile:C.spoolProfile||s(`common.unknown`),trayProfile:C.trayProfile||s(`common.unknown`),location:a.location})}`:C.type===`partial_profile`&&(e=`${s(`inventory.assignPartialMismatchMessage`,{spoolMaterial:C.spoolMaterial,trayMaterial:C.trayMaterial,location:a.location})}\n\n${s(`inventory.assignProfileMismatchMessage`,{spoolProfile:C.spoolProfile||s(`common.unknown`),trayProfile:C.trayProfile||s(`common.unknown`),location:a.location})}`),e=`${e}\n\n${s(`inventory.assignReconfigureNote`)}`,(0,K.jsx)(jd,{title:s(`inventory.assignMismatchTitle`),message:e,confirmText:s(`inventory.assignMismatchConfirm`),variant:`warning`,overlayZIndex:`z-[110]`,isLoading:P.isPending,onConfirm:H,onCancel:()=>{P.isPending||(S(!1),b(null),w(null))}})})()]})}var VOe={bambuModelByShortCode:{}},jU={"A1 MINI":[`A1M`]};function MU(e,t){let n=e.toUpperCase(),r=t.toUpperCase();if(n===r)return!0;let i=jU[r];if(i&&i.includes(n))return!0;let a=jU[n];return!!(a&&a.includes(r))}function HOe(e){let t={};for(let[n,r]of Object.entries(e))r in t||(t[r]=n.replace(/^Bambu Lab\s+/,``));return t}function NU(e={}){return{bambuModelByShortCode:HOe(e)}}function PU(e){return e.replace(/\s+/g,``).toLowerCase()}var UOe=`0.4`;function FU(e){let t=e.match(/^(.*?)\s+([\d.]+)\s*nozzle\s*$/i);return t?{stripped:t[1].trim(),nozzle:t[2]}:{stripped:e.trim(),nozzle:null}}function WOe(e){let t=e.indexOf(`@BBL `);if(t<0)return null;let{stripped:n,nozzle:r}=FU(e.slice(t+5).trim());return n?{token:n,nozzle:r}:null}function GOe(e){let t=e.match(/^Bambu Lab\s+(.+)$/i);if(!t)return null;let{stripped:n,nozzle:r}=FU(t[1]);return n?{model:n,nozzle:r}:null}function KOe(e,t,n){let r=WOe(e);if(!r)return`unknown`;let i=n[r.token]??r.token,a=GOe(t);return a?PU(a.model)!==PU(i)&&!MU(r.token,a.model)||a.nozzle!==null&&(r.nozzle??UOe)!==a.nozzle?`mismatch`:`match`:`unknown`}function IU(e,t,n,r){if(!n)return`unknown`;let i=e.compatible_printers;return i&&i.length>0?i.includes(n)?`match`:`mismatch`:KOe(e.name,n,r.bambuModelByShortCode)}var LU=[`PLA`,`PETG`,`ABS`,`TPU`,`ASA`,`PC`,`PA`,`PVA`,`HIPS`,`PA-CF`,`PETG-CF`,`PLA-CF`],RU=[`Bambu`,`PolyLite`,`PolyTerra`,`eSUN`,`Overture`,`Fiberon`,`SUNLU`,`Inland`,`Hatchbox`,`Generic`],zU=`Basic.Matte.Silk.Silk+.Tough.Tough+.HF.High Flow.Engineering.CF.GF.Galaxy.Glow.Marble.Metal.Rainbow.Sparkle.Wood.Translucent.Transparent.Clear.Lite.Pro.Plus.Max.Super.Ultra.Flex.Soft.Hard.Strong.Impact.Heat Resistant.UV Resistant.ESD.Conductive.Magnetic.Gradient.Dual Color.Tri Color.Multicolor`.split(`.`),BU=[{name:`Black`,hex:`000000`},{name:`White`,hex:`FFFFFF`},{name:`Gray`,hex:`808080`},{name:`Red`,hex:`FF0000`},{name:`Orange`,hex:`FFA500`},{name:`Yellow`,hex:`FFFF00`},{name:`Green`,hex:`00AE42`},{name:`Blue`,hex:`0066FF`},{name:`Purple`,hex:`8B00FF`},{name:`Pink`,hex:`FF69B4`},{name:`Brown`,hex:`8B4513`},{name:`Silver`,hex:`C0C0C0`},{name:`Clear`,hex:`00000000`}],qOe=[{name:`Dark Red`,hex:`8B0000`},{name:`Crimson`,hex:`DC143C`},{name:`Coral`,hex:`FF7F50`},{name:`Salmon`,hex:`FA8072`},{name:`Dark Orange`,hex:`FF8C00`},{name:`Peach`,hex:`FFDAB9`},{name:`Gold`,hex:`FFD700`},{name:`Khaki`,hex:`F0E68C`},{name:`Lemon`,hex:`FFF44F`},{name:`Lime`,hex:`32CD32`},{name:`Forest Green`,hex:`228B22`},{name:`Olive`,hex:`808000`},{name:`Mint`,hex:`98FF98`},{name:`Teal`,hex:`008080`},{name:`Navy`,hex:`000080`},{name:`Sky Blue`,hex:`87CEEB`},{name:`Royal Blue`,hex:`4169E1`},{name:`Cyan`,hex:`00FFFF`},{name:`Turquoise`,hex:`40E0D0`},{name:`Violet`,hex:`EE82EE`},{name:`Magenta`,hex:`FF00FF`},{name:`Indigo`,hex:`4B0082`},{name:`Lavender`,hex:`E6E6FA`},{name:`Plum`,hex:`DDA0DD`},{name:`Hot Pink`,hex:`FF69B4`},{name:`Rose`,hex:`FF007F`},{name:`Blush`,hex:`FFB6C1`},{name:`Chocolate`,hex:`D2691E`},{name:`Tan`,hex:`D2B48C`},{name:`Beige`,hex:`F5F5DC`},{name:`Maroon`,hex:`800000`},{name:`Dark Gray`,hex:`404040`},{name:`Light Gray`,hex:`D3D3D3`},{name:`Charcoal`,hex:`36454F`},{name:`Ivory`,hex:`FFFFF0`},{name:`Bambu Green`,hex:`00AE42`},{name:`Jade White`,hex:`E8E8E8`},{name:`Titan Gray`,hex:`5A5A5A`}],VU=[...BU,...qOe],HU=`bambuddy-recent-colors`,JOe=[{code:`GFL00`,name:`Bambu PLA Basic`,displayName:`Bambu PLA Basic`,isCustom:!1,allCodes:[`GFL00`]},{code:`GFL01`,name:`Bambu PLA Matte`,displayName:`Bambu PLA Matte`,isCustom:!1,allCodes:[`GFL01`]},{code:`GFL05`,name:`Generic PLA`,displayName:`Generic PLA`,isCustom:!1,allCodes:[`GFL05`]},{code:`GFG00`,name:`Bambu PETG Basic`,displayName:`Bambu PETG Basic`,isCustom:!1,allCodes:[`GFG00`]},{code:`GFG05`,name:`Generic PETG`,displayName:`Generic PETG`,isCustom:!1,allCodes:[`GFG05`]},{code:`GFB00`,name:`Bambu ABS Basic`,displayName:`Bambu ABS Basic`,isCustom:!1,allCodes:[`GFB00`]},{code:`GFB05`,name:`Generic ABS`,displayName:`Generic ABS`,isCustom:!1,allCodes:[`GFB05`]},{code:`GFA00`,name:`Bambu ASA Basic`,displayName:`Bambu ASA Basic`,isCustom:!1,allCodes:[`GFA00`]},{code:`GFU00`,name:`Bambu TPU 95A`,displayName:`Bambu TPU 95A`,isCustom:!1,allCodes:[`GFU00`]},{code:`GFU05`,name:`Generic TPU`,displayName:`Generic TPU`,isCustom:!1,allCodes:[`GFU05`]},{code:`GFC00`,name:`Bambu PC Basic`,displayName:`Bambu PC Basic`,isCustom:!1,allCodes:[`GFC00`]},{code:`GFN00`,name:`Bambu PA Basic`,displayName:`Bambu PA Basic`,isCustom:!1,allCodes:[`GFN00`]},{code:`GFN05`,name:`Generic PA`,displayName:`Generic PA`,isCustom:!1,allCodes:[`GFN05`]},{code:`GFS00`,name:`Bambu PLA-CF`,displayName:`Bambu PLA-CF`,isCustom:!1,allCodes:[`GFS00`]},{code:`GFT00`,name:`Bambu PETG-CF`,displayName:`Bambu PETG-CF`,isCustom:!1,allCodes:[`GFT00`]},{code:`GFNC0`,name:`Bambu PA-CF`,displayName:`Bambu PA-CF`,isCustom:!1,allCodes:[`GFNC0`]},{code:`GFV00`,name:`Bambu PVA`,displayName:`Bambu PVA`,isCustom:!1,allCodes:[`GFV00`]}];function UU(e){let t=e.replace(/@.*$/,``).trim();t=t.replace(/\(Custom\)/i,``).trim(),t=t.replace(/^[#*]+\s*/,``).trim();let n=`PLA-CF.PETG-CF.ABS-GF.ASA-CF.PA-CF.PAHT-CF.PA6-CF.PA6-GF.PPA-CF.PPA-GF.PET-CF.PPS-CF.PC-CF.PC-ABS.ABS-GF.PCTG.PETG.PLA.ABS.ASA.PC.PA.TPU.PVA.HIPS.BVOH.PPS.PEEK.PEI`.split(`.`),r=``,i=-1;for(let e of n){let n=t.toUpperCase().indexOf(e.toUpperCase());if(n!==-1){r=e,i=n;break}}let a=``;i>0&&(a=t.substring(0,i).trim(),a=a.replace(/[-_\s]+$/,``));let o=``;i!==-1&&r&&(o=t.substring(i+r.length).trim(),o=o.replace(/^[-_\s]+/,``));let s=``;for(let e of zU)if(o.toLowerCase().includes(e.toLowerCase())){s=e;break}if(!s&&a)for(let e of zU){let t=RegExp(`\\s+${e}$`,`i`);if(t.test(a)){s=e,a=a.replace(t,``).trim();break}}return{brand:a,material:r,variant:s}}function WU(e,t){let n=new Set(RU);for(let t of e){let{brand:e}=UU(t.name);e&&e.length>1&&n.add(e)}if(t)for(let e of t)if(e.filament_vendor&&e.filament_vendor.length>1)n.add(e.filament_vendor);else{let{brand:t}=UU(e.name);t&&t.length>1&&n.add(t)}return Array.from(n).sort((e,t)=>e.localeCompare(t))}function YOe(e){let t=e.filter(e=>e.preset_type===`filament`);return t.length===0?[]:t.map(e=>{let t=String(e.id),n=e.filament_type||t,r=Array.from(new Set([t,n]));return{code:t,name:e.name,displayName:e.name,isCustom:!1,allCodes:r}}).sort((e,t)=>e.displayName.localeCompare(t.displayName))}function GU(e,t,n,r){let i=[],a=[],o=new Set;for(let n of e)if(n.is_custom){let e=n.name.toUpperCase();(t.size===0||Array.from(t).some(t=>e.includes(t))||!e.includes(`@`))&&(i.push({code:n.setting_id,name:n.name,displayName:`${n.name} (Custom)`,isCustom:!0,allCodes:[n.setting_id]}),o.add(n.setting_id))}else a.push({code:n.setting_id,name:n.name,displayName:n.name,isCustom:!1,allCodes:[n.setting_id]}),o.add(n.setting_id);let s=n&&n.length>0?YOe(n):[],c=[];if(r&&r.length>0)for(let e of r){let t=e.filament_id.startsWith(`GF`)?`GFS`+e.filament_id.slice(2):e.filament_id;o.has(e.filament_id)||o.has(t)||c.push({code:e.filament_id,name:e.name,displayName:e.name,isCustom:!1,allCodes:[e.filament_id,t]})}let l=[...i,...a,...s,...c];return l.length===0?JOe:l.sort((e,t)=>e.displayName.localeCompare(t.displayName))}function KU(e,t){if(!e)return;let n=t.find(t=>t.code===e);if(n||=t.find(t=>t.allCodes.includes(e)),!n){let r=e.toLowerCase();n=t.find(e=>e.code.toLowerCase()===r||e.allCodes.some(e=>e.toLowerCase()===r))}return n}function qU(){try{let e=localStorage.getItem(HU);if(e)return JSON.parse(e)}catch{}return[]}function JU(e,t){let n=[e,...t.filter(t=>t.hex.toUpperCase()!==e.hex.toUpperCase())].slice(0,8);try{localStorage.setItem(HU,JSON.stringify(n))}catch{}return n}function YU(e){if(!e)return``;let t=e.split(`_`)[0];return/^GFS/i.test(t)&&(t=t.slice(0,2)+t.slice(3)),t.toUpperCase()}function XU(e){return!!e&&/^GF[A-Z]99$/i.test(e)}function ZU(e,t){if(!t.material)return!1;let n=YU(t.slicer_filament),r=YU(e.filament_id);if(n&&r&&n===r&&!XU(r))return!0;let i=(e.name||``).replace(/^High Flow[_\s]+/i,``).replace(/^Standard[_\s]+/i,``).replace(/^HF[_\s]+/i,``).replace(/^S[_\s]+/i,``).trim(),a=UU(i);return!(a.material.toUpperCase()!==t.material.toUpperCase()||t.brand&&!(a.brand.toLowerCase().includes(t.brand.toLowerCase())||t.brand.toLowerCase().includes(a.brand.toLowerCase()))||t.subtype&&!(a.variant.toLowerCase().includes(t.subtype.toLowerCase())||t.subtype.toLowerCase().includes(a.variant.toLowerCase())||i.toLowerCase().includes(t.subtype.toLowerCase())))}function QU(e){let t=e.includes(`_`)?e.split(`_`)[0]:e;return t.startsWith(`GFS`)?`GF`+t.slice(3):(t.startsWith(`PFUS`)||t.startsWith(`PFSP`),t)}var $U=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`NYLON`,`PVA`,`HIPS`,`PP`,`PET`];function eW(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase(),r=n.match(/\bSUPPORT\s+FOR\s+/);if(r){let e=n.slice(r.index+r[0].length);for(let n of $U)if(RegExp(`\\b${n}\\b`).test(e))return{material:n,brand:t.slice(0,r.index).trim(),variant:`Support`}}for(let e of $U){let r=RegExp(`\\b${e}\\b`,`i`);if(r.test(n)){let n=t.split(r);return{material:e,brand:n[0]?.trim()||``,variant:n[1]?.trim()||``}}}let i=t.split(/\s+/);return i.length>=2?{material:i[1],brand:i[0],variant:i.slice(2).join(` `)}:{material:t,brand:``,variant:``}}function XOe(e){return!e.startsWith(`GF`)&&!e.startsWith(`P1`)}var ZOe={white:`FFFFFF`,black:`000000`,red:`FF0000`,green:`00FF00`,blue:`0000FF`,yellow:`FFFF00`,cyan:`00FFFF`,magenta:`FF00FF`,orange:`FFA500`,purple:`800080`,pink:`FFC0CB`,brown:`8B4513`,gray:`808080`,grey:`808080`,"jade white":`FFFEF2`,ivory:`FFFFF0`,beige:`F5F5DC`,cream:`FFFDD0`,silver:`C0C0C0`,gold:`FFD700`,bronze:`CD7F32`,copper:`B87333`,navy:`000080`,teal:`008080`,olive:`808000`,maroon:`800000`,coral:`FF7F50`,salmon:`FA8072`,lime:`32CD32`,mint:`98FF98`,"forest green":`228B22`,"sky blue":`87CEEB`,"royal blue":`4169E1`,turquoise:`40E0D0`,lavender:`E6E6FA`,violet:`EE82EE`,plum:`DDA0DD`,tan:`D2B48C`,chocolate:`D2691E`,charcoal:`36454F`,slate:`708090`,transparent:`000000`,natural:`F5F5DC`,wood:`DEB887`},tW=[{name:`White`,hex:`FFFFFF`},{name:`Black`,hex:`000000`},{name:`Red`,hex:`FF0000`},{name:`Blue`,hex:`0000FF`},{name:`Green`,hex:`00AA00`},{name:`Yellow`,hex:`FFFF00`},{name:`Orange`,hex:`FFA500`},{name:`Gray`,hex:`808080`}],nW=[{name:`Cyan`,hex:`00FFFF`},{name:`Magenta`,hex:`FF00FF`},{name:`Purple`,hex:`800080`},{name:`Pink`,hex:`FFC0CB`},{name:`Brown`,hex:`8B4513`},{name:`Beige`,hex:`F5F5DC`},{name:`Navy`,hex:`000080`},{name:`Teal`,hex:`008080`},{name:`Lime`,hex:`32CD32`},{name:`Gold`,hex:`FFD700`},{name:`Silver`,hex:`C0C0C0`},{name:`Maroon`,hex:`800000`},{name:`Olive`,hex:`808000`},{name:`Coral`,hex:`FF7F50`},{name:`Salmon`,hex:`FA8072`},{name:`Turquoise`,hex:`40E0D0`},{name:`Violet`,hex:`EE82EE`},{name:`Indigo`,hex:`4B0082`},{name:`Chocolate`,hex:`D2691E`},{name:`Tan`,hex:`D2B48C`},{name:`Slate`,hex:`708090`},{name:`Charcoal`,hex:`36454F`},{name:`Ivory`,hex:`FFFFF0`},{name:`Cream`,hex:`FFFDD0`}];function rW(e){return ZOe[e.toLowerCase().trim()]||null}function QOe(e){let t=e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`).replace(/\s+/g,`\\s+`);return RegExp(`\\b${t}\\b`,`i`)}function iW(e,t){let n=e.indexOf(`@`);if(n>=0){let r=e.slice(n+1).trim(),i=r.match(/^BBL\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);if(i)return i[1].trim();let a=r.match(/^Bambu Lab\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);if(a){let e=a[1].trim(),n=`Bambu Lab ${e}`;if(t[n])return t[n];let r=n.toLowerCase();for(let[e,n]of Object.entries(t))if(e.toLowerCase()===r)return n;return e}}let r=[],i=new Set;for(let[e,n]of Object.entries(t)){let t=e.replace(/^Bambu Lab\s+/,``),a=t.toLowerCase();i.has(a)||(r.push({token:t,short:n}),i.add(a));let o=n.toLowerCase();i.has(o)||(r.push({token:n,short:n}),i.add(o))}r.sort((e,t)=>t.token.length-e.token.length);for(let{token:t,short:n}of r)if(QOe(t).test(e))return n;return null}function aW({isOpen:e,onClose:t,printerId:n,slotInfo:r,nozzleDiameter:i=`0.4`,printerModel:a,onSuccess:o,fullScreen:s}){let{t:c}=$e(),[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)(``),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),w=(0,y.useRef)(``),{data:T,isLoading:E,isError:D}=q({queryKey:[`cloudSettings`],queryFn:()=>Q.getCloudSettings(),enabled:e,retry:!1}),{data:O}=q({queryKey:[`orcaCloudProfilesForAmsSlot`],queryFn:()=>Q.orcaCloudListProfiles(),enabled:e,retry:!1}),{data:k,isLoading:A}=q({queryKey:[`localPresets`],queryFn:()=>Q.getLocalPresets(),enabled:e}),{data:j,isLoading:M}=q({queryKey:[`builtinFilaments`],queryFn:()=>Q.getBuiltinFilaments(),enabled:e,staleTime:1/0}),{data:N,isLoading:P}=q({queryKey:[`kprofiles`,n,i],queryFn:()=>Q.getKProfiles(n,i),enabled:e&&!!n}),{data:F}=q({queryKey:[`colorCatalog`],queryFn:()=>Q.getColorCatalog(),enabled:e,staleTime:1/0}),{data:I}=q({queryKey:[`slicerPrinterModels`],queryFn:Q.getSlicerPrinterModels,enabled:e,staleTime:1/0}),L=(0,y.useMemo)(()=>NU(I??{}),[I]),R=(0,y.useMemo)(()=>{if(!a||!I)return null;for(let[e,t]of Object.entries(I))if(t===a)return`${e.startsWith(`Bambu Lab `)?e:`Bambu Lab ${e}`} ${i} nozzle`;return null},[a,I,i]),z=J({mutationFn:async()=>{if(!l)throw Error(`No filament preset selected`);let e=l.startsWith(`local_`),t=l.startsWith(`builtin_`),a=l.startsWith(`orca_`)?l.replace(`orca_`,``):l,o=!e&&!t?O?.filament.find(e=>e.setting_id===a):void 0,s=!!o,c=o??null,u=e?parseInt(l.replace(`local_`,``),10):null,f=t?l.replace(`builtin_`,``):null,m=e?k?.filament.find(e=>e.id===u):null,h=t?j?.find(e=>e.filament_id===f):null,g=!e&&!t&&!s?T?.filament.find(e=>e.setting_id===l):null;if(!e&&!t&&!s&&!g)throw Error(`Selected preset not found`);if(e&&!m)throw Error(`Selected local preset not found`);if(t&&!h)throw Error(`Selected builtin preset not found`);if(s&&!c)throw Error(`Selected Orca Cloud preset not found`);let _=e?m.name:t?h.name:s?c.name:g.name,v=eW(_),y=d?.slot_id??-1,b=p||r.trayColor?.slice(0,6)||`FFFFFF`,x=_.replace(/@.+$/,``).trim(),S,C,w=v.material.toUpperCase(),E={PLA:`GFL99`,"PLA-CF":`GFL98`,"PLA SILK":`GFL96`,"PLA HIGH SPEED":`GFL95`,PETG:`GFG99`,"PETG HF":`GFG96`,"PETG-CF":`GFG98`,PCTG:`GFG97`,ABS:`GFB99`,ASA:`GFB98`,PC:`GFC99`,PA:`GFN99`,"PA-CF":`GFN98`,NYLON:`GFN99`,TPU:`GFU99`,PVA:`GFS99`,HIPS:`GFS98`,PE:`GFP99`,PP:`GFP97`};if(e){let e=($U.includes(w)?w:m?.filament_type||v.material||``).toUpperCase();S=E[e]||E[e.replace(/[-\s]?CF$/,``)]||E[e.replace(/\+$/,``)]||E[e.split(/[-\s]/)[0]]||``,C=``}else if(s){let e=($U.includes(w)?w:v.material||``).toUpperCase();S=E[e]||E[e.replace(/[-\s]?CF$/,``)]||E[e.replace(/\+$/,``)]||E[e.split(/[-\s]/)[0]]||``,C=``}else if(t)S=f,C=``;else if(S=QU(l),C=l,!l.startsWith(`GFS`))try{let e=await Q.getCloudSettingDetail(l);e.filament_id&&(S=e.filament_id)}catch(e){console.warn(`Failed to fetch preset detail for filament_id:`,e)}let D=e&&m?.nozzle_temp_min?m.nozzle_temp_min:190,A=e&&m?.nozzle_temp_max?m.nozzle_temp_max:230;if(!e||t||s||!m?.nozzle_temp_min&&!m?.nozzle_temp_max){let t=(e?$U.includes(w)?w:m?.filament_type||v.material||``:v.material).toUpperCase();t.includes(`PLA`)?(D=190,A=230):t.includes(`PETG`)?(D=220,A=260):t.includes(`ABS`)||t.includes(`ASA`)?(D=240,A=280):t.includes(`TPU`)?(D=200,A=240):t===`PCTG`?(D=220,A=260):t.includes(`PC`)?(D=260,A=300):(t.includes(`PA`)||t.includes(`NYLON`))&&(D=250,A=290)}let M=d?.k_value?parseFloat(d.k_value):0,N=e?$U.includes(w)?w:m?.filament_type||v.material||`PLA`:s&&$U.includes(w)?w:v.material||`PLA`,P=await Q.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:S,tray_type:N,tray_sub_brands:x,tray_color:b+`FF`,nozzle_temp_min:D,nozzle_temp_max:A,cali_idx:y,nozzle_diameter:i,setting_id:C,kprofile_filament_id:d?.filament_id,kprofile_setting_id:d?.setting_id||void 0,k_value:M}),F=e?`local_${u}`:t?`builtin_${f}`:l,I=e?`local`:t?`builtin`:s?`orca_cloud`:`cloud`;try{await Q.saveSlotPreset(n,r.amsId,r.trayId,F,x,I)}catch(e){console.warn(`Failed to save slot preset mapping:`,e)}return P},onSuccess:()=>{x(!0),o?.(),setTimeout(()=>{x(!1),t()},1500)}}),B=J({mutationFn:async()=>Q.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{x(!0),o?.(),setTimeout(()=>{x(!1),t()},1500)}}),V=(0,y.useMemo)(()=>{let e=_.toLowerCase(),t=[],n=new Set,i=r.savedPresetId,o=r.trayInfoIdx;if(O?.filament)for(let r of O.filament){let i=`orca_${r.setting_id}`;if(n.add(r.setting_id),n.add(i),!(e&&!r.name.toLowerCase().includes(e))){if(a){let e=iW(r.name,I??{});if(e&&!MU(e,a))continue}t.push({id:i,name:r.name,source:`orca_cloud`,isUser:!0})}}if(T?.filament)for(let r of T.filament){if(n.has(r.setting_id))continue;n.add(r.setting_id);let s=i===r.setting_id||o&&(r.setting_id===o||QU(r.setting_id)===o);if(!(e&&!r.name.toLowerCase().includes(e))){if(!s&&a){let e=iW(r.name,I??{});if(e&&!MU(e,a))continue}t.push({id:r.setting_id,name:r.name,source:`cloud`,isUser:XOe(r.setting_id)})}}if(k?.filament){let n=r.savedPresetId;for(let r of k.filament){let i=`local_${r.id}`;if(!(e&&!r.name.toLowerCase().includes(e))){if(n!==i&&R){let e=null;if(r.compatible_printers)try{let t=JSON.parse(r.compatible_printers);Array.isArray(t)&&(e=t.filter(e=>typeof e==`string`))}catch{e=null}if(IU({name:r.name,compatible_printers:e},`filament`,R,L)===`mismatch`)continue}t.push({id:i,name:r.name,source:`local`,isUser:!1})}}}if(j)for(let r of j){if(n.has(r.filament_id))continue;let i=r.filament_id.startsWith(`GF`)?`GFS`+r.filament_id.slice(2):r.filament_id;n.has(i)||(!e||r.name.toLowerCase().includes(e))&&t.push({id:`builtin_${r.filament_id}`,name:r.name,source:`builtin`,isUser:!1})}return t.sort((e,t)=>{let n={local:0,orca_cloud:1,cloud:2,builtin:3};return e.source===t.source?e.isUser&&!t.isUser?-1:!e.isUser&&t.isUser?1:e.name.localeCompare(t.name):n[e.source]-n[t.source]})},[O?.filament,T?.filament,k?.filament,j,_,a,r.savedPresetId,r.trayInfoIdx,R,L,I]),ee=(0,y.useMemo)(()=>{if(!l)return null;let e=null,t=``;if(l.startsWith(`local_`)){let t=parseInt(l.replace(`local_`,``),10);e=k?.filament.find(e=>e.id===t)?.name||null}else if(l.startsWith(`builtin_`)){let n=l.replace(`builtin_`,``);e=j?.find(e=>e.filament_id===n)?.name||null,t=YU(n)}else{let n=l.startsWith(`orca_`)?l.replace(`orca_`,``):l,r=O?.filament.find(e=>e.setting_id===n);if(r)e=r.name;else if(T?.filament){let n=T.filament.find(e=>e.setting_id===l);e=n?.name||null,n&&(t=YU(n.setting_id))}}if(!e)return null;let n=e.replace(/@.+$/,``).trim();n.startsWith(`# `)&&(n=n.slice(2).trim());let r=eW(n);return{fullName:n,material:r.material,brand:r.brand,filamentId:t}},[l,T?.filament,k?.filament,j,O?.filament]),te=ee?.fullName||``,H=(0,y.useMemo)(()=>{if(!F||!ee)return[];let{fullName:e,brand:t}=ee,n=e.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,``).trim();return F.filter(e=>{let r=(e.material||``).toUpperCase(),i=e.manufacturer.toUpperCase();if(!(r===n.toUpperCase()||r.includes(n.toUpperCase())||n.toUpperCase().includes(r)))return!1;if(t){let e=t.toUpperCase();if(!i.includes(e)&&!e.includes(i))return!1}return!0})},[F,ee]),ne=(0,y.useMemo)(()=>{if(!N?.profiles)return[];if(!ee){let e=r.caliIdx;if(e!=null&&e>0){let t=N.profiles.find(t=>t.slot_id===e&&(r.extruderId===void 0||t.extruder_id===r.extruderId));if(t)return[t]}return[]}let{fullName:e,material:t,brand:n,filamentId:i}=ee,a=e.toUpperCase(),o=t.toUpperCase(),s=n.toUpperCase(),c=i;if(!o||o.length<2)return[];let l=N.profiles.filter(e=>{if(c){let t=YU(e.filament_id);if(t&&t===c&&!XU(t))return!0}let t=e.name.toUpperCase();if(s)return!(!t.includes(s)||!t.includes(o));if(t.includes(a)||t.includes(o))return!0;let n={NYLON:[`PA`,`PA-CF`,`PA6`],PA:[`NYLON`]}[o]||[];for(let e of n)if(t.includes(e))return!0;return!1}),u=new Map;for(let e of l){let t=`${e.name}|${e.k_value}`,n=u.get(t);n?r.extruderId!==void 0&&e.extruder_id===r.extruderId&&n.extruder_id!==r.extruderId&&u.set(t,e):u.set(t,e)}let d=Array.from(u.values()),f=r.caliIdx;if(f!=null&&f>0&&!d.some(e=>e.slot_id===f)){let e=N.profiles.find(e=>e.slot_id===f&&(r.extruderId===void 0||e.extruder_id===r.extruderId));e&&d.unshift(e)}return d},[N?.profiles,ee,r.extruderId,r.caliIdx]);(0,y.useEffect)(()=>{if(e){if(r.savedPresetId)u(r.savedPresetId);else if(r.trayInfoIdx&&T?.filament){let e=T.filament.find(e=>e.setting_id===r.trayInfoIdx);e||=T.filament.find(e=>QU(e.setting_id)===r.trayInfoIdx),e&&u(e.setting_id)}else if(r.trayInfoIdx&&j?.length){let e=r.trayInfoIdx,t=j.find(t=>t.filament_id===e);t&&u(`builtin_${t.filament_id}`)}if(r.trayColor){let e=r.trayColor.slice(0,6);e&&m(e)}}else u(``),f(null),m(``),g(``),v(``),x(!1),w.current=``},[e,r.savedPresetId,r.trayInfoIdx,r.trayColor,T?.filament,j]),(0,y.useEffect)(()=>{if(ne.length>0){if(r.caliIdx!=null&&r.caliIdx>0){let e=ne.find(e=>e.slot_id===r.caliIdx);if(e){f(e);return}}f(ne[0])}else f(null)},[l,ne,r.caliIdx]);let re=(0,y.useCallback)(e=>{e.key===`Escape`&&t()},[t]);(0,y.useEffect)(()=>{if(e)return document.addEventListener(`keydown`,re),()=>document.removeEventListener(`keydown`,re)},[e,re]);let U=E&&!D||A||M||P;if((0,y.useEffect)(()=>{if(!U&&l&&l!==w.current){let e=requestAnimationFrame(()=>{let e=document.querySelector(`[class*="fixed inset-0 z-50"]`)?.querySelector(`[data-preset-id="${CSS.escape(l)}"]`);e&&(w.current=l,e.scrollIntoView({block:`nearest`}))});return()=>cancelAnimationFrame(e)}},[l,U]),!e)return null;let ie=l&&!z.isPending,ae=p||r.trayColor?.slice(0,6)||`FFFFFF`;return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex ${s?``:`items-center justify-center`}`,children:[!s&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,K.jsxs)(`div`,{className:s?`relative w-full h-full bg-bambu-dark-secondary flex flex-col`:`relative w-full max-w-lg mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl`,children:[(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)(Hl,{className:`w-5 h-5 text-bambu-blue`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:c(`configureAmsSlot.title`)}),s&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 ml-4 text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`text-white/30`,children:`|`}),r.trayColor&&(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),(0,K.jsx)(`span`,{className:`text-white/70`,children:c(`configureAmsSlot.slotLabel`,{ams:jf(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&(0,K.jsxs)(`span`,{children:[`(`,r.traySubBrands,`)`]})]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(Bu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 overflow-y-auto ${s?`flex-1 min-h-0`:`space-y-4 max-h-[60vh]`}`,children:[b&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl`,children:(0,K.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,K.jsx)(ps,{className:`w-16 h-16 text-bambu-green mx-auto`}),(0,K.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:c(`configureAmsSlot.slotConfigured`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:c(`configureAmsSlot.settingsSentToPrinter`)})]})}),!s&&(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:c(`configureAmsSlot.configuringSlot`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r.trayColor&&(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:c(`configureAmsSlot.slotLabel`,{ams:jf(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,r.traySubBrands,`)`]})]})]}),U?(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`})}):s?(0,K.jsxs)(`div`,{className:`flex gap-4 h-full`,children:[(0,K.jsxs)(`div`,{className:`w-1/2 flex flex-col min-h-0`,children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[c(`configureAmsSlot.filamentProfile`),` `,(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsx)(`input`,{type:`text`,placeholder:c(`configureAmsSlot.searchPresets`),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 placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2 shrink-0`}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto space-y-1`,children:V.length===0?(0,K.jsx)(`p`,{className:`text-center py-4 text-bambu-gray`,children:T?.filament?.length===0&&!k?.filament?.length?c(`configureAmsSlot.noPresetsAvailable`):c(`configureAmsSlot.noMatchingPresets`)}):V.map(e=>(0,K.jsx)(`button`,{"data-preset-id":e.id,onClick:()=>u(e.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${l===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all`,title:e.name,children:e.name}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[e.source===`local`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400`,children:c(`profiles.localProfiles.badge`)}),e.source===`orca_cloud`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-purple-500/20 text-purple-400`,children:c(`configureAmsSlot.orcaCloud`)}),e.source===`cloud`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue`,children:c(`configureAmsSlot.bambuCloud`)}),e.source===`builtin`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400`,children:c(`configureAmsSlot.builtin`)})]})]})},e.id))})]}),(0,K.jsxs)(`div`,{className:`w-1/2 flex flex-col gap-4 min-h-0 overflow-y-auto`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[c(`configureAmsSlot.kProfileLabel`),te&&(0,K.jsx)(`span`,{className:`ml-2 text-xs text-bambu-blue`,children:c(`configureAmsSlot.filteringFor`,{material:te})})]}),ne.length>0?(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:d?.name||``,onChange:e=>{f(ne.find(t=>t.name===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 appearance-none pr-10`,children:[(0,K.jsx)(`option`,{value:``,children:c(`configureAmsSlot.noKProfile`)}),ne.map(e=>(0,K.jsxs)(`option`,{value:e.name,children:[e.name,` (K=`,e.k_value,`)`]},`${e.name}-${e.extruder_id}`))]}),(0,K.jsx)(rs,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}):l?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:c(`configureAmsSlot.noMatchingKProfiles`)}):(0,K.jsx)(`span`,{className:`inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30`,children:c(`configureAmsSlot.selectFilamentFirst`)}),d&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-green mt-1`,children:c(`configureAmsSlot.kFromCalibration`,{value:d.k_value})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:c(`configureAmsSlot.customColorLabel`)}),H.length>0&&(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1.5`,children:c(`configureAmsSlot.presetColors`,{name:ee?.fullName})}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:H.map(e=>(0,K.jsxs)(`button`,{onClick:()=>{m(e.hex_color.replace(`#`,``).toUpperCase()),g(e.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${p===e.hex_color.replace(`#`,``).toUpperCase()?`border-bambu-green scale-105`:`border-white/20 hover:border-white/40`}`,title:e.color_name,children:[(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.hex_color}}),(0,K.jsx)(`span`,{className:`text-xs text-white/80 whitespace-nowrap`,children:e.color_name})]},e.id))})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:[tW.map(e=>(0,K.jsx)(`button`,{onClick:()=>{m(e.hex),g(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex)),(0,K.jsx)(`button`,{onClick:()=>C(!S),className:`w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs`,title:c(S?`configureAmsSlot.showLessColors`:`configureAmsSlot.showMoreColors`),children:S?`−`:`+`})]}),S&&(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:nW.map(e=>(0,K.jsx)(`button`,{onClick:()=>{m(e.hex),g(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex))}),(0,K.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0`,style:{backgroundColor:`#${ae}`}}),(0,K.jsx)(`input`,{type:`text`,placeholder:c(`configureAmsSlot.colorPlaceholder`),value:h,onChange:e=>{let t=e.target.value;g(t);let n=rW(t);if(n)m(n);else{let e=t.replace(/[^0-9A-Fa-f]/g,``).toUpperCase();e.length===6?m(e):e.length===3&&m(e.split(``).map(e=>e+e).join(``))}},className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm`}),p&&(0,K.jsx)(`button`,{onClick:()=>{m(``),g(``)},className:`px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded`,title:c(`configureAmsSlot.clearCustomColor`),children:c(`configureAmsSlot.clear`)})]}),p&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5`,children:c(`configureAmsSlot.hexLabel`,{hex:p})})]})]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[c(`configureAmsSlot.filamentProfile`),` `,(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{type:`text`,placeholder:c(`configureAmsSlot.searchPresets`),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 placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2`}),(0,K.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:V.length===0?(0,K.jsx)(`p`,{className:`text-center py-4 text-bambu-gray`,children:T?.filament?.length===0&&!k?.filament?.length?c(`configureAmsSlot.noPresetsAvailable`):c(`configureAmsSlot.noMatchingPresets`)}):V.map(e=>(0,K.jsx)(`button`,{"data-preset-id":e.id,onClick:()=>u(e.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${l===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all`,title:e.name,children:e.name}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[e.source===`local`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400`,children:c(`profiles.localProfiles.badge`)}),e.source===`orca_cloud`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-purple-500/20 text-purple-400`,children:c(`configureAmsSlot.orcaCloud`)}),e.source===`cloud`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue`,children:c(`configureAmsSlot.bambuCloud`)}),e.source===`builtin`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400`,children:c(`configureAmsSlot.builtin`)})]})]})},e.id))})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[c(`configureAmsSlot.kProfileLabel`),te&&(0,K.jsx)(`span`,{className:`ml-2 text-xs text-bambu-blue`,children:c(`configureAmsSlot.filteringFor`,{material:te})})]}),ne.length>0?(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:d?.name||``,onChange:e=>{f(ne.find(t=>t.name===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 appearance-none pr-10`,children:[(0,K.jsx)(`option`,{value:``,children:c(`configureAmsSlot.noKProfile`)}),ne.map(e=>(0,K.jsxs)(`option`,{value:e.name,children:[e.name,` (K=`,e.k_value,`)`]},`${e.name}-${e.extruder_id}`))]}),(0,K.jsx)(rs,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}):l?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:c(`configureAmsSlot.noMatchingKProfiles`)}):(0,K.jsx)(`span`,{className:`inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30`,children:c(`configureAmsSlot.selectFilamentFirst`)}),d&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-green mt-1`,children:c(`configureAmsSlot.kFromCalibration`,{value:d.k_value})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:c(`configureAmsSlot.customColorLabel`)}),H.length>0&&(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1.5`,children:c(`configureAmsSlot.presetColors`,{name:ee?.fullName})}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:H.map(e=>(0,K.jsxs)(`button`,{onClick:()=>{m(e.hex_color.replace(`#`,``).toUpperCase()),g(e.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${p===e.hex_color.replace(`#`,``).toUpperCase()?`border-bambu-green scale-105`:`border-white/20 hover:border-white/40`}`,title:e.color_name,children:[(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.hex_color}}),(0,K.jsx)(`span`,{className:`text-xs text-white/80 whitespace-nowrap`,children:e.color_name})]},e.id))})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:[tW.map(e=>(0,K.jsx)(`button`,{onClick:()=>{m(e.hex),g(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex)),(0,K.jsx)(`button`,{onClick:()=>C(!S),className:`w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs`,title:c(S?`configureAmsSlot.showLessColors`:`configureAmsSlot.showMoreColors`),children:S?`−`:`+`})]}),S&&(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:nW.map(e=>(0,K.jsx)(`button`,{onClick:()=>{m(e.hex),g(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex))}),(0,K.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0`,style:{backgroundColor:`#${ae}`}}),(0,K.jsx)(`input`,{type:`text`,placeholder:c(`configureAmsSlot.colorPlaceholder`),value:h,onChange:e=>{let t=e.target.value;g(t);let n=rW(t);if(n)m(n);else{let e=t.replace(/[^0-9A-Fa-f]/g,``).toUpperCase();e.length===6?m(e):e.length===3&&m(e.split(``).map(e=>e+e).join(``))}},className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm`}),p&&(0,K.jsx)(`button`,{onClick:()=>{m(``),g(``)},className:`px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded`,title:c(`configureAmsSlot.clearCustomColor`),children:c(`configureAmsSlot.clear`)})]}),p&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5`,children:c(`configureAmsSlot.hexLabel`,{hex:p})})]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>B.mutate(),disabled:B.isPending||z.isPending,className:`text-red-400 hover:text-red-300 hover:bg-red-500/10`,children:B.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),c(`configureAmsSlot.resetting`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Al,{className:`w-4 h-4`}),c(`configureAmsSlot.resetSlot`)]})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,children:c(`configureAmsSlot.cancel`)}),(0,K.jsx)($,{onClick:()=>z.mutate(),disabled:!ie,children:z.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),c(`configureAmsSlot.configuring`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Hl,{className:`w-4 h-4`}),c(`configureAmsSlot.configureSlot`)]})})]})]}),(z.isError||B.isError)&&(0,K.jsx)(`div`,{className:`mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400`,children:z.error?.message||B.error?.message})]})]})}function oW({className:e=`w-4 h-4`}){return(0,K.jsx)(`svg`,{viewBox:`0 0 1945 1370`,fill:`none`,className:e,"aria-hidden":`true`,children:(0,K.jsxs)(`g`,{transform:`translate(-754.293 -471.685)`,children:[(0,K.jsxs)(`g`,{transform:`translate(0.18191 255.976)`,children:[(0,K.jsx)(`g`,{transform:`matrix(1.05469 0 0 0.241063 -153.484 1120.2)`,children:(0,K.jsx)(`rect`,{x:`922.048`,y:`1195.15`,width:`1721.5`,height:`470.135`,stroke:`currentColor`,strokeOpacity:`0.99`,strokeWidth:`168.84`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,K.jsx)(`g`,{transform:`matrix(0.983656 0 0 1.0767 -62.2035 141.539)`,children:(0,K.jsx)(`path`,{d:`M2741.42,1175.93L895.832,1175.93L1125.16,621.902L2512.09,621.902L2741.42,1175.93Z`,fill:`currentColor`,fillOpacity:`0.05`,stroke:`currentColor`,strokeOpacity:`0.99`,strokeWidth:`125.26`,strokeLinecap:`round`,strokeLinejoin:`round`})})]}),(0,K.jsx)(`g`,{transform:`translate(21.1916 0.684817)`,children:(0,K.jsx)(`path`,{d:`M1981.31,567.518C1954.86,567.518 1933.39,546.047 1933.39,519.601C1933.39,493.156 1954.86,471.685 1981.31,471.685L2146.61,471.685C2173.07,471.685 2194.53,493.138 2194.53,519.601L2194.53,688.741C2194.53,715.187 2173.05,736.658 2146.61,736.658C2120.16,736.658 2098.69,715.187 2098.69,688.741L2098.69,567.518L1981.31,567.518ZM2098.69,1252.54C2098.69,1226.1 2120.16,1204.62 2146.61,1204.62C2173.05,1204.62 2194.53,1226.1 2194.53,1252.54L2194.53,1421.68C2194.53,1448.14 2173.07,1469.6 2146.61,1469.6L1981.31,1469.6C1954.86,1469.6 1933.39,1448.13 1933.39,1421.68C1933.39,1395.24 1954.86,1373.76 1981.31,1373.76L2098.69,1373.76L2098.69,1252.54ZM1430.29,1373.76C1456.74,1373.76 1478.21,1395.24 1478.21,1421.68C1478.21,1448.13 1456.74,1469.6 1430.29,1469.6L1264.99,1469.6C1238.53,1469.6 1217.07,1448.14 1217.07,1421.68L1217.07,1252.54C1217.07,1226.1 1238.55,1204.62 1264.99,1204.62C1291.44,1204.62 1312.91,1226.1 1312.91,1252.54L1312.91,1373.76L1430.29,1373.76ZM1312.91,688.741C1312.91,715.187 1291.44,736.658 1264.99,736.658C1238.55,736.658 1217.07,715.187 1217.07,688.741L1217.07,519.601C1217.07,493.138 1238.53,471.685 1264.99,471.685L1430.29,471.685C1456.74,471.685 1478.21,493.156 1478.21,519.601C1478.21,546.047 1456.74,567.518 1430.29,567.518L1312.91,567.518L1312.91,688.741Z`,fill:`currentColor`,fillOpacity:`0.99`})})]})})}function sW({folderId:e,onClose:t,onUploadComplete:n,onFileUploaded:r,autoUpload:i,validateFile:a,accept:o,initialFiles:s}){let{t:c}=$e(),[l,u]=(0,y.useState)([]),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!0),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!0),[S,C]=(0,y.useState)(null),w=(0,y.useRef)(null),T=e=>{e.preventDefault(),f(!0)},E=e=>{e.preventDefault(),f(!1)},D=e=>{e.preventDefault(),f(!1),j(Array.from(e.dataTransfer.files))},O=e=>{e.target.files&&j(Array.from(e.target.files))},k=(e,t)=>{u(n=>n.map(n=>n.file===e?{...n,...t}:n))},A=async i=>{m(!0);for(let t of i)if(t.status===`pending`){k(t.file,{status:`uploading`});try{if(t.isZip){let n=await Q.extractZipFile(t.file,e,h,_,b);k(t.file,{status:n.errors.length>0&&n.extracted===0?`error`:`success`,extractedCount:n.extracted,error:n.errors.length>0?c(`fileManager.zipFilesFailed`,`{{count}} files failed`,{count:n.errors.length}):void 0})}else{let n=await Q.uploadLibraryFile(t.file,e,b);k(t.file,{status:`success`});let i=r?.(n);if(i){C(i),u([]),m(!1);return}}}catch(e){k(t.file,{status:`error`,error:e instanceof Error?e.message:c(`fileManager.uploadFailed`,`Upload failed`)})}}m(!1),n(),u(e=>(e.some(e=>e.status===`error`)||t(),e))},j=e=>{if(C(null),a)for(let t of e){let e=a(t);if(e){C(e);return}}let t=e.map(e=>({file:e,status:`pending`,isZip:e.name.toLowerCase().endsWith(`.zip`),is3mf:e.name.toLowerCase().endsWith(`.3mf`)}));u(e=>[...e,...t]),i&&e.length>0&&A(t)},M=e=>{u(t=>t.filter((t,n)=>n!==e))},N=(0,y.useRef)(!1);(0,y.useEffect)(()=>{N.current||!s||s.length===0||(N.current=!0,j(s))},[]);let P=l.some(e=>e.isZip&&e.status===`pending`),F=l.some(e=>e.file.name.toLowerCase().endsWith(`.stl`)&&e.status===`pending`),I=l.some(e=>e.is3mf&&e.status===`pending`),L=l.filter(e=>e.status===`pending`).length,R=l.length>0&&L===0&&!p;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-lg 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.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:c(`fileManager.uploadFiles`)}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,K.jsx)(Bu,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,K.jsxs)(`div`,{onDragOver:T,onDragLeave:E,onDrop:D,onClick:()=>w.current?.click(),className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${d?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,children:[(0,K.jsx)(Du,{className:`w-10 h-10 mx-auto mb-3 ${d?`text-bambu-green`:`text-bambu-gray`}`}),(0,K.jsx)(`p`,{className:`text-white font-medium`,children:c(d?`fileManager.dropFilesHere`:`fileManager.dragDropFiles`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:c(`fileManager.orClickToBrowse`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-2`,children:c(`fileManager.allFileTypesSupported`)})]}),(0,K.jsx)(`input`,{ref:w,type:`file`,multiple:!0,accept:o,className:`hidden`,onChange:O}),P&&(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 items-start gap-3`,children:[(0,K.jsx)(Oo,{className:`w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-blue-300 font-medium`,children:c(`fileManager.zipFilesDetected`)}),(0,K.jsx)(`p`,{className:`text-xs text-blue-300/70 mt-1`,children:c(`fileManager.zipExtractOptions`)}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 mt-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`w-4 h-4 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:c(`fileManager.preserveZipStructure`)})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 mt-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`w-4 h-4 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:c(`fileManager.createFolderFromZip`)})]})]})]})}),I&&(0,K.jsx)(`div`,{className:`p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(Tl,{className:`w-5 h-5 text-purple-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-purple-300 font-medium`,children:c(`fileManager.threemfDetected`)}),(0,K.jsx)(`p`,{className:`text-xs text-purple-300/70 mt-1`,children:c(`fileManager.threemfExtractionInfo`)})]})]})}),(F||P)&&(0,K.jsx)(`div`,{className:`p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(jc,{className:`w-5 h-5 text-bambu-green mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-green font-medium`,children:c(`fileManager.stlThumbnailGeneration`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-green/70 mt-1`,children:c(P&&!F?`fileManager.zipMayContainStl`:`fileManager.thumbnailsCanBeGenerated`)}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 mt-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>x(e.target.checked),className:`w-4 h-4 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:c(`fileManager.generateThumbnailsForStl`)})]})]})]})}),l.length>0&&(0,K.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-2`,children:l.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-2 bg-bambu-dark rounded-lg`,children:[e.isZip?(0,K.jsx)(Oo,{className:`w-4 h-4 text-blue-400 flex-shrink-0`}):(0,K.jsx)(nc,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.file.name}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[(e.file.size/1024/1024).toFixed(2),` MB`,e.isZip&&e.status===`pending`&&(0,K.jsxs)(`span`,{className:`text-blue-400 ml-2`,children:[`• `,c(`fileManager.willBeExtracted`)]}),e.extractedCount!==void 0&&(0,K.jsxs)(`span`,{className:`text-green-400 ml-2`,children:[`• `,c(`fileManager.filesExtracted`,{count:e.extractedCount})]})]}),e.status===`error`&&e.error&&(0,K.jsx)(`p`,{className:`text-xs text-red-400 mt-1 break-words`,children:e.error})]}),e.status===`pending`&&(0,K.jsx)(`button`,{onClick:()=>M(t),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,K.jsx)(Bu,{className:`w-4 h-4 text-bambu-gray`})}),e.status===`uploading`&&(0,K.jsx)(X,{className:`w-4 h-4 text-bambu-green animate-spin`}),e.status===`success`&&(0,K.jsx)(fs,{className:`w-4 h-4 text-green-500`}),e.status===`error`&&(0,K.jsx)(`span`,{title:e.error,children:(0,K.jsx)(vs,{className:`w-4 h-4 text-red-500`})})]},t))}),S&&(0,K.jsx)(`div`,{className:`p-3 bg-red-500/10 border border-red-500/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(vs,{className:`w-5 h-5 text-red-400 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`p`,{className:`text-sm text-red-300`,children:S})]})})]}),(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:t,children:c(`common.cancel`)}),!R&&(0,K.jsx)($,{onClick:()=>A(l),disabled:L===0||p,children:p?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 mr-2 animate-spin`}),c(`fileManager.uploading`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Du,{className:`w-4 h-4 mr-2`}),c(`common.upload`),` `,L>0?`(${L})`:``]})})]})]})})}function cW(e){let t=[],n=e?.ams_extruder_map,r=!!e?.nozzles?.[1]?.nozzle_diameter||n&&Object.keys(n).length>0||(e?.vt_tray?.length??0)>1;e?.ams?.forEach(e=>{let r=e.tray.length===1;e.tray.forEach(i=>{if(i.tray_type){let a=kf(i.tray_color);t.push({type:i.tray_type,color:a,colorName:Kd(a),amsId:e.id,trayId:i.id,isHt:r,isExternal:!1,label:Lf(e.id,i.id,r,!1),globalTrayId:Rf(e.id,i.id,!1),trayInfoIdx:i.tray_info_idx||``,traySubBrands:i.tray_sub_brands||``,extruderId:n?.[String(e.id)],remain:i.remain??-1})}})});for(let n of e?.vt_tray??[])if(n.tray_type){let i=kf(n.tray_color),a=n.id??254,o=(e?.vt_tray?.length??0)>1;t.push({type:n.tray_type,color:i,colorName:Kd(i),amsId:-1,trayId:a-254,isHt:!1,isExternal:!0,label:o?a===254?`Ext-L`:`Ext-R`:`External`,globalTrayId:a,trayInfoIdx:n.tray_info_idx||``,traySubBrands:n.tray_sub_brands||``,extruderId:r?255-a:void 0,remain:n.remain??-1})}return t}function lW(e,t,n,r){if(!e?.filaments||e.filaments.length===0)return;let i=cW(t);if(i.length===0)return;let a=t?.fila_switch?.installed===!0,o=new Set,s=e.filaments.map(e=>{let t=e.tray_info_idx||``,s=i.filter(e=>!o.has(e.globalTrayId));e.nozzle_id!=null&&!a&&(s=s.filter(t=>t.extruderId===e.nozzle_id)),n&&(s=[...s].sort((e,t)=>qf(Kf(e,r),Kf(t,r))));let c,l,u,d;if(t){let i=s.filter(e=>e.trayInfoIdx===t);i.length===1?c=i[0]:i.length>1&&(n&&i.sort((e,t)=>qf(Kf(e,r),Kf(t,r))),l=i.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&Af(t.color)===Af(e.color)),l||(u=i.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&If(t.color,e.color))),!l&&!u&&(d=i.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase())))}!c&&!l&&!u&&!d&&(l=s.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&Af(t.color)===Af(e.color)),l||(u=s.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&If(t.color,e.color))),!l&&!u&&(d=s.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase())));let f=c||l||u||d||void 0;return f&&o.add(f.globalTrayId),{slot_id:e.slot_id,globalTrayId:f?.globalTrayId??-1}}),c=Math.max(...s.map(e=>e.slot_id||0));if(c<=0)return;let l=Array(c).fill(-1);return s.forEach(e=>{e.slot_id&&e.slot_id>0&&(l[e.slot_id-1]=e.globalTrayId)}),l}function $Oe(e){return(0,y.useMemo)(()=>cW(e),[e])}function uW(e,t,n,r,i){let a=$Oe(t),o=t?.fila_switch?.installed===!0,s=(0,y.useMemo)(()=>{if(!e?.filaments||e.filaments.length===0)return[];let t=new Set(Object.values(n));return e.filaments.map(e=>{let s=e.slot_id||0;if(s>0&&n[s]!==void 0){let t=n[s],r=a.find(e=>e.globalTrayId===t);if(r){let t=r.type?.toUpperCase()===e.type?.toUpperCase(),n=Af(r.color)===Af(e.color)||If(r.color,e.color),i;return i=t&&n?`match`:t?`type_only`:`mismatch`,{...e,loaded:r,hasFilament:!0,typeMatch:t,colorMatch:n,status:i,isManual:!0}}}let c=e.tray_info_idx||``,l=a.filter(e=>!t.has(e.globalTrayId));e.nozzle_id!=null&&!o&&(l=l.filter(t=>t.extruderId===e.nozzle_id)),r&&(l=[...l].sort((e,t)=>qf(Kf(e,i),Kf(t,i))));let u,d,f,p;if(c){let t=l.filter(e=>e.trayInfoIdx===c);t.length===1?u=t[0]:t.length>1&&(r&&t.sort((e,t)=>qf(Kf(e,i),Kf(t,i))),d=t.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&Af(t.color)===Af(e.color)),d||(f=t.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&If(t.color,e.color))),!d&&!f&&(p=t.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase())))}!u&&!d&&!f&&!p&&(d=l.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&Af(t.color)===Af(e.color)),d||(f=l.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&If(t.color,e.color))),!d&&!f&&(p=l.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase())));let m=u||d||f||p||void 0;m&&t.add(m.globalTrayId);let h=!!m,g=h,_=!!u||!!d||!!f,v;return v=u||d||f?`match`:p?`type_only`:`mismatch`,{...e,loaded:m,hasFilament:h,typeMatch:g,colorMatch:_,status:v,isManual:!1}})},[e,a,n,r,o,i]);return{loadedFilaments:a,filamentComparison:s,amsMapping:(0,y.useMemo)(()=>{if(s.length===0)return;let e=Math.max(...s.map(e=>e.slot_id||0));if(e<=0)return;let t=Array(e).fill(-1);return s.forEach(e=>{e.slot_id&&e.slot_id>0&&(t[e.slot_id-1]=e.loaded?.globalTrayId??-1)}),t},[s]),hasTypeMismatch:s.some(e=>e.status===`mismatch`),hasColorMismatch:s.some(e=>e.status===`type_only`)}}function eke(e,t,n,r,i){if(!e||e.length===0)return{exactMatches:0,typeOnlyMatches:0,missingTypes:0,totalSlots:0,status:`full`};let a=0,o=0,s=0,c=new Set(Object.values(n));for(let l of e){let e=l.slot_id||0;if(e>0&&n[e]!==void 0){let r=n[e],i=t.find(e=>e.globalTrayId===r);if(i){let e=i.type?.toUpperCase()===l.type?.toUpperCase(),t=Af(i.color)===Af(l.color)||If(i.color,l.color);e&&t?a++:e?o++:s++;continue}}let u=t.filter(e=>!c.has(e.globalTrayId));if(l.nozzle_id!=null){let e=u.filter(e=>e.extruderId===l.nozzle_id);e.length>0&&(u=e)}r&&(u=[...u].sort((e,t)=>qf(Kf(e,i),Kf(t,i))));let d=u.find(e=>e.type?.toUpperCase()===l.type?.toUpperCase()&&Af(e.color)===Af(l.color)),f=d?void 0:u.find(e=>e.type?.toUpperCase()===l.type?.toUpperCase()&&If(e.color,l.color)),p=d||f?void 0:u.find(e=>e.type?.toUpperCase()===l.type?.toUpperCase()),m=d??f??p;m&&c.add(m.globalTrayId),d||f?a++:p?o++:s++}let l=e.length,u=`full`;return s>0?u=`missing`:o>0&&(u=`partial`),{exactMatches:a,typeOnlyMatches:o,missingTypes:s,totalSlots:l,status:u}}function tke(e,t,n,r,i){if(!e?.filaments||e.filaments.length===0)return;let a=cW(t);if(a.length===0)return;let o=new Set(Object.values(n)),s=[];for(let t of e.filaments){let e=t.slot_id||0;if(e>0&&n[e]!==void 0){s.push({slot_id:e,globalTrayId:n[e]});continue}let c=a.filter(e=>!o.has(e.globalTrayId));if(t.nozzle_id!=null){let e=c.filter(e=>e.extruderId===t.nozzle_id);e.length>0&&(c=e)}r&&(c=[...c].sort((e,t)=>qf(Kf(e,i),Kf(t,i))));let l=c.find(e=>e.type?.toUpperCase()===t.type?.toUpperCase()&&Af(e.color)===Af(t.color)),u=l?void 0:c.find(e=>e.type?.toUpperCase()===t.type?.toUpperCase()&&If(e.color,t.color)),d=l||u?void 0:c.find(e=>e.type?.toUpperCase()===t.type?.toUpperCase()),f=l??u??d;f&&o.add(f.globalTrayId),s.push({slot_id:e,globalTrayId:f?.globalTrayId??-1})}let c=Math.max(...s.map(e=>e.slot_id||0));if(c<=0)return;let l=Array(c).fill(-1);return s.forEach(e=>{e.slot_id&&e.slot_id>0&&(l[e.slot_id-1]=e.globalTrayId)}),l}var dW={useDefault:!0,manualMappings:{},autoConfigured:!1};function nke(e,t,n,r,i,a,o,s){let c=_o({queries:e.map(t=>({queryKey:[`printer-status`,t],queryFn:()=>Q.getPrinterStatus(t),enabled:e.length>0,staleTime:5e3}))}),l=(0,y.useMemo)(()=>e.map((e,a)=>{let l=c[a],u=l?.data,d=t?.find(t=>t.id===e)?.name||`Printer ${e}`,f=cW(u),p=i[e]||dW,m=s?.get(e),h=Jf(o,u?.ams_filament_backup),g=lW(n,u,h,m),_=p.useDefault?r:p.manualMappings,v=tke(n,u,_,h,m),y=eke(n?.filaments,f,_,h,m);return{printerId:e,printerName:d,status:u,isLoading:l?.isLoading??!1,loadedFilaments:f,autoMapping:g,finalMapping:v,matchStatus:y.status,exactMatches:y.exactMatches,typeOnlyMatches:y.typeOnlyMatches,missingTypes:y.missingTypes,totalSlots:y.totalSlots,config:p,inventoryByTrayId:m}}),[e,c,t,n,i,r,o,s]),u=c.some(e=>e.isLoading),d=(e,t)=>{a(n=>({...n,[e]:{...n[e]||dW,...t}}))},f=e=>{let t=l.find(t=>t.printerId===e);if(!t||!t.status||!n?.filaments)return;let r=lW(n,t.status,Jf(o,t.status?.ams_filament_backup),s?.get(e));if(!r)return;let i={};r.forEach((e,t)=>{e!==-1&&(i[t+1]=e)}),d(e,{useDefault:!1,manualMappings:i,autoConfigured:!0})};return{printerResults:l,isLoading:u,perPrinterConfigs:i,updatePrinterConfig:d,autoConfigureAll:()=>{for(let t of e)f(t)},autoConfigurePrinter:f,getFinalMapping:e=>l.find(t=>t.printerId===e)?.finalMapping,allPrintersReady:l.every(e=>e.matchStatus!==`missing`)}}var fW=`/img/bed`,rke={"cool plate":{icon:`${fW}/bed_cool.png`,label:`Cool Plate`},"pc plate":{icon:`${fW}/bed_cool.png`,label:`Cool Plate`},"cool plate (supertack)":{icon:`${fW}/bed_cool_supertack.png`,label:`Cool Plate SuperTack`},"supertack plate":{icon:`${fW}/bed_cool_supertack.png`,label:`Cool Plate SuperTack`},"bambu cool plate supertack":{icon:`${fW}/bed_cool_supertack.png`,label:`Cool Plate SuperTack`},"engineering plate":{icon:`${fW}/bed_engineering.png`,label:`Engineering Plate`},"high temp plate":{icon:`${fW}/bed_high_templ.png`,label:`High Temp Plate`},"textured pei plate":{icon:`${fW}/bed_pei.png`,label:`Textured PEI Plate`},"pei plate":{icon:`${fW}/bed_pei.png`,label:`PEI Plate`},"smooth pei plate":{icon:`${fW}/bed_pei_cool.png`,label:`Smooth PEI Plate`}};function pW(e){return e?rke[e.trim().toLowerCase()]??null:null}function ike(e){let t=e.trim().split(/\s+/);return t.length<=1?e.trim():t.slice(1).join(` `)}function mW(e){let{data:t}=q({queryKey:[`builtin-filaments`],queryFn:()=>Q.getBuiltinFilaments(),staleTime:300*1e3}),{data:n}=q({queryKey:[`filament-id-map`],queryFn:()=>Q.getFilamentIdMap(),staleTime:300*1e3}),r=(0,y.useMemo)(()=>{let e={};for(let n of t||[])n.filament_id&&(e[n.filament_id]=n.name);for(let[t,r]of Object.entries(n||{}))t&&r&&(e[t]=r);return e},[t,n]),i=(0,y.useMemo)(()=>(e||[]).map(e=>{let t=e.tray_info_idx&&r[e.tray_info_idx]||e.type;return{resolvedName:t,materialHint:ike(t),color:e.color}}),[e,r]),a=_o({queries:i.map(({color:e,materialHint:t})=>({queryKey:[`color-by-material`,e,t],queryFn:()=>Q.getColorByMaterial(e,t),enabled:!!e,staleTime:300*1e3}))});return i.map(({resolvedName:e,color:t},n)=>({resolvedName:e,colorLabel:(a[n]?.data?.color_name??null)||Kd(t)}))}function ake({printerId:e,filamentReqs:t,manualMappings:n,onManualMappingChange:r,currencySymbol:i,defaultCostPerKg:a,defaultExpanded:o=!1,forceColorMatch:s,onForceColorMatchChange:c}){let{t:l}=$e(),u=no(),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(o),{data:h}=q({queryKey:[`printer-status`,e],queryFn:()=>Q.getPrinterStatus(e),enabled:!!e}),{data:g}=q({queryKey:[`spool-assignments`,e],queryFn:()=>Q.getAssignments(e),enabled:!!e}),{data:_}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:v}=q({queryKey:[`printer-inventory-remain`,e],queryFn:()=>Q.getInventoryRemain(e),enabled:!!e,staleTime:30*1e3}),b=(0,y.useMemo)(()=>{if(!v?.inventory_remain_g)return;let e=new Map;return Object.entries(v.inventory_remain_g).forEach(([t,n])=>{let r=Number(t);Number.isNaN(r)||e.set(r,n)}),e},[v]),{loadedFilaments:x,filamentComparison:S,hasTypeMismatch:C,hasColorMismatch:w}=uW(t,h,n,Jf(_?.prefer_lowest_filament,h?.ams_filament_backup),b),T=mW(t?.filaments),E=(0,y.useMemo)(()=>{let e=new Map;for(let t of g||[]){let n=t.ams_id===255,r=Rf(t.ams_id,t.tray_id,n);e.set(r,t.spool?.cost_per_kg??null)}return e},[g]),D=(0,y.useMemo)(()=>{let e=new Map;for(let t of g||[]){let n=t.ams_id===255,r=Rf(t.ams_id,t.tray_id,n),i=t.spool;if(!i){e.set(r,null);continue}e.set(r,Math.max(0,Math.round((i.label_weight??0)-(i.weight_used??0))))}return e},[g]),O=(0,y.useMemo)(()=>{let e=0;for(let t of S){let n=t.loaded?.globalTrayId;if(n==null)continue;let r=E.get(n)??null??a;r>0&&(e+=t.used_grams/1e3*r)}return e},[S,E,a]),k=(0,y.useMemo)(()=>Array.from(E.values()).some(e=>e!=null&&e>0),[E]),A=t?.filaments&&t.filaments.length>0,j=t?.filaments?.some(e=>e.nozzle_id!=null)??!1,M=h?.fila_switch?.installed===!0,N=e=>{let t=h?.fila_switch;if(!t?.installed)return null;let n=t.in_slots.indexOf(e);return n<0?null:t.out_extruders[n]??null};if(!A||!h)return null;let P=C?`#f97316`:w?`#facc15`:`#00ae42`,F=(e,t)=>{if(e>0)if(t===``){let t={...n};delete t[e],r(t)}else r({...n,[e]:parseInt(t,10)})};return(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>m(!p),className:`flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full`,children:[(0,K.jsx)(ys,{className:`w-4 h-4`,fill:P,stroke:`none`}),(0,K.jsx)(`span`,{children:l(`printModal.filamentMapping`)}),C?(0,K.jsx)(`span`,{className:`text-xs text-orange-400`,children:`(Type not found)`}):w?(0,K.jsx)(`span`,{className:`text-xs text-yellow-400`,children:`(Color mismatch)`}):(0,K.jsx)(`span`,{className:`text-xs text-bambu-green`,children:`(Ready)`}),p?(0,K.jsx)(ss,{className:`w-4 h-4 ml-auto`}):(0,K.jsx)(rs,{className:`w-4 h-4 ml-auto`})]}),p&&(0,K.jsxs)(`div`,{className:`mt-2 bg-bambu-dark rounded-lg p-3 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`Click to change slot assignment`}),(0,K.jsxs)(`button`,{type:`button`,onClick:async()=>{f(!0);try{await Q.refreshPrinterStatus(e),await new Promise(e=>setTimeout(e,500)),await u.refetchQueries({queryKey:[`printer-status`,e]})}finally{f(!1)}},className:`flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white`,disabled:d,children:[(0,K.jsx)(Ol,{className:`w-3 h-3 ${d?`animate-spin`:``}`}),(0,K.jsx)(`span`,{children:`Re-read`})]})]}),S.map((e,t)=>{let n=e.slot_id??0,r=n>0&&c!=null,{resolvedName:i,colorLabel:a}=T[t]??{resolvedName:e.type,colorLabel:Kd(e.color)};return(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`div`,{className:`grid items-center gap-2 text-xs`,style:{gridTemplateColumns:`16px minmax(70px, 1fr) auto 2fr 16px`},children:[(0,K.jsx)(`span`,{title:`Required: ${i} - ${a}`,children:(0,K.jsx)(ys,{className:`w-3 h-3`,fill:e.color,stroke:e.color})}),(0,K.jsxs)(`span`,{className:`text-white truncate flex items-center gap-1`,children:[j&&e.nozzle_id!=null&&(0,K.jsx)(`span`,{className:`inline-flex items-center justify-center w-3.5 h-3.5 rounded text-[9px] font-bold leading-none bg-bambu-gray/20 text-bambu-gray shrink-0`,title:e.nozzle_id===1?l(`printModal.leftNozzleTooltip`):l(`printModal.rightNozzleTooltip`),children:e.nozzle_id===1?l(`printModal.leftNozzle`):l(`printModal.rightNozzle`)}),i,` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.used_grams,`g)`]})]}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`→`}),(0,K.jsxs)(`select`,{value:e.loaded?.globalTrayId??``,onChange:e=>F(n,e.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${e.status===`match`?`border-bambu-green/50 text-bambu-green`:e.status===`type_only`?`border-yellow-400/50 text-yellow-400`:`border-orange-400/50 text-orange-400`} ${e.isManual?`ring-1 ring-blue-400/50`:``}`,title:e.isManual?`Manually selected`:`Auto-matched`,children:[(0,K.jsx)(`option`,{value:``,className:`bg-bambu-dark text-bambu-gray`,children:`-- Select slot --`}),x.map(e=>{let t=D.get(e.globalTrayId),n=t==null?``:l(`printModal.slotRemainingShort`,{grams:t,defaultValue:` - ${t}g left`}),r=M?N(e.globalTrayId):null,i=r==null?``:` [${l(r===1?`printModal.leftNozzle`:`printModal.rightNozzle`)}]`;return(0,K.jsxs)(`option`,{value:e.globalTrayId,className:`bg-bambu-dark text-white`,children:[e.label,`: `,e.traySubBrands||e.type,` (`,e.colorName,`)`,n,i]},e.globalTrayId)})]}),e.status===`match`?(0,K.jsx)(ns,{className:`w-3 h-3 text-bambu-green`}):e.status===`type_only`?(0,K.jsx)(`span`,{title:`Same type, different color`,children:(0,K.jsx)(Cu,{className:`w-3 h-3 text-yellow-400`})}):(0,K.jsx)(`span`,{title:`Filament type not loaded`,children:(0,K.jsx)(Cu,{className:`w-3 h-3 text-orange-400`})})]}),r&&(0,K.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer select-none pl-5`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:s?.[n]??!1,onChange:e=>c(n,e.target.checked),className:`accent-bambu-green w-3 h-3`}),(0,K.jsx)(ml,{className:`w-3 h-3`}),l(`printModal.forceColorMatch`)]})]},t)}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[l(`printModal.totalCost`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:O>0||k?`${i}${O.toFixed(2)}`:`N/A`})]}),C&&(0,K.jsx)(`p`,{className:`text-xs text-orange-400 mt-2`,children:`Required filament type not found in printer.`})]})]})}function oke({filamentReqs:e,availableFilaments:t,overrides:n,onChange:r,forceColorMatch:i,onForceColorMatchChange:a}){let{t:o}=$e(),s=mW(e?.filaments),c=(0,y.useMemo)(()=>{let e={};for(let n of t){let t=Pf(n.type);e[t]||(e[t]=[]),e[t].push(n)}return e},[t]),l=e?.filaments;if(!l||l.length===0||t.length===0)return null;let u=(e,t)=>{if(t===``){let t={...n};delete t[e],r(t)}else{let[i,a]=t.split(`|`);r({...n,[e]:{type:i,color:a}})}};return(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:(0,K.jsx)(`span`,{children:o(`printModal.filamentOverride`)})}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:o(`printModal.filamentOverrideHint`)}),(0,K.jsx)(`div`,{className:`bg-bambu-dark rounded-lg p-3 space-y-2`,children:l.map((e,t)=>{let r=n[e.slot_id],l=!!r,d=c[Pf(e.type)]||[],f=e.nozzle_id==null?d:d.filter(t=>t.extruder_id==null||t.extruder_id===e.nozzle_id),{resolvedName:p,colorLabel:m}=s[t]??{resolvedName:e.type,colorLabel:Kd(e.color)};return(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`div`,{className:`grid items-center gap-2 text-xs`,style:{gridTemplateColumns:`16px minmax(70px, 1fr) auto 2fr 20px`},children:[(0,K.jsx)(`span`,{title:`${o(`printModal.originalFilament`)}: ${p} - ${m}`,children:(0,K.jsx)(ys,{className:`w-3 h-3`,fill:e.color,stroke:e.color})}),(0,K.jsxs)(`span`,{className:`text-white truncate`,children:[p,` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.used_grams,`g)`]})]}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`→`}),(0,K.jsxs)(`select`,{value:l?`${r.type}|${r.color}`:``,onChange:t=>u(e.slot_id,t.target.value),disabled:f.length===0,className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${l?`border-blue-400/50 text-blue-400`:`border-bambu-gray/30 text-bambu-gray`}`,children:[(0,K.jsxs)(`option`,{value:``,className:`bg-bambu-dark text-bambu-gray`,children:[o(`printModal.originalFilament`),`: `,p,` (`,m,`)`]}),f.map((e,t)=>(0,K.jsxs)(`option`,{value:`${e.type}|${e.color}`,className:`bg-bambu-dark text-white`,children:[e.tray_sub_brands||e.type,` (`,Kd(e.color),`)`]},`${e.type}-${e.color}-${e.tray_sub_brands}-${t}`))]}),l?(0,K.jsx)(`button`,{type:`button`,onClick:()=>u(e.slot_id,``),className:`text-bambu-gray hover:text-white transition-colors`,title:o(`printModal.resetToOriginal`),children:(0,K.jsx)(Al,{className:`w-3 h-3`})}):(0,K.jsx)(`span`,{className:`w-3`})]}),(0,K.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer select-none pl-5`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:i?.[e.slot_id]??!1,onChange:t=>a?.(e.slot_id,t.target.checked),className:`accent-bambu-green w-3 h-3`}),(0,K.jsx)(ml,{className:`w-3 h-3`}),o(`printModal.forceColorMatch`)]})]},e.slot_id)})})]})}function ske({plates:e,isMultiPlate:t,selectedPlates:n,onToggle:r,onSelectAll:i,onDeselectAll:a,multiSelect:o}){let{t:s}=$e();if(!t||e.length<=1)return null;let c=n.size===e.length;return(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(Lc,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`Select Plate`,o?`s`:``,` to Print`]}),n.size===0&&(0,K.jsxs)(`span`,{className:`text-xs text-orange-400 flex items-center gap-1`,children:[(0,K.jsx)(Cu,{className:`w-3 h-3`}),`Selection required`]}),o&&i&&a&&(0,K.jsx)(`button`,{type:`button`,onClick:c?a:i,className:`ml-auto text-xs px-2 py-0.5 rounded-full border transition-colors ${c?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray`}`,children:c?s(`queue.deselectAll`):s(`queue.selectAllPlates`,{count:e.length})})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:e.map(e=>{let t=n.has(e.index);return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>r(e.index),className:`flex items-center gap-2 p-2 rounded-lg border transition-colors text-left ${t?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray`}`,children:[o&&(t?(0,K.jsx)(iu,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}):(0,K.jsx)(ou,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`})),e.has_thumbnail&&e.thumbnail_url!=null?(0,K.jsx)(`img`,{src:Qu(e.thumbnail_url),alt:`Plate ${e.index}`,className:`w-10 h-10 rounded object-cover bg-bambu-dark-tertiary`}):(0,K.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,K.jsx)(Lc,{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||`Plate ${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.filaments.length} filament${e.filaments.length===1?``:`s`}`,e.print_time_seconds==null?``:` • ${wf(e.print_time_seconds)}`]}),(()=>{let t=pW(e.bed_type);return t?(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray flex items-center gap-1 mt-0.5 truncate`,title:t.label,children:[(0,K.jsx)(`img`,{src:t.icon,alt:``,className:`w-3.5 h-3.5 object-contain flex-shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:t.label})]}):null})()]}),!o&&t&&(0,K.jsx)(ns,{className:`w-4 h-4 text-bambu-green flex-shrink-0`})]},e.index)})})]})}var cke=new Set([`IDLE`,`FINISH`,`FAILED`]);function lke({printerResult:e,filamentReqs:t,onUpdateConfig:n}){let r=no(),[i,a]=(0,y.useState)(!1),o=(t,r)=>{if(t<=0)return;let i={...e.config.manualMappings};r===``?delete i[t]:i[t]=parseInt(r,10),n({useDefault:!1,manualMappings:i,autoConfigured:!1})},s=async()=>{a(!0);try{await Q.refreshPrinterStatus(e.printerId),await new Promise(e=>setTimeout(e,500)),await r.refetchQueries({queryKey:[`printer-status`,e.printerId]})}finally{a(!1)}},c=t.map(t=>{let n=t.slot_id||0,i=e.config.manualMappings[n],a,o=!1;if(i!==void 0)a=e.loadedFilaments.find(e=>e.globalTrayId===i),o=!0;else{let n=new Set(Object.values(e.config.manualMappings)),i=r.getQueryData([`settings`]);a=Yf(t,e.loadedFilaments,n,Jf(i?.prefer_lowest_filament,e.status?.ams_filament_backup),e.inventoryByTrayId)}let s=`mismatch`;if(a){let e=a.type?.toUpperCase()===t.type?.toUpperCase(),n=Af(a.color)===Af(t.color)||If(a.color,t.color);e&&n?s=`match`:e&&(s=`type_only`)}return{req:t,loaded:a,status:s,isManual:o}});return(0,K.jsxs)(`div`,{className:`mt-2 bg-bambu-dark rounded-lg p-3 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`Custom slot mapping`}),(0,K.jsxs)(`button`,{type:`button`,onClick:s,className:`flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white`,disabled:i,children:[(0,K.jsx)(Ol,{className:`w-3 h-3 ${i?`animate-spin`:``}`}),(0,K.jsx)(`span`,{children:`Re-read`})]})]}),c.map(({req:t,loaded:n,status:r,isManual:i},a)=>(0,K.jsxs)(`div`,{className:`grid items-center gap-2 text-xs`,style:{gridTemplateColumns:`16px minmax(70px, 1fr) auto 2fr 16px`},children:[(0,K.jsx)(`span`,{title:`Required: ${t.type} - ${Kd(t.color)}`,children:(0,K.jsx)(ys,{className:`w-3 h-3`,fill:t.color,stroke:t.color})}),(0,K.jsxs)(`span`,{className:`text-white truncate`,children:[t.type,` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,t.used_grams,`g)`]})]}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`→`}),(0,K.jsxs)(`select`,{value:n?.globalTrayId??``,onChange:e=>o(t.slot_id||0,e.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${r===`match`?`border-bambu-green/50 text-bambu-green`:r===`type_only`?`border-yellow-400/50 text-yellow-400`:`border-orange-400/50 text-orange-400`} ${i?`ring-1 ring-blue-400/50`:``}`,title:i?`Manually selected`:`Auto-matched`,children:[(0,K.jsx)(`option`,{value:``,className:`bg-bambu-dark text-bambu-gray`,children:`-- Select slot --`}),Xf(e.loadedFilaments,t.nozzle_id).map(e=>(0,K.jsxs)(`option`,{value:e.globalTrayId,className:`bg-bambu-dark text-white`,children:[e.label,`: `,e.traySubBrands||e.type,` (`,e.colorName,`)`]},e.globalTrayId))]}),r===`match`?(0,K.jsx)(ns,{className:`w-3 h-3 text-bambu-green`}):r===`type_only`?(0,K.jsx)(`span`,{title:`Same type, different color`,children:(0,K.jsx)(Cu,{className:`w-3 h-3 text-yellow-400`})}):(0,K.jsx)(`span`,{title:`Filament type not loaded`,children:(0,K.jsx)(Cu,{className:`w-3 h-3 text-orange-400`})})]},a))]})}function uke({printers:e,selectedPrinterIds:t,onMultiSelect:n,isLoading:r=!1,allowMultiple:i=!1,showInactive:a=!1,disableBusy:o=!1,printerMappingResults:s,filamentReqs:c,onAutoConfigurePrinter:l,onUpdatePrinterConfig:u,assignmentMode:d=`printer`,onAssignmentModeChange:f,targetModel:p,onTargetModelChange:m,targetLocation:h,onTargetLocationChange:g,slicedForModel:_}){let[v,b]=(0,y.useState)(!1),x=a?e:e.filter(e=>e.is_active),S=_o({queries:x.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),staleTime:5e3}))}),C=(0,y.useMemo)(()=>{let e=new Map;return x.forEach((t,n)=>{let r=S[n];r?.data&&e.set(t.id,r.data)}),e},[x,S]),w=e=>{let t=C.get(e);return t?t.connected?!cke.has(t.state??``):!0:!1},T=e=>{let t=C.get(e);if(!t)return null;if(!t.connected)return`Offline`;let n=t.state;return n?n===`RUNNING`?t.stg_cur_name||`Printing`:n===`PREPARE`?`Preparing`:n===`PAUSE`?`Paused`:n===`IDLE`?`Idle`:n===`FINISH`?`Finished`:n===`FAILED`?`Failed`:n:null},E=(0,y.useMemo)(()=>{if(d!==`printer`||!_||v)return x;let e=x.filter(e=>e.model===_);return e.length>0?e:x},[x,d,_,v]),D=x.length-E.length,O=(0,y.useMemo)(()=>{let e=x.map(e=>e.model).filter(e=>!!e);return[...new Set(e)].sort()},[x]),k=(0,y.useMemo)(()=>{if(!p)return[];let e=x.filter(e=>e.model===p&&e.location).map(e=>e.location).filter(e=>!!e);return[...new Set(e)].sort()},[x,p]),A=f&&m&&O.length>0,j=i&&t.length>1&&s&&c?.filaments&&c.filaments.length>0&&l&&u;if(r)return(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`})});if(E.length===0)return(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-red-400 text-sm mb-4`,children:[(0,K.jsx)(us,{className:`w-4 h-4`}),`No `,a?``:`active `,`printers available`]});let M=e=>{o&&w(e)||(i?t.includes(e)?n(t.filter(t=>t!==e)):n([...t,e]):n([e]))},N=()=>{n((o?E.filter(e=>!w(e.id)):E).map(e=>e.id))},P=()=>{n([])},F=(e,t,n)=>{n.stopPropagation(),!(!l||!u)&&(t?l(e):u(e,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},I=e=>t.includes(e),L=t.length,R=e=>s?.find(t=>t.printerId===e);return(0,K.jsxs)(`div`,{className:`space-y-2 mb-6`,children:[A&&(0,K.jsxs)(`div`,{className:`flex gap-2 mb-4`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{f(`printer`),m(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${d===`printer`?`border-bambu-green bg-bambu-green/10 text-white`:`border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray`}`,children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-sm`,children:`Specific Printer`})]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{f(`model`),n([]),m(_&&O.includes(_)?_:O[0])},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${d===`model`?`border-bambu-green bg-bambu-green/10 text-white`:`border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray`}`,children:[(0,K.jsx)(ku,{className:`w-4 h-4`}),(0,K.jsxs)(`span`,{className:`text-sm`,children:[`Any `,_||`Model`]})]})]}),d===`model`&&A&&(0,K.jsxs)(`div`,{className:`space-y-3 mb-4`,children:[!_&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:`Target Model`}),(0,K.jsxs)(`select`,{value:p||``,onChange:e=>{m(e.target.value||null),g&&g(null)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,children:[(0,K.jsx)(`option`,{value:``,children:`Select a model...`}),O.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]})]}),p&&k.length>0&&g&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:`Location Filter (optional)`}),(0,K.jsxs)(`select`,{value:h||``,onChange:e=>g(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 text-sm`,children:[(0,K.jsx)(`option`,{value:``,children:`Any location`}),k.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]})]}),p&&(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[`Scheduler will assign to first available idle `,p,` printer`,h?` in ${h}`:``]})]}),d===`printer`&&i&&E.length>1&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray mb-2`,children:[(0,K.jsx)(`span`,{children:L===0?`Select printers`:`${L} printer${L===1?``:`s`} selected`}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[L0&&(0,K.jsx)(`button`,{type:`button`,onClick:P,className:`text-bambu-gray hover:text-white transition-colors`,children:`Clear`})]})]}),d===`printer`&&E.map(e=>{let t=I(e.id),n=R(e.id),r=n&&!n.config.useDefault,a=w(e.id),s=o&&a,d=T(e.id);return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>M(e.id),disabled:s,className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${s?`border-bambu-dark-tertiary bg-bambu-dark opacity-50 cursor-not-allowed`:t?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray`} ${e.is_active?``:`opacity-60`}`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${s?`bg-bambu-dark-tertiary`:t?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(Tl,{className:`w-5 h-5 ${s?`text-bambu-gray/50`:t?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{className:`text-left flex-1`,children:[(0,K.jsxs)(`p`,{className:`font-medium ${s?`text-bambu-gray`:`text-white`}`,children:[e.name,!e.is_active&&(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs ml-2`,children:`(inactive)`})]}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[e.model||`Unknown model`,` • `,e.ip_address]})]}),d&&(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full ${a?`bg-yellow-500/20 text-yellow-400`:`bg-bambu-green/20 text-bambu-green`}`,children:d}),i&&(0,K.jsx)(`div`,{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${s?`border-bambu-gray/30`:t?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:t&&(0,K.jsx)(ns,{className:`w-3 h-3 text-white`})})]}),t&&j&&n&&(0,K.jsxs)(`div`,{className:`ml-4 mt-2 mb-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:r,onChange:t=>F(e.id,t.target.checked,t),className:`w-3.5 h-3.5 rounded border-bambu-gray/30 bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green focus:ring-offset-0`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`Custom mapping`})]}),(0,K.jsxs)(`span`,{className:`text-xs ml-2 ${n.matchStatus===`full`?`text-bambu-green`:n.matchStatus===`partial`?`text-yellow-400`:`text-orange-400`}`,children:[`(`,n.exactMatches,`/`,n.totalSlots,` matched)`]}),n.isLoading&&(0,K.jsx)(Ol,{className:`w-3 h-3 text-bambu-gray animate-spin`}),r&&(0,K.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),l(e.id)},className:`ml-auto flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white`,children:[(0,K.jsx)(Pu,{className:`w-3 h-3`}),`Auto`]})]}),r&&(0,K.jsx)(lke,{printerResult:n,filamentReqs:c.filaments,onUpdateConfig:t=>u(e.id,t)})]})]},e.id)}),d===`printer`&&D>0&&!v&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>b(!0),className:`text-xs text-bambu-gray hover:text-white transition-colors mt-2 flex items-center gap-1`,children:[(0,K.jsx)(Cu,{className:`w-3 h-3 text-yellow-400`}),D,` other printer`,D>1?`s`:``,` hidden (different model) —`,(0,K.jsx)(`span`,{className:`underline`,children:`show all`})]}),d===`printer`&&v&&_&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>b(!1),className:`text-xs text-bambu-gray hover:text-white transition-colors mt-2`,children:(0,K.jsxs)(`span`,{className:`underline`,children:[`Show only `,_,` printers`]})}),d===`printer`&&L===0&&(0,K.jsxs)(`p`,{className:`text-xs text-orange-400 mt-1 flex items-center gap-1`,children:[(0,K.jsx)(us,{className:`w-3 h-3`}),`Select at least one printer`]}),d===`model`&&!p&&(0,K.jsxs)(`p`,{className:`text-xs text-orange-400 mt-1 flex items-center gap-1`,children:[(0,K.jsx)(us,{className:`w-3 h-3`}),`Select a target printer model`]})]})}function dke({options:e,onChange:t,defaultExpanded:n=!1,showDualNozzleOptions:r=!1}){let{t:i}=$e(),[a,o]=(0,y.useState)(n),s=[{key:`bed_levelling`,label:i(`settings.defaultBedLevelling`),desc:i(`settings.defaultBedLevellingDesc`)},{key:`flow_cali`,label:i(`settings.defaultFlowCali`),desc:i(`settings.defaultFlowCaliDesc`)},{key:`vibration_cali`,label:i(`settings.defaultVibrationCali`),desc:i(`settings.defaultVibrationCaliDesc`)},{key:`layer_inspect`,label:i(`settings.defaultLayerInspect`),desc:i(`settings.defaultLayerInspectDesc`)},{key:`timelapse`,label:i(`settings.defaultTimelapse`),desc:i(`settings.defaultTimelapseDesc`)},{key:`nozzle_offset_cali`,label:i(`settings.defaultNozzleOffsetCali`),desc:i(`settings.defaultNozzleOffsetCaliDesc`),dualNozzleOnly:!0}].filter(e=>!e.dualNozzleOnly||r),c=n=>{t({...e,[n]:!e[n]})};return(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>o(!a),className:`flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full`,children:[(0,K.jsx)(Ul,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:i(`queue.bulkEdit.printOptions`)}),a?(0,K.jsx)(ss,{className:`w-4 h-4 ml-auto`}):(0,K.jsx)(rs,{className:`w-4 h-4 ml-auto`})]}),a&&(0,K.jsx)(`div`,{className:`mt-2 bg-bambu-dark rounded-lg p-3 space-y-2`,children:s.map(({key:t,label:n,desc:r})=>(0,K.jsxs)(`label`,{className:`flex items-center justify-between cursor-pointer group`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r})]}),(0,K.jsx)(`div`,{className:`relative w-10 h-5 rounded-full transition-colors ${e[t]?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,onClick:()=>c(t),children:(0,K.jsx)(`div`,{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white transition-transform ${e[t]?`translate-x-5`:`translate-x-0.5`}`})})]},t))})]})}function fke({options:e,onChange:t,dateFormat:n=`system`,timeFormat:r=`system`,canControlPrinter:i=!0,showStagger:a=!1,printerCount:o=0,hasGcodeSnippets:s=!1}){let{t:c}=$e(),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!0),[h,g]=(0,y.useState)(!0),_=(0,y.useRef)(null),v=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(e.scheduleType!==`scheduled`){v.current=!1;return}if(!v.current){v.current=!0;let i;e.scheduledTime?(i=new Date(e.scheduledTime),isNaN(i.getTime())&&(i=new Date,i.setHours(i.getHours()+1,0,0,0))):(i=new Date,i.setHours(i.getHours()+1,0,0,0),t({...e,scheduledTime:_f(i)})),u(df(i,n)),f(ff(i,r)),m(!0),g(!0)}},[e.scheduleType,e.scheduledTime,n,r,t,e]);let b=n=>{t({...e,scheduleType:n,requireManualStart:n===`queue`?e.requireManualStart:!1})},x=(r,i)=>{let a=hf(r,n),o=gf(i);m(!!a),g(!!o),a&&o&&(a.setHours(o.hours,o.minutes,0,0),a>new Date&&t({...e,scheduledTime:_f(a)}))},S=e=>{u(e),x(e,d)},C=e=>{f(e),x(l,e)};return(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-2`,children:c(`printModal.whenToPrint`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${e.scheduleType===`asap`?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,onClick:()=>b(`asap`),children:[(0,K.jsx)(xs,{className:`w-4 h-4`}),c(`printModal.asap`)]}),(0,K.jsxs)(`button`,{type:`button`,className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${e.scheduleType===`queue`?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,onClick:()=>b(`queue`),children:[(0,K.jsx)(Hc,{className:`w-4 h-4`}),c(`printModal.queue`)]}),(0,K.jsxs)(`button`,{type:`button`,className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${e.scheduleType===`scheduled`?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,onClick:()=>b(`scheduled`),children:[(0,K.jsx)(Xo,{className:`w-4 h-4`}),c(`printModal.schedule`)]})]})]}),e.scheduleType===`scheduled`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:c(`printModal.dateTime`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex-1 relative`,children:[(0,K.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 pr-10 bg-bambu-dark border rounded-lg text-white focus:outline-none ${p?`border-bambu-dark-tertiary focus:border-bambu-green`:`border-red-500`}`,value:l,onChange:e=>S(e.target.value),placeholder:lf(n)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{_.current?.showPicker()},className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,title:c(`printModal.openCalendar`),children:(0,K.jsx)(Xo,{className:`w-4 h-4`})}),(0,K.jsx)(`input`,{ref:_,type:`datetime-local`,className:`absolute top-0 left-0 w-0 h-0 opacity-0 pointer-events-none`,value:e.scheduledTime,onChange:i=>{let a=i.target.value;if(a){let i=new Date(a);isNaN(i.getTime())||(u(df(i,n)),f(ff(i,r)),m(!0),g(!0),t({...e,scheduledTime:a}))}},tabIndex:-1})]}),(0,K.jsx)(`div`,{className:`w-32`,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border rounded-lg text-white focus:outline-none ${h?`border-bambu-dark-tertiary focus:border-bambu-green`:`border-red-500`}`,value:d,onChange:e=>C(e.target.value),placeholder:uf(r)})})]}),(!p||!h)&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-400`,children:c(`printModal.invalidDateTime`)})]}),e.scheduleType===`queue`&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`requireManualStart`,checked:e.requireManualStart,onChange:n=>t({...e,requireManualStart:n.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`label`,{htmlFor:`requireManualStart`,className:`text-sm flex items-center gap-1 text-bambu-gray`,children:[(0,K.jsx)(Sc,{className:`w-3.5 h-3.5`}),c(`printModal.requireManualStart`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`requirePrevious`,checked:e.requirePreviousSuccess,onChange:n=>t({...e,requirePreviousSuccess:n.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsx)(`label`,{htmlFor:`requirePrevious`,className:`text-sm text-bambu-gray`,children:c(`printModal.requirePreviousSuccess`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`autoOffAfter`,checked:e.autoOffAfter,onChange:n=>t({...e,autoOffAfter:n.target.checked}),disabled:!i,className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green disabled:opacity-50`}),(0,K.jsxs)(`label`,{htmlFor:`autoOffAfter`,className:`text-sm flex items-center gap-1 ${i?`text-bambu-gray`:`text-bambu-gray/50`}`,children:[(0,K.jsx)(wl,{className:`w-3.5 h-3.5`}),c(`printModal.autoOffAfter`)]})]}),s&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`gcodeInjection`,checked:e.gcodeInjection,onChange:n=>t({...e,gcodeInjection:n.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`label`,{htmlFor:`gcodeInjection`,className:`text-sm flex items-center gap-1 text-bambu-gray`,children:[(0,K.jsx)(Ts,{className:`w-3.5 h-3.5`}),c(`printModal.gcodeInjection`,`Inject auto-print G-code`)]})]}),a&&e.scheduleType!==`queue`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`staggerEnabled`,checked:e.staggerEnabled,onChange:n=>t({...e,staggerEnabled:n.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`label`,{htmlFor:`staggerEnabled`,className:`text-sm flex items-center gap-1 text-bambu-gray`,children:[(0,K.jsx)(Lc,{className:`w-3.5 h-3.5`}),c(`printModal.staggerPrinterStarts`,`Stagger printer starts`)]})]}),e.staggerEnabled&&(0,K.jsxs)(`div`,{className:`ml-6 space-y-3`,children:[(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-bambu-gray mb-1`,children:c(`printModal.staggerGroupSize`,`Group size`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:o,value:e.staggerGroupSize,onChange:n=>t({...e,staggerGroupSize:Math.max(1,parseInt(n.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.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:c(`printModal.staggerInterval`,`Interval (min)`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:60,value:e.staggerIntervalMinutes,onChange:n=>t({...e,staggerIntervalMinutes:Math.max(1,parseInt(n.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`})]})]}),o>0&&(()=>{let t=Math.ceil(o/e.staggerGroupSize),n=o%e.staggerGroupSize,r=(t-1)*e.staggerIntervalMinutes;return(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[c(`printModal.staggerPreview`,`{{printers}} printers → {{groups}} groups of {{size}}, starting every {{interval}} min`,{printers:o,groups:t,size:e.staggerGroupSize,interval:e.staggerIntervalMinutes}),n!==0&&e.staggerGroupSize1?` (${c(`printModal.staggerTotal`,`total: {{minutes}} min`,{minutes:r})})`:``]})})()]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.scheduleType===`asap`?c(`printModal.helpAsap`):e.scheduleType===`scheduled`?c(`printModal.helpSchedule`):c(`printModal.helpQueue`)})]})}var hW={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1,nozzle_offset_cali:!0},gW={scheduleType:`asap`,scheduledTime:``,requireManualStart:!1,requirePreviousSuccess:!1,autoOffAfter:!1,gcodeInjection:!1,staggerEnabled:!1,staggerGroupSize:2,staggerIntervalMinutes:5};function _W({mode:e,archiveId:t,libraryFileId:n,archiveName:r,queueItem:i,initialSelectedPrinterIds:a,onClose:o,onSuccess:s,projectId:c,cleanupLibraryAfterDispatch:l}){let{t:u}=$e(),d=no(),{showToast:f}=Ed(),{hasPermission:p}=pd(),m=!!n&&!t,h=e===`edit-queue-item`,[g,_]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.printer_id?[i.printer_id]:a?.length?a:[]),[v,b]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.plate_id!=null?new Set([i.plate_id]):new Set),x=v.size===1?[...v][0]:null,[S,C]=(0,y.useState)(1),[w,T]=(0,y.useState)(()=>e===`edit-queue-item`&&i?{bed_levelling:i.bed_levelling??hW.bed_levelling,flow_cali:i.flow_cali??hW.flow_cali,vibration_cali:i.vibration_cali??hW.vibration_cali,layer_inspect:i.layer_inspect??hW.layer_inspect,timelapse:i.timelapse??hW.timelapse,nozzle_offset_cali:i.nozzle_offset_cali??hW.nozzle_offset_cali}:hW),[E,D]=(0,y.useState)(()=>{if(e===`edit-queue-item`&&i){let e=`queue`;i.scheduled_time&&!Wf(i.scheduled_time)&&(e=`scheduled`);let t=``;return i.scheduled_time&&!Wf(i.scheduled_time)&&(t=_f(yf(i.scheduled_time)??new Date)),{scheduleType:e,scheduledTime:t,requireManualStart:i.manual_start,requirePreviousSuccess:i.require_previous_success,autoOffAfter:i.auto_off_after,gcodeInjection:i.gcode_injection??!1,staggerEnabled:!1,staggerGroupSize:gW.staggerGroupSize,staggerIntervalMinutes:gW.staggerIntervalMinutes}}return gW}),[O,k]=(0,y.useState)(()=>{if(e===`edit-queue-item`&&i?.ams_mapping&&Array.isArray(i.ams_mapping)){let e={};return i.ams_mapping.forEach((t,n)=>{t!==-1&&(e[n+1]=t)}),e}return{}}),[A,j]=(0,y.useState)({}),[M,N]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.target_model?`model`:`printer`),[P,F]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.target_model?i.target_model:null),[I,L]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.target_location?i.target_location:null),[R,z]=(0,y.useState)(()=>{if(e===`edit-queue-item`&&i?.filament_overrides){let e={};for(let t of i.filament_overrides)e[t.slot_id]={type:t.type,color:t.color};return e}return{}}),[B,V]=(0,y.useState)(()=>{if(e===`edit-queue-item`&&i?.filament_overrides){let e={};for(let t of i.filament_overrides)e[t.slot_id]=t.force_color_match===!0;return e}return{}}),[ee]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.printer_id?[i.printer_id]:[]),[te]=(0,y.useState)(()=>e===`edit-queue-item`&&i?i.plate_id:null),[H,ne]=(0,y.useState)(!1),[re,U]=(0,y.useState)({current:0,total:0}),[ie,ae]=(0,y.useState)(null),[W,oe]=(0,y.useState)(new Set),se=g.length,ce=g.length>0?g[0]:null,{data:le}=q({queryKey:[`settings`],queryFn:Q.getSettings}),ue=(0,y.useRef)(!1);(0,y.useEffect)(()=>{!le||ue.current||e===`edit-queue-item`||(ue.current=!0,T({bed_levelling:le.default_bed_levelling??hW.bed_levelling,flow_cali:le.default_flow_cali??hW.flow_cali,vibration_cali:le.default_vibration_cali??hW.vibration_cali,layer_inspect:le.default_layer_inspect??hW.layer_inspect,timelapse:le.default_timelapse??hW.timelapse,nozzle_offset_cali:le.default_nozzle_offset_cali??hW.nozzle_offset_cali}))},[le,e]);let de=(0,y.useRef)(!1);(0,y.useEffect)(()=>{!le||de.current||e===`edit-queue-item`||(de.current=!0,D(e=>({...e,staggerGroupSize:le.stagger_group_size??e.staggerGroupSize,staggerIntervalMinutes:le.stagger_interval_minutes??e.staggerIntervalMinutes})))},[le,e]);let fe=ef(le?.currency||`USD`),pe=le?.default_filament_cost??0,{data:me,isLoading:he}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:ge}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),staleTime:30*1e3,enabled:!h&&M===`printer`}),_e=_o({queries:g.map(e=>({queryKey:[`printer-inventory-remain`,e],queryFn:()=>Q.getInventoryRemain(e),staleTime:30*1e3,enabled:g.length>0}))}),ve=(0,y.useMemo)(()=>{let e=new Map;return g.forEach((t,n)=>{let r=_e[n]?.data?.inventory_remain_g;if(!r)return;let i=new Map;Object.entries(r).forEach(([e,t])=>{let n=Number(e);Number.isNaN(n)||i.set(n,t)}),e.set(t,i)}),e},[g,_e]),{data:ye}=q({queryKey:[`archive`,t],queryFn:()=>Q.getArchive(t),enabled:!!t&&!m}),{data:be}=q({queryKey:[`library-file`,n],queryFn:()=>Q.getLibraryFile(n),enabled:m&&!!n}),xe=ye?.sliced_for_model||be?.sliced_for_model||null,{data:Se,isError:Ce}=q({queryKey:[`archive-plates`,t],queryFn:()=>Q.getArchivePlates(t),enabled:!!t&&!m,retry:!1}),{data:we}=q({queryKey:[`library-file-plates`,n],queryFn:()=>Q.getLibraryFilePlates(n),enabled:m&&!!n}),Te=m?we:Se,{data:Ee,isError:De}=q({queryKey:[`archive-filaments`,t,x],queryFn:()=>Q.getArchiveFilamentRequirements(t,x??void 0),enabled:!!t&&!m&&(x!==null||!Te?.is_multi_plate),retry:!1}),{data:Oe}=q({queryKey:[`library-file-filaments`,n,x],queryFn:()=>Q.getLibraryFileFilamentRequirements(n,x??void 0),enabled:m&&!!n&&(x!==null||!Te?.is_multi_plate)}),ke=!m&&(Ce||De),Ae=m?Oe:Ee,{data:je}=q({queryKey:[`available-filaments`,P,I],queryFn:()=>Q.getAvailableFilaments(P,I??void 0),enabled:M===`model`&&!!P}),{data:Me}=q({queryKey:[`printer-status`,ce],queryFn:()=>Q.getPrinterStatus(ce),enabled:!!ce}),Ne=Jf(le?.prefer_lowest_filament,Me?.ams_filament_backup),Pe=e=>!e?.connected||e.awaiting_plate_clear||e.ams?.some(e=>e.dry_time>0)?!1:[`IDLE`,`FINISH`,`FAILED`].includes(e.state??``),Fe=async()=>{if(E.scheduleType!==`asap`||M!==`printer`||g.length===0)return!1;try{return(await Promise.all(g.map(e=>d.fetchQuery({queryKey:[`printer-status`,e],queryFn:()=>Q.getPrinterStatus(e),staleTime:0})))).some(e=>!Pe(e))}catch{return!0}},{amsMapping:Ie}=uW(Ae,Me,O,Ne,ce?ve.get(ce):void 0),Le=nke(g,me,Ae,O,A,j,le?.prefer_lowest_filament,ve);(0,y.useEffect)(()=>{Te?.plates&&Te.plates.length>=1&&v.size===0&&b(new Set([Te.plates[0].index]))},[Te,v.size]),(0,y.useEffect)(()=>{if(e===`edit-queue-item`)return;let t=me?.filter(e=>e.is_active)||[];t.length===1&&g.length===0&&_([t[0].id])},[e,me,g.length]),(0,y.useEffect)(()=>{e===`edit-queue-item`?(JSON.stringify(g.sort())!==JSON.stringify(ee.sort())||x!==te)&&(k({}),j({}),oe(new Set)):(k({}),j({}),oe(new Set))},[e,g,x,ee,te]);let[Re,ze]=(0,y.useState)(P),[Be,Ve]=(0,y.useState)(x);(0,y.useEffect)(()=>{(P!==Re||x!==Be)&&(ze(P),Ve(x),(e!==`edit-queue-item`||Re!==null)&&(z({}),V({})))},[P,x,Re,Be,e]),(0,y.useEffect)(()=>{if(!le?.per_printer_mapping_expanded||g.length<=1)return;let e=g.filter(e=>{if(W.has(e))return!1;let t=Le.printerResults.find(t=>t.printerId===e);return t&&t.status&&!t.isLoading});e.length>0&&(oe(t=>{let n=new Set(t);return e.forEach(e=>n.add(e)),n}),e.forEach(e=>{Le.autoConfigurePrinter(e)}))},[le?.per_printer_mapping_expanded,g,W,Le]),(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!H&&o()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o,H]);let He=Te?.is_multi_plate??!1,Ue=Te?.plates??[],We=(0,y.useMemo)(()=>{let e=new Map;return ge&&ge.forEach(t=>{let n=t.ams_id===255,r=Rf(t.ams_id,t.tray_id,n),i=e.get(t.printer_id)??new Map;i.set(r,t),e.set(t.printer_id,i)}),e},[ge]),Ge=(0,y.useMemo)(()=>{if(!ie||ie.length===0)return``;let e=ie.map(e=>u(`printModal.insufficientFilamentLine`,{printer:e.printerName,slot:e.slotLabel,required:Math.round(e.requiredGrams),remaining:Math.round(e.remainingGrams)}));return[u(`printModal.insufficientFilamentMessage`),...e].join(`
+ `})]}),document.body)]})}function OU({isOpen:e,onClose:t,tagUid:n,trayUuid:r,printerId:i,amsId:a,trayId:o}){let{t:s}=$e(),c=no(),{showToast:l}=Ed(),[u,d]=(0,y.useState)(``),f=r||n,{data:p,isLoading:m}=q({queryKey:[`unlinked-spools`],queryFn:Q.getUnlinkedSpools,enabled:e}),h=(0,y.useMemo)(()=>p?p.filter(e=>{if(!u)return!0;let t=u.toLowerCase();return e.filament_name&&e.filament_name.toLowerCase().includes(t)||e.filament_vendor&&e.filament_vendor.toLowerCase().includes(t)||e.filament_material&&e.filament_material.toLowerCase().includes(t)||String(e.id).includes(t)}):[],[p,u]),g=J({mutationFn:e=>Q.linkSpool(e,{spoolTag:f,printerId:i,amsId:a,trayId:o}),onSuccess:()=>{c.invalidateQueries({queryKey:[`unlinked-spools`]}),c.invalidateQueries({queryKey:[`linked-spools`]}),c.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),l(s(`spoolman.linkSuccess`),`success`),t()},onError:e=>{l(e.message||s(`spoolman.linkFailed`),`error`)}});return e?(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 bg-bambu-dark-secondary rounded-xl shadow-xl w-full max-w-md mx-4 max-h-[80vh] flex flex-col border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-white/10`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Vc,{className:`w-5 h-5 text-bambu-green`}),s(`spoolman.selectSpool`)]}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[`AMS `,a,` T`,o,` · Printer #`,i]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(Bu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 border-b border-white/10`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Rl,{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:u,onChange:e=>d(e.target.value),placeholder:s(`inventory.searchSpools`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark rounded-lg border border-white/10 text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),(r||n)&&(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-2 font-mono truncate`,title:r||n,children:[`Tag: `,r||n]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 min-h-0`,children:m?(0,K.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):h.length===0?(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-8 text-sm`,children:s(`inventory.noSpoolsMatch`)}):h.map(e=>(0,K.jsxs)(`button`,{onClick:()=>g.mutate(e.id),disabled:g.isPending||!f,className:`w-full flex items-center gap-3 p-3 rounded-lg hover:bg-white/5 transition-colors text-left`,children:[(0,K.jsx)(`span`,{className:`w-6 h-6 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.filament_color_hex?`#${e.filament_color_hex}`:`#808080`}}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm text-white font-medium truncate`,children:e.filament_name||s(`spoolman.spoolId`)}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray truncate`,children:[e.filament_vendor?`${e.filament_vendor} · `:``,e.filament_material||`Unknown`,` · #`,e.id]})]}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.remaining_weight==null?`—`:`${Math.round(e.remaining_weight)}g`})]},e.id))}),(0,K.jsx)(`div`,{className:`p-4 border-t border-white/10 flex justify-end`,children:(0,K.jsx)($,{variant:`ghost`,onClick:t,children:s(`inventory.cancel`)||`Cancel`})})]})]}):null}function BOe(e,t){if(!t)return!0;let n=t.toLowerCase();return String(e.id).includes(n)||e.material.toLowerCase().includes(n)||(e.brand?.toLowerCase().includes(n)??!1)||(e.color_name?.toLowerCase().includes(n)??!1)||(e.subtype?.toLowerCase().includes(n)??!1)||(e.note?.toLowerCase().includes(n)??!1)||(e.slicer_filament_name?.toLowerCase().includes(n)??!1)||(e.storage_location?.toLowerCase().includes(n)??!1)}function kU(e,t){return t?e.filter(e=>BOe(e,t)):e}function AU({isOpen:e,onClose:t,printerId:n,amsId:r,trayId:i,trayInfo:a,spoolmanEnabled:o}){let{t:s}=$e(),c=no(),{showToast:l}=Ed(),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null);(0,y.useEffect)(()=>{p(null),h(null)},[u]);let[g,_]=(0,y.useState)(``),[v,b]=(0,y.useState)(null),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(null);(0,y.useEffect)(()=>{e&&d(!1)},[e]);let{data:T,isLoading:E}=q({queryKey:[`inventory-spools`,`assign-modal`],queryFn:()=>Q.getSpools(!0),enabled:e&&!o}),{data:D}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),enabled:e}),{data:O}=q({queryKey:[`settings`],queryFn:()=>Q.getSettings(),enabled:e}),{data:k,isLoading:A}=q({queryKey:[`spoolman-inventory-spools`,`assign-modal`],queryFn:()=>Q.getSpoolmanInventorySpools(!1),enabled:e&&!!o}),{data:j}=q({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:e&&!!o}),M=(0,y.useMemo)(()=>j?new Set(j.filter(e=>!(e.printer_id===n&&e.ams_id===r&&e.tray_id===i)).map(e=>e.spoolman_spool_id)):new Set,[j,n,r,i]),N=()=>{Q.refreshPrinterStatus(n).catch(()=>{}),c.invalidateQueries({queryKey:[`printerStatus`,n]})},P=J({mutationFn:e=>Q.assignSpool({spool_id:e,printer_id:n,ams_id:r,tray_id:i}),onSuccess:e=>{c.setQueryData([`spool-assignments`],t=>{let a=(t||[]).filter(e=>!(e.printer_id===n&&e.ams_id===r&&e.tray_id===i));return a.push(e),a}),c.invalidateQueries({queryKey:[`spool-assignments`]}),N(),l(s(e.pending_config?`inventory.assignPendingInsert`:`inventory.assignSuccess`),`success`),S(!1),b(null),w(null),t()},onError:e=>{l(`${s(`inventory.assignFailed`)}: ${e.message}`,`error`)}}),F=J({mutationFn:e=>Q.assignSpoolmanSlot({spoolman_spool_id:e,printer_id:n,ams_id:r,tray_id:i}),onSuccess:()=>{c.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),c.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),N(),l(s(`inventory.assignSuccess`),`success`),t()},onError:e=>{l(`${s(`inventory.assignFailed`)}: ${e.message}`,`error`)}}),I=e=>(e??``).trim().toUpperCase(),L=(e,t)=>{let n=I(e),r=I(t);return!n||!r?`none`:n===r?`exact`:r.includes(n)||n.includes(r)?`partial`:`none`},R=e=>e.split(`@`)[0].trim(),z=(e,t)=>{let n=R(I(e)),r=R(I(t));return!n||!r?!1:n===r};if(!e)return null;let B=new Set((D||[]).filter(e=>!(e.printer_id===n&&e.ams_id===r&&e.tray_id===i)).map(e=>e.spool_id)),V=T?.filter(e=>!e.archived_at&&(u||!B.has(e.id))),ee=V;if(!u){let e=R(I(a?.profile)),t=I(a?.material||a?.type);(e||t)&&(ee=ee?.filter(n=>{let r=R(I(n.slicer_filament_name||n.slicer_filament)),i=I(n.material);return e&&r&&r===e?!0:t&&i?i===t||t.includes(i)||i.includes(t):!r&&!i}))}g&&ee&&(ee=kU(ee,g));let te=()=>{if(m!==null){F.mutate(m);return}if(!f)return;let e=T?.find(e=>e.id===f);if(!e){l(s(`inventory.assignFailed`),`error`);return}if(!O?.disable_filament_warnings&&a){let t=a.material||a.type,n=L(e.material,t),r=e.slicer_filament_name||e.slicer_filament,i=a.profile||a.type,o=z(r,i);if(n!==`exact`){let a;a=n===`none`&&!o?`material_profile`:n===`partial`&&!o?`partial_profile`:n===`none`?`material`:`partial`,b(f),w({type:a,spoolMaterial:e.material||``,trayMaterial:t||``,spoolProfile:r||void 0,trayProfile:i||void 0}),S(!0);return}}P.mutate(f)},H=()=>{v&&(P.mutate(v),S(!1),b(null))};return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`fixed inset-0 z-[100] 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-2xl 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)(pl,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:s(`inventory.assignSpool`)})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(Bu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto`,children:[a&&(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:[s(`inventory.selectSpool`),`:`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a.color&&(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${a.color}`}}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:a.type||s(`ams.emptySlot`)}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,a.location,`)`]})]})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Rl,{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:g,onChange:e=>_(e.target.value),placeholder:s(`inventory.searchSpools`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[!o&&(E?(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`})}):ee&&ee.length>0?(0,K.jsx)(`div`,{className:`max-h-96 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2`,children:ee.map(e=>(0,K.jsxs)(`button`,{onClick:()=>{p(e.id),h(null)},title:e.note||void 0,className:`p-2.5 rounded-lg border text-left transition-colors ${f===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,K.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[e.rgba&&(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:Yd(e.rgba)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:e.color_name||``})]}),e.label_weight&&(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[Math.max(0,Math.round(e.label_weight-e.weight_used)),` / `,e.label_weight,`g`]}),e.note&&(0,K.jsx)(`p`,{className:`text-[10px] text-bambu-gray/70 mt-1 truncate`,title:e.note,children:e.note})]},e.id))}):V&&V.length===0?(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(`p`,{children:s(`inventory.noAvailableSpools`)}),T&&(0,K.jsxs)(`p`,{className:`text-[10px] mt-2 opacity-60`,children:[T.length,` fetched · `,T.filter(e=>e.archived_at).length,` archived ·`,` `,T.filter(e=>B.has(e.id)).length,` assigned to other slots`]})]}):(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(`p`,{children:s(`inventory.noSpoolsMatch`)}),V&&(0,K.jsxs)(`p`,{className:`text-[10px] mt-2 opacity-60`,children:[V.length,` unassigned spools — `,V.length-(ee?.length??0),` filtered by tray match. Try "Show all spools".`]})]})),o&&(0,K.jsx)(K.Fragment,{children:A?(0,K.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,K.jsx)(X,{className:`w-5 h-5 text-bambu-green animate-spin`})}):k&&k.filter(e=>!e.archived_at&&!M.has(e.id)).length>0?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide pt-1`,children:s(`inventory.spoolmanSpools`)}),(0,K.jsx)(`div`,{className:`max-h-64 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2`,children:kU(k.filter(e=>!e.archived_at&&!M.has(e.id)),g).map(e=>(0,K.jsxs)(`button`,{onClick:()=>{h(e.id),p(null)},title:e.note||void 0,className:`p-2.5 rounded-lg border text-left transition-colors ${m===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,K.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[e.rgba&&(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:Yd(e.rgba)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:e.color_name||``})]}),e.label_weight&&(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[Math.max(0,Math.round(e.label_weight-e.weight_used)),` / `,e.label_weight,`g`]}),e.note&&(0,K.jsx)(`p`,{className:`text-[10px] text-bambu-gray/70 mt-1 truncate`,title:e.note,children:e.note})]},`spoolman-${e.id}`))})]}):null})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between items-center p-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{id:`disable-filtering-toggle`,type:`checkbox`,checked:u,onChange:()=>d(e=>!e),className:`accent-bambu-green w-4 h-4 rounded focus:ring-0 border-bambu-dark-tertiary`}),(0,K.jsx)(`label`,{htmlFor:`disable-filtering-toggle`,className:`text-xs text-bambu-gray select-none cursor-pointer`,children:s(`inventory.showAllSpools`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,children:s(`common.cancel`)}),(0,K.jsx)($,{onClick:te,disabled:!f&&m===null||P.isPending||F.isPending,children:P.isPending||F.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),s(`inventory.assigning`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(pl,{className:`w-4 h-4`}),s(`inventory.assignSpool`)]})})]})]}),P.isError&&(0,K.jsx)(`div`,{className:`mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400`,children:P.error.message})]})]}),x&&a&&f&&C&&(()=>{let e=``;return C.type===`material`?e=s(`inventory.assignMismatchMessage`,{spoolMaterial:C.spoolMaterial,trayMaterial:C.trayMaterial,location:a.location}):C.type===`partial`?e=s(`inventory.assignPartialMismatchMessage`,{spoolMaterial:C.spoolMaterial,trayMaterial:C.trayMaterial,location:a.location}):C.type===`material_profile`?e=`${s(`inventory.assignMismatchMessage`,{spoolMaterial:C.spoolMaterial,trayMaterial:C.trayMaterial,location:a.location})}\n\n${s(`inventory.assignProfileMismatchMessage`,{spoolProfile:C.spoolProfile||s(`common.unknown`),trayProfile:C.trayProfile||s(`common.unknown`),location:a.location})}`:C.type===`partial_profile`&&(e=`${s(`inventory.assignPartialMismatchMessage`,{spoolMaterial:C.spoolMaterial,trayMaterial:C.trayMaterial,location:a.location})}\n\n${s(`inventory.assignProfileMismatchMessage`,{spoolProfile:C.spoolProfile||s(`common.unknown`),trayProfile:C.trayProfile||s(`common.unknown`),location:a.location})}`),e=`${e}\n\n${s(`inventory.assignReconfigureNote`)}`,(0,K.jsx)(jd,{title:s(`inventory.assignMismatchTitle`),message:e,confirmText:s(`inventory.assignMismatchConfirm`),variant:`warning`,overlayZIndex:`z-[110]`,isLoading:P.isPending,onConfirm:H,onCancel:()=>{P.isPending||(S(!1),b(null),w(null))}})})()]})}var VOe={bambuModelByShortCode:{}},jU={"A1 MINI":[`A1M`]};function MU(e,t){let n=e.toUpperCase(),r=t.toUpperCase();if(n===r)return!0;let i=jU[r];if(i&&i.includes(n))return!0;let a=jU[n];return!!(a&&a.includes(r))}function HOe(e){let t={};for(let[n,r]of Object.entries(e))r in t||(t[r]=n.replace(/^Bambu Lab\s+/,``));return t}function NU(e={}){return{bambuModelByShortCode:HOe(e)}}function PU(e){return e.replace(/\s+/g,``).toLowerCase()}var UOe=`0.4`;function FU(e){let t=e.match(/^(.*?)\s+([\d.]+)\s*nozzle\s*$/i);return t?{stripped:t[1].trim(),nozzle:t[2]}:{stripped:e.trim(),nozzle:null}}function WOe(e){let t=e.indexOf(`@BBL `);if(t<0)return null;let{stripped:n,nozzle:r}=FU(e.slice(t+5).trim());return n?{token:n,nozzle:r}:null}function GOe(e){let t=e.match(/^Bambu Lab\s+(.+)$/i);if(!t)return null;let{stripped:n,nozzle:r}=FU(t[1]);return n?{model:n,nozzle:r}:null}function KOe(e,t,n){let r=WOe(e);if(!r)return`unknown`;let i=n[r.token]??r.token,a=GOe(t);return a?PU(a.model)!==PU(i)&&!MU(r.token,a.model)||a.nozzle!==null&&(r.nozzle??UOe)!==a.nozzle?`mismatch`:`match`:`unknown`}function IU(e,t,n,r){if(!n)return`unknown`;let i=e.compatible_printers;return i&&i.length>0?i.includes(n)?`match`:`mismatch`:KOe(e.name,n,r.bambuModelByShortCode)}var LU=[`PLA`,`PETG`,`ABS`,`TPU`,`ASA`,`PC`,`PA`,`PVA`,`HIPS`,`PA-CF`,`PETG-CF`,`PLA-CF`],RU=[`Bambu`,`PolyLite`,`PolyTerra`,`eSUN`,`Overture`,`Fiberon`,`SUNLU`,`Inland`,`Hatchbox`,`Generic`],zU=`Basic.Matte.Silk.Silk+.Tough.Tough+.HF.High Flow.Engineering.CF.GF.Galaxy.Glow.Marble.Metal.Rainbow.Sparkle.Wood.Translucent.Transparent.Clear.Lite.Pro.Plus.Max.Super.Ultra.Flex.Soft.Hard.Strong.Impact.Heat Resistant.UV Resistant.ESD.Conductive.Magnetic.Gradient.Dual Color.Tri Color.Multicolor`.split(`.`),BU=[{name:`Black`,hex:`000000`},{name:`White`,hex:`FFFFFF`},{name:`Gray`,hex:`808080`},{name:`Red`,hex:`FF0000`},{name:`Orange`,hex:`FFA500`},{name:`Yellow`,hex:`FFFF00`},{name:`Green`,hex:`00AE42`},{name:`Blue`,hex:`0066FF`},{name:`Purple`,hex:`8B00FF`},{name:`Pink`,hex:`FF69B4`},{name:`Brown`,hex:`8B4513`},{name:`Silver`,hex:`C0C0C0`},{name:`Clear`,hex:`00000000`}],qOe=[{name:`Dark Red`,hex:`8B0000`},{name:`Crimson`,hex:`DC143C`},{name:`Coral`,hex:`FF7F50`},{name:`Salmon`,hex:`FA8072`},{name:`Dark Orange`,hex:`FF8C00`},{name:`Peach`,hex:`FFDAB9`},{name:`Gold`,hex:`FFD700`},{name:`Khaki`,hex:`F0E68C`},{name:`Lemon`,hex:`FFF44F`},{name:`Lime`,hex:`32CD32`},{name:`Forest Green`,hex:`228B22`},{name:`Olive`,hex:`808000`},{name:`Mint`,hex:`98FF98`},{name:`Teal`,hex:`008080`},{name:`Navy`,hex:`000080`},{name:`Sky Blue`,hex:`87CEEB`},{name:`Royal Blue`,hex:`4169E1`},{name:`Cyan`,hex:`00FFFF`},{name:`Turquoise`,hex:`40E0D0`},{name:`Violet`,hex:`EE82EE`},{name:`Magenta`,hex:`FF00FF`},{name:`Indigo`,hex:`4B0082`},{name:`Lavender`,hex:`E6E6FA`},{name:`Plum`,hex:`DDA0DD`},{name:`Hot Pink`,hex:`FF69B4`},{name:`Rose`,hex:`FF007F`},{name:`Blush`,hex:`FFB6C1`},{name:`Chocolate`,hex:`D2691E`},{name:`Tan`,hex:`D2B48C`},{name:`Beige`,hex:`F5F5DC`},{name:`Maroon`,hex:`800000`},{name:`Dark Gray`,hex:`404040`},{name:`Light Gray`,hex:`D3D3D3`},{name:`Charcoal`,hex:`36454F`},{name:`Ivory`,hex:`FFFFF0`},{name:`Bambu Green`,hex:`00AE42`},{name:`Jade White`,hex:`E8E8E8`},{name:`Titan Gray`,hex:`5A5A5A`}],VU=[...BU,...qOe],HU=`bambuddy-recent-colors`,JOe=[{code:`GFL00`,name:`Bambu PLA Basic`,displayName:`Bambu PLA Basic`,isCustom:!1,allCodes:[`GFL00`]},{code:`GFL01`,name:`Bambu PLA Matte`,displayName:`Bambu PLA Matte`,isCustom:!1,allCodes:[`GFL01`]},{code:`GFL05`,name:`Generic PLA`,displayName:`Generic PLA`,isCustom:!1,allCodes:[`GFL05`]},{code:`GFG00`,name:`Bambu PETG Basic`,displayName:`Bambu PETG Basic`,isCustom:!1,allCodes:[`GFG00`]},{code:`GFG05`,name:`Generic PETG`,displayName:`Generic PETG`,isCustom:!1,allCodes:[`GFG05`]},{code:`GFB00`,name:`Bambu ABS Basic`,displayName:`Bambu ABS Basic`,isCustom:!1,allCodes:[`GFB00`]},{code:`GFB05`,name:`Generic ABS`,displayName:`Generic ABS`,isCustom:!1,allCodes:[`GFB05`]},{code:`GFA00`,name:`Bambu ASA Basic`,displayName:`Bambu ASA Basic`,isCustom:!1,allCodes:[`GFA00`]},{code:`GFU00`,name:`Bambu TPU 95A`,displayName:`Bambu TPU 95A`,isCustom:!1,allCodes:[`GFU00`]},{code:`GFU05`,name:`Generic TPU`,displayName:`Generic TPU`,isCustom:!1,allCodes:[`GFU05`]},{code:`GFC00`,name:`Bambu PC Basic`,displayName:`Bambu PC Basic`,isCustom:!1,allCodes:[`GFC00`]},{code:`GFN00`,name:`Bambu PA Basic`,displayName:`Bambu PA Basic`,isCustom:!1,allCodes:[`GFN00`]},{code:`GFN05`,name:`Generic PA`,displayName:`Generic PA`,isCustom:!1,allCodes:[`GFN05`]},{code:`GFS00`,name:`Bambu PLA-CF`,displayName:`Bambu PLA-CF`,isCustom:!1,allCodes:[`GFS00`]},{code:`GFT00`,name:`Bambu PETG-CF`,displayName:`Bambu PETG-CF`,isCustom:!1,allCodes:[`GFT00`]},{code:`GFNC0`,name:`Bambu PA-CF`,displayName:`Bambu PA-CF`,isCustom:!1,allCodes:[`GFNC0`]},{code:`GFV00`,name:`Bambu PVA`,displayName:`Bambu PVA`,isCustom:!1,allCodes:[`GFV00`]}];function UU(e){let t=e.replace(/@.*$/,``).trim();t=t.replace(/\(Custom\)/i,``).trim(),t=t.replace(/^[#*]+\s*/,``).trim();let n=`PLA-CF.PETG-CF.ABS-GF.ASA-CF.PA-CF.PAHT-CF.PA6-CF.PA6-GF.PPA-CF.PPA-GF.PET-CF.PPS-CF.PC-CF.PC-ABS.ABS-GF.PCTG.PETG.PLA.ABS.ASA.PC.PA.TPU.PVA.HIPS.BVOH.PPS.PEEK.PEI`.split(`.`),r=``,i=-1;for(let e of n){let n=t.toUpperCase().indexOf(e.toUpperCase());if(n!==-1){r=e,i=n;break}}let a=``;i>0&&(a=t.substring(0,i).trim(),a=a.replace(/[-_\s]+$/,``));let o=``;i!==-1&&r&&(o=t.substring(i+r.length).trim(),o=o.replace(/^[-_\s]+/,``));let s=``;for(let e of zU)if(o.toLowerCase().includes(e.toLowerCase())){s=e;break}if(!s&&a)for(let e of zU){let t=RegExp(`\\s+${e}$`,`i`);if(t.test(a)){s=e,a=a.replace(t,``).trim();break}}return{brand:a,material:r,variant:s}}function WU(e,t){let n=new Set(RU);for(let t of e){let{brand:e}=UU(t.name);e&&e.length>1&&n.add(e)}if(t)for(let e of t)if(e.filament_vendor&&e.filament_vendor.length>1)n.add(e.filament_vendor);else{let{brand:t}=UU(e.name);t&&t.length>1&&n.add(t)}return Array.from(n).sort((e,t)=>e.localeCompare(t))}function YOe(e){let t=e.filter(e=>e.preset_type===`filament`);return t.length===0?[]:t.map(e=>{let t=String(e.id),n=e.filament_type||t,r=Array.from(new Set([t,n]));return{code:t,name:e.name,displayName:e.name,isCustom:!1,allCodes:r}}).sort((e,t)=>e.displayName.localeCompare(t.displayName))}function GU(e,t,n,r){let i=[],a=[],o=new Set;for(let n of e)if(n.is_custom){let e=n.name.toUpperCase();(t.size===0||Array.from(t).some(t=>e.includes(t))||!e.includes(`@`))&&(i.push({code:n.setting_id,name:n.name,displayName:`${n.name} (Custom)`,isCustom:!0,allCodes:[n.setting_id]}),o.add(n.setting_id))}else a.push({code:n.setting_id,name:n.name,displayName:n.name,isCustom:!1,allCodes:[n.setting_id]}),o.add(n.setting_id);let s=n&&n.length>0?YOe(n):[],c=[];if(r&&r.length>0)for(let e of r){let t=e.filament_id.startsWith(`GF`)?`GFS`+e.filament_id.slice(2):e.filament_id;o.has(e.filament_id)||o.has(t)||c.push({code:e.filament_id,name:e.name,displayName:e.name,isCustom:!1,allCodes:[e.filament_id,t]})}let l=[...i,...a,...s,...c];return l.length===0?JOe:l.sort((e,t)=>e.displayName.localeCompare(t.displayName))}function KU(e,t){if(!e)return;let n=t.find(t=>t.code===e);if(n||=t.find(t=>t.allCodes.includes(e)),!n){let r=e.toLowerCase();n=t.find(e=>e.code.toLowerCase()===r||e.allCodes.some(e=>e.toLowerCase()===r))}return n}function qU(){try{let e=localStorage.getItem(HU);if(e)return JSON.parse(e)}catch{}return[]}function JU(e,t){let n=[e,...t.filter(t=>t.hex.toUpperCase()!==e.hex.toUpperCase())].slice(0,8);try{localStorage.setItem(HU,JSON.stringify(n))}catch{}return n}function YU(e){if(!e)return``;let t=e.split(`_`)[0];return/^GFS/i.test(t)&&(t=t.slice(0,2)+t.slice(3)),t.toUpperCase()}function XU(e){return!!e&&/^GF[A-Z]99$/i.test(e)}function ZU(e,t){if(!t.material)return!1;let n=YU(t.slicer_filament),r=YU(e.filament_id);if(n&&r&&n===r&&!XU(r))return!0;let i=(e.name||``).replace(/^High Flow[_\s]+/i,``).replace(/^Standard[_\s]+/i,``).replace(/^HF[_\s]+/i,``).replace(/^S[_\s]+/i,``).trim(),a=UU(i);return!(a.material.toUpperCase()!==t.material.toUpperCase()||t.brand&&!(a.brand.toLowerCase().includes(t.brand.toLowerCase())||t.brand.toLowerCase().includes(a.brand.toLowerCase()))||t.subtype&&!(a.variant.toLowerCase().includes(t.subtype.toLowerCase())||t.subtype.toLowerCase().includes(a.variant.toLowerCase())||i.toLowerCase().includes(t.subtype.toLowerCase())))}function QU(e){let t=e.includes(`_`)?e.split(`_`)[0]:e;return t.startsWith(`GFS`)?`GF`+t.slice(3):(t.startsWith(`PFUS`)||t.startsWith(`PFSP`),t)}var $U=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`NYLON`,`PVA`,`HIPS`,`PP`,`PET`];function eW(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase(),r=n.match(/\bSUPPORT\s+FOR\s+/);if(r){let e=n.slice(r.index+r[0].length);for(let n of $U)if(RegExp(`\\b${n}\\b`).test(e))return{material:n,brand:t.slice(0,r.index).trim(),variant:`Support`}}for(let e of $U){let r=RegExp(`\\b${e}\\b`,`i`);if(r.test(n)){let n=t.split(r);return{material:e,brand:n[0]?.trim()||``,variant:n[1]?.trim()||``}}}let i=t.split(/\s+/);return i.length>=2?{material:i[1],brand:i[0],variant:i.slice(2).join(` `)}:{material:t,brand:``,variant:``}}function XOe(e){return!e.startsWith(`GF`)&&!e.startsWith(`P1`)}var ZOe={white:`FFFFFF`,black:`000000`,red:`FF0000`,green:`00FF00`,blue:`0000FF`,yellow:`FFFF00`,cyan:`00FFFF`,magenta:`FF00FF`,orange:`FFA500`,purple:`800080`,pink:`FFC0CB`,brown:`8B4513`,gray:`808080`,grey:`808080`,"jade white":`FFFEF2`,ivory:`FFFFF0`,beige:`F5F5DC`,cream:`FFFDD0`,silver:`C0C0C0`,gold:`FFD700`,bronze:`CD7F32`,copper:`B87333`,navy:`000080`,teal:`008080`,olive:`808000`,maroon:`800000`,coral:`FF7F50`,salmon:`FA8072`,lime:`32CD32`,mint:`98FF98`,"forest green":`228B22`,"sky blue":`87CEEB`,"royal blue":`4169E1`,turquoise:`40E0D0`,lavender:`E6E6FA`,violet:`EE82EE`,plum:`DDA0DD`,tan:`D2B48C`,chocolate:`D2691E`,charcoal:`36454F`,slate:`708090`,transparent:`000000`,natural:`F5F5DC`,wood:`DEB887`},tW=[{name:`White`,hex:`FFFFFF`},{name:`Black`,hex:`000000`},{name:`Red`,hex:`FF0000`},{name:`Blue`,hex:`0000FF`},{name:`Green`,hex:`00AA00`},{name:`Yellow`,hex:`FFFF00`},{name:`Orange`,hex:`FFA500`},{name:`Gray`,hex:`808080`}],nW=[{name:`Cyan`,hex:`00FFFF`},{name:`Magenta`,hex:`FF00FF`},{name:`Purple`,hex:`800080`},{name:`Pink`,hex:`FFC0CB`},{name:`Brown`,hex:`8B4513`},{name:`Beige`,hex:`F5F5DC`},{name:`Navy`,hex:`000080`},{name:`Teal`,hex:`008080`},{name:`Lime`,hex:`32CD32`},{name:`Gold`,hex:`FFD700`},{name:`Silver`,hex:`C0C0C0`},{name:`Maroon`,hex:`800000`},{name:`Olive`,hex:`808000`},{name:`Coral`,hex:`FF7F50`},{name:`Salmon`,hex:`FA8072`},{name:`Turquoise`,hex:`40E0D0`},{name:`Violet`,hex:`EE82EE`},{name:`Indigo`,hex:`4B0082`},{name:`Chocolate`,hex:`D2691E`},{name:`Tan`,hex:`D2B48C`},{name:`Slate`,hex:`708090`},{name:`Charcoal`,hex:`36454F`},{name:`Ivory`,hex:`FFFFF0`},{name:`Cream`,hex:`FFFDD0`}];function rW(e){return ZOe[e.toLowerCase().trim()]||null}function QOe(e){let t=e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`).replace(/\s+/g,`\\s+`);return RegExp(`\\b${t}\\b`,`i`)}function iW(e,t){let n=e.indexOf(`@`);if(n>=0){let r=e.slice(n+1).trim(),i=r.match(/^BBL\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);if(i)return i[1].trim();let a=r.match(/^Bambu Lab\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);if(a){let e=a[1].trim(),n=`Bambu Lab ${e}`;if(t[n])return t[n];let r=n.toLowerCase();for(let[e,n]of Object.entries(t))if(e.toLowerCase()===r)return n;return e}}let r=[],i=new Set;for(let[e,n]of Object.entries(t)){let t=e.replace(/^Bambu Lab\s+/,``),a=t.toLowerCase();i.has(a)||(r.push({token:t,short:n}),i.add(a));let o=n.toLowerCase();i.has(o)||(r.push({token:n,short:n}),i.add(o))}r.sort((e,t)=>t.token.length-e.token.length);for(let{token:t,short:n}of r)if(QOe(t).test(e))return n;return null}function aW({isOpen:e,onClose:t,printerId:n,slotInfo:r,nozzleDiameter:i=`0.4`,printerModel:a,onSuccess:o,fullScreen:s}){let{t:c}=$e(),[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)(``),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),w=(0,y.useRef)(``),{data:T,isLoading:E,isError:D}=q({queryKey:[`cloudSettings`],queryFn:()=>Q.getCloudSettings(),enabled:e,retry:!1}),{data:O}=q({queryKey:[`orcaCloudProfilesForAmsSlot`],queryFn:()=>Q.orcaCloudListProfiles(),enabled:e,retry:!1}),{data:k,isLoading:A}=q({queryKey:[`localPresets`],queryFn:()=>Q.getLocalPresets(),enabled:e}),{data:j,isLoading:M}=q({queryKey:[`builtinFilaments`],queryFn:()=>Q.getBuiltinFilaments(),enabled:e,staleTime:1/0}),{data:N,isLoading:P}=q({queryKey:[`kprofiles`,n,i],queryFn:()=>Q.getKProfiles(n,i),enabled:e&&!!n}),{data:F}=q({queryKey:[`colorCatalog`],queryFn:()=>Q.getColorCatalog(),enabled:e,staleTime:1/0}),{data:I}=q({queryKey:[`slicerPrinterModels`],queryFn:Q.getSlicerPrinterModels,enabled:e,staleTime:1/0}),L=(0,y.useMemo)(()=>NU(I??{}),[I]),R=(0,y.useMemo)(()=>{if(!a||!I)return null;for(let[e,t]of Object.entries(I))if(t===a)return`${e.startsWith(`Bambu Lab `)?e:`Bambu Lab ${e}`} ${i} nozzle`;return null},[a,I,i]),z=J({mutationFn:async()=>{if(!l)throw Error(`No filament preset selected`);let e=l.startsWith(`local_`),t=l.startsWith(`builtin_`),a=l.startsWith(`orca_`)?l.replace(`orca_`,``):l,o=!e&&!t?O?.filament.find(e=>e.setting_id===a):void 0,s=!!o,c=o??null,u=e?parseInt(l.replace(`local_`,``),10):null,f=t?l.replace(`builtin_`,``):null,m=e?k?.filament.find(e=>e.id===u):null,h=t?j?.find(e=>e.filament_id===f):null,g=!e&&!t&&!s?T?.filament.find(e=>e.setting_id===l):null;if(!e&&!t&&!s&&!g)throw Error(`Selected preset not found`);if(e&&!m)throw Error(`Selected local preset not found`);if(t&&!h)throw Error(`Selected builtin preset not found`);if(s&&!c)throw Error(`Selected Orca Cloud preset not found`);let _=e?m.name:t?h.name:s?c.name:g.name,v=eW(_),y=d?.slot_id??-1,b=p||r.trayColor?.slice(0,6)||`FFFFFF`,x=_.replace(/@.+$/,``).trim(),S,C,w=v.material.toUpperCase(),E={PLA:`GFL99`,"PLA-CF":`GFL98`,"PLA SILK":`GFL96`,"PLA HIGH SPEED":`GFL95`,PETG:`GFG99`,"PETG HF":`GFG96`,"PETG-CF":`GFG98`,PCTG:`GFG97`,ABS:`GFB99`,ASA:`GFB98`,PC:`GFC99`,PA:`GFN99`,"PA-CF":`GFN98`,NYLON:`GFN99`,TPU:`GFU99`,PVA:`GFS99`,HIPS:`GFS98`,PE:`GFP99`,PP:`GFP97`};if(e){let e=($U.includes(w)?w:m?.filament_type||v.material||``).toUpperCase();S=E[e]||E[e.replace(/[-\s]?CF$/,``)]||E[e.replace(/\+$/,``)]||E[e.split(/[-\s]/)[0]]||``,C=``}else if(s){let e=($U.includes(w)?w:v.material||``).toUpperCase();S=E[e]||E[e.replace(/[-\s]?CF$/,``)]||E[e.replace(/\+$/,``)]||E[e.split(/[-\s]/)[0]]||``,C=``}else if(t)S=f,C=``;else if(S=QU(l),C=l,!l.startsWith(`GFS`))try{let e=await Q.getCloudSettingDetail(l);e.filament_id&&(S=e.filament_id)}catch(e){console.warn(`Failed to fetch preset detail for filament_id:`,e)}let D=e&&m?.nozzle_temp_min?m.nozzle_temp_min:190,A=e&&m?.nozzle_temp_max?m.nozzle_temp_max:230;if(!e||t||s||!m?.nozzle_temp_min&&!m?.nozzle_temp_max){let t=(e?$U.includes(w)?w:m?.filament_type||v.material||``:v.material).toUpperCase();t.includes(`PLA`)?(D=190,A=230):t.includes(`PETG`)?(D=220,A=260):t.includes(`ABS`)||t.includes(`ASA`)?(D=240,A=280):t.includes(`TPU`)?(D=200,A=240):t===`PCTG`?(D=220,A=260):t.includes(`PC`)?(D=260,A=300):(t.includes(`PA`)||t.includes(`NYLON`))&&(D=250,A=290)}let M=d?.k_value?parseFloat(d.k_value):0,N=e?$U.includes(w)?w:m?.filament_type||v.material||`PLA`:s&&$U.includes(w)?w:v.material||`PLA`,P=await Q.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:S,tray_type:N,tray_sub_brands:x,tray_color:b+`FF`,nozzle_temp_min:D,nozzle_temp_max:A,cali_idx:y,nozzle_diameter:i,setting_id:C,kprofile_filament_id:d?.filament_id,kprofile_setting_id:d?.setting_id||void 0,k_value:M}),F=e?`local_${u}`:t?`builtin_${f}`:l,I=e?`local`:t?`builtin`:s?`orca_cloud`:`cloud`;try{await Q.saveSlotPreset(n,r.amsId,r.trayId,F,x,I)}catch(e){console.warn(`Failed to save slot preset mapping:`,e)}return P},onSuccess:()=>{x(!0),o?.(),setTimeout(()=>{x(!1),t()},1500)}}),B=J({mutationFn:async()=>Q.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{x(!0),o?.(),setTimeout(()=>{x(!1),t()},1500)}}),V=(0,y.useMemo)(()=>{let e=_.toLowerCase(),t=[],n=new Set,i=r.savedPresetId,o=r.trayInfoIdx;if(O?.filament)for(let r of O.filament){let i=`orca_${r.setting_id}`;if(n.add(r.setting_id),n.add(i),!(e&&!r.name.toLowerCase().includes(e))){if(a){let e=iW(r.name,I??{});if(e&&!MU(e,a))continue}t.push({id:i,name:r.name,source:`orca_cloud`,isUser:!0})}}if(T?.filament)for(let r of T.filament){if(n.has(r.setting_id))continue;n.add(r.setting_id);let s=i===r.setting_id||o&&(r.setting_id===o||QU(r.setting_id)===o);if(!(e&&!r.name.toLowerCase().includes(e))){if(!s&&a){let e=iW(r.name,I??{});if(e&&!MU(e,a))continue}t.push({id:r.setting_id,name:r.name,source:`cloud`,isUser:XOe(r.setting_id)})}}if(k?.filament){let n=r.savedPresetId;for(let r of k.filament){let i=`local_${r.id}`;if(!(e&&!r.name.toLowerCase().includes(e))){if(n!==i&&R){let e=null;if(r.compatible_printers)try{let t=JSON.parse(r.compatible_printers);Array.isArray(t)&&(e=t.filter(e=>typeof e==`string`))}catch{e=null}if(IU({name:r.name,compatible_printers:e},`filament`,R,L)===`mismatch`)continue}t.push({id:i,name:r.name,source:`local`,isUser:!1})}}}if(j)for(let r of j){if(n.has(r.filament_id))continue;let i=r.filament_id.startsWith(`GF`)?`GFS`+r.filament_id.slice(2):r.filament_id;n.has(i)||(!e||r.name.toLowerCase().includes(e))&&t.push({id:`builtin_${r.filament_id}`,name:r.name,source:`builtin`,isUser:!1})}return t.sort((e,t)=>{let n={local:0,orca_cloud:1,cloud:2,builtin:3};return e.source===t.source?e.isUser&&!t.isUser?-1:!e.isUser&&t.isUser?1:e.name.localeCompare(t.name):n[e.source]-n[t.source]})},[O?.filament,T?.filament,k?.filament,j,_,a,r.savedPresetId,r.trayInfoIdx,R,L,I]),ee=(0,y.useMemo)(()=>{if(!l)return null;let e=null,t=``;if(l.startsWith(`local_`)){let t=parseInt(l.replace(`local_`,``),10);e=k?.filament.find(e=>e.id===t)?.name||null}else if(l.startsWith(`builtin_`)){let n=l.replace(`builtin_`,``);e=j?.find(e=>e.filament_id===n)?.name||null,t=YU(n)}else{let n=l.startsWith(`orca_`)?l.replace(`orca_`,``):l,r=O?.filament.find(e=>e.setting_id===n);if(r)e=r.name;else if(T?.filament){let n=T.filament.find(e=>e.setting_id===l);e=n?.name||null,n&&(t=YU(n.setting_id))}}if(!e)return null;let n=e.replace(/@.+$/,``).trim();n.startsWith(`# `)&&(n=n.slice(2).trim());let r=eW(n);return{fullName:n,material:r.material,brand:r.brand,filamentId:t}},[l,T?.filament,k?.filament,j,O?.filament]),te=ee?.fullName||``,H=(0,y.useMemo)(()=>{if(!F||!ee)return[];let{fullName:e,brand:t}=ee,n=e.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,``).trim();return F.filter(e=>{let r=(e.material||``).toUpperCase(),i=e.manufacturer.toUpperCase();if(!(r===n.toUpperCase()||r.includes(n.toUpperCase())||n.toUpperCase().includes(r)))return!1;if(t){let e=t.toUpperCase();if(!i.includes(e)&&!e.includes(i))return!1}return!0})},[F,ee]),ne=(0,y.useMemo)(()=>{if(!N?.profiles)return[];if(!ee){let e=r.caliIdx;if(e!=null&&e>0){let t=N.profiles.find(t=>t.slot_id===e&&(r.extruderId===void 0||t.extruder_id===r.extruderId));if(t)return[t]}return[]}let{fullName:e,material:t,brand:n,filamentId:i}=ee,a=e.toUpperCase(),o=t.toUpperCase(),s=n.toUpperCase(),c=i;if(!o||o.length<2)return[];let l=N.profiles.filter(e=>{if(c){let t=YU(e.filament_id);if(t&&t===c&&!XU(t))return!0}let t=e.name.toUpperCase();if(s)return!(!t.includes(s)||!t.includes(o));if(t.includes(a)||t.includes(o))return!0;let n={NYLON:[`PA`,`PA-CF`,`PA6`],PA:[`NYLON`]}[o]||[];for(let e of n)if(t.includes(e))return!0;return!1}),u=new Map;for(let e of l){let t=`${e.name}|${e.k_value}`,n=u.get(t);n?r.extruderId!==void 0&&e.extruder_id===r.extruderId&&n.extruder_id!==r.extruderId&&u.set(t,e):u.set(t,e)}let d=Array.from(u.values()),f=r.caliIdx;if(f!=null&&f>0&&!d.some(e=>e.slot_id===f)){let e=N.profiles.find(e=>e.slot_id===f&&(r.extruderId===void 0||e.extruder_id===r.extruderId));e&&d.unshift(e)}return d},[N?.profiles,ee,r.extruderId,r.caliIdx]);(0,y.useEffect)(()=>{if(e){if(r.savedPresetId)u(r.savedPresetId);else if(r.trayInfoIdx&&T?.filament){let e=T.filament.find(e=>e.setting_id===r.trayInfoIdx);e||=T.filament.find(e=>QU(e.setting_id)===r.trayInfoIdx),e&&u(e.setting_id)}else if(r.trayInfoIdx&&j?.length){let e=r.trayInfoIdx,t=j.find(t=>t.filament_id===e);t&&u(`builtin_${t.filament_id}`)}if(r.trayColor){let e=r.trayColor.slice(0,6);e&&m(e)}}else u(``),f(null),m(``),g(``),v(``),x(!1),w.current=``},[e,r.savedPresetId,r.trayInfoIdx,r.trayColor,T?.filament,j]),(0,y.useEffect)(()=>{if(ne.length>0){if(r.caliIdx!=null&&r.caliIdx>0){let e=ne.find(e=>e.slot_id===r.caliIdx);if(e){f(e);return}}f(ne[0])}else f(null)},[l,ne,r.caliIdx]);let re=(0,y.useCallback)(e=>{e.key===`Escape`&&t()},[t]);(0,y.useEffect)(()=>{if(e)return document.addEventListener(`keydown`,re),()=>document.removeEventListener(`keydown`,re)},[e,re]);let U=E&&!D||A||M||P;if((0,y.useEffect)(()=>{if(!U&&l&&l!==w.current){let e=requestAnimationFrame(()=>{let e=document.querySelector(`[class*="fixed inset-0 z-50"]`)?.querySelector(`[data-preset-id="${CSS.escape(l)}"]`);e&&(w.current=l,e.scrollIntoView({block:`nearest`}))});return()=>cancelAnimationFrame(e)}},[l,U]),!e)return null;let ie=l&&!z.isPending,ae=p||r.trayColor?.slice(0,6)||`FFFFFF`;return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex ${s?``:`items-center justify-center`}`,children:[!s&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,K.jsxs)(`div`,{className:s?`relative w-full h-full bg-bambu-dark-secondary flex flex-col`:`relative w-full max-w-lg mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl`,children:[(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)(Hl,{className:`w-5 h-5 text-bambu-blue`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:c(`configureAmsSlot.title`)}),s&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 ml-4 text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`text-white/30`,children:`|`}),r.trayColor&&(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),(0,K.jsx)(`span`,{className:`text-white/70`,children:c(`configureAmsSlot.slotLabel`,{ams:jf(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&(0,K.jsxs)(`span`,{children:[`(`,r.traySubBrands,`)`]})]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(Bu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 overflow-y-auto ${s?`flex-1 min-h-0`:`space-y-4 max-h-[60vh]`}`,children:[b&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl`,children:(0,K.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,K.jsx)(ps,{className:`w-16 h-16 text-bambu-green mx-auto`}),(0,K.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:c(`configureAmsSlot.slotConfigured`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:c(`configureAmsSlot.settingsSentToPrinter`)})]})}),!s&&(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:c(`configureAmsSlot.configuringSlot`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r.trayColor&&(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:c(`configureAmsSlot.slotLabel`,{ams:jf(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,r.traySubBrands,`)`]})]})]}),U?(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`})}):s?(0,K.jsxs)(`div`,{className:`flex gap-4 h-full`,children:[(0,K.jsxs)(`div`,{className:`w-1/2 flex flex-col min-h-0`,children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[c(`configureAmsSlot.filamentProfile`),` `,(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsx)(`input`,{type:`text`,placeholder:c(`configureAmsSlot.searchPresets`),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 placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2 shrink-0`}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto space-y-1`,children:V.length===0?(0,K.jsx)(`p`,{className:`text-center py-4 text-bambu-gray`,children:T?.filament?.length===0&&!k?.filament?.length?c(`configureAmsSlot.noPresetsAvailable`):c(`configureAmsSlot.noMatchingPresets`)}):V.map(e=>(0,K.jsx)(`button`,{"data-preset-id":e.id,onClick:()=>u(e.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${l===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all`,title:e.name,children:e.name}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[e.source===`local`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400`,children:c(`profiles.localProfiles.badge`)}),e.source===`orca_cloud`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-purple-500/20 text-purple-400`,children:c(`configureAmsSlot.orcaCloud`)}),e.source===`cloud`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue`,children:c(`configureAmsSlot.bambuCloud`)}),e.source===`builtin`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400`,children:c(`configureAmsSlot.builtin`)})]})]})},e.id))})]}),(0,K.jsxs)(`div`,{className:`w-1/2 flex flex-col gap-4 min-h-0 overflow-y-auto`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[c(`configureAmsSlot.kProfileLabel`),te&&(0,K.jsx)(`span`,{className:`ml-2 text-xs text-bambu-blue`,children:c(`configureAmsSlot.filteringFor`,{material:te})})]}),ne.length>0?(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:d?.name||``,onChange:e=>{f(ne.find(t=>t.name===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 appearance-none pr-10`,children:[(0,K.jsx)(`option`,{value:``,children:c(`configureAmsSlot.noKProfile`)}),ne.map(e=>(0,K.jsxs)(`option`,{value:e.name,children:[e.name,` (K=`,e.k_value,`)`]},`${e.name}-${e.extruder_id}`))]}),(0,K.jsx)(rs,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}):l?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:c(`configureAmsSlot.noMatchingKProfiles`)}):(0,K.jsx)(`span`,{className:`inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30`,children:c(`configureAmsSlot.selectFilamentFirst`)}),d&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-green mt-1`,children:c(`configureAmsSlot.kFromCalibration`,{value:d.k_value})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:c(`configureAmsSlot.customColorLabel`)}),H.length>0&&(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1.5`,children:c(`configureAmsSlot.presetColors`,{name:ee?.fullName})}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:H.map(e=>(0,K.jsxs)(`button`,{onClick:()=>{m(e.hex_color.replace(`#`,``).toUpperCase()),g(e.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${p===e.hex_color.replace(`#`,``).toUpperCase()?`border-bambu-green scale-105`:`border-white/20 hover:border-white/40`}`,title:e.color_name,children:[(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.hex_color}}),(0,K.jsx)(`span`,{className:`text-xs text-white/80 whitespace-nowrap`,children:e.color_name})]},e.id))})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:[tW.map(e=>(0,K.jsx)(`button`,{onClick:()=>{m(e.hex),g(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex)),(0,K.jsx)(`button`,{onClick:()=>C(!S),className:`w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs`,title:c(S?`configureAmsSlot.showLessColors`:`configureAmsSlot.showMoreColors`),children:S?`−`:`+`})]}),S&&(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:nW.map(e=>(0,K.jsx)(`button`,{onClick:()=>{m(e.hex),g(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex))}),(0,K.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0`,style:{backgroundColor:`#${ae}`}}),(0,K.jsx)(`input`,{type:`text`,placeholder:c(`configureAmsSlot.colorPlaceholder`),value:h,onChange:e=>{let t=e.target.value;g(t);let n=rW(t);if(n)m(n);else{let e=t.replace(/[^0-9A-Fa-f]/g,``).toUpperCase();e.length===6?m(e):e.length===3&&m(e.split(``).map(e=>e+e).join(``))}},className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm`}),p&&(0,K.jsx)(`button`,{onClick:()=>{m(``),g(``)},className:`px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded`,title:c(`configureAmsSlot.clearCustomColor`),children:c(`configureAmsSlot.clear`)})]}),p&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5`,children:c(`configureAmsSlot.hexLabel`,{hex:p})})]})]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[c(`configureAmsSlot.filamentProfile`),` `,(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{type:`text`,placeholder:c(`configureAmsSlot.searchPresets`),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 placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2`}),(0,K.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:V.length===0?(0,K.jsx)(`p`,{className:`text-center py-4 text-bambu-gray`,children:T?.filament?.length===0&&!k?.filament?.length?c(`configureAmsSlot.noPresetsAvailable`):c(`configureAmsSlot.noMatchingPresets`)}):V.map(e=>(0,K.jsx)(`button`,{"data-preset-id":e.id,onClick:()=>u(e.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${l===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all`,title:e.name,children:e.name}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[e.source===`local`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400`,children:c(`profiles.localProfiles.badge`)}),e.source===`orca_cloud`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-purple-500/20 text-purple-400`,children:c(`configureAmsSlot.orcaCloud`)}),e.source===`cloud`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue`,children:c(`configureAmsSlot.bambuCloud`)}),e.source===`builtin`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400`,children:c(`configureAmsSlot.builtin`)})]})]})},e.id))})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[c(`configureAmsSlot.kProfileLabel`),te&&(0,K.jsx)(`span`,{className:`ml-2 text-xs text-bambu-blue`,children:c(`configureAmsSlot.filteringFor`,{material:te})})]}),ne.length>0?(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:d?.name||``,onChange:e=>{f(ne.find(t=>t.name===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 appearance-none pr-10`,children:[(0,K.jsx)(`option`,{value:``,children:c(`configureAmsSlot.noKProfile`)}),ne.map(e=>(0,K.jsxs)(`option`,{value:e.name,children:[e.name,` (K=`,e.k_value,`)`]},`${e.name}-${e.extruder_id}`))]}),(0,K.jsx)(rs,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}):l?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:c(`configureAmsSlot.noMatchingKProfiles`)}):(0,K.jsx)(`span`,{className:`inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30`,children:c(`configureAmsSlot.selectFilamentFirst`)}),d&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-green mt-1`,children:c(`configureAmsSlot.kFromCalibration`,{value:d.k_value})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:c(`configureAmsSlot.customColorLabel`)}),H.length>0&&(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1.5`,children:c(`configureAmsSlot.presetColors`,{name:ee?.fullName})}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:H.map(e=>(0,K.jsxs)(`button`,{onClick:()=>{m(e.hex_color.replace(`#`,``).toUpperCase()),g(e.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${p===e.hex_color.replace(`#`,``).toUpperCase()?`border-bambu-green scale-105`:`border-white/20 hover:border-white/40`}`,title:e.color_name,children:[(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.hex_color}}),(0,K.jsx)(`span`,{className:`text-xs text-white/80 whitespace-nowrap`,children:e.color_name})]},e.id))})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:[tW.map(e=>(0,K.jsx)(`button`,{onClick:()=>{m(e.hex),g(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex)),(0,K.jsx)(`button`,{onClick:()=>C(!S),className:`w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs`,title:c(S?`configureAmsSlot.showLessColors`:`configureAmsSlot.showMoreColors`),children:S?`−`:`+`})]}),S&&(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:nW.map(e=>(0,K.jsx)(`button`,{onClick:()=>{m(e.hex),g(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex))}),(0,K.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0`,style:{backgroundColor:`#${ae}`}}),(0,K.jsx)(`input`,{type:`text`,placeholder:c(`configureAmsSlot.colorPlaceholder`),value:h,onChange:e=>{let t=e.target.value;g(t);let n=rW(t);if(n)m(n);else{let e=t.replace(/[^0-9A-Fa-f]/g,``).toUpperCase();e.length===6?m(e):e.length===3&&m(e.split(``).map(e=>e+e).join(``))}},className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm`}),p&&(0,K.jsx)(`button`,{onClick:()=>{m(``),g(``)},className:`px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded`,title:c(`configureAmsSlot.clearCustomColor`),children:c(`configureAmsSlot.clear`)})]}),p&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5`,children:c(`configureAmsSlot.hexLabel`,{hex:p})})]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>B.mutate(),disabled:B.isPending||z.isPending,className:`text-red-400 hover:text-red-300 hover:bg-red-500/10`,children:B.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),c(`configureAmsSlot.resetting`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Al,{className:`w-4 h-4`}),c(`configureAmsSlot.resetSlot`)]})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,children:c(`configureAmsSlot.cancel`)}),(0,K.jsx)($,{onClick:()=>z.mutate(),disabled:!ie,children:z.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),c(`configureAmsSlot.configuring`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Hl,{className:`w-4 h-4`}),c(`configureAmsSlot.configureSlot`)]})})]})]}),(z.isError||B.isError)&&(0,K.jsx)(`div`,{className:`mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400`,children:z.error?.message||B.error?.message})]})]})}function oW({className:e=`w-4 h-4`}){return(0,K.jsx)(`svg`,{viewBox:`0 0 1945 1370`,fill:`none`,className:e,"aria-hidden":`true`,children:(0,K.jsxs)(`g`,{transform:`translate(-754.293 -471.685)`,children:[(0,K.jsxs)(`g`,{transform:`translate(0.18191 255.976)`,children:[(0,K.jsx)(`g`,{transform:`matrix(1.05469 0 0 0.241063 -153.484 1120.2)`,children:(0,K.jsx)(`rect`,{x:`922.048`,y:`1195.15`,width:`1721.5`,height:`470.135`,stroke:`currentColor`,strokeOpacity:`0.99`,strokeWidth:`168.84`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,K.jsx)(`g`,{transform:`matrix(0.983656 0 0 1.0767 -62.2035 141.539)`,children:(0,K.jsx)(`path`,{d:`M2741.42,1175.93L895.832,1175.93L1125.16,621.902L2512.09,621.902L2741.42,1175.93Z`,fill:`currentColor`,fillOpacity:`0.05`,stroke:`currentColor`,strokeOpacity:`0.99`,strokeWidth:`125.26`,strokeLinecap:`round`,strokeLinejoin:`round`})})]}),(0,K.jsx)(`g`,{transform:`translate(21.1916 0.684817)`,children:(0,K.jsx)(`path`,{d:`M1981.31,567.518C1954.86,567.518 1933.39,546.047 1933.39,519.601C1933.39,493.156 1954.86,471.685 1981.31,471.685L2146.61,471.685C2173.07,471.685 2194.53,493.138 2194.53,519.601L2194.53,688.741C2194.53,715.187 2173.05,736.658 2146.61,736.658C2120.16,736.658 2098.69,715.187 2098.69,688.741L2098.69,567.518L1981.31,567.518ZM2098.69,1252.54C2098.69,1226.1 2120.16,1204.62 2146.61,1204.62C2173.05,1204.62 2194.53,1226.1 2194.53,1252.54L2194.53,1421.68C2194.53,1448.14 2173.07,1469.6 2146.61,1469.6L1981.31,1469.6C1954.86,1469.6 1933.39,1448.13 1933.39,1421.68C1933.39,1395.24 1954.86,1373.76 1981.31,1373.76L2098.69,1373.76L2098.69,1252.54ZM1430.29,1373.76C1456.74,1373.76 1478.21,1395.24 1478.21,1421.68C1478.21,1448.13 1456.74,1469.6 1430.29,1469.6L1264.99,1469.6C1238.53,1469.6 1217.07,1448.14 1217.07,1421.68L1217.07,1252.54C1217.07,1226.1 1238.55,1204.62 1264.99,1204.62C1291.44,1204.62 1312.91,1226.1 1312.91,1252.54L1312.91,1373.76L1430.29,1373.76ZM1312.91,688.741C1312.91,715.187 1291.44,736.658 1264.99,736.658C1238.55,736.658 1217.07,715.187 1217.07,688.741L1217.07,519.601C1217.07,493.138 1238.53,471.685 1264.99,471.685L1430.29,471.685C1456.74,471.685 1478.21,493.156 1478.21,519.601C1478.21,546.047 1456.74,567.518 1430.29,567.518L1312.91,567.518L1312.91,688.741Z`,fill:`currentColor`,fillOpacity:`0.99`})})]})})}function sW({folderId:e,onClose:t,onUploadComplete:n,onFileUploaded:r,autoUpload:i,validateFile:a,accept:o,initialFiles:s}){let{t:c}=$e(),[l,u]=(0,y.useState)([]),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!0),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!0),[S,C]=(0,y.useState)(null),w=(0,y.useRef)(null),T=e=>{e.preventDefault(),f(!0)},E=e=>{e.preventDefault(),f(!1)},D=e=>{e.preventDefault(),f(!1),j(Array.from(e.dataTransfer.files))},O=e=>{e.target.files&&j(Array.from(e.target.files))},k=(e,t)=>{u(n=>n.map(n=>n.file===e?{...n,...t}:n))},A=async i=>{m(!0);for(let t of i)if(t.status===`pending`){k(t.file,{status:`uploading`});try{if(t.isZip){let n=await Q.extractZipFile(t.file,e,h,_,b);k(t.file,{status:n.errors.length>0&&n.extracted===0?`error`:`success`,extractedCount:n.extracted,error:n.errors.length>0?c(`fileManager.zipFilesFailed`,`{{count}} files failed`,{count:n.errors.length}):void 0})}else{let n=await Q.uploadLibraryFile(t.file,e,b);k(t.file,{status:`success`});let i=r?.(n);if(i){C(i),u([]),m(!1);return}}}catch(e){k(t.file,{status:`error`,error:e instanceof Error?e.message:c(`fileManager.uploadFailed`,`Upload failed`)})}}m(!1),n(),u(e=>(e.some(e=>e.status===`error`)||t(),e))},j=e=>{if(C(null),a)for(let t of e){let e=a(t);if(e){C(e);return}}let t=e.map(e=>({file:e,status:`pending`,isZip:e.name.toLowerCase().endsWith(`.zip`),is3mf:e.name.toLowerCase().endsWith(`.3mf`)}));u(e=>[...e,...t]),i&&e.length>0&&A(t)},M=e=>{u(t=>t.filter((t,n)=>n!==e))},N=(0,y.useRef)(!1);(0,y.useEffect)(()=>{N.current||!s||s.length===0||(N.current=!0,j(s))},[]);let P=l.some(e=>e.isZip&&e.status===`pending`),F=l.some(e=>e.file.name.toLowerCase().endsWith(`.stl`)&&e.status===`pending`),I=l.some(e=>e.is3mf&&e.status===`pending`),L=l.filter(e=>e.status===`pending`).length,R=l.length>0&&L===0&&!p;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-lg 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.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:c(`fileManager.uploadFiles`)}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,K.jsx)(Bu,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,K.jsxs)(`div`,{onDragOver:T,onDragLeave:E,onDrop:D,onClick:()=>w.current?.click(),className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${d?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,children:[(0,K.jsx)(Du,{className:`w-10 h-10 mx-auto mb-3 ${d?`text-bambu-green`:`text-bambu-gray`}`}),(0,K.jsx)(`p`,{className:`text-white font-medium`,children:c(d?`fileManager.dropFilesHere`:`fileManager.dragDropFiles`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:c(`fileManager.orClickToBrowse`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-2`,children:c(`fileManager.allFileTypesSupported`)})]}),(0,K.jsx)(`input`,{ref:w,type:`file`,multiple:!0,accept:o,className:`hidden`,onChange:O}),P&&(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 items-start gap-3`,children:[(0,K.jsx)(Oo,{className:`w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-blue-300 font-medium`,children:c(`fileManager.zipFilesDetected`)}),(0,K.jsx)(`p`,{className:`text-xs text-blue-300/70 mt-1`,children:c(`fileManager.zipExtractOptions`)}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 mt-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`w-4 h-4 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:c(`fileManager.preserveZipStructure`)})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 mt-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`w-4 h-4 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:c(`fileManager.createFolderFromZip`)})]})]})]})}),I&&(0,K.jsx)(`div`,{className:`p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(Tl,{className:`w-5 h-5 text-purple-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-purple-300 font-medium`,children:c(`fileManager.threemfDetected`)}),(0,K.jsx)(`p`,{className:`text-xs text-purple-300/70 mt-1`,children:c(`fileManager.threemfExtractionInfo`)})]})]})}),(F||P)&&(0,K.jsx)(`div`,{className:`p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(jc,{className:`w-5 h-5 text-bambu-green mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-green font-medium`,children:c(`fileManager.stlThumbnailGeneration`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-green/70 mt-1`,children:c(P&&!F?`fileManager.zipMayContainStl`:`fileManager.thumbnailsCanBeGenerated`)}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 mt-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>x(e.target.checked),className:`w-4 h-4 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:c(`fileManager.generateThumbnailsForStl`)})]})]})]})}),l.length>0&&(0,K.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-2`,children:l.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-2 bg-bambu-dark rounded-lg`,children:[e.isZip?(0,K.jsx)(Oo,{className:`w-4 h-4 text-blue-400 flex-shrink-0`}):(0,K.jsx)(nc,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.file.name}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[(e.file.size/1024/1024).toFixed(2),` MB`,e.isZip&&e.status===`pending`&&(0,K.jsxs)(`span`,{className:`text-blue-400 ml-2`,children:[`• `,c(`fileManager.willBeExtracted`)]}),e.extractedCount!==void 0&&(0,K.jsxs)(`span`,{className:`text-green-400 ml-2`,children:[`• `,c(`fileManager.filesExtracted`,{count:e.extractedCount})]})]}),e.status===`error`&&e.error&&(0,K.jsx)(`p`,{className:`text-xs text-red-400 mt-1 break-words`,children:e.error})]}),e.status===`pending`&&(0,K.jsx)(`button`,{onClick:()=>M(t),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,K.jsx)(Bu,{className:`w-4 h-4 text-bambu-gray`})}),e.status===`uploading`&&(0,K.jsx)(X,{className:`w-4 h-4 text-bambu-green animate-spin`}),e.status===`success`&&(0,K.jsx)(fs,{className:`w-4 h-4 text-green-500`}),e.status===`error`&&(0,K.jsx)(`span`,{title:e.error,children:(0,K.jsx)(vs,{className:`w-4 h-4 text-red-500`})})]},t))}),S&&(0,K.jsx)(`div`,{className:`p-3 bg-red-500/10 border border-red-500/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(vs,{className:`w-5 h-5 text-red-400 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`p`,{className:`text-sm text-red-300`,children:S})]})})]}),(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:t,children:c(`common.cancel`)}),!R&&(0,K.jsx)($,{onClick:()=>A(l),disabled:L===0||p,children:p?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 mr-2 animate-spin`}),c(`fileManager.uploading`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Du,{className:`w-4 h-4 mr-2`}),c(`common.upload`),` `,L>0?`(${L})`:``]})})]})]})})}function cW(e){let t=[],n=e?.ams_extruder_map,r=!!e?.nozzles?.[1]?.nozzle_diameter||n&&Object.keys(n).length>0||(e?.vt_tray?.length??0)>1;e?.ams?.forEach(e=>{let r=e.tray.length===1;e.tray.forEach(i=>{if(i.tray_type){let a=kf(i.tray_color);t.push({type:i.tray_type,color:a,colorName:Kd(a),amsId:e.id,trayId:i.id,isHt:r,isExternal:!1,label:Lf(e.id,i.id,r,!1),globalTrayId:Rf(e.id,i.id,!1),trayInfoIdx:i.tray_info_idx||``,traySubBrands:i.tray_sub_brands||``,extruderId:n?.[String(e.id)],remain:i.remain??-1})}})});for(let n of e?.vt_tray??[])if(n.tray_type){let i=kf(n.tray_color),a=n.id??254,o=(e?.vt_tray?.length??0)>1;t.push({type:n.tray_type,color:i,colorName:Kd(i),amsId:-1,trayId:a-254,isHt:!1,isExternal:!0,label:o?a===254?`Ext-L`:`Ext-R`:`External`,globalTrayId:a,trayInfoIdx:n.tray_info_idx||``,traySubBrands:n.tray_sub_brands||``,extruderId:r?255-a:void 0,remain:n.remain??-1})}return t}function lW(e,t,n,r){if(!e?.filaments||e.filaments.length===0)return;let i=cW(t);if(i.length===0)return;let a=t?.fila_switch?.installed===!0,o=new Set,s=e.filaments.map(e=>{let t=e.tray_info_idx||``,s=i.filter(e=>!o.has(e.globalTrayId));e.nozzle_id!=null&&!a&&(s=s.filter(t=>t.extruderId===e.nozzle_id)),n&&(s=[...s].sort((e,t)=>qf(Kf(e,r),Kf(t,r))));let c,l,u,d;if(t){let i=s.filter(e=>e.trayInfoIdx===t);i.length===1?c=i[0]:i.length>1&&(n&&i.sort((e,t)=>qf(Kf(e,r),Kf(t,r))),l=i.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&Af(t.color)===Af(e.color)),l||(u=i.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&If(t.color,e.color))),!l&&!u&&(d=i.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase())))}!c&&!l&&!u&&!d&&(l=s.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&Af(t.color)===Af(e.color)),l||(u=s.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&If(t.color,e.color))),!l&&!u&&(d=s.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase())));let f=c||l||u||d||void 0;return f&&o.add(f.globalTrayId),{slot_id:e.slot_id,globalTrayId:f?.globalTrayId??-1}}),c=Math.max(...s.map(e=>e.slot_id||0));if(c<=0)return;let l=Array(c).fill(-1);return s.forEach(e=>{e.slot_id&&e.slot_id>0&&(l[e.slot_id-1]=e.globalTrayId)}),l}function $Oe(e){return(0,y.useMemo)(()=>cW(e),[e])}function uW(e,t,n,r,i){let a=$Oe(t),o=t?.fila_switch?.installed===!0,s=(0,y.useMemo)(()=>{if(!e?.filaments||e.filaments.length===0)return[];let t=new Set(Object.values(n));return e.filaments.map(e=>{let s=e.slot_id||0;if(s>0&&n[s]!==void 0){let t=n[s],r=a.find(e=>e.globalTrayId===t);if(r){let t=r.type?.toUpperCase()===e.type?.toUpperCase(),n=Af(r.color)===Af(e.color)||If(r.color,e.color),i;return i=t&&n?`match`:t?`type_only`:`mismatch`,{...e,loaded:r,hasFilament:!0,typeMatch:t,colorMatch:n,status:i,isManual:!0}}}let c=e.tray_info_idx||``,l=a.filter(e=>!t.has(e.globalTrayId));e.nozzle_id!=null&&!o&&(l=l.filter(t=>t.extruderId===e.nozzle_id)),r&&(l=[...l].sort((e,t)=>qf(Kf(e,i),Kf(t,i))));let u,d,f,p;if(c){let t=l.filter(e=>e.trayInfoIdx===c);t.length===1?u=t[0]:t.length>1&&(r&&t.sort((e,t)=>qf(Kf(e,i),Kf(t,i))),d=t.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&Af(t.color)===Af(e.color)),d||(f=t.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&If(t.color,e.color))),!d&&!f&&(p=t.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase())))}!u&&!d&&!f&&!p&&(d=l.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&Af(t.color)===Af(e.color)),d||(f=l.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&If(t.color,e.color))),!d&&!f&&(p=l.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase())));let m=u||d||f||p||void 0;m&&t.add(m.globalTrayId);let h=!!m,g=h,_=!!u||!!d||!!f,v;return v=u||d||f?`match`:p?`type_only`:`mismatch`,{...e,loaded:m,hasFilament:h,typeMatch:g,colorMatch:_,status:v,isManual:!1}})},[e,a,n,r,o,i]);return{loadedFilaments:a,filamentComparison:s,amsMapping:(0,y.useMemo)(()=>{if(s.length===0)return;let e=Math.max(...s.map(e=>e.slot_id||0));if(e<=0)return;let t=Array(e).fill(-1);return s.forEach(e=>{e.slot_id&&e.slot_id>0&&(t[e.slot_id-1]=e.loaded?.globalTrayId??-1)}),t},[s]),hasTypeMismatch:s.some(e=>e.status===`mismatch`),hasColorMismatch:s.some(e=>e.status===`type_only`)}}function eke(e,t,n,r,i){if(!e||e.length===0)return{exactMatches:0,typeOnlyMatches:0,missingTypes:0,totalSlots:0,status:`full`};let a=0,o=0,s=0,c=new Set(Object.values(n));for(let l of e){let e=l.slot_id||0;if(e>0&&n[e]!==void 0){let r=n[e],i=t.find(e=>e.globalTrayId===r);if(i){let e=i.type?.toUpperCase()===l.type?.toUpperCase(),t=Af(i.color)===Af(l.color)||If(i.color,l.color);e&&t?a++:e?o++:s++;continue}}let u=t.filter(e=>!c.has(e.globalTrayId));if(l.nozzle_id!=null){let e=u.filter(e=>e.extruderId===l.nozzle_id);e.length>0&&(u=e)}r&&(u=[...u].sort((e,t)=>qf(Kf(e,i),Kf(t,i))));let d=u.find(e=>e.type?.toUpperCase()===l.type?.toUpperCase()&&Af(e.color)===Af(l.color)),f=d?void 0:u.find(e=>e.type?.toUpperCase()===l.type?.toUpperCase()&&If(e.color,l.color)),p=d||f?void 0:u.find(e=>e.type?.toUpperCase()===l.type?.toUpperCase()),m=d??f??p;m&&c.add(m.globalTrayId),d||f?a++:p?o++:s++}let l=e.length,u=`full`;return s>0?u=`missing`:o>0&&(u=`partial`),{exactMatches:a,typeOnlyMatches:o,missingTypes:s,totalSlots:l,status:u}}function tke(e,t,n,r,i){if(!e?.filaments||e.filaments.length===0)return;let a=cW(t);if(a.length===0)return;let o=new Set(Object.values(n)),s=[];for(let t of e.filaments){let e=t.slot_id||0;if(e>0&&n[e]!==void 0){s.push({slot_id:e,globalTrayId:n[e]});continue}let c=a.filter(e=>!o.has(e.globalTrayId));if(t.nozzle_id!=null){let e=c.filter(e=>e.extruderId===t.nozzle_id);e.length>0&&(c=e)}r&&(c=[...c].sort((e,t)=>qf(Kf(e,i),Kf(t,i))));let l=c.find(e=>e.type?.toUpperCase()===t.type?.toUpperCase()&&Af(e.color)===Af(t.color)),u=l?void 0:c.find(e=>e.type?.toUpperCase()===t.type?.toUpperCase()&&If(e.color,t.color)),d=l||u?void 0:c.find(e=>e.type?.toUpperCase()===t.type?.toUpperCase()),f=l??u??d;f&&o.add(f.globalTrayId),s.push({slot_id:e,globalTrayId:f?.globalTrayId??-1})}let c=Math.max(...s.map(e=>e.slot_id||0));if(c<=0)return;let l=Array(c).fill(-1);return s.forEach(e=>{e.slot_id&&e.slot_id>0&&(l[e.slot_id-1]=e.globalTrayId)}),l}var dW={useDefault:!0,manualMappings:{},autoConfigured:!1};function nke(e,t,n,r,i,a,o,s){let c=_o({queries:e.map(t=>({queryKey:[`printer-status`,t],queryFn:()=>Q.getPrinterStatus(t),enabled:e.length>0,staleTime:5e3}))}),l=(0,y.useMemo)(()=>e.map((e,a)=>{let l=c[a],u=l?.data,d=t?.find(t=>t.id===e)?.name||`Printer ${e}`,f=cW(u),p=i[e]||dW,m=s?.get(e),h=Jf(o,u?.ams_filament_backup),g=lW(n,u,h,m),_=p.useDefault?r:p.manualMappings,v=tke(n,u,_,h,m),y=eke(n?.filaments,f,_,h,m);return{printerId:e,printerName:d,status:u,isLoading:l?.isLoading??!1,loadedFilaments:f,autoMapping:g,finalMapping:v,matchStatus:y.status,exactMatches:y.exactMatches,typeOnlyMatches:y.typeOnlyMatches,missingTypes:y.missingTypes,totalSlots:y.totalSlots,config:p,inventoryByTrayId:m}}),[e,c,t,n,i,r,o,s]),u=c.some(e=>e.isLoading),d=(e,t)=>{a(n=>({...n,[e]:{...n[e]||dW,...t}}))},f=e=>{let t=l.find(t=>t.printerId===e);if(!t||!t.status||!n?.filaments)return;let r=lW(n,t.status,Jf(o,t.status?.ams_filament_backup),s?.get(e));if(!r)return;let i={};r.forEach((e,t)=>{e!==-1&&(i[t+1]=e)}),d(e,{useDefault:!1,manualMappings:i,autoConfigured:!0})};return{printerResults:l,isLoading:u,perPrinterConfigs:i,updatePrinterConfig:d,autoConfigureAll:()=>{for(let t of e)f(t)},autoConfigurePrinter:f,getFinalMapping:e=>l.find(t=>t.printerId===e)?.finalMapping,allPrintersReady:l.every(e=>e.matchStatus!==`missing`)}}var fW=`/img/bed`,rke={"cool plate":{icon:`${fW}/bed_cool.png`,label:`Cool Plate`},"pc plate":{icon:`${fW}/bed_cool.png`,label:`Cool Plate`},"cool plate (supertack)":{icon:`${fW}/bed_cool_supertack.png`,label:`Cool Plate SuperTack`},"supertack plate":{icon:`${fW}/bed_cool_supertack.png`,label:`Cool Plate SuperTack`},"bambu cool plate supertack":{icon:`${fW}/bed_cool_supertack.png`,label:`Cool Plate SuperTack`},"engineering plate":{icon:`${fW}/bed_engineering.png`,label:`Engineering Plate`},"high temp plate":{icon:`${fW}/bed_high_templ.png`,label:`High Temp Plate`},"textured pei plate":{icon:`${fW}/bed_pei.png`,label:`Textured PEI Plate`},"pei plate":{icon:`${fW}/bed_pei.png`,label:`PEI Plate`},"smooth pei plate":{icon:`${fW}/bed_pei_cool.png`,label:`Smooth PEI Plate`}};function pW(e){return e?rke[e.trim().toLowerCase()]??null:null}function ike(e){let t=e.trim().split(/\s+/);return t.length<=1?e.trim():t.slice(1).join(` `)}function mW(e){let{data:t}=q({queryKey:[`builtin-filaments`],queryFn:()=>Q.getBuiltinFilaments(),staleTime:300*1e3}),{data:n}=q({queryKey:[`filament-id-map`],queryFn:()=>Q.getFilamentIdMap(),staleTime:300*1e3}),r=(0,y.useMemo)(()=>{let e={};for(let n of t||[])n.filament_id&&(e[n.filament_id]=n.name);for(let[t,r]of Object.entries(n||{}))t&&r&&(e[t]=r);return e},[t,n]),i=(0,y.useMemo)(()=>(e||[]).map(e=>{let t=e.tray_info_idx&&r[e.tray_info_idx]||e.type;return{resolvedName:t,materialHint:ike(t),color:e.color}}),[e,r]),a=_o({queries:i.map(({color:e,materialHint:t})=>({queryKey:[`color-by-material`,e,t],queryFn:()=>Q.getColorByMaterial(e,t),enabled:!!e,staleTime:300*1e3}))});return i.map(({resolvedName:e,color:t},n)=>({resolvedName:e,colorLabel:(a[n]?.data?.color_name??null)||Kd(t)}))}function ake({printerId:e,filamentReqs:t,manualMappings:n,onManualMappingChange:r,currencySymbol:i,defaultCostPerKg:a,defaultExpanded:o=!1,forceColorMatch:s,onForceColorMatchChange:c}){let{t:l}=$e(),u=no(),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(o),{data:h}=q({queryKey:[`printer-status`,e],queryFn:()=>Q.getPrinterStatus(e),enabled:!!e}),{data:g}=q({queryKey:[`spool-assignments`,e],queryFn:()=>Q.getAssignments(e),enabled:!!e}),{data:_}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:v}=q({queryKey:[`printer-inventory-remain`,e],queryFn:()=>Q.getInventoryRemain(e),enabled:!!e,staleTime:30*1e3}),b=(0,y.useMemo)(()=>{if(!v?.inventory_remain_g)return;let e=new Map;return Object.entries(v.inventory_remain_g).forEach(([t,n])=>{let r=Number(t);Number.isNaN(r)||e.set(r,n)}),e},[v]),{loadedFilaments:x,filamentComparison:S,hasTypeMismatch:C,hasColorMismatch:w}=uW(t,h,n,Jf(_?.prefer_lowest_filament,h?.ams_filament_backup),b),T=mW(t?.filaments),E=(0,y.useMemo)(()=>{let e=new Map;for(let t of g||[]){let n=t.ams_id===255,r=Rf(t.ams_id,t.tray_id,n);e.set(r,t.spool?.cost_per_kg??null)}return e},[g]),D=(0,y.useMemo)(()=>{let e=new Map;for(let t of g||[]){let n=t.ams_id===255,r=Rf(t.ams_id,t.tray_id,n),i=t.spool;if(!i){e.set(r,null);continue}e.set(r,Math.max(0,Math.round((i.label_weight??0)-(i.weight_used??0))))}return e},[g]),O=(0,y.useMemo)(()=>{let e=0;for(let t of S){let n=t.loaded?.globalTrayId;if(n==null)continue;let r=E.get(n)??null??a;r>0&&(e+=t.used_grams/1e3*r)}return e},[S,E,a]),k=(0,y.useMemo)(()=>Array.from(E.values()).some(e=>e!=null&&e>0),[E]),A=t?.filaments&&t.filaments.length>0,j=t?.filaments?.some(e=>e.nozzle_id!=null)??!1,M=h?.fila_switch?.installed===!0,N=e=>{let t=h?.fila_switch;if(!t?.installed)return null;let n=t.in_slots.indexOf(e);return n<0?null:t.out_extruders[n]??null};if(!A||!h)return null;let P=C?`#f97316`:w?`#facc15`:`#00ae42`,F=(e,t)=>{if(e>0)if(t===``){let t={...n};delete t[e],r(t)}else r({...n,[e]:parseInt(t,10)})};return(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>m(!p),className:`flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full`,children:[(0,K.jsx)(ys,{className:`w-4 h-4`,fill:P,stroke:`none`}),(0,K.jsx)(`span`,{children:l(`printModal.filamentMapping`)}),C?(0,K.jsx)(`span`,{className:`text-xs text-orange-400`,children:`(Type not found)`}):w?(0,K.jsx)(`span`,{className:`text-xs text-yellow-400`,children:`(Color mismatch)`}):(0,K.jsx)(`span`,{className:`text-xs text-bambu-green`,children:`(Ready)`}),p?(0,K.jsx)(ss,{className:`w-4 h-4 ml-auto`}):(0,K.jsx)(rs,{className:`w-4 h-4 ml-auto`})]}),p&&(0,K.jsxs)(`div`,{className:`mt-2 bg-bambu-dark rounded-lg p-3 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`Click to change slot assignment`}),(0,K.jsxs)(`button`,{type:`button`,onClick:async()=>{f(!0);try{await Q.refreshPrinterStatus(e),await new Promise(e=>setTimeout(e,500)),await u.refetchQueries({queryKey:[`printer-status`,e]})}finally{f(!1)}},className:`flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white`,disabled:d,children:[(0,K.jsx)(Ol,{className:`w-3 h-3 ${d?`animate-spin`:``}`}),(0,K.jsx)(`span`,{children:`Re-read`})]})]}),S.map((e,t)=>{let n=e.slot_id??0,r=n>0&&c!=null,{resolvedName:i,colorLabel:a}=T[t]??{resolvedName:e.type,colorLabel:Kd(e.color)};return(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`div`,{className:`grid items-center gap-2 text-xs`,style:{gridTemplateColumns:`16px minmax(70px, 1fr) auto 2fr 16px`},children:[(0,K.jsx)(`span`,{title:`Required: ${i} - ${a}`,children:(0,K.jsx)(ys,{className:`w-3 h-3`,fill:e.color,stroke:e.color})}),(0,K.jsxs)(`span`,{className:`text-white truncate flex items-center gap-1`,children:[j&&e.nozzle_id!=null&&(0,K.jsx)(`span`,{className:`inline-flex items-center justify-center w-3.5 h-3.5 rounded text-[9px] font-bold leading-none bg-bambu-gray/20 text-bambu-gray shrink-0`,title:e.nozzle_id===1?l(`printModal.leftNozzleTooltip`):l(`printModal.rightNozzleTooltip`),children:e.nozzle_id===1?l(`printModal.leftNozzle`):l(`printModal.rightNozzle`)}),i,` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.used_grams,`g)`]})]}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`→`}),(0,K.jsxs)(`select`,{value:e.loaded?.globalTrayId??``,onChange:e=>F(n,e.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${e.status===`match`?`border-bambu-green/50 text-bambu-green`:e.status===`type_only`?`border-yellow-400/50 text-yellow-400`:`border-orange-400/50 text-orange-400`} ${e.isManual?`ring-1 ring-blue-400/50`:``}`,title:e.isManual?`Manually selected`:`Auto-matched`,children:[(0,K.jsx)(`option`,{value:``,className:`bg-bambu-dark text-bambu-gray`,children:`-- Select slot --`}),x.map(e=>{let t=D.get(e.globalTrayId),n=t==null?``:l(`printModal.slotRemainingShort`,{grams:t,defaultValue:` - ${t}g left`}),r=M?N(e.globalTrayId):null,i=r==null?``:` [${l(r===1?`printModal.leftNozzle`:`printModal.rightNozzle`)}]`;return(0,K.jsxs)(`option`,{value:e.globalTrayId,className:`bg-bambu-dark text-white`,children:[e.label,`: `,e.traySubBrands||e.type,` (`,e.colorName,`)`,n,i]},e.globalTrayId)})]}),e.status===`match`?(0,K.jsx)(ns,{className:`w-3 h-3 text-bambu-green`}):e.status===`type_only`?(0,K.jsx)(`span`,{title:`Same type, different color`,children:(0,K.jsx)(Cu,{className:`w-3 h-3 text-yellow-400`})}):(0,K.jsx)(`span`,{title:`Filament type not loaded`,children:(0,K.jsx)(Cu,{className:`w-3 h-3 text-orange-400`})})]}),r&&(0,K.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer select-none pl-5`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:s?.[n]??!1,onChange:e=>c(n,e.target.checked),className:`accent-bambu-green w-3 h-3`}),(0,K.jsx)(ml,{className:`w-3 h-3`}),l(`printModal.forceColorMatch`)]})]},t)}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[l(`printModal.totalCost`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:O>0||k?`${i}${O.toFixed(2)}`:`N/A`})]}),C&&(0,K.jsx)(`p`,{className:`text-xs text-orange-400 mt-2`,children:`Required filament type not found in printer.`})]})]})}function oke({filamentReqs:e,availableFilaments:t,overrides:n,onChange:r,forceColorMatch:i,onForceColorMatchChange:a}){let{t:o}=$e(),s=mW(e?.filaments),c=(0,y.useMemo)(()=>{let e={};for(let n of t){let t=Pf(n.type);e[t]||(e[t]=[]),e[t].push(n)}return e},[t]),l=e?.filaments;if(!l||l.length===0||t.length===0)return null;let u=(e,t)=>{if(t===``){let t={...n};delete t[e],r(t)}else{let[i,a]=t.split(`|`);r({...n,[e]:{type:i,color:a}})}};return(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:(0,K.jsx)(`span`,{children:o(`printModal.filamentOverride`)})}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:o(`printModal.filamentOverrideHint`)}),(0,K.jsx)(`div`,{className:`bg-bambu-dark rounded-lg p-3 space-y-2`,children:l.map((e,t)=>{let r=n[e.slot_id],l=!!r,d=c[Pf(e.type)]||[],f=e.nozzle_id==null?d:d.filter(t=>t.extruder_id==null||t.extruder_id===e.nozzle_id),{resolvedName:p,colorLabel:m}=s[t]??{resolvedName:e.type,colorLabel:Kd(e.color)};return(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`div`,{className:`grid items-center gap-2 text-xs`,style:{gridTemplateColumns:`16px minmax(70px, 1fr) auto 2fr 20px`},children:[(0,K.jsx)(`span`,{title:`${o(`printModal.originalFilament`)}: ${p} - ${m}`,children:(0,K.jsx)(ys,{className:`w-3 h-3`,fill:e.color,stroke:e.color})}),(0,K.jsxs)(`span`,{className:`text-white truncate`,children:[p,` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.used_grams,`g)`]})]}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`→`}),(0,K.jsxs)(`select`,{value:l?`${r.type}|${r.color}`:``,onChange:t=>u(e.slot_id,t.target.value),disabled:f.length===0,className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${l?`border-blue-400/50 text-blue-400`:`border-bambu-gray/30 text-bambu-gray`}`,children:[(0,K.jsxs)(`option`,{value:``,className:`bg-bambu-dark text-bambu-gray`,children:[o(`printModal.originalFilament`),`: `,p,` (`,m,`)`]}),f.map((e,t)=>(0,K.jsxs)(`option`,{value:`${e.type}|${e.color}`,className:`bg-bambu-dark text-white`,children:[e.tray_sub_brands||e.type,` (`,Kd(e.color),`)`]},`${e.type}-${e.color}-${e.tray_sub_brands}-${t}`))]}),l?(0,K.jsx)(`button`,{type:`button`,onClick:()=>u(e.slot_id,``),className:`text-bambu-gray hover:text-white transition-colors`,title:o(`printModal.resetToOriginal`),children:(0,K.jsx)(Al,{className:`w-3 h-3`})}):(0,K.jsx)(`span`,{className:`w-3`})]}),(0,K.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer select-none pl-5`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:i?.[e.slot_id]??!1,onChange:t=>a?.(e.slot_id,t.target.checked),className:`accent-bambu-green w-3 h-3`}),(0,K.jsx)(ml,{className:`w-3 h-3`}),o(`printModal.forceColorMatch`)]})]},e.slot_id)})})]})}function ske({plates:e,isMultiPlate:t,selectedPlates:n,onToggle:r,onSelectAll:i,onDeselectAll:a,multiSelect:o}){let{t:s}=$e();if(!t||e.length<=1)return null;let c=n.size===e.length;return(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(Lc,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`Select Plate`,o?`s`:``,` to Print`]}),n.size===0&&(0,K.jsxs)(`span`,{className:`text-xs text-orange-400 flex items-center gap-1`,children:[(0,K.jsx)(Cu,{className:`w-3 h-3`}),`Selection required`]}),o&&i&&a&&(0,K.jsx)(`button`,{type:`button`,onClick:c?a:i,className:`ml-auto text-xs px-2 py-0.5 rounded-full border transition-colors ${c?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray`}`,children:c?s(`queue.deselectAll`):s(`queue.selectAllPlates`,{count:e.length})})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:e.map(e=>{let t=n.has(e.index);return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>r(e.index),className:`flex items-center gap-2 p-2 rounded-lg border transition-colors text-left ${t?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray`}`,children:[o&&(t?(0,K.jsx)(iu,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}):(0,K.jsx)(ou,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`})),e.has_thumbnail&&e.thumbnail_url!=null?(0,K.jsx)(`img`,{src:Qu(e.thumbnail_url),alt:`Plate ${e.index}`,className:`w-10 h-10 rounded object-cover bg-bambu-dark-tertiary`}):(0,K.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,K.jsx)(Lc,{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||`Plate ${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.filaments.length} filament${e.filaments.length===1?``:`s`}`,e.print_time_seconds==null?``:` • ${wf(e.print_time_seconds)}`]}),(()=>{let t=pW(e.bed_type);return t?(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray flex items-center gap-1 mt-0.5 truncate`,title:t.label,children:[(0,K.jsx)(`img`,{src:t.icon,alt:``,className:`w-3.5 h-3.5 object-contain flex-shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:t.label})]}):null})()]}),!o&&t&&(0,K.jsx)(ns,{className:`w-4 h-4 text-bambu-green flex-shrink-0`})]},e.index)})})]})}var cke=new Set([`IDLE`,`FINISH`,`FAILED`]);function lke({printerResult:e,filamentReqs:t,onUpdateConfig:n}){let r=no(),[i,a]=(0,y.useState)(!1),o=(t,r)=>{if(t<=0)return;let i={...e.config.manualMappings};r===``?delete i[t]:i[t]=parseInt(r,10),n({useDefault:!1,manualMappings:i,autoConfigured:!1})},s=async()=>{a(!0);try{await Q.refreshPrinterStatus(e.printerId),await new Promise(e=>setTimeout(e,500)),await r.refetchQueries({queryKey:[`printer-status`,e.printerId]})}finally{a(!1)}},c=t.map(t=>{let n=t.slot_id||0,i=e.config.manualMappings[n],a,o=!1;if(i!==void 0)a=e.loadedFilaments.find(e=>e.globalTrayId===i),o=!0;else{let n=new Set(Object.values(e.config.manualMappings)),i=r.getQueryData([`settings`]);a=Yf(t,e.loadedFilaments,n,Jf(i?.prefer_lowest_filament,e.status?.ams_filament_backup),e.inventoryByTrayId)}let s=`mismatch`;if(a){let e=a.type?.toUpperCase()===t.type?.toUpperCase(),n=Af(a.color)===Af(t.color)||If(a.color,t.color);e&&n?s=`match`:e&&(s=`type_only`)}return{req:t,loaded:a,status:s,isManual:o}});return(0,K.jsxs)(`div`,{className:`mt-2 bg-bambu-dark rounded-lg p-3 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`Custom slot mapping`}),(0,K.jsxs)(`button`,{type:`button`,onClick:s,className:`flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white`,disabled:i,children:[(0,K.jsx)(Ol,{className:`w-3 h-3 ${i?`animate-spin`:``}`}),(0,K.jsx)(`span`,{children:`Re-read`})]})]}),c.map(({req:t,loaded:n,status:r,isManual:i},a)=>(0,K.jsxs)(`div`,{className:`grid items-center gap-2 text-xs`,style:{gridTemplateColumns:`16px minmax(70px, 1fr) auto 2fr 16px`},children:[(0,K.jsx)(`span`,{title:`Required: ${t.type} - ${Kd(t.color)}`,children:(0,K.jsx)(ys,{className:`w-3 h-3`,fill:t.color,stroke:t.color})}),(0,K.jsxs)(`span`,{className:`text-white truncate`,children:[t.type,` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,t.used_grams,`g)`]})]}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`→`}),(0,K.jsxs)(`select`,{value:n?.globalTrayId??``,onChange:e=>o(t.slot_id||0,e.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${r===`match`?`border-bambu-green/50 text-bambu-green`:r===`type_only`?`border-yellow-400/50 text-yellow-400`:`border-orange-400/50 text-orange-400`} ${i?`ring-1 ring-blue-400/50`:``}`,title:i?`Manually selected`:`Auto-matched`,children:[(0,K.jsx)(`option`,{value:``,className:`bg-bambu-dark text-bambu-gray`,children:`-- Select slot --`}),Xf(e.loadedFilaments,t.nozzle_id).map(e=>(0,K.jsxs)(`option`,{value:e.globalTrayId,className:`bg-bambu-dark text-white`,children:[e.label,`: `,e.traySubBrands||e.type,` (`,e.colorName,`)`]},e.globalTrayId))]}),r===`match`?(0,K.jsx)(ns,{className:`w-3 h-3 text-bambu-green`}):r===`type_only`?(0,K.jsx)(`span`,{title:`Same type, different color`,children:(0,K.jsx)(Cu,{className:`w-3 h-3 text-yellow-400`})}):(0,K.jsx)(`span`,{title:`Filament type not loaded`,children:(0,K.jsx)(Cu,{className:`w-3 h-3 text-orange-400`})})]},a))]})}function uke({printers:e,selectedPrinterIds:t,onMultiSelect:n,isLoading:r=!1,allowMultiple:i=!1,showInactive:a=!1,disableBusy:o=!1,printerMappingResults:s,filamentReqs:c,onAutoConfigurePrinter:l,onUpdatePrinterConfig:u,assignmentMode:d=`printer`,onAssignmentModeChange:f,targetModel:p,onTargetModelChange:m,targetLocation:h,onTargetLocationChange:g,slicedForModel:_}){let[v,b]=(0,y.useState)(!1),x=a?e:e.filter(e=>e.is_active),S=_o({queries:x.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),staleTime:5e3}))}),C=(0,y.useMemo)(()=>{let e=new Map;return x.forEach((t,n)=>{let r=S[n];r?.data&&e.set(t.id,r.data)}),e},[x,S]),w=e=>{let t=C.get(e);return t?t.connected?!cke.has(t.state??``):!0:!1},T=e=>{let t=C.get(e);if(!t)return null;if(!t.connected)return`Offline`;let n=t.state;return n?n===`RUNNING`?t.stg_cur_name||`Printing`:n===`PREPARE`?`Preparing`:n===`PAUSE`?`Paused`:n===`IDLE`?`Idle`:n===`FINISH`?`Finished`:n===`FAILED`?`Failed`:n:null},E=(0,y.useMemo)(()=>{if(d!==`printer`||!_||v)return x;let e=x.filter(e=>e.model===_);return e.length>0?e:x},[x,d,_,v]),D=x.length-E.length,O=(0,y.useMemo)(()=>{let e=x.map(e=>e.model).filter(e=>!!e);return[...new Set(e)].sort()},[x]),k=(0,y.useMemo)(()=>{if(!p)return[];let e=x.filter(e=>e.model===p&&e.location).map(e=>e.location).filter(e=>!!e);return[...new Set(e)].sort()},[x,p]),A=f&&m&&O.length>0,j=i&&t.length>1&&s&&c?.filaments&&c.filaments.length>0&&l&&u;if(r)return(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`})});if(E.length===0)return(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-red-400 text-sm mb-4`,children:[(0,K.jsx)(us,{className:`w-4 h-4`}),`No `,a?``:`active `,`printers available`]});let M=e=>{o&&w(e)||(i?t.includes(e)?n(t.filter(t=>t!==e)):n([...t,e]):n([e]))},N=()=>{n((o?E.filter(e=>!w(e.id)):E).map(e=>e.id))},P=()=>{n([])},F=(e,t,n)=>{n.stopPropagation(),!(!l||!u)&&(t?l(e):u(e,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},I=e=>t.includes(e),L=t.length,R=e=>s?.find(t=>t.printerId===e);return(0,K.jsxs)(`div`,{className:`space-y-2 mb-6`,children:[A&&(0,K.jsxs)(`div`,{className:`flex gap-2 mb-4`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{f(`printer`),m(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${d===`printer`?`border-bambu-green bg-bambu-green/10 text-white`:`border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray`}`,children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-sm`,children:`Specific Printer`})]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{f(`model`),n([]),m(_&&O.includes(_)?_:O[0])},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${d===`model`?`border-bambu-green bg-bambu-green/10 text-white`:`border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray`}`,children:[(0,K.jsx)(ku,{className:`w-4 h-4`}),(0,K.jsxs)(`span`,{className:`text-sm`,children:[`Any `,_||`Model`]})]})]}),d===`model`&&A&&(0,K.jsxs)(`div`,{className:`space-y-3 mb-4`,children:[!_&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:`Target Model`}),(0,K.jsxs)(`select`,{value:p||``,onChange:e=>{m(e.target.value||null),g&&g(null)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,children:[(0,K.jsx)(`option`,{value:``,children:`Select a model...`}),O.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]})]}),p&&k.length>0&&g&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:`Location Filter (optional)`}),(0,K.jsxs)(`select`,{value:h||``,onChange:e=>g(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 text-sm`,children:[(0,K.jsx)(`option`,{value:``,children:`Any location`}),k.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]})]}),p&&(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[`Scheduler will assign to first available idle `,p,` printer`,h?` in ${h}`:``]})]}),d===`printer`&&i&&E.length>1&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray mb-2`,children:[(0,K.jsx)(`span`,{children:L===0?`Select printers`:`${L} printer${L===1?``:`s`} selected`}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[L0&&(0,K.jsx)(`button`,{type:`button`,onClick:P,className:`text-bambu-gray hover:text-white transition-colors`,children:`Clear`})]})]}),d===`printer`&&E.map(e=>{let t=I(e.id),n=R(e.id),r=n&&!n.config.useDefault,a=w(e.id),s=o&&a,d=T(e.id);return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>M(e.id),disabled:s,className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${s?`border-bambu-dark-tertiary bg-bambu-dark opacity-50 cursor-not-allowed`:t?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray`} ${e.is_active?``:`opacity-60`}`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${s?`bg-bambu-dark-tertiary`:t?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(Tl,{className:`w-5 h-5 ${s?`text-bambu-gray/50`:t?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{className:`text-left flex-1`,children:[(0,K.jsxs)(`p`,{className:`font-medium ${s?`text-bambu-gray`:`text-white`}`,children:[e.name,!e.is_active&&(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs ml-2`,children:`(inactive)`})]}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[e.model||`Unknown model`,` • `,e.ip_address]})]}),d&&(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full ${a?`bg-yellow-500/20 text-yellow-400`:`bg-bambu-green/20 text-bambu-green`}`,children:d}),i&&(0,K.jsx)(`div`,{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${s?`border-bambu-gray/30`:t?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:t&&(0,K.jsx)(ns,{className:`w-3 h-3 text-white`})})]}),t&&j&&n&&(0,K.jsxs)(`div`,{className:`ml-4 mt-2 mb-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:r,onChange:t=>F(e.id,t.target.checked,t),className:`w-3.5 h-3.5 rounded border-bambu-gray/30 bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green focus:ring-offset-0`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`Custom mapping`})]}),(0,K.jsxs)(`span`,{className:`text-xs ml-2 ${n.matchStatus===`full`?`text-bambu-green`:n.matchStatus===`partial`?`text-yellow-400`:`text-orange-400`}`,children:[`(`,n.exactMatches,`/`,n.totalSlots,` matched)`]}),n.isLoading&&(0,K.jsx)(Ol,{className:`w-3 h-3 text-bambu-gray animate-spin`}),r&&(0,K.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),l(e.id)},className:`ml-auto flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white`,children:[(0,K.jsx)(Pu,{className:`w-3 h-3`}),`Auto`]})]}),r&&(0,K.jsx)(lke,{printerResult:n,filamentReqs:c.filaments,onUpdateConfig:t=>u(e.id,t)})]})]},e.id)}),d===`printer`&&D>0&&!v&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>b(!0),className:`text-xs text-bambu-gray hover:text-white transition-colors mt-2 flex items-center gap-1`,children:[(0,K.jsx)(Cu,{className:`w-3 h-3 text-yellow-400`}),D,` other printer`,D>1?`s`:``,` hidden (different model) —`,(0,K.jsx)(`span`,{className:`underline`,children:`show all`})]}),d===`printer`&&v&&_&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>b(!1),className:`text-xs text-bambu-gray hover:text-white transition-colors mt-2`,children:(0,K.jsxs)(`span`,{className:`underline`,children:[`Show only `,_,` printers`]})}),d===`printer`&&L===0&&(0,K.jsxs)(`p`,{className:`text-xs text-orange-400 mt-1 flex items-center gap-1`,children:[(0,K.jsx)(us,{className:`w-3 h-3`}),`Select at least one printer`]}),d===`model`&&!p&&(0,K.jsxs)(`p`,{className:`text-xs text-orange-400 mt-1 flex items-center gap-1`,children:[(0,K.jsx)(us,{className:`w-3 h-3`}),`Select a target printer model`]})]})}function dke({options:e,onChange:t,defaultExpanded:n=!1,showDualNozzleOptions:r=!1}){let{t:i}=$e(),[a,o]=(0,y.useState)(n),s=[{key:`bed_levelling`,label:i(`settings.defaultBedLevelling`),desc:i(`settings.defaultBedLevellingDesc`)},{key:`flow_cali`,label:i(`settings.defaultFlowCali`),desc:i(`settings.defaultFlowCaliDesc`)},{key:`vibration_cali`,label:i(`settings.defaultVibrationCali`),desc:i(`settings.defaultVibrationCaliDesc`)},{key:`layer_inspect`,label:i(`settings.defaultLayerInspect`),desc:i(`settings.defaultLayerInspectDesc`)},{key:`timelapse`,label:i(`settings.defaultTimelapse`),desc:i(`settings.defaultTimelapseDesc`)},{key:`nozzle_offset_cali`,label:i(`settings.defaultNozzleOffsetCali`),desc:i(`settings.defaultNozzleOffsetCaliDesc`),dualNozzleOnly:!0}].filter(e=>!e.dualNozzleOnly||r),c=n=>{t({...e,[n]:!e[n]})};return(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>o(!a),className:`flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full`,children:[(0,K.jsx)(Ul,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:i(`queue.bulkEdit.printOptions`)}),a?(0,K.jsx)(ss,{className:`w-4 h-4 ml-auto`}):(0,K.jsx)(rs,{className:`w-4 h-4 ml-auto`})]}),a&&(0,K.jsx)(`div`,{className:`mt-2 bg-bambu-dark rounded-lg p-3 space-y-2`,children:s.map(({key:t,label:n,desc:r})=>(0,K.jsxs)(`label`,{className:`flex items-center justify-between cursor-pointer group`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r})]}),(0,K.jsx)(`div`,{className:`relative w-10 h-5 rounded-full transition-colors ${e[t]?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,onClick:()=>c(t),children:(0,K.jsx)(`div`,{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white transition-transform ${e[t]?`translate-x-5`:`translate-x-0.5`}`})})]},t))})]})}function fke({options:e,onChange:t,dateFormat:n=`system`,timeFormat:r=`system`,canControlPrinter:i=!0,showStagger:a=!1,printerCount:o=0,hasGcodeSnippets:s=!1}){let{t:c}=$e(),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!0),[h,g]=(0,y.useState)(!0),_=(0,y.useRef)(null),v=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(e.scheduleType!==`scheduled`){v.current=!1;return}if(!v.current){v.current=!0;let i;e.scheduledTime?(i=new Date(e.scheduledTime),isNaN(i.getTime())&&(i=new Date,i.setHours(i.getHours()+1,0,0,0))):(i=new Date,i.setHours(i.getHours()+1,0,0,0),t({...e,scheduledTime:_f(i)})),u(df(i,n)),f(ff(i,r)),m(!0),g(!0)}},[e.scheduleType,e.scheduledTime,n,r,t,e]);let b=n=>{t({...e,scheduleType:n,requireManualStart:n===`queue`?e.requireManualStart:!1})},x=(r,i)=>{let a=hf(r,n),o=gf(i);m(!!a),g(!!o),a&&o&&(a.setHours(o.hours,o.minutes,0,0),a>new Date&&t({...e,scheduledTime:_f(a)}))},S=e=>{u(e),x(e,d)},C=e=>{f(e),x(l,e)};return(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-2`,children:c(`printModal.whenToPrint`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${e.scheduleType===`asap`?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,onClick:()=>b(`asap`),children:[(0,K.jsx)(xs,{className:`w-4 h-4`}),c(`printModal.asap`)]}),(0,K.jsxs)(`button`,{type:`button`,className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${e.scheduleType===`queue`?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,onClick:()=>b(`queue`),children:[(0,K.jsx)(Hc,{className:`w-4 h-4`}),c(`printModal.queue`)]}),(0,K.jsxs)(`button`,{type:`button`,className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${e.scheduleType===`scheduled`?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,onClick:()=>b(`scheduled`),children:[(0,K.jsx)(Xo,{className:`w-4 h-4`}),c(`printModal.schedule`)]})]})]}),e.scheduleType===`scheduled`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:c(`printModal.dateTime`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex-1 relative`,children:[(0,K.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 pr-10 bg-bambu-dark border rounded-lg text-white focus:outline-none ${p?`border-bambu-dark-tertiary focus:border-bambu-green`:`border-red-500`}`,value:l,onChange:e=>S(e.target.value),placeholder:lf(n)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{_.current?.showPicker()},className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,title:c(`printModal.openCalendar`),children:(0,K.jsx)(Xo,{className:`w-4 h-4`})}),(0,K.jsx)(`input`,{ref:_,type:`datetime-local`,className:`absolute top-0 left-0 w-0 h-0 opacity-0 pointer-events-none`,value:e.scheduledTime,onChange:i=>{let a=i.target.value;if(a){let i=new Date(a);isNaN(i.getTime())||(u(df(i,n)),f(ff(i,r)),m(!0),g(!0),t({...e,scheduledTime:a}))}},tabIndex:-1})]}),(0,K.jsx)(`div`,{className:`w-32`,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border rounded-lg text-white focus:outline-none ${h?`border-bambu-dark-tertiary focus:border-bambu-green`:`border-red-500`}`,value:d,onChange:e=>C(e.target.value),placeholder:uf(r)})})]}),(!p||!h)&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-400`,children:c(`printModal.invalidDateTime`)})]}),e.scheduleType===`queue`&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`requireManualStart`,checked:e.requireManualStart,onChange:n=>t({...e,requireManualStart:n.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`label`,{htmlFor:`requireManualStart`,className:`text-sm flex items-center gap-1 text-bambu-gray`,children:[(0,K.jsx)(Sc,{className:`w-3.5 h-3.5`}),c(`printModal.requireManualStart`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`requirePrevious`,checked:e.requirePreviousSuccess,onChange:n=>t({...e,requirePreviousSuccess:n.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsx)(`label`,{htmlFor:`requirePrevious`,className:`text-sm text-bambu-gray`,children:c(`printModal.requirePreviousSuccess`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`autoOffAfter`,checked:e.autoOffAfter,onChange:n=>t({...e,autoOffAfter:n.target.checked}),disabled:!i,className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green disabled:opacity-50`}),(0,K.jsxs)(`label`,{htmlFor:`autoOffAfter`,className:`text-sm flex items-center gap-1 ${i?`text-bambu-gray`:`text-bambu-gray/50`}`,children:[(0,K.jsx)(wl,{className:`w-3.5 h-3.5`}),c(`printModal.autoOffAfter`)]})]}),s&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`gcodeInjection`,checked:e.gcodeInjection,onChange:n=>t({...e,gcodeInjection:n.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`label`,{htmlFor:`gcodeInjection`,className:`text-sm flex items-center gap-1 text-bambu-gray`,children:[(0,K.jsx)(Ts,{className:`w-3.5 h-3.5`}),c(`printModal.gcodeInjection`,`Inject auto-print G-code`)]})]}),a&&e.scheduleType!==`queue`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`staggerEnabled`,checked:e.staggerEnabled,onChange:n=>t({...e,staggerEnabled:n.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`label`,{htmlFor:`staggerEnabled`,className:`text-sm flex items-center gap-1 text-bambu-gray`,children:[(0,K.jsx)(Lc,{className:`w-3.5 h-3.5`}),c(`printModal.staggerPrinterStarts`,`Stagger printer starts`)]})]}),e.staggerEnabled&&(0,K.jsxs)(`div`,{className:`ml-6 space-y-3`,children:[(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-bambu-gray mb-1`,children:c(`printModal.staggerGroupSize`,`Group size`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:o,value:e.staggerGroupSize,onChange:n=>t({...e,staggerGroupSize:Math.max(1,parseInt(n.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.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:c(`printModal.staggerInterval`,`Interval (min)`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:60,value:e.staggerIntervalMinutes,onChange:n=>t({...e,staggerIntervalMinutes:Math.max(1,parseInt(n.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`})]})]}),o>0&&(()=>{let t=Math.ceil(o/e.staggerGroupSize),n=o%e.staggerGroupSize,r=(t-1)*e.staggerIntervalMinutes;return(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[c(`printModal.staggerPreview`,`{{printers}} printers → {{groups}} groups of {{size}}, starting every {{interval}} min`,{printers:o,groups:t,size:e.staggerGroupSize,interval:e.staggerIntervalMinutes}),n!==0&&e.staggerGroupSize1?` (${c(`printModal.staggerTotal`,`total: {{minutes}} min`,{minutes:r})})`:``]})})()]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.scheduleType===`asap`?c(`printModal.helpAsap`):e.scheduleType===`scheduled`?c(`printModal.helpSchedule`):c(`printModal.helpQueue`)})]})}var hW={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1,nozzle_offset_cali:!0},gW={scheduleType:`asap`,scheduledTime:``,requireManualStart:!1,requirePreviousSuccess:!1,autoOffAfter:!1,gcodeInjection:!1,staggerEnabled:!1,staggerGroupSize:2,staggerIntervalMinutes:5};function _W({mode:e,archiveId:t,libraryFileId:n,archiveName:r,queueItem:i,initialSelectedPrinterIds:a,onClose:o,onSuccess:s,projectId:c,cleanupLibraryAfterDispatch:l}){let{t:u}=$e(),d=no(),{showToast:f}=Ed(),{hasPermission:p}=pd(),m=!!n&&!t,h=e===`edit-queue-item`,[g,_]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.printer_id?[i.printer_id]:a?.length?a:[]),[v,b]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.plate_id!=null?new Set([i.plate_id]):new Set),x=v.size===1?[...v][0]:null,[S,C]=(0,y.useState)(1),[w,T]=(0,y.useState)(()=>e===`edit-queue-item`&&i?{bed_levelling:i.bed_levelling??hW.bed_levelling,flow_cali:i.flow_cali??hW.flow_cali,vibration_cali:i.vibration_cali??hW.vibration_cali,layer_inspect:i.layer_inspect??hW.layer_inspect,timelapse:i.timelapse??hW.timelapse,nozzle_offset_cali:i.nozzle_offset_cali??hW.nozzle_offset_cali}:hW),[E,D]=(0,y.useState)(()=>{if(e===`edit-queue-item`&&i){let e=`queue`;i.scheduled_time&&!Wf(i.scheduled_time)&&(e=`scheduled`);let t=``;return i.scheduled_time&&!Wf(i.scheduled_time)&&(t=_f(yf(i.scheduled_time)??new Date)),{scheduleType:e,scheduledTime:t,requireManualStart:i.manual_start,requirePreviousSuccess:i.require_previous_success,autoOffAfter:i.auto_off_after,gcodeInjection:i.gcode_injection??!1,staggerEnabled:!1,staggerGroupSize:gW.staggerGroupSize,staggerIntervalMinutes:gW.staggerIntervalMinutes}}return gW}),[O,k]=(0,y.useState)(()=>{if(e===`edit-queue-item`&&i?.ams_mapping&&Array.isArray(i.ams_mapping)){let e={};return i.ams_mapping.forEach((t,n)=>{t!==-1&&(e[n+1]=t)}),e}return{}}),[A,j]=(0,y.useState)({}),[M,N]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.target_model?`model`:`printer`),[P,F]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.target_model?i.target_model:null),[I,L]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.target_location?i.target_location:null),[R,z]=(0,y.useState)(()=>{if(e===`edit-queue-item`&&i?.filament_overrides){let e={};for(let t of i.filament_overrides)e[t.slot_id]={type:t.type,color:t.color};return e}return{}}),[B,V]=(0,y.useState)(()=>{if(e===`edit-queue-item`&&i?.filament_overrides){let e={};for(let t of i.filament_overrides)e[t.slot_id]=t.force_color_match===!0;return e}return{}}),[ee]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.printer_id?[i.printer_id]:[]),[te]=(0,y.useState)(()=>e===`edit-queue-item`&&i?i.plate_id:null),[H,ne]=(0,y.useState)(!1),[re,U]=(0,y.useState)({current:0,total:0}),[ie,ae]=(0,y.useState)(null),[W,oe]=(0,y.useState)(new Set),se=g.length,ce=g.length>0?g[0]:null,{data:le}=q({queryKey:[`settings`],queryFn:Q.getSettings}),ue=(0,y.useRef)(!1);(0,y.useEffect)(()=>{!le||ue.current||e===`edit-queue-item`||(ue.current=!0,T({bed_levelling:le.default_bed_levelling??hW.bed_levelling,flow_cali:le.default_flow_cali??hW.flow_cali,vibration_cali:le.default_vibration_cali??hW.vibration_cali,layer_inspect:le.default_layer_inspect??hW.layer_inspect,timelapse:le.default_timelapse??hW.timelapse,nozzle_offset_cali:le.default_nozzle_offset_cali??hW.nozzle_offset_cali}))},[le,e]);let de=(0,y.useRef)(!1);(0,y.useEffect)(()=>{!le||de.current||e===`edit-queue-item`||(de.current=!0,D(e=>({...e,staggerGroupSize:le.stagger_group_size??e.staggerGroupSize,staggerIntervalMinutes:le.stagger_interval_minutes??e.staggerIntervalMinutes})))},[le,e]);let fe=ef(le?.currency||`USD`),pe=le?.default_filament_cost??0,{data:me,isLoading:he}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:ge}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),staleTime:30*1e3,enabled:!h&&M===`printer`}),_e=_o({queries:g.map(e=>({queryKey:[`printer-inventory-remain`,e],queryFn:()=>Q.getInventoryRemain(e),staleTime:30*1e3,enabled:g.length>0}))}),ve=(0,y.useMemo)(()=>{let e=new Map;return g.forEach((t,n)=>{let r=_e[n]?.data?.inventory_remain_g;if(!r)return;let i=new Map;Object.entries(r).forEach(([e,t])=>{let n=Number(e);Number.isNaN(n)||i.set(n,t)}),e.set(t,i)}),e},[g,_e]),{data:ye}=q({queryKey:[`archive`,t],queryFn:()=>Q.getArchive(t),enabled:!!t&&!m}),{data:be}=q({queryKey:[`library-file`,n],queryFn:()=>Q.getLibraryFile(n),enabled:m&&!!n}),xe=ye?.sliced_for_model||be?.sliced_for_model||null,{data:Se,isError:Ce}=q({queryKey:[`archive-plates`,t],queryFn:()=>Q.getArchivePlates(t),enabled:!!t&&!m,retry:!1}),{data:we}=q({queryKey:[`library-file-plates`,n],queryFn:()=>Q.getLibraryFilePlates(n),enabled:m&&!!n}),Te=m?we:Se,{data:Ee,isError:De}=q({queryKey:[`archive-filaments`,t,x],queryFn:()=>Q.getArchiveFilamentRequirements(t,x??void 0),enabled:!!t&&!m&&(x!==null||!Te?.is_multi_plate),retry:!1}),{data:Oe}=q({queryKey:[`library-file-filaments`,n,x],queryFn:()=>Q.getLibraryFileFilamentRequirements(n,x??void 0),enabled:m&&!!n&&(x!==null||!Te?.is_multi_plate)}),ke=!m&&(Ce||De),Ae=m?Oe:Ee,{data:je}=q({queryKey:[`available-filaments`,P,I],queryFn:()=>Q.getAvailableFilaments(P,I??void 0),enabled:M===`model`&&!!P}),{data:Me}=q({queryKey:[`printer-status`,ce],queryFn:()=>Q.getPrinterStatus(ce),enabled:!!ce}),Ne=Jf(le?.prefer_lowest_filament,Me?.ams_filament_backup),Pe=e=>!e?.connected||e.awaiting_plate_clear||e.ams?.some(e=>e.dry_time>0)?!1:[`IDLE`,`FINISH`,`FAILED`].includes(e.state??``),Fe=async()=>{if(E.scheduleType!==`asap`||M!==`printer`||g.length===0)return!1;try{return(await Promise.all(g.map(e=>d.fetchQuery({queryKey:[`printer-status`,e],queryFn:()=>Q.getPrinterStatus(e),staleTime:0})))).some(e=>!Pe(e))}catch{return!0}},{amsMapping:Ie}=uW(Ae,Me,O,Ne,ce?ve.get(ce):void 0),Le=nke(g,me,Ae,O,A,j,le?.prefer_lowest_filament,ve);(0,y.useEffect)(()=>{Te?.plates&&Te.plates.length>=1&&v.size===0&&b(new Set([Te.plates[0].index]))},[Te,v.size]),(0,y.useEffect)(()=>{if(e===`edit-queue-item`)return;let t=me?.filter(e=>e.is_active)||[];t.length===1&&g.length===0&&_([t[0].id])},[e,me,g.length]),(0,y.useEffect)(()=>{e===`edit-queue-item`?(JSON.stringify(g.sort())!==JSON.stringify(ee.sort())||x!==te)&&(k({}),j({}),oe(new Set)):(k({}),j({}),oe(new Set))},[e,g,x,ee,te]);let[Re,ze]=(0,y.useState)(P),[Be,Ve]=(0,y.useState)(x);(0,y.useEffect)(()=>{(P!==Re||x!==Be)&&(ze(P),Ve(x),(e!==`edit-queue-item`||Re!==null)&&(z({}),V({})))},[P,x,Re,Be,e]),(0,y.useEffect)(()=>{if(!le?.per_printer_mapping_expanded||g.length<=1)return;let e=g.filter(e=>{if(W.has(e))return!1;let t=Le.printerResults.find(t=>t.printerId===e);return t&&t.status&&!t.isLoading});e.length>0&&(oe(t=>{let n=new Set(t);return e.forEach(e=>n.add(e)),n}),e.forEach(e=>{Le.autoConfigurePrinter(e)}))},[le?.per_printer_mapping_expanded,g,W,Le]),(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!H&&o()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o,H]);let He=Te?.is_multi_plate??!1,Ue=Te?.plates??[],We=(0,y.useMemo)(()=>{let e=new Map;return ge&&ge.forEach(t=>{let n=t.ams_id===255,r=Rf(t.ams_id,t.tray_id,n),i=e.get(t.printer_id)??new Map;i.set(r,t),e.set(t.printer_id,i)}),e},[ge]),Ge=(0,y.useMemo)(()=>{if(!ie||ie.length===0)return``;let e=ie.map(e=>u(`printModal.insufficientFilamentLine`,{printer:e.printerName,slot:e.slotLabel,required:Math.round(e.requiredGrams),remaining:Math.round(e.remainingGrams)}));return[u(`printModal.insufficientFilamentMessage`),...e].join(`
`)},[ie,u]),Ke=J({mutationFn:e=>Q.addToQueue(e)}),qe=J({mutationFn:e=>Q.updateQueueItem(i.id,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`queue`]}),f(`Queue item updated`),s?.(),o()},onError:e=>{f(e.message||`Failed to update queue item`,`error`)}}),Je=async(i,a)=>{if(i?.preventDefault(),!a?.skipFilamentCheck&&!le?.disable_filament_warnings&&!h&&M===`printer`){let e=[],t=Ae?.filaments??[];if(t.length>0&&We.size>0){let n=(e,t)=>!Number.isFinite(e)||e<=0||!Number.isFinite(t)||t<0?null:Math.max(0,e-t);for(let r of g){let i=g.length>1?Le.getFinalMapping(r):Ie;if(!i)continue;let a=cW(g.length>1?Le.printerResults.find(e=>e.printerId===r)?.status:Me),o=new Map(a.map(e=>[e.globalTrayId,e.label])),s=We.get(r),c=me?.find(e=>e.id===r)?.name??`Printer ${r}`;s&&t.forEach(t=>{if(!t.slot_id||t.slot_id<=0)return;let r=i[t.slot_id-1];if(!Number.isFinite(r)||r<0)return;let a=s.get(r)?.spool;if(!a)return;let l=n(a.label_weight,a.weight_used);l!==null&&(l>=t.used_grams||e.push({printerName:c,slotLabel:o.get(r)??`Slot ${t.slot_id}`,requiredGrams:t.used_grams,remainingGrams:l}))})}}if(e.length>0){ae(e);return}}if(M===`printer`&&g.length===0){f(`Please select at least one printer`,`error`);return}if(M===`model`&&!P){f(`Please select a target printer model`,`error`);return}ne(!0);let p=v.size>1?Ue.filter(e=>v.has(e.index)):[null],_=M===`model`?p.length:g.length*p.length;U({current:0,total:_});let y={success:0,failed:0,errors:[]},b=e=>{if(g.length>1){let t=A[e];if(t&&!t.useDefault)return Le.getFinalMapping(e)}return Ie},S=(()=>{let e=[];if(Ae?.filaments)for(let t of Ae.filaments){let n=R[t.slot_id],r=B[t.slot_id]??!1,i=n?.type??t.type,a=n?.color??t.color;(n||r)&&e.push({slot_id:t.slot_id,type:i,color:a,color_name:Kd(a),force_color_match:r})}else for(let[t,{type:n,color:r}]of Object.entries(R)){let i=parseInt(t,10),a=B[i]??!1;e.push({slot_id:i,type:n,color:r,color_name:Kd(r),force_color_match:a})}return e.length>0?e:void 0})(),C=e===`create`&&p.length>1&&(M===`model`||g.length===1),T=null;if(C)try{let e=`${(r||``).replace(/\.gcode\.3mf$/i,``).replace(/\.3mf$/i,``)||`Batch`} · ${p.length} plates`;T=(await Q.createBatch({name:e,archive_id:m?void 0:t,library_file_id:m?n:void 0})).id}catch{T=null}let D=new Map,O=(e,t,n=1)=>{if(E.scheduleType!==`asap`)return;let r=t===null?`unassigned`:`printer:${t}`,i=(D.get(r)??0)+1;e.insert_at_top=!0,e.insert_position=i,D.set(r,i+n-1)},k=(e,r)=>({printer_id:M===`printer`?e:null,target_model:M===`model`?P:null,target_location:M===`model`?I:null,filament_overrides:M===`model`?S:void 0,archive_id:m?void 0:t,library_file_id:m?n:void 0,require_previous_success:E.requirePreviousSuccess,auto_off_after:E.autoOffAfter,gcode_injection:E.gcodeInjection,manual_start:E.scheduleType===`queue`&&E.requireManualStart,skip_filament_check:a?.skipFilamentCheck===!0?!0:void 0,ams_mapping:e?b(e):void 0,plate_id:r===void 0?x:r,scheduled_time:E.scheduleType===`scheduled`&&E.scheduledTime?new Date(E.scheduledTime).toISOString():void 0,...w,project_id:c??void 0,batch_id:T??void 0,cleanup_library_after_dispatch:l});if(M===`model`){let t=0;for(let n of p){t++,U({current:t,total:_});let r=n?n.index:x;try{if(e===`edit-queue-item`&&!n){let e={printer_id:null,target_model:P,target_location:I,filament_overrides:S||null,require_previous_success:E.requirePreviousSuccess,auto_off_after:E.autoOffAfter,gcode_injection:E.gcodeInjection,manual_start:E.scheduleType===`queue`&&E.requireManualStart,ams_mapping:void 0,plate_id:r,scheduled_time:E.scheduleType===`scheduled`&&E.scheduledTime?new Date(E.scheduledTime).toISOString():null,...w};await qe.mutateAsync(e)}else{let e=k(null,r);Ze>1&&(e.quantity=Ze),O(e,null,Ze),await Ke.mutateAsync(e)}y.success++}catch(e){y.failed++;let t=n?n.name||`Plate ${n.index}`:``;y.errors.push(t?`${t}: ${e.message}`:e.message)}}}else{let e=E.staggerEnabled&&!h&&g.length>1,t=e?E.scheduleType===`scheduled`&&E.scheduledTime?new Date(E.scheduledTime).getTime():Date.now():0,n=0;for(let r of p){let i=r?r.index:x;for(let a=0;a1&&(n.quantity=Ze),O(n,o,Ze),e){let e=Math.floor(a/E.staggerGroupSize);if(e>0){let r=e*E.staggerIntervalMinutes*6e4;n.scheduled_time=new Date(t+r).toISOString()}}await Ke.mutateAsync(n)}y.success++}catch(e){y.failed++;let t=me?.find(e=>e.id===o)?.name||`Printer ${o}`,n=r?r.name||`Plate ${r.index}`:``,i=n?`${t} (${n})`:t;y.errors.push(`${i}: ${e.message}`)}}}}ne(!1),y.failed===0?(h?e===`edit-queue-item`&&f(`Queue item updated`):y.success===1?f(await Fe()?u(`queue.printQueuedWillStartWhenIdle`):M===`model`?`Queued for any ${P}`:u(`queue.printQueued`)):f(await Fe()?u(`queue.printQueuedWillStartWhenIdle`):u(`queue.itemsQueued`,{count:y.success})),d.invalidateQueries({queryKey:[`queue`]}),s?.(),o()):y.success===0?f(`Failed: ${y.errors[0]}`,`error`):(f(`${y.success} succeeded, ${y.failed} failed`,`error`),d.invalidateQueries({queryKey:[`queue`]}))},Ye=H||qe.isPending,Xe=(0,y.useMemo)(()=>!(Ye||M===`printer`&&g.length===0||M===`model`&&!P||He&&v.size===0),[g.length,M,P,He,v.size,Ye]),Ze=M===`printer`&&g.length>1?1:S;(0,y.useEffect)(()=>{e===`create`&&E.gcodeInjection&&(Ze<=1||!le?.gcode_snippets)&&D(e=>({...e,gcodeInjection:!1}))},[e,Ze,le?.gcode_snippets,E.gcodeInjection]);let Qe=h?{title:u(`queue.editQueueItem`),icon:vl,submitText:u(`common.save`),submitIcon:vl,loadingText:re.total>1?u(`queue.savingProgress`,{current:re.current,total:re.total}):u(`common.saving`)}:{title:u(`common.print`),icon:Tl,submitText:u(`common.print`),submitIcon:Tl,loadingText:re.total>1?u(`queue.addingProgress`,{current:re.current,total:re.total}):u(`queue.adding`)},et=Qe.icon,tt=Qe.submitIcon,nt=ce&&v.size<=1&&(m||(He?x!==null:!0)),rt=(0,y.useMemo)(()=>new Set([`H2D`,`H2DPRO`,`H2C`,`X2D`]),[]),it=(0,y.useMemo)(()=>M===`model`?P?rt.has(P.toUpperCase().replace(/[\s-]/g,``)):!1:!me||g.length===0?!1:g.some(e=>me.find(t=>t.id===e)?.nozzle_count===2),[M,P,me,g,rt]);return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:H?void 0:o,children:[(0,K.jsx)(yd,{className:`w-full max-w-2xl max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(xd,{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)(et,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:Qe.title})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:o,disabled:H,children:(0,K.jsx)(Bu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`form`,{onSubmit:Je,className:`p-4 space-y-4`,children:[(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`block text-bambu-gray mb-1`,children:`Print Job`}),(0,K.jsx)(`span`,{className:`text-white font-medium truncate block`,children:r})]}),(()=>{if(!Ue.length)return null;let e=pW((x==null?Ue[0]:Ue.find(e=>e.index===x))?.bed_type);return e?(0,K.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-bambu-gray -mt-2`,title:e.label,children:[(0,K.jsx)(`img`,{src:e.icon,alt:``,className:`w-4 h-4 object-contain flex-shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:e.label})]}):null})(),(0,K.jsx)(ske,{plates:Ue,isMultiPlate:He,selectedPlates:v,onToggle:e=>{b(t=>{let n=new Set(t);return h?(n.clear(),n.add(e)):n.has(e)?n.delete(e):n.add(e),n})},onSelectAll:h?void 0:()=>b(new Set(Ue.map(e=>e.index))),onDeselectAll:h?void 0:()=>b(new Set),multiSelect:!h}),!a?.length&&(0,K.jsx)(uke,{printers:me||[],selectedPrinterIds:g,onMultiSelect:_,isLoading:he,allowMultiple:!0,showInactive:e===`edit-queue-item`,disableBusy:!1,printerMappingResults:Le.printerResults,filamentReqs:Ae,onAutoConfigurePrinter:Le.autoConfigurePrinter,onUpdatePrinterConfig:Le.updatePrinterConfig,assignmentMode:M,onAssignmentModeChange:h?void 0:N,targetModel:P,onTargetModelChange:h?void 0:F,targetLocation:I,onTargetLocationChange:h?void 0:L,slicedForModel:xe}),M===`model`&&P&&Ae&&je&&je.length>0&&(0,K.jsx)(oke,{filamentReqs:Ae,availableFilaments:je,overrides:R,onChange:z,forceColorMatch:B,onForceColorMatchChange:(e,t)=>V(n=>({...n,[e]:t}))}),xe&&M===`printer`&&g.length===1&&(()=>{let e=me?.find(e=>e.id===g[0]);return e&&e.model&&xe!==e.model?(0,K.jsxs)(`div`,{className:`p-3 mb-2 bg-yellow-500/10 border border-yellow-500/30 rounded-lg flex items-center gap-2`,children:[(0,K.jsx)(Cu,{className:`w-4 h-4 text-yellow-400 flex-shrink-0`}),(0,K.jsxs)(`span`,{className:`text-sm text-yellow-400`,children:[`File was sliced for `,xe,`, but printing on `,e.model]})]}):null})(),ke&&(0,K.jsxs)(`div`,{className:`flex items-start gap-2 p-3 mb-2 bg-orange-500/10 border border-orange-500/30 rounded-lg text-sm`,children:[(0,K.jsx)(us,{className:`w-4 h-4 text-orange-400 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`p`,{className:`text-orange-400`,children:`Archive data unavailable. The source file may have been deleted. Filament mapping is disabled.`})]}),nt&&!ke&&g.length===1&&(0,K.jsx)(ake,{printerId:ce,filamentReqs:Ae,manualMappings:O,onManualMappingChange:k,defaultExpanded:!!a?.length||(le?.per_printer_mapping_expanded??!1),currencySymbol:fe,defaultCostPerKg:pe,forceColorMatch:B,onForceColorMatchChange:(e,t)=>V(n=>({...n,[e]:t}))}),(e===`create`||se>0||M===`model`&&P)&&(0,K.jsx)(dke,{options:w,onChange:T,defaultExpanded:!!a?.length,showDualNozzleOptions:it}),e!==`edit-queue-item`&&(M===`model`||g.length<=1)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`label`,{htmlFor:`printQuantity`,className:`text-sm text-bambu-gray whitespace-nowrap`,children:u(`queue.quantity`,`Quantity`)}),(0,K.jsx)(`input`,{id:`printQuantity`,type:`number`,min:1,max:999,value:S,onChange:e=>C(Math.max(1,Math.min(999,parseInt(e.target.value)||1))),className:`w-20 px-2 py-1 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green`}),S>1&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:u(`queue.quantityHint`,`Creates {{count}} queue items`,{count:S})})]}),(0,K.jsx)(fke,{options:E,onChange:D,dateFormat:le?.date_format||`system`,timeFormat:le?.time_format||`system`,canControlPrinter:p(`printers:control`),showStagger:!h&&M===`printer`&&g.length>1,printerCount:g.length,hasGcodeSnippets:!!le?.gcode_snippets}),qe.isError&&(0,K.jsx)(`div`,{className:`mb-4 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400`,children:qe.error?.message||`Failed to complete operation`}),(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:o,className:`flex-1`,disabled:H,children:`Cancel`}),(0,K.jsx)($,{type:`submit`,disabled:!Xe,className:`flex-1`,children:Ye?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),Qe.loadingText]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(tt,{className:`w-4 h-4`}),Qe.submitText]})})]})]})]})}),ie&&ie.length>0&&(0,K.jsx)(jd,{title:u(`printModal.insufficientFilamentTitle`),message:Ge,confirmText:u(`printModal.printAnyway`),cancelText:u(`common.cancel`),variant:`warning`,onConfirm:()=>{ae(null),Je(void 0,{skipFilamentCheck:!0})},onCancel:()=>ae(null)})]})}function vW({value:e}){let{t}=$e(),[n,r]=(0,y.useState)(!1);return(0,K.jsx)(`button`,{onClick:async()=>{try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(e);else{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{if(t.select(),!document.execCommand(`copy`))return}finally{document.body.removeChild(t)}}r(!0),setTimeout(()=>r(!1),2e3)}catch{}},className:`ml-2 p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,title:t(n?`printers.copied`:`printers.copyToClipboard`),children:n?(0,K.jsx)(ns,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,K.jsx)(js,{className:`w-3.5 h-3.5`})})}function pke({printer:e,status:t,totalPrintHours:n,onClose:r}){let{t:i}=$e();(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let a=[];if(a.push({label:i(`printers.model`),value:e.model??`—`}),a.push({label:i(`common.status`),value:(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-xs font-medium ${t?.connected?`bg-bambu-green/20 text-bambu-green`:`bg-red-500/20 text-red-400`}`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${t?.connected?`bg-bambu-green`:`bg-red-400`}`}),t?.connected?i(`printers.status.available`):i(`printers.status.offline`)]})}),t?.state&&a.push({label:i(`printers.state`),value:i({IDLE:`printers.status.idle`,RUNNING:`printers.status.printing`,PAUSE:`printers.status.paused`,FINISH:`printers.status.finished`,FAILED:`printers.status.error`}[t.state]??`printers.status.unknown`)}),a.push({label:i(`printers.ipAddress`),value:(0,K.jsxs)(`span`,{className:`flex items-center`,children:[(0,K.jsx)(`span`,{className:`font-mono`,children:e.ip_address}),(0,K.jsx)(vW,{value:e.ip_address})]})}),a.push({label:i(`printers.serialNumber`),value:(0,K.jsxs)(`span`,{className:`flex items-center`,children:[(0,K.jsx)(`span`,{className:`font-mono truncate`,children:e.serial_number}),(0,K.jsx)(vW,{value:e.serial_number})]})}),t?.wired_network)a.push({label:i(`printers.networkLabel`,`Network`),value:(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(qo,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-bambu-green`,children:i(`printers.connection.ethernet`,`Ethernet`)})]})});else if(t?.wifi_signal!=null){let e=Sle(t.wifi_signal);a.push({label:i(`printers.wifiSignalLabel`),value:(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Yl,{className:`w-4 h-4 ${e.color}`}),(0,K.jsx)(`span`,{className:e.color,children:i(e.labelKey)}),(0,K.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[`(`,t.wifi_signal,` dBm)`]})]})})}return a.push({label:i(`printers.firmware`),value:t?.firmware_version??`—`}),t?.developer_mode!=null&&a.push({label:i(`printers.developerMode`),value:(0,K.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${t.developer_mode?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:t.developer_mode?i(`printers.enabled`):i(`printers.disabled`)})}),a.push({label:i(`printers.nozzleCount`),value:e.nozzle_count}),a.push({label:i(`printers.autoArchive`),value:(0,K.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${e.auto_archive?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:e.auto_archive?i(`printers.enabled`):i(`printers.disabled`)})}),n!=null&&n>0&&a.push({label:i(`printers.totalPrintHours`),value:`${Math.round(n)}h`}),e.location&&a.push({label:i(`printers.sort.location`),value:e.location}),a.push({label:i(`printers.addedOn`),value:bf(e.created_at)}),(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,onClick:r,children:(0,K.jsx)(yd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(xd,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e.name}),(0,K.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-bambu-dark rounded flex-shrink-0`,children:(0,K.jsx)(Bu,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,K.jsx)(`img`,{src:xle(e.model),alt:e.model??e.name,className:`h-24 object-contain`})}),(0,K.jsx)(`div`,{className:`space-y-0`,children:a.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-2.5 border-b border-bambu-dark-tertiary last:border-0`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray whitespace-nowrap`,children:e.label}),(0,K.jsx)(`span`,{className:`text-sm text-white text-right`,children:e.value})]},t))})]})})})}function mke(e){if(!e||e.length<6)return!1;let t=parseInt(e.slice(0,2),16),n=parseInt(e.slice(2,4),16),r=parseInt(e.slice(4,6),16);return(.299*t+.587*n+.114*r)/255>.6}function yW({trayColor:e,trayType:t,isEmpty:n,emptyKind:r,slotNumber:i}){let a=r===`reset`?`#3d3d3d`:`#666`;return(0,K.jsx)(`div`,{className:`w-3.5 h-3.5 rounded-full mx-auto mb-0.5 border-2 flex items-center justify-center`,style:{backgroundColor:e?`#${e}`:t?`#333`:`transparent`,borderColor:n?a:`rgba(255,255,255,0.1)`,borderStyle:n?`dashed`:`solid`},children:(0,K.jsx)(`span`,{className:`text-[6px] font-bold leading-none select-none`,style:{color:e&&mke(e)?`#000`:`#fff`},children:i})})}var bW=240,xW=320;function SW(e){return(e??.02).toFixed(3)}function CW({side:e}){let{mode:t}=gd();return(0,K.jsx)(`span`,{className:`inline-flex items-center justify-center w-4 h-4 text-[10px] font-bold rounded`,style:{backgroundColor:t===`dark`?`#1a4d2e`:`#e7f5e9`,color:`#00ae42`},children:e})}function wW(e,t){if(!e)return``;if(e.includes(`hardened`))return t(`printers.nozzleHardenedSteel`);if(e.includes(`stainless`))return t(`printers.nozzleStainlessSteel`);if(e.includes(`tungsten`))return t(`printers.nozzleTungstenCarbide`);if(e.length>=4){let n=e.slice(2,4);if(n===`00`)return t(`printers.nozzleStainlessSteel`);if(n===`01`)return t(`printers.nozzleHardenedSteel`);if(n===`05`)return t(`printers.nozzleTungstenCarbide`)}return e===`00`?t(`printers.nozzleStainlessSteel`):e===`01`?t(`printers.nozzleHardenedSteel`):e===`05`?t(`printers.nozzleTungstenCarbide`):e.startsWith(`H`)?t(`printers.nozzleHardenedSteel`):e}function TW(e,t){return e?e.startsWith(`HH`)?t(`printers.nozzleHighFlow`):e.startsWith(`HS`)?t(`printers.nozzleStandardFlow`):``:``}function EW({slot:e,index:t,activeStatus:n,filamentName:r,children:i}){let{t:a}=$e(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(`top`),u=(0,y.useRef)(null),d=(0,y.useRef)(null),f=(0,y.useRef)(null),p=!e.nozzle_diameter&&!e.nozzle_type,m=e.stat===1;(0,y.useEffect)(()=>{if(o&&u.current&&d.current){let e=u.current.getBoundingClientRect(),t=d.current.offsetHeight,n=e.top-56,r=window.innerHeight-e.bottom;nn?l(`bottom`):l(`top`)}},[o]);let h=()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>s(!0),80)},g=()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>s(!1),100)};(0,y.useEffect)(()=>()=>{f.current&&clearTimeout(f.current)},[]);let _=Xd(e.filament_color),v=wW(e.nozzle_type,a),b=TW(e.nozzle_type,a);return(0,K.jsxs)(`div`,{ref:u,className:`relative`,onMouseEnter:h,onMouseLeave:g,children:[i,o&&(0,K.jsxs)(`div`,{ref:d,className:`
absolute left-1/2 -translate-x-1/2 z-50
${c===`top`?`bottom-full mb-2`:`top-full mt-2`}
diff --git a/static/index.html b/static/index.html
index aa12e12d9..0aa0e486f 100644
--- a/static/index.html
+++ b/static/index.html
@@ -26,7 +26,7 @@
-
+