From 94c66964694e56577af26f0c658b83b9ce47e6b2 Mon Sep 17 00:00:00 2001 From: maziggy Date: Thu, 26 Mar 2026 17:25:35 +0100 Subject: [PATCH] Add Ukrainian Hryvnia to known currencies (#815) --- frontend/src/__tests__/utils/currency.test.ts | 6 +++++- frontend/src/utils/currency.ts | 1 + static/assets/{index-COZAa55N.js => index-DBBfrr2z.js} | 2 +- static/index.html | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) rename static/assets/{index-COZAa55N.js => index-DBBfrr2z.js} (99%) diff --git a/frontend/src/__tests__/utils/currency.test.ts b/frontend/src/__tests__/utils/currency.test.ts index 7e3d9715b..f0bc9a060 100644 --- a/frontend/src/__tests__/utils/currency.test.ts +++ b/frontend/src/__tests__/utils/currency.test.ts @@ -26,6 +26,10 @@ describe('getCurrencySymbol', () => { expect(getCurrencySymbol('MYR')).toBe('RM'); }); + it('returns ₴ for UAH', () => { + expect(getCurrencySymbol('UAH')).toBe('₴'); + }); + it('returns the code itself for unknown currencies', () => { expect(getCurrencySymbol('XYZ')).toBe('XYZ'); }); @@ -46,6 +50,6 @@ describe('SUPPORTED_CURRENCIES', () => { }); it('has 28 entries', () => { - expect(SUPPORTED_CURRENCIES).toHaveLength(28); + expect(SUPPORTED_CURRENCIES).toHaveLength(29); }); }); diff --git a/frontend/src/utils/currency.ts b/frontend/src/utils/currency.ts index 8315015b8..ab3d87e38 100644 --- a/frontend/src/utils/currency.ts +++ b/frontend/src/utils/currency.ts @@ -27,6 +27,7 @@ const CURRENCY_SYMBOLS: Record = { RUB: '₽', HUF: 'Ft', ILS: '₪', + UAH: '₴', }; export function getCurrencySymbol(currencyCode: string): string { diff --git a/static/assets/index-COZAa55N.js b/static/assets/index-DBBfrr2z.js similarity index 99% rename from static/assets/index-COZAa55N.js rename to static/assets/index-DBBfrr2z.js index a49ae4218..de8989c06 100644 --- a/static/assets/index-COZAa55N.js +++ b/static/assets/index-DBBfrr2z.js @@ -8507,7 +8507,7 @@ void main() { ${o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})}`:g.type==="partial_profile"?Z=`${o("inventory.assignPartialMismatchMessage",{spoolMaterial:g.spoolMaterial,trayMaterial:g.trayMaterial,location:s.location})} -${o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})}`:g.type==="profile"&&(Z=o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})),i.jsx(_n,{title:o("inventory.assignMismatchTitle"),message:Z,confirmText:o("inventory.assignMismatchConfirm"),variant:"warning",isLoading:T.isPending,onConfirm:se,onCancel:()=>{T.isPending||(b(!1),y(null),_(null))}})})()]})}function yW(t,e){if(t===255)return"External";let n,r=!1;t>=128&&t<=135?(n=t-128,r=!0):t>=0&&t<=3?(n=t,r=e===1):n=0,n=Math.max(0,Math.min(n,7));const a=String.fromCharCode(65+n);return r?`HT-${a}`:`AMS-${a}`}function R1(t){const e=t.includes("_")?t.split("_")[0]:t;return e.startsWith("GFS")?"GF"+e.slice(3):(e.startsWith("PFUS")||e.startsWith("PFSP"),e)}const n0=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function vW(t){const e=t.replace(/@.+$/,"").trim(),n=e.toUpperCase(),r=n.match(/\bSUPPORT\s+FOR\s+/);if(r){const s=n.slice(r.index+r[0].length);for(const o of n0)if(new RegExp(`\\b${o}\\b`).test(s)){const c=e.slice(0,r.index).trim();return{material:o,brand:c,variant:"Support"}}}for(const s of n0){const o=new RegExp(`\\b${s}\\b`,"i");if(o.test(n)){const l=e.split(o),c=l[0]?.trim()||"",d=l[1]?.trim()||"";return{material:s,brand:c,variant:d}}}const a=e.split(/\s+/);return a.length>=2?{material:a[1],brand:a[0],variant:a.slice(2).join(" ")}:{material:e,brand:"",variant:""}}function aVe(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const sVe={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"},wW=[{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"}],SW=[{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 _W(t){const e=t.toLowerCase().trim();return sVe[e]||null}function oVe(t){const e=t.indexOf("@");if(e<0)return null;const r=t.slice(e+1).trim().match(/^BBL\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);return r?r[1].trim():null}function mie({isOpen:t,onClose:e,printerId:n,slotInfo:r,nozzleDiameter:a="0.4",printerModel:s,onSuccess:o,fullScreen:l}){const{t:c}=jt(),[d,u]=w.useState(""),[m,p]=w.useState(null),[f,y]=w.useState(""),[v,b]=w.useState(""),[g,_]=w.useState(""),[N,C]=w.useState(!1),[k,P]=w.useState(!1),T=w.useRef(""),{data:j,isLoading:A,isError:F}=Je({queryKey:["cloudSettings"],queryFn:()=>fe.getCloudSettings(),enabled:t,retry:!1}),{data:G,isLoading:z}=Je({queryKey:["localPresets"],queryFn:()=>fe.getLocalPresets(),enabled:t}),{data:J,isLoading:I}=Je({queryKey:["builtinFilaments"],queryFn:()=>fe.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:te,isLoading:se}=Je({queryKey:["kprofiles",n,a],queryFn:()=>fe.getKProfiles(n,a),enabled:t&&!!n}),{data:Z}=Je({queryKey:["colorCatalog"],queryFn:()=>fe.getColorCatalog(),enabled:t,staleTime:1/0}),de=ht({mutationFn:async()=>{if(!d)throw new Error("No filament preset selected");const M=d.startsWith("local_"),U=d.startsWith("builtin_"),K=M?parseInt(d.replace("local_",""),10):null,B=U?d.replace("builtin_",""):null,ie=M?G?.filament.find(Ae=>Ae.id===K):null,O=U?J?.find(Ae=>Ae.filament_id===B):null,q=!M&&!U?j?.filament.find(Ae=>Ae.setting_id===d):null;if(!M&&!U&&!q)throw new Error("Selected preset not found");if(M&&!ie)throw new Error("Selected local preset not found");if(U&&!O)throw new Error("Selected builtin preset not found");const Y=M?ie.name:U?O.name:q.name,V=vW(Y),ee=m?.slot_id??-1,oe=f||r.trayColor?.slice(0,6)||"FFFFFF",he=Y.replace(/@.+$/,"").trim();let pe,re;const L=V.material.toUpperCase();if(M){const Ae=(n0.includes(L)?L:ie?.filament_type||V.material||"").toUpperCase(),Le={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"};pe=Le[Ae]||Le[Ae.replace(/[-\s]?CF$/,"")]||Le[Ae.replace(/\+$/,"")]||Le[Ae.split(/[-\s]/)[0]]||"",re=""}else if(U)pe=B,re="";else if(pe=R1(d),re=d,!d.startsWith("GFS"))try{const Ae=await fe.getCloudSettingDetail(d);Ae.filament_id?pe=Ae.filament_id:Ae.base_id&&(pe=R1(Ae.base_id),console.log(`Derived tray_info_idx from base_id: ${Ae.base_id} -> ${pe}`))}catch(Ae){console.warn("Failed to fetch preset detail for filament_id:",Ae)}let R=M&&ie?.nozzle_temp_min?ie.nozzle_temp_min:190,ne=M&&ie?.nozzle_temp_max?ie.nozzle_temp_max:230;if(!M||U||!ie?.nozzle_temp_min&&!ie?.nozzle_temp_max){const Ae=(M?n0.includes(L)?L:ie?.filament_type||V.material||"":V.material).toUpperCase();Ae.includes("PLA")?(R=190,ne=230):Ae.includes("PETG")?(R=220,ne=260):Ae.includes("ABS")||Ae.includes("ASA")?(R=240,ne=280):Ae.includes("TPU")?(R=200,ne=240):Ae==="PCTG"?(R=220,ne=260):Ae.includes("PC")?(R=260,ne=300):(Ae.includes("PA")||Ae.includes("NYLON"))&&(R=250,ne=290)}const ye=m?.k_value?parseFloat(m.k_value):0,ve=M?n0.includes(L)?L:ie?.filament_type||V.material||"PLA":V.material||"PLA",be=await fe.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:pe,tray_type:ve,tray_sub_brands:he,tray_color:oe+"FF",nozzle_temp_min:R,nozzle_temp_max:ne,cali_idx:ee,nozzle_diameter:a,setting_id:re,kprofile_filament_id:m?.filament_id,kprofile_setting_id:m?.setting_id||void 0,k_value:ye}),Be=M?`local_${K}`:U?`builtin_${B}`:d,we=M?"local":U?"builtin":"cloud";try{await fe.saveSlotPreset(n,r.amsId,r.trayId,Be,he,we)}catch(Ae){console.warn("Failed to save slot preset mapping:",Ae)}return be},onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),ue=ht({mutationFn:async()=>fe.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),me=w.useMemo(()=>{const M=g.toLowerCase(),U=[],K=new Set,B=r.savedPresetId,ie=r.trayInfoIdx;if(j?.filament)for(const O of j.filament){K.add(O.setting_id);const Y=B===O.setting_id||ie&&(O.setting_id===ie||R1(O.setting_id)===ie);if(!(M&&!O.name.toLowerCase().includes(M))){if(!Y&&s){const V=oVe(O.name);if(V&&V.toUpperCase()!==s.toUpperCase())continue}U.push({id:O.setting_id,name:O.name,source:"cloud",isUser:aVe(O.setting_id)})}}if(G?.filament)for(const O of G.filament){const q=`local_${O.id}`;M&&!O.name.toLowerCase().includes(M)||U.push({id:q,name:O.name,source:"local",isUser:!1})}if(J)for(const O of J){if(K.has(O.filament_id))continue;const q=O.filament_id.startsWith("GF")?"GFS"+O.filament_id.slice(2):O.filament_id;K.has(q)||(!M||O.name.toLowerCase().includes(M))&&U.push({id:`builtin_${O.filament_id}`,name:O.name,source:"builtin",isUser:!1})}return U.sort((O,q)=>{const Y={cloud:0,local:1,builtin:2};return O.source!==q.source?Y[O.source]-Y[q.source]:O.isUser&&!q.isUser?-1:!O.isUser&&q.isUser?1:O.name.localeCompare(q.name)})},[j?.filament,G?.filament,J,g,s,r.savedPresetId,r.trayInfoIdx]),W=w.useMemo(()=>{if(!d)return null;let M=null;if(d.startsWith("local_")){const B=parseInt(d.replace("local_",""),10);M=G?.filament.find(O=>O.id===B)?.name||null}else if(d.startsWith("builtin_")){const B=d.replace("builtin_","");M=J?.find(O=>O.filament_id===B)?.name||null}else j?.filament&&(M=j.filament.find(ie=>ie.setting_id===d)?.name||null);if(!M)return null;let U=M.replace(/@.+$/,"").trim();U.startsWith("# ")&&(U=U.slice(2).trim());const K=vW(U);return{fullName:U,material:K.material,brand:K.brand}},[d,j?.filament,G?.filament,J]),ae=W?.fullName||"",ce=w.useMemo(()=>{if(!Z||!W)return[];const{fullName:M,brand:U}=W,K=M.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return Z.filter(B=>{const ie=(B.material||"").toUpperCase(),O=B.manufacturer.toUpperCase();if(!(ie===K.toUpperCase()||ie.includes(K.toUpperCase())||K.toUpperCase().includes(ie)))return!1;if(U){const Y=U.toUpperCase();if(!O.includes(Y)&&!Y.includes(O))return!1}return!0})},[Z,W]),ge=w.useMemo(()=>{if(!te?.profiles||!W)return[];const{fullName:M,material:U,brand:K}=W,B=M.toUpperCase(),ie=U.toUpperCase(),O=K.toUpperCase();if(!ie||ie.length<2)return[];const q=te.profiles.filter(V=>{const ee=V.name.toUpperCase();if(O)return!(!ee.includes(O)||!ee.includes(ie));if(ee.includes(B)||ee.includes(ie))return!0;const he={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[ie]||[];for(const pe of he)if(ee.includes(pe))return!0;return!1}),Y=new Map;for(const V of q){const ee=`${V.name}|${V.k_value}`,oe=Y.get(ee);oe?r.extruderId!==void 0&&V.extruder_id===r.extruderId&&oe.extruder_id!==r.extruderId&&Y.set(ee,V):Y.set(ee,V)}return Array.from(Y.values())},[te?.profiles,W,r.extruderId]);w.useEffect(()=>{if(t){if(r.savedPresetId)u(r.savedPresetId);else if(r.trayInfoIdx&&j?.filament){let M=j.filament.find(U=>U.setting_id===r.trayInfoIdx);M||(M=j.filament.find(U=>R1(U.setting_id)===r.trayInfoIdx)),M&&u(M.setting_id)}else if(r.trayInfoIdx&&J?.length){const M=r.trayInfoIdx,U=J.find(K=>K.filament_id===M);U&&u(`builtin_${U.filament_id}`)}if(r.trayColor){const M=r.trayColor.slice(0,6);M&&y(M)}}else u(""),p(null),y(""),b(""),_(""),C(!1),T.current=""},[t,r.savedPresetId,r.trayInfoIdx,r.trayColor,j?.filament,J]),w.useEffect(()=>{if(ge.length>0){if(r.caliIdx!=null&&r.caliIdx>0){const M=ge.find(U=>U.slot_id===r.caliIdx);if(M){p(M);return}}p(ge[0])}else p(null)},[d,ge,r.caliIdx]);const Ne=w.useCallback(M=>{M.key==="Escape"&&e()},[e]);w.useEffect(()=>{if(t)return document.addEventListener("keydown",Ne),()=>document.removeEventListener("keydown",Ne)},[t,Ne]);const H=A&&!F||z||I||se;if(w.useEffect(()=>{if(!H&&d&&d!==T.current){const M=requestAnimationFrame(()=>{const K=document.querySelector('[class*="fixed inset-0 z-50"]')?.querySelector(`[data-preset-id="${CSS.escape(d)}"]`);K&&(T.current=d,K.scrollIntoView({block:"nearest"}))});return()=>cancelAnimationFrame(M)}},[d,H]),!t)return null;const X=d&&!de.isPending,D=f||r.trayColor?.slice(0,6)||"FFFFFF";return i.jsxs("div",{className:`fixed inset-0 z-50 flex ${l?"":"items-center justify-center"}`,children:[!l&&i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),i.jsxs("div",{className:l?"relative w-full h-full bg-bambu-dark-secondary flex flex-col":"relative w-full max-w-lg mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(vd,{className:"w-5 h-5 text-bambu-blue"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.title")}),l&&i.jsxs("div",{className:"flex items-center gap-2 ml-4 text-sm text-bambu-gray",children:[i.jsx("span",{className:"text-white/30",children:"|"}),r.trayColor&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),i.jsx("span",{className:"text-white/70",children:c("configureAmsSlot.slotLabel",{ams:yW(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&i.jsxs("span",{children:["(",r.traySubBrands,")"]})]})]}),i.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(qt,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:`p-4 overflow-y-auto ${l?"flex-1 min-h-0":"space-y-4 max-h-[60vh]"}`,children:[N&&i.jsx("div",{className:"absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl",children:i.jsxs("div",{className:"text-center space-y-3",children:[i.jsx(Sc,{className:"w-16 h-16 text-bambu-green mx-auto"}),i.jsx("p",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.slotConfigured")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:c("configureAmsSlot.settingsSentToPrinter")})]})}),!l&&i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:c("configureAmsSlot.configuringSlot")}),i.jsxs("div",{className:"flex items-center gap-2",children:[r.trayColor&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),i.jsx("span",{className:"text-white font-medium",children:c("configureAmsSlot.slotLabel",{ams:yW(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&i.jsxs("span",{className:"text-bambu-gray",children:["(",r.traySubBrands,")"]})]})]}),H?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ft,{className:"w-6 h-6 text-bambu-green animate-spin"})}):l?i.jsxs("div",{className:"flex gap-4 h-full",children:[i.jsxs("div",{className:"w-1/2 flex flex-col min-h-0",children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:g,onChange:M=>_(M.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"}),i.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-1",children:me.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:j?.filament?.length===0&&!G?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):me.map(M=>i.jsx("button",{"data-preset-id":M.id,onClick:()=>u(M.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${d===M.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-white text-sm truncate",children:M.name}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[M.source==="local"&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),M.source==="builtin"&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),M.isUser&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},M.id))})]}),i.jsxs("div",{className:"w-1/2 flex flex-col gap-4 min-h-0 overflow-y-auto",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),ae&&i.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:ae})})]}),ge.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:M=>{const U=ge.find(K=>K.name===M.target.value);p(U||null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10",children:[i.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),ge.map(M=>i.jsxs("option",{value:M.name,children:[M.name," (K=",M.k_value,")"]},`${M.name}-${M.extruder_id}`))]}),i.jsx(zn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):d?i.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):i.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),m&&i.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:m.k_value})})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),ce.length>0&&i.jsxs("div",{className:"mb-3",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:W?.fullName})}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:ce.map(M=>i.jsxs("button",{onClick:()=>{const U=M.hex_color.replace("#","").toUpperCase();y(U),b(M.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===M.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:M.color_name,children:[i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:M.hex_color}}),i.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:M.color_name})]},M.id))})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[wW.map(M=>i.jsx("button",{onClick:()=>{y(M.hex),b(M.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===M.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${M.hex}`},title:M.name},M.hex)),i.jsx("button",{onClick:()=>P(!k),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(k?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:k?"−":"+"})]}),k&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:SW.map(M=>i.jsx("button",{onClick:()=>{y(M.hex),b(M.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===M.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${M.hex}`},title:M.name},M.hex))}),i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${D}`}}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:M=>{const U=M.target.value;b(U);const K=_W(U);if(K)y(K);else{const B=U.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();B.length===6?y(B):B.length===3&&y(B.split("").map(ie=>ie+ie).join(""))}},className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm"}),f&&i.jsx("button",{onClick:()=>{y(""),b("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:g,onChange:M=>_(M.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"}),i.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:me.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:j?.filament?.length===0&&!G?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):me.map(M=>i.jsx("button",{"data-preset-id":M.id,onClick:()=>u(M.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${d===M.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-white text-sm truncate",children:M.name}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[M.source==="local"&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),M.source==="builtin"&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),M.isUser&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},M.id))})]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),ae&&i.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:ae})})]}),ge.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:M=>{const U=ge.find(K=>K.name===M.target.value);p(U||null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10",children:[i.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),ge.map(M=>i.jsxs("option",{value:M.name,children:[M.name," (K=",M.k_value,")"]},`${M.name}-${M.extruder_id}`))]}),i.jsx(zn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):d?i.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):i.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),m&&i.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:m.k_value})})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),ce.length>0&&i.jsxs("div",{className:"mb-3",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:W?.fullName})}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:ce.map(M=>i.jsxs("button",{onClick:()=>{const U=M.hex_color.replace("#","").toUpperCase();y(U),b(M.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===M.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:M.color_name,children:[i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:M.hex_color}}),i.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:M.color_name})]},M.id))})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[wW.map(M=>i.jsx("button",{onClick:()=>{y(M.hex),b(M.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===M.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${M.hex}`},title:M.name},M.hex)),i.jsx("button",{onClick:()=>P(!k),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(k?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:k?"−":"+"})]}),k&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:SW.map(M=>i.jsx("button",{onClick:()=>{y(M.hex),b(M.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===M.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${M.hex}`},title:M.name},M.hex))}),i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${D}`}}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:M=>{const U=M.target.value;b(U);const K=_W(U);if(K)y(K);else{const B=U.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();B.length===6?y(B):B.length===3&&y(B.split("").map(ie=>ie+ie).join(""))}},className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm"}),f&&i.jsx("button",{onClick:()=>{y(""),b("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}),i.jsxs("div",{className:"flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[i.jsx(Ie,{variant:"secondary",onClick:()=>ue.mutate(),disabled:ue.isPending||de.isPending,className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:ue.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.resetting")]}):i.jsxs(i.Fragment,{children:[i.jsx(Ao,{className:"w-4 h-4"}),c("configureAmsSlot.resetSlot")]})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:e,children:c("configureAmsSlot.cancel")}),i.jsx(Ie,{onClick:()=>de.mutate(),disabled:!X,children:de.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.configuring")]}):i.jsxs(i.Fragment,{children:[i.jsx(vd,{className:"w-4 h-4"}),c("configureAmsSlot.configureSlot")]})})]})]}),(de.isError||ue.isError)&&i.jsx("div",{className:"mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:de.error?.message||ue.error?.message})]})]})}function hie({folderId:t,onClose:e,onUploadComplete:n,onFileUploaded:r,autoUpload:a,validateFile:s,accept:o}){const{t:l}=jt(),[c,d]=w.useState([]),[u,m]=w.useState(!1),[p,f]=w.useState(!1),[y,v]=w.useState(!0),[b,g]=w.useState(!1),[_,N]=w.useState(!0),[C,k]=w.useState(null),P=w.useRef(null),T=me=>{me.preventDefault(),m(!0)},j=me=>{me.preventDefault(),m(!1)},A=me=>{me.preventDefault(),m(!1),J(Array.from(me.dataTransfer.files))},F=me=>{me.target.files&&J(Array.from(me.target.files))},G=(me,W)=>{d(ae=>ae.map(ce=>ce.file===me?{...ce,...W}:ce))},z=async me=>{f(!0);for(const W of me)if(W.status==="pending"){G(W.file,{status:"uploading"});try{if(W.isZip){const ae=await fe.extractZipFile(W.file,t,y,b,_);G(W.file,{status:ae.errors.length>0&&ae.extracted===0?"error":"success",extractedCount:ae.extracted,error:ae.errors.length>0?l("fileManager.zipFilesFailed","{{count}} files failed",{count:ae.errors.length}):void 0})}else{const ae=await fe.uploadLibraryFile(W.file,t,_);G(W.file,{status:"success"});const ce=r?.(ae);if(ce){k(ce),d([]),f(!1);return}}}catch(ae){G(W.file,{status:"error",error:ae instanceof Error?ae.message:l("fileManager.uploadFailed","Upload failed")})}}f(!1),n(),e()},J=me=>{if(k(null),s)for(const ae of me){const ce=s(ae);if(ce){k(ce);return}}const W=me.map(ae=>({file:ae,status:"pending",isZip:ae.name.toLowerCase().endsWith(".zip"),is3mf:ae.name.toLowerCase().endsWith(".3mf")}));d(ae=>[...ae,...W]),a&&me.length>0&&z(W)},I=me=>{d(W=>W.filter((ae,ce)=>ce!==me))},te=c.some(me=>me.isZip&&me.status==="pending"),se=c.some(me=>me.file.name.toLowerCase().endsWith(".stl")&&me.status==="pending"),Z=c.some(me=>me.is3mf&&me.status==="pending"),de=c.filter(me=>me.status==="pending").length,ue=c.length>0&&de===0&&!p;return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:l("fileManager.uploadFiles")}),i.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:i.jsx(qt,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsxs("div",{onDragOver:T,onDragLeave:j,onDrop:A,onClick:()=>P.current?.click(),className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${u?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,children:[i.jsx(wi,{className:`w-10 h-10 mx-auto mb-3 ${u?"text-bambu-green":"text-bambu-gray"}`}),i.jsx("p",{className:"text-white font-medium",children:l(u?"fileManager.dropFilesHere":"fileManager.dragDropFiles")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:l("fileManager.orClickToBrowse")}),i.jsx("p",{className:"text-xs text-bambu-gray/70 mt-2",children:l("fileManager.allFileTypesSupported")})]}),i.jsx("input",{ref:P,type:"file",multiple:!0,accept:o,className:"hidden",onChange:F}),te&&i.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Vs,{className:"w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-blue-300 font-medium",children:l("fileManager.zipFilesDetected")}),i.jsx("p",{className:"text-xs text-blue-300/70 mt-1",children:l("fileManager.zipExtractOptions")}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:y,onChange:me=>v(me.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.preserveZipStructure")})]}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:b,onChange:me=>g(me.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.createFolderFromZip")})]})]})]})}),Z&&i.jsx("div",{className:"p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Nr,{className:"w-5 h-5 text-purple-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-purple-300 font-medium",children:l("fileManager.threemfDetected")}),i.jsx("p",{className:"text-xs text-purple-300/70 mt-1",children:l("fileManager.threemfExtractionInfo")})]})]})}),(se||te)&&i.jsx("div",{className:"p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Vu,{className:"w-5 h-5 text-bambu-green mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-bambu-green font-medium",children:l("fileManager.stlThumbnailGeneration")}),i.jsx("p",{className:"text-xs text-bambu-green/70 mt-1",children:l(te&&!se?"fileManager.zipMayContainStl":"fileManager.thumbnailsCanBeGenerated")}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:_,onChange:me=>N(me.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.generateThumbnailsForStl")})]})]})]})}),c.length>0&&i.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:c.map((me,W)=>i.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[me.isZip?i.jsx(Vs,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):i.jsx(cT,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-sm text-white truncate",children:me.file.name}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[(me.file.size/1024/1024).toFixed(2)," MB",me.isZip&&me.status==="pending"&&i.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",l("fileManager.willBeExtracted")]}),me.extractedCount!==void 0&&i.jsxs("span",{className:"text-green-400 ml-2",children:["• ",l("fileManager.filesExtracted",{count:me.extractedCount})]})]})]}),me.status==="pending"&&i.jsx("button",{onClick:()=>I(W),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(qt,{className:"w-4 h-4 text-bambu-gray"})}),me.status==="uploading"&&i.jsx(ft,{className:"w-4 h-4 text-bambu-green animate-spin"}),me.status==="success"&&i.jsx(pr,{className:"w-4 h-4 text-green-500"}),me.status==="error"&&i.jsx("span",{title:me.error,children:i.jsx(Wi,{className:"w-4 h-4 text-red-500"})})]},W))}),C&&i.jsx("div",{className:"p-3 bg-red-500/10 border border-red-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Wi,{className:"w-5 h-5 text-red-400 mt-0.5 flex-shrink-0"}),i.jsx("p",{className:"text-sm text-red-300",children:C})]})})]}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:e,children:l("common.cancel")}),!ue&&i.jsx(Ie,{onClick:()=>z(c),disabled:de===0||p,children:p?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-4 h-4 mr-2 animate-spin"}),l("fileManager.uploading")]}):i.jsxs(i.Fragment,{children:[i.jsx(wi,{className:"w-4 h-4 mr-2"}),l("common.upload")," ",de>0?`(${de})`:""]})})]})]})})}function NW(t){return t?`#${t.replace("#","").substring(0,6)}`:"#808080"}function Li(t){return t?t.replace("#","").toLowerCase().substring(0,6):""}const lVe=[["PA-CF","PA12-CF","PAHT-CF"]],pie={};for(const t of lVe){const e=t[0];for(const n of t)pie[n.toUpperCase()]=e.toUpperCase()}function oC(t){if(!t)return"";const e=t.toUpperCase();return pie[e]??e}function iD(t,e){return oC(t)===oC(e)}function xd(t,e,n=40){const r=Li(t),a=Li(e);if(!r||!a||r.length<6||a.length<6)return!1;const s=parseInt(r.substring(0,2),16),o=parseInt(r.substring(2,4),16),l=parseInt(r.substring(4,6),16),c=parseInt(a.substring(0,2),16),d=parseInt(a.substring(2,4),16),u=parseInt(a.substring(4,6),16);return Math.abs(s-c)<=n&&Math.abs(o-d)<=n&&Math.abs(l-u)<=n}function Zw(t,e,n,r){if(r)return"Ext";const a=String.fromCharCode(65+(t>=128?t-128:t));return n?`HT-${a}`:`${a}${e+1}`}function Fx(t,e,n){return n?254+e:t>=128?t:t*4+e}function ox(t){return t>50?"#00ae42":t>=15?"#f59e0b":"#ef4444"}function SN(t){return!t?.remaining_weight||!t?.filament_weight||t.filament_weight<=0?null:Math.min(100,Math.round(t.remaining_weight/t.filament_weight*100))}function kW(t,e){return(Number.isFinite(t)?Math.max(0,Math.trunc(t)):0).toString(16).toUpperCase().padStart(e,"0").slice(-e)}function cVe(t){const e=(t||"").trim().toUpperCase();let n=2166136261;for(let r=0;r>>0).toString(16).toUpperCase().padStart(8,"0")}function Su(t,e,n){return`${cVe(t)}${kW(e,4)}${kW(n,4)}`}function CW(t){if(!t)return!1;const e=Date.now()+4320*60*60*1e3;return(Qn(t)?.getTime()??0)>e}function dVe(t,e,n){const r=fie(e,t.nozzle_id),a=r.find(l=>!n.has(l.globalTrayId)&&iD(l.type,t.type)&&Li(l.color)===Li(t.color)),s=a?void 0:r.find(l=>!n.has(l.globalTrayId)&&iD(l.type,t.type)&&xd(l.color,t.color)),o=a||s?void 0:r.find(l=>!n.has(l.globalTrayId)&&iD(l.type,t.type));return a??s??o}function fie(t,e){return t.filter(n=>e==null||n.extruderId===e)}function Jw(t){const e=[],n=t?.ams_extruder_map,r=n&&Object.keys(n).length>0;t?.ams?.forEach(a=>{const s=a.tray.length===1;a.tray.forEach(o=>{if(o.tray_type){const l=NW(o.tray_color);e.push({type:o.tray_type,color:l,colorName:Bu(l),amsId:a.id,trayId:o.id,isHt:s,isExternal:!1,label:Zw(a.id,o.id,s,!1),globalTrayId:Fx(a.id,o.id,!1),trayInfoIdx:o.tray_info_idx||"",traySubBrands:o.tray_sub_brands||"",extruderId:n?.[String(a.id)]})}})});for(const a of t?.vt_tray??[])if(a.tray_type){const s=NW(a.tray_color),o=a.id??254,l=(t?.vt_tray?.length??0)>1;e.push({type:a.tray_type,color:s,colorName:Bu(s),amsId:-1,trayId:o-254,isHt:!1,isExternal:!0,label:l?o===254?"Ext-L":"Ext-R":"External",globalTrayId:o,trayInfoIdx:a.tray_info_idx||"",traySubBrands:a.tray_sub_brands||"",extruderId:r?255-o:void 0})}return e}function TW(t,e){if(!t?.filaments||t.filaments.length===0)return;const n=Jw(e);if(n.length===0)return;const r=new Set,a=t.filaments.map(l=>{const c=l.tray_info_idx||"";let d=n.filter(v=>!r.has(v.globalTrayId));l.nozzle_id!=null&&(d=d.filter(v=>v.extruderId===l.nozzle_id));let u,m,p,f;if(c){const v=d.filter(b=>b.trayInfoIdx===c);v.length===1?u=v[0]:v.length>1&&(m=v.find(b=>b.type?.toUpperCase()===l.type?.toUpperCase()&&Li(b.color)===Li(l.color)),m||(p=v.find(b=>b.type?.toUpperCase()===l.type?.toUpperCase()&&xd(b.color,l.color))),!m&&!p&&(f=v.find(b=>b.type?.toUpperCase()===l.type?.toUpperCase())))}!u&&!m&&!p&&!f&&(m=d.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&Li(v.color)===Li(l.color)),m||(p=d.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&xd(v.color,l.color))),!m&&!p&&(f=d.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase())));const y=u||m||p||f||void 0;return y&&r.add(y.globalTrayId),{slot_id:l.slot_id,globalTrayId:y?.globalTrayId??-1}}),s=Math.max(...a.map(l=>l.slot_id||0));if(s<=0)return;const o=new Array(s).fill(-1);return a.forEach(l=>{l.slot_id&&l.slot_id>0&&(o[l.slot_id-1]=l.globalTrayId)}),o}function uVe(t){return w.useMemo(()=>Jw(t),[t])}function gie(t,e,n){const r=uVe(e),a=w.useMemo(()=>{if(!t?.filaments||t.filaments.length===0)return[];const c=new Set(Object.values(n));return t.filaments.map(d=>{const u=d.slot_id||0;if(u>0&&n[u]!==void 0){const P=n[u],T=r.find(j=>j.globalTrayId===P);if(T){const j=T.type?.toUpperCase()===d.type?.toUpperCase(),A=Li(T.color)===Li(d.color)||xd(T.color,d.color);let F;return j&&A?F="match":j?F="type_only":F="mismatch",{...d,loaded:T,hasFilament:!0,typeMatch:j,colorMatch:A,status:F,isManual:!0}}}const m=d.tray_info_idx||"";let p=r.filter(P=>!c.has(P.globalTrayId));d.nozzle_id!=null&&(p=p.filter(P=>P.extruderId===d.nozzle_id));let f,y,v,b;if(m){const P=p.filter(T=>T.trayInfoIdx===m);P.length===1?f=P[0]:P.length>1&&(y=P.find(T=>T.type?.toUpperCase()===d.type?.toUpperCase()&&Li(T.color)===Li(d.color)),y||(v=P.find(T=>T.type?.toUpperCase()===d.type?.toUpperCase()&&xd(T.color,d.color))),!y&&!v&&(b=P.find(T=>T.type?.toUpperCase()===d.type?.toUpperCase())))}!f&&!y&&!v&&!b&&(y=p.find(P=>P.type?.toUpperCase()===d.type?.toUpperCase()&&Li(P.color)===Li(d.color)),y||(v=p.find(P=>P.type?.toUpperCase()===d.type?.toUpperCase()&&xd(P.color,d.color))),!y&&!v&&(b=p.find(P=>P.type?.toUpperCase()===d.type?.toUpperCase())));const g=f||y||v||b||void 0;g&&c.add(g.globalTrayId);const _=!!g,N=_,C=!!f||!!y||!!v;let k;return f||y||v?k="match":b?k="type_only":k="mismatch",{...d,loaded:g,hasFilament:_,typeMatch:N,colorMatch:C,status:k,isManual:!1}})},[t,r,n]),s=w.useMemo(()=>{if(a.length===0)return;const c=Math.max(...a.map(u=>u.slot_id||0));if(c<=0)return;const d=new Array(c).fill(-1);return a.forEach(u=>{u.slot_id&&u.slot_id>0&&(d[u.slot_id-1]=u.loaded?.globalTrayId??-1)}),d},[a]),o=a.some(c=>c.status==="mismatch"),l=a.some(c=>c.status==="type_only");return{loadedFilaments:r,filamentComparison:a,amsMapping:s,hasTypeMismatch:o,hasColorMismatch:l}}function mVe(t,e,n){if(!t||t.length===0)return{exactMatches:0,typeOnlyMatches:0,missingTypes:0,totalSlots:0,status:"full"};let r=0,a=0,s=0;const o=new Set(Object.values(n));for(const d of t){const u=d.slot_id||0;if(u>0&&n[u]!==void 0){const b=n[u],g=e.find(_=>_.globalTrayId===b);if(g){const _=g.type?.toUpperCase()===d.type?.toUpperCase(),N=Li(g.color)===Li(d.color)||xd(g.color,d.color);_&&N?r++:_?a++:s++;continue}}let m=e.filter(b=>!o.has(b.globalTrayId));if(d.nozzle_id!=null){const b=m.filter(g=>g.extruderId===d.nozzle_id);b.length>0&&(m=b)}const p=m.find(b=>b.type?.toUpperCase()===d.type?.toUpperCase()&&Li(b.color)===Li(d.color)),f=p?void 0:m.find(b=>b.type?.toUpperCase()===d.type?.toUpperCase()&&xd(b.color,d.color)),y=p||f?void 0:m.find(b=>b.type?.toUpperCase()===d.type?.toUpperCase()),v=p??f??y;v&&o.add(v.globalTrayId),p||f?r++:y?a++:s++}const l=t.length;let c="full";return s>0?c="missing":a>0&&(c="partial"),{exactMatches:r,typeOnlyMatches:a,missingTypes:s,totalSlots:l,status:c}}function hVe(t,e,n){if(!t?.filaments||t.filaments.length===0)return;const r=Jw(e);if(r.length===0)return;const a=new Set(Object.values(n)),s=[];for(const c of t.filaments){const d=c.slot_id||0;if(d>0&&n[d]!==void 0){s.push({slot_id:d,globalTrayId:n[d]});continue}let u=r.filter(v=>!a.has(v.globalTrayId));if(c.nozzle_id!=null){const v=u.filter(b=>b.extruderId===c.nozzle_id);v.length>0&&(u=v)}const m=u.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&Li(v.color)===Li(c.color)),p=m?void 0:u.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&xd(v.color,c.color)),f=m||p?void 0:u.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()),y=m??p??f;y&&a.add(y.globalTrayId),s.push({slot_id:d,globalTrayId:y?.globalTrayId??-1})}const o=Math.max(...s.map(c=>c.slot_id||0));if(o<=0)return;const l=new Array(o).fill(-1);return s.forEach(c=>{c.slot_id&&c.slot_id>0&&(l[c.slot_id-1]=c.globalTrayId)}),l}const AW={useDefault:!0,manualMappings:{},autoConfigured:!1};function pVe(t,e,n,r,a,s){const o=ep({queries:t.map(y=>({queryKey:["printer-status",y],queryFn:()=>fe.getPrinterStatus(y),enabled:t.length>0,staleTime:5e3}))}),l=w.useMemo(()=>t.map((y,v)=>{const b=o[v],g=b?.data,N=e?.find(F=>F.id===y)?.name||`Printer ${y}`,C=Jw(g),k=a[y]||AW,P=TW(n,g),T=k.useDefault?r:k.manualMappings,j=hVe(n,g,T),A=mVe(n?.filaments,C,T);return{printerId:y,printerName:N,status:g,isLoading:b?.isLoading??!1,loadedFilaments:C,autoMapping:P,finalMapping:j,matchStatus:A.status,exactMatches:A.exactMatches,typeOnlyMatches:A.typeOnlyMatches,missingTypes:A.missingTypes,totalSlots:A.totalSlots,config:k}}),[t,o,e,n,a,r]),c=o.some(y=>y.isLoading),d=(y,v)=>{s(b=>({...b,[y]:{...b[y]||AW,...v}}))},u=y=>{const v=l.find(_=>_.printerId===y);if(!v||!v.status||!n?.filaments)return;const b=TW(n,v.status);if(!b)return;const g={};b.forEach((_,N)=>{_!==-1&&(g[N+1]=_)}),d(y,{useDefault:!1,manualMappings:g,autoConfigured:!0})},m=()=>{for(const y of t)u(y)},p=y=>l.find(b=>b.printerId===y)?.finalMapping,f=l.every(y=>y.matchStatus!=="missing");return{printerResults:l,isLoading:c,perPrinterConfigs:a,updatePrinterConfig:d,autoConfigureAll:m,autoConfigurePrinter:u,getFinalMapping:p,allPrintersReady:f}}const bie={USD:"$",EUR:"€",GBP:"£",CHF:"Fr.",JPY:"¥",CNY:"¥",CAD:"$",AUD:"$",INR:"₹",HKD:"HK$",KRW:"₩",SEK:"kr",NOK:"kr",DKK:"kr",PLN:"zł",BRL:"R$",TWD:"NT$",SGD:"S$",NZD:"NZ$",MXN:"MX$",MYR:"RM",CZK:"Kč",THB:"฿",ZAR:"R",TRY:"₺",RUB:"₽",HUF:"Ft",ILS:"₪"};function go(t){return bie[t.toUpperCase()]||t}const fVe=Object.entries(bie).map(([t,e])=>({code:t,label:`${t} (${e})`}));function gVe({printerId:t,filamentReqs:e,manualMappings:n,onManualMappingChange:r,currencySymbol:a,defaultCostPerKg:s,defaultExpanded:o=!1}){const{t:l}=jt(),c=cn(),[d,u]=w.useState(!1),[m,p]=w.useState(o),{data:f}=Je({queryKey:["printer-status",t],queryFn:()=>fe.getPrinterStatus(t),enabled:!!t}),{data:y}=Je({queryKey:["spool-assignments",t],queryFn:()=>fe.getAssignments(t),enabled:!!t}),{loadedFilaments:v,filamentComparison:b,hasTypeMismatch:g,hasColorMismatch:_}=gie(e,f,n),N=w.useMemo(()=>{const z=new Map;for(const J of y||[]){const I=J.ams_id===255,te=Fx(J.ams_id,J.tray_id,I);z.set(te,J.spool?.cost_per_kg??null)}return z},[y]),C=w.useMemo(()=>{const z=new Map;for(const J of y||[]){const I=J.ams_id===255,te=Fx(J.ams_id,J.tray_id,I),se=J.spool;if(!se){z.set(te,null);continue}z.set(te,Math.max(0,Math.round((se.label_weight??0)-(se.weight_used??0))))}return z},[y]),k=w.useMemo(()=>{let z=0;for(const J of b){const I=J.loaded?.globalTrayId;if(I==null)continue;const se=N.get(I)??null??s;se>0&&(z+=J.used_grams/1e3*se)}return z},[b,N,s]),P=w.useMemo(()=>Array.from(N.values()).some(z=>z!=null&&z>0),[N]),T=e?.filaments&&e.filaments.length>0,j=e?.filaments?.some(z=>z.nozzle_id!=null)??!1;if(!T||!f)return null;const A=g?"#f97316":_?"#facc15":"#00ae42",F=(z,J)=>{if(z>0)if(J===""){const I={...n};delete I[z],r(I)}else r({...n,[z]:parseInt(J,10)})},G=async()=>{u(!0);try{await fe.refreshPrinterStatus(t),await new Promise(z=>setTimeout(z,500)),await c.refetchQueries({queryKey:["printer-status",t]})}finally{u(!1)}};return i.jsxs("div",{className:"mb-4",children:[i.jsxs("button",{type:"button",onClick:()=>p(!m),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[i.jsx(N0,{className:"w-4 h-4",fill:A,stroke:"none"}),i.jsx("span",{children:l("printModal.filamentMapping")}),g?i.jsx("span",{className:"text-xs text-orange-400",children:"(Type not found)"}):_?i.jsx("span",{className:"text-xs text-yellow-400",children:"(Color mismatch)"}):i.jsx("span",{className:"text-xs text-bambu-green",children:"(Ready)"}),m?i.jsx(Gl,{className:"w-4 h-4 ml-auto"}):i.jsx(zn,{className:"w-4 h-4 ml-auto"})]}),m&&i.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:"Click to change slot assignment"}),i.jsxs("button",{type:"button",onClick:G,className:"flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",disabled:d,children:[i.jsx(vr,{className:`w-3 h-3 ${d?"animate-spin":""}`}),i.jsx("span",{children:"Re-read"})]})]}),b.map((z,J)=>i.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[i.jsx("span",{title:`Required: ${z.type} - ${Bu(z.color)}`,children:i.jsx(N0,{className:"w-3 h-3",fill:z.color,stroke:z.color})}),i.jsxs("span",{className:"text-white truncate flex items-center gap-1",children:[j&&z.nozzle_id!=null&&i.jsx("span",{className:"inline-flex items-center justify-center w-3.5 h-3.5 rounded text-[9px] font-bold leading-none bg-bambu-gray/20 text-bambu-gray shrink-0",title:z.nozzle_id===1?l("printModal.leftNozzleTooltip"):l("printModal.rightNozzleTooltip"),children:z.nozzle_id===1?l("printModal.leftNozzle"):l("printModal.rightNozzle")}),z.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",z.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:z.loaded?.globalTrayId??"",onChange:I=>F(z.slot_id||0,I.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${z.status==="match"?"border-bambu-green/50 text-bambu-green":z.status==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${z.isManual?"ring-1 ring-blue-400/50":""}`,title:z.isManual?"Manually selected":"Auto-matched",children:[i.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),v.filter(I=>z.nozzle_id==null||I.extruderId===z.nozzle_id).map(I=>{const te=C.get(I.globalTrayId),se=te!=null?l("printModal.slotRemainingShort",{grams:te,defaultValue:` - ${te}g left`}):"";return i.jsxs("option",{value:I.globalTrayId,className:"bg-bambu-dark text-white",children:[I.label,": ",I.traySubBrands||I.type," (",I.colorName,")",se]},I.globalTrayId)})]}),z.status==="match"?i.jsx(Zr,{className:"w-3 h-3 text-bambu-green"}):z.status==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(jn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(jn,{className:"w-3 h-3 text-orange-400"})})]},J)),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[l("printModal.totalCost")," ",i.jsx("span",{className:"text-white",children:k>0||P?`${a}${k.toFixed(2)}`:"N/A"})]}),g&&i.jsx("p",{className:"text-xs text-orange-400 mt-2",children:"Required filament type not found in printer."})]})]})}function bVe({filamentReqs:t,availableFilaments:e,overrides:n,onChange:r,forceColorMatch:a,onForceColorMatchChange:s}){const{t:o}=jt(),l=w.useMemo(()=>{const u={};for(const m of e){const p=oC(m.type);u[p]||(u[p]=[]),u[p].push(m)}return u},[e]),c=t?.filaments;if(!c||c.length===0||e.length===0)return null;const d=(u,m)=>{if(m===""){const p={...n};delete p[u],r(p)}else{const[p,f]=m.split("|");r({...n,[u]:{type:p,color:f}})}};return i.jsxs("div",{className:"mb-4",children:[i.jsx("div",{className:"flex items-center gap-2 text-sm text-bambu-gray mb-2",children:i.jsx("span",{children:o("printModal.filamentOverride")})}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:o("printModal.filamentOverrideHint")}),i.jsx("div",{className:"bg-bambu-dark rounded-lg p-3 space-y-2",children:c.map(u=>{const m=n[u.slot_id],p=!!m,f=l[oC(u.type)]||[],y=u.nozzle_id!=null?f.filter(v=>v.extruder_id==null||v.extruder_id===u.nozzle_id):f;return i.jsxs("div",{className:"space-y-1",children:[i.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 20px"},children:[i.jsx("span",{title:`${o("printModal.originalFilament")}: ${u.type} - ${Bu(u.color)}`,children:i.jsx(N0,{className:"w-3 h-3",fill:u.color,stroke:u.color})}),i.jsxs("span",{className:"text-white truncate",children:[u.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",u.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:p?`${m.type}|${m.color}`:"",onChange:v=>d(u.slot_id,v.target.value),disabled:y.length===0,className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${p?"border-blue-400/50 text-blue-400":"border-bambu-gray/30 text-bambu-gray"}`,children:[i.jsxs("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:[o("printModal.originalFilament"),": ",u.type," (",Bu(u.color),")"]}),y.map((v,b)=>i.jsxs("option",{value:`${v.type}|${v.color}`,className:"bg-bambu-dark text-white",children:[v.tray_sub_brands||v.type," (",Bu(v.color),")"]},`${v.type}-${v.color}-${v.tray_sub_brands}-${b}`))]}),p?i.jsx("button",{type:"button",onClick:()=>d(u.slot_id,""),className:"text-bambu-gray hover:text-white transition-colors",title:o("printModal.resetToOriginal"),children:i.jsx(Ao,{className:"w-3 h-3"})}):i.jsx("span",{className:"w-3"})]}),i.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer select-none pl-5",children:[i.jsx("input",{type:"checkbox",checked:a?.[u.slot_id]??!1,onChange:v=>s?.(u.slot_id,v.target.checked),className:"accent-bambu-green w-3 h-3"}),i.jsx(_w,{className:"w-3 h-3"}),o("printModal.forceColorMatch")]})]},u.slot_id)})})]})}function xVe({plates:t,isMultiPlate:e,selectedPlates:n,onToggle:r,onSelectAll:a,onDeselectAll:s,multiSelect:o}){const{t:l}=jt();if(!e||t.length<=1)return null;const c=n.size===t.length;return i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx(Ki,{className:"w-4 h-4 text-bambu-gray"}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:["Select Plate",o?"s":""," to Print"]}),n.size===0&&i.jsxs("span",{className:"text-xs text-orange-400 flex items-center gap-1",children:[i.jsx(jn,{className:"w-3 h-3"}),"Selection required"]}),o&&a&&s&&i.jsx("button",{type:"button",onClick:c?s:a,className:`ml-auto text-xs px-2 py-0.5 rounded-full border transition-colors ${c?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray"}`,children:c?l("queue.deselectAll"):l("queue.selectAllPlates",{count:t.length})})]}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map(d=>{const u=n.has(d.index);return i.jsxs("button",{type:"button",onClick:()=>r(d.index),className:`flex items-center gap-2 p-2 rounded-lg border transition-colors text-left ${u?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"}`,children:[o&&(u?i.jsx(Ys,{className:"w-4 h-4 text-bambu-green flex-shrink-0"}):i.jsx(il,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"})),d.has_thumbnail&&d.thumbnail_url!=null?i.jsx("img",{src:d.thumbnail_url,alt:`Plate ${d.index}`,className:"w-10 h-10 rounded object-cover bg-bambu-dark-tertiary"}):i.jsx("div",{className:"w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center",children:i.jsx(Ki,{className:"w-5 h-5 text-bambu-gray"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-sm text-white font-medium truncate",children:d.name||`Plate ${d.index}`}),i.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[d.objects.length>0?d.objects.slice(0,3).join(", ")+(d.objects.length>3?"...":""):`${d.filaments.length} filament${d.filaments.length!==1?"s":""}`,d.print_time_seconds!=null?` • ${Bs(d.print_time_seconds)}`:""]})]}),!o&&u&&i.jsx(Zr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]},d.index)})})]})}const yVe=new Set(["IDLE","FINISH","FAILED"]);function vVe({printerResult:t,filamentReqs:e,onUpdateConfig:n}){const r=cn(),[a,s]=w.useState(!1),o=(d,u)=>{if(d<=0)return;const m={...t.config.manualMappings};u===""?delete m[d]:m[d]=parseInt(u,10),n({useDefault:!1,manualMappings:m,autoConfigured:!1})},l=async()=>{s(!0);try{await fe.refreshPrinterStatus(t.printerId),await new Promise(d=>setTimeout(d,500)),await r.refetchQueries({queryKey:["printer-status",t.printerId]})}finally{s(!1)}},c=e.map(d=>{const u=d.slot_id||0,m=t.config.manualMappings[u];let p,f=!1;if(m!==void 0)p=t.loadedFilaments.find(v=>v.globalTrayId===m),f=!0;else{const v=new Set(Object.values(t.config.manualMappings));p=dVe(d,t.loadedFilaments,v)}let y="mismatch";if(p){const v=p.type?.toUpperCase()===d.type?.toUpperCase(),b=Li(p.color)===Li(d.color)||xd(p.color,d.color);v&&b?y="match":v&&(y="type_only")}return{req:d,loaded:p,status:y,isManual:f}});return i.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom slot mapping"}),i.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",disabled:a,children:[i.jsx(vr,{className:`w-3 h-3 ${a?"animate-spin":""}`}),i.jsx("span",{children:"Re-read"})]})]}),c.map(({req:d,loaded:u,status:m,isManual:p},f)=>i.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[i.jsx("span",{title:`Required: ${d.type} - ${Bu(d.color)}`,children:i.jsx(N0,{className:"w-3 h-3",fill:d.color,stroke:d.color})}),i.jsxs("span",{className:"text-white truncate",children:[d.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",d.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:u?.globalTrayId??"",onChange:y=>o(d.slot_id||0,y.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${m==="match"?"border-bambu-green/50 text-bambu-green":m==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${p?"ring-1 ring-blue-400/50":""}`,title:p?"Manually selected":"Auto-matched",children:[i.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),fie(t.loadedFilaments,d.nozzle_id).map(y=>i.jsxs("option",{value:y.globalTrayId,className:"bg-bambu-dark text-white",children:[y.label,": ",y.traySubBrands||y.type," (",y.colorName,")"]},y.globalTrayId))]}),m==="match"?i.jsx(Zr,{className:"w-3 h-3 text-bambu-green"}):m==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(jn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(jn,{className:"w-3 h-3 text-orange-400"})})]},f))]})}function wVe({printers:t,selectedPrinterIds:e,onMultiSelect:n,isLoading:r=!1,allowMultiple:a=!1,showInactive:s=!1,disableBusy:o=!1,printerMappingResults:l,filamentReqs:c,onAutoConfigurePrinter:d,onUpdatePrinterConfig:u,assignmentMode:m="printer",onAssignmentModeChange:p,targetModel:f,onTargetModelChange:y,targetLocation:v,onTargetLocationChange:b,slicedForModel:g}){const[_,N]=w.useState(!1),C=s?t:t.filter(ae=>ae.is_active),k=ep({queries:C.map(ae=>({queryKey:["printerStatus",ae.id],queryFn:()=>fe.getPrinterStatus(ae.id),staleTime:5e3}))}),P=w.useMemo(()=>{const ae=new Map;return C.forEach((ce,ge)=>{const Ne=k[ge];Ne?.data&&ae.set(ce.id,Ne.data)}),ae},[C,k]),T=ae=>{const ce=P.get(ae);return ce?ce.connected?!yVe.has(ce.state??""):!0:!1},j=ae=>{const ce=P.get(ae);if(!ce)return null;if(!ce.connected)return"Offline";const ge=ce.state;return ge?ge==="RUNNING"?ce.stg_cur_name||"Printing":ge==="PREPARE"?"Preparing":ge==="PAUSE"?"Paused":ge==="IDLE"?"Idle":ge==="FINISH"?"Finished":ge==="FAILED"?"Failed":ge:null},A=w.useMemo(()=>{if(m!=="printer"||!g||_)return C;const ae=C.filter(ce=>ce.model===g);return ae.length>0?ae:C},[C,m,g,_]),F=C.length-A.length,G=w.useMemo(()=>{const ae=C.map(ce=>ce.model).filter(ce=>!!ce);return[...new Set(ae)].sort()},[C]),z=w.useMemo(()=>{if(!f)return[];const ae=C.filter(ce=>ce.model===f&&ce.location).map(ce=>ce.location).filter(ce=>!!ce);return[...new Set(ae)].sort()},[C,f]),J=p&&y&&G.length>0,I=a&&e.length>1&&l&&c?.filaments&&c.filaments.length>0&&d&&u;if(r)return i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ft,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(A.length===0)return i.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm mb-4",children:[i.jsx(Ii,{className:"w-4 h-4"}),"No ",s?"":"active ","printers available"]});const te=ae=>{o&&T(ae)||(a?e.includes(ae)?n(e.filter(ce=>ce!==ae)):n([...e,ae]):n([ae]))},se=()=>{const ae=o?A.filter(ce=>!T(ce.id)):A;n(ae.map(ce=>ce.id))},Z=()=>{n([])},de=(ae,ce,ge)=>{ge.stopPropagation(),!(!d||!u)&&(ce?d(ae):u(ae,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},ue=ae=>e.includes(ae),me=e.length,W=ae=>l?.find(ce=>ce.printerId===ae);return i.jsxs("div",{className:"space-y-2 mb-6",children:[J&&i.jsxs("div",{className:"flex gap-2 mb-4",children:[i.jsxs("button",{type:"button",onClick:()=>{p("printer"),y(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${m==="printer"?"border-bambu-green bg-bambu-green/10 text-white":"border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray"}`,children:[i.jsx(Nr,{className:"w-4 h-4"}),i.jsx("span",{className:"text-sm",children:"Specific Printer"})]}),i.jsxs("button",{type:"button",onClick:()=>{p("model"),n([]);const ae=g&&G.includes(g)?g:G[0];y(ae)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${m==="model"?"border-bambu-green bg-bambu-green/10 text-white":"border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray"}`,children:[i.jsx(lh,{className:"w-4 h-4"}),i.jsxs("span",{className:"text-sm",children:["Any ",g||"Model"]})]})]}),m==="model"&&J&&i.jsxs("div",{className:"space-y-3 mb-4",children:[!g&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Target Model"}),i.jsxs("select",{value:f||"",onChange:ae=>{y(ae.target.value||null),b&&b(null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",children:[i.jsx("option",{value:"",children:"Select a model..."}),G.map(ae=>i.jsx("option",{value:ae,children:ae},ae))]})]}),f&&z.length>0&&b&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Location Filter (optional)"}),i.jsxs("select",{value:v||"",onChange:ae=>b(ae.target.value||null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",children:[i.jsx("option",{value:"",children:"Any location"}),z.map(ae=>i.jsx("option",{value:ae,children:ae},ae))]})]}),f&&i.jsxs("p",{className:"text-xs text-bambu-gray",children:["Scheduler will assign to first available idle ",f," printer",v?` in ${v}`:""]})]}),m==="printer"&&a&&A.length>1&&i.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray mb-2",children:[i.jsx("span",{children:me===0?"Select printers":`${me} printer${me!==1?"s":""} selected`}),i.jsxs("div",{className:"flex gap-2",children:[me0&&i.jsx("button",{type:"button",onClick:Z,className:"text-bambu-gray hover:text-white transition-colors",children:"Clear"})]})]}),m==="printer"&&A.map(ae=>{const ce=ue(ae.id),ge=W(ae.id),Ne=ge&&!ge.config.useDefault,H=T(ae.id),X=o&&H,D=j(ae.id);return i.jsxs("div",{children:[i.jsxs("button",{type:"button",onClick:()=>te(ae.id),disabled:X,className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${X?"border-bambu-dark-tertiary bg-bambu-dark opacity-50 cursor-not-allowed":ce?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"} ${ae.is_active?"":"opacity-60"}`,children:[i.jsx("div",{className:`p-2 rounded-lg ${X?"bg-bambu-dark-tertiary":ce?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:i.jsx(Nr,{className:`w-5 h-5 ${X?"text-bambu-gray/50":ce?"text-bambu-green":"text-bambu-gray"}`})}),i.jsxs("div",{className:"text-left flex-1",children:[i.jsxs("p",{className:`font-medium ${X?"text-bambu-gray":"text-white"}`,children:[ae.name,!ae.is_active&&i.jsx("span",{className:"text-bambu-gray text-xs ml-2",children:"(inactive)"})]}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[ae.model||"Unknown model"," • ",ae.ip_address]})]}),D&&i.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${H?"bg-yellow-500/20 text-yellow-400":"bg-bambu-green/20 text-bambu-green"}`,children:D}),a&&i.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${X?"border-bambu-gray/30":ce?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:ce&&i.jsx(Zr,{className:"w-3 h-3 text-white"})})]}),ce&&I&&ge&&i.jsxs("div",{className:"ml-4 mt-2 mb-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",onClick:M=>M.stopPropagation(),children:[i.jsx("input",{type:"checkbox",checked:Ne,onChange:M=>de(ae.id,M.target.checked,M),className:"w-3.5 h-3.5 rounded border-bambu-gray/30 bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green focus:ring-offset-0"}),i.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom mapping"})]}),i.jsxs("span",{className:`text-xs ml-2 ${ge.matchStatus==="full"?"text-bambu-green":ge.matchStatus==="partial"?"text-yellow-400":"text-orange-400"}`,children:["(",ge.exactMatches,"/",ge.totalSlots," matched)"]}),ge.isLoading&&i.jsx(vr,{className:"w-3 h-3 text-bambu-gray animate-spin"}),Ne&&i.jsxs("button",{type:"button",onClick:M=>{M.stopPropagation(),d(ae.id)},className:"ml-auto flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",children:[i.jsx(pQ,{className:"w-3 h-3"}),"Auto"]})]}),Ne&&i.jsx(vVe,{printerResult:ge,filamentReqs:c.filaments,onUpdateConfig:M=>u(ae.id,M)})]})]},ae.id)}),m==="printer"&&F>0&&!_&&i.jsxs("button",{type:"button",onClick:()=>N(!0),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2 flex items-center gap-1",children:[i.jsx(jn,{className:"w-3 h-3 text-yellow-400"}),F," other printer",F>1?"s":""," hidden (different model) —",i.jsx("span",{className:"underline",children:"show all"})]}),m==="printer"&&_&&g&&i.jsx("button",{type:"button",onClick:()=>N(!1),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2",children:i.jsxs("span",{className:"underline",children:["Show only ",g," printers"]})}),m==="printer"&&me===0&&i.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[i.jsx(Ii,{className:"w-3 h-3"}),"Select at least one printer"]}),m==="model"&&!f&&i.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[i.jsx(Ii,{className:"w-3 h-3"}),"Select a target printer model"]})]})}const SVe=[{key:"bed_levelling",label:"Bed Levelling",desc:"Auto-level bed before print"},{key:"flow_cali",label:"Flow Calibration",desc:"Calibrate extrusion flow"},{key:"vibration_cali",label:"Vibration Calibration",desc:"Reduce ringing artifacts"},{key:"layer_inspect",label:"First Layer Inspection",desc:"AI inspection of first layer"},{key:"timelapse",label:"Timelapse",desc:"Record timelapse video"}];function _Ve({options:t,onChange:e,defaultExpanded:n=!1}){const[r,a]=w.useState(n),s=o=>{e({...t,[o]:!t[o]})};return i.jsxs("div",{className:"mb-4",children:[i.jsxs("button",{type:"button",onClick:()=>a(!r),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[i.jsx(gT,{className:"w-4 h-4"}),i.jsx("span",{children:"Print Options"}),r?i.jsx(Gl,{className:"w-4 h-4 ml-auto"}):i.jsx(zn,{className:"w-4 h-4 ml-auto"})]}),r&&i.jsx("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:SVe.map(({key:o,label:l,desc:c})=>i.jsxs("label",{className:"flex items-center justify-between cursor-pointer group",children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-sm text-white",children:l}),i.jsx("p",{className:"text-xs text-bambu-gray",children:c})]}),i.jsx("div",{className:`relative w-10 h-5 rounded-full transition-colors ${t[o]?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,onClick:()=>s(o),children:i.jsx("div",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white transition-transform ${t[o]?"translate-x-5":"translate-x-0.5"}`})})]},o))})]})}function NVe({options:t,onChange:e,dateFormat:n="system",timeFormat:r="system",canControlPrinter:a=!0}){const[s,o]=w.useState(""),[l,c]=w.useState(""),[d,u]=w.useState(!0),[m,p]=w.useState(!0),f=w.useRef(null),y=w.useRef(!1);w.useEffect(()=>{if(t.scheduleType!=="scheduled"){y.current=!1;return}if(!y.current){y.current=!0;let k;t.scheduledTime?(k=new Date(t.scheduledTime),isNaN(k.getTime())&&(k=new Date,k.setHours(k.getHours()+1,0,0,0))):(k=new Date,k.setHours(k.getHours()+1,0,0,0),e({...t,scheduledTime:O3(k)})),o(L3(k,n)),c(c6(k,r)),u(!0),p(!0)}},[t.scheduleType,t.scheduledTime,n,r,e,t]);const v=k=>{e({...t,scheduleType:k})},b=(k,P)=>{const T=Dxe(k,n),j=Fxe(P);u(!!T),p(!!j),T&&j&&(T.setHours(j.hours,j.minutes,0,0),T>new Date&&e({...t,scheduledTime:O3(T)}))},g=k=>{o(k),b(k,l)},_=k=>{c(k),b(s,k)},N=k=>{const P=k.target.value;if(P){const T=new Date(P);isNaN(T.getTime())||(o(L3(T,n)),c(c6(T,r)),u(!0),p(!0),e({...t,scheduledTime:P}))}},C=()=>{f.current?.showPicker()};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"When to print"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="asap"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("asap"),children:[i.jsx(Zn,{className:"w-4 h-4"}),"ASAP"]}),i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="scheduled"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("scheduled"),children:[i.jsx(Xr,{className:"w-4 h-4"}),"Scheduled"]}),i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="manual"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("manual"),children:[i.jsx(aQ,{className:"w-4 h-4"}),"Queue Only"]})]})]}),t.scheduleType==="scheduled"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date & Time"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("div",{className:"flex-1 relative",children:[i.jsx("input",{type:"text",className:`w-full px-3 py-2 pr-10 bg-bambu-dark border rounded-lg text-white focus:outline-none ${d?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:s,onChange:k=>g(k.target.value),placeholder:Mxe(n)}),i.jsx("button",{type:"button",onClick:C,className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",title:"Open calendar",children:i.jsx(Xr,{className:"w-4 h-4"})})]}),i.jsx("div",{className:"w-32",children:i.jsx("input",{type:"text",className:`w-full px-3 py-2 bg-bambu-dark border rounded-lg text-white focus:outline-none ${m?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:l,onChange:k=>_(k.target.value),placeholder:Exe(r)})})]}),i.jsx("input",{ref:f,type:"datetime-local",className:"sr-only",value:t.scheduledTime,onChange:N,tabIndex:-1}),(!d||!m)&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:"Please enter a valid date and time"})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"checkbox",id:"requirePrevious",checked:t.requirePreviousSuccess,onChange:k=>e({...t,requirePreviousSuccess:k.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("label",{htmlFor:"requirePrevious",className:"text-sm text-bambu-gray",children:"Only start if previous print succeeded"})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"checkbox",id:"autoOffAfter",checked:t.autoOffAfter,onChange:k=>e({...t,autoOffAfter:k.target.checked}),disabled:!a,className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green disabled:opacity-50"}),i.jsxs("label",{htmlFor:"autoOffAfter",className:`text-sm flex items-center gap-1 ${a?"text-bambu-gray":"text-bambu-gray/50"}`,children:[i.jsx(im,{className:"w-3.5 h-3.5"}),"Power off printer when done"]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:t.scheduleType==="asap"?"Print will start as soon as the printer is idle.":t.scheduleType==="scheduled"?"Print will start at the scheduled time if the printer is idle. If busy, it will wait until the printer becomes available.":"Print will be staged but won't start automatically. Use the Start button to release it to the queue."})]})}const Ab={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1},kVe={scheduleType:"asap",scheduledTime:"",requirePreviousSuccess:!1,autoOffAfter:!1};function yd({mode:t,archiveId:e,libraryFileId:n,archiveName:r,queueItem:a,initialSelectedPrinterIds:s,onClose:o,onSuccess:l}){const{t:c}=jt(),d=cn(),{showToast:u}=pn(),{hasPermission:m}=Pr(),p=!!n&&!e,[f,y]=w.useState(()=>t==="edit-queue-item"&&a?.printer_id?[a.printer_id]:s?.length?s:[]),[v,b]=w.useState(()=>t==="edit-queue-item"&&a?.plate_id!=null?new Set([a.plate_id]):new Set),g=v.size===1?[...v][0]:null,[_,N]=w.useState(()=>t==="edit-queue-item"&&a?{bed_levelling:a.bed_levelling??Ab.bed_levelling,flow_cali:a.flow_cali??Ab.flow_cali,vibration_cali:a.vibration_cali??Ab.vibration_cali,layer_inspect:a.layer_inspect??Ab.layer_inspect,timelapse:a.timelapse??Ab.timelapse}:Ab),[C,k]=w.useState(()=>{if(t==="edit-queue-item"&&a){let Pt="asap";a.manual_start?Pt="manual":a.scheduled_time&&!CW(a.scheduled_time)&&(Pt="scheduled");let ut="";if(a.scheduled_time&&!CW(a.scheduled_time)){const Lt=Qn(a.scheduled_time)??new Date;ut=O3(Lt)}return{scheduleType:Pt,scheduledTime:ut,requirePreviousSuccess:a.require_previous_success,autoOffAfter:a.auto_off_after}}return kVe}),[P,T]=w.useState(()=>{if(t==="edit-queue-item"&&a?.ams_mapping&&Array.isArray(a.ams_mapping)){const Pt={};return a.ams_mapping.forEach((ut,Lt)=>{ut!==-1&&(Pt[Lt+1]=ut)}),Pt}return{}}),[j,A]=w.useState({}),[F,G]=w.useState(()=>t==="edit-queue-item"&&a?.target_model?"model":"printer"),[z,J]=w.useState(()=>t==="edit-queue-item"&&a?.target_model?a.target_model:null),[I,te]=w.useState(()=>t==="edit-queue-item"&&a?.target_location?a.target_location:null),[se,Z]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const Pt={};for(const ut of a.filament_overrides)Pt[ut.slot_id]={type:ut.type,color:ut.color};return Pt}return{}}),[de,ue]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const Pt={};for(const ut of a.filament_overrides)Pt[ut.slot_id]=ut.force_color_match===!0;return Pt}return{}}),[me]=w.useState(()=>t==="edit-queue-item"&&a?.printer_id?[a.printer_id]:[]),[W]=w.useState(()=>t==="edit-queue-item"&&a?a.plate_id:null),[ae,ce]=w.useState(!1),[ge,Ne]=w.useState({current:0,total:0}),[H,X]=w.useState(null),[D,M]=w.useState(new Set),U=f.length,K=f.length>0?f[0]:null,{data:B}=Je({queryKey:["settings"],queryFn:fe.getSettings}),ie=go(B?.currency||"USD"),O=B?.default_filament_cost??0,{data:q,isLoading:Y}=Je({queryKey:["printers"],queryFn:fe.getPrinters}),{data:V}=Je({queryKey:["spool-assignments"],queryFn:()=>fe.getAssignments(),staleTime:30*1e3,enabled:(t==="reprint"||t==="add-to-queue")&&F==="printer"||p&&t==="reprint"}),{data:ee}=Je({queryKey:["archive",e],queryFn:()=>fe.getArchive(e),enabled:!!e&&!p}),{data:oe}=Je({queryKey:["library-file",n],queryFn:()=>fe.getLibraryFile(n),enabled:p&&!!n}),he=ee?.sliced_for_model||oe?.sliced_for_model||null,{data:pe,isError:re}=Je({queryKey:["archive-plates",e],queryFn:()=>fe.getArchivePlates(e),enabled:!!e&&!p,retry:!1}),{data:L}=Je({queryKey:["library-file-plates",n],queryFn:()=>fe.getLibraryFilePlates(n),enabled:p&&!!n}),R=p?L:pe,{data:ne,isError:ye}=Je({queryKey:["archive-filaments",e,g],queryFn:()=>fe.getArchiveFilamentRequirements(e,g??void 0),enabled:!!e&&!p&&(g!==null||!R?.is_multi_plate),retry:!1}),{data:ve}=Je({queryKey:["library-file-filaments",n,g],queryFn:()=>fe.getLibraryFileFilamentRequirements(n,g??void 0),enabled:p&&!!n&&(g!==null||!R?.is_multi_plate)}),be=!p&&(re||ye),Be=p?ve:ne,we=w.useMemo(()=>{if(!(g===null||!R?.plates?.length))return R.plates.find(Pt=>Pt.index===g)?.name||void 0},[R,g]),{data:Ae}=Je({queryKey:["available-filaments",z,I],queryFn:()=>fe.getAvailableFilaments(z,I??void 0),enabled:F==="model"&&!!z}),{data:Le}=Je({queryKey:["printer-status",K],queryFn:()=>fe.getPrinterStatus(K),enabled:!!K}),{amsMapping:Ee}=gie(Be,Le,P),_e=pVe(f,q,Be,P,j,A);w.useEffect(()=>{R?.plates&&R.plates.length>=1&&v.size===0&&b(new Set([R.plates[0].index]))},[R,v.size]),w.useEffect(()=>{if(t==="edit-queue-item")return;const Pt=q?.filter(ut=>ut.is_active)||[];Pt.length===1&&f.length===0&&y([Pt[0].id])},[t,q,f.length]),w.useEffect(()=>{t==="edit-queue-item"?(JSON.stringify(f.sort())!==JSON.stringify(me.sort())||g!==W)&&(T({}),A({}),M(new Set)):(T({}),A({}),M(new Set))},[t,f,g,me,W]);const[Me,He]=w.useState(z),[De,Xe]=w.useState(g);w.useEffect(()=>{(z!==Me||g!==De)&&(He(z),Xe(g),(t!=="edit-queue-item"||Me!==null)&&(Z({}),ue({})))},[z,g,Me,De,t]),w.useEffect(()=>{if(!B?.per_printer_mapping_expanded||f.length<=1)return;const Pt=f.filter(ut=>{if(D.has(ut))return!1;const Lt=_e.printerResults.find(qe=>qe.printerId===ut);return Lt&&Lt.status&&!Lt.isLoading});Pt.length>0&&(M(ut=>{const Lt=new Set(ut);return Pt.forEach(qe=>Lt.add(qe)),Lt}),Pt.forEach(ut=>{_e.autoConfigurePrinter(ut)}))},[B?.per_printer_mapping_expanded,f,D,_e]),w.useEffect(()=>{const Pt=ut=>{ut.key==="Escape"&&!ae&&o()};return window.addEventListener("keydown",Pt),()=>window.removeEventListener("keydown",Pt)},[o,ae]);const xe=R?.is_multi_plate??!1,We=R?.plates??[],Pe=w.useMemo(()=>{const Pt=new Map;return V&&V.forEach(ut=>{const Lt=ut.ams_id===255,qe=Fx(ut.ams_id,ut.tray_id,Lt),St=Pt.get(ut.printer_id)??new Map;St.set(qe,ut),Pt.set(ut.printer_id,St)}),Pt},[V]),Ke=w.useMemo(()=>{if(!H||H.length===0)return"";const Pt=H.map(ut=>c("printModal.insufficientFilamentLine",{printer:ut.printerName,slot:ut.slotLabel,required:Math.round(ut.requiredGrams),remaining:Math.round(ut.remainingGrams)}));return[c("printModal.insufficientFilamentMessage"),...Pt].join(` +${o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})}`:g.type==="profile"&&(Z=o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})),i.jsx(_n,{title:o("inventory.assignMismatchTitle"),message:Z,confirmText:o("inventory.assignMismatchConfirm"),variant:"warning",isLoading:T.isPending,onConfirm:se,onCancel:()=>{T.isPending||(b(!1),y(null),_(null))}})})()]})}function yW(t,e){if(t===255)return"External";let n,r=!1;t>=128&&t<=135?(n=t-128,r=!0):t>=0&&t<=3?(n=t,r=e===1):n=0,n=Math.max(0,Math.min(n,7));const a=String.fromCharCode(65+n);return r?`HT-${a}`:`AMS-${a}`}function R1(t){const e=t.includes("_")?t.split("_")[0]:t;return e.startsWith("GFS")?"GF"+e.slice(3):(e.startsWith("PFUS")||e.startsWith("PFSP"),e)}const n0=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function vW(t){const e=t.replace(/@.+$/,"").trim(),n=e.toUpperCase(),r=n.match(/\bSUPPORT\s+FOR\s+/);if(r){const s=n.slice(r.index+r[0].length);for(const o of n0)if(new RegExp(`\\b${o}\\b`).test(s)){const c=e.slice(0,r.index).trim();return{material:o,brand:c,variant:"Support"}}}for(const s of n0){const o=new RegExp(`\\b${s}\\b`,"i");if(o.test(n)){const l=e.split(o),c=l[0]?.trim()||"",d=l[1]?.trim()||"";return{material:s,brand:c,variant:d}}}const a=e.split(/\s+/);return a.length>=2?{material:a[1],brand:a[0],variant:a.slice(2).join(" ")}:{material:e,brand:"",variant:""}}function aVe(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const sVe={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"},wW=[{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"}],SW=[{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 _W(t){const e=t.toLowerCase().trim();return sVe[e]||null}function oVe(t){const e=t.indexOf("@");if(e<0)return null;const r=t.slice(e+1).trim().match(/^BBL\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);return r?r[1].trim():null}function mie({isOpen:t,onClose:e,printerId:n,slotInfo:r,nozzleDiameter:a="0.4",printerModel:s,onSuccess:o,fullScreen:l}){const{t:c}=jt(),[d,u]=w.useState(""),[m,p]=w.useState(null),[f,y]=w.useState(""),[v,b]=w.useState(""),[g,_]=w.useState(""),[N,C]=w.useState(!1),[k,P]=w.useState(!1),T=w.useRef(""),{data:j,isLoading:A,isError:F}=Je({queryKey:["cloudSettings"],queryFn:()=>fe.getCloudSettings(),enabled:t,retry:!1}),{data:G,isLoading:z}=Je({queryKey:["localPresets"],queryFn:()=>fe.getLocalPresets(),enabled:t}),{data:J,isLoading:I}=Je({queryKey:["builtinFilaments"],queryFn:()=>fe.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:te,isLoading:se}=Je({queryKey:["kprofiles",n,a],queryFn:()=>fe.getKProfiles(n,a),enabled:t&&!!n}),{data:Z}=Je({queryKey:["colorCatalog"],queryFn:()=>fe.getColorCatalog(),enabled:t,staleTime:1/0}),de=ht({mutationFn:async()=>{if(!d)throw new Error("No filament preset selected");const M=d.startsWith("local_"),U=d.startsWith("builtin_"),K=M?parseInt(d.replace("local_",""),10):null,B=U?d.replace("builtin_",""):null,ie=M?G?.filament.find(Ae=>Ae.id===K):null,O=U?J?.find(Ae=>Ae.filament_id===B):null,q=!M&&!U?j?.filament.find(Ae=>Ae.setting_id===d):null;if(!M&&!U&&!q)throw new Error("Selected preset not found");if(M&&!ie)throw new Error("Selected local preset not found");if(U&&!O)throw new Error("Selected builtin preset not found");const Y=M?ie.name:U?O.name:q.name,V=vW(Y),ee=m?.slot_id??-1,oe=f||r.trayColor?.slice(0,6)||"FFFFFF",he=Y.replace(/@.+$/,"").trim();let pe,re;const L=V.material.toUpperCase();if(M){const Ae=(n0.includes(L)?L:ie?.filament_type||V.material||"").toUpperCase(),Le={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"};pe=Le[Ae]||Le[Ae.replace(/[-\s]?CF$/,"")]||Le[Ae.replace(/\+$/,"")]||Le[Ae.split(/[-\s]/)[0]]||"",re=""}else if(U)pe=B,re="";else if(pe=R1(d),re=d,!d.startsWith("GFS"))try{const Ae=await fe.getCloudSettingDetail(d);Ae.filament_id?pe=Ae.filament_id:Ae.base_id&&(pe=R1(Ae.base_id),console.log(`Derived tray_info_idx from base_id: ${Ae.base_id} -> ${pe}`))}catch(Ae){console.warn("Failed to fetch preset detail for filament_id:",Ae)}let R=M&&ie?.nozzle_temp_min?ie.nozzle_temp_min:190,ne=M&&ie?.nozzle_temp_max?ie.nozzle_temp_max:230;if(!M||U||!ie?.nozzle_temp_min&&!ie?.nozzle_temp_max){const Ae=(M?n0.includes(L)?L:ie?.filament_type||V.material||"":V.material).toUpperCase();Ae.includes("PLA")?(R=190,ne=230):Ae.includes("PETG")?(R=220,ne=260):Ae.includes("ABS")||Ae.includes("ASA")?(R=240,ne=280):Ae.includes("TPU")?(R=200,ne=240):Ae==="PCTG"?(R=220,ne=260):Ae.includes("PC")?(R=260,ne=300):(Ae.includes("PA")||Ae.includes("NYLON"))&&(R=250,ne=290)}const ye=m?.k_value?parseFloat(m.k_value):0,ve=M?n0.includes(L)?L:ie?.filament_type||V.material||"PLA":V.material||"PLA",be=await fe.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:pe,tray_type:ve,tray_sub_brands:he,tray_color:oe+"FF",nozzle_temp_min:R,nozzle_temp_max:ne,cali_idx:ee,nozzle_diameter:a,setting_id:re,kprofile_filament_id:m?.filament_id,kprofile_setting_id:m?.setting_id||void 0,k_value:ye}),Be=M?`local_${K}`:U?`builtin_${B}`:d,we=M?"local":U?"builtin":"cloud";try{await fe.saveSlotPreset(n,r.amsId,r.trayId,Be,he,we)}catch(Ae){console.warn("Failed to save slot preset mapping:",Ae)}return be},onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),ue=ht({mutationFn:async()=>fe.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),me=w.useMemo(()=>{const M=g.toLowerCase(),U=[],K=new Set,B=r.savedPresetId,ie=r.trayInfoIdx;if(j?.filament)for(const O of j.filament){K.add(O.setting_id);const Y=B===O.setting_id||ie&&(O.setting_id===ie||R1(O.setting_id)===ie);if(!(M&&!O.name.toLowerCase().includes(M))){if(!Y&&s){const V=oVe(O.name);if(V&&V.toUpperCase()!==s.toUpperCase())continue}U.push({id:O.setting_id,name:O.name,source:"cloud",isUser:aVe(O.setting_id)})}}if(G?.filament)for(const O of G.filament){const q=`local_${O.id}`;M&&!O.name.toLowerCase().includes(M)||U.push({id:q,name:O.name,source:"local",isUser:!1})}if(J)for(const O of J){if(K.has(O.filament_id))continue;const q=O.filament_id.startsWith("GF")?"GFS"+O.filament_id.slice(2):O.filament_id;K.has(q)||(!M||O.name.toLowerCase().includes(M))&&U.push({id:`builtin_${O.filament_id}`,name:O.name,source:"builtin",isUser:!1})}return U.sort((O,q)=>{const Y={cloud:0,local:1,builtin:2};return O.source!==q.source?Y[O.source]-Y[q.source]:O.isUser&&!q.isUser?-1:!O.isUser&&q.isUser?1:O.name.localeCompare(q.name)})},[j?.filament,G?.filament,J,g,s,r.savedPresetId,r.trayInfoIdx]),W=w.useMemo(()=>{if(!d)return null;let M=null;if(d.startsWith("local_")){const B=parseInt(d.replace("local_",""),10);M=G?.filament.find(O=>O.id===B)?.name||null}else if(d.startsWith("builtin_")){const B=d.replace("builtin_","");M=J?.find(O=>O.filament_id===B)?.name||null}else j?.filament&&(M=j.filament.find(ie=>ie.setting_id===d)?.name||null);if(!M)return null;let U=M.replace(/@.+$/,"").trim();U.startsWith("# ")&&(U=U.slice(2).trim());const K=vW(U);return{fullName:U,material:K.material,brand:K.brand}},[d,j?.filament,G?.filament,J]),ae=W?.fullName||"",ce=w.useMemo(()=>{if(!Z||!W)return[];const{fullName:M,brand:U}=W,K=M.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return Z.filter(B=>{const ie=(B.material||"").toUpperCase(),O=B.manufacturer.toUpperCase();if(!(ie===K.toUpperCase()||ie.includes(K.toUpperCase())||K.toUpperCase().includes(ie)))return!1;if(U){const Y=U.toUpperCase();if(!O.includes(Y)&&!Y.includes(O))return!1}return!0})},[Z,W]),ge=w.useMemo(()=>{if(!te?.profiles||!W)return[];const{fullName:M,material:U,brand:K}=W,B=M.toUpperCase(),ie=U.toUpperCase(),O=K.toUpperCase();if(!ie||ie.length<2)return[];const q=te.profiles.filter(V=>{const ee=V.name.toUpperCase();if(O)return!(!ee.includes(O)||!ee.includes(ie));if(ee.includes(B)||ee.includes(ie))return!0;const he={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[ie]||[];for(const pe of he)if(ee.includes(pe))return!0;return!1}),Y=new Map;for(const V of q){const ee=`${V.name}|${V.k_value}`,oe=Y.get(ee);oe?r.extruderId!==void 0&&V.extruder_id===r.extruderId&&oe.extruder_id!==r.extruderId&&Y.set(ee,V):Y.set(ee,V)}return Array.from(Y.values())},[te?.profiles,W,r.extruderId]);w.useEffect(()=>{if(t){if(r.savedPresetId)u(r.savedPresetId);else if(r.trayInfoIdx&&j?.filament){let M=j.filament.find(U=>U.setting_id===r.trayInfoIdx);M||(M=j.filament.find(U=>R1(U.setting_id)===r.trayInfoIdx)),M&&u(M.setting_id)}else if(r.trayInfoIdx&&J?.length){const M=r.trayInfoIdx,U=J.find(K=>K.filament_id===M);U&&u(`builtin_${U.filament_id}`)}if(r.trayColor){const M=r.trayColor.slice(0,6);M&&y(M)}}else u(""),p(null),y(""),b(""),_(""),C(!1),T.current=""},[t,r.savedPresetId,r.trayInfoIdx,r.trayColor,j?.filament,J]),w.useEffect(()=>{if(ge.length>0){if(r.caliIdx!=null&&r.caliIdx>0){const M=ge.find(U=>U.slot_id===r.caliIdx);if(M){p(M);return}}p(ge[0])}else p(null)},[d,ge,r.caliIdx]);const Ne=w.useCallback(M=>{M.key==="Escape"&&e()},[e]);w.useEffect(()=>{if(t)return document.addEventListener("keydown",Ne),()=>document.removeEventListener("keydown",Ne)},[t,Ne]);const H=A&&!F||z||I||se;if(w.useEffect(()=>{if(!H&&d&&d!==T.current){const M=requestAnimationFrame(()=>{const K=document.querySelector('[class*="fixed inset-0 z-50"]')?.querySelector(`[data-preset-id="${CSS.escape(d)}"]`);K&&(T.current=d,K.scrollIntoView({block:"nearest"}))});return()=>cancelAnimationFrame(M)}},[d,H]),!t)return null;const X=d&&!de.isPending,D=f||r.trayColor?.slice(0,6)||"FFFFFF";return i.jsxs("div",{className:`fixed inset-0 z-50 flex ${l?"":"items-center justify-center"}`,children:[!l&&i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),i.jsxs("div",{className:l?"relative w-full h-full bg-bambu-dark-secondary flex flex-col":"relative w-full max-w-lg mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(vd,{className:"w-5 h-5 text-bambu-blue"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.title")}),l&&i.jsxs("div",{className:"flex items-center gap-2 ml-4 text-sm text-bambu-gray",children:[i.jsx("span",{className:"text-white/30",children:"|"}),r.trayColor&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),i.jsx("span",{className:"text-white/70",children:c("configureAmsSlot.slotLabel",{ams:yW(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&i.jsxs("span",{children:["(",r.traySubBrands,")"]})]})]}),i.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(qt,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:`p-4 overflow-y-auto ${l?"flex-1 min-h-0":"space-y-4 max-h-[60vh]"}`,children:[N&&i.jsx("div",{className:"absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl",children:i.jsxs("div",{className:"text-center space-y-3",children:[i.jsx(Sc,{className:"w-16 h-16 text-bambu-green mx-auto"}),i.jsx("p",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.slotConfigured")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:c("configureAmsSlot.settingsSentToPrinter")})]})}),!l&&i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:c("configureAmsSlot.configuringSlot")}),i.jsxs("div",{className:"flex items-center gap-2",children:[r.trayColor&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),i.jsx("span",{className:"text-white font-medium",children:c("configureAmsSlot.slotLabel",{ams:yW(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&i.jsxs("span",{className:"text-bambu-gray",children:["(",r.traySubBrands,")"]})]})]}),H?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ft,{className:"w-6 h-6 text-bambu-green animate-spin"})}):l?i.jsxs("div",{className:"flex gap-4 h-full",children:[i.jsxs("div",{className:"w-1/2 flex flex-col min-h-0",children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:g,onChange:M=>_(M.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"}),i.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-1",children:me.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:j?.filament?.length===0&&!G?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):me.map(M=>i.jsx("button",{"data-preset-id":M.id,onClick:()=>u(M.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${d===M.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-white text-sm truncate",children:M.name}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[M.source==="local"&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),M.source==="builtin"&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),M.isUser&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},M.id))})]}),i.jsxs("div",{className:"w-1/2 flex flex-col gap-4 min-h-0 overflow-y-auto",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),ae&&i.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:ae})})]}),ge.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:M=>{const U=ge.find(K=>K.name===M.target.value);p(U||null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10",children:[i.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),ge.map(M=>i.jsxs("option",{value:M.name,children:[M.name," (K=",M.k_value,")"]},`${M.name}-${M.extruder_id}`))]}),i.jsx(zn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):d?i.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):i.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),m&&i.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:m.k_value})})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),ce.length>0&&i.jsxs("div",{className:"mb-3",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:W?.fullName})}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:ce.map(M=>i.jsxs("button",{onClick:()=>{const U=M.hex_color.replace("#","").toUpperCase();y(U),b(M.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===M.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:M.color_name,children:[i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:M.hex_color}}),i.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:M.color_name})]},M.id))})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[wW.map(M=>i.jsx("button",{onClick:()=>{y(M.hex),b(M.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===M.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${M.hex}`},title:M.name},M.hex)),i.jsx("button",{onClick:()=>P(!k),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(k?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:k?"−":"+"})]}),k&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:SW.map(M=>i.jsx("button",{onClick:()=>{y(M.hex),b(M.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===M.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${M.hex}`},title:M.name},M.hex))}),i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${D}`}}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:M=>{const U=M.target.value;b(U);const K=_W(U);if(K)y(K);else{const B=U.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();B.length===6?y(B):B.length===3&&y(B.split("").map(ie=>ie+ie).join(""))}},className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm"}),f&&i.jsx("button",{onClick:()=>{y(""),b("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:g,onChange:M=>_(M.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"}),i.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:me.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:j?.filament?.length===0&&!G?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):me.map(M=>i.jsx("button",{"data-preset-id":M.id,onClick:()=>u(M.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${d===M.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-white text-sm truncate",children:M.name}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[M.source==="local"&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),M.source==="builtin"&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),M.isUser&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},M.id))})]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),ae&&i.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:ae})})]}),ge.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:M=>{const U=ge.find(K=>K.name===M.target.value);p(U||null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10",children:[i.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),ge.map(M=>i.jsxs("option",{value:M.name,children:[M.name," (K=",M.k_value,")"]},`${M.name}-${M.extruder_id}`))]}),i.jsx(zn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):d?i.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):i.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),m&&i.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:m.k_value})})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),ce.length>0&&i.jsxs("div",{className:"mb-3",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:W?.fullName})}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:ce.map(M=>i.jsxs("button",{onClick:()=>{const U=M.hex_color.replace("#","").toUpperCase();y(U),b(M.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===M.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:M.color_name,children:[i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:M.hex_color}}),i.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:M.color_name})]},M.id))})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[wW.map(M=>i.jsx("button",{onClick:()=>{y(M.hex),b(M.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===M.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${M.hex}`},title:M.name},M.hex)),i.jsx("button",{onClick:()=>P(!k),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(k?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:k?"−":"+"})]}),k&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:SW.map(M=>i.jsx("button",{onClick:()=>{y(M.hex),b(M.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===M.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${M.hex}`},title:M.name},M.hex))}),i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${D}`}}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:M=>{const U=M.target.value;b(U);const K=_W(U);if(K)y(K);else{const B=U.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();B.length===6?y(B):B.length===3&&y(B.split("").map(ie=>ie+ie).join(""))}},className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm"}),f&&i.jsx("button",{onClick:()=>{y(""),b("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}),i.jsxs("div",{className:"flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[i.jsx(Ie,{variant:"secondary",onClick:()=>ue.mutate(),disabled:ue.isPending||de.isPending,className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:ue.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.resetting")]}):i.jsxs(i.Fragment,{children:[i.jsx(Ao,{className:"w-4 h-4"}),c("configureAmsSlot.resetSlot")]})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:e,children:c("configureAmsSlot.cancel")}),i.jsx(Ie,{onClick:()=>de.mutate(),disabled:!X,children:de.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.configuring")]}):i.jsxs(i.Fragment,{children:[i.jsx(vd,{className:"w-4 h-4"}),c("configureAmsSlot.configureSlot")]})})]})]}),(de.isError||ue.isError)&&i.jsx("div",{className:"mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:de.error?.message||ue.error?.message})]})]})}function hie({folderId:t,onClose:e,onUploadComplete:n,onFileUploaded:r,autoUpload:a,validateFile:s,accept:o}){const{t:l}=jt(),[c,d]=w.useState([]),[u,m]=w.useState(!1),[p,f]=w.useState(!1),[y,v]=w.useState(!0),[b,g]=w.useState(!1),[_,N]=w.useState(!0),[C,k]=w.useState(null),P=w.useRef(null),T=me=>{me.preventDefault(),m(!0)},j=me=>{me.preventDefault(),m(!1)},A=me=>{me.preventDefault(),m(!1),J(Array.from(me.dataTransfer.files))},F=me=>{me.target.files&&J(Array.from(me.target.files))},G=(me,W)=>{d(ae=>ae.map(ce=>ce.file===me?{...ce,...W}:ce))},z=async me=>{f(!0);for(const W of me)if(W.status==="pending"){G(W.file,{status:"uploading"});try{if(W.isZip){const ae=await fe.extractZipFile(W.file,t,y,b,_);G(W.file,{status:ae.errors.length>0&&ae.extracted===0?"error":"success",extractedCount:ae.extracted,error:ae.errors.length>0?l("fileManager.zipFilesFailed","{{count}} files failed",{count:ae.errors.length}):void 0})}else{const ae=await fe.uploadLibraryFile(W.file,t,_);G(W.file,{status:"success"});const ce=r?.(ae);if(ce){k(ce),d([]),f(!1);return}}}catch(ae){G(W.file,{status:"error",error:ae instanceof Error?ae.message:l("fileManager.uploadFailed","Upload failed")})}}f(!1),n(),e()},J=me=>{if(k(null),s)for(const ae of me){const ce=s(ae);if(ce){k(ce);return}}const W=me.map(ae=>({file:ae,status:"pending",isZip:ae.name.toLowerCase().endsWith(".zip"),is3mf:ae.name.toLowerCase().endsWith(".3mf")}));d(ae=>[...ae,...W]),a&&me.length>0&&z(W)},I=me=>{d(W=>W.filter((ae,ce)=>ce!==me))},te=c.some(me=>me.isZip&&me.status==="pending"),se=c.some(me=>me.file.name.toLowerCase().endsWith(".stl")&&me.status==="pending"),Z=c.some(me=>me.is3mf&&me.status==="pending"),de=c.filter(me=>me.status==="pending").length,ue=c.length>0&&de===0&&!p;return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:l("fileManager.uploadFiles")}),i.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:i.jsx(qt,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsxs("div",{onDragOver:T,onDragLeave:j,onDrop:A,onClick:()=>P.current?.click(),className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${u?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,children:[i.jsx(wi,{className:`w-10 h-10 mx-auto mb-3 ${u?"text-bambu-green":"text-bambu-gray"}`}),i.jsx("p",{className:"text-white font-medium",children:l(u?"fileManager.dropFilesHere":"fileManager.dragDropFiles")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:l("fileManager.orClickToBrowse")}),i.jsx("p",{className:"text-xs text-bambu-gray/70 mt-2",children:l("fileManager.allFileTypesSupported")})]}),i.jsx("input",{ref:P,type:"file",multiple:!0,accept:o,className:"hidden",onChange:F}),te&&i.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Vs,{className:"w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-blue-300 font-medium",children:l("fileManager.zipFilesDetected")}),i.jsx("p",{className:"text-xs text-blue-300/70 mt-1",children:l("fileManager.zipExtractOptions")}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:y,onChange:me=>v(me.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.preserveZipStructure")})]}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:b,onChange:me=>g(me.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.createFolderFromZip")})]})]})]})}),Z&&i.jsx("div",{className:"p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Nr,{className:"w-5 h-5 text-purple-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-purple-300 font-medium",children:l("fileManager.threemfDetected")}),i.jsx("p",{className:"text-xs text-purple-300/70 mt-1",children:l("fileManager.threemfExtractionInfo")})]})]})}),(se||te)&&i.jsx("div",{className:"p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Vu,{className:"w-5 h-5 text-bambu-green mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-bambu-green font-medium",children:l("fileManager.stlThumbnailGeneration")}),i.jsx("p",{className:"text-xs text-bambu-green/70 mt-1",children:l(te&&!se?"fileManager.zipMayContainStl":"fileManager.thumbnailsCanBeGenerated")}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:_,onChange:me=>N(me.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.generateThumbnailsForStl")})]})]})]})}),c.length>0&&i.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:c.map((me,W)=>i.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[me.isZip?i.jsx(Vs,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):i.jsx(cT,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-sm text-white truncate",children:me.file.name}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[(me.file.size/1024/1024).toFixed(2)," MB",me.isZip&&me.status==="pending"&&i.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",l("fileManager.willBeExtracted")]}),me.extractedCount!==void 0&&i.jsxs("span",{className:"text-green-400 ml-2",children:["• ",l("fileManager.filesExtracted",{count:me.extractedCount})]})]})]}),me.status==="pending"&&i.jsx("button",{onClick:()=>I(W),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(qt,{className:"w-4 h-4 text-bambu-gray"})}),me.status==="uploading"&&i.jsx(ft,{className:"w-4 h-4 text-bambu-green animate-spin"}),me.status==="success"&&i.jsx(pr,{className:"w-4 h-4 text-green-500"}),me.status==="error"&&i.jsx("span",{title:me.error,children:i.jsx(Wi,{className:"w-4 h-4 text-red-500"})})]},W))}),C&&i.jsx("div",{className:"p-3 bg-red-500/10 border border-red-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Wi,{className:"w-5 h-5 text-red-400 mt-0.5 flex-shrink-0"}),i.jsx("p",{className:"text-sm text-red-300",children:C})]})})]}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:e,children:l("common.cancel")}),!ue&&i.jsx(Ie,{onClick:()=>z(c),disabled:de===0||p,children:p?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-4 h-4 mr-2 animate-spin"}),l("fileManager.uploading")]}):i.jsxs(i.Fragment,{children:[i.jsx(wi,{className:"w-4 h-4 mr-2"}),l("common.upload")," ",de>0?`(${de})`:""]})})]})]})})}function NW(t){return t?`#${t.replace("#","").substring(0,6)}`:"#808080"}function Li(t){return t?t.replace("#","").toLowerCase().substring(0,6):""}const lVe=[["PA-CF","PA12-CF","PAHT-CF"]],pie={};for(const t of lVe){const e=t[0];for(const n of t)pie[n.toUpperCase()]=e.toUpperCase()}function oC(t){if(!t)return"";const e=t.toUpperCase();return pie[e]??e}function iD(t,e){return oC(t)===oC(e)}function xd(t,e,n=40){const r=Li(t),a=Li(e);if(!r||!a||r.length<6||a.length<6)return!1;const s=parseInt(r.substring(0,2),16),o=parseInt(r.substring(2,4),16),l=parseInt(r.substring(4,6),16),c=parseInt(a.substring(0,2),16),d=parseInt(a.substring(2,4),16),u=parseInt(a.substring(4,6),16);return Math.abs(s-c)<=n&&Math.abs(o-d)<=n&&Math.abs(l-u)<=n}function Zw(t,e,n,r){if(r)return"Ext";const a=String.fromCharCode(65+(t>=128?t-128:t));return n?`HT-${a}`:`${a}${e+1}`}function Fx(t,e,n){return n?254+e:t>=128?t:t*4+e}function ox(t){return t>50?"#00ae42":t>=15?"#f59e0b":"#ef4444"}function SN(t){return!t?.remaining_weight||!t?.filament_weight||t.filament_weight<=0?null:Math.min(100,Math.round(t.remaining_weight/t.filament_weight*100))}function kW(t,e){return(Number.isFinite(t)?Math.max(0,Math.trunc(t)):0).toString(16).toUpperCase().padStart(e,"0").slice(-e)}function cVe(t){const e=(t||"").trim().toUpperCase();let n=2166136261;for(let r=0;r>>0).toString(16).toUpperCase().padStart(8,"0")}function Su(t,e,n){return`${cVe(t)}${kW(e,4)}${kW(n,4)}`}function CW(t){if(!t)return!1;const e=Date.now()+4320*60*60*1e3;return(Qn(t)?.getTime()??0)>e}function dVe(t,e,n){const r=fie(e,t.nozzle_id),a=r.find(l=>!n.has(l.globalTrayId)&&iD(l.type,t.type)&&Li(l.color)===Li(t.color)),s=a?void 0:r.find(l=>!n.has(l.globalTrayId)&&iD(l.type,t.type)&&xd(l.color,t.color)),o=a||s?void 0:r.find(l=>!n.has(l.globalTrayId)&&iD(l.type,t.type));return a??s??o}function fie(t,e){return t.filter(n=>e==null||n.extruderId===e)}function Jw(t){const e=[],n=t?.ams_extruder_map,r=n&&Object.keys(n).length>0;t?.ams?.forEach(a=>{const s=a.tray.length===1;a.tray.forEach(o=>{if(o.tray_type){const l=NW(o.tray_color);e.push({type:o.tray_type,color:l,colorName:Bu(l),amsId:a.id,trayId:o.id,isHt:s,isExternal:!1,label:Zw(a.id,o.id,s,!1),globalTrayId:Fx(a.id,o.id,!1),trayInfoIdx:o.tray_info_idx||"",traySubBrands:o.tray_sub_brands||"",extruderId:n?.[String(a.id)]})}})});for(const a of t?.vt_tray??[])if(a.tray_type){const s=NW(a.tray_color),o=a.id??254,l=(t?.vt_tray?.length??0)>1;e.push({type:a.tray_type,color:s,colorName:Bu(s),amsId:-1,trayId:o-254,isHt:!1,isExternal:!0,label:l?o===254?"Ext-L":"Ext-R":"External",globalTrayId:o,trayInfoIdx:a.tray_info_idx||"",traySubBrands:a.tray_sub_brands||"",extruderId:r?255-o:void 0})}return e}function TW(t,e){if(!t?.filaments||t.filaments.length===0)return;const n=Jw(e);if(n.length===0)return;const r=new Set,a=t.filaments.map(l=>{const c=l.tray_info_idx||"";let d=n.filter(v=>!r.has(v.globalTrayId));l.nozzle_id!=null&&(d=d.filter(v=>v.extruderId===l.nozzle_id));let u,m,p,f;if(c){const v=d.filter(b=>b.trayInfoIdx===c);v.length===1?u=v[0]:v.length>1&&(m=v.find(b=>b.type?.toUpperCase()===l.type?.toUpperCase()&&Li(b.color)===Li(l.color)),m||(p=v.find(b=>b.type?.toUpperCase()===l.type?.toUpperCase()&&xd(b.color,l.color))),!m&&!p&&(f=v.find(b=>b.type?.toUpperCase()===l.type?.toUpperCase())))}!u&&!m&&!p&&!f&&(m=d.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&Li(v.color)===Li(l.color)),m||(p=d.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&xd(v.color,l.color))),!m&&!p&&(f=d.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase())));const y=u||m||p||f||void 0;return y&&r.add(y.globalTrayId),{slot_id:l.slot_id,globalTrayId:y?.globalTrayId??-1}}),s=Math.max(...a.map(l=>l.slot_id||0));if(s<=0)return;const o=new Array(s).fill(-1);return a.forEach(l=>{l.slot_id&&l.slot_id>0&&(o[l.slot_id-1]=l.globalTrayId)}),o}function uVe(t){return w.useMemo(()=>Jw(t),[t])}function gie(t,e,n){const r=uVe(e),a=w.useMemo(()=>{if(!t?.filaments||t.filaments.length===0)return[];const c=new Set(Object.values(n));return t.filaments.map(d=>{const u=d.slot_id||0;if(u>0&&n[u]!==void 0){const P=n[u],T=r.find(j=>j.globalTrayId===P);if(T){const j=T.type?.toUpperCase()===d.type?.toUpperCase(),A=Li(T.color)===Li(d.color)||xd(T.color,d.color);let F;return j&&A?F="match":j?F="type_only":F="mismatch",{...d,loaded:T,hasFilament:!0,typeMatch:j,colorMatch:A,status:F,isManual:!0}}}const m=d.tray_info_idx||"";let p=r.filter(P=>!c.has(P.globalTrayId));d.nozzle_id!=null&&(p=p.filter(P=>P.extruderId===d.nozzle_id));let f,y,v,b;if(m){const P=p.filter(T=>T.trayInfoIdx===m);P.length===1?f=P[0]:P.length>1&&(y=P.find(T=>T.type?.toUpperCase()===d.type?.toUpperCase()&&Li(T.color)===Li(d.color)),y||(v=P.find(T=>T.type?.toUpperCase()===d.type?.toUpperCase()&&xd(T.color,d.color))),!y&&!v&&(b=P.find(T=>T.type?.toUpperCase()===d.type?.toUpperCase())))}!f&&!y&&!v&&!b&&(y=p.find(P=>P.type?.toUpperCase()===d.type?.toUpperCase()&&Li(P.color)===Li(d.color)),y||(v=p.find(P=>P.type?.toUpperCase()===d.type?.toUpperCase()&&xd(P.color,d.color))),!y&&!v&&(b=p.find(P=>P.type?.toUpperCase()===d.type?.toUpperCase())));const g=f||y||v||b||void 0;g&&c.add(g.globalTrayId);const _=!!g,N=_,C=!!f||!!y||!!v;let k;return f||y||v?k="match":b?k="type_only":k="mismatch",{...d,loaded:g,hasFilament:_,typeMatch:N,colorMatch:C,status:k,isManual:!1}})},[t,r,n]),s=w.useMemo(()=>{if(a.length===0)return;const c=Math.max(...a.map(u=>u.slot_id||0));if(c<=0)return;const d=new Array(c).fill(-1);return a.forEach(u=>{u.slot_id&&u.slot_id>0&&(d[u.slot_id-1]=u.loaded?.globalTrayId??-1)}),d},[a]),o=a.some(c=>c.status==="mismatch"),l=a.some(c=>c.status==="type_only");return{loadedFilaments:r,filamentComparison:a,amsMapping:s,hasTypeMismatch:o,hasColorMismatch:l}}function mVe(t,e,n){if(!t||t.length===0)return{exactMatches:0,typeOnlyMatches:0,missingTypes:0,totalSlots:0,status:"full"};let r=0,a=0,s=0;const o=new Set(Object.values(n));for(const d of t){const u=d.slot_id||0;if(u>0&&n[u]!==void 0){const b=n[u],g=e.find(_=>_.globalTrayId===b);if(g){const _=g.type?.toUpperCase()===d.type?.toUpperCase(),N=Li(g.color)===Li(d.color)||xd(g.color,d.color);_&&N?r++:_?a++:s++;continue}}let m=e.filter(b=>!o.has(b.globalTrayId));if(d.nozzle_id!=null){const b=m.filter(g=>g.extruderId===d.nozzle_id);b.length>0&&(m=b)}const p=m.find(b=>b.type?.toUpperCase()===d.type?.toUpperCase()&&Li(b.color)===Li(d.color)),f=p?void 0:m.find(b=>b.type?.toUpperCase()===d.type?.toUpperCase()&&xd(b.color,d.color)),y=p||f?void 0:m.find(b=>b.type?.toUpperCase()===d.type?.toUpperCase()),v=p??f??y;v&&o.add(v.globalTrayId),p||f?r++:y?a++:s++}const l=t.length;let c="full";return s>0?c="missing":a>0&&(c="partial"),{exactMatches:r,typeOnlyMatches:a,missingTypes:s,totalSlots:l,status:c}}function hVe(t,e,n){if(!t?.filaments||t.filaments.length===0)return;const r=Jw(e);if(r.length===0)return;const a=new Set(Object.values(n)),s=[];for(const c of t.filaments){const d=c.slot_id||0;if(d>0&&n[d]!==void 0){s.push({slot_id:d,globalTrayId:n[d]});continue}let u=r.filter(v=>!a.has(v.globalTrayId));if(c.nozzle_id!=null){const v=u.filter(b=>b.extruderId===c.nozzle_id);v.length>0&&(u=v)}const m=u.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&Li(v.color)===Li(c.color)),p=m?void 0:u.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&xd(v.color,c.color)),f=m||p?void 0:u.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()),y=m??p??f;y&&a.add(y.globalTrayId),s.push({slot_id:d,globalTrayId:y?.globalTrayId??-1})}const o=Math.max(...s.map(c=>c.slot_id||0));if(o<=0)return;const l=new Array(o).fill(-1);return s.forEach(c=>{c.slot_id&&c.slot_id>0&&(l[c.slot_id-1]=c.globalTrayId)}),l}const AW={useDefault:!0,manualMappings:{},autoConfigured:!1};function pVe(t,e,n,r,a,s){const o=ep({queries:t.map(y=>({queryKey:["printer-status",y],queryFn:()=>fe.getPrinterStatus(y),enabled:t.length>0,staleTime:5e3}))}),l=w.useMemo(()=>t.map((y,v)=>{const b=o[v],g=b?.data,N=e?.find(F=>F.id===y)?.name||`Printer ${y}`,C=Jw(g),k=a[y]||AW,P=TW(n,g),T=k.useDefault?r:k.manualMappings,j=hVe(n,g,T),A=mVe(n?.filaments,C,T);return{printerId:y,printerName:N,status:g,isLoading:b?.isLoading??!1,loadedFilaments:C,autoMapping:P,finalMapping:j,matchStatus:A.status,exactMatches:A.exactMatches,typeOnlyMatches:A.typeOnlyMatches,missingTypes:A.missingTypes,totalSlots:A.totalSlots,config:k}}),[t,o,e,n,a,r]),c=o.some(y=>y.isLoading),d=(y,v)=>{s(b=>({...b,[y]:{...b[y]||AW,...v}}))},u=y=>{const v=l.find(_=>_.printerId===y);if(!v||!v.status||!n?.filaments)return;const b=TW(n,v.status);if(!b)return;const g={};b.forEach((_,N)=>{_!==-1&&(g[N+1]=_)}),d(y,{useDefault:!1,manualMappings:g,autoConfigured:!0})},m=()=>{for(const y of t)u(y)},p=y=>l.find(b=>b.printerId===y)?.finalMapping,f=l.every(y=>y.matchStatus!=="missing");return{printerResults:l,isLoading:c,perPrinterConfigs:a,updatePrinterConfig:d,autoConfigureAll:m,autoConfigurePrinter:u,getFinalMapping:p,allPrintersReady:f}}const bie={USD:"$",EUR:"€",GBP:"£",CHF:"Fr.",JPY:"¥",CNY:"¥",CAD:"$",AUD:"$",INR:"₹",HKD:"HK$",KRW:"₩",SEK:"kr",NOK:"kr",DKK:"kr",PLN:"zł",BRL:"R$",TWD:"NT$",SGD:"S$",NZD:"NZ$",MXN:"MX$",MYR:"RM",CZK:"Kč",THB:"฿",ZAR:"R",TRY:"₺",RUB:"₽",HUF:"Ft",ILS:"₪",UAH:"₴"};function go(t){return bie[t.toUpperCase()]||t}const fVe=Object.entries(bie).map(([t,e])=>({code:t,label:`${t} (${e})`}));function gVe({printerId:t,filamentReqs:e,manualMappings:n,onManualMappingChange:r,currencySymbol:a,defaultCostPerKg:s,defaultExpanded:o=!1}){const{t:l}=jt(),c=cn(),[d,u]=w.useState(!1),[m,p]=w.useState(o),{data:f}=Je({queryKey:["printer-status",t],queryFn:()=>fe.getPrinterStatus(t),enabled:!!t}),{data:y}=Je({queryKey:["spool-assignments",t],queryFn:()=>fe.getAssignments(t),enabled:!!t}),{loadedFilaments:v,filamentComparison:b,hasTypeMismatch:g,hasColorMismatch:_}=gie(e,f,n),N=w.useMemo(()=>{const z=new Map;for(const J of y||[]){const I=J.ams_id===255,te=Fx(J.ams_id,J.tray_id,I);z.set(te,J.spool?.cost_per_kg??null)}return z},[y]),C=w.useMemo(()=>{const z=new Map;for(const J of y||[]){const I=J.ams_id===255,te=Fx(J.ams_id,J.tray_id,I),se=J.spool;if(!se){z.set(te,null);continue}z.set(te,Math.max(0,Math.round((se.label_weight??0)-(se.weight_used??0))))}return z},[y]),k=w.useMemo(()=>{let z=0;for(const J of b){const I=J.loaded?.globalTrayId;if(I==null)continue;const se=N.get(I)??null??s;se>0&&(z+=J.used_grams/1e3*se)}return z},[b,N,s]),P=w.useMemo(()=>Array.from(N.values()).some(z=>z!=null&&z>0),[N]),T=e?.filaments&&e.filaments.length>0,j=e?.filaments?.some(z=>z.nozzle_id!=null)??!1;if(!T||!f)return null;const A=g?"#f97316":_?"#facc15":"#00ae42",F=(z,J)=>{if(z>0)if(J===""){const I={...n};delete I[z],r(I)}else r({...n,[z]:parseInt(J,10)})},G=async()=>{u(!0);try{await fe.refreshPrinterStatus(t),await new Promise(z=>setTimeout(z,500)),await c.refetchQueries({queryKey:["printer-status",t]})}finally{u(!1)}};return i.jsxs("div",{className:"mb-4",children:[i.jsxs("button",{type:"button",onClick:()=>p(!m),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[i.jsx(N0,{className:"w-4 h-4",fill:A,stroke:"none"}),i.jsx("span",{children:l("printModal.filamentMapping")}),g?i.jsx("span",{className:"text-xs text-orange-400",children:"(Type not found)"}):_?i.jsx("span",{className:"text-xs text-yellow-400",children:"(Color mismatch)"}):i.jsx("span",{className:"text-xs text-bambu-green",children:"(Ready)"}),m?i.jsx(Gl,{className:"w-4 h-4 ml-auto"}):i.jsx(zn,{className:"w-4 h-4 ml-auto"})]}),m&&i.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:"Click to change slot assignment"}),i.jsxs("button",{type:"button",onClick:G,className:"flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",disabled:d,children:[i.jsx(vr,{className:`w-3 h-3 ${d?"animate-spin":""}`}),i.jsx("span",{children:"Re-read"})]})]}),b.map((z,J)=>i.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[i.jsx("span",{title:`Required: ${z.type} - ${Bu(z.color)}`,children:i.jsx(N0,{className:"w-3 h-3",fill:z.color,stroke:z.color})}),i.jsxs("span",{className:"text-white truncate flex items-center gap-1",children:[j&&z.nozzle_id!=null&&i.jsx("span",{className:"inline-flex items-center justify-center w-3.5 h-3.5 rounded text-[9px] font-bold leading-none bg-bambu-gray/20 text-bambu-gray shrink-0",title:z.nozzle_id===1?l("printModal.leftNozzleTooltip"):l("printModal.rightNozzleTooltip"),children:z.nozzle_id===1?l("printModal.leftNozzle"):l("printModal.rightNozzle")}),z.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",z.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:z.loaded?.globalTrayId??"",onChange:I=>F(z.slot_id||0,I.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${z.status==="match"?"border-bambu-green/50 text-bambu-green":z.status==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${z.isManual?"ring-1 ring-blue-400/50":""}`,title:z.isManual?"Manually selected":"Auto-matched",children:[i.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),v.filter(I=>z.nozzle_id==null||I.extruderId===z.nozzle_id).map(I=>{const te=C.get(I.globalTrayId),se=te!=null?l("printModal.slotRemainingShort",{grams:te,defaultValue:` - ${te}g left`}):"";return i.jsxs("option",{value:I.globalTrayId,className:"bg-bambu-dark text-white",children:[I.label,": ",I.traySubBrands||I.type," (",I.colorName,")",se]},I.globalTrayId)})]}),z.status==="match"?i.jsx(Zr,{className:"w-3 h-3 text-bambu-green"}):z.status==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(jn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(jn,{className:"w-3 h-3 text-orange-400"})})]},J)),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[l("printModal.totalCost")," ",i.jsx("span",{className:"text-white",children:k>0||P?`${a}${k.toFixed(2)}`:"N/A"})]}),g&&i.jsx("p",{className:"text-xs text-orange-400 mt-2",children:"Required filament type not found in printer."})]})]})}function bVe({filamentReqs:t,availableFilaments:e,overrides:n,onChange:r,forceColorMatch:a,onForceColorMatchChange:s}){const{t:o}=jt(),l=w.useMemo(()=>{const u={};for(const m of e){const p=oC(m.type);u[p]||(u[p]=[]),u[p].push(m)}return u},[e]),c=t?.filaments;if(!c||c.length===0||e.length===0)return null;const d=(u,m)=>{if(m===""){const p={...n};delete p[u],r(p)}else{const[p,f]=m.split("|");r({...n,[u]:{type:p,color:f}})}};return i.jsxs("div",{className:"mb-4",children:[i.jsx("div",{className:"flex items-center gap-2 text-sm text-bambu-gray mb-2",children:i.jsx("span",{children:o("printModal.filamentOverride")})}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:o("printModal.filamentOverrideHint")}),i.jsx("div",{className:"bg-bambu-dark rounded-lg p-3 space-y-2",children:c.map(u=>{const m=n[u.slot_id],p=!!m,f=l[oC(u.type)]||[],y=u.nozzle_id!=null?f.filter(v=>v.extruder_id==null||v.extruder_id===u.nozzle_id):f;return i.jsxs("div",{className:"space-y-1",children:[i.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 20px"},children:[i.jsx("span",{title:`${o("printModal.originalFilament")}: ${u.type} - ${Bu(u.color)}`,children:i.jsx(N0,{className:"w-3 h-3",fill:u.color,stroke:u.color})}),i.jsxs("span",{className:"text-white truncate",children:[u.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",u.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:p?`${m.type}|${m.color}`:"",onChange:v=>d(u.slot_id,v.target.value),disabled:y.length===0,className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${p?"border-blue-400/50 text-blue-400":"border-bambu-gray/30 text-bambu-gray"}`,children:[i.jsxs("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:[o("printModal.originalFilament"),": ",u.type," (",Bu(u.color),")"]}),y.map((v,b)=>i.jsxs("option",{value:`${v.type}|${v.color}`,className:"bg-bambu-dark text-white",children:[v.tray_sub_brands||v.type," (",Bu(v.color),")"]},`${v.type}-${v.color}-${v.tray_sub_brands}-${b}`))]}),p?i.jsx("button",{type:"button",onClick:()=>d(u.slot_id,""),className:"text-bambu-gray hover:text-white transition-colors",title:o("printModal.resetToOriginal"),children:i.jsx(Ao,{className:"w-3 h-3"})}):i.jsx("span",{className:"w-3"})]}),i.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer select-none pl-5",children:[i.jsx("input",{type:"checkbox",checked:a?.[u.slot_id]??!1,onChange:v=>s?.(u.slot_id,v.target.checked),className:"accent-bambu-green w-3 h-3"}),i.jsx(_w,{className:"w-3 h-3"}),o("printModal.forceColorMatch")]})]},u.slot_id)})})]})}function xVe({plates:t,isMultiPlate:e,selectedPlates:n,onToggle:r,onSelectAll:a,onDeselectAll:s,multiSelect:o}){const{t:l}=jt();if(!e||t.length<=1)return null;const c=n.size===t.length;return i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx(Ki,{className:"w-4 h-4 text-bambu-gray"}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:["Select Plate",o?"s":""," to Print"]}),n.size===0&&i.jsxs("span",{className:"text-xs text-orange-400 flex items-center gap-1",children:[i.jsx(jn,{className:"w-3 h-3"}),"Selection required"]}),o&&a&&s&&i.jsx("button",{type:"button",onClick:c?s:a,className:`ml-auto text-xs px-2 py-0.5 rounded-full border transition-colors ${c?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray"}`,children:c?l("queue.deselectAll"):l("queue.selectAllPlates",{count:t.length})})]}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map(d=>{const u=n.has(d.index);return i.jsxs("button",{type:"button",onClick:()=>r(d.index),className:`flex items-center gap-2 p-2 rounded-lg border transition-colors text-left ${u?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"}`,children:[o&&(u?i.jsx(Ys,{className:"w-4 h-4 text-bambu-green flex-shrink-0"}):i.jsx(il,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"})),d.has_thumbnail&&d.thumbnail_url!=null?i.jsx("img",{src:d.thumbnail_url,alt:`Plate ${d.index}`,className:"w-10 h-10 rounded object-cover bg-bambu-dark-tertiary"}):i.jsx("div",{className:"w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center",children:i.jsx(Ki,{className:"w-5 h-5 text-bambu-gray"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-sm text-white font-medium truncate",children:d.name||`Plate ${d.index}`}),i.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[d.objects.length>0?d.objects.slice(0,3).join(", ")+(d.objects.length>3?"...":""):`${d.filaments.length} filament${d.filaments.length!==1?"s":""}`,d.print_time_seconds!=null?` • ${Bs(d.print_time_seconds)}`:""]})]}),!o&&u&&i.jsx(Zr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]},d.index)})})]})}const yVe=new Set(["IDLE","FINISH","FAILED"]);function vVe({printerResult:t,filamentReqs:e,onUpdateConfig:n}){const r=cn(),[a,s]=w.useState(!1),o=(d,u)=>{if(d<=0)return;const m={...t.config.manualMappings};u===""?delete m[d]:m[d]=parseInt(u,10),n({useDefault:!1,manualMappings:m,autoConfigured:!1})},l=async()=>{s(!0);try{await fe.refreshPrinterStatus(t.printerId),await new Promise(d=>setTimeout(d,500)),await r.refetchQueries({queryKey:["printer-status",t.printerId]})}finally{s(!1)}},c=e.map(d=>{const u=d.slot_id||0,m=t.config.manualMappings[u];let p,f=!1;if(m!==void 0)p=t.loadedFilaments.find(v=>v.globalTrayId===m),f=!0;else{const v=new Set(Object.values(t.config.manualMappings));p=dVe(d,t.loadedFilaments,v)}let y="mismatch";if(p){const v=p.type?.toUpperCase()===d.type?.toUpperCase(),b=Li(p.color)===Li(d.color)||xd(p.color,d.color);v&&b?y="match":v&&(y="type_only")}return{req:d,loaded:p,status:y,isManual:f}});return i.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom slot mapping"}),i.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",disabled:a,children:[i.jsx(vr,{className:`w-3 h-3 ${a?"animate-spin":""}`}),i.jsx("span",{children:"Re-read"})]})]}),c.map(({req:d,loaded:u,status:m,isManual:p},f)=>i.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[i.jsx("span",{title:`Required: ${d.type} - ${Bu(d.color)}`,children:i.jsx(N0,{className:"w-3 h-3",fill:d.color,stroke:d.color})}),i.jsxs("span",{className:"text-white truncate",children:[d.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",d.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:u?.globalTrayId??"",onChange:y=>o(d.slot_id||0,y.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${m==="match"?"border-bambu-green/50 text-bambu-green":m==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${p?"ring-1 ring-blue-400/50":""}`,title:p?"Manually selected":"Auto-matched",children:[i.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),fie(t.loadedFilaments,d.nozzle_id).map(y=>i.jsxs("option",{value:y.globalTrayId,className:"bg-bambu-dark text-white",children:[y.label,": ",y.traySubBrands||y.type," (",y.colorName,")"]},y.globalTrayId))]}),m==="match"?i.jsx(Zr,{className:"w-3 h-3 text-bambu-green"}):m==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(jn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(jn,{className:"w-3 h-3 text-orange-400"})})]},f))]})}function wVe({printers:t,selectedPrinterIds:e,onMultiSelect:n,isLoading:r=!1,allowMultiple:a=!1,showInactive:s=!1,disableBusy:o=!1,printerMappingResults:l,filamentReqs:c,onAutoConfigurePrinter:d,onUpdatePrinterConfig:u,assignmentMode:m="printer",onAssignmentModeChange:p,targetModel:f,onTargetModelChange:y,targetLocation:v,onTargetLocationChange:b,slicedForModel:g}){const[_,N]=w.useState(!1),C=s?t:t.filter(ae=>ae.is_active),k=ep({queries:C.map(ae=>({queryKey:["printerStatus",ae.id],queryFn:()=>fe.getPrinterStatus(ae.id),staleTime:5e3}))}),P=w.useMemo(()=>{const ae=new Map;return C.forEach((ce,ge)=>{const Ne=k[ge];Ne?.data&&ae.set(ce.id,Ne.data)}),ae},[C,k]),T=ae=>{const ce=P.get(ae);return ce?ce.connected?!yVe.has(ce.state??""):!0:!1},j=ae=>{const ce=P.get(ae);if(!ce)return null;if(!ce.connected)return"Offline";const ge=ce.state;return ge?ge==="RUNNING"?ce.stg_cur_name||"Printing":ge==="PREPARE"?"Preparing":ge==="PAUSE"?"Paused":ge==="IDLE"?"Idle":ge==="FINISH"?"Finished":ge==="FAILED"?"Failed":ge:null},A=w.useMemo(()=>{if(m!=="printer"||!g||_)return C;const ae=C.filter(ce=>ce.model===g);return ae.length>0?ae:C},[C,m,g,_]),F=C.length-A.length,G=w.useMemo(()=>{const ae=C.map(ce=>ce.model).filter(ce=>!!ce);return[...new Set(ae)].sort()},[C]),z=w.useMemo(()=>{if(!f)return[];const ae=C.filter(ce=>ce.model===f&&ce.location).map(ce=>ce.location).filter(ce=>!!ce);return[...new Set(ae)].sort()},[C,f]),J=p&&y&&G.length>0,I=a&&e.length>1&&l&&c?.filaments&&c.filaments.length>0&&d&&u;if(r)return i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ft,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(A.length===0)return i.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm mb-4",children:[i.jsx(Ii,{className:"w-4 h-4"}),"No ",s?"":"active ","printers available"]});const te=ae=>{o&&T(ae)||(a?e.includes(ae)?n(e.filter(ce=>ce!==ae)):n([...e,ae]):n([ae]))},se=()=>{const ae=o?A.filter(ce=>!T(ce.id)):A;n(ae.map(ce=>ce.id))},Z=()=>{n([])},de=(ae,ce,ge)=>{ge.stopPropagation(),!(!d||!u)&&(ce?d(ae):u(ae,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},ue=ae=>e.includes(ae),me=e.length,W=ae=>l?.find(ce=>ce.printerId===ae);return i.jsxs("div",{className:"space-y-2 mb-6",children:[J&&i.jsxs("div",{className:"flex gap-2 mb-4",children:[i.jsxs("button",{type:"button",onClick:()=>{p("printer"),y(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${m==="printer"?"border-bambu-green bg-bambu-green/10 text-white":"border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray"}`,children:[i.jsx(Nr,{className:"w-4 h-4"}),i.jsx("span",{className:"text-sm",children:"Specific Printer"})]}),i.jsxs("button",{type:"button",onClick:()=>{p("model"),n([]);const ae=g&&G.includes(g)?g:G[0];y(ae)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${m==="model"?"border-bambu-green bg-bambu-green/10 text-white":"border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray"}`,children:[i.jsx(lh,{className:"w-4 h-4"}),i.jsxs("span",{className:"text-sm",children:["Any ",g||"Model"]})]})]}),m==="model"&&J&&i.jsxs("div",{className:"space-y-3 mb-4",children:[!g&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Target Model"}),i.jsxs("select",{value:f||"",onChange:ae=>{y(ae.target.value||null),b&&b(null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",children:[i.jsx("option",{value:"",children:"Select a model..."}),G.map(ae=>i.jsx("option",{value:ae,children:ae},ae))]})]}),f&&z.length>0&&b&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Location Filter (optional)"}),i.jsxs("select",{value:v||"",onChange:ae=>b(ae.target.value||null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",children:[i.jsx("option",{value:"",children:"Any location"}),z.map(ae=>i.jsx("option",{value:ae,children:ae},ae))]})]}),f&&i.jsxs("p",{className:"text-xs text-bambu-gray",children:["Scheduler will assign to first available idle ",f," printer",v?` in ${v}`:""]})]}),m==="printer"&&a&&A.length>1&&i.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray mb-2",children:[i.jsx("span",{children:me===0?"Select printers":`${me} printer${me!==1?"s":""} selected`}),i.jsxs("div",{className:"flex gap-2",children:[me0&&i.jsx("button",{type:"button",onClick:Z,className:"text-bambu-gray hover:text-white transition-colors",children:"Clear"})]})]}),m==="printer"&&A.map(ae=>{const ce=ue(ae.id),ge=W(ae.id),Ne=ge&&!ge.config.useDefault,H=T(ae.id),X=o&&H,D=j(ae.id);return i.jsxs("div",{children:[i.jsxs("button",{type:"button",onClick:()=>te(ae.id),disabled:X,className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${X?"border-bambu-dark-tertiary bg-bambu-dark opacity-50 cursor-not-allowed":ce?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"} ${ae.is_active?"":"opacity-60"}`,children:[i.jsx("div",{className:`p-2 rounded-lg ${X?"bg-bambu-dark-tertiary":ce?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:i.jsx(Nr,{className:`w-5 h-5 ${X?"text-bambu-gray/50":ce?"text-bambu-green":"text-bambu-gray"}`})}),i.jsxs("div",{className:"text-left flex-1",children:[i.jsxs("p",{className:`font-medium ${X?"text-bambu-gray":"text-white"}`,children:[ae.name,!ae.is_active&&i.jsx("span",{className:"text-bambu-gray text-xs ml-2",children:"(inactive)"})]}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[ae.model||"Unknown model"," • ",ae.ip_address]})]}),D&&i.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${H?"bg-yellow-500/20 text-yellow-400":"bg-bambu-green/20 text-bambu-green"}`,children:D}),a&&i.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${X?"border-bambu-gray/30":ce?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:ce&&i.jsx(Zr,{className:"w-3 h-3 text-white"})})]}),ce&&I&&ge&&i.jsxs("div",{className:"ml-4 mt-2 mb-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",onClick:M=>M.stopPropagation(),children:[i.jsx("input",{type:"checkbox",checked:Ne,onChange:M=>de(ae.id,M.target.checked,M),className:"w-3.5 h-3.5 rounded border-bambu-gray/30 bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green focus:ring-offset-0"}),i.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom mapping"})]}),i.jsxs("span",{className:`text-xs ml-2 ${ge.matchStatus==="full"?"text-bambu-green":ge.matchStatus==="partial"?"text-yellow-400":"text-orange-400"}`,children:["(",ge.exactMatches,"/",ge.totalSlots," matched)"]}),ge.isLoading&&i.jsx(vr,{className:"w-3 h-3 text-bambu-gray animate-spin"}),Ne&&i.jsxs("button",{type:"button",onClick:M=>{M.stopPropagation(),d(ae.id)},className:"ml-auto flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",children:[i.jsx(pQ,{className:"w-3 h-3"}),"Auto"]})]}),Ne&&i.jsx(vVe,{printerResult:ge,filamentReqs:c.filaments,onUpdateConfig:M=>u(ae.id,M)})]})]},ae.id)}),m==="printer"&&F>0&&!_&&i.jsxs("button",{type:"button",onClick:()=>N(!0),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2 flex items-center gap-1",children:[i.jsx(jn,{className:"w-3 h-3 text-yellow-400"}),F," other printer",F>1?"s":""," hidden (different model) —",i.jsx("span",{className:"underline",children:"show all"})]}),m==="printer"&&_&&g&&i.jsx("button",{type:"button",onClick:()=>N(!1),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2",children:i.jsxs("span",{className:"underline",children:["Show only ",g," printers"]})}),m==="printer"&&me===0&&i.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[i.jsx(Ii,{className:"w-3 h-3"}),"Select at least one printer"]}),m==="model"&&!f&&i.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[i.jsx(Ii,{className:"w-3 h-3"}),"Select a target printer model"]})]})}const SVe=[{key:"bed_levelling",label:"Bed Levelling",desc:"Auto-level bed before print"},{key:"flow_cali",label:"Flow Calibration",desc:"Calibrate extrusion flow"},{key:"vibration_cali",label:"Vibration Calibration",desc:"Reduce ringing artifacts"},{key:"layer_inspect",label:"First Layer Inspection",desc:"AI inspection of first layer"},{key:"timelapse",label:"Timelapse",desc:"Record timelapse video"}];function _Ve({options:t,onChange:e,defaultExpanded:n=!1}){const[r,a]=w.useState(n),s=o=>{e({...t,[o]:!t[o]})};return i.jsxs("div",{className:"mb-4",children:[i.jsxs("button",{type:"button",onClick:()=>a(!r),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[i.jsx(gT,{className:"w-4 h-4"}),i.jsx("span",{children:"Print Options"}),r?i.jsx(Gl,{className:"w-4 h-4 ml-auto"}):i.jsx(zn,{className:"w-4 h-4 ml-auto"})]}),r&&i.jsx("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:SVe.map(({key:o,label:l,desc:c})=>i.jsxs("label",{className:"flex items-center justify-between cursor-pointer group",children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-sm text-white",children:l}),i.jsx("p",{className:"text-xs text-bambu-gray",children:c})]}),i.jsx("div",{className:`relative w-10 h-5 rounded-full transition-colors ${t[o]?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,onClick:()=>s(o),children:i.jsx("div",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white transition-transform ${t[o]?"translate-x-5":"translate-x-0.5"}`})})]},o))})]})}function NVe({options:t,onChange:e,dateFormat:n="system",timeFormat:r="system",canControlPrinter:a=!0}){const[s,o]=w.useState(""),[l,c]=w.useState(""),[d,u]=w.useState(!0),[m,p]=w.useState(!0),f=w.useRef(null),y=w.useRef(!1);w.useEffect(()=>{if(t.scheduleType!=="scheduled"){y.current=!1;return}if(!y.current){y.current=!0;let k;t.scheduledTime?(k=new Date(t.scheduledTime),isNaN(k.getTime())&&(k=new Date,k.setHours(k.getHours()+1,0,0,0))):(k=new Date,k.setHours(k.getHours()+1,0,0,0),e({...t,scheduledTime:O3(k)})),o(L3(k,n)),c(c6(k,r)),u(!0),p(!0)}},[t.scheduleType,t.scheduledTime,n,r,e,t]);const v=k=>{e({...t,scheduleType:k})},b=(k,P)=>{const T=Dxe(k,n),j=Fxe(P);u(!!T),p(!!j),T&&j&&(T.setHours(j.hours,j.minutes,0,0),T>new Date&&e({...t,scheduledTime:O3(T)}))},g=k=>{o(k),b(k,l)},_=k=>{c(k),b(s,k)},N=k=>{const P=k.target.value;if(P){const T=new Date(P);isNaN(T.getTime())||(o(L3(T,n)),c(c6(T,r)),u(!0),p(!0),e({...t,scheduledTime:P}))}},C=()=>{f.current?.showPicker()};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"When to print"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="asap"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("asap"),children:[i.jsx(Zn,{className:"w-4 h-4"}),"ASAP"]}),i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="scheduled"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("scheduled"),children:[i.jsx(Xr,{className:"w-4 h-4"}),"Scheduled"]}),i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="manual"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("manual"),children:[i.jsx(aQ,{className:"w-4 h-4"}),"Queue Only"]})]})]}),t.scheduleType==="scheduled"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date & Time"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("div",{className:"flex-1 relative",children:[i.jsx("input",{type:"text",className:`w-full px-3 py-2 pr-10 bg-bambu-dark border rounded-lg text-white focus:outline-none ${d?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:s,onChange:k=>g(k.target.value),placeholder:Mxe(n)}),i.jsx("button",{type:"button",onClick:C,className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",title:"Open calendar",children:i.jsx(Xr,{className:"w-4 h-4"})})]}),i.jsx("div",{className:"w-32",children:i.jsx("input",{type:"text",className:`w-full px-3 py-2 bg-bambu-dark border rounded-lg text-white focus:outline-none ${m?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:l,onChange:k=>_(k.target.value),placeholder:Exe(r)})})]}),i.jsx("input",{ref:f,type:"datetime-local",className:"sr-only",value:t.scheduledTime,onChange:N,tabIndex:-1}),(!d||!m)&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:"Please enter a valid date and time"})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"checkbox",id:"requirePrevious",checked:t.requirePreviousSuccess,onChange:k=>e({...t,requirePreviousSuccess:k.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("label",{htmlFor:"requirePrevious",className:"text-sm text-bambu-gray",children:"Only start if previous print succeeded"})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"checkbox",id:"autoOffAfter",checked:t.autoOffAfter,onChange:k=>e({...t,autoOffAfter:k.target.checked}),disabled:!a,className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green disabled:opacity-50"}),i.jsxs("label",{htmlFor:"autoOffAfter",className:`text-sm flex items-center gap-1 ${a?"text-bambu-gray":"text-bambu-gray/50"}`,children:[i.jsx(im,{className:"w-3.5 h-3.5"}),"Power off printer when done"]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:t.scheduleType==="asap"?"Print will start as soon as the printer is idle.":t.scheduleType==="scheduled"?"Print will start at the scheduled time if the printer is idle. If busy, it will wait until the printer becomes available.":"Print will be staged but won't start automatically. Use the Start button to release it to the queue."})]})}const Ab={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1},kVe={scheduleType:"asap",scheduledTime:"",requirePreviousSuccess:!1,autoOffAfter:!1};function yd({mode:t,archiveId:e,libraryFileId:n,archiveName:r,queueItem:a,initialSelectedPrinterIds:s,onClose:o,onSuccess:l}){const{t:c}=jt(),d=cn(),{showToast:u}=pn(),{hasPermission:m}=Pr(),p=!!n&&!e,[f,y]=w.useState(()=>t==="edit-queue-item"&&a?.printer_id?[a.printer_id]:s?.length?s:[]),[v,b]=w.useState(()=>t==="edit-queue-item"&&a?.plate_id!=null?new Set([a.plate_id]):new Set),g=v.size===1?[...v][0]:null,[_,N]=w.useState(()=>t==="edit-queue-item"&&a?{bed_levelling:a.bed_levelling??Ab.bed_levelling,flow_cali:a.flow_cali??Ab.flow_cali,vibration_cali:a.vibration_cali??Ab.vibration_cali,layer_inspect:a.layer_inspect??Ab.layer_inspect,timelapse:a.timelapse??Ab.timelapse}:Ab),[C,k]=w.useState(()=>{if(t==="edit-queue-item"&&a){let Pt="asap";a.manual_start?Pt="manual":a.scheduled_time&&!CW(a.scheduled_time)&&(Pt="scheduled");let ut="";if(a.scheduled_time&&!CW(a.scheduled_time)){const Lt=Qn(a.scheduled_time)??new Date;ut=O3(Lt)}return{scheduleType:Pt,scheduledTime:ut,requirePreviousSuccess:a.require_previous_success,autoOffAfter:a.auto_off_after}}return kVe}),[P,T]=w.useState(()=>{if(t==="edit-queue-item"&&a?.ams_mapping&&Array.isArray(a.ams_mapping)){const Pt={};return a.ams_mapping.forEach((ut,Lt)=>{ut!==-1&&(Pt[Lt+1]=ut)}),Pt}return{}}),[j,A]=w.useState({}),[F,G]=w.useState(()=>t==="edit-queue-item"&&a?.target_model?"model":"printer"),[z,J]=w.useState(()=>t==="edit-queue-item"&&a?.target_model?a.target_model:null),[I,te]=w.useState(()=>t==="edit-queue-item"&&a?.target_location?a.target_location:null),[se,Z]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const Pt={};for(const ut of a.filament_overrides)Pt[ut.slot_id]={type:ut.type,color:ut.color};return Pt}return{}}),[de,ue]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const Pt={};for(const ut of a.filament_overrides)Pt[ut.slot_id]=ut.force_color_match===!0;return Pt}return{}}),[me]=w.useState(()=>t==="edit-queue-item"&&a?.printer_id?[a.printer_id]:[]),[W]=w.useState(()=>t==="edit-queue-item"&&a?a.plate_id:null),[ae,ce]=w.useState(!1),[ge,Ne]=w.useState({current:0,total:0}),[H,X]=w.useState(null),[D,M]=w.useState(new Set),U=f.length,K=f.length>0?f[0]:null,{data:B}=Je({queryKey:["settings"],queryFn:fe.getSettings}),ie=go(B?.currency||"USD"),O=B?.default_filament_cost??0,{data:q,isLoading:Y}=Je({queryKey:["printers"],queryFn:fe.getPrinters}),{data:V}=Je({queryKey:["spool-assignments"],queryFn:()=>fe.getAssignments(),staleTime:30*1e3,enabled:(t==="reprint"||t==="add-to-queue")&&F==="printer"||p&&t==="reprint"}),{data:ee}=Je({queryKey:["archive",e],queryFn:()=>fe.getArchive(e),enabled:!!e&&!p}),{data:oe}=Je({queryKey:["library-file",n],queryFn:()=>fe.getLibraryFile(n),enabled:p&&!!n}),he=ee?.sliced_for_model||oe?.sliced_for_model||null,{data:pe,isError:re}=Je({queryKey:["archive-plates",e],queryFn:()=>fe.getArchivePlates(e),enabled:!!e&&!p,retry:!1}),{data:L}=Je({queryKey:["library-file-plates",n],queryFn:()=>fe.getLibraryFilePlates(n),enabled:p&&!!n}),R=p?L:pe,{data:ne,isError:ye}=Je({queryKey:["archive-filaments",e,g],queryFn:()=>fe.getArchiveFilamentRequirements(e,g??void 0),enabled:!!e&&!p&&(g!==null||!R?.is_multi_plate),retry:!1}),{data:ve}=Je({queryKey:["library-file-filaments",n,g],queryFn:()=>fe.getLibraryFileFilamentRequirements(n,g??void 0),enabled:p&&!!n&&(g!==null||!R?.is_multi_plate)}),be=!p&&(re||ye),Be=p?ve:ne,we=w.useMemo(()=>{if(!(g===null||!R?.plates?.length))return R.plates.find(Pt=>Pt.index===g)?.name||void 0},[R,g]),{data:Ae}=Je({queryKey:["available-filaments",z,I],queryFn:()=>fe.getAvailableFilaments(z,I??void 0),enabled:F==="model"&&!!z}),{data:Le}=Je({queryKey:["printer-status",K],queryFn:()=>fe.getPrinterStatus(K),enabled:!!K}),{amsMapping:Ee}=gie(Be,Le,P),_e=pVe(f,q,Be,P,j,A);w.useEffect(()=>{R?.plates&&R.plates.length>=1&&v.size===0&&b(new Set([R.plates[0].index]))},[R,v.size]),w.useEffect(()=>{if(t==="edit-queue-item")return;const Pt=q?.filter(ut=>ut.is_active)||[];Pt.length===1&&f.length===0&&y([Pt[0].id])},[t,q,f.length]),w.useEffect(()=>{t==="edit-queue-item"?(JSON.stringify(f.sort())!==JSON.stringify(me.sort())||g!==W)&&(T({}),A({}),M(new Set)):(T({}),A({}),M(new Set))},[t,f,g,me,W]);const[Me,He]=w.useState(z),[De,Xe]=w.useState(g);w.useEffect(()=>{(z!==Me||g!==De)&&(He(z),Xe(g),(t!=="edit-queue-item"||Me!==null)&&(Z({}),ue({})))},[z,g,Me,De,t]),w.useEffect(()=>{if(!B?.per_printer_mapping_expanded||f.length<=1)return;const Pt=f.filter(ut=>{if(D.has(ut))return!1;const Lt=_e.printerResults.find(qe=>qe.printerId===ut);return Lt&&Lt.status&&!Lt.isLoading});Pt.length>0&&(M(ut=>{const Lt=new Set(ut);return Pt.forEach(qe=>Lt.add(qe)),Lt}),Pt.forEach(ut=>{_e.autoConfigurePrinter(ut)}))},[B?.per_printer_mapping_expanded,f,D,_e]),w.useEffect(()=>{const Pt=ut=>{ut.key==="Escape"&&!ae&&o()};return window.addEventListener("keydown",Pt),()=>window.removeEventListener("keydown",Pt)},[o,ae]);const xe=R?.is_multi_plate??!1,We=R?.plates??[],Pe=w.useMemo(()=>{const Pt=new Map;return V&&V.forEach(ut=>{const Lt=ut.ams_id===255,qe=Fx(ut.ams_id,ut.tray_id,Lt),St=Pt.get(ut.printer_id)??new Map;St.set(qe,ut),Pt.set(ut.printer_id,St)}),Pt},[V]),Ke=w.useMemo(()=>{if(!H||H.length===0)return"";const Pt=H.map(ut=>c("printModal.insufficientFilamentLine",{printer:ut.printerName,slot:ut.slotLabel,required:Math.round(ut.requiredGrams),remaining:Math.round(ut.remainingGrams)}));return[c("printModal.insufficientFilamentMessage"),...Pt].join(` `)},[H,c]),Ve=ht({mutationFn:Pt=>fe.addToQueue(Pt)}),Ce=ht({mutationFn:Pt=>fe.updateQueueItem(a.id,Pt),onSuccess:()=>{d.invalidateQueries({queryKey:["queue"]}),u("Queue item updated"),l?.(),o()},onError:Pt=>{u(Pt.message||"Failed to update queue item","error")}}),Te=async(Pt,ut)=>{if(Pt?.preventDefault(),!ut?.skipFilamentCheck&&!B?.disable_filament_warnings&&(t==="reprint"||t==="add-to-queue")&&F==="printer"){const Qe=[],Re=Be?.filaments??[];if(Re.length>0&&Pe.size>0){const lt=(st,Ze)=>!Number.isFinite(st)||st<=0||!Number.isFinite(Ze)||Ze<0?null:Math.max(0,st-Ze);for(const st of f){const Ze=f.length>1?_e.getFinalMapping(st):Ee;if(!Ze)continue;const je=f.length>1?_e.printerResults.find(Ge=>Ge.printerId===st)?.status:Le,ct=Jw(je),le=new Map(ct.map(Ge=>[Ge.globalTrayId,Ge.label])),Oe=Pe.get(st),Ye=q?.find(Ge=>Ge.id===st)?.name??`Printer ${st}`;Oe&&Re.forEach(Ge=>{if(!Ge.slot_id||Ge.slot_id<=0)return;const ze=Ze[Ge.slot_id-1];if(!Number.isFinite(ze)||ze<0)return;const dt=Oe.get(ze)?.spool;if(!dt)return;const et=lt(dt.label_weight,dt.weight_used);et!==null&&(et>=Ge.used_grams||Qe.push({printerName:Ye,slotLabel:le.get(ze)??`Slot ${Ge.slot_id}`,requiredGrams:Ge.used_grams,remainingGrams:et}))})}}if(Qe.length>0){X(Qe);return}}if(F==="printer"&&f.length===0){u("Please select at least one printer","error");return}if(F==="model"&&!z){u("Please select a target printer model","error");return}ce(!0);const Lt=v.size>1?We.filter(Qe=>v.has(Qe.index)):[null],qe=F==="model"?Lt.length:f.length*Lt.length;Ne({current:0,total:qe});const St={success:0,failed:0,errors:[]},Ut=Qe=>{if(f.length>1){const Re=j[Qe];if(Re&&!Re.useDefault)return _e.getFinalMapping(Qe)}return Ee},ln=(()=>{const Qe=[];if(Be?.filaments)for(const Re of Be.filaments){const lt=se[Re.slot_id],st=de[Re.slot_id]??!1,Ze=lt?.type??Re.type,je=lt?.color??Re.color;(lt||st)&&Qe.push({slot_id:Re.slot_id,type:Ze,color:je,color_name:Bu(je),force_color_match:st})}else for(const[Re,{type:lt,color:st}]of Object.entries(se)){const Ze=parseInt(Re,10),je=de[Ze]??!1;Qe.push({slot_id:Ze,type:lt,color:st,color_name:Bu(st),force_color_match:je})}return Qe.length>0?Qe:void 0})(),Un=(Qe,Re)=>({printer_id:F==="printer"?Qe:null,target_model:F==="model"?z:null,target_location:F==="model"?I:null,filament_overrides:F==="model"?ln:void 0,archive_id:p?void 0:e,library_file_id:p?n:void 0,require_previous_success:C.requirePreviousSuccess,auto_off_after:C.autoOffAfter,manual_start:C.scheduleType==="manual",ams_mapping:Qe?Ut(Qe):void 0,plate_id:Re!==void 0?Re:g,scheduled_time:C.scheduleType==="scheduled"&&C.scheduledTime?new Date(C.scheduledTime).toISOString():void 0,..._});if(F==="model"){if(t==="reprint"){u("Model-based assignment only works with queue mode","error"),ce(!1);return}let Qe=0;for(const Re of Lt){Qe++,Ne({current:Qe,total:qe});const lt=Re?Re.index:g;try{if(t==="edit-queue-item"&&!Re){const st={printer_id:null,target_model:z,target_location:I,filament_overrides:ln||null,require_previous_success:C.requirePreviousSuccess,auto_off_after:C.autoOffAfter,manual_start:C.scheduleType==="manual",ams_mapping:void 0,plate_id:lt,scheduled_time:C.scheduleType==="scheduled"&&C.scheduledTime?new Date(C.scheduledTime).toISOString():null,..._};await Ce.mutateAsync(st)}else await Ve.mutateAsync(Un(null,lt));St.success++}catch(st){St.failed++;const Ze=Re?Re.name||`Plate ${Re.index}`:"";St.errors.push(Ze?`${Ze}: ${st.message}`:st.message)}}}else{let Qe=0;for(const Re of Lt){const lt=Re?Re.index:g;for(let st=0;stYe.id===Ze)?.name||`Printer ${Ze}`,le=Re?Re.name||`Plate ${Re.index}`:"",Oe=le?`${ct} (${le})`:ct;St.errors.push(`${Oe}: ${je.message}`)}}}}ce(!1),St.failed===0?(t!=="reprint"&&(t==="edit-queue-item"?u("Queue item updated"):St.success===1?u(F==="model"?`Queued for any ${z}`:c("queue.printQueued")):u(c("queue.itemsQueued",{count:St.success}))),d.invalidateQueries({queryKey:["queue"]}),l?.(),o()):St.success===0?u(`Failed: ${St.errors[0]}`,"error"):(u(`${St.success} succeeded, ${St.failed} failed`,"error"),d.invalidateQueries({queryKey:["queue"]}))},$e=ae||Ce.isPending,nt=w.useMemo(()=>!($e||F==="printer"&&f.length===0||F==="model"&&!z||F==="model"&&t==="reprint"||xe&&v.size===0),[f.length,F,z,t,xe,v.size,$e]),vt=(()=>{const Pt=f.length;if(t==="reprint")return{title:c(p?"queue.print":"queue.reprint"),icon:Nr,submitText:Pt>1?c("queue.printToPrinters",{count:Pt}):c("queue.print"),submitIcon:Nr,loadingText:ge.total>1?c("queue.sendingProgress",{current:ge.current,total:ge.total}):c("queue.sending")};if(t==="add-to-queue"){let ut=c("queue.addToQueue");return v.size>1?ut=c("queue.queueSelectedPlates",{count:v.size}):Pt>1&&(ut=c("queue.queueToPrinters",{count:Pt})),{title:c("queue.schedulePrint"),icon:Xr,submitText:ut,submitIcon:Xr,loadingText:ge.total>1?c("queue.addingProgress",{current:ge.current,total:ge.total}):c("queue.adding")}}return{title:c("queue.editQueueItem"),icon:Xi,submitText:c("common.save"),submitIcon:Xi,loadingText:ge.total>1?c("queue.savingProgress",{current:ge.current,total:ge.total}):c("common.saving")}})(),mt=vt.icon,Ht=vt.submitIcon,Yt=K&&v.size<=1&&(p||(xe?g!==null:!0));return i.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:ae?void 0:o,children:[i.jsx(At,{className:"w-full max-w-2xl max-h-[90vh] overflow-y-auto",onClick:Pt=>Pt.stopPropagation(),children:i.jsxs(Et,{className:t==="reprint"?"":"p-0",children:[i.jsxs("div",{className:`flex items-center justify-between ${t==="reprint"?"mb-4":"p-4 border-b border-bambu-dark-tertiary"}`,children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(mt,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:vt.title})]}),i.jsx(Ie,{variant:"ghost",size:"sm",onClick:o,disabled:ae,children:i.jsx(qt,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:Te,className:t==="reprint"?"":"p-4 space-y-4",children:[i.jsx("p",{className:`text-sm text-bambu-gray ${t==="reprint"?"mb-4":""}`,children:t==="reprint"?i.jsxs(i.Fragment,{children:["Send ",i.jsx("span",{className:"text-white",children:r})," to"," ",s?.length===1&&q?i.jsx("span",{className:"text-white",children:q.find(Pt=>Pt.id===s[0])?.name??"printer(s)"}):"printer(s)"]}):i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"block text-bambu-gray mb-1",children:"Print Job"}),i.jsx("span",{className:"text-white font-medium truncate block",children:r})]})}),i.jsx(xVe,{plates:We,isMultiPlate:xe,selectedPlates:v,onToggle:Pt=>{b(ut=>{const Lt=new Set(ut);return t==="add-to-queue"?Lt.has(Pt)?Lt.delete(Pt):Lt.add(Pt):(Lt.clear(),Lt.add(Pt)),Lt})},onSelectAll:t==="add-to-queue"?()=>b(new Set(We.map(Pt=>Pt.index))):void 0,onDeselectAll:t==="add-to-queue"?()=>b(new Set):void 0,multiSelect:t==="add-to-queue"}),!s?.length&&i.jsx(wVe,{printers:q||[],selectedPrinterIds:f,onMultiSelect:y,isLoading:Y,allowMultiple:!0,showInactive:t==="edit-queue-item",disableBusy:t==="reprint",printerMappingResults:_e.printerResults,filamentReqs:Be,onAutoConfigurePrinter:_e.autoConfigurePrinter,onUpdatePrinterConfig:_e.updatePrinterConfig,assignmentMode:t==="reprint"?"printer":F,onAssignmentModeChange:t!=="reprint"?G:void 0,targetModel:z,onTargetModelChange:t!=="reprint"?J:void 0,targetLocation:I,onTargetLocationChange:t!=="reprint"?te:void 0,slicedForModel:he}),F==="model"&&z&&Be&&Ae&&Ae.length>0&&i.jsx(bVe,{filamentReqs:Be,availableFilaments:Ae,overrides:se,onChange:Z,forceColorMatch:de,onForceColorMatchChange:(Pt,ut)=>ue(Lt=>({...Lt,[Pt]:ut}))}),he&&F==="printer"&&f.length===1&&(()=>{const Pt=q?.find(ut=>ut.id===f[0]);return Pt&&Pt.model&&he!==Pt.model?i.jsxs("div",{className:"p-3 mb-2 bg-yellow-500/10 border border-yellow-500/30 rounded-lg flex items-center gap-2",children:[i.jsx(jn,{className:"w-4 h-4 text-yellow-400 flex-shrink-0"}),i.jsxs("span",{className:"text-sm text-yellow-400",children:["File was sliced for ",he,", but printing on ",Pt.model]})]}):null})(),be&&i.jsxs("div",{className:"flex items-start gap-2 p-3 mb-2 bg-orange-500/10 border border-orange-500/30 rounded-lg text-sm",children:[i.jsx(Ii,{className:"w-4 h-4 text-orange-400 mt-0.5 flex-shrink-0"}),i.jsx("p",{className:"text-orange-400",children:"Archive data unavailable. The source file may have been deleted. Filament mapping is disabled."})]}),Yt&&!be&&f.length===1&&i.jsx(gVe,{printerId:K,filamentReqs:Be,manualMappings:P,onManualMappingChange:T,defaultExpanded:!!s?.length||(B?.per_printer_mapping_expanded??!1),currencySymbol:ie,defaultCostPerKg:O}),(t==="reprint"||U>0||F==="model"&&z)&&i.jsx(_Ve,{options:_,onChange:N,defaultExpanded:!!s?.length}),t!=="reprint"&&i.jsx(NVe,{options:C,onChange:k,dateFormat:B?.date_format||"system",timeFormat:B?.time_format||"system",canControlPrinter:m("printers:control")}),Ce.isError&&i.jsx("div",{className:"mb-4 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:Ce.error?.message||"Failed to complete operation"}),i.jsxs("div",{className:`flex gap-3 ${t==="reprint"?"":"pt-2"}`,children:[i.jsx(Ie,{type:"button",variant:"secondary",onClick:o,className:"flex-1",disabled:ae,children:"Cancel"}),i.jsx(Ie,{type:"submit",disabled:!nt,className:"flex-1",children:$e?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-4 h-4 animate-spin"}),vt.loadingText]}):i.jsxs(i.Fragment,{children:[i.jsx(Ht,{className:"w-4 h-4"}),vt.submitText]})})]})]})]})}),H&&H.length>0&&i.jsx(_n,{title:c("printModal.insufficientFilamentTitle"),message:Ke,confirmText:c("printModal.printAnyway"),cancelText:c("common.cancel"),variant:"warning",onConfirm:()=>{X(null),Te(void 0,{skipFilamentCheck:!0})},onCancel:()=>X(null)})]})}function PW({value:t}){const{t:e}=jt(),[n,r]=w.useState(!1),a=async()=>{try{await navigator.clipboard.writeText(t),r(!0),setTimeout(()=>r(!1),2e3)}catch{}};return i.jsx("button",{onClick:a,className:"ml-2 p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:e(n?"printers.copied":"printers.copyToClipboard"),children:n?i.jsx(Zr,{className:"w-3.5 h-3.5 text-bambu-green"}):i.jsx(To,{className:"w-3.5 h-3.5"})})}function CVe({printer:t,status:e,totalPrintHours:n,onClose:r}){const{t:a}=jt();w.useEffect(()=>{const o=l=>{l.key==="Escape"&&r()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[r]);const s=[];if(s.push({label:a("printers.model"),value:t.model??"—"}),s.push({label:a("common.status"),value:i.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-xs font-medium ${e?.connected?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:[i.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${e?.connected?"bg-bambu-green":"bg-red-400"}`}),e?.connected?a("printers.status.available"):a("printers.status.offline")]})}),e?.state){const o={IDLE:"printers.status.idle",RUNNING:"printers.status.printing",PAUSE:"printers.status.paused",FINISH:"printers.status.finished",FAILED:"printers.status.error"};s.push({label:a("printers.state"),value:a(o[e.state]??"printers.status.unknown")})}if(s.push({label:a("printers.ipAddress"),value:i.jsxs("span",{className:"flex items-center",children:[i.jsx("span",{className:"font-mono",children:t.ip_address}),i.jsx(PW,{value:t.ip_address})]})}),s.push({label:a("printers.serialNumber"),value:i.jsxs("span",{className:"flex items-center",children:[i.jsx("span",{className:"font-mono truncate",children:t.serial_number}),i.jsx(PW,{value:t.serial_number})]})}),e?.wired_network)s.push({label:a("printers.networkLabel","Network"),value:i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(eO,{className:"w-4 h-4 text-bambu-green"}),i.jsx("span",{className:"text-bambu-green",children:a("printers.connection.ethernet","Ethernet")})]})});else if(e?.wifi_signal!=null){const o=KZ(e.wifi_signal);s.push({label:a("printers.wifiSignalLabel"),value:i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(dQ,{className:`w-4 h-4 ${o.color}`}),i.jsx("span",{className:o.color,children:a(o.labelKey)}),i.jsxs("span",{className:"text-bambu-gray text-xs",children:["(",e.wifi_signal," dBm)"]})]})})}return s.push({label:a("printers.firmware"),value:e?.firmware_version??"—"}),e?.developer_mode!=null&&s.push({label:a("printers.developerMode"),value:i.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${e.developer_mode?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:e.developer_mode?a("printers.enabled"):a("printers.disabled")})}),s.push({label:a("printers.nozzleCount"),value:t.nozzle_count}),e?.sdcard!=null&&s.push({label:a("printers.sdCard"),value:i.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${e.sdcard?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:e.sdcard?a("printers.inserted"):a("printers.notInserted")})}),s.push({label:a("printers.autoArchive"),value:i.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${t.auto_archive?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:t.auto_archive?a("printers.enabled"):a("printers.disabled")})}),n!=null&&n>0&&s.push({label:a("printers.totalPrintHours"),value:`${Math.round(n)}h`}),t.location&&s.push({label:a("printers.sort.location"),value:t.location}),s.push({label:a("printers.addedOn"),value:Of(t.created_at)}),i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",role:"dialog","aria-modal":"true",onClick:r,children:i.jsx(At,{className:"w-full max-w-md",onClick:o=>o.stopPropagation(),children:i.jsxs(Et,{children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:t.name}),i.jsx("button",{onClick:r,className:"p-1 hover:bg-bambu-dark rounded flex-shrink-0",children:i.jsx(qt,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsx("div",{className:"flex justify-center mb-4",children:i.jsx("img",{src:WZ(t.model),alt:t.model??t.name,className:"h-24 object-contain"})}),i.jsx("div",{className:"space-y-0",children:s.map((o,l)=>i.jsxs("div",{className:"flex items-center justify-between gap-4 py-2.5 border-b border-bambu-dark-tertiary last:border-0",children:[i.jsx("span",{className:"text-sm text-bambu-gray whitespace-nowrap",children:o.label}),i.jsx("span",{className:"text-sm text-white text-right",children:o.value})]},l))})]})})})}function TVe(t){if(!t||t.length<6)return!1;const e=parseInt(t.slice(0,2),16),n=parseInt(t.slice(2,4),16),r=parseInt(t.slice(4,6),16);return(.299*e+.587*n+.114*r)/255>.6}function aD({trayColor:t,trayType:e,isEmpty:n,slotNumber:r}){return i.jsx("div",{className:"w-3.5 h-3.5 rounded-full mx-auto mb-0.5 border-2 flex items-center justify-center",style:{backgroundColor:t?`#${t}`:e?"#333":"transparent",borderColor:n?"#666":"rgba(255,255,255,0.1)",borderStyle:n?"dashed":"solid"},children:i.jsx("span",{className:"text-[6px] font-bold leading-none select-none",style:{color:t&&TVe(t)?"#000":"#fff"},children:r})})}const MW={"A00-W1":"Jade White","A00-P0":"Beige","A00-D2":"Light Gray","A00-Y0":"Yellow","A00-Y2":"Sunflower Yellow","A00-A1":"Pumpkin Orange","A00-A0":"Orange","A00-Y4":"Gold","A00-G3":"Bright Green","A00-G1":"Bambu Green","A00-G2":"Mistletoe Green","A00-R3":"Hot Pink","A00-P6":"Magenta","A00-R0":"Red","A00-R2":"Maroon Red","A00-P5":"Purple","A00-P2":"Indigo Purple","A00-B5":"Turquoise","A00-B8":"Cyan","A00-B3":"Cobalt Blue","A00-N0":"Brown","A00-N1":"Cocoa Brown","A00-Y3":"Bronze","A00-D0":"Gray","A00-D1":"Silver","A00-B1":"Blue Grey","A00-D3":"Dark Gray","A00-K0":"Black","A00-M3":"Pink Citrus","A00-M6":"Dusk Glare","A00-M0":"Arctic Whisper","A00-M1":"Solar Breeze","A00-M5":"Blueberry Bubblegum","A00-M4":"Mint Lime","A00-M2":"Ocean to Meadow","A00-M7":"Cotton Candy Cloud","A18-K0":"Black","A18-D0":"Gray","A18-W0":"White","A18-R0":"Red","A18-Y0":"Yellow","A18-B0":"Cyan","A18-B1":"Blue","A18-P0":"Matte Beige","A01-W2":"Ivory White","A01-W3":"Bone White","A01-Y2":"Lemon Yellow","A01-A2":"Mandarin Orange","A01-P3":"Sakura Pink","A01-P4":"Lilac Purple","A01-R3":"Plum","A01-R1":"Scarlet Red","A01-R4":"Dark Red","A01-G0":"Apple Green","A01-G1":"Grass Green","A01-G7":"Dark Green","A01-B4":"Ice Blue","A01-B0":"Sky Blue","A01-B3":"Marine Blue","A01-B6":"Dark Blue","A01-Y3":"Desert Tan","A01-N1":"Latte Brown","A01-N3":"Caramel","A01-R2":"Terracotta","A01-N2":"Dark Brown","A01-N0":"Dark Chocolate","A01-D3":"Ash Gray","A01-D0":"Nardo Gray","A01-K1":"Charcoal","A12-G0":"Green","A12-R0":"Pink","A12-A0":"Orange","A12-Y0":"Yellow","A12-B0":"Blue","A07-R5":"Red Granite","A07-D4":"White Marble","A11-W0":"White","A11-K0":"Black","A08-G3":"Alpine Green Sparkle","A08-D5":"Slate Gray Sparkle","A08-B7":"Royal Purple Sparkle","A08-R2":"Crimson Red Sparkle","A08-K2":"Onyx Black Sparkle","A08-Y1":"Classic Gold Sparkle","A02-B2":"Cobalt Blue Metallic","A02-G2":"Oxide Green Metallic","A02-Y1":"Iridium Gold Metallic","A02-D2":"Iron Gray Metallic","A17-B1":"Blue","A17-A0":"Orange","A17-P0":"Purple","A06-Y1":"Gold","A06-D0":"Titan Gray","A06-D1":"Silver","A06-W0":"White","A06-R0":"Candy Red","A06-G0":"Candy Green","A06-G1":"Mint","A06-B1":"Blue","A06-B0":"Baby Blue","A06-P0":"Purple","A06-R1":"Rose Gold","A06-R2":"Pink","A06-Y0":"Champagne","A05-M8":"Dawn Radiance","A05-M4":"Aurora Purple","A05-M1":"South Beach","A05-T3":"Neon City","A05-T2":"Midnight Blaze","A05-T1":"Gilded Rose","A05-T4":"Blue Hawaii","A05-T5":"Velvet Eclipse","A15-B0":"Purple","A15-G0":"Green","A15-G1":"Nebulae","A15-R0":"Brown","A16-K0":"Black Walnut","A16-R0":"Rosewood","A16-N0":"Clay Brown","A16-G0":"Classic Birch","A16-W0":"White Oak","A16-Y0":"Ochre Yellow","A50-D6":"Lava Gray","A50-K0":"Black","A50-B6":"Royal Blue","A10-W0":"White","A10-D0":"Gray","A09-B5":"Lavender Blue","A09-B4":"Light Blue","A09-A0":"Orange","A09-D1":"Silver","A09-R3":"Vermilion Red","A09-Y0":"Yellow","G02-K0":"Black","G02-W0":"White","G02-R0":"Red","G02-D0":"Gray","G02-D1":"Dark Gray","G02-Y1":"Cream","G02-Y0":"Yellow","G02-A0":"Orange","G02-N1":"Peanut Brown","G02-G1":"Lime Green","G02-G0":"Green","G02-G2":"Forest Green","G02-B1":"Lake Blue","G02-B0":"Blue","G01-G1":"Translucent Teal","G01-B0":"Translucent Light Blue","G01-C0":"Clear","G01-D0":"Translucent Gray","G01-G0":"Translucent Olive","G01-N0":"Translucent Brown","G01-A0":"Translucent Orange","G01-P1":"Translucent Pink","G01-P0":"Translucent Purple","G50-P7":"Violet Purple","G50-K0":"Black","B00-D1":"Silver","B00-K0":"Black","B00-W0":"White","B00-G6":"Bambu Green","B00-G7":"Olive","B00-Y1":"Tangerine Yellow","B00-A0":"Orange","B00-R0":"Red","B00-B4":"Azure","B00-B0":"Blue","B00-B6":"Navy Blue","B50-A0":"Orange","B50-K0":"Black","B01-W0":"White","B01-K0":"Black","B01-D0":"Gray","B02-W0":"White","C00-C1":"Transparent","C00-C0":"Clear Black","C00-K0":"Black","C00-W0":"White","C01-K0":"Black","U02-B0":"Blue","U02-D0":"Gray","U02-K0":"Black","N04-K0":"Black","N08-K0":"Black","S02-W0":"Nature","S02-W1":"White","S05-C0":"Black","S06-W0":"White","S03-G1":"Green","S04-Y0":"Clear"},AVe={W0:"White",W1:"Jade White",W2:"Ivory White",W3:"Bone White",Y0:"Yellow",Y1:"Gold",Y2:"Sunflower Yellow",Y3:"Bronze",Y4:"Gold",A0:"Orange",A1:"Pumpkin Orange",A2:"Mandarin Orange",R0:"Red",R1:"Scarlet Red",R2:"Maroon Red",R3:"Hot Pink",R4:"Dark Red",R5:"Red Granite",P0:"Beige",P1:"Pink",P2:"Indigo Purple",P3:"Sakura Pink",P4:"Lilac Purple",P5:"Purple",P6:"Magenta",P7:"Violet Purple",B0:"Blue",B1:"Blue Grey",B2:"Cobalt Blue",B3:"Cobalt Blue",B4:"Ice Blue",B5:"Turquoise",B6:"Navy Blue",B7:"Royal Purple",B8:"Cyan",G0:"Green",G1:"Grass Green",G2:"Mistletoe Green",G3:"Bright Green",G6:"Bambu Green",G7:"Dark Green",N0:"Brown",N1:"Peanut Brown",N2:"Dark Brown",N3:"Caramel",D0:"Gray",D1:"Silver",D2:"Light Gray",D3:"Dark Gray",D4:"White Marble",D5:"Slate Gray",D6:"Lava Gray",K0:"Black",K1:"Charcoal",K2:"Onyx Black",C0:"Clear Black",C1:"Transparent",M0:"Arctic Whisper",M1:"Solar Breeze",M2:"Ocean to Meadow",M3:"Pink Citrus",M4:"Aurora Purple",M5:"Blueberry Bubblegum",M6:"Dusk Glare",M7:"Cotton Candy Cloud",M8:"Dawn Radiance",T1:"Gilded Rose",T2:"Midnight Blaze",T3:"Neon City",T4:"Blue Hawaii",T5:"Velvet Eclipse"};function sD(t){if(!t)return null;if(MW[t])return MW[t];const e=t.split("-");if(e.length<2)return null;const n=e[1];return AVe[n]||null}function oD(t){return(t??.02).toFixed(3)}function EW({side:t}){const{mode:e}=sg(),n=e==="dark"?"#1a4d2e":"#e7f5e9";return i.jsx("span",{className:"inline-flex items-center justify-center w-4 h-4 text-[10px] font-bold rounded",style:{backgroundColor:n,color:"#00ae42"},children:t})}function xie(t,e){if(!t)return"";if(t.includes("hardened"))return e("printers.nozzleHardenedSteel");if(t.includes("stainless"))return e("printers.nozzleStainlessSteel");if(t.includes("tungsten"))return e("printers.nozzleTungstenCarbide");if(t.length>=4){const n=t.slice(2,4);if(n==="00")return e("printers.nozzleStainlessSteel");if(n==="01")return e("printers.nozzleHardenedSteel");if(n==="05")return e("printers.nozzleTungstenCarbide")}return t==="00"?e("printers.nozzleStainlessSteel"):t==="01"?e("printers.nozzleHardenedSteel"):t==="05"?e("printers.nozzleTungstenCarbide"):t.startsWith("H")?e("printers.nozzleHardenedSteel"):t}function yie(t,e){return t?t.startsWith("HH")?e("printers.nozzleHighFlow"):t.startsWith("HS")?e("printers.nozzleStandardFlow"):"":""}function vie({slot:t,index:e,activeStatus:n,filamentName:r,children:a}){const{t:s}=jt(),[o,l]=w.useState(!1),[c,d]=w.useState("top"),u=w.useRef(null),m=w.useRef(null),p=w.useRef(null),f=!t.nozzle_diameter&&!t.nozzle_type,y=t.stat===1;w.useEffect(()=>{if(o&&u.current&&m.current){const C=u.current.getBoundingClientRect(),k=m.current.offsetHeight,T=C.top-56,j=window.innerHeight-C.bottom;TT?d("bottom"):d("top")}},[o]);const v=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>l(!0),80)},b=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>l(!1),100)};w.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const g=HI(t.filament_color),_=xie(t.nozzle_type,s),N=yie(t.nozzle_type,s);return i.jsxs("div",{ref:u,className:"relative",onMouseEnter:v,onMouseLeave:b,children:[a,o&&i.jsxs("div",{ref:m,className:` absolute left-1/2 -translate-x-1/2 z-50 ${c==="top"?"bottom-full mb-2":"top-full mt-2"} diff --git a/static/index.html b/static/index.html index 57ba92187..e4462f8a9 100644 --- a/static/index.html +++ b/static/index.html @@ -23,7 +23,7 @@ - +