diff --git a/CHANGELOG.md b/CHANGELOG.md index 398b5368b..01554528b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ All notable changes to Bambuddy will be documented in this file. - **Print Log page: per-row delete (#1687 part 1, reported by @IndividualGhost1905)** — Reporter noted that the existing "Also remove this print from Quick Stats" toggle on archive delete is one-shot: if you tick "keep stats" at delete time, there was no later way to drop the row from /stats; and rows that aren't tied to an archive (errors, aborts, manual entries) had no delete affordance at all. **Fix:** every row in the Archives → Print Log table now has a trash icon next to the filament cell, gated on `archives:delete_own` (own rows) or `archives:delete_all` (any row), matching the archive-delete permission shape. Click → confirm modal → row is gone, and because /archives/stats aggregates over `PrintLogEntry` the filament / time / cost contribution drops out of Quick Stats in the same response cycle. The matching archive (if any) is untouched — the log row is a sibling, not a child. **Backend:** new `DELETE /print-log/{entry_id}` mirrors `delete_archive`'s ownership flow via `require_ownership_permission(ARCHIVES_DELETE_ALL, ARCHIVES_DELETE_OWN)`; owners can drop their own rows, admins can drop any row, missing IDs return 404 rather than 200-silently. **Frontend:** new `deletePrintLogEntry` API helper, per-row mutation that invalidates both `print-log` and `archives-stats` query keys so the totals re-render without a manual refresh. **i18n:** 4 new keys (`deleteEntryTitle`, `deleteEntryConfirm`, `entryDeleted`, `entryDeleteFailed`) translated across all 11 locales (de / en / es / fr / it / ja / ko / pt-BR / tr / zh-CN / zh-TW). **Tests:** 3 backend integration cases — delete drops the row from /stats while keeping the linked archive listed, missing ID returns 404, delete-one does not touch siblings (regression guard against an accidental `delete(PrintLogEntry)` without a `where`). Frontend ArchivesPage / PrintLogModal vitests stay green (31 / 31). i18n parity green (5099 leaves × 11 locales). Issue #1687 also asks for per-row tagging (already covered by `EditArchiveModal`'s tags field) and per-row filament-usage-history edits (deferred — see the issue thread for the reasoning). ### Fixed +- **Configure Slot now keeps the active K-profile on reopen for assigned-but-unconfigured slots (#1689 follow-up, reported and patched by @Spionkiller01)** — After the original #1689 fix shipped, Spionkiller01 found a residual case: on a slot that's *physically loaded but unconfigured* (filament inserted, but the printer hasn't bound a preset yet — `tray_type=""`, `tray_info_idx=""`, no `slot_preset_mappings` row), the first open of Configure Slot showed the right K-profile, but closing it with the X and reopening it dropped back to "default 0.020". Clicking "Configure slot" (Apply) once persisted it, but the user shouldn't have to. **Root cause: the original #1689 cali_idx safety net was unreachable on this code path.** `matchingKProfiles` in `ConfigureAmsSlotModal.tsx:751` early-returned `[]` when `selectedPresetInfo` was null — and `selectedPresetInfo` resolves to null exactly when there's no resolvable slot preset (unconfigured slot, no mapping row). The "always include the slot's currently-active K-profile by cali_idx" branch lives *past* the main name+id matcher, so it never ran from the no-preset path. On first open a freshly-cached preset briefly let the safety net trigger; on reopen the live slot state had no preset, returned `[]`, the auto-select effect saw no candidates, the modal fell back to default 0.020. **Fix (verbatim from Spionkiller01's H2C-tested diff, with the existing extruder guard):** split the early return into two — still short-circuit on missing kprofilesData, but when `selectedPresetInfo` is null and `slotInfo.caliIdx > 0`, find the active profile by `slot_id === activeIdx` (extruder-matched when known) and return it as a single-item list. The auto-select effect downstream then pre-selects it on reopen with no extra change. Strictly additive: with a resolvable preset present the existing matcher runs untouched; with `caliIdx === 0 || null` the function still returns `[]` (no unrelated profiles leak in). **Tests:** new vitest case `surfaces the slot's active K-profile when no preset is resolvable (#1689 follow-up)` exercises the path with `trayType=''`, no `savedPresetId`, and `caliIdx=6` against a K-profile fixture at `slot_id=6` — asserts the dropdown surfaces it. Verified the test fails without the patch (stash → run filter → fail; pop → run → pass). The existing `caliIdx === 0` guard test continues to pass under the new branch. Full ConfigureAmsSlotModal vitest 24/24 green. **Credit:** @Spionkiller01 for spotting the residual edge case after merge, producing the diff, and testing live on an H2C — `Co-Authored-By` on the commit. + - **K-profile matching now prefers filament_id over parsed names — surfaces custom profiles in the spool form AND fixes Configure Slot showing "default 0.020" for an actively-bound K-profile (#1688 + #1689, both reported and diagnosed by @Spionkiller01 with concrete H2C testing; #1689 also reported by @IndividualGhost1905)** — Two related symptoms on different UI surfaces, same root cause. **#1688: spool form's PA-profile suggester** (`frontend/src/components/spool-form/PAProfileSection.tsx` via `isMatchingCalibration` in `spool-form/utils.ts`) only matched K-profiles by parsing the profile *name* for material/brand/variant. Spools already store `slicer_filament` (the slicer preset's id) and K-profiles already carry `filament_id`, but both were ignored — so a user's custom K-profile whose name doesn't agree with the slicer preset's name got silently dropped from the suggestion list even when the underlying filament_id was identical. **#1689: ConfigureAmsSlotModal's K-profile filter** (`matchingKProfiles`) ran the same name-only logic on the slot's selected preset — a spool assigned under "Generic PLA" with a custom K-profile actively bound on the printer landed in the modal as "K profile not assigned, default 0.020 will be used", while the printer-card hover-card correctly showed the active profile. The hover-card and the Configure Slot modal disagreed because they used different lookup paths; the modal's path was the one with the name-parse filter. **The shared root cause: spool preset ids and K-profile filament_ids look different but are equivalent after normalisation.** Spools store `slicer_filament` as the cloud setting_id form ("GFSG98_09" — `_09` is the variant suffix, the "S" infix marks it as a setting_id); K-profiles store `filament_id` as the bare form ("GFG98"). Plain `===` doesn't match; both need normalising first. This conversion already exists *in the other direction* at `buildFilamentOptions` (filament_id → "GFS" + filament_id.slice(2) for setting_id), so the inverse `toFilamentId` helper isn't speculative — it's just the matching reverse. **Fix — one shared helper, two surfaces:** new exports in `frontend/src/components/spool-form/utils.ts` — `toFilamentId(id)` normalises both shapes by dropping the "_NN" variant suffix and stripping the "S" in "GFS" (so both "GFSG98_09" and "GFG98" yield "GFG98"); `isGenericFilamentId(id)` flags Bambu's generic `GFx99` ids (GFL99 = generic PLA, GFG99 = generic PETG, etc.) which are shared across many physical filaments and must NOT id-match (they over-match and obscure brand-specific profiles — name fallback handles those correctly). Then: (1) `isMatchingCalibration` accepts a new `slicer_filament?: string` formData field, tries id-match first (with generic exclusion), falls through to the existing name parse — `PAProfileSection` already passes the full `formData` so no caller edit needed. (2) `ConfigureAmsSlotModal.selectedPresetInfo` now also resolves a `filamentId` (via `toFilamentId(cp.setting_id)` for cloud presets; `toFilamentId(builtinFilamentId)` for builtin; empty for local/orca paths that fall through to name match); `matchingKProfiles` adds the id-match check at the top of the per-profile predicate, then keeps the existing name logic, then *always* unshifts the slot's currently-active K-profile (by `slot_id === slotInfo.caliIdx`, gated on `activeIdx > 0` so caliIdx=0/null doesn't leak unrelated profiles in, and extruder-matched when known) — covers the #1689 case where the spool was bound under a generic preset but the active profile lives under a different filament_id entirely. The "always include active" branch is Spionkiller01's #1689 diff verbatim, gated more tightly. **SpoolBuddy coverage:** both K-profile surfaces in the kiosk UI reuse the shared components — `SpoolBuddyWriteTagPage` renders `` (auto-fixed via `isMatchingCalibration`), `SpoolBuddyAmsPage` renders `` (auto-fixed via `matchingKProfiles`). No kiosk-specific edits required; the shared helpers carry the fixes through. (`SpoolBuddyCalibrationPage` is scale calibration, unrelated; `InventorySpoolInfoCard` is display-only.) **What this does NOT change**: spools without a slicer_filament, K-profiles without a filament_id, and generic GFx99 ids all fall through to the existing name-based matching path — strictly additive precedence, no behaviour change for the name-only cases that already worked. The new id-match never causes a *miss* the old code would have caught. **Tests:** 21 new vitest cases — `isMatchingCalibration.test.ts` (18 cases) pins the `toFilamentId` round-trip in both directions (GFSG98_09 → GFG98 and back is identity-preserving for the cloud→K-profile flow), the generic `GFx99` exclusion, falsy/non-Bambu id pass-through (numeric local-preset id, Orca UUID), and the id-match-wins-over-name behaviour including the spool's reported `"GFSG98_09" ↔ K-profile "GFG98"` real-data scenario. `ConfigureAmsSlotModal.test.tsx` (3 cases) pins the modal-level behaviour: a custom K-profile name surfaces when filament_id matches (#1688 in-modal), the slot's active profile is always included even with no name/id match (#1689), and the `caliIdx == 0` guard prevents unrelated profiles from leaking in via the safety net. Full frontend vitest suite: 2108 / 2108 green. ESLint clean on touched files; frontend build clean. **Credit & dispatch:** @Spionkiller01 diagnosed both issues with concrete data (the `GFSG98_09 ↔ GFG98` normalisation case is theirs), tested both patches live on an H2C, and explicitly offered to PR. Landed verbatim with adjustments (shared helper, tighter active-profile guard) and `Co-Authored-By`. @IndividualGhost1905 also reported #1689 independently and identified its connection to #1688. - **Tabs no longer go silently zombie after the JWT expires — auth-expiry now redirects to /login on the same tab (#1698, reported by @TCL987, fix patched in reporter's fork)** — Reporter on X1C, Docker install, left a Bambuddy tab open past the 24 h JWT lifetime. After expiry: navigation between pages still worked, but every API request silently failed, leaving the UI looking like every list was empty. A manual refresh was needed to land on `/login`. **Root cause: `AuthContext.user` stays stale after the JWT clears.** When a 401 with a token-invalidating message (`Token has expired`, `Could not validate credentials`, `User not found or inactive`, `Invalid API key`, `API key has expired`) lands in `frontend/src/api/client.ts:154-167`, the handler calls `setAuthToken(null)` to drop the token from sessionStorage / localStorage — but `AuthContext.user` is a React state value that was populated once at mount via `checkAuthStatus()` → `/auth/me`, and `setAuthToken(null)` doesn't reach into AuthContext's React tree. `ProtectedRoute` (`App.tsx:101`) only redirects when `user === null`, so the protected tree keeps rendering, every subsequent request goes out with no Authorization header, the backend 401s, and the UI shows nothing. A page refresh remounts `AuthProvider`, `checkAuthStatus()` finds no token, `setUser(null)` fires, the redirect runs — which is what the reporter ended up doing every 24 h. The 3 other `setAuthToken(null)` call sites all live inside `AuthContext` itself and pair with `setUser(null)` directly, so no cross-module signal was needed for them; the `client.ts:165` site was the only one missing the React-tree notification. **Fix (mirrors the reporter's fork patch deec96d1):** after `setAuthToken(null)` in `client.ts`, dispatch a `window.dispatchEvent(new CustomEvent('auth:expired'))` (guarded on `typeof window !== 'undefined'` for SSR / test safety). `AuthContext`'s mount `useEffect` adds a `window.addEventListener('auth:expired', handleAuthExpired)` listener whose handler calls `setUser(null)` after a `mountedRef.current` guard, and removes the listener in the effect's cleanup so unmount → remount doesn't double-bind. `ProtectedRoute` then sees `user === null` on the next render and runs `` immediately, no manual refresh needed. **What this intentionally does NOT change**: generic `401 Authentication required` responses (without a token-invalidating message) still don't clear the token or fire the event — they're treated as transient timing issues, exactly as `client.ts:155`'s pre-existing comment documents. So a one-off 401 from a race during login won't redirect a working session. Listener cleanup means tests / dev hot-reload don't accumulate handlers. **Tests:** 4 new vitest cases — `client.test.ts` gains "dispatches 'auth:expired' event on 401 with invalid token message" and "does not dispatch 'auth:expired' on 401 with generic auth error" (both use `vi.fn()` listeners on `window` to assert the event fires/doesn't fire). `AuthContext.test.tsx` gains a new `auth:expired event (#1698)` describe block — "clears user when an auth:expired event is dispatched" simulates the login → expiry → event → user-null flow end-to-end via `setAuthToken('valid-token')` (the canonical setter; writing to sessionStorage post-import wouldn't propagate to the module-level `authToken` variable initialised at import time), and "does not crash when the event fires after unmount" pins the `mountedRef` guard so the listener can't trigger a state-update-after-unmount warning. Full frontend vitest suite: 2087 / 2087 green. ESLint clean on touched files. Frontend build clean. **Credit to @TCL987** for diagnosing this and shipping the working fix on their fork before opening the issue. diff --git a/frontend/src/__tests__/components/ConfigureAmsSlotModal.test.tsx b/frontend/src/__tests__/components/ConfigureAmsSlotModal.test.tsx index 4ed73e453..b6eacfd8a 100644 --- a/frontend/src/__tests__/components/ConfigureAmsSlotModal.test.tsx +++ b/frontend/src/__tests__/components/ConfigureAmsSlotModal.test.tsx @@ -497,6 +497,45 @@ describe('ConfigureAmsSlotModal', () => { }); }); + it("surfaces the slot's active K-profile when no preset is resolvable (#1689 follow-up)", async () => { + // Repro from Spionkiller01: slot is physically loaded but unconfigured — + // tray_type='', tray_info_idx='', no slot_preset_mappings row — so + // selectedPresetInfo resolves to null. Before the patch the main matcher's + // early return on !selectedPresetInfo skipped past the cali_idx safety net + // entirely; on reopen the dropdown went back to default 0.020 even though + // the printer still holds the active profile at cali_idx=6. + (api.getKProfiles as ReturnType).mockResolvedValue({ + profiles: [ + { + slot_id: 6, + extruder_id: 0, + nozzle_id: 'HH00-0.4', + nozzle_diameter: '0.4', + filament_id: 'GFG98', + name: 'active-on-unconfigured-slot', + k_value: '0.030', + n_coef: '0', + ams_id: 0, + tray_id: 0, + setting_id: '', + }, + ], + }); + const slotInfo = { + ...defaultProps.slotInfo, + trayType: '', + traySubBrands: '', + caliIdx: 6, + extruderId: 0, + // savedPresetId intentionally omitted — no preset bound yet + }; + render(); + + await waitFor(() => { + expect(screen.getByRole('option', { name: /active-on-unconfigured-slot/ })).toBeInTheDocument(); + }); + }); + it('does not include the active K-profile when caliIdx is 0 or null (#1689 guard)', async () => { // cali_idx == 0 / null means no profile is active (printer default 0.020). // The safety net only triggers for activeIdx > 0 — otherwise unrelated diff --git a/frontend/src/components/ConfigureAmsSlotModal.tsx b/frontend/src/components/ConfigureAmsSlotModal.tsx index ccfe787c0..60b942d9b 100644 --- a/frontend/src/components/ConfigureAmsSlotModal.tsx +++ b/frontend/src/components/ConfigureAmsSlotModal.tsx @@ -748,7 +748,24 @@ export function ConfigureAmsSlotModal({ }, [colorCatalog, selectedPresetInfo]); const matchingKProfiles = useMemo(() => { - if (!kprofilesData?.profiles || !selectedPresetInfo) return []; + if (!kprofilesData?.profiles) return []; + if (!selectedPresetInfo) { + // Assigned-but-unconfigured slot (filament loaded but the printer hasn't + // bound a preset yet: tray_type=""/tray_info_idx=""/no slot_preset_mappings + // row). The cali_idx safety net further down lives past the main name+id + // matcher and never runs from here, so surface the slot's currently-active + // K-profile directly so Configure Slot keeps showing it across reopen + // instead of dropping to default 0.020 (#1689 follow-up). + const activeIdx = slotInfo.caliIdx; + if (activeIdx != null && activeIdx > 0) { + const active = kprofilesData.profiles.find( + p => p.slot_id === activeIdx + && (slotInfo.extruderId === undefined || p.extruder_id === slotInfo.extruderId), + ); + if (active) return [active]; + } + return []; + } const { fullName, material, brand, filamentId } = selectedPresetInfo; const upperFullName = fullName.toUpperCase(); diff --git a/static/assets/index-kb-CgWpZ.js b/static/assets/index-QVjYxA_R.js similarity index 98% rename from static/assets/index-kb-CgWpZ.js rename to static/assets/index-QVjYxA_R.js index deca9091a..d231855f4 100644 --- a/static/assets/index-kb-CgWpZ.js +++ b/static/assets/index-QVjYxA_R.js @@ -8514,7 +8514,7 @@ ${l("inventory.assignProfileMismatchMessage",{spoolProfile:T.spoolProfile||l("co ${l("inventory.assignProfileMismatchMessage",{spoolProfile:T.spoolProfile||l("common.unknown"),trayProfile:T.trayProfile||l("common.unknown"),location:s.location})}`),A=`${A} -${l("inventory.assignReconfigureNote")}`,r.jsx(ka,{title:l("inventory.assignMismatchTitle"),message:A,confirmText:l("inventory.assignMismatchConfirm"),variant:"warning",overlayZIndex:"z-[110]",isLoading:X.isPending,onConfirm:Q,onCancel:()=>{X.isPending||(N(!1),k(null),j(null))}})})()]})}const h9e={process:new Map,filament:new Map,bambuModelByShortCode:{}};function yse(t){return t.replace(/^#\s*/,"").trim()}const eY={"A1 MINI":["A1M"]};function Pz(t,e){const a=t.toUpperCase(),n=e.toUpperCase();if(a===n)return!0;const i=eY[n];if(i&&i.includes(a))return!0;const s=eY[a];return!!(s&&s.includes(n))}function f9e(t){const e={};for(const[a,n]of Object.entries(t))n in e||(e[n]=a.replace(/^Bambu Lab\s+/,""));return e}function g9e(t,e={}){const a=new Map,n=new Map,i=(s,o,l)=>{const c=yse(o);if(!c)return;const d=s.get(c)??new Set;d.add(l),s.set(c,d)};for(const s of t){const o=s.printer_preset_name?.trim();if(o){for(const l of s.process)i(a,l,o);for(const l of s.filament)i(n,l,o)}}return{process:a,filament:n,bambuModelByShortCode:f9e(e)}}function tY(t){return t.replace(/\s+/g,"").toLowerCase()}const b9e="0.4";function vse(t){const e=t.match(/^(.*?)\s+([\d.]+)\s*nozzle\s*$/i);return e?{stripped:e[1].trim(),nozzle:e[2]}:{stripped:t.trim(),nozzle:null}}function x9e(t){const e="@BBL ",a=t.indexOf(e);if(a<0)return null;const n=t.slice(a+e.length).trim(),{stripped:i,nozzle:s}=vse(n);return i?{token:i,nozzle:s}:null}function y9e(t){const e=t.match(/^Bambu Lab\s+(.+)$/i);if(!e)return null;const{stripped:a,nozzle:n}=vse(e[1]);return a?{model:a,nozzle:n}:null}function v9e(t,e,a){const n=x9e(t);if(!n)return"unknown";const i=a[n.token]??n.token,s=y9e(e);return s?tY(s.model)!==tY(i)&&!Pz(n.token,s.model)||s.nozzle!==null&&(n.nozzle??b9e)!==s.nozzle?"mismatch":"match":"unknown"}function Uy(t,e,a,n){if(!a)return"unknown";const i=t.compatible_printers;if(i&&i.length>0)return i.includes(a)?"match":"mismatch";const s=n[e].get(yse(t.name));return s&&s.size>0?s.has(a)?"match":"mismatch":v9e(t.name,a,n.bambuModelByShortCode)}const wse=["PLA","PETG","ABS","TPU","ASA","PC","PA","PVA","HIPS","PA-CF","PETG-CF","PLA-CF"],w9e=["Bambu","PolyLite","PolyTerra","eSUN","Overture","Fiberon","SUNLU","Inland","Hatchbox","Generic"],fw=["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"],Sse=[{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"}],S9e=[{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"}],aY=[...Sse,...S9e],kse="bambuddy-recent-colors",k9e=8,_9e=[{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 of(t){let e=t.replace(/@.*$/,"").trim();e=e.replace(/\(Custom\)/i,"").trim(),e=e.replace(/^[#*]+\s*/,"").trim();const a=["PLA-CF","PETG-CF","ABS-GF","ASA-CF","PA-CF","PAHT-CF","PA6-CF","PA6-GF","PPA-CF","PPA-GF","PET-CF","PPS-CF","PC-CF","PC-ABS","ABS-GF","PCTG","PETG","PLA","ABS","ASA","PC","PA","TPU","PVA","HIPS","BVOH","PPS","PEEK","PEI"];let n="",i=-1;for(const c of a){const d=e.toUpperCase().indexOf(c.toUpperCase());if(d!==-1){n=c,i=d;break}}let s="";i>0&&(s=e.substring(0,i).trim(),s=s.replace(/[-_\s]+$/,""));let o="";i!==-1&&n&&(o=e.substring(i+n.length).trim(),o=o.replace(/^[-_\s]+/,""));let l="";for(const c of fw)if(o.toLowerCase().includes(c.toLowerCase())){l=c;break}if(!l&&s)for(const c of fw){const d=new RegExp(`\\s+${c}$`,"i");if(d.test(s)){l=c,s=s.replace(d,"").trim();break}}return{brand:s,material:n,variant:l}}function _se(t,e){const a=new Set(w9e);for(const n of t){const{brand:i}=of(n.name);i&&i.length>1&&a.add(i)}if(e)for(const n of e)if(n.filament_vendor&&n.filament_vendor.length>1)a.add(n.filament_vendor);else{const{brand:i}=of(n.name);i&&i.length>1&&a.add(i)}return Array.from(a).sort((n,i)=>n.localeCompare(i))}function P9e(t){const e=t.filter(n=>n.preset_type==="filament");return e.length===0?[]:e.map(n=>{const i=String(n.id),s=n.filament_type||i,o=Array.from(new Set([i,s]));return{code:i,name:n.name,displayName:n.name,isCustom:!1,allCodes:o}}).sort((n,i)=>n.displayName.localeCompare(i.displayName))}function Pse(t,e,a,n){const i=[],s=[],o=new Set;for(const u of t)if(u.is_custom){const m=u.name.toUpperCase();(e.size===0||Array.from(e).some(f=>m.includes(f))||!m.includes("@"))&&(i.push({code:u.setting_id,name:u.name,displayName:`${u.name} (Custom)`,isCustom:!0,allCodes:[u.setting_id]}),o.add(u.setting_id))}else s.push({code:u.setting_id,name:u.name,displayName:u.name,isCustom:!1,allCodes:[u.setting_id]}),o.add(u.setting_id);const l=a&&a.length>0?P9e(a):[],c=[];if(n&&n.length>0)for(const u of n){const m=u.filament_id.startsWith("GF")?"GFS"+u.filament_id.slice(2):u.filament_id;o.has(u.filament_id)||o.has(m)||c.push({code:u.filament_id,name:u.name,displayName:u.name,isCustom:!1,allCodes:[u.filament_id,m]})}const d=[...i,...s,...l,...c];return d.length===0?_9e:d.sort((u,m)=>u.displayName.localeCompare(m.displayName))}function Cse(t,e){if(!t)return;let a=e.find(n=>n.code===t);if(a||(a=e.find(n=>n.allCodes.includes(t))),!a){const n=t.toLowerCase();a=e.find(i=>i.code.toLowerCase()===n||i.allCodes.some(s=>s.toLowerCase()===n))}return a}function Nse(){try{const t=localStorage.getItem(kse);if(t)return JSON.parse(t)}catch{}return[]}function Tse(t,e){const a=e.filter(i=>i.hex.toUpperCase()!==t.hex.toUpperCase()),n=[t,...a].slice(0,k9e);try{localStorage.setItem(kse,JSON.stringify(n))}catch{}return n}function gw(t){if(!t)return"";let e=t.split("_")[0];return/^GFS/i.test(e)&&(e=e.slice(0,2)+e.slice(3)),e.toUpperCase()}function Ase(t){return!!t&&/^GF[A-Z]99$/i.test(t)}function PF(t,e){if(!e.material)return!1;const a=gw(e.slicer_filament),n=gw(t.filament_id);if(a&&n&&a===n&&!Ase(n))return!0;const s=(t.name||"").replace(/^High Flow[_\s]+/i,"").replace(/^Standard[_\s]+/i,"").replace(/^HF[_\s]+/i,"").replace(/^S[_\s]+/i,"").trim(),o=of(s);return!(!(o.material.toUpperCase()===e.material.toUpperCase())||e.brand&&!(o.brand.toLowerCase().includes(e.brand.toLowerCase())||e.brand.toLowerCase().includes(o.brand.toLowerCase()))||e.subtype&&!(o.variant.toLowerCase().includes(e.subtype.toLowerCase())||e.subtype.toLowerCase().includes(o.variant.toLowerCase())||s.toLowerCase().includes(e.subtype.toLowerCase())))}function rY(t,e){if(t===255)return"External";let a,n=!1;t>=128&&t<=135?(a=t-128,n=!0):t>=0&&t<=3?(a=t,n=e===1):a=0,a=Math.max(0,Math.min(a,7));const i=String.fromCharCode(65+a);return n?`HT-${i}`:`AMS-${i}`}function CF(t){const e=t.includes("_")?t.split("_")[0]:t;return e.startsWith("GFS")?"GF"+e.slice(3):(e.startsWith("PFUS")||e.startsWith("PFSP"),e)}const cg=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function nY(t){const e=t.replace(/@.+$/,"").trim(),a=e.toUpperCase(),n=a.match(/\bSUPPORT\s+FOR\s+/);if(n){const s=a.slice(n.index+n[0].length);for(const o of cg)if(new RegExp(`\\b${o}\\b`).test(s)){const c=e.slice(0,n.index).trim();return{material:o,brand:c,variant:"Support"}}}for(const s of cg){const o=new RegExp(`\\b${s}\\b`,"i");if(o.test(a)){const l=e.split(o),c=l[0]?.trim()||"",d=l[1]?.trim()||"";return{material:s,brand:c,variant:d}}}const i=e.split(/\s+/);return i.length>=2?{material:i[1],brand:i[0],variant:i.slice(2).join(" ")}:{material:e,brand:"",variant:""}}function C9e(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const N9e={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"},iY=[{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"}],sY=[{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 oY(t){const e=t.toLowerCase().trim();return N9e[e]||null}function lY(t){const e=t.indexOf("@");if(e<0)return null;const n=t.slice(e+1).trim().match(/^BBL\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);return n?n[1].trim():null}function jse({isOpen:t,onClose:e,printerId:a,slotInfo:n,nozzleDiameter:i="0.4",printerModel:s,onSuccess:o,fullScreen:l}){const{t:c}=wt(),[d,u]=y.useState(""),[m,p]=y.useState(null),[f,g]=y.useState(""),[v,b]=y.useState(""),[x,S]=y.useState(""),[k,C]=y.useState(!1),[N,T]=y.useState(!1),j=y.useRef(""),{data:D,isLoading:P,isError:E}=$e({queryKey:["cloudSettings"],queryFn:()=>ne.getCloudSettings(),enabled:t,retry:!1}),{data:z}=$e({queryKey:["orcaCloudProfilesForAmsSlot"],queryFn:()=>ne.orcaCloudListProfiles(),enabled:t,retry:!1}),{data:I,isLoading:B}=$e({queryKey:["localPresets"],queryFn:()=>ne.getLocalPresets(),enabled:t}),{data:R,isLoading:K}=$e({queryKey:["builtinFilaments"],queryFn:()=>ne.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:J,isLoading:X}=$e({queryKey:["kprofiles",a,i],queryFn:()=>ne.getKProfiles(a,i),enabled:t&&!!a}),{data:ce}=$e({queryKey:["colorCatalog"],queryFn:()=>ne.getColorCatalog(),enabled:t,staleTime:1/0}),de=at({mutationFn:async()=>{if(!d)throw new Error("No filament preset selected");const U=d.startsWith("local_"),$=d.startsWith("builtin_"),H=d.startsWith("orca_")?d.replace("orca_",""):d,le=!U&&!$?z?.filament.find(ze=>ze.setting_id===H):void 0,O=!!le,q=le??null,Z=U?parseInt(d.replace("local_",""),10):null,ee=$?d.replace("builtin_",""):null,re=U?I?.filament.find(ze=>ze.id===Z):null,se=$?R?.find(ze=>ze.filament_id===ee):null,fe=!U&&!$&&!O?D?.filament.find(ze=>ze.setting_id===d):null;if(!U&&!$&&!O&&!fe)throw new Error("Selected preset not found");if(U&&!re)throw new Error("Selected local preset not found");if($&&!se)throw new Error("Selected builtin preset not found");if(O&&!q)throw new Error("Selected Orca Cloud preset not found");const ue=U?re.name:$?se.name:O?q.name:fe.name,pe=nY(ue),G=m?.slot_id??-1,L=f||n.trayColor?.slice(0,6)||"FFFFFF",ae=ue.replace(/@.+$/,"").trim();let ge,be;const ve=pe.material.toUpperCase(),De={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(U){const ze=(cg.includes(ve)?ve:re?.filament_type||pe.material||"").toUpperCase();ge=De[ze]||De[ze.replace(/[-\s]?CF$/,"")]||De[ze.replace(/\+$/,"")]||De[ze.split(/[-\s]/)[0]]||"",be=""}else if(O){const ze=(cg.includes(ve)?ve:pe.material||"").toUpperCase();ge=De[ze]||De[ze.replace(/[-\s]?CF$/,"")]||De[ze.replace(/\+$/,"")]||De[ze.split(/[-\s]/)[0]]||"",be=""}else if($)ge=ee,be="";else if(ge=CF(d),be=d,!d.startsWith("GFS"))try{const ze=await ne.getCloudSettingDetail(d);ze.filament_id&&(ge=ze.filament_id)}catch(ze){console.warn("Failed to fetch preset detail for filament_id:",ze)}let je=U&&re?.nozzle_temp_min?re.nozzle_temp_min:190,Te=U&&re?.nozzle_temp_max?re.nozzle_temp_max:230;if(!U||$||O||!re?.nozzle_temp_min&&!re?.nozzle_temp_max){const ze=(U?cg.includes(ve)?ve:re?.filament_type||pe.material||"":pe.material).toUpperCase();ze.includes("PLA")?(je=190,Te=230):ze.includes("PETG")?(je=220,Te=260):ze.includes("ABS")||ze.includes("ASA")?(je=240,Te=280):ze.includes("TPU")?(je=200,Te=240):ze==="PCTG"?(je=220,Te=260):ze.includes("PC")?(je=260,Te=300):(ze.includes("PA")||ze.includes("NYLON"))&&(je=250,Te=290)}const qe=m?.k_value?parseFloat(m.k_value):0,Ce=U?cg.includes(ve)?ve:re?.filament_type||pe.material||"PLA":O&&cg.includes(ve)?ve:pe.material||"PLA",Ie=await ne.configureAmsSlot(a,n.amsId,n.trayId,{tray_info_idx:ge,tray_type:Ce,tray_sub_brands:ae,tray_color:L+"FF",nozzle_temp_min:je,nozzle_temp_max:Te,cali_idx:G,nozzle_diameter:i,setting_id:be,kprofile_filament_id:m?.filament_id,kprofile_setting_id:m?.setting_id||void 0,k_value:qe}),Re=U?`local_${Z}`:$?`builtin_${ee}`:d,Ue=U?"local":$?"builtin":O?"orca_cloud":"cloud";try{await ne.saveSlotPreset(a,n.amsId,n.trayId,Re,ae,Ue)}catch(ze){console.warn("Failed to save slot preset mapping:",ze)}return Ie},onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),oe=at({mutationFn:async()=>ne.resetAmsSlot(a,n.amsId,n.trayId),onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),Y=y.useMemo(()=>{const U=x.toLowerCase(),$=[],H=new Set,le=n.savedPresetId,O=n.trayInfoIdx;if(z?.filament)for(const q of z.filament){const Z=`orca_${q.setting_id}`;if(H.add(q.setting_id),H.add(Z),!(U&&!q.name.toLowerCase().includes(U))){if(s){const ee=lY(q.name);if(ee&&!Pz(ee,s))continue}$.push({id:Z,name:q.name,source:"orca_cloud",isUser:!0})}}if(D?.filament)for(const q of D.filament){if(H.has(q.setting_id))continue;H.add(q.setting_id);const ee=le===q.setting_id||O&&(q.setting_id===O||CF(q.setting_id)===O);if(!(U&&!q.name.toLowerCase().includes(U))){if(!ee&&s){const re=lY(q.name);if(re&&!Pz(re,s))continue}$.push({id:q.setting_id,name:q.name,source:"cloud",isUser:C9e(q.setting_id)})}}if(I?.filament)for(const q of I.filament){const Z=`local_${q.id}`;U&&!q.name.toLowerCase().includes(U)||$.push({id:Z,name:q.name,source:"local",isUser:!1})}if(R)for(const q of R){if(H.has(q.filament_id))continue;const Z=q.filament_id.startsWith("GF")?"GFS"+q.filament_id.slice(2):q.filament_id;H.has(Z)||(!U||q.name.toLowerCase().includes(U))&&$.push({id:`builtin_${q.filament_id}`,name:q.name,source:"builtin",isUser:!1})}return $.sort((q,Z)=>{const ee={orca_cloud:0,cloud:1,local:2,builtin:3};return q.source!==Z.source?ee[q.source]-ee[Z.source]:q.isUser&&!Z.isUser?-1:!q.isUser&&Z.isUser?1:q.name.localeCompare(Z.name)})},[z?.filament,D?.filament,I?.filament,R,x,s,n.savedPresetId,n.trayInfoIdx]),ie=y.useMemo(()=>{if(!d)return null;let U=null,$="";if(d.startsWith("local_")){const O=parseInt(d.replace("local_",""),10);U=I?.filament.find(Z=>Z.id===O)?.name||null}else if(d.startsWith("builtin_")){const O=d.replace("builtin_","");U=R?.find(Z=>Z.filament_id===O)?.name||null,$=gw(O)}else{const O=d.startsWith("orca_")?d.replace("orca_",""):d,q=z?.filament.find(Z=>Z.setting_id===O);if(q)U=q.name;else if(D?.filament){const Z=D.filament.find(ee=>ee.setting_id===d);U=Z?.name||null,Z&&($=gw(Z.setting_id))}}if(!U)return null;let H=U.replace(/@.+$/,"").trim();H.startsWith("# ")&&(H=H.slice(2).trim());const le=nY(H);return{fullName:H,material:le.material,brand:le.brand,filamentId:$}},[d,D?.filament,I?.filament,R,z?.filament]),me=ie?.fullName||"",he=y.useMemo(()=>{if(!ce||!ie)return[];const{fullName:U,brand:$}=ie,H=U.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return ce.filter(le=>{const O=(le.material||"").toUpperCase(),q=le.manufacturer.toUpperCase();if(!(O===H.toUpperCase()||O.includes(H.toUpperCase())||H.toUpperCase().includes(O)))return!1;if($){const ee=$.toUpperCase();if(!q.includes(ee)&&!ee.includes(q))return!1}return!0})},[ce,ie]),xe=y.useMemo(()=>{if(!J?.profiles||!ie)return[];const{fullName:U,material:$,brand:H,filamentId:le}=ie,O=U.toUpperCase(),q=$.toUpperCase(),Z=H.toUpperCase(),ee=le;if(!q||q.length<2)return[];const re=J.profiles.filter(pe=>{if(ee){const ge=gw(pe.filament_id);if(ge&&ge===ee&&!Ase(ge))return!0}const G=pe.name.toUpperCase();if(Z)return!(!G.includes(Z)||!G.includes(q));if(G.includes(O)||G.includes(q))return!0;const ae={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[q]||[];for(const ge of ae)if(G.includes(ge))return!0;return!1}),se=new Map;for(const pe of re){const G=`${pe.name}|${pe.k_value}`,L=se.get(G);L?n.extruderId!==void 0&&pe.extruder_id===n.extruderId&&L.extruder_id!==n.extruderId&&se.set(G,pe):se.set(G,pe)}const fe=Array.from(se.values()),ue=n.caliIdx;if(ue!=null&&ue>0&&!fe.some(pe=>pe.slot_id===ue)){const pe=J.profiles.find(G=>G.slot_id===ue&&(n.extruderId===void 0||G.extruder_id===n.extruderId));pe&&fe.unshift(pe)}return fe},[J?.profiles,ie,n.extruderId,n.caliIdx]);y.useEffect(()=>{if(t){if(n.savedPresetId)u(n.savedPresetId);else if(n.trayInfoIdx&&D?.filament){let U=D.filament.find($=>$.setting_id===n.trayInfoIdx);U||(U=D.filament.find($=>CF($.setting_id)===n.trayInfoIdx)),U&&u(U.setting_id)}else if(n.trayInfoIdx&&R?.length){const U=n.trayInfoIdx,$=R.find(H=>H.filament_id===U);$&&u(`builtin_${$.filament_id}`)}if(n.trayColor){const U=n.trayColor.slice(0,6);U&&g(U)}}else u(""),p(null),g(""),b(""),S(""),C(!1),j.current=""},[t,n.savedPresetId,n.trayInfoIdx,n.trayColor,D?.filament,R]),y.useEffect(()=>{if(xe.length>0){if(n.caliIdx!=null&&n.caliIdx>0){const U=xe.find($=>$.slot_id===n.caliIdx);if(U){p(U);return}}p(xe[0])}else p(null)},[d,xe,n.caliIdx]);const V=y.useCallback(U=>{U.key==="Escape"&&e()},[e]);y.useEffect(()=>{if(t)return document.addEventListener("keydown",V),()=>document.removeEventListener("keydown",V)},[t,V]);const Q=P&&!E||B||K||X;if(y.useEffect(()=>{if(!Q&&d&&d!==j.current){const U=requestAnimationFrame(()=>{const H=document.querySelector('[class*="fixed inset-0 z-50"]')?.querySelector(`[data-preset-id="${CSS.escape(d)}"]`);H&&(j.current=d,H.scrollIntoView({block:"nearest"}))});return()=>cancelAnimationFrame(U)}},[d,Q]),!t)return null;const A=d&&!de.isPending,F=f||n.trayColor?.slice(0,6)||"FFFFFF";return r.jsxs("div",{className:`fixed inset-0 z-50 flex ${l?"":"items-center justify-center"}`,children:[!l&&r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),r.jsxs("div",{className:l?"relative w-full h-full bg-bambu-dark-secondary flex flex-col":"relative w-full max-w-lg mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl",children:[r.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(xd,{className:"w-5 h-5 text-bambu-blue"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.title")}),l&&r.jsxs("div",{className:"flex items-center gap-2 ml-4 text-sm text-bambu-gray",children:[r.jsx("span",{className:"text-white/30",children:"|"}),n.trayColor&&r.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${n.trayColor.slice(0,6)}`}}),r.jsx("span",{className:"text-white/70",children:c("configureAmsSlot.slotLabel",{ams:rY(n.amsId,n.trayCount),slot:n.trayId+1})}),n.traySubBrands&&r.jsxs("span",{children:["(",n.traySubBrands,")"]})]})]}),r.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:r.jsx(Ht,{className:"w-5 h-5"})})]}),r.jsxs("div",{className:`p-4 overflow-y-auto ${l?"flex-1 min-h-0":"space-y-4 max-h-[60vh]"}`,children:[k&&r.jsx("div",{className:"absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl",children:r.jsxs("div",{className:"text-center space-y-3",children:[r.jsx(to,{className:"w-16 h-16 text-bambu-green mx-auto"}),r.jsx("p",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.slotConfigured")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:c("configureAmsSlot.settingsSentToPrinter")})]})}),!l&&r.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[r.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:c("configureAmsSlot.configuringSlot")}),r.jsxs("div",{className:"flex items-center gap-2",children:[n.trayColor&&r.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${n.trayColor.slice(0,6)}`}}),r.jsx("span",{className:"text-white font-medium",children:c("configureAmsSlot.slotLabel",{ams:rY(n.amsId,n.trayCount),slot:n.trayId+1})}),n.traySubBrands&&r.jsxs("span",{className:"text-bambu-gray",children:["(",n.traySubBrands,")"]})]})]}),Q?r.jsx("div",{className:"flex justify-center py-8",children:r.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):l?r.jsxs("div",{className:"flex gap-4 h-full",children:[r.jsxs("div",{className:"w-1/2 flex flex-col min-h-0",children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",r.jsx("span",{className:"text-red-400",children:"*"})]}),r.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:x,onChange:U=>S(U.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"}),r.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-1",children:Y.length===0?r.jsx("p",{className:"text-center py-4 text-bambu-gray",children:D?.filament?.length===0&&!I?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):Y.map(U=>r.jsx("button",{"data-preset-id":U.id,onClick:()=>u(U.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${d===U.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all",title:U.name,children:U.name}),r.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[U.source==="local"&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),U.source==="builtin"&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),U.isUser&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},U.id))})]}),r.jsxs("div",{className:"w-1/2 flex flex-col gap-4 min-h-0 overflow-y-auto",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),me&&r.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:me})})]}),xe.length>0?r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:m?.name||"",onChange:U=>{const $=xe.find(H=>H.name===U.target.value);p($||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:[r.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),xe.map(U=>r.jsxs("option",{value:U.name,children:[U.name," (K=",U.k_value,")"]},`${U.name}-${U.extruder_id}`))]}),r.jsx(za,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):d?r.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):r.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),m&&r.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:m.k_value})})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),he.length>0&&r.jsxs("div",{className:"mb-3",children:[r.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:ie?.fullName})}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:he.map(U=>r.jsxs("button",{onClick:()=>{const $=U.hex_color.replace("#","").toUpperCase();g($),b(U.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===U.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:U.color_name,children:[r.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:U.hex_color}}),r.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:U.color_name})]},U.id))})]}),r.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[iY.map(U=>r.jsx("button",{onClick:()=>{g(U.hex),b(U.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===U.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${U.hex}`},title:U.name},U.hex)),r.jsx("button",{onClick:()=>T(!N),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(N?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:N?"−":"+"})]}),N&&r.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:sY.map(U=>r.jsx("button",{onClick:()=>{g(U.hex),b(U.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===U.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${U.hex}`},title:U.name},U.hex))}),r.jsxs("div",{className:"flex gap-2 items-center",children:[r.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${F}`}}),r.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:U=>{const $=U.target.value;b($);const H=oY($);if(H)g(H);else{const le=$.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();le.length===6?g(le):le.length===3&&g(le.split("").map(O=>O+O).join(""))}},className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm"}),f&&r.jsx("button",{onClick:()=>{g(""),b("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&r.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",r.jsx("span",{className:"text-red-400",children:"*"})]}),r.jsxs("div",{className:"relative",children:[r.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:x,onChange:U=>S(U.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"}),r.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:Y.length===0?r.jsx("p",{className:"text-center py-4 text-bambu-gray",children:D?.filament?.length===0&&!I?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):Y.map(U=>r.jsx("button",{"data-preset-id":U.id,onClick:()=>u(U.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${d===U.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all",title:U.name,children:U.name}),r.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[U.source==="local"&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),U.source==="builtin"&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),U.isUser&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},U.id))})]})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),me&&r.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:me})})]}),xe.length>0?r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:m?.name||"",onChange:U=>{const $=xe.find(H=>H.name===U.target.value);p($||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:[r.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),xe.map(U=>r.jsxs("option",{value:U.name,children:[U.name," (K=",U.k_value,")"]},`${U.name}-${U.extruder_id}`))]}),r.jsx(za,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):d?r.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):r.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),m&&r.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:m.k_value})})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),he.length>0&&r.jsxs("div",{className:"mb-3",children:[r.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:ie?.fullName})}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:he.map(U=>r.jsxs("button",{onClick:()=>{const $=U.hex_color.replace("#","").toUpperCase();g($),b(U.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===U.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:U.color_name,children:[r.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:U.hex_color}}),r.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:U.color_name})]},U.id))})]}),r.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[iY.map(U=>r.jsx("button",{onClick:()=>{g(U.hex),b(U.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===U.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${U.hex}`},title:U.name},U.hex)),r.jsx("button",{onClick:()=>T(!N),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(N?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:N?"−":"+"})]}),N&&r.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:sY.map(U=>r.jsx("button",{onClick:()=>{g(U.hex),b(U.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===U.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${U.hex}`},title:U.name},U.hex))}),r.jsxs("div",{className:"flex gap-2 items-center",children:[r.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${F}`}}),r.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:U=>{const $=U.target.value;b($);const H=oY($);if(H)g(H);else{const le=$.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();le.length===6?g(le):le.length===3&&g(le.split("").map(O=>O+O).join(""))}},className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm"}),f&&r.jsx("button",{onClick:()=>{g(""),b("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&r.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}),r.jsxs("div",{className:"flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[r.jsx(Le,{variant:"secondary",onClick:()=>oe.mutate(),disabled:oe.isPending||de.isPending,className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:oe.isPending?r.jsxs(r.Fragment,{children:[r.jsx(lt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.resetting")]}):r.jsxs(r.Fragment,{children:[r.jsx(bs,{className:"w-4 h-4"}),c("configureAmsSlot.resetSlot")]})}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx(Le,{variant:"secondary",onClick:e,children:c("configureAmsSlot.cancel")}),r.jsx(Le,{onClick:()=>de.mutate(),disabled:!A,children:de.isPending?r.jsxs(r.Fragment,{children:[r.jsx(lt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.configuring")]}):r.jsxs(r.Fragment,{children:[r.jsx(xd,{className:"w-4 h-4"}),c("configureAmsSlot.configureSlot")]})})]})]}),(de.isError||oe.isError)&&r.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:de.error?.message||oe.error?.message})]})]})}function cY({className:t="w-4 h-4"}){return r.jsx("svg",{viewBox:"0 0 1945 1370",fill:"none",className:t,"aria-hidden":"true",children:r.jsxs("g",{transform:"translate(-754.293 -471.685)",children:[r.jsxs("g",{transform:"translate(0.18191 255.976)",children:[r.jsx("g",{transform:"matrix(1.05469 0 0 0.241063 -153.484 1120.2)",children:r.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"})}),r.jsx("g",{transform:"matrix(0.983656 0 0 1.0767 -62.2035 141.539)",children:r.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"})})]}),r.jsx("g",{transform:"translate(21.1916 0.684817)",children:r.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 Mse({folderId:t,onClose:e,onUploadComplete:a,onFileUploaded:n,autoUpload:i,validateFile:s,accept:o}){const{t:l}=wt(),[c,d]=y.useState([]),[u,m]=y.useState(!1),[p,f]=y.useState(!1),[g,v]=y.useState(!0),[b,x]=y.useState(!1),[S,k]=y.useState(!0),[C,N]=y.useState(null),T=y.useRef(null),j=oe=>{oe.preventDefault(),m(!0)},D=oe=>{oe.preventDefault(),m(!1)},P=oe=>{oe.preventDefault(),m(!1),B(Array.from(oe.dataTransfer.files))},E=oe=>{oe.target.files&&B(Array.from(oe.target.files))},z=(oe,Y)=>{d(ie=>ie.map(me=>me.file===oe?{...me,...Y}:me))},I=async oe=>{f(!0);for(const Y of oe)if(Y.status==="pending"){z(Y.file,{status:"uploading"});try{if(Y.isZip){const ie=await ne.extractZipFile(Y.file,t,g,b,S);z(Y.file,{status:ie.errors.length>0&&ie.extracted===0?"error":"success",extractedCount:ie.extracted,error:ie.errors.length>0?l("fileManager.zipFilesFailed","{{count}} files failed",{count:ie.errors.length}):void 0})}else{const ie=await ne.uploadLibraryFile(Y.file,t,S);z(Y.file,{status:"success"});const me=n?.(ie);if(me){N(me),d([]),f(!1);return}}}catch(ie){z(Y.file,{status:"error",error:ie instanceof Error?ie.message:l("fileManager.uploadFailed","Upload failed")})}}f(!1),a(),d(Y=>(Y.some(me=>me.status==="error")||e(),Y))},B=oe=>{if(N(null),s)for(const ie of oe){const me=s(ie);if(me){N(me);return}}const Y=oe.map(ie=>({file:ie,status:"pending",isZip:ie.name.toLowerCase().endsWith(".zip"),is3mf:ie.name.toLowerCase().endsWith(".3mf")}));d(ie=>[...ie,...Y]),i&&oe.length>0&&I(Y)},R=oe=>{d(Y=>Y.filter((ie,me)=>me!==oe))},K=c.some(oe=>oe.isZip&&oe.status==="pending"),J=c.some(oe=>oe.file.name.toLowerCase().endsWith(".stl")&&oe.status==="pending"),X=c.some(oe=>oe.is3mf&&oe.status==="pending"),ce=c.filter(oe=>oe.status==="pending").length,de=c.length>0&&ce===0&&!p;return r.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-lg border border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[r.jsx("h2",{className:"text-lg font-semibold text-white",children:l("fileManager.uploadFiles")}),r.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:r.jsx(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),r.jsxs("div",{className:"p-4 space-y-4",children:[r.jsxs("div",{onDragOver:j,onDragLeave:D,onDrop:P,onClick:()=>T.current?.click(),className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${u?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,children:[r.jsx(fn,{className:`w-10 h-10 mx-auto mb-3 ${u?"text-bambu-green":"text-bambu-gray"}`}),r.jsx("p",{className:"text-white font-medium",children:l(u?"fileManager.dropFilesHere":"fileManager.dragDropFiles")}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:l("fileManager.orClickToBrowse")}),r.jsx("p",{className:"text-xs text-bambu-gray/70 mt-2",children:l("fileManager.allFileTypesSupported")})]}),r.jsx("input",{ref:T,type:"file",multiple:!0,accept:o,className:"hidden",onChange:E}),K&&r.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(ro,{className:"w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"text-sm text-blue-300 font-medium",children:l("fileManager.zipFilesDetected")}),r.jsx("p",{className:"text-xs text-blue-300/70 mt-1",children:l("fileManager.zipExtractOptions")}),r.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:g,onChange:oe=>v(oe.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsx("span",{className:"text-sm text-white",children:l("fileManager.preserveZipStructure")})]}),r.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:b,onChange:oe=>x(oe.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsx("span",{className:"text-sm text-white",children:l("fileManager.createFolderFromZip")})]})]})]})}),X&&r.jsx("div",{className:"p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(xr,{className:"w-5 h-5 text-purple-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"text-sm text-purple-300 font-medium",children:l("fileManager.threemfDetected")}),r.jsx("p",{className:"text-xs text-purple-300/70 mt-1",children:l("fileManager.threemfExtractionInfo")})]})]})}),(J||K)&&r.jsx("div",{className:"p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(bu,{className:"w-5 h-5 text-bambu-green mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"text-sm text-bambu-green font-medium",children:l("fileManager.stlThumbnailGeneration")}),r.jsx("p",{className:"text-xs text-bambu-green/70 mt-1",children:l(K&&!J?"fileManager.zipMayContainStl":"fileManager.thumbnailsCanBeGenerated")}),r.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S,onChange:oe=>k(oe.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsx("span",{className:"text-sm text-white",children:l("fileManager.generateThumbnailsForStl")})]})]})]})}),c.length>0&&r.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:c.map((oe,Y)=>r.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[oe.isZip?r.jsx(ro,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):r.jsx(D1,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm text-white truncate",children:oe.file.name}),r.jsxs("p",{className:"text-xs text-bambu-gray",children:[(oe.file.size/1024/1024).toFixed(2)," MB",oe.isZip&&oe.status==="pending"&&r.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",l("fileManager.willBeExtracted")]}),oe.extractedCount!==void 0&&r.jsxs("span",{className:"text-green-400 ml-2",children:["• ",l("fileManager.filesExtracted",{count:oe.extractedCount})]})]}),oe.status==="error"&&oe.error&&r.jsx("p",{className:"text-xs text-red-400 mt-1 break-words",children:oe.error})]}),oe.status==="pending"&&r.jsx("button",{onClick:()=>R(Y),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:r.jsx(Ht,{className:"w-4 h-4 text-bambu-gray"})}),oe.status==="uploading"&&r.jsx(lt,{className:"w-4 h-4 text-bambu-green animate-spin"}),oe.status==="success"&&r.jsx(fr,{className:"w-4 h-4 text-green-500"}),oe.status==="error"&&r.jsx("span",{title:oe.error,children:r.jsx(Fr,{className:"w-4 h-4 text-red-500"})})]},Y))}),C&&r.jsx("div",{className:"p-3 bg-red-500/10 border border-red-500/30 rounded-lg",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(Fr,{className:"w-5 h-5 text-red-400 mt-0.5 flex-shrink-0"}),r.jsx("p",{className:"text-sm text-red-300",children:C})]})})]}),r.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2",children:[r.jsx(Le,{variant:"secondary",onClick:e,children:l("common.cancel")}),!de&&r.jsx(Le,{onClick:()=>I(c),disabled:ce===0||p,children:p?r.jsxs(r.Fragment,{children:[r.jsx(lt,{className:"w-4 h-4 mr-2 animate-spin"}),l("fileManager.uploading")]}):r.jsxs(r.Fragment,{children:[r.jsx(fn,{className:"w-4 h-4 mr-2"}),l("common.upload")," ",ce>0?`(${ce})`:""]})})]})]})})}function dY(t){if(!t)return"#808080";const e=t.replace("#","");return e.length>=8&&e.substring(6,8).toLowerCase()!=="ff"?`#${e.substring(0,8)}`:`#${e.substring(0,6)}`}function On(t){return t?t.replace("#","").toLowerCase().substring(0,6):""}const T9e=[["PA-CF","PA12-CF","PAHT-CF"]],Ese={};for(const t of T9e){const e=t[0];for(const a of t)Ese[a.toUpperCase()]=e.toUpperCase()}function jT(t){if(!t)return"";const e=t.toUpperCase();return Ese[e]??e}function NF(t,e){return jT(t)===jT(e)}function fd(t,e,a=40){const n=On(t),i=On(e);if(!n||!i||n.length<6||i.length<6)return!1;const s=parseInt(n.substring(0,2),16),o=parseInt(n.substring(2,4),16),l=parseInt(n.substring(4,6),16),c=parseInt(i.substring(0,2),16),d=parseInt(i.substring(2,4),16),u=parseInt(i.substring(4,6),16);return Math.abs(s-c)<=a&&Math.abs(o-d)<=a&&Math.abs(l-u)<=a}function yk(t,e,a,n){if(n)return"Ext";const i=String.fromCharCode(65+(t>=128?t-128:t));return a?`HT-${i}`:`${i}${e+1}`}function ib(t,e,a){return a?254+e:t>=128?t:t*4+e}function by(t){return t>50?"#00ae42":t>=15?"#f59e0b":"#ef4444"}function GC(t){return!t?.remaining_weight||!t?.filament_weight||t.filament_weight<=0?null:Math.min(100,Math.round(t.remaining_weight/t.filament_weight*100))}function uY(t,e){return(Number.isFinite(t)?Math.max(0,Math.trunc(t)):0).toString(16).toUpperCase().padStart(e,"0").slice(-e)}function A9e(t){const e=(t||"").trim().toUpperCase();let a=2166136261;for(let n=0;n>>0).toString(16).toUpperCase().padStart(8,"0")}function Sm(t,e,a){return`${A9e(t)}${uY(e,4)}${uY(a,4)}`}function mY(t){if(!t)return!1;const e=Date.now()+4320*60*60*1e3;return(Ga(t)?.getTime()??0)>e}function j9e(t,e,a,n){let i=Dse(e,t.nozzle_id);n&&(i=[...i].sort((c,d)=>{const u=(c.remain??-1)>=0?c.remain??-1:101,m=(d.remain??-1)>=0?d.remain??-1:101;return u-m}));const s=i.find(c=>!a.has(c.globalTrayId)&&NF(c.type,t.type)&&On(c.color)===On(t.color)),o=s?void 0:i.find(c=>!a.has(c.globalTrayId)&&NF(c.type,t.type)&&fd(c.color,t.color)),l=s||o?void 0:i.find(c=>!a.has(c.globalTrayId)&&NF(c.type,t.type));return s??o??l}function Dse(t,e){return t.filter(a=>e==null||a.extruderId===e)}function Qs(t){return t?!!(t.tray_uuid&&t.tray_uuid!=="00000000000000000000000000000000"||t.tag_uid&&t.tag_uid!=="0000000000000000"):!1}function vk(t){const e=[],a=t?.ams_extruder_map,n=!!t?.nozzles?.[1]?.nozzle_diameter||a&&Object.keys(a).length>0||(t?.vt_tray?.length??0)>1;t?.ams?.forEach(i=>{const s=i.tray.length===1;i.tray.forEach(o=>{if(o.tray_type){const l=dY(o.tray_color);e.push({type:o.tray_type,color:l,colorName:_c(l),amsId:i.id,trayId:o.id,isHt:s,isExternal:!1,label:yk(i.id,o.id,s,!1),globalTrayId:ib(i.id,o.id,!1),trayInfoIdx:o.tray_info_idx||"",traySubBrands:o.tray_sub_brands||"",extruderId:a?.[String(i.id)],remain:o.remain??-1})}})});for(const i of t?.vt_tray??[])if(i.tray_type){const s=dY(i.tray_color),o=i.id??254,l=(t?.vt_tray?.length??0)>1;e.push({type:i.tray_type,color:s,colorName:_c(s),amsId:-1,trayId:o-254,isHt:!1,isExternal:!0,label:l?o===254?"Ext-L":"Ext-R":"External",globalTrayId:o,trayInfoIdx:i.tray_info_idx||"",traySubBrands:i.tray_sub_brands||"",extruderId:n?255-o:void 0,remain:i.remain??-1})}return e}function pY(t,e,a){if(!t?.filaments||t.filaments.length===0)return;const n=vk(e);if(n.length===0)return;const i=e?.fila_switch?.installed===!0,s=new Set,o=t.filaments.map(d=>{const u=d.tray_info_idx||"";let m=n.filter(x=>!s.has(x.globalTrayId));d.nozzle_id!=null&&!i&&(m=m.filter(x=>x.extruderId===d.nozzle_id)),a&&(m=[...m].sort((x,S)=>{const k=x.remain>=0?x.remain:101,C=S.remain>=0?S.remain:101;return k-C}));let p,f,g,v;if(u){const x=m.filter(S=>S.trayInfoIdx===u);x.length===1?p=x[0]:x.length>1&&(a&&x.sort((S,k)=>{const C=S.remain>=0?S.remain:101,N=k.remain>=0?k.remain:101;return C-N}),f=x.find(S=>S.type?.toUpperCase()===d.type?.toUpperCase()&&On(S.color)===On(d.color)),f||(g=x.find(S=>S.type?.toUpperCase()===d.type?.toUpperCase()&&fd(S.color,d.color))),!f&&!g&&(v=x.find(S=>S.type?.toUpperCase()===d.type?.toUpperCase())))}!p&&!f&&!g&&!v&&(f=m.find(x=>x.type?.toUpperCase()===d.type?.toUpperCase()&&On(x.color)===On(d.color)),f||(g=m.find(x=>x.type?.toUpperCase()===d.type?.toUpperCase()&&fd(x.color,d.color))),!f&&!g&&(v=m.find(x=>x.type?.toUpperCase()===d.type?.toUpperCase())));const b=p||f||g||v||void 0;return b&&s.add(b.globalTrayId),{slot_id:d.slot_id,globalTrayId:b?.globalTrayId??-1}}),l=Math.max(...o.map(d=>d.slot_id||0));if(l<=0)return;const c=new Array(l).fill(-1);return o.forEach(d=>{d.slot_id&&d.slot_id>0&&(c[d.slot_id-1]=d.globalTrayId)}),c}function M9e(t){return y.useMemo(()=>vk(t),[t])}function Fse(t,e,a,n){const i=M9e(e),s=e?.fila_switch?.installed===!0,o=y.useMemo(()=>{if(!t?.filaments||t.filaments.length===0)return[];const u=new Set(Object.values(a));return t.filaments.map(m=>{const p=m.slot_id||0;if(p>0&&a[p]!==void 0){const D=a[p],P=i.find(E=>E.globalTrayId===D);if(P){const E=P.type?.toUpperCase()===m.type?.toUpperCase(),z=On(P.color)===On(m.color)||fd(P.color,m.color);let I;return E&&z?I="match":E?I="type_only":I="mismatch",{...m,loaded:P,hasFilament:!0,typeMatch:E,colorMatch:z,status:I,isManual:!0}}}const f=m.tray_info_idx||"";let g=i.filter(D=>!u.has(D.globalTrayId));m.nozzle_id!=null&&!s&&(g=g.filter(D=>D.extruderId===m.nozzle_id)),n&&(g=[...g].sort((D,P)=>{const E=D.remain>=0?D.remain:101,z=P.remain>=0?P.remain:101;return E-z}));let v,b,x,S;if(f){const D=g.filter(P=>P.trayInfoIdx===f);D.length===1?v=D[0]:D.length>1&&(n&&D.sort((P,E)=>{const z=P.remain>=0?P.remain:101,I=E.remain>=0?E.remain:101;return z-I}),b=D.find(P=>P.type?.toUpperCase()===m.type?.toUpperCase()&&On(P.color)===On(m.color)),b||(x=D.find(P=>P.type?.toUpperCase()===m.type?.toUpperCase()&&fd(P.color,m.color))),!b&&!x&&(S=D.find(P=>P.type?.toUpperCase()===m.type?.toUpperCase())))}!v&&!b&&!x&&!S&&(b=g.find(D=>D.type?.toUpperCase()===m.type?.toUpperCase()&&On(D.color)===On(m.color)),b||(x=g.find(D=>D.type?.toUpperCase()===m.type?.toUpperCase()&&fd(D.color,m.color))),!b&&!x&&(S=g.find(D=>D.type?.toUpperCase()===m.type?.toUpperCase())));const k=v||b||x||S||void 0;k&&u.add(k.globalTrayId);const C=!!k,N=C,T=!!v||!!b||!!x;let j;return v||b||x?j="match":S?j="type_only":j="mismatch",{...m,loaded:k,hasFilament:C,typeMatch:N,colorMatch:T,status:j,isManual:!1}})},[t,i,a,n,s]),l=y.useMemo(()=>{if(o.length===0)return;const u=Math.max(...o.map(p=>p.slot_id||0));if(u<=0)return;const m=new Array(u).fill(-1);return o.forEach(p=>{p.slot_id&&p.slot_id>0&&(m[p.slot_id-1]=p.loaded?.globalTrayId??-1)}),m},[o]),c=o.some(u=>u.status==="mismatch"),d=o.some(u=>u.status==="type_only");return{loadedFilaments:i,filamentComparison:o,amsMapping:l,hasTypeMismatch:c,hasColorMismatch:d}}function E9e(t,e,a,n){if(!t||t.length===0)return{exactMatches:0,typeOnlyMatches:0,missingTypes:0,totalSlots:0,status:"full"};let i=0,s=0,o=0;const l=new Set(Object.values(a));for(const u of t){const m=u.slot_id||0;if(m>0&&a[m]!==void 0){const x=a[m],S=e.find(k=>k.globalTrayId===x);if(S){const k=S.type?.toUpperCase()===u.type?.toUpperCase(),C=On(S.color)===On(u.color)||fd(S.color,u.color);k&&C?i++:k?s++:o++;continue}}let p=e.filter(x=>!l.has(x.globalTrayId));if(u.nozzle_id!=null){const x=p.filter(S=>S.extruderId===u.nozzle_id);x.length>0&&(p=x)}n&&(p=[...p].sort((x,S)=>{const k=x.remain>=0?x.remain:101,C=S.remain>=0?S.remain:101;return k-C}));const f=p.find(x=>x.type?.toUpperCase()===u.type?.toUpperCase()&&On(x.color)===On(u.color)),g=f?void 0:p.find(x=>x.type?.toUpperCase()===u.type?.toUpperCase()&&fd(x.color,u.color)),v=f||g?void 0:p.find(x=>x.type?.toUpperCase()===u.type?.toUpperCase()),b=f??g??v;b&&l.add(b.globalTrayId),f||g?i++:v?s++:o++}const c=t.length;let d="full";return o>0?d="missing":s>0&&(d="partial"),{exactMatches:i,typeOnlyMatches:s,missingTypes:o,totalSlots:c,status:d}}function D9e(t,e,a,n){if(!t?.filaments||t.filaments.length===0)return;const i=vk(e);if(i.length===0)return;const s=new Set(Object.values(a)),o=[];for(const d of t.filaments){const u=d.slot_id||0;if(u>0&&a[u]!==void 0){o.push({slot_id:u,globalTrayId:a[u]});continue}let m=i.filter(b=>!s.has(b.globalTrayId));if(d.nozzle_id!=null){const b=m.filter(x=>x.extruderId===d.nozzle_id);b.length>0&&(m=b)}n&&(m=[...m].sort((b,x)=>{const S=b.remain>=0?b.remain:101,k=x.remain>=0?x.remain:101;return S-k}));const p=m.find(b=>b.type?.toUpperCase()===d.type?.toUpperCase()&&On(b.color)===On(d.color)),f=p?void 0:m.find(b=>b.type?.toUpperCase()===d.type?.toUpperCase()&&fd(b.color,d.color)),g=p||f?void 0:m.find(b=>b.type?.toUpperCase()===d.type?.toUpperCase()),v=p??f??g;v&&s.add(v.globalTrayId),o.push({slot_id:u,globalTrayId:v?.globalTrayId??-1})}const l=Math.max(...o.map(d=>d.slot_id||0));if(l<=0)return;const c=new Array(l).fill(-1);return o.forEach(d=>{d.slot_id&&d.slot_id>0&&(c[d.slot_id-1]=d.globalTrayId)}),c}const hY={useDefault:!0,manualMappings:{},autoConfigured:!1};function F9e(t,e,a,n,i,s,o){const l=df({queries:t.map(v=>({queryKey:["printer-status",v],queryFn:()=>ne.getPrinterStatus(v),enabled:t.length>0,staleTime:5e3}))}),c=y.useMemo(()=>t.map((v,b)=>{const x=l[b],S=x?.data,C=e?.find(z=>z.id===v)?.name||`Printer ${v}`,N=vk(S),T=i[v]||hY,j=pY(a,S,o),D=T.useDefault?n:T.manualMappings,P=D9e(a,S,D,o),E=E9e(a?.filaments,N,D,o);return{printerId:v,printerName:C,status:S,isLoading:x?.isLoading??!1,loadedFilaments:N,autoMapping:j,finalMapping:P,matchStatus:E.status,exactMatches:E.exactMatches,typeOnlyMatches:E.typeOnlyMatches,missingTypes:E.missingTypes,totalSlots:E.totalSlots,config:T}}),[t,l,e,a,i,n,o]),d=l.some(v=>v.isLoading),u=(v,b)=>{s(x=>({...x,[v]:{...x[v]||hY,...b}}))},m=v=>{const b=c.find(k=>k.printerId===v);if(!b||!b.status||!a?.filaments)return;const x=pY(a,b.status,o);if(!x)return;const S={};x.forEach((k,C)=>{k!==-1&&(S[C+1]=k)}),u(v,{useDefault:!1,manualMappings:S,autoConfigured:!0})},p=()=>{for(const v of t)m(v)},f=v=>c.find(x=>x.printerId===v)?.finalMapping,g=c.every(v=>v.matchStatus!=="missing");return{printerResults:c,isLoading:d,perPrinterConfigs:i,updatePrinterConfig:u,autoConfigureAll:p,autoConfigurePrinter:m,getFinalMapping:f,allPrintersReady:g}}const Lse={USD:"$",EUR:"€",GBP:"£",CHF:"Fr.",JPY:"¥",CNY:"¥",CAD:"$",AUD:"$",INR:"₹",HKD:"HK$",KRW:"₩",SEK:"kr",NOK:"kr",DKK:"kr",PLN:"zł",BRL:"R$",TWD:"NT$",SGD:"S$",NZD:"NZ$",MXN:"MX$",BZD:"BZ$",MYR:"RM",CZK:"Kč",THB:"฿",ZAR:"R",TRY:"₺",RUB:"₽",HUF:"Ft",ILS:"₪",UAH:"₴"};function Vo(t){return Lse[t.toUpperCase()]||t}const L9e=Object.entries(Lse).map(([t,e])=>({code:t,label:`${t} (${e})`})),Vd="/img/bed",R9e={"cool plate":{icon:`${Vd}/bed_cool.png`,label:"Cool Plate"},"pc plate":{icon:`${Vd}/bed_cool.png`,label:"Cool Plate"},"cool plate (supertack)":{icon:`${Vd}/bed_cool_supertack.png`,label:"Cool Plate SuperTack"},"supertack plate":{icon:`${Vd}/bed_cool_supertack.png`,label:"Cool Plate SuperTack"},"bambu cool plate supertack":{icon:`${Vd}/bed_cool_supertack.png`,label:"Cool Plate SuperTack"},"engineering plate":{icon:`${Vd}/bed_engineering.png`,label:"Engineering Plate"},"high temp plate":{icon:`${Vd}/bed_high_templ.png`,label:"High Temp Plate"},"textured pei plate":{icon:`${Vd}/bed_pei.png`,label:"Textured PEI Plate"},"pei plate":{icon:`${Vd}/bed_pei.png`,label:"PEI Plate"},"smooth pei plate":{icon:`${Vd}/bed_pei_cool.png`,label:"Smooth PEI Plate"}};function wk(t){return t?R9e[t.trim().toLowerCase()]??null:null}function z9e({printerId:t,filamentReqs:e,manualMappings:a,onManualMappingChange:n,currencySymbol:i,defaultCostPerKg:s,defaultExpanded:o=!1}){const{t:l}=wt(),c=na(),[d,u]=y.useState(!1),[m,p]=y.useState(o),{data:f}=$e({queryKey:["printer-status",t],queryFn:()=>ne.getPrinterStatus(t),enabled:!!t}),{data:g}=$e({queryKey:["spool-assignments",t],queryFn:()=>ne.getAssignments(t),enabled:!!t}),{loadedFilaments:v,filamentComparison:b,hasTypeMismatch:x,hasColorMismatch:S}=Fse(e,f,a),k=y.useMemo(()=>{const R=new Map;for(const K of g||[]){const J=K.ams_id===255,X=ib(K.ams_id,K.tray_id,J);R.set(X,K.spool?.cost_per_kg??null)}return R},[g]),C=y.useMemo(()=>{const R=new Map;for(const K of g||[]){const J=K.ams_id===255,X=ib(K.ams_id,K.tray_id,J),ce=K.spool;if(!ce){R.set(X,null);continue}R.set(X,Math.max(0,Math.round((ce.label_weight??0)-(ce.weight_used??0))))}return R},[g]),N=y.useMemo(()=>{let R=0;for(const K of b){const J=K.loaded?.globalTrayId;if(J==null)continue;const ce=k.get(J)??null??s;ce>0&&(R+=K.used_grams/1e3*ce)}return R},[b,k,s]),T=y.useMemo(()=>Array.from(k.values()).some(R=>R!=null&&R>0),[k]),j=e?.filaments&&e.filaments.length>0,D=e?.filaments?.some(R=>R.nozzle_id!=null)??!1,P=f?.fila_switch?.installed===!0,E=R=>{const K=f?.fila_switch;if(!K?.installed)return null;const J=K.in_slots.indexOf(R);return J<0?null:K.out_extruders[J]??null};if(!j||!f)return null;const z=x?"#f97316":S?"#facc15":"#00ae42",I=(R,K)=>{if(R>0)if(K===""){const J={...a};delete J[R],n(J)}else n({...a,[R]:parseInt(K,10)})},B=async()=>{u(!0);try{await ne.refreshPrinterStatus(t),await new Promise(R=>setTimeout(R,500)),await c.refetchQueries({queryKey:["printer-status",t]})}finally{u(!1)}};return r.jsxs("div",{className:"mb-4",children:[r.jsxs("button",{type:"button",onClick:()=>p(!m),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[r.jsx(Bw,{className:"w-4 h-4",fill:z,stroke:"none"}),r.jsx("span",{children:l("printModal.filamentMapping")}),x?r.jsx("span",{className:"text-xs text-orange-400",children:"(Type not found)"}):S?r.jsx("span",{className:"text-xs text-yellow-400",children:"(Color mismatch)"}):r.jsx("span",{className:"text-xs text-bambu-green",children:"(Ready)"}),m?r.jsx(el,{className:"w-4 h-4 ml-auto"}):r.jsx(za,{className:"w-4 h-4 ml-auto"})]}),m&&r.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("span",{className:"text-xs text-bambu-gray",children:"Click to change slot assignment"}),r.jsxs("button",{type:"button",onClick:B,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:[r.jsx(tr,{className:`w-3 h-3 ${d?"animate-spin":""}`}),r.jsx("span",{children:"Re-read"})]})]}),b.map((R,K)=>r.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[r.jsx("span",{title:`Required: ${R.type} - ${_c(R.color)}`,children:r.jsx(Bw,{className:"w-3 h-3",fill:R.color,stroke:R.color})}),r.jsxs("span",{className:"text-white truncate flex items-center gap-1",children:[D&&R.nozzle_id!=null&&r.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:R.nozzle_id===1?l("printModal.leftNozzleTooltip"):l("printModal.rightNozzleTooltip"),children:R.nozzle_id===1?l("printModal.leftNozzle"):l("printModal.rightNozzle")}),R.type," ",r.jsxs("span",{className:"text-bambu-gray",children:["(",R.used_grams,"g)"]})]}),r.jsx("span",{className:"text-bambu-gray",children:"→"}),r.jsxs("select",{value:R.loaded?.globalTrayId??"",onChange:J=>I(R.slot_id||0,J.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.status==="match"?"border-bambu-green/50 text-bambu-green":R.status==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${R.isManual?"ring-1 ring-blue-400/50":""}`,title:R.isManual?"Manually selected":"Auto-matched",children:[r.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),v.filter(J=>R.nozzle_id==null||P||J.extruderId===R.nozzle_id).map(J=>{const X=C.get(J.globalTrayId),ce=X!=null?l("printModal.slotRemainingShort",{grams:X,defaultValue:` - ${X}g left`}):"",de=P?E(J.globalTrayId):null,oe=de==null?"":` [${l(de===1?"printModal.leftNozzle":"printModal.rightNozzle")}]`;return r.jsxs("option",{value:J.globalTrayId,className:"bg-bambu-dark text-white",children:[J.label,": ",J.traySubBrands||J.type," (",J.colorName,")",ce,oe]},J.globalTrayId)})]}),R.status==="match"?r.jsx(_r,{className:"w-3 h-3 text-bambu-green"}):R.status==="type_only"?r.jsx("span",{title:"Same type, different color",children:r.jsx(xa,{className:"w-3 h-3 text-yellow-400"})}):r.jsx("span",{title:"Filament type not loaded",children:r.jsx(xa,{className:"w-3 h-3 text-orange-400"})})]},K)),r.jsxs("div",{className:"text-xs text-bambu-gray",children:[l("printModal.totalCost")," ",r.jsx("span",{className:"text-white",children:N>0||T?`${i}${N.toFixed(2)}`:"N/A"})]}),x&&r.jsx("p",{className:"text-xs text-orange-400 mt-2",children:"Required filament type not found in printer."})]})]})}function I9e({filamentReqs:t,availableFilaments:e,overrides:a,onChange:n,forceColorMatch:i,onForceColorMatchChange:s}){const{t:o}=wt(),l=y.useMemo(()=>{const u={};for(const m of e){const p=jT(m.type);u[p]||(u[p]=[]),u[p].push(m)}return u},[e]),c=t?.filaments;if(!c||c.length===0||e.length===0)return null;const d=(u,m)=>{if(m===""){const p={...a};delete p[u],n(p)}else{const[p,f]=m.split("|");n({...a,[u]:{type:p,color:f}})}};return r.jsxs("div",{className:"mb-4",children:[r.jsx("div",{className:"flex items-center gap-2 text-sm text-bambu-gray mb-2",children:r.jsx("span",{children:o("printModal.filamentOverride")})}),r.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:o("printModal.filamentOverrideHint")}),r.jsx("div",{className:"bg-bambu-dark rounded-lg p-3 space-y-2",children:c.map(u=>{const m=a[u.slot_id],p=!!m,f=l[jT(u.type)]||[],g=u.nozzle_id!=null?f.filter(v=>v.extruder_id==null||v.extruder_id===u.nozzle_id):f;return r.jsxs("div",{className:"space-y-1",children:[r.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 20px"},children:[r.jsx("span",{title:`${o("printModal.originalFilament")}: ${u.type} - ${_c(u.color)}`,children:r.jsx(Bw,{className:"w-3 h-3",fill:u.color,stroke:u.color})}),r.jsxs("span",{className:"text-white truncate",children:[u.type," ",r.jsxs("span",{className:"text-bambu-gray",children:["(",u.used_grams,"g)"]})]}),r.jsx("span",{className:"text-bambu-gray",children:"→"}),r.jsxs("select",{value:p?`${m.type}|${m.color}`:"",onChange:v=>d(u.slot_id,v.target.value),disabled:g.length===0,className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${p?"border-blue-400/50 text-blue-400":"border-bambu-gray/30 text-bambu-gray"}`,children:[r.jsxs("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:[o("printModal.originalFilament"),": ",u.type," (",_c(u.color),")"]}),g.map((v,b)=>r.jsxs("option",{value:`${v.type}|${v.color}`,className:"bg-bambu-dark text-white",children:[v.tray_sub_brands||v.type," (",_c(v.color),")"]},`${v.type}-${v.color}-${v.tray_sub_brands}-${b}`))]}),p?r.jsx("button",{type:"button",onClick:()=>d(u.slot_id,""),className:"text-bambu-gray hover:text-white transition-colors",title:o("printModal.resetToOriginal"),children:r.jsx(bs,{className:"w-3 h-3"})}):r.jsx("span",{className:"w-3"})]}),r.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer select-none pl-5",children:[r.jsx("input",{type:"checkbox",checked:i?.[u.slot_id]??!1,onChange:v=>s?.(u.slot_id,v.target.checked),className:"accent-bambu-green w-3 h-3"}),r.jsx(BS,{className:"w-3 h-3"}),o("printModal.forceColorMatch")]})]},u.slot_id)})})]})}function O9e({plates:t,isMultiPlate:e,selectedPlates:a,onToggle:n,onSelectAll:i,onDeselectAll:s,multiSelect:o}){const{t:l}=wt();if(!e||t.length<=1)return null;const c=a.size===t.length;return r.jsxs("div",{className:"mb-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx(tn,{className:"w-4 h-4 text-bambu-gray"}),r.jsxs("span",{className:"text-sm text-bambu-gray",children:["Select Plate",o?"s":""," to Print"]}),a.size===0&&r.jsxs("span",{className:"text-xs text-orange-400 flex items-center gap-1",children:[r.jsx(xa,{className:"w-3 h-3"}),"Selection required"]}),o&&i&&s&&r.jsx("button",{type:"button",onClick:c?s: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?l("queue.deselectAll"):l("queue.selectAllPlates",{count:t.length})})]}),r.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map(d=>{const u=a.has(d.index);return r.jsxs("button",{type:"button",onClick:()=>n(d.index),className:`flex items-center gap-2 p-2 rounded-lg border transition-colors text-left ${u?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"}`,children:[o&&(u?r.jsx(xs,{className:"w-4 h-4 text-bambu-green flex-shrink-0"}):r.jsx(so,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"})),d.has_thumbnail&&d.thumbnail_url!=null?r.jsx("img",{src:zn(d.thumbnail_url),alt:`Plate ${d.index}`,className:"w-10 h-10 rounded object-cover bg-bambu-dark-tertiary"}):r.jsx("div",{className:"w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center",children:r.jsx(tn,{className:"w-5 h-5 text-bambu-gray"})}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"text-sm text-white font-medium truncate",children:d.name||`Plate ${d.index}`}),r.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[d.objects.length>0?d.objects.slice(0,3).join(", ")+(d.objects.length>3?"...":""):`${d.filaments.length} filament${d.filaments.length!==1?"s":""}`,d.print_time_seconds!=null?` • ${ds(d.print_time_seconds)}`:""]}),(()=>{const m=wk(d.bed_type);return m?r.jsxs("p",{className:"text-xs text-bambu-gray flex items-center gap-1 mt-0.5 truncate",title:m.label,children:[r.jsx("img",{src:m.icon,alt:"",className:"w-3.5 h-3.5 object-contain flex-shrink-0"}),r.jsx("span",{className:"truncate",children:m.label})]}):null})()]}),!o&&u&&r.jsx(_r,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]},d.index)})})]})}const B9e=new Set(["IDLE","FINISH","FAILED"]);function U9e({printerResult:t,filamentReqs:e,onUpdateConfig:a}){const n=na(),[i,s]=y.useState(!1),o=(d,u)=>{if(d<=0)return;const m={...t.config.manualMappings};u===""?delete m[d]:m[d]=parseInt(u,10),a({useDefault:!1,manualMappings:m,autoConfigured:!1})},l=async()=>{s(!0);try{await ne.refreshPrinterStatus(t.printerId),await new Promise(d=>setTimeout(d,500)),await n.refetchQueries({queryKey:["printer-status",t.printerId]})}finally{s(!1)}},c=e.map(d=>{const u=d.slot_id||0,m=t.config.manualMappings[u];let p,f=!1;if(m!==void 0)p=t.loadedFilaments.find(v=>v.globalTrayId===m),f=!0;else{const v=new Set(Object.values(t.config.manualMappings)),b=n.getQueryData(["settings"]);p=j9e(d,t.loadedFilaments,v,b?.prefer_lowest_filament)}let g="mismatch";if(p){const v=p.type?.toUpperCase()===d.type?.toUpperCase(),b=On(p.color)===On(d.color)||fd(p.color,d.color);v&&b?g="match":v&&(g="type_only")}return{req:d,loaded:p,status:g,isManual:f}});return r.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom slot mapping"}),r.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",disabled:i,children:[r.jsx(tr,{className:`w-3 h-3 ${i?"animate-spin":""}`}),r.jsx("span",{children:"Re-read"})]})]}),c.map(({req:d,loaded:u,status:m,isManual:p},f)=>r.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[r.jsx("span",{title:`Required: ${d.type} - ${_c(d.color)}`,children:r.jsx(Bw,{className:"w-3 h-3",fill:d.color,stroke:d.color})}),r.jsxs("span",{className:"text-white truncate",children:[d.type," ",r.jsxs("span",{className:"text-bambu-gray",children:["(",d.used_grams,"g)"]})]}),r.jsx("span",{className:"text-bambu-gray",children:"→"}),r.jsxs("select",{value:u?.globalTrayId??"",onChange:g=>o(d.slot_id||0,g.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${m==="match"?"border-bambu-green/50 text-bambu-green":m==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${p?"ring-1 ring-blue-400/50":""}`,title:p?"Manually selected":"Auto-matched",children:[r.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),Dse(t.loadedFilaments,d.nozzle_id).map(g=>r.jsxs("option",{value:g.globalTrayId,className:"bg-bambu-dark text-white",children:[g.label,": ",g.traySubBrands||g.type," (",g.colorName,")"]},g.globalTrayId))]}),m==="match"?r.jsx(_r,{className:"w-3 h-3 text-bambu-green"}):m==="type_only"?r.jsx("span",{title:"Same type, different color",children:r.jsx(xa,{className:"w-3 h-3 text-yellow-400"})}):r.jsx("span",{title:"Filament type not loaded",children:r.jsx(xa,{className:"w-3 h-3 text-orange-400"})})]},f))]})}function H9e({printers:t,selectedPrinterIds:e,onMultiSelect:a,isLoading:n=!1,allowMultiple:i=!1,showInactive:s=!1,disableBusy:o=!1,printerMappingResults:l,filamentReqs:c,onAutoConfigurePrinter:d,onUpdatePrinterConfig:u,assignmentMode:m="printer",onAssignmentModeChange:p,targetModel:f,onTargetModelChange:g,targetLocation:v,onTargetLocationChange:b,slicedForModel:x}){const[S,k]=y.useState(!1),C=s?t:t.filter(ie=>ie.is_active),N=df({queries:C.map(ie=>({queryKey:["printerStatus",ie.id],queryFn:()=>ne.getPrinterStatus(ie.id),staleTime:5e3}))}),T=y.useMemo(()=>{const ie=new Map;return C.forEach((me,he)=>{const xe=N[he];xe?.data&&ie.set(me.id,xe.data)}),ie},[C,N]),j=ie=>{const me=T.get(ie);return me?me.connected?!B9e.has(me.state??""):!0:!1},D=ie=>{const me=T.get(ie);if(!me)return null;if(!me.connected)return"Offline";const he=me.state;return he?he==="RUNNING"?me.stg_cur_name||"Printing":he==="PREPARE"?"Preparing":he==="PAUSE"?"Paused":he==="IDLE"?"Idle":he==="FINISH"?"Finished":he==="FAILED"?"Failed":he:null},P=y.useMemo(()=>{if(m!=="printer"||!x||S)return C;const ie=C.filter(me=>me.model===x);return ie.length>0?ie:C},[C,m,x,S]),E=C.length-P.length,z=y.useMemo(()=>{const ie=C.map(me=>me.model).filter(me=>!!me);return[...new Set(ie)].sort()},[C]),I=y.useMemo(()=>{if(!f)return[];const ie=C.filter(me=>me.model===f&&me.location).map(me=>me.location).filter(me=>!!me);return[...new Set(ie)].sort()},[C,f]),B=p&&g&&z.length>0,R=i&&e.length>1&&l&&c?.filaments&&c.filaments.length>0&&d&&u;if(n)return r.jsx("div",{className:"flex justify-center py-8",children:r.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(P.length===0)return r.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm mb-4",children:[r.jsx(Sn,{className:"w-4 h-4"}),"No ",s?"":"active ","printers available"]});const K=ie=>{o&&j(ie)||(i?e.includes(ie)?a(e.filter(me=>me!==ie)):a([...e,ie]):a([ie]))},J=()=>{const ie=o?P.filter(me=>!j(me.id)):P;a(ie.map(me=>me.id))},X=()=>{a([])},ce=(ie,me,he)=>{he.stopPropagation(),!(!d||!u)&&(me?d(ie):u(ie,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},de=ie=>e.includes(ie),oe=e.length,Y=ie=>l?.find(me=>me.printerId===ie);return r.jsxs("div",{className:"space-y-2 mb-6",children:[B&&r.jsxs("div",{className:"flex gap-2 mb-4",children:[r.jsxs("button",{type:"button",onClick:()=>{p("printer"),g(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${m==="printer"?"border-bambu-green bg-bambu-green/10 text-white":"border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray"}`,children:[r.jsx(xr,{className:"w-4 h-4"}),r.jsx("span",{className:"text-sm",children:"Specific Printer"})]}),r.jsxs("button",{type:"button",onClick:()=>{p("model"),a([]);const ie=x&&z.includes(x)?x:z[0];g(ie)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${m==="model"?"border-bambu-green bg-bambu-green/10 text-white":"border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray"}`,children:[r.jsx(km,{className:"w-4 h-4"}),r.jsxs("span",{className:"text-sm",children:["Any ",x||"Model"]})]})]}),m==="model"&&B&&r.jsxs("div",{className:"space-y-3 mb-4",children:[!x&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Target Model"}),r.jsxs("select",{value:f||"",onChange:ie=>{g(ie.target.value||null),b&&b(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:[r.jsx("option",{value:"",children:"Select a model..."}),z.map(ie=>r.jsx("option",{value:ie,children:ie},ie))]})]}),f&&I.length>0&&b&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Location Filter (optional)"}),r.jsxs("select",{value:v||"",onChange:ie=>b(ie.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:[r.jsx("option",{value:"",children:"Any location"}),I.map(ie=>r.jsx("option",{value:ie,children:ie},ie))]})]}),f&&r.jsxs("p",{className:"text-xs text-bambu-gray",children:["Scheduler will assign to first available idle ",f," printer",v?` in ${v}`:""]})]}),m==="printer"&&i&&P.length>1&&r.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray mb-2",children:[r.jsx("span",{children:oe===0?"Select printers":`${oe} printer${oe!==1?"s":""} selected`}),r.jsxs("div",{className:"flex gap-2",children:[oe0&&r.jsx("button",{type:"button",onClick:X,className:"text-bambu-gray hover:text-white transition-colors",children:"Clear"})]})]}),m==="printer"&&P.map(ie=>{const me=de(ie.id),he=Y(ie.id),xe=he&&!he.config.useDefault,V=j(ie.id),Q=o&&V,A=D(ie.id);return r.jsxs("div",{children:[r.jsxs("button",{type:"button",onClick:()=>K(ie.id),disabled:Q,className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${Q?"border-bambu-dark-tertiary bg-bambu-dark opacity-50 cursor-not-allowed":me?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"} ${ie.is_active?"":"opacity-60"}`,children:[r.jsx("div",{className:`p-2 rounded-lg ${Q?"bg-bambu-dark-tertiary":me?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:r.jsx(xr,{className:`w-5 h-5 ${Q?"text-bambu-gray/50":me?"text-bambu-green":"text-bambu-gray"}`})}),r.jsxs("div",{className:"text-left flex-1",children:[r.jsxs("p",{className:`font-medium ${Q?"text-bambu-gray":"text-white"}`,children:[ie.name,!ie.is_active&&r.jsx("span",{className:"text-bambu-gray text-xs ml-2",children:"(inactive)"})]}),r.jsxs("p",{className:"text-xs text-bambu-gray",children:[ie.model||"Unknown model"," • ",ie.ip_address]})]}),A&&r.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${V?"bg-yellow-500/20 text-yellow-400":"bg-bambu-green/20 text-bambu-green"}`,children:A}),i&&r.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${Q?"border-bambu-gray/30":me?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:me&&r.jsx(_r,{className:"w-3 h-3 text-white"})})]}),me&&R&&he&&r.jsxs("div",{className:"ml-4 mt-2 mb-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",onClick:F=>F.stopPropagation(),children:[r.jsx("input",{type:"checkbox",checked:xe,onChange:F=>ce(ie.id,F.target.checked,F),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"}),r.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom mapping"})]}),r.jsxs("span",{className:`text-xs ml-2 ${he.matchStatus==="full"?"text-bambu-green":he.matchStatus==="partial"?"text-yellow-400":"text-orange-400"}`,children:["(",he.exactMatches,"/",he.totalSlots," matched)"]}),he.isLoading&&r.jsx(tr,{className:"w-3 h-3 text-bambu-gray animate-spin"}),xe&&r.jsxs("button",{type:"button",onClick:F=>{F.stopPropagation(),d(ie.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:[r.jsx(HI,{className:"w-3 h-3"}),"Auto"]})]}),xe&&r.jsx(U9e,{printerResult:he,filamentReqs:c.filaments,onUpdateConfig:F=>u(ie.id,F)})]})]},ie.id)}),m==="printer"&&E>0&&!S&&r.jsxs("button",{type:"button",onClick:()=>k(!0),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2 flex items-center gap-1",children:[r.jsx(xa,{className:"w-3 h-3 text-yellow-400"}),E," other printer",E>1?"s":""," hidden (different model) —",r.jsx("span",{className:"underline",children:"show all"})]}),m==="printer"&&S&&x&&r.jsx("button",{type:"button",onClick:()=>k(!1),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2",children:r.jsxs("span",{className:"underline",children:["Show only ",x," printers"]})}),m==="printer"&&oe===0&&r.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[r.jsx(Sn,{className:"w-3 h-3"}),"Select at least one printer"]}),m==="model"&&!f&&r.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[r.jsx(Sn,{className:"w-3 h-3"}),"Select a target printer model"]})]})}function q9e({options:t,onChange:e,defaultExpanded:a=!1,showDualNozzleOptions:n=!1}){const{t:i}=wt(),[s,o]=y.useState(a),c=[{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(u=>!u.dualNozzleOnly||n),d=u=>{e({...t,[u]:!t[u]})};return r.jsxs("div",{className:"mb-4",children:[r.jsxs("button",{type:"button",onClick:()=>o(!s),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[r.jsx(Sy,{className:"w-4 h-4"}),r.jsx("span",{children:i("queue.bulkEdit.printOptions")}),s?r.jsx(el,{className:"w-4 h-4 ml-auto"}):r.jsx(za,{className:"w-4 h-4 ml-auto"})]}),s&&r.jsx("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:c.map(({key:u,label:m,desc:p})=>r.jsxs("label",{className:"flex items-center justify-between cursor-pointer group",children:[r.jsxs("div",{children:[r.jsx("span",{className:"text-sm text-white",children:m}),r.jsx("p",{className:"text-xs text-bambu-gray",children:p})]}),r.jsx("div",{className:`relative w-10 h-5 rounded-full transition-colors ${t[u]?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,onClick:()=>d(u),children:r.jsx("div",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white transition-transform ${t[u]?"translate-x-5":"translate-x-0.5"}`})})]},u))})]})}function V9e({options:t,onChange:e,dateFormat:a="system",timeFormat:n="system",canControlPrinter:i=!0,showStagger:s=!1,printerCount:o=0,hasGcodeSnippets:l=!1}){const{t:c}=wt(),[d,u]=y.useState(""),[m,p]=y.useState(""),[f,g]=y.useState(!0),[v,b]=y.useState(!0),x=y.useRef(null),S=y.useRef(!1);y.useEffect(()=>{if(t.scheduleType!=="scheduled"){S.current=!1;return}if(!S.current){S.current=!0;let P;t.scheduledTime?(P=new Date(t.scheduledTime),isNaN(P.getTime())&&(P=new Date,P.setHours(P.getHours()+1,0,0,0))):(P=new Date,P.setHours(P.getHours()+1,0,0,0),e({...t,scheduledTime:g3(P)})),u(f3(P,a)),p(U8(P,n)),g(!0),b(!0)}},[t.scheduleType,t.scheduledTime,a,n,e,t]);const k=P=>{e({...t,scheduleType:P})},C=(P,E)=>{const z=F0e(P,a),I=L0e(E);g(!!z),b(!!I),z&&I&&(z.setHours(I.hours,I.minutes,0,0),z>new Date&&e({...t,scheduledTime:g3(z)}))},N=P=>{u(P),C(P,m)},T=P=>{p(P),C(d,P)},j=P=>{const E=P.target.value;if(E){const z=new Date(E);isNaN(z.getTime())||(u(f3(z,a)),p(U8(z,n)),g(!0),b(!0),e({...t,scheduledTime:E}))}},D=()=>{x.current?.showPicker()};return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"When to print"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="asap"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>k("asap"),children:[r.jsx(ar,{className:"w-4 h-4"}),"ASAP"]}),r.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="scheduled"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>k("scheduled"),children:[r.jsx(Pn,{className:"w-4 h-4"}),"Scheduled"]}),r.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="manual"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>k("manual"),children:[r.jsx(lJ,{className:"w-4 h-4"}),"Queue Only"]})]})]}),t.scheduleType==="scheduled"&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date & Time"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("div",{className:"flex-1 relative",children:[r.jsx("input",{type:"text",className:`w-full px-3 py-2 pr-10 bg-bambu-dark border rounded-lg text-white focus:outline-none ${f?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:d,onChange:P=>N(P.target.value),placeholder:M0e(a)}),r.jsx("button",{type:"button",onClick:D,className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",title:"Open calendar",children:r.jsx(Pn,{className:"w-4 h-4"})}),r.jsx("input",{ref:x,type:"datetime-local",className:"absolute top-0 left-0 w-0 h-0 opacity-0 pointer-events-none",value:t.scheduledTime,onChange:j,tabIndex:-1})]}),r.jsx("div",{className:"w-32",children:r.jsx("input",{type:"text",className:`w-full px-3 py-2 bg-bambu-dark border rounded-lg text-white focus:outline-none ${v?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:m,onChange:P=>T(P.target.value),placeholder:E0e(n)})})]}),(!f||!v)&&r.jsx("p",{className:"mt-1 text-xs text-red-400",children:"Please enter a valid date and time"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"requirePrevious",checked:t.requirePreviousSuccess,onChange:P=>e({...t,requirePreviousSuccess:P.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsx("label",{htmlFor:"requirePrevious",className:"text-sm text-bambu-gray",children:"Only start if previous print succeeded"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"autoOffAfter",checked:t.autoOffAfter,onChange:P=>e({...t,autoOffAfter:P.target.checked}),disabled:!i,className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green disabled:opacity-50"}),r.jsxs("label",{htmlFor:"autoOffAfter",className:`text-sm flex items-center gap-1 ${i?"text-bambu-gray":"text-bambu-gray/50"}`,children:[r.jsx(Tu,{className:"w-3.5 h-3.5"}),"Power off printer when done"]})]}),l&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"gcodeInjection",checked:t.gcodeInjection,onChange:P=>e({...t,gcodeInjection:P.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsxs("label",{htmlFor:"gcodeInjection",className:"text-sm flex items-center gap-1 text-bambu-gray",children:[r.jsx(tv,{className:"w-3.5 h-3.5"}),c("printModal.gcodeInjection","Inject auto-print G-code")]})]}),s&&t.scheduleType!=="manual"&&r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"staggerEnabled",checked:t.staggerEnabled,onChange:P=>e({...t,staggerEnabled:P.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsxs("label",{htmlFor:"staggerEnabled",className:"text-sm flex items-center gap-1 text-bambu-gray",children:[r.jsx(tn,{className:"w-3.5 h-3.5"}),c("printModal.staggerPrinterStarts","Stagger printer starts")]})]}),t.staggerEnabled&&r.jsxs("div",{className:"ml-6 space-y-3",children:[r.jsxs("div",{className:"flex gap-3",children:[r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:c("printModal.staggerGroupSize","Group size")}),r.jsx("input",{type:"number",min:1,max:o,value:t.staggerGroupSize,onChange:P=>e({...t,staggerGroupSize:Math.max(1,parseInt(P.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"})]}),r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:c("printModal.staggerInterval","Interval (min)")}),r.jsx("input",{type:"number",min:1,max:60,value:t.staggerIntervalMinutes,onChange:P=>e({...t,staggerIntervalMinutes:Math.max(1,parseInt(P.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&&(()=>{const P=Math.ceil(o/t.staggerGroupSize),E=o%t.staggerGroupSize,z=(P-1)*t.staggerIntervalMinutes;return r.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:P,size:t.staggerGroupSize,interval:t.staggerIntervalMinutes}),E!==0&&t.staggerGroupSize1?` (${c("printModal.staggerTotal","total: {{minutes}} min",{minutes:z})})`:""]})})()]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:t.scheduleType==="asap"?"Print will start as soon as the printer is idle.":t.scheduleType==="scheduled"?"Print will start at the scheduled time if the printer is idle. If busy, it will wait until the printer becomes available.":"Print will be staged but won't start automatically. Use the Start button to release it to the queue."})]})}const Sl={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1,nozzle_offset_cali:!0},TF={scheduleType:"asap",scheduledTime:"",requirePreviousSuccess:!1,autoOffAfter:!1,gcodeInjection:!1,staggerEnabled:!1,staggerGroupSize:2,staggerIntervalMinutes:5};function Cc({mode:t,archiveId:e,libraryFileId:a,archiveName:n,queueItem:i,initialSelectedPrinterIds:s,onClose:o,onSuccess:l,projectId:c,cleanupLibraryAfterDispatch:d}){const{t:u}=wt(),m=na(),{showToast:p}=oa(),{hasPermission:f}=lr(),g=!!a&&!e,[v,b]=y.useState(()=>t==="edit-queue-item"&&i?.printer_id?[i.printer_id]:s?.length?s:[]),[x,S]=y.useState(()=>t==="edit-queue-item"&&i?.plate_id!=null?new Set([i.plate_id]):new Set),k=x.size===1?[...x][0]:null,[C,N]=y.useState(1),[T,j]=y.useState(()=>t==="edit-queue-item"&&i?{bed_levelling:i.bed_levelling??Sl.bed_levelling,flow_cali:i.flow_cali??Sl.flow_cali,vibration_cali:i.vibration_cali??Sl.vibration_cali,layer_inspect:i.layer_inspect??Sl.layer_inspect,timelapse:i.timelapse??Sl.timelapse,nozzle_offset_cali:i.nozzle_offset_cali??Sl.nozzle_offset_cali}:Sl),[D,P]=y.useState(()=>{if(t==="edit-queue-item"&&i){let Pe="asap";i.manual_start?Pe="manual":i.scheduled_time&&!mY(i.scheduled_time)&&(Pe="scheduled");let Ye="";if(i.scheduled_time&&!mY(i.scheduled_time)){const it=Ga(i.scheduled_time)??new Date;Ye=g3(it)}return{scheduleType:Pe,scheduledTime:Ye,requirePreviousSuccess:i.require_previous_success,autoOffAfter:i.auto_off_after,gcodeInjection:i.gcode_injection??!1,staggerEnabled:!1,staggerGroupSize:TF.staggerGroupSize,staggerIntervalMinutes:TF.staggerIntervalMinutes}}return TF}),[E,z]=y.useState(()=>{if(t==="edit-queue-item"&&i?.ams_mapping&&Array.isArray(i.ams_mapping)){const Pe={};return i.ams_mapping.forEach((Ye,it)=>{Ye!==-1&&(Pe[it+1]=Ye)}),Pe}return{}}),[I,B]=y.useState({}),[R,K]=y.useState(()=>t==="edit-queue-item"&&i?.target_model?"model":"printer"),[J,X]=y.useState(()=>t==="edit-queue-item"&&i?.target_model?i.target_model:null),[ce,de]=y.useState(()=>t==="edit-queue-item"&&i?.target_location?i.target_location:null),[oe,Y]=y.useState(()=>{if(t==="edit-queue-item"&&i?.filament_overrides){const Pe={};for(const Ye of i.filament_overrides)Pe[Ye.slot_id]={type:Ye.type,color:Ye.color};return Pe}return{}}),[ie,me]=y.useState(()=>{if(t==="edit-queue-item"&&i?.filament_overrides){const Pe={};for(const Ye of i.filament_overrides)Pe[Ye.slot_id]=Ye.force_color_match===!0;return Pe}return{}}),[he]=y.useState(()=>t==="edit-queue-item"&&i?.printer_id?[i.printer_id]:[]),[xe]=y.useState(()=>t==="edit-queue-item"&&i?i.plate_id:null),[V,Q]=y.useState(!1),[A,F]=y.useState({current:0,total:0}),[U,$]=y.useState(null),[H,le]=y.useState(new Set),O=v.length,q=v.length>0?v[0]:null,{data:Z}=$e({queryKey:["settings"],queryFn:ne.getSettings}),ee=y.useRef(!1);y.useEffect(()=>{!Z||ee.current||t==="edit-queue-item"||(ee.current=!0,j({bed_levelling:Z.default_bed_levelling??Sl.bed_levelling,flow_cali:Z.default_flow_cali??Sl.flow_cali,vibration_cali:Z.default_vibration_cali??Sl.vibration_cali,layer_inspect:Z.default_layer_inspect??Sl.layer_inspect,timelapse:Z.default_timelapse??Sl.timelapse,nozzle_offset_cali:Z.default_nozzle_offset_cali??Sl.nozzle_offset_cali}))},[Z,t]);const re=y.useRef(!1);y.useEffect(()=>{!Z||re.current||t==="edit-queue-item"||(re.current=!0,P(Pe=>({...Pe,staggerGroupSize:Z.stagger_group_size??Pe.staggerGroupSize,staggerIntervalMinutes:Z.stagger_interval_minutes??Pe.staggerIntervalMinutes})))},[Z,t]);const se=Vo(Z?.currency||"USD"),fe=Z?.default_filament_cost??0,{data:ue,isLoading:pe}=$e({queryKey:["printers"],queryFn:ne.getPrinters}),{data:G}=$e({queryKey:["spool-assignments"],queryFn:()=>ne.getAssignments(),staleTime:30*1e3,enabled:(t==="reprint"||t==="add-to-queue")&&R==="printer"||g&&t==="reprint"}),{data:L}=$e({queryKey:["archive",e],queryFn:()=>ne.getArchive(e),enabled:!!e&&!g}),{data:ae}=$e({queryKey:["library-file",a],queryFn:()=>ne.getLibraryFile(a),enabled:g&&!!a}),ge=L?.sliced_for_model||ae?.sliced_for_model||null,{data:be,isError:ve}=$e({queryKey:["archive-plates",e],queryFn:()=>ne.getArchivePlates(e),enabled:!!e&&!g,retry:!1}),{data:De}=$e({queryKey:["library-file-plates",a],queryFn:()=>ne.getLibraryFilePlates(a),enabled:g&&!!a}),je=g?De:be,{data:Te,isError:qe}=$e({queryKey:["archive-filaments",e,k],queryFn:()=>ne.getArchiveFilamentRequirements(e,k??void 0),enabled:!!e&&!g&&(k!==null||!je?.is_multi_plate),retry:!1}),{data:Ce}=$e({queryKey:["library-file-filaments",a,k],queryFn:()=>ne.getLibraryFileFilamentRequirements(a,k??void 0),enabled:g&&!!a&&(k!==null||!je?.is_multi_plate)}),Ie=!g&&(ve||qe),Re=g?Ce:Te,Ue=y.useMemo(()=>{if(!(k===null||!je?.plates?.length))return je.plates.find(Pe=>Pe.index===k)?.name||void 0},[je,k]),{data:ze}=$e({queryKey:["available-filaments",J,ce],queryFn:()=>ne.getAvailableFilaments(J,ce??void 0),enabled:R==="model"&&!!J}),{data:nt}=$e({queryKey:["printer-status",q],queryFn:()=>ne.getPrinterStatus(q),enabled:!!q}),{amsMapping:Oe}=Fse(Re,nt,E,Z?.prefer_lowest_filament),tt=F9e(v,ue,Re,E,I,B,Z?.prefer_lowest_filament);y.useEffect(()=>{je?.plates&&je.plates.length>=1&&x.size===0&&S(new Set([je.plates[0].index]))},[je,x.size]),y.useEffect(()=>{if(t==="edit-queue-item")return;const Pe=ue?.filter(Ye=>Ye.is_active)||[];Pe.length===1&&v.length===0&&b([Pe[0].id])},[t,ue,v.length]),y.useEffect(()=>{t==="edit-queue-item"?(JSON.stringify(v.sort())!==JSON.stringify(he.sort())||k!==xe)&&(z({}),B({}),le(new Set)):(z({}),B({}),le(new Set))},[t,v,k,he,xe]);const[Fe,Ke]=y.useState(J),[Ve,Me]=y.useState(k);y.useEffect(()=>{(J!==Fe||k!==Ve)&&(Ke(J),Me(k),(t!=="edit-queue-item"||Fe!==null)&&(Y({}),me({})))},[J,k,Fe,Ve,t]),y.useEffect(()=>{if(!Z?.per_printer_mapping_expanded||v.length<=1)return;const Pe=v.filter(Ye=>{if(H.has(Ye))return!1;const it=tt.printerResults.find(Ae=>Ae.printerId===Ye);return it&&it.status&&!it.isLoading});Pe.length>0&&(le(Ye=>{const it=new Set(Ye);return Pe.forEach(Ae=>it.add(Ae)),it}),Pe.forEach(Ye=>{tt.autoConfigurePrinter(Ye)}))},[Z?.per_printer_mapping_expanded,v,H,tt]),y.useEffect(()=>{const Pe=Ye=>{Ye.key==="Escape"&&!V&&o()};return window.addEventListener("keydown",Pe),()=>window.removeEventListener("keydown",Pe)},[o,V]);const Be=je?.is_multi_plate??!1,Qe=je?.plates??[],Ge=y.useMemo(()=>{const Pe=new Map;return G&&G.forEach(Ye=>{const it=Ye.ams_id===255,Ae=ib(Ye.ams_id,Ye.tray_id,it),Se=Pe.get(Ye.printer_id)??new Map;Se.set(Ae,Ye),Pe.set(Ye.printer_id,Se)}),Pe},[G]),Ee=y.useMemo(()=>{if(!U||U.length===0)return"";const Pe=U.map(Ye=>u("printModal.insufficientFilamentLine",{printer:Ye.printerName,slot:Ye.slotLabel,required:Math.round(Ye.requiredGrams),remaining:Math.round(Ye.remainingGrams)}));return[u("printModal.insufficientFilamentMessage"),...Pe].join(` +${l("inventory.assignReconfigureNote")}`,r.jsx(ka,{title:l("inventory.assignMismatchTitle"),message:A,confirmText:l("inventory.assignMismatchConfirm"),variant:"warning",overlayZIndex:"z-[110]",isLoading:X.isPending,onConfirm:Q,onCancel:()=>{X.isPending||(N(!1),k(null),j(null))}})})()]})}const h9e={process:new Map,filament:new Map,bambuModelByShortCode:{}};function yse(t){return t.replace(/^#\s*/,"").trim()}const eY={"A1 MINI":["A1M"]};function Pz(t,e){const a=t.toUpperCase(),n=e.toUpperCase();if(a===n)return!0;const i=eY[n];if(i&&i.includes(a))return!0;const s=eY[a];return!!(s&&s.includes(n))}function f9e(t){const e={};for(const[a,n]of Object.entries(t))n in e||(e[n]=a.replace(/^Bambu Lab\s+/,""));return e}function g9e(t,e={}){const a=new Map,n=new Map,i=(s,o,l)=>{const c=yse(o);if(!c)return;const d=s.get(c)??new Set;d.add(l),s.set(c,d)};for(const s of t){const o=s.printer_preset_name?.trim();if(o){for(const l of s.process)i(a,l,o);for(const l of s.filament)i(n,l,o)}}return{process:a,filament:n,bambuModelByShortCode:f9e(e)}}function tY(t){return t.replace(/\s+/g,"").toLowerCase()}const b9e="0.4";function vse(t){const e=t.match(/^(.*?)\s+([\d.]+)\s*nozzle\s*$/i);return e?{stripped:e[1].trim(),nozzle:e[2]}:{stripped:t.trim(),nozzle:null}}function x9e(t){const e="@BBL ",a=t.indexOf(e);if(a<0)return null;const n=t.slice(a+e.length).trim(),{stripped:i,nozzle:s}=vse(n);return i?{token:i,nozzle:s}:null}function y9e(t){const e=t.match(/^Bambu Lab\s+(.+)$/i);if(!e)return null;const{stripped:a,nozzle:n}=vse(e[1]);return a?{model:a,nozzle:n}:null}function v9e(t,e,a){const n=x9e(t);if(!n)return"unknown";const i=a[n.token]??n.token,s=y9e(e);return s?tY(s.model)!==tY(i)&&!Pz(n.token,s.model)||s.nozzle!==null&&(n.nozzle??b9e)!==s.nozzle?"mismatch":"match":"unknown"}function Uy(t,e,a,n){if(!a)return"unknown";const i=t.compatible_printers;if(i&&i.length>0)return i.includes(a)?"match":"mismatch";const s=n[e].get(yse(t.name));return s&&s.size>0?s.has(a)?"match":"mismatch":v9e(t.name,a,n.bambuModelByShortCode)}const wse=["PLA","PETG","ABS","TPU","ASA","PC","PA","PVA","HIPS","PA-CF","PETG-CF","PLA-CF"],w9e=["Bambu","PolyLite","PolyTerra","eSUN","Overture","Fiberon","SUNLU","Inland","Hatchbox","Generic"],fw=["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"],Sse=[{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"}],S9e=[{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"}],aY=[...Sse,...S9e],kse="bambuddy-recent-colors",k9e=8,_9e=[{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 of(t){let e=t.replace(/@.*$/,"").trim();e=e.replace(/\(Custom\)/i,"").trim(),e=e.replace(/^[#*]+\s*/,"").trim();const a=["PLA-CF","PETG-CF","ABS-GF","ASA-CF","PA-CF","PAHT-CF","PA6-CF","PA6-GF","PPA-CF","PPA-GF","PET-CF","PPS-CF","PC-CF","PC-ABS","ABS-GF","PCTG","PETG","PLA","ABS","ASA","PC","PA","TPU","PVA","HIPS","BVOH","PPS","PEEK","PEI"];let n="",i=-1;for(const c of a){const d=e.toUpperCase().indexOf(c.toUpperCase());if(d!==-1){n=c,i=d;break}}let s="";i>0&&(s=e.substring(0,i).trim(),s=s.replace(/[-_\s]+$/,""));let o="";i!==-1&&n&&(o=e.substring(i+n.length).trim(),o=o.replace(/^[-_\s]+/,""));let l="";for(const c of fw)if(o.toLowerCase().includes(c.toLowerCase())){l=c;break}if(!l&&s)for(const c of fw){const d=new RegExp(`\\s+${c}$`,"i");if(d.test(s)){l=c,s=s.replace(d,"").trim();break}}return{brand:s,material:n,variant:l}}function _se(t,e){const a=new Set(w9e);for(const n of t){const{brand:i}=of(n.name);i&&i.length>1&&a.add(i)}if(e)for(const n of e)if(n.filament_vendor&&n.filament_vendor.length>1)a.add(n.filament_vendor);else{const{brand:i}=of(n.name);i&&i.length>1&&a.add(i)}return Array.from(a).sort((n,i)=>n.localeCompare(i))}function P9e(t){const e=t.filter(n=>n.preset_type==="filament");return e.length===0?[]:e.map(n=>{const i=String(n.id),s=n.filament_type||i,o=Array.from(new Set([i,s]));return{code:i,name:n.name,displayName:n.name,isCustom:!1,allCodes:o}}).sort((n,i)=>n.displayName.localeCompare(i.displayName))}function Pse(t,e,a,n){const i=[],s=[],o=new Set;for(const u of t)if(u.is_custom){const m=u.name.toUpperCase();(e.size===0||Array.from(e).some(f=>m.includes(f))||!m.includes("@"))&&(i.push({code:u.setting_id,name:u.name,displayName:`${u.name} (Custom)`,isCustom:!0,allCodes:[u.setting_id]}),o.add(u.setting_id))}else s.push({code:u.setting_id,name:u.name,displayName:u.name,isCustom:!1,allCodes:[u.setting_id]}),o.add(u.setting_id);const l=a&&a.length>0?P9e(a):[],c=[];if(n&&n.length>0)for(const u of n){const m=u.filament_id.startsWith("GF")?"GFS"+u.filament_id.slice(2):u.filament_id;o.has(u.filament_id)||o.has(m)||c.push({code:u.filament_id,name:u.name,displayName:u.name,isCustom:!1,allCodes:[u.filament_id,m]})}const d=[...i,...s,...l,...c];return d.length===0?_9e:d.sort((u,m)=>u.displayName.localeCompare(m.displayName))}function Cse(t,e){if(!t)return;let a=e.find(n=>n.code===t);if(a||(a=e.find(n=>n.allCodes.includes(t))),!a){const n=t.toLowerCase();a=e.find(i=>i.code.toLowerCase()===n||i.allCodes.some(s=>s.toLowerCase()===n))}return a}function Nse(){try{const t=localStorage.getItem(kse);if(t)return JSON.parse(t)}catch{}return[]}function Tse(t,e){const a=e.filter(i=>i.hex.toUpperCase()!==t.hex.toUpperCase()),n=[t,...a].slice(0,k9e);try{localStorage.setItem(kse,JSON.stringify(n))}catch{}return n}function gw(t){if(!t)return"";let e=t.split("_")[0];return/^GFS/i.test(e)&&(e=e.slice(0,2)+e.slice(3)),e.toUpperCase()}function Ase(t){return!!t&&/^GF[A-Z]99$/i.test(t)}function PF(t,e){if(!e.material)return!1;const a=gw(e.slicer_filament),n=gw(t.filament_id);if(a&&n&&a===n&&!Ase(n))return!0;const s=(t.name||"").replace(/^High Flow[_\s]+/i,"").replace(/^Standard[_\s]+/i,"").replace(/^HF[_\s]+/i,"").replace(/^S[_\s]+/i,"").trim(),o=of(s);return!(!(o.material.toUpperCase()===e.material.toUpperCase())||e.brand&&!(o.brand.toLowerCase().includes(e.brand.toLowerCase())||e.brand.toLowerCase().includes(o.brand.toLowerCase()))||e.subtype&&!(o.variant.toLowerCase().includes(e.subtype.toLowerCase())||e.subtype.toLowerCase().includes(o.variant.toLowerCase())||s.toLowerCase().includes(e.subtype.toLowerCase())))}function rY(t,e){if(t===255)return"External";let a,n=!1;t>=128&&t<=135?(a=t-128,n=!0):t>=0&&t<=3?(a=t,n=e===1):a=0,a=Math.max(0,Math.min(a,7));const i=String.fromCharCode(65+a);return n?`HT-${i}`:`AMS-${i}`}function CF(t){const e=t.includes("_")?t.split("_")[0]:t;return e.startsWith("GFS")?"GF"+e.slice(3):(e.startsWith("PFUS")||e.startsWith("PFSP"),e)}const cg=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function nY(t){const e=t.replace(/@.+$/,"").trim(),a=e.toUpperCase(),n=a.match(/\bSUPPORT\s+FOR\s+/);if(n){const s=a.slice(n.index+n[0].length);for(const o of cg)if(new RegExp(`\\b${o}\\b`).test(s)){const c=e.slice(0,n.index).trim();return{material:o,brand:c,variant:"Support"}}}for(const s of cg){const o=new RegExp(`\\b${s}\\b`,"i");if(o.test(a)){const l=e.split(o),c=l[0]?.trim()||"",d=l[1]?.trim()||"";return{material:s,brand:c,variant:d}}}const i=e.split(/\s+/);return i.length>=2?{material:i[1],brand:i[0],variant:i.slice(2).join(" ")}:{material:e,brand:"",variant:""}}function C9e(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const N9e={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"},iY=[{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"}],sY=[{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 oY(t){const e=t.toLowerCase().trim();return N9e[e]||null}function lY(t){const e=t.indexOf("@");if(e<0)return null;const n=t.slice(e+1).trim().match(/^BBL\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);return n?n[1].trim():null}function jse({isOpen:t,onClose:e,printerId:a,slotInfo:n,nozzleDiameter:i="0.4",printerModel:s,onSuccess:o,fullScreen:l}){const{t:c}=wt(),[d,u]=y.useState(""),[m,p]=y.useState(null),[f,g]=y.useState(""),[v,b]=y.useState(""),[x,S]=y.useState(""),[k,C]=y.useState(!1),[N,T]=y.useState(!1),j=y.useRef(""),{data:D,isLoading:P,isError:E}=$e({queryKey:["cloudSettings"],queryFn:()=>ne.getCloudSettings(),enabled:t,retry:!1}),{data:z}=$e({queryKey:["orcaCloudProfilesForAmsSlot"],queryFn:()=>ne.orcaCloudListProfiles(),enabled:t,retry:!1}),{data:I,isLoading:B}=$e({queryKey:["localPresets"],queryFn:()=>ne.getLocalPresets(),enabled:t}),{data:R,isLoading:K}=$e({queryKey:["builtinFilaments"],queryFn:()=>ne.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:J,isLoading:X}=$e({queryKey:["kprofiles",a,i],queryFn:()=>ne.getKProfiles(a,i),enabled:t&&!!a}),{data:ce}=$e({queryKey:["colorCatalog"],queryFn:()=>ne.getColorCatalog(),enabled:t,staleTime:1/0}),de=at({mutationFn:async()=>{if(!d)throw new Error("No filament preset selected");const U=d.startsWith("local_"),$=d.startsWith("builtin_"),H=d.startsWith("orca_")?d.replace("orca_",""):d,le=!U&&!$?z?.filament.find(ze=>ze.setting_id===H):void 0,O=!!le,q=le??null,Z=U?parseInt(d.replace("local_",""),10):null,ee=$?d.replace("builtin_",""):null,re=U?I?.filament.find(ze=>ze.id===Z):null,se=$?R?.find(ze=>ze.filament_id===ee):null,fe=!U&&!$&&!O?D?.filament.find(ze=>ze.setting_id===d):null;if(!U&&!$&&!O&&!fe)throw new Error("Selected preset not found");if(U&&!re)throw new Error("Selected local preset not found");if($&&!se)throw new Error("Selected builtin preset not found");if(O&&!q)throw new Error("Selected Orca Cloud preset not found");const ue=U?re.name:$?se.name:O?q.name:fe.name,pe=nY(ue),G=m?.slot_id??-1,L=f||n.trayColor?.slice(0,6)||"FFFFFF",ae=ue.replace(/@.+$/,"").trim();let ge,be;const ve=pe.material.toUpperCase(),De={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(U){const ze=(cg.includes(ve)?ve:re?.filament_type||pe.material||"").toUpperCase();ge=De[ze]||De[ze.replace(/[-\s]?CF$/,"")]||De[ze.replace(/\+$/,"")]||De[ze.split(/[-\s]/)[0]]||"",be=""}else if(O){const ze=(cg.includes(ve)?ve:pe.material||"").toUpperCase();ge=De[ze]||De[ze.replace(/[-\s]?CF$/,"")]||De[ze.replace(/\+$/,"")]||De[ze.split(/[-\s]/)[0]]||"",be=""}else if($)ge=ee,be="";else if(ge=CF(d),be=d,!d.startsWith("GFS"))try{const ze=await ne.getCloudSettingDetail(d);ze.filament_id&&(ge=ze.filament_id)}catch(ze){console.warn("Failed to fetch preset detail for filament_id:",ze)}let je=U&&re?.nozzle_temp_min?re.nozzle_temp_min:190,Te=U&&re?.nozzle_temp_max?re.nozzle_temp_max:230;if(!U||$||O||!re?.nozzle_temp_min&&!re?.nozzle_temp_max){const ze=(U?cg.includes(ve)?ve:re?.filament_type||pe.material||"":pe.material).toUpperCase();ze.includes("PLA")?(je=190,Te=230):ze.includes("PETG")?(je=220,Te=260):ze.includes("ABS")||ze.includes("ASA")?(je=240,Te=280):ze.includes("TPU")?(je=200,Te=240):ze==="PCTG"?(je=220,Te=260):ze.includes("PC")?(je=260,Te=300):(ze.includes("PA")||ze.includes("NYLON"))&&(je=250,Te=290)}const qe=m?.k_value?parseFloat(m.k_value):0,Ce=U?cg.includes(ve)?ve:re?.filament_type||pe.material||"PLA":O&&cg.includes(ve)?ve:pe.material||"PLA",Ie=await ne.configureAmsSlot(a,n.amsId,n.trayId,{tray_info_idx:ge,tray_type:Ce,tray_sub_brands:ae,tray_color:L+"FF",nozzle_temp_min:je,nozzle_temp_max:Te,cali_idx:G,nozzle_diameter:i,setting_id:be,kprofile_filament_id:m?.filament_id,kprofile_setting_id:m?.setting_id||void 0,k_value:qe}),Re=U?`local_${Z}`:$?`builtin_${ee}`:d,Ue=U?"local":$?"builtin":O?"orca_cloud":"cloud";try{await ne.saveSlotPreset(a,n.amsId,n.trayId,Re,ae,Ue)}catch(ze){console.warn("Failed to save slot preset mapping:",ze)}return Ie},onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),oe=at({mutationFn:async()=>ne.resetAmsSlot(a,n.amsId,n.trayId),onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),Y=y.useMemo(()=>{const U=x.toLowerCase(),$=[],H=new Set,le=n.savedPresetId,O=n.trayInfoIdx;if(z?.filament)for(const q of z.filament){const Z=`orca_${q.setting_id}`;if(H.add(q.setting_id),H.add(Z),!(U&&!q.name.toLowerCase().includes(U))){if(s){const ee=lY(q.name);if(ee&&!Pz(ee,s))continue}$.push({id:Z,name:q.name,source:"orca_cloud",isUser:!0})}}if(D?.filament)for(const q of D.filament){if(H.has(q.setting_id))continue;H.add(q.setting_id);const ee=le===q.setting_id||O&&(q.setting_id===O||CF(q.setting_id)===O);if(!(U&&!q.name.toLowerCase().includes(U))){if(!ee&&s){const re=lY(q.name);if(re&&!Pz(re,s))continue}$.push({id:q.setting_id,name:q.name,source:"cloud",isUser:C9e(q.setting_id)})}}if(I?.filament)for(const q of I.filament){const Z=`local_${q.id}`;U&&!q.name.toLowerCase().includes(U)||$.push({id:Z,name:q.name,source:"local",isUser:!1})}if(R)for(const q of R){if(H.has(q.filament_id))continue;const Z=q.filament_id.startsWith("GF")?"GFS"+q.filament_id.slice(2):q.filament_id;H.has(Z)||(!U||q.name.toLowerCase().includes(U))&&$.push({id:`builtin_${q.filament_id}`,name:q.name,source:"builtin",isUser:!1})}return $.sort((q,Z)=>{const ee={orca_cloud:0,cloud:1,local:2,builtin:3};return q.source!==Z.source?ee[q.source]-ee[Z.source]:q.isUser&&!Z.isUser?-1:!q.isUser&&Z.isUser?1:q.name.localeCompare(Z.name)})},[z?.filament,D?.filament,I?.filament,R,x,s,n.savedPresetId,n.trayInfoIdx]),ie=y.useMemo(()=>{if(!d)return null;let U=null,$="";if(d.startsWith("local_")){const O=parseInt(d.replace("local_",""),10);U=I?.filament.find(Z=>Z.id===O)?.name||null}else if(d.startsWith("builtin_")){const O=d.replace("builtin_","");U=R?.find(Z=>Z.filament_id===O)?.name||null,$=gw(O)}else{const O=d.startsWith("orca_")?d.replace("orca_",""):d,q=z?.filament.find(Z=>Z.setting_id===O);if(q)U=q.name;else if(D?.filament){const Z=D.filament.find(ee=>ee.setting_id===d);U=Z?.name||null,Z&&($=gw(Z.setting_id))}}if(!U)return null;let H=U.replace(/@.+$/,"").trim();H.startsWith("# ")&&(H=H.slice(2).trim());const le=nY(H);return{fullName:H,material:le.material,brand:le.brand,filamentId:$}},[d,D?.filament,I?.filament,R,z?.filament]),me=ie?.fullName||"",he=y.useMemo(()=>{if(!ce||!ie)return[];const{fullName:U,brand:$}=ie,H=U.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return ce.filter(le=>{const O=(le.material||"").toUpperCase(),q=le.manufacturer.toUpperCase();if(!(O===H.toUpperCase()||O.includes(H.toUpperCase())||H.toUpperCase().includes(O)))return!1;if($){const ee=$.toUpperCase();if(!q.includes(ee)&&!ee.includes(q))return!1}return!0})},[ce,ie]),xe=y.useMemo(()=>{if(!J?.profiles)return[];if(!ie){const pe=n.caliIdx;if(pe!=null&&pe>0){const G=J.profiles.find(L=>L.slot_id===pe&&(n.extruderId===void 0||L.extruder_id===n.extruderId));if(G)return[G]}return[]}const{fullName:U,material:$,brand:H,filamentId:le}=ie,O=U.toUpperCase(),q=$.toUpperCase(),Z=H.toUpperCase(),ee=le;if(!q||q.length<2)return[];const re=J.profiles.filter(pe=>{if(ee){const ge=gw(pe.filament_id);if(ge&&ge===ee&&!Ase(ge))return!0}const G=pe.name.toUpperCase();if(Z)return!(!G.includes(Z)||!G.includes(q));if(G.includes(O)||G.includes(q))return!0;const ae={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[q]||[];for(const ge of ae)if(G.includes(ge))return!0;return!1}),se=new Map;for(const pe of re){const G=`${pe.name}|${pe.k_value}`,L=se.get(G);L?n.extruderId!==void 0&&pe.extruder_id===n.extruderId&&L.extruder_id!==n.extruderId&&se.set(G,pe):se.set(G,pe)}const fe=Array.from(se.values()),ue=n.caliIdx;if(ue!=null&&ue>0&&!fe.some(pe=>pe.slot_id===ue)){const pe=J.profiles.find(G=>G.slot_id===ue&&(n.extruderId===void 0||G.extruder_id===n.extruderId));pe&&fe.unshift(pe)}return fe},[J?.profiles,ie,n.extruderId,n.caliIdx]);y.useEffect(()=>{if(t){if(n.savedPresetId)u(n.savedPresetId);else if(n.trayInfoIdx&&D?.filament){let U=D.filament.find($=>$.setting_id===n.trayInfoIdx);U||(U=D.filament.find($=>CF($.setting_id)===n.trayInfoIdx)),U&&u(U.setting_id)}else if(n.trayInfoIdx&&R?.length){const U=n.trayInfoIdx,$=R.find(H=>H.filament_id===U);$&&u(`builtin_${$.filament_id}`)}if(n.trayColor){const U=n.trayColor.slice(0,6);U&&g(U)}}else u(""),p(null),g(""),b(""),S(""),C(!1),j.current=""},[t,n.savedPresetId,n.trayInfoIdx,n.trayColor,D?.filament,R]),y.useEffect(()=>{if(xe.length>0){if(n.caliIdx!=null&&n.caliIdx>0){const U=xe.find($=>$.slot_id===n.caliIdx);if(U){p(U);return}}p(xe[0])}else p(null)},[d,xe,n.caliIdx]);const V=y.useCallback(U=>{U.key==="Escape"&&e()},[e]);y.useEffect(()=>{if(t)return document.addEventListener("keydown",V),()=>document.removeEventListener("keydown",V)},[t,V]);const Q=P&&!E||B||K||X;if(y.useEffect(()=>{if(!Q&&d&&d!==j.current){const U=requestAnimationFrame(()=>{const H=document.querySelector('[class*="fixed inset-0 z-50"]')?.querySelector(`[data-preset-id="${CSS.escape(d)}"]`);H&&(j.current=d,H.scrollIntoView({block:"nearest"}))});return()=>cancelAnimationFrame(U)}},[d,Q]),!t)return null;const A=d&&!de.isPending,F=f||n.trayColor?.slice(0,6)||"FFFFFF";return r.jsxs("div",{className:`fixed inset-0 z-50 flex ${l?"":"items-center justify-center"}`,children:[!l&&r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),r.jsxs("div",{className:l?"relative w-full h-full bg-bambu-dark-secondary flex flex-col":"relative w-full max-w-lg mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl",children:[r.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(xd,{className:"w-5 h-5 text-bambu-blue"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.title")}),l&&r.jsxs("div",{className:"flex items-center gap-2 ml-4 text-sm text-bambu-gray",children:[r.jsx("span",{className:"text-white/30",children:"|"}),n.trayColor&&r.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${n.trayColor.slice(0,6)}`}}),r.jsx("span",{className:"text-white/70",children:c("configureAmsSlot.slotLabel",{ams:rY(n.amsId,n.trayCount),slot:n.trayId+1})}),n.traySubBrands&&r.jsxs("span",{children:["(",n.traySubBrands,")"]})]})]}),r.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:r.jsx(Ht,{className:"w-5 h-5"})})]}),r.jsxs("div",{className:`p-4 overflow-y-auto ${l?"flex-1 min-h-0":"space-y-4 max-h-[60vh]"}`,children:[k&&r.jsx("div",{className:"absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl",children:r.jsxs("div",{className:"text-center space-y-3",children:[r.jsx(to,{className:"w-16 h-16 text-bambu-green mx-auto"}),r.jsx("p",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.slotConfigured")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:c("configureAmsSlot.settingsSentToPrinter")})]})}),!l&&r.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[r.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:c("configureAmsSlot.configuringSlot")}),r.jsxs("div",{className:"flex items-center gap-2",children:[n.trayColor&&r.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${n.trayColor.slice(0,6)}`}}),r.jsx("span",{className:"text-white font-medium",children:c("configureAmsSlot.slotLabel",{ams:rY(n.amsId,n.trayCount),slot:n.trayId+1})}),n.traySubBrands&&r.jsxs("span",{className:"text-bambu-gray",children:["(",n.traySubBrands,")"]})]})]}),Q?r.jsx("div",{className:"flex justify-center py-8",children:r.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):l?r.jsxs("div",{className:"flex gap-4 h-full",children:[r.jsxs("div",{className:"w-1/2 flex flex-col min-h-0",children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",r.jsx("span",{className:"text-red-400",children:"*"})]}),r.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:x,onChange:U=>S(U.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"}),r.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-1",children:Y.length===0?r.jsx("p",{className:"text-center py-4 text-bambu-gray",children:D?.filament?.length===0&&!I?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):Y.map(U=>r.jsx("button",{"data-preset-id":U.id,onClick:()=>u(U.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${d===U.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all",title:U.name,children:U.name}),r.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[U.source==="local"&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),U.source==="builtin"&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),U.isUser&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},U.id))})]}),r.jsxs("div",{className:"w-1/2 flex flex-col gap-4 min-h-0 overflow-y-auto",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),me&&r.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:me})})]}),xe.length>0?r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:m?.name||"",onChange:U=>{const $=xe.find(H=>H.name===U.target.value);p($||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:[r.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),xe.map(U=>r.jsxs("option",{value:U.name,children:[U.name," (K=",U.k_value,")"]},`${U.name}-${U.extruder_id}`))]}),r.jsx(za,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):d?r.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):r.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),m&&r.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:m.k_value})})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),he.length>0&&r.jsxs("div",{className:"mb-3",children:[r.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:ie?.fullName})}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:he.map(U=>r.jsxs("button",{onClick:()=>{const $=U.hex_color.replace("#","").toUpperCase();g($),b(U.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===U.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:U.color_name,children:[r.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:U.hex_color}}),r.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:U.color_name})]},U.id))})]}),r.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[iY.map(U=>r.jsx("button",{onClick:()=>{g(U.hex),b(U.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===U.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${U.hex}`},title:U.name},U.hex)),r.jsx("button",{onClick:()=>T(!N),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(N?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:N?"−":"+"})]}),N&&r.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:sY.map(U=>r.jsx("button",{onClick:()=>{g(U.hex),b(U.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===U.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${U.hex}`},title:U.name},U.hex))}),r.jsxs("div",{className:"flex gap-2 items-center",children:[r.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${F}`}}),r.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:U=>{const $=U.target.value;b($);const H=oY($);if(H)g(H);else{const le=$.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();le.length===6?g(le):le.length===3&&g(le.split("").map(O=>O+O).join(""))}},className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm"}),f&&r.jsx("button",{onClick:()=>{g(""),b("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&r.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",r.jsx("span",{className:"text-red-400",children:"*"})]}),r.jsxs("div",{className:"relative",children:[r.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:x,onChange:U=>S(U.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"}),r.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:Y.length===0?r.jsx("p",{className:"text-center py-4 text-bambu-gray",children:D?.filament?.length===0&&!I?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):Y.map(U=>r.jsx("button",{"data-preset-id":U.id,onClick:()=>u(U.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${d===U.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all",title:U.name,children:U.name}),r.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[U.source==="local"&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),U.source==="builtin"&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),U.isUser&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},U.id))})]})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),me&&r.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:me})})]}),xe.length>0?r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:m?.name||"",onChange:U=>{const $=xe.find(H=>H.name===U.target.value);p($||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:[r.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),xe.map(U=>r.jsxs("option",{value:U.name,children:[U.name," (K=",U.k_value,")"]},`${U.name}-${U.extruder_id}`))]}),r.jsx(za,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):d?r.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):r.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),m&&r.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:m.k_value})})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),he.length>0&&r.jsxs("div",{className:"mb-3",children:[r.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:ie?.fullName})}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:he.map(U=>r.jsxs("button",{onClick:()=>{const $=U.hex_color.replace("#","").toUpperCase();g($),b(U.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===U.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:U.color_name,children:[r.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:U.hex_color}}),r.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:U.color_name})]},U.id))})]}),r.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[iY.map(U=>r.jsx("button",{onClick:()=>{g(U.hex),b(U.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===U.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${U.hex}`},title:U.name},U.hex)),r.jsx("button",{onClick:()=>T(!N),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(N?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:N?"−":"+"})]}),N&&r.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:sY.map(U=>r.jsx("button",{onClick:()=>{g(U.hex),b(U.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===U.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${U.hex}`},title:U.name},U.hex))}),r.jsxs("div",{className:"flex gap-2 items-center",children:[r.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${F}`}}),r.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:U=>{const $=U.target.value;b($);const H=oY($);if(H)g(H);else{const le=$.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();le.length===6?g(le):le.length===3&&g(le.split("").map(O=>O+O).join(""))}},className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm"}),f&&r.jsx("button",{onClick:()=>{g(""),b("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&r.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}),r.jsxs("div",{className:"flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[r.jsx(Le,{variant:"secondary",onClick:()=>oe.mutate(),disabled:oe.isPending||de.isPending,className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:oe.isPending?r.jsxs(r.Fragment,{children:[r.jsx(lt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.resetting")]}):r.jsxs(r.Fragment,{children:[r.jsx(bs,{className:"w-4 h-4"}),c("configureAmsSlot.resetSlot")]})}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx(Le,{variant:"secondary",onClick:e,children:c("configureAmsSlot.cancel")}),r.jsx(Le,{onClick:()=>de.mutate(),disabled:!A,children:de.isPending?r.jsxs(r.Fragment,{children:[r.jsx(lt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.configuring")]}):r.jsxs(r.Fragment,{children:[r.jsx(xd,{className:"w-4 h-4"}),c("configureAmsSlot.configureSlot")]})})]})]}),(de.isError||oe.isError)&&r.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:de.error?.message||oe.error?.message})]})]})}function cY({className:t="w-4 h-4"}){return r.jsx("svg",{viewBox:"0 0 1945 1370",fill:"none",className:t,"aria-hidden":"true",children:r.jsxs("g",{transform:"translate(-754.293 -471.685)",children:[r.jsxs("g",{transform:"translate(0.18191 255.976)",children:[r.jsx("g",{transform:"matrix(1.05469 0 0 0.241063 -153.484 1120.2)",children:r.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"})}),r.jsx("g",{transform:"matrix(0.983656 0 0 1.0767 -62.2035 141.539)",children:r.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"})})]}),r.jsx("g",{transform:"translate(21.1916 0.684817)",children:r.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 Mse({folderId:t,onClose:e,onUploadComplete:a,onFileUploaded:n,autoUpload:i,validateFile:s,accept:o}){const{t:l}=wt(),[c,d]=y.useState([]),[u,m]=y.useState(!1),[p,f]=y.useState(!1),[g,v]=y.useState(!0),[b,x]=y.useState(!1),[S,k]=y.useState(!0),[C,N]=y.useState(null),T=y.useRef(null),j=oe=>{oe.preventDefault(),m(!0)},D=oe=>{oe.preventDefault(),m(!1)},P=oe=>{oe.preventDefault(),m(!1),B(Array.from(oe.dataTransfer.files))},E=oe=>{oe.target.files&&B(Array.from(oe.target.files))},z=(oe,Y)=>{d(ie=>ie.map(me=>me.file===oe?{...me,...Y}:me))},I=async oe=>{f(!0);for(const Y of oe)if(Y.status==="pending"){z(Y.file,{status:"uploading"});try{if(Y.isZip){const ie=await ne.extractZipFile(Y.file,t,g,b,S);z(Y.file,{status:ie.errors.length>0&&ie.extracted===0?"error":"success",extractedCount:ie.extracted,error:ie.errors.length>0?l("fileManager.zipFilesFailed","{{count}} files failed",{count:ie.errors.length}):void 0})}else{const ie=await ne.uploadLibraryFile(Y.file,t,S);z(Y.file,{status:"success"});const me=n?.(ie);if(me){N(me),d([]),f(!1);return}}}catch(ie){z(Y.file,{status:"error",error:ie instanceof Error?ie.message:l("fileManager.uploadFailed","Upload failed")})}}f(!1),a(),d(Y=>(Y.some(me=>me.status==="error")||e(),Y))},B=oe=>{if(N(null),s)for(const ie of oe){const me=s(ie);if(me){N(me);return}}const Y=oe.map(ie=>({file:ie,status:"pending",isZip:ie.name.toLowerCase().endsWith(".zip"),is3mf:ie.name.toLowerCase().endsWith(".3mf")}));d(ie=>[...ie,...Y]),i&&oe.length>0&&I(Y)},R=oe=>{d(Y=>Y.filter((ie,me)=>me!==oe))},K=c.some(oe=>oe.isZip&&oe.status==="pending"),J=c.some(oe=>oe.file.name.toLowerCase().endsWith(".stl")&&oe.status==="pending"),X=c.some(oe=>oe.is3mf&&oe.status==="pending"),ce=c.filter(oe=>oe.status==="pending").length,de=c.length>0&&ce===0&&!p;return r.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-lg border border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[r.jsx("h2",{className:"text-lg font-semibold text-white",children:l("fileManager.uploadFiles")}),r.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:r.jsx(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),r.jsxs("div",{className:"p-4 space-y-4",children:[r.jsxs("div",{onDragOver:j,onDragLeave:D,onDrop:P,onClick:()=>T.current?.click(),className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${u?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,children:[r.jsx(fn,{className:`w-10 h-10 mx-auto mb-3 ${u?"text-bambu-green":"text-bambu-gray"}`}),r.jsx("p",{className:"text-white font-medium",children:l(u?"fileManager.dropFilesHere":"fileManager.dragDropFiles")}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:l("fileManager.orClickToBrowse")}),r.jsx("p",{className:"text-xs text-bambu-gray/70 mt-2",children:l("fileManager.allFileTypesSupported")})]}),r.jsx("input",{ref:T,type:"file",multiple:!0,accept:o,className:"hidden",onChange:E}),K&&r.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(ro,{className:"w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"text-sm text-blue-300 font-medium",children:l("fileManager.zipFilesDetected")}),r.jsx("p",{className:"text-xs text-blue-300/70 mt-1",children:l("fileManager.zipExtractOptions")}),r.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:g,onChange:oe=>v(oe.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsx("span",{className:"text-sm text-white",children:l("fileManager.preserveZipStructure")})]}),r.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:b,onChange:oe=>x(oe.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsx("span",{className:"text-sm text-white",children:l("fileManager.createFolderFromZip")})]})]})]})}),X&&r.jsx("div",{className:"p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(xr,{className:"w-5 h-5 text-purple-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"text-sm text-purple-300 font-medium",children:l("fileManager.threemfDetected")}),r.jsx("p",{className:"text-xs text-purple-300/70 mt-1",children:l("fileManager.threemfExtractionInfo")})]})]})}),(J||K)&&r.jsx("div",{className:"p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(bu,{className:"w-5 h-5 text-bambu-green mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"text-sm text-bambu-green font-medium",children:l("fileManager.stlThumbnailGeneration")}),r.jsx("p",{className:"text-xs text-bambu-green/70 mt-1",children:l(K&&!J?"fileManager.zipMayContainStl":"fileManager.thumbnailsCanBeGenerated")}),r.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S,onChange:oe=>k(oe.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsx("span",{className:"text-sm text-white",children:l("fileManager.generateThumbnailsForStl")})]})]})]})}),c.length>0&&r.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:c.map((oe,Y)=>r.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[oe.isZip?r.jsx(ro,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):r.jsx(D1,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm text-white truncate",children:oe.file.name}),r.jsxs("p",{className:"text-xs text-bambu-gray",children:[(oe.file.size/1024/1024).toFixed(2)," MB",oe.isZip&&oe.status==="pending"&&r.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",l("fileManager.willBeExtracted")]}),oe.extractedCount!==void 0&&r.jsxs("span",{className:"text-green-400 ml-2",children:["• ",l("fileManager.filesExtracted",{count:oe.extractedCount})]})]}),oe.status==="error"&&oe.error&&r.jsx("p",{className:"text-xs text-red-400 mt-1 break-words",children:oe.error})]}),oe.status==="pending"&&r.jsx("button",{onClick:()=>R(Y),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:r.jsx(Ht,{className:"w-4 h-4 text-bambu-gray"})}),oe.status==="uploading"&&r.jsx(lt,{className:"w-4 h-4 text-bambu-green animate-spin"}),oe.status==="success"&&r.jsx(fr,{className:"w-4 h-4 text-green-500"}),oe.status==="error"&&r.jsx("span",{title:oe.error,children:r.jsx(Fr,{className:"w-4 h-4 text-red-500"})})]},Y))}),C&&r.jsx("div",{className:"p-3 bg-red-500/10 border border-red-500/30 rounded-lg",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(Fr,{className:"w-5 h-5 text-red-400 mt-0.5 flex-shrink-0"}),r.jsx("p",{className:"text-sm text-red-300",children:C})]})})]}),r.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2",children:[r.jsx(Le,{variant:"secondary",onClick:e,children:l("common.cancel")}),!de&&r.jsx(Le,{onClick:()=>I(c),disabled:ce===0||p,children:p?r.jsxs(r.Fragment,{children:[r.jsx(lt,{className:"w-4 h-4 mr-2 animate-spin"}),l("fileManager.uploading")]}):r.jsxs(r.Fragment,{children:[r.jsx(fn,{className:"w-4 h-4 mr-2"}),l("common.upload")," ",ce>0?`(${ce})`:""]})})]})]})})}function dY(t){if(!t)return"#808080";const e=t.replace("#","");return e.length>=8&&e.substring(6,8).toLowerCase()!=="ff"?`#${e.substring(0,8)}`:`#${e.substring(0,6)}`}function On(t){return t?t.replace("#","").toLowerCase().substring(0,6):""}const T9e=[["PA-CF","PA12-CF","PAHT-CF"]],Ese={};for(const t of T9e){const e=t[0];for(const a of t)Ese[a.toUpperCase()]=e.toUpperCase()}function jT(t){if(!t)return"";const e=t.toUpperCase();return Ese[e]??e}function NF(t,e){return jT(t)===jT(e)}function fd(t,e,a=40){const n=On(t),i=On(e);if(!n||!i||n.length<6||i.length<6)return!1;const s=parseInt(n.substring(0,2),16),o=parseInt(n.substring(2,4),16),l=parseInt(n.substring(4,6),16),c=parseInt(i.substring(0,2),16),d=parseInt(i.substring(2,4),16),u=parseInt(i.substring(4,6),16);return Math.abs(s-c)<=a&&Math.abs(o-d)<=a&&Math.abs(l-u)<=a}function yk(t,e,a,n){if(n)return"Ext";const i=String.fromCharCode(65+(t>=128?t-128:t));return a?`HT-${i}`:`${i}${e+1}`}function ib(t,e,a){return a?254+e:t>=128?t:t*4+e}function by(t){return t>50?"#00ae42":t>=15?"#f59e0b":"#ef4444"}function GC(t){return!t?.remaining_weight||!t?.filament_weight||t.filament_weight<=0?null:Math.min(100,Math.round(t.remaining_weight/t.filament_weight*100))}function uY(t,e){return(Number.isFinite(t)?Math.max(0,Math.trunc(t)):0).toString(16).toUpperCase().padStart(e,"0").slice(-e)}function A9e(t){const e=(t||"").trim().toUpperCase();let a=2166136261;for(let n=0;n>>0).toString(16).toUpperCase().padStart(8,"0")}function Sm(t,e,a){return`${A9e(t)}${uY(e,4)}${uY(a,4)}`}function mY(t){if(!t)return!1;const e=Date.now()+4320*60*60*1e3;return(Ga(t)?.getTime()??0)>e}function j9e(t,e,a,n){let i=Dse(e,t.nozzle_id);n&&(i=[...i].sort((c,d)=>{const u=(c.remain??-1)>=0?c.remain??-1:101,m=(d.remain??-1)>=0?d.remain??-1:101;return u-m}));const s=i.find(c=>!a.has(c.globalTrayId)&&NF(c.type,t.type)&&On(c.color)===On(t.color)),o=s?void 0:i.find(c=>!a.has(c.globalTrayId)&&NF(c.type,t.type)&&fd(c.color,t.color)),l=s||o?void 0:i.find(c=>!a.has(c.globalTrayId)&&NF(c.type,t.type));return s??o??l}function Dse(t,e){return t.filter(a=>e==null||a.extruderId===e)}function Qs(t){return t?!!(t.tray_uuid&&t.tray_uuid!=="00000000000000000000000000000000"||t.tag_uid&&t.tag_uid!=="0000000000000000"):!1}function vk(t){const e=[],a=t?.ams_extruder_map,n=!!t?.nozzles?.[1]?.nozzle_diameter||a&&Object.keys(a).length>0||(t?.vt_tray?.length??0)>1;t?.ams?.forEach(i=>{const s=i.tray.length===1;i.tray.forEach(o=>{if(o.tray_type){const l=dY(o.tray_color);e.push({type:o.tray_type,color:l,colorName:_c(l),amsId:i.id,trayId:o.id,isHt:s,isExternal:!1,label:yk(i.id,o.id,s,!1),globalTrayId:ib(i.id,o.id,!1),trayInfoIdx:o.tray_info_idx||"",traySubBrands:o.tray_sub_brands||"",extruderId:a?.[String(i.id)],remain:o.remain??-1})}})});for(const i of t?.vt_tray??[])if(i.tray_type){const s=dY(i.tray_color),o=i.id??254,l=(t?.vt_tray?.length??0)>1;e.push({type:i.tray_type,color:s,colorName:_c(s),amsId:-1,trayId:o-254,isHt:!1,isExternal:!0,label:l?o===254?"Ext-L":"Ext-R":"External",globalTrayId:o,trayInfoIdx:i.tray_info_idx||"",traySubBrands:i.tray_sub_brands||"",extruderId:n?255-o:void 0,remain:i.remain??-1})}return e}function pY(t,e,a){if(!t?.filaments||t.filaments.length===0)return;const n=vk(e);if(n.length===0)return;const i=e?.fila_switch?.installed===!0,s=new Set,o=t.filaments.map(d=>{const u=d.tray_info_idx||"";let m=n.filter(x=>!s.has(x.globalTrayId));d.nozzle_id!=null&&!i&&(m=m.filter(x=>x.extruderId===d.nozzle_id)),a&&(m=[...m].sort((x,S)=>{const k=x.remain>=0?x.remain:101,C=S.remain>=0?S.remain:101;return k-C}));let p,f,g,v;if(u){const x=m.filter(S=>S.trayInfoIdx===u);x.length===1?p=x[0]:x.length>1&&(a&&x.sort((S,k)=>{const C=S.remain>=0?S.remain:101,N=k.remain>=0?k.remain:101;return C-N}),f=x.find(S=>S.type?.toUpperCase()===d.type?.toUpperCase()&&On(S.color)===On(d.color)),f||(g=x.find(S=>S.type?.toUpperCase()===d.type?.toUpperCase()&&fd(S.color,d.color))),!f&&!g&&(v=x.find(S=>S.type?.toUpperCase()===d.type?.toUpperCase())))}!p&&!f&&!g&&!v&&(f=m.find(x=>x.type?.toUpperCase()===d.type?.toUpperCase()&&On(x.color)===On(d.color)),f||(g=m.find(x=>x.type?.toUpperCase()===d.type?.toUpperCase()&&fd(x.color,d.color))),!f&&!g&&(v=m.find(x=>x.type?.toUpperCase()===d.type?.toUpperCase())));const b=p||f||g||v||void 0;return b&&s.add(b.globalTrayId),{slot_id:d.slot_id,globalTrayId:b?.globalTrayId??-1}}),l=Math.max(...o.map(d=>d.slot_id||0));if(l<=0)return;const c=new Array(l).fill(-1);return o.forEach(d=>{d.slot_id&&d.slot_id>0&&(c[d.slot_id-1]=d.globalTrayId)}),c}function M9e(t){return y.useMemo(()=>vk(t),[t])}function Fse(t,e,a,n){const i=M9e(e),s=e?.fila_switch?.installed===!0,o=y.useMemo(()=>{if(!t?.filaments||t.filaments.length===0)return[];const u=new Set(Object.values(a));return t.filaments.map(m=>{const p=m.slot_id||0;if(p>0&&a[p]!==void 0){const D=a[p],P=i.find(E=>E.globalTrayId===D);if(P){const E=P.type?.toUpperCase()===m.type?.toUpperCase(),z=On(P.color)===On(m.color)||fd(P.color,m.color);let I;return E&&z?I="match":E?I="type_only":I="mismatch",{...m,loaded:P,hasFilament:!0,typeMatch:E,colorMatch:z,status:I,isManual:!0}}}const f=m.tray_info_idx||"";let g=i.filter(D=>!u.has(D.globalTrayId));m.nozzle_id!=null&&!s&&(g=g.filter(D=>D.extruderId===m.nozzle_id)),n&&(g=[...g].sort((D,P)=>{const E=D.remain>=0?D.remain:101,z=P.remain>=0?P.remain:101;return E-z}));let v,b,x,S;if(f){const D=g.filter(P=>P.trayInfoIdx===f);D.length===1?v=D[0]:D.length>1&&(n&&D.sort((P,E)=>{const z=P.remain>=0?P.remain:101,I=E.remain>=0?E.remain:101;return z-I}),b=D.find(P=>P.type?.toUpperCase()===m.type?.toUpperCase()&&On(P.color)===On(m.color)),b||(x=D.find(P=>P.type?.toUpperCase()===m.type?.toUpperCase()&&fd(P.color,m.color))),!b&&!x&&(S=D.find(P=>P.type?.toUpperCase()===m.type?.toUpperCase())))}!v&&!b&&!x&&!S&&(b=g.find(D=>D.type?.toUpperCase()===m.type?.toUpperCase()&&On(D.color)===On(m.color)),b||(x=g.find(D=>D.type?.toUpperCase()===m.type?.toUpperCase()&&fd(D.color,m.color))),!b&&!x&&(S=g.find(D=>D.type?.toUpperCase()===m.type?.toUpperCase())));const k=v||b||x||S||void 0;k&&u.add(k.globalTrayId);const C=!!k,N=C,T=!!v||!!b||!!x;let j;return v||b||x?j="match":S?j="type_only":j="mismatch",{...m,loaded:k,hasFilament:C,typeMatch:N,colorMatch:T,status:j,isManual:!1}})},[t,i,a,n,s]),l=y.useMemo(()=>{if(o.length===0)return;const u=Math.max(...o.map(p=>p.slot_id||0));if(u<=0)return;const m=new Array(u).fill(-1);return o.forEach(p=>{p.slot_id&&p.slot_id>0&&(m[p.slot_id-1]=p.loaded?.globalTrayId??-1)}),m},[o]),c=o.some(u=>u.status==="mismatch"),d=o.some(u=>u.status==="type_only");return{loadedFilaments:i,filamentComparison:o,amsMapping:l,hasTypeMismatch:c,hasColorMismatch:d}}function E9e(t,e,a,n){if(!t||t.length===0)return{exactMatches:0,typeOnlyMatches:0,missingTypes:0,totalSlots:0,status:"full"};let i=0,s=0,o=0;const l=new Set(Object.values(a));for(const u of t){const m=u.slot_id||0;if(m>0&&a[m]!==void 0){const x=a[m],S=e.find(k=>k.globalTrayId===x);if(S){const k=S.type?.toUpperCase()===u.type?.toUpperCase(),C=On(S.color)===On(u.color)||fd(S.color,u.color);k&&C?i++:k?s++:o++;continue}}let p=e.filter(x=>!l.has(x.globalTrayId));if(u.nozzle_id!=null){const x=p.filter(S=>S.extruderId===u.nozzle_id);x.length>0&&(p=x)}n&&(p=[...p].sort((x,S)=>{const k=x.remain>=0?x.remain:101,C=S.remain>=0?S.remain:101;return k-C}));const f=p.find(x=>x.type?.toUpperCase()===u.type?.toUpperCase()&&On(x.color)===On(u.color)),g=f?void 0:p.find(x=>x.type?.toUpperCase()===u.type?.toUpperCase()&&fd(x.color,u.color)),v=f||g?void 0:p.find(x=>x.type?.toUpperCase()===u.type?.toUpperCase()),b=f??g??v;b&&l.add(b.globalTrayId),f||g?i++:v?s++:o++}const c=t.length;let d="full";return o>0?d="missing":s>0&&(d="partial"),{exactMatches:i,typeOnlyMatches:s,missingTypes:o,totalSlots:c,status:d}}function D9e(t,e,a,n){if(!t?.filaments||t.filaments.length===0)return;const i=vk(e);if(i.length===0)return;const s=new Set(Object.values(a)),o=[];for(const d of t.filaments){const u=d.slot_id||0;if(u>0&&a[u]!==void 0){o.push({slot_id:u,globalTrayId:a[u]});continue}let m=i.filter(b=>!s.has(b.globalTrayId));if(d.nozzle_id!=null){const b=m.filter(x=>x.extruderId===d.nozzle_id);b.length>0&&(m=b)}n&&(m=[...m].sort((b,x)=>{const S=b.remain>=0?b.remain:101,k=x.remain>=0?x.remain:101;return S-k}));const p=m.find(b=>b.type?.toUpperCase()===d.type?.toUpperCase()&&On(b.color)===On(d.color)),f=p?void 0:m.find(b=>b.type?.toUpperCase()===d.type?.toUpperCase()&&fd(b.color,d.color)),g=p||f?void 0:m.find(b=>b.type?.toUpperCase()===d.type?.toUpperCase()),v=p??f??g;v&&s.add(v.globalTrayId),o.push({slot_id:u,globalTrayId:v?.globalTrayId??-1})}const l=Math.max(...o.map(d=>d.slot_id||0));if(l<=0)return;const c=new Array(l).fill(-1);return o.forEach(d=>{d.slot_id&&d.slot_id>0&&(c[d.slot_id-1]=d.globalTrayId)}),c}const hY={useDefault:!0,manualMappings:{},autoConfigured:!1};function F9e(t,e,a,n,i,s,o){const l=df({queries:t.map(v=>({queryKey:["printer-status",v],queryFn:()=>ne.getPrinterStatus(v),enabled:t.length>0,staleTime:5e3}))}),c=y.useMemo(()=>t.map((v,b)=>{const x=l[b],S=x?.data,C=e?.find(z=>z.id===v)?.name||`Printer ${v}`,N=vk(S),T=i[v]||hY,j=pY(a,S,o),D=T.useDefault?n:T.manualMappings,P=D9e(a,S,D,o),E=E9e(a?.filaments,N,D,o);return{printerId:v,printerName:C,status:S,isLoading:x?.isLoading??!1,loadedFilaments:N,autoMapping:j,finalMapping:P,matchStatus:E.status,exactMatches:E.exactMatches,typeOnlyMatches:E.typeOnlyMatches,missingTypes:E.missingTypes,totalSlots:E.totalSlots,config:T}}),[t,l,e,a,i,n,o]),d=l.some(v=>v.isLoading),u=(v,b)=>{s(x=>({...x,[v]:{...x[v]||hY,...b}}))},m=v=>{const b=c.find(k=>k.printerId===v);if(!b||!b.status||!a?.filaments)return;const x=pY(a,b.status,o);if(!x)return;const S={};x.forEach((k,C)=>{k!==-1&&(S[C+1]=k)}),u(v,{useDefault:!1,manualMappings:S,autoConfigured:!0})},p=()=>{for(const v of t)m(v)},f=v=>c.find(x=>x.printerId===v)?.finalMapping,g=c.every(v=>v.matchStatus!=="missing");return{printerResults:c,isLoading:d,perPrinterConfigs:i,updatePrinterConfig:u,autoConfigureAll:p,autoConfigurePrinter:m,getFinalMapping:f,allPrintersReady:g}}const Lse={USD:"$",EUR:"€",GBP:"£",CHF:"Fr.",JPY:"¥",CNY:"¥",CAD:"$",AUD:"$",INR:"₹",HKD:"HK$",KRW:"₩",SEK:"kr",NOK:"kr",DKK:"kr",PLN:"zł",BRL:"R$",TWD:"NT$",SGD:"S$",NZD:"NZ$",MXN:"MX$",BZD:"BZ$",MYR:"RM",CZK:"Kč",THB:"฿",ZAR:"R",TRY:"₺",RUB:"₽",HUF:"Ft",ILS:"₪",UAH:"₴"};function Vo(t){return Lse[t.toUpperCase()]||t}const L9e=Object.entries(Lse).map(([t,e])=>({code:t,label:`${t} (${e})`})),Vd="/img/bed",R9e={"cool plate":{icon:`${Vd}/bed_cool.png`,label:"Cool Plate"},"pc plate":{icon:`${Vd}/bed_cool.png`,label:"Cool Plate"},"cool plate (supertack)":{icon:`${Vd}/bed_cool_supertack.png`,label:"Cool Plate SuperTack"},"supertack plate":{icon:`${Vd}/bed_cool_supertack.png`,label:"Cool Plate SuperTack"},"bambu cool plate supertack":{icon:`${Vd}/bed_cool_supertack.png`,label:"Cool Plate SuperTack"},"engineering plate":{icon:`${Vd}/bed_engineering.png`,label:"Engineering Plate"},"high temp plate":{icon:`${Vd}/bed_high_templ.png`,label:"High Temp Plate"},"textured pei plate":{icon:`${Vd}/bed_pei.png`,label:"Textured PEI Plate"},"pei plate":{icon:`${Vd}/bed_pei.png`,label:"PEI Plate"},"smooth pei plate":{icon:`${Vd}/bed_pei_cool.png`,label:"Smooth PEI Plate"}};function wk(t){return t?R9e[t.trim().toLowerCase()]??null:null}function z9e({printerId:t,filamentReqs:e,manualMappings:a,onManualMappingChange:n,currencySymbol:i,defaultCostPerKg:s,defaultExpanded:o=!1}){const{t:l}=wt(),c=na(),[d,u]=y.useState(!1),[m,p]=y.useState(o),{data:f}=$e({queryKey:["printer-status",t],queryFn:()=>ne.getPrinterStatus(t),enabled:!!t}),{data:g}=$e({queryKey:["spool-assignments",t],queryFn:()=>ne.getAssignments(t),enabled:!!t}),{loadedFilaments:v,filamentComparison:b,hasTypeMismatch:x,hasColorMismatch:S}=Fse(e,f,a),k=y.useMemo(()=>{const R=new Map;for(const K of g||[]){const J=K.ams_id===255,X=ib(K.ams_id,K.tray_id,J);R.set(X,K.spool?.cost_per_kg??null)}return R},[g]),C=y.useMemo(()=>{const R=new Map;for(const K of g||[]){const J=K.ams_id===255,X=ib(K.ams_id,K.tray_id,J),ce=K.spool;if(!ce){R.set(X,null);continue}R.set(X,Math.max(0,Math.round((ce.label_weight??0)-(ce.weight_used??0))))}return R},[g]),N=y.useMemo(()=>{let R=0;for(const K of b){const J=K.loaded?.globalTrayId;if(J==null)continue;const ce=k.get(J)??null??s;ce>0&&(R+=K.used_grams/1e3*ce)}return R},[b,k,s]),T=y.useMemo(()=>Array.from(k.values()).some(R=>R!=null&&R>0),[k]),j=e?.filaments&&e.filaments.length>0,D=e?.filaments?.some(R=>R.nozzle_id!=null)??!1,P=f?.fila_switch?.installed===!0,E=R=>{const K=f?.fila_switch;if(!K?.installed)return null;const J=K.in_slots.indexOf(R);return J<0?null:K.out_extruders[J]??null};if(!j||!f)return null;const z=x?"#f97316":S?"#facc15":"#00ae42",I=(R,K)=>{if(R>0)if(K===""){const J={...a};delete J[R],n(J)}else n({...a,[R]:parseInt(K,10)})},B=async()=>{u(!0);try{await ne.refreshPrinterStatus(t),await new Promise(R=>setTimeout(R,500)),await c.refetchQueries({queryKey:["printer-status",t]})}finally{u(!1)}};return r.jsxs("div",{className:"mb-4",children:[r.jsxs("button",{type:"button",onClick:()=>p(!m),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[r.jsx(Bw,{className:"w-4 h-4",fill:z,stroke:"none"}),r.jsx("span",{children:l("printModal.filamentMapping")}),x?r.jsx("span",{className:"text-xs text-orange-400",children:"(Type not found)"}):S?r.jsx("span",{className:"text-xs text-yellow-400",children:"(Color mismatch)"}):r.jsx("span",{className:"text-xs text-bambu-green",children:"(Ready)"}),m?r.jsx(el,{className:"w-4 h-4 ml-auto"}):r.jsx(za,{className:"w-4 h-4 ml-auto"})]}),m&&r.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("span",{className:"text-xs text-bambu-gray",children:"Click to change slot assignment"}),r.jsxs("button",{type:"button",onClick:B,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:[r.jsx(tr,{className:`w-3 h-3 ${d?"animate-spin":""}`}),r.jsx("span",{children:"Re-read"})]})]}),b.map((R,K)=>r.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[r.jsx("span",{title:`Required: ${R.type} - ${_c(R.color)}`,children:r.jsx(Bw,{className:"w-3 h-3",fill:R.color,stroke:R.color})}),r.jsxs("span",{className:"text-white truncate flex items-center gap-1",children:[D&&R.nozzle_id!=null&&r.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:R.nozzle_id===1?l("printModal.leftNozzleTooltip"):l("printModal.rightNozzleTooltip"),children:R.nozzle_id===1?l("printModal.leftNozzle"):l("printModal.rightNozzle")}),R.type," ",r.jsxs("span",{className:"text-bambu-gray",children:["(",R.used_grams,"g)"]})]}),r.jsx("span",{className:"text-bambu-gray",children:"→"}),r.jsxs("select",{value:R.loaded?.globalTrayId??"",onChange:J=>I(R.slot_id||0,J.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.status==="match"?"border-bambu-green/50 text-bambu-green":R.status==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${R.isManual?"ring-1 ring-blue-400/50":""}`,title:R.isManual?"Manually selected":"Auto-matched",children:[r.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),v.filter(J=>R.nozzle_id==null||P||J.extruderId===R.nozzle_id).map(J=>{const X=C.get(J.globalTrayId),ce=X!=null?l("printModal.slotRemainingShort",{grams:X,defaultValue:` - ${X}g left`}):"",de=P?E(J.globalTrayId):null,oe=de==null?"":` [${l(de===1?"printModal.leftNozzle":"printModal.rightNozzle")}]`;return r.jsxs("option",{value:J.globalTrayId,className:"bg-bambu-dark text-white",children:[J.label,": ",J.traySubBrands||J.type," (",J.colorName,")",ce,oe]},J.globalTrayId)})]}),R.status==="match"?r.jsx(_r,{className:"w-3 h-3 text-bambu-green"}):R.status==="type_only"?r.jsx("span",{title:"Same type, different color",children:r.jsx(xa,{className:"w-3 h-3 text-yellow-400"})}):r.jsx("span",{title:"Filament type not loaded",children:r.jsx(xa,{className:"w-3 h-3 text-orange-400"})})]},K)),r.jsxs("div",{className:"text-xs text-bambu-gray",children:[l("printModal.totalCost")," ",r.jsx("span",{className:"text-white",children:N>0||T?`${i}${N.toFixed(2)}`:"N/A"})]}),x&&r.jsx("p",{className:"text-xs text-orange-400 mt-2",children:"Required filament type not found in printer."})]})]})}function I9e({filamentReqs:t,availableFilaments:e,overrides:a,onChange:n,forceColorMatch:i,onForceColorMatchChange:s}){const{t:o}=wt(),l=y.useMemo(()=>{const u={};for(const m of e){const p=jT(m.type);u[p]||(u[p]=[]),u[p].push(m)}return u},[e]),c=t?.filaments;if(!c||c.length===0||e.length===0)return null;const d=(u,m)=>{if(m===""){const p={...a};delete p[u],n(p)}else{const[p,f]=m.split("|");n({...a,[u]:{type:p,color:f}})}};return r.jsxs("div",{className:"mb-4",children:[r.jsx("div",{className:"flex items-center gap-2 text-sm text-bambu-gray mb-2",children:r.jsx("span",{children:o("printModal.filamentOverride")})}),r.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:o("printModal.filamentOverrideHint")}),r.jsx("div",{className:"bg-bambu-dark rounded-lg p-3 space-y-2",children:c.map(u=>{const m=a[u.slot_id],p=!!m,f=l[jT(u.type)]||[],g=u.nozzle_id!=null?f.filter(v=>v.extruder_id==null||v.extruder_id===u.nozzle_id):f;return r.jsxs("div",{className:"space-y-1",children:[r.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 20px"},children:[r.jsx("span",{title:`${o("printModal.originalFilament")}: ${u.type} - ${_c(u.color)}`,children:r.jsx(Bw,{className:"w-3 h-3",fill:u.color,stroke:u.color})}),r.jsxs("span",{className:"text-white truncate",children:[u.type," ",r.jsxs("span",{className:"text-bambu-gray",children:["(",u.used_grams,"g)"]})]}),r.jsx("span",{className:"text-bambu-gray",children:"→"}),r.jsxs("select",{value:p?`${m.type}|${m.color}`:"",onChange:v=>d(u.slot_id,v.target.value),disabled:g.length===0,className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${p?"border-blue-400/50 text-blue-400":"border-bambu-gray/30 text-bambu-gray"}`,children:[r.jsxs("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:[o("printModal.originalFilament"),": ",u.type," (",_c(u.color),")"]}),g.map((v,b)=>r.jsxs("option",{value:`${v.type}|${v.color}`,className:"bg-bambu-dark text-white",children:[v.tray_sub_brands||v.type," (",_c(v.color),")"]},`${v.type}-${v.color}-${v.tray_sub_brands}-${b}`))]}),p?r.jsx("button",{type:"button",onClick:()=>d(u.slot_id,""),className:"text-bambu-gray hover:text-white transition-colors",title:o("printModal.resetToOriginal"),children:r.jsx(bs,{className:"w-3 h-3"})}):r.jsx("span",{className:"w-3"})]}),r.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer select-none pl-5",children:[r.jsx("input",{type:"checkbox",checked:i?.[u.slot_id]??!1,onChange:v=>s?.(u.slot_id,v.target.checked),className:"accent-bambu-green w-3 h-3"}),r.jsx(BS,{className:"w-3 h-3"}),o("printModal.forceColorMatch")]})]},u.slot_id)})})]})}function O9e({plates:t,isMultiPlate:e,selectedPlates:a,onToggle:n,onSelectAll:i,onDeselectAll:s,multiSelect:o}){const{t:l}=wt();if(!e||t.length<=1)return null;const c=a.size===t.length;return r.jsxs("div",{className:"mb-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx(tn,{className:"w-4 h-4 text-bambu-gray"}),r.jsxs("span",{className:"text-sm text-bambu-gray",children:["Select Plate",o?"s":""," to Print"]}),a.size===0&&r.jsxs("span",{className:"text-xs text-orange-400 flex items-center gap-1",children:[r.jsx(xa,{className:"w-3 h-3"}),"Selection required"]}),o&&i&&s&&r.jsx("button",{type:"button",onClick:c?s: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?l("queue.deselectAll"):l("queue.selectAllPlates",{count:t.length})})]}),r.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map(d=>{const u=a.has(d.index);return r.jsxs("button",{type:"button",onClick:()=>n(d.index),className:`flex items-center gap-2 p-2 rounded-lg border transition-colors text-left ${u?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"}`,children:[o&&(u?r.jsx(xs,{className:"w-4 h-4 text-bambu-green flex-shrink-0"}):r.jsx(so,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"})),d.has_thumbnail&&d.thumbnail_url!=null?r.jsx("img",{src:zn(d.thumbnail_url),alt:`Plate ${d.index}`,className:"w-10 h-10 rounded object-cover bg-bambu-dark-tertiary"}):r.jsx("div",{className:"w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center",children:r.jsx(tn,{className:"w-5 h-5 text-bambu-gray"})}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"text-sm text-white font-medium truncate",children:d.name||`Plate ${d.index}`}),r.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[d.objects.length>0?d.objects.slice(0,3).join(", ")+(d.objects.length>3?"...":""):`${d.filaments.length} filament${d.filaments.length!==1?"s":""}`,d.print_time_seconds!=null?` • ${ds(d.print_time_seconds)}`:""]}),(()=>{const m=wk(d.bed_type);return m?r.jsxs("p",{className:"text-xs text-bambu-gray flex items-center gap-1 mt-0.5 truncate",title:m.label,children:[r.jsx("img",{src:m.icon,alt:"",className:"w-3.5 h-3.5 object-contain flex-shrink-0"}),r.jsx("span",{className:"truncate",children:m.label})]}):null})()]}),!o&&u&&r.jsx(_r,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]},d.index)})})]})}const B9e=new Set(["IDLE","FINISH","FAILED"]);function U9e({printerResult:t,filamentReqs:e,onUpdateConfig:a}){const n=na(),[i,s]=y.useState(!1),o=(d,u)=>{if(d<=0)return;const m={...t.config.manualMappings};u===""?delete m[d]:m[d]=parseInt(u,10),a({useDefault:!1,manualMappings:m,autoConfigured:!1})},l=async()=>{s(!0);try{await ne.refreshPrinterStatus(t.printerId),await new Promise(d=>setTimeout(d,500)),await n.refetchQueries({queryKey:["printer-status",t.printerId]})}finally{s(!1)}},c=e.map(d=>{const u=d.slot_id||0,m=t.config.manualMappings[u];let p,f=!1;if(m!==void 0)p=t.loadedFilaments.find(v=>v.globalTrayId===m),f=!0;else{const v=new Set(Object.values(t.config.manualMappings)),b=n.getQueryData(["settings"]);p=j9e(d,t.loadedFilaments,v,b?.prefer_lowest_filament)}let g="mismatch";if(p){const v=p.type?.toUpperCase()===d.type?.toUpperCase(),b=On(p.color)===On(d.color)||fd(p.color,d.color);v&&b?g="match":v&&(g="type_only")}return{req:d,loaded:p,status:g,isManual:f}});return r.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom slot mapping"}),r.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",disabled:i,children:[r.jsx(tr,{className:`w-3 h-3 ${i?"animate-spin":""}`}),r.jsx("span",{children:"Re-read"})]})]}),c.map(({req:d,loaded:u,status:m,isManual:p},f)=>r.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[r.jsx("span",{title:`Required: ${d.type} - ${_c(d.color)}`,children:r.jsx(Bw,{className:"w-3 h-3",fill:d.color,stroke:d.color})}),r.jsxs("span",{className:"text-white truncate",children:[d.type," ",r.jsxs("span",{className:"text-bambu-gray",children:["(",d.used_grams,"g)"]})]}),r.jsx("span",{className:"text-bambu-gray",children:"→"}),r.jsxs("select",{value:u?.globalTrayId??"",onChange:g=>o(d.slot_id||0,g.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${m==="match"?"border-bambu-green/50 text-bambu-green":m==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${p?"ring-1 ring-blue-400/50":""}`,title:p?"Manually selected":"Auto-matched",children:[r.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),Dse(t.loadedFilaments,d.nozzle_id).map(g=>r.jsxs("option",{value:g.globalTrayId,className:"bg-bambu-dark text-white",children:[g.label,": ",g.traySubBrands||g.type," (",g.colorName,")"]},g.globalTrayId))]}),m==="match"?r.jsx(_r,{className:"w-3 h-3 text-bambu-green"}):m==="type_only"?r.jsx("span",{title:"Same type, different color",children:r.jsx(xa,{className:"w-3 h-3 text-yellow-400"})}):r.jsx("span",{title:"Filament type not loaded",children:r.jsx(xa,{className:"w-3 h-3 text-orange-400"})})]},f))]})}function H9e({printers:t,selectedPrinterIds:e,onMultiSelect:a,isLoading:n=!1,allowMultiple:i=!1,showInactive:s=!1,disableBusy:o=!1,printerMappingResults:l,filamentReqs:c,onAutoConfigurePrinter:d,onUpdatePrinterConfig:u,assignmentMode:m="printer",onAssignmentModeChange:p,targetModel:f,onTargetModelChange:g,targetLocation:v,onTargetLocationChange:b,slicedForModel:x}){const[S,k]=y.useState(!1),C=s?t:t.filter(ie=>ie.is_active),N=df({queries:C.map(ie=>({queryKey:["printerStatus",ie.id],queryFn:()=>ne.getPrinterStatus(ie.id),staleTime:5e3}))}),T=y.useMemo(()=>{const ie=new Map;return C.forEach((me,he)=>{const xe=N[he];xe?.data&&ie.set(me.id,xe.data)}),ie},[C,N]),j=ie=>{const me=T.get(ie);return me?me.connected?!B9e.has(me.state??""):!0:!1},D=ie=>{const me=T.get(ie);if(!me)return null;if(!me.connected)return"Offline";const he=me.state;return he?he==="RUNNING"?me.stg_cur_name||"Printing":he==="PREPARE"?"Preparing":he==="PAUSE"?"Paused":he==="IDLE"?"Idle":he==="FINISH"?"Finished":he==="FAILED"?"Failed":he:null},P=y.useMemo(()=>{if(m!=="printer"||!x||S)return C;const ie=C.filter(me=>me.model===x);return ie.length>0?ie:C},[C,m,x,S]),E=C.length-P.length,z=y.useMemo(()=>{const ie=C.map(me=>me.model).filter(me=>!!me);return[...new Set(ie)].sort()},[C]),I=y.useMemo(()=>{if(!f)return[];const ie=C.filter(me=>me.model===f&&me.location).map(me=>me.location).filter(me=>!!me);return[...new Set(ie)].sort()},[C,f]),B=p&&g&&z.length>0,R=i&&e.length>1&&l&&c?.filaments&&c.filaments.length>0&&d&&u;if(n)return r.jsx("div",{className:"flex justify-center py-8",children:r.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(P.length===0)return r.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm mb-4",children:[r.jsx(Sn,{className:"w-4 h-4"}),"No ",s?"":"active ","printers available"]});const K=ie=>{o&&j(ie)||(i?e.includes(ie)?a(e.filter(me=>me!==ie)):a([...e,ie]):a([ie]))},J=()=>{const ie=o?P.filter(me=>!j(me.id)):P;a(ie.map(me=>me.id))},X=()=>{a([])},ce=(ie,me,he)=>{he.stopPropagation(),!(!d||!u)&&(me?d(ie):u(ie,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},de=ie=>e.includes(ie),oe=e.length,Y=ie=>l?.find(me=>me.printerId===ie);return r.jsxs("div",{className:"space-y-2 mb-6",children:[B&&r.jsxs("div",{className:"flex gap-2 mb-4",children:[r.jsxs("button",{type:"button",onClick:()=>{p("printer"),g(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${m==="printer"?"border-bambu-green bg-bambu-green/10 text-white":"border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray"}`,children:[r.jsx(xr,{className:"w-4 h-4"}),r.jsx("span",{className:"text-sm",children:"Specific Printer"})]}),r.jsxs("button",{type:"button",onClick:()=>{p("model"),a([]);const ie=x&&z.includes(x)?x:z[0];g(ie)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${m==="model"?"border-bambu-green bg-bambu-green/10 text-white":"border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray"}`,children:[r.jsx(km,{className:"w-4 h-4"}),r.jsxs("span",{className:"text-sm",children:["Any ",x||"Model"]})]})]}),m==="model"&&B&&r.jsxs("div",{className:"space-y-3 mb-4",children:[!x&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Target Model"}),r.jsxs("select",{value:f||"",onChange:ie=>{g(ie.target.value||null),b&&b(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:[r.jsx("option",{value:"",children:"Select a model..."}),z.map(ie=>r.jsx("option",{value:ie,children:ie},ie))]})]}),f&&I.length>0&&b&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Location Filter (optional)"}),r.jsxs("select",{value:v||"",onChange:ie=>b(ie.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:[r.jsx("option",{value:"",children:"Any location"}),I.map(ie=>r.jsx("option",{value:ie,children:ie},ie))]})]}),f&&r.jsxs("p",{className:"text-xs text-bambu-gray",children:["Scheduler will assign to first available idle ",f," printer",v?` in ${v}`:""]})]}),m==="printer"&&i&&P.length>1&&r.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray mb-2",children:[r.jsx("span",{children:oe===0?"Select printers":`${oe} printer${oe!==1?"s":""} selected`}),r.jsxs("div",{className:"flex gap-2",children:[oe0&&r.jsx("button",{type:"button",onClick:X,className:"text-bambu-gray hover:text-white transition-colors",children:"Clear"})]})]}),m==="printer"&&P.map(ie=>{const me=de(ie.id),he=Y(ie.id),xe=he&&!he.config.useDefault,V=j(ie.id),Q=o&&V,A=D(ie.id);return r.jsxs("div",{children:[r.jsxs("button",{type:"button",onClick:()=>K(ie.id),disabled:Q,className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${Q?"border-bambu-dark-tertiary bg-bambu-dark opacity-50 cursor-not-allowed":me?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"} ${ie.is_active?"":"opacity-60"}`,children:[r.jsx("div",{className:`p-2 rounded-lg ${Q?"bg-bambu-dark-tertiary":me?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:r.jsx(xr,{className:`w-5 h-5 ${Q?"text-bambu-gray/50":me?"text-bambu-green":"text-bambu-gray"}`})}),r.jsxs("div",{className:"text-left flex-1",children:[r.jsxs("p",{className:`font-medium ${Q?"text-bambu-gray":"text-white"}`,children:[ie.name,!ie.is_active&&r.jsx("span",{className:"text-bambu-gray text-xs ml-2",children:"(inactive)"})]}),r.jsxs("p",{className:"text-xs text-bambu-gray",children:[ie.model||"Unknown model"," • ",ie.ip_address]})]}),A&&r.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${V?"bg-yellow-500/20 text-yellow-400":"bg-bambu-green/20 text-bambu-green"}`,children:A}),i&&r.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${Q?"border-bambu-gray/30":me?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:me&&r.jsx(_r,{className:"w-3 h-3 text-white"})})]}),me&&R&&he&&r.jsxs("div",{className:"ml-4 mt-2 mb-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",onClick:F=>F.stopPropagation(),children:[r.jsx("input",{type:"checkbox",checked:xe,onChange:F=>ce(ie.id,F.target.checked,F),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"}),r.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom mapping"})]}),r.jsxs("span",{className:`text-xs ml-2 ${he.matchStatus==="full"?"text-bambu-green":he.matchStatus==="partial"?"text-yellow-400":"text-orange-400"}`,children:["(",he.exactMatches,"/",he.totalSlots," matched)"]}),he.isLoading&&r.jsx(tr,{className:"w-3 h-3 text-bambu-gray animate-spin"}),xe&&r.jsxs("button",{type:"button",onClick:F=>{F.stopPropagation(),d(ie.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:[r.jsx(HI,{className:"w-3 h-3"}),"Auto"]})]}),xe&&r.jsx(U9e,{printerResult:he,filamentReqs:c.filaments,onUpdateConfig:F=>u(ie.id,F)})]})]},ie.id)}),m==="printer"&&E>0&&!S&&r.jsxs("button",{type:"button",onClick:()=>k(!0),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2 flex items-center gap-1",children:[r.jsx(xa,{className:"w-3 h-3 text-yellow-400"}),E," other printer",E>1?"s":""," hidden (different model) —",r.jsx("span",{className:"underline",children:"show all"})]}),m==="printer"&&S&&x&&r.jsx("button",{type:"button",onClick:()=>k(!1),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2",children:r.jsxs("span",{className:"underline",children:["Show only ",x," printers"]})}),m==="printer"&&oe===0&&r.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[r.jsx(Sn,{className:"w-3 h-3"}),"Select at least one printer"]}),m==="model"&&!f&&r.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[r.jsx(Sn,{className:"w-3 h-3"}),"Select a target printer model"]})]})}function q9e({options:t,onChange:e,defaultExpanded:a=!1,showDualNozzleOptions:n=!1}){const{t:i}=wt(),[s,o]=y.useState(a),c=[{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(u=>!u.dualNozzleOnly||n),d=u=>{e({...t,[u]:!t[u]})};return r.jsxs("div",{className:"mb-4",children:[r.jsxs("button",{type:"button",onClick:()=>o(!s),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[r.jsx(Sy,{className:"w-4 h-4"}),r.jsx("span",{children:i("queue.bulkEdit.printOptions")}),s?r.jsx(el,{className:"w-4 h-4 ml-auto"}):r.jsx(za,{className:"w-4 h-4 ml-auto"})]}),s&&r.jsx("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:c.map(({key:u,label:m,desc:p})=>r.jsxs("label",{className:"flex items-center justify-between cursor-pointer group",children:[r.jsxs("div",{children:[r.jsx("span",{className:"text-sm text-white",children:m}),r.jsx("p",{className:"text-xs text-bambu-gray",children:p})]}),r.jsx("div",{className:`relative w-10 h-5 rounded-full transition-colors ${t[u]?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,onClick:()=>d(u),children:r.jsx("div",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white transition-transform ${t[u]?"translate-x-5":"translate-x-0.5"}`})})]},u))})]})}function V9e({options:t,onChange:e,dateFormat:a="system",timeFormat:n="system",canControlPrinter:i=!0,showStagger:s=!1,printerCount:o=0,hasGcodeSnippets:l=!1}){const{t:c}=wt(),[d,u]=y.useState(""),[m,p]=y.useState(""),[f,g]=y.useState(!0),[v,b]=y.useState(!0),x=y.useRef(null),S=y.useRef(!1);y.useEffect(()=>{if(t.scheduleType!=="scheduled"){S.current=!1;return}if(!S.current){S.current=!0;let P;t.scheduledTime?(P=new Date(t.scheduledTime),isNaN(P.getTime())&&(P=new Date,P.setHours(P.getHours()+1,0,0,0))):(P=new Date,P.setHours(P.getHours()+1,0,0,0),e({...t,scheduledTime:g3(P)})),u(f3(P,a)),p(U8(P,n)),g(!0),b(!0)}},[t.scheduleType,t.scheduledTime,a,n,e,t]);const k=P=>{e({...t,scheduleType:P})},C=(P,E)=>{const z=F0e(P,a),I=L0e(E);g(!!z),b(!!I),z&&I&&(z.setHours(I.hours,I.minutes,0,0),z>new Date&&e({...t,scheduledTime:g3(z)}))},N=P=>{u(P),C(P,m)},T=P=>{p(P),C(d,P)},j=P=>{const E=P.target.value;if(E){const z=new Date(E);isNaN(z.getTime())||(u(f3(z,a)),p(U8(z,n)),g(!0),b(!0),e({...t,scheduledTime:E}))}},D=()=>{x.current?.showPicker()};return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"When to print"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="asap"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>k("asap"),children:[r.jsx(ar,{className:"w-4 h-4"}),"ASAP"]}),r.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="scheduled"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>k("scheduled"),children:[r.jsx(Pn,{className:"w-4 h-4"}),"Scheduled"]}),r.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="manual"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>k("manual"),children:[r.jsx(lJ,{className:"w-4 h-4"}),"Queue Only"]})]})]}),t.scheduleType==="scheduled"&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date & Time"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("div",{className:"flex-1 relative",children:[r.jsx("input",{type:"text",className:`w-full px-3 py-2 pr-10 bg-bambu-dark border rounded-lg text-white focus:outline-none ${f?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:d,onChange:P=>N(P.target.value),placeholder:M0e(a)}),r.jsx("button",{type:"button",onClick:D,className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",title:"Open calendar",children:r.jsx(Pn,{className:"w-4 h-4"})}),r.jsx("input",{ref:x,type:"datetime-local",className:"absolute top-0 left-0 w-0 h-0 opacity-0 pointer-events-none",value:t.scheduledTime,onChange:j,tabIndex:-1})]}),r.jsx("div",{className:"w-32",children:r.jsx("input",{type:"text",className:`w-full px-3 py-2 bg-bambu-dark border rounded-lg text-white focus:outline-none ${v?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:m,onChange:P=>T(P.target.value),placeholder:E0e(n)})})]}),(!f||!v)&&r.jsx("p",{className:"mt-1 text-xs text-red-400",children:"Please enter a valid date and time"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"requirePrevious",checked:t.requirePreviousSuccess,onChange:P=>e({...t,requirePreviousSuccess:P.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsx("label",{htmlFor:"requirePrevious",className:"text-sm text-bambu-gray",children:"Only start if previous print succeeded"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"autoOffAfter",checked:t.autoOffAfter,onChange:P=>e({...t,autoOffAfter:P.target.checked}),disabled:!i,className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green disabled:opacity-50"}),r.jsxs("label",{htmlFor:"autoOffAfter",className:`text-sm flex items-center gap-1 ${i?"text-bambu-gray":"text-bambu-gray/50"}`,children:[r.jsx(Tu,{className:"w-3.5 h-3.5"}),"Power off printer when done"]})]}),l&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"gcodeInjection",checked:t.gcodeInjection,onChange:P=>e({...t,gcodeInjection:P.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsxs("label",{htmlFor:"gcodeInjection",className:"text-sm flex items-center gap-1 text-bambu-gray",children:[r.jsx(tv,{className:"w-3.5 h-3.5"}),c("printModal.gcodeInjection","Inject auto-print G-code")]})]}),s&&t.scheduleType!=="manual"&&r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"staggerEnabled",checked:t.staggerEnabled,onChange:P=>e({...t,staggerEnabled:P.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsxs("label",{htmlFor:"staggerEnabled",className:"text-sm flex items-center gap-1 text-bambu-gray",children:[r.jsx(tn,{className:"w-3.5 h-3.5"}),c("printModal.staggerPrinterStarts","Stagger printer starts")]})]}),t.staggerEnabled&&r.jsxs("div",{className:"ml-6 space-y-3",children:[r.jsxs("div",{className:"flex gap-3",children:[r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:c("printModal.staggerGroupSize","Group size")}),r.jsx("input",{type:"number",min:1,max:o,value:t.staggerGroupSize,onChange:P=>e({...t,staggerGroupSize:Math.max(1,parseInt(P.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"})]}),r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:c("printModal.staggerInterval","Interval (min)")}),r.jsx("input",{type:"number",min:1,max:60,value:t.staggerIntervalMinutes,onChange:P=>e({...t,staggerIntervalMinutes:Math.max(1,parseInt(P.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&&(()=>{const P=Math.ceil(o/t.staggerGroupSize),E=o%t.staggerGroupSize,z=(P-1)*t.staggerIntervalMinutes;return r.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:P,size:t.staggerGroupSize,interval:t.staggerIntervalMinutes}),E!==0&&t.staggerGroupSize1?` (${c("printModal.staggerTotal","total: {{minutes}} min",{minutes:z})})`:""]})})()]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:t.scheduleType==="asap"?"Print will start as soon as the printer is idle.":t.scheduleType==="scheduled"?"Print will start at the scheduled time if the printer is idle. If busy, it will wait until the printer becomes available.":"Print will be staged but won't start automatically. Use the Start button to release it to the queue."})]})}const Sl={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1,nozzle_offset_cali:!0},TF={scheduleType:"asap",scheduledTime:"",requirePreviousSuccess:!1,autoOffAfter:!1,gcodeInjection:!1,staggerEnabled:!1,staggerGroupSize:2,staggerIntervalMinutes:5};function Cc({mode:t,archiveId:e,libraryFileId:a,archiveName:n,queueItem:i,initialSelectedPrinterIds:s,onClose:o,onSuccess:l,projectId:c,cleanupLibraryAfterDispatch:d}){const{t:u}=wt(),m=na(),{showToast:p}=oa(),{hasPermission:f}=lr(),g=!!a&&!e,[v,b]=y.useState(()=>t==="edit-queue-item"&&i?.printer_id?[i.printer_id]:s?.length?s:[]),[x,S]=y.useState(()=>t==="edit-queue-item"&&i?.plate_id!=null?new Set([i.plate_id]):new Set),k=x.size===1?[...x][0]:null,[C,N]=y.useState(1),[T,j]=y.useState(()=>t==="edit-queue-item"&&i?{bed_levelling:i.bed_levelling??Sl.bed_levelling,flow_cali:i.flow_cali??Sl.flow_cali,vibration_cali:i.vibration_cali??Sl.vibration_cali,layer_inspect:i.layer_inspect??Sl.layer_inspect,timelapse:i.timelapse??Sl.timelapse,nozzle_offset_cali:i.nozzle_offset_cali??Sl.nozzle_offset_cali}:Sl),[D,P]=y.useState(()=>{if(t==="edit-queue-item"&&i){let Pe="asap";i.manual_start?Pe="manual":i.scheduled_time&&!mY(i.scheduled_time)&&(Pe="scheduled");let Ye="";if(i.scheduled_time&&!mY(i.scheduled_time)){const it=Ga(i.scheduled_time)??new Date;Ye=g3(it)}return{scheduleType:Pe,scheduledTime:Ye,requirePreviousSuccess:i.require_previous_success,autoOffAfter:i.auto_off_after,gcodeInjection:i.gcode_injection??!1,staggerEnabled:!1,staggerGroupSize:TF.staggerGroupSize,staggerIntervalMinutes:TF.staggerIntervalMinutes}}return TF}),[E,z]=y.useState(()=>{if(t==="edit-queue-item"&&i?.ams_mapping&&Array.isArray(i.ams_mapping)){const Pe={};return i.ams_mapping.forEach((Ye,it)=>{Ye!==-1&&(Pe[it+1]=Ye)}),Pe}return{}}),[I,B]=y.useState({}),[R,K]=y.useState(()=>t==="edit-queue-item"&&i?.target_model?"model":"printer"),[J,X]=y.useState(()=>t==="edit-queue-item"&&i?.target_model?i.target_model:null),[ce,de]=y.useState(()=>t==="edit-queue-item"&&i?.target_location?i.target_location:null),[oe,Y]=y.useState(()=>{if(t==="edit-queue-item"&&i?.filament_overrides){const Pe={};for(const Ye of i.filament_overrides)Pe[Ye.slot_id]={type:Ye.type,color:Ye.color};return Pe}return{}}),[ie,me]=y.useState(()=>{if(t==="edit-queue-item"&&i?.filament_overrides){const Pe={};for(const Ye of i.filament_overrides)Pe[Ye.slot_id]=Ye.force_color_match===!0;return Pe}return{}}),[he]=y.useState(()=>t==="edit-queue-item"&&i?.printer_id?[i.printer_id]:[]),[xe]=y.useState(()=>t==="edit-queue-item"&&i?i.plate_id:null),[V,Q]=y.useState(!1),[A,F]=y.useState({current:0,total:0}),[U,$]=y.useState(null),[H,le]=y.useState(new Set),O=v.length,q=v.length>0?v[0]:null,{data:Z}=$e({queryKey:["settings"],queryFn:ne.getSettings}),ee=y.useRef(!1);y.useEffect(()=>{!Z||ee.current||t==="edit-queue-item"||(ee.current=!0,j({bed_levelling:Z.default_bed_levelling??Sl.bed_levelling,flow_cali:Z.default_flow_cali??Sl.flow_cali,vibration_cali:Z.default_vibration_cali??Sl.vibration_cali,layer_inspect:Z.default_layer_inspect??Sl.layer_inspect,timelapse:Z.default_timelapse??Sl.timelapse,nozzle_offset_cali:Z.default_nozzle_offset_cali??Sl.nozzle_offset_cali}))},[Z,t]);const re=y.useRef(!1);y.useEffect(()=>{!Z||re.current||t==="edit-queue-item"||(re.current=!0,P(Pe=>({...Pe,staggerGroupSize:Z.stagger_group_size??Pe.staggerGroupSize,staggerIntervalMinutes:Z.stagger_interval_minutes??Pe.staggerIntervalMinutes})))},[Z,t]);const se=Vo(Z?.currency||"USD"),fe=Z?.default_filament_cost??0,{data:ue,isLoading:pe}=$e({queryKey:["printers"],queryFn:ne.getPrinters}),{data:G}=$e({queryKey:["spool-assignments"],queryFn:()=>ne.getAssignments(),staleTime:30*1e3,enabled:(t==="reprint"||t==="add-to-queue")&&R==="printer"||g&&t==="reprint"}),{data:L}=$e({queryKey:["archive",e],queryFn:()=>ne.getArchive(e),enabled:!!e&&!g}),{data:ae}=$e({queryKey:["library-file",a],queryFn:()=>ne.getLibraryFile(a),enabled:g&&!!a}),ge=L?.sliced_for_model||ae?.sliced_for_model||null,{data:be,isError:ve}=$e({queryKey:["archive-plates",e],queryFn:()=>ne.getArchivePlates(e),enabled:!!e&&!g,retry:!1}),{data:De}=$e({queryKey:["library-file-plates",a],queryFn:()=>ne.getLibraryFilePlates(a),enabled:g&&!!a}),je=g?De:be,{data:Te,isError:qe}=$e({queryKey:["archive-filaments",e,k],queryFn:()=>ne.getArchiveFilamentRequirements(e,k??void 0),enabled:!!e&&!g&&(k!==null||!je?.is_multi_plate),retry:!1}),{data:Ce}=$e({queryKey:["library-file-filaments",a,k],queryFn:()=>ne.getLibraryFileFilamentRequirements(a,k??void 0),enabled:g&&!!a&&(k!==null||!je?.is_multi_plate)}),Ie=!g&&(ve||qe),Re=g?Ce:Te,Ue=y.useMemo(()=>{if(!(k===null||!je?.plates?.length))return je.plates.find(Pe=>Pe.index===k)?.name||void 0},[je,k]),{data:ze}=$e({queryKey:["available-filaments",J,ce],queryFn:()=>ne.getAvailableFilaments(J,ce??void 0),enabled:R==="model"&&!!J}),{data:nt}=$e({queryKey:["printer-status",q],queryFn:()=>ne.getPrinterStatus(q),enabled:!!q}),{amsMapping:Oe}=Fse(Re,nt,E,Z?.prefer_lowest_filament),tt=F9e(v,ue,Re,E,I,B,Z?.prefer_lowest_filament);y.useEffect(()=>{je?.plates&&je.plates.length>=1&&x.size===0&&S(new Set([je.plates[0].index]))},[je,x.size]),y.useEffect(()=>{if(t==="edit-queue-item")return;const Pe=ue?.filter(Ye=>Ye.is_active)||[];Pe.length===1&&v.length===0&&b([Pe[0].id])},[t,ue,v.length]),y.useEffect(()=>{t==="edit-queue-item"?(JSON.stringify(v.sort())!==JSON.stringify(he.sort())||k!==xe)&&(z({}),B({}),le(new Set)):(z({}),B({}),le(new Set))},[t,v,k,he,xe]);const[Fe,Ke]=y.useState(J),[Ve,Me]=y.useState(k);y.useEffect(()=>{(J!==Fe||k!==Ve)&&(Ke(J),Me(k),(t!=="edit-queue-item"||Fe!==null)&&(Y({}),me({})))},[J,k,Fe,Ve,t]),y.useEffect(()=>{if(!Z?.per_printer_mapping_expanded||v.length<=1)return;const Pe=v.filter(Ye=>{if(H.has(Ye))return!1;const it=tt.printerResults.find(Ae=>Ae.printerId===Ye);return it&&it.status&&!it.isLoading});Pe.length>0&&(le(Ye=>{const it=new Set(Ye);return Pe.forEach(Ae=>it.add(Ae)),it}),Pe.forEach(Ye=>{tt.autoConfigurePrinter(Ye)}))},[Z?.per_printer_mapping_expanded,v,H,tt]),y.useEffect(()=>{const Pe=Ye=>{Ye.key==="Escape"&&!V&&o()};return window.addEventListener("keydown",Pe),()=>window.removeEventListener("keydown",Pe)},[o,V]);const Be=je?.is_multi_plate??!1,Qe=je?.plates??[],Ge=y.useMemo(()=>{const Pe=new Map;return G&&G.forEach(Ye=>{const it=Ye.ams_id===255,Ae=ib(Ye.ams_id,Ye.tray_id,it),Se=Pe.get(Ye.printer_id)??new Map;Se.set(Ae,Ye),Pe.set(Ye.printer_id,Se)}),Pe},[G]),Ee=y.useMemo(()=>{if(!U||U.length===0)return"";const Pe=U.map(Ye=>u("printModal.insufficientFilamentLine",{printer:Ye.printerName,slot:Ye.slotLabel,required:Math.round(Ye.requiredGrams),remaining:Math.round(Ye.remainingGrams)}));return[u("printModal.insufficientFilamentMessage"),...Pe].join(` `)},[U,u]),rt=at({mutationFn:Pe=>ne.addToQueue(Pe)}),Xe=at({mutationFn:Pe=>ne.updateQueueItem(i.id,Pe),onSuccess:()=>{m.invalidateQueries({queryKey:["queue"]}),p("Queue item updated"),l?.(),o()},onError:Pe=>{p(Pe.message||"Failed to update queue item","error")}}),Nt=D.staggerEnabled&&v.length>1,Vt=async(Pe,Ye)=>{if(Pe?.preventDefault(),!Ye?.skipFilamentCheck&&!Z?.disable_filament_warnings&&(t==="reprint"||t==="add-to-queue")&&R==="printer"){const Je=[],Ze=Re?.filaments??[];if(Ze.length>0&&Ge.size>0){const kt=(ft,_t)=>!Number.isFinite(ft)||ft<=0||!Number.isFinite(_t)||_t<0?null:Math.max(0,ft-_t);for(const ft of v){const _t=v.length>1?tt.getFinalMapping(ft):Oe;if(!_t)continue;const St=v.length>1?tt.printerResults.find(ke=>ke.printerId===ft)?.status:nt,qt=vk(St),yt=new Map(qt.map(ke=>[ke.globalTrayId,ke.label])),Ot=Ge.get(ft),ua=ue?.find(ke=>ke.id===ft)?.name??`Printer ${ft}`;Ot&&Ze.forEach(ke=>{if(!ke.slot_id||ke.slot_id<=0)return;const xt=_t[ke.slot_id-1];if(!Number.isFinite(xt)||xt<0)return;const Kt=Ot.get(xt)?.spool;if(!Kt)return;const Zt=kt(Kt.label_weight,Kt.weight_used);Zt!==null&&(Zt>=ke.used_grams||Je.push({printerName:ua,slotLabel:yt.get(xt)??`Slot ${ke.slot_id}`,requiredGrams:ke.used_grams,remainingGrams:Zt}))})}}if(Je.length>0){$(Je);return}}if(R==="printer"&&v.length===0){p("Please select at least one printer","error");return}if(R==="model"&&!J){p("Please select a target printer model","error");return}Q(!0);const it=x.size>1?Qe.filter(Je=>x.has(Je.index)):[null],Ae=R==="model"?it.length:v.length*it.length;F({current:0,total:Ae});const Se={success:0,failed:0,errors:[]},ct=Je=>{if(v.length>1){const Ze=I[Je];if(Ze&&!Ze.useDefault)return tt.getFinalMapping(Je)}return Oe},We=(()=>{const Je=[];if(Re?.filaments)for(const Ze of Re.filaments){const kt=oe[Ze.slot_id],ft=ie[Ze.slot_id]??!1,_t=kt?.type??Ze.type,St=kt?.color??Ze.color;(kt||ft)&&Je.push({slot_id:Ze.slot_id,type:_t,color:St,color_name:_c(St),force_color_match:ft})}else for(const[Ze,{type:kt,color:ft}]of Object.entries(oe)){const _t=parseInt(Ze,10),St=ie[_t]??!1;Je.push({slot_id:_t,type:kt,color:ft,color_name:_c(ft),force_color_match:St})}return Je.length>0?Je:void 0})(),st=(Je,Ze)=>({printer_id:R==="printer"?Je:null,target_model:R==="model"?J:null,target_location:R==="model"?ce:null,filament_overrides:R==="model"?We:void 0,archive_id:g?void 0:e,library_file_id:g?a:void 0,require_previous_success:D.requirePreviousSuccess,auto_off_after:D.autoOffAfter,gcode_injection:D.gcodeInjection,manual_start:D.scheduleType==="manual",skip_filament_check:Ye?.skipFilamentCheck===!0?!0:void 0,ams_mapping:Je?ct(Je):void 0,plate_id:Ze!==void 0?Ze:k,scheduled_time:D.scheduleType==="scheduled"&&D.scheduledTime?new Date(D.scheduledTime).toISOString():void 0,...T,project_id:c??void 0});if(R==="model"){if(t==="reprint"){p("Model-based assignment only works with queue mode","error"),Q(!1);return}let Je=0;for(const Ze of it){Je++,F({current:Je,total:Ae});const kt=Ze?Ze.index:k;try{if(t==="edit-queue-item"&&!Ze){const ft={printer_id:null,target_model:J,target_location:ce,filament_overrides:We||null,require_previous_success:D.requirePreviousSuccess,auto_off_after:D.autoOffAfter,gcode_injection:D.gcodeInjection,manual_start:D.scheduleType==="manual",ams_mapping:void 0,plate_id:kt,scheduled_time:D.scheduleType==="scheduled"&&D.scheduledTime?new Date(D.scheduledTime).toISOString():null,...T};await Xe.mutateAsync(ft)}else{const ft=st(null,kt);Xt>1&&(ft.quantity=Xt),await rt.mutateAsync(ft)}Se.success++}catch(ft){Se.failed++;const _t=Ze?Ze.name||`Plate ${Ze.index}`:"";Se.errors.push(_t?`${_t}: ${ft.message}`:ft.message)}}}else{const Je=D.staggerEnabled&&(t==="add-to-queue"||t==="reprint")&&v.length>1,Ze=Je?D.scheduleType==="scheduled"&&D.scheduledTime?new Date(D.scheduledTime).getTime():Date.now():0;let kt=0;for(const ft of it){const _t=ft?ft.index:k;for(let St=0;St1){const Ot=st(qt,_t);Ot.quantity=Xt-1,await rt.mutateAsync(Ot)}}else if(t==="edit-queue-item"&&kt===1){const yt=ct(qt),Ot={printer_id:qt,target_model:null,target_location:null,require_previous_success:D.requirePreviousSuccess,auto_off_after:D.autoOffAfter,gcode_injection:D.gcodeInjection,manual_start:D.scheduleType==="manual",ams_mapping:yt,plate_id:_t,scheduled_time:D.scheduleType==="scheduled"&&D.scheduledTime?new Date(D.scheduledTime).toISOString():null,...T};await Xe.mutateAsync(Ot)}else{const yt=st(qt,_t);if(Xt>1&&(yt.quantity=Xt),Je){const Ot=Math.floor(St/D.staggerGroupSize);if(Ot>0){const ua=Ot*D.staggerIntervalMinutes*6e4;yt.scheduled_time=new Date(Ze+ua).toISOString()}}await rt.mutateAsync(yt)}Se.success++}catch(yt){Se.failed++;const Ot=ue?.find(xt=>xt.id===qt)?.name||`Printer ${qt}`,ua=ft?ft.name||`Plate ${ft.index}`:"",ke=ua?`${Ot} (${ua})`:Ot;Se.errors.push(`${ke}: ${yt.message}`)}}}}Q(!1),Se.failed===0?(t==="reprint"&&Nt?p(u("queue.itemsQueued",{count:Se.success})):t!=="reprint"&&(t==="edit-queue-item"?p("Queue item updated"):Se.success===1?p(R==="model"?`Queued for any ${J}`:u("queue.printQueued")):p(u("queue.itemsQueued",{count:Se.success}))),m.invalidateQueries({queryKey:["queue"]}),l?.(),o()):Se.success===0?p(`Failed: ${Se.errors[0]}`,"error"):(p(`${Se.success} succeeded, ${Se.failed} failed`,"error"),m.invalidateQueries({queryKey:["queue"]}))},ht=V||Xe.isPending,It=y.useMemo(()=>!(ht||R==="printer"&&v.length===0||R==="model"&&!J||R==="model"&&t==="reprint"||Be&&x.size===0),[v.length,R,J,t,Be,x.size,ht]),Xt=R==="printer"&&v.length>1?1:C,ca=(()=>{const Pe=v.length;if(t==="reprint"){const Ye=Nt&&Pe>1;let it=Ye?u("printModal.staggerToPrinters",{count:Pe,defaultValue:"Stagger to {{count}} printers"}):Pe>1?u("queue.printToPrinters",{count:Pe}):u("queue.print");return Xt>1&&(it=`${it} ×${Xt}`),{title:u(g?"queue.print":"queue.reprint"),icon:xr,submitText:it,submitIcon:Ye?Pn:xr,loadingText:A.total>1?u("queue.sendingProgress",{current:A.current,total:A.total}):u("queue.sending")}}if(t==="add-to-queue"){let Ye=u("queue.addToQueue");return x.size>1?Ye=u("queue.queueSelectedPlates",{count:x.size}):Pe>1&&(Ye=u("queue.queueToPrinters",{count:Pe})),Xt>1&&(Ye=`${Ye} ×${Xt}`),{title:u("queue.schedulePrint"),icon:Pn,submitText:Ye,submitIcon:Pn,loadingText:A.total>1?u("queue.addingProgress",{current:A.current,total:A.total}):u("queue.adding")}}return{title:u("queue.editQueueItem"),icon:ci,submitText:u("common.save"),submitIcon:ci,loadingText:A.total>1?u("queue.savingProgress",{current:A.current,total:A.total}):u("common.saving")}})(),ot=ca.icon,vt=ca.submitIcon,Ct=q&&x.size<=1&&(g||(Be?k!==null:!0)),ea=y.useMemo(()=>new Set(["H2D","H2DPRO","H2C","X2D"]),[]),aa=y.useMemo(()=>R==="model"?J?ea.has(J.toUpperCase().replace(/[\s-]/g,"")):!1:!ue||v.length===0?!1:v.some(Pe=>ue.find(Ye=>Ye.id===Pe)?.nozzle_count===2),[R,J,ue,v,ea]);return r.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:V?void 0:o,children:[r.jsx(Tt,{className:"w-full max-w-2xl max-h-[90vh] overflow-y-auto",onClick:Pe=>Pe.stopPropagation(),children:r.jsxs(jt,{className:t==="reprint"?"":"p-0",children:[r.jsxs("div",{className:`flex items-center justify-between ${t==="reprint"?"mb-4":"p-4 border-b border-bambu-dark-tertiary"}`,children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(ot,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:ca.title})]}),r.jsx(Le,{variant:"ghost",size:"sm",onClick:o,disabled:V,children:r.jsx(Ht,{className:"w-5 h-5"})})]}),r.jsxs("form",{onSubmit:Vt,className:t==="reprint"?"":"p-4 space-y-4",children:[r.jsx("p",{className:`text-sm text-bambu-gray ${t==="reprint"?"mb-4":""}`,children:t==="reprint"?r.jsxs(r.Fragment,{children:["Send ",r.jsx("span",{className:"text-white",children:n})," to"," ",s?.length===1&&ue?r.jsx("span",{className:"text-white",children:ue.find(Pe=>Pe.id===s[0])?.name??"printer(s)"}):"printer(s)"]}):r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"block text-bambu-gray mb-1",children:"Print Job"}),r.jsx("span",{className:"text-white font-medium truncate block",children:n})]})}),(()=>{if(!Qe.length)return null;const Pe=k!=null?Qe.find(it=>it.index===k):Qe[0],Ye=wk(Pe?.bed_type);return Ye?r.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-bambu-gray -mt-2",title:Ye.label,children:[r.jsx("img",{src:Ye.icon,alt:"",className:"w-4 h-4 object-contain flex-shrink-0"}),r.jsx("span",{className:"truncate",children:Ye.label})]}):null})(),r.jsx(O9e,{plates:Qe,isMultiPlate:Be,selectedPlates:x,onToggle:Pe=>{S(Ye=>{const it=new Set(Ye);return t==="add-to-queue"?it.has(Pe)?it.delete(Pe):it.add(Pe):(it.clear(),it.add(Pe)),it})},onSelectAll:t==="add-to-queue"?()=>S(new Set(Qe.map(Pe=>Pe.index))):void 0,onDeselectAll:t==="add-to-queue"?()=>S(new Set):void 0,multiSelect:t==="add-to-queue"}),!s?.length&&r.jsx(H9e,{printers:ue||[],selectedPrinterIds:v,onMultiSelect:b,isLoading:pe,allowMultiple:!0,showInactive:t==="edit-queue-item",disableBusy:t==="reprint",printerMappingResults:tt.printerResults,filamentReqs:Re,onAutoConfigurePrinter:tt.autoConfigurePrinter,onUpdatePrinterConfig:tt.updatePrinterConfig,assignmentMode:t==="reprint"?"printer":R,onAssignmentModeChange:t!=="reprint"?K:void 0,targetModel:J,onTargetModelChange:t!=="reprint"?X:void 0,targetLocation:ce,onTargetLocationChange:t!=="reprint"?de:void 0,slicedForModel:ge}),R==="model"&&J&&Re&&ze&&ze.length>0&&r.jsx(I9e,{filamentReqs:Re,availableFilaments:ze,overrides:oe,onChange:Y,forceColorMatch:ie,onForceColorMatchChange:(Pe,Ye)=>me(it=>({...it,[Pe]:Ye}))}),ge&&R==="printer"&&v.length===1&&(()=>{const Pe=ue?.find(Ye=>Ye.id===v[0]);return Pe&&Pe.model&&ge!==Pe.model?r.jsxs("div",{className:"p-3 mb-2 bg-yellow-500/10 border border-yellow-500/30 rounded-lg flex items-center gap-2",children:[r.jsx(xa,{className:"w-4 h-4 text-yellow-400 flex-shrink-0"}),r.jsxs("span",{className:"text-sm text-yellow-400",children:["File was sliced for ",ge,", but printing on ",Pe.model]})]}):null})(),Ie&&r.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:[r.jsx(Sn,{className:"w-4 h-4 text-orange-400 mt-0.5 flex-shrink-0"}),r.jsx("p",{className:"text-orange-400",children:"Archive data unavailable. The source file may have been deleted. Filament mapping is disabled."})]}),Ct&&!Ie&&v.length===1&&r.jsx(z9e,{printerId:q,filamentReqs:Re,manualMappings:E,onManualMappingChange:z,defaultExpanded:!!s?.length||(Z?.per_printer_mapping_expanded??!1),currencySymbol:se,defaultCostPerKg:fe}),(t==="reprint"||O>0||R==="model"&&J)&&r.jsx(q9e,{options:T,onChange:j,defaultExpanded:!!s?.length,showDualNozzleOptions:aa}),t!=="edit-queue-item"&&(R==="model"||v.length<=1)&&r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("label",{htmlFor:"printQuantity",className:"text-sm text-bambu-gray whitespace-nowrap",children:u("queue.quantity","Quantity")}),r.jsx("input",{id:"printQuantity",type:"number",min:1,max:999,value:C,onChange:Pe=>N(Math.max(1,Math.min(999,parseInt(Pe.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"}),C>1&&r.jsx("span",{className:"text-xs text-bambu-gray",children:u("queue.quantityHint","Creates {{count}} queue items",{count:C})})]}),t==="reprint"&&R==="printer"&&v.length>1&&r.jsxs("div",{className:"space-y-2 pb-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"staggerEnabledReprint",checked:D.staggerEnabled,onChange:Pe=>P({...D,staggerEnabled:Pe.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsxs("label",{htmlFor:"staggerEnabledReprint",className:"text-sm flex items-center gap-1 text-bambu-gray",children:[r.jsx(tn,{className:"w-3.5 h-3.5"}),u("printModal.staggerPrinterStarts","Stagger printer starts")]})]}),D.staggerEnabled&&(()=>{const Pe=D.staggerGroupSize,Ye=D.staggerIntervalMinutes,it=Math.ceil(v.length/Pe),Ae=(it-1)*Ye;return r.jsxs("p",{className:"ml-6 text-xs text-bambu-gray",children:[u("printModal.staggerPreview","{{printers}} printers → {{groups}} groups of {{size}}, starting every {{interval}} min",{printers:v.length,groups:it,size:Pe,interval:Ye}),it>1?` (${u("printModal.staggerTotal","total: {{minutes}} min",{minutes:Ae})})`:""]})})()]}),t!=="reprint"&&r.jsx(V9e,{options:D,onChange:P,dateFormat:Z?.date_format||"system",timeFormat:Z?.time_format||"system",canControlPrinter:f("printers:control"),showStagger:t==="add-to-queue"&&R==="printer"&&v.length>1,printerCount:v.length,hasGcodeSnippets:!!Z?.gcode_snippets}),t==="reprint"&&!!Z?.gcode_snippets&&Xt>1&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"gcodeInjectionReprint",checked:D.gcodeInjection,onChange:Pe=>P({...D,gcodeInjection:Pe.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsxs("label",{htmlFor:"gcodeInjectionReprint",className:"text-sm flex items-center gap-1 text-bambu-gray",children:[r.jsx(tv,{className:"w-3.5 h-3.5"}),u("printModal.gcodeInjection","Inject auto-print G-code")]})]}),Xe.isError&&r.jsx("div",{className:"mb-4 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:Xe.error?.message||"Failed to complete operation"}),r.jsxs("div",{className:`flex gap-3 ${t==="reprint"?"":"pt-2"}`,children:[r.jsx(Le,{type:"button",variant:"secondary",onClick:o,className:"flex-1",disabled:V,children:"Cancel"}),r.jsx(Le,{type:"submit",disabled:!It,className:"flex-1",children:ht?r.jsxs(r.Fragment,{children:[r.jsx(lt,{className:"w-4 h-4 animate-spin"}),ca.loadingText]}):r.jsxs(r.Fragment,{children:[r.jsx(vt,{className:"w-4 h-4"}),ca.submitText]})})]})]})]})}),U&&U.length>0&&r.jsx(ka,{title:u("printModal.insufficientFilamentTitle"),message:Ee,confirmText:u("printModal.printAnyway"),cancelText:u("common.cancel"),variant:"warning",onConfirm:()=>{$(null),Vt(void 0,{skipFilamentCheck:!0})},onCancel:()=>$(null)})]})}function fY({value:t}){const{t:e}=wt(),[a,n]=y.useState(!1),i=async()=>{try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(t);else{const s=document.createElement("textarea");s.value=t,s.style.position="fixed",s.style.opacity="0",document.body.appendChild(s);try{if(s.select(),!document.execCommand("copy"))return}finally{document.body.removeChild(s)}}n(!0),setTimeout(()=>n(!1),2e3)}catch{}};return r.jsx("button",{onClick:i,className:"ml-2 p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:e(a?"printers.copied":"printers.copyToClipboard"),children:a?r.jsx(_r,{className:"w-3.5 h-3.5 text-bambu-green"}):r.jsx(li,{className:"w-3.5 h-3.5"})})}function G9e({printer:t,status:e,totalPrintHours:a,onClose:n}){const{t:i}=wt();y.useEffect(()=>{const o=l=>{l.key==="Escape"&&n()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[n]);const s=[];if(s.push({label:i("printers.model"),value:t.model??"—"}),s.push({label:i("common.status"),value:r.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-xs font-medium ${e?.connected?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${e?.connected?"bg-bambu-green":"bg-red-400"}`}),e?.connected?i("printers.status.available"):i("printers.status.offline")]})}),e?.state){const o={IDLE:"printers.status.idle",RUNNING:"printers.status.printing",PAUSE:"printers.status.paused",FINISH:"printers.status.finished",FAILED:"printers.status.error"};s.push({label:i("printers.state"),value:i(o[e.state]??"printers.status.unknown")})}if(s.push({label:i("printers.ipAddress"),value:r.jsxs("span",{className:"flex items-center",children:[r.jsx("span",{className:"font-mono",children:t.ip_address}),r.jsx(fY,{value:t.ip_address})]})}),s.push({label:i("printers.serialNumber"),value:r.jsxs("span",{className:"flex items-center",children:[r.jsx("span",{className:"font-mono truncate",children:t.serial_number}),r.jsx(fY,{value:t.serial_number})]})}),e?.wired_network)s.push({label:i("printers.networkLabel","Network"),value:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(LI,{className:"w-4 h-4 text-bambu-green"}),r.jsx("span",{className:"text-bambu-green",children:i("printers.connection.ethernet","Ethernet")})]})});else if(e?.wifi_signal!=null){const o=nte(e.wifi_signal);s.push({label:i("printers.wifiSignalLabel"),value:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(pJ,{className:`w-4 h-4 ${o.color}`}),r.jsx("span",{className:o.color,children:i(o.labelKey)}),r.jsxs("span",{className:"text-bambu-gray text-xs",children:["(",e.wifi_signal," dBm)"]})]})})}return s.push({label:i("printers.firmware"),value:e?.firmware_version??"—"}),e?.developer_mode!=null&&s.push({label:i("printers.developerMode"),value:r.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${e.developer_mode?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:e.developer_mode?i("printers.enabled"):i("printers.disabled")})}),s.push({label:i("printers.nozzleCount"),value:t.nozzle_count}),s.push({label:i("printers.autoArchive"),value:r.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${t.auto_archive?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:t.auto_archive?i("printers.enabled"):i("printers.disabled")})}),a!=null&&a>0&&s.push({label:i("printers.totalPrintHours"),value:`${Math.round(a)}h`}),t.location&&s.push({label:i("printers.sort.location"),value:t.location}),s.push({label:i("printers.addedOn"),value:qg(t.created_at)}),r.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",role:"dialog","aria-modal":"true",onClick:n,children:r.jsx(Tt,{className:"w-full max-w-md",onClick:o=>o.stopPropagation(),children:r.jsxs(jt,{children:[r.jsxs("div",{className:"flex items-center justify-between mb-4",children:[r.jsx("h2",{className:"text-lg font-semibold text-white",children:t.name}),r.jsx("button",{onClick:n,className:"p-1 hover:bg-bambu-dark rounded flex-shrink-0",children:r.jsx(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),r.jsx("div",{className:"flex justify-center mb-4",children:r.jsx("img",{src:rte(t.model),alt:t.model??t.name,className:"h-24 object-contain"})}),r.jsx("div",{className:"space-y-0",children:s.map((o,l)=>r.jsxs("div",{className:"flex items-center justify-between gap-4 py-2.5 border-b border-bambu-dark-tertiary last:border-0",children:[r.jsx("span",{className:"text-sm text-bambu-gray whitespace-nowrap",children:o.label}),r.jsx("span",{className:"text-sm text-white text-right",children:o.value})]},l))})]})})})}function $9e(t){if(!t||t.length<6)return!1;const e=parseInt(t.slice(0,2),16),a=parseInt(t.slice(2,4),16),n=parseInt(t.slice(4,6),16);return(.299*e+.587*a+.114*n)/255>.6}function AF({trayColor:t,trayType:e,isEmpty:a,emptyKind:n,slotNumber:i}){const s=n==="reset"?"#3d3d3d":"#666";return r.jsx("div",{className:"w-3.5 h-3.5 rounded-full mx-auto mb-0.5 border-2 flex items-center justify-center",style:{backgroundColor:t?`#${t}`:e?"#333":"transparent",borderColor:a?s:"rgba(255,255,255,0.1)",borderStyle:a?"dashed":"solid"},children:r.jsx("span",{className:"text-[6px] font-bold leading-none select-none",style:{color:t&&$9e(t)?"#000":"#fff"},children:i})})}const gY=240,bY=320;function jF(t){return(t??.02).toFixed(3)}function xY({side:t}){const{mode:e}=gb(),a=e==="dark"?"#1a4d2e":"#e7f5e9";return r.jsx("span",{className:"inline-flex items-center justify-center w-4 h-4 text-[10px] font-bold rounded",style:{backgroundColor:a,color:"#00ae42"},children:t})}function Rse(t,e){if(!t)return"";if(t.includes("hardened"))return e("printers.nozzleHardenedSteel");if(t.includes("stainless"))return e("printers.nozzleStainlessSteel");if(t.includes("tungsten"))return e("printers.nozzleTungstenCarbide");if(t.length>=4){const a=t.slice(2,4);if(a==="00")return e("printers.nozzleStainlessSteel");if(a==="01")return e("printers.nozzleHardenedSteel");if(a==="05")return e("printers.nozzleTungstenCarbide")}return t==="00"?e("printers.nozzleStainlessSteel"):t==="01"?e("printers.nozzleHardenedSteel"):t==="05"?e("printers.nozzleTungstenCarbide"):t.startsWith("H")?e("printers.nozzleHardenedSteel"):t}function zse(t,e){return t?t.startsWith("HH")?e("printers.nozzleHighFlow"):t.startsWith("HS")?e("printers.nozzleStandardFlow"):"":""}function Ise({slot:t,index:e,activeStatus:a,filamentName:n,children:i}){const{t:s}=wt(),[o,l]=y.useState(!1),[c,d]=y.useState("top"),u=y.useRef(null),m=y.useRef(null),p=y.useRef(null),f=!t.nozzle_diameter&&!t.nozzle_type,g=t.stat===1;y.useEffect(()=>{if(o&&u.current&&m.current){const C=u.current.getBoundingClientRect(),N=m.current.offsetHeight,j=C.top-56,D=window.innerHeight-C.bottom;jj?d("bottom"):d("top")}},[o]);const v=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>l(!0),80)},b=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>l(!1),100)};y.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const x=WI(t.filament_color),S=Rse(t.nozzle_type,s),k=zse(t.nozzle_type,s);return r.jsxs("div",{ref:u,className:"relative",onMouseEnter:v,onMouseLeave:b,children:[i,o&&r.jsxs("div",{ref:m,className:` absolute left-1/2 -translate-x-1/2 z-50 ${c==="top"?"bottom-full mb-2":"top-full mt-2"} diff --git a/static/index.html b/static/index.html index bbdc7d0ba..b7a1768f1 100644 --- a/static/index.html +++ b/static/index.html @@ -26,7 +26,7 @@ - +