ConfigureAmsSlotModal-CbooDTZJ.js 45 KB

1
  1. import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{T as t,a as n,k as r,w as i}from"./client-Wixdakxn.js";import{n as a}from"./QueryClientProvider-DEK0HFZS.js";import{t as o}from"./useQuery-DkJQ4hAK.js";import{t as s}from"./useMutation-C6DF_nPh.js";import{t as c}from"./arrow-left-CB7yV5kj.js";import{a as l}from"./info-Cs6q0Q_N.js";import{n as ee}from"./ToastContext-FG4Q6YJB.js";import{t as u}from"./circle-check-CkxF-bv8.js";import{t as d}from"./loader-circle-HWxuHTYP.js";import{t as f}from"./package-Cs0dyY6c.js";import{t as te}from"./qr-code-sm0XMy71.js";import{t as p}from"./rotate-ccw-CP7fZeaJ.js";import{t as m}from"./search-W6Qccq34.js";import{t as h}from"./settings-2-DjCtXdKz.js";import{t as ne}from"./x-vFoBjOZn.js";import{t as g}from"./Button-Bj3LhBE2.js";import{t as _}from"./ConfirmModal-Cswi0gVe.js";import{M as v,N as y,j as re,m as b}from"./amsHelpers-DDsrDUnz.js";import{a as x,c as S}from"./colors-BBBvvSKR.js";import{n as C}from"./useUiSettings-BC4O5ZgX.js";import{t as ie}from"./printer-DfB6SVGc.js";import{a as ae,i as w,n as oe,r as T}from"./slicerPrinterMatch-CUdoNag2.js";import{m as se}from"./utils-CRm_p6_K.js";import{n as E,r as ce,t as le}from"./nozzleFlow-DwF_jePd.js";import{a as ue,c as de,i as fe,l as D,n as O,o as pe,r as me,s as he,t as k}from"./inventorySearch-D36VsGbN.js";import{t as ge}from"./useCancellableTimeout-CGrjpQD3.js";var A=e(r(),1),j=i();function M(e){return[e.brand,e.material,e.subtype].filter(Boolean).join(` `)}function N({isOpen:e,onClose:r,printerId:i,amsId:l,trayId:u,trayInfo:p,spoolmanEnabled:h}){let{t:_}=t(),v=a(),{showToast:y}=ee(),[re,b]=(0,A.useState)(!1),[ie,ae]=(0,A.useState)(null),[w,oe]=(0,A.useState)(null);(0,A.useEffect)(()=>{ae(null),oe(null)},[re]);let[T,se]=(0,A.useState)(``),[E,ce]=(0,A.useState)(null),[le,ge]=(0,A.useState)(!1),[N,P]=(0,A.useState)(null),F=(0,A.useRef)(!1);(0,A.useEffect)(()=>{e&&(b(!1),ge(!1),P(null),F.current=!1)},[e]);let{data:I,isLoading:L,isFetching:_e}=o({queryKey:[`inventory-spools`,`assign-modal`],queryFn:()=>n.getSpools(!0),enabled:e&&!h}),{data:ve}=o({queryKey:[`spool-assignments`],queryFn:()=>n.getAssignments(),enabled:e}),{data:ye}=C({enabled:e}),{data:be,isLoading:R}=o({queryKey:[`spoolman-inventory-spools`,`assign-modal`],queryFn:()=>n.getSpoolmanInventorySpools(!1),enabled:e&&!!h}),{data:xe}=o({queryKey:[`spoolman-slot-assignments`,`all`],queryFn:()=>n.getSpoolmanSlotAssignments(),enabled:e&&!!h}),Se=(0,A.useMemo)(()=>xe?new Set(xe.filter(e=>!(e.printer_id===i&&e.ams_id===l&&e.tray_id===u)).map(e=>e.spoolman_spool_id)):new Set,[xe,i,l,u]),Ce=()=>{n.refreshPrinterStatus(i).catch(()=>{}),v.invalidateQueries({queryKey:[`printerStatus`,i]})},z=s({mutationFn:({spoolId:e,move:t})=>n.assignSpool({spool_id:e,printer_id:i,ams_id:l,tray_id:u,...t&&{move:t}}),onSuccess:(e,{move:t})=>{v.setQueryData([`spool-assignments`],n=>{let r=(n||[]).filter(n=>!(n.printer_id===i&&n.ams_id===l&&n.tray_id===u)&&!(t&&n.spool_id===e.spool_id));return r.push(e),r}),v.invalidateQueries({queryKey:[`spool-assignments`]}),Ce();let n=e.pending_config?`inventory.assignPendingInsert`:`inventory.assignSuccess`;y(_(n),`success`),ce(null),r()},onError:e=>{y(`${_(`inventory.assignFailed`)}: ${e.message}`,`error`),F.current=!1}}),B=s({mutationFn:({spoolmanSpoolId:e,move:t})=>n.assignSpoolmanSlot({spoolman_spool_id:e,printer_id:i,ams_id:l,tray_id:u,...t&&{move:t}}),onSuccess:(e,{move:t})=>{v.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),v.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),t&&v.invalidateQueries({queryKey:[`linked-spools`]}),Ce(),y(_(`inventory.assignSuccess`),`success`),r()},onError:e=>{let t=`${_(`inventory.assignFailed`)}: ${e.message}`;F.current?P(t):y(t,`error`),F.current=!1}});if(!e)return null;let V=new Set((ve||[]).filter(e=>!(e.printer_id===i&&e.ams_id===l&&e.tray_id===u)).map(e=>e.spool_id)),H=I?.filter(e=>!e.archived_at&&(re||!V.has(e.id))),U=k(T),W=H;if(!re&&U===null){let e=D(de(p?.profile)),t=de(p?.material||p?.type);(e||t)&&(W=W?.filter(n=>{let r=D(de(n.slicer_filament_name||n.slicer_filament)),i=de(n.material);return e&&r&&r===e?!0:t&&i?i===t||t.includes(i)||i.includes(t):!r&&!i}))}T&&W&&(W=O(W,T));let we=null;if(U!==null&&I&&W?.length===0){let e=I.find(e=>e.id===U);we=e?e.archived_at?_(`inventory.spoolIdArchived`,{id:U}):_(`inventory.spoolIdInOtherSlot`,{id:U}):_(`inventory.spoolIdNotFound`,{id:U})}let G=(e,t)=>{let n=!ye?.disable_filament_warnings&&p?he(e,p):null;if(n){ce({spoolId:e.id,move:t,details:n});return}z.mutate({spoolId:e.id,move:t})},Te=()=>{if(w!==null){B.mutate({spoolmanSpoolId:w});return}if(!ie)return;let e=I?.find(e=>e.id===ie);if(!e){y(_(`inventory.assignFailed`),`error`);return}G(e,!1)},Ee=()=>{E&&(z.mutate({spoolId:E.spoolId,move:E.move}),ce(null))},De=()=>{ce(null),F.current=!1},K=e=>{if(F.current||z.isPending||B.isPending)return;let t=me(e);if(!t){P(_(`inventory.qrAssign.invalidQr`));return}let n=fe(t,!!h);if(n===null){P(_(`inventory.qrAssign.spoolmanLabel`));return}if(h){P(null),F.current=!0,B.mutate({spoolmanSpoolId:n,move:!0});return}let r=I?.find(e=>e.id===n);if(!r){P(_(`inventory.spoolIdNotFound`,{id:n}));return}if(r.archived_at){P(_(`inventory.spoolIdArchived`,{id:n}));return}P(null),F.current=!0,G(r,!0)},Oe=()=>{ge(!1),P(null),F.current=!1},ke=z.isPending||B.isPending,q=(()=>{if(h){let e=xe?.find(e=>e.printer_id===i&&e.ams_id===l&&e.tray_id===u);return e?{id:e.spoolman_spool_id,spool:be?.find(t=>t.id===e.spoolman_spool_id)}:null}let e=ve?.find(e=>e.printer_id===i&&e.ams_id===l&&e.tray_id===u);return e?{id:e.spool_id,spool:e.spool??I?.find(t=>t.id===e.spool_id)}:null})(),J=p?.type||(p?.emptyKind===`physical`?_(`ams.emptySlot`):_(`ams.emptySlotReset`));return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-start sm:items-center justify-center p-4 overflow-y-auto`,children:[(0,j.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:r}),(0,j.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,j.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[le?(0,j.jsx)(te,{className:`w-5 h-5 text-bambu-green`}):(0,j.jsx)(f,{className:`w-5 h-5 text-bambu-green`}),(0,j.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:_(le?`inventory.qrAssign.scanTitle`:`inventory.assignSpool`)})]}),(0,j.jsx)(`button`,{onClick:r,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,j.jsx)(ne,{className:`w-5 h-5`})})]}),(0,j.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto`,children:[p&&(0,j.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,j.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:[_(`inventory.selectSpool`),`:`]}),(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[p.color&&(0,j.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:x(p.color)}),(0,j.jsx)(`span`,{className:`text-white font-medium`,children:J}),(0,j.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,p.location,`)`]})]}),q&&(0,j.jsxs)(`p`,{className:`mt-1 text-xs text-bambu-gray truncate`,children:[_(`inventory.assigned`),`:`,` `,(0,j.jsxs)(`span`,{className:`text-white`,children:[`#`,q.id,q.spool?` ${M(q.spool)}`:``]})]})]}),le?(0,j.jsx)(ue,{onDecode:K,busy:ke||E!==null||_e,error:N}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,j.jsxs)(`div`,{className:`relative flex-1 min-w-[12rem]`,children:[(0,j.jsx)(m,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,j.jsx)(`input`,{type:`text`,value:T,onChange:e=>se(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,j.jsxs)(g,{variant:`secondary`,onClick:()=>{P(null),ge(!0)},children:[(0,j.jsx)(te,{className:`w-4 h-4`}),(0,j.jsx)(`span`,{className:`whitespace-nowrap`,children:_(`inventory.qrAssign.scanTitle`)})]})]}),(0,j.jsxs)(`div`,{className:`space-y-3`,children:[!h&&(L?(0,j.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,j.jsx)(d,{className:`w-6 h-6 text-bambu-green animate-spin`})}):W&&W.length>0?(0,j.jsx)(`div`,{className:`max-h-96 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2`,children:W.map(e=>(0,j.jsxs)(`button`,{onClick:()=>{ae(e.id),oe(null)},title:e.note||void 0,className:`p-2.5 rounded-lg border text-left transition-colors ${ie===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,j.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,j.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,j.jsxs)(`span`,{className:`text-[10px] font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]}),(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[e.rgba&&(0,j.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:x(e.rgba)}),(0,j.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:S(e.color_name,e.rgba,e.color_name_is_synthesized)||``})]}),e.label_weight&&(0,j.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,j.jsx)(`p`,{className:`text-[10px] text-bambu-gray/70 mt-1 truncate`,title:e.note,children:e.note})]},e.id))}):we?(0,j.jsx)(`div`,{className:`text-center py-8 text-bambu-gray`,children:(0,j.jsx)(`p`,{children:we})}):H&&H.length===0?(0,j.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,j.jsx)(`p`,{children:_(`inventory.noAvailableSpools`)}),I&&(0,j.jsxs)(`p`,{className:`text-[10px] mt-2 opacity-60`,children:[I.length,` fetched · `,I.filter(e=>e.archived_at).length,` archived ·`,` `,I.filter(e=>V.has(e.id)).length,` assigned to other slots`]})]}):(0,j.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,j.jsx)(`p`,{children:_(`inventory.noSpoolsMatch`)}),H&&(0,j.jsxs)(`p`,{className:`text-[10px] mt-2 opacity-60`,children:[H.length,` unassigned spools — `,H.length-(W?.length??0),` filtered by tray match. Try "Show all spools".`]})]})),h&&(0,j.jsx)(j.Fragment,{children:R?(0,j.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,j.jsx)(d,{className:`w-5 h-5 text-bambu-green animate-spin`})}):be&&be.filter(e=>!e.archived_at&&!Se.has(e.id)).length>0?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide pt-1`,children:_(`inventory.spoolmanSpools`)}),(0,j.jsx)(`div`,{className:`max-h-64 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2`,children:O(be.filter(e=>!e.archived_at&&!Se.has(e.id)),T).map(e=>(0,j.jsxs)(`button`,{onClick:()=>{oe(e.id),ae(null)},title:e.note||void 0,className:`p-2.5 rounded-lg border text-left transition-colors ${w===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,j.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,j.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,j.jsxs)(`span`,{className:`text-[10px] font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]}),(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[e.rgba&&(0,j.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:x(e.rgba)}),(0,j.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:S(e.color_name,e.rgba,e.color_name_is_synthesized)||``})]}),e.label_weight&&(0,j.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,j.jsx)(`p`,{className:`text-[10px] text-bambu-gray/70 mt-1 truncate`,title:e.note,children:e.note})]},`spoolman-${e.id}`))})]}):null})]})]})]}),le?(0,j.jsx)(`div`,{className:`flex justify-start p-4 border-t border-bambu-dark-tertiary`,children:(0,j.jsxs)(g,{variant:`secondary`,onClick:Oe,disabled:ke,children:[(0,j.jsx)(c,{className:`w-4 h-4`}),_(`inventory.qrAssign.back`)]})}):(0,j.jsxs)(`div`,{className:`flex justify-between items-center p-4 border-t border-bambu-dark-tertiary`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsx)(`input`,{id:`disable-filtering-toggle`,type:`checkbox`,checked:re,onChange:()=>b(e=>!e),className:`accent-bambu-green w-4 h-4 rounded focus:ring-0 border-bambu-dark-tertiary`}),(0,j.jsx)(`label`,{htmlFor:`disable-filtering-toggle`,className:`text-xs text-bambu-gray select-none cursor-pointer`,children:_(`inventory.showAllSpools`)})]}),(0,j.jsxs)(`div`,{className:`flex gap-2`,children:[(0,j.jsx)(g,{variant:`secondary`,onClick:r,children:_(`common.cancel`)}),(0,j.jsx)(g,{onClick:Te,disabled:!ie&&w===null||z.isPending||B.isPending,children:z.isPending||B.isPending?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(d,{className:`w-4 h-4 animate-spin`}),_(`inventory.assigning`)]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(f,{className:`w-4 h-4`}),_(`inventory.assignSpool`)]})})]})]}),z.isError&&(0,j.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:z.error.message})]})]}),E&&p&&(0,j.jsx)(pe,{mismatch:E.details,location:p.location,isLoading:z.isPending,onConfirm:Ee,onCancel:()=>{z.isPending||De()}})]})}var P=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`NYLON`,`PVA`,`HIPS`,`PP`,`PET`];function F(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 P)if(RegExp(`\\b${n}\\b`).test(e))return{material:n,brand:t.slice(0,r.index).trim(),variant:`Support`}}for(let e of P){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 I(e){let t=E(ce(e.nozzle_id));return t?`[${t}] `:``}function L(e){return`${e.extruder_id??0}|${e.name}|${e.k_value}`}function _e(e,t){return t!==void 0&&e.some(e=>(e.extruder_id??0)===t)}function ve(e,t,n){return _e(e,n)?e.find(e=>e.slot_id===t&&(e.extruder_id??0)===n):e.find(e=>e.slot_id===t)}function ye(e,t,n){return t?` \u00b7 ${e.extruder_id===1?n(`common.left`):n(`common.right`)}`:``}function be(e){return!e.startsWith(`GF`)&&!e.startsWith(`P1`)}var R={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`},xe=[{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`}],Se=[{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 Ce(e){return R[e.toLowerCase().trim()]||null}function z({isOpen:e,onClose:r,printerId:i,slotInfo:a,nozzleDiameter:c=`0.4`,printerModel:f,onSuccess:te,fullScreen:m,printerState:S}){let{t:C}=t(),{showToast:E}=ee(),[ue,de]=(0,A.useState)(!1),fe=ie.includes(S??``),[D,O]=(0,A.useState)(``),[pe,me]=(0,A.useState)(``),he=(0,A.useCallback)(e=>e===pe?{slotTrayInfoIdx:a.trayInfoIdx}:{pickedFromList:!0},[pe,a.trayInfoIdx]),[k,M]=(0,A.useState)(null),N=(0,A.useRef)(null);N.current=k;let[R,z]=(0,A.useState)(``),[B,V]=(0,A.useState)(``),[H,U]=(0,A.useState)(``),[W,we]=(0,A.useState)(!1),[G,Te]=(0,A.useState)(!1),Ee=(0,A.useRef)(``),{schedule:De}=ge(),{data:K,isLoading:Oe,isError:ke}=o({queryKey:[`cloudSettings`],queryFn:()=>n.getCloudSettings(),enabled:e,retry:!1}),{data:q}=o({queryKey:[`orcaCloudProfilesForAmsSlot`],queryFn:()=>n.orcaCloudListProfiles(),enabled:e,retry:!1}),{data:J,isLoading:Ae}=o({queryKey:[`localPresets`],queryFn:()=>n.getLocalPresets(),enabled:e}),{data:Y,isLoading:je}=o({queryKey:[`builtinFilaments`],queryFn:()=>n.getBuiltinFilaments(),enabled:e,staleTime:1/0}),{data:X,isLoading:Me}=o({queryKey:[`kprofiles`,i,c],queryFn:()=>n.getKProfiles(i,c),enabled:e&&!!i}),{data:Ne}=o({queryKey:[`colorCatalog`],queryFn:()=>n.getColorCatalog(),enabled:e,staleTime:1/0}),{data:Pe}=o({queryKey:[`slicerPrinterModels`],queryFn:n.getSlicerPrinterModels,enabled:e,staleTime:1/0}),{data:Z}=o({queryKey:[`slot-spool-defaults`,i,a.amsId,a.trayId],queryFn:()=>n.getSlotSpoolDefaults(i,a.amsId,a.trayId),enabled:e,staleTime:0}),Fe=(0,A.useMemo)(()=>oe(Pe??{}),[Pe]),Ie=(0,A.useMemo)(()=>{if(!f||!Pe)return null;for(let[e,t]of Object.entries(Pe))if(t===f)return`${e.startsWith(`Bambu Lab `)?e:`Bambu Lab ${e}`} ${c} nozzle`;return null},[f,Pe,c]),Le=s({mutationFn:async()=>{if(!D)throw Error(`No filament preset selected`);let e=D.startsWith(`local_`),t=D.startsWith(`builtin_`),r=D.startsWith(`orca_`)?D.replace(`orca_`,``):D,o=!e&&!t?q?.filament.find(e=>e.setting_id===r):void 0,s=!!o,l=o??null,ee=e?parseInt(D.replace(`local_`,``),10):null,u=t?D.replace(`builtin_`,``):null,d=e?J?.filament.find(e=>e.id===ee):null,f=t?Y?.find(e=>e.filament_id===u):null,te=!e&&!t&&!s?K?.filament.find(e=>e.setting_id===D):null;if(!e&&!t&&!s&&!te)throw Error(`Selected preset not found`);if(e&&!d)throw Error(`Selected local preset not found`);if(t&&!f)throw Error(`Selected builtin preset not found`);if(s&&!l)throw Error(`Selected Orca Cloud preset not found`);let p=e?d.name:t?f.name:s?l.name:te.name,m=F(p),h=N.current?.slot_id??-1,ne=R||a.trayColor?.slice(0,6)||`FFFFFF`,g=p.replace(/@.+$/,``).trim(),_,v,y=m.material.toUpperCase(),b={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=(P.includes(y)?y:d?.filament_type||m.material||``).toUpperCase();_=b[e]||b[e.replace(/[-\s]?CF$/,``)]||b[e.replace(/\+$/,``)]||b[e.split(/[-\s]/)[0]]||``,v=``}else if(s)_=``,v=``;else if(t)_=u,v=``;else{if(_=re(te,he(D)),v=D,!D.startsWith(`GFS`))try{let e=await n.getCloudSettingDetail(D),t=e.setting?.filament_id,r=e.filament_id||(typeof t==`string`?t:``);r&&(_=r)}catch(e){console.warn(`Failed to fetch preset detail for filament_id:`,e)}/^(PFUS|PFSP|PFCN)/.test(_)&&(console.warn(`Cloud preset ${D} carries no filament_id in either place; sending no tray_info_idx so the printer keeps a resolvable one.`),_=``)}let x=e&&d?.nozzle_temp_min?d.nozzle_temp_min:190,S=e&&d?.nozzle_temp_max?d.nozzle_temp_max:230;if(!e||t||s||!d?.nozzle_temp_min&&!d?.nozzle_temp_max){let t=(e?P.includes(y)?y:d?.filament_type||m.material||``:m.material).toUpperCase();t.includes(`PLA`)?(x=190,S=230):t.includes(`PETG`)?(x=220,S=260):t.includes(`ABS`)||t.includes(`ASA`)?(x=240,S=280):t.includes(`TPU`)?(x=200,S=240):t===`PCTG`?(x=220,S=260):t.includes(`PC`)?(x=260,S=300):(t.includes(`PA`)||t.includes(`NYLON`))&&(x=250,S=290)}let ie=N.current?.k_value?parseFloat(N.current.k_value):0,ae=e?P.includes(y)?y:d?.filament_type||m.material||`PLA`:s&&P.includes(y)?y:m.material||`PLA`,w=await n.configureAmsSlot(i,a.amsId,a.trayId,{tray_info_idx:_,tray_type:ae,tray_sub_brands:g,tray_color:ne+`FF`,nozzle_temp_min:x,nozzle_temp_max:S,cali_idx:h,nozzle_diameter:c,setting_id:v,kprofile_filament_id:N.current?.filament_id,kprofile_setting_id:N.current?.setting_id||void 0,k_value:ie,orca_profile_id:s?r:void 0});w.k_value_unsent&&E(C(`configureAmsSlot.kValueUnsent`),`warning`),s&&w.orca_fallback_reason&&E(C(`configureAmsSlot.orcaFallback.${w.orca_fallback_reason}`,{material:ae}),`warning`);let oe=e?`local_${ee}`:t?`builtin_${u}`:D,T=e?`local`:t?`builtin`:s?`orca_cloud`:`cloud`;try{await n.saveSlotPreset(i,a.amsId,a.trayId,oe,g,T,w.tray_info_idx)}catch(e){console.warn(`Failed to save slot preset mapping:`,e)}return w},onSuccess:()=>{we(!0),te?.(),De(()=>{we(!1),r()},1500)}}),Re=s({mutationFn:async()=>n.resetAmsSlot(i,a.amsId,a.trayId),onSuccess:()=>{we(!0),te?.(),De(()=>{we(!1),r()},1500)}}),ze=(0,A.useMemo)(()=>{let e=H.toLowerCase(),t=[],n=new Set,r=a.savedPresetId,i=a.trayInfoIdx;if(q?.filament)for(let r of q.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,Pe??{});if(e&&!w(e,f))continue}t.push({id:i,name:r.name,source:`orca_cloud`,isUser:!0})}}if(K?.filament)for(let a of K.filament){if(n.has(a.setting_id))continue;n.add(a.setting_id);let o=r===a.setting_id||i&&(a.setting_id===i||v(a).includes(i));if(!(e&&!a.name.toLowerCase().includes(e))){if(!o&&f){let e=T(a.name,Pe??{});if(e&&!w(e,f))continue}t.push({id:a.setting_id,name:a.name,source:`cloud`,isUser:be(a.setting_id)})}}if(J?.filament){let n=a.savedPresetId;for(let r of J.filament){let i=`local_${r.id}`;if(!(e&&!r.name.toLowerCase().includes(e))){if(n!==i&&Ie){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(ae({name:r.name,compatible_printers:e},`filament`,Ie,Fe)===`mismatch`)continue}t.push({id:i,name:r.name,source:`local`,isUser:!1})}}}if(Y)for(let r of Y){if(n.has(r.filament_id))continue;let i=y(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]})},[q?.filament,K?.filament,J?.filament,Y,H,f,a.savedPresetId,a.trayInfoIdx,Ie,Fe,Pe]),Q=(0,A.useMemo)(()=>{if(!D)return null;let e=null,t=``;if(D.startsWith(`local_`)){let t=parseInt(D.replace(`local_`,``),10);e=J?.filament.find(e=>e.id===t)?.name||null}else if(D.startsWith(`builtin_`)){let n=D.replace(`builtin_`,``);e=Y?.find(e=>e.filament_id===n)?.name||null,t=se(n)}else{let n=D.startsWith(`orca_`)?D.replace(`orca_`,``):D,r=q?.filament.find(e=>e.setting_id===n);if(r)e=r.name;else if(K?.filament){let n=K.filament.find(e=>e.setting_id===D);e=n?.name||null,n&&(t=se(re(n,he(n.setting_id))))}}if(!e)return null;let n=e.replace(/@.+$/,``).trim();n.startsWith(`# `)&&(n=n.slice(2).trim());let r=F(n);return{fullName:n,material:r.material,brand:r.brand,filamentId:t}},[D,K?.filament,J?.filament,Y,q?.filament,he]),Be=Q?.fullName||``,Ve=(0,A.useMemo)(()=>{if(!Ne||!Q)return[];let{fullName:e,brand:t}=Q,n=e.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,``).trim();return Ne.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})},[Ne,Q]),He=(0,A.useMemo)(()=>new Set((X?.profiles??[]).map(e=>e.extruder_id??0)).size>1,[X?.profiles]),{data:Ue}=o({queryKey:[`printerStatus`,i],queryFn:()=>n.getPrinterStatus(i),enabled:e}),We=(0,A.useMemo)(()=>{let e=Ue?.nozzles??[];return ce(e[a.extruderId??0]?.nozzle_type)??ce(e[0]?.nozzle_type)},[Ue?.nozzles,a.extruderId]),$=(0,A.useMemo)(()=>{if(!X?.profiles)return[];if(!Q){let e=a.caliIdx;if(e!=null&&e>0){let t=ve(X.profiles,e,a.extruderId);if(t)return[t]}return[]}let{fullName:e,material:t,brand:n,filamentId:r}=Q,i=e.toUpperCase(),o=t.toUpperCase(),s=n.toUpperCase()===`GENERIC`?``:n.toUpperCase(),c=r;if(!o||o.length<2)return[];let l=X.profiles.filter(e=>{if(c){let t=se(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}),ee=(_e(X.profiles,a.extruderId)?l.filter(e=>(e.extruder_id??0)===a.extruderId):l).filter(e=>le(e.nozzle_id,We)),u=new Map;for(let e of ee){let t=L(e);u.has(t)||u.set(t,e)}let d=Array.from(u.values()),f=a.caliIdx;if((pe&&D===pe||c&&c===se(a.trayInfoIdx))&&f!=null&&f>0&&!d.some(e=>e.slot_id===f)){let e=ve(X.profiles,f,a.extruderId);e&&d.unshift(e)}return d},[X?.profiles,Q,a.extruderId,a.caliIdx,a.trayInfoIdx,D,pe,We]),Ge=(0,A.useMemo)(()=>{if(!X?.profiles)return[];let e=new Set($.map(e=>L(e))),t=new Map;for(let n of X.profiles){let r=L(n);e.has(r)||t.has(r)||t.set(r,n)}return Array.from(t.values()).sort((e,t)=>e.name.localeCompare(t.name))},[X?.profiles,$]),Ke=$.length>0||Ge.length>0,qe=(0,A.useCallback)(e=>{if(!e){M(null);return}let t=$.find(t=>L(t)===e)||Ge.find(t=>L(t)===e)||null;M(t)},[$,Ge]);(0,A.useEffect)(()=>{if(e){if(Z?.slicer_filament)O(Z.slicer_filament),me(Z.slicer_filament);else if(a.savedPresetId)O(a.savedPresetId),me(a.savedPresetId);else if(a.trayInfoIdx&&K?.filament){let e=K.filament.find(e=>e.setting_id===a.trayInfoIdx);e||=K.filament.find(e=>e.filament_id===a.trayInfoIdx)||K.filament.find(e=>v(e).includes(a.trayInfoIdx)),e&&(O(e.setting_id),me(e.setting_id))}else if(a.trayInfoIdx&&Y?.length){let e=a.trayInfoIdx,t=Y.find(t=>t.filament_id===e);t&&(O(`builtin_${t.filament_id}`),me(`builtin_${t.filament_id}`))}if(a.trayColor){let e=a.trayColor.slice(0,6);e&&z(e)}}else O(``),me(``),M(null),z(``),V(``),U(``),we(!1),Ee.current=``},[e,Z?.slicer_filament,a.savedPresetId,a.trayInfoIdx,a.trayColor,K?.filament,Y]),(0,A.useEffect)(()=>{if($.length>0){if(Z?.cali_idx!=null){let e=ve($,Z.cali_idx,Z.extruder??a.extruderId);if(e){M(e);return}}if(a.caliIdx!=null&&a.caliIdx>0){let e=ve($,a.caliIdx,a.extruderId);if(e){M(e);return}}M($[0])}else M(null)},[D,$,Z?.cali_idx,Z?.extruder,a.caliIdx,a.extruderId]);let Je=(0,A.useCallback)(e=>{e.key===`Escape`&&!ue&&r()},[r,ue]);(0,A.useEffect)(()=>{if(e)return document.addEventListener(`keydown`,Je),()=>document.removeEventListener(`keydown`,Je)},[e,Je]);let Ye=Oe&&!ke||Ae||je||Me;if((0,A.useEffect)(()=>{if(!Ye&&D&&D!==Ee.current){let e=requestAnimationFrame(()=>{let e=document.querySelector(`[class*="fixed inset-0 z-50"]`)?.querySelector(`[data-preset-id="${CSS.escape(D)}"]`);e&&(Ee.current=D,e.scrollIntoView({block:`nearest`}))});return()=>cancelAnimationFrame(e)}},[D,Ye]),!e)return null;let Xe=D&&!Le.isPending,Ze=R||a.trayColor||`FFFFFF`;return(0,j.jsxs)(`div`,{className:`fixed inset-0 z-50 flex ${m?``:`items-center justify-center`}`,children:[!m&&(0,j.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:r}),(0,j.jsxs)(`div`,{className:m?`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,j.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsx)(h,{className:`w-5 h-5 text-bambu-blue`}),(0,j.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:C(`configureAmsSlot.title`)}),m&&(0,j.jsxs)(`div`,{className:`flex items-center gap-2 ml-4 text-sm text-bambu-gray`,children:[(0,j.jsx)(`span`,{className:`text-white/30`,children:`|`}),a.trayColor&&(0,j.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:x(a.trayColor)}),(0,j.jsx)(`span`,{className:`text-white/70`,children:C(`configureAmsSlot.slotLabel`,{ams:b(a.amsId),slot:a.trayId+1})}),a.traySubBrands&&(0,j.jsxs)(`span`,{children:[`(`,a.traySubBrands,`)`]})]})]}),(0,j.jsx)(`button`,{onClick:r,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,j.jsx)(ne,{className:`w-5 h-5`})})]}),(0,j.jsxs)(`div`,{className:`p-4 overflow-y-auto ${m?`flex-1 min-h-0`:`space-y-4 max-h-[60vh]`}`,children:[W&&(0,j.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl`,children:(0,j.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,j.jsx)(u,{className:`w-16 h-16 text-bambu-green mx-auto`}),(0,j.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:C(`configureAmsSlot.slotConfigured`)}),(0,j.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:C(`configureAmsSlot.settingsSentToPrinter`)})]})}),!m&&(0,j.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,j.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:C(`configureAmsSlot.configuringSlot`)}),(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a.trayColor&&(0,j.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:x(a.trayColor)}),(0,j.jsx)(`span`,{className:`text-white font-medium`,children:C(`configureAmsSlot.slotLabel`,{ams:b(a.amsId),slot:a.trayId+1})}),a.traySubBrands&&(0,j.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,a.traySubBrands,`)`]})]})]}),Ye?(0,j.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,j.jsx)(d,{className:`w-6 h-6 text-bambu-green animate-spin`})}):m?(0,j.jsxs)(`div`,{className:`flex gap-4 h-full`,children:[(0,j.jsxs)(`div`,{className:`w-1/2 flex flex-col min-h-0`,children:[(0,j.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[C(`configureAmsSlot.filamentProfile`),` `,(0,j.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,j.jsx)(`input`,{type:`text`,placeholder:C(`configureAmsSlot.searchPresets`),value:H,onChange:e=>U(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,j.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto space-y-1`,children:ze.length===0?(0,j.jsx)(`p`,{className:`text-center py-4 text-bambu-gray`,children:K?.filament?.length===0&&!J?.filament?.length?C(`configureAmsSlot.noPresetsAvailable`):C(`configureAmsSlot.noMatchingPresets`)}):ze.map(e=>(0,j.jsx)(`button`,{"data-preset-id":e.id,onClick:()=>O(e.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${D===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:(0,j.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,j.jsx)(`span`,{className:`text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all`,title:e.name,children:e.name}),(0,j.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[e.source===`local`&&(0,j.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:C(`profiles.localProfiles.badge`)}),e.source===`orca_cloud`&&(0,j.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:C(`configureAmsSlot.orcaCloud`)}),e.source===`cloud`&&(0,j.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,j.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:C(`configureAmsSlot.builtin`)})]})]})},e.id))})]}),(0,j.jsxs)(`div`,{className:`w-1/2 flex flex-col gap-4 min-h-0 overflow-y-auto`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[C(`configureAmsSlot.kProfileLabel`),Be&&(0,j.jsx)(`span`,{className:`ml-2 text-xs text-bambu-blue`,children:C(`configureAmsSlot.filteringFor`,{material:Be})})]}),Ke?(0,j.jsxs)(`div`,{className:`relative`,children:[(0,j.jsxs)(`select`,{value:k?L(k):``,onChange:e=>qe(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,j.jsx)(`option`,{value:``,children:C(`configureAmsSlot.noKProfile`)}),$.map(e=>(0,j.jsxs)(`option`,{value:L(e),children:[I(e),e.name,` (K=`,e.k_value,`)`,ye(e,He,C)]},L(e))),Ge.length>0&&(0,j.jsx)(`optgroup`,{label:C(`configureAmsSlot.otherKProfiles`),children:Ge.map(e=>(0,j.jsxs)(`option`,{value:L(e),children:[I(e),e.name,` (K=`,e.k_value,`)`,ye(e,He,C)]},L(e)))})]}),(0,j.jsx)(l,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}):D?(0,j.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:C(`configureAmsSlot.noMatchingKProfiles`)}):(0,j.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:C(`configureAmsSlot.selectFilamentFirst`)}),k&&(0,j.jsx)(`p`,{className:`text-xs text-bambu-green mt-1`,children:C(`configureAmsSlot.kFromCalibration`,{value:k.k_value})})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:C(`configureAmsSlot.customColorLabel`)}),Ve.length>0&&(0,j.jsxs)(`div`,{className:`mb-3`,children:[(0,j.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1.5`,children:C(`configureAmsSlot.presetColors`,{name:Q?.fullName})}),(0,j.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Ve.map(e=>(0,j.jsxs)(`button`,{onClick:()=>{let t=e.hex_color.replace(`#`,``).toUpperCase();z(t),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,j.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.hex_color}}),(0,j.jsx)(`span`,{className:`text-xs text-white/80 whitespace-nowrap`,children:e.color_name})]},e.id))})]}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:[xe.map(e=>(0,j.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,j.jsx)(`button`,{onClick:()=>Te(!G),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(G?`configureAmsSlot.showLessColors`:`configureAmsSlot.showMoreColors`),children:G?`−`:`+`})]}),G&&(0,j.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:Se.map(e=>(0,j.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,j.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,j.jsx)(`div`,{className:`w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0`,style:x(Ze)}),(0,j.jsx)(`input`,{type:`text`,placeholder:C(`configureAmsSlot.colorPlaceholder`),value:B,onChange:e=>{let t=e.target.value;V(t);let n=Ce(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,j.jsx)(`button`,{onClick:()=>{z(``),V(``)},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`)})]}),R&&(0,j.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5`,children:C(`configureAmsSlot.hexLabel`,{hex:R})})]})]})]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[C(`configureAmsSlot.filamentProfile`),` `,(0,j.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,j.jsxs)(`div`,{className:`relative`,children:[(0,j.jsx)(`input`,{type:`text`,placeholder:C(`configureAmsSlot.searchPresets`),value:H,onChange:e=>U(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,j.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:ze.length===0?(0,j.jsx)(`p`,{className:`text-center py-4 text-bambu-gray`,children:K?.filament?.length===0&&!J?.filament?.length?C(`configureAmsSlot.noPresetsAvailable`):C(`configureAmsSlot.noMatchingPresets`)}):ze.map(e=>(0,j.jsx)(`button`,{"data-preset-id":e.id,onClick:()=>O(e.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${D===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:(0,j.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,j.jsx)(`span`,{className:`text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all`,title:e.name,children:e.name}),(0,j.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[e.source===`local`&&(0,j.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:C(`profiles.localProfiles.badge`)}),e.source===`orca_cloud`&&(0,j.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:C(`configureAmsSlot.orcaCloud`)}),e.source===`cloud`&&(0,j.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,j.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:C(`configureAmsSlot.builtin`)})]})]})},e.id))})]})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[C(`configureAmsSlot.kProfileLabel`),Be&&(0,j.jsx)(`span`,{className:`ml-2 text-xs text-bambu-blue`,children:C(`configureAmsSlot.filteringFor`,{material:Be})})]}),Ke?(0,j.jsxs)(`div`,{className:`relative`,children:[(0,j.jsxs)(`select`,{value:k?L(k):``,onChange:e=>qe(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,j.jsx)(`option`,{value:``,children:C(`configureAmsSlot.noKProfile`)}),$.map(e=>(0,j.jsxs)(`option`,{value:L(e),children:[I(e),e.name,` (K=`,e.k_value,`)`,ye(e,He,C)]},L(e))),Ge.length>0&&(0,j.jsx)(`optgroup`,{label:C(`configureAmsSlot.otherKProfiles`),children:Ge.map(e=>(0,j.jsxs)(`option`,{value:L(e),children:[I(e),e.name,` (K=`,e.k_value,`)`,ye(e,He,C)]},L(e)))})]}),(0,j.jsx)(l,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}):D?(0,j.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:C(`configureAmsSlot.noMatchingKProfiles`)}):(0,j.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:C(`configureAmsSlot.selectFilamentFirst`)}),k&&(0,j.jsx)(`p`,{className:`text-xs text-bambu-green mt-1`,children:C(`configureAmsSlot.kFromCalibration`,{value:k.k_value})})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:C(`configureAmsSlot.customColorLabel`)}),Ve.length>0&&(0,j.jsxs)(`div`,{className:`mb-3`,children:[(0,j.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1.5`,children:C(`configureAmsSlot.presetColors`,{name:Q?.fullName})}),(0,j.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Ve.map(e=>(0,j.jsxs)(`button`,{onClick:()=>{let t=e.hex_color.replace(`#`,``).toUpperCase();z(t),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,j.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.hex_color}}),(0,j.jsx)(`span`,{className:`text-xs text-white/80 whitespace-nowrap`,children:e.color_name})]},e.id))})]}),(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:[xe.map(e=>(0,j.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,j.jsx)(`button`,{onClick:()=>Te(!G),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(G?`configureAmsSlot.showLessColors`:`configureAmsSlot.showMoreColors`),children:G?`−`:`+`})]}),G&&(0,j.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:Se.map(e=>(0,j.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,j.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,j.jsx)(`div`,{className:`w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0`,style:x(Ze)}),(0,j.jsx)(`input`,{type:`text`,placeholder:C(`configureAmsSlot.colorPlaceholder`),value:B,onChange:e=>{let t=e.target.value;V(t);let n=Ce(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,j.jsx)(`button`,{onClick:()=>{z(``),V(``)},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`)})]}),R&&(0,j.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5`,children:C(`configureAmsSlot.hexLabel`,{hex:R})})]})]})]}),(0,j.jsxs)(`div`,{className:`flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0`,children:[(0,j.jsx)(g,{variant:`secondary`,onClick:()=>de(!0),disabled:fe||Re.isPending||Le.isPending,title:fe?C(`configureAmsSlot.resetBlockedPrinting`):void 0,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:Re.isPending?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(d,{className:`w-4 h-4 animate-spin`}),C(`configureAmsSlot.resetting`)]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(p,{className:`w-4 h-4`}),C(`configureAmsSlot.resetSlot`)]})}),(0,j.jsxs)(`div`,{className:`flex gap-2`,children:[(0,j.jsx)(g,{variant:`secondary`,onClick:r,children:C(`configureAmsSlot.cancel`)}),(0,j.jsx)(g,{onClick:()=>Le.mutate(),disabled:!Xe,children:Le.isPending?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(d,{className:`w-4 h-4 animate-spin`}),C(`configureAmsSlot.configuring`)]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(h,{className:`w-4 h-4`}),C(`configureAmsSlot.configureSlot`)]})})]})]}),(Le.isError||Re.isError)&&(0,j.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:Le.error?.message||Re.error?.message})]}),ue&&(0,j.jsx)(_,{title:C(`configureAmsSlot.resetConfirmTitle`),message:C(`configureAmsSlot.resetConfirmMessage`),confirmText:C(`configureAmsSlot.resetSlot`),variant:`danger`,overlayZIndex:`z-[60]`,onConfirm:()=>{de(!1),Re.mutate()},onCancel:()=>de(!1)})]})}export{N as n,z as t};