From 60b17ea5d8673e30f0cb0580b2b920e3e7f9ab90 Mon Sep 17 00:00:00 2001 From: maziggy Date: Sat, 7 Mar 2026 08:59:51 +0100 Subject: [PATCH] Added MYR (Malaysian Ringgit) with the symbol RM to the currency list --- frontend/src/utils/currency.ts | 1 + static/assets/{index-p3ObkGK6.js => index-DCHZw0ab.js} | 2 +- static/index.html | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) rename static/assets/{index-p3ObkGK6.js => index-DCHZw0ab.js} (98%) diff --git a/frontend/src/utils/currency.ts b/frontend/src/utils/currency.ts index de40c4a91..ea8747224 100644 --- a/frontend/src/utils/currency.ts +++ b/frontend/src/utils/currency.ts @@ -19,6 +19,7 @@ const CURRENCY_SYMBOLS: Record = { SGD: 'S$', NZD: 'NZ$', MXN: 'MX$', + MYR: 'RM', CZK: 'Kč', THB: '฿', ZAR: 'R', diff --git a/static/assets/index-p3ObkGK6.js b/static/assets/index-DCHZw0ab.js similarity index 98% rename from static/assets/index-p3ObkGK6.js rename to static/assets/index-DCHZw0ab.js index b1d8d937a..994191549 100644 --- a/static/assets/index-p3ObkGK6.js +++ b/static/assets/index-DCHZw0ab.js @@ -8503,7 +8503,7 @@ void main() { border-l-[5px] border-l-transparent border-r-[5px] border-r-transparent border-t-[5px] border-t-bambu-dark-tertiary - `})]})]})}function O$e({isOpen:t,onClose:e,tagUid:n,trayUuid:r,printerId:a,amsId:s,trayId:o}){const{t:l}=Mt(),c=Zt(),{showToast:d}=hn(),[u,m]=w.useState(""),{data:p,isLoading:f}=Ze({queryKey:["inventory-spools"],queryFn:()=>fe.getSpools(!1),enabled:t}),x=w.useMemo(()=>p?p.filter(g=>{if(g.tag_uid||g.tray_uuid)return!1;if(!u)return!0;const y=u.toLowerCase();return g.material.toLowerCase().includes(y)||g.brand&&g.brand.toLowerCase().includes(y)||g.color_name&&g.color_name.toLowerCase().includes(y)}):[],[p,u]),v=dt({mutationFn:g=>fe.linkTagToSpool(g,{tag_uid:n||void 0,tray_uuid:r||void 0,tag_type:r?"bambulab":"generic",data_origin:"nfc_link"}),onSuccess:()=>{c.invalidateQueries({queryKey:["inventory-spools"]}),c.invalidateQueries({queryKey:["inventory-assignments"]}),d(l("inventory.tagLinked"),"success"),e()},onError:g=>{d(g.message||l("inventory.tagLinkFailed"),"error")}});return t?i.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),i.jsxs("div",{className:"relative bg-bambu-dark-secondary rounded-xl shadow-xl w-full max-w-md mx-4 max-h-[80vh] flex flex-col border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[i.jsxs("div",{children:[i.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(dx,{className:"w-5 h-5 text-bambu-green"}),l("inventory.linkToSpool")]}),i.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["AMS ",s," T",o," · Printer #",a]})]}),i.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(zt,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-4 border-b border-white/10",children:[i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:u,onChange:g=>m(g.target.value),placeholder:l("inventory.searchSpools"),className:"w-full pl-9 pr-3 py-2 bg-bambu-dark rounded-lg border border-white/10 text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green"})]}),(n||r)&&i.jsxs("p",{className:"text-xs text-bambu-gray mt-2 font-mono truncate",title:n||r,children:["Tag: ",n||r]})]}),i.jsx("div",{className:"flex-1 overflow-y-auto p-2 min-h-0",children:f?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(lt,{className:"w-6 h-6 animate-spin text-bambu-green"})}):x.length===0?i.jsx("p",{className:"text-center text-bambu-gray py-8 text-sm",children:l("inventory.noSpoolsMatch")}):x.map(g=>i.jsxs("button",{onClick:()=>v.mutate(g.id),disabled:v.isPending,className:"w-full flex items-center gap-3 p-3 rounded-lg hover:bg-white/5 transition-colors text-left",children:[i.jsx("span",{className:"w-6 h-6 rounded-full border border-white/20 flex-shrink-0",style:{backgroundColor:g.rgba?`#${g.rgba.substring(0,6)}`:"#808080"}}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"text-sm text-white font-medium truncate",children:[g.brand?`${g.brand} `:"",g.material,g.subtype?` ${g.subtype}`:""]}),i.jsxs("div",{className:"text-xs text-bambu-gray truncate",children:[g.color_name||"No color"," · #",g.id]})]}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:[Math.round(g.label_weight-g.weight_used),"g"]})]},g.id))}),i.jsx("div",{className:"p-4 border-t border-white/10 flex justify-end",children:i.jsx(Oe,{variant:"ghost",onClick:e,children:l("inventory.cancel")||"Cancel"})})]})]}):null}function I$e({isOpen:t,onClose:e,printerId:n,amsId:r,trayId:a,trayInfo:s}){const{t:o}=Mt(),l=Zt(),{showToast:c}=hn(),[d,u]=w.useState(null),[m,p]=w.useState(""),{data:f,isLoading:x}=Ze({queryKey:["inventory-spools"],queryFn:()=>fe.getSpools(),enabled:t}),{data:v}=Ze({queryKey:["spool-assignments"],queryFn:()=>fe.getAssignments(),enabled:t}),g=dt({mutationFn:P=>fe.assignSpool({spool_id:P,printer_id:n,ams_id:r,tray_id:a}),onSuccess:P=>{l.setQueryData(["spool-assignments"],k=>{const D=(k||[]).filter(A=>!(A.printer_id===n&&A.ams_id===r&&A.tray_id===a));return D.push(P),D}),l.invalidateQueries({queryKey:["spool-assignments"]}),c(o("inventory.assignSuccess"),"success"),e()},onError:P=>{c(`${o("inventory.assignFailed")}: ${P.message}`,"error")}});if(!t)return null;const y=new Set((v||[]).filter(P=>!(P.printer_id===n&&P.ams_id===r&&P.tray_id===a)).map(P=>P.spool_id)),_=r===254||r===255,N=f?.filter(P=>!y.has(P.id)&&(_||!P.tag_uid&&!P.tray_uuid)),C=N?.filter(P=>{if(!m)return!0;const k=m.toLowerCase();return P.material.toLowerCase().includes(k)||(P.brand?.toLowerCase().includes(k)??!1)||(P.color_name?.toLowerCase().includes(k)??!1)||(P.subtype?.toLowerCase().includes(k)??!1)}),T=()=>{d&&g.mutate(d)};return i.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),i.jsxs("div",{className:"relative w-full max-w-md 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",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(oa,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:o("inventory.assignSpool")})]}),i.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(zt,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[s&&i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("p",{className:"text-xs text-bambu-gray mb-1",children:[o("inventory.selectSpool"),":"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[s.color&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20",style:{backgroundColor:`#${s.color}`}}),i.jsx("span",{className:"text-white font-medium",children:s.type||o("ams.emptySlot")}),i.jsxs("span",{className:"text-bambu-gray",children:["(",s.location,")"]})]})]}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:m,onChange:P=>p(P.target.value),placeholder:o("inventory.searchSpools"),className:"w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green"})]}),i.jsx("div",{children:x?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):C&&C.length>0?i.jsx("div",{className:"max-h-64 overflow-y-auto space-y-2",children:C.map(P=>i.jsx("button",{onClick:()=>u(P.id),className:`w-full p-3 rounded-lg border text-left transition-colors ${d===P.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 gap-2",children:[P.rgba&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20 flex-shrink-0",style:{backgroundColor:`#${P.rgba.substring(0,6)}`}}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("p",{className:"text-white font-medium truncate",children:[P.brand?`${P.brand} `:"",P.material,P.subtype?` ${P.subtype}`:""]}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[P.color_name||"",P.label_weight?` - ${P.label_weight}g`:"",P.label_weight?` (${Math.max(0,Math.round(P.label_weight-P.weight_used))}g ${o("ams.remainingUnit")})`:""]})]}),d===P.id&&i.jsx(Vr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]})},P.id))}):N&&N.length===0?i.jsx("div",{className:"text-center py-8 text-bambu-gray",children:i.jsx("p",{children:o("inventory.noManualSpools")})}):i.jsx("div",{className:"text-center py-8 text-bambu-gray",children:i.jsx("p",{children:o("inventory.noSpoolsMatch")})})})]}),i.jsxs("div",{className:"flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary",children:[i.jsx(Oe,{variant:"secondary",onClick:e,children:o("common.cancel")}),i.jsx(Oe,{onClick:T,disabled:!d||g.isPending,children:g.isPending?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),o("inventory.assigning")]}):i.jsxs(i.Fragment,{children:[i.jsx(oa,{className:"w-4 h-4"}),o("inventory.assignSpool")]})})]}),g.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:g.error.message})]})]})}function xG(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 U_(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 hv=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function yG(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 hv)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 hv){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 z$e(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const U$e={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"},vG=[{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"}],wG=[{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 SG(t){const e=t.toLowerCase().trim();return U$e[e]||null}function B$e(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 Kne({isOpen:t,onClose:e,printerId:n,slotInfo:r,nozzleDiameter:a="0.4",printerModel:s,onSuccess:o,fullScreen:l}){const{t:c}=Mt(),[d,u]=w.useState(""),[m,p]=w.useState(null),[f,x]=w.useState(""),[v,g]=w.useState(""),[y,_]=w.useState(""),[N,C]=w.useState(!1),[T,P]=w.useState(!1),k=w.useRef(""),{data:D,isLoading:A,isError:R}=Ze({queryKey:["cloudSettings"],queryFn:()=>fe.getCloudSettings(),enabled:t,retry:!1}),{data:$,isLoading:U}=Ze({queryKey:["localPresets"],queryFn:()=>fe.getLocalPresets(),enabled:t}),{data:W,isLoading:O}=Ze({queryKey:["builtinFilaments"],queryFn:()=>fe.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:te,isLoading:re}=Ze({queryKey:["kprofiles",n,a],queryFn:()=>fe.getKProfiles(n,a),enabled:t&&!!n}),{data:J}=Ze({queryKey:["colorCatalog"],queryFn:()=>fe.getColorCatalog(),enabled:t,staleTime:1/0}),le=dt({mutationFn:async()=>{if(!d)throw new Error("No filament preset selected");const j=d.startsWith("local_"),L=d.startsWith("builtin_"),G=j?parseInt(d.replace("local_",""),10):null,B=L?d.replace("builtin_",""):null,ie=j?$?.filament.find(Ue=>Ue.id===G):null,z=L?W?.find(Ue=>Ue.filament_id===B):null,V=!j&&!L?D?.filament.find(Ue=>Ue.setting_id===d):null;if(!j&&!L&&!V)throw new Error("Selected preset not found");if(j&&!ie)throw new Error("Selected local preset not found");if(L&&!z)throw new Error("Selected builtin preset not found");const ee=j?ie.name:L?z.name:V.name,Z=yG(ee),ne=m?.slot_id??-1,se=f||r.trayColor?.slice(0,6)||"FFFFFF",ue=ee.replace(/@.+$/,"").trim();let ge,ce;const I=Z.material.toUpperCase();if(j){const Ue=(hv.includes(I)?I:ie?.filament_type||Z.material||"").toUpperCase(),$e={PLA:"GFL99","PLA-CF":"GFL98","PLA SILK":"GFL96","PLA HIGH SPEED":"GFL95",PETG:"GFG99","PETG HF":"GFG96","PETG-CF":"GFG98",PCTG:"GFG97",ABS:"GFB99",ASA:"GFB98",PC:"GFC99",PA:"GFN99","PA-CF":"GFN98",NYLON:"GFN99",TPU:"GFU99",PVA:"GFS99",HIPS:"GFS98",PE:"GFP99",PP:"GFP97"};ge=$e[Ue]||$e[Ue.replace(/[-\s]?CF$/,"")]||$e[Ue.replace(/\+$/,"")]||$e[Ue.split(/[-\s]/)[0]]||"",ce=""}else if(L)ge=B,ce="";else if(ge=U_(d),ce=d,!d.startsWith("GFS"))try{const Ue=await fe.getCloudSettingDetail(d);Ue.filament_id?ge=Ue.filament_id:Ue.base_id&&(ge=U_(Ue.base_id),console.log(`Derived tray_info_idx from base_id: ${Ue.base_id} -> ${ge}`))}catch(Ue){console.warn("Failed to fetch preset detail for filament_id:",Ue)}let F=j&&ie?.nozzle_temp_min?ie.nozzle_temp_min:190,Q=j&&ie?.nozzle_temp_max?ie.nozzle_temp_max:230;if(!j||L||!ie?.nozzle_temp_min&&!ie?.nozzle_temp_max){const Ue=(j?hv.includes(I)?I:ie?.filament_type||Z.material||"":Z.material).toUpperCase();Ue.includes("PLA")?(F=190,Q=230):Ue.includes("PETG")?(F=220,Q=260):Ue.includes("ABS")||Ue.includes("ASA")?(F=240,Q=280):Ue.includes("TPU")?(F=200,Q=240):Ue==="PCTG"?(F=220,Q=260):Ue.includes("PC")?(F=260,Q=300):(Ue.includes("PA")||Ue.includes("NYLON"))&&(F=250,Q=290)}const xe=m?.k_value?parseFloat(m.k_value):0,pe=j?hv.includes(I)?I:ie?.filament_type||Z.material||"PLA":Z.material||"PLA",de=await fe.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:ge,tray_type:pe,tray_sub_brands:ue,tray_color:se+"FF",nozzle_temp_min:F,nozzle_temp_max:Q,cali_idx:ne,nozzle_diameter:a,setting_id:ce,kprofile_filament_id:m?.filament_id,kprofile_setting_id:m?.setting_id||void 0,k_value:xe}),Ae=j?`local_${G}`:L?`builtin_${B}`:d,_e=j?"local":L?"builtin":"cloud";try{await fe.saveSlotPreset(n,r.amsId,r.trayId,Ae,ue,_e)}catch(Ue){console.warn("Failed to save slot preset mapping:",Ue)}return de},onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),me=dt({mutationFn:async()=>fe.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),he=w.useMemo(()=>{const j=y.toLowerCase(),L=[],G=new Set,B=r.savedPresetId,ie=r.trayInfoIdx;if(D?.filament)for(const z of D.filament){G.add(z.setting_id);const V=B===z.setting_id||ie&&(z.setting_id===ie||U_(z.setting_id)===ie);if(!(!V&&j&&!z.name.toLowerCase().includes(j))){if(!V&&s){const ee=B$e(z.name);if(ee&&ee.toUpperCase()!==s.toUpperCase())continue}L.push({id:z.setting_id,name:z.name,source:"cloud",isUser:z$e(z.setting_id)})}}if($?.filament)for(const z of $.filament){const V=`local_${z.id}`,ee=B===V;if(!(!ee&&j&&!z.name.toLowerCase().includes(j))){if(!ee&&s&&z.compatible_printers){const Z=z.compatible_printers.split(";").map(ne=>{const se=ne.trim(),ue=se.match(/^BBL\s+(.+)/i);return ue?ue[1].trim().toUpperCase():se.toUpperCase()}).filter(Boolean);if(Z.length>0&&!Z.includes(s.toUpperCase()))continue}L.push({id:V,name:z.name,source:"local",isUser:!1})}}if(W)for(const z of W){if(G.has(z.filament_id))continue;const V=z.filament_id.startsWith("GF")?"GFS"+z.filament_id.slice(2):z.filament_id;G.has(V)||(!j||z.name.toLowerCase().includes(j))&&L.push({id:`builtin_${z.filament_id}`,name:z.name,source:"builtin",isUser:!1})}return L.sort((z,V)=>{const ee={cloud:0,local:1,builtin:2};return z.source!==V.source?ee[z.source]-ee[V.source]:z.isUser&&!V.isUser?-1:!z.isUser&&V.isUser?1:z.name.localeCompare(V.name)})},[D?.filament,$?.filament,W,y,s,r.savedPresetId,r.trayInfoIdx]),X=w.useMemo(()=>{if(!d)return null;let j=null;if(d.startsWith("local_")){const B=parseInt(d.replace("local_",""),10);j=$?.filament.find(z=>z.id===B)?.name||null}else if(d.startsWith("builtin_")){const B=d.replace("builtin_","");j=W?.find(z=>z.filament_id===B)?.name||null}else D?.filament&&(j=D.filament.find(ie=>ie.setting_id===d)?.name||null);if(!j)return null;let L=j.replace(/@.+$/,"").trim();L.startsWith("# ")&&(L=L.slice(2).trim());const G=yG(L);return{fullName:L,material:G.material,brand:G.brand}},[d,D?.filament,$?.filament,W]),ae=X?.fullName||"",oe=w.useMemo(()=>{if(!J||!X)return[];const{fullName:j,brand:L}=X,G=j.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return J.filter(B=>{const ie=(B.material||"").toUpperCase(),z=B.manufacturer.toUpperCase();if(!(ie===G.toUpperCase()||ie.includes(G.toUpperCase())||G.toUpperCase().includes(ie)))return!1;if(L){const ee=L.toUpperCase();if(!z.includes(ee)&&!ee.includes(z))return!1}return!0})},[J,X]),ye=w.useMemo(()=>{if(!te?.profiles||!X)return[];const{fullName:j,material:L,brand:G}=X,B=j.toUpperCase(),ie=L.toUpperCase(),z=G.toUpperCase();if(!ie||ie.length<2)return[];const V=te.profiles.filter(Z=>{const ne=Z.name.toUpperCase();if(z)return!(!ne.includes(z)||!ne.includes(ie));if(ne.includes(B)||ne.includes(ie))return!0;const ue={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[ie]||[];for(const ge of ue)if(ne.includes(ge))return!0;return!1}),ee=new Map;for(const Z of V){const ne=`${Z.name}|${Z.k_value}`,se=ee.get(ne);se?r.extruderId!==void 0&&Z.extruder_id===r.extruderId&&se.extruder_id!==r.extruderId&&ee.set(ne,Z):ee.set(ne,Z)}return Array.from(ee.values())},[te?.profiles,X,r.extruderId]);w.useEffect(()=>{if(t){if(r.savedPresetId)u(r.savedPresetId);else if(r.trayInfoIdx&&D?.filament){let j=D.filament.find(L=>L.setting_id===r.trayInfoIdx);j||(j=D.filament.find(L=>U_(L.setting_id)===r.trayInfoIdx)),j&&u(j.setting_id)}else if(r.trayInfoIdx&&W?.length){const j=r.trayInfoIdx,L=W.find(G=>G.filament_id===j);L&&u(`builtin_${L.filament_id}`)}if(r.trayColor){const j=r.trayColor.slice(0,6);j&&x(j)}}else u(""),p(null),x(""),g(""),_(""),C(!1),k.current=""},[t,r.savedPresetId,r.trayInfoIdx,r.trayColor,D?.filament,W]),w.useEffect(()=>{if(ye.length>0){if(r.caliIdx!=null&&r.caliIdx>0){const j=ye.find(L=>L.slot_id===r.caliIdx);if(j){p(j);return}}p(ye[0])}else p(null)},[d,ye,r.caliIdx]);const Ee=w.useCallback(j=>{j.key==="Escape"&&e()},[e]);w.useEffect(()=>{if(t)return document.addEventListener("keydown",Ee),()=>document.removeEventListener("keydown",Ee)},[t,Ee]);const q=A&&!R||U||O||re;if(w.useEffect(()=>{if(!q&&d&&d!==k.current){const j=requestAnimationFrame(()=>{const G=document.querySelector('[class*="fixed inset-0 z-50"]')?.querySelector(`[data-preset-id="${CSS.escape(d)}"]`);G&&(k.current=d,G.scrollIntoView({block:"nearest"}))});return()=>cancelAnimationFrame(j)}},[d,q]),!t)return null;const K=d&&!le.isPending,E=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(cu,{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-white/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),i.jsx("span",{className:"text-white/70",children:c("configureAmsSlot.slotLabel",{ams:xG(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(zt,{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(Eb,{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-white/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),i.jsx("span",{className:"text-white font-medium",children:c("configureAmsSlot.slotLabel",{ams:xG(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&i.jsxs("span",{className:"text-bambu-gray",children:["(",r.traySubBrands,")"]})]})]}),q?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(lt,{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:y,onChange:j=>_(j.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:he.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:D?.filament?.length===0&&!$?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):he.map(j=>i.jsx("button",{"data-preset-id":j.id,onClick:()=>u(j.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${d===j.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:j.name}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[j.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")}),j.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")}),j.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")})]})]})},j.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})})]}),ye.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:j=>{const L=ye.find(G=>G.name===j.target.value);p(L||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")}),ye.map(j=>i.jsxs("option",{value:j.name,children:[j.name," (K=",j.k_value,")"]},`${j.name}-${j.extruder_id}`))]}),i.jsx(jn,{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")}),oe.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:X?.fullName})}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:oe.map(j=>i.jsxs("button",{onClick:()=>{const L=j.hex_color.replace("#","").toUpperCase();x(L),g(j.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===j.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:j.color_name,children:[i.jsx("span",{className:"w-4 h-4 rounded-full border border-white/30 flex-shrink-0",style:{backgroundColor:j.hex_color}}),i.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:j.color_name})]},j.id))})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[vG.map(j=>i.jsx("button",{onClick:()=>{x(j.hex),g(j.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===j.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${j.hex}`},title:j.name},j.hex)),i.jsx("button",{onClick:()=>P(!T),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(T?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:T?"−":"+"})]}),T&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:wG.map(j=>i.jsx("button",{onClick:()=>{x(j.hex),g(j.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===j.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${j.hex}`},title:j.name},j.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:`#${E}`}}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:j=>{const L=j.target.value;g(L);const G=SG(L);if(G)x(G);else{const B=L.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();B.length===6?x(B):B.length===3&&x(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:()=>{x(""),g("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),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:y,onChange:j=>_(j.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:he.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:D?.filament?.length===0&&!$?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):he.map(j=>i.jsx("button",{"data-preset-id":j.id,onClick:()=>u(j.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${d===j.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:j.name}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[j.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")}),j.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")}),j.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")})]})]})},j.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})})]}),ye.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:j=>{const L=ye.find(G=>G.name===j.target.value);p(L||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")}),ye.map(j=>i.jsxs("option",{value:j.name,children:[j.name," (K=",j.k_value,")"]},`${j.name}-${j.extruder_id}`))]}),i.jsx(jn,{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")}),oe.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:X?.fullName})}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:oe.map(j=>i.jsxs("button",{onClick:()=>{const L=j.hex_color.replace("#","").toUpperCase();x(L),g(j.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===j.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:j.color_name,children:[i.jsx("span",{className:"w-4 h-4 rounded-full border border-white/30 flex-shrink-0",style:{backgroundColor:j.hex_color}}),i.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:j.color_name})]},j.id))})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[vG.map(j=>i.jsx("button",{onClick:()=>{x(j.hex),g(j.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===j.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${j.hex}`},title:j.name},j.hex)),i.jsx("button",{onClick:()=>P(!T),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(T?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:T?"−":"+"})]}),T&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:wG.map(j=>i.jsx("button",{onClick:()=>{x(j.hex),g(j.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===j.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${j.hex}`},title:j.name},j.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:`#${E}`}}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:j=>{const L=j.target.value;g(L);const G=SG(L);if(G)x(G);else{const B=L.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();B.length===6?x(B):B.length===3&&x(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:()=>{x(""),g("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),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(Oe,{variant:"secondary",onClick:()=>me.mutate(),disabled:me.isPending||le.isPending,className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:me.isPending?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.resetting")]}):i.jsxs(i.Fragment,{children:[i.jsx(mo,{className:"w-4 h-4"}),c("configureAmsSlot.resetSlot")]})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{variant:"secondary",onClick:e,children:c("configureAmsSlot.cancel")}),i.jsx(Oe,{onClick:()=>le.mutate(),disabled:!K,children:le.isPending?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.configuring")]}):i.jsxs(i.Fragment,{children:[i.jsx(cu,{className:"w-4 h-4"}),c("configureAmsSlot.configureSlot")]})})]})]}),(le.isError||me.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:le.error?.message||me.error?.message})]})]})}function Yne({folderId:t,onClose:e,onUploadComplete:n,onFileUploaded:r,autoUpload:a,validateFile:s,accept:o}){const{t:l}=Mt(),[c,d]=w.useState([]),[u,m]=w.useState(!1),[p,f]=w.useState(!1),[x,v]=w.useState(!0),[g,y]=w.useState(!1),[_,N]=w.useState(!0),[C,T]=w.useState(null),P=w.useRef(null),k=he=>{he.preventDefault(),m(!0)},D=he=>{he.preventDefault(),m(!1)},A=he=>{he.preventDefault(),m(!1),W(Array.from(he.dataTransfer.files))},R=he=>{he.target.files&&W(Array.from(he.target.files))},$=(he,X)=>{d(ae=>ae.map(oe=>oe.file===he?{...oe,...X}:oe))},U=async he=>{f(!0);for(const X of he)if(X.status==="pending"){$(X.file,{status:"uploading"});try{if(X.isZip){const ae=await fe.extractZipFile(X.file,t,x,g,_);$(X.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(X.file,t,_);$(X.file,{status:"success"});const oe=r?.(ae);if(oe){T(oe),d([]),f(!1);return}}}catch(ae){$(X.file,{status:"error",error:ae instanceof Error?ae.message:l("fileManager.uploadFailed","Upload failed")})}}f(!1),n(),e()},W=he=>{if(T(null),s)for(const ae of he){const oe=s(ae);if(oe){T(oe);return}}const X=he.map(ae=>({file:ae,status:"pending",isZip:ae.name.toLowerCase().endsWith(".zip"),is3mf:ae.name.toLowerCase().endsWith(".3mf")}));d(ae=>[...ae,...X]),a&&he.length>0&&U(X)},O=he=>{d(X=>X.filter((ae,oe)=>oe!==he))},te=c.some(he=>he.isZip&&he.status==="pending"),re=c.some(he=>he.file.name.toLowerCase().endsWith(".stl")&&he.status==="pending"),J=c.some(he=>he.is3mf&&he.status==="pending"),le=c.filter(he=>he.status==="pending").length,me=c.length>0&&le===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(zt,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsxs("div",{onDragOver:k,onDragLeave:D,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(Si,{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:R}),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(Os,{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:x,onChange:he=>v(he.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:g,onChange:he=>y(he.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")})]})]})]})}),J&&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(_r,{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")})]})]})}),(re||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(lu,{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&&!re?"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:he=>N(he.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((he,X)=>i.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[he.isZip?i.jsx(Os,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):i.jsx(oC,{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:he.file.name}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[(he.file.size/1024/1024).toFixed(2)," MB",he.isZip&&he.status==="pending"&&i.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",l("fileManager.willBeExtracted")]}),he.extractedCount!==void 0&&i.jsxs("span",{className:"text-green-400 ml-2",children:["• ",l("fileManager.filesExtracted",{count:he.extractedCount})]})]})]}),he.status==="pending"&&i.jsx("button",{onClick:()=>O(X),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(zt,{className:"w-4 h-4 text-bambu-gray"})}),he.status==="uploading"&&i.jsx(lt,{className:"w-4 h-4 text-bambu-green animate-spin"}),he.status==="success"&&i.jsx(pr,{className:"w-4 h-4 text-green-500"}),he.status==="error"&&i.jsx("span",{title:he.error,children:i.jsx(Vi,{className:"w-4 h-4 text-red-500"})})]},X))}),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(Vi,{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(Oe,{variant:"secondary",onClick:e,children:l("common.cancel")}),!me&&i.jsx(Oe,{onClick:()=>U(c),disabled:le===0||p,children:p?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 mr-2 animate-spin"}),l("fileManager.uploading")]}):i.jsxs(i.Fragment,{children:[i.jsx(Si,{className:"w-4 h-4 mr-2"}),l("common.upload")," ",le>0?`(${le})`:""]})})]})]})})}function _G(t){return t?`#${t.replace("#","").substring(0,6)}`:"#808080"}function Oi(t){return t?t.replace("#","").toLowerCase().substring(0,6):""}function qc(t,e,n=40){const r=Oi(t),a=Oi(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 L4(t,e,n,r){if(r)return"External";const a=String.fromCharCode(65+(t>=128?t-128:t));return n?`HT-${a}`:`AMS-${a} Slot ${e+1}`}function sk(t,e,n){return n?254+e:t>=128?t:t*4+e}function NG(t){if(!t)return!1;const e=Date.now()+4320*60*60*1e3;return(er(t)?.getTime()??0)>e}function H$e(t,e,n){const r=Xne(e,t.nozzle_id),a=r.find(l=>!n.has(l.globalTrayId)&&l.type?.toUpperCase()===t.type?.toUpperCase()&&Oi(l.color)===Oi(t.color)),s=a?void 0:r.find(l=>!n.has(l.globalTrayId)&&l.type?.toUpperCase()===t.type?.toUpperCase()&&qc(l.color,t.color)),o=a||s?void 0:r.find(l=>!n.has(l.globalTrayId)&&l.type?.toUpperCase()===t.type?.toUpperCase());return a??s??o}function Xne(t,e){return t.filter(n=>e==null||n.extruderId===e)}function kT(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=_G(o.tray_color);e.push({type:o.tray_type,color:l,colorName:Rp(l),amsId:a.id,trayId:o.id,isHt:s,isExternal:!1,label:L4(a.id,o.id,s,!1),globalTrayId:sk(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=_G(a.tray_color),o=a.id??254,l=(t?.vt_tray?.length??0)>1;e.push({type:a.tray_type,color:s,colorName:Rp(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 kG(t,e){if(!t?.filaments||t.filaments.length===0)return;const n=kT(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(g=>g.trayInfoIdx===c);v.length===1?u=v[0]:v.length>1&&(m=v.find(g=>g.type?.toUpperCase()===l.type?.toUpperCase()&&Oi(g.color)===Oi(l.color)),m||(p=v.find(g=>g.type?.toUpperCase()===l.type?.toUpperCase()&&qc(g.color,l.color))),!m&&!p&&(f=v.find(g=>g.type?.toUpperCase()===l.type?.toUpperCase())))}!u&&!m&&!p&&!f&&(m=d.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&Oi(v.color)===Oi(l.color)),m||(p=d.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&qc(v.color,l.color))),!m&&!p&&(f=d.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase())));const x=u||m||p||f||void 0;return x&&r.add(x.globalTrayId),{slot_id:l.slot_id,globalTrayId:x?.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 $$e(t){return w.useMemo(()=>kT(t),[t])}function Qne(t,e,n){const r=$$e(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],k=r.find(D=>D.globalTrayId===P);if(k){const D=k.type?.toUpperCase()===d.type?.toUpperCase(),A=Oi(k.color)===Oi(d.color)||qc(k.color,d.color);let R;return D&&A?R="match":D?R="type_only":R="mismatch",{...d,loaded:k,hasFilament:!0,typeMatch:D,colorMatch:A,status:R,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,x,v,g;if(m){const P=p.filter(k=>k.trayInfoIdx===m);P.length===1?f=P[0]:P.length>1&&(x=P.find(k=>k.type?.toUpperCase()===d.type?.toUpperCase()&&Oi(k.color)===Oi(d.color)),x||(v=P.find(k=>k.type?.toUpperCase()===d.type?.toUpperCase()&&qc(k.color,d.color))),!x&&!v&&(g=P.find(k=>k.type?.toUpperCase()===d.type?.toUpperCase())))}!f&&!x&&!v&&!g&&(x=p.find(P=>P.type?.toUpperCase()===d.type?.toUpperCase()&&Oi(P.color)===Oi(d.color)),x||(v=p.find(P=>P.type?.toUpperCase()===d.type?.toUpperCase()&&qc(P.color,d.color))),!x&&!v&&(g=p.find(P=>P.type?.toUpperCase()===d.type?.toUpperCase())));const y=f||x||v||g||void 0;y&&c.add(y.globalTrayId);const _=!!y,N=_,C=!!f||!!x||!!v;let T;return f||x||v?T="match":g?T="type_only":T="mismatch",{...d,loaded:y,hasFilament:_,typeMatch:N,colorMatch:C,status:T,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 q$e(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 g=n[u],y=e.find(_=>_.globalTrayId===g);if(y){const _=y.type?.toUpperCase()===d.type?.toUpperCase(),N=Oi(y.color)===Oi(d.color)||qc(y.color,d.color);_&&N?r++:_?a++:s++;continue}}let m=e.filter(g=>!o.has(g.globalTrayId));if(d.nozzle_id!=null){const g=m.filter(y=>y.extruderId===d.nozzle_id);g.length>0&&(m=g)}const p=m.find(g=>g.type?.toUpperCase()===d.type?.toUpperCase()&&Oi(g.color)===Oi(d.color)),f=p?void 0:m.find(g=>g.type?.toUpperCase()===d.type?.toUpperCase()&&qc(g.color,d.color)),x=p||f?void 0:m.find(g=>g.type?.toUpperCase()===d.type?.toUpperCase()),v=p??f??x;v&&o.add(v.globalTrayId),p||f?r++:x?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 V$e(t,e,n){if(!t?.filaments||t.filaments.length===0)return;const r=kT(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(g=>g.extruderId===c.nozzle_id);v.length>0&&(u=v)}const m=u.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&Oi(v.color)===Oi(c.color)),p=m?void 0:u.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&qc(v.color,c.color)),f=m||p?void 0:u.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()),x=m??p??f;x&&a.add(x.globalTrayId),s.push({slot_id:d,globalTrayId:x?.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 CG={useDefault:!0,manualMappings:{},autoConfigured:!1};function G$e(t,e,n,r,a,s){const o=bf({queries:t.map(x=>({queryKey:["printer-status",x],queryFn:()=>fe.getPrinterStatus(x),enabled:t.length>0,staleTime:5e3}))}),l=w.useMemo(()=>t.map((x,v)=>{const g=o[v],y=g?.data,N=e?.find(R=>R.id===x)?.name||`Printer ${x}`,C=kT(y),T=a[x]||CG,P=kG(n,y),k=T.useDefault?r:T.manualMappings,D=V$e(n,y,k),A=q$e(n?.filaments,C,k);return{printerId:x,printerName:N,status:y,isLoading:g?.isLoading??!1,loadedFilaments:C,autoMapping:P,finalMapping:D,matchStatus:A.status,exactMatches:A.exactMatches,typeOnlyMatches:A.typeOnlyMatches,missingTypes:A.missingTypes,totalSlots:A.totalSlots,config:T}}),[t,o,e,n,a,r]),c=o.some(x=>x.isLoading),d=(x,v)=>{s(g=>({...g,[x]:{...g[x]||CG,...v}}))},u=x=>{const v=l.find(_=>_.printerId===x);if(!v||!v.status||!n?.filaments)return;const g=kG(n,v.status);if(!g)return;const y={};g.forEach((_,N)=>{_!==-1&&(y[N+1]=_)}),d(x,{useDefault:!1,manualMappings:y,autoConfigured:!0})},m=()=>{for(const x of t)u(x)},p=x=>l.find(g=>g.printerId===x)?.finalMapping,f=l.every(x=>x.matchStatus!=="missing");return{printerResults:l,isLoading:c,perPrinterConfigs:a,updatePrinterConfig:d,autoConfigureAll:m,autoConfigurePrinter:u,getFinalMapping:p,allPrintersReady:f}}const Zne={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$",CZK:"Kč",THB:"฿",ZAR:"R",TRY:"₺",RUB:"₽",HUF:"Ft"};function ol(t){return Zne[t.toUpperCase()]||t}const W$e=Object.entries(Zne).map(([t,e])=>({code:t,label:`${t} (${e})`}));function K$e({printerId:t,filamentReqs:e,manualMappings:n,onManualMappingChange:r,currencySymbol:a,defaultCostPerKg:s,defaultExpanded:o=!1}){const{t:l}=Mt(),c=Zt(),[d,u]=w.useState(!1),[m,p]=w.useState(o),{data:f}=Ze({queryKey:["printer-status",t],queryFn:()=>fe.getPrinterStatus(t),enabled:!!t}),{data:x}=Ze({queryKey:["spool-assignments",t],queryFn:()=>fe.getAssignments(t),enabled:!!t}),{loadedFilaments:v,filamentComparison:g,hasTypeMismatch:y,hasColorMismatch:_}=Qne(e,f,n),N=w.useMemo(()=>{const U=new Map;for(const W of x||[]){const O=W.ams_id===255,te=sk(W.ams_id,W.tray_id,O);U.set(te,W.spool?.cost_per_kg??null)}return U},[x]),C=w.useMemo(()=>{const U=new Map;for(const W of x||[]){const O=W.ams_id===255,te=sk(W.ams_id,W.tray_id,O),re=W.spool;if(!re){U.set(te,null);continue}U.set(te,Math.max(0,Math.round((re.label_weight??0)-(re.weight_used??0))))}return U},[x]),T=w.useMemo(()=>{let U=0;for(const W of g){const O=W.loaded?.globalTrayId;if(O==null)continue;const re=N.get(O)??null??s;re>0&&(U+=W.used_grams/1e3*re)}return U},[g,N,s]),P=w.useMemo(()=>Array.from(N.values()).some(U=>U!=null&&U>0),[N]),k=e?.filaments&&e.filaments.length>0,D=e?.filaments?.some(U=>U.nozzle_id!=null)??!1;if(!k||!f)return null;const A=y?"#f97316":_?"#facc15":"#00ae42",R=(U,W)=>{if(U>0)if(W===""){const O={...n};delete O[U],r(O)}else r({...n,[U]:parseInt(W,10)})},$=async()=>{u(!0);try{await fe.refreshPrinterStatus(t),await new Promise(U=>setTimeout(U,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(z1,{className:"w-4 h-4",fill:A,stroke:"none"}),i.jsx("span",{children:l("printModal.filamentMapping")}),y?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(Sl,{className:"w-4 h-4 ml-auto"}):i.jsx(jn,{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:$,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(Sr,{className:`w-3 h-3 ${d?"animate-spin":""}`}),i.jsx("span",{children:"Re-read"})]})]}),g.map((U,W)=>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: ${U.type} - ${Rp(U.color)}`,children:i.jsx(z1,{className:"w-3 h-3",fill:U.color,stroke:U.color})}),i.jsxs("span",{className:"text-white truncate flex items-center gap-1",children:[D&&U.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:U.nozzle_id===1?l("printModal.leftNozzleTooltip"):l("printModal.rightNozzleTooltip"),children:U.nozzle_id===1?l("printModal.leftNozzle"):l("printModal.rightNozzle")}),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:U.loaded?.globalTrayId??"",onChange:O=>R(U.slot_id||0,O.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 ${U.status==="match"?"border-bambu-green/50 text-bambu-green":U.status==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${U.isManual?"ring-1 ring-blue-400/50":""}`,title:U.isManual?"Manually selected":"Auto-matched",children:[i.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),v.filter(O=>U.nozzle_id==null||O.extruderId===U.nozzle_id).map(O=>{const te=C.get(O.globalTrayId),re=te!=null?l("printModal.slotRemainingShort",{grams:te,defaultValue:` - ${te}g left`}):"";return i.jsxs("option",{value:O.globalTrayId,className:"bg-bambu-dark text-white",children:[O.label,": ",O.traySubBrands||O.type," (",O.colorName,")",re]},O.globalTrayId)})]}),U.status==="match"?i.jsx(Vr,{className:"w-3 h-3 text-bambu-green"}):U.status==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(Cn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(Cn,{className:"w-3 h-3 text-orange-400"})})]},W)),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[l("printModal.totalCost")," ",i.jsx("span",{className:"text-white",children:T>0||P?`${a}${T.toFixed(2)}`:"N/A"})]}),y&&i.jsx("p",{className:"text-xs text-orange-400 mt-2",children:"Required filament type not found in printer."})]})]})}function Y$e({filamentReqs:t,availableFilaments:e,overrides:n,onChange:r}){const{t:a}=Mt(),s=w.useMemo(()=>{const c={};for(const d of e){const u=d.type.toUpperCase();c[u]||(c[u]=[]),c[u].push(d)}return c},[e]),o=t?.filaments;if(!o||o.length===0||e.length===0)return null;const l=(c,d)=>{if(d===""){const u={...n};delete u[c],r(u)}else{const[u,m]=d.split("|");r({...n,[c]:{type:u,color:m}})}};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:a("printModal.filamentOverride")})}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:a("printModal.filamentOverrideHint")}),i.jsx("div",{className:"bg-bambu-dark rounded-lg p-3 space-y-2",children:o.map(c=>{const d=n[c.slot_id],u=!!d,m=s[c.type.toUpperCase()]||[],p=c.nozzle_id!=null?m.filter(f=>f.extruder_id==null||f.extruder_id===c.nozzle_id):m;return 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:`${a("printModal.originalFilament")}: ${c.type} - ${Rp(c.color)}`,children:i.jsx(z1,{className:"w-3 h-3",fill:c.color,stroke:c.color})}),i.jsxs("span",{className:"text-white truncate",children:[c.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",c.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:u?`${d.type}|${d.color}`:"",onChange:f=>l(c.slot_id,f.target.value),disabled:p.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 ${u?"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:[a("printModal.originalFilament"),": ",c.type," (",Rp(c.color),")"]}),p.map((f,x)=>i.jsxs("option",{value:`${f.type}|${f.color}`,className:"bg-bambu-dark text-white",children:[f.tray_sub_brands||f.type," (",Rp(f.color),")"]},`${f.type}-${f.color}-${f.tray_sub_brands}-${x}`))]}),u?i.jsx("button",{type:"button",onClick:()=>l(c.slot_id,""),className:"text-bambu-gray hover:text-white transition-colors",title:a("printModal.resetToOriginal"),children:i.jsx(mo,{className:"w-3 h-3"})}):i.jsx("span",{className:"w-3"})]},c.slot_id)})})]})}function X$e({plates:t,isMultiPlate:e,selectedPlate:n,onSelect:r}){return!e||t.length<=1?null:i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx(Gi,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:"Select Plate to Print"}),!n&&i.jsxs("span",{className:"text-xs text-orange-400 flex items-center gap-1",children:[i.jsx(Cn,{className:"w-3 h-3"}),"Selection required"]})]}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map(a=>i.jsxs("button",{type:"button",onClick:()=>r(a.index),className:`flex items-center gap-2 p-2 rounded-lg border transition-colors text-left ${n===a.index?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"}`,children:[a.has_thumbnail&&a.thumbnail_url!=null?i.jsx("img",{src:a.thumbnail_url,alt:`Plate ${a.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(Gi,{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:a.name||`Plate ${a.index}`}),i.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[a.objects.length>0?a.objects.slice(0,3).join(", ")+(a.objects.length>3?"...":""):`${a.filaments.length} filament${a.filaments.length!==1?"s":""}`,a.print_time_seconds!=null?` • ${js(a.print_time_seconds)}`:""]})]}),n===a.index&&i.jsx(Vr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]},a.index))})]})}const Q$e=new Set(["IDLE","FINISH","FAILED"]);function Z$e({printerResult:t,filamentReqs:e,onUpdateConfig:n}){const r=Zt(),[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=H$e(d,t.loadedFilaments,v)}let x="mismatch";if(p){const v=p.type?.toUpperCase()===d.type?.toUpperCase(),g=Oi(p.color)===Oi(d.color)||qc(p.color,d.color);v&&g?x="match":v&&(x="type_only")}return{req:d,loaded:p,status:x,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(Sr,{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} - ${Rp(d.color)}`,children:i.jsx(z1,{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:x=>o(d.slot_id||0,x.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 --"}),Xne(t.loadedFilaments,d.nozzle_id).map(x=>i.jsxs("option",{value:x.globalTrayId,className:"bg-bambu-dark text-white",children:[x.label,": ",x.traySubBrands||x.type," (",x.colorName,")"]},x.globalTrayId))]}),m==="match"?i.jsx(Vr,{className:"w-3 h-3 text-bambu-green"}):m==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(Cn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(Cn,{className:"w-3 h-3 text-orange-400"})})]},f))]})}function J$e({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:x,targetLocation:v,onTargetLocationChange:g,slicedForModel:y}){const[_,N]=w.useState(!1),C=s?t:t.filter(ae=>ae.is_active),T=bf({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((oe,ye)=>{const Ee=T[ye];Ee?.data&&ae.set(oe.id,Ee.data)}),ae},[C,T]),k=ae=>{const oe=P.get(ae);return oe?oe.connected?!Q$e.has(oe.state??""):!0:!1},D=ae=>{const oe=P.get(ae);if(!oe)return null;if(!oe.connected)return"Offline";const ye=oe.state;return ye?ye==="RUNNING"?oe.stg_cur_name||"Printing":ye==="PREPARE"?"Preparing":ye==="PAUSE"?"Paused":ye==="IDLE"?"Idle":ye==="FINISH"?"Finished":ye==="FAILED"?"Failed":ye:null},A=w.useMemo(()=>{if(m!=="printer"||!y||_)return C;const ae=C.filter(oe=>oe.model===y);return ae.length>0?ae:C},[C,m,y,_]),R=C.length-A.length,$=w.useMemo(()=>{const ae=C.map(oe=>oe.model).filter(oe=>!!oe);return[...new Set(ae)].sort()},[C]),U=w.useMemo(()=>{if(!f)return[];const ae=C.filter(oe=>oe.model===f&&oe.location).map(oe=>oe.location).filter(oe=>!!oe);return[...new Set(ae)].sort()},[C,f]),W=p&&x&&$.length>0,O=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(lt,{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(zi,{className:"w-4 h-4"}),"No ",s?"":"active ","printers available"]});const te=ae=>{o&&k(ae)||(a?e.includes(ae)?n(e.filter(oe=>oe!==ae)):n([...e,ae]):n([ae]))},re=()=>{const ae=o?A.filter(oe=>!k(oe.id)):A;n(ae.map(oe=>oe.id))},J=()=>{n([])},le=(ae,oe,ye)=>{ye.stopPropagation(),!(!d||!u)&&(oe?d(ae):u(ae,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},me=ae=>e.includes(ae),he=e.length,X=ae=>l?.find(oe=>oe.printerId===ae);return i.jsxs("div",{className:"space-y-2 mb-6",children:[W&&i.jsxs("div",{className:"flex gap-2 mb-4",children:[i.jsxs("button",{type:"button",onClick:()=>{p("printer"),x(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(_r,{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=y&&$.includes(y)?y:$[0];x(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(Sm,{className:"w-4 h-4"}),i.jsxs("span",{className:"text-sm",children:["Any ",y||"Model"]})]})]}),m==="model"&&W&&i.jsxs("div",{className:"space-y-3 mb-4",children:[!y&&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=>{x(ae.target.value||null),g&&g(null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",children:[i.jsx("option",{value:"",children:"Select a model..."}),$.map(ae=>i.jsx("option",{value:ae,children:ae},ae))]})]}),f&&U.length>0&&g&&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=>g(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"}),U.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:he===0?"Select printers":`${he} printer${he!==1?"s":""} selected`}),i.jsxs("div",{className:"flex gap-2",children:[he0&&i.jsx("button",{type:"button",onClick:J,className:"text-bambu-gray hover:text-white transition-colors",children:"Clear"})]})]}),m==="printer"&&A.map(ae=>{const oe=me(ae.id),ye=X(ae.id),Ee=ye&&!ye.config.useDefault,q=k(ae.id),K=o&&q,E=D(ae.id);return i.jsxs("div",{children:[i.jsxs("button",{type:"button",onClick:()=>te(ae.id),disabled:K,className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${K?"border-bambu-dark-tertiary bg-bambu-dark opacity-50 cursor-not-allowed":oe?"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 ${K?"bg-bambu-dark-tertiary":oe?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:i.jsx(_r,{className:`w-5 h-5 ${K?"text-bambu-gray/50":oe?"text-bambu-green":"text-bambu-gray"}`})}),i.jsxs("div",{className:"text-left flex-1",children:[i.jsxs("p",{className:`font-medium ${K?"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]})]}),E&&i.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${q?"bg-yellow-500/20 text-yellow-400":"bg-bambu-green/20 text-bambu-green"}`,children:E}),a&&i.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${K?"border-bambu-gray/30":oe?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:oe&&i.jsx(Vr,{className:"w-3 h-3 text-white"})})]}),oe&&O&&ye&&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:j=>j.stopPropagation(),children:[i.jsx("input",{type:"checkbox",checked:Ee,onChange:j=>le(ae.id,j.target.checked,j),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 ${ye.matchStatus==="full"?"text-bambu-green":ye.matchStatus==="partial"?"text-yellow-400":"text-orange-400"}`,children:["(",ye.exactMatches,"/",ye.totalSlots," matched)"]}),ye.isLoading&&i.jsx(Sr,{className:"w-3 h-3 text-bambu-gray animate-spin"}),Ee&&i.jsxs("button",{type:"button",onClick:j=>{j.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(Uge,{className:"w-3 h-3"}),"Auto"]})]}),Ee&&i.jsx(Z$e,{printerResult:ye,filamentReqs:c.filaments,onUpdateConfig:j=>u(ae.id,j)})]})]},ae.id)}),m==="printer"&&R>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(Cn,{className:"w-3 h-3 text-yellow-400"}),R," other printer",R>1?"s":""," hidden (different model) —",i.jsx("span",{className:"underline",children:"show all"})]}),m==="printer"&&_&&y&&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 ",y," printers"]})}),m==="printer"&&he===0&&i.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[i.jsx(zi,{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(zi,{className:"w-3 h-3"}),"Select a target printer model"]})]})}const eqe=[{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 tqe({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(gC,{className:"w-4 h-4"}),i.jsx("span",{children:"Print Options"}),r?i.jsx(Sl,{className:"w-4 h-4 ml-auto"}):i.jsx(jn,{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:eqe.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 nqe({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),x=w.useRef(!1);w.useEffect(()=>{if(t.scheduleType!=="scheduled"){x.current=!1;return}if(!x.current){x.current=!0;let T;t.scheduledTime?(T=new Date(t.scheduledTime),isNaN(T.getTime())&&(T=new Date,T.setHours(T.getHours()+1,0,0,0))):(T=new Date,T.setHours(T.getHours()+1,0,0,0),e({...t,scheduledTime:jD(T)})),o(ED(T,n)),c(c8(T,r)),u(!0),p(!0)}},[t.scheduleType,t.scheduledTime,n,r,e,t]);const v=T=>{e({...t,scheduleType:T})},g=(T,P)=>{const k=dbe(T,n),D=ube(P);u(!!k),p(!!D),k&&D&&(k.setHours(D.hours,D.minutes,0,0),k>new Date&&e({...t,scheduledTime:jD(k)}))},y=T=>{o(T),g(T,l)},_=T=>{c(T),g(s,T)},N=T=>{const P=T.target.value;if(P){const k=new Date(P);isNaN(k.getTime())||(o(ED(k,n)),c(c8(k,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(Xn,{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(WY,{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:T=>y(T.target.value),placeholder:obe(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:T=>_(T.target.value),placeholder:lbe(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:T=>e({...t,requirePreviousSuccess:T.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:T=>e({...t,autoOffAfter:T.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(Su,{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 qg={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1},rqe={scheduleType:"asap",scheduledTime:"",requirePreviousSuccess:!1,autoOffAfter:!1};function Vc({mode:t,archiveId:e,libraryFileId:n,archiveName:r,queueItem:a,initialSelectedPrinterIds:s,onClose:o,onSuccess:l}){const{t:c}=Mt(),d=Zt(),{showToast:u}=hn(),{hasPermission:m}=Dr(),p=!!n&&!e,[f,x]=w.useState(()=>t==="edit-queue-item"&&a?.printer_id?[a.printer_id]:s?.length?s:[]),[v,g]=w.useState(()=>t==="edit-queue-item"&&a?a.plate_id:null),[y,_]=w.useState(()=>t==="edit-queue-item"&&a?{bed_levelling:a.bed_levelling??qg.bed_levelling,flow_cali:a.flow_cali??qg.flow_cali,vibration_cali:a.vibration_cali??qg.vibration_cali,layer_inspect:a.layer_inspect??qg.layer_inspect,timelapse:a.timelapse??qg.timelapse}:qg),[N,C]=w.useState(()=>{if(t==="edit-queue-item"&&a){let we="asap";a.manual_start?we="manual":a.scheduled_time&&!NG(a.scheduled_time)&&(we="scheduled");let Ge="";if(a.scheduled_time&&!NG(a.scheduled_time)){const rt=er(a.scheduled_time)??new Date;Ge=jD(rt)}return{scheduleType:we,scheduledTime:Ge,requirePreviousSuccess:a.require_previous_success,autoOffAfter:a.auto_off_after}}return rqe}),[T,P]=w.useState(()=>{if(t==="edit-queue-item"&&a?.ams_mapping&&Array.isArray(a.ams_mapping)){const we={};return a.ams_mapping.forEach((Ge,rt)=>{Ge!==-1&&(we[rt+1]=Ge)}),we}return{}}),[k,D]=w.useState({}),[A,R]=w.useState(()=>t==="edit-queue-item"&&a?.target_model?"model":"printer"),[$,U]=w.useState(()=>t==="edit-queue-item"&&a?.target_model?a.target_model:null),[W,O]=w.useState(()=>t==="edit-queue-item"&&a?.target_location?a.target_location:null),[te,re]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const we={};for(const Ge of a.filament_overrides)we[Ge.slot_id]={type:Ge.type,color:Ge.color};return we}return{}}),[J]=w.useState(()=>t==="edit-queue-item"&&a?.printer_id?[a.printer_id]:[]),[le]=w.useState(()=>t==="edit-queue-item"&&a?a.plate_id:null),[me,he]=w.useState(!1),[X,ae]=w.useState({current:0,total:0}),[oe,ye]=w.useState(new Set),Ee=f.length,q=f.length>0?f[0]:null,{data:K}=Ze({queryKey:["settings"],queryFn:fe.getSettings}),E=ol(K?.currency||"USD"),j=K?.default_filament_cost??0,{data:L,isLoading:G}=Ze({queryKey:["printers"],queryFn:fe.getPrinters}),{data:B}=Ze({queryKey:["archive",e],queryFn:()=>fe.getArchive(e),enabled:!!e&&!p}),{data:ie}=Ze({queryKey:["library-file",n],queryFn:()=>fe.getLibraryFile(n),enabled:p&&!!n}),z=B?.sliced_for_model||ie?.sliced_for_model||null,{data:V,isError:ee}=Ze({queryKey:["archive-plates",e],queryFn:()=>fe.getArchivePlates(e),enabled:!!e&&!p,retry:!1}),{data:Z}=Ze({queryKey:["library-file-plates",n],queryFn:()=>fe.getLibraryFilePlates(n),enabled:p&&!!n}),ne=p?Z:V,{data:se,isError:ue}=Ze({queryKey:["archive-filaments",e,v],queryFn:()=>fe.getArchiveFilamentRequirements(e,v??void 0),enabled:!!e&&!p&&(v!==null||!ne?.is_multi_plate),retry:!1}),{data:ge}=Ze({queryKey:["library-file-filaments",n,v],queryFn:()=>fe.getLibraryFileFilamentRequirements(n,v??void 0),enabled:p&&!!n&&(v!==null||!ne?.is_multi_plate)}),ce=!p&&(ee||ue),I=p?ge:se,F=w.useMemo(()=>{if(!(v===null||!ne?.plates?.length))return ne.plates.find(we=>we.index===v)?.name||void 0},[ne,v]),{data:Q}=Ze({queryKey:["available-filaments",$,W],queryFn:()=>fe.getAvailableFilaments($,W??void 0),enabled:A==="model"&&!!$}),{data:xe}=Ze({queryKey:["printer-status",q],queryFn:()=>fe.getPrinterStatus(q),enabled:!!q}),{amsMapping:pe}=Qne(I,xe,T),de=G$e(f,L,I,T,k,D);w.useEffect(()=>{ne?.plates&&ne.plates.length>=1&&!v&&g(ne.plates[0].index)},[ne,v]),w.useEffect(()=>{if(t==="edit-queue-item")return;const we=L?.filter(Ge=>Ge.is_active)||[];we.length===1&&f.length===0&&x([we[0].id])},[t,L,f.length]),w.useEffect(()=>{t==="edit-queue-item"?(JSON.stringify(f.sort())!==JSON.stringify(J.sort())||v!==le)&&(P({}),D({}),ye(new Set)):(P({}),D({}),ye(new Set))},[t,f,v,J,le]);const[Ae,_e]=w.useState($),[Ue,$e]=w.useState(v);w.useEffect(()=>{($!==Ae||v!==Ue)&&(_e($),$e(v),(t!=="edit-queue-item"||Ae!==null)&&re({}))},[$,v,Ae,Ue,t]),w.useEffect(()=>{if(!K?.per_printer_mapping_expanded||f.length<=1)return;const we=f.filter(Ge=>{if(oe.has(Ge))return!1;const rt=de.printerResults.find(vt=>vt.printerId===Ge);return rt&&rt.status&&!rt.isLoading});we.length>0&&(ye(Ge=>{const rt=new Set(Ge);return we.forEach(vt=>rt.add(vt)),rt}),we.forEach(Ge=>{de.autoConfigurePrinter(Ge)}))},[K?.per_printer_mapping_expanded,f,oe,de]),w.useEffect(()=>{const we=Ge=>{Ge.key==="Escape"&&!me&&o()};return window.addEventListener("keydown",we),()=>window.removeEventListener("keydown",we)},[o,me]);const Fe=ne?.is_multi_plate??!1,ke=ne?.plates??[],Me=dt({mutationFn:we=>fe.addToQueue(we)}),Ne=dt({mutationFn:we=>fe.updateQueueItem(a.id,we),onSuccess:()=>{d.invalidateQueries({queryKey:["queue"]}),u("Queue item updated"),l?.(),o()},onError:we=>{u(we.message||"Failed to update queue item","error")}}),Pe=async we=>{if(we?.preventDefault(),A==="printer"&&f.length===0){u("Please select at least one printer","error");return}if(A==="model"&&!$){u("Please select a target printer model","error");return}he(!0);const Ge=A==="model"?1:f.length;ae({current:0,total:Ge});const rt={success:0,failed:0,errors:[]},vt=qe=>{if(f.length>1){const ht=k[qe];if(ht&&!ht.useDefault)return de.getFinalMapping(qe)}return pe},_t=Object.keys(te).length>0?Object.entries(te).map(([qe,{type:ht,color:ft}])=>({slot_id:parseInt(qe,10),type:ht,color:ft})):void 0,kt=qe=>({printer_id:A==="printer"?qe:null,target_model:A==="model"?$:null,target_location:A==="model"?W:null,filament_overrides:A==="model"?_t:void 0,archive_id:p?void 0:e,library_file_id:p?n:void 0,require_previous_success:N.requirePreviousSuccess,auto_off_after:N.autoOffAfter,manual_start:N.scheduleType==="manual",ams_mapping:qe?vt(qe):void 0,plate_id:v,scheduled_time:N.scheduleType==="scheduled"&&N.scheduledTime?new Date(N.scheduledTime).toISOString():void 0,...y});if(A==="model"){ae({current:1,total:1});try{if(t==="reprint"){u("Model-based assignment only works with queue mode","error"),he(!1);return}else if(t==="edit-queue-item"){const qe={printer_id:null,target_model:$,target_location:W,filament_overrides:_t||null,require_previous_success:N.requirePreviousSuccess,auto_off_after:N.autoOffAfter,manual_start:N.scheduleType==="manual",ams_mapping:void 0,plate_id:v,scheduled_time:N.scheduleType==="scheduled"&&N.scheduledTime?new Date(N.scheduledTime).toISOString():null,...y};await Ne.mutateAsync(qe)}else await Me.mutateAsync(kt(null));rt.success++}catch(qe){rt.failed++,rt.errors.push(qe.message)}}else for(let qe=0;qetn.id===ht)?.name||`Printer ${ht}`;rt.errors.push(`${Bt}: ${ft.message}`)}}he(!1),rt.failed===0?(t!=="reprint"&&(A==="model"?u(t==="edit-queue-item"?"Queue item updated":`Queued for any ${$}`):t==="edit-queue-item"?u("Queue item updated"):rt.success===1?u("Print queued for printer"):u(`Print queued for ${rt.success} printers`)),d.invalidateQueries({queryKey:["queue"]}),l?.(),o()):rt.success===0?u(`Failed: ${rt.errors[0]}`,"error"):(u(`${rt.success} succeeded, ${rt.failed} failed`,"error"),d.invalidateQueries({queryKey:["queue"]}))},We=me||Ne.isPending,be=w.useMemo(()=>!(We||A==="printer"&&f.length===0||A==="model"&&!$||A==="model"&&t==="reprint"||Fe&&!v),[f.length,A,$,t,Fe,v,We]),Ce=(()=>{const we=f.length;return t==="reprint"?{title:c(p?"queue.print":"queue.reprint"),icon:_r,submitText:we>1?c("queue.printToPrinters",{count:we}):c("queue.print"),submitIcon:_r,loadingText:X.total>1?c("queue.sendingProgress",{current:X.current,total:X.total}):c("queue.sending")}:t==="add-to-queue"?{title:c("queue.schedulePrint"),icon:Xr,submitText:we>1?c("queue.queueToPrinters",{count:we}):c("queue.addToQueue"),submitIcon:Xr,loadingText:X.total>1?c("queue.addingProgress",{current:X.current,total:X.total}):c("queue.adding")}:{title:c("queue.editQueueItem"),icon:Ki,submitText:c("common.save"),submitIcon:Ki,loadingText:X.total>1?c("queue.savingProgress",{current:X.current,total:X.total}):c("common.saving")}})(),Ve=Ce.icon,je=Ce.submitIcon,Re=q&&(p||(Fe?v!==null:!0));return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:me?void 0:o,children:i.jsx(Tt,{className:"w-full max-w-2xl max-h-[90vh] overflow-y-auto",onClick:we=>we.stopPropagation(),children:i.jsxs(Pt,{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(Ve,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:Ce.title})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:o,disabled:me,children:i.jsx(zt,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:Pe,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&&L?i.jsx("span",{className:"text-white",children:L.find(we=>we.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(X$e,{plates:ke,isMultiPlate:Fe,selectedPlate:v,onSelect:g}),!s?.length&&i.jsx(J$e,{printers:L||[],selectedPrinterIds:f,onMultiSelect:x,isLoading:G,allowMultiple:!0,showInactive:t==="edit-queue-item",disableBusy:t==="reprint",printerMappingResults:de.printerResults,filamentReqs:I,onAutoConfigurePrinter:de.autoConfigurePrinter,onUpdatePrinterConfig:de.updatePrinterConfig,assignmentMode:t==="reprint"?"printer":A,onAssignmentModeChange:t!=="reprint"?R:void 0,targetModel:$,onTargetModelChange:t!=="reprint"?U:void 0,targetLocation:W,onTargetLocationChange:t!=="reprint"?O:void 0,slicedForModel:z}),A==="model"&&$&&I&&Q&&Q.length>0&&i.jsx(Y$e,{filamentReqs:I,availableFilaments:Q,overrides:te,onChange:re}),z&&A==="printer"&&f.length===1&&(()=>{const we=L?.find(Ge=>Ge.id===f[0]);return we&&we.model&&z!==we.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(Cn,{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 ",z,", but printing on ",we.model]})]}):null})(),ce&&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(zi,{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."})]}),Re&&!ce&&f.length===1&&i.jsx(K$e,{printerId:q,filamentReqs:I,manualMappings:T,onManualMappingChange:P,defaultExpanded:!!s?.length||(K?.per_printer_mapping_expanded??!1),currencySymbol:E,defaultCostPerKg:j}),(t==="reprint"||Ee>0||A==="model"&&$)&&i.jsx(tqe,{options:y,onChange:_,defaultExpanded:!!s?.length}),t!=="reprint"&&i.jsx(nqe,{options:N,onChange:C,dateFormat:K?.date_format||"system",timeFormat:K?.time_format||"system",canControlPrinter:m("printers:control")}),Ne.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:Ne.error?.message||"Failed to complete operation"}),i.jsxs("div",{className:`flex gap-3 ${t==="reprint"?"":"pt-2"}`,children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:o,className:"flex-1",disabled:me,children:"Cancel"}),i.jsx(Oe,{type:"submit",disabled:!be,className:"flex-1",children:We?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),Ce.loadingText]}):i.jsxs(i.Fragment,{children:[i.jsx(je,{className:"w-4 h-4"}),Ce.submitText]})})]})]})]})})})}function Jne(t){if(!t)return"/img/printers/default.png";const e=t.toLowerCase().replace(/\s+/g,"");return e.includes("x1e")?"/img/printers/x1e.png":e.includes("x1c")||e.includes("x1carbon")||e.includes("x1")?"/img/printers/x1c.png":e.includes("h2dpro")||e.includes("h2d-pro")?"/img/printers/h2dpro.png":e.includes("h2d")?"/img/printers/h2d.png":e.includes("h2c")?"/img/printers/h2c.png":e.includes("h2s")?"/img/printers/h2d.png":e.includes("p2s")||e.includes("p1s")?"/img/printers/p1s.png":e.includes("p1p")?"/img/printers/p1p.png":e.includes("a1mini")?"/img/printers/a1mini.png":e.includes("a1")?"/img/printers/a1.png":"/img/printers/default.png"}function ere(t){return t>=-50?{labelKey:"printers.wifiSignal.excellent",color:"text-bambu-green",bars:4}:t>=-60?{labelKey:"printers.wifiSignal.good",color:"text-bambu-green",bars:3}:t>=-70?{labelKey:"printers.wifiSignal.fair",color:"text-yellow-400",bars:2}:t>=-80?{labelKey:"printers.wifiSignal.weak",color:"text-orange-400",bars:1}:{labelKey:"printers.wifiSignal.veryWeak",color:"text-red-400",bars:1}}function TG({value:t}){const{t:e}=Mt(),[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(Vr,{className:"w-3.5 h-3.5 text-bambu-green"}):i.jsx(_l,{className:"w-3.5 h-3.5"})})}function iqe({printer:t,status:e,totalPrintHours:n,onClose:r}){const{t:a}=Mt();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(TG,{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(TG,{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(GF,{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=ere(e.wifi_signal);s.push({label:a("printers.wifiSignalLabel"),value:i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(ZY,{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:Wp(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(Tt,{className:"w-full max-w-md",onClick:o=>o.stopPropagation(),children:i.jsxs(Pt,{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(zt,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsx("div",{className:"flex justify-center mb-4",children:i.jsx("img",{src:Jne(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 aqe(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 sj({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&&aqe(t)?"#000":"#fff"},children:r})})}const PG={"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"},sqe={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 oj(t){if(!t)return null;if(PG[t])return PG[t];const e=t.split("-");if(e.length<2)return null;const n=e[1];return sqe[n]||null}function lj(t){return(t??.02).toFixed(3)}function AG({side:t}){const{mode:e}=xf(),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 tre(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 nre(t,e){return t?t.startsWith("HH")?e("printers.nozzleHighFlow"):t.startsWith("HS")?e("printers.nozzleStandardFlow"):"":""}function rre({slot:t,index:e,activeStatus:n,filamentName:r,children:a}){const{t:s}=Mt(),[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,x=t.stat===1;w.useEffect(()=>{if(o&&u.current&&m.current){const C=u.current.getBoundingClientRect(),T=m.current.offsetHeight,k=C.top-56,D=window.innerHeight-C.bottom;kk?d("bottom"):d("top")}},[o]);const v=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>l(!0),80)},g=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>l(!1),100)};w.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const y=F4(t.filament_color),_=tre(t.nozzle_type,s),N=nre(t.nozzle_type,s);return i.jsxs("div",{ref:u,className:"relative",onMouseEnter:v,onMouseLeave:g,children:[a,o&&i.jsxs("div",{ref:m,className:` + `})]})]})}function O$e({isOpen:t,onClose:e,tagUid:n,trayUuid:r,printerId:a,amsId:s,trayId:o}){const{t:l}=Mt(),c=Zt(),{showToast:d}=hn(),[u,m]=w.useState(""),{data:p,isLoading:f}=Ze({queryKey:["inventory-spools"],queryFn:()=>fe.getSpools(!1),enabled:t}),x=w.useMemo(()=>p?p.filter(g=>{if(g.tag_uid||g.tray_uuid)return!1;if(!u)return!0;const y=u.toLowerCase();return g.material.toLowerCase().includes(y)||g.brand&&g.brand.toLowerCase().includes(y)||g.color_name&&g.color_name.toLowerCase().includes(y)}):[],[p,u]),v=dt({mutationFn:g=>fe.linkTagToSpool(g,{tag_uid:n||void 0,tray_uuid:r||void 0,tag_type:r?"bambulab":"generic",data_origin:"nfc_link"}),onSuccess:()=>{c.invalidateQueries({queryKey:["inventory-spools"]}),c.invalidateQueries({queryKey:["inventory-assignments"]}),d(l("inventory.tagLinked"),"success"),e()},onError:g=>{d(g.message||l("inventory.tagLinkFailed"),"error")}});return t?i.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),i.jsxs("div",{className:"relative bg-bambu-dark-secondary rounded-xl shadow-xl w-full max-w-md mx-4 max-h-[80vh] flex flex-col border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[i.jsxs("div",{children:[i.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(dx,{className:"w-5 h-5 text-bambu-green"}),l("inventory.linkToSpool")]}),i.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["AMS ",s," T",o," · Printer #",a]})]}),i.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(zt,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-4 border-b border-white/10",children:[i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:u,onChange:g=>m(g.target.value),placeholder:l("inventory.searchSpools"),className:"w-full pl-9 pr-3 py-2 bg-bambu-dark rounded-lg border border-white/10 text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green"})]}),(n||r)&&i.jsxs("p",{className:"text-xs text-bambu-gray mt-2 font-mono truncate",title:n||r,children:["Tag: ",n||r]})]}),i.jsx("div",{className:"flex-1 overflow-y-auto p-2 min-h-0",children:f?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(lt,{className:"w-6 h-6 animate-spin text-bambu-green"})}):x.length===0?i.jsx("p",{className:"text-center text-bambu-gray py-8 text-sm",children:l("inventory.noSpoolsMatch")}):x.map(g=>i.jsxs("button",{onClick:()=>v.mutate(g.id),disabled:v.isPending,className:"w-full flex items-center gap-3 p-3 rounded-lg hover:bg-white/5 transition-colors text-left",children:[i.jsx("span",{className:"w-6 h-6 rounded-full border border-white/20 flex-shrink-0",style:{backgroundColor:g.rgba?`#${g.rgba.substring(0,6)}`:"#808080"}}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"text-sm text-white font-medium truncate",children:[g.brand?`${g.brand} `:"",g.material,g.subtype?` ${g.subtype}`:""]}),i.jsxs("div",{className:"text-xs text-bambu-gray truncate",children:[g.color_name||"No color"," · #",g.id]})]}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:[Math.round(g.label_weight-g.weight_used),"g"]})]},g.id))}),i.jsx("div",{className:"p-4 border-t border-white/10 flex justify-end",children:i.jsx(Oe,{variant:"ghost",onClick:e,children:l("inventory.cancel")||"Cancel"})})]})]}):null}function I$e({isOpen:t,onClose:e,printerId:n,amsId:r,trayId:a,trayInfo:s}){const{t:o}=Mt(),l=Zt(),{showToast:c}=hn(),[d,u]=w.useState(null),[m,p]=w.useState(""),{data:f,isLoading:x}=Ze({queryKey:["inventory-spools"],queryFn:()=>fe.getSpools(),enabled:t}),{data:v}=Ze({queryKey:["spool-assignments"],queryFn:()=>fe.getAssignments(),enabled:t}),g=dt({mutationFn:P=>fe.assignSpool({spool_id:P,printer_id:n,ams_id:r,tray_id:a}),onSuccess:P=>{l.setQueryData(["spool-assignments"],k=>{const D=(k||[]).filter(A=>!(A.printer_id===n&&A.ams_id===r&&A.tray_id===a));return D.push(P),D}),l.invalidateQueries({queryKey:["spool-assignments"]}),c(o("inventory.assignSuccess"),"success"),e()},onError:P=>{c(`${o("inventory.assignFailed")}: ${P.message}`,"error")}});if(!t)return null;const y=new Set((v||[]).filter(P=>!(P.printer_id===n&&P.ams_id===r&&P.tray_id===a)).map(P=>P.spool_id)),_=r===254||r===255,N=f?.filter(P=>!y.has(P.id)&&(_||!P.tag_uid&&!P.tray_uuid)),C=N?.filter(P=>{if(!m)return!0;const k=m.toLowerCase();return P.material.toLowerCase().includes(k)||(P.brand?.toLowerCase().includes(k)??!1)||(P.color_name?.toLowerCase().includes(k)??!1)||(P.subtype?.toLowerCase().includes(k)??!1)}),T=()=>{d&&g.mutate(d)};return i.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),i.jsxs("div",{className:"relative w-full max-w-md 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",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(oa,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:o("inventory.assignSpool")})]}),i.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(zt,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[s&&i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("p",{className:"text-xs text-bambu-gray mb-1",children:[o("inventory.selectSpool"),":"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[s.color&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20",style:{backgroundColor:`#${s.color}`}}),i.jsx("span",{className:"text-white font-medium",children:s.type||o("ams.emptySlot")}),i.jsxs("span",{className:"text-bambu-gray",children:["(",s.location,")"]})]})]}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:m,onChange:P=>p(P.target.value),placeholder:o("inventory.searchSpools"),className:"w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green"})]}),i.jsx("div",{children:x?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):C&&C.length>0?i.jsx("div",{className:"max-h-64 overflow-y-auto space-y-2",children:C.map(P=>i.jsx("button",{onClick:()=>u(P.id),className:`w-full p-3 rounded-lg border text-left transition-colors ${d===P.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 gap-2",children:[P.rgba&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20 flex-shrink-0",style:{backgroundColor:`#${P.rgba.substring(0,6)}`}}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("p",{className:"text-white font-medium truncate",children:[P.brand?`${P.brand} `:"",P.material,P.subtype?` ${P.subtype}`:""]}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[P.color_name||"",P.label_weight?` - ${P.label_weight}g`:"",P.label_weight?` (${Math.max(0,Math.round(P.label_weight-P.weight_used))}g ${o("ams.remainingUnit")})`:""]})]}),d===P.id&&i.jsx(Vr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]})},P.id))}):N&&N.length===0?i.jsx("div",{className:"text-center py-8 text-bambu-gray",children:i.jsx("p",{children:o("inventory.noManualSpools")})}):i.jsx("div",{className:"text-center py-8 text-bambu-gray",children:i.jsx("p",{children:o("inventory.noSpoolsMatch")})})})]}),i.jsxs("div",{className:"flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary",children:[i.jsx(Oe,{variant:"secondary",onClick:e,children:o("common.cancel")}),i.jsx(Oe,{onClick:T,disabled:!d||g.isPending,children:g.isPending?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),o("inventory.assigning")]}):i.jsxs(i.Fragment,{children:[i.jsx(oa,{className:"w-4 h-4"}),o("inventory.assignSpool")]})})]}),g.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:g.error.message})]})]})}function xG(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 U_(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 hv=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function yG(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 hv)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 hv){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 z$e(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const U$e={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"},vG=[{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"}],wG=[{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 SG(t){const e=t.toLowerCase().trim();return U$e[e]||null}function B$e(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 Kne({isOpen:t,onClose:e,printerId:n,slotInfo:r,nozzleDiameter:a="0.4",printerModel:s,onSuccess:o,fullScreen:l}){const{t:c}=Mt(),[d,u]=w.useState(""),[m,p]=w.useState(null),[f,x]=w.useState(""),[v,g]=w.useState(""),[y,_]=w.useState(""),[N,C]=w.useState(!1),[T,P]=w.useState(!1),k=w.useRef(""),{data:D,isLoading:A,isError:R}=Ze({queryKey:["cloudSettings"],queryFn:()=>fe.getCloudSettings(),enabled:t,retry:!1}),{data:$,isLoading:U}=Ze({queryKey:["localPresets"],queryFn:()=>fe.getLocalPresets(),enabled:t}),{data:W,isLoading:O}=Ze({queryKey:["builtinFilaments"],queryFn:()=>fe.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:te,isLoading:re}=Ze({queryKey:["kprofiles",n,a],queryFn:()=>fe.getKProfiles(n,a),enabled:t&&!!n}),{data:J}=Ze({queryKey:["colorCatalog"],queryFn:()=>fe.getColorCatalog(),enabled:t,staleTime:1/0}),le=dt({mutationFn:async()=>{if(!d)throw new Error("No filament preset selected");const j=d.startsWith("local_"),L=d.startsWith("builtin_"),G=j?parseInt(d.replace("local_",""),10):null,B=L?d.replace("builtin_",""):null,ie=j?$?.filament.find(Ue=>Ue.id===G):null,z=L?W?.find(Ue=>Ue.filament_id===B):null,V=!j&&!L?D?.filament.find(Ue=>Ue.setting_id===d):null;if(!j&&!L&&!V)throw new Error("Selected preset not found");if(j&&!ie)throw new Error("Selected local preset not found");if(L&&!z)throw new Error("Selected builtin preset not found");const ee=j?ie.name:L?z.name:V.name,Z=yG(ee),ne=m?.slot_id??-1,se=f||r.trayColor?.slice(0,6)||"FFFFFF",ue=ee.replace(/@.+$/,"").trim();let ge,ce;const I=Z.material.toUpperCase();if(j){const Ue=(hv.includes(I)?I:ie?.filament_type||Z.material||"").toUpperCase(),$e={PLA:"GFL99","PLA-CF":"GFL98","PLA SILK":"GFL96","PLA HIGH SPEED":"GFL95",PETG:"GFG99","PETG HF":"GFG96","PETG-CF":"GFG98",PCTG:"GFG97",ABS:"GFB99",ASA:"GFB98",PC:"GFC99",PA:"GFN99","PA-CF":"GFN98",NYLON:"GFN99",TPU:"GFU99",PVA:"GFS99",HIPS:"GFS98",PE:"GFP99",PP:"GFP97"};ge=$e[Ue]||$e[Ue.replace(/[-\s]?CF$/,"")]||$e[Ue.replace(/\+$/,"")]||$e[Ue.split(/[-\s]/)[0]]||"",ce=""}else if(L)ge=B,ce="";else if(ge=U_(d),ce=d,!d.startsWith("GFS"))try{const Ue=await fe.getCloudSettingDetail(d);Ue.filament_id?ge=Ue.filament_id:Ue.base_id&&(ge=U_(Ue.base_id),console.log(`Derived tray_info_idx from base_id: ${Ue.base_id} -> ${ge}`))}catch(Ue){console.warn("Failed to fetch preset detail for filament_id:",Ue)}let F=j&&ie?.nozzle_temp_min?ie.nozzle_temp_min:190,Q=j&&ie?.nozzle_temp_max?ie.nozzle_temp_max:230;if(!j||L||!ie?.nozzle_temp_min&&!ie?.nozzle_temp_max){const Ue=(j?hv.includes(I)?I:ie?.filament_type||Z.material||"":Z.material).toUpperCase();Ue.includes("PLA")?(F=190,Q=230):Ue.includes("PETG")?(F=220,Q=260):Ue.includes("ABS")||Ue.includes("ASA")?(F=240,Q=280):Ue.includes("TPU")?(F=200,Q=240):Ue==="PCTG"?(F=220,Q=260):Ue.includes("PC")?(F=260,Q=300):(Ue.includes("PA")||Ue.includes("NYLON"))&&(F=250,Q=290)}const xe=m?.k_value?parseFloat(m.k_value):0,pe=j?hv.includes(I)?I:ie?.filament_type||Z.material||"PLA":Z.material||"PLA",de=await fe.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:ge,tray_type:pe,tray_sub_brands:ue,tray_color:se+"FF",nozzle_temp_min:F,nozzle_temp_max:Q,cali_idx:ne,nozzle_diameter:a,setting_id:ce,kprofile_filament_id:m?.filament_id,kprofile_setting_id:m?.setting_id||void 0,k_value:xe}),Ae=j?`local_${G}`:L?`builtin_${B}`:d,_e=j?"local":L?"builtin":"cloud";try{await fe.saveSlotPreset(n,r.amsId,r.trayId,Ae,ue,_e)}catch(Ue){console.warn("Failed to save slot preset mapping:",Ue)}return de},onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),me=dt({mutationFn:async()=>fe.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),he=w.useMemo(()=>{const j=y.toLowerCase(),L=[],G=new Set,B=r.savedPresetId,ie=r.trayInfoIdx;if(D?.filament)for(const z of D.filament){G.add(z.setting_id);const V=B===z.setting_id||ie&&(z.setting_id===ie||U_(z.setting_id)===ie);if(!(!V&&j&&!z.name.toLowerCase().includes(j))){if(!V&&s){const ee=B$e(z.name);if(ee&&ee.toUpperCase()!==s.toUpperCase())continue}L.push({id:z.setting_id,name:z.name,source:"cloud",isUser:z$e(z.setting_id)})}}if($?.filament)for(const z of $.filament){const V=`local_${z.id}`,ee=B===V;if(!(!ee&&j&&!z.name.toLowerCase().includes(j))){if(!ee&&s&&z.compatible_printers){const Z=z.compatible_printers.split(";").map(ne=>{const se=ne.trim(),ue=se.match(/^BBL\s+(.+)/i);return ue?ue[1].trim().toUpperCase():se.toUpperCase()}).filter(Boolean);if(Z.length>0&&!Z.includes(s.toUpperCase()))continue}L.push({id:V,name:z.name,source:"local",isUser:!1})}}if(W)for(const z of W){if(G.has(z.filament_id))continue;const V=z.filament_id.startsWith("GF")?"GFS"+z.filament_id.slice(2):z.filament_id;G.has(V)||(!j||z.name.toLowerCase().includes(j))&&L.push({id:`builtin_${z.filament_id}`,name:z.name,source:"builtin",isUser:!1})}return L.sort((z,V)=>{const ee={cloud:0,local:1,builtin:2};return z.source!==V.source?ee[z.source]-ee[V.source]:z.isUser&&!V.isUser?-1:!z.isUser&&V.isUser?1:z.name.localeCompare(V.name)})},[D?.filament,$?.filament,W,y,s,r.savedPresetId,r.trayInfoIdx]),X=w.useMemo(()=>{if(!d)return null;let j=null;if(d.startsWith("local_")){const B=parseInt(d.replace("local_",""),10);j=$?.filament.find(z=>z.id===B)?.name||null}else if(d.startsWith("builtin_")){const B=d.replace("builtin_","");j=W?.find(z=>z.filament_id===B)?.name||null}else D?.filament&&(j=D.filament.find(ie=>ie.setting_id===d)?.name||null);if(!j)return null;let L=j.replace(/@.+$/,"").trim();L.startsWith("# ")&&(L=L.slice(2).trim());const G=yG(L);return{fullName:L,material:G.material,brand:G.brand}},[d,D?.filament,$?.filament,W]),ae=X?.fullName||"",oe=w.useMemo(()=>{if(!J||!X)return[];const{fullName:j,brand:L}=X,G=j.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return J.filter(B=>{const ie=(B.material||"").toUpperCase(),z=B.manufacturer.toUpperCase();if(!(ie===G.toUpperCase()||ie.includes(G.toUpperCase())||G.toUpperCase().includes(ie)))return!1;if(L){const ee=L.toUpperCase();if(!z.includes(ee)&&!ee.includes(z))return!1}return!0})},[J,X]),ye=w.useMemo(()=>{if(!te?.profiles||!X)return[];const{fullName:j,material:L,brand:G}=X,B=j.toUpperCase(),ie=L.toUpperCase(),z=G.toUpperCase();if(!ie||ie.length<2)return[];const V=te.profiles.filter(Z=>{const ne=Z.name.toUpperCase();if(z)return!(!ne.includes(z)||!ne.includes(ie));if(ne.includes(B)||ne.includes(ie))return!0;const ue={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[ie]||[];for(const ge of ue)if(ne.includes(ge))return!0;return!1}),ee=new Map;for(const Z of V){const ne=`${Z.name}|${Z.k_value}`,se=ee.get(ne);se?r.extruderId!==void 0&&Z.extruder_id===r.extruderId&&se.extruder_id!==r.extruderId&&ee.set(ne,Z):ee.set(ne,Z)}return Array.from(ee.values())},[te?.profiles,X,r.extruderId]);w.useEffect(()=>{if(t){if(r.savedPresetId)u(r.savedPresetId);else if(r.trayInfoIdx&&D?.filament){let j=D.filament.find(L=>L.setting_id===r.trayInfoIdx);j||(j=D.filament.find(L=>U_(L.setting_id)===r.trayInfoIdx)),j&&u(j.setting_id)}else if(r.trayInfoIdx&&W?.length){const j=r.trayInfoIdx,L=W.find(G=>G.filament_id===j);L&&u(`builtin_${L.filament_id}`)}if(r.trayColor){const j=r.trayColor.slice(0,6);j&&x(j)}}else u(""),p(null),x(""),g(""),_(""),C(!1),k.current=""},[t,r.savedPresetId,r.trayInfoIdx,r.trayColor,D?.filament,W]),w.useEffect(()=>{if(ye.length>0){if(r.caliIdx!=null&&r.caliIdx>0){const j=ye.find(L=>L.slot_id===r.caliIdx);if(j){p(j);return}}p(ye[0])}else p(null)},[d,ye,r.caliIdx]);const Ee=w.useCallback(j=>{j.key==="Escape"&&e()},[e]);w.useEffect(()=>{if(t)return document.addEventListener("keydown",Ee),()=>document.removeEventListener("keydown",Ee)},[t,Ee]);const q=A&&!R||U||O||re;if(w.useEffect(()=>{if(!q&&d&&d!==k.current){const j=requestAnimationFrame(()=>{const G=document.querySelector('[class*="fixed inset-0 z-50"]')?.querySelector(`[data-preset-id="${CSS.escape(d)}"]`);G&&(k.current=d,G.scrollIntoView({block:"nearest"}))});return()=>cancelAnimationFrame(j)}},[d,q]),!t)return null;const K=d&&!le.isPending,E=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(cu,{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-white/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),i.jsx("span",{className:"text-white/70",children:c("configureAmsSlot.slotLabel",{ams:xG(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(zt,{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(Eb,{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-white/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),i.jsx("span",{className:"text-white font-medium",children:c("configureAmsSlot.slotLabel",{ams:xG(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&i.jsxs("span",{className:"text-bambu-gray",children:["(",r.traySubBrands,")"]})]})]}),q?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(lt,{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:y,onChange:j=>_(j.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:he.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:D?.filament?.length===0&&!$?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):he.map(j=>i.jsx("button",{"data-preset-id":j.id,onClick:()=>u(j.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${d===j.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:j.name}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[j.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")}),j.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")}),j.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")})]})]})},j.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})})]}),ye.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:j=>{const L=ye.find(G=>G.name===j.target.value);p(L||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")}),ye.map(j=>i.jsxs("option",{value:j.name,children:[j.name," (K=",j.k_value,")"]},`${j.name}-${j.extruder_id}`))]}),i.jsx(jn,{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")}),oe.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:X?.fullName})}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:oe.map(j=>i.jsxs("button",{onClick:()=>{const L=j.hex_color.replace("#","").toUpperCase();x(L),g(j.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===j.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:j.color_name,children:[i.jsx("span",{className:"w-4 h-4 rounded-full border border-white/30 flex-shrink-0",style:{backgroundColor:j.hex_color}}),i.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:j.color_name})]},j.id))})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[vG.map(j=>i.jsx("button",{onClick:()=>{x(j.hex),g(j.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===j.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${j.hex}`},title:j.name},j.hex)),i.jsx("button",{onClick:()=>P(!T),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(T?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:T?"−":"+"})]}),T&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:wG.map(j=>i.jsx("button",{onClick:()=>{x(j.hex),g(j.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===j.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${j.hex}`},title:j.name},j.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:`#${E}`}}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:j=>{const L=j.target.value;g(L);const G=SG(L);if(G)x(G);else{const B=L.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();B.length===6?x(B):B.length===3&&x(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:()=>{x(""),g("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),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:y,onChange:j=>_(j.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:he.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:D?.filament?.length===0&&!$?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):he.map(j=>i.jsx("button",{"data-preset-id":j.id,onClick:()=>u(j.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${d===j.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:j.name}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[j.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")}),j.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")}),j.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")})]})]})},j.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})})]}),ye.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:j=>{const L=ye.find(G=>G.name===j.target.value);p(L||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")}),ye.map(j=>i.jsxs("option",{value:j.name,children:[j.name," (K=",j.k_value,")"]},`${j.name}-${j.extruder_id}`))]}),i.jsx(jn,{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")}),oe.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:X?.fullName})}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:oe.map(j=>i.jsxs("button",{onClick:()=>{const L=j.hex_color.replace("#","").toUpperCase();x(L),g(j.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===j.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:j.color_name,children:[i.jsx("span",{className:"w-4 h-4 rounded-full border border-white/30 flex-shrink-0",style:{backgroundColor:j.hex_color}}),i.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:j.color_name})]},j.id))})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[vG.map(j=>i.jsx("button",{onClick:()=>{x(j.hex),g(j.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===j.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${j.hex}`},title:j.name},j.hex)),i.jsx("button",{onClick:()=>P(!T),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(T?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:T?"−":"+"})]}),T&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:wG.map(j=>i.jsx("button",{onClick:()=>{x(j.hex),g(j.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===j.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${j.hex}`},title:j.name},j.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:`#${E}`}}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:j=>{const L=j.target.value;g(L);const G=SG(L);if(G)x(G);else{const B=L.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();B.length===6?x(B):B.length===3&&x(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:()=>{x(""),g("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),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(Oe,{variant:"secondary",onClick:()=>me.mutate(),disabled:me.isPending||le.isPending,className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:me.isPending?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.resetting")]}):i.jsxs(i.Fragment,{children:[i.jsx(mo,{className:"w-4 h-4"}),c("configureAmsSlot.resetSlot")]})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{variant:"secondary",onClick:e,children:c("configureAmsSlot.cancel")}),i.jsx(Oe,{onClick:()=>le.mutate(),disabled:!K,children:le.isPending?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.configuring")]}):i.jsxs(i.Fragment,{children:[i.jsx(cu,{className:"w-4 h-4"}),c("configureAmsSlot.configureSlot")]})})]})]}),(le.isError||me.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:le.error?.message||me.error?.message})]})]})}function Yne({folderId:t,onClose:e,onUploadComplete:n,onFileUploaded:r,autoUpload:a,validateFile:s,accept:o}){const{t:l}=Mt(),[c,d]=w.useState([]),[u,m]=w.useState(!1),[p,f]=w.useState(!1),[x,v]=w.useState(!0),[g,y]=w.useState(!1),[_,N]=w.useState(!0),[C,T]=w.useState(null),P=w.useRef(null),k=he=>{he.preventDefault(),m(!0)},D=he=>{he.preventDefault(),m(!1)},A=he=>{he.preventDefault(),m(!1),W(Array.from(he.dataTransfer.files))},R=he=>{he.target.files&&W(Array.from(he.target.files))},$=(he,X)=>{d(ae=>ae.map(oe=>oe.file===he?{...oe,...X}:oe))},U=async he=>{f(!0);for(const X of he)if(X.status==="pending"){$(X.file,{status:"uploading"});try{if(X.isZip){const ae=await fe.extractZipFile(X.file,t,x,g,_);$(X.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(X.file,t,_);$(X.file,{status:"success"});const oe=r?.(ae);if(oe){T(oe),d([]),f(!1);return}}}catch(ae){$(X.file,{status:"error",error:ae instanceof Error?ae.message:l("fileManager.uploadFailed","Upload failed")})}}f(!1),n(),e()},W=he=>{if(T(null),s)for(const ae of he){const oe=s(ae);if(oe){T(oe);return}}const X=he.map(ae=>({file:ae,status:"pending",isZip:ae.name.toLowerCase().endsWith(".zip"),is3mf:ae.name.toLowerCase().endsWith(".3mf")}));d(ae=>[...ae,...X]),a&&he.length>0&&U(X)},O=he=>{d(X=>X.filter((ae,oe)=>oe!==he))},te=c.some(he=>he.isZip&&he.status==="pending"),re=c.some(he=>he.file.name.toLowerCase().endsWith(".stl")&&he.status==="pending"),J=c.some(he=>he.is3mf&&he.status==="pending"),le=c.filter(he=>he.status==="pending").length,me=c.length>0&&le===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(zt,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsxs("div",{onDragOver:k,onDragLeave:D,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(Si,{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:R}),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(Os,{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:x,onChange:he=>v(he.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:g,onChange:he=>y(he.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")})]})]})]})}),J&&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(_r,{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")})]})]})}),(re||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(lu,{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&&!re?"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:he=>N(he.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((he,X)=>i.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[he.isZip?i.jsx(Os,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):i.jsx(oC,{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:he.file.name}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[(he.file.size/1024/1024).toFixed(2)," MB",he.isZip&&he.status==="pending"&&i.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",l("fileManager.willBeExtracted")]}),he.extractedCount!==void 0&&i.jsxs("span",{className:"text-green-400 ml-2",children:["• ",l("fileManager.filesExtracted",{count:he.extractedCount})]})]})]}),he.status==="pending"&&i.jsx("button",{onClick:()=>O(X),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(zt,{className:"w-4 h-4 text-bambu-gray"})}),he.status==="uploading"&&i.jsx(lt,{className:"w-4 h-4 text-bambu-green animate-spin"}),he.status==="success"&&i.jsx(pr,{className:"w-4 h-4 text-green-500"}),he.status==="error"&&i.jsx("span",{title:he.error,children:i.jsx(Vi,{className:"w-4 h-4 text-red-500"})})]},X))}),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(Vi,{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(Oe,{variant:"secondary",onClick:e,children:l("common.cancel")}),!me&&i.jsx(Oe,{onClick:()=>U(c),disabled:le===0||p,children:p?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 mr-2 animate-spin"}),l("fileManager.uploading")]}):i.jsxs(i.Fragment,{children:[i.jsx(Si,{className:"w-4 h-4 mr-2"}),l("common.upload")," ",le>0?`(${le})`:""]})})]})]})})}function _G(t){return t?`#${t.replace("#","").substring(0,6)}`:"#808080"}function Oi(t){return t?t.replace("#","").toLowerCase().substring(0,6):""}function qc(t,e,n=40){const r=Oi(t),a=Oi(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 L4(t,e,n,r){if(r)return"External";const a=String.fromCharCode(65+(t>=128?t-128:t));return n?`HT-${a}`:`AMS-${a} Slot ${e+1}`}function sk(t,e,n){return n?254+e:t>=128?t:t*4+e}function NG(t){if(!t)return!1;const e=Date.now()+4320*60*60*1e3;return(er(t)?.getTime()??0)>e}function H$e(t,e,n){const r=Xne(e,t.nozzle_id),a=r.find(l=>!n.has(l.globalTrayId)&&l.type?.toUpperCase()===t.type?.toUpperCase()&&Oi(l.color)===Oi(t.color)),s=a?void 0:r.find(l=>!n.has(l.globalTrayId)&&l.type?.toUpperCase()===t.type?.toUpperCase()&&qc(l.color,t.color)),o=a||s?void 0:r.find(l=>!n.has(l.globalTrayId)&&l.type?.toUpperCase()===t.type?.toUpperCase());return a??s??o}function Xne(t,e){return t.filter(n=>e==null||n.extruderId===e)}function kT(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=_G(o.tray_color);e.push({type:o.tray_type,color:l,colorName:Rp(l),amsId:a.id,trayId:o.id,isHt:s,isExternal:!1,label:L4(a.id,o.id,s,!1),globalTrayId:sk(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=_G(a.tray_color),o=a.id??254,l=(t?.vt_tray?.length??0)>1;e.push({type:a.tray_type,color:s,colorName:Rp(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 kG(t,e){if(!t?.filaments||t.filaments.length===0)return;const n=kT(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(g=>g.trayInfoIdx===c);v.length===1?u=v[0]:v.length>1&&(m=v.find(g=>g.type?.toUpperCase()===l.type?.toUpperCase()&&Oi(g.color)===Oi(l.color)),m||(p=v.find(g=>g.type?.toUpperCase()===l.type?.toUpperCase()&&qc(g.color,l.color))),!m&&!p&&(f=v.find(g=>g.type?.toUpperCase()===l.type?.toUpperCase())))}!u&&!m&&!p&&!f&&(m=d.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&Oi(v.color)===Oi(l.color)),m||(p=d.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&qc(v.color,l.color))),!m&&!p&&(f=d.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase())));const x=u||m||p||f||void 0;return x&&r.add(x.globalTrayId),{slot_id:l.slot_id,globalTrayId:x?.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 $$e(t){return w.useMemo(()=>kT(t),[t])}function Qne(t,e,n){const r=$$e(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],k=r.find(D=>D.globalTrayId===P);if(k){const D=k.type?.toUpperCase()===d.type?.toUpperCase(),A=Oi(k.color)===Oi(d.color)||qc(k.color,d.color);let R;return D&&A?R="match":D?R="type_only":R="mismatch",{...d,loaded:k,hasFilament:!0,typeMatch:D,colorMatch:A,status:R,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,x,v,g;if(m){const P=p.filter(k=>k.trayInfoIdx===m);P.length===1?f=P[0]:P.length>1&&(x=P.find(k=>k.type?.toUpperCase()===d.type?.toUpperCase()&&Oi(k.color)===Oi(d.color)),x||(v=P.find(k=>k.type?.toUpperCase()===d.type?.toUpperCase()&&qc(k.color,d.color))),!x&&!v&&(g=P.find(k=>k.type?.toUpperCase()===d.type?.toUpperCase())))}!f&&!x&&!v&&!g&&(x=p.find(P=>P.type?.toUpperCase()===d.type?.toUpperCase()&&Oi(P.color)===Oi(d.color)),x||(v=p.find(P=>P.type?.toUpperCase()===d.type?.toUpperCase()&&qc(P.color,d.color))),!x&&!v&&(g=p.find(P=>P.type?.toUpperCase()===d.type?.toUpperCase())));const y=f||x||v||g||void 0;y&&c.add(y.globalTrayId);const _=!!y,N=_,C=!!f||!!x||!!v;let T;return f||x||v?T="match":g?T="type_only":T="mismatch",{...d,loaded:y,hasFilament:_,typeMatch:N,colorMatch:C,status:T,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 q$e(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 g=n[u],y=e.find(_=>_.globalTrayId===g);if(y){const _=y.type?.toUpperCase()===d.type?.toUpperCase(),N=Oi(y.color)===Oi(d.color)||qc(y.color,d.color);_&&N?r++:_?a++:s++;continue}}let m=e.filter(g=>!o.has(g.globalTrayId));if(d.nozzle_id!=null){const g=m.filter(y=>y.extruderId===d.nozzle_id);g.length>0&&(m=g)}const p=m.find(g=>g.type?.toUpperCase()===d.type?.toUpperCase()&&Oi(g.color)===Oi(d.color)),f=p?void 0:m.find(g=>g.type?.toUpperCase()===d.type?.toUpperCase()&&qc(g.color,d.color)),x=p||f?void 0:m.find(g=>g.type?.toUpperCase()===d.type?.toUpperCase()),v=p??f??x;v&&o.add(v.globalTrayId),p||f?r++:x?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 V$e(t,e,n){if(!t?.filaments||t.filaments.length===0)return;const r=kT(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(g=>g.extruderId===c.nozzle_id);v.length>0&&(u=v)}const m=u.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&Oi(v.color)===Oi(c.color)),p=m?void 0:u.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&qc(v.color,c.color)),f=m||p?void 0:u.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()),x=m??p??f;x&&a.add(x.globalTrayId),s.push({slot_id:d,globalTrayId:x?.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 CG={useDefault:!0,manualMappings:{},autoConfigured:!1};function G$e(t,e,n,r,a,s){const o=bf({queries:t.map(x=>({queryKey:["printer-status",x],queryFn:()=>fe.getPrinterStatus(x),enabled:t.length>0,staleTime:5e3}))}),l=w.useMemo(()=>t.map((x,v)=>{const g=o[v],y=g?.data,N=e?.find(R=>R.id===x)?.name||`Printer ${x}`,C=kT(y),T=a[x]||CG,P=kG(n,y),k=T.useDefault?r:T.manualMappings,D=V$e(n,y,k),A=q$e(n?.filaments,C,k);return{printerId:x,printerName:N,status:y,isLoading:g?.isLoading??!1,loadedFilaments:C,autoMapping:P,finalMapping:D,matchStatus:A.status,exactMatches:A.exactMatches,typeOnlyMatches:A.typeOnlyMatches,missingTypes:A.missingTypes,totalSlots:A.totalSlots,config:T}}),[t,o,e,n,a,r]),c=o.some(x=>x.isLoading),d=(x,v)=>{s(g=>({...g,[x]:{...g[x]||CG,...v}}))},u=x=>{const v=l.find(_=>_.printerId===x);if(!v||!v.status||!n?.filaments)return;const g=kG(n,v.status);if(!g)return;const y={};g.forEach((_,N)=>{_!==-1&&(y[N+1]=_)}),d(x,{useDefault:!1,manualMappings:y,autoConfigured:!0})},m=()=>{for(const x of t)u(x)},p=x=>l.find(g=>g.printerId===x)?.finalMapping,f=l.every(x=>x.matchStatus!=="missing");return{printerResults:l,isLoading:c,perPrinterConfigs:a,updatePrinterConfig:d,autoConfigureAll:m,autoConfigurePrinter:u,getFinalMapping:p,allPrintersReady:f}}const Zne={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"};function ol(t){return Zne[t.toUpperCase()]||t}const W$e=Object.entries(Zne).map(([t,e])=>({code:t,label:`${t} (${e})`}));function K$e({printerId:t,filamentReqs:e,manualMappings:n,onManualMappingChange:r,currencySymbol:a,defaultCostPerKg:s,defaultExpanded:o=!1}){const{t:l}=Mt(),c=Zt(),[d,u]=w.useState(!1),[m,p]=w.useState(o),{data:f}=Ze({queryKey:["printer-status",t],queryFn:()=>fe.getPrinterStatus(t),enabled:!!t}),{data:x}=Ze({queryKey:["spool-assignments",t],queryFn:()=>fe.getAssignments(t),enabled:!!t}),{loadedFilaments:v,filamentComparison:g,hasTypeMismatch:y,hasColorMismatch:_}=Qne(e,f,n),N=w.useMemo(()=>{const U=new Map;for(const W of x||[]){const O=W.ams_id===255,te=sk(W.ams_id,W.tray_id,O);U.set(te,W.spool?.cost_per_kg??null)}return U},[x]),C=w.useMemo(()=>{const U=new Map;for(const W of x||[]){const O=W.ams_id===255,te=sk(W.ams_id,W.tray_id,O),re=W.spool;if(!re){U.set(te,null);continue}U.set(te,Math.max(0,Math.round((re.label_weight??0)-(re.weight_used??0))))}return U},[x]),T=w.useMemo(()=>{let U=0;for(const W of g){const O=W.loaded?.globalTrayId;if(O==null)continue;const re=N.get(O)??null??s;re>0&&(U+=W.used_grams/1e3*re)}return U},[g,N,s]),P=w.useMemo(()=>Array.from(N.values()).some(U=>U!=null&&U>0),[N]),k=e?.filaments&&e.filaments.length>0,D=e?.filaments?.some(U=>U.nozzle_id!=null)??!1;if(!k||!f)return null;const A=y?"#f97316":_?"#facc15":"#00ae42",R=(U,W)=>{if(U>0)if(W===""){const O={...n};delete O[U],r(O)}else r({...n,[U]:parseInt(W,10)})},$=async()=>{u(!0);try{await fe.refreshPrinterStatus(t),await new Promise(U=>setTimeout(U,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(z1,{className:"w-4 h-4",fill:A,stroke:"none"}),i.jsx("span",{children:l("printModal.filamentMapping")}),y?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(Sl,{className:"w-4 h-4 ml-auto"}):i.jsx(jn,{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:$,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(Sr,{className:`w-3 h-3 ${d?"animate-spin":""}`}),i.jsx("span",{children:"Re-read"})]})]}),g.map((U,W)=>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: ${U.type} - ${Rp(U.color)}`,children:i.jsx(z1,{className:"w-3 h-3",fill:U.color,stroke:U.color})}),i.jsxs("span",{className:"text-white truncate flex items-center gap-1",children:[D&&U.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:U.nozzle_id===1?l("printModal.leftNozzleTooltip"):l("printModal.rightNozzleTooltip"),children:U.nozzle_id===1?l("printModal.leftNozzle"):l("printModal.rightNozzle")}),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:U.loaded?.globalTrayId??"",onChange:O=>R(U.slot_id||0,O.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 ${U.status==="match"?"border-bambu-green/50 text-bambu-green":U.status==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${U.isManual?"ring-1 ring-blue-400/50":""}`,title:U.isManual?"Manually selected":"Auto-matched",children:[i.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),v.filter(O=>U.nozzle_id==null||O.extruderId===U.nozzle_id).map(O=>{const te=C.get(O.globalTrayId),re=te!=null?l("printModal.slotRemainingShort",{grams:te,defaultValue:` - ${te}g left`}):"";return i.jsxs("option",{value:O.globalTrayId,className:"bg-bambu-dark text-white",children:[O.label,": ",O.traySubBrands||O.type," (",O.colorName,")",re]},O.globalTrayId)})]}),U.status==="match"?i.jsx(Vr,{className:"w-3 h-3 text-bambu-green"}):U.status==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(Cn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(Cn,{className:"w-3 h-3 text-orange-400"})})]},W)),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[l("printModal.totalCost")," ",i.jsx("span",{className:"text-white",children:T>0||P?`${a}${T.toFixed(2)}`:"N/A"})]}),y&&i.jsx("p",{className:"text-xs text-orange-400 mt-2",children:"Required filament type not found in printer."})]})]})}function Y$e({filamentReqs:t,availableFilaments:e,overrides:n,onChange:r}){const{t:a}=Mt(),s=w.useMemo(()=>{const c={};for(const d of e){const u=d.type.toUpperCase();c[u]||(c[u]=[]),c[u].push(d)}return c},[e]),o=t?.filaments;if(!o||o.length===0||e.length===0)return null;const l=(c,d)=>{if(d===""){const u={...n};delete u[c],r(u)}else{const[u,m]=d.split("|");r({...n,[c]:{type:u,color:m}})}};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:a("printModal.filamentOverride")})}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:a("printModal.filamentOverrideHint")}),i.jsx("div",{className:"bg-bambu-dark rounded-lg p-3 space-y-2",children:o.map(c=>{const d=n[c.slot_id],u=!!d,m=s[c.type.toUpperCase()]||[],p=c.nozzle_id!=null?m.filter(f=>f.extruder_id==null||f.extruder_id===c.nozzle_id):m;return 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:`${a("printModal.originalFilament")}: ${c.type} - ${Rp(c.color)}`,children:i.jsx(z1,{className:"w-3 h-3",fill:c.color,stroke:c.color})}),i.jsxs("span",{className:"text-white truncate",children:[c.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",c.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:u?`${d.type}|${d.color}`:"",onChange:f=>l(c.slot_id,f.target.value),disabled:p.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 ${u?"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:[a("printModal.originalFilament"),": ",c.type," (",Rp(c.color),")"]}),p.map((f,x)=>i.jsxs("option",{value:`${f.type}|${f.color}`,className:"bg-bambu-dark text-white",children:[f.tray_sub_brands||f.type," (",Rp(f.color),")"]},`${f.type}-${f.color}-${f.tray_sub_brands}-${x}`))]}),u?i.jsx("button",{type:"button",onClick:()=>l(c.slot_id,""),className:"text-bambu-gray hover:text-white transition-colors",title:a("printModal.resetToOriginal"),children:i.jsx(mo,{className:"w-3 h-3"})}):i.jsx("span",{className:"w-3"})]},c.slot_id)})})]})}function X$e({plates:t,isMultiPlate:e,selectedPlate:n,onSelect:r}){return!e||t.length<=1?null:i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx(Gi,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:"Select Plate to Print"}),!n&&i.jsxs("span",{className:"text-xs text-orange-400 flex items-center gap-1",children:[i.jsx(Cn,{className:"w-3 h-3"}),"Selection required"]})]}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map(a=>i.jsxs("button",{type:"button",onClick:()=>r(a.index),className:`flex items-center gap-2 p-2 rounded-lg border transition-colors text-left ${n===a.index?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"}`,children:[a.has_thumbnail&&a.thumbnail_url!=null?i.jsx("img",{src:a.thumbnail_url,alt:`Plate ${a.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(Gi,{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:a.name||`Plate ${a.index}`}),i.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[a.objects.length>0?a.objects.slice(0,3).join(", ")+(a.objects.length>3?"...":""):`${a.filaments.length} filament${a.filaments.length!==1?"s":""}`,a.print_time_seconds!=null?` • ${js(a.print_time_seconds)}`:""]})]}),n===a.index&&i.jsx(Vr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]},a.index))})]})}const Q$e=new Set(["IDLE","FINISH","FAILED"]);function Z$e({printerResult:t,filamentReqs:e,onUpdateConfig:n}){const r=Zt(),[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=H$e(d,t.loadedFilaments,v)}let x="mismatch";if(p){const v=p.type?.toUpperCase()===d.type?.toUpperCase(),g=Oi(p.color)===Oi(d.color)||qc(p.color,d.color);v&&g?x="match":v&&(x="type_only")}return{req:d,loaded:p,status:x,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(Sr,{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} - ${Rp(d.color)}`,children:i.jsx(z1,{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:x=>o(d.slot_id||0,x.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 --"}),Xne(t.loadedFilaments,d.nozzle_id).map(x=>i.jsxs("option",{value:x.globalTrayId,className:"bg-bambu-dark text-white",children:[x.label,": ",x.traySubBrands||x.type," (",x.colorName,")"]},x.globalTrayId))]}),m==="match"?i.jsx(Vr,{className:"w-3 h-3 text-bambu-green"}):m==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(Cn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(Cn,{className:"w-3 h-3 text-orange-400"})})]},f))]})}function J$e({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:x,targetLocation:v,onTargetLocationChange:g,slicedForModel:y}){const[_,N]=w.useState(!1),C=s?t:t.filter(ae=>ae.is_active),T=bf({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((oe,ye)=>{const Ee=T[ye];Ee?.data&&ae.set(oe.id,Ee.data)}),ae},[C,T]),k=ae=>{const oe=P.get(ae);return oe?oe.connected?!Q$e.has(oe.state??""):!0:!1},D=ae=>{const oe=P.get(ae);if(!oe)return null;if(!oe.connected)return"Offline";const ye=oe.state;return ye?ye==="RUNNING"?oe.stg_cur_name||"Printing":ye==="PREPARE"?"Preparing":ye==="PAUSE"?"Paused":ye==="IDLE"?"Idle":ye==="FINISH"?"Finished":ye==="FAILED"?"Failed":ye:null},A=w.useMemo(()=>{if(m!=="printer"||!y||_)return C;const ae=C.filter(oe=>oe.model===y);return ae.length>0?ae:C},[C,m,y,_]),R=C.length-A.length,$=w.useMemo(()=>{const ae=C.map(oe=>oe.model).filter(oe=>!!oe);return[...new Set(ae)].sort()},[C]),U=w.useMemo(()=>{if(!f)return[];const ae=C.filter(oe=>oe.model===f&&oe.location).map(oe=>oe.location).filter(oe=>!!oe);return[...new Set(ae)].sort()},[C,f]),W=p&&x&&$.length>0,O=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(lt,{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(zi,{className:"w-4 h-4"}),"No ",s?"":"active ","printers available"]});const te=ae=>{o&&k(ae)||(a?e.includes(ae)?n(e.filter(oe=>oe!==ae)):n([...e,ae]):n([ae]))},re=()=>{const ae=o?A.filter(oe=>!k(oe.id)):A;n(ae.map(oe=>oe.id))},J=()=>{n([])},le=(ae,oe,ye)=>{ye.stopPropagation(),!(!d||!u)&&(oe?d(ae):u(ae,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},me=ae=>e.includes(ae),he=e.length,X=ae=>l?.find(oe=>oe.printerId===ae);return i.jsxs("div",{className:"space-y-2 mb-6",children:[W&&i.jsxs("div",{className:"flex gap-2 mb-4",children:[i.jsxs("button",{type:"button",onClick:()=>{p("printer"),x(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(_r,{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=y&&$.includes(y)?y:$[0];x(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(Sm,{className:"w-4 h-4"}),i.jsxs("span",{className:"text-sm",children:["Any ",y||"Model"]})]})]}),m==="model"&&W&&i.jsxs("div",{className:"space-y-3 mb-4",children:[!y&&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=>{x(ae.target.value||null),g&&g(null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",children:[i.jsx("option",{value:"",children:"Select a model..."}),$.map(ae=>i.jsx("option",{value:ae,children:ae},ae))]})]}),f&&U.length>0&&g&&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=>g(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"}),U.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:he===0?"Select printers":`${he} printer${he!==1?"s":""} selected`}),i.jsxs("div",{className:"flex gap-2",children:[he0&&i.jsx("button",{type:"button",onClick:J,className:"text-bambu-gray hover:text-white transition-colors",children:"Clear"})]})]}),m==="printer"&&A.map(ae=>{const oe=me(ae.id),ye=X(ae.id),Ee=ye&&!ye.config.useDefault,q=k(ae.id),K=o&&q,E=D(ae.id);return i.jsxs("div",{children:[i.jsxs("button",{type:"button",onClick:()=>te(ae.id),disabled:K,className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${K?"border-bambu-dark-tertiary bg-bambu-dark opacity-50 cursor-not-allowed":oe?"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 ${K?"bg-bambu-dark-tertiary":oe?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:i.jsx(_r,{className:`w-5 h-5 ${K?"text-bambu-gray/50":oe?"text-bambu-green":"text-bambu-gray"}`})}),i.jsxs("div",{className:"text-left flex-1",children:[i.jsxs("p",{className:`font-medium ${K?"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]})]}),E&&i.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${q?"bg-yellow-500/20 text-yellow-400":"bg-bambu-green/20 text-bambu-green"}`,children:E}),a&&i.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${K?"border-bambu-gray/30":oe?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:oe&&i.jsx(Vr,{className:"w-3 h-3 text-white"})})]}),oe&&O&&ye&&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:j=>j.stopPropagation(),children:[i.jsx("input",{type:"checkbox",checked:Ee,onChange:j=>le(ae.id,j.target.checked,j),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 ${ye.matchStatus==="full"?"text-bambu-green":ye.matchStatus==="partial"?"text-yellow-400":"text-orange-400"}`,children:["(",ye.exactMatches,"/",ye.totalSlots," matched)"]}),ye.isLoading&&i.jsx(Sr,{className:"w-3 h-3 text-bambu-gray animate-spin"}),Ee&&i.jsxs("button",{type:"button",onClick:j=>{j.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(Uge,{className:"w-3 h-3"}),"Auto"]})]}),Ee&&i.jsx(Z$e,{printerResult:ye,filamentReqs:c.filaments,onUpdateConfig:j=>u(ae.id,j)})]})]},ae.id)}),m==="printer"&&R>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(Cn,{className:"w-3 h-3 text-yellow-400"}),R," other printer",R>1?"s":""," hidden (different model) —",i.jsx("span",{className:"underline",children:"show all"})]}),m==="printer"&&_&&y&&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 ",y," printers"]})}),m==="printer"&&he===0&&i.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[i.jsx(zi,{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(zi,{className:"w-3 h-3"}),"Select a target printer model"]})]})}const eqe=[{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 tqe({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(gC,{className:"w-4 h-4"}),i.jsx("span",{children:"Print Options"}),r?i.jsx(Sl,{className:"w-4 h-4 ml-auto"}):i.jsx(jn,{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:eqe.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 nqe({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),x=w.useRef(!1);w.useEffect(()=>{if(t.scheduleType!=="scheduled"){x.current=!1;return}if(!x.current){x.current=!0;let T;t.scheduledTime?(T=new Date(t.scheduledTime),isNaN(T.getTime())&&(T=new Date,T.setHours(T.getHours()+1,0,0,0))):(T=new Date,T.setHours(T.getHours()+1,0,0,0),e({...t,scheduledTime:jD(T)})),o(ED(T,n)),c(c8(T,r)),u(!0),p(!0)}},[t.scheduleType,t.scheduledTime,n,r,e,t]);const v=T=>{e({...t,scheduleType:T})},g=(T,P)=>{const k=dbe(T,n),D=ube(P);u(!!k),p(!!D),k&&D&&(k.setHours(D.hours,D.minutes,0,0),k>new Date&&e({...t,scheduledTime:jD(k)}))},y=T=>{o(T),g(T,l)},_=T=>{c(T),g(s,T)},N=T=>{const P=T.target.value;if(P){const k=new Date(P);isNaN(k.getTime())||(o(ED(k,n)),c(c8(k,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(Xn,{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(WY,{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:T=>y(T.target.value),placeholder:obe(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:T=>_(T.target.value),placeholder:lbe(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:T=>e({...t,requirePreviousSuccess:T.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:T=>e({...t,autoOffAfter:T.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(Su,{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 qg={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1},rqe={scheduleType:"asap",scheduledTime:"",requirePreviousSuccess:!1,autoOffAfter:!1};function Vc({mode:t,archiveId:e,libraryFileId:n,archiveName:r,queueItem:a,initialSelectedPrinterIds:s,onClose:o,onSuccess:l}){const{t:c}=Mt(),d=Zt(),{showToast:u}=hn(),{hasPermission:m}=Dr(),p=!!n&&!e,[f,x]=w.useState(()=>t==="edit-queue-item"&&a?.printer_id?[a.printer_id]:s?.length?s:[]),[v,g]=w.useState(()=>t==="edit-queue-item"&&a?a.plate_id:null),[y,_]=w.useState(()=>t==="edit-queue-item"&&a?{bed_levelling:a.bed_levelling??qg.bed_levelling,flow_cali:a.flow_cali??qg.flow_cali,vibration_cali:a.vibration_cali??qg.vibration_cali,layer_inspect:a.layer_inspect??qg.layer_inspect,timelapse:a.timelapse??qg.timelapse}:qg),[N,C]=w.useState(()=>{if(t==="edit-queue-item"&&a){let we="asap";a.manual_start?we="manual":a.scheduled_time&&!NG(a.scheduled_time)&&(we="scheduled");let Ge="";if(a.scheduled_time&&!NG(a.scheduled_time)){const rt=er(a.scheduled_time)??new Date;Ge=jD(rt)}return{scheduleType:we,scheduledTime:Ge,requirePreviousSuccess:a.require_previous_success,autoOffAfter:a.auto_off_after}}return rqe}),[T,P]=w.useState(()=>{if(t==="edit-queue-item"&&a?.ams_mapping&&Array.isArray(a.ams_mapping)){const we={};return a.ams_mapping.forEach((Ge,rt)=>{Ge!==-1&&(we[rt+1]=Ge)}),we}return{}}),[k,D]=w.useState({}),[A,R]=w.useState(()=>t==="edit-queue-item"&&a?.target_model?"model":"printer"),[$,U]=w.useState(()=>t==="edit-queue-item"&&a?.target_model?a.target_model:null),[W,O]=w.useState(()=>t==="edit-queue-item"&&a?.target_location?a.target_location:null),[te,re]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const we={};for(const Ge of a.filament_overrides)we[Ge.slot_id]={type:Ge.type,color:Ge.color};return we}return{}}),[J]=w.useState(()=>t==="edit-queue-item"&&a?.printer_id?[a.printer_id]:[]),[le]=w.useState(()=>t==="edit-queue-item"&&a?a.plate_id:null),[me,he]=w.useState(!1),[X,ae]=w.useState({current:0,total:0}),[oe,ye]=w.useState(new Set),Ee=f.length,q=f.length>0?f[0]:null,{data:K}=Ze({queryKey:["settings"],queryFn:fe.getSettings}),E=ol(K?.currency||"USD"),j=K?.default_filament_cost??0,{data:L,isLoading:G}=Ze({queryKey:["printers"],queryFn:fe.getPrinters}),{data:B}=Ze({queryKey:["archive",e],queryFn:()=>fe.getArchive(e),enabled:!!e&&!p}),{data:ie}=Ze({queryKey:["library-file",n],queryFn:()=>fe.getLibraryFile(n),enabled:p&&!!n}),z=B?.sliced_for_model||ie?.sliced_for_model||null,{data:V,isError:ee}=Ze({queryKey:["archive-plates",e],queryFn:()=>fe.getArchivePlates(e),enabled:!!e&&!p,retry:!1}),{data:Z}=Ze({queryKey:["library-file-plates",n],queryFn:()=>fe.getLibraryFilePlates(n),enabled:p&&!!n}),ne=p?Z:V,{data:se,isError:ue}=Ze({queryKey:["archive-filaments",e,v],queryFn:()=>fe.getArchiveFilamentRequirements(e,v??void 0),enabled:!!e&&!p&&(v!==null||!ne?.is_multi_plate),retry:!1}),{data:ge}=Ze({queryKey:["library-file-filaments",n,v],queryFn:()=>fe.getLibraryFileFilamentRequirements(n,v??void 0),enabled:p&&!!n&&(v!==null||!ne?.is_multi_plate)}),ce=!p&&(ee||ue),I=p?ge:se,F=w.useMemo(()=>{if(!(v===null||!ne?.plates?.length))return ne.plates.find(we=>we.index===v)?.name||void 0},[ne,v]),{data:Q}=Ze({queryKey:["available-filaments",$,W],queryFn:()=>fe.getAvailableFilaments($,W??void 0),enabled:A==="model"&&!!$}),{data:xe}=Ze({queryKey:["printer-status",q],queryFn:()=>fe.getPrinterStatus(q),enabled:!!q}),{amsMapping:pe}=Qne(I,xe,T),de=G$e(f,L,I,T,k,D);w.useEffect(()=>{ne?.plates&&ne.plates.length>=1&&!v&&g(ne.plates[0].index)},[ne,v]),w.useEffect(()=>{if(t==="edit-queue-item")return;const we=L?.filter(Ge=>Ge.is_active)||[];we.length===1&&f.length===0&&x([we[0].id])},[t,L,f.length]),w.useEffect(()=>{t==="edit-queue-item"?(JSON.stringify(f.sort())!==JSON.stringify(J.sort())||v!==le)&&(P({}),D({}),ye(new Set)):(P({}),D({}),ye(new Set))},[t,f,v,J,le]);const[Ae,_e]=w.useState($),[Ue,$e]=w.useState(v);w.useEffect(()=>{($!==Ae||v!==Ue)&&(_e($),$e(v),(t!=="edit-queue-item"||Ae!==null)&&re({}))},[$,v,Ae,Ue,t]),w.useEffect(()=>{if(!K?.per_printer_mapping_expanded||f.length<=1)return;const we=f.filter(Ge=>{if(oe.has(Ge))return!1;const rt=de.printerResults.find(vt=>vt.printerId===Ge);return rt&&rt.status&&!rt.isLoading});we.length>0&&(ye(Ge=>{const rt=new Set(Ge);return we.forEach(vt=>rt.add(vt)),rt}),we.forEach(Ge=>{de.autoConfigurePrinter(Ge)}))},[K?.per_printer_mapping_expanded,f,oe,de]),w.useEffect(()=>{const we=Ge=>{Ge.key==="Escape"&&!me&&o()};return window.addEventListener("keydown",we),()=>window.removeEventListener("keydown",we)},[o,me]);const Fe=ne?.is_multi_plate??!1,ke=ne?.plates??[],Me=dt({mutationFn:we=>fe.addToQueue(we)}),Ne=dt({mutationFn:we=>fe.updateQueueItem(a.id,we),onSuccess:()=>{d.invalidateQueries({queryKey:["queue"]}),u("Queue item updated"),l?.(),o()},onError:we=>{u(we.message||"Failed to update queue item","error")}}),Pe=async we=>{if(we?.preventDefault(),A==="printer"&&f.length===0){u("Please select at least one printer","error");return}if(A==="model"&&!$){u("Please select a target printer model","error");return}he(!0);const Ge=A==="model"?1:f.length;ae({current:0,total:Ge});const rt={success:0,failed:0,errors:[]},vt=qe=>{if(f.length>1){const ht=k[qe];if(ht&&!ht.useDefault)return de.getFinalMapping(qe)}return pe},_t=Object.keys(te).length>0?Object.entries(te).map(([qe,{type:ht,color:ft}])=>({slot_id:parseInt(qe,10),type:ht,color:ft})):void 0,kt=qe=>({printer_id:A==="printer"?qe:null,target_model:A==="model"?$:null,target_location:A==="model"?W:null,filament_overrides:A==="model"?_t:void 0,archive_id:p?void 0:e,library_file_id:p?n:void 0,require_previous_success:N.requirePreviousSuccess,auto_off_after:N.autoOffAfter,manual_start:N.scheduleType==="manual",ams_mapping:qe?vt(qe):void 0,plate_id:v,scheduled_time:N.scheduleType==="scheduled"&&N.scheduledTime?new Date(N.scheduledTime).toISOString():void 0,...y});if(A==="model"){ae({current:1,total:1});try{if(t==="reprint"){u("Model-based assignment only works with queue mode","error"),he(!1);return}else if(t==="edit-queue-item"){const qe={printer_id:null,target_model:$,target_location:W,filament_overrides:_t||null,require_previous_success:N.requirePreviousSuccess,auto_off_after:N.autoOffAfter,manual_start:N.scheduleType==="manual",ams_mapping:void 0,plate_id:v,scheduled_time:N.scheduleType==="scheduled"&&N.scheduledTime?new Date(N.scheduledTime).toISOString():null,...y};await Ne.mutateAsync(qe)}else await Me.mutateAsync(kt(null));rt.success++}catch(qe){rt.failed++,rt.errors.push(qe.message)}}else for(let qe=0;qetn.id===ht)?.name||`Printer ${ht}`;rt.errors.push(`${Bt}: ${ft.message}`)}}he(!1),rt.failed===0?(t!=="reprint"&&(A==="model"?u(t==="edit-queue-item"?"Queue item updated":`Queued for any ${$}`):t==="edit-queue-item"?u("Queue item updated"):rt.success===1?u("Print queued for printer"):u(`Print queued for ${rt.success} printers`)),d.invalidateQueries({queryKey:["queue"]}),l?.(),o()):rt.success===0?u(`Failed: ${rt.errors[0]}`,"error"):(u(`${rt.success} succeeded, ${rt.failed} failed`,"error"),d.invalidateQueries({queryKey:["queue"]}))},We=me||Ne.isPending,be=w.useMemo(()=>!(We||A==="printer"&&f.length===0||A==="model"&&!$||A==="model"&&t==="reprint"||Fe&&!v),[f.length,A,$,t,Fe,v,We]),Ce=(()=>{const we=f.length;return t==="reprint"?{title:c(p?"queue.print":"queue.reprint"),icon:_r,submitText:we>1?c("queue.printToPrinters",{count:we}):c("queue.print"),submitIcon:_r,loadingText:X.total>1?c("queue.sendingProgress",{current:X.current,total:X.total}):c("queue.sending")}:t==="add-to-queue"?{title:c("queue.schedulePrint"),icon:Xr,submitText:we>1?c("queue.queueToPrinters",{count:we}):c("queue.addToQueue"),submitIcon:Xr,loadingText:X.total>1?c("queue.addingProgress",{current:X.current,total:X.total}):c("queue.adding")}:{title:c("queue.editQueueItem"),icon:Ki,submitText:c("common.save"),submitIcon:Ki,loadingText:X.total>1?c("queue.savingProgress",{current:X.current,total:X.total}):c("common.saving")}})(),Ve=Ce.icon,je=Ce.submitIcon,Re=q&&(p||(Fe?v!==null:!0));return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:me?void 0:o,children:i.jsx(Tt,{className:"w-full max-w-2xl max-h-[90vh] overflow-y-auto",onClick:we=>we.stopPropagation(),children:i.jsxs(Pt,{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(Ve,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:Ce.title})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:o,disabled:me,children:i.jsx(zt,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:Pe,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&&L?i.jsx("span",{className:"text-white",children:L.find(we=>we.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(X$e,{plates:ke,isMultiPlate:Fe,selectedPlate:v,onSelect:g}),!s?.length&&i.jsx(J$e,{printers:L||[],selectedPrinterIds:f,onMultiSelect:x,isLoading:G,allowMultiple:!0,showInactive:t==="edit-queue-item",disableBusy:t==="reprint",printerMappingResults:de.printerResults,filamentReqs:I,onAutoConfigurePrinter:de.autoConfigurePrinter,onUpdatePrinterConfig:de.updatePrinterConfig,assignmentMode:t==="reprint"?"printer":A,onAssignmentModeChange:t!=="reprint"?R:void 0,targetModel:$,onTargetModelChange:t!=="reprint"?U:void 0,targetLocation:W,onTargetLocationChange:t!=="reprint"?O:void 0,slicedForModel:z}),A==="model"&&$&&I&&Q&&Q.length>0&&i.jsx(Y$e,{filamentReqs:I,availableFilaments:Q,overrides:te,onChange:re}),z&&A==="printer"&&f.length===1&&(()=>{const we=L?.find(Ge=>Ge.id===f[0]);return we&&we.model&&z!==we.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(Cn,{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 ",z,", but printing on ",we.model]})]}):null})(),ce&&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(zi,{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."})]}),Re&&!ce&&f.length===1&&i.jsx(K$e,{printerId:q,filamentReqs:I,manualMappings:T,onManualMappingChange:P,defaultExpanded:!!s?.length||(K?.per_printer_mapping_expanded??!1),currencySymbol:E,defaultCostPerKg:j}),(t==="reprint"||Ee>0||A==="model"&&$)&&i.jsx(tqe,{options:y,onChange:_,defaultExpanded:!!s?.length}),t!=="reprint"&&i.jsx(nqe,{options:N,onChange:C,dateFormat:K?.date_format||"system",timeFormat:K?.time_format||"system",canControlPrinter:m("printers:control")}),Ne.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:Ne.error?.message||"Failed to complete operation"}),i.jsxs("div",{className:`flex gap-3 ${t==="reprint"?"":"pt-2"}`,children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:o,className:"flex-1",disabled:me,children:"Cancel"}),i.jsx(Oe,{type:"submit",disabled:!be,className:"flex-1",children:We?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),Ce.loadingText]}):i.jsxs(i.Fragment,{children:[i.jsx(je,{className:"w-4 h-4"}),Ce.submitText]})})]})]})]})})})}function Jne(t){if(!t)return"/img/printers/default.png";const e=t.toLowerCase().replace(/\s+/g,"");return e.includes("x1e")?"/img/printers/x1e.png":e.includes("x1c")||e.includes("x1carbon")||e.includes("x1")?"/img/printers/x1c.png":e.includes("h2dpro")||e.includes("h2d-pro")?"/img/printers/h2dpro.png":e.includes("h2d")?"/img/printers/h2d.png":e.includes("h2c")?"/img/printers/h2c.png":e.includes("h2s")?"/img/printers/h2d.png":e.includes("p2s")||e.includes("p1s")?"/img/printers/p1s.png":e.includes("p1p")?"/img/printers/p1p.png":e.includes("a1mini")?"/img/printers/a1mini.png":e.includes("a1")?"/img/printers/a1.png":"/img/printers/default.png"}function ere(t){return t>=-50?{labelKey:"printers.wifiSignal.excellent",color:"text-bambu-green",bars:4}:t>=-60?{labelKey:"printers.wifiSignal.good",color:"text-bambu-green",bars:3}:t>=-70?{labelKey:"printers.wifiSignal.fair",color:"text-yellow-400",bars:2}:t>=-80?{labelKey:"printers.wifiSignal.weak",color:"text-orange-400",bars:1}:{labelKey:"printers.wifiSignal.veryWeak",color:"text-red-400",bars:1}}function TG({value:t}){const{t:e}=Mt(),[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(Vr,{className:"w-3.5 h-3.5 text-bambu-green"}):i.jsx(_l,{className:"w-3.5 h-3.5"})})}function iqe({printer:t,status:e,totalPrintHours:n,onClose:r}){const{t:a}=Mt();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(TG,{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(TG,{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(GF,{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=ere(e.wifi_signal);s.push({label:a("printers.wifiSignalLabel"),value:i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(ZY,{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:Wp(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(Tt,{className:"w-full max-w-md",onClick:o=>o.stopPropagation(),children:i.jsxs(Pt,{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(zt,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsx("div",{className:"flex justify-center mb-4",children:i.jsx("img",{src:Jne(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 aqe(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 sj({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&&aqe(t)?"#000":"#fff"},children:r})})}const PG={"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"},sqe={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 oj(t){if(!t)return null;if(PG[t])return PG[t];const e=t.split("-");if(e.length<2)return null;const n=e[1];return sqe[n]||null}function lj(t){return(t??.02).toFixed(3)}function AG({side:t}){const{mode:e}=xf(),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 tre(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 nre(t,e){return t?t.startsWith("HH")?e("printers.nozzleHighFlow"):t.startsWith("HS")?e("printers.nozzleStandardFlow"):"":""}function rre({slot:t,index:e,activeStatus:n,filamentName:r,children:a}){const{t:s}=Mt(),[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,x=t.stat===1;w.useEffect(()=>{if(o&&u.current&&m.current){const C=u.current.getBoundingClientRect(),T=m.current.offsetHeight,k=C.top-56,D=window.innerHeight-C.bottom;kk?d("bottom"):d("top")}},[o]);const v=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>l(!0),80)},g=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>l(!1),100)};w.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const y=F4(t.filament_color),_=tre(t.nozzle_type,s),N=nre(t.nozzle_type,s);return i.jsxs("div",{ref:u,className:"relative",onMouseEnter:v,onMouseLeave:g,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"} animate-in fade-in-0 zoom-in-95 duration-150 diff --git a/static/index.html b/static/index.html index 777d26cea..53cfbca5a 100644 --- a/static/index.html +++ b/static/index.html @@ -23,7 +23,7 @@ - +