From 10ad9267e1090825fc62df85f966ffff58af65d2 Mon Sep 17 00:00:00 2001 From: maziggy Date: Thu, 2 Jul 2026 09:39:56 +0200 Subject: [PATCH] fix(queue): edit modal shows printer/model selection for model-assigned items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Editing a queue item that was created with "Any of model X" left the printer selection area completely blank — the assignmentMode was initialised to 'model' from queueItem.target_model, but the three model-mode props (onAssignmentModeChange, onTargetModelChange, onTargetLocationChange) were gated behind !isEditing. That flipped modelAssignmentAvailable to false in PrinterSelector and hid the mode toggle, the model dropdown, AND the location filter; combined with the assignmentMode === 'printer' gate on the printer list, the whole selector rendered empty. Users hit this whenever they queued something to "Any of model X" and then wanted to change the target model / location — the only workaround was delete + re-queue. Fix: drop the !isEditing gate on all three PrinterSelector props. The submit path already handles both flavours (target_model+target_location with printer_id=null vs. printer_id with the target fields nulled), so un-gating the UI just surfaces the machinery that was already there. Edit is still only offered on pending items, so the mode-flip can't race an in-flight dispatch. --- CHANGELOG.md | 2 ++ frontend/src/components/PrintModal/index.tsx | 6 +++--- static/assets/{index-DxxKVIUT.js => index-BwslAeY1.js} | 2 +- static/index.html | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) rename static/assets/{index-DxxKVIUT.js => index-BwslAeY1.js} (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44e88ba4c..d8bd82cf2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to Bambuddy will be documented in this file. ## [0.2.5b2] - Unreleased ### Fixed +- **Editing a queue item assigned to "Any of model X" left the printer selection area blank** — `PrintModal` initialises `assignmentMode` from `queueItem.target_model`: items created with a specific printer got `'printer'` mode (renders the printer list), items created with model-based assignment got `'model'` mode. But `PrintModal/index.tsx:1102-1106` was passing `onAssignmentModeChange={!isEditing ? setAssignmentMode : undefined}` (same for `onTargetModelChange` / `onTargetLocationChange`), which flipped `modelAssignmentAvailable` to `false` in `PrinterSelector` and hid every model-mode control — the mode toggle at `PrinterSelector.tsx:390`, the model dropdown at `:431`, the location filter at `:459`. Combined with the `assignmentMode === 'printer'` gate on the printer list at `:519`, edit-mode for a model-assigned item rendered an empty container. Users couldn't retarget the item or even see what model it was assigned to; the only way to change it was delete + re-queue. **Fix.** Drop the `!isEditing` gate on all three props — the underlying submit path already handles both directions cleanly (`printer_id: null, target_model, target_location` when saving in model mode at `index.tsx:788-802`; `printer_id, target_model: null, target_location: null` when saving in printer mode at `:844-857`), so un-gating the UI just surfaces the machinery that was already there. Users can now (a) see the current target model + location on a model-assigned item, (b) change the target model or narrow / widen the location filter, and (c) flip the item between "Specific Printer" and "Any of Model" without deleting + re-queueing. Edit is only offered on `pending` items (`QueuePage.tsx:2137`), so there's no race with an in-flight dispatch when the assignment mode flips. **Scope.** Frontend-only, one-hunk change to the props on the existing `PrinterSelector` invocation. No new i18n key (the model / location / mode strings already existed for create mode). No backend change. Existing 61/61 `PrintModal.test.tsx` cases green — the tests that pass `initialSelectedPrinterIds={[1]}` for the create-with-printer flow are unaffected because the `!initialSelectedPrinterIds?.length` gate at `index.tsx:1088` still hides the whole `PrinterSelector` for the post-upload dispatch dialog. + - **Finish photo captures the wrong plate on A1 / A1 Mini when SwapMod plate-swap End G-code is injected (#1867, reporter @qoatzelcoat)** — The "Print Complete" snapshot arrived after the user's SwapMod plate-swap moves had already ejected the printed part, so the notification always carried an image of the *swapped* (empty) plate. **Root cause.** The stage-22 ("Filament unloading") edge that normally fires the finish-photo pre-capture never fires on A1 Mini firmware (confirmed in the reporter's log: `FINISH PHOTO MOMENT (FINISH fallback) — stage-22 never fired; capturing at FINISH-state transition`). The fallback path in `bambu_mqtt.py` waits for `gcode_state → FINISH`, and Bambu Studio runs the user-defined End G-code *before* that state transition — so by the time the fallback captures, SwapMod has already moved the plate. **Fix.** Added a new `layer_num → total_layer_num` edge trigger inside `_parse_print_data` that fires the finish-photo moment the instant the last object layer completes, before any end G-code runs. Guarded by the existing `_was_running` / `_finish_photo_captured` one-shot so subsequent stage-22 and FINISH-state ticks become no-ops for the same print. Works on every Bambu variant (A1, A1 Mini, P1P/S, X1C, H2S/H2D) without model detection; on AMS printers the last-layer edge fires slightly before stage-22 would have, which also fixes SwapMod-style setups on those printers rather than only on the A1 family. Test coverage: `TestLastLayerFinishPhotoTrigger` in `backend/tests/unit/services/test_bambu_mqtt.py` (7 cases — fires on last layer, edge-only, skipped on stage-22 replay, skipped on the FINISH fallback, ignores `total=0` bootstrap frames, ignores non-running catch-up messages). ### Added diff --git a/frontend/src/components/PrintModal/index.tsx b/frontend/src/components/PrintModal/index.tsx index 71e26a24c..f5c992fd9 100644 --- a/frontend/src/components/PrintModal/index.tsx +++ b/frontend/src/components/PrintModal/index.tsx @@ -1099,11 +1099,11 @@ export function PrintModal({ onAutoConfigurePrinter={multiPrinterMapping.autoConfigurePrinter} onUpdatePrinterConfig={multiPrinterMapping.updatePrinterConfig} assignmentMode={assignmentMode} - onAssignmentModeChange={!isEditing ? setAssignmentMode : undefined} + onAssignmentModeChange={setAssignmentMode} targetModel={targetModel} - onTargetModelChange={!isEditing ? setTargetModel : undefined} + onTargetModelChange={setTargetModel} targetLocation={targetLocation} - onTargetLocationChange={!isEditing ? setTargetLocation : undefined} + onTargetLocationChange={setTargetLocation} slicedForModel={slicedForModel} /> )} diff --git a/static/assets/index-DxxKVIUT.js b/static/assets/index-BwslAeY1.js similarity index 99% rename from static/assets/index-DxxKVIUT.js rename to static/assets/index-BwslAeY1.js index 7c15e67fb..3885129b2 100644 --- a/static/assets/index-DxxKVIUT.js +++ b/static/assets/index-BwslAeY1.js @@ -8509,7 +8509,7 @@ void main() { border-r-[5px] border-r-transparent border-t-[5px] border-t-bambu-dark-tertiary `})]}),document.body)]})}function vU({isOpen:e,onClose:t,tagUid:n,trayUuid:r,printerId:i,amsId:a,trayId:o}){let{t:s}=W(),c=no(),{showToast:l}=Dd(),[u,d]=(0,y.useState)(``),f=r||n,{data:p,isLoading:m}=q({queryKey:[`unlinked-spools`],queryFn:Q.getUnlinkedSpools,enabled:e}),h=(0,y.useMemo)(()=>p?p.filter(e=>{if(!u)return!0;let t=u.toLowerCase();return e.filament_name&&e.filament_name.toLowerCase().includes(t)||e.filament_vendor&&e.filament_vendor.toLowerCase().includes(t)||e.filament_material&&e.filament_material.toLowerCase().includes(t)||String(e.id).includes(t)}):[],[p,u]),g=J({mutationFn:e=>Q.linkSpool(e,{spoolTag:f,printerId:i,amsId:a,trayId:o}),onSuccess:()=>{c.invalidateQueries({queryKey:[`unlinked-spools`]}),c.invalidateQueries({queryKey:[`linked-spools`]}),c.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),l(s(`spoolman.linkSuccess`),`success`),t()},onError:e=>{l(e.message||s(`spoolman.linkFailed`),`error`)}});return e?(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,K.jsxs)(`div`,{className:`relative bg-bambu-dark-secondary rounded-xl shadow-xl w-full max-w-md mx-4 max-h-[80vh] flex flex-col border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-white/10`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Vc,{className:`w-5 h-5 text-bambu-green`}),s(`spoolman.selectSpool`)]}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[`AMS `,a,` T`,o,` · Printer #`,i]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(Bu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 border-b border-white/10`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Ll,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:s(`inventory.searchSpools`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark rounded-lg border border-white/10 text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),(r||n)&&(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-2 font-mono truncate`,title:r||n,children:[`Tag: `,r||n]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 min-h-0`,children:m?(0,K.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):h.length===0?(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-8 text-sm`,children:s(`inventory.noSpoolsMatch`)}):h.map(e=>(0,K.jsxs)(`button`,{onClick:()=>g.mutate(e.id),disabled:g.isPending||!f,className:`w-full flex items-center gap-3 p-3 rounded-lg hover:bg-white/5 transition-colors text-left`,children:[(0,K.jsx)(`span`,{className:`w-6 h-6 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.filament_color_hex?`#${e.filament_color_hex}`:`#808080`}}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm text-white font-medium truncate`,children:e.filament_name||s(`spoolman.spoolId`)}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray truncate`,children:[e.filament_vendor?`${e.filament_vendor} · `:``,e.filament_material||`Unknown`,` · #`,e.id]})]}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.remaining_weight==null?`—`:`${Math.round(e.remaining_weight)}g`})]},e.id))}),(0,K.jsx)(`div`,{className:`p-4 border-t border-white/10 flex justify-end`,children:(0,K.jsx)($,{variant:`ghost`,onClick:t,children:s(`inventory.cancel`)||`Cancel`})})]})]}):null}function tke(e,t){if(!t)return!0;let n=t.toLowerCase();return String(e.id).includes(n)||e.material.toLowerCase().includes(n)||(e.brand?.toLowerCase().includes(n)??!1)||(e.color_name?.toLowerCase().includes(n)??!1)||(e.subtype?.toLowerCase().includes(n)??!1)||(e.note?.toLowerCase().includes(n)??!1)||(e.slicer_filament_name?.toLowerCase().includes(n)??!1)||(e.storage_location?.toLowerCase().includes(n)??!1)}function yU(e,t){return t?e.filter(e=>tke(e,t)):e}function bU({isOpen:e,onClose:t,printerId:n,amsId:r,trayId:i,trayInfo:a,spoolmanEnabled:o}){let{t:s}=W(),c=no(),{showToast:l}=Dd(),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null);(0,y.useEffect)(()=>{p(null),h(null)},[u]);let[g,_]=(0,y.useState)(``),[v,b]=(0,y.useState)(null),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(null);(0,y.useEffect)(()=>{e&&d(!1)},[e]);let{data:T,isLoading:E}=q({queryKey:[`inventory-spools`,`assign-modal`],queryFn:()=>Q.getSpools(!0),enabled:e&&!o}),{data:D}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),enabled:e}),{data:O}=q({queryKey:[`settings`],queryFn:()=>Q.getSettings(),enabled:e}),{data:k,isLoading:A}=q({queryKey:[`spoolman-inventory-spools`,`assign-modal`],queryFn:()=>Q.getSpoolmanInventorySpools(!1),enabled:e&&!!o}),{data:j}=q({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:e&&!!o}),M=(0,y.useMemo)(()=>j?new Set(j.filter(e=>!(e.printer_id===n&&e.ams_id===r&&e.tray_id===i)).map(e=>e.spoolman_spool_id)):new Set,[j,n,r,i]),N=()=>{Q.refreshPrinterStatus(n).catch(()=>{}),c.invalidateQueries({queryKey:[`printerStatus`,n]})},P=J({mutationFn:e=>Q.assignSpool({spool_id:e,printer_id:n,ams_id:r,tray_id:i}),onSuccess:e=>{c.setQueryData([`spool-assignments`],t=>{let a=(t||[]).filter(e=>!(e.printer_id===n&&e.ams_id===r&&e.tray_id===i));return a.push(e),a}),c.invalidateQueries({queryKey:[`spool-assignments`]}),N(),l(s(e.pending_config?`inventory.assignPendingInsert`:`inventory.assignSuccess`),`success`),S(!1),b(null),w(null),t()},onError:e=>{l(`${s(`inventory.assignFailed`)}: ${e.message}`,`error`)}}),F=J({mutationFn:e=>Q.assignSpoolmanSlot({spoolman_spool_id:e,printer_id:n,ams_id:r,tray_id:i}),onSuccess:()=>{c.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),c.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),N(),l(s(`inventory.assignSuccess`),`success`),t()},onError:e=>{l(`${s(`inventory.assignFailed`)}: ${e.message}`,`error`)}}),I=e=>(e??``).trim().toUpperCase(),L=(e,t)=>{let n=I(e),r=I(t);return!n||!r?`none`:n===r?`exact`:r.includes(n)||n.includes(r)?`partial`:`none`},R=e=>e.split(`@`)[0].trim(),z=(e,t)=>{let n=R(I(e)),r=R(I(t));return!n||!r?!1:n===r};if(!e)return null;let B=new Set((D||[]).filter(e=>!(e.printer_id===n&&e.ams_id===r&&e.tray_id===i)).map(e=>e.spool_id)),V=T?.filter(e=>!e.archived_at&&(u||!B.has(e.id))),ee=V;if(!u){let e=R(I(a?.profile)),t=I(a?.material||a?.type);(e||t)&&(ee=ee?.filter(n=>{let r=R(I(n.slicer_filament_name||n.slicer_filament)),i=I(n.material);return e&&r&&r===e?!0:t&&i?i===t||t.includes(i)||i.includes(t):!r&&!i}))}g&&ee&&(ee=yU(ee,g));let te=()=>{if(m!==null){F.mutate(m);return}if(!f)return;let e=T?.find(e=>e.id===f);if(!e){l(s(`inventory.assignFailed`),`error`);return}if(!O?.disable_filament_warnings&&a){let t=a.material||a.type,n=L(e.material,t),r=e.slicer_filament_name||e.slicer_filament,i=a.profile||a.type,o=z(r,i);if(n!==`exact`){let a;a=n===`none`&&!o?`material_profile`:n===`partial`&&!o?`partial_profile`:n===`none`?`material`:`partial`,b(f),w({type:a,spoolMaterial:e.material||``,trayMaterial:t||``,spoolProfile:r||void 0,trayProfile:i||void 0}),S(!0);return}}P.mutate(f)},ne=()=>{v&&(P.mutate(v),S(!1),b(null))};return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-start sm:items-center justify-center p-4 overflow-y-auto`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-2xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] overflow-hidden flex flex-col my-auto`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(fl,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:s(`inventory.assignSpool`)})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(Bu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto`,children:[a&&(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:[s(`inventory.selectSpool`),`:`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a.color&&(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${a.color}`}}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:a.type||s(`ams.emptySlot`)}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,a.location,`)`]})]})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Ll,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:g,onChange:e=>_(e.target.value),placeholder:s(`inventory.searchSpools`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[!o&&(E?(0,K.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})}):ee&&ee.length>0?(0,K.jsx)(`div`,{className:`max-h-96 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2`,children:ee.map(e=>(0,K.jsxs)(`button`,{onClick:()=>{p(e.id),h(null)},title:e.note||void 0,className:`p-2.5 rounded-lg border text-left transition-colors ${f===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,K.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[e.rgba&&(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:ef(e.rgba)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:e.color_name||``})]}),e.label_weight&&(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[Math.max(0,Math.round(e.label_weight-e.weight_used)),` / `,e.label_weight,`g`]}),e.note&&(0,K.jsx)(`p`,{className:`text-[10px] text-bambu-gray/70 mt-1 truncate`,title:e.note,children:e.note})]},e.id))}):V&&V.length===0?(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(`p`,{children:s(`inventory.noAvailableSpools`)}),T&&(0,K.jsxs)(`p`,{className:`text-[10px] mt-2 opacity-60`,children:[T.length,` fetched · `,T.filter(e=>e.archived_at).length,` archived ·`,` `,T.filter(e=>B.has(e.id)).length,` assigned to other slots`]})]}):(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(`p`,{children:s(`inventory.noSpoolsMatch`)}),V&&(0,K.jsxs)(`p`,{className:`text-[10px] mt-2 opacity-60`,children:[V.length,` unassigned spools — `,V.length-(ee?.length??0),` filtered by tray match. Try "Show all spools".`]})]})),o&&(0,K.jsx)(K.Fragment,{children:A?(0,K.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,K.jsx)(X,{className:`w-5 h-5 text-bambu-green animate-spin`})}):k&&k.filter(e=>!e.archived_at&&!M.has(e.id)).length>0?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide pt-1`,children:s(`inventory.spoolmanSpools`)}),(0,K.jsx)(`div`,{className:`max-h-64 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2`,children:yU(k.filter(e=>!e.archived_at&&!M.has(e.id)),g).map(e=>(0,K.jsxs)(`button`,{onClick:()=>{h(e.id),p(null)},title:e.note||void 0,className:`p-2.5 rounded-lg border text-left transition-colors ${m===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,K.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[e.rgba&&(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:ef(e.rgba)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:e.color_name||``})]}),e.label_weight&&(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[Math.max(0,Math.round(e.label_weight-e.weight_used)),` / `,e.label_weight,`g`]}),e.note&&(0,K.jsx)(`p`,{className:`text-[10px] text-bambu-gray/70 mt-1 truncate`,title:e.note,children:e.note})]},`spoolman-${e.id}`))})]}):null})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between items-center p-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{id:`disable-filtering-toggle`,type:`checkbox`,checked:u,onChange:()=>d(e=>!e),className:`accent-bambu-green w-4 h-4 rounded focus:ring-0 border-bambu-dark-tertiary`}),(0,K.jsx)(`label`,{htmlFor:`disable-filtering-toggle`,className:`text-xs text-bambu-gray select-none cursor-pointer`,children:s(`inventory.showAllSpools`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,children:s(`common.cancel`)}),(0,K.jsx)($,{onClick:te,disabled:!f&&m===null||P.isPending||F.isPending,children:P.isPending||F.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),s(`inventory.assigning`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(fl,{className:`w-4 h-4`}),s(`inventory.assignSpool`)]})})]})]}),P.isError&&(0,K.jsx)(`div`,{className:`mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400`,children:P.error.message})]})]}),x&&a&&f&&C&&(()=>{let e=``;return C.type===`material`?e=s(`inventory.assignMismatchMessage`,{spoolMaterial:C.spoolMaterial,trayMaterial:C.trayMaterial,location:a.location}):C.type===`partial`?e=s(`inventory.assignPartialMismatchMessage`,{spoolMaterial:C.spoolMaterial,trayMaterial:C.trayMaterial,location:a.location}):C.type===`material_profile`?e=`${s(`inventory.assignMismatchMessage`,{spoolMaterial:C.spoolMaterial,trayMaterial:C.trayMaterial,location:a.location})}\n\n${s(`inventory.assignProfileMismatchMessage`,{spoolProfile:C.spoolProfile||s(`common.unknown`),trayProfile:C.trayProfile||s(`common.unknown`),location:a.location})}`:C.type===`partial_profile`&&(e=`${s(`inventory.assignPartialMismatchMessage`,{spoolMaterial:C.spoolMaterial,trayMaterial:C.trayMaterial,location:a.location})}\n\n${s(`inventory.assignProfileMismatchMessage`,{spoolProfile:C.spoolProfile||s(`common.unknown`),trayProfile:C.trayProfile||s(`common.unknown`),location:a.location})}`),e=`${e}\n\n${s(`inventory.assignReconfigureNote`)}`,(0,K.jsx)(Id,{title:s(`inventory.assignMismatchTitle`),message:e,confirmText:s(`inventory.assignMismatchConfirm`),variant:`warning`,overlayZIndex:`z-[110]`,isLoading:P.isPending,onConfirm:ne,onCancel:()=>{P.isPending||(S(!1),b(null),w(null))}})})()]})}var nke={bambuModelByShortCode:{}},xU={"A1 MINI":[`A1M`]};function SU(e,t){let n=e.toUpperCase(),r=t.toUpperCase();if(n===r)return!0;let i=xU[r];if(i&&i.includes(n))return!0;let a=xU[n];return!!(a&&a.includes(r))}function rke(e){let t={};for(let[n,r]of Object.entries(e))r in t||(t[r]=n.replace(/^Bambu Lab\s+/,``));return t}function CU(e={}){return{bambuModelByShortCode:rke(e)}}function wU(e){return e.replace(/\s+/g,``).toLowerCase()}var ike=`0.4`;function TU(e){let t=e.match(/^(.*?)\s+([\d.]+)\s*nozzle\s*$/i);return t?{stripped:t[1].trim(),nozzle:t[2]}:{stripped:e.trim(),nozzle:null}}function ake(e){let t=e.indexOf(`@BBL `);if(t<0)return null;let{stripped:n,nozzle:r}=TU(e.slice(t+5).trim());return n?{token:n,nozzle:r}:null}function oke(e){let t=e.match(/^Bambu Lab\s+(.+)$/i);if(!t)return null;let{stripped:n,nozzle:r}=TU(t[1]);return n?{model:n,nozzle:r}:null}function ske(e,t,n){let r=ake(e);if(!r)return`unknown`;let i=n[r.token]??r.token,a=oke(t);return a?wU(a.model)!==wU(i)&&!SU(r.token,a.model)||a.nozzle!==null&&(r.nozzle??ike)!==a.nozzle?`mismatch`:`match`:`unknown`}function EU(e,t,n,r){if(!n)return`unknown`;let i=e.compatible_printers;return i&&i.length>0?i.includes(n)?`match`:`mismatch`:ske(e.name,n,r.bambuModelByShortCode)}var DU=[`PLA`,`PETG`,`ABS`,`TPU`,`ASA`,`PC`,`PA`,`PVA`,`HIPS`,`PA-CF`,`PETG-CF`,`PLA-CF`],OU=[`Bambu`,`PolyLite`,`PolyTerra`,`eSUN`,`Overture`,`Fiberon`,`SUNLU`,`Inland`,`Hatchbox`,`Generic`],kU=`Basic.Matte.Silk.Silk+.Tough.Tough+.HF.High Flow.Engineering.CF.GF.Galaxy.Glow.Marble.Metal.Rainbow.Sparkle.Wood.Translucent.Transparent.Clear.Lite.Pro.Plus.Max.Super.Ultra.Flex.Soft.Hard.Strong.Impact.Heat Resistant.UV Resistant.ESD.Conductive.Magnetic.Gradient.Dual Color.Tri Color.Multicolor`.split(`.`),AU=[{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`}],cke=[{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`}],jU=[...AU,...cke],MU=`bambuddy-recent-colors`,lke=[{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 NU(e){let t=e.replace(/@.*$/,``).trim();t=t.replace(/\(Custom\)/i,``).trim(),t=t.replace(/^[#*]+\s*/,``).trim();let n=`PLA-CF.PETG-CF.ABS-GF.ASA-CF.PA-CF.PAHT-CF.PA6-CF.PA6-GF.PPA-CF.PPA-GF.PET-CF.PPS-CF.PC-CF.PC-ABS.ABS-GF.PCTG.PETG.PLA.ABS.ASA.PC.PA.TPU.PVA.HIPS.BVOH.PPS.PEEK.PEI`.split(`.`),r=``,i=-1;for(let e of n){let n=t.toUpperCase().indexOf(e.toUpperCase());if(n!==-1){r=e,i=n;break}}let a=``;i>0&&(a=t.substring(0,i).trim(),a=a.replace(/[-_\s]+$/,``));let o=``;i!==-1&&r&&(o=t.substring(i+r.length).trim(),o=o.replace(/^[-_\s]+/,``));let s=``;for(let e of kU)if(o.toLowerCase().includes(e.toLowerCase())){s=e;break}if(!s&&a)for(let e of kU){let t=RegExp(`\\s+${e}$`,`i`);if(t.test(a)){s=e,a=a.replace(t,``).trim();break}}return{brand:a,material:r,variant:s}}function PU(e,t){let n=new Set(OU);for(let t of e){let{brand:e}=NU(t.name);e&&e.length>1&&n.add(e)}if(t)for(let e of t)if(e.filament_vendor&&e.filament_vendor.length>1)n.add(e.filament_vendor);else{let{brand:t}=NU(e.name);t&&t.length>1&&n.add(t)}return Array.from(n).sort((e,t)=>e.localeCompare(t))}function uke(e){let t=e.filter(e=>e.preset_type===`filament`);return t.length===0?[]:t.map(e=>{let t=String(e.id),n=e.filament_type||t,r=Array.from(new Set([t,n]));return{code:t,name:e.name,displayName:e.name,isCustom:!1,allCodes:r}}).sort((e,t)=>e.displayName.localeCompare(t.displayName))}function FU(e,t,n,r){let i=[],a=[],o=new Set;for(let n of e)if(n.is_custom){let e=n.name.toUpperCase();(t.size===0||Array.from(t).some(t=>e.includes(t))||!e.includes(`@`))&&(i.push({code:n.setting_id,name:n.name,displayName:`${n.name} (Custom)`,isCustom:!0,allCodes:[n.setting_id]}),o.add(n.setting_id))}else a.push({code:n.setting_id,name:n.name,displayName:n.name,isCustom:!1,allCodes:[n.setting_id]}),o.add(n.setting_id);let s=n&&n.length>0?uke(n):[],c=[];if(r&&r.length>0)for(let e of r){let t=e.filament_id.startsWith(`GF`)?`GFS`+e.filament_id.slice(2):e.filament_id;o.has(e.filament_id)||o.has(t)||c.push({code:e.filament_id,name:e.name,displayName:e.name,isCustom:!1,allCodes:[e.filament_id,t]})}let l=[...i,...a,...s,...c];return l.length===0?lke:l.sort((e,t)=>e.displayName.localeCompare(t.displayName))}function IU(e,t){if(!e)return;let n=t.find(t=>t.code===e);if(n||=t.find(t=>t.allCodes.includes(e)),!n){let r=e.toLowerCase();n=t.find(e=>e.code.toLowerCase()===r||e.allCodes.some(e=>e.toLowerCase()===r))}return n}function LU(){try{let e=localStorage.getItem(MU);if(e)return JSON.parse(e)}catch{}return[]}function RU(e,t){let n=[e,...t.filter(t=>t.hex.toUpperCase()!==e.hex.toUpperCase())].slice(0,8);try{localStorage.setItem(MU,JSON.stringify(n))}catch{}return n}function zU(e){if(!e)return``;let t=e.split(`_`)[0];return/^GFS/i.test(t)&&(t=t.slice(0,2)+t.slice(3)),t.toUpperCase()}function BU(e){return!!e&&/^GF[A-Z]99$/i.test(e)}function VU(e,t){if(!t.material)return!1;let n=zU(t.slicer_filament),r=zU(e.filament_id);if(n&&r&&n===r&&!BU(r))return!0;let i=(e.name||``).replace(/^High Flow[_\s]+/i,``).replace(/^Standard[_\s]+/i,``).replace(/^HF[_\s]+/i,``).replace(/^S[_\s]+/i,``).trim(),a=NU(i);return!(a.material.toUpperCase()!==t.material.toUpperCase()||t.brand&&!(a.brand.toLowerCase().includes(t.brand.toLowerCase())||t.brand.toLowerCase().includes(a.brand.toLowerCase()))||t.subtype&&!(a.variant.toLowerCase().includes(t.subtype.toLowerCase())||t.subtype.toLowerCase().includes(a.variant.toLowerCase())||i.toLowerCase().includes(t.subtype.toLowerCase())))}function HU(e){let t=e.includes(`_`)?e.split(`_`)[0]:e;return t.startsWith(`GFS`)?`GF`+t.slice(3):(t.startsWith(`PFUS`)||t.startsWith(`PFSP`),t)}var UU=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`NYLON`,`PVA`,`HIPS`,`PP`,`PET`];function WU(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase(),r=n.match(/\bSUPPORT\s+FOR\s+/);if(r){let e=n.slice(r.index+r[0].length);for(let n of UU)if(RegExp(`\\b${n}\\b`).test(e))return{material:n,brand:t.slice(0,r.index).trim(),variant:`Support`}}for(let e of UU){let r=RegExp(`\\b${e}\\b`,`i`);if(r.test(n)){let n=t.split(r);return{material:e,brand:n[0]?.trim()||``,variant:n[1]?.trim()||``}}}let i=t.split(/\s+/);return i.length>=2?{material:i[1],brand:i[0],variant:i.slice(2).join(` `)}:{material:t,brand:``,variant:``}}function dke(e){return!e.startsWith(`GF`)&&!e.startsWith(`P1`)}var fke={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`},GU=[{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`}],KU=[{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 qU(e){return fke[e.toLowerCase().trim()]||null}function pke(e){let t=e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`).replace(/\s+/g,`\\s+`);return RegExp(`\\b${t}\\b`,`i`)}function JU(e,t){let n=e.indexOf(`@`);if(n>=0){let r=e.slice(n+1).trim(),i=r.match(/^BBL\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);if(i)return i[1].trim();let a=r.match(/^Bambu Lab\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);if(a){let e=a[1].trim(),n=`Bambu Lab ${e}`;if(t[n])return t[n];let r=n.toLowerCase();for(let[e,n]of Object.entries(t))if(e.toLowerCase()===r)return n;return e}}let r=[],i=new Set;for(let[e,n]of Object.entries(t)){let t=e.replace(/^Bambu Lab\s+/,``),a=t.toLowerCase();i.has(a)||(r.push({token:t,short:n}),i.add(a));let o=n.toLowerCase();i.has(o)||(r.push({token:n,short:n}),i.add(o))}r.sort((e,t)=>t.token.length-e.token.length);for(let{token:t,short:n}of r)if(pke(t).test(e))return n;return null}function YU({isOpen:e,onClose:t,printerId:n,slotInfo:r,nozzleDiameter:i=`0.4`,printerModel:a,onSuccess:o,fullScreen:s}){let{t:c}=W(),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),w=(0,y.useRef)(``),{data:T,isLoading:E,isError:D}=q({queryKey:[`cloudSettings`],queryFn:()=>Q.getCloudSettings(),enabled:e,retry:!1}),{data:O}=q({queryKey:[`orcaCloudProfilesForAmsSlot`],queryFn:()=>Q.orcaCloudListProfiles(),enabled:e,retry:!1}),{data:k,isLoading:A}=q({queryKey:[`localPresets`],queryFn:()=>Q.getLocalPresets(),enabled:e}),{data:j,isLoading:M}=q({queryKey:[`builtinFilaments`],queryFn:()=>Q.getBuiltinFilaments(),enabled:e,staleTime:1/0}),{data:N,isLoading:P}=q({queryKey:[`kprofiles`,n,i],queryFn:()=>Q.getKProfiles(n,i),enabled:e&&!!n}),{data:F}=q({queryKey:[`colorCatalog`],queryFn:()=>Q.getColorCatalog(),enabled:e,staleTime:1/0}),{data:I}=q({queryKey:[`slicerPrinterModels`],queryFn:Q.getSlicerPrinterModels,enabled:e,staleTime:1/0}),L=(0,y.useMemo)(()=>CU(I??{}),[I]),R=(0,y.useMemo)(()=>{if(!a||!I)return null;for(let[e,t]of Object.entries(I))if(t===a)return`${e.startsWith(`Bambu Lab `)?e:`Bambu Lab ${e}`} ${i} nozzle`;return null},[a,I,i]),z=J({mutationFn:async()=>{if(!l)throw Error(`No filament preset selected`);let e=l.startsWith(`local_`),t=l.startsWith(`builtin_`),a=l.startsWith(`orca_`)?l.replace(`orca_`,``):l,o=!e&&!t?O?.filament.find(e=>e.setting_id===a):void 0,s=!!o,c=o??null,u=e?parseInt(l.replace(`local_`,``),10):null,f=t?l.replace(`builtin_`,``):null,m=e?k?.filament.find(e=>e.id===u):null,h=t?j?.find(e=>e.filament_id===f):null,g=!e&&!t&&!s?T?.filament.find(e=>e.setting_id===l):null;if(!e&&!t&&!s&&!g)throw Error(`Selected preset not found`);if(e&&!m)throw Error(`Selected local preset not found`);if(t&&!h)throw Error(`Selected builtin preset not found`);if(s&&!c)throw Error(`Selected Orca Cloud preset not found`);let _=e?m.name:t?h.name:s?c.name:g.name,v=WU(_),y=d?.slot_id??-1,b=p||r.trayColor?.slice(0,6)||`FFFFFF`,x=_.replace(/@.+$/,``).trim(),S,C,w=v.material.toUpperCase(),E={PLA:`GFL99`,"PLA-CF":`GFL98`,"PLA SILK":`GFL96`,"PLA HIGH SPEED":`GFL95`,PETG:`GFG99`,"PETG HF":`GFG96`,"PETG-CF":`GFG98`,PCTG:`GFG97`,ABS:`GFB99`,ASA:`GFB98`,PC:`GFC99`,PA:`GFN99`,"PA-CF":`GFN98`,NYLON:`GFN99`,TPU:`GFU99`,PVA:`GFS99`,HIPS:`GFS98`,PE:`GFP99`,PP:`GFP97`};if(e){let e=(UU.includes(w)?w:m?.filament_type||v.material||``).toUpperCase();S=E[e]||E[e.replace(/[-\s]?CF$/,``)]||E[e.replace(/\+$/,``)]||E[e.split(/[-\s]/)[0]]||``,C=``}else if(s){let e=(UU.includes(w)?w:v.material||``).toUpperCase();S=E[e]||E[e.replace(/[-\s]?CF$/,``)]||E[e.replace(/\+$/,``)]||E[e.split(/[-\s]/)[0]]||``,C=``}else if(t)S=f,C=``;else if(S=HU(l),C=l,!l.startsWith(`GFS`))try{let e=await Q.getCloudSettingDetail(l);e.filament_id&&(S=e.filament_id)}catch(e){console.warn(`Failed to fetch preset detail for filament_id:`,e)}let D=e&&m?.nozzle_temp_min?m.nozzle_temp_min:190,A=e&&m?.nozzle_temp_max?m.nozzle_temp_max:230;if(!e||t||s||!m?.nozzle_temp_min&&!m?.nozzle_temp_max){let t=(e?UU.includes(w)?w:m?.filament_type||v.material||``:v.material).toUpperCase();t.includes(`PLA`)?(D=190,A=230):t.includes(`PETG`)?(D=220,A=260):t.includes(`ABS`)||t.includes(`ASA`)?(D=240,A=280):t.includes(`TPU`)?(D=200,A=240):t===`PCTG`?(D=220,A=260):t.includes(`PC`)?(D=260,A=300):(t.includes(`PA`)||t.includes(`NYLON`))&&(D=250,A=290)}let M=d?.k_value?parseFloat(d.k_value):0,N=e?UU.includes(w)?w:m?.filament_type||v.material||`PLA`:s&&UU.includes(w)?w:v.material||`PLA`,P=await Q.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:S,tray_type:N,tray_sub_brands:x,tray_color:b+`FF`,nozzle_temp_min:D,nozzle_temp_max:A,cali_idx:y,nozzle_diameter:i,setting_id:C,kprofile_filament_id:d?.filament_id,kprofile_setting_id:d?.setting_id||void 0,k_value:M}),F=e?`local_${u}`:t?`builtin_${f}`:l,I=e?`local`:t?`builtin`:s?`orca_cloud`:`cloud`;try{await Q.saveSlotPreset(n,r.amsId,r.trayId,F,x,I)}catch(e){console.warn(`Failed to save slot preset mapping:`,e)}return P},onSuccess:()=>{x(!0),o?.(),setTimeout(()=>{x(!1),t()},1500)}}),B=J({mutationFn:async()=>Q.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{x(!0),o?.(),setTimeout(()=>{x(!1),t()},1500)}}),V=(0,y.useMemo)(()=>{let e=_.toLowerCase(),t=[],n=new Set,i=r.savedPresetId,o=r.trayInfoIdx;if(O?.filament)for(let r of O.filament){let i=`orca_${r.setting_id}`;if(n.add(r.setting_id),n.add(i),!(e&&!r.name.toLowerCase().includes(e))){if(a){let e=JU(r.name,I??{});if(e&&!SU(e,a))continue}t.push({id:i,name:r.name,source:`orca_cloud`,isUser:!0})}}if(T?.filament)for(let r of T.filament){if(n.has(r.setting_id))continue;n.add(r.setting_id);let s=i===r.setting_id||o&&(r.setting_id===o||HU(r.setting_id)===o);if(!(e&&!r.name.toLowerCase().includes(e))){if(!s&&a){let e=JU(r.name,I??{});if(e&&!SU(e,a))continue}t.push({id:r.setting_id,name:r.name,source:`cloud`,isUser:dke(r.setting_id)})}}if(k?.filament){let n=r.savedPresetId;for(let r of k.filament){let i=`local_${r.id}`;if(!(e&&!r.name.toLowerCase().includes(e))){if(n!==i&&R){let e=null;if(r.compatible_printers)try{let t=JSON.parse(r.compatible_printers);Array.isArray(t)&&(e=t.filter(e=>typeof e==`string`))}catch{e=null}if(EU({name:r.name,compatible_printers:e},`filament`,R,L)===`mismatch`)continue}t.push({id:i,name:r.name,source:`local`,isUser:!1})}}}if(j)for(let r of j){if(n.has(r.filament_id))continue;let i=r.filament_id.startsWith(`GF`)?`GFS`+r.filament_id.slice(2):r.filament_id;n.has(i)||(!e||r.name.toLowerCase().includes(e))&&t.push({id:`builtin_${r.filament_id}`,name:r.name,source:`builtin`,isUser:!1})}return t.sort((e,t)=>{let n={local:0,orca_cloud:1,cloud:2,builtin:3};return e.source===t.source?e.isUser&&!t.isUser?-1:!e.isUser&&t.isUser?1:e.name.localeCompare(t.name):n[e.source]-n[t.source]})},[O?.filament,T?.filament,k?.filament,j,_,a,r.savedPresetId,r.trayInfoIdx,R,L,I]),ee=(0,y.useMemo)(()=>{if(!l)return null;let e=null,t=``;if(l.startsWith(`local_`)){let t=parseInt(l.replace(`local_`,``),10);e=k?.filament.find(e=>e.id===t)?.name||null}else if(l.startsWith(`builtin_`)){let n=l.replace(`builtin_`,``);e=j?.find(e=>e.filament_id===n)?.name||null,t=zU(n)}else{let n=l.startsWith(`orca_`)?l.replace(`orca_`,``):l,r=O?.filament.find(e=>e.setting_id===n);if(r)e=r.name;else if(T?.filament){let n=T.filament.find(e=>e.setting_id===l);e=n?.name||null,n&&(t=zU(n.setting_id))}}if(!e)return null;let n=e.replace(/@.+$/,``).trim();n.startsWith(`# `)&&(n=n.slice(2).trim());let r=WU(n);return{fullName:n,material:r.material,brand:r.brand,filamentId:t}},[l,T?.filament,k?.filament,j,O?.filament]),te=ee?.fullName||``,ne=(0,y.useMemo)(()=>{if(!F||!ee)return[];let{fullName:e,brand:t}=ee,n=e.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,``).trim();return F.filter(e=>{let r=(e.material||``).toUpperCase(),i=e.manufacturer.toUpperCase();if(!(r===n.toUpperCase()||r.includes(n.toUpperCase())||n.toUpperCase().includes(r)))return!1;if(t){let e=t.toUpperCase();if(!i.includes(e)&&!e.includes(i))return!1}return!0})},[F,ee]),re=(0,y.useMemo)(()=>{if(!N?.profiles)return[];if(!ee){let e=r.caliIdx;if(e!=null&&e>0){let t=N.profiles.find(t=>t.slot_id===e&&(r.extruderId===void 0||t.extruder_id===r.extruderId));if(t)return[t]}return[]}let{fullName:e,material:t,brand:n,filamentId:i}=ee,a=e.toUpperCase(),o=t.toUpperCase(),s=n.toUpperCase(),c=i;if(!o||o.length<2)return[];let l=N.profiles.filter(e=>{if(c){let t=zU(e.filament_id);if(t&&t===c&&!BU(t))return!0}let t=e.name.toUpperCase();if(s)return!(!t.includes(s)||!t.includes(o));if(t.includes(a)||t.includes(o))return!0;let n={NYLON:[`PA`,`PA-CF`,`PA6`],PA:[`NYLON`]}[o]||[];for(let e of n)if(t.includes(e))return!0;return!1}),u=new Map;for(let e of l){let t=`${e.name}|${e.k_value}`,n=u.get(t);n?r.extruderId!==void 0&&e.extruder_id===r.extruderId&&n.extruder_id!==r.extruderId&&u.set(t,e):u.set(t,e)}let d=Array.from(u.values()),f=r.caliIdx;if(f!=null&&f>0&&!d.some(e=>e.slot_id===f)){let e=N.profiles.find(e=>e.slot_id===f&&(r.extruderId===void 0||e.extruder_id===r.extruderId));e&&d.unshift(e)}return d},[N?.profiles,ee,r.extruderId,r.caliIdx]);(0,y.useEffect)(()=>{if(e){if(r.savedPresetId)u(r.savedPresetId);else if(r.trayInfoIdx&&T?.filament){let e=T.filament.find(e=>e.setting_id===r.trayInfoIdx);e||=T.filament.find(e=>HU(e.setting_id)===r.trayInfoIdx),e&&u(e.setting_id)}else if(r.trayInfoIdx&&j?.length){let e=r.trayInfoIdx,t=j.find(t=>t.filament_id===e);t&&u(`builtin_${t.filament_id}`)}if(r.trayColor){let e=r.trayColor.slice(0,6);e&&m(e)}}else u(``),f(null),m(``),g(``),v(``),x(!1),w.current=``},[e,r.savedPresetId,r.trayInfoIdx,r.trayColor,T?.filament,j]),(0,y.useEffect)(()=>{if(re.length>0){if(r.caliIdx!=null&&r.caliIdx>0){let e=re.find(e=>e.slot_id===r.caliIdx);if(e){f(e);return}}f(re[0])}else f(null)},[l,re,r.caliIdx]);let ie=(0,y.useCallback)(e=>{e.key===`Escape`&&t()},[t]);(0,y.useEffect)(()=>{if(e)return document.addEventListener(`keydown`,ie),()=>document.removeEventListener(`keydown`,ie)},[e,ie]);let H=E&&!D||A||M||P;if((0,y.useEffect)(()=>{if(!H&&l&&l!==w.current){let e=requestAnimationFrame(()=>{let e=document.querySelector(`[class*="fixed inset-0 z-50"]`)?.querySelector(`[data-preset-id="${CSS.escape(l)}"]`);e&&(w.current=l,e.scrollIntoView({block:`nearest`}))});return()=>cancelAnimationFrame(e)}},[l,H]),!e)return null;let ae=l&&!z.isPending,oe=p||r.trayColor?.slice(0,6)||`FFFFFF`;return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex ${s?``:`items-center justify-center`}`,children:[!s&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,K.jsxs)(`div`,{className:s?`relative w-full h-full bg-bambu-dark-secondary flex flex-col`:`relative w-full max-w-lg mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Vl,{className:`w-5 h-5 text-bambu-blue`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:c(`configureAmsSlot.title`)}),s&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 ml-4 text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`text-white/30`,children:`|`}),r.trayColor&&(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),(0,K.jsx)(`span`,{className:`text-white/70`,children:c(`configureAmsSlot.slotLabel`,{ams:If(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&(0,K.jsxs)(`span`,{children:[`(`,r.traySubBrands,`)`]})]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(Bu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 overflow-y-auto ${s?`flex-1 min-h-0`:`space-y-4 max-h-[60vh]`}`,children:[b&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl`,children:(0,K.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,K.jsx)(ps,{className:`w-16 h-16 text-bambu-green mx-auto`}),(0,K.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:c(`configureAmsSlot.slotConfigured`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:c(`configureAmsSlot.settingsSentToPrinter`)})]})}),!s&&(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:c(`configureAmsSlot.configuringSlot`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r.trayColor&&(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:c(`configureAmsSlot.slotLabel`,{ams:If(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,r.traySubBrands,`)`]})]})]}),H?(0,K.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})}):s?(0,K.jsxs)(`div`,{className:`flex gap-4 h-full`,children:[(0,K.jsxs)(`div`,{className:`w-1/2 flex flex-col min-h-0`,children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[c(`configureAmsSlot.filamentProfile`),` `,(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsx)(`input`,{type:`text`,placeholder:c(`configureAmsSlot.searchPresets`),value:_,onChange:e=>v(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2 shrink-0`}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto space-y-1`,children:V.length===0?(0,K.jsx)(`p`,{className:`text-center py-4 text-bambu-gray`,children:T?.filament?.length===0&&!k?.filament?.length?c(`configureAmsSlot.noPresetsAvailable`):c(`configureAmsSlot.noMatchingPresets`)}):V.map(e=>(0,K.jsx)(`button`,{"data-preset-id":e.id,onClick:()=>u(e.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${l===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all`,title:e.name,children:e.name}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[e.source===`local`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400`,children:c(`profiles.localProfiles.badge`)}),e.source===`orca_cloud`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-purple-500/20 text-purple-400`,children:c(`configureAmsSlot.orcaCloud`)}),e.source===`cloud`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue`,children:c(`configureAmsSlot.bambuCloud`)}),e.source===`builtin`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400`,children:c(`configureAmsSlot.builtin`)})]})]})},e.id))})]}),(0,K.jsxs)(`div`,{className:`w-1/2 flex flex-col gap-4 min-h-0 overflow-y-auto`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[c(`configureAmsSlot.kProfileLabel`),te&&(0,K.jsx)(`span`,{className:`ml-2 text-xs text-bambu-blue`,children:c(`configureAmsSlot.filteringFor`,{material:te})})]}),re.length>0?(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:d?.name||``,onChange:e=>{f(re.find(t=>t.name===e.target.value)||null)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10`,children:[(0,K.jsx)(`option`,{value:``,children:c(`configureAmsSlot.noKProfile`)}),re.map(e=>(0,K.jsxs)(`option`,{value:e.name,children:[e.name,` (K=`,e.k_value,`)`]},`${e.name}-${e.extruder_id}`))]}),(0,K.jsx)(rs,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}):l?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:c(`configureAmsSlot.noMatchingKProfiles`)}):(0,K.jsx)(`span`,{className:`inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30`,children:c(`configureAmsSlot.selectFilamentFirst`)}),d&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-green mt-1`,children:c(`configureAmsSlot.kFromCalibration`,{value:d.k_value})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:c(`configureAmsSlot.customColorLabel`)}),ne.length>0&&(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1.5`,children:c(`configureAmsSlot.presetColors`,{name:ee?.fullName})}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:ne.map(e=>(0,K.jsxs)(`button`,{onClick:()=>{m(e.hex_color.replace(`#`,``).toUpperCase()),g(e.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${p===e.hex_color.replace(`#`,``).toUpperCase()?`border-bambu-green scale-105`:`border-white/20 hover:border-white/40`}`,title:e.color_name,children:[(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.hex_color}}),(0,K.jsx)(`span`,{className:`text-xs text-white/80 whitespace-nowrap`,children:e.color_name})]},e.id))})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:[GU.map(e=>(0,K.jsx)(`button`,{onClick:()=>{m(e.hex),g(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex)),(0,K.jsx)(`button`,{onClick:()=>C(!S),className:`w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs`,title:c(S?`configureAmsSlot.showLessColors`:`configureAmsSlot.showMoreColors`),children:S?`−`:`+`})]}),S&&(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:KU.map(e=>(0,K.jsx)(`button`,{onClick:()=>{m(e.hex),g(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex))}),(0,K.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0`,style:{backgroundColor:`#${oe}`}}),(0,K.jsx)(`input`,{type:`text`,placeholder:c(`configureAmsSlot.colorPlaceholder`),value:h,onChange:e=>{let t=e.target.value;g(t);let n=qU(t);if(n)m(n);else{let e=t.replace(/[^0-9A-Fa-f]/g,``).toUpperCase();e.length===6?m(e):e.length===3&&m(e.split(``).map(e=>e+e).join(``))}},className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm`}),p&&(0,K.jsx)(`button`,{onClick:()=>{m(``),g(``)},className:`px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded`,title:c(`configureAmsSlot.clearCustomColor`),children:c(`configureAmsSlot.clear`)})]}),p&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5`,children:c(`configureAmsSlot.hexLabel`,{hex:p})})]})]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[c(`configureAmsSlot.filamentProfile`),` `,(0,K.jsx)(`span`,{className:`text-red-400`,children:`*`})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{type:`text`,placeholder:c(`configureAmsSlot.searchPresets`),value:_,onChange:e=>v(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2`}),(0,K.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:V.length===0?(0,K.jsx)(`p`,{className:`text-center py-4 text-bambu-gray`,children:T?.filament?.length===0&&!k?.filament?.length?c(`configureAmsSlot.noPresetsAvailable`):c(`configureAmsSlot.noMatchingPresets`)}):V.map(e=>(0,K.jsx)(`button`,{"data-preset-id":e.id,onClick:()=>u(e.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${l===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all`,title:e.name,children:e.name}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[e.source===`local`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400`,children:c(`profiles.localProfiles.badge`)}),e.source===`orca_cloud`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-purple-500/20 text-purple-400`,children:c(`configureAmsSlot.orcaCloud`)}),e.source===`cloud`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue`,children:c(`configureAmsSlot.bambuCloud`)}),e.source===`builtin`&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400`,children:c(`configureAmsSlot.builtin`)})]})]})},e.id))})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[c(`configureAmsSlot.kProfileLabel`),te&&(0,K.jsx)(`span`,{className:`ml-2 text-xs text-bambu-blue`,children:c(`configureAmsSlot.filteringFor`,{material:te})})]}),re.length>0?(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`select`,{value:d?.name||``,onChange:e=>{f(re.find(t=>t.name===e.target.value)||null)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10`,children:[(0,K.jsx)(`option`,{value:``,children:c(`configureAmsSlot.noKProfile`)}),re.map(e=>(0,K.jsxs)(`option`,{value:e.name,children:[e.name,` (K=`,e.k_value,`)`]},`${e.name}-${e.extruder_id}`))]}),(0,K.jsx)(rs,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}):l?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:c(`configureAmsSlot.noMatchingKProfiles`)}):(0,K.jsx)(`span`,{className:`inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30`,children:c(`configureAmsSlot.selectFilamentFirst`)}),d&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-green mt-1`,children:c(`configureAmsSlot.kFromCalibration`,{value:d.k_value})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:c(`configureAmsSlot.customColorLabel`)}),ne.length>0&&(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1.5`,children:c(`configureAmsSlot.presetColors`,{name:ee?.fullName})}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:ne.map(e=>(0,K.jsxs)(`button`,{onClick:()=>{m(e.hex_color.replace(`#`,``).toUpperCase()),g(e.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${p===e.hex_color.replace(`#`,``).toUpperCase()?`border-bambu-green scale-105`:`border-white/20 hover:border-white/40`}`,title:e.color_name,children:[(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.hex_color}}),(0,K.jsx)(`span`,{className:`text-xs text-white/80 whitespace-nowrap`,children:e.color_name})]},e.id))})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:[GU.map(e=>(0,K.jsx)(`button`,{onClick:()=>{m(e.hex),g(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex)),(0,K.jsx)(`button`,{onClick:()=>C(!S),className:`w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs`,title:c(S?`configureAmsSlot.showLessColors`:`configureAmsSlot.showMoreColors`),children:S?`−`:`+`})]}),S&&(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:KU.map(e=>(0,K.jsx)(`button`,{onClick:()=>{m(e.hex),g(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex))}),(0,K.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0`,style:{backgroundColor:`#${oe}`}}),(0,K.jsx)(`input`,{type:`text`,placeholder:c(`configureAmsSlot.colorPlaceholder`),value:h,onChange:e=>{let t=e.target.value;g(t);let n=qU(t);if(n)m(n);else{let e=t.replace(/[^0-9A-Fa-f]/g,``).toUpperCase();e.length===6?m(e):e.length===3&&m(e.split(``).map(e=>e+e).join(``))}},className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm`}),p&&(0,K.jsx)(`button`,{onClick:()=>{m(``),g(``)},className:`px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded`,title:c(`configureAmsSlot.clearCustomColor`),children:c(`configureAmsSlot.clear`)})]}),p&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5`,children:c(`configureAmsSlot.hexLabel`,{hex:p})})]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>B.mutate(),disabled:B.isPending||z.isPending,className:`text-red-400 hover:text-red-300 hover:bg-red-500/10`,children:B.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),c(`configureAmsSlot.resetting`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(kl,{className:`w-4 h-4`}),c(`configureAmsSlot.resetSlot`)]})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,children:c(`configureAmsSlot.cancel`)}),(0,K.jsx)($,{onClick:()=>z.mutate(),disabled:!ae,children:z.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),c(`configureAmsSlot.configuring`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Vl,{className:`w-4 h-4`}),c(`configureAmsSlot.configureSlot`)]})})]})]}),(z.isError||B.isError)&&(0,K.jsx)(`div`,{className:`mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400`,children:z.error?.message||B.error?.message})]})]})}function XU({className:e=`w-4 h-4`}){return(0,K.jsx)(`svg`,{viewBox:`0 0 1945 1370`,fill:`none`,className:e,"aria-hidden":`true`,children:(0,K.jsxs)(`g`,{transform:`translate(-754.293 -471.685)`,children:[(0,K.jsxs)(`g`,{transform:`translate(0.18191 255.976)`,children:[(0,K.jsx)(`g`,{transform:`matrix(1.05469 0 0 0.241063 -153.484 1120.2)`,children:(0,K.jsx)(`rect`,{x:`922.048`,y:`1195.15`,width:`1721.5`,height:`470.135`,stroke:`currentColor`,strokeOpacity:`0.99`,strokeWidth:`168.84`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,K.jsx)(`g`,{transform:`matrix(0.983656 0 0 1.0767 -62.2035 141.539)`,children:(0,K.jsx)(`path`,{d:`M2741.42,1175.93L895.832,1175.93L1125.16,621.902L2512.09,621.902L2741.42,1175.93Z`,fill:`currentColor`,fillOpacity:`0.05`,stroke:`currentColor`,strokeOpacity:`0.99`,strokeWidth:`125.26`,strokeLinecap:`round`,strokeLinejoin:`round`})})]}),(0,K.jsx)(`g`,{transform:`translate(21.1916 0.684817)`,children:(0,K.jsx)(`path`,{d:`M1981.31,567.518C1954.86,567.518 1933.39,546.047 1933.39,519.601C1933.39,493.156 1954.86,471.685 1981.31,471.685L2146.61,471.685C2173.07,471.685 2194.53,493.138 2194.53,519.601L2194.53,688.741C2194.53,715.187 2173.05,736.658 2146.61,736.658C2120.16,736.658 2098.69,715.187 2098.69,688.741L2098.69,567.518L1981.31,567.518ZM2098.69,1252.54C2098.69,1226.1 2120.16,1204.62 2146.61,1204.62C2173.05,1204.62 2194.53,1226.1 2194.53,1252.54L2194.53,1421.68C2194.53,1448.14 2173.07,1469.6 2146.61,1469.6L1981.31,1469.6C1954.86,1469.6 1933.39,1448.13 1933.39,1421.68C1933.39,1395.24 1954.86,1373.76 1981.31,1373.76L2098.69,1373.76L2098.69,1252.54ZM1430.29,1373.76C1456.74,1373.76 1478.21,1395.24 1478.21,1421.68C1478.21,1448.13 1456.74,1469.6 1430.29,1469.6L1264.99,1469.6C1238.53,1469.6 1217.07,1448.14 1217.07,1421.68L1217.07,1252.54C1217.07,1226.1 1238.55,1204.62 1264.99,1204.62C1291.44,1204.62 1312.91,1226.1 1312.91,1252.54L1312.91,1373.76L1430.29,1373.76ZM1312.91,688.741C1312.91,715.187 1291.44,736.658 1264.99,736.658C1238.55,736.658 1217.07,715.187 1217.07,688.741L1217.07,519.601C1217.07,493.138 1238.53,471.685 1264.99,471.685L1430.29,471.685C1456.74,471.685 1478.21,493.156 1478.21,519.601C1478.21,546.047 1456.74,567.518 1430.29,567.518L1312.91,567.518L1312.91,688.741Z`,fill:`currentColor`,fillOpacity:`0.99`})})]})})}function ZU({folderId:e,onClose:t,onUploadComplete:n,onFileUploaded:r,autoUpload:i,validateFile:a,accept:o,initialFiles:s}){let{t:c}=W(),[l,u]=(0,y.useState)([]),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!0),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!0),[S,C]=(0,y.useState)(null),w=(0,y.useRef)(null),T=e=>{e.preventDefault(),f(!0)},E=e=>{e.preventDefault(),f(!1)},D=e=>{e.preventDefault(),f(!1),j(Array.from(e.dataTransfer.files))},O=e=>{e.target.files&&j(Array.from(e.target.files))},k=(e,t)=>{u(n=>n.map(n=>n.file===e?{...n,...t}:n))},A=async i=>{m(!0);for(let t of i)if(t.status===`pending`){k(t.file,{status:`uploading`});try{if(t.isZip){let n=await Q.extractZipFile(t.file,e,h,_,b);k(t.file,{status:n.errors.length>0&&n.extracted===0?`error`:`success`,extractedCount:n.extracted,error:n.errors.length>0?c(`fileManager.zipFilesFailed`,`{{count}} files failed`,{count:n.errors.length}):void 0})}else{let n=await Q.uploadLibraryFile(t.file,e,b);k(t.file,{status:`success`});let i=r?.(n);if(i){C(i),u([]),m(!1);return}}}catch(e){k(t.file,{status:`error`,error:e instanceof Error?e.message:c(`fileManager.uploadFailed`,`Upload failed`)})}}m(!1),n(),u(e=>(e.some(e=>e.status===`error`)||t(),e))},j=e=>{if(C(null),a)for(let t of e){let e=a(t);if(e){C(e);return}}let t=e.map(e=>({file:e,status:`pending`,isZip:e.name.toLowerCase().endsWith(`.zip`),is3mf:e.name.toLowerCase().endsWith(`.3mf`)}));u(e=>[...e,...t]),i&&e.length>0&&A(t)},M=e=>{u(t=>t.filter((t,n)=>n!==e))},N=(0,y.useRef)(!1);(0,y.useEffect)(()=>{N.current||!s||s.length===0||(N.current=!0,j(s))},[]);let P=l.some(e=>e.isZip&&e.status===`pending`),F=l.some(e=>e.file.name.toLowerCase().endsWith(`.stl`)&&e.status===`pending`),I=l.some(e=>e.is3mf&&e.status===`pending`),L=l.filter(e=>e.status===`pending`).length,R=l.length>0&&L===0&&!p;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:c(`fileManager.uploadFiles`)}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,K.jsx)(Bu,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,K.jsxs)(`div`,{onDragOver:T,onDragLeave:E,onDrop:D,onClick:()=>w.current?.click(),className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${d?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,children:[(0,K.jsx)(Eu,{className:`w-10 h-10 mx-auto mb-3 ${d?`text-bambu-green`:`text-bambu-gray`}`}),(0,K.jsx)(`p`,{className:`text-white font-medium`,children:c(d?`fileManager.dropFilesHere`:`fileManager.dragDropFiles`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:c(`fileManager.orClickToBrowse`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-2`,children:c(`fileManager.allFileTypesSupported`)})]}),(0,K.jsx)(`input`,{ref:w,type:`file`,multiple:!0,accept:o,className:`hidden`,onChange:O}),P&&(0,K.jsx)(`div`,{className:`p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(Oo,{className:`w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-blue-300 font-medium`,children:c(`fileManager.zipFilesDetected`)}),(0,K.jsx)(`p`,{className:`text-xs text-blue-300/70 mt-1`,children:c(`fileManager.zipExtractOptions`)}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 mt-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:c(`fileManager.preserveZipStructure`)})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 mt-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:c(`fileManager.createFolderFromZip`)})]})]})]})}),I&&(0,K.jsx)(`div`,{className:`p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(wl,{className:`w-5 h-5 text-purple-400 mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-purple-300 font-medium`,children:c(`fileManager.threemfDetected`)}),(0,K.jsx)(`p`,{className:`text-xs text-purple-300/70 mt-1`,children:c(`fileManager.threemfExtractionInfo`)})]})]})}),(F||P)&&(0,K.jsx)(`div`,{className:`p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(jc,{className:`w-5 h-5 text-bambu-green mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-green font-medium`,children:c(`fileManager.stlThumbnailGeneration`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-green/70 mt-1`,children:c(P&&!F?`fileManager.zipMayContainStl`:`fileManager.thumbnailsCanBeGenerated`)}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 mt-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>x(e.target.checked),className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:c(`fileManager.generateThumbnailsForStl`)})]})]})]})}),l.length>0&&(0,K.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-2`,children:l.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-2 bg-bambu-dark rounded-lg`,children:[e.isZip?(0,K.jsx)(Oo,{className:`w-4 h-4 text-blue-400 flex-shrink-0`}):(0,K.jsx)(nc,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.file.name}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[(e.file.size/1024/1024).toFixed(2),` MB`,e.isZip&&e.status===`pending`&&(0,K.jsxs)(`span`,{className:`text-blue-400 ml-2`,children:[`• `,c(`fileManager.willBeExtracted`)]}),e.extractedCount!==void 0&&(0,K.jsxs)(`span`,{className:`text-green-400 ml-2`,children:[`• `,c(`fileManager.filesExtracted`,{count:e.extractedCount})]})]}),e.status===`error`&&e.error&&(0,K.jsx)(`p`,{className:`text-xs text-red-400 mt-1 break-words`,children:e.error})]}),e.status===`pending`&&(0,K.jsx)(`button`,{onClick:()=>M(t),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,K.jsx)(Bu,{className:`w-4 h-4 text-bambu-gray`})}),e.status===`uploading`&&(0,K.jsx)(X,{className:`w-4 h-4 text-bambu-green animate-spin`}),e.status===`success`&&(0,K.jsx)(fs,{className:`w-4 h-4 text-green-500`}),e.status===`error`&&(0,K.jsx)(`span`,{title:e.error,children:(0,K.jsx)(vs,{className:`w-4 h-4 text-red-500`})})]},t))}),S&&(0,K.jsx)(`div`,{className:`p-3 bg-red-500/10 border border-red-500/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(vs,{className:`w-5 h-5 text-red-400 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`p`,{className:`text-sm text-red-300`,children:S})]})})]}),(0,K.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,children:c(`common.cancel`)}),!R&&(0,K.jsx)($,{onClick:()=>A(l),disabled:L===0||p,children:p?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 mr-2 animate-spin`}),c(`fileManager.uploading`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Eu,{className:`w-4 h-4 mr-2`}),c(`common.upload`),` `,L>0?`(${L})`:``]})})]})]})})}function QU(e){let t=[],n=e?.ams_extruder_map,r=!!e?.nozzles?.[1]?.nozzle_diameter||n&&Object.keys(n).length>0||(e?.vt_tray?.length??0)>1;e?.ams?.forEach(e=>{let r=e.tray.length===1;e.tray.forEach(i=>{if(i.tray_type){let a=Pf(i.tray_color);t.push({type:i.tray_type,color:a,colorName:Zd(a),amsId:e.id,trayId:i.id,isHt:r,isExternal:!1,label:Hf(e.id,i.id,r,!1),globalTrayId:Uf(e.id,i.id,!1),trayInfoIdx:i.tray_info_idx||``,traySubBrands:i.tray_sub_brands||``,extruderId:n?.[String(e.id)],remain:i.remain??-1})}})});for(let n of e?.vt_tray??[])if(n.tray_type){let i=Pf(n.tray_color),a=n.id??254,o=(e?.vt_tray?.length??0)>1;t.push({type:n.tray_type,color:i,colorName:Zd(i),amsId:-1,trayId:a-254,isHt:!1,isExternal:!0,label:o?a===254?`Ext-L`:`Ext-R`:`External`,globalTrayId:a,trayInfoIdx:n.tray_info_idx||``,traySubBrands:n.tray_sub_brands||``,extruderId:r?255-a:void 0,remain:n.remain??-1})}return t}function $U(e,t,n,r){if(!e?.filaments||e.filaments.length===0)return;let i=QU(t);if(i.length===0)return;let a=t?.fila_switch?.installed===!0,o=new Set,s=e.filaments.map(e=>{let t=e.tray_info_idx||``,s=i.filter(e=>!o.has(e.globalTrayId));e.nozzle_id!=null&&!a&&(s=s.filter(t=>t.extruderId===e.nozzle_id)),n&&(s=[...s].sort((e,t)=>Qf(Zf(e,r),Zf(t,r))));let c,l,u,d;if(t){let i=s.filter(e=>e.trayInfoIdx===t);i.length===1?c=i[0]:i.length>1&&(n&&i.sort((e,t)=>Qf(Zf(e,r),Zf(t,r))),l=i.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&Ff(t.color)===Ff(e.color)),l||(u=i.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&Vf(t.color,e.color))),!l&&!u&&(d=i.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase())))}!c&&!l&&!u&&!d&&(l=s.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&Ff(t.color)===Ff(e.color)),l||(u=s.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&Vf(t.color,e.color))),!l&&!u&&(d=s.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase())));let f=c||l||u||d||void 0;return f&&o.add(f.globalTrayId),{slot_id:e.slot_id,globalTrayId:f?.globalTrayId??-1}}),c=Math.max(...s.map(e=>e.slot_id||0));if(c<=0)return;let l=Array(c).fill(-1);return s.forEach(e=>{e.slot_id&&e.slot_id>0&&(l[e.slot_id-1]=e.globalTrayId)}),l}function mke(e){return(0,y.useMemo)(()=>QU(e),[e])}function eW(e,t,n,r,i){let a=mke(t),o=t?.fila_switch?.installed===!0,s=(0,y.useMemo)(()=>{if(!e?.filaments||e.filaments.length===0)return[];let t=new Set(Object.values(n));return e.filaments.map(e=>{let s=e.slot_id||0;if(s>0&&n[s]!==void 0){let t=n[s],r=a.find(e=>e.globalTrayId===t);if(r){let t=r.type?.toUpperCase()===e.type?.toUpperCase(),n=Ff(r.color)===Ff(e.color)||Vf(r.color,e.color),i;return i=t&&n?`match`:t?`type_only`:`mismatch`,{...e,loaded:r,hasFilament:!0,typeMatch:t,colorMatch:n,status:i,isManual:!0}}}let c=e.tray_info_idx||``,l=a.filter(e=>!t.has(e.globalTrayId));e.nozzle_id!=null&&!o&&(l=l.filter(t=>t.extruderId===e.nozzle_id)),r&&(l=[...l].sort((e,t)=>Qf(Zf(e,i),Zf(t,i))));let u,d,f,p;if(c){let t=l.filter(e=>e.trayInfoIdx===c);t.length===1?u=t[0]:t.length>1&&(r&&t.sort((e,t)=>Qf(Zf(e,i),Zf(t,i))),d=t.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&Ff(t.color)===Ff(e.color)),d||(f=t.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&Vf(t.color,e.color))),!d&&!f&&(p=t.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase())))}!u&&!d&&!f&&!p&&(d=l.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&Ff(t.color)===Ff(e.color)),d||(f=l.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase()&&Vf(t.color,e.color))),!d&&!f&&(p=l.find(t=>t.type?.toUpperCase()===e.type?.toUpperCase())));let m=u||d||f||p||void 0;m&&t.add(m.globalTrayId);let h=!!m,g=h,_=!!u||!!d||!!f,v;return v=u||d||f?`match`:p?`type_only`:`mismatch`,{...e,loaded:m,hasFilament:h,typeMatch:g,colorMatch:_,status:v,isManual:!1}})},[e,a,n,r,o,i]);return{loadedFilaments:a,filamentComparison:s,amsMapping:(0,y.useMemo)(()=>{if(s.length===0)return;let e=Math.max(...s.map(e=>e.slot_id||0));if(e<=0)return;let t=Array(e).fill(-1);return s.forEach(e=>{e.slot_id&&e.slot_id>0&&(t[e.slot_id-1]=e.loaded?.globalTrayId??-1)}),t},[s]),hasTypeMismatch:s.some(e=>e.status===`mismatch`),hasColorMismatch:s.some(e=>e.status===`type_only`)}}function hke(e,t,n,r,i){if(!e||e.length===0)return{exactMatches:0,typeOnlyMatches:0,missingTypes:0,totalSlots:0,status:`full`};let a=0,o=0,s=0,c=new Set(Object.values(n));for(let l of e){let e=l.slot_id||0;if(e>0&&n[e]!==void 0){let r=n[e],i=t.find(e=>e.globalTrayId===r);if(i){let e=i.type?.toUpperCase()===l.type?.toUpperCase(),t=Ff(i.color)===Ff(l.color)||Vf(i.color,l.color);e&&t?a++:e?o++:s++;continue}}let u=t.filter(e=>!c.has(e.globalTrayId));if(l.nozzle_id!=null){let e=u.filter(e=>e.extruderId===l.nozzle_id);e.length>0&&(u=e)}r&&(u=[...u].sort((e,t)=>Qf(Zf(e,i),Zf(t,i))));let d=u.find(e=>e.type?.toUpperCase()===l.type?.toUpperCase()&&Ff(e.color)===Ff(l.color)),f=d?void 0:u.find(e=>e.type?.toUpperCase()===l.type?.toUpperCase()&&Vf(e.color,l.color)),p=d||f?void 0:u.find(e=>e.type?.toUpperCase()===l.type?.toUpperCase()),m=d??f??p;m&&c.add(m.globalTrayId),d||f?a++:p?o++:s++}let l=e.length,u=`full`;return s>0?u=`missing`:o>0&&(u=`partial`),{exactMatches:a,typeOnlyMatches:o,missingTypes:s,totalSlots:l,status:u}}function gke(e,t,n,r,i){if(!e?.filaments||e.filaments.length===0)return;let a=QU(t);if(a.length===0)return;let o=new Set(Object.values(n)),s=[];for(let t of e.filaments){let e=t.slot_id||0;if(e>0&&n[e]!==void 0){s.push({slot_id:e,globalTrayId:n[e]});continue}let c=a.filter(e=>!o.has(e.globalTrayId));if(t.nozzle_id!=null){let e=c.filter(e=>e.extruderId===t.nozzle_id);e.length>0&&(c=e)}r&&(c=[...c].sort((e,t)=>Qf(Zf(e,i),Zf(t,i))));let l=c.find(e=>e.type?.toUpperCase()===t.type?.toUpperCase()&&Ff(e.color)===Ff(t.color)),u=l?void 0:c.find(e=>e.type?.toUpperCase()===t.type?.toUpperCase()&&Vf(e.color,t.color)),d=l||u?void 0:c.find(e=>e.type?.toUpperCase()===t.type?.toUpperCase()),f=l??u??d;f&&o.add(f.globalTrayId),s.push({slot_id:e,globalTrayId:f?.globalTrayId??-1})}let c=Math.max(...s.map(e=>e.slot_id||0));if(c<=0)return;let l=Array(c).fill(-1);return s.forEach(e=>{e.slot_id&&e.slot_id>0&&(l[e.slot_id-1]=e.globalTrayId)}),l}var tW={useDefault:!0,manualMappings:{},autoConfigured:!1};function _ke(e,t,n,r,i,a,o,s){let c=_o({queries:e.map(t=>({queryKey:[`printer-status`,t],queryFn:()=>Q.getPrinterStatus(t),enabled:e.length>0,staleTime:5e3}))}),l=(0,y.useMemo)(()=>e.map((e,a)=>{let l=c[a],u=l?.data,d=t?.find(t=>t.id===e)?.name||`Printer ${e}`,f=QU(u),p=i[e]||tW,m=s?.get(e),h=$f(o,u?.ams_filament_backup),g=$U(n,u,h,m),_=p.useDefault?r:p.manualMappings,v=gke(n,u,_,h,m),y=hke(n?.filaments,f,_,h,m);return{printerId:e,printerName:d,status:u,isLoading:l?.isLoading??!1,loadedFilaments:f,autoMapping:g,finalMapping:v,matchStatus:y.status,exactMatches:y.exactMatches,typeOnlyMatches:y.typeOnlyMatches,missingTypes:y.missingTypes,totalSlots:y.totalSlots,config:p,inventoryByTrayId:m}}),[e,c,t,n,i,r,o,s]),u=c.some(e=>e.isLoading),d=(e,t)=>{a(n=>({...n,[e]:{...n[e]||tW,...t}}))},f=e=>{let t=l.find(t=>t.printerId===e);if(!t||!t.status||!n?.filaments)return;let r=$U(n,t.status,$f(o,t.status?.ams_filament_backup),s?.get(e));if(!r)return;let i={};r.forEach((e,t)=>{e!==-1&&(i[t+1]=e)}),d(e,{useDefault:!1,manualMappings:i,autoConfigured:!0})};return{printerResults:l,isLoading:u,perPrinterConfigs:i,updatePrinterConfig:d,autoConfigureAll:()=>{for(let t of e)f(t)},autoConfigurePrinter:f,getFinalMapping:e=>l.find(t=>t.printerId===e)?.finalMapping,allPrintersReady:l.every(e=>e.matchStatus!==`missing`)}}var nW=`/img/bed`,vke={"cool plate":{icon:`${nW}/bed_cool.png`,label:`Cool Plate`},"pc plate":{icon:`${nW}/bed_cool.png`,label:`Cool Plate`},"cool plate (supertack)":{icon:`${nW}/bed_cool_supertack.png`,label:`Cool Plate SuperTack`},"supertack plate":{icon:`${nW}/bed_cool_supertack.png`,label:`Cool Plate SuperTack`},"bambu cool plate supertack":{icon:`${nW}/bed_cool_supertack.png`,label:`Cool Plate SuperTack`},"engineering plate":{icon:`${nW}/bed_engineering.png`,label:`Engineering Plate`},"high temp plate":{icon:`${nW}/bed_high_templ.png`,label:`High Temp Plate`},"textured pei plate":{icon:`${nW}/bed_pei.png`,label:`Textured PEI Plate`},"pei plate":{icon:`${nW}/bed_pei.png`,label:`PEI Plate`},"smooth pei plate":{icon:`${nW}/bed_pei_cool.png`,label:`Smooth PEI Plate`}};function rW(e){return e?vke[e.trim().toLowerCase()]??null:null}function yke(e){let t=e.trim().split(/\s+/);return t.length<=1?e.trim():t.slice(1).join(` `)}function iW(e){let{data:t}=q({queryKey:[`builtin-filaments`],queryFn:()=>Q.getBuiltinFilaments(),staleTime:300*1e3}),{data:n}=q({queryKey:[`filament-id-map`],queryFn:()=>Q.getFilamentIdMap(),staleTime:300*1e3}),r=(0,y.useMemo)(()=>{let e={};for(let n of t||[])n.filament_id&&(e[n.filament_id]=n.name);for(let[t,r]of Object.entries(n||{}))t&&r&&(e[t]=r);return e},[t,n]),i=(0,y.useMemo)(()=>(e||[]).map(e=>{let t=e.tray_info_idx&&r[e.tray_info_idx]||e.type;return{resolvedName:t,materialHint:yke(t),color:e.color}}),[e,r]),a=_o({queries:i.map(({color:e,materialHint:t})=>({queryKey:[`color-by-material`,e,t],queryFn:()=>Q.getColorByMaterial(e,t),enabled:!!e,staleTime:300*1e3}))});return i.map(({resolvedName:e,color:t},n)=>({resolvedName:e,colorLabel:(a[n]?.data?.color_name??null)||Zd(t)}))}function bke({printerId:e,filamentReqs:t,manualMappings:n,onManualMappingChange:r,currencySymbol:i,defaultCostPerKg:a,defaultExpanded:o=!1,forceColorMatch:s,onForceColorMatchChange:c}){let{t:l}=W(),u=no(),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(o),{data:h}=q({queryKey:[`printer-status`,e],queryFn:()=>Q.getPrinterStatus(e),enabled:!!e}),{data:g}=q({queryKey:[`spool-assignments`,e],queryFn:()=>Q.getAssignments(e),enabled:!!e}),{data:_}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:v}=q({queryKey:[`printer-inventory-remain`,e],queryFn:()=>Q.getInventoryRemain(e),enabled:!!e,staleTime:30*1e3}),b=(0,y.useMemo)(()=>{if(!v?.inventory_remain_g)return;let e=new Map;return Object.entries(v.inventory_remain_g).forEach(([t,n])=>{let r=Number(t);Number.isNaN(r)||e.set(r,n)}),e},[v]),{loadedFilaments:x,filamentComparison:S,hasTypeMismatch:C,hasColorMismatch:w}=eW(t,h,n,$f(_?.prefer_lowest_filament,h?.ams_filament_backup),b),T=iW(t?.filaments),E=(0,y.useMemo)(()=>{let e=new Map;for(let t of g||[]){let n=t.ams_id===255,r=Uf(t.ams_id,t.tray_id,n);e.set(r,t.spool?.cost_per_kg??null)}return e},[g]),D=(0,y.useMemo)(()=>{let e=new Map;for(let t of g||[]){let n=t.ams_id===255,r=Uf(t.ams_id,t.tray_id,n),i=t.spool;if(!i){e.set(r,null);continue}e.set(r,Math.max(0,Math.round((i.label_weight??0)-(i.weight_used??0))))}return e},[g]),O=(0,y.useMemo)(()=>{let e=0;for(let t of S){let n=t.loaded?.globalTrayId;if(n==null)continue;let r=E.get(n)??null??a;r>0&&(e+=t.used_grams/1e3*r)}return e},[S,E,a]),k=(0,y.useMemo)(()=>Array.from(E.values()).some(e=>e!=null&&e>0),[E]),A=t?.filaments&&t.filaments.length>0,j=t?.filaments?.some(e=>e.nozzle_id!=null)??!1,M=h?.fila_switch?.installed===!0,N=e=>{let t=h?.fila_switch;if(!t?.installed)return null;let n=t.in_slots.indexOf(e);return n<0?null:t.out_extruders[n]??null};if(!A||!h)return null;let P=C?`#f97316`:w?`#facc15`:`#00ae42`,F=(e,t)=>{if(e>0)if(t===``){let t={...n};delete t[e],r(t)}else r({...n,[e]:parseInt(t,10)})};return(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>m(!p),className:`flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full`,children:[(0,K.jsx)(ys,{className:`w-4 h-4`,fill:P,stroke:`none`}),(0,K.jsx)(`span`,{children:l(`printModal.filamentMapping`)}),C?(0,K.jsx)(`span`,{className:`text-xs text-orange-400`,children:`(Type not found)`}):w?(0,K.jsx)(`span`,{className:`text-xs text-yellow-400`,children:`(Color mismatch)`}):(0,K.jsx)(`span`,{className:`text-xs text-bambu-green`,children:`(Ready)`}),p?(0,K.jsx)(ss,{className:`w-4 h-4 ml-auto`}):(0,K.jsx)(rs,{className:`w-4 h-4 ml-auto`})]}),p&&(0,K.jsxs)(`div`,{className:`mt-2 bg-bambu-dark rounded-lg p-3 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`Click to change slot assignment`}),(0,K.jsxs)(`button`,{type:`button`,onClick:async()=>{f(!0);try{await Q.refreshPrinterStatus(e),await new Promise(e=>setTimeout(e,500)),await u.refetchQueries({queryKey:[`printer-status`,e]})}finally{f(!1)}},className:`flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white`,disabled:d,children:[(0,K.jsx)(Dl,{className:`w-3 h-3 ${d?`animate-spin`:``}`}),(0,K.jsx)(`span`,{children:`Re-read`})]})]}),S.map((e,t)=>{let n=e.slot_id??0,r=n>0&&c!=null,{resolvedName:i,colorLabel:a}=T[t]??{resolvedName:e.type,colorLabel:Zd(e.color)};return(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`div`,{className:`grid items-center gap-2 text-xs`,style:{gridTemplateColumns:`16px minmax(70px, 1fr) auto 2fr 16px`},children:[(0,K.jsx)(`span`,{title:`Required: ${i} - ${a}`,children:(0,K.jsx)(ys,{className:`w-3 h-3`,fill:e.color,stroke:e.color})}),(0,K.jsxs)(`span`,{className:`text-white truncate flex items-center gap-1`,children:[j&&e.nozzle_id!=null&&(0,K.jsx)(`span`,{className:`inline-flex items-center justify-center w-3.5 h-3.5 rounded text-[9px] font-bold leading-none bg-bambu-gray/20 text-bambu-gray shrink-0`,title:e.nozzle_id===1?l(`printModal.leftNozzleTooltip`):l(`printModal.rightNozzleTooltip`),children:e.nozzle_id===1?l(`printModal.leftNozzle`):l(`printModal.rightNozzle`)}),i,` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.used_grams,`g)`]})]}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`→`}),(0,K.jsxs)(`select`,{value:e.loaded?.globalTrayId??``,onChange:e=>F(n,e.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${e.status===`match`?`border-bambu-green/50 text-bambu-green`:e.status===`type_only`?`border-yellow-400/50 text-yellow-400`:`border-orange-400/50 text-orange-400`} ${e.isManual?`ring-1 ring-blue-400/50`:``}`,title:e.isManual?`Manually selected`:`Auto-matched`,children:[(0,K.jsx)(`option`,{value:``,className:`bg-bambu-dark text-bambu-gray`,children:`-- Select slot --`}),x.map(e=>{let t=D.get(e.globalTrayId),n=t==null?``:l(`printModal.slotRemainingShort`,{grams:t,defaultValue:` - ${t}g left`}),r=M?N(e.globalTrayId):null,i=r==null?``:` [${l(r===1?`printModal.leftNozzle`:`printModal.rightNozzle`)}]`;return(0,K.jsxs)(`option`,{value:e.globalTrayId,className:`bg-bambu-dark text-white`,children:[e.label,`: `,e.traySubBrands||e.type,` (`,e.colorName,`)`,n,i]},e.globalTrayId)})]}),e.status===`match`?(0,K.jsx)(ns,{className:`w-3 h-3 text-bambu-green`}):e.status===`type_only`?(0,K.jsx)(`span`,{title:`Same type, different color`,children:(0,K.jsx)(Su,{className:`w-3 h-3 text-yellow-400`})}):(0,K.jsx)(`span`,{title:`Filament type not loaded`,children:(0,K.jsx)(Su,{className:`w-3 h-3 text-orange-400`})})]}),r&&(0,K.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer select-none pl-5`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:s?.[n]??!1,onChange:e=>c(n,e.target.checked),className:`accent-bambu-green w-3 h-3`}),(0,K.jsx)(pl,{className:`w-3 h-3`}),l(`printModal.forceColorMatch`)]})]},t)}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[l(`printModal.totalCost`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:O>0||k?`${i}${O.toFixed(2)}`:`N/A`})]}),C&&(0,K.jsx)(`p`,{className:`text-xs text-orange-400 mt-2`,children:`Required filament type not found in printer.`})]})]})}function xke({filamentReqs:e,availableFilaments:t,overrides:n,onChange:r,forceColorMatch:i,onForceColorMatchChange:a}){let{t:o}=W(),s=iW(e?.filaments),c=(0,y.useMemo)(()=>{let e={};for(let n of t){let t=zf(n.type);e[t]||(e[t]=[]),e[t].push(n)}return e},[t]),l=e?.filaments;if(!l||l.length===0||t.length===0)return null;let u=(e,t)=>{if(t===``){let t={...n};delete t[e],r(t)}else{let[i,a]=t.split(`|`);r({...n,[e]:{type:i,color:a}})}};return(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:(0,K.jsx)(`span`,{children:o(`printModal.filamentOverride`)})}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:o(`printModal.filamentOverrideHint`)}),(0,K.jsx)(`div`,{className:`bg-bambu-dark rounded-lg p-3 space-y-2`,children:l.map((e,t)=>{let r=n[e.slot_id],l=!!r,d=c[zf(e.type)]||[],f=e.nozzle_id==null?d:d.filter(t=>t.extruder_id==null||t.extruder_id===e.nozzle_id),{resolvedName:p,colorLabel:m}=s[t]??{resolvedName:e.type,colorLabel:Zd(e.color)};return(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`div`,{className:`grid items-center gap-2 text-xs`,style:{gridTemplateColumns:`16px minmax(70px, 1fr) auto 2fr 20px`},children:[(0,K.jsx)(`span`,{title:`${o(`printModal.originalFilament`)}: ${p} - ${m}`,children:(0,K.jsx)(ys,{className:`w-3 h-3`,fill:e.color,stroke:e.color})}),(0,K.jsxs)(`span`,{className:`text-white truncate`,children:[p,` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.used_grams,`g)`]})]}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`→`}),(0,K.jsxs)(`select`,{value:l?`${r.type}|${r.color}`:``,onChange:t=>u(e.slot_id,t.target.value),disabled:f.length===0,className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${l?`border-blue-400/50 text-blue-400`:`border-bambu-gray/30 text-bambu-gray`}`,children:[(0,K.jsxs)(`option`,{value:``,className:`bg-bambu-dark text-bambu-gray`,children:[o(`printModal.originalFilament`),`: `,p,` (`,m,`)`]}),f.map((e,t)=>(0,K.jsxs)(`option`,{value:`${e.type}|${e.color}`,className:`bg-bambu-dark text-white`,children:[e.tray_sub_brands||e.type,` (`,Zd(e.color),`)`]},`${e.type}-${e.color}-${e.tray_sub_brands}-${t}`))]}),l?(0,K.jsx)(`button`,{type:`button`,onClick:()=>u(e.slot_id,``),className:`text-bambu-gray hover:text-white transition-colors`,title:o(`printModal.resetToOriginal`),children:(0,K.jsx)(kl,{className:`w-3 h-3`})}):(0,K.jsx)(`span`,{className:`w-3`})]}),(0,K.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer select-none pl-5`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:i?.[e.slot_id]??!1,onChange:t=>a?.(e.slot_id,t.target.checked),className:`accent-bambu-green w-3 h-3`}),(0,K.jsx)(pl,{className:`w-3 h-3`}),o(`printModal.forceColorMatch`)]})]},e.slot_id)})})]})}function Ske({plates:e,isMultiPlate:t,selectedPlates:n,onToggle:r,onSelectAll:i,onDeselectAll:a,multiSelect:o}){let{t:s}=W();if(!t||e.length<=1)return null;let c=n.size===e.length;return(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(Lc,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`Select Plate`,o?`s`:``,` to Print`]}),n.size===0&&(0,K.jsxs)(`span`,{className:`text-xs text-orange-400 flex items-center gap-1`,children:[(0,K.jsx)(Su,{className:`w-3 h-3`}),`Selection required`]}),o&&i&&a&&(0,K.jsx)(`button`,{type:`button`,onClick:c?a:i,className:`ml-auto text-xs px-2 py-0.5 rounded-full border transition-colors ${c?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray`}`,children:c?s(`queue.deselectAll`):s(`queue.selectAllPlates`,{count:e.length})})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:e.map(e=>{let t=n.has(e.index);return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>r(e.index),className:`flex items-center gap-2 p-2 rounded-lg border transition-colors text-left ${t?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray`}`,children:[o&&(t?(0,K.jsx)(ru,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}):(0,K.jsx)(au,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`})),e.has_thumbnail&&e.thumbnail_url!=null?(0,K.jsx)(`img`,{src:Qu(e.thumbnail_url),alt:`Plate ${e.index}`,className:`w-10 h-10 rounded object-cover bg-bambu-dark-tertiary`}):(0,K.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,K.jsx)(Lc,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:e.name||`Plate ${e.index}`}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[e.objects.length>0?e.objects.slice(0,3).join(`, `)+(e.objects.length>3?`...`:``):`${e.filaments.length} filament${e.filaments.length===1?``:`s`}`,e.print_time_seconds==null?``:` • ${kf(e.print_time_seconds)}`]}),(()=>{let t=rW(e.bed_type);return t?(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray flex items-center gap-1 mt-0.5 truncate`,title:t.label,children:[(0,K.jsx)(`img`,{src:t.icon,alt:``,className:`w-3.5 h-3.5 object-contain flex-shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:t.label})]}):null})()]}),!o&&t&&(0,K.jsx)(ns,{className:`w-4 h-4 text-bambu-green flex-shrink-0`})]},e.index)})})]})}var Cke=new Set([`IDLE`,`FINISH`,`FAILED`]);function wke({printerResult:e,filamentReqs:t,onUpdateConfig:n}){let r=no(),[i,a]=(0,y.useState)(!1),o=(t,r)=>{if(t<=0)return;let i={...e.config.manualMappings};r===``?delete i[t]:i[t]=parseInt(r,10),n({useDefault:!1,manualMappings:i,autoConfigured:!1})},s=async()=>{a(!0);try{await Q.refreshPrinterStatus(e.printerId),await new Promise(e=>setTimeout(e,500)),await r.refetchQueries({queryKey:[`printer-status`,e.printerId]})}finally{a(!1)}},c=t.map(t=>{let n=t.slot_id||0,i=e.config.manualMappings[n],a,o=!1;if(i!==void 0)a=e.loadedFilaments.find(e=>e.globalTrayId===i),o=!0;else{let n=new Set(Object.values(e.config.manualMappings)),i=r.getQueryData([`settings`]);a=ep(t,e.loadedFilaments,n,$f(i?.prefer_lowest_filament,e.status?.ams_filament_backup),e.inventoryByTrayId)}let s=`mismatch`;if(a){let e=a.type?.toUpperCase()===t.type?.toUpperCase(),n=Ff(a.color)===Ff(t.color)||Vf(a.color,t.color);e&&n?s=`match`:e&&(s=`type_only`)}return{req:t,loaded:a,status:s,isManual:o}});return(0,K.jsxs)(`div`,{className:`mt-2 bg-bambu-dark rounded-lg p-3 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`Custom slot mapping`}),(0,K.jsxs)(`button`,{type:`button`,onClick:s,className:`flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white`,disabled:i,children:[(0,K.jsx)(Dl,{className:`w-3 h-3 ${i?`animate-spin`:``}`}),(0,K.jsx)(`span`,{children:`Re-read`})]})]}),c.map(({req:t,loaded:n,status:r,isManual:i},a)=>(0,K.jsxs)(`div`,{className:`grid items-center gap-2 text-xs`,style:{gridTemplateColumns:`16px minmax(70px, 1fr) auto 2fr 16px`},children:[(0,K.jsx)(`span`,{title:`Required: ${t.type} - ${Zd(t.color)}`,children:(0,K.jsx)(ys,{className:`w-3 h-3`,fill:t.color,stroke:t.color})}),(0,K.jsxs)(`span`,{className:`text-white truncate`,children:[t.type,` `,(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,t.used_grams,`g)`]})]}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:`→`}),(0,K.jsxs)(`select`,{value:n?.globalTrayId??``,onChange:e=>o(t.slot_id||0,e.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${r===`match`?`border-bambu-green/50 text-bambu-green`:r===`type_only`?`border-yellow-400/50 text-yellow-400`:`border-orange-400/50 text-orange-400`} ${i?`ring-1 ring-blue-400/50`:``}`,title:i?`Manually selected`:`Auto-matched`,children:[(0,K.jsx)(`option`,{value:``,className:`bg-bambu-dark text-bambu-gray`,children:`-- Select slot --`}),tp(e.loadedFilaments,t.nozzle_id).map(e=>(0,K.jsxs)(`option`,{value:e.globalTrayId,className:`bg-bambu-dark text-white`,children:[e.label,`: `,e.traySubBrands||e.type,` (`,e.colorName,`)`]},e.globalTrayId))]}),r===`match`?(0,K.jsx)(ns,{className:`w-3 h-3 text-bambu-green`}):r===`type_only`?(0,K.jsx)(`span`,{title:`Same type, different color`,children:(0,K.jsx)(Su,{className:`w-3 h-3 text-yellow-400`})}):(0,K.jsx)(`span`,{title:`Filament type not loaded`,children:(0,K.jsx)(Su,{className:`w-3 h-3 text-orange-400`})})]},a))]})}function Tke({printers:e,selectedPrinterIds:t,onMultiSelect:n,isLoading:r=!1,allowMultiple:i=!1,showInactive:a=!1,disableBusy:o=!1,printerMappingResults:s,filamentReqs:c,onAutoConfigurePrinter:l,onUpdatePrinterConfig:u,assignmentMode:d=`printer`,onAssignmentModeChange:f,targetModel:p,onTargetModelChange:m,targetLocation:h,onTargetLocationChange:g,slicedForModel:_}){let[v,b]=(0,y.useState)(!1),x=a?e:e.filter(e=>e.is_active),S=_o({queries:x.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),staleTime:5e3}))}),C=(0,y.useMemo)(()=>{let e=new Map;return x.forEach((t,n)=>{let r=S[n];r?.data&&e.set(t.id,r.data)}),e},[x,S]),w=e=>{let t=C.get(e);return t?t.connected?!Cke.has(t.state??``):!0:!1},T=e=>{let t=C.get(e);if(!t)return null;if(!t.connected)return`Offline`;let n=t.state;return n?n===`RUNNING`?t.stg_cur_name||`Printing`:n===`PREPARE`?`Preparing`:n===`PAUSE`?`Paused`:n===`IDLE`?`Idle`:n===`FINISH`?`Finished`:n===`FAILED`?`Failed`:n:null},E=(0,y.useMemo)(()=>{if(d!==`printer`||!_||v)return x;let e=x.filter(e=>e.model===_);return e.length>0?e:x},[x,d,_,v]),D=x.length-E.length,O=(0,y.useMemo)(()=>{let e=x.map(e=>e.model).filter(e=>!!e);return[...new Set(e)].sort()},[x]),k=(0,y.useMemo)(()=>{if(!p)return[];let e=x.filter(e=>e.model===p&&e.location).map(e=>e.location).filter(e=>!!e);return[...new Set(e)].sort()},[x,p]),A=f&&m&&O.length>0,j=i&&t.length>1&&s&&c?.filaments&&c.filaments.length>0&&l&&u;if(r)return(0,K.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 text-bambu-green animate-spin`})});if(E.length===0)return(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-red-400 text-sm mb-4`,children:[(0,K.jsx)(us,{className:`w-4 h-4`}),`No `,a?``:`active `,`printers available`]});let M=e=>{o&&w(e)||(i?t.includes(e)?n(t.filter(t=>t!==e)):n([...t,e]):n([e]))},N=()=>{n((o?E.filter(e=>!w(e.id)):E).map(e=>e.id))},P=()=>{n([])},F=(e,t,n)=>{n.stopPropagation(),!(!l||!u)&&(t?l(e):u(e,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},I=e=>t.includes(e),L=t.length,R=e=>s?.find(t=>t.printerId===e);return(0,K.jsxs)(`div`,{className:`space-y-2 mb-6`,children:[A&&(0,K.jsxs)(`div`,{className:`flex gap-2 mb-4`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{f(`printer`),m(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${d===`printer`?`border-bambu-green bg-bambu-green/10 text-white`:`border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray`}`,children:[(0,K.jsx)(wl,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-sm`,children:`Specific Printer`})]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{f(`model`),n([]),m(_&&O.includes(_)?_:O[0])},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${d===`model`?`border-bambu-green bg-bambu-green/10 text-white`:`border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray`}`,children:[(0,K.jsx)(Ou,{className:`w-4 h-4`}),(0,K.jsxs)(`span`,{className:`text-sm`,children:[`Any `,_||`Model`]})]})]}),d===`model`&&A&&(0,K.jsxs)(`div`,{className:`space-y-3 mb-4`,children:[!_&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:`Target Model`}),(0,K.jsxs)(`select`,{value:p||``,onChange:e=>{m(e.target.value||null),g&&g(null)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,children:[(0,K.jsx)(`option`,{value:``,children:`Select a model...`}),O.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]})]}),p&&k.length>0&&g&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:`Location Filter (optional)`}),(0,K.jsxs)(`select`,{value:h||``,onChange:e=>g(e.target.value||null),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,children:[(0,K.jsx)(`option`,{value:``,children:`Any location`}),k.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]})]}),p&&(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[`Scheduler will assign to first available idle `,p,` printer`,h?` in ${h}`:``]})]}),d===`printer`&&i&&E.length>1&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray mb-2`,children:[(0,K.jsx)(`span`,{children:L===0?`Select printers`:`${L} printer${L===1?``:`s`} selected`}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[L0&&(0,K.jsx)(`button`,{type:`button`,onClick:P,className:`text-bambu-gray hover:text-white transition-colors`,children:`Clear`})]})]}),d===`printer`&&E.map(e=>{let t=I(e.id),n=R(e.id),r=n&&!n.config.useDefault,a=w(e.id),s=o&&a,d=T(e.id);return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>M(e.id),disabled:s,className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${s?`border-bambu-dark-tertiary bg-bambu-dark opacity-50 cursor-not-allowed`:t?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray`} ${e.is_active?``:`opacity-60`}`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${s?`bg-bambu-dark-tertiary`:t?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(wl,{className:`w-5 h-5 ${s?`text-bambu-gray/50`:t?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{className:`text-left flex-1`,children:[(0,K.jsxs)(`p`,{className:`font-medium ${s?`text-bambu-gray`:`text-white`}`,children:[e.name,!e.is_active&&(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs ml-2`,children:`(inactive)`})]}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[e.model||`Unknown model`,` • `,e.ip_address]})]}),d&&(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full ${a?`bg-yellow-500/20 text-yellow-400`:`bg-bambu-green/20 text-bambu-green`}`,children:d}),i&&(0,K.jsx)(`div`,{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${s?`border-bambu-gray/30`:t?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:t&&(0,K.jsx)(ns,{className:`w-3 h-3 text-white`})})]}),t&&j&&n&&(0,K.jsxs)(`div`,{className:`ml-4 mt-2 mb-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:r,onChange:t=>F(e.id,t.target.checked,t),className:`w-3.5 h-3.5 rounded border-bambu-gray/30 bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green focus:ring-offset-0`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`Custom mapping`})]}),(0,K.jsxs)(`span`,{className:`text-xs ml-2 ${n.matchStatus===`full`?`text-bambu-green`:n.matchStatus===`partial`?`text-yellow-400`:`text-orange-400`}`,children:[`(`,n.exactMatches,`/`,n.totalSlots,` matched)`]}),n.isLoading&&(0,K.jsx)(Dl,{className:`w-3 h-3 text-bambu-gray animate-spin`}),r&&(0,K.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),l(e.id)},className:`ml-auto flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white`,children:[(0,K.jsx)(Nu,{className:`w-3 h-3`}),`Auto`]})]}),r&&(0,K.jsx)(wke,{printerResult:n,filamentReqs:c.filaments,onUpdateConfig:t=>u(e.id,t)})]})]},e.id)}),d===`printer`&&D>0&&!v&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>b(!0),className:`text-xs text-bambu-gray hover:text-white transition-colors mt-2 flex items-center gap-1`,children:[(0,K.jsx)(Su,{className:`w-3 h-3 text-yellow-400`}),D,` other printer`,D>1?`s`:``,` hidden (different model) —`,(0,K.jsx)(`span`,{className:`underline`,children:`show all`})]}),d===`printer`&&v&&_&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>b(!1),className:`text-xs text-bambu-gray hover:text-white transition-colors mt-2`,children:(0,K.jsxs)(`span`,{className:`underline`,children:[`Show only `,_,` printers`]})}),d===`printer`&&L===0&&(0,K.jsxs)(`p`,{className:`text-xs text-orange-400 mt-1 flex items-center gap-1`,children:[(0,K.jsx)(us,{className:`w-3 h-3`}),`Select at least one printer`]}),d===`model`&&!p&&(0,K.jsxs)(`p`,{className:`text-xs text-orange-400 mt-1 flex items-center gap-1`,children:[(0,K.jsx)(us,{className:`w-3 h-3`}),`Select a target printer model`]})]})}function Eke({options:e,onChange:t,defaultExpanded:n=!1,showDualNozzleOptions:r=!1}){let{t:i}=W(),[a,o]=(0,y.useState)(n),s=[{key:`bed_levelling`,label:i(`settings.defaultBedLevelling`),desc:i(`settings.defaultBedLevellingDesc`)},{key:`flow_cali`,label:i(`settings.defaultFlowCali`),desc:i(`settings.defaultFlowCaliDesc`)},{key:`vibration_cali`,label:i(`settings.defaultVibrationCali`),desc:i(`settings.defaultVibrationCaliDesc`)},{key:`layer_inspect`,label:i(`settings.defaultLayerInspect`),desc:i(`settings.defaultLayerInspectDesc`)},{key:`timelapse`,label:i(`settings.defaultTimelapse`),desc:i(`settings.defaultTimelapseDesc`)},{key:`nozzle_offset_cali`,label:i(`settings.defaultNozzleOffsetCali`),desc:i(`settings.defaultNozzleOffsetCaliDesc`),dualNozzleOnly:!0}].filter(e=>!e.dualNozzleOnly||r),c=n=>{t({...e,[n]:!e[n]})},l=n=>{t({...e,preheat_override:n,...n===`off`?{preheat_chamber_target_override:null}:{}})},u=n=>{if(n===``){t({...e,preheat_chamber_target_override:null});return}let r=parseInt(n,10);Number.isNaN(r)||t({...e,preheat_chamber_target_override:Math.max(0,Math.min(60,r))})};return(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>o(!a),className:`flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full`,children:[(0,K.jsx)(Hl,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:i(`queue.bulkEdit.printOptions`)}),a?(0,K.jsx)(ss,{className:`w-4 h-4 ml-auto`}):(0,K.jsx)(rs,{className:`w-4 h-4 ml-auto`})]}),a&&(0,K.jsxs)(`div`,{className:`mt-2 bg-bambu-dark rounded-lg p-3 space-y-2`,children:[s.map(({key:t,label:n,desc:r})=>(0,K.jsxs)(`label`,{className:`flex items-center justify-between cursor-pointer group`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:n}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r})]}),(0,K.jsx)(`div`,{className:`relative w-10 h-5 rounded-full transition-colors ${e[t]?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,onClick:()=>c(t),children:(0,K.jsx)(`div`,{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white transition-transform ${e[t]?`translate-x-5`:`translate-x-0.5`}`})})]},t)),(0,K.jsxs)(`div`,{className:`pt-2 mt-1 border-t border-bambu-dark-tertiary/60`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,K.jsx)(ic,{className:`w-3.5 h-3.5 text-amber-400`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:i(`settings.preheatTitle`,`Preheat & Heat Soak`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:i(`settings.preheatPerItemDesc`,`Heat the bed and chamber before this print starts. Defaults to the global Settings → Workflow toggle.`)}),(0,K.jsx)(`div`,{className:`flex gap-1.5 mb-2`,children:[`inherit`,`on`,`off`].map(t=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>l(t),className:`flex-1 px-2 py-1.5 text-xs rounded transition-colors ${e.preheat_override===t?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:i(`settings.preheatOverride_${t}`,t===`inherit`?`Inherit`:t===`on`?`On`:`Off`)},t))}),e.preheat_override!==`off`&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray flex-1`,children:i(`settings.preheatTargetOverride`,`Chamber target override (°C, blank = filament default)`)}),(0,K.jsx)(`input`,{type:`number`,min:0,max:60,step:1,value:e.preheat_chamber_target_override??``,onChange:e=>u(e.target.value),placeholder:`—`,className:`w-16 px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-white text-xs text-right focus:outline-none focus:border-bambu-green`})]})]})]})]})}function Dke({options:e,onChange:t,dateFormat:n=`system`,timeFormat:r=`system`,canControlPrinter:i=!0,showStagger:a=!1,printerCount:o=0,hasGcodeSnippets:s=!1}){let{t:c}=W(),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!0),[h,g]=(0,y.useState)(!0),_=(0,y.useRef)(null),v=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(e.scheduleType!==`scheduled`){v.current=!1;return}if(!v.current){v.current=!0;let i;e.scheduledTime?(i=new Date(e.scheduledTime),isNaN(i.getTime())&&(i=new Date,i.setHours(i.getHours()+1,0,0,0))):(i=new Date,i.setHours(i.getHours()+1,0,0,0),t({...e,scheduledTime:Sf(i)})),u(gf(i,n)),f(_f(i,r)),m(!0),g(!0)}},[e.scheduleType,e.scheduledTime,n,r,t,e]);let b=n=>{t({...e,scheduleType:n,requireManualStart:n===`queue`?e.requireManualStart:!1})},x=(r,i)=>{let a=bf(r,n),o=xf(i);m(!!a),g(!!o),a&&o&&(a.setHours(o.hours,o.minutes,0,0),a>new Date&&t({...e,scheduledTime:Sf(a)}))},S=e=>{u(e),x(e,d)},C=e=>{f(e),x(l,e)};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:c(`printModal.whenToPrint`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${e.scheduleType===`asap`?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,onClick:()=>b(`asap`),children:[(0,K.jsx)(xs,{className:`w-4 h-4`}),c(`printModal.asap`)]}),(0,K.jsxs)(`button`,{type:`button`,className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${e.scheduleType===`queue`?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,onClick:()=>b(`queue`),children:[(0,K.jsx)(Hc,{className:`w-4 h-4`}),c(`printModal.queue`)]}),(0,K.jsxs)(`button`,{type:`button`,className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${e.scheduleType===`scheduled`?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,onClick:()=>b(`scheduled`),children:[(0,K.jsx)(Xo,{className:`w-4 h-4`}),c(`printModal.schedule`)]})]})]}),e.scheduleType===`scheduled`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:c(`printModal.dateTime`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex-1 relative`,children:[(0,K.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 pr-10 bg-bambu-dark border rounded-lg text-white focus:outline-none ${p?`border-bambu-dark-tertiary focus:border-bambu-green`:`border-red-500`}`,value:l,onChange:e=>S(e.target.value),placeholder:mf(n)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{_.current?.showPicker()},className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,title:c(`printModal.openCalendar`),children:(0,K.jsx)(Xo,{className:`w-4 h-4`})}),(0,K.jsx)(`input`,{ref:_,type:`datetime-local`,className:`absolute top-0 left-0 w-0 h-0 opacity-0 pointer-events-none`,value:e.scheduledTime,onChange:i=>{let a=i.target.value;if(a){let i=new Date(a);isNaN(i.getTime())||(u(gf(i,n)),f(_f(i,r)),m(!0),g(!0),t({...e,scheduledTime:a}))}},tabIndex:-1})]}),(0,K.jsx)(`div`,{className:`w-32`,children:(0,K.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border rounded-lg text-white focus:outline-none ${h?`border-bambu-dark-tertiary focus:border-bambu-green`:`border-red-500`}`,value:d,onChange:e=>C(e.target.value),placeholder:hf(r)})})]}),(!p||!h)&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-400`,children:c(`printModal.invalidDateTime`)})]}),e.scheduleType===`queue`&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`requireManualStart`,checked:e.requireManualStart,onChange:n=>t({...e,requireManualStart:n.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`label`,{htmlFor:`requireManualStart`,className:`text-sm flex items-center gap-1 text-bambu-gray`,children:[(0,K.jsx)(Sc,{className:`w-3.5 h-3.5`}),c(`printModal.requireManualStart`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`requirePrevious`,checked:e.requirePreviousSuccess,onChange:n=>t({...e,requirePreviousSuccess:n.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsx)(`label`,{htmlFor:`requirePrevious`,className:`text-sm text-bambu-gray`,children:c(`printModal.requirePreviousSuccess`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`autoOffAfter`,checked:e.autoOffAfter,onChange:n=>t({...e,autoOffAfter:n.target.checked}),disabled:!i,className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green disabled:opacity-50`}),(0,K.jsxs)(`label`,{htmlFor:`autoOffAfter`,className:`text-sm flex items-center gap-1 ${i?`text-bambu-gray`:`text-bambu-gray/50`}`,children:[(0,K.jsx)(Cl,{className:`w-3.5 h-3.5`}),c(`printModal.autoOffAfter`)]})]}),s&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`gcodeInjection`,checked:e.gcodeInjection,onChange:n=>t({...e,gcodeInjection:n.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`label`,{htmlFor:`gcodeInjection`,className:`text-sm flex items-center gap-1 text-bambu-gray`,children:[(0,K.jsx)(Ts,{className:`w-3.5 h-3.5`}),c(`printModal.gcodeInjection`,`Inject auto-print G-code`)]})]}),a&&e.scheduleType!==`queue`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,id:`staggerEnabled`,checked:e.staggerEnabled,onChange:n=>t({...e,staggerEnabled:n.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,K.jsxs)(`label`,{htmlFor:`staggerEnabled`,className:`text-sm flex items-center gap-1 text-bambu-gray`,children:[(0,K.jsx)(Lc,{className:`w-3.5 h-3.5`}),c(`printModal.staggerPrinterStarts`,`Stagger printer starts`)]})]}),e.staggerEnabled&&(0,K.jsxs)(`div`,{className:`ml-6 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:c(`printModal.staggerGroupSize`,`Group size`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:o,value:e.staggerGroupSize,onChange:n=>t({...e,staggerGroupSize:Math.max(1,parseInt(n.target.value)||1)}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:c(`printModal.staggerInterval`,`Interval (min)`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:60,value:e.staggerIntervalMinutes,onChange:n=>t({...e,staggerIntervalMinutes:Math.max(1,parseInt(n.target.value)||1)}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`})]})]}),o>0&&(()=>{let t=Math.ceil(o/e.staggerGroupSize),n=o%e.staggerGroupSize,r=(t-1)*e.staggerIntervalMinutes;return(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[c(`printModal.staggerPreview`,`{{printers}} printers → {{groups}} groups of {{size}}, starting every {{interval}} min`,{printers:o,groups:t,size:e.staggerGroupSize,interval:e.staggerIntervalMinutes}),n!==0&&e.staggerGroupSize1?` (${c(`printModal.staggerTotal`,`total: {{minutes}} min`,{minutes:r})})`:``]})})()]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.scheduleType===`asap`?c(`printModal.helpAsap`):e.scheduleType===`scheduled`?c(`printModal.helpSchedule`):c(`printModal.helpQueue`)})]})}var aW={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1,nozzle_offset_cali:!0,preheat_override:`inherit`,preheat_chamber_target_override:null},oW={scheduleType:`asap`,scheduledTime:``,requireManualStart:!1,requirePreviousSuccess:!1,autoOffAfter:!1,gcodeInjection:!1,staggerEnabled:!1,staggerGroupSize:2,staggerIntervalMinutes:5};function sW({mode:e,archiveId:t,libraryFileId:n,archiveName:r,queueItem:i,initialSelectedPrinterIds:a,onClose:o,onSuccess:s,projectId:c,cleanupLibraryAfterDispatch:l}){let{t:u}=W(),d=no(),{showToast:f}=Dd(),{hasPermission:p}=pd(),m=!!n&&!t,h=e===`edit-queue-item`,[g,_]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.printer_id?[i.printer_id]:a?.length?a:[]),[v,b]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.plate_id!=null?new Set([i.plate_id]):new Set),x=v.size===1?[...v][0]:null,[S,C]=(0,y.useState)(1),[w,T]=(0,y.useState)(()=>e===`edit-queue-item`&&i?{bed_levelling:i.bed_levelling??aW.bed_levelling,flow_cali:i.flow_cali??aW.flow_cali,vibration_cali:i.vibration_cali??aW.vibration_cali,layer_inspect:i.layer_inspect??aW.layer_inspect,timelapse:i.timelapse??aW.timelapse,nozzle_offset_cali:i.nozzle_offset_cali??aW.nozzle_offset_cali,preheat_override:i.preheat_override??aW.preheat_override,preheat_chamber_target_override:i.preheat_chamber_target_override??aW.preheat_chamber_target_override}:aW),[E,D]=(0,y.useState)(()=>{if(e===`edit-queue-item`&&i){let e=`queue`;i.scheduled_time&&!Yf(i.scheduled_time)&&(e=`scheduled`);let t=``;return i.scheduled_time&&!Yf(i.scheduled_time)&&(t=Sf(wf(i.scheduled_time)??new Date)),{scheduleType:e,scheduledTime:t,requireManualStart:i.manual_start,requirePreviousSuccess:i.require_previous_success,autoOffAfter:i.auto_off_after,gcodeInjection:i.gcode_injection??!1,staggerEnabled:!1,staggerGroupSize:oW.staggerGroupSize,staggerIntervalMinutes:oW.staggerIntervalMinutes}}return oW}),[O,k]=(0,y.useState)(()=>{if(e===`edit-queue-item`&&i?.ams_mapping&&Array.isArray(i.ams_mapping)){let e={};return i.ams_mapping.forEach((t,n)=>{t!==-1&&(e[n+1]=t)}),e}return{}}),[A,j]=(0,y.useState)({}),[M,N]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.target_model?`model`:`printer`),[P,F]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.target_model?i.target_model:null),[I,L]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.target_location?i.target_location:null),[R,z]=(0,y.useState)(()=>{if(e===`edit-queue-item`&&i?.filament_overrides){let e={};for(let t of i.filament_overrides)e[t.slot_id]={type:t.type,color:t.color};return e}return{}}),[B,V]=(0,y.useState)(()=>{if(e===`edit-queue-item`&&i?.filament_overrides){let e={};for(let t of i.filament_overrides)e[t.slot_id]=t.force_color_match===!0;return e}return{}}),[ee]=(0,y.useState)(()=>e===`edit-queue-item`&&i?.printer_id?[i.printer_id]:[]),[te]=(0,y.useState)(()=>e===`edit-queue-item`&&i?i.plate_id:null),[ne,re]=(0,y.useState)(!1),[ie,H]=(0,y.useState)({current:0,total:0}),[ae,oe]=(0,y.useState)(null),[U,se]=(0,y.useState)(new Set),ce=g.length,le=g.length>0?g[0]:null,{data:ue}=q({queryKey:[`settings`],queryFn:Q.getSettings}),de=(0,y.useRef)(!1);(0,y.useEffect)(()=>{!ue||de.current||e===`edit-queue-item`||(de.current=!0,T({bed_levelling:ue.default_bed_levelling??aW.bed_levelling,flow_cali:ue.default_flow_cali??aW.flow_cali,vibration_cali:ue.default_vibration_cali??aW.vibration_cali,layer_inspect:ue.default_layer_inspect??aW.layer_inspect,timelapse:ue.default_timelapse??aW.timelapse,nozzle_offset_cali:ue.default_nozzle_offset_cali??aW.nozzle_offset_cali,preheat_override:aW.preheat_override,preheat_chamber_target_override:aW.preheat_chamber_target_override}))},[ue,e]);let fe=(0,y.useRef)(!1);(0,y.useEffect)(()=>{!ue||fe.current||e===`edit-queue-item`||(fe.current=!0,D(e=>({...e,staggerGroupSize:ue.stagger_group_size??e.staggerGroupSize,staggerIntervalMinutes:ue.stagger_interval_minutes??e.staggerIntervalMinutes})))},[ue,e]);let pe=of(ue?.currency||`USD`),me=ue?.default_filament_cost??0,{data:he,isLoading:ge}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:_e}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),staleTime:30*1e3,enabled:!h&&M===`printer`}),ve=_o({queries:g.map(e=>({queryKey:[`printer-inventory-remain`,e],queryFn:()=>Q.getInventoryRemain(e),staleTime:30*1e3,enabled:g.length>0}))}),ye=(0,y.useMemo)(()=>{let e=new Map;return g.forEach((t,n)=>{let r=ve[n]?.data?.inventory_remain_g;if(!r)return;let i=new Map;Object.entries(r).forEach(([e,t])=>{let n=Number(e);Number.isNaN(n)||i.set(n,t)}),e.set(t,i)}),e},[g,ve]),{data:be}=q({queryKey:[`archive`,t],queryFn:()=>Q.getArchive(t),enabled:!!t&&!m}),{data:xe}=q({queryKey:[`library-file`,n],queryFn:()=>Q.getLibraryFile(n),enabled:m&&!!n}),Se=be?.sliced_for_model||xe?.sliced_for_model||null,{data:Ce,isError:we}=q({queryKey:[`archive-plates`,t],queryFn:()=>Q.getArchivePlates(t),enabled:!!t&&!m,retry:!1}),{data:Te}=q({queryKey:[`library-file-plates`,n],queryFn:()=>Q.getLibraryFilePlates(n),enabled:m&&!!n}),Ee=m?Te:Ce,{data:De,isError:Oe}=q({queryKey:[`archive-filaments`,t,x],queryFn:()=>Q.getArchiveFilamentRequirements(t,x??void 0),enabled:!!t&&!m&&(x!==null||!Ee?.is_multi_plate),retry:!1}),{data:ke}=q({queryKey:[`library-file-filaments`,n,x],queryFn:()=>Q.getLibraryFileFilamentRequirements(n,x??void 0),enabled:m&&!!n&&(x!==null||!Ee?.is_multi_plate)}),Ae=!m&&(we||Oe),je=m?ke:De,{data:Me}=q({queryKey:[`available-filaments`,P,I],queryFn:()=>Q.getAvailableFilaments(P,I??void 0),enabled:M===`model`&&!!P}),{data:Ne}=q({queryKey:[`printer-status`,le],queryFn:()=>Q.getPrinterStatus(le),enabled:!!le}),Pe=$f(ue?.prefer_lowest_filament,Ne?.ams_filament_backup),Fe=e=>!e?.connected||e.awaiting_plate_clear||e.ams?.some(e=>e.dry_time>0)?!1:[`IDLE`,`FINISH`,`FAILED`].includes(e.state??``),Ie=async()=>{if(E.scheduleType!==`asap`||M!==`printer`||g.length===0)return!1;try{return(await Promise.all(g.map(e=>d.fetchQuery({queryKey:[`printer-status`,e],queryFn:()=>Q.getPrinterStatus(e),staleTime:0})))).some(e=>!Fe(e))}catch{return!0}},{amsMapping:Le}=eW(je,Ne,O,Pe,le?ye.get(le):void 0),Re=_ke(g,he,je,O,A,j,ue?.prefer_lowest_filament,ye);(0,y.useEffect)(()=>{Ee?.plates&&Ee.plates.length>=1&&v.size===0&&b(new Set([Ee.plates[0].index]))},[Ee,v.size]),(0,y.useEffect)(()=>{if(e===`edit-queue-item`)return;let t=he?.filter(e=>e.is_active)||[];t.length===1&&g.length===0&&_([t[0].id])},[e,he,g.length]),(0,y.useEffect)(()=>{e===`edit-queue-item`?(JSON.stringify(g.sort())!==JSON.stringify(ee.sort())||x!==te)&&(k({}),j({}),se(new Set)):(k({}),j({}),se(new Set))},[e,g,x,ee,te]);let[ze,Be]=(0,y.useState)(P),[Ve,He]=(0,y.useState)(x);(0,y.useEffect)(()=>{(P!==ze||x!==Ve)&&(Be(P),He(x),(e!==`edit-queue-item`||ze!==null)&&(z({}),V({})))},[P,x,ze,Ve,e]),(0,y.useEffect)(()=>{if(!ue?.per_printer_mapping_expanded||g.length<=1)return;let e=g.filter(e=>{if(U.has(e))return!1;let t=Re.printerResults.find(t=>t.printerId===e);return t&&t.status&&!t.isLoading});e.length>0&&(se(t=>{let n=new Set(t);return e.forEach(e=>n.add(e)),n}),e.forEach(e=>{Re.autoConfigurePrinter(e)}))},[ue?.per_printer_mapping_expanded,g,U,Re]),(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!ne&&o()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o,ne]);let Ue=Ee?.is_multi_plate??!1,We=Ee?.plates??[],Ge=(0,y.useMemo)(()=>{let e=new Map;return _e&&_e.forEach(t=>{let n=t.ams_id===255,r=Uf(t.ams_id,t.tray_id,n),i=e.get(t.printer_id)??new Map;i.set(r,t),e.set(t.printer_id,i)}),e},[_e]),Ke=(0,y.useMemo)(()=>{if(!ae||ae.length===0)return``;let e=ae.map(e=>u(`printModal.insufficientFilamentLine`,{printer:e.printerName,slot:e.slotLabel,required:Math.round(e.requiredGrams),remaining:Math.round(e.remainingGrams)}));return[u(`printModal.insufficientFilamentMessage`),...e].join(` -`)},[ae,u]),qe=J({mutationFn:e=>Q.addToQueue(e)}),Je=J({mutationFn:e=>Q.updateQueueItem(i.id,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`queue`]}),f(`Queue item updated`),s?.(),o()},onError:e=>{f(e.message||`Failed to update queue item`,`error`)}}),Ye=async(i,a)=>{if(i?.preventDefault(),!a?.skipFilamentCheck&&!ue?.disable_filament_warnings&&!h&&M===`printer`){let e=[],t=je?.filaments??[];if(t.length>0&&Ge.size>0){let n=(e,t)=>!Number.isFinite(e)||e<=0||!Number.isFinite(t)||t<0?null:Math.max(0,e-t);for(let r of g){let i=g.length>1?Re.getFinalMapping(r):Le;if(!i)continue;let a=QU(g.length>1?Re.printerResults.find(e=>e.printerId===r)?.status:Ne),o=new Map(a.map(e=>[e.globalTrayId,e.label])),s=Ge.get(r),c=he?.find(e=>e.id===r)?.name??`Printer ${r}`;s&&t.forEach(t=>{if(!t.slot_id||t.slot_id<=0)return;let r=i[t.slot_id-1];if(!Number.isFinite(r)||r<0)return;let a=s.get(r)?.spool;if(!a)return;let l=n(a.label_weight,a.weight_used);l!==null&&(l>=t.used_grams||e.push({printerName:c,slotLabel:o.get(r)??`Slot ${t.slot_id}`,requiredGrams:t.used_grams,remainingGrams:l}))})}}if(e.length>0){oe(e);return}}if(M===`printer`&&g.length===0){f(`Please select at least one printer`,`error`);return}if(M===`model`&&!P){f(`Please select a target printer model`,`error`);return}re(!0);let p=v.size>1?We.filter(e=>v.has(e.index)):[null],_=M===`model`?p.length:g.length*p.length;H({current:0,total:_});let y={success:0,failed:0,errors:[]},b=e=>{if(g.length>1){let t=A[e];if(t&&!t.useDefault)return Re.getFinalMapping(e)}return Le},S=(()=>{let e=[];if(je?.filaments)for(let t of je.filaments){let n=R[t.slot_id],r=B[t.slot_id]??!1,i=n?.type??t.type,a=n?.color??t.color;(n||r)&&e.push({slot_id:t.slot_id,type:i,color:a,color_name:Zd(a),force_color_match:r})}else for(let[t,{type:n,color:r}]of Object.entries(R)){let i=parseInt(t,10),a=B[i]??!1;e.push({slot_id:i,type:n,color:r,color_name:Zd(r),force_color_match:a})}return e.length>0?e:void 0})(),C=e===`create`&&p.length>1&&(M===`model`||g.length===1),T=null;if(C)try{let e=`${(r||``).replace(/\.gcode\.3mf$/i,``).replace(/\.3mf$/i,``)||`Batch`} · ${p.length} plates`;T=(await Q.createBatch({name:e,archive_id:m?void 0:t,library_file_id:m?n:void 0})).id}catch{T=null}let D=new Map,O=(e,t,n=1)=>{if(E.scheduleType!==`asap`)return;let r=t===null?`unassigned`:`printer:${t}`,i=(D.get(r)??0)+1;e.insert_at_top=!0,e.insert_position=i,D.set(r,i+n-1)},k=(e,r)=>({printer_id:M===`printer`?e:null,target_model:M===`model`?P:null,target_location:M===`model`?I:null,filament_overrides:M===`model`?S:void 0,archive_id:m?void 0:t,library_file_id:m?n:void 0,require_previous_success:E.requirePreviousSuccess,auto_off_after:E.autoOffAfter,gcode_injection:E.gcodeInjection,manual_start:E.scheduleType===`queue`&&E.requireManualStart,skip_filament_check:a?.skipFilamentCheck===!0?!0:void 0,ams_mapping:e?b(e):void 0,plate_id:r===void 0?x:r,scheduled_time:E.scheduleType===`scheduled`&&E.scheduledTime?new Date(E.scheduledTime).toISOString():void 0,...w,project_id:c??void 0,batch_id:T??void 0,cleanup_library_after_dispatch:l});if(M===`model`){let t=0;for(let n of p){t++,H({current:t,total:_});let r=n?n.index:x;try{if(e===`edit-queue-item`&&!n){let e={printer_id:null,target_model:P,target_location:I,filament_overrides:S||null,require_previous_success:E.requirePreviousSuccess,auto_off_after:E.autoOffAfter,gcode_injection:E.gcodeInjection,manual_start:E.scheduleType===`queue`&&E.requireManualStart,ams_mapping:void 0,plate_id:r,scheduled_time:E.scheduleType===`scheduled`&&E.scheduledTime?new Date(E.scheduledTime).toISOString():null,...w};await Je.mutateAsync(e)}else{let e=k(null,r);Qe>1&&(e.quantity=Qe),O(e,null,Qe),await qe.mutateAsync(e)}y.success++}catch(e){y.failed++;let t=n?n.name||`Plate ${n.index}`:``;y.errors.push(t?`${t}: ${e.message}`:e.message)}}}else{let e=E.staggerEnabled&&!h&&g.length>1,t=e?E.scheduleType===`scheduled`&&E.scheduledTime?new Date(E.scheduledTime).getTime():Date.now():0,n=0;for(let r of p){let i=r?r.index:x;for(let a=0;a1&&(n.quantity=Qe),O(n,o,Qe),e){let e=Math.floor(a/E.staggerGroupSize);if(e>0){let r=e*E.staggerIntervalMinutes*6e4;n.scheduled_time=new Date(t+r).toISOString()}}await qe.mutateAsync(n)}y.success++}catch(e){y.failed++;let t=he?.find(e=>e.id===o)?.name||`Printer ${o}`,n=r?r.name||`Plate ${r.index}`:``,i=n?`${t} (${n})`:t;y.errors.push(`${i}: ${e.message}`)}}}}re(!1),y.failed===0?(h?e===`edit-queue-item`&&f(`Queue item updated`):y.success===1?f(await Ie()?u(`queue.printQueuedWillStartWhenIdle`):M===`model`?`Queued for any ${P}`:u(`queue.printQueued`)):f(await Ie()?u(`queue.printQueuedWillStartWhenIdle`):u(`queue.itemsQueued`,{count:y.success})),d.invalidateQueries({queryKey:[`queue`]}),s?.(),o()):y.success===0?f(`Failed: ${y.errors[0]}`,`error`):(f(`${y.success} succeeded, ${y.failed} failed`,`error`),d.invalidateQueries({queryKey:[`queue`]}))},Xe=ne||Je.isPending,Ze=(0,y.useMemo)(()=>!(Xe||M===`printer`&&g.length===0||M===`model`&&!P||Ue&&v.size===0),[g.length,M,P,Ue,v.size,Xe]),Qe=M===`printer`&&g.length>1?1:S;(0,y.useEffect)(()=>{e===`create`&&E.gcodeInjection&&!ue?.gcode_snippets&&D(e=>({...e,gcodeInjection:!1}))},[e,ue?.gcode_snippets,E.gcodeInjection]);let $e=h?{title:u(`queue.editQueueItem`),icon:_l,submitText:u(`common.save`),submitIcon:_l,loadingText:ie.total>1?u(`queue.savingProgress`,{current:ie.current,total:ie.total}):u(`common.saving`)}:{title:u(`common.print`),icon:wl,submitText:u(`common.print`),submitIcon:wl,loadingText:ie.total>1?u(`queue.addingProgress`,{current:ie.current,total:ie.total}):u(`queue.adding`)},et=$e.icon,tt=$e.submitIcon,nt=le&&v.size<=1&&(m||(Ue?x!==null:!0)),rt=(0,y.useMemo)(()=>new Set([`H2D`,`H2DPRO`,`H2C`,`X2D`]),[]),it=(0,y.useMemo)(()=>M===`model`?P?rt.has(P.toUpperCase().replace(/[\s-]/g,``)):!1:!he||g.length===0?!1:g.some(e=>he.find(t=>t.id===e)?.nozzle_count===2),[M,P,he,g,rt]);return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:ne?void 0:o,children:[(0,K.jsx)(yd,{className:`w-full max-w-2xl max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(xd,{className:`p-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(et,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:$e.title})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:o,disabled:ne,children:(0,K.jsx)(Bu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`form`,{onSubmit:Ye,className:`p-4 space-y-4`,children:[(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`block text-bambu-gray mb-1`,children:`Print Job`}),(0,K.jsx)(`span`,{className:`text-white font-medium truncate block`,children:r})]}),(()=>{if(!We.length)return null;let e=rW((x==null?We[0]:We.find(e=>e.index===x))?.bed_type);return e?(0,K.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-bambu-gray -mt-2`,title:e.label,children:[(0,K.jsx)(`img`,{src:e.icon,alt:``,className:`w-4 h-4 object-contain flex-shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:e.label})]}):null})(),(0,K.jsx)(Ske,{plates:We,isMultiPlate:Ue,selectedPlates:v,onToggle:e=>{b(t=>{let n=new Set(t);return h?(n.clear(),n.add(e)):n.has(e)?n.delete(e):n.add(e),n})},onSelectAll:h?void 0:()=>b(new Set(We.map(e=>e.index))),onDeselectAll:h?void 0:()=>b(new Set),multiSelect:!h}),!a?.length&&(0,K.jsx)(Tke,{printers:he||[],selectedPrinterIds:g,onMultiSelect:_,isLoading:ge,allowMultiple:!0,showInactive:e===`edit-queue-item`,disableBusy:!1,printerMappingResults:Re.printerResults,filamentReqs:je,onAutoConfigurePrinter:Re.autoConfigurePrinter,onUpdatePrinterConfig:Re.updatePrinterConfig,assignmentMode:M,onAssignmentModeChange:h?void 0:N,targetModel:P,onTargetModelChange:h?void 0:F,targetLocation:I,onTargetLocationChange:h?void 0:L,slicedForModel:Se}),M===`model`&&P&&je&&Me&&Me.length>0&&(0,K.jsx)(xke,{filamentReqs:je,availableFilaments:Me,overrides:R,onChange:z,forceColorMatch:B,onForceColorMatchChange:(e,t)=>V(n=>({...n,[e]:t}))}),Se&&M===`printer`&&g.length===1&&(()=>{let e=he?.find(e=>e.id===g[0]);return e&&e.model&&Se!==e.model?(0,K.jsxs)(`div`,{className:`p-3 mb-2 bg-yellow-500/10 border border-yellow-500/30 rounded-lg flex items-center gap-2`,children:[(0,K.jsx)(Su,{className:`w-4 h-4 text-yellow-400 flex-shrink-0`}),(0,K.jsxs)(`span`,{className:`text-sm text-yellow-400`,children:[`File was sliced for `,Se,`, but printing on `,e.model]})]}):null})(),Ae&&(0,K.jsxs)(`div`,{className:`flex items-start gap-2 p-3 mb-2 bg-orange-500/10 border border-orange-500/30 rounded-lg text-sm`,children:[(0,K.jsx)(us,{className:`w-4 h-4 text-orange-400 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`p`,{className:`text-orange-400`,children:`Archive data unavailable. The source file may have been deleted. Filament mapping is disabled.`})]}),nt&&!Ae&&g.length===1&&(0,K.jsx)(bke,{printerId:le,filamentReqs:je,manualMappings:O,onManualMappingChange:k,defaultExpanded:!!a?.length||(ue?.per_printer_mapping_expanded??!1),currencySymbol:pe,defaultCostPerKg:me,forceColorMatch:B,onForceColorMatchChange:(e,t)=>V(n=>({...n,[e]:t}))}),(e===`create`||ce>0||M===`model`&&P)&&(0,K.jsx)(Eke,{options:w,onChange:T,defaultExpanded:!!a?.length,showDualNozzleOptions:it}),e!==`edit-queue-item`&&(M===`model`||g.length<=1)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`label`,{htmlFor:`printQuantity`,className:`text-sm text-bambu-gray whitespace-nowrap`,children:u(`queue.quantity`,`Quantity`)}),(0,K.jsx)(`input`,{id:`printQuantity`,type:`number`,min:1,max:999,value:S,onChange:e=>C(Math.max(1,Math.min(999,parseInt(e.target.value)||1))),className:`w-20 px-2 py-1 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green`}),S>1&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:u(`queue.quantityHint`,`Creates {{count}} queue items`,{count:S})})]}),(0,K.jsx)(Dke,{options:E,onChange:D,dateFormat:ue?.date_format||`system`,timeFormat:ue?.time_format||`system`,canControlPrinter:p(`printers:control`),showStagger:!h&&M===`printer`&&g.length>1,printerCount:g.length,hasGcodeSnippets:!!ue?.gcode_snippets}),Je.isError&&(0,K.jsx)(`div`,{className:`mb-4 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400`,children:Je.error?.message||`Failed to complete operation`}),(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:o,className:`flex-1`,disabled:ne,children:`Cancel`}),(0,K.jsx)($,{type:`submit`,disabled:!Ze,className:`flex-1`,children:Xe?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),$e.loadingText]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(tt,{className:`w-4 h-4`}),$e.submitText]})})]})]})]})}),ae&&ae.length>0&&(0,K.jsx)(Id,{title:u(`printModal.insufficientFilamentTitle`),message:Ke,confirmText:u(`printModal.printAnyway`),cancelText:u(`common.cancel`),variant:`warning`,onConfirm:()=>{oe(null),Ye(void 0,{skipFilamentCheck:!0})},onCancel:()=>oe(null)})]})}function cW({value:e}){let{t}=W(),[n,r]=(0,y.useState)(!1);return(0,K.jsx)(`button`,{onClick:async()=>{try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(e);else{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{if(t.select(),!document.execCommand(`copy`))return}finally{document.body.removeChild(t)}}r(!0),setTimeout(()=>r(!1),2e3)}catch{}},className:`ml-2 p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,title:t(n?`printers.copied`:`printers.copyToClipboard`),children:n?(0,K.jsx)(ns,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,K.jsx)(js,{className:`w-3.5 h-3.5`})})}function Oke({printer:e,status:t,totalPrintHours:n,onClose:r}){let{t:i}=W();(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let a=[];if(a.push({label:i(`printers.model`),value:e.model??`—`}),a.push({label:i(`common.status`),value:(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-xs font-medium ${t?.connected?`bg-bambu-green/20 text-bambu-green`:`bg-red-500/20 text-red-400`}`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${t?.connected?`bg-bambu-green`:`bg-red-400`}`}),t?.connected?i(`printers.status.available`):i(`printers.status.offline`)]})}),t?.state&&a.push({label:i(`printers.state`),value:i({IDLE:`printers.status.idle`,RUNNING:`printers.status.printing`,PAUSE:`printers.status.paused`,FINISH:`printers.status.finished`,FAILED:`printers.status.error`}[t.state]??`printers.status.unknown`)}),a.push({label:i(`printers.ipAddress`),value:(0,K.jsxs)(`span`,{className:`flex items-center`,children:[(0,K.jsx)(`span`,{className:`font-mono`,children:e.ip_address}),(0,K.jsx)(cW,{value:e.ip_address})]})}),a.push({label:i(`printers.serialNumber`),value:(0,K.jsxs)(`span`,{className:`flex items-center`,children:[(0,K.jsx)(`span`,{className:`font-mono truncate`,children:e.serial_number}),(0,K.jsx)(cW,{value:e.serial_number})]})}),t?.wired_network)a.push({label:i(`printers.networkLabel`,`Network`),value:(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(qo,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-bambu-green`,children:i(`printers.connection.ethernet`,`Ethernet`)})]})});else if(t?.wifi_signal!=null){let e=xT(t.wifi_signal);a.push({label:i(`printers.wifiSignalLabel`),value:(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Jl,{className:`w-4 h-4 ${e.color}`}),(0,K.jsx)(`span`,{className:e.color,children:i(e.labelKey)}),(0,K.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[`(`,t.wifi_signal,` dBm)`]})]})})}return a.push({label:i(`printers.firmware`),value:t?.firmware_version??`—`}),t?.developer_mode!=null&&a.push({label:i(`printers.developerMode`),value:(0,K.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${t.developer_mode?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:t.developer_mode?i(`printers.enabled`):i(`printers.disabled`)})}),a.push({label:i(`printers.nozzleCount`),value:e.nozzle_count}),a.push({label:i(`printers.autoArchive`),value:(0,K.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${e.auto_archive?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:e.auto_archive?i(`printers.enabled`):i(`printers.disabled`)})}),n!=null&&n>0&&a.push({label:i(`printers.totalPrintHours`),value:`${Math.round(n)}h`}),e.location&&a.push({label:i(`printers.sort.location`),value:e.location}),a.push({label:i(`printers.addedOn`),value:Tf(e.created_at)}),(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,onClick:r,children:(0,K.jsx)(yd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(xd,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e.name}),(0,K.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-bambu-dark rounded flex-shrink-0`,children:(0,K.jsx)(Bu,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,K.jsx)(`img`,{src:bT(e.model),alt:e.model??e.name,className:`h-24 object-contain`})}),(0,K.jsx)(`div`,{className:`space-y-0`,children:a.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-2.5 border-b border-bambu-dark-tertiary last:border-0`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray whitespace-nowrap`,children:e.label}),(0,K.jsx)(`span`,{className:`text-sm text-white text-right`,children:e.value})]},t))})]})})})}function kke(e){if(!e||e.length<6)return!1;let t=parseInt(e.slice(0,2),16),n=parseInt(e.slice(2,4),16),r=parseInt(e.slice(4,6),16);return(.299*t+.587*n+.114*r)/255>.6}function lW({trayColor:e,trayType:t,isEmpty:n,emptyKind:r,slotNumber:i}){let a=r===`reset`?`#3d3d3d`:`#666`;return(0,K.jsx)(`div`,{className:`w-3.5 h-3.5 rounded-full mx-auto mb-0.5 border-2 flex items-center justify-center`,style:{backgroundColor:e?`#${e}`:t?`#333`:`transparent`,borderColor:n?a:`rgba(255,255,255,0.1)`,borderStyle:n?`dashed`:`solid`},children:(0,K.jsx)(`span`,{className:`text-[6px] font-bold leading-none select-none`,style:{color:e&&kke(e)?`#000`:`#fff`},children:i})})}var uW=240,dW=320;function fW(e){return(e??.02).toFixed(3)}function pW({side:e}){let{mode:t}=gd();return(0,K.jsx)(`span`,{className:`inline-flex items-center justify-center w-4 h-4 text-[10px] font-bold rounded`,style:{backgroundColor:t===`dark`?`#1a4d2e`:`#e7f5e9`,color:`#00ae42`},children:e})}function mW(e,t){if(!e)return``;if(e.includes(`hardened`))return t(`printers.nozzleHardenedSteel`);if(e.includes(`stainless`))return t(`printers.nozzleStainlessSteel`);if(e.includes(`tungsten`))return t(`printers.nozzleTungstenCarbide`);if(e.length>=4){let n=e.slice(2,4);if(n===`00`)return t(`printers.nozzleStainlessSteel`);if(n===`01`)return t(`printers.nozzleHardenedSteel`);if(n===`05`)return t(`printers.nozzleTungstenCarbide`)}return e===`00`?t(`printers.nozzleStainlessSteel`):e===`01`?t(`printers.nozzleHardenedSteel`):e===`05`?t(`printers.nozzleTungstenCarbide`):e.startsWith(`H`)?t(`printers.nozzleHardenedSteel`):e}function hW(e,t){return e?e.startsWith(`HH`)?t(`printers.nozzleHighFlow`):e.startsWith(`HS`)?t(`printers.nozzleStandardFlow`):``:``}function gW({slot:e,index:t,activeStatus:n,filamentName:r,children:i}){let{t:a}=W(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(`top`),u=(0,y.useRef)(null),d=(0,y.useRef)(null),f=(0,y.useRef)(null),p=!e.nozzle_diameter&&!e.nozzle_type,m=e.stat===1;(0,y.useEffect)(()=>{if(o&&u.current&&d.current){let e=u.current.getBoundingClientRect(),t=d.current.offsetHeight,n=e.top-56,r=window.innerHeight-e.bottom;nn?l(`bottom`):l(`top`)}},[o]);let h=()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>s(!0),80)},g=()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>s(!1),100)};(0,y.useEffect)(()=>()=>{f.current&&clearTimeout(f.current)},[]);let _=tf(e.filament_color),v=mW(e.nozzle_type,a),b=hW(e.nozzle_type,a);return(0,K.jsxs)(`div`,{ref:u,className:`relative`,onMouseEnter:h,onMouseLeave:g,children:[i,o&&(0,K.jsxs)(`div`,{ref:d,className:` +`)},[ae,u]),qe=J({mutationFn:e=>Q.addToQueue(e)}),Je=J({mutationFn:e=>Q.updateQueueItem(i.id,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`queue`]}),f(`Queue item updated`),s?.(),o()},onError:e=>{f(e.message||`Failed to update queue item`,`error`)}}),Ye=async(i,a)=>{if(i?.preventDefault(),!a?.skipFilamentCheck&&!ue?.disable_filament_warnings&&!h&&M===`printer`){let e=[],t=je?.filaments??[];if(t.length>0&&Ge.size>0){let n=(e,t)=>!Number.isFinite(e)||e<=0||!Number.isFinite(t)||t<0?null:Math.max(0,e-t);for(let r of g){let i=g.length>1?Re.getFinalMapping(r):Le;if(!i)continue;let a=QU(g.length>1?Re.printerResults.find(e=>e.printerId===r)?.status:Ne),o=new Map(a.map(e=>[e.globalTrayId,e.label])),s=Ge.get(r),c=he?.find(e=>e.id===r)?.name??`Printer ${r}`;s&&t.forEach(t=>{if(!t.slot_id||t.slot_id<=0)return;let r=i[t.slot_id-1];if(!Number.isFinite(r)||r<0)return;let a=s.get(r)?.spool;if(!a)return;let l=n(a.label_weight,a.weight_used);l!==null&&(l>=t.used_grams||e.push({printerName:c,slotLabel:o.get(r)??`Slot ${t.slot_id}`,requiredGrams:t.used_grams,remainingGrams:l}))})}}if(e.length>0){oe(e);return}}if(M===`printer`&&g.length===0){f(`Please select at least one printer`,`error`);return}if(M===`model`&&!P){f(`Please select a target printer model`,`error`);return}re(!0);let p=v.size>1?We.filter(e=>v.has(e.index)):[null],_=M===`model`?p.length:g.length*p.length;H({current:0,total:_});let y={success:0,failed:0,errors:[]},b=e=>{if(g.length>1){let t=A[e];if(t&&!t.useDefault)return Re.getFinalMapping(e)}return Le},S=(()=>{let e=[];if(je?.filaments)for(let t of je.filaments){let n=R[t.slot_id],r=B[t.slot_id]??!1,i=n?.type??t.type,a=n?.color??t.color;(n||r)&&e.push({slot_id:t.slot_id,type:i,color:a,color_name:Zd(a),force_color_match:r})}else for(let[t,{type:n,color:r}]of Object.entries(R)){let i=parseInt(t,10),a=B[i]??!1;e.push({slot_id:i,type:n,color:r,color_name:Zd(r),force_color_match:a})}return e.length>0?e:void 0})(),C=e===`create`&&p.length>1&&(M===`model`||g.length===1),T=null;if(C)try{let e=`${(r||``).replace(/\.gcode\.3mf$/i,``).replace(/\.3mf$/i,``)||`Batch`} · ${p.length} plates`;T=(await Q.createBatch({name:e,archive_id:m?void 0:t,library_file_id:m?n:void 0})).id}catch{T=null}let D=new Map,O=(e,t,n=1)=>{if(E.scheduleType!==`asap`)return;let r=t===null?`unassigned`:`printer:${t}`,i=(D.get(r)??0)+1;e.insert_at_top=!0,e.insert_position=i,D.set(r,i+n-1)},k=(e,r)=>({printer_id:M===`printer`?e:null,target_model:M===`model`?P:null,target_location:M===`model`?I:null,filament_overrides:M===`model`?S:void 0,archive_id:m?void 0:t,library_file_id:m?n:void 0,require_previous_success:E.requirePreviousSuccess,auto_off_after:E.autoOffAfter,gcode_injection:E.gcodeInjection,manual_start:E.scheduleType===`queue`&&E.requireManualStart,skip_filament_check:a?.skipFilamentCheck===!0?!0:void 0,ams_mapping:e?b(e):void 0,plate_id:r===void 0?x:r,scheduled_time:E.scheduleType===`scheduled`&&E.scheduledTime?new Date(E.scheduledTime).toISOString():void 0,...w,project_id:c??void 0,batch_id:T??void 0,cleanup_library_after_dispatch:l});if(M===`model`){let t=0;for(let n of p){t++,H({current:t,total:_});let r=n?n.index:x;try{if(e===`edit-queue-item`&&!n){let e={printer_id:null,target_model:P,target_location:I,filament_overrides:S||null,require_previous_success:E.requirePreviousSuccess,auto_off_after:E.autoOffAfter,gcode_injection:E.gcodeInjection,manual_start:E.scheduleType===`queue`&&E.requireManualStart,ams_mapping:void 0,plate_id:r,scheduled_time:E.scheduleType===`scheduled`&&E.scheduledTime?new Date(E.scheduledTime).toISOString():null,...w};await Je.mutateAsync(e)}else{let e=k(null,r);Qe>1&&(e.quantity=Qe),O(e,null,Qe),await qe.mutateAsync(e)}y.success++}catch(e){y.failed++;let t=n?n.name||`Plate ${n.index}`:``;y.errors.push(t?`${t}: ${e.message}`:e.message)}}}else{let e=E.staggerEnabled&&!h&&g.length>1,t=e?E.scheduleType===`scheduled`&&E.scheduledTime?new Date(E.scheduledTime).getTime():Date.now():0,n=0;for(let r of p){let i=r?r.index:x;for(let a=0;a1&&(n.quantity=Qe),O(n,o,Qe),e){let e=Math.floor(a/E.staggerGroupSize);if(e>0){let r=e*E.staggerIntervalMinutes*6e4;n.scheduled_time=new Date(t+r).toISOString()}}await qe.mutateAsync(n)}y.success++}catch(e){y.failed++;let t=he?.find(e=>e.id===o)?.name||`Printer ${o}`,n=r?r.name||`Plate ${r.index}`:``,i=n?`${t} (${n})`:t;y.errors.push(`${i}: ${e.message}`)}}}}re(!1),y.failed===0?(h?e===`edit-queue-item`&&f(`Queue item updated`):y.success===1?f(await Ie()?u(`queue.printQueuedWillStartWhenIdle`):M===`model`?`Queued for any ${P}`:u(`queue.printQueued`)):f(await Ie()?u(`queue.printQueuedWillStartWhenIdle`):u(`queue.itemsQueued`,{count:y.success})),d.invalidateQueries({queryKey:[`queue`]}),s?.(),o()):y.success===0?f(`Failed: ${y.errors[0]}`,`error`):(f(`${y.success} succeeded, ${y.failed} failed`,`error`),d.invalidateQueries({queryKey:[`queue`]}))},Xe=ne||Je.isPending,Ze=(0,y.useMemo)(()=>!(Xe||M===`printer`&&g.length===0||M===`model`&&!P||Ue&&v.size===0),[g.length,M,P,Ue,v.size,Xe]),Qe=M===`printer`&&g.length>1?1:S;(0,y.useEffect)(()=>{e===`create`&&E.gcodeInjection&&!ue?.gcode_snippets&&D(e=>({...e,gcodeInjection:!1}))},[e,ue?.gcode_snippets,E.gcodeInjection]);let $e=h?{title:u(`queue.editQueueItem`),icon:_l,submitText:u(`common.save`),submitIcon:_l,loadingText:ie.total>1?u(`queue.savingProgress`,{current:ie.current,total:ie.total}):u(`common.saving`)}:{title:u(`common.print`),icon:wl,submitText:u(`common.print`),submitIcon:wl,loadingText:ie.total>1?u(`queue.addingProgress`,{current:ie.current,total:ie.total}):u(`queue.adding`)},et=$e.icon,tt=$e.submitIcon,nt=le&&v.size<=1&&(m||(Ue?x!==null:!0)),rt=(0,y.useMemo)(()=>new Set([`H2D`,`H2DPRO`,`H2C`,`X2D`]),[]),it=(0,y.useMemo)(()=>M===`model`?P?rt.has(P.toUpperCase().replace(/[\s-]/g,``)):!1:!he||g.length===0?!1:g.some(e=>he.find(t=>t.id===e)?.nozzle_count===2),[M,P,he,g,rt]);return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:ne?void 0:o,children:[(0,K.jsx)(yd,{className:`w-full max-w-2xl max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(xd,{className:`p-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(et,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:$e.title})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:o,disabled:ne,children:(0,K.jsx)(Bu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`form`,{onSubmit:Ye,className:`p-4 space-y-4`,children:[(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`block text-bambu-gray mb-1`,children:`Print Job`}),(0,K.jsx)(`span`,{className:`text-white font-medium truncate block`,children:r})]}),(()=>{if(!We.length)return null;let e=rW((x==null?We[0]:We.find(e=>e.index===x))?.bed_type);return e?(0,K.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-bambu-gray -mt-2`,title:e.label,children:[(0,K.jsx)(`img`,{src:e.icon,alt:``,className:`w-4 h-4 object-contain flex-shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:e.label})]}):null})(),(0,K.jsx)(Ske,{plates:We,isMultiPlate:Ue,selectedPlates:v,onToggle:e=>{b(t=>{let n=new Set(t);return h?(n.clear(),n.add(e)):n.has(e)?n.delete(e):n.add(e),n})},onSelectAll:h?void 0:()=>b(new Set(We.map(e=>e.index))),onDeselectAll:h?void 0:()=>b(new Set),multiSelect:!h}),!a?.length&&(0,K.jsx)(Tke,{printers:he||[],selectedPrinterIds:g,onMultiSelect:_,isLoading:ge,allowMultiple:!0,showInactive:e===`edit-queue-item`,disableBusy:!1,printerMappingResults:Re.printerResults,filamentReqs:je,onAutoConfigurePrinter:Re.autoConfigurePrinter,onUpdatePrinterConfig:Re.updatePrinterConfig,assignmentMode:M,onAssignmentModeChange:N,targetModel:P,onTargetModelChange:F,targetLocation:I,onTargetLocationChange:L,slicedForModel:Se}),M===`model`&&P&&je&&Me&&Me.length>0&&(0,K.jsx)(xke,{filamentReqs:je,availableFilaments:Me,overrides:R,onChange:z,forceColorMatch:B,onForceColorMatchChange:(e,t)=>V(n=>({...n,[e]:t}))}),Se&&M===`printer`&&g.length===1&&(()=>{let e=he?.find(e=>e.id===g[0]);return e&&e.model&&Se!==e.model?(0,K.jsxs)(`div`,{className:`p-3 mb-2 bg-yellow-500/10 border border-yellow-500/30 rounded-lg flex items-center gap-2`,children:[(0,K.jsx)(Su,{className:`w-4 h-4 text-yellow-400 flex-shrink-0`}),(0,K.jsxs)(`span`,{className:`text-sm text-yellow-400`,children:[`File was sliced for `,Se,`, but printing on `,e.model]})]}):null})(),Ae&&(0,K.jsxs)(`div`,{className:`flex items-start gap-2 p-3 mb-2 bg-orange-500/10 border border-orange-500/30 rounded-lg text-sm`,children:[(0,K.jsx)(us,{className:`w-4 h-4 text-orange-400 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`p`,{className:`text-orange-400`,children:`Archive data unavailable. The source file may have been deleted. Filament mapping is disabled.`})]}),nt&&!Ae&&g.length===1&&(0,K.jsx)(bke,{printerId:le,filamentReqs:je,manualMappings:O,onManualMappingChange:k,defaultExpanded:!!a?.length||(ue?.per_printer_mapping_expanded??!1),currencySymbol:pe,defaultCostPerKg:me,forceColorMatch:B,onForceColorMatchChange:(e,t)=>V(n=>({...n,[e]:t}))}),(e===`create`||ce>0||M===`model`&&P)&&(0,K.jsx)(Eke,{options:w,onChange:T,defaultExpanded:!!a?.length,showDualNozzleOptions:it}),e!==`edit-queue-item`&&(M===`model`||g.length<=1)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`label`,{htmlFor:`printQuantity`,className:`text-sm text-bambu-gray whitespace-nowrap`,children:u(`queue.quantity`,`Quantity`)}),(0,K.jsx)(`input`,{id:`printQuantity`,type:`number`,min:1,max:999,value:S,onChange:e=>C(Math.max(1,Math.min(999,parseInt(e.target.value)||1))),className:`w-20 px-2 py-1 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green`}),S>1&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:u(`queue.quantityHint`,`Creates {{count}} queue items`,{count:S})})]}),(0,K.jsx)(Dke,{options:E,onChange:D,dateFormat:ue?.date_format||`system`,timeFormat:ue?.time_format||`system`,canControlPrinter:p(`printers:control`),showStagger:!h&&M===`printer`&&g.length>1,printerCount:g.length,hasGcodeSnippets:!!ue?.gcode_snippets}),Je.isError&&(0,K.jsx)(`div`,{className:`mb-4 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400`,children:Je.error?.message||`Failed to complete operation`}),(0,K.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:o,className:`flex-1`,disabled:ne,children:`Cancel`}),(0,K.jsx)($,{type:`submit`,disabled:!Ze,className:`flex-1`,children:Xe?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),$e.loadingText]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(tt,{className:`w-4 h-4`}),$e.submitText]})})]})]})]})}),ae&&ae.length>0&&(0,K.jsx)(Id,{title:u(`printModal.insufficientFilamentTitle`),message:Ke,confirmText:u(`printModal.printAnyway`),cancelText:u(`common.cancel`),variant:`warning`,onConfirm:()=>{oe(null),Ye(void 0,{skipFilamentCheck:!0})},onCancel:()=>oe(null)})]})}function cW({value:e}){let{t}=W(),[n,r]=(0,y.useState)(!1);return(0,K.jsx)(`button`,{onClick:async()=>{try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(e);else{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{if(t.select(),!document.execCommand(`copy`))return}finally{document.body.removeChild(t)}}r(!0),setTimeout(()=>r(!1),2e3)}catch{}},className:`ml-2 p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,title:t(n?`printers.copied`:`printers.copyToClipboard`),children:n?(0,K.jsx)(ns,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,K.jsx)(js,{className:`w-3.5 h-3.5`})})}function Oke({printer:e,status:t,totalPrintHours:n,onClose:r}){let{t:i}=W();(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let a=[];if(a.push({label:i(`printers.model`),value:e.model??`—`}),a.push({label:i(`common.status`),value:(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-xs font-medium ${t?.connected?`bg-bambu-green/20 text-bambu-green`:`bg-red-500/20 text-red-400`}`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${t?.connected?`bg-bambu-green`:`bg-red-400`}`}),t?.connected?i(`printers.status.available`):i(`printers.status.offline`)]})}),t?.state&&a.push({label:i(`printers.state`),value:i({IDLE:`printers.status.idle`,RUNNING:`printers.status.printing`,PAUSE:`printers.status.paused`,FINISH:`printers.status.finished`,FAILED:`printers.status.error`}[t.state]??`printers.status.unknown`)}),a.push({label:i(`printers.ipAddress`),value:(0,K.jsxs)(`span`,{className:`flex items-center`,children:[(0,K.jsx)(`span`,{className:`font-mono`,children:e.ip_address}),(0,K.jsx)(cW,{value:e.ip_address})]})}),a.push({label:i(`printers.serialNumber`),value:(0,K.jsxs)(`span`,{className:`flex items-center`,children:[(0,K.jsx)(`span`,{className:`font-mono truncate`,children:e.serial_number}),(0,K.jsx)(cW,{value:e.serial_number})]})}),t?.wired_network)a.push({label:i(`printers.networkLabel`,`Network`),value:(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(qo,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-bambu-green`,children:i(`printers.connection.ethernet`,`Ethernet`)})]})});else if(t?.wifi_signal!=null){let e=xT(t.wifi_signal);a.push({label:i(`printers.wifiSignalLabel`),value:(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Jl,{className:`w-4 h-4 ${e.color}`}),(0,K.jsx)(`span`,{className:e.color,children:i(e.labelKey)}),(0,K.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[`(`,t.wifi_signal,` dBm)`]})]})})}return a.push({label:i(`printers.firmware`),value:t?.firmware_version??`—`}),t?.developer_mode!=null&&a.push({label:i(`printers.developerMode`),value:(0,K.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${t.developer_mode?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:t.developer_mode?i(`printers.enabled`):i(`printers.disabled`)})}),a.push({label:i(`printers.nozzleCount`),value:e.nozzle_count}),a.push({label:i(`printers.autoArchive`),value:(0,K.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${e.auto_archive?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:e.auto_archive?i(`printers.enabled`):i(`printers.disabled`)})}),n!=null&&n>0&&a.push({label:i(`printers.totalPrintHours`),value:`${Math.round(n)}h`}),e.location&&a.push({label:i(`printers.sort.location`),value:e.location}),a.push({label:i(`printers.addedOn`),value:Tf(e.created_at)}),(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,onClick:r,children:(0,K.jsx)(yd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(xd,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e.name}),(0,K.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-bambu-dark rounded flex-shrink-0`,children:(0,K.jsx)(Bu,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,K.jsx)(`img`,{src:bT(e.model),alt:e.model??e.name,className:`h-24 object-contain`})}),(0,K.jsx)(`div`,{className:`space-y-0`,children:a.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-2.5 border-b border-bambu-dark-tertiary last:border-0`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray whitespace-nowrap`,children:e.label}),(0,K.jsx)(`span`,{className:`text-sm text-white text-right`,children:e.value})]},t))})]})})})}function kke(e){if(!e||e.length<6)return!1;let t=parseInt(e.slice(0,2),16),n=parseInt(e.slice(2,4),16),r=parseInt(e.slice(4,6),16);return(.299*t+.587*n+.114*r)/255>.6}function lW({trayColor:e,trayType:t,isEmpty:n,emptyKind:r,slotNumber:i}){let a=r===`reset`?`#3d3d3d`:`#666`;return(0,K.jsx)(`div`,{className:`w-3.5 h-3.5 rounded-full mx-auto mb-0.5 border-2 flex items-center justify-center`,style:{backgroundColor:e?`#${e}`:t?`#333`:`transparent`,borderColor:n?a:`rgba(255,255,255,0.1)`,borderStyle:n?`dashed`:`solid`},children:(0,K.jsx)(`span`,{className:`text-[6px] font-bold leading-none select-none`,style:{color:e&&kke(e)?`#000`:`#fff`},children:i})})}var uW=240,dW=320;function fW(e){return(e??.02).toFixed(3)}function pW({side:e}){let{mode:t}=gd();return(0,K.jsx)(`span`,{className:`inline-flex items-center justify-center w-4 h-4 text-[10px] font-bold rounded`,style:{backgroundColor:t===`dark`?`#1a4d2e`:`#e7f5e9`,color:`#00ae42`},children:e})}function mW(e,t){if(!e)return``;if(e.includes(`hardened`))return t(`printers.nozzleHardenedSteel`);if(e.includes(`stainless`))return t(`printers.nozzleStainlessSteel`);if(e.includes(`tungsten`))return t(`printers.nozzleTungstenCarbide`);if(e.length>=4){let n=e.slice(2,4);if(n===`00`)return t(`printers.nozzleStainlessSteel`);if(n===`01`)return t(`printers.nozzleHardenedSteel`);if(n===`05`)return t(`printers.nozzleTungstenCarbide`)}return e===`00`?t(`printers.nozzleStainlessSteel`):e===`01`?t(`printers.nozzleHardenedSteel`):e===`05`?t(`printers.nozzleTungstenCarbide`):e.startsWith(`H`)?t(`printers.nozzleHardenedSteel`):e}function hW(e,t){return e?e.startsWith(`HH`)?t(`printers.nozzleHighFlow`):e.startsWith(`HS`)?t(`printers.nozzleStandardFlow`):``:``}function gW({slot:e,index:t,activeStatus:n,filamentName:r,children:i}){let{t:a}=W(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(`top`),u=(0,y.useRef)(null),d=(0,y.useRef)(null),f=(0,y.useRef)(null),p=!e.nozzle_diameter&&!e.nozzle_type,m=e.stat===1;(0,y.useEffect)(()=>{if(o&&u.current&&d.current){let e=u.current.getBoundingClientRect(),t=d.current.offsetHeight,n=e.top-56,r=window.innerHeight-e.bottom;nn?l(`bottom`):l(`top`)}},[o]);let h=()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>s(!0),80)},g=()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>s(!1),100)};(0,y.useEffect)(()=>()=>{f.current&&clearTimeout(f.current)},[]);let _=tf(e.filament_color),v=mW(e.nozzle_type,a),b=hW(e.nozzle_type,a);return(0,K.jsxs)(`div`,{ref:u,className:`relative`,onMouseEnter:h,onMouseLeave:g,children:[i,o&&(0,K.jsxs)(`div`,{ref:d,className:` absolute left-1/2 -translate-x-1/2 z-50 ${c===`top`?`bottom-full mb-2`:`top-full mt-2`} animate-in fade-in-0 zoom-in-95 duration-150 diff --git a/static/index.html b/static/index.html index d25b0648e..071895b4e 100644 --- a/static/index.html +++ b/static/index.html @@ -26,7 +26,7 @@ - +