From 46f2b8ee0da50c8430ae704db9e32dc977a68645 Mon Sep 17 00:00:00 2001 From: maziggy Date: Sun, 15 Feb 2026 08:33:59 +0100 Subject: [PATCH] fix: AMS slot configure modal not pre-populating black filament color The color pre-population logic skipped hex 000000 (black) to guard against empty/uninitialized slots, but empty slots already don't pass trayColor to the modal. Removed the unnecessary check so black filament color is now pre-populated like any other color. --- CHANGELOG.md | 1 + frontend/src/components/ConfigureAmsSlotModal.tsx | 4 ++-- static/assets/{index-CS3Lw7Ok.js => index-C3i3HoUc.js} | 2 +- static/index.html | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) rename static/assets/{index-CS3Lw7Ok.js => index-C3i3HoUc.js} (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 177709b6c..fd9606533 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ All notable changes to Bambuddy will be documented in this file. - **RFID Spool Data Erased by Periodic AMS Updates** — Periodic MQTT push-all responses cleared `tag_uid` and `tray_uuid` fields because they were included in the "always update" list. These fields are now preserved during updates and only cleared when a spool is physically removed (slot clearing detected by empty `tray_type`). This fixes the AMS "eye" icon disappearing for RFID spools after startup. - **AMS Slot Configuration Overwrites RFID Spool State** — Configuring an AMS slot for an RFID-detected Bambu Lab spool sent `ams_set_filament_setting`, which replaced the firmware's RFID-managed filament config with a manual one — causing the slicer's "eye" icon to change to a "pen" icon. Now detects RFID spools and skips the filament setting command, only sending K-profile selection. - **K-Profile Selection Corrupts Existing Profiles on X1C/P1S** — The `extrusion_cali_sel` command included a `setting_id` field that BambuStudio never sends, causing firmware to mislink calibration data. The `extrusion_cali_set` command was sent unconditionally, overwriting existing profile metadata. Now `setting_id` is removed from selection commands, and `extrusion_cali_set` is only sent when no existing profile is selected (`cali_idx < 0`). +- **AMS Slot Configure — Black Filament Color Not Pre-Populated** — When re-opening the Configure AMS Slot modal for a slot with black filament, the color field was empty despite the preset and K-profile being correctly pre-selected. The color pre-population logic excluded hex `000000` (black) as a guard against empty slots, but empty slots already skip color data entirely. Removed the unnecessary check so black is now pre-populated like any other color. ### Improved - **SQLite WAL Mode for Database Reliability** — Database now uses Write-Ahead Logging (WAL) mode with a 5-second busy timeout, reducing "database is locked" errors under concurrent access. WAL mode allows simultaneous reads during writes, improving responsiveness for multi-printer setups. Automatically enabled on startup. diff --git a/frontend/src/components/ConfigureAmsSlotModal.tsx b/frontend/src/components/ConfigureAmsSlotModal.tsx index 75497ffa4..f52fbd88f 100644 --- a/frontend/src/components/ConfigureAmsSlotModal.tsx +++ b/frontend/src/components/ConfigureAmsSlotModal.tsx @@ -693,10 +693,10 @@ export function ConfigureAmsSlotModal({ } } - // Pre-populate color from current slot + // Pre-populate color from current slot (black is valid — empty slots don't pass trayColor) if (slotInfo.trayColor) { const hex = slotInfo.trayColor.slice(0, 6); - if (hex && hex !== '000000') { + if (hex) { setColorHex(hex); } } diff --git a/static/assets/index-CS3Lw7Ok.js b/static/assets/index-C3i3HoUc.js similarity index 99% rename from static/assets/index-CS3Lw7Ok.js rename to static/assets/index-C3i3HoUc.js index 69ebe21ea..a36052742 100644 --- a/static/assets/index-CS3Lw7Ok.js +++ b/static/assets/index-C3i3HoUc.js @@ -8482,7 +8482,7 @@ void main() { border-l-[5px] border-l-transparent border-r-[5px] border-r-transparent border-t-[5px] border-t-bambu-dark-tertiary - `})]})]})}function gHe({isOpen:t,onClose:e,tagUid:n,trayUuid:r,printerId:i,amsId:s,trayId:o}){const{t:l}=Ut(),c=Zt(),{showToast:u}=hn(),[d,h]=w.useState(""),{data:f,isLoading:p}=et({queryKey:["inventory-spools"],queryFn:()=>ae.getSpools(!1),enabled:t}),x=w.useMemo(()=>f?f.filter(b=>{if(b.tag_uid||b.tray_uuid)return!1;if(!d)return!0;const y=d.toLowerCase();return b.material.toLowerCase().includes(y)||b.brand&&b.brand.toLowerCase().includes(y)||b.color_name&&b.color_name.toLowerCase().includes(y)}):[],[f,d]),v=ot({mutationFn:b=>ae.linkTagToSpool(b,{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"]}),u(l("inventory.tagLinked"),"success"),e()},onError:b=>{u(b.message||l("inventory.tagLinkFailed"),"error")}});return t?a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[a.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),a.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:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[a.jsxs("div",{children:[a.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Vb,{className:"w-5 h-5 text-bambu-green"}),l("inventory.linkToSpool")]}),a.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["AMS ",s," T",o," · Printer #",i]})]}),a.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:a.jsx(Rt,{className:"w-5 h-5"})})]}),a.jsxs("div",{className:"p-4 border-b border-white/10",children:[a.jsxs("div",{className:"relative",children:[a.jsx(Br,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),a.jsx("input",{type:"text",value:d,onChange:b=>h(b.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)&&a.jsxs("p",{className:"text-xs text-bambu-gray mt-2 font-mono truncate",title:n||r,children:["Tag: ",n||r]})]}),a.jsx("div",{className:"flex-1 overflow-y-auto p-2 min-h-0",children:p?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(it,{className:"w-6 h-6 animate-spin text-bambu-green"})}):x.length===0?a.jsx("p",{className:"text-center text-bambu-gray py-8 text-sm",children:l("inventory.noSpoolsMatch")}):x.map(b=>a.jsxs("button",{onClick:()=>v.mutate(b.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:[a.jsx("span",{className:"w-6 h-6 rounded-full border border-white/20 flex-shrink-0",style:{backgroundColor:b.rgba?`#${b.rgba.substring(0,6)}`:"#808080"}}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"text-sm text-white font-medium truncate",children:[b.brand?`${b.brand} `:"",b.material,b.subtype?` ${b.subtype}`:""]}),a.jsxs("div",{className:"text-xs text-bambu-gray truncate",children:[b.color_name||"No color"," · #",b.id]})]}),a.jsxs("span",{className:"text-xs text-bambu-gray",children:[Math.round(b.label_weight-b.weight_used),"g"]})]},b.id))}),a.jsx("div",{className:"p-4 border-t border-white/10 flex justify-end",children:a.jsx(Te,{variant:"ghost",onClick:e,children:l("inventory.cancel")||"Cancel"})})]})]}):null}function bHe({isOpen:t,onClose:e,printerId:n,amsId:r,trayId:i,trayInfo:s}){const{t:o}=Ut(),l=Zt(),{showToast:c}=hn(),[u,d]=w.useState(null),[h,f]=w.useState(""),{data:p,isLoading:x}=et({queryKey:["inventory-spools"],queryFn:()=>ae.getSpools(),enabled:t}),{data:v}=et({queryKey:["spool-assignments"],queryFn:()=>ae.getAssignments(),enabled:t}),b=ot({mutationFn:T=>ae.assignSpool({spool_id:T,printer_id:n,ams_id:r,tray_id:i}),onSuccess:T=>{l.setQueryData(["spool-assignments"],C=>{const j=(C||[]).filter(E=>!(E.printer_id===n&&E.ams_id===r&&E.tray_id===i));return j.push(T),j}),l.invalidateQueries({queryKey:["spool-assignments"]}),c(o("inventory.assignSuccess"),"success"),e()},onError:T=>{c(`${o("inventory.assignFailed")}: ${T.message}`,"error")}});if(!t)return null;const y=new Set((v||[]).filter(T=>!(T.printer_id===n&&T.ams_id===r&&T.tray_id===i)).map(T=>T.spool_id)),S=r===254||r===255,N=p?.filter(T=>!y.has(T.id)&&(S||!T.tag_uid&&!T.tray_uuid)),M=N?.filter(T=>{if(!h)return!0;const C=h.toLowerCase();return T.material.toLowerCase().includes(C)||(T.brand?.toLowerCase().includes(C)??!1)||(T.color_name?.toLowerCase().includes(C)??!1)||(T.subtype?.toLowerCase().includes(C)??!1)}),k=()=>{u&&b.mutate(u)};return a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[a.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),a.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:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ra,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:o("inventory.assignSpool")})]}),a.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:a.jsx(Rt,{className:"w-5 h-5"})})]}),a.jsxs("div",{className:"p-4 space-y-4",children:[s&&a.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsxs("p",{className:"text-xs text-bambu-gray mb-1",children:[o("inventory.selectSpool"),":"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[s.color&&a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20",style:{backgroundColor:`#${s.color}`}}),a.jsx("span",{className:"text-white font-medium",children:s.type||o("ams.emptySlot")}),a.jsxs("span",{className:"text-bambu-gray",children:["(",s.location,")"]})]})]}),a.jsxs("div",{className:"relative",children:[a.jsx(Br,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),a.jsx("input",{type:"text",value:h,onChange:T=>f(T.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"})]}),a.jsx("div",{children:x?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(it,{className:"w-6 h-6 text-bambu-green animate-spin"})}):M&&M.length>0?a.jsx("div",{className:"max-h-64 overflow-y-auto space-y-2",children:M.map(T=>a.jsx("button",{onClick:()=>d(T.id),className:`w-full p-3 rounded-lg border text-left transition-colors ${u===T.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:a.jsxs("div",{className:"flex items-center gap-2",children:[T.rgba&&a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20 flex-shrink-0",style:{backgroundColor:`#${T.rgba.substring(0,6)}`}}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("p",{className:"text-white font-medium truncate",children:[T.brand?`${T.brand} `:"",T.material,T.subtype?` ${T.subtype}`:""]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[T.color_name||"",T.label_weight?` - ${T.label_weight}g`:"",T.weight_used>0?` (${Math.round(T.weight_used)}g used)`:""]})]}),u===T.id&&a.jsx(Yr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]})},T.id))}):N&&N.length===0?a.jsx("div",{className:"text-center py-8 text-bambu-gray",children:a.jsx("p",{children:o("inventory.noManualSpools")})}):a.jsx("div",{className:"text-center py-8 text-bambu-gray",children:a.jsx("p",{children:o("inventory.noSpoolsMatch")})})})]}),a.jsxs("div",{className:"flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary",children:[a.jsx(Te,{variant:"secondary",onClick:e,children:o("common.cancel")}),a.jsx(Te,{onClick:k,disabled:!u||b.isPending,children:b.isPending?a.jsxs(a.Fragment,{children:[a.jsx(it,{className:"w-4 h-4 animate-spin"}),o("inventory.assigning")]}):a.jsxs(a.Fragment,{children:[a.jsx(ra,{className:"w-4 h-4"}),o("inventory.assignSpool")]})})]}),b.isError&&a.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:b.error.message})]})]})}function xHe(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 i=String.fromCharCode(65+n);return r?`HT-${i}`:`AMS-${i}`}function MS(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 yHe=["PLA","PETG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function Q7(t){const e=t.replace(/@.+$/,"").trim(),n=e.toUpperCase();for(const i of yHe){const s=new RegExp(`\\b${i}\\b`,"i");if(s.test(n)){const o=e.split(s),l=o[0]?.trim()||"",c=o[1]?.trim()||"";return{material:i,brand:l,variant:c}}}const r=e.split(/\s+/);return r.length>=2?{material:r[1],brand:r[0],variant:r.slice(2).join(" ")}:{material:e,brand:"",variant:""}}function vHe(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const wHe={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"},_He=[{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"}],SHe=[{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 NHe(t){const e=t.toLowerCase().trim();return wHe[e]||null}function CHe(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 kHe({isOpen:t,onClose:e,printerId:n,slotInfo:r,nozzleDiameter:i="0.4",printerModel:s,onSuccess:o}){const{t:l}=Ut(),[c,u]=w.useState(""),[d,h]=w.useState(null),[f,p]=w.useState(""),[x,v]=w.useState(""),[b,y]=w.useState(""),[S,N]=w.useState(!1),[M,k]=w.useState(!1),{data:T,isLoading:C,isError:j}=et({queryKey:["cloudSettings"],queryFn:()=>ae.getCloudSettings(),enabled:t,retry:!1}),{data:E,isLoading:P}=et({queryKey:["localPresets"],queryFn:()=>ae.getLocalPresets(),enabled:t}),{data:U,isLoading:L}=et({queryKey:["builtinFilaments"],queryFn:()=>ae.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:B,isLoading:D}=et({queryKey:["kprofiles",n,i],queryFn:()=>ae.getKProfiles(n,i),enabled:t&&!!n}),{data:$}=et({queryKey:["colorCatalog"],queryFn:()=>ae.getColorCatalog(),enabled:t,staleTime:1/0}),q=ot({mutationFn:async()=>{if(!c)throw new Error("No filament preset selected");const ue=c.startsWith("local_"),Re=c.startsWith("builtin_"),le=ue?parseInt(c.replace("local_",""),10):null,se=Re?c.replace("builtin_",""):null,Ne=ue?E?.filament.find(ge=>ge.id===le):null,J=Re?U?.find(ge=>ge.filament_id===se):null,Le=!ue&&!Re?T?.filament.find(ge=>ge.setting_id===c):null;if(!ue&&!Re&&!Le)throw new Error("Selected preset not found");if(ue&&!Ne)throw new Error("Selected local preset not found");if(Re&&!J)throw new Error("Selected builtin preset not found");const V=ue?Ne.name:Re?J.name:Le.name,Y=Q7(V),ce=d?.slot_id??-1,H=f||r.trayColor?.slice(0,6)||"FFFFFF",Z=V.replace(/@.+$/,"").trim();let de,pe;if(ue)de="",pe="";else if(Re)de=se,pe="";else if(de=MS(c),pe=c,!c.startsWith("GFS"))try{const ge=await ae.getCloudSettingDetail(c);ge.filament_id?de=ge.filament_id:ge.base_id&&(de=MS(ge.base_id),console.log(`Derived tray_info_idx from base_id: ${ge.base_id} -> ${de}`))}catch(ge){console.warn("Failed to fetch preset detail for filament_id:",ge)}let ve=ue&&Ne?.nozzle_temp_min?Ne.nozzle_temp_min:190,ee=ue&&Ne?.nozzle_temp_max?Ne.nozzle_temp_max:230;if(!ue||Re||!Ne?.nozzle_temp_min&&!Ne?.nozzle_temp_max){const ge=(ue&&Ne?.filament_type||Y.material).toUpperCase();ge.includes("PLA")?(ve=190,ee=230):ge.includes("PETG")?(ve=220,ee=260):ge.includes("ABS")||ge.includes("ASA")?(ve=240,ee=280):ge.includes("TPU")?(ve=200,ee=240):ge.includes("PC")?(ve=260,ee=300):(ge.includes("PA")||ge.includes("NYLON"))&&(ve=250,ee=290)}const z=d?.k_value?parseFloat(d.k_value):0,F=ue?Ne?.filament_type||Y.material||"PLA":Y.material||"PLA",W=await ae.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:de,tray_type:F,tray_sub_brands:Z,tray_color:H+"FF",nozzle_temp_min:ve,nozzle_temp_max:ee,cali_idx:ce,nozzle_diameter:i,setting_id:pe,kprofile_filament_id:d?.filament_id,kprofile_setting_id:d?.setting_id||void 0,k_value:z}),me=ue?`local_${le}`:Re?`builtin_${se}`:c,Se=ue?"local":Re?"builtin":"cloud";try{await ae.saveSlotPreset(n,r.amsId,r.trayId,me,Z,Se)}catch(ge){console.warn("Failed to save slot preset mapping:",ge)}return W},onSuccess:()=>{N(!0),o?.(),setTimeout(()=>{N(!1),e()},1500)}}),I=ot({mutationFn:async()=>ae.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{N(!0),o?.(),setTimeout(()=>{N(!1),e()},1500)}}),K=w.useMemo(()=>{const ue=b.toLowerCase(),Re=[],le=new Set,se=r.savedPresetId,Ne=r.trayInfoIdx;if(T?.filament)for(const J of T.filament){le.add(J.setting_id);const Le=se===J.setting_id||Ne&&(J.setting_id===Ne||MS(J.setting_id)===Ne);if(!(!Le&&ue&&!J.name.toLowerCase().includes(ue))){if(!Le&&s){const V=CHe(J.name);if(V&&V.toUpperCase()!==s.toUpperCase())continue}Re.push({id:J.setting_id,name:J.name,source:"cloud",isUser:vHe(J.setting_id)})}}if(E?.filament)for(const J of E.filament){const Le=`local_${J.id}`,V=se===Le;if(!(!V&&ue&&!J.name.toLowerCase().includes(ue))){if(!V&&s&&J.compatible_printers){const Y=J.compatible_printers.split(";").map(ce=>{const H=ce.trim(),Z=H.match(/^BBL\s+(.+)/i);return Z?Z[1].trim().toUpperCase():H.toUpperCase()}).filter(Boolean);if(Y.length>0&&!Y.includes(s.toUpperCase()))continue}Re.push({id:Le,name:J.name,source:"local",isUser:!1})}}if(U)for(const J of U){if(le.has(J.filament_id))continue;const Le=J.filament_id.startsWith("GF")?"GFS"+J.filament_id.slice(2):J.filament_id;le.has(Le)||(!ue||J.name.toLowerCase().includes(ue))&&Re.push({id:`builtin_${J.filament_id}`,name:J.name,source:"builtin",isUser:!1})}return Re.sort((J,Le)=>{const V={cloud:0,local:1,builtin:2};return J.source!==Le.source?V[J.source]-V[Le.source]:J.isUser&&!Le.isUser?-1:!J.isUser&&Le.isUser?1:J.name.localeCompare(Le.name)})},[T?.filament,E?.filament,U,b,s,r.savedPresetId,r.trayInfoIdx]),Q=w.useMemo(()=>{if(!c)return null;let ue=null;if(c.startsWith("local_")){const se=parseInt(c.replace("local_",""),10);ue=E?.filament.find(J=>J.id===se)?.name||null}else if(c.startsWith("builtin_")){const se=c.replace("builtin_","");ue=U?.find(J=>J.filament_id===se)?.name||null}else T?.filament&&(ue=T.filament.find(Ne=>Ne.setting_id===c)?.name||null);if(!ue)return null;let Re=ue.replace(/@.+$/,"").trim();Re.startsWith("# ")&&(Re=Re.slice(2).trim());const le=Q7(Re);return{fullName:Re,material:le.material,brand:le.brand}},[c,T?.filament,E?.filament,U]),ie=Q?.fullName||"",G=w.useMemo(()=>{if(!$||!Q)return[];const{fullName:ue,brand:Re}=Q,le=ue.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return $.filter(se=>{const Ne=(se.material||"").toUpperCase(),J=se.manufacturer.toUpperCase();if(!(Ne===le.toUpperCase()||Ne.includes(le.toUpperCase())||le.toUpperCase().includes(Ne)))return!1;if(Re){const V=Re.toUpperCase();if(!J.includes(V)&&!V.includes(J))return!1}return!0})},[$,Q]),X=w.useMemo(()=>{if(!B?.profiles||!Q)return[];const{fullName:ue,material:Re,brand:le}=Q,se=ue.toUpperCase(),Ne=Re.toUpperCase(),J=le.toUpperCase();if(!Ne||Ne.length<2)return[];const Le=B.profiles.filter(Y=>{const ce=Y.name.toUpperCase();if(J)return!(!ce.includes(J)||!ce.includes(Ne));if(ce.includes(se)||ce.includes(Ne))return!0;const Z={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[Ne]||[];for(const de of Z)if(ce.includes(de))return!0;return!1}),V=new Map;for(const Y of Le){const ce=`${Y.name}|${Y.k_value}`,H=V.get(ce);H?r.extruderId!==void 0&&Y.extruder_id===r.extruderId&&H.extruder_id!==r.extruderId&&V.set(ce,Y):V.set(ce,Y)}return Array.from(V.values())},[B?.profiles,Q]);w.useEffect(()=>{if(t){if(r.savedPresetId)u(r.savedPresetId);else if(r.trayInfoIdx&&T?.filament){let ue=T.filament.find(Re=>Re.setting_id===r.trayInfoIdx);ue||(ue=T.filament.find(Re=>MS(Re.setting_id)===r.trayInfoIdx)),ue&&u(ue.setting_id)}if(r.trayColor){const ue=r.trayColor.slice(0,6);ue&&ue!=="000000"&&p(ue)}}else u(""),h(null),p(""),v(""),y(""),N(!1)},[t,r.savedPresetId,r.trayInfoIdx,r.trayColor,T?.filament]),w.useEffect(()=>{if(X.length>0){if(r.caliIdx!=null&&r.caliIdx>0){const ue=X.find(Re=>Re.slot_id===r.caliIdx);if(ue){h(ue);return}}h(X[0])}else h(null)},[c,X,r.caliIdx]);const ne=w.useCallback(ue=>{ue.key==="Escape"&&e()},[e]);if(w.useEffect(()=>{if(t)return document.addEventListener("keydown",ne),()=>document.removeEventListener("keydown",ne)},[t,ne]),!t)return null;const te=C&&!j||P||L||D,xe=c&&!q.isPending,he=f||r.trayColor?.slice(0,6)||"FFFFFF";return a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[a.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),a.jsxs("div",{className:"relative w-full max-w-lg mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(nd,{className:"w-5 h-5 text-bambu-blue"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:l("configureAmsSlot.title")})]}),a.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:a.jsx(Rt,{className:"w-5 h-5"})})]}),a.jsxs("div",{className:"p-4 space-y-4 max-h-[60vh] overflow-y-auto",children:[S&&a.jsx("div",{className:"absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl",children:a.jsxs("div",{className:"text-center space-y-3",children:[a.jsx(ub,{className:"w-16 h-16 text-bambu-green mx-auto"}),a.jsx("p",{className:"text-lg font-semibold text-white",children:l("configureAmsSlot.slotConfigured")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:l("configureAmsSlot.settingsSentToPrinter")})]})}),a.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:l("configureAmsSlot.configuringSlot")}),a.jsxs("div",{className:"flex items-center gap-2",children:[r.trayColor&&a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),a.jsx("span",{className:"text-white font-medium",children:l("configureAmsSlot.slotLabel",{ams:xHe(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&a.jsxs("span",{className:"text-bambu-gray",children:["(",r.traySubBrands,")"]})]})]}),te?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(it,{className:"w-6 h-6 text-bambu-green animate-spin"})}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[l("configureAmsSlot.filamentProfile")," ",a.jsx("span",{className:"text-red-400",children:"*"})]}),a.jsxs("div",{className:"relative",children:[a.jsx("input",{type:"text",placeholder:l("configureAmsSlot.searchPresets"),value:b,onChange:ue=>y(ue.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"}),a.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:K.length===0?a.jsx("p",{className:"text-center py-4 text-bambu-gray",children:T?.filament?.length===0&&!E?.filament?.length?l("configureAmsSlot.noPresetsAvailable"):l("configureAmsSlot.noMatchingPresets")}):K.map(ue=>a.jsx("button",{ref:c===ue.id?Re=>{Re?.scrollIntoView({block:"nearest"})}:void 0,onClick:()=>u(ue.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${c===ue.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-white text-sm truncate",children:ue.name}),a.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[ue.source==="local"&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:l("profiles.localProfiles.badge")}),ue.source==="builtin"&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:l("configureAmsSlot.builtin")}),ue.isUser&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:l("configureAmsSlot.custom")})]})]})},ue.id))})]})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[l("configureAmsSlot.kProfileLabel"),ie&&a.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:l("configureAmsSlot.filteringFor",{material:ie})})]}),X.length>0?a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:d?.name||"",onChange:ue=>{const Re=X.find(le=>le.name===ue.target.value);h(Re||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:[a.jsx("option",{value:"",children:l("configureAmsSlot.noKProfile")}),X.map(ue=>a.jsxs("option",{value:ue.name,children:[ue.name," (K=",ue.k_value,")"]},`${ue.name}-${ue.extruder_id}`))]}),a.jsx(Jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):c?a.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:l("configureAmsSlot.noMatchingKProfiles")}):a.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:l("configureAmsSlot.selectFilamentFirst")}),d&&a.jsx("p",{className:"text-xs text-bambu-green mt-1",children:l("configureAmsSlot.kFromCalibration",{value:d.k_value})})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:l("configureAmsSlot.customColorLabel")}),G.length>0&&a.jsxs("div",{className:"mb-3",children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:l("configureAmsSlot.presetColors",{name:Q?.fullName})}),a.jsx("div",{className:"flex flex-wrap gap-1.5",children:G.map(ue=>a.jsxs("button",{onClick:()=>{const Re=ue.hex_color.replace("#","").toUpperCase();p(Re),v(ue.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===ue.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:ue.color_name,children:[a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/30 flex-shrink-0",style:{backgroundColor:ue.hex_color}}),a.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:ue.color_name})]},ue.id))})]}),a.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[_He.map(ue=>a.jsx("button",{onClick:()=>{p(ue.hex),v(ue.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===ue.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${ue.hex}`},title:ue.name},ue.hex)),a.jsx("button",{onClick:()=>k(!M),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:l(M?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:M?"−":"+"})]}),M&&a.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:SHe.map(ue=>a.jsx("button",{onClick:()=>{p(ue.hex),v(ue.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===ue.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${ue.hex}`},title:ue.name},ue.hex))}),a.jsxs("div",{className:"flex gap-2 items-center",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${he}`}}),a.jsx("input",{type:"text",placeholder:l("configureAmsSlot.colorPlaceholder"),value:x,onChange:ue=>{const Re=ue.target.value;v(Re);const le=NHe(Re);if(le)p(le);else{const se=Re.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();se.length===6?p(se):se.length===3&&p(se.split("").map(Ne=>Ne+Ne).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&&a.jsx("button",{onClick:()=>{p(""),v("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:l("configureAmsSlot.clearCustomColor"),children:l("configureAmsSlot.clear")})]}),f&&a.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:l("configureAmsSlot.hexLabel",{hex:f})})]})]})]}),a.jsxs("div",{className:"flex justify-between p-4 border-t border-bambu-dark-tertiary",children:[a.jsx(Te,{variant:"secondary",onClick:()=>I.mutate(),disabled:I.isPending||q.isPending,className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:I.isPending?a.jsxs(a.Fragment,{children:[a.jsx(it,{className:"w-4 h-4 animate-spin"}),l("configureAmsSlot.resetting")]}):a.jsxs(a.Fragment,{children:[a.jsx(Do,{className:"w-4 h-4"}),l("configureAmsSlot.resetSlot")]})}),a.jsxs("div",{className:"flex gap-2",children:[a.jsx(Te,{variant:"secondary",onClick:e,children:l("configureAmsSlot.cancel")}),a.jsx(Te,{onClick:()=>q.mutate(),disabled:!xe,children:q.isPending?a.jsxs(a.Fragment,{children:[a.jsx(it,{className:"w-4 h-4 animate-spin"}),l("configureAmsSlot.configuring")]}):a.jsxs(a.Fragment,{children:[a.jsx(nd,{className:"w-4 h-4"}),l("configureAmsSlot.configureSlot")]})})]})]}),(q.isError||I.isError)&&a.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:q.error?.message||I.error?.message})]})]})}const Z7={"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"},MHe={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 XP(t){if(!t)return null;if(Z7[t])return Z7[t];const e=t.split("-");if(e.length<2)return null;const n=e[1];return MHe[n]||null}function YP(t){if(!t||t.length<6)return"Unknown";const e=parseInt(t.substring(0,2),16),n=parseInt(t.substring(2,4),16),r=parseInt(t.substring(4,6),16),i=Math.max(e,n,r)/255,s=Math.min(e,n,r)/255,o=(i+s)/2;let l=0,c=0;if(i!==s){const u=i-s;c=o>.5?u/(2-i-s):u/(i+s);const d=e/255,h=n/255,f=r/255;i===d?l=((h-f)/u+(h.85?"White":c<.15?o<.4?"Dark Gray":o>.6?"Light Gray":"Gray":l>=15&&l<45&&o<.45||l>=45&&l<70&&o<.4?"Brown":l<15||l>=345?"Red":l<45?"Orange":l<70?"Yellow":l<150?"Green":l<200?"Cyan":l<260?"Blue":l<290?"Purple":"Pink"}function QP(t){return(t??.02).toFixed(3)}function J7({side:t}){const{mode:e}=rp(),n=e==="dark"?"#1a4d2e":"#e7f5e9";return a.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 b4(t){if(!t||t==="00000000"||t.length<6)return null;const e=t.slice(0,2),n=t.slice(2,4),r=t.slice(4,6),i=t.length>=8?parseInt(t.slice(6,8),16)/255:1;return i===0?null:`rgba(${parseInt(e,16)}, ${parseInt(n,16)}, ${parseInt(r,16)}, ${i})`}function AHe(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 nne(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 rne(t,e){return t?t.startsWith("HH")?e("printers.nozzleHighFlow"):t.startsWith("HS")?e("printers.nozzleStandardFlow"):"":""}function ine({slot:t,index:e,activeStatus:n,filamentName:r,children:i}){const{t:s}=Ut(),[o,l]=w.useState(!1),[c,u]=w.useState("top"),d=w.useRef(null),h=w.useRef(null),f=w.useRef(null),p=!t.nozzle_diameter&&!t.nozzle_type,x=t.stat===1;w.useEffect(()=>{if(o&&d.current&&h.current){const M=d.current.getBoundingClientRect(),k=h.current.offsetHeight,C=M.top-56,j=window.innerHeight-M.bottom;CC?u("bottom"):u("top")}},[o]);const v=()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>l(!0),80)},b=()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>l(!1),100)};w.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]);const y=b4(t.filament_color),S=nne(t.nozzle_type,s),N=rne(t.nozzle_type,s);return a.jsxs("div",{ref:d,className:"relative",onMouseEnter:v,onMouseLeave:b,children:[i,o&&a.jsxs("div",{ref:h,className:` + `})]})]})}function gHe({isOpen:t,onClose:e,tagUid:n,trayUuid:r,printerId:i,amsId:s,trayId:o}){const{t:l}=Ut(),c=Zt(),{showToast:u}=hn(),[d,h]=w.useState(""),{data:f,isLoading:p}=et({queryKey:["inventory-spools"],queryFn:()=>ae.getSpools(!1),enabled:t}),x=w.useMemo(()=>f?f.filter(b=>{if(b.tag_uid||b.tray_uuid)return!1;if(!d)return!0;const y=d.toLowerCase();return b.material.toLowerCase().includes(y)||b.brand&&b.brand.toLowerCase().includes(y)||b.color_name&&b.color_name.toLowerCase().includes(y)}):[],[f,d]),v=ot({mutationFn:b=>ae.linkTagToSpool(b,{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"]}),u(l("inventory.tagLinked"),"success"),e()},onError:b=>{u(b.message||l("inventory.tagLinkFailed"),"error")}});return t?a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[a.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),a.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:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[a.jsxs("div",{children:[a.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Vb,{className:"w-5 h-5 text-bambu-green"}),l("inventory.linkToSpool")]}),a.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["AMS ",s," T",o," · Printer #",i]})]}),a.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:a.jsx(Rt,{className:"w-5 h-5"})})]}),a.jsxs("div",{className:"p-4 border-b border-white/10",children:[a.jsxs("div",{className:"relative",children:[a.jsx(Br,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),a.jsx("input",{type:"text",value:d,onChange:b=>h(b.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)&&a.jsxs("p",{className:"text-xs text-bambu-gray mt-2 font-mono truncate",title:n||r,children:["Tag: ",n||r]})]}),a.jsx("div",{className:"flex-1 overflow-y-auto p-2 min-h-0",children:p?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(it,{className:"w-6 h-6 animate-spin text-bambu-green"})}):x.length===0?a.jsx("p",{className:"text-center text-bambu-gray py-8 text-sm",children:l("inventory.noSpoolsMatch")}):x.map(b=>a.jsxs("button",{onClick:()=>v.mutate(b.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:[a.jsx("span",{className:"w-6 h-6 rounded-full border border-white/20 flex-shrink-0",style:{backgroundColor:b.rgba?`#${b.rgba.substring(0,6)}`:"#808080"}}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"text-sm text-white font-medium truncate",children:[b.brand?`${b.brand} `:"",b.material,b.subtype?` ${b.subtype}`:""]}),a.jsxs("div",{className:"text-xs text-bambu-gray truncate",children:[b.color_name||"No color"," · #",b.id]})]}),a.jsxs("span",{className:"text-xs text-bambu-gray",children:[Math.round(b.label_weight-b.weight_used),"g"]})]},b.id))}),a.jsx("div",{className:"p-4 border-t border-white/10 flex justify-end",children:a.jsx(Te,{variant:"ghost",onClick:e,children:l("inventory.cancel")||"Cancel"})})]})]}):null}function bHe({isOpen:t,onClose:e,printerId:n,amsId:r,trayId:i,trayInfo:s}){const{t:o}=Ut(),l=Zt(),{showToast:c}=hn(),[u,d]=w.useState(null),[h,f]=w.useState(""),{data:p,isLoading:x}=et({queryKey:["inventory-spools"],queryFn:()=>ae.getSpools(),enabled:t}),{data:v}=et({queryKey:["spool-assignments"],queryFn:()=>ae.getAssignments(),enabled:t}),b=ot({mutationFn:T=>ae.assignSpool({spool_id:T,printer_id:n,ams_id:r,tray_id:i}),onSuccess:T=>{l.setQueryData(["spool-assignments"],C=>{const j=(C||[]).filter(E=>!(E.printer_id===n&&E.ams_id===r&&E.tray_id===i));return j.push(T),j}),l.invalidateQueries({queryKey:["spool-assignments"]}),c(o("inventory.assignSuccess"),"success"),e()},onError:T=>{c(`${o("inventory.assignFailed")}: ${T.message}`,"error")}});if(!t)return null;const y=new Set((v||[]).filter(T=>!(T.printer_id===n&&T.ams_id===r&&T.tray_id===i)).map(T=>T.spool_id)),S=r===254||r===255,N=p?.filter(T=>!y.has(T.id)&&(S||!T.tag_uid&&!T.tray_uuid)),M=N?.filter(T=>{if(!h)return!0;const C=h.toLowerCase();return T.material.toLowerCase().includes(C)||(T.brand?.toLowerCase().includes(C)??!1)||(T.color_name?.toLowerCase().includes(C)??!1)||(T.subtype?.toLowerCase().includes(C)??!1)}),k=()=>{u&&b.mutate(u)};return a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[a.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),a.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:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ra,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:o("inventory.assignSpool")})]}),a.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:a.jsx(Rt,{className:"w-5 h-5"})})]}),a.jsxs("div",{className:"p-4 space-y-4",children:[s&&a.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsxs("p",{className:"text-xs text-bambu-gray mb-1",children:[o("inventory.selectSpool"),":"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[s.color&&a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20",style:{backgroundColor:`#${s.color}`}}),a.jsx("span",{className:"text-white font-medium",children:s.type||o("ams.emptySlot")}),a.jsxs("span",{className:"text-bambu-gray",children:["(",s.location,")"]})]})]}),a.jsxs("div",{className:"relative",children:[a.jsx(Br,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),a.jsx("input",{type:"text",value:h,onChange:T=>f(T.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"})]}),a.jsx("div",{children:x?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(it,{className:"w-6 h-6 text-bambu-green animate-spin"})}):M&&M.length>0?a.jsx("div",{className:"max-h-64 overflow-y-auto space-y-2",children:M.map(T=>a.jsx("button",{onClick:()=>d(T.id),className:`w-full p-3 rounded-lg border text-left transition-colors ${u===T.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:a.jsxs("div",{className:"flex items-center gap-2",children:[T.rgba&&a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20 flex-shrink-0",style:{backgroundColor:`#${T.rgba.substring(0,6)}`}}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("p",{className:"text-white font-medium truncate",children:[T.brand?`${T.brand} `:"",T.material,T.subtype?` ${T.subtype}`:""]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[T.color_name||"",T.label_weight?` - ${T.label_weight}g`:"",T.weight_used>0?` (${Math.round(T.weight_used)}g used)`:""]})]}),u===T.id&&a.jsx(Yr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]})},T.id))}):N&&N.length===0?a.jsx("div",{className:"text-center py-8 text-bambu-gray",children:a.jsx("p",{children:o("inventory.noManualSpools")})}):a.jsx("div",{className:"text-center py-8 text-bambu-gray",children:a.jsx("p",{children:o("inventory.noSpoolsMatch")})})})]}),a.jsxs("div",{className:"flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary",children:[a.jsx(Te,{variant:"secondary",onClick:e,children:o("common.cancel")}),a.jsx(Te,{onClick:k,disabled:!u||b.isPending,children:b.isPending?a.jsxs(a.Fragment,{children:[a.jsx(it,{className:"w-4 h-4 animate-spin"}),o("inventory.assigning")]}):a.jsxs(a.Fragment,{children:[a.jsx(ra,{className:"w-4 h-4"}),o("inventory.assignSpool")]})})]}),b.isError&&a.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:b.error.message})]})]})}function xHe(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 i=String.fromCharCode(65+n);return r?`HT-${i}`:`AMS-${i}`}function MS(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 yHe=["PLA","PETG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function Q7(t){const e=t.replace(/@.+$/,"").trim(),n=e.toUpperCase();for(const i of yHe){const s=new RegExp(`\\b${i}\\b`,"i");if(s.test(n)){const o=e.split(s),l=o[0]?.trim()||"",c=o[1]?.trim()||"";return{material:i,brand:l,variant:c}}}const r=e.split(/\s+/);return r.length>=2?{material:r[1],brand:r[0],variant:r.slice(2).join(" ")}:{material:e,brand:"",variant:""}}function vHe(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const wHe={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"},_He=[{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"}],SHe=[{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 NHe(t){const e=t.toLowerCase().trim();return wHe[e]||null}function CHe(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 kHe({isOpen:t,onClose:e,printerId:n,slotInfo:r,nozzleDiameter:i="0.4",printerModel:s,onSuccess:o}){const{t:l}=Ut(),[c,u]=w.useState(""),[d,h]=w.useState(null),[f,p]=w.useState(""),[x,v]=w.useState(""),[b,y]=w.useState(""),[S,N]=w.useState(!1),[M,k]=w.useState(!1),{data:T,isLoading:C,isError:j}=et({queryKey:["cloudSettings"],queryFn:()=>ae.getCloudSettings(),enabled:t,retry:!1}),{data:E,isLoading:P}=et({queryKey:["localPresets"],queryFn:()=>ae.getLocalPresets(),enabled:t}),{data:U,isLoading:L}=et({queryKey:["builtinFilaments"],queryFn:()=>ae.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:B,isLoading:D}=et({queryKey:["kprofiles",n,i],queryFn:()=>ae.getKProfiles(n,i),enabled:t&&!!n}),{data:$}=et({queryKey:["colorCatalog"],queryFn:()=>ae.getColorCatalog(),enabled:t,staleTime:1/0}),q=ot({mutationFn:async()=>{if(!c)throw new Error("No filament preset selected");const ue=c.startsWith("local_"),Re=c.startsWith("builtin_"),le=ue?parseInt(c.replace("local_",""),10):null,se=Re?c.replace("builtin_",""):null,Ne=ue?E?.filament.find(ge=>ge.id===le):null,J=Re?U?.find(ge=>ge.filament_id===se):null,Le=!ue&&!Re?T?.filament.find(ge=>ge.setting_id===c):null;if(!ue&&!Re&&!Le)throw new Error("Selected preset not found");if(ue&&!Ne)throw new Error("Selected local preset not found");if(Re&&!J)throw new Error("Selected builtin preset not found");const V=ue?Ne.name:Re?J.name:Le.name,Y=Q7(V),ce=d?.slot_id??-1,H=f||r.trayColor?.slice(0,6)||"FFFFFF",Z=V.replace(/@.+$/,"").trim();let de,pe;if(ue)de="",pe="";else if(Re)de=se,pe="";else if(de=MS(c),pe=c,!c.startsWith("GFS"))try{const ge=await ae.getCloudSettingDetail(c);ge.filament_id?de=ge.filament_id:ge.base_id&&(de=MS(ge.base_id),console.log(`Derived tray_info_idx from base_id: ${ge.base_id} -> ${de}`))}catch(ge){console.warn("Failed to fetch preset detail for filament_id:",ge)}let ve=ue&&Ne?.nozzle_temp_min?Ne.nozzle_temp_min:190,ee=ue&&Ne?.nozzle_temp_max?Ne.nozzle_temp_max:230;if(!ue||Re||!Ne?.nozzle_temp_min&&!Ne?.nozzle_temp_max){const ge=(ue&&Ne?.filament_type||Y.material).toUpperCase();ge.includes("PLA")?(ve=190,ee=230):ge.includes("PETG")?(ve=220,ee=260):ge.includes("ABS")||ge.includes("ASA")?(ve=240,ee=280):ge.includes("TPU")?(ve=200,ee=240):ge.includes("PC")?(ve=260,ee=300):(ge.includes("PA")||ge.includes("NYLON"))&&(ve=250,ee=290)}const z=d?.k_value?parseFloat(d.k_value):0,F=ue?Ne?.filament_type||Y.material||"PLA":Y.material||"PLA",W=await ae.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:de,tray_type:F,tray_sub_brands:Z,tray_color:H+"FF",nozzle_temp_min:ve,nozzle_temp_max:ee,cali_idx:ce,nozzle_diameter:i,setting_id:pe,kprofile_filament_id:d?.filament_id,kprofile_setting_id:d?.setting_id||void 0,k_value:z}),me=ue?`local_${le}`:Re?`builtin_${se}`:c,Se=ue?"local":Re?"builtin":"cloud";try{await ae.saveSlotPreset(n,r.amsId,r.trayId,me,Z,Se)}catch(ge){console.warn("Failed to save slot preset mapping:",ge)}return W},onSuccess:()=>{N(!0),o?.(),setTimeout(()=>{N(!1),e()},1500)}}),I=ot({mutationFn:async()=>ae.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{N(!0),o?.(),setTimeout(()=>{N(!1),e()},1500)}}),K=w.useMemo(()=>{const ue=b.toLowerCase(),Re=[],le=new Set,se=r.savedPresetId,Ne=r.trayInfoIdx;if(T?.filament)for(const J of T.filament){le.add(J.setting_id);const Le=se===J.setting_id||Ne&&(J.setting_id===Ne||MS(J.setting_id)===Ne);if(!(!Le&&ue&&!J.name.toLowerCase().includes(ue))){if(!Le&&s){const V=CHe(J.name);if(V&&V.toUpperCase()!==s.toUpperCase())continue}Re.push({id:J.setting_id,name:J.name,source:"cloud",isUser:vHe(J.setting_id)})}}if(E?.filament)for(const J of E.filament){const Le=`local_${J.id}`,V=se===Le;if(!(!V&&ue&&!J.name.toLowerCase().includes(ue))){if(!V&&s&&J.compatible_printers){const Y=J.compatible_printers.split(";").map(ce=>{const H=ce.trim(),Z=H.match(/^BBL\s+(.+)/i);return Z?Z[1].trim().toUpperCase():H.toUpperCase()}).filter(Boolean);if(Y.length>0&&!Y.includes(s.toUpperCase()))continue}Re.push({id:Le,name:J.name,source:"local",isUser:!1})}}if(U)for(const J of U){if(le.has(J.filament_id))continue;const Le=J.filament_id.startsWith("GF")?"GFS"+J.filament_id.slice(2):J.filament_id;le.has(Le)||(!ue||J.name.toLowerCase().includes(ue))&&Re.push({id:`builtin_${J.filament_id}`,name:J.name,source:"builtin",isUser:!1})}return Re.sort((J,Le)=>{const V={cloud:0,local:1,builtin:2};return J.source!==Le.source?V[J.source]-V[Le.source]:J.isUser&&!Le.isUser?-1:!J.isUser&&Le.isUser?1:J.name.localeCompare(Le.name)})},[T?.filament,E?.filament,U,b,s,r.savedPresetId,r.trayInfoIdx]),Q=w.useMemo(()=>{if(!c)return null;let ue=null;if(c.startsWith("local_")){const se=parseInt(c.replace("local_",""),10);ue=E?.filament.find(J=>J.id===se)?.name||null}else if(c.startsWith("builtin_")){const se=c.replace("builtin_","");ue=U?.find(J=>J.filament_id===se)?.name||null}else T?.filament&&(ue=T.filament.find(Ne=>Ne.setting_id===c)?.name||null);if(!ue)return null;let Re=ue.replace(/@.+$/,"").trim();Re.startsWith("# ")&&(Re=Re.slice(2).trim());const le=Q7(Re);return{fullName:Re,material:le.material,brand:le.brand}},[c,T?.filament,E?.filament,U]),ie=Q?.fullName||"",G=w.useMemo(()=>{if(!$||!Q)return[];const{fullName:ue,brand:Re}=Q,le=ue.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return $.filter(se=>{const Ne=(se.material||"").toUpperCase(),J=se.manufacturer.toUpperCase();if(!(Ne===le.toUpperCase()||Ne.includes(le.toUpperCase())||le.toUpperCase().includes(Ne)))return!1;if(Re){const V=Re.toUpperCase();if(!J.includes(V)&&!V.includes(J))return!1}return!0})},[$,Q]),X=w.useMemo(()=>{if(!B?.profiles||!Q)return[];const{fullName:ue,material:Re,brand:le}=Q,se=ue.toUpperCase(),Ne=Re.toUpperCase(),J=le.toUpperCase();if(!Ne||Ne.length<2)return[];const Le=B.profiles.filter(Y=>{const ce=Y.name.toUpperCase();if(J)return!(!ce.includes(J)||!ce.includes(Ne));if(ce.includes(se)||ce.includes(Ne))return!0;const Z={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[Ne]||[];for(const de of Z)if(ce.includes(de))return!0;return!1}),V=new Map;for(const Y of Le){const ce=`${Y.name}|${Y.k_value}`,H=V.get(ce);H?r.extruderId!==void 0&&Y.extruder_id===r.extruderId&&H.extruder_id!==r.extruderId&&V.set(ce,Y):V.set(ce,Y)}return Array.from(V.values())},[B?.profiles,Q,r.extruderId]);w.useEffect(()=>{if(t){if(r.savedPresetId)u(r.savedPresetId);else if(r.trayInfoIdx&&T?.filament){let ue=T.filament.find(Re=>Re.setting_id===r.trayInfoIdx);ue||(ue=T.filament.find(Re=>MS(Re.setting_id)===r.trayInfoIdx)),ue&&u(ue.setting_id)}if(r.trayColor){const ue=r.trayColor.slice(0,6);ue&&p(ue)}}else u(""),h(null),p(""),v(""),y(""),N(!1)},[t,r.savedPresetId,r.trayInfoIdx,r.trayColor,T?.filament]),w.useEffect(()=>{if(X.length>0){if(r.caliIdx!=null&&r.caliIdx>0){const ue=X.find(Re=>Re.slot_id===r.caliIdx);if(ue){h(ue);return}}h(X[0])}else h(null)},[c,X,r.caliIdx]);const ne=w.useCallback(ue=>{ue.key==="Escape"&&e()},[e]);if(w.useEffect(()=>{if(t)return document.addEventListener("keydown",ne),()=>document.removeEventListener("keydown",ne)},[t,ne]),!t)return null;const te=C&&!j||P||L||D,xe=c&&!q.isPending,he=f||r.trayColor?.slice(0,6)||"FFFFFF";return a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[a.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),a.jsxs("div",{className:"relative w-full max-w-lg mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(nd,{className:"w-5 h-5 text-bambu-blue"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:l("configureAmsSlot.title")})]}),a.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:a.jsx(Rt,{className:"w-5 h-5"})})]}),a.jsxs("div",{className:"p-4 space-y-4 max-h-[60vh] overflow-y-auto",children:[S&&a.jsx("div",{className:"absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl",children:a.jsxs("div",{className:"text-center space-y-3",children:[a.jsx(ub,{className:"w-16 h-16 text-bambu-green mx-auto"}),a.jsx("p",{className:"text-lg font-semibold text-white",children:l("configureAmsSlot.slotConfigured")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:l("configureAmsSlot.settingsSentToPrinter")})]})}),a.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:l("configureAmsSlot.configuringSlot")}),a.jsxs("div",{className:"flex items-center gap-2",children:[r.trayColor&&a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),a.jsx("span",{className:"text-white font-medium",children:l("configureAmsSlot.slotLabel",{ams:xHe(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&a.jsxs("span",{className:"text-bambu-gray",children:["(",r.traySubBrands,")"]})]})]}),te?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(it,{className:"w-6 h-6 text-bambu-green animate-spin"})}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[l("configureAmsSlot.filamentProfile")," ",a.jsx("span",{className:"text-red-400",children:"*"})]}),a.jsxs("div",{className:"relative",children:[a.jsx("input",{type:"text",placeholder:l("configureAmsSlot.searchPresets"),value:b,onChange:ue=>y(ue.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"}),a.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:K.length===0?a.jsx("p",{className:"text-center py-4 text-bambu-gray",children:T?.filament?.length===0&&!E?.filament?.length?l("configureAmsSlot.noPresetsAvailable"):l("configureAmsSlot.noMatchingPresets")}):K.map(ue=>a.jsx("button",{ref:c===ue.id?Re=>{Re?.scrollIntoView({block:"nearest"})}:void 0,onClick:()=>u(ue.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${c===ue.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-white text-sm truncate",children:ue.name}),a.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[ue.source==="local"&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:l("profiles.localProfiles.badge")}),ue.source==="builtin"&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:l("configureAmsSlot.builtin")}),ue.isUser&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:l("configureAmsSlot.custom")})]})]})},ue.id))})]})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[l("configureAmsSlot.kProfileLabel"),ie&&a.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:l("configureAmsSlot.filteringFor",{material:ie})})]}),X.length>0?a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:d?.name||"",onChange:ue=>{const Re=X.find(le=>le.name===ue.target.value);h(Re||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:[a.jsx("option",{value:"",children:l("configureAmsSlot.noKProfile")}),X.map(ue=>a.jsxs("option",{value:ue.name,children:[ue.name," (K=",ue.k_value,")"]},`${ue.name}-${ue.extruder_id}`))]}),a.jsx(Jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):c?a.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:l("configureAmsSlot.noMatchingKProfiles")}):a.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:l("configureAmsSlot.selectFilamentFirst")}),d&&a.jsx("p",{className:"text-xs text-bambu-green mt-1",children:l("configureAmsSlot.kFromCalibration",{value:d.k_value})})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:l("configureAmsSlot.customColorLabel")}),G.length>0&&a.jsxs("div",{className:"mb-3",children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:l("configureAmsSlot.presetColors",{name:Q?.fullName})}),a.jsx("div",{className:"flex flex-wrap gap-1.5",children:G.map(ue=>a.jsxs("button",{onClick:()=>{const Re=ue.hex_color.replace("#","").toUpperCase();p(Re),v(ue.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===ue.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:ue.color_name,children:[a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/30 flex-shrink-0",style:{backgroundColor:ue.hex_color}}),a.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:ue.color_name})]},ue.id))})]}),a.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[_He.map(ue=>a.jsx("button",{onClick:()=>{p(ue.hex),v(ue.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===ue.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${ue.hex}`},title:ue.name},ue.hex)),a.jsx("button",{onClick:()=>k(!M),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:l(M?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:M?"−":"+"})]}),M&&a.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:SHe.map(ue=>a.jsx("button",{onClick:()=>{p(ue.hex),v(ue.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===ue.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${ue.hex}`},title:ue.name},ue.hex))}),a.jsxs("div",{className:"flex gap-2 items-center",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${he}`}}),a.jsx("input",{type:"text",placeholder:l("configureAmsSlot.colorPlaceholder"),value:x,onChange:ue=>{const Re=ue.target.value;v(Re);const le=NHe(Re);if(le)p(le);else{const se=Re.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();se.length===6?p(se):se.length===3&&p(se.split("").map(Ne=>Ne+Ne).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&&a.jsx("button",{onClick:()=>{p(""),v("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:l("configureAmsSlot.clearCustomColor"),children:l("configureAmsSlot.clear")})]}),f&&a.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:l("configureAmsSlot.hexLabel",{hex:f})})]})]})]}),a.jsxs("div",{className:"flex justify-between p-4 border-t border-bambu-dark-tertiary",children:[a.jsx(Te,{variant:"secondary",onClick:()=>I.mutate(),disabled:I.isPending||q.isPending,className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:I.isPending?a.jsxs(a.Fragment,{children:[a.jsx(it,{className:"w-4 h-4 animate-spin"}),l("configureAmsSlot.resetting")]}):a.jsxs(a.Fragment,{children:[a.jsx(Do,{className:"w-4 h-4"}),l("configureAmsSlot.resetSlot")]})}),a.jsxs("div",{className:"flex gap-2",children:[a.jsx(Te,{variant:"secondary",onClick:e,children:l("configureAmsSlot.cancel")}),a.jsx(Te,{onClick:()=>q.mutate(),disabled:!xe,children:q.isPending?a.jsxs(a.Fragment,{children:[a.jsx(it,{className:"w-4 h-4 animate-spin"}),l("configureAmsSlot.configuring")]}):a.jsxs(a.Fragment,{children:[a.jsx(nd,{className:"w-4 h-4"}),l("configureAmsSlot.configureSlot")]})})]})]}),(q.isError||I.isError)&&a.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:q.error?.message||I.error?.message})]})]})}const Z7={"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"},MHe={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 XP(t){if(!t)return null;if(Z7[t])return Z7[t];const e=t.split("-");if(e.length<2)return null;const n=e[1];return MHe[n]||null}function YP(t){if(!t||t.length<6)return"Unknown";const e=parseInt(t.substring(0,2),16),n=parseInt(t.substring(2,4),16),r=parseInt(t.substring(4,6),16),i=Math.max(e,n,r)/255,s=Math.min(e,n,r)/255,o=(i+s)/2;let l=0,c=0;if(i!==s){const u=i-s;c=o>.5?u/(2-i-s):u/(i+s);const d=e/255,h=n/255,f=r/255;i===d?l=((h-f)/u+(h.85?"White":c<.15?o<.4?"Dark Gray":o>.6?"Light Gray":"Gray":l>=15&&l<45&&o<.45||l>=45&&l<70&&o<.4?"Brown":l<15||l>=345?"Red":l<45?"Orange":l<70?"Yellow":l<150?"Green":l<200?"Cyan":l<260?"Blue":l<290?"Purple":"Pink"}function QP(t){return(t??.02).toFixed(3)}function J7({side:t}){const{mode:e}=rp(),n=e==="dark"?"#1a4d2e":"#e7f5e9";return a.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 b4(t){if(!t||t==="00000000"||t.length<6)return null;const e=t.slice(0,2),n=t.slice(2,4),r=t.slice(4,6),i=t.length>=8?parseInt(t.slice(6,8),16)/255:1;return i===0?null:`rgba(${parseInt(e,16)}, ${parseInt(n,16)}, ${parseInt(r,16)}, ${i})`}function AHe(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 nne(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 rne(t,e){return t?t.startsWith("HH")?e("printers.nozzleHighFlow"):t.startsWith("HS")?e("printers.nozzleStandardFlow"):"":""}function ine({slot:t,index:e,activeStatus:n,filamentName:r,children:i}){const{t:s}=Ut(),[o,l]=w.useState(!1),[c,u]=w.useState("top"),d=w.useRef(null),h=w.useRef(null),f=w.useRef(null),p=!t.nozzle_diameter&&!t.nozzle_type,x=t.stat===1;w.useEffect(()=>{if(o&&d.current&&h.current){const M=d.current.getBoundingClientRect(),k=h.current.offsetHeight,C=M.top-56,j=window.innerHeight-M.bottom;CC?u("bottom"):u("top")}},[o]);const v=()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>l(!0),80)},b=()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>l(!1),100)};w.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]);const y=b4(t.filament_color),S=nne(t.nozzle_type,s),N=rne(t.nozzle_type,s);return a.jsxs("div",{ref:d,className:"relative",onMouseEnter:v,onMouseLeave:b,children:[i,o&&a.jsxs("div",{ref:h,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 2330089ed..f731634d0 100644 --- a/static/index.html +++ b/static/index.html @@ -23,7 +23,7 @@ - +