ConfigureAmsSlotModal-C4N9v6PJ.js 46 KB

1
  1. import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{a as c}from"./info-DcT0QU8O.js";import{n as l}from"./ToastContext-VFOrCCoA.js";import{t as u}from"./loader-circle-CB4leTZa.js";import{t as d}from"./package-D9xR0eOt.js";import{t as f}from"./search-BpAJdxRw.js";import{t as p}from"./settings-2-DYB5IzKV.js";import{t as ee}from"./x-Dctff5l9.js";import{t as m}from"./Button-pwVKPiYn.js";import{An as h,Gt as g,U as _,_t as v,ft as y,lt as b,sn as x}from"./index-BoVbGTav.js";import{a as S,i as C,n as w,r as T}from"./slicerPrinterMatch-g7Dr6p0c.js";import{p as E}from"./utils-D0ctH_jZ.js";import{t as te}from"./inventorySearch-yJim1_Yj.js";import{t as ne}from"./useCancellableTimeout-CXuQGelB.js";var D=e(n(),1),O=t();function k({isOpen:e,onClose:t,tagUid:n,trayUuid:c,printerId:d,amsId:p,trayId:h}){let{t:g}=i(),_=a(),{showToast:v}=l(),[y,S]=(0,D.useState)(``),C=c||n,{data:w,isLoading:T}=o({queryKey:[`unlinked-spools`],queryFn:r.getUnlinkedSpools,enabled:e}),E=(0,D.useMemo)(()=>w?w.filter(e=>{if(!y)return!0;let t=y.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)}):[],[w,y]),te=s({mutationFn:e=>r.linkSpool(e,{spoolTag:C,printerId:d,amsId:p,trayId:h}),onSuccess:()=>{_.invalidateQueries({queryKey:[`unlinked-spools`]}),_.invalidateQueries({queryKey:[`linked-spools`]}),_.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),v(g(`spoolman.linkSuccess`),`success`),t()},onError:e=>{v(e.message||g(`spoolman.linkFailed`),`error`)}});return e?(0,O.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,O.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,O.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,O.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-white/10`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,O.jsx)(x,{className:`w-5 h-5 text-bambu-green`}),g(`spoolman.selectSpool`)]}),(0,O.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[`AMS `,p,` T`,h,` · Printer #`,d]})]}),(0,O.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,O.jsx)(ee,{className:`w-5 h-5`})})]}),(0,O.jsxs)(`div`,{className:`p-4 border-b border-white/10`,children:[(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(f,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,O.jsx)(`input`,{type:`text`,value:y,onChange:e=>S(e.target.value),placeholder:g(`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`})]}),(c||n)&&(0,O.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-2 font-mono truncate`,title:c||n,children:[`Tag: `,c||n]})]}),(0,O.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 min-h-0`,children:T?(0,O.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,O.jsx)(u,{className:`w-6 h-6 animate-spin text-bambu-green`})}):E.length===0?(0,O.jsx)(`p`,{className:`text-center text-bambu-gray py-8 text-sm`,children:g(`inventory.noSpoolsMatch`)}):E.map(e=>(0,O.jsxs)(`button`,{onClick:()=>te.mutate(e.id),disabled:te.isPending||!C,className:`w-full flex items-center gap-3 p-3 rounded-lg hover:bg-white/5 transition-colors text-left`,children:[(0,O.jsx)(`span`,{className:`w-6 h-6 rounded-full border border-black/20 flex-shrink-0`,style:b(e.filament_color_hex)}),(0,O.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,O.jsx)(`div`,{className:`text-sm text-white font-medium truncate`,children:e.filament_name||g(`spoolman.spoolId`)}),(0,O.jsxs)(`div`,{className:`text-xs text-bambu-gray truncate`,children:[e.filament_vendor?`${e.filament_vendor} · `:``,e.filament_material||`Unknown`,` · #`,e.id]})]}),(0,O.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.remaining_weight==null?`—`:`${Math.round(e.remaining_weight)}g`})]},e.id))}),(0,O.jsx)(`div`,{className:`p-4 border-t border-white/10 flex justify-end`,children:(0,O.jsx)(m,{variant:`ghost`,onClick:t,children:g(`inventory.cancel`)||`Cancel`})})]})]}):null}function A({isOpen:e,onClose:t,printerId:n,amsId:c,trayId:p,trayInfo:h,spoolmanEnabled:g}){let{t:_}=i(),x=a(),{showToast:S}=l(),[C,w]=(0,D.useState)(!1),[T,E]=(0,D.useState)(null),[ne,k]=(0,D.useState)(null);(0,D.useEffect)(()=>{E(null),k(null)},[C]);let[A,re]=(0,D.useState)(``),[j,ie]=(0,D.useState)(null),[M,ae]=(0,D.useState)(!1),[N,oe]=(0,D.useState)(null);(0,D.useEffect)(()=>{e&&w(!1)},[e]);let{data:se,isLoading:ce}=o({queryKey:[`inventory-spools`,`assign-modal`],queryFn:()=>r.getSpools(!0),enabled:e&&!g}),{data:le}=o({queryKey:[`spool-assignments`],queryFn:()=>r.getAssignments(),enabled:e}),{data:ue}=o({queryKey:[`settings`],queryFn:()=>r.getSettings(),enabled:e}),{data:de,isLoading:P}=o({queryKey:[`spoolman-inventory-spools`,`assign-modal`],queryFn:()=>r.getSpoolmanInventorySpools(!1),enabled:e&&!!g}),{data:F}=o({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>r.getSpoolmanSlotAssignments(),enabled:e&&!!g}),I=(0,D.useMemo)(()=>F?new Set(F.filter(e=>!(e.printer_id===n&&e.ams_id===c&&e.tray_id===p)).map(e=>e.spoolman_spool_id)):new Set,[F,n,c,p]),L=()=>{r.refreshPrinterStatus(n).catch(()=>{}),x.invalidateQueries({queryKey:[`printerStatus`,n]})},R=s({mutationFn:e=>r.assignSpool({spool_id:e,printer_id:n,ams_id:c,tray_id:p}),onSuccess:e=>{x.setQueryData([`spool-assignments`],t=>{let r=(t||[]).filter(e=>!(e.printer_id===n&&e.ams_id===c&&e.tray_id===p));return r.push(e),r}),x.invalidateQueries({queryKey:[`spool-assignments`]}),L(),S(_(e.pending_config?`inventory.assignPendingInsert`:`inventory.assignSuccess`),`success`),ae(!1),ie(null),oe(null),t()},onError:e=>{S(`${_(`inventory.assignFailed`)}: ${e.message}`,`error`)}}),z=s({mutationFn:e=>r.assignSpoolmanSlot({spoolman_spool_id:e,printer_id:n,ams_id:c,tray_id:p}),onSuccess:()=>{x.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),x.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),L(),S(_(`inventory.assignSuccess`),`success`),t()},onError:e=>{S(`${_(`inventory.assignFailed`)}: ${e.message}`,`error`)}}),B=e=>(e??``).trim().toUpperCase(),V=(e,t)=>{let n=B(e),r=B(t);return!n||!r?`none`:n===r?`exact`:r.includes(n)||n.includes(r)?`partial`:`none`},H=e=>e.split(`@`)[0].trim(),fe=(e,t)=>{let n=H(B(e)),r=H(B(t));return!n||!r?!1:n===r};if(!e)return null;let pe=new Set((le||[]).filter(e=>!(e.printer_id===n&&e.ams_id===c&&e.tray_id===p)).map(e=>e.spool_id)),U=se?.filter(e=>!e.archived_at&&(C||!pe.has(e.id))),W=U;if(!C){let e=H(B(h?.profile)),t=B(h?.material||h?.type);(e||t)&&(W=W?.filter(n=>{let r=H(B(n.slicer_filament_name||n.slicer_filament)),i=B(n.material);return e&&r&&r===e?!0:t&&i?i===t||t.includes(i)||i.includes(t):!r&&!i}))}A&&W&&(W=te(W,A));let me=()=>{if(ne!==null){z.mutate(ne);return}if(!T)return;let e=se?.find(e=>e.id===T);if(!e){S(_(`inventory.assignFailed`),`error`);return}if(!ue?.disable_filament_warnings&&h){let t=h.material||h.type,n=V(e.material,t),r=e.slicer_filament_name||e.slicer_filament,i=h.profile||h.type,a=fe(r,i);if(n!==`exact`){let o;o=n===`none`&&!a?`material_profile`:n===`partial`&&!a?`partial_profile`:n===`none`?`material`:`partial`,ie(T),oe({type:o,spoolMaterial:e.material||``,trayMaterial:t||``,spoolProfile:r||void 0,trayProfile:i||void 0}),ae(!0);return}}R.mutate(T)},he=()=>{j&&(R.mutate(j),ae(!1),ie(null))};return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-start sm:items-center justify-center p-4 overflow-y-auto`,children:[(0,O.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,O.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,O.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(d,{className:`w-5 h-5 text-bambu-green`}),(0,O.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:_(`inventory.assignSpool`)})]}),(0,O.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,O.jsx)(ee,{className:`w-5 h-5`})})]}),(0,O.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto`,children:[h&&(0,O.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,O.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:[_(`inventory.selectSpool`),`:`]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[h.color&&(0,O.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:b(h.color)}),(0,O.jsx)(`span`,{className:`text-white font-medium`,children:h.type||_(`ams.emptySlot`)}),(0,O.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,h.location,`)`]})]})]}),(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(f,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,O.jsx)(`input`,{type:`text`,value:A,onChange:e=>re(e.target.value),placeholder:_(`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,O.jsxs)(`div`,{className:`space-y-3`,children:[!g&&(ce?(0,O.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,O.jsx)(u,{className:`w-6 h-6 text-bambu-green animate-spin`})}):W&&W.length>0?(0,O.jsx)(`div`,{className:`max-h-96 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2`,children:W.map(e=>(0,O.jsxs)(`button`,{onClick:()=>{E(e.id),k(null)},title:e.note||void 0,className:`p-2.5 rounded-lg border text-left transition-colors ${T===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,O.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,O.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,O.jsxs)(`span`,{className:`text-[10px] font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[e.rgba&&(0,O.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:b(e.rgba)}),(0,O.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:y(e.color_name,e.rgba,e.color_name_is_synthesized)||``})]}),e.label_weight&&(0,O.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,O.jsx)(`p`,{className:`text-[10px] text-bambu-gray/70 mt-1 truncate`,title:e.note,children:e.note})]},e.id))}):U&&U.length===0?(0,O.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,O.jsx)(`p`,{children:_(`inventory.noAvailableSpools`)}),se&&(0,O.jsxs)(`p`,{className:`text-[10px] mt-2 opacity-60`,children:[se.length,` fetched · `,se.filter(e=>e.archived_at).length,` archived ·`,` `,se.filter(e=>pe.has(e.id)).length,` assigned to other slots`]})]}):(0,O.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,O.jsx)(`p`,{children:_(`inventory.noSpoolsMatch`)}),U&&(0,O.jsxs)(`p`,{className:`text-[10px] mt-2 opacity-60`,children:[U.length,` unassigned spools — `,U.length-(W?.length??0),` filtered by tray match. Try "Show all spools".`]})]})),g&&(0,O.jsx)(O.Fragment,{children:P?(0,O.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,O.jsx)(u,{className:`w-5 h-5 text-bambu-green animate-spin`})}):de&&de.filter(e=>!e.archived_at&&!I.has(e.id)).length>0?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide pt-1`,children:_(`inventory.spoolmanSpools`)}),(0,O.jsx)(`div`,{className:`max-h-64 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2`,children:te(de.filter(e=>!e.archived_at&&!I.has(e.id)),A).map(e=>(0,O.jsxs)(`button`,{onClick:()=>{k(e.id),E(null)},title:e.note||void 0,className:`p-2.5 rounded-lg border text-left transition-colors ${ne===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,O.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,O.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,O.jsxs)(`span`,{className:`text-[10px] font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[e.rgba&&(0,O.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:b(e.rgba)}),(0,O.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:y(e.color_name,e.rgba,e.color_name_is_synthesized)||``})]}),e.label_weight&&(0,O.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,O.jsx)(`p`,{className:`text-[10px] text-bambu-gray/70 mt-1 truncate`,title:e.note,children:e.note})]},`spoolman-${e.id}`))})]}):null})]})]}),(0,O.jsxs)(`div`,{className:`flex justify-between items-center p-4 border-t border-bambu-dark-tertiary`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`input`,{id:`disable-filtering-toggle`,type:`checkbox`,checked:C,onChange:()=>w(e=>!e),className:`accent-bambu-green w-4 h-4 rounded focus:ring-0 border-bambu-dark-tertiary`}),(0,O.jsx)(`label`,{htmlFor:`disable-filtering-toggle`,className:`text-xs text-bambu-gray select-none cursor-pointer`,children:_(`inventory.showAllSpools`)})]}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsx)(m,{variant:`secondary`,onClick:t,children:_(`common.cancel`)}),(0,O.jsx)(m,{onClick:me,disabled:!T&&ne===null||R.isPending||z.isPending,children:R.isPending||z.isPending?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(u,{className:`w-4 h-4 animate-spin`}),_(`inventory.assigning`)]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(d,{className:`w-4 h-4`}),_(`inventory.assignSpool`)]})})]})]}),R.isError&&(0,O.jsx)(`div`,{className:`mx-4 mb-4 p-2 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-sm text-red-700 dark:text-red-400`,children:R.error.message})]})]}),M&&h&&T&&N&&(()=>{let e=``;return N.type===`material`?e=_(`inventory.assignMismatchMessage`,{spoolMaterial:N.spoolMaterial,trayMaterial:N.trayMaterial,location:h.location}):N.type===`partial`?e=_(`inventory.assignPartialMismatchMessage`,{spoolMaterial:N.spoolMaterial,trayMaterial:N.trayMaterial,location:h.location}):N.type===`material_profile`?e=`${_(`inventory.assignMismatchMessage`,{spoolMaterial:N.spoolMaterial,trayMaterial:N.trayMaterial,location:h.location})}\n\n${_(`inventory.assignProfileMismatchMessage`,{spoolProfile:N.spoolProfile||_(`common.unknown`),trayProfile:N.trayProfile||_(`common.unknown`),location:h.location})}`:N.type===`partial_profile`&&(e=`${_(`inventory.assignPartialMismatchMessage`,{spoolMaterial:N.spoolMaterial,trayMaterial:N.trayMaterial,location:h.location})}\n\n${_(`inventory.assignProfileMismatchMessage`,{spoolProfile:N.spoolProfile||_(`common.unknown`),trayProfile:N.trayProfile||_(`common.unknown`),location:h.location})}`),e=`${e}\n\n${_(`inventory.assignReconfigureNote`)}`,(0,O.jsx)(v,{title:_(`inventory.assignMismatchTitle`),message:e,confirmText:_(`inventory.assignMismatchConfirm`),variant:`warning`,overlayZIndex:`z-[110]`,isLoading:R.isPending,onConfirm:he,onCancel:()=>{R.isPending||(ae(!1),ie(null),oe(null))}})})()]})}function re(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 j=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`NYLON`,`PVA`,`HIPS`,`PP`,`PET`];function ie(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 j)if(RegExp(`\\b${n}\\b`).test(e))return{material:n,brand:t.slice(0,r.index).trim(),variant:`Support`}}for(let e of j){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 M(e){return`${e.extruder_id??0}|${e.name}|${e.k_value}`}function ae(e,t){return t===void 0?!1:e.some(e=>(e.extruder_id??0)===t)}function N(e,t,n){return ae(e,n)?e.find(e=>e.slot_id===t&&(e.extruder_id??0)===n):e.find(e=>e.slot_id===t)}function oe(e,t,n){return t?` \u00b7 ${e.extruder_id===1?n(`common.left`):n(`common.right`)}`:``}function se(e){return!e.startsWith(`GF`)&&!e.startsWith(`P1`)}var ce={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`},le=[{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`}],ue=[{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 de(e){return ce[e.toLowerCase().trim()]||null}function P({isOpen:e,onClose:t,printerId:n,slotInfo:a,nozzleDiameter:d=`0.4`,printerModel:f,onSuccess:v,fullScreen:y}){let{t:x}=i(),{showToast:te}=l(),[k,A]=(0,D.useState)(``),[ce,P]=(0,D.useState)(``),[F,I]=(0,D.useState)(null),L=(0,D.useRef)(null);L.current=F;let[R,z]=(0,D.useState)(``),[B,V]=(0,D.useState)(``),[H,fe]=(0,D.useState)(``),[pe,U]=(0,D.useState)(!1),[W,me]=(0,D.useState)(!1),he=(0,D.useRef)(``),{schedule:ge}=ne(),{data:G,isLoading:_e,isError:ve}=o({queryKey:[`cloudSettings`],queryFn:()=>r.getCloudSettings(),enabled:e,retry:!1}),{data:ye}=o({queryKey:[`orcaCloudProfilesForAmsSlot`],queryFn:()=>r.orcaCloudListProfiles(),enabled:e,retry:!1}),{data:K,isLoading:be}=o({queryKey:[`localPresets`],queryFn:()=>r.getLocalPresets(),enabled:e}),{data:q,isLoading:xe}=o({queryKey:[`builtinFilaments`],queryFn:()=>r.getBuiltinFilaments(),enabled:e,staleTime:1/0}),{data:J,isLoading:Se}=o({queryKey:[`kprofiles`,n,d],queryFn:()=>r.getKProfiles(n,d),enabled:e&&!!n}),{data:Ce}=o({queryKey:[`colorCatalog`],queryFn:()=>r.getColorCatalog(),enabled:e,staleTime:1/0}),{data:Y}=o({queryKey:[`slicerPrinterModels`],queryFn:r.getSlicerPrinterModels,enabled:e,staleTime:1/0}),{data:X}=o({queryKey:[`slot-spool-defaults`,n,a.amsId,a.trayId],queryFn:()=>r.getSlotSpoolDefaults(n,a.amsId,a.trayId),enabled:e,staleTime:0}),we=(0,D.useMemo)(()=>w(Y??{}),[Y]),Te=(0,D.useMemo)(()=>{if(!f||!Y)return null;for(let[e,t]of Object.entries(Y))if(t===f)return`${e.startsWith(`Bambu Lab `)?e:`Bambu Lab ${e}`} ${d} nozzle`;return null},[f,Y,d]),Ee=s({mutationFn:async()=>{if(!k)throw Error(`No filament preset selected`);let e=k.startsWith(`local_`),t=k.startsWith(`builtin_`),i=k.startsWith(`orca_`)?k.replace(`orca_`,``):k,o=!e&&!t?ye?.filament.find(e=>e.setting_id===i):void 0,s=!!o,c=o??null,l=e?parseInt(k.replace(`local_`,``),10):null,u=t?k.replace(`builtin_`,``):null,f=e?K?.filament.find(e=>e.id===l):null,p=t?q?.find(e=>e.filament_id===u):null,ee=!e&&!t&&!s?G?.filament.find(e=>e.setting_id===k):null;if(!e&&!t&&!s&&!ee)throw Error(`Selected preset not found`);if(e&&!f)throw Error(`Selected local preset not found`);if(t&&!p)throw Error(`Selected builtin preset not found`);if(s&&!c)throw Error(`Selected Orca Cloud preset not found`);let m=e?f.name:t?p.name:s?c.name:ee.name,h=ie(m),g=L.current?.slot_id??-1,_=R||a.trayColor?.slice(0,6)||`FFFFFF`,v=m.replace(/@.+$/,``).trim(),y,b,S=h.material.toUpperCase(),C={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=(j.includes(S)?S:f?.filament_type||h.material||``).toUpperCase();y=C[e]||C[e.replace(/[-\s]?CF$/,``)]||C[e.replace(/\+$/,``)]||C[e.split(/[-\s]/)[0]]||``,b=``}else if(s)y=``,b=``;else if(t)y=u,b=``;else{if(y=re(k),b=k,!k.startsWith(`GFS`))try{let e=await r.getCloudSettingDetail(k),t=e.setting?.filament_id,n=e.filament_id||(typeof t==`string`?t:``);n&&(y=n)}catch(e){console.warn(`Failed to fetch preset detail for filament_id:`,e)}/^(PFUS|PFSP|PFCN)/.test(y)&&(console.warn(`Cloud preset ${k} carries no filament_id in either place; sending no tray_info_idx so the printer keeps a resolvable one.`),y=``)}let w=e&&f?.nozzle_temp_min?f.nozzle_temp_min:190,T=e&&f?.nozzle_temp_max?f.nozzle_temp_max:230;if(!e||t||s||!f?.nozzle_temp_min&&!f?.nozzle_temp_max){let t=(e?j.includes(S)?S:f?.filament_type||h.material||``:h.material).toUpperCase();t.includes(`PLA`)?(w=190,T=230):t.includes(`PETG`)?(w=220,T=260):t.includes(`ABS`)||t.includes(`ASA`)?(w=240,T=280):t.includes(`TPU`)?(w=200,T=240):t===`PCTG`?(w=220,T=260):t.includes(`PC`)?(w=260,T=300):(t.includes(`PA`)||t.includes(`NYLON`))&&(w=250,T=290)}let E=L.current?.k_value?parseFloat(L.current.k_value):0,ne=e?j.includes(S)?S:f?.filament_type||h.material||`PLA`:s&&j.includes(S)?S:h.material||`PLA`,D=await r.configureAmsSlot(n,a.amsId,a.trayId,{tray_info_idx:y,tray_type:ne,tray_sub_brands:v,tray_color:_+`FF`,nozzle_temp_min:w,nozzle_temp_max:T,cali_idx:g,nozzle_diameter:d,setting_id:b,kprofile_filament_id:L.current?.filament_id,kprofile_setting_id:L.current?.setting_id||void 0,k_value:E,orca_profile_id:s?i:void 0});s&&D.orca_fallback_reason&&te(x(`configureAmsSlot.orcaFallback.${D.orca_fallback_reason}`,{material:ne}),`warning`);let O=e?`local_${l}`:t?`builtin_${u}`:k,A=e?`local`:t?`builtin`:s?`orca_cloud`:`cloud`;try{await r.saveSlotPreset(n,a.amsId,a.trayId,O,v,A,D.tray_info_idx)}catch(e){console.warn(`Failed to save slot preset mapping:`,e)}return D},onSuccess:()=>{U(!0),v?.(),ge(()=>{U(!1),t()},1500)}}),De=s({mutationFn:async()=>r.resetAmsSlot(n,a.amsId,a.trayId),onSuccess:()=>{U(!0),v?.(),ge(()=>{U(!1),t()},1500)}}),Oe=(0,D.useMemo)(()=>{let e=H.toLowerCase(),t=[],n=new Set,r=a.savedPresetId,i=a.trayInfoIdx;if(ye?.filament)for(let r of ye.filament){let i=`orca_${r.setting_id}`;if(n.add(r.setting_id),n.add(i),!(e&&!r.name.toLowerCase().includes(e))){if(f){let e=T(r.name,Y??{});if(e&&!C(e,f))continue}t.push({id:i,name:r.name,source:`orca_cloud`,isUser:!0})}}if(G?.filament)for(let a of G.filament){if(n.has(a.setting_id))continue;n.add(a.setting_id);let o=r===a.setting_id||i&&(a.setting_id===i||re(a.setting_id)===i);if(!(e&&!a.name.toLowerCase().includes(e))){if(!o&&f){let e=T(a.name,Y??{});if(e&&!C(e,f))continue}t.push({id:a.setting_id,name:a.name,source:`cloud`,isUser:se(a.setting_id)})}}if(K?.filament){let n=a.savedPresetId;for(let r of K.filament){let i=`local_${r.id}`;if(!(e&&!r.name.toLowerCase().includes(e))){if(n!==i&&Te){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(S({name:r.name,compatible_printers:e},`filament`,Te,we)===`mismatch`)continue}t.push({id:i,name:r.name,source:`local`,isUser:!1})}}}if(q)for(let r of q){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]})},[ye?.filament,G?.filament,K?.filament,q,H,f,a.savedPresetId,a.trayInfoIdx,Te,we,Y]),Z=(0,D.useMemo)(()=>{if(!k)return null;let e=null,t=``;if(k.startsWith(`local_`)){let t=parseInt(k.replace(`local_`,``),10);e=K?.filament.find(e=>e.id===t)?.name||null}else if(k.startsWith(`builtin_`)){let n=k.replace(`builtin_`,``);e=q?.find(e=>e.filament_id===n)?.name||null,t=E(n)}else{let n=k.startsWith(`orca_`)?k.replace(`orca_`,``):k,r=ye?.filament.find(e=>e.setting_id===n);if(r)e=r.name;else if(G?.filament){let n=G.filament.find(e=>e.setting_id===k);e=n?.name||null,n&&(t=E(n.setting_id))}}if(!e)return null;let n=e.replace(/@.+$/,``).trim();n.startsWith(`# `)&&(n=n.slice(2).trim());let r=ie(n);return{fullName:n,material:r.material,brand:r.brand,filamentId:t}},[k,G?.filament,K?.filament,q,ye?.filament]),ke=Z?.fullName||``,Ae=(0,D.useMemo)(()=>{if(!Ce||!Z)return[];let{fullName:e,brand:t}=Z,n=e.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,``).trim();return Ce.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})},[Ce,Z]),je=(0,D.useMemo)(()=>new Set((J?.profiles??[]).map(e=>e.extruder_id??0)).size>1,[J?.profiles]),Q=(0,D.useMemo)(()=>{if(!J?.profiles)return[];if(!Z){let e=a.caliIdx;if(e!=null&&e>0){let t=N(J.profiles,e,a.extruderId);if(t)return[t]}return[]}let{fullName:e,material:t,brand:n,filamentId:r}=Z,i=e.toUpperCase(),o=t.toUpperCase(),s=n.toUpperCase()===`GENERIC`?``:n.toUpperCase(),c=r;if(!o||o.length<2)return[];let l=J.profiles.filter(e=>{if(c){let t=E(e.filament_id);if(t&&t===c)return!0}let t=e.name.toUpperCase();if(s)return!(!t.includes(s)||!t.includes(o));if(t.includes(i)||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=ae(J.profiles,a.extruderId)?l.filter(e=>(e.extruder_id??0)===a.extruderId):l,d=new Map;for(let e of u){let t=M(e);d.has(t)||d.set(t,e)}let f=Array.from(d.values()),p=a.caliIdx;if((ce&&k===ce||c&&c===E(a.trayInfoIdx))&&p!=null&&p>0&&!f.some(e=>e.slot_id===p)){let e=N(J.profiles,p,a.extruderId);e&&f.unshift(e)}return f},[J?.profiles,Z,a.extruderId,a.caliIdx,a.trayInfoIdx,k,ce]),$=(0,D.useMemo)(()=>{if(!J?.profiles)return[];let e=new Set(Q.map(e=>M(e))),t=new Map;for(let n of J.profiles){let r=M(n);e.has(r)||t.has(r)||t.set(r,n)}return Array.from(t.values()).sort((e,t)=>e.name.localeCompare(t.name))},[J?.profiles,Q]),Me=Q.length>0||$.length>0,Ne=(0,D.useCallback)(e=>{if(!e){I(null);return}I(Q.find(t=>M(t)===e)||$.find(t=>M(t)===e)||null)},[Q,$]);(0,D.useEffect)(()=>{if(e){if(X?.slicer_filament)A(X.slicer_filament),P(X.slicer_filament);else if(a.savedPresetId)A(a.savedPresetId),P(a.savedPresetId);else if(a.trayInfoIdx&&G?.filament){let e=G.filament.find(e=>e.setting_id===a.trayInfoIdx);e||=G.filament.find(e=>re(e.setting_id)===a.trayInfoIdx),e&&(A(e.setting_id),P(e.setting_id))}else if(a.trayInfoIdx&&q?.length){let e=a.trayInfoIdx,t=q.find(t=>t.filament_id===e);t&&(A(`builtin_${t.filament_id}`),P(`builtin_${t.filament_id}`))}if(a.trayColor){let e=a.trayColor.slice(0,6);e&&z(e)}}else A(``),P(``),I(null),z(``),V(``),fe(``),U(!1),he.current=``},[e,X?.slicer_filament,a.savedPresetId,a.trayInfoIdx,a.trayColor,G?.filament,q]),(0,D.useEffect)(()=>{if(Q.length>0){if(X?.cali_idx!=null){let e=N(Q,X.cali_idx,X.extruder??a.extruderId);if(e){I(e);return}}if(a.caliIdx!=null&&a.caliIdx>0){let e=N(Q,a.caliIdx,a.extruderId);if(e){I(e);return}}I(Q[0])}else I(null)},[k,Q,X?.cali_idx,X?.extruder,a.caliIdx,a.extruderId]);let Pe=(0,D.useCallback)(e=>{e.key===`Escape`&&t()},[t]);(0,D.useEffect)(()=>{if(e)return document.addEventListener(`keydown`,Pe),()=>document.removeEventListener(`keydown`,Pe)},[e,Pe]);let Fe=_e&&!ve||be||xe||Se;if((0,D.useEffect)(()=>{if(!Fe&&k&&k!==he.current){let e=requestAnimationFrame(()=>{let e=document.querySelector(`[class*="fixed inset-0 z-50"]`)?.querySelector(`[data-preset-id="${CSS.escape(k)}"]`);e&&(he.current=k,e.scrollIntoView({block:`nearest`}))});return()=>cancelAnimationFrame(e)}},[k,Fe]),!e)return null;let Ie=k&&!Ee.isPending,Le=R||a.trayColor||`FFFFFF`;return(0,O.jsxs)(`div`,{className:`fixed inset-0 z-50 flex ${y?``:`items-center justify-center`}`,children:[!y&&(0,O.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,O.jsxs)(`div`,{className:y?`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,O.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(p,{className:`w-5 h-5 text-bambu-blue`}),(0,O.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:x(`configureAmsSlot.title`)}),y&&(0,O.jsxs)(`div`,{className:`flex items-center gap-2 ml-4 text-sm text-bambu-gray`,children:[(0,O.jsx)(`span`,{className:`text-white/30`,children:`|`}),a.trayColor&&(0,O.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:b(a.trayColor)}),(0,O.jsx)(`span`,{className:`text-white/70`,children:x(`configureAmsSlot.slotLabel`,{ams:_(a.amsId,a.trayCount),slot:a.trayId+1})}),a.traySubBrands&&(0,O.jsxs)(`span`,{children:[`(`,a.traySubBrands,`)`]})]})]}),(0,O.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,O.jsx)(ee,{className:`w-5 h-5`})})]}),(0,O.jsxs)(`div`,{className:`p-4 overflow-y-auto ${y?`flex-1 min-h-0`:`space-y-4 max-h-[60vh]`}`,children:[pe&&(0,O.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl`,children:(0,O.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,O.jsx)(h,{className:`w-16 h-16 text-bambu-green mx-auto`}),(0,O.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:x(`configureAmsSlot.slotConfigured`)}),(0,O.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:x(`configureAmsSlot.settingsSentToPrinter`)})]})}),!y&&(0,O.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:x(`configureAmsSlot.configuringSlot`)}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a.trayColor&&(0,O.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:b(a.trayColor)}),(0,O.jsx)(`span`,{className:`text-white font-medium`,children:x(`configureAmsSlot.slotLabel`,{ams:_(a.amsId,a.trayCount),slot:a.trayId+1})}),a.traySubBrands&&(0,O.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,a.traySubBrands,`)`]})]})]}),Fe?(0,O.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,O.jsx)(u,{className:`w-6 h-6 text-bambu-green animate-spin`})}):y?(0,O.jsxs)(`div`,{className:`flex gap-4 h-full`,children:[(0,O.jsxs)(`div`,{className:`w-1/2 flex flex-col min-h-0`,children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[x(`configureAmsSlot.filamentProfile`),` `,(0,O.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,O.jsx)(`input`,{type:`text`,placeholder:x(`configureAmsSlot.searchPresets`),value:H,onChange:e=>fe(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,O.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto space-y-1`,children:Oe.length===0?(0,O.jsx)(`p`,{className:`text-center py-4 text-bambu-gray`,children:G?.filament?.length===0&&!K?.filament?.length?x(`configureAmsSlot.noPresetsAvailable`):x(`configureAmsSlot.noMatchingPresets`)}):Oe.map(e=>(0,O.jsx)(`button`,{"data-preset-id":e.id,onClick:()=>A(e.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${k===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:(0,O.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,O.jsx)(`span`,{className:`text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all`,title:e.name,children:e.name}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[e.source===`local`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,children:x(`profiles.localProfiles.badge`)}),e.source===`orca_cloud`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,children:x(`configureAmsSlot.orcaCloud`)}),e.source===`cloud`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue`,children:x(`configureAmsSlot.bambuCloud`)}),e.source===`builtin`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,children:x(`configureAmsSlot.builtin`)})]})]})},e.id))})]}),(0,O.jsxs)(`div`,{className:`w-1/2 flex flex-col gap-4 min-h-0 overflow-y-auto`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[x(`configureAmsSlot.kProfileLabel`),ke&&(0,O.jsx)(`span`,{className:`ml-2 text-xs text-bambu-blue`,children:x(`configureAmsSlot.filteringFor`,{material:ke})})]}),Me?(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsxs)(`select`,{value:F?M(F):``,onChange:e=>Ne(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10`,children:[(0,O.jsx)(`option`,{value:``,children:x(`configureAmsSlot.noKProfile`)}),Q.map(e=>(0,O.jsxs)(`option`,{value:M(e),children:[e.name,` (K=`,e.k_value,`)`,oe(e,je,x)]},M(e))),$.length>0&&(0,O.jsx)(`optgroup`,{label:x(`configureAmsSlot.otherKProfiles`),children:$.map(e=>(0,O.jsxs)(`option`,{value:M(e),children:[e.name,` (K=`,e.k_value,`)`,oe(e,je,x)]},M(e)))})]}),(0,O.jsx)(c,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}):k?(0,O.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:x(`configureAmsSlot.noMatchingKProfiles`)}):(0,O.jsx)(`span`,{className:`inline-block text-xs px-2 py-1 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 border border-amber-300 dark:border-amber-500/30`,children:x(`configureAmsSlot.selectFilamentFirst`)}),F&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-green mt-1`,children:x(`configureAmsSlot.kFromCalibration`,{value:F.k_value})})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:x(`configureAmsSlot.customColorLabel`)}),Ae.length>0&&(0,O.jsxs)(`div`,{className:`mb-3`,children:[(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1.5`,children:x(`configureAmsSlot.presetColors`,{name:Z?.fullName})}),(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Ae.map(e=>(0,O.jsxs)(`button`,{onClick:()=>{z(e.hex_color.replace(`#`,``).toUpperCase()),V(e.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${R===e.hex_color.replace(`#`,``).toUpperCase()?`border-bambu-green scale-105`:`border-white/20 hover:border-white/40`}`,title:e.color_name,children:[(0,O.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.hex_color}}),(0,O.jsx)(`span`,{className:`text-xs text-white/80 whitespace-nowrap`,children:e.color_name})]},e.id))})]}),(0,O.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:[le.map(e=>(0,O.jsx)(`button`,{onClick:()=>{z(e.hex),V(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${R===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex)),(0,O.jsx)(`button`,{onClick:()=>me(!W),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:x(W?`configureAmsSlot.showLessColors`:`configureAmsSlot.showMoreColors`),children:W?`−`:`+`})]}),W&&(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:ue.map(e=>(0,O.jsx)(`button`,{onClick:()=>{z(e.hex),V(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${R===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex))}),(0,O.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,O.jsx)(`div`,{className:`w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0`,style:b(Le)}),(0,O.jsx)(`input`,{type:`text`,placeholder:x(`configureAmsSlot.colorPlaceholder`),value:B,onChange:e=>{let t=e.target.value;V(t);let n=de(t);if(n)z(n);else{let e=t.replace(/[^0-9A-Fa-f]/g,``).toUpperCase();e.length===6?z(e):e.length===3&&z(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`}),R&&(0,O.jsx)(`button`,{onClick:()=>{z(``),V(``)},className:`px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded`,title:x(`configureAmsSlot.clearCustomColor`),children:x(`configureAmsSlot.clear`)})]}),R&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5`,children:x(`configureAmsSlot.hexLabel`,{hex:R})})]})]})]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[x(`configureAmsSlot.filamentProfile`),` `,(0,O.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(`input`,{type:`text`,placeholder:x(`configureAmsSlot.searchPresets`),value:H,onChange:e=>fe(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,O.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:Oe.length===0?(0,O.jsx)(`p`,{className:`text-center py-4 text-bambu-gray`,children:G?.filament?.length===0&&!K?.filament?.length?x(`configureAmsSlot.noPresetsAvailable`):x(`configureAmsSlot.noMatchingPresets`)}):Oe.map(e=>(0,O.jsx)(`button`,{"data-preset-id":e.id,onClick:()=>A(e.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${k===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:(0,O.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,O.jsx)(`span`,{className:`text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all`,title:e.name,children:e.name}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[e.source===`local`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,children:x(`profiles.localProfiles.badge`)}),e.source===`orca_cloud`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,children:x(`configureAmsSlot.orcaCloud`)}),e.source===`cloud`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue`,children:x(`configureAmsSlot.bambuCloud`)}),e.source===`builtin`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,children:x(`configureAmsSlot.builtin`)})]})]})},e.id))})]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[x(`configureAmsSlot.kProfileLabel`),ke&&(0,O.jsx)(`span`,{className:`ml-2 text-xs text-bambu-blue`,children:x(`configureAmsSlot.filteringFor`,{material:ke})})]}),Me?(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsxs)(`select`,{value:F?M(F):``,onChange:e=>Ne(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10`,children:[(0,O.jsx)(`option`,{value:``,children:x(`configureAmsSlot.noKProfile`)}),Q.map(e=>(0,O.jsxs)(`option`,{value:M(e),children:[e.name,` (K=`,e.k_value,`)`,oe(e,je,x)]},M(e))),$.length>0&&(0,O.jsx)(`optgroup`,{label:x(`configureAmsSlot.otherKProfiles`),children:$.map(e=>(0,O.jsxs)(`option`,{value:M(e),children:[e.name,` (K=`,e.k_value,`)`,oe(e,je,x)]},M(e)))})]}),(0,O.jsx)(c,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}):k?(0,O.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:x(`configureAmsSlot.noMatchingKProfiles`)}):(0,O.jsx)(`span`,{className:`inline-block text-xs px-2 py-1 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 border border-amber-300 dark:border-amber-500/30`,children:x(`configureAmsSlot.selectFilamentFirst`)}),F&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-green mt-1`,children:x(`configureAmsSlot.kFromCalibration`,{value:F.k_value})})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:x(`configureAmsSlot.customColorLabel`)}),Ae.length>0&&(0,O.jsxs)(`div`,{className:`mb-3`,children:[(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1.5`,children:x(`configureAmsSlot.presetColors`,{name:Z?.fullName})}),(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Ae.map(e=>(0,O.jsxs)(`button`,{onClick:()=>{z(e.hex_color.replace(`#`,``).toUpperCase()),V(e.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${R===e.hex_color.replace(`#`,``).toUpperCase()?`border-bambu-green scale-105`:`border-white/20 hover:border-white/40`}`,title:e.color_name,children:[(0,O.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.hex_color}}),(0,O.jsx)(`span`,{className:`text-xs text-white/80 whitespace-nowrap`,children:e.color_name})]},e.id))})]}),(0,O.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:[le.map(e=>(0,O.jsx)(`button`,{onClick:()=>{z(e.hex),V(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${R===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex)),(0,O.jsx)(`button`,{onClick:()=>me(!W),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:x(W?`configureAmsSlot.showLessColors`:`configureAmsSlot.showMoreColors`),children:W?`−`:`+`})]}),W&&(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:ue.map(e=>(0,O.jsx)(`button`,{onClick:()=>{z(e.hex),V(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${R===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex))}),(0,O.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,O.jsx)(`div`,{className:`w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0`,style:b(Le)}),(0,O.jsx)(`input`,{type:`text`,placeholder:x(`configureAmsSlot.colorPlaceholder`),value:B,onChange:e=>{let t=e.target.value;V(t);let n=de(t);if(n)z(n);else{let e=t.replace(/[^0-9A-Fa-f]/g,``).toUpperCase();e.length===6?z(e):e.length===3&&z(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`}),R&&(0,O.jsx)(`button`,{onClick:()=>{z(``),V(``)},className:`px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded`,title:x(`configureAmsSlot.clearCustomColor`),children:x(`configureAmsSlot.clear`)})]}),R&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5`,children:x(`configureAmsSlot.hexLabel`,{hex:R})})]})]})]}),(0,O.jsxs)(`div`,{className:`flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0`,children:[(0,O.jsx)(m,{variant:`secondary`,onClick:()=>De.mutate(),disabled:De.isPending||Ee.isPending,className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-500/10`,children:De.isPending?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(u,{className:`w-4 h-4 animate-spin`}),x(`configureAmsSlot.resetting`)]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(g,{className:`w-4 h-4`}),x(`configureAmsSlot.resetSlot`)]})}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsx)(m,{variant:`secondary`,onClick:t,children:x(`configureAmsSlot.cancel`)}),(0,O.jsx)(m,{onClick:()=>Ee.mutate(),disabled:!Ie,children:Ee.isPending?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(u,{className:`w-4 h-4 animate-spin`}),x(`configureAmsSlot.configuring`)]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(p,{className:`w-4 h-4`}),x(`configureAmsSlot.configureSlot`)]})})]})]}),(Ee.isError||De.isError)&&(0,O.jsx)(`div`,{className:`mx-4 mb-4 p-2 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-sm text-red-700 dark:text-red-400`,children:Ee.error?.message||De.error?.message})]})]})}export{A as n,k as r,P as t};