diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bf9d0faf..b1c154fad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to Bambuddy will be documented in this file. - **Per-User Email Notifications** ([#693](https://github.com/maziggy/bambuddy/pull/693)) — When Advanced Authentication is enabled, individual users can now receive email notifications for their own print jobs. A new "Notifications" page lets each user toggle notifications for print start, complete, failed, and stopped events. Only prints submitted by that user trigger their email — other users' prints are not affected. Requires SMTP to be configured and the "User Notifications" toggle enabled in Settings → Notifications. Administrators and Operators have access by default; Viewers do not. Contributed by @cadtoolbox. ### Fixed +- **AMS Slot Search Shows Unrelated Profiles** ([#681](https://github.com/maziggy/bambuddy/issues/681)) — Searching for a non-existent filament profile in the AMS slot configuration showed profiles matching the currently loaded filament type (e.g. "Generic PLA" variants) instead of an empty result. The search filter was bypassed for all presets sharing the same `tray_info_idx` as the current slot, not just the exact saved preset. Now only the one configured preset bypasses the search filter. Reported by @RosdasHH. - **Virtual Printer FTP Routed to Wrong VP** ([#735](https://github.com/maziggy/bambuddy/issues/735)) — When running multiple virtual printers with different access codes on separate bind IPs, FTP connections were routed to the wrong VP. Root cause: the iptables `REDIRECT` rule rewrites the destination IP to the incoming interface's primary address, so all FTP traffic went to the first VP regardless of the intended target. Fix: FTP server now binds directly to port 990 (standard implicit FTPS), eliminating the need for iptables redirect. Requires `CAP_NET_BIND_SERVICE` (already set in the systemd service and Docker image). Also removed a global `set_exception_handler()` in the MQTT server that caused spurious error messages when running multiple VPs. See `docs/migration-vp-ftp-port.md` for migration steps. Reported by @VREmma. - **X1C Virtual Printer Not Accepting Sends** ([#735](https://github.com/maziggy/bambuddy/issues/735)) — X1C (and X1) virtual printers were advertised with legacy SSDP model codes (`3DPrinter-X1-Carbon` / `3DPrinter-X1`) that BambuStudio doesn't recognize, causing "incompatible printer preset" when sending. Fixed to use the correct codes (`BL-P001` / `BL-P002`). Also fixed proxy mode auto-inherit storing the printer's display name (e.g. `X1C`) instead of the SSDP code. Existing VPs are automatically migrated on startup. Reported by @RosdasHH. - **White Filament Color Swatches Invisible in Light Theme** ([#726](https://github.com/maziggy/bambuddy/issues/726)) — Filament color circles used a white border that was invisible against light theme backgrounds, making white spools indistinguishable. Changed to a dark border (`border-black/20`) across all views: Inventory, Archives, Assign Spool, Configure AMS Slot, Calendar, Projects, Filament Trends, Local Profiles, Link Spool, and Spoolman Settings. Reported by user. diff --git a/frontend/src/components/ConfigureAmsSlotModal.tsx b/frontend/src/components/ConfigureAmsSlotModal.tsx index 40892d0c8..e53abbd30 100644 --- a/frontend/src/components/ConfigureAmsSlotModal.tsx +++ b/frontend/src/components/ConfigureAmsSlotModal.tsx @@ -512,9 +512,11 @@ export function ConfigureAmsSlotModal({ for (const cp of cloudSettings.filament) { coveredIds.add(cp.setting_id); // Keep preset if it matches the slot's saved mapping or current tray_info_idx - const isCurrentPreset = savedId === cp.setting_id + const isSavedPreset = savedId === cp.setting_id; + const isCurrentPreset = isSavedPreset || (trayIdx && (cp.setting_id === trayIdx || convertToTrayInfoIdx(cp.setting_id) === trayIdx)); - if (!isCurrentPreset && query && !cp.name.toLowerCase().includes(query)) continue; + // Only the exact saved preset bypasses search — trayIdx matches are too broad + if (!isSavedPreset && query && !cp.name.toLowerCase().includes(query)) continue; // Filter by printer model if set (skip for current preset) if (!isCurrentPreset && printerModel) { const presetModel = extractPresetModel(cp.name); diff --git a/static/assets/index-BAXfE2V4.js b/static/assets/index-DTIUjlhj.js similarity index 98% rename from static/assets/index-BAXfE2V4.js rename to static/assets/index-DTIUjlhj.js index 05e37e280..95211dc91 100644 --- a/static/assets/index-BAXfE2V4.js +++ b/static/assets/index-DTIUjlhj.js @@ -8507,7 +8507,7 @@ void main() { ${o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})}`:g.type==="partial_profile"?Q=`${o("inventory.assignPartialMismatchMessage",{spoolMaterial:g.spoolMaterial,trayMaterial:g.trayMaterial,location:s.location})} -${o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})}`:g.type==="profile"&&(Q=o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})),i.jsx(_n,{title:o("inventory.assignMismatchTitle"),message:Q,confirmText:o("inventory.assignMismatchConfirm"),variant:"warning",isLoading:k.isPending,onConfirm:ie,onCancel:()=>{k.isPending||(b(!1),y(null),_(null))}})})()]})}function oW(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 T1(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 Xv=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function lW(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 Xv)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 Xv){const o=new RegExp(`\\b${s}\\b`,"i");if(o.test(n)){const l=e.split(o),c=l[0]?.trim()||"",u=l[1]?.trim()||"";return{material:s,brand:c,variant:u}}}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 Mqe(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const Eqe={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"},cW=[{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"}],uW=[{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 dW(t){const e=t.toLowerCase().trim();return Eqe[e]||null}function jqe(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 Xre({isOpen:t,onClose:e,printerId:n,slotInfo:r,nozzleDiameter:a="0.4",printerModel:s,onSuccess:o,fullScreen:l}){const{t:c}=Rt(),[u,d]=w.useState(""),[m,p]=w.useState(null),[f,y]=w.useState(""),[v,b]=w.useState(""),[g,_]=w.useState(""),[N,T]=w.useState(!1),[C,P]=w.useState(!1),k=w.useRef(""),{data:R,isLoading:A,isError:D}=tt({queryKey:["cloudSettings"],queryFn:()=>fe.getCloudSettings(),enabled:t,retry:!1}),{data:B,isLoading:z}=tt({queryKey:["localPresets"],queryFn:()=>fe.getLocalPresets(),enabled:t}),{data:W,isLoading:I}=tt({queryKey:["builtinFilaments"],queryFn:()=>fe.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:J,isLoading:ie}=tt({queryKey:["kprofiles",n,a],queryFn:()=>fe.getKProfiles(n,a),enabled:t&&!!n}),{data:Q}=tt({queryKey:["colorCatalog"],queryFn:()=>fe.getColorCatalog(),enabled:t,staleTime:1/0}),ue=ft({mutationFn:async()=>{if(!u)throw new Error("No filament preset selected");const E=u.startsWith("local_"),U=u.startsWith("builtin_"),K=E?parseInt(u.replace("local_",""),10):null,$=U?u.replace("builtin_",""):null,ne=E?B?.filament.find(Le=>Le.id===K):null,O=U?W?.find(Le=>Le.filament_id===$):null,V=!E&&!U?R?.filament.find(Le=>Le.setting_id===u):null;if(!E&&!U&&!V)throw new Error("Selected preset not found");if(E&&!ne)throw new Error("Selected local preset not found");if(U&&!O)throw new Error("Selected builtin preset not found");const ee=E?ne.name:U?O.name:V.name,G=lW(ee),re=m?.slot_id??-1,ce=f||r.trayColor?.slice(0,6)||"FFFFFF",ge=ee.replace(/@.+$/,"").trim();let xe,ae;const L=G.material.toUpperCase();if(E){const Le=(Xv.includes(L)?L:ne?.filament_type||G.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"};xe=$e[Le]||$e[Le.replace(/[-\s]?CF$/,"")]||$e[Le.replace(/\+$/,"")]||$e[Le.split(/[-\s]/)[0]]||"",ae=""}else if(U)xe=$,ae="";else if(xe=T1(u),ae=u,!u.startsWith("GFS"))try{const Le=await fe.getCloudSettingDetail(u);Le.filament_id?xe=Le.filament_id:Le.base_id&&(xe=T1(Le.base_id),console.log(`Derived tray_info_idx from base_id: ${Le.base_id} -> ${xe}`))}catch(Le){console.warn("Failed to fetch preset detail for filament_id:",Le)}let F=E&&ne?.nozzle_temp_min?ne.nozzle_temp_min:190,te=E&&ne?.nozzle_temp_max?ne.nozzle_temp_max:230;if(!E||U||!ne?.nozzle_temp_min&&!ne?.nozzle_temp_max){const Le=(E?Xv.includes(L)?L:ne?.filament_type||G.material||"":G.material).toUpperCase();Le.includes("PLA")?(F=190,te=230):Le.includes("PETG")?(F=220,te=260):Le.includes("ABS")||Le.includes("ASA")?(F=240,te=280):Le.includes("TPU")?(F=200,te=240):Le==="PCTG"?(F=220,te=260):Le.includes("PC")?(F=260,te=300):(Le.includes("PA")||Le.includes("NYLON"))&&(F=250,te=290)}const ve=m?.k_value?parseFloat(m.k_value):0,he=E?Xv.includes(L)?L:ne?.filament_type||G.material||"PLA":G.material||"PLA",de=await fe.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:xe,tray_type:he,tray_sub_brands:ge,tray_color:ce+"FF",nozzle_temp_min:F,nozzle_temp_max:te,cali_idx:re,nozzle_diameter:a,setting_id:ae,kprofile_filament_id:m?.filament_id,kprofile_setting_id:m?.setting_id||void 0,k_value:ve}),ke=E?`local_${K}`:U?`builtin_${$}`:u,_e=E?"local":U?"builtin":"cloud";try{await fe.saveSlotPreset(n,r.amsId,r.trayId,ke,ge,_e)}catch(Le){console.warn("Failed to save slot preset mapping:",Le)}return de},onSuccess:()=>{T(!0),o?.(),setTimeout(()=>{T(!1),e()},1500)}}),me=ft({mutationFn:async()=>fe.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{T(!0),o?.(),setTimeout(()=>{T(!1),e()},1500)}}),pe=w.useMemo(()=>{const E=g.toLowerCase(),U=[],K=new Set,$=r.savedPresetId,ne=r.trayInfoIdx;if(R?.filament)for(const O of R.filament){K.add(O.setting_id);const V=$===O.setting_id||ne&&(O.setting_id===ne||T1(O.setting_id)===ne);if(!(!V&&E&&!O.name.toLowerCase().includes(E))){if(!V&&s){const ee=jqe(O.name);if(ee&&ee.toUpperCase()!==s.toUpperCase())continue}U.push({id:O.setting_id,name:O.name,source:"cloud",isUser:Mqe(O.setting_id)})}}if(B?.filament)for(const O of B.filament){const V=`local_${O.id}`;!($===V)&&E&&!O.name.toLowerCase().includes(E)||U.push({id:V,name:O.name,source:"local",isUser:!1})}if(W)for(const O of W){if(K.has(O.filament_id))continue;const V=O.filament_id.startsWith("GF")?"GFS"+O.filament_id.slice(2):O.filament_id;K.has(V)||(!E||O.name.toLowerCase().includes(E))&&U.push({id:`builtin_${O.filament_id}`,name:O.name,source:"builtin",isUser:!1})}return U.sort((O,V)=>{const ee={cloud:0,local:1,builtin:2};return O.source!==V.source?ee[O.source]-ee[V.source]:O.isUser&&!V.isUser?-1:!O.isUser&&V.isUser?1:O.name.localeCompare(V.name)})},[R?.filament,B?.filament,W,g,s,r.savedPresetId,r.trayInfoIdx]),Y=w.useMemo(()=>{if(!u)return null;let E=null;if(u.startsWith("local_")){const $=parseInt(u.replace("local_",""),10);E=B?.filament.find(O=>O.id===$)?.name||null}else if(u.startsWith("builtin_")){const $=u.replace("builtin_","");E=W?.find(O=>O.filament_id===$)?.name||null}else R?.filament&&(E=R.filament.find(ne=>ne.setting_id===u)?.name||null);if(!E)return null;let U=E.replace(/@.+$/,"").trim();U.startsWith("# ")&&(U=U.slice(2).trim());const K=lW(U);return{fullName:U,material:K.material,brand:K.brand}},[u,R?.filament,B?.filament,W]),se=Y?.fullName||"",oe=w.useMemo(()=>{if(!Q||!Y)return[];const{fullName:E,brand:U}=Y,K=E.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return Q.filter($=>{const ne=($.material||"").toUpperCase(),O=$.manufacturer.toUpperCase();if(!(ne===K.toUpperCase()||ne.includes(K.toUpperCase())||K.toUpperCase().includes(ne)))return!1;if(U){const ee=U.toUpperCase();if(!O.includes(ee)&&!ee.includes(O))return!1}return!0})},[Q,Y]),be=w.useMemo(()=>{if(!J?.profiles||!Y)return[];const{fullName:E,material:U,brand:K}=Y,$=E.toUpperCase(),ne=U.toUpperCase(),O=K.toUpperCase();if(!ne||ne.length<2)return[];const V=J.profiles.filter(G=>{const re=G.name.toUpperCase();if(O)return!(!re.includes(O)||!re.includes(ne));if(re.includes($)||re.includes(ne))return!0;const ge={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[ne]||[];for(const xe of ge)if(re.includes(xe))return!0;return!1}),ee=new Map;for(const G of V){const re=`${G.name}|${G.k_value}`,ce=ee.get(re);ce?r.extruderId!==void 0&&G.extruder_id===r.extruderId&&ce.extruder_id!==r.extruderId&&ee.set(re,G):ee.set(re,G)}return Array.from(ee.values())},[J?.profiles,Y,r.extruderId]);w.useEffect(()=>{if(t){if(r.savedPresetId)d(r.savedPresetId);else if(r.trayInfoIdx&&R?.filament){let E=R.filament.find(U=>U.setting_id===r.trayInfoIdx);E||(E=R.filament.find(U=>T1(U.setting_id)===r.trayInfoIdx)),E&&d(E.setting_id)}else if(r.trayInfoIdx&&W?.length){const E=r.trayInfoIdx,U=W.find(K=>K.filament_id===E);U&&d(`builtin_${U.filament_id}`)}if(r.trayColor){const E=r.trayColor.slice(0,6);E&&y(E)}}else d(""),p(null),y(""),b(""),_(""),T(!1),k.current=""},[t,r.savedPresetId,r.trayInfoIdx,r.trayColor,R?.filament,W]),w.useEffect(()=>{if(be.length>0){if(r.caliIdx!=null&&r.caliIdx>0){const E=be.find(U=>U.slot_id===r.caliIdx);if(E){p(E);return}}p(be[0])}else p(null)},[u,be,r.caliIdx]);const Me=w.useCallback(E=>{E.key==="Escape"&&e()},[e]);w.useEffect(()=>{if(t)return document.addEventListener("keydown",Me),()=>document.removeEventListener("keydown",Me)},[t,Me]);const q=A&&!D||z||I||ie;if(w.useEffect(()=>{if(!q&&u&&u!==k.current){const E=requestAnimationFrame(()=>{const K=document.querySelector('[class*="fixed inset-0 z-50"]')?.querySelector(`[data-preset-id="${CSS.escape(u)}"]`);K&&(k.current=u,K.scrollIntoView({block:"nearest"}))});return()=>cancelAnimationFrame(E)}},[u,q]),!t)return null;const Z=u&&!ue.isPending,j=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(Od,{className:"w-5 h-5 text-bambu-blue"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.title")}),l&&i.jsxs("div",{className:"flex items-center gap-2 ml-4 text-sm text-bambu-gray",children:[i.jsx("span",{className:"text-white/30",children:"|"}),r.trayColor&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),i.jsx("span",{className:"text-white/70",children:c("configureAmsSlot.slotLabel",{ams:oW(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(Ht,{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(su,{className:"w-16 h-16 text-bambu-green mx-auto"}),i.jsx("p",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.slotConfigured")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:c("configureAmsSlot.settingsSentToPrinter")})]})}),!l&&i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:c("configureAmsSlot.configuringSlot")}),i.jsxs("div",{className:"flex items-center gap-2",children:[r.trayColor&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),i.jsx("span",{className:"text-white font-medium",children:c("configureAmsSlot.slotLabel",{ams:oW(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(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):l?i.jsxs("div",{className:"flex gap-4 h-full",children:[i.jsxs("div",{className:"w-1/2 flex flex-col min-h-0",children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:g,onChange:E=>_(E.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2 shrink-0"}),i.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-1",children:pe.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:R?.filament?.length===0&&!B?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):pe.map(E=>i.jsx("button",{"data-preset-id":E.id,onClick:()=>d(E.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${u===E.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:E.name}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[E.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")}),E.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")}),E.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")})]})]})},E.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"),se&&i.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:se})})]}),be.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:E=>{const U=be.find(K=>K.name===E.target.value);p(U||null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10",children:[i.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),be.map(E=>i.jsxs("option",{value:E.name,children:[E.name," (K=",E.k_value,")"]},`${E.name}-${E.extruder_id}`))]}),i.jsx(On,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):u?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:Y?.fullName})}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:oe.map(E=>i.jsxs("button",{onClick:()=>{const U=E.hex_color.replace("#","").toUpperCase();y(U),b(E.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===E.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:E.color_name,children:[i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:E.hex_color}}),i.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:E.color_name})]},E.id))})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[cW.map(E=>i.jsx("button",{onClick:()=>{y(E.hex),b(E.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===E.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${E.hex}`},title:E.name},E.hex)),i.jsx("button",{onClick:()=>P(!C),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(C?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:C?"−":"+"})]}),C&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:uW.map(E=>i.jsx("button",{onClick:()=>{y(E.hex),b(E.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===E.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${E.hex}`},title:E.name},E.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:`#${j}`}}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:E=>{const U=E.target.value;b(U);const K=dW(U);if(K)y(K);else{const $=U.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();$.length===6?y($):$.length===3&&y($.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&&i.jsx("button",{onClick:()=>{y(""),b("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:g,onChange:E=>_(E.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2"}),i.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:pe.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:R?.filament?.length===0&&!B?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):pe.map(E=>i.jsx("button",{"data-preset-id":E.id,onClick:()=>d(E.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${u===E.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:E.name}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[E.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")}),E.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")}),E.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")})]})]})},E.id))})]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),se&&i.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:se})})]}),be.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:E=>{const U=be.find(K=>K.name===E.target.value);p(U||null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10",children:[i.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),be.map(E=>i.jsxs("option",{value:E.name,children:[E.name," (K=",E.k_value,")"]},`${E.name}-${E.extruder_id}`))]}),i.jsx(On,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):u?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:Y?.fullName})}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:oe.map(E=>i.jsxs("button",{onClick:()=>{const U=E.hex_color.replace("#","").toUpperCase();y(U),b(E.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===E.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:E.color_name,children:[i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:E.hex_color}}),i.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:E.color_name})]},E.id))})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[cW.map(E=>i.jsx("button",{onClick:()=>{y(E.hex),b(E.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===E.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${E.hex}`},title:E.name},E.hex)),i.jsx("button",{onClick:()=>P(!C),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(C?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:C?"−":"+"})]}),C&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:uW.map(E=>i.jsx("button",{onClick:()=>{y(E.hex),b(E.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===E.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${E.hex}`},title:E.name},E.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:`#${j}`}}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:E=>{const U=E.target.value;b(U);const K=dW(U);if(K)y(K);else{const $=U.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();$.length===6?y($):$.length===3&&y($.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&&i.jsx("button",{onClick:()=>{y(""),b("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}),i.jsxs("div",{className:"flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[i.jsx(Ie,{variant:"secondary",onClick:()=>me.mutate(),disabled:me.isPending||ue.isPending,className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:me.isPending?i.jsxs(i.Fragment,{children:[i.jsx(pt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.resetting")]}):i.jsxs(i.Fragment,{children:[i.jsx(So,{className:"w-4 h-4"}),c("configureAmsSlot.resetSlot")]})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:e,children:c("configureAmsSlot.cancel")}),i.jsx(Ie,{onClick:()=>ue.mutate(),disabled:!Z,children:ue.isPending?i.jsxs(i.Fragment,{children:[i.jsx(pt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.configuring")]}):i.jsxs(i.Fragment,{children:[i.jsx(Od,{className:"w-4 h-4"}),c("configureAmsSlot.configureSlot")]})})]})]}),(ue.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:ue.error?.message||me.error?.message})]})]})}function Qre({folderId:t,onClose:e,onUploadComplete:n,onFileUploaded:r,autoUpload:a,validateFile:s,accept:o}){const{t:l}=Rt(),[c,u]=w.useState([]),[d,m]=w.useState(!1),[p,f]=w.useState(!1),[y,v]=w.useState(!0),[b,g]=w.useState(!1),[_,N]=w.useState(!0),[T,C]=w.useState(null),P=w.useRef(null),k=pe=>{pe.preventDefault(),m(!0)},R=pe=>{pe.preventDefault(),m(!1)},A=pe=>{pe.preventDefault(),m(!1),W(Array.from(pe.dataTransfer.files))},D=pe=>{pe.target.files&&W(Array.from(pe.target.files))},B=(pe,Y)=>{u(se=>se.map(oe=>oe.file===pe?{...oe,...Y}:oe))},z=async pe=>{f(!0);for(const Y of pe)if(Y.status==="pending"){B(Y.file,{status:"uploading"});try{if(Y.isZip){const se=await fe.extractZipFile(Y.file,t,y,b,_);B(Y.file,{status:se.errors.length>0&&se.extracted===0?"error":"success",extractedCount:se.extracted,error:se.errors.length>0?l("fileManager.zipFilesFailed","{{count}} files failed",{count:se.errors.length}):void 0})}else{const se=await fe.uploadLibraryFile(Y.file,t,_);B(Y.file,{status:"success"});const oe=r?.(se);if(oe){C(oe),u([]),f(!1);return}}}catch(se){B(Y.file,{status:"error",error:se instanceof Error?se.message:l("fileManager.uploadFailed","Upload failed")})}}f(!1),n(),e()},W=pe=>{if(C(null),s)for(const se of pe){const oe=s(se);if(oe){C(oe);return}}const Y=pe.map(se=>({file:se,status:"pending",isZip:se.name.toLowerCase().endsWith(".zip"),is3mf:se.name.toLowerCase().endsWith(".3mf")}));u(se=>[...se,...Y]),a&&pe.length>0&&z(Y)},I=pe=>{u(Y=>Y.filter((se,oe)=>oe!==pe))},J=c.some(pe=>pe.isZip&&pe.status==="pending"),ie=c.some(pe=>pe.file.name.toLowerCase().endsWith(".stl")&&pe.status==="pending"),Q=c.some(pe=>pe.is3mf&&pe.status==="pending"),ue=c.filter(pe=>pe.status==="pending").length,me=c.length>0&&ue===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(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsxs("div",{onDragOver:k,onDragLeave:R,onDrop:A,onClick:()=>P.current?.click(),className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${d?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,children:[i.jsx(vi,{className:`w-10 h-10 mx-auto mb-3 ${d?"text-bambu-green":"text-bambu-gray"}`}),i.jsx("p",{className:"text-white font-medium",children:l(d?"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:D}),J&&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($s,{className:"w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-blue-300 font-medium",children:l("fileManager.zipFilesDetected")}),i.jsx("p",{className:"text-xs text-blue-300/70 mt-1",children:l("fileManager.zipExtractOptions")}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:y,onChange:pe=>v(pe.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.preserveZipStructure")})]}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:b,onChange:pe=>g(pe.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")})]})]})]})}),Q&&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")})]})]})}),(ie||J)&&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(Ld,{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(J&&!ie?"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:pe=>N(pe.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((pe,Y)=>i.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[pe.isZip?i.jsx($s,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):i.jsx(ZC,{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:pe.file.name}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[(pe.file.size/1024/1024).toFixed(2)," MB",pe.isZip&&pe.status==="pending"&&i.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",l("fileManager.willBeExtracted")]}),pe.extractedCount!==void 0&&i.jsxs("span",{className:"text-green-400 ml-2",children:["• ",l("fileManager.filesExtracted",{count:pe.extractedCount})]})]})]}),pe.status==="pending"&&i.jsx("button",{onClick:()=>I(Y),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(Ht,{className:"w-4 h-4 text-bambu-gray"})}),pe.status==="uploading"&&i.jsx(pt,{className:"w-4 h-4 text-bambu-green animate-spin"}),pe.status==="success"&&i.jsx(fr,{className:"w-4 h-4 text-green-500"}),pe.status==="error"&&i.jsx("span",{title:pe.error,children:i.jsx(qi,{className:"w-4 h-4 text-red-500"})})]},Y))}),T&&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(qi,{className:"w-5 h-5 text-red-400 mt-0.5 flex-shrink-0"}),i.jsx("p",{className:"text-sm text-red-300",children:T})]})})]}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:e,children:l("common.cancel")}),!me&&i.jsx(Ie,{onClick:()=>z(c),disabled:ue===0||p,children:p?i.jsxs(i.Fragment,{children:[i.jsx(pt,{className:"w-4 h-4 mr-2 animate-spin"}),l("fileManager.uploading")]}):i.jsxs(i.Fragment,{children:[i.jsx(vi,{className:"w-4 h-4 mr-2"}),l("common.upload")," ",ue>0?`(${ue})`:""]})})]})]})})}function mW(t){return t?`#${t.replace("#","").substring(0,6)}`:"#808080"}function Ri(t){return t?t.replace("#","").toLowerCase().substring(0,6):""}const Dqe=[["PA-CF","PA12-CF","PAHT-CF"]],Zre={};for(const t of Dqe){const e=t[0];for(const n of t)Zre[n.toUpperCase()]=e.toUpperCase()}function Qk(t){if(!t)return"";const e=t.toUpperCase();return Zre[e]??e}function Gj(t,e){return Qk(t)===Qk(e)}function gu(t,e,n=40){const r=Ri(t),a=Ri(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),u=parseInt(a.substring(2,4),16),d=parseInt(a.substring(4,6),16);return Math.abs(s-c)<=n&&Math.abs(o-u)<=n&&Math.abs(l-d)<=n}function EI(t,e,n,r){if(r)return"Ext";const a=String.fromCharCode(65+(t>=128?t-128:t));return n?`HT-${a}`:`${a}${e+1}`}function Y0(t,e,n){return n?254+e:t>=128?t:t*4+e}function hW(t){if(!t)return!1;const e=Date.now()+4320*60*60*1e3;return(Zn(t)?.getTime()??0)>e}function Rqe(t,e,n){const r=Jre(e,t.nozzle_id),a=r.find(l=>!n.has(l.globalTrayId)&&Gj(l.type,t.type)&&Ri(l.color)===Ri(t.color)),s=a?void 0:r.find(l=>!n.has(l.globalTrayId)&&Gj(l.type,t.type)&&gu(l.color,t.color)),o=a||s?void 0:r.find(l=>!n.has(l.globalTrayId)&&Gj(l.type,t.type));return a??s??o}function Jre(t,e){return t.filter(n=>e==null||n.extruderId===e)}function Ww(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=mW(o.tray_color);e.push({type:o.tray_type,color:l,colorName:jd(l),amsId:a.id,trayId:o.id,isHt:s,isExternal:!1,label:EI(a.id,o.id,s,!1),globalTrayId:Y0(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=mW(a.tray_color),o=a.id??254,l=(t?.vt_tray?.length??0)>1;e.push({type:a.tray_type,color:s,colorName:jd(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 pW(t,e){if(!t?.filaments||t.filaments.length===0)return;const n=Ww(e);if(n.length===0)return;const r=new Set,a=t.filaments.map(l=>{const c=l.tray_info_idx||"";let u=n.filter(v=>!r.has(v.globalTrayId));l.nozzle_id!=null&&(u=u.filter(v=>v.extruderId===l.nozzle_id));let d,m,p,f;if(c){const v=u.filter(b=>b.trayInfoIdx===c);v.length===1?d=v[0]:v.length>1&&(m=v.find(b=>b.type?.toUpperCase()===l.type?.toUpperCase()&&Ri(b.color)===Ri(l.color)),m||(p=v.find(b=>b.type?.toUpperCase()===l.type?.toUpperCase()&&gu(b.color,l.color))),!m&&!p&&(f=v.find(b=>b.type?.toUpperCase()===l.type?.toUpperCase())))}!d&&!m&&!p&&!f&&(m=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&Ri(v.color)===Ri(l.color)),m||(p=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&gu(v.color,l.color))),!m&&!p&&(f=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase())));const y=d||m||p||f||void 0;return y&&r.add(y.globalTrayId),{slot_id:l.slot_id,globalTrayId:y?.globalTrayId??-1}}),s=Math.max(...a.map(l=>l.slot_id||0));if(s<=0)return;const o=new Array(s).fill(-1);return a.forEach(l=>{l.slot_id&&l.slot_id>0&&(o[l.slot_id-1]=l.globalTrayId)}),o}function Fqe(t){return w.useMemo(()=>Ww(t),[t])}function eie(t,e,n){const r=Fqe(e),a=w.useMemo(()=>{if(!t?.filaments||t.filaments.length===0)return[];const c=new Set(Object.values(n));return t.filaments.map(u=>{const d=u.slot_id||0;if(d>0&&n[d]!==void 0){const P=n[d],k=r.find(R=>R.globalTrayId===P);if(k){const R=k.type?.toUpperCase()===u.type?.toUpperCase(),A=Ri(k.color)===Ri(u.color)||gu(k.color,u.color);let D;return R&&A?D="match":R?D="type_only":D="mismatch",{...u,loaded:k,hasFilament:!0,typeMatch:R,colorMatch:A,status:D,isManual:!0}}}const m=u.tray_info_idx||"";let p=r.filter(P=>!c.has(P.globalTrayId));u.nozzle_id!=null&&(p=p.filter(P=>P.extruderId===u.nozzle_id));let f,y,v,b;if(m){const P=p.filter(k=>k.trayInfoIdx===m);P.length===1?f=P[0]:P.length>1&&(y=P.find(k=>k.type?.toUpperCase()===u.type?.toUpperCase()&&Ri(k.color)===Ri(u.color)),y||(v=P.find(k=>k.type?.toUpperCase()===u.type?.toUpperCase()&&gu(k.color,u.color))),!y&&!v&&(b=P.find(k=>k.type?.toUpperCase()===u.type?.toUpperCase())))}!f&&!y&&!v&&!b&&(y=p.find(P=>P.type?.toUpperCase()===u.type?.toUpperCase()&&Ri(P.color)===Ri(u.color)),y||(v=p.find(P=>P.type?.toUpperCase()===u.type?.toUpperCase()&&gu(P.color,u.color))),!y&&!v&&(b=p.find(P=>P.type?.toUpperCase()===u.type?.toUpperCase())));const g=f||y||v||b||void 0;g&&c.add(g.globalTrayId);const _=!!g,N=_,T=!!f||!!y||!!v;let C;return f||y||v?C="match":b?C="type_only":C="mismatch",{...u,loaded:g,hasFilament:_,typeMatch:N,colorMatch:T,status:C,isManual:!1}})},[t,r,n]),s=w.useMemo(()=>{if(a.length===0)return;const c=Math.max(...a.map(d=>d.slot_id||0));if(c<=0)return;const u=new Array(c).fill(-1);return a.forEach(d=>{d.slot_id&&d.slot_id>0&&(u[d.slot_id-1]=d.loaded?.globalTrayId??-1)}),u},[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 Lqe(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 u of t){const d=u.slot_id||0;if(d>0&&n[d]!==void 0){const b=n[d],g=e.find(_=>_.globalTrayId===b);if(g){const _=g.type?.toUpperCase()===u.type?.toUpperCase(),N=Ri(g.color)===Ri(u.color)||gu(g.color,u.color);_&&N?r++:_?a++:s++;continue}}let m=e.filter(b=>!o.has(b.globalTrayId));if(u.nozzle_id!=null){const b=m.filter(g=>g.extruderId===u.nozzle_id);b.length>0&&(m=b)}const p=m.find(b=>b.type?.toUpperCase()===u.type?.toUpperCase()&&Ri(b.color)===Ri(u.color)),f=p?void 0:m.find(b=>b.type?.toUpperCase()===u.type?.toUpperCase()&&gu(b.color,u.color)),y=p||f?void 0:m.find(b=>b.type?.toUpperCase()===u.type?.toUpperCase()),v=p??f??y;v&&o.add(v.globalTrayId),p||f?r++:y?a++:s++}const l=t.length;let c="full";return s>0?c="missing":a>0&&(c="partial"),{exactMatches:r,typeOnlyMatches:a,missingTypes:s,totalSlots:l,status:c}}function Oqe(t,e,n){if(!t?.filaments||t.filaments.length===0)return;const r=Ww(e);if(r.length===0)return;const a=new Set(Object.values(n)),s=[];for(const c of t.filaments){const u=c.slot_id||0;if(u>0&&n[u]!==void 0){s.push({slot_id:u,globalTrayId:n[u]});continue}let d=r.filter(v=>!a.has(v.globalTrayId));if(c.nozzle_id!=null){const v=d.filter(b=>b.extruderId===c.nozzle_id);v.length>0&&(d=v)}const m=d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&Ri(v.color)===Ri(c.color)),p=m?void 0:d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&gu(v.color,c.color)),f=m||p?void 0:d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()),y=m??p??f;y&&a.add(y.globalTrayId),s.push({slot_id:u,globalTrayId:y?.globalTrayId??-1})}const o=Math.max(...s.map(c=>c.slot_id||0));if(o<=0)return;const l=new Array(o).fill(-1);return s.forEach(c=>{c.slot_id&&c.slot_id>0&&(l[c.slot_id-1]=c.globalTrayId)}),l}const fW={useDefault:!0,manualMappings:{},autoConfigured:!1};function Iqe(t,e,n,r,a,s){const o=Yf({queries:t.map(y=>({queryKey:["printer-status",y],queryFn:()=>fe.getPrinterStatus(y),enabled:t.length>0,staleTime:5e3}))}),l=w.useMemo(()=>t.map((y,v)=>{const b=o[v],g=b?.data,N=e?.find(D=>D.id===y)?.name||`Printer ${y}`,T=Ww(g),C=a[y]||fW,P=pW(n,g),k=C.useDefault?r:C.manualMappings,R=Oqe(n,g,k),A=Lqe(n?.filaments,T,k);return{printerId:y,printerName:N,status:g,isLoading:b?.isLoading??!1,loadedFilaments:T,autoMapping:P,finalMapping:R,matchStatus:A.status,exactMatches:A.exactMatches,typeOnlyMatches:A.typeOnlyMatches,missingTypes:A.missingTypes,totalSlots:A.totalSlots,config:C}}),[t,o,e,n,a,r]),c=o.some(y=>y.isLoading),u=(y,v)=>{s(b=>({...b,[y]:{...b[y]||fW,...v}}))},d=y=>{const v=l.find(_=>_.printerId===y);if(!v||!v.status||!n?.filaments)return;const b=pW(n,v.status);if(!b)return;const g={};b.forEach((_,N)=>{_!==-1&&(g[N+1]=_)}),u(y,{useDefault:!1,manualMappings:g,autoConfigured:!0})},m=()=>{for(const y of t)d(y)},p=y=>l.find(b=>b.printerId===y)?.finalMapping,f=l.every(y=>y.matchStatus!=="missing");return{printerResults:l,isLoading:c,perPrinterConfigs:a,updatePrinterConfig:u,autoConfigureAll:m,autoConfigurePrinter:d,getFinalMapping:p,allPrintersReady:f}}const tie={USD:"$",EUR:"€",GBP:"£",CHF:"Fr.",JPY:"¥",CNY:"¥",CAD:"$",AUD:"$",INR:"₹",HKD:"HK$",KRW:"₩",SEK:"kr",NOK:"kr",DKK:"kr",PLN:"zł",BRL:"R$",TWD:"NT$",SGD:"S$",NZD:"NZ$",MXN:"MX$",MYR:"RM",CZK:"Kč",THB:"฿",ZAR:"R",TRY:"₺",RUB:"₽",HUF:"Ft",ILS:"₪"};function Go(t){return tie[t.toUpperCase()]||t}const zqe=Object.entries(tie).map(([t,e])=>({code:t,label:`${t} (${e})`}));function Uqe({printerId:t,filamentReqs:e,manualMappings:n,onManualMappingChange:r,currencySymbol:a,defaultCostPerKg:s,defaultExpanded:o=!1}){const{t:l}=Rt(),c=sn(),[u,d]=w.useState(!1),[m,p]=w.useState(o),{data:f}=tt({queryKey:["printer-status",t],queryFn:()=>fe.getPrinterStatus(t),enabled:!!t}),{data:y}=tt({queryKey:["spool-assignments",t],queryFn:()=>fe.getAssignments(t),enabled:!!t}),{loadedFilaments:v,filamentComparison:b,hasTypeMismatch:g,hasColorMismatch:_}=eie(e,f,n),N=w.useMemo(()=>{const z=new Map;for(const W of y||[]){const I=W.ams_id===255,J=Y0(W.ams_id,W.tray_id,I);z.set(J,W.spool?.cost_per_kg??null)}return z},[y]),T=w.useMemo(()=>{const z=new Map;for(const W of y||[]){const I=W.ams_id===255,J=Y0(W.ams_id,W.tray_id,I),ie=W.spool;if(!ie){z.set(J,null);continue}z.set(J,Math.max(0,Math.round((ie.label_weight??0)-(ie.weight_used??0))))}return z},[y]),C=w.useMemo(()=>{let z=0;for(const W of b){const I=W.loaded?.globalTrayId;if(I==null)continue;const ie=N.get(I)??null??s;ie>0&&(z+=W.used_grams/1e3*ie)}return z},[b,N,s]),P=w.useMemo(()=>Array.from(N.values()).some(z=>z!=null&&z>0),[N]),k=e?.filaments&&e.filaments.length>0,R=e?.filaments?.some(z=>z.nozzle_id!=null)??!1;if(!k||!f)return null;const A=g?"#f97316":_?"#facc15":"#00ae42",D=(z,W)=>{if(z>0)if(W===""){const I={...n};delete I[z],r(I)}else r({...n,[z]:parseInt(W,10)})},B=async()=>{d(!0);try{await fe.refreshPrinterStatus(t),await new Promise(z=>setTimeout(z,500)),await c.refetchQueries({queryKey:["printer-status",t]})}finally{d(!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(MN,{className:"w-4 h-4",fill:A,stroke:"none"}),i.jsx("span",{children:l("printModal.filamentMapping")}),g?i.jsx("span",{className:"text-xs text-orange-400",children:"(Type not found)"}):_?i.jsx("span",{className:"text-xs text-yellow-400",children:"(Color mismatch)"}):i.jsx("span",{className:"text-xs text-bambu-green",children:"(Ready)"}),m?i.jsx($l,{className:"w-4 h-4 ml-auto"}):i.jsx(On,{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:B,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:u,children:[i.jsx(Sr,{className:`w-3 h-3 ${u?"animate-spin":""}`}),i.jsx("span",{children:"Re-read"})]})]}),b.map((z,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: ${z.type} - ${jd(z.color)}`,children:i.jsx(MN,{className:"w-3 h-3",fill:z.color,stroke:z.color})}),i.jsxs("span",{className:"text-white truncate flex items-center gap-1",children:[R&&z.nozzle_id!=null&&i.jsx("span",{className:"inline-flex items-center justify-center w-3.5 h-3.5 rounded text-[9px] font-bold leading-none bg-bambu-gray/20 text-bambu-gray shrink-0",title:z.nozzle_id===1?l("printModal.leftNozzleTooltip"):l("printModal.rightNozzleTooltip"),children:z.nozzle_id===1?l("printModal.leftNozzle"):l("printModal.rightNozzle")}),z.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",z.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:z.loaded?.globalTrayId??"",onChange:I=>D(z.slot_id||0,I.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${z.status==="match"?"border-bambu-green/50 text-bambu-green":z.status==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${z.isManual?"ring-1 ring-blue-400/50":""}`,title:z.isManual?"Manually selected":"Auto-matched",children:[i.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),v.filter(I=>z.nozzle_id==null||I.extruderId===z.nozzle_id).map(I=>{const J=T.get(I.globalTrayId),ie=J!=null?l("printModal.slotRemainingShort",{grams:J,defaultValue:` - ${J}g left`}):"";return i.jsxs("option",{value:I.globalTrayId,className:"bg-bambu-dark text-white",children:[I.label,": ",I.traySubBrands||I.type," (",I.colorName,")",ie]},I.globalTrayId)})]}),z.status==="match"?i.jsx(Qr,{className:"w-3 h-3 text-bambu-green"}):z.status==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(Mn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(Mn,{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:C>0||P?`${a}${C.toFixed(2)}`:"N/A"})]}),g&&i.jsx("p",{className:"text-xs text-orange-400 mt-2",children:"Required filament type not found in printer."})]})]})}function Bqe({filamentReqs:t,availableFilaments:e,overrides:n,onChange:r,forceColorMatch:a,onForceColorMatchChange:s}){const{t:o}=Rt(),l=w.useMemo(()=>{const d={};for(const m of e){const p=Qk(m.type);d[p]||(d[p]=[]),d[p].push(m)}return d},[e]),c=t?.filaments;if(!c||c.length===0||e.length===0)return null;const u=(d,m)=>{if(m===""){const p={...n};delete p[d],r(p)}else{const[p,f]=m.split("|");r({...n,[d]:{type:p,color:f}})}};return i.jsxs("div",{className:"mb-4",children:[i.jsx("div",{className:"flex items-center gap-2 text-sm text-bambu-gray mb-2",children:i.jsx("span",{children:o("printModal.filamentOverride")})}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:o("printModal.filamentOverrideHint")}),i.jsx("div",{className:"bg-bambu-dark rounded-lg p-3 space-y-2",children:c.map(d=>{const m=n[d.slot_id],p=!!m,f=l[Qk(d.type)]||[],y=d.nozzle_id!=null?f.filter(v=>v.extruder_id==null||v.extruder_id===d.nozzle_id):f;return i.jsxs("div",{className:"space-y-1",children:[i.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 20px"},children:[i.jsx("span",{title:`${o("printModal.originalFilament")}: ${d.type} - ${jd(d.color)}`,children:i.jsx(MN,{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:p?`${m.type}|${m.color}`:"",onChange:v=>u(d.slot_id,v.target.value),disabled:y.length===0,className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${p?"border-blue-400/50 text-blue-400":"border-bambu-gray/30 text-bambu-gray"}`,children:[i.jsxs("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:[o("printModal.originalFilament"),": ",d.type," (",jd(d.color),")"]}),y.map((v,b)=>i.jsxs("option",{value:`${v.type}|${v.color}`,className:"bg-bambu-dark text-white",children:[v.tray_sub_brands||v.type," (",jd(v.color),")"]},`${v.type}-${v.color}-${v.tray_sub_brands}-${b}`))]}),p?i.jsx("button",{type:"button",onClick:()=>u(d.slot_id,""),className:"text-bambu-gray hover:text-white transition-colors",title:o("printModal.resetToOriginal"),children:i.jsx(So,{className:"w-3 h-3"})}):i.jsx("span",{className:"w-3"})]}),i.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer select-none pl-5",children:[i.jsx("input",{type:"checkbox",checked:a?.[d.slot_id]??!1,onChange:v=>s?.(d.slot_id,v.target.checked),className:"accent-bambu-green w-3 h-3"}),i.jsx(yw,{className:"w-3 h-3"}),o("printModal.forceColorMatch")]})]},d.slot_id)})})]})}function Hqe({plates:t,isMultiPlate:e,selectedPlate:n,onSelect:r,queueAll:a,onQueueAllChange:s}){const{t:o}=Rt();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(Vi,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:"Select Plate to Print"}),!n&&!a&&i.jsxs("span",{className:"text-xs text-orange-400 flex items-center gap-1",children:[i.jsx(Mn,{className:"w-3 h-3"}),"Selection required"]}),s&&i.jsx("button",{type:"button",onClick:()=>s(!a),className:`ml-auto text-xs px-2 py-0.5 rounded-full border transition-colors ${a?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray"}`,children:o("queue.queueAllPlates",{count:t.length})})]}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map(l=>i.jsxs("button",{type:"button",onClick:()=>{a&&s&&s(!1),r(l.index)},className:`flex items-center gap-2 p-2 rounded-lg border transition-colors text-left ${a||n===l.index?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"}`,children:[l.has_thumbnail&&l.thumbnail_url!=null?i.jsx("img",{src:l.thumbnail_url,alt:`Plate ${l.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(Vi,{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:l.name||`Plate ${l.index}`}),i.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[l.objects.length>0?l.objects.slice(0,3).join(", ")+(l.objects.length>3?"...":""):`${l.filaments.length} filament${l.filaments.length!==1?"s":""}`,l.print_time_seconds!=null?` • ${Is(l.print_time_seconds)}`:""]})]}),(a||n===l.index)&&i.jsx(Qr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]},l.index))})]})}const $qe=new Set(["IDLE","FINISH","FAILED"]);function qqe({printerResult:t,filamentReqs:e,onUpdateConfig:n}){const r=sn(),[a,s]=w.useState(!1),o=(u,d)=>{if(u<=0)return;const m={...t.config.manualMappings};d===""?delete m[u]:m[u]=parseInt(d,10),n({useDefault:!1,manualMappings:m,autoConfigured:!1})},l=async()=>{s(!0);try{await fe.refreshPrinterStatus(t.printerId),await new Promise(u=>setTimeout(u,500)),await r.refetchQueries({queryKey:["printer-status",t.printerId]})}finally{s(!1)}},c=e.map(u=>{const d=u.slot_id||0,m=t.config.manualMappings[d];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=Rqe(u,t.loadedFilaments,v)}let y="mismatch";if(p){const v=p.type?.toUpperCase()===u.type?.toUpperCase(),b=Ri(p.color)===Ri(u.color)||gu(p.color,u.color);v&&b?y="match":v&&(y="type_only")}return{req:u,loaded:p,status:y,isManual:f}});return i.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom slot mapping"}),i.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",disabled:a,children:[i.jsx(Sr,{className:`w-3 h-3 ${a?"animate-spin":""}`}),i.jsx("span",{children:"Re-read"})]})]}),c.map(({req:u,loaded:d,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: ${u.type} - ${jd(u.color)}`,children:i.jsx(MN,{className:"w-3 h-3",fill:u.color,stroke:u.color})}),i.jsxs("span",{className:"text-white truncate",children:[u.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",u.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:d?.globalTrayId??"",onChange:y=>o(u.slot_id||0,y.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${m==="match"?"border-bambu-green/50 text-bambu-green":m==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${p?"ring-1 ring-blue-400/50":""}`,title:p?"Manually selected":"Auto-matched",children:[i.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),Jre(t.loadedFilaments,u.nozzle_id).map(y=>i.jsxs("option",{value:y.globalTrayId,className:"bg-bambu-dark text-white",children:[y.label,": ",y.traySubBrands||y.type," (",y.colorName,")"]},y.globalTrayId))]}),m==="match"?i.jsx(Qr,{className:"w-3 h-3 text-bambu-green"}):m==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(Mn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(Mn,{className:"w-3 h-3 text-orange-400"})})]},f))]})}function Vqe({printers:t,selectedPrinterIds:e,onMultiSelect:n,isLoading:r=!1,allowMultiple:a=!1,showInactive:s=!1,disableBusy:o=!1,printerMappingResults:l,filamentReqs:c,onAutoConfigurePrinter:u,onUpdatePrinterConfig:d,assignmentMode:m="printer",onAssignmentModeChange:p,targetModel:f,onTargetModelChange:y,targetLocation:v,onTargetLocationChange:b,slicedForModel:g}){const[_,N]=w.useState(!1),T=s?t:t.filter(se=>se.is_active),C=Yf({queries:T.map(se=>({queryKey:["printerStatus",se.id],queryFn:()=>fe.getPrinterStatus(se.id),staleTime:5e3}))}),P=w.useMemo(()=>{const se=new Map;return T.forEach((oe,be)=>{const Me=C[be];Me?.data&&se.set(oe.id,Me.data)}),se},[T,C]),k=se=>{const oe=P.get(se);return oe?oe.connected?!$qe.has(oe.state??""):!0:!1},R=se=>{const oe=P.get(se);if(!oe)return null;if(!oe.connected)return"Offline";const be=oe.state;return be?be==="RUNNING"?oe.stg_cur_name||"Printing":be==="PREPARE"?"Preparing":be==="PAUSE"?"Paused":be==="IDLE"?"Idle":be==="FINISH"?"Finished":be==="FAILED"?"Failed":be:null},A=w.useMemo(()=>{if(m!=="printer"||!g||_)return T;const se=T.filter(oe=>oe.model===g);return se.length>0?se:T},[T,m,g,_]),D=T.length-A.length,B=w.useMemo(()=>{const se=T.map(oe=>oe.model).filter(oe=>!!oe);return[...new Set(se)].sort()},[T]),z=w.useMemo(()=>{if(!f)return[];const se=T.filter(oe=>oe.model===f&&oe.location).map(oe=>oe.location).filter(oe=>!!oe);return[...new Set(se)].sort()},[T,f]),W=p&&y&&B.length>0,I=a&&e.length>1&&l&&c?.filaments&&c.filaments.length>0&&u&&d;if(r)return i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(pt,{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(Li,{className:"w-4 h-4"}),"No ",s?"":"active ","printers available"]});const J=se=>{o&&k(se)||(a?e.includes(se)?n(e.filter(oe=>oe!==se)):n([...e,se]):n([se]))},ie=()=>{const se=o?A.filter(oe=>!k(oe.id)):A;n(se.map(oe=>oe.id))},Q=()=>{n([])},ue=(se,oe,be)=>{be.stopPropagation(),!(!u||!d)&&(oe?u(se):d(se,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},me=se=>e.includes(se),pe=e.length,Y=se=>l?.find(oe=>oe.printerId===se);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"),y(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${m==="printer"?"border-bambu-green bg-bambu-green/10 text-white":"border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray"}`,children:[i.jsx(_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 se=g&&B.includes(g)?g:B[0];y(se)},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(Jm,{className:"w-4 h-4"}),i.jsxs("span",{className:"text-sm",children:["Any ",g||"Model"]})]})]}),m==="model"&&W&&i.jsxs("div",{className:"space-y-3 mb-4",children:[!g&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Target Model"}),i.jsxs("select",{value:f||"",onChange:se=>{y(se.target.value||null),b&&b(null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",children:[i.jsx("option",{value:"",children:"Select a model..."}),B.map(se=>i.jsx("option",{value:se,children:se},se))]})]}),f&&z.length>0&&b&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Location Filter (optional)"}),i.jsxs("select",{value:v||"",onChange:se=>b(se.target.value||null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",children:[i.jsx("option",{value:"",children:"Any location"}),z.map(se=>i.jsx("option",{value:se,children:se},se))]})]}),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:pe===0?"Select printers":`${pe} printer${pe!==1?"s":""} selected`}),i.jsxs("div",{className:"flex gap-2",children:[pe0&&i.jsx("button",{type:"button",onClick:Q,className:"text-bambu-gray hover:text-white transition-colors",children:"Clear"})]})]}),m==="printer"&&A.map(se=>{const oe=me(se.id),be=Y(se.id),Me=be&&!be.config.useDefault,q=k(se.id),Z=o&&q,j=R(se.id);return i.jsxs("div",{children:[i.jsxs("button",{type:"button",onClick:()=>J(se.id),disabled:Z,className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${Z?"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"} ${se.is_active?"":"opacity-60"}`,children:[i.jsx("div",{className:`p-2 rounded-lg ${Z?"bg-bambu-dark-tertiary":oe?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:i.jsx(_r,{className:`w-5 h-5 ${Z?"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 ${Z?"text-bambu-gray":"text-white"}`,children:[se.name,!se.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:[se.model||"Unknown model"," • ",se.ip_address]})]}),j&&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:j}),a&&i.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${Z?"border-bambu-gray/30":oe?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:oe&&i.jsx(Qr,{className:"w-3 h-3 text-white"})})]}),oe&&I&&be&&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:E=>E.stopPropagation(),children:[i.jsx("input",{type:"checkbox",checked:Me,onChange:E=>ue(se.id,E.target.checked,E),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 ${be.matchStatus==="full"?"text-bambu-green":be.matchStatus==="partial"?"text-yellow-400":"text-orange-400"}`,children:["(",be.exactMatches,"/",be.totalSlots," matched)"]}),be.isLoading&&i.jsx(Sr,{className:"w-3 h-3 text-bambu-gray animate-spin"}),Me&&i.jsxs("button",{type:"button",onClick:E=>{E.stopPropagation(),u(se.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(Ebe,{className:"w-3 h-3"}),"Auto"]})]}),Me&&i.jsx(qqe,{printerResult:be,filamentReqs:c.filaments,onUpdateConfig:E=>d(se.id,E)})]})]},se.id)}),m==="printer"&&D>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(Mn,{className:"w-3 h-3 text-yellow-400"}),D," other printer",D>1?"s":""," hidden (different model) —",i.jsx("span",{className:"underline",children:"show all"})]}),m==="printer"&&_&&g&&i.jsx("button",{type:"button",onClick:()=>N(!1),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2",children:i.jsxs("span",{className:"underline",children:["Show only ",g," printers"]})}),m==="printer"&&pe===0&&i.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[i.jsx(Li,{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(Li,{className:"w-3 h-3"}),"Select a target printer model"]})]})}const Gqe=[{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 Wqe({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(aT,{className:"w-4 h-4"}),i.jsx("span",{children:"Print Options"}),r?i.jsx($l,{className:"w-4 h-4 ml-auto"}):i.jsx(On,{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:Gqe.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 Kqe({options:t,onChange:e,dateFormat:n="system",timeFormat:r="system",canControlPrinter:a=!0}){const[s,o]=w.useState(""),[l,c]=w.useState(""),[u,d]=w.useState(!0),[m,p]=w.useState(!0),f=w.useRef(null),y=w.useRef(!1);w.useEffect(()=>{if(t.scheduleType!=="scheduled"){y.current=!1;return}if(!y.current){y.current=!0;let C;t.scheduledTime?(C=new Date(t.scheduledTime),isNaN(C.getTime())&&(C=new Date,C.setHours(C.getHours()+1,0,0,0))):(C=new Date,C.setHours(C.getHours()+1,0,0,0),e({...t,scheduledTime:k3(C)})),o(N3(C,n)),c(Z8(C,r)),d(!0),p(!0)}},[t.scheduleType,t.scheduledTime,n,r,e,t]);const v=C=>{e({...t,scheduleType:C})},b=(C,P)=>{const k=txe(C,n),R=nxe(P);d(!!k),p(!!R),k&&R&&(k.setHours(R.hours,R.minutes,0,0),k>new Date&&e({...t,scheduledTime:k3(k)}))},g=C=>{o(C),b(C,l)},_=C=>{c(C),b(s,C)},N=C=>{const P=C.target.value;if(P){const k=new Date(P);isNaN(k.getTime())||(o(N3(k,n)),c(Z8(k,r)),d(!0),p(!0),e({...t,scheduledTime:P}))}},T=()=>{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(Jn,{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(Yr,{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(GX,{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 ${u?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:s,onChange:C=>g(C.target.value),placeholder:Zbe(n)}),i.jsx("button",{type:"button",onClick:T,className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",title:"Open calendar",children:i.jsx(Yr,{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:C=>_(C.target.value),placeholder:Jbe(r)})})]}),i.jsx("input",{ref:f,type:"datetime-local",className:"sr-only",value:t.scheduledTime,onChange:N,tabIndex:-1}),(!u||!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:C=>e({...t,requirePreviousSuccess:C.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:C=>e({...t,autoOffAfter:C.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(Xd,{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 yb={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1},Yqe={scheduleType:"asap",scheduledTime:"",requirePreviousSuccess:!1,autoOffAfter:!1};function bu({mode:t,archiveId:e,libraryFileId:n,archiveName:r,queueItem:a,initialSelectedPrinterIds:s,onClose:o,onSuccess:l}){const{t:c}=Rt(),u=sn(),{showToast:d}=fn(),{hasPermission:m}=Nr(),p=!!n&&!e,[f,y]=w.useState(()=>t==="edit-queue-item"&&a?.printer_id?[a.printer_id]:s?.length?s:[]),[v,b]=w.useState(()=>t==="edit-queue-item"&&a?a.plate_id:null),[g,_]=w.useState(!1),[N,T]=w.useState(()=>t==="edit-queue-item"&&a?{bed_levelling:a.bed_levelling??yb.bed_levelling,flow_cali:a.flow_cali??yb.flow_cali,vibration_cali:a.vibration_cali??yb.vibration_cali,layer_inspect:a.layer_inspect??yb.layer_inspect,timelapse:a.timelapse??yb.timelapse}:yb),[C,P]=w.useState(()=>{if(t==="edit-queue-item"&&a){let mt="asap";a.manual_start?mt="manual":a.scheduled_time&&!hW(a.scheduled_time)&&(mt="scheduled");let jt="";if(a.scheduled_time&&!hW(a.scheduled_time)){const qt=Zn(a.scheduled_time)??new Date;jt=k3(qt)}return{scheduleType:mt,scheduledTime:jt,requirePreviousSuccess:a.require_previous_success,autoOffAfter:a.auto_off_after}}return Yqe}),[k,R]=w.useState(()=>{if(t==="edit-queue-item"&&a?.ams_mapping&&Array.isArray(a.ams_mapping)){const mt={};return a.ams_mapping.forEach((jt,qt)=>{jt!==-1&&(mt[qt+1]=jt)}),mt}return{}}),[A,D]=w.useState({}),[B,z]=w.useState(()=>t==="edit-queue-item"&&a?.target_model?"model":"printer"),[W,I]=w.useState(()=>t==="edit-queue-item"&&a?.target_model?a.target_model:null),[J,ie]=w.useState(()=>t==="edit-queue-item"&&a?.target_location?a.target_location:null),[Q,ue]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const mt={};for(const jt of a.filament_overrides)mt[jt.slot_id]={type:jt.type,color:jt.color};return mt}return{}}),[me,pe]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const mt={};for(const jt of a.filament_overrides)mt[jt.slot_id]=jt.force_color_match===!0;return mt}return{}}),[Y]=w.useState(()=>t==="edit-queue-item"&&a?.printer_id?[a.printer_id]:[]),[se]=w.useState(()=>t==="edit-queue-item"&&a?a.plate_id:null),[oe,be]=w.useState(!1),[Me,q]=w.useState({current:0,total:0}),[Z,j]=w.useState(null),[E,U]=w.useState(new Set),K=f.length,$=f.length>0?f[0]:null,{data:ne}=tt({queryKey:["settings"],queryFn:fe.getSettings}),O=Go(ne?.currency||"USD"),V=ne?.default_filament_cost??0,{data:ee,isLoading:G}=tt({queryKey:["printers"],queryFn:fe.getPrinters}),{data:re}=tt({queryKey:["spool-assignments"],queryFn:()=>fe.getAssignments(),staleTime:30*1e3,enabled:(t==="reprint"||t==="add-to-queue")&&B==="printer"||p&&t==="reprint"}),{data:ce}=tt({queryKey:["archive",e],queryFn:()=>fe.getArchive(e),enabled:!!e&&!p}),{data:ge}=tt({queryKey:["library-file",n],queryFn:()=>fe.getLibraryFile(n),enabled:p&&!!n}),xe=ce?.sliced_for_model||ge?.sliced_for_model||null,{data:ae,isError:L}=tt({queryKey:["archive-plates",e],queryFn:()=>fe.getArchivePlates(e),enabled:!!e&&!p,retry:!1}),{data:F}=tt({queryKey:["library-file-plates",n],queryFn:()=>fe.getLibraryFilePlates(n),enabled:p&&!!n}),te=p?F:ae,{data:ve,isError:he}=tt({queryKey:["archive-filaments",e,v],queryFn:()=>fe.getArchiveFilamentRequirements(e,v??void 0),enabled:!!e&&!p&&(v!==null||!te?.is_multi_plate),retry:!1}),{data:de}=tt({queryKey:["library-file-filaments",n,v],queryFn:()=>fe.getLibraryFileFilamentRequirements(n,v??void 0),enabled:p&&!!n&&(v!==null||!te?.is_multi_plate)}),ke=!p&&(L||he),_e=p?de:ve,Le=w.useMemo(()=>{if(!(v===null||!te?.plates?.length))return te.plates.find(mt=>mt.index===v)?.name||void 0},[te,v]),{data:$e}=tt({queryKey:["available-filaments",W,J],queryFn:()=>fe.getAvailableFilaments(W,J??void 0),enabled:B==="model"&&!!W}),{data:Re}=tt({queryKey:["printer-status",$],queryFn:()=>fe.getPrinterStatus($),enabled:!!$}),{amsMapping:Ae}=eie(_e,Re,k),Pe=Iqe(f,ee,_e,k,A,D);w.useEffect(()=>{te?.plates&&te.plates.length>=1&&!v&&b(te.plates[0].index)},[te,v]),w.useEffect(()=>{if(t==="edit-queue-item")return;const mt=ee?.filter(jt=>jt.is_active)||[];mt.length===1&&f.length===0&&y([mt[0].id])},[t,ee,f.length]),w.useEffect(()=>{t==="edit-queue-item"?(JSON.stringify(f.sort())!==JSON.stringify(Y.sort())||v!==se)&&(R({}),D({}),U(new Set)):(R({}),D({}),U(new Set))},[t,f,v,Y,se]);const[Ue,je]=w.useState(W),[Xe,ye]=w.useState(v);w.useEffect(()=>{(W!==Ue||v!==Xe)&&(je(W),ye(v),(t!=="edit-queue-item"||Ue!==null)&&(ue({}),pe({})))},[W,v,Ue,Xe,t]),w.useEffect(()=>{if(!ne?.per_printer_mapping_expanded||f.length<=1)return;const mt=f.filter(jt=>{if(E.has(jt))return!1;const qt=Pe.printerResults.find(Jt=>Jt.printerId===jt);return qt&&qt.status&&!qt.isLoading});mt.length>0&&(U(jt=>{const qt=new Set(jt);return mt.forEach(Jt=>qt.add(Jt)),qt}),mt.forEach(jt=>{Pe.autoConfigurePrinter(jt)}))},[ne?.per_printer_mapping_expanded,f,E,Pe]),w.useEffect(()=>{const mt=jt=>{jt.key==="Escape"&&!oe&&o()};return window.addEventListener("keydown",mt),()=>window.removeEventListener("keydown",mt)},[o,oe]);const Ge=te?.is_multi_plate??!1,Ee=te?.plates??[],Ke=w.useMemo(()=>{const mt=new Map;return re&&re.forEach(jt=>{const qt=jt.ams_id===255,Jt=Y0(jt.ams_id,jt.tray_id,qt),Wt=mt.get(jt.printer_id)??new Map;Wt.set(Jt,jt),mt.set(jt.printer_id,Wt)}),mt},[re]),Ve=w.useMemo(()=>{if(!Z||Z.length===0)return"";const mt=Z.map(jt=>c("printModal.insufficientFilamentLine",{printer:jt.printerName,slot:jt.slotLabel,required:Math.round(jt.requiredGrams),remaining:Math.round(jt.remainingGrams)}));return[c("printModal.insufficientFilamentMessage"),...mt].join(` +${o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})}`:g.type==="profile"&&(Q=o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})),i.jsx(_n,{title:o("inventory.assignMismatchTitle"),message:Q,confirmText:o("inventory.assignMismatchConfirm"),variant:"warning",isLoading:k.isPending,onConfirm:ie,onCancel:()=>{k.isPending||(b(!1),y(null),_(null))}})})()]})}function oW(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 T1(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 Xv=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function lW(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 Xv)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 Xv){const o=new RegExp(`\\b${s}\\b`,"i");if(o.test(n)){const l=e.split(o),c=l[0]?.trim()||"",u=l[1]?.trim()||"";return{material:s,brand:c,variant:u}}}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 Mqe(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const Eqe={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"},cW=[{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"}],uW=[{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 dW(t){const e=t.toLowerCase().trim();return Eqe[e]||null}function jqe(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 Xre({isOpen:t,onClose:e,printerId:n,slotInfo:r,nozzleDiameter:a="0.4",printerModel:s,onSuccess:o,fullScreen:l}){const{t:c}=Rt(),[u,d]=w.useState(""),[m,p]=w.useState(null),[f,y]=w.useState(""),[v,b]=w.useState(""),[g,_]=w.useState(""),[N,T]=w.useState(!1),[C,P]=w.useState(!1),k=w.useRef(""),{data:R,isLoading:A,isError:D}=tt({queryKey:["cloudSettings"],queryFn:()=>fe.getCloudSettings(),enabled:t,retry:!1}),{data:B,isLoading:z}=tt({queryKey:["localPresets"],queryFn:()=>fe.getLocalPresets(),enabled:t}),{data:W,isLoading:I}=tt({queryKey:["builtinFilaments"],queryFn:()=>fe.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:J,isLoading:ie}=tt({queryKey:["kprofiles",n,a],queryFn:()=>fe.getKProfiles(n,a),enabled:t&&!!n}),{data:Q}=tt({queryKey:["colorCatalog"],queryFn:()=>fe.getColorCatalog(),enabled:t,staleTime:1/0}),ue=ft({mutationFn:async()=>{if(!u)throw new Error("No filament preset selected");const E=u.startsWith("local_"),U=u.startsWith("builtin_"),K=E?parseInt(u.replace("local_",""),10):null,$=U?u.replace("builtin_",""):null,ne=E?B?.filament.find(Le=>Le.id===K):null,O=U?W?.find(Le=>Le.filament_id===$):null,V=!E&&!U?R?.filament.find(Le=>Le.setting_id===u):null;if(!E&&!U&&!V)throw new Error("Selected preset not found");if(E&&!ne)throw new Error("Selected local preset not found");if(U&&!O)throw new Error("Selected builtin preset not found");const ee=E?ne.name:U?O.name:V.name,G=lW(ee),re=m?.slot_id??-1,ce=f||r.trayColor?.slice(0,6)||"FFFFFF",ge=ee.replace(/@.+$/,"").trim();let xe,ae;const L=G.material.toUpperCase();if(E){const Le=(Xv.includes(L)?L:ne?.filament_type||G.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"};xe=$e[Le]||$e[Le.replace(/[-\s]?CF$/,"")]||$e[Le.replace(/\+$/,"")]||$e[Le.split(/[-\s]/)[0]]||"",ae=""}else if(U)xe=$,ae="";else if(xe=T1(u),ae=u,!u.startsWith("GFS"))try{const Le=await fe.getCloudSettingDetail(u);Le.filament_id?xe=Le.filament_id:Le.base_id&&(xe=T1(Le.base_id),console.log(`Derived tray_info_idx from base_id: ${Le.base_id} -> ${xe}`))}catch(Le){console.warn("Failed to fetch preset detail for filament_id:",Le)}let F=E&&ne?.nozzle_temp_min?ne.nozzle_temp_min:190,te=E&&ne?.nozzle_temp_max?ne.nozzle_temp_max:230;if(!E||U||!ne?.nozzle_temp_min&&!ne?.nozzle_temp_max){const Le=(E?Xv.includes(L)?L:ne?.filament_type||G.material||"":G.material).toUpperCase();Le.includes("PLA")?(F=190,te=230):Le.includes("PETG")?(F=220,te=260):Le.includes("ABS")||Le.includes("ASA")?(F=240,te=280):Le.includes("TPU")?(F=200,te=240):Le==="PCTG"?(F=220,te=260):Le.includes("PC")?(F=260,te=300):(Le.includes("PA")||Le.includes("NYLON"))&&(F=250,te=290)}const ve=m?.k_value?parseFloat(m.k_value):0,he=E?Xv.includes(L)?L:ne?.filament_type||G.material||"PLA":G.material||"PLA",de=await fe.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:xe,tray_type:he,tray_sub_brands:ge,tray_color:ce+"FF",nozzle_temp_min:F,nozzle_temp_max:te,cali_idx:re,nozzle_diameter:a,setting_id:ae,kprofile_filament_id:m?.filament_id,kprofile_setting_id:m?.setting_id||void 0,k_value:ve}),ke=E?`local_${K}`:U?`builtin_${$}`:u,_e=E?"local":U?"builtin":"cloud";try{await fe.saveSlotPreset(n,r.amsId,r.trayId,ke,ge,_e)}catch(Le){console.warn("Failed to save slot preset mapping:",Le)}return de},onSuccess:()=>{T(!0),o?.(),setTimeout(()=>{T(!1),e()},1500)}}),me=ft({mutationFn:async()=>fe.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{T(!0),o?.(),setTimeout(()=>{T(!1),e()},1500)}}),pe=w.useMemo(()=>{const E=g.toLowerCase(),U=[],K=new Set,$=r.savedPresetId,ne=r.trayInfoIdx;if(R?.filament)for(const O of R.filament){K.add(O.setting_id);const V=$===O.setting_id,ee=V||ne&&(O.setting_id===ne||T1(O.setting_id)===ne);if(!(!V&&E&&!O.name.toLowerCase().includes(E))){if(!ee&&s){const G=jqe(O.name);if(G&&G.toUpperCase()!==s.toUpperCase())continue}U.push({id:O.setting_id,name:O.name,source:"cloud",isUser:Mqe(O.setting_id)})}}if(B?.filament)for(const O of B.filament){const V=`local_${O.id}`;!($===V)&&E&&!O.name.toLowerCase().includes(E)||U.push({id:V,name:O.name,source:"local",isUser:!1})}if(W)for(const O of W){if(K.has(O.filament_id))continue;const V=O.filament_id.startsWith("GF")?"GFS"+O.filament_id.slice(2):O.filament_id;K.has(V)||(!E||O.name.toLowerCase().includes(E))&&U.push({id:`builtin_${O.filament_id}`,name:O.name,source:"builtin",isUser:!1})}return U.sort((O,V)=>{const ee={cloud:0,local:1,builtin:2};return O.source!==V.source?ee[O.source]-ee[V.source]:O.isUser&&!V.isUser?-1:!O.isUser&&V.isUser?1:O.name.localeCompare(V.name)})},[R?.filament,B?.filament,W,g,s,r.savedPresetId,r.trayInfoIdx]),Y=w.useMemo(()=>{if(!u)return null;let E=null;if(u.startsWith("local_")){const $=parseInt(u.replace("local_",""),10);E=B?.filament.find(O=>O.id===$)?.name||null}else if(u.startsWith("builtin_")){const $=u.replace("builtin_","");E=W?.find(O=>O.filament_id===$)?.name||null}else R?.filament&&(E=R.filament.find(ne=>ne.setting_id===u)?.name||null);if(!E)return null;let U=E.replace(/@.+$/,"").trim();U.startsWith("# ")&&(U=U.slice(2).trim());const K=lW(U);return{fullName:U,material:K.material,brand:K.brand}},[u,R?.filament,B?.filament,W]),se=Y?.fullName||"",oe=w.useMemo(()=>{if(!Q||!Y)return[];const{fullName:E,brand:U}=Y,K=E.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return Q.filter($=>{const ne=($.material||"").toUpperCase(),O=$.manufacturer.toUpperCase();if(!(ne===K.toUpperCase()||ne.includes(K.toUpperCase())||K.toUpperCase().includes(ne)))return!1;if(U){const ee=U.toUpperCase();if(!O.includes(ee)&&!ee.includes(O))return!1}return!0})},[Q,Y]),be=w.useMemo(()=>{if(!J?.profiles||!Y)return[];const{fullName:E,material:U,brand:K}=Y,$=E.toUpperCase(),ne=U.toUpperCase(),O=K.toUpperCase();if(!ne||ne.length<2)return[];const V=J.profiles.filter(G=>{const re=G.name.toUpperCase();if(O)return!(!re.includes(O)||!re.includes(ne));if(re.includes($)||re.includes(ne))return!0;const ge={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[ne]||[];for(const xe of ge)if(re.includes(xe))return!0;return!1}),ee=new Map;for(const G of V){const re=`${G.name}|${G.k_value}`,ce=ee.get(re);ce?r.extruderId!==void 0&&G.extruder_id===r.extruderId&&ce.extruder_id!==r.extruderId&&ee.set(re,G):ee.set(re,G)}return Array.from(ee.values())},[J?.profiles,Y,r.extruderId]);w.useEffect(()=>{if(t){if(r.savedPresetId)d(r.savedPresetId);else if(r.trayInfoIdx&&R?.filament){let E=R.filament.find(U=>U.setting_id===r.trayInfoIdx);E||(E=R.filament.find(U=>T1(U.setting_id)===r.trayInfoIdx)),E&&d(E.setting_id)}else if(r.trayInfoIdx&&W?.length){const E=r.trayInfoIdx,U=W.find(K=>K.filament_id===E);U&&d(`builtin_${U.filament_id}`)}if(r.trayColor){const E=r.trayColor.slice(0,6);E&&y(E)}}else d(""),p(null),y(""),b(""),_(""),T(!1),k.current=""},[t,r.savedPresetId,r.trayInfoIdx,r.trayColor,R?.filament,W]),w.useEffect(()=>{if(be.length>0){if(r.caliIdx!=null&&r.caliIdx>0){const E=be.find(U=>U.slot_id===r.caliIdx);if(E){p(E);return}}p(be[0])}else p(null)},[u,be,r.caliIdx]);const Me=w.useCallback(E=>{E.key==="Escape"&&e()},[e]);w.useEffect(()=>{if(t)return document.addEventListener("keydown",Me),()=>document.removeEventListener("keydown",Me)},[t,Me]);const q=A&&!D||z||I||ie;if(w.useEffect(()=>{if(!q&&u&&u!==k.current){const E=requestAnimationFrame(()=>{const K=document.querySelector('[class*="fixed inset-0 z-50"]')?.querySelector(`[data-preset-id="${CSS.escape(u)}"]`);K&&(k.current=u,K.scrollIntoView({block:"nearest"}))});return()=>cancelAnimationFrame(E)}},[u,q]),!t)return null;const Z=u&&!ue.isPending,j=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(Od,{className:"w-5 h-5 text-bambu-blue"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.title")}),l&&i.jsxs("div",{className:"flex items-center gap-2 ml-4 text-sm text-bambu-gray",children:[i.jsx("span",{className:"text-white/30",children:"|"}),r.trayColor&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),i.jsx("span",{className:"text-white/70",children:c("configureAmsSlot.slotLabel",{ams:oW(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(Ht,{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(su,{className:"w-16 h-16 text-bambu-green mx-auto"}),i.jsx("p",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.slotConfigured")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:c("configureAmsSlot.settingsSentToPrinter")})]})}),!l&&i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:c("configureAmsSlot.configuringSlot")}),i.jsxs("div",{className:"flex items-center gap-2",children:[r.trayColor&&i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),i.jsx("span",{className:"text-white font-medium",children:c("configureAmsSlot.slotLabel",{ams:oW(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(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):l?i.jsxs("div",{className:"flex gap-4 h-full",children:[i.jsxs("div",{className:"w-1/2 flex flex-col min-h-0",children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:g,onChange:E=>_(E.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2 shrink-0"}),i.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-1",children:pe.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:R?.filament?.length===0&&!B?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):pe.map(E=>i.jsx("button",{"data-preset-id":E.id,onClick:()=>d(E.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${u===E.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:E.name}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[E.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")}),E.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")}),E.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")})]})]})},E.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"),se&&i.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:se})})]}),be.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:E=>{const U=be.find(K=>K.name===E.target.value);p(U||null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10",children:[i.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),be.map(E=>i.jsxs("option",{value:E.name,children:[E.name," (K=",E.k_value,")"]},`${E.name}-${E.extruder_id}`))]}),i.jsx(On,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):u?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:Y?.fullName})}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:oe.map(E=>i.jsxs("button",{onClick:()=>{const U=E.hex_color.replace("#","").toUpperCase();y(U),b(E.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===E.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:E.color_name,children:[i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:E.hex_color}}),i.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:E.color_name})]},E.id))})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[cW.map(E=>i.jsx("button",{onClick:()=>{y(E.hex),b(E.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===E.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${E.hex}`},title:E.name},E.hex)),i.jsx("button",{onClick:()=>P(!C),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(C?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:C?"−":"+"})]}),C&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:uW.map(E=>i.jsx("button",{onClick:()=>{y(E.hex),b(E.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===E.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${E.hex}`},title:E.name},E.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:`#${j}`}}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:E=>{const U=E.target.value;b(U);const K=dW(U);if(K)y(K);else{const $=U.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();$.length===6?y($):$.length===3&&y($.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&&i.jsx("button",{onClick:()=>{y(""),b("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:g,onChange:E=>_(E.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2"}),i.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:pe.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:R?.filament?.length===0&&!B?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):pe.map(E=>i.jsx("button",{"data-preset-id":E.id,onClick:()=>d(E.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${u===E.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:E.name}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[E.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")}),E.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")}),E.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")})]})]})},E.id))})]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),se&&i.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:se})})]}),be.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:E=>{const U=be.find(K=>K.name===E.target.value);p(U||null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10",children:[i.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),be.map(E=>i.jsxs("option",{value:E.name,children:[E.name," (K=",E.k_value,")"]},`${E.name}-${E.extruder_id}`))]}),i.jsx(On,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):u?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:Y?.fullName})}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:oe.map(E=>i.jsxs("button",{onClick:()=>{const U=E.hex_color.replace("#","").toUpperCase();y(U),b(E.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===E.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:E.color_name,children:[i.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:E.hex_color}}),i.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:E.color_name})]},E.id))})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[cW.map(E=>i.jsx("button",{onClick:()=>{y(E.hex),b(E.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===E.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${E.hex}`},title:E.name},E.hex)),i.jsx("button",{onClick:()=>P(!C),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(C?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:C?"−":"+"})]}),C&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:uW.map(E=>i.jsx("button",{onClick:()=>{y(E.hex),b(E.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===E.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${E.hex}`},title:E.name},E.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:`#${j}`}}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:E=>{const U=E.target.value;b(U);const K=dW(U);if(K)y(K);else{const $=U.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();$.length===6?y($):$.length===3&&y($.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&&i.jsx("button",{onClick:()=>{y(""),b("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}),i.jsxs("div",{className:"flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[i.jsx(Ie,{variant:"secondary",onClick:()=>me.mutate(),disabled:me.isPending||ue.isPending,className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:me.isPending?i.jsxs(i.Fragment,{children:[i.jsx(pt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.resetting")]}):i.jsxs(i.Fragment,{children:[i.jsx(So,{className:"w-4 h-4"}),c("configureAmsSlot.resetSlot")]})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:e,children:c("configureAmsSlot.cancel")}),i.jsx(Ie,{onClick:()=>ue.mutate(),disabled:!Z,children:ue.isPending?i.jsxs(i.Fragment,{children:[i.jsx(pt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.configuring")]}):i.jsxs(i.Fragment,{children:[i.jsx(Od,{className:"w-4 h-4"}),c("configureAmsSlot.configureSlot")]})})]})]}),(ue.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:ue.error?.message||me.error?.message})]})]})}function Qre({folderId:t,onClose:e,onUploadComplete:n,onFileUploaded:r,autoUpload:a,validateFile:s,accept:o}){const{t:l}=Rt(),[c,u]=w.useState([]),[d,m]=w.useState(!1),[p,f]=w.useState(!1),[y,v]=w.useState(!0),[b,g]=w.useState(!1),[_,N]=w.useState(!0),[T,C]=w.useState(null),P=w.useRef(null),k=pe=>{pe.preventDefault(),m(!0)},R=pe=>{pe.preventDefault(),m(!1)},A=pe=>{pe.preventDefault(),m(!1),W(Array.from(pe.dataTransfer.files))},D=pe=>{pe.target.files&&W(Array.from(pe.target.files))},B=(pe,Y)=>{u(se=>se.map(oe=>oe.file===pe?{...oe,...Y}:oe))},z=async pe=>{f(!0);for(const Y of pe)if(Y.status==="pending"){B(Y.file,{status:"uploading"});try{if(Y.isZip){const se=await fe.extractZipFile(Y.file,t,y,b,_);B(Y.file,{status:se.errors.length>0&&se.extracted===0?"error":"success",extractedCount:se.extracted,error:se.errors.length>0?l("fileManager.zipFilesFailed","{{count}} files failed",{count:se.errors.length}):void 0})}else{const se=await fe.uploadLibraryFile(Y.file,t,_);B(Y.file,{status:"success"});const oe=r?.(se);if(oe){C(oe),u([]),f(!1);return}}}catch(se){B(Y.file,{status:"error",error:se instanceof Error?se.message:l("fileManager.uploadFailed","Upload failed")})}}f(!1),n(),e()},W=pe=>{if(C(null),s)for(const se of pe){const oe=s(se);if(oe){C(oe);return}}const Y=pe.map(se=>({file:se,status:"pending",isZip:se.name.toLowerCase().endsWith(".zip"),is3mf:se.name.toLowerCase().endsWith(".3mf")}));u(se=>[...se,...Y]),a&&pe.length>0&&z(Y)},I=pe=>{u(Y=>Y.filter((se,oe)=>oe!==pe))},J=c.some(pe=>pe.isZip&&pe.status==="pending"),ie=c.some(pe=>pe.file.name.toLowerCase().endsWith(".stl")&&pe.status==="pending"),Q=c.some(pe=>pe.is3mf&&pe.status==="pending"),ue=c.filter(pe=>pe.status==="pending").length,me=c.length>0&&ue===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(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsxs("div",{onDragOver:k,onDragLeave:R,onDrop:A,onClick:()=>P.current?.click(),className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${d?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,children:[i.jsx(vi,{className:`w-10 h-10 mx-auto mb-3 ${d?"text-bambu-green":"text-bambu-gray"}`}),i.jsx("p",{className:"text-white font-medium",children:l(d?"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:D}),J&&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($s,{className:"w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-blue-300 font-medium",children:l("fileManager.zipFilesDetected")}),i.jsx("p",{className:"text-xs text-blue-300/70 mt-1",children:l("fileManager.zipExtractOptions")}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:y,onChange:pe=>v(pe.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.preserveZipStructure")})]}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:b,onChange:pe=>g(pe.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")})]})]})]})}),Q&&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")})]})]})}),(ie||J)&&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(Ld,{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(J&&!ie?"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:pe=>N(pe.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((pe,Y)=>i.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[pe.isZip?i.jsx($s,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):i.jsx(ZC,{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:pe.file.name}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[(pe.file.size/1024/1024).toFixed(2)," MB",pe.isZip&&pe.status==="pending"&&i.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",l("fileManager.willBeExtracted")]}),pe.extractedCount!==void 0&&i.jsxs("span",{className:"text-green-400 ml-2",children:["• ",l("fileManager.filesExtracted",{count:pe.extractedCount})]})]})]}),pe.status==="pending"&&i.jsx("button",{onClick:()=>I(Y),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(Ht,{className:"w-4 h-4 text-bambu-gray"})}),pe.status==="uploading"&&i.jsx(pt,{className:"w-4 h-4 text-bambu-green animate-spin"}),pe.status==="success"&&i.jsx(fr,{className:"w-4 h-4 text-green-500"}),pe.status==="error"&&i.jsx("span",{title:pe.error,children:i.jsx(qi,{className:"w-4 h-4 text-red-500"})})]},Y))}),T&&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(qi,{className:"w-5 h-5 text-red-400 mt-0.5 flex-shrink-0"}),i.jsx("p",{className:"text-sm text-red-300",children:T})]})})]}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:e,children:l("common.cancel")}),!me&&i.jsx(Ie,{onClick:()=>z(c),disabled:ue===0||p,children:p?i.jsxs(i.Fragment,{children:[i.jsx(pt,{className:"w-4 h-4 mr-2 animate-spin"}),l("fileManager.uploading")]}):i.jsxs(i.Fragment,{children:[i.jsx(vi,{className:"w-4 h-4 mr-2"}),l("common.upload")," ",ue>0?`(${ue})`:""]})})]})]})})}function mW(t){return t?`#${t.replace("#","").substring(0,6)}`:"#808080"}function Ri(t){return t?t.replace("#","").toLowerCase().substring(0,6):""}const Dqe=[["PA-CF","PA12-CF","PAHT-CF"]],Zre={};for(const t of Dqe){const e=t[0];for(const n of t)Zre[n.toUpperCase()]=e.toUpperCase()}function Qk(t){if(!t)return"";const e=t.toUpperCase();return Zre[e]??e}function Gj(t,e){return Qk(t)===Qk(e)}function gu(t,e,n=40){const r=Ri(t),a=Ri(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),u=parseInt(a.substring(2,4),16),d=parseInt(a.substring(4,6),16);return Math.abs(s-c)<=n&&Math.abs(o-u)<=n&&Math.abs(l-d)<=n}function EI(t,e,n,r){if(r)return"Ext";const a=String.fromCharCode(65+(t>=128?t-128:t));return n?`HT-${a}`:`${a}${e+1}`}function Y0(t,e,n){return n?254+e:t>=128?t:t*4+e}function hW(t){if(!t)return!1;const e=Date.now()+4320*60*60*1e3;return(Zn(t)?.getTime()??0)>e}function Rqe(t,e,n){const r=Jre(e,t.nozzle_id),a=r.find(l=>!n.has(l.globalTrayId)&&Gj(l.type,t.type)&&Ri(l.color)===Ri(t.color)),s=a?void 0:r.find(l=>!n.has(l.globalTrayId)&&Gj(l.type,t.type)&&gu(l.color,t.color)),o=a||s?void 0:r.find(l=>!n.has(l.globalTrayId)&&Gj(l.type,t.type));return a??s??o}function Jre(t,e){return t.filter(n=>e==null||n.extruderId===e)}function Ww(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=mW(o.tray_color);e.push({type:o.tray_type,color:l,colorName:jd(l),amsId:a.id,trayId:o.id,isHt:s,isExternal:!1,label:EI(a.id,o.id,s,!1),globalTrayId:Y0(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=mW(a.tray_color),o=a.id??254,l=(t?.vt_tray?.length??0)>1;e.push({type:a.tray_type,color:s,colorName:jd(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 pW(t,e){if(!t?.filaments||t.filaments.length===0)return;const n=Ww(e);if(n.length===0)return;const r=new Set,a=t.filaments.map(l=>{const c=l.tray_info_idx||"";let u=n.filter(v=>!r.has(v.globalTrayId));l.nozzle_id!=null&&(u=u.filter(v=>v.extruderId===l.nozzle_id));let d,m,p,f;if(c){const v=u.filter(b=>b.trayInfoIdx===c);v.length===1?d=v[0]:v.length>1&&(m=v.find(b=>b.type?.toUpperCase()===l.type?.toUpperCase()&&Ri(b.color)===Ri(l.color)),m||(p=v.find(b=>b.type?.toUpperCase()===l.type?.toUpperCase()&&gu(b.color,l.color))),!m&&!p&&(f=v.find(b=>b.type?.toUpperCase()===l.type?.toUpperCase())))}!d&&!m&&!p&&!f&&(m=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&Ri(v.color)===Ri(l.color)),m||(p=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&gu(v.color,l.color))),!m&&!p&&(f=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase())));const y=d||m||p||f||void 0;return y&&r.add(y.globalTrayId),{slot_id:l.slot_id,globalTrayId:y?.globalTrayId??-1}}),s=Math.max(...a.map(l=>l.slot_id||0));if(s<=0)return;const o=new Array(s).fill(-1);return a.forEach(l=>{l.slot_id&&l.slot_id>0&&(o[l.slot_id-1]=l.globalTrayId)}),o}function Fqe(t){return w.useMemo(()=>Ww(t),[t])}function eie(t,e,n){const r=Fqe(e),a=w.useMemo(()=>{if(!t?.filaments||t.filaments.length===0)return[];const c=new Set(Object.values(n));return t.filaments.map(u=>{const d=u.slot_id||0;if(d>0&&n[d]!==void 0){const P=n[d],k=r.find(R=>R.globalTrayId===P);if(k){const R=k.type?.toUpperCase()===u.type?.toUpperCase(),A=Ri(k.color)===Ri(u.color)||gu(k.color,u.color);let D;return R&&A?D="match":R?D="type_only":D="mismatch",{...u,loaded:k,hasFilament:!0,typeMatch:R,colorMatch:A,status:D,isManual:!0}}}const m=u.tray_info_idx||"";let p=r.filter(P=>!c.has(P.globalTrayId));u.nozzle_id!=null&&(p=p.filter(P=>P.extruderId===u.nozzle_id));let f,y,v,b;if(m){const P=p.filter(k=>k.trayInfoIdx===m);P.length===1?f=P[0]:P.length>1&&(y=P.find(k=>k.type?.toUpperCase()===u.type?.toUpperCase()&&Ri(k.color)===Ri(u.color)),y||(v=P.find(k=>k.type?.toUpperCase()===u.type?.toUpperCase()&&gu(k.color,u.color))),!y&&!v&&(b=P.find(k=>k.type?.toUpperCase()===u.type?.toUpperCase())))}!f&&!y&&!v&&!b&&(y=p.find(P=>P.type?.toUpperCase()===u.type?.toUpperCase()&&Ri(P.color)===Ri(u.color)),y||(v=p.find(P=>P.type?.toUpperCase()===u.type?.toUpperCase()&&gu(P.color,u.color))),!y&&!v&&(b=p.find(P=>P.type?.toUpperCase()===u.type?.toUpperCase())));const g=f||y||v||b||void 0;g&&c.add(g.globalTrayId);const _=!!g,N=_,T=!!f||!!y||!!v;let C;return f||y||v?C="match":b?C="type_only":C="mismatch",{...u,loaded:g,hasFilament:_,typeMatch:N,colorMatch:T,status:C,isManual:!1}})},[t,r,n]),s=w.useMemo(()=>{if(a.length===0)return;const c=Math.max(...a.map(d=>d.slot_id||0));if(c<=0)return;const u=new Array(c).fill(-1);return a.forEach(d=>{d.slot_id&&d.slot_id>0&&(u[d.slot_id-1]=d.loaded?.globalTrayId??-1)}),u},[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 Lqe(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 u of t){const d=u.slot_id||0;if(d>0&&n[d]!==void 0){const b=n[d],g=e.find(_=>_.globalTrayId===b);if(g){const _=g.type?.toUpperCase()===u.type?.toUpperCase(),N=Ri(g.color)===Ri(u.color)||gu(g.color,u.color);_&&N?r++:_?a++:s++;continue}}let m=e.filter(b=>!o.has(b.globalTrayId));if(u.nozzle_id!=null){const b=m.filter(g=>g.extruderId===u.nozzle_id);b.length>0&&(m=b)}const p=m.find(b=>b.type?.toUpperCase()===u.type?.toUpperCase()&&Ri(b.color)===Ri(u.color)),f=p?void 0:m.find(b=>b.type?.toUpperCase()===u.type?.toUpperCase()&&gu(b.color,u.color)),y=p||f?void 0:m.find(b=>b.type?.toUpperCase()===u.type?.toUpperCase()),v=p??f??y;v&&o.add(v.globalTrayId),p||f?r++:y?a++:s++}const l=t.length;let c="full";return s>0?c="missing":a>0&&(c="partial"),{exactMatches:r,typeOnlyMatches:a,missingTypes:s,totalSlots:l,status:c}}function Oqe(t,e,n){if(!t?.filaments||t.filaments.length===0)return;const r=Ww(e);if(r.length===0)return;const a=new Set(Object.values(n)),s=[];for(const c of t.filaments){const u=c.slot_id||0;if(u>0&&n[u]!==void 0){s.push({slot_id:u,globalTrayId:n[u]});continue}let d=r.filter(v=>!a.has(v.globalTrayId));if(c.nozzle_id!=null){const v=d.filter(b=>b.extruderId===c.nozzle_id);v.length>0&&(d=v)}const m=d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&Ri(v.color)===Ri(c.color)),p=m?void 0:d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&gu(v.color,c.color)),f=m||p?void 0:d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()),y=m??p??f;y&&a.add(y.globalTrayId),s.push({slot_id:u,globalTrayId:y?.globalTrayId??-1})}const o=Math.max(...s.map(c=>c.slot_id||0));if(o<=0)return;const l=new Array(o).fill(-1);return s.forEach(c=>{c.slot_id&&c.slot_id>0&&(l[c.slot_id-1]=c.globalTrayId)}),l}const fW={useDefault:!0,manualMappings:{},autoConfigured:!1};function Iqe(t,e,n,r,a,s){const o=Yf({queries:t.map(y=>({queryKey:["printer-status",y],queryFn:()=>fe.getPrinterStatus(y),enabled:t.length>0,staleTime:5e3}))}),l=w.useMemo(()=>t.map((y,v)=>{const b=o[v],g=b?.data,N=e?.find(D=>D.id===y)?.name||`Printer ${y}`,T=Ww(g),C=a[y]||fW,P=pW(n,g),k=C.useDefault?r:C.manualMappings,R=Oqe(n,g,k),A=Lqe(n?.filaments,T,k);return{printerId:y,printerName:N,status:g,isLoading:b?.isLoading??!1,loadedFilaments:T,autoMapping:P,finalMapping:R,matchStatus:A.status,exactMatches:A.exactMatches,typeOnlyMatches:A.typeOnlyMatches,missingTypes:A.missingTypes,totalSlots:A.totalSlots,config:C}}),[t,o,e,n,a,r]),c=o.some(y=>y.isLoading),u=(y,v)=>{s(b=>({...b,[y]:{...b[y]||fW,...v}}))},d=y=>{const v=l.find(_=>_.printerId===y);if(!v||!v.status||!n?.filaments)return;const b=pW(n,v.status);if(!b)return;const g={};b.forEach((_,N)=>{_!==-1&&(g[N+1]=_)}),u(y,{useDefault:!1,manualMappings:g,autoConfigured:!0})},m=()=>{for(const y of t)d(y)},p=y=>l.find(b=>b.printerId===y)?.finalMapping,f=l.every(y=>y.matchStatus!=="missing");return{printerResults:l,isLoading:c,perPrinterConfigs:a,updatePrinterConfig:u,autoConfigureAll:m,autoConfigurePrinter:d,getFinalMapping:p,allPrintersReady:f}}const tie={USD:"$",EUR:"€",GBP:"£",CHF:"Fr.",JPY:"¥",CNY:"¥",CAD:"$",AUD:"$",INR:"₹",HKD:"HK$",KRW:"₩",SEK:"kr",NOK:"kr",DKK:"kr",PLN:"zł",BRL:"R$",TWD:"NT$",SGD:"S$",NZD:"NZ$",MXN:"MX$",MYR:"RM",CZK:"Kč",THB:"฿",ZAR:"R",TRY:"₺",RUB:"₽",HUF:"Ft",ILS:"₪"};function Go(t){return tie[t.toUpperCase()]||t}const zqe=Object.entries(tie).map(([t,e])=>({code:t,label:`${t} (${e})`}));function Uqe({printerId:t,filamentReqs:e,manualMappings:n,onManualMappingChange:r,currencySymbol:a,defaultCostPerKg:s,defaultExpanded:o=!1}){const{t:l}=Rt(),c=sn(),[u,d]=w.useState(!1),[m,p]=w.useState(o),{data:f}=tt({queryKey:["printer-status",t],queryFn:()=>fe.getPrinterStatus(t),enabled:!!t}),{data:y}=tt({queryKey:["spool-assignments",t],queryFn:()=>fe.getAssignments(t),enabled:!!t}),{loadedFilaments:v,filamentComparison:b,hasTypeMismatch:g,hasColorMismatch:_}=eie(e,f,n),N=w.useMemo(()=>{const z=new Map;for(const W of y||[]){const I=W.ams_id===255,J=Y0(W.ams_id,W.tray_id,I);z.set(J,W.spool?.cost_per_kg??null)}return z},[y]),T=w.useMemo(()=>{const z=new Map;for(const W of y||[]){const I=W.ams_id===255,J=Y0(W.ams_id,W.tray_id,I),ie=W.spool;if(!ie){z.set(J,null);continue}z.set(J,Math.max(0,Math.round((ie.label_weight??0)-(ie.weight_used??0))))}return z},[y]),C=w.useMemo(()=>{let z=0;for(const W of b){const I=W.loaded?.globalTrayId;if(I==null)continue;const ie=N.get(I)??null??s;ie>0&&(z+=W.used_grams/1e3*ie)}return z},[b,N,s]),P=w.useMemo(()=>Array.from(N.values()).some(z=>z!=null&&z>0),[N]),k=e?.filaments&&e.filaments.length>0,R=e?.filaments?.some(z=>z.nozzle_id!=null)??!1;if(!k||!f)return null;const A=g?"#f97316":_?"#facc15":"#00ae42",D=(z,W)=>{if(z>0)if(W===""){const I={...n};delete I[z],r(I)}else r({...n,[z]:parseInt(W,10)})},B=async()=>{d(!0);try{await fe.refreshPrinterStatus(t),await new Promise(z=>setTimeout(z,500)),await c.refetchQueries({queryKey:["printer-status",t]})}finally{d(!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(MN,{className:"w-4 h-4",fill:A,stroke:"none"}),i.jsx("span",{children:l("printModal.filamentMapping")}),g?i.jsx("span",{className:"text-xs text-orange-400",children:"(Type not found)"}):_?i.jsx("span",{className:"text-xs text-yellow-400",children:"(Color mismatch)"}):i.jsx("span",{className:"text-xs text-bambu-green",children:"(Ready)"}),m?i.jsx($l,{className:"w-4 h-4 ml-auto"}):i.jsx(On,{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:B,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:u,children:[i.jsx(Sr,{className:`w-3 h-3 ${u?"animate-spin":""}`}),i.jsx("span",{children:"Re-read"})]})]}),b.map((z,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: ${z.type} - ${jd(z.color)}`,children:i.jsx(MN,{className:"w-3 h-3",fill:z.color,stroke:z.color})}),i.jsxs("span",{className:"text-white truncate flex items-center gap-1",children:[R&&z.nozzle_id!=null&&i.jsx("span",{className:"inline-flex items-center justify-center w-3.5 h-3.5 rounded text-[9px] font-bold leading-none bg-bambu-gray/20 text-bambu-gray shrink-0",title:z.nozzle_id===1?l("printModal.leftNozzleTooltip"):l("printModal.rightNozzleTooltip"),children:z.nozzle_id===1?l("printModal.leftNozzle"):l("printModal.rightNozzle")}),z.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",z.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:z.loaded?.globalTrayId??"",onChange:I=>D(z.slot_id||0,I.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${z.status==="match"?"border-bambu-green/50 text-bambu-green":z.status==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${z.isManual?"ring-1 ring-blue-400/50":""}`,title:z.isManual?"Manually selected":"Auto-matched",children:[i.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),v.filter(I=>z.nozzle_id==null||I.extruderId===z.nozzle_id).map(I=>{const J=T.get(I.globalTrayId),ie=J!=null?l("printModal.slotRemainingShort",{grams:J,defaultValue:` - ${J}g left`}):"";return i.jsxs("option",{value:I.globalTrayId,className:"bg-bambu-dark text-white",children:[I.label,": ",I.traySubBrands||I.type," (",I.colorName,")",ie]},I.globalTrayId)})]}),z.status==="match"?i.jsx(Qr,{className:"w-3 h-3 text-bambu-green"}):z.status==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(Mn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(Mn,{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:C>0||P?`${a}${C.toFixed(2)}`:"N/A"})]}),g&&i.jsx("p",{className:"text-xs text-orange-400 mt-2",children:"Required filament type not found in printer."})]})]})}function Bqe({filamentReqs:t,availableFilaments:e,overrides:n,onChange:r,forceColorMatch:a,onForceColorMatchChange:s}){const{t:o}=Rt(),l=w.useMemo(()=>{const d={};for(const m of e){const p=Qk(m.type);d[p]||(d[p]=[]),d[p].push(m)}return d},[e]),c=t?.filaments;if(!c||c.length===0||e.length===0)return null;const u=(d,m)=>{if(m===""){const p={...n};delete p[d],r(p)}else{const[p,f]=m.split("|");r({...n,[d]:{type:p,color:f}})}};return i.jsxs("div",{className:"mb-4",children:[i.jsx("div",{className:"flex items-center gap-2 text-sm text-bambu-gray mb-2",children:i.jsx("span",{children:o("printModal.filamentOverride")})}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:o("printModal.filamentOverrideHint")}),i.jsx("div",{className:"bg-bambu-dark rounded-lg p-3 space-y-2",children:c.map(d=>{const m=n[d.slot_id],p=!!m,f=l[Qk(d.type)]||[],y=d.nozzle_id!=null?f.filter(v=>v.extruder_id==null||v.extruder_id===d.nozzle_id):f;return i.jsxs("div",{className:"space-y-1",children:[i.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 20px"},children:[i.jsx("span",{title:`${o("printModal.originalFilament")}: ${d.type} - ${jd(d.color)}`,children:i.jsx(MN,{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:p?`${m.type}|${m.color}`:"",onChange:v=>u(d.slot_id,v.target.value),disabled:y.length===0,className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${p?"border-blue-400/50 text-blue-400":"border-bambu-gray/30 text-bambu-gray"}`,children:[i.jsxs("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:[o("printModal.originalFilament"),": ",d.type," (",jd(d.color),")"]}),y.map((v,b)=>i.jsxs("option",{value:`${v.type}|${v.color}`,className:"bg-bambu-dark text-white",children:[v.tray_sub_brands||v.type," (",jd(v.color),")"]},`${v.type}-${v.color}-${v.tray_sub_brands}-${b}`))]}),p?i.jsx("button",{type:"button",onClick:()=>u(d.slot_id,""),className:"text-bambu-gray hover:text-white transition-colors",title:o("printModal.resetToOriginal"),children:i.jsx(So,{className:"w-3 h-3"})}):i.jsx("span",{className:"w-3"})]}),i.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer select-none pl-5",children:[i.jsx("input",{type:"checkbox",checked:a?.[d.slot_id]??!1,onChange:v=>s?.(d.slot_id,v.target.checked),className:"accent-bambu-green w-3 h-3"}),i.jsx(yw,{className:"w-3 h-3"}),o("printModal.forceColorMatch")]})]},d.slot_id)})})]})}function Hqe({plates:t,isMultiPlate:e,selectedPlate:n,onSelect:r,queueAll:a,onQueueAllChange:s}){const{t:o}=Rt();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(Vi,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:"Select Plate to Print"}),!n&&!a&&i.jsxs("span",{className:"text-xs text-orange-400 flex items-center gap-1",children:[i.jsx(Mn,{className:"w-3 h-3"}),"Selection required"]}),s&&i.jsx("button",{type:"button",onClick:()=>s(!a),className:`ml-auto text-xs px-2 py-0.5 rounded-full border transition-colors ${a?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray"}`,children:o("queue.queueAllPlates",{count:t.length})})]}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map(l=>i.jsxs("button",{type:"button",onClick:()=>{a&&s&&s(!1),r(l.index)},className:`flex items-center gap-2 p-2 rounded-lg border transition-colors text-left ${a||n===l.index?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"}`,children:[l.has_thumbnail&&l.thumbnail_url!=null?i.jsx("img",{src:l.thumbnail_url,alt:`Plate ${l.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(Vi,{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:l.name||`Plate ${l.index}`}),i.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[l.objects.length>0?l.objects.slice(0,3).join(", ")+(l.objects.length>3?"...":""):`${l.filaments.length} filament${l.filaments.length!==1?"s":""}`,l.print_time_seconds!=null?` • ${Is(l.print_time_seconds)}`:""]})]}),(a||n===l.index)&&i.jsx(Qr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]},l.index))})]})}const $qe=new Set(["IDLE","FINISH","FAILED"]);function qqe({printerResult:t,filamentReqs:e,onUpdateConfig:n}){const r=sn(),[a,s]=w.useState(!1),o=(u,d)=>{if(u<=0)return;const m={...t.config.manualMappings};d===""?delete m[u]:m[u]=parseInt(d,10),n({useDefault:!1,manualMappings:m,autoConfigured:!1})},l=async()=>{s(!0);try{await fe.refreshPrinterStatus(t.printerId),await new Promise(u=>setTimeout(u,500)),await r.refetchQueries({queryKey:["printer-status",t.printerId]})}finally{s(!1)}},c=e.map(u=>{const d=u.slot_id||0,m=t.config.manualMappings[d];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=Rqe(u,t.loadedFilaments,v)}let y="mismatch";if(p){const v=p.type?.toUpperCase()===u.type?.toUpperCase(),b=Ri(p.color)===Ri(u.color)||gu(p.color,u.color);v&&b?y="match":v&&(y="type_only")}return{req:u,loaded:p,status:y,isManual:f}});return i.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom slot mapping"}),i.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",disabled:a,children:[i.jsx(Sr,{className:`w-3 h-3 ${a?"animate-spin":""}`}),i.jsx("span",{children:"Re-read"})]})]}),c.map(({req:u,loaded:d,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: ${u.type} - ${jd(u.color)}`,children:i.jsx(MN,{className:"w-3 h-3",fill:u.color,stroke:u.color})}),i.jsxs("span",{className:"text-white truncate",children:[u.type," ",i.jsxs("span",{className:"text-bambu-gray",children:["(",u.used_grams,"g)"]})]}),i.jsx("span",{className:"text-bambu-gray",children:"→"}),i.jsxs("select",{value:d?.globalTrayId??"",onChange:y=>o(u.slot_id||0,y.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${m==="match"?"border-bambu-green/50 text-bambu-green":m==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${p?"ring-1 ring-blue-400/50":""}`,title:p?"Manually selected":"Auto-matched",children:[i.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),Jre(t.loadedFilaments,u.nozzle_id).map(y=>i.jsxs("option",{value:y.globalTrayId,className:"bg-bambu-dark text-white",children:[y.label,": ",y.traySubBrands||y.type," (",y.colorName,")"]},y.globalTrayId))]}),m==="match"?i.jsx(Qr,{className:"w-3 h-3 text-bambu-green"}):m==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(Mn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(Mn,{className:"w-3 h-3 text-orange-400"})})]},f))]})}function Vqe({printers:t,selectedPrinterIds:e,onMultiSelect:n,isLoading:r=!1,allowMultiple:a=!1,showInactive:s=!1,disableBusy:o=!1,printerMappingResults:l,filamentReqs:c,onAutoConfigurePrinter:u,onUpdatePrinterConfig:d,assignmentMode:m="printer",onAssignmentModeChange:p,targetModel:f,onTargetModelChange:y,targetLocation:v,onTargetLocationChange:b,slicedForModel:g}){const[_,N]=w.useState(!1),T=s?t:t.filter(se=>se.is_active),C=Yf({queries:T.map(se=>({queryKey:["printerStatus",se.id],queryFn:()=>fe.getPrinterStatus(se.id),staleTime:5e3}))}),P=w.useMemo(()=>{const se=new Map;return T.forEach((oe,be)=>{const Me=C[be];Me?.data&&se.set(oe.id,Me.data)}),se},[T,C]),k=se=>{const oe=P.get(se);return oe?oe.connected?!$qe.has(oe.state??""):!0:!1},R=se=>{const oe=P.get(se);if(!oe)return null;if(!oe.connected)return"Offline";const be=oe.state;return be?be==="RUNNING"?oe.stg_cur_name||"Printing":be==="PREPARE"?"Preparing":be==="PAUSE"?"Paused":be==="IDLE"?"Idle":be==="FINISH"?"Finished":be==="FAILED"?"Failed":be:null},A=w.useMemo(()=>{if(m!=="printer"||!g||_)return T;const se=T.filter(oe=>oe.model===g);return se.length>0?se:T},[T,m,g,_]),D=T.length-A.length,B=w.useMemo(()=>{const se=T.map(oe=>oe.model).filter(oe=>!!oe);return[...new Set(se)].sort()},[T]),z=w.useMemo(()=>{if(!f)return[];const se=T.filter(oe=>oe.model===f&&oe.location).map(oe=>oe.location).filter(oe=>!!oe);return[...new Set(se)].sort()},[T,f]),W=p&&y&&B.length>0,I=a&&e.length>1&&l&&c?.filaments&&c.filaments.length>0&&u&&d;if(r)return i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(pt,{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(Li,{className:"w-4 h-4"}),"No ",s?"":"active ","printers available"]});const J=se=>{o&&k(se)||(a?e.includes(se)?n(e.filter(oe=>oe!==se)):n([...e,se]):n([se]))},ie=()=>{const se=o?A.filter(oe=>!k(oe.id)):A;n(se.map(oe=>oe.id))},Q=()=>{n([])},ue=(se,oe,be)=>{be.stopPropagation(),!(!u||!d)&&(oe?u(se):d(se,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},me=se=>e.includes(se),pe=e.length,Y=se=>l?.find(oe=>oe.printerId===se);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"),y(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${m==="printer"?"border-bambu-green bg-bambu-green/10 text-white":"border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray"}`,children:[i.jsx(_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 se=g&&B.includes(g)?g:B[0];y(se)},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(Jm,{className:"w-4 h-4"}),i.jsxs("span",{className:"text-sm",children:["Any ",g||"Model"]})]})]}),m==="model"&&W&&i.jsxs("div",{className:"space-y-3 mb-4",children:[!g&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Target Model"}),i.jsxs("select",{value:f||"",onChange:se=>{y(se.target.value||null),b&&b(null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",children:[i.jsx("option",{value:"",children:"Select a model..."}),B.map(se=>i.jsx("option",{value:se,children:se},se))]})]}),f&&z.length>0&&b&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Location Filter (optional)"}),i.jsxs("select",{value:v||"",onChange:se=>b(se.target.value||null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",children:[i.jsx("option",{value:"",children:"Any location"}),z.map(se=>i.jsx("option",{value:se,children:se},se))]})]}),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:pe===0?"Select printers":`${pe} printer${pe!==1?"s":""} selected`}),i.jsxs("div",{className:"flex gap-2",children:[pe0&&i.jsx("button",{type:"button",onClick:Q,className:"text-bambu-gray hover:text-white transition-colors",children:"Clear"})]})]}),m==="printer"&&A.map(se=>{const oe=me(se.id),be=Y(se.id),Me=be&&!be.config.useDefault,q=k(se.id),Z=o&&q,j=R(se.id);return i.jsxs("div",{children:[i.jsxs("button",{type:"button",onClick:()=>J(se.id),disabled:Z,className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${Z?"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"} ${se.is_active?"":"opacity-60"}`,children:[i.jsx("div",{className:`p-2 rounded-lg ${Z?"bg-bambu-dark-tertiary":oe?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:i.jsx(_r,{className:`w-5 h-5 ${Z?"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 ${Z?"text-bambu-gray":"text-white"}`,children:[se.name,!se.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:[se.model||"Unknown model"," • ",se.ip_address]})]}),j&&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:j}),a&&i.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${Z?"border-bambu-gray/30":oe?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:oe&&i.jsx(Qr,{className:"w-3 h-3 text-white"})})]}),oe&&I&&be&&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:E=>E.stopPropagation(),children:[i.jsx("input",{type:"checkbox",checked:Me,onChange:E=>ue(se.id,E.target.checked,E),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 ${be.matchStatus==="full"?"text-bambu-green":be.matchStatus==="partial"?"text-yellow-400":"text-orange-400"}`,children:["(",be.exactMatches,"/",be.totalSlots," matched)"]}),be.isLoading&&i.jsx(Sr,{className:"w-3 h-3 text-bambu-gray animate-spin"}),Me&&i.jsxs("button",{type:"button",onClick:E=>{E.stopPropagation(),u(se.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(Ebe,{className:"w-3 h-3"}),"Auto"]})]}),Me&&i.jsx(qqe,{printerResult:be,filamentReqs:c.filaments,onUpdateConfig:E=>d(se.id,E)})]})]},se.id)}),m==="printer"&&D>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(Mn,{className:"w-3 h-3 text-yellow-400"}),D," other printer",D>1?"s":""," hidden (different model) —",i.jsx("span",{className:"underline",children:"show all"})]}),m==="printer"&&_&&g&&i.jsx("button",{type:"button",onClick:()=>N(!1),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2",children:i.jsxs("span",{className:"underline",children:["Show only ",g," printers"]})}),m==="printer"&&pe===0&&i.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[i.jsx(Li,{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(Li,{className:"w-3 h-3"}),"Select a target printer model"]})]})}const Gqe=[{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 Wqe({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(aT,{className:"w-4 h-4"}),i.jsx("span",{children:"Print Options"}),r?i.jsx($l,{className:"w-4 h-4 ml-auto"}):i.jsx(On,{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:Gqe.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 Kqe({options:t,onChange:e,dateFormat:n="system",timeFormat:r="system",canControlPrinter:a=!0}){const[s,o]=w.useState(""),[l,c]=w.useState(""),[u,d]=w.useState(!0),[m,p]=w.useState(!0),f=w.useRef(null),y=w.useRef(!1);w.useEffect(()=>{if(t.scheduleType!=="scheduled"){y.current=!1;return}if(!y.current){y.current=!0;let C;t.scheduledTime?(C=new Date(t.scheduledTime),isNaN(C.getTime())&&(C=new Date,C.setHours(C.getHours()+1,0,0,0))):(C=new Date,C.setHours(C.getHours()+1,0,0,0),e({...t,scheduledTime:k3(C)})),o(N3(C,n)),c(Z8(C,r)),d(!0),p(!0)}},[t.scheduleType,t.scheduledTime,n,r,e,t]);const v=C=>{e({...t,scheduleType:C})},b=(C,P)=>{const k=txe(C,n),R=nxe(P);d(!!k),p(!!R),k&&R&&(k.setHours(R.hours,R.minutes,0,0),k>new Date&&e({...t,scheduledTime:k3(k)}))},g=C=>{o(C),b(C,l)},_=C=>{c(C),b(s,C)},N=C=>{const P=C.target.value;if(P){const k=new Date(P);isNaN(k.getTime())||(o(N3(k,n)),c(Z8(k,r)),d(!0),p(!0),e({...t,scheduledTime:P}))}},T=()=>{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(Jn,{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(Yr,{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(GX,{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 ${u?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:s,onChange:C=>g(C.target.value),placeholder:Zbe(n)}),i.jsx("button",{type:"button",onClick:T,className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",title:"Open calendar",children:i.jsx(Yr,{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:C=>_(C.target.value),placeholder:Jbe(r)})})]}),i.jsx("input",{ref:f,type:"datetime-local",className:"sr-only",value:t.scheduledTime,onChange:N,tabIndex:-1}),(!u||!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:C=>e({...t,requirePreviousSuccess:C.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:C=>e({...t,autoOffAfter:C.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(Xd,{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 yb={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1},Yqe={scheduleType:"asap",scheduledTime:"",requirePreviousSuccess:!1,autoOffAfter:!1};function bu({mode:t,archiveId:e,libraryFileId:n,archiveName:r,queueItem:a,initialSelectedPrinterIds:s,onClose:o,onSuccess:l}){const{t:c}=Rt(),u=sn(),{showToast:d}=fn(),{hasPermission:m}=Nr(),p=!!n&&!e,[f,y]=w.useState(()=>t==="edit-queue-item"&&a?.printer_id?[a.printer_id]:s?.length?s:[]),[v,b]=w.useState(()=>t==="edit-queue-item"&&a?a.plate_id:null),[g,_]=w.useState(!1),[N,T]=w.useState(()=>t==="edit-queue-item"&&a?{bed_levelling:a.bed_levelling??yb.bed_levelling,flow_cali:a.flow_cali??yb.flow_cali,vibration_cali:a.vibration_cali??yb.vibration_cali,layer_inspect:a.layer_inspect??yb.layer_inspect,timelapse:a.timelapse??yb.timelapse}:yb),[C,P]=w.useState(()=>{if(t==="edit-queue-item"&&a){let mt="asap";a.manual_start?mt="manual":a.scheduled_time&&!hW(a.scheduled_time)&&(mt="scheduled");let jt="";if(a.scheduled_time&&!hW(a.scheduled_time)){const qt=Zn(a.scheduled_time)??new Date;jt=k3(qt)}return{scheduleType:mt,scheduledTime:jt,requirePreviousSuccess:a.require_previous_success,autoOffAfter:a.auto_off_after}}return Yqe}),[k,R]=w.useState(()=>{if(t==="edit-queue-item"&&a?.ams_mapping&&Array.isArray(a.ams_mapping)){const mt={};return a.ams_mapping.forEach((jt,qt)=>{jt!==-1&&(mt[qt+1]=jt)}),mt}return{}}),[A,D]=w.useState({}),[B,z]=w.useState(()=>t==="edit-queue-item"&&a?.target_model?"model":"printer"),[W,I]=w.useState(()=>t==="edit-queue-item"&&a?.target_model?a.target_model:null),[J,ie]=w.useState(()=>t==="edit-queue-item"&&a?.target_location?a.target_location:null),[Q,ue]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const mt={};for(const jt of a.filament_overrides)mt[jt.slot_id]={type:jt.type,color:jt.color};return mt}return{}}),[me,pe]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const mt={};for(const jt of a.filament_overrides)mt[jt.slot_id]=jt.force_color_match===!0;return mt}return{}}),[Y]=w.useState(()=>t==="edit-queue-item"&&a?.printer_id?[a.printer_id]:[]),[se]=w.useState(()=>t==="edit-queue-item"&&a?a.plate_id:null),[oe,be]=w.useState(!1),[Me,q]=w.useState({current:0,total:0}),[Z,j]=w.useState(null),[E,U]=w.useState(new Set),K=f.length,$=f.length>0?f[0]:null,{data:ne}=tt({queryKey:["settings"],queryFn:fe.getSettings}),O=Go(ne?.currency||"USD"),V=ne?.default_filament_cost??0,{data:ee,isLoading:G}=tt({queryKey:["printers"],queryFn:fe.getPrinters}),{data:re}=tt({queryKey:["spool-assignments"],queryFn:()=>fe.getAssignments(),staleTime:30*1e3,enabled:(t==="reprint"||t==="add-to-queue")&&B==="printer"||p&&t==="reprint"}),{data:ce}=tt({queryKey:["archive",e],queryFn:()=>fe.getArchive(e),enabled:!!e&&!p}),{data:ge}=tt({queryKey:["library-file",n],queryFn:()=>fe.getLibraryFile(n),enabled:p&&!!n}),xe=ce?.sliced_for_model||ge?.sliced_for_model||null,{data:ae,isError:L}=tt({queryKey:["archive-plates",e],queryFn:()=>fe.getArchivePlates(e),enabled:!!e&&!p,retry:!1}),{data:F}=tt({queryKey:["library-file-plates",n],queryFn:()=>fe.getLibraryFilePlates(n),enabled:p&&!!n}),te=p?F:ae,{data:ve,isError:he}=tt({queryKey:["archive-filaments",e,v],queryFn:()=>fe.getArchiveFilamentRequirements(e,v??void 0),enabled:!!e&&!p&&(v!==null||!te?.is_multi_plate),retry:!1}),{data:de}=tt({queryKey:["library-file-filaments",n,v],queryFn:()=>fe.getLibraryFileFilamentRequirements(n,v??void 0),enabled:p&&!!n&&(v!==null||!te?.is_multi_plate)}),ke=!p&&(L||he),_e=p?de:ve,Le=w.useMemo(()=>{if(!(v===null||!te?.plates?.length))return te.plates.find(mt=>mt.index===v)?.name||void 0},[te,v]),{data:$e}=tt({queryKey:["available-filaments",W,J],queryFn:()=>fe.getAvailableFilaments(W,J??void 0),enabled:B==="model"&&!!W}),{data:Re}=tt({queryKey:["printer-status",$],queryFn:()=>fe.getPrinterStatus($),enabled:!!$}),{amsMapping:Ae}=eie(_e,Re,k),Pe=Iqe(f,ee,_e,k,A,D);w.useEffect(()=>{te?.plates&&te.plates.length>=1&&!v&&b(te.plates[0].index)},[te,v]),w.useEffect(()=>{if(t==="edit-queue-item")return;const mt=ee?.filter(jt=>jt.is_active)||[];mt.length===1&&f.length===0&&y([mt[0].id])},[t,ee,f.length]),w.useEffect(()=>{t==="edit-queue-item"?(JSON.stringify(f.sort())!==JSON.stringify(Y.sort())||v!==se)&&(R({}),D({}),U(new Set)):(R({}),D({}),U(new Set))},[t,f,v,Y,se]);const[Ue,je]=w.useState(W),[Xe,ye]=w.useState(v);w.useEffect(()=>{(W!==Ue||v!==Xe)&&(je(W),ye(v),(t!=="edit-queue-item"||Ue!==null)&&(ue({}),pe({})))},[W,v,Ue,Xe,t]),w.useEffect(()=>{if(!ne?.per_printer_mapping_expanded||f.length<=1)return;const mt=f.filter(jt=>{if(E.has(jt))return!1;const qt=Pe.printerResults.find(Jt=>Jt.printerId===jt);return qt&&qt.status&&!qt.isLoading});mt.length>0&&(U(jt=>{const qt=new Set(jt);return mt.forEach(Jt=>qt.add(Jt)),qt}),mt.forEach(jt=>{Pe.autoConfigurePrinter(jt)}))},[ne?.per_printer_mapping_expanded,f,E,Pe]),w.useEffect(()=>{const mt=jt=>{jt.key==="Escape"&&!oe&&o()};return window.addEventListener("keydown",mt),()=>window.removeEventListener("keydown",mt)},[o,oe]);const Ge=te?.is_multi_plate??!1,Ee=te?.plates??[],Ke=w.useMemo(()=>{const mt=new Map;return re&&re.forEach(jt=>{const qt=jt.ams_id===255,Jt=Y0(jt.ams_id,jt.tray_id,qt),Wt=mt.get(jt.printer_id)??new Map;Wt.set(Jt,jt),mt.set(jt.printer_id,Wt)}),mt},[re]),Ve=w.useMemo(()=>{if(!Z||Z.length===0)return"";const mt=Z.map(jt=>c("printModal.insufficientFilamentLine",{printer:jt.printerName,slot:jt.slotLabel,required:Math.round(jt.requiredGrams),remaining:Math.round(jt.remainingGrams)}));return[c("printModal.insufficientFilamentMessage"),...mt].join(` `)},[Z,c]),Ne=ft({mutationFn:mt=>fe.addToQueue(mt)}),Ce=ft({mutationFn:mt=>fe.updateQueueItem(a.id,mt),onSuccess:()=>{u.invalidateQueries({queryKey:["queue"]}),d("Queue item updated"),l?.(),o()},onError:mt=>{d(mt.message||"Failed to update queue item","error")}}),He=async(mt,jt)=>{if(mt?.preventDefault(),!jt?.skipFilamentCheck&&!ne?.disable_filament_warnings&&(t==="reprint"||t==="add-to-queue")&&B==="printer"){const Oe=[],nt=_e?.filaments??[];if(nt.length>0&&Ke.size>0){const dt=(Qe,Te)=>!Number.isFinite(Qe)||Qe<=0||!Number.isFinite(Te)||Te<0?null:Math.max(0,Qe-Te);for(const Qe of f){const Te=f.length>1?Pe.getFinalMapping(Qe):Ae;if(!Te)continue;const st=f.length>1?Pe.printerResults.find(De=>De.printerId===Qe)?.status:Re,le=Ww(st),Be=new Map(le.map(De=>[De.globalTrayId,De.label])),We=Ke.get(Qe),Ye=ee?.find(De=>De.id===Qe)?.name??`Printer ${Qe}`;We&&nt.forEach(De=>{if(!De.slot_id||De.slot_id<=0)return;const ht=Te[De.slot_id-1];if(!Number.isFinite(ht)||ht<0)return;const rt=We.get(ht)?.spool;if(!rt)return;const wt=dt(rt.label_weight,rt.weight_used);wt!==null&&(wt>=De.used_grams||Oe.push({printerName:Ye,slotLabel:Be.get(ht)??`Slot ${De.slot_id}`,requiredGrams:De.used_grams,remainingGrams:wt}))})}}if(Oe.length>0){j(Oe);return}}if(B==="printer"&&f.length===0){d("Please select at least one printer","error");return}if(B==="model"&&!W){d("Please select a target printer model","error");return}be(!0);const qt=g?Ee:[null],Jt=B==="model"?qt.length:f.length*qt.length;q({current:0,total:Jt});const Wt={success:0,failed:0,errors:[]},un=Oe=>{if(f.length>1){const nt=A[Oe];if(nt&&!nt.useDefault)return Pe.getFinalMapping(Oe)}return Ae},xn=(()=>{const Oe=[];if(_e?.filaments)for(const nt of _e.filaments){const dt=Q[nt.slot_id],Qe=me[nt.slot_id]??!1,Te=dt?.type??nt.type,st=dt?.color??nt.color;(dt||Qe)&&Oe.push({slot_id:nt.slot_id,type:Te,color:st,color_name:jd(st),force_color_match:Qe})}else for(const[nt,{type:dt,color:Qe}]of Object.entries(Q)){const Te=parseInt(nt,10),st=me[Te]??!1;Oe.push({slot_id:Te,type:dt,color:Qe,color_name:jd(Qe),force_color_match:st})}return Oe.length>0?Oe:void 0})(),Cn=(Oe,nt)=>({printer_id:B==="printer"?Oe:null,target_model:B==="model"?W:null,target_location:B==="model"?J:null,filament_overrides:B==="model"?xn:void 0,archive_id:p?void 0:e,library_file_id:p?n:void 0,require_previous_success:C.requirePreviousSuccess,auto_off_after:C.autoOffAfter,manual_start:C.scheduleType==="manual",ams_mapping:Oe?un(Oe):void 0,plate_id:nt!==void 0?nt:v,scheduled_time:C.scheduleType==="scheduled"&&C.scheduledTime?new Date(C.scheduledTime).toISOString():void 0,...N});if(B==="model"){if(t==="reprint"){d("Model-based assignment only works with queue mode","error"),be(!1);return}let Oe=0;for(const nt of qt){Oe++,q({current:Oe,total:Jt});const dt=nt?nt.index:v;try{if(t==="edit-queue-item"&&!nt){const Qe={printer_id:null,target_model:W,target_location:J,filament_overrides:xn||null,require_previous_success:C.requirePreviousSuccess,auto_off_after:C.autoOffAfter,manual_start:C.scheduleType==="manual",ams_mapping:void 0,plate_id:dt,scheduled_time:C.scheduleType==="scheduled"&&C.scheduledTime?new Date(C.scheduledTime).toISOString():null,...N};await Ce.mutateAsync(Qe)}else await Ne.mutateAsync(Cn(null,dt));Wt.success++}catch(Qe){Wt.failed++;const Te=nt?nt.name||`Plate ${nt.index}`:"";Wt.errors.push(Te?`${Te}: ${Qe.message}`:Qe.message)}}}else{let Oe=0;for(const nt of qt){const dt=nt?nt.index:v;for(let Qe=0;QeYe.id===Te)?.name||`Printer ${Te}`,Be=nt?nt.name||`Plate ${nt.index}`:"",We=Be?`${le} (${Be})`:le;Wt.errors.push(`${We}: ${st.message}`)}}}}be(!1),Wt.failed===0?(t!=="reprint"&&(t==="edit-queue-item"?d("Queue item updated"):Wt.success===1?d(B==="model"?`Queued for any ${W}`:c("queue.printQueued")):d(c("queue.itemsQueued",{count:Wt.success}))),u.invalidateQueries({queryKey:["queue"]}),l?.(),o()):Wt.success===0?d(`Failed: ${Wt.errors[0]}`,"error"):(d(`${Wt.success} succeeded, ${Wt.failed} failed`,"error"),u.invalidateQueries({queryKey:["queue"]}))},et=oe||Ce.isPending,it=w.useMemo(()=>!(et||B==="printer"&&f.length===0||B==="model"&&!W||B==="model"&&t==="reprint"||Ge&&!v&&!g),[f.length,B,W,t,Ge,v,g,et]),vt=(()=>{const mt=f.length;if(t==="reprint")return{title:c(p?"queue.print":"queue.reprint"),icon:_r,submitText:mt>1?c("queue.printToPrinters",{count:mt}):c("queue.print"),submitIcon:_r,loadingText:Me.total>1?c("queue.sendingProgress",{current:Me.current,total:Me.total}):c("queue.sending")};if(t==="add-to-queue"){let jt=c("queue.addToQueue");return g&&Ee.length>1?jt=c("queue.queueAllPlates",{count:Ee.length}):mt>1&&(jt=c("queue.queueToPrinters",{count:mt})),{title:c("queue.schedulePrint"),icon:Yr,submitText:jt,submitIcon:Yr,loadingText:Me.total>1?c("queue.addingProgress",{current:Me.current,total:Me.total}):c("queue.adding")}}return{title:c("queue.editQueueItem"),icon:Ki,submitText:c("common.save"),submitIcon:Ki,loadingText:Me.total>1?c("queue.savingProgress",{current:Me.current,total:Me.total}):c("common.saving")}})(),qe=vt.icon,_t=vt.submitIcon,Nt=$&&!g&&(p||(Ge?v!==null:!0));return i.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:oe?void 0:o,children:[i.jsx(Pt,{className:"w-full max-w-2xl max-h-[90vh] overflow-y-auto",onClick:mt=>mt.stopPropagation(),children:i.jsxs(Et,{className:t==="reprint"?"":"p-0",children:[i.jsxs("div",{className:`flex items-center justify-between ${t==="reprint"?"mb-4":"p-4 border-b border-bambu-dark-tertiary"}`,children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(qe,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:vt.title})]}),i.jsx(Ie,{variant:"ghost",size:"sm",onClick:o,disabled:oe,children:i.jsx(Ht,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:He,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&&ee?i.jsx("span",{className:"text-white",children:ee.find(mt=>mt.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(Hqe,{plates:Ee,isMultiPlate:Ge,selectedPlate:v,onSelect:b,queueAll:g,onQueueAllChange:t==="add-to-queue"?_:void 0}),!s?.length&&i.jsx(Vqe,{printers:ee||[],selectedPrinterIds:f,onMultiSelect:y,isLoading:G,allowMultiple:!0,showInactive:t==="edit-queue-item",disableBusy:t==="reprint",printerMappingResults:Pe.printerResults,filamentReqs:_e,onAutoConfigurePrinter:Pe.autoConfigurePrinter,onUpdatePrinterConfig:Pe.updatePrinterConfig,assignmentMode:t==="reprint"?"printer":B,onAssignmentModeChange:t!=="reprint"?z:void 0,targetModel:W,onTargetModelChange:t!=="reprint"?I:void 0,targetLocation:J,onTargetLocationChange:t!=="reprint"?ie:void 0,slicedForModel:xe}),B==="model"&&W&&_e&&$e&&$e.length>0&&i.jsx(Bqe,{filamentReqs:_e,availableFilaments:$e,overrides:Q,onChange:ue,forceColorMatch:me,onForceColorMatchChange:(mt,jt)=>pe(qt=>({...qt,[mt]:jt}))}),xe&&B==="printer"&&f.length===1&&(()=>{const mt=ee?.find(jt=>jt.id===f[0]);return mt&&mt.model&&xe!==mt.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(Mn,{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 ",xe,", but printing on ",mt.model]})]}):null})(),ke&&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(Li,{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."})]}),Nt&&!ke&&f.length===1&&i.jsx(Uqe,{printerId:$,filamentReqs:_e,manualMappings:k,onManualMappingChange:R,defaultExpanded:!!s?.length||(ne?.per_printer_mapping_expanded??!1),currencySymbol:O,defaultCostPerKg:V}),(t==="reprint"||K>0||B==="model"&&W)&&i.jsx(Wqe,{options:N,onChange:T,defaultExpanded:!!s?.length}),t!=="reprint"&&i.jsx(Kqe,{options:C,onChange:P,dateFormat:ne?.date_format||"system",timeFormat:ne?.time_format||"system",canControlPrinter:m("printers:control")}),Ce.isError&&i.jsx("div",{className:"mb-4 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:Ce.error?.message||"Failed to complete operation"}),i.jsxs("div",{className:`flex gap-3 ${t==="reprint"?"":"pt-2"}`,children:[i.jsx(Ie,{type:"button",variant:"secondary",onClick:o,className:"flex-1",disabled:oe,children:"Cancel"}),i.jsx(Ie,{type:"submit",disabled:!it,className:"flex-1",children:et?i.jsxs(i.Fragment,{children:[i.jsx(pt,{className:"w-4 h-4 animate-spin"}),vt.loadingText]}):i.jsxs(i.Fragment,{children:[i.jsx(_t,{className:"w-4 h-4"}),vt.submitText]})})]})]})]})}),Z&&Z.length>0&&i.jsx(_n,{title:c("printModal.insufficientFilamentTitle"),message:Ve,confirmText:c("printModal.printAnyway"),cancelText:c("common.cancel"),variant:"warning",onConfirm:()=>{j(null),He(void 0,{skipFilamentCheck:!0})},onCancel:()=>j(null)})]})}function gW({value:t}){const{t:e}=Rt(),[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(Qr,{className:"w-3.5 h-3.5 text-bambu-green"}):i.jsx(vo,{className:"w-3.5 h-3.5"})})}function Xqe({printer:t,status:e,totalPrintHours:n,onClose:r}){const{t:a}=Rt();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(gW,{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(gW,{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(BL,{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=RZ(e.wifi_signal);s.push({label:a("printers.wifiSignalLabel"),value:i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(QX,{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:Cf(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(Pt,{className:"w-full max-w-md",onClick:o=>o.stopPropagation(),children:i.jsxs(Et,{children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:t.name}),i.jsx("button",{onClick:r,className:"p-1 hover:bg-bambu-dark rounded flex-shrink-0",children:i.jsx(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsx("div",{className:"flex justify-center mb-4",children:i.jsx("img",{src:DZ(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 Qqe(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 Wj({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&&Qqe(t)?"#000":"#fff"},children:r})})}const bW={"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"},Zqe={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 Kj(t){if(!t)return null;if(bW[t])return bW[t];const e=t.split("-");if(e.length<2)return null;const n=e[1];return Zqe[n]||null}function Yj(t){return(t??.02).toFixed(3)}function xW({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 nie(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 rie(t,e){return t?t.startsWith("HH")?e("printers.nozzleHighFlow"):t.startsWith("HS")?e("printers.nozzleStandardFlow"):"":""}function iie({slot:t,index:e,activeStatus:n,filamentName:r,children:a}){const{t:s}=Rt(),[o,l]=w.useState(!1),[c,u]=w.useState("top"),d=w.useRef(null),m=w.useRef(null),p=w.useRef(null),f=!t.nozzle_diameter&&!t.nozzle_type,y=t.stat===1;w.useEffect(()=>{if(o&&d.current&&m.current){const T=d.current.getBoundingClientRect(),C=m.current.offsetHeight,k=T.top-56,R=window.innerHeight-T.bottom;kk?u("bottom"):u("top")}},[o]);const v=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>l(!0),80)},b=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>l(!1),100)};w.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const g=MI(t.filament_color),_=nie(t.nozzle_type,s),N=rie(t.nozzle_type,s);return i.jsxs("div",{ref:d,className:"relative",onMouseEnter:v,onMouseLeave:b,children:[a,o&&i.jsxs("div",{ref:m,className:` absolute left-1/2 -translate-x-1/2 z-50 ${c==="top"?"bottom-full mb-2":"top-full mt-2"} diff --git a/static/index.html b/static/index.html index 600b2f69b..7c7c8d5ed 100644 --- a/static/index.html +++ b/static/index.html @@ -23,7 +23,7 @@ - +