ConfigureAmsSlotModal-DDCiNSu4.js 44 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-DSw2TdH4.js";import{n as a}from"./QueryClientProvider-B5vEWYBq.js";import{t as o}from"./useQuery-DfiorXB9.js";import{t as s}from"./useMutation-DLyYCmQ0.js";import{a as c}from"./info-3cB5_JmI.js";import{n as ee}from"./ToastContext-C3zxW_t3.js";import{t as l}from"./circle-check-CjN7Vmv0.js";import{t as u}from"./loader-circle-Ck-s1kyS.js";import{t as d}from"./package-BxMzbAJg.js";import{t as f}from"./rotate-ccw-DQ5GxrrP.js";import{t as p}from"./search-CiK-3DPp.js";import{t as m}from"./settings-2-C-EZSjBo.js";import{t as h}from"./x-DIT5l0_1.js";import{t as te}from"./Button-C_-d0X5W.js";import{t as ne}from"./ConfirmModal-lZYjzFL6.js";import{m as g}from"./amsHelpers-Dlwij40i.js";import{a as _,c as v}from"./colors-BF4_h-XA.js";import{n as y}from"./useUiSettings-BoONraTd.js";import{t as b}from"./printer-qo845RQA.js";import{a as x,i as S,n as re,r as C}from"./slicerPrinterMatch-CUdoNag2.js";import{p as w}from"./utils-B8CUydnj.js";import{n as T,r as ie,t as ae}from"./nozzleFlow-DwF_jePd.js";import{n as E,t as oe}from"./inventorySearch-CV2XH-nr.js";import{t as se}from"./useCancellableTimeout-BZWG_dnG.js";var D=e(r(),1),O=i();function ce({isOpen:e,onClose:r,printerId:i,amsId:c,trayId:l,trayInfo:f,spoolmanEnabled:m}){let{t:g}=t(),b=a(),{showToast:x}=ee(),[S,re]=(0,D.useState)(!1),[C,w]=(0,D.useState)(null),[T,ie]=(0,D.useState)(null);(0,D.useEffect)(()=>{w(null),ie(null)},[S]);let[ae,se]=(0,D.useState)(``),[ce,k]=(0,D.useState)(null),[A,le]=(0,D.useState)(!1),[j,M]=(0,D.useState)(null);(0,D.useEffect)(()=>{e&&re(!1)},[e]);let{data:N,isLoading:ue}=o({queryKey:[`inventory-spools`,`assign-modal`],queryFn:()=>n.getSpools(!0),enabled:e&&!m}),{data:de}=o({queryKey:[`spool-assignments`],queryFn:()=>n.getAssignments(),enabled:e}),{data:fe}=y({enabled:e}),{data:P,isLoading:pe}=o({queryKey:[`spoolman-inventory-spools`,`assign-modal`],queryFn:()=>n.getSpoolmanInventorySpools(!1),enabled:e&&!!m}),{data:me}=o({queryKey:[`spoolman-slot-assignments`,`all`],queryFn:()=>n.getSpoolmanSlotAssignments(),enabled:e&&!!m}),he=(0,D.useMemo)(()=>me?new Set(me.filter(e=>!(e.printer_id===i&&e.ams_id===c&&e.tray_id===l)).map(e=>e.spoolman_spool_id)):new Set,[me,i,c,l]),ge=()=>{n.refreshPrinterStatus(i).catch(()=>{}),b.invalidateQueries({queryKey:[`printerStatus`,i]})},F=s({mutationFn:e=>n.assignSpool({spool_id:e,printer_id:i,ams_id:c,tray_id:l}),onSuccess:e=>{b.setQueryData([`spool-assignments`],t=>{let n=(t||[]).filter(e=>!(e.printer_id===i&&e.ams_id===c&&e.tray_id===l));return n.push(e),n}),b.invalidateQueries({queryKey:[`spool-assignments`]}),ge();let t=e.pending_config?`inventory.assignPendingInsert`:`inventory.assignSuccess`;x(g(t),`success`),le(!1),k(null),M(null),r()},onError:e=>{x(`${g(`inventory.assignFailed`)}: ${e.message}`,`error`)}}),I=s({mutationFn:e=>n.assignSpoolmanSlot({spoolman_spool_id:e,printer_id:i,ams_id:c,tray_id:l}),onSuccess:()=>{b.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),b.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),ge(),x(g(`inventory.assignSuccess`),`success`),r()},onError:e=>{x(`${g(`inventory.assignFailed`)}: ${e.message}`,`error`)}}),L=e=>(e??``).trim().toUpperCase(),_e=(e,t)=>{let n=L(e),r=L(t);return!n||!r?`none`:n===r?`exact`:r.includes(n)||n.includes(r)?`partial`:`none`},R=e=>e.split(`@`)[0].trim(),z=(e,t)=>{let n=R(L(e)),r=R(L(t));return!n||!r?!1:n===r};if(!e)return null;let B=new Set((de||[]).filter(e=>!(e.printer_id===i&&e.ams_id===c&&e.tray_id===l)).map(e=>e.spool_id)),V=N?.filter(e=>!e.archived_at&&(S||!B.has(e.id))),H=oe(ae),U=V;if(!S&&H===null){let e=R(L(f?.profile)),t=L(f?.material||f?.type);(e||t)&&(U=U?.filter(n=>{let r=R(L(n.slicer_filament_name||n.slicer_filament)),i=L(n.material);return e&&r&&r===e?!0:t&&i?i===t||t.includes(i)||i.includes(t):!r&&!i}))}ae&&U&&(U=E(U,ae));let W=null;if(H!==null&&N&&U?.length===0){let e=N.find(e=>e.id===H);W=e?e.archived_at?g(`inventory.spoolIdArchived`,{id:H}):g(`inventory.spoolIdInOtherSlot`,{id:H}):g(`inventory.spoolIdNotFound`,{id:H})}let ve=()=>{if(T!==null){I.mutate(T);return}if(!C)return;let e=N?.find(e=>e.id===C);if(!e){x(g(`inventory.assignFailed`),`error`);return}if(!fe?.disable_filament_warnings&&f){let t=f.material||f.type,n=_e(e.material,t),r=e.slicer_filament_name||e.slicer_filament,i=f.profile||f.type,a=z(r,i);if(n!==`exact`){let o;o=n===`none`&&!a?`material_profile`:n===`partial`&&!a?`partial_profile`:n===`none`?`material`:`partial`,k(C),M({type:o,spoolMaterial:e.material||``,trayMaterial:t||``,spoolProfile:r||void 0,trayProfile:i||void 0}),le(!0);return}}F.mutate(C)},ye=()=>{ce&&(F.mutate(ce),le(!1),k(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:r}),(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:g(`inventory.assignSpool`)})]}),(0,O.jsx)(`button`,{onClick:r,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,O.jsx)(h,{className:`w-5 h-5`})})]}),(0,O.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto`,children:[f&&(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:[g(`inventory.selectSpool`),`:`]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[f.color&&(0,O.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:_(f.color)}),(0,O.jsx)(`span`,{className:`text-white font-medium`,children:f.type||g(`ams.emptySlot`)}),(0,O.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,f.location,`)`]})]})]}),(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(p,{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:ae,onChange:e=>se(e.target.value),placeholder:g(`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:[!m&&(ue?(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`})}):U&&U.length>0?(0,O.jsx)(`div`,{className:`max-h-96 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2`,children:U.map(e=>(0,O.jsxs)(`button`,{onClick:()=>{w(e.id),ie(null)},title:e.note||void 0,className:`p-2.5 rounded-lg border text-left transition-colors ${C===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:_(e.rgba)}),(0,O.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:v(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))}):W?(0,O.jsx)(`div`,{className:`text-center py-8 text-bambu-gray`,children:(0,O.jsx)(`p`,{children:W})}):V&&V.length===0?(0,O.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,O.jsx)(`p`,{children:g(`inventory.noAvailableSpools`)}),N&&(0,O.jsxs)(`p`,{className:`text-[10px] mt-2 opacity-60`,children:[N.length,` fetched · `,N.filter(e=>e.archived_at).length,` archived ·`,` `,N.filter(e=>B.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:g(`inventory.noSpoolsMatch`)}),V&&(0,O.jsxs)(`p`,{className:`text-[10px] mt-2 opacity-60`,children:[V.length,` unassigned spools — `,V.length-(U?.length??0),` filtered by tray match. Try "Show all spools".`]})]})),m&&(0,O.jsx)(O.Fragment,{children:pe?(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`})}):P&&P.filter(e=>!e.archived_at&&!he.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:g(`inventory.spoolmanSpools`)}),(0,O.jsx)(`div`,{className:`max-h-64 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2`,children:E(P.filter(e=>!e.archived_at&&!he.has(e.id)),ae).map(e=>(0,O.jsxs)(`button`,{onClick:()=>{ie(e.id),w(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:_(e.rgba)}),(0,O.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:v(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:S,onChange:()=>re(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:g(`inventory.showAllSpools`)})]}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsx)(te,{variant:`secondary`,onClick:r,children:g(`common.cancel`)}),(0,O.jsx)(te,{onClick:ve,disabled:!C&&T===null||F.isPending||I.isPending,children:F.isPending||I.isPending?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(u,{className:`w-4 h-4 animate-spin`}),g(`inventory.assigning`)]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(d,{className:`w-4 h-4`}),g(`inventory.assignSpool`)]})})]})]}),F.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:F.error.message})]})]}),A&&f&&C&&j&&(()=>{let e=``;return j.type===`material`?e=g(`inventory.assignMismatchMessage`,{spoolMaterial:j.spoolMaterial,trayMaterial:j.trayMaterial,location:f.location}):j.type===`partial`?e=g(`inventory.assignPartialMismatchMessage`,{spoolMaterial:j.spoolMaterial,trayMaterial:j.trayMaterial,location:f.location}):j.type===`material_profile`?e=`${g(`inventory.assignMismatchMessage`,{spoolMaterial:j.spoolMaterial,trayMaterial:j.trayMaterial,location:f.location})}\n\n${g(`inventory.assignProfileMismatchMessage`,{spoolProfile:j.spoolProfile||g(`common.unknown`),trayProfile:j.trayProfile||g(`common.unknown`),location:f.location})}`:j.type===`partial_profile`&&(e=`${g(`inventory.assignPartialMismatchMessage`,{spoolMaterial:j.spoolMaterial,trayMaterial:j.trayMaterial,location:f.location})}\n\n${g(`inventory.assignProfileMismatchMessage`,{spoolProfile:j.spoolProfile||g(`common.unknown`),trayProfile:j.trayProfile||g(`common.unknown`),location:f.location})}`),e=`${e}\n\n${g(`inventory.assignReconfigureNote`)}`,(0,O.jsx)(ne,{title:g(`inventory.assignMismatchTitle`),message:e,confirmText:g(`inventory.assignMismatchConfirm`),variant:`warning`,overlayZIndex:`z-[110]`,isLoading:F.isPending,onConfirm:ye,onCancel:()=>{F.isPending||(le(!1),k(null),M(null))}})})()]})}function k(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 A=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`NYLON`,`PVA`,`HIPS`,`PP`,`PET`];function le(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 A)if(RegExp(`\\b${n}\\b`).test(e))return{material:n,brand:t.slice(0,r.index).trim(),variant:`Support`}}for(let e of A){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 j(e){let t=T(ie(e.nozzle_id));return t?`[${t}] `:``}function M(e){return`${e.extruder_id??0}|${e.name}|${e.k_value}`}function N(e,t){return t!==void 0&&e.some(e=>(e.extruder_id??0)===t)}function ue(e,t,n){return N(e,n)?e.find(e=>e.slot_id===t&&(e.extruder_id??0)===n):e.find(e=>e.slot_id===t)}function de(e,t,n){return t?` \u00b7 ${e.extruder_id===1?n(`common.left`):n(`common.right`)}`:``}function fe(e){return!e.startsWith(`GF`)&&!e.startsWith(`P1`)}var P={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`},pe=[{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`}],me=[{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 he(e){return P[e.toLowerCase().trim()]||null}function ge({isOpen:e,onClose:r,printerId:i,slotInfo:a,nozzleDiameter:d=`0.4`,printerModel:p,onSuccess:v,fullScreen:y,printerState:T}){let{t:E}=t(),{showToast:oe}=ee(),[ce,P]=(0,D.useState)(!1),ge=b.includes(T??``),[F,I]=(0,D.useState)(``),[L,_e]=(0,D.useState)(``),[R,z]=(0,D.useState)(null),B=(0,D.useRef)(null);B.current=R;let[V,H]=(0,D.useState)(``),[U,W]=(0,D.useState)(``),[ve,ye]=(0,D.useState)(``),[be,xe]=(0,D.useState)(!1),[G,Se]=(0,D.useState)(!1),Ce=(0,D.useRef)(``),{schedule:we}=se(),{data:K,isLoading:Te,isError:Ee}=o({queryKey:[`cloudSettings`],queryFn:()=>n.getCloudSettings(),enabled:e,retry:!1}),{data:De}=o({queryKey:[`orcaCloudProfilesForAmsSlot`],queryFn:()=>n.orcaCloudListProfiles(),enabled:e,retry:!1}),{data:q,isLoading:Oe}=o({queryKey:[`localPresets`],queryFn:()=>n.getLocalPresets(),enabled:e}),{data:J,isLoading:ke}=o({queryKey:[`builtinFilaments`],queryFn:()=>n.getBuiltinFilaments(),enabled:e,staleTime:1/0}),{data:Y,isLoading:Ae}=o({queryKey:[`kprofiles`,i,d],queryFn:()=>n.getKProfiles(i,d),enabled:e&&!!i}),{data:je}=o({queryKey:[`colorCatalog`],queryFn:()=>n.getColorCatalog(),enabled:e,staleTime:1/0}),{data:X}=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}),Me=(0,D.useMemo)(()=>re(X??{}),[X]),Ne=(0,D.useMemo)(()=>{if(!p||!X)return null;for(let[e,t]of Object.entries(X))if(t===p)return`${e.startsWith(`Bambu Lab `)?e:`Bambu Lab ${e}`} ${d} nozzle`;return null},[p,X,d]),Pe=s({mutationFn:async()=>{if(!F)throw Error(`No filament preset selected`);let e=F.startsWith(`local_`),t=F.startsWith(`builtin_`),r=F.startsWith(`orca_`)?F.replace(`orca_`,``):F,o=!e&&!t?De?.filament.find(e=>e.setting_id===r):void 0,s=!!o,c=o??null,ee=e?parseInt(F.replace(`local_`,``),10):null,l=t?F.replace(`builtin_`,``):null,u=e?q?.filament.find(e=>e.id===ee):null,f=t?J?.find(e=>e.filament_id===l):null,p=!e&&!t&&!s?K?.filament.find(e=>e.setting_id===F):null;if(!e&&!t&&!s&&!p)throw Error(`Selected preset not found`);if(e&&!u)throw Error(`Selected local preset not found`);if(t&&!f)throw Error(`Selected builtin preset not found`);if(s&&!c)throw Error(`Selected Orca Cloud preset not found`);let m=e?u.name:t?f.name:s?c.name:p.name,h=le(m),te=B.current?.slot_id??-1,ne=V||a.trayColor?.slice(0,6)||`FFFFFF`,g=m.replace(/@.+$/,``).trim(),_,v,y=h.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=(A.includes(y)?y:u?.filament_type||h.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)_=l,v=``;else{if(_=k(F),v=F,!F.startsWith(`GFS`))try{let e=await n.getCloudSettingDetail(F),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 ${F} carries no filament_id in either place; sending no tray_info_idx so the printer keeps a resolvable one.`),_=``)}let x=e&&u?.nozzle_temp_min?u.nozzle_temp_min:190,S=e&&u?.nozzle_temp_max?u.nozzle_temp_max:230;if(!e||t||s||!u?.nozzle_temp_min&&!u?.nozzle_temp_max){let t=(e?A.includes(y)?y:u?.filament_type||h.material||``:h.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 re=B.current?.k_value?parseFloat(B.current.k_value):0,C=e?A.includes(y)?y:u?.filament_type||h.material||`PLA`:s&&A.includes(y)?y:h.material||`PLA`,w=await n.configureAmsSlot(i,a.amsId,a.trayId,{tray_info_idx:_,tray_type:C,tray_sub_brands:g,tray_color:ne+`FF`,nozzle_temp_min:x,nozzle_temp_max:S,cali_idx:te,nozzle_diameter:d,setting_id:v,kprofile_filament_id:B.current?.filament_id,kprofile_setting_id:B.current?.setting_id||void 0,k_value:re,orca_profile_id:s?r:void 0});w.k_value_unsent&&oe(E(`configureAmsSlot.kValueUnsent`),`warning`),s&&w.orca_fallback_reason&&oe(E(`configureAmsSlot.orcaFallback.${w.orca_fallback_reason}`,{material:C}),`warning`);let T=e?`local_${ee}`:t?`builtin_${l}`:F,ie=e?`local`:t?`builtin`:s?`orca_cloud`:`cloud`;try{await n.saveSlotPreset(i,a.amsId,a.trayId,T,g,ie,w.tray_info_idx)}catch(e){console.warn(`Failed to save slot preset mapping:`,e)}return w},onSuccess:()=>{xe(!0),v?.(),we(()=>{xe(!1),r()},1500)}}),Fe=s({mutationFn:async()=>n.resetAmsSlot(i,a.amsId,a.trayId),onSuccess:()=>{xe(!0),v?.(),we(()=>{xe(!1),r()},1500)}}),Ie=(0,D.useMemo)(()=>{let e=ve.toLowerCase(),t=[],n=new Set,r=a.savedPresetId,i=a.trayInfoIdx;if(De?.filament)for(let r of De.filament){let i=`orca_${r.setting_id}`;if(n.add(r.setting_id),n.add(i),!(e&&!r.name.toLowerCase().includes(e))){if(p){let e=C(r.name,X??{});if(e&&!S(e,p))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||k(a.setting_id)===i);if(!(e&&!a.name.toLowerCase().includes(e))){if(!o&&p){let e=C(a.name,X??{});if(e&&!S(e,p))continue}t.push({id:a.setting_id,name:a.name,source:`cloud`,isUser:fe(a.setting_id)})}}if(q?.filament){let n=a.savedPresetId;for(let r of q.filament){let i=`local_${r.id}`;if(!(e&&!r.name.toLowerCase().includes(e))){if(n!==i&&Ne){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(x({name:r.name,compatible_printers:e},`filament`,Ne,Me)===`mismatch`)continue}t.push({id:i,name:r.name,source:`local`,isUser:!1})}}}if(J)for(let r of J){if(n.has(r.filament_id))continue;let i=r.filament_id.startsWith(`GF`)?`GFS`+r.filament_id.slice(2):r.filament_id;n.has(i)||(!e||r.name.toLowerCase().includes(e))&&t.push({id:`builtin_${r.filament_id}`,name:r.name,source:`builtin`,isUser:!1})}return t.sort((e,t)=>{let n={local:0,orca_cloud:1,cloud:2,builtin:3};return e.source===t.source?e.isUser&&!t.isUser?-1:!e.isUser&&t.isUser?1:e.name.localeCompare(t.name):n[e.source]-n[t.source]})},[De?.filament,K?.filament,q?.filament,J,ve,p,a.savedPresetId,a.trayInfoIdx,Ne,Me,X]),Q=(0,D.useMemo)(()=>{if(!F)return null;let e=null,t=``;if(F.startsWith(`local_`)){let t=parseInt(F.replace(`local_`,``),10);e=q?.filament.find(e=>e.id===t)?.name||null}else if(F.startsWith(`builtin_`)){let n=F.replace(`builtin_`,``);e=J?.find(e=>e.filament_id===n)?.name||null,t=w(n)}else{let n=F.startsWith(`orca_`)?F.replace(`orca_`,``):F,r=De?.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===F);e=n?.name||null,n&&(t=w(n.setting_id))}}if(!e)return null;let n=e.replace(/@.+$/,``).trim();n.startsWith(`# `)&&(n=n.slice(2).trim());let r=le(n);return{fullName:n,material:r.material,brand:r.brand,filamentId:t}},[F,K?.filament,q?.filament,J,De?.filament]),Le=Q?.fullName||``,Re=(0,D.useMemo)(()=>{if(!je||!Q)return[];let{fullName:e,brand:t}=Q,n=e.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,``).trim();return je.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})},[je,Q]),ze=(0,D.useMemo)(()=>new Set((Y?.profiles??[]).map(e=>e.extruder_id??0)).size>1,[Y?.profiles]),{data:Be}=o({queryKey:[`printerStatus`,i],queryFn:()=>n.getPrinterStatus(i),enabled:e}),Ve=(0,D.useMemo)(()=>{let e=Be?.nozzles??[];return ie(e[a.extruderId??0]?.nozzle_type)??ie(e[0]?.nozzle_type)},[Be?.nozzles,a.extruderId]),$=(0,D.useMemo)(()=>{if(!Y?.profiles)return[];if(!Q){let e=a.caliIdx;if(e!=null&&e>0){let t=ue(Y.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 ee=Y.profiles.filter(e=>{if(c){let t=w(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}),l=(N(Y.profiles,a.extruderId)?ee.filter(e=>(e.extruder_id??0)===a.extruderId):ee).filter(e=>ae(e.nozzle_id,Ve)),u=new Map;for(let e of l){let t=M(e);u.has(t)||u.set(t,e)}let d=Array.from(u.values()),f=a.caliIdx;if((L&&F===L||c&&c===w(a.trayInfoIdx))&&f!=null&&f>0&&!d.some(e=>e.slot_id===f)){let e=ue(Y.profiles,f,a.extruderId);e&&d.unshift(e)}return d},[Y?.profiles,Q,a.extruderId,a.caliIdx,a.trayInfoIdx,F,L,Ve]),He=(0,D.useMemo)(()=>{if(!Y?.profiles)return[];let e=new Set($.map(e=>M(e))),t=new Map;for(let n of Y.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))},[Y?.profiles,$]),Ue=$.length>0||He.length>0,We=(0,D.useCallback)(e=>{if(!e){z(null);return}let t=$.find(t=>M(t)===e)||He.find(t=>M(t)===e)||null;z(t)},[$,He]);(0,D.useEffect)(()=>{if(e){if(Z?.slicer_filament)I(Z.slicer_filament),_e(Z.slicer_filament);else if(a.savedPresetId)I(a.savedPresetId),_e(a.savedPresetId);else if(a.trayInfoIdx&&K?.filament){let e=K.filament.find(e=>e.setting_id===a.trayInfoIdx);e||=K.filament.find(e=>k(e.setting_id)===a.trayInfoIdx),e&&(I(e.setting_id),_e(e.setting_id))}else if(a.trayInfoIdx&&J?.length){let e=a.trayInfoIdx,t=J.find(t=>t.filament_id===e);t&&(I(`builtin_${t.filament_id}`),_e(`builtin_${t.filament_id}`))}if(a.trayColor){let e=a.trayColor.slice(0,6);e&&H(e)}}else I(``),_e(``),z(null),H(``),W(``),ye(``),xe(!1),Ce.current=``},[e,Z?.slicer_filament,a.savedPresetId,a.trayInfoIdx,a.trayColor,K?.filament,J]),(0,D.useEffect)(()=>{if($.length>0){if(Z?.cali_idx!=null){let e=ue($,Z.cali_idx,Z.extruder??a.extruderId);if(e){z(e);return}}if(a.caliIdx!=null&&a.caliIdx>0){let e=ue($,a.caliIdx,a.extruderId);if(e){z(e);return}}z($[0])}else z(null)},[F,$,Z?.cali_idx,Z?.extruder,a.caliIdx,a.extruderId]);let Ge=(0,D.useCallback)(e=>{e.key===`Escape`&&!ce&&r()},[r,ce]);(0,D.useEffect)(()=>{if(e)return document.addEventListener(`keydown`,Ge),()=>document.removeEventListener(`keydown`,Ge)},[e,Ge]);let Ke=Te&&!Ee||Oe||ke||Ae;if((0,D.useEffect)(()=>{if(!Ke&&F&&F!==Ce.current){let e=requestAnimationFrame(()=>{let e=document.querySelector(`[class*="fixed inset-0 z-50"]`)?.querySelector(`[data-preset-id="${CSS.escape(F)}"]`);e&&(Ce.current=F,e.scrollIntoView({block:`nearest`}))});return()=>cancelAnimationFrame(e)}},[F,Ke]),!e)return null;let qe=F&&!Pe.isPending,Je=V||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:r}),(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)(m,{className:`w-5 h-5 text-bambu-blue`}),(0,O.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:E(`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:_(a.trayColor)}),(0,O.jsx)(`span`,{className:`text-white/70`,children:E(`configureAmsSlot.slotLabel`,{ams:g(a.amsId),slot:a.trayId+1})}),a.traySubBrands&&(0,O.jsxs)(`span`,{children:[`(`,a.traySubBrands,`)`]})]})]}),(0,O.jsx)(`button`,{onClick:r,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,O.jsx)(h,{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:[be&&(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)(l,{className:`w-16 h-16 text-bambu-green mx-auto`}),(0,O.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:E(`configureAmsSlot.slotConfigured`)}),(0,O.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:E(`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:E(`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:_(a.trayColor)}),(0,O.jsx)(`span`,{className:`text-white font-medium`,children:E(`configureAmsSlot.slotLabel`,{ams:g(a.amsId),slot:a.trayId+1})}),a.traySubBrands&&(0,O.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,a.traySubBrands,`)`]})]})]}),Ke?(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:[E(`configureAmsSlot.filamentProfile`),` `,(0,O.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,O.jsx)(`input`,{type:`text`,placeholder:E(`configureAmsSlot.searchPresets`),value:ve,onChange:e=>ye(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:Ie.length===0?(0,O.jsx)(`p`,{className:`text-center py-4 text-bambu-gray`,children:K?.filament?.length===0&&!q?.filament?.length?E(`configureAmsSlot.noPresetsAvailable`):E(`configureAmsSlot.noMatchingPresets`)}):Ie.map(e=>(0,O.jsx)(`button`,{"data-preset-id":e.id,onClick:()=>I(e.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${F===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:(0,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:E(`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:E(`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:E(`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:E(`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:[E(`configureAmsSlot.kProfileLabel`),Le&&(0,O.jsx)(`span`,{className:`ml-2 text-xs text-bambu-blue`,children:E(`configureAmsSlot.filteringFor`,{material:Le})})]}),Ue?(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsxs)(`select`,{value:R?M(R):``,onChange:e=>We(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:E(`configureAmsSlot.noKProfile`)}),$.map(e=>(0,O.jsxs)(`option`,{value:M(e),children:[j(e),e.name,` (K=`,e.k_value,`)`,de(e,ze,E)]},M(e))),He.length>0&&(0,O.jsx)(`optgroup`,{label:E(`configureAmsSlot.otherKProfiles`),children:He.map(e=>(0,O.jsxs)(`option`,{value:M(e),children:[j(e),e.name,` (K=`,e.k_value,`)`,de(e,ze,E)]},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`})]}):F?(0,O.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:E(`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:E(`configureAmsSlot.selectFilamentFirst`)}),R&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-green mt-1`,children:E(`configureAmsSlot.kFromCalibration`,{value:R.k_value})})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:E(`configureAmsSlot.customColorLabel`)}),Re.length>0&&(0,O.jsxs)(`div`,{className:`mb-3`,children:[(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1.5`,children:E(`configureAmsSlot.presetColors`,{name:Q?.fullName})}),(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Re.map(e=>(0,O.jsxs)(`button`,{onClick:()=>{let t=e.hex_color.replace(`#`,``).toUpperCase();H(t),W(e.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${V===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:[pe.map(e=>(0,O.jsx)(`button`,{onClick:()=>{H(e.hex),W(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${V===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:()=>Se(!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:E(G?`configureAmsSlot.showLessColors`:`configureAmsSlot.showMoreColors`),children:G?`−`:`+`})]}),G&&(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:me.map(e=>(0,O.jsx)(`button`,{onClick:()=>{H(e.hex),W(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${V===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:_(Je)}),(0,O.jsx)(`input`,{type:`text`,placeholder:E(`configureAmsSlot.colorPlaceholder`),value:U,onChange:e=>{let t=e.target.value;W(t);let n=he(t);if(n)H(n);else{let e=t.replace(/[^0-9A-Fa-f]/g,``).toUpperCase();e.length===6?H(e):e.length===3&&H(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`}),V&&(0,O.jsx)(`button`,{onClick:()=>{H(``),W(``)},className:`px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded`,title:E(`configureAmsSlot.clearCustomColor`),children:E(`configureAmsSlot.clear`)})]}),V&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5`,children:E(`configureAmsSlot.hexLabel`,{hex:V})})]})]})]}):(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:[E(`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:E(`configureAmsSlot.searchPresets`),value:ve,onChange:e=>ye(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:Ie.length===0?(0,O.jsx)(`p`,{className:`text-center py-4 text-bambu-gray`,children:K?.filament?.length===0&&!q?.filament?.length?E(`configureAmsSlot.noPresetsAvailable`):E(`configureAmsSlot.noMatchingPresets`)}):Ie.map(e=>(0,O.jsx)(`button`,{"data-preset-id":e.id,onClick:()=>I(e.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${F===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:(0,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:E(`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:E(`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:E(`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:E(`configureAmsSlot.builtin`)})]})]})},e.id))})]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[E(`configureAmsSlot.kProfileLabel`),Le&&(0,O.jsx)(`span`,{className:`ml-2 text-xs text-bambu-blue`,children:E(`configureAmsSlot.filteringFor`,{material:Le})})]}),Ue?(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsxs)(`select`,{value:R?M(R):``,onChange:e=>We(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:E(`configureAmsSlot.noKProfile`)}),$.map(e=>(0,O.jsxs)(`option`,{value:M(e),children:[j(e),e.name,` (K=`,e.k_value,`)`,de(e,ze,E)]},M(e))),He.length>0&&(0,O.jsx)(`optgroup`,{label:E(`configureAmsSlot.otherKProfiles`),children:He.map(e=>(0,O.jsxs)(`option`,{value:M(e),children:[j(e),e.name,` (K=`,e.k_value,`)`,de(e,ze,E)]},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`})]}):F?(0,O.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:E(`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:E(`configureAmsSlot.selectFilamentFirst`)}),R&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-green mt-1`,children:E(`configureAmsSlot.kFromCalibration`,{value:R.k_value})})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:E(`configureAmsSlot.customColorLabel`)}),Re.length>0&&(0,O.jsxs)(`div`,{className:`mb-3`,children:[(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1.5`,children:E(`configureAmsSlot.presetColors`,{name:Q?.fullName})}),(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Re.map(e=>(0,O.jsxs)(`button`,{onClick:()=>{let t=e.hex_color.replace(`#`,``).toUpperCase();H(t),W(e.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${V===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:[pe.map(e=>(0,O.jsx)(`button`,{onClick:()=>{H(e.hex),W(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${V===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:()=>Se(!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:E(G?`configureAmsSlot.showLessColors`:`configureAmsSlot.showMoreColors`),children:G?`−`:`+`})]}),G&&(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:me.map(e=>(0,O.jsx)(`button`,{onClick:()=>{H(e.hex),W(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${V===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:_(Je)}),(0,O.jsx)(`input`,{type:`text`,placeholder:E(`configureAmsSlot.colorPlaceholder`),value:U,onChange:e=>{let t=e.target.value;W(t);let n=he(t);if(n)H(n);else{let e=t.replace(/[^0-9A-Fa-f]/g,``).toUpperCase();e.length===6?H(e):e.length===3&&H(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`}),V&&(0,O.jsx)(`button`,{onClick:()=>{H(``),W(``)},className:`px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded`,title:E(`configureAmsSlot.clearCustomColor`),children:E(`configureAmsSlot.clear`)})]}),V&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5`,children:E(`configureAmsSlot.hexLabel`,{hex:V})})]})]})]}),(0,O.jsxs)(`div`,{className:`flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0`,children:[(0,O.jsx)(te,{variant:`secondary`,onClick:()=>P(!0),disabled:ge||Fe.isPending||Pe.isPending,title:ge?E(`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:Fe.isPending?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(u,{className:`w-4 h-4 animate-spin`}),E(`configureAmsSlot.resetting`)]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(f,{className:`w-4 h-4`}),E(`configureAmsSlot.resetSlot`)]})}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsx)(te,{variant:`secondary`,onClick:r,children:E(`configureAmsSlot.cancel`)}),(0,O.jsx)(te,{onClick:()=>Pe.mutate(),disabled:!qe,children:Pe.isPending?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(u,{className:`w-4 h-4 animate-spin`}),E(`configureAmsSlot.configuring`)]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(m,{className:`w-4 h-4`}),E(`configureAmsSlot.configureSlot`)]})})]})]}),(Pe.isError||Fe.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:Pe.error?.message||Fe.error?.message})]}),ce&&(0,O.jsx)(ne,{title:E(`configureAmsSlot.resetConfirmTitle`),message:E(`configureAmsSlot.resetConfirmMessage`),confirmText:E(`configureAmsSlot.resetSlot`),variant:`danger`,overlayZIndex:`z-[60]`,onConfirm:()=>{P(!1),Fe.mutate()},onCancel:()=>P(!1)})]})}export{ce as n,ge as t};