diff --git a/CHANGELOG.md b/CHANGELOG.md index b973908af..9d12993c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +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. +- **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 unrelated profiles instead of an empty result. The saved preset bypassed the search filter entirely, so stale mappings (e.g. a slot previously configured with "Bambu PLA Matte" that now holds a Silk spool) would always appear regardless of the search query. The saved preset now only bypasses the printer model filter, not 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 e53abbd30..2fd4e0145 100644 --- a/frontend/src/components/ConfigureAmsSlotModal.tsx +++ b/frontend/src/components/ConfigureAmsSlotModal.tsx @@ -515,8 +515,8 @@ export function ConfigureAmsSlotModal({ const isSavedPreset = savedId === cp.setting_id; const isCurrentPreset = isSavedPreset || (trayIdx && (cp.setting_id === trayIdx || convertToTrayInfoIdx(cp.setting_id) === trayIdx)); - // Only the exact saved preset bypasses search — trayIdx matches are too broad - if (!isSavedPreset && query && !cp.name.toLowerCase().includes(query)) continue; + // Search filter applies to ALL presets (including saved) — no bypass + if (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); @@ -530,8 +530,7 @@ export function ConfigureAmsSlotModal({ if (localPresets?.filament) { for (const lp of localPresets.filament) { const localId = `local_${lp.id}`; - const isSaved = savedId === localId; - if (!isSaved && query && !lp.name.toLowerCase().includes(query)) continue; + if (query && !lp.name.toLowerCase().includes(query)) continue; items.push({ id: localId, name: lp.name, source: 'local', isUser: false }); } } diff --git a/static/assets/index-AHXeK7K5.js b/static/assets/index-REte0XxX.js similarity index 98% rename from static/assets/index-AHXeK7K5.js rename to static/assets/index-REte0XxX.js index 86a9b0363..f48335926 100644 --- a/static/assets/index-AHXeK7K5.js +++ b/static/assets/index-REte0XxX.js @@ -8507,7 +8507,7 @@ void main() { ${o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})}`:g.type==="partial_profile"?Z=`${o("inventory.assignPartialMismatchMessage",{spoolMaterial:g.spoolMaterial,trayMaterial:g.trayMaterial,location:s.location})} -${o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})}`:g.type==="profile"&&(Z=o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})),i.jsx(Nn,{title:o("inventory.assignMismatchTitle"),message:Z,confirmText:o("inventory.assignMismatchConfirm"),variant:"warning",isLoading:T.isPending,onConfirm:ie,onCancel:()=>{T.isPending||(b(!1),y(null),_(null))}})})()]})}function mW(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 M1(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 Qv=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function hW(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 Qv)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 Qv){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 Eqe(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const jqe={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"},pW=[{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"}],fW=[{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 gW(t){const e=t.toLowerCase().trim();return jqe[e]||null}function Dqe(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 tie({isOpen:t,onClose:e,printerId:n,slotInfo:r,nozzleDiameter:a="0.4",printerModel:s,onSuccess:o,fullScreen:l}){const{t:c}=Dt(),[u,d]=w.useState(""),[m,p]=w.useState(null),[f,y]=w.useState(""),[v,b]=w.useState(""),[g,_]=w.useState(""),[N,C]=w.useState(!1),[k,P]=w.useState(!1),T=w.useRef(""),{data:D,isLoading:A,isError:R}=nt({queryKey:["cloudSettings"],queryFn:()=>ge.getCloudSettings(),enabled:t,retry:!1}),{data:B,isLoading:z}=nt({queryKey:["localPresets"],queryFn:()=>ge.getLocalPresets(),enabled:t}),{data:W,isLoading:I}=nt({queryKey:["builtinFilaments"],queryFn:()=>ge.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:ee,isLoading:ie}=nt({queryKey:["kprofiles",n,a],queryFn:()=>ge.getKProfiles(n,a),enabled:t&&!!n}),{data:Z}=nt({queryKey:["colorCatalog"],queryFn:()=>ge.getColorCatalog(),enabled:t,staleTime:1/0}),ue=gt({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(Fe=>Fe.id===K):null,O=U?W?.find(Fe=>Fe.filament_id===$):null,q=!E&&!U?D?.filament.find(Fe=>Fe.setting_id===u):null;if(!E&&!U&&!q)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 J=E?ne.name:U?O.name:q.name,G=hW(J),re=m?.slot_id??-1,ce=f||r.trayColor?.slice(0,6)||"FFFFFF",be=J.replace(/@.+$/,"").trim();let xe,ae;const L=G.material.toUpperCase();if(E){const Fe=(Qv.includes(L)?L:ne?.filament_type||G.material||"").toUpperCase(),He={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=He[Fe]||He[Fe.replace(/[-\s]?CF$/,"")]||He[Fe.replace(/\+$/,"")]||He[Fe.split(/[-\s]/)[0]]||"",ae=""}else if(U)xe=$,ae="";else if(xe=M1(u),ae=u,!u.startsWith("GFS"))try{const Fe=await ge.getCloudSettingDetail(u);Fe.filament_id?xe=Fe.filament_id:Fe.base_id&&(xe=M1(Fe.base_id),console.log(`Derived tray_info_idx from base_id: ${Fe.base_id} -> ${xe}`))}catch(Fe){console.warn("Failed to fetch preset detail for filament_id:",Fe)}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 Fe=(E?Qv.includes(L)?L:ne?.filament_type||G.material||"":G.material).toUpperCase();Fe.includes("PLA")?(F=190,te=230):Fe.includes("PETG")?(F=220,te=260):Fe.includes("ABS")||Fe.includes("ASA")?(F=240,te=280):Fe.includes("TPU")?(F=200,te=240):Fe==="PCTG"?(F=220,te=260):Fe.includes("PC")?(F=260,te=300):(Fe.includes("PA")||Fe.includes("NYLON"))&&(F=250,te=290)}const ve=m?.k_value?parseFloat(m.k_value):0,pe=E?Qv.includes(L)?L:ne?.filament_type||G.material||"PLA":G.material||"PLA",de=await ge.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:xe,tray_type:pe,tray_sub_brands:be,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}),je=E?`local_${K}`:U?`builtin_${$}`:u,we=E?"local":U?"builtin":"cloud";try{await ge.saveSlotPreset(n,r.amsId,r.trayId,je,be,we)}catch(Fe){console.warn("Failed to save slot preset mapping:",Fe)}return de},onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),me=gt({mutationFn:async()=>ge.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),he=w.useMemo(()=>{const E=g.toLowerCase(),U=[],K=new Set,$=r.savedPresetId,ne=r.trayInfoIdx;if(D?.filament)for(const O of D.filament){K.add(O.setting_id);const q=$===O.setting_id,J=q||ne&&(O.setting_id===ne||M1(O.setting_id)===ne);if(!(!q&&E&&!O.name.toLowerCase().includes(E))){if(!J&&s){const G=Dqe(O.name);if(G&&G.toUpperCase()!==s.toUpperCase())continue}U.push({id:O.setting_id,name:O.name,source:"cloud",isUser:Eqe(O.setting_id)})}}if(B?.filament)for(const O of B.filament){const q=`local_${O.id}`;!($===q)&&E&&!O.name.toLowerCase().includes(E)||U.push({id:q,name:O.name,source:"local",isUser:!1})}if(W)for(const O of W){if(K.has(O.filament_id))continue;const q=O.filament_id.startsWith("GF")?"GFS"+O.filament_id.slice(2):O.filament_id;K.has(q)||(!E||O.name.toLowerCase().includes(E))&&U.push({id:`builtin_${O.filament_id}`,name:O.name,source:"builtin",isUser:!1})}return U.sort((O,q)=>{const J={cloud:0,local:1,builtin:2};return O.source!==q.source?J[O.source]-J[q.source]:O.isUser&&!q.isUser?-1:!O.isUser&&q.isUser?1:O.name.localeCompare(q.name)})},[D?.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 D?.filament&&(E=D.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=hW(U);return{fullName:U,material:K.material,brand:K.brand}},[u,D?.filament,B?.filament,W]),se=Y?.fullName||"",le=w.useMemo(()=>{if(!Z||!Y)return[];const{fullName:E,brand:U}=Y,K=E.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return Z.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 J=U.toUpperCase();if(!O.includes(J)&&!J.includes(O))return!1}return!0})},[Z,Y]),fe=w.useMemo(()=>{if(!ee?.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 q=ee.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 be={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[ne]||[];for(const xe of be)if(re.includes(xe))return!0;return!1}),J=new Map;for(const G of q){const re=`${G.name}|${G.k_value}`,ce=J.get(re);ce?r.extruderId!==void 0&&G.extruder_id===r.extruderId&&ce.extruder_id!==r.extruderId&&J.set(re,G):J.set(re,G)}return Array.from(J.values())},[ee?.profiles,Y,r.extruderId]);w.useEffect(()=>{if(t){if(r.savedPresetId)d(r.savedPresetId);else if(r.trayInfoIdx&&D?.filament){let E=D.filament.find(U=>U.setting_id===r.trayInfoIdx);E||(E=D.filament.find(U=>M1(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(""),_(""),C(!1),T.current=""},[t,r.savedPresetId,r.trayInfoIdx,r.trayColor,D?.filament,W]),w.useEffect(()=>{if(fe.length>0){if(r.caliIdx!=null&&r.caliIdx>0){const E=fe.find(U=>U.slot_id===r.caliIdx);if(E){p(E);return}}p(fe[0])}else p(null)},[u,fe,r.caliIdx]);const Te=w.useCallback(E=>{E.key==="Escape"&&e()},[e]);w.useEffect(()=>{if(t)return document.addEventListener("keydown",Te),()=>document.removeEventListener("keydown",Te)},[t,Te]);const V=A&&!R||z||I||ie;if(w.useEffect(()=>{if(!V&&u&&u!==T.current){const E=requestAnimationFrame(()=>{const K=document.querySelector('[class*="fixed inset-0 z-50"]')?.querySelector(`[data-preset-id="${CSS.escape(u)}"]`);K&&(T.current=u,K.scrollIntoView({block:"nearest"}))});return()=>cancelAnimationFrame(E)}},[u,V]),!t)return null;const X=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(Bd,{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:mW(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(Bt,{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(wc,{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:mW(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&i.jsxs("span",{className:"text-bambu-gray",children:["(",r.traySubBrands,")"]})]})]}),V?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ft,{className:"w-6 h-6 text-bambu-green animate-spin"})}):l?i.jsxs("div",{className:"flex gap-4 h-full",children:[i.jsxs("div",{className:"w-1/2 flex flex-col min-h-0",children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:g,onChange: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:he.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:D?.filament?.length===0&&!B?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):he.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})})]}),fe.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:E=>{const U=fe.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")}),fe.map(E=>i.jsxs("option",{value:E.name,children:[E.name," (K=",E.k_value,")"]},`${E.name}-${E.extruder_id}`))]}),i.jsx(In,{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")}),le.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:le.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:[pW.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(!k),className:"w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs",title:c(k?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:k?"−":"+"})]}),k&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:fW.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=gW(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:he.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:D?.filament?.length===0&&!B?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):he.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})})]}),fe.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:E=>{const U=fe.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")}),fe.map(E=>i.jsxs("option",{value:E.name,children:[E.name," (K=",E.k_value,")"]},`${E.name}-${E.extruder_id}`))]}),i.jsx(In,{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")}),le.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:le.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:[pW.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(!k),className:"w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs",title:c(k?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:k?"−":"+"})]}),k&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:fW.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=gW(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(ze,{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(ft,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.resetting")]}):i.jsxs(i.Fragment,{children:[i.jsx(Co,{className:"w-4 h-4"}),c("configureAmsSlot.resetSlot")]})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(ze,{variant:"secondary",onClick:e,children:c("configureAmsSlot.cancel")}),i.jsx(ze,{onClick:()=>ue.mutate(),disabled:!X,children:ue.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.configuring")]}):i.jsxs(i.Fragment,{children:[i.jsx(Bd,{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 nie({folderId:t,onClose:e,onUploadComplete:n,onFileUploaded:r,autoUpload:a,validateFile:s,accept:o}){const{t:l}=Dt(),[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),[C,k]=w.useState(null),P=w.useRef(null),T=he=>{he.preventDefault(),m(!0)},D=he=>{he.preventDefault(),m(!1)},A=he=>{he.preventDefault(),m(!1),W(Array.from(he.dataTransfer.files))},R=he=>{he.target.files&&W(Array.from(he.target.files))},B=(he,Y)=>{u(se=>se.map(le=>le.file===he?{...le,...Y}:le))},z=async he=>{f(!0);for(const Y of he)if(Y.status==="pending"){B(Y.file,{status:"uploading"});try{if(Y.isZip){const se=await ge.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 ge.uploadLibraryFile(Y.file,t,_);B(Y.file,{status:"success"});const le=r?.(se);if(le){k(le),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=he=>{if(k(null),s)for(const se of he){const le=s(se);if(le){k(le);return}}const Y=he.map(se=>({file:se,status:"pending",isZip:se.name.toLowerCase().endsWith(".zip"),is3mf:se.name.toLowerCase().endsWith(".3mf")}));u(se=>[...se,...Y]),a&&he.length>0&&z(Y)},I=he=>{u(Y=>Y.filter((se,le)=>le!==he))},ee=c.some(he=>he.isZip&&he.status==="pending"),ie=c.some(he=>he.file.name.toLowerCase().endsWith(".stl")&&he.status==="pending"),Z=c.some(he=>he.is3mf&&he.status==="pending"),ue=c.filter(he=>he.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(Bt,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsxs("div",{onDragOver:T,onDragLeave:D,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:R}),ee&&i.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Vs,{className:"w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-blue-300 font-medium",children:l("fileManager.zipFilesDetected")}),i.jsx("p",{className:"text-xs text-blue-300/70 mt-1",children:l("fileManager.zipExtractOptions")}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:y,onChange:he=>v(he.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.preserveZipStructure")})]}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:b,onChange:he=>g(he.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.createFolderFromZip")})]})]})]})}),Z&&i.jsx("div",{className:"p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(_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||ee)&&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(Ud,{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(ee&&!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:he=>N(he.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.generateThumbnailsForStl")})]})]})]})}),c.length>0&&i.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:c.map((he,Y)=>i.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[he.isZip?i.jsx(Vs,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):i.jsx(tT,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-sm text-white truncate",children:he.file.name}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[(he.file.size/1024/1024).toFixed(2)," MB",he.isZip&&he.status==="pending"&&i.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",l("fileManager.willBeExtracted")]}),he.extractedCount!==void 0&&i.jsxs("span",{className:"text-green-400 ml-2",children:["• ",l("fileManager.filesExtracted",{count:he.extractedCount})]})]})]}),he.status==="pending"&&i.jsx("button",{onClick:()=>I(Y),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(Bt,{className:"w-4 h-4 text-bambu-gray"})}),he.status==="uploading"&&i.jsx(ft,{className:"w-4 h-4 text-bambu-green animate-spin"}),he.status==="success"&&i.jsx(pr,{className:"w-4 h-4 text-green-500"}),he.status==="error"&&i.jsx("span",{title:he.error,children:i.jsx(Vi,{className:"w-4 h-4 text-red-500"})})]},Y))}),C&&i.jsx("div",{className:"p-3 bg-red-500/10 border border-red-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Vi,{className:"w-5 h-5 text-red-400 mt-0.5 flex-shrink-0"}),i.jsx("p",{className:"text-sm text-red-300",children:C})]})})]}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2",children:[i.jsx(ze,{variant:"secondary",onClick:e,children:l("common.cancel")}),!me&&i.jsx(ze,{onClick:()=>z(c),disabled:ue===0||p,children:p?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-4 h-4 mr-2 animate-spin"}),l("fileManager.uploading")]}):i.jsxs(i.Fragment,{children:[i.jsx(vi,{className:"w-4 h-4 mr-2"}),l("common.upload")," ",ue>0?`(${ue})`:""]})})]})]})})}function bW(t){return t?`#${t.replace("#","").substring(0,6)}`:"#808080"}function Fi(t){return t?t.replace("#","").toLowerCase().substring(0,6):""}const Rqe=[["PA-CF","PA12-CF","PAHT-CF"]],rie={};for(const t of Rqe){const e=t[0];for(const n of t)rie[n.toUpperCase()]=e.toUpperCase()}function eC(t){if(!t)return"";const e=t.toUpperCase();return rie[e]??e}function X2(t,e){return eC(t)===eC(e)}function bu(t,e,n=40){const r=Fi(t),a=Fi(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 F4(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 X0(t,e,n){return n?254+e:t>=128?t:t*4+e}function xW(t){if(!t)return!1;const e=Date.now()+4320*60*60*1e3;return(Qn(t)?.getTime()??0)>e}function Fqe(t,e,n){const r=iie(e,t.nozzle_id),a=r.find(l=>!n.has(l.globalTrayId)&&X2(l.type,t.type)&&Fi(l.color)===Fi(t.color)),s=a?void 0:r.find(l=>!n.has(l.globalTrayId)&&X2(l.type,t.type)&&bu(l.color,t.color)),o=a||s?void 0:r.find(l=>!n.has(l.globalTrayId)&&X2(l.type,t.type));return a??s??o}function iie(t,e){return t.filter(n=>e==null||n.extruderId===e)}function Kw(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=bW(o.tray_color);e.push({type:o.tray_type,color:l,colorName:Ld(l),amsId:a.id,trayId:o.id,isHt:s,isExternal:!1,label:F4(a.id,o.id,s,!1),globalTrayId:X0(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=bW(a.tray_color),o=a.id??254,l=(t?.vt_tray?.length??0)>1;e.push({type:a.tray_type,color:s,colorName:Ld(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 yW(t,e){if(!t?.filaments||t.filaments.length===0)return;const n=Kw(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()&&Fi(b.color)===Fi(l.color)),m||(p=v.find(b=>b.type?.toUpperCase()===l.type?.toUpperCase()&&bu(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()&&Fi(v.color)===Fi(l.color)),m||(p=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&bu(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 Lqe(t){return w.useMemo(()=>Kw(t),[t])}function aie(t,e,n){const r=Lqe(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],T=r.find(D=>D.globalTrayId===P);if(T){const D=T.type?.toUpperCase()===u.type?.toUpperCase(),A=Fi(T.color)===Fi(u.color)||bu(T.color,u.color);let R;return D&&A?R="match":D?R="type_only":R="mismatch",{...u,loaded:T,hasFilament:!0,typeMatch:D,colorMatch:A,status:R,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(T=>T.trayInfoIdx===m);P.length===1?f=P[0]:P.length>1&&(y=P.find(T=>T.type?.toUpperCase()===u.type?.toUpperCase()&&Fi(T.color)===Fi(u.color)),y||(v=P.find(T=>T.type?.toUpperCase()===u.type?.toUpperCase()&&bu(T.color,u.color))),!y&&!v&&(b=P.find(T=>T.type?.toUpperCase()===u.type?.toUpperCase())))}!f&&!y&&!v&&!b&&(y=p.find(P=>P.type?.toUpperCase()===u.type?.toUpperCase()&&Fi(P.color)===Fi(u.color)),y||(v=p.find(P=>P.type?.toUpperCase()===u.type?.toUpperCase()&&bu(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=_,C=!!f||!!y||!!v;let k;return f||y||v?k="match":b?k="type_only":k="mismatch",{...u,loaded:g,hasFilament:_,typeMatch:N,colorMatch:C,status:k,isManual:!1}})},[t,r,n]),s=w.useMemo(()=>{if(a.length===0)return;const c=Math.max(...a.map(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 Oqe(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=Fi(g.color)===Fi(u.color)||bu(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()&&Fi(b.color)===Fi(u.color)),f=p?void 0:m.find(b=>b.type?.toUpperCase()===u.type?.toUpperCase()&&bu(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 Iqe(t,e,n){if(!t?.filaments||t.filaments.length===0)return;const r=Kw(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()&&Fi(v.color)===Fi(c.color)),p=m?void 0:d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&bu(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 vW={useDefault:!0,manualMappings:{},autoConfigured:!1};function zqe(t,e,n,r,a,s){const o=eg({queries:t.map(y=>({queryKey:["printer-status",y],queryFn:()=>ge.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(R=>R.id===y)?.name||`Printer ${y}`,C=Kw(g),k=a[y]||vW,P=yW(n,g),T=k.useDefault?r:k.manualMappings,D=Iqe(n,g,T),A=Oqe(n?.filaments,C,T);return{printerId:y,printerName:N,status:g,isLoading:b?.isLoading??!1,loadedFilaments:C,autoMapping:P,finalMapping:D,matchStatus:A.status,exactMatches:A.exactMatches,typeOnlyMatches:A.typeOnlyMatches,missingTypes:A.missingTypes,totalSlots:A.totalSlots,config:k}}),[t,o,e,n,a,r]),c=o.some(y=>y.isLoading),u=(y,v)=>{s(b=>({...b,[y]:{...b[y]||vW,...v}}))},d=y=>{const v=l.find(_=>_.printerId===y);if(!v||!v.status||!n?.filaments)return;const b=yW(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 sie={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 Wo(t){return sie[t.toUpperCase()]||t}const Uqe=Object.entries(sie).map(([t,e])=>({code:t,label:`${t} (${e})`}));function Bqe({printerId:t,filamentReqs:e,manualMappings:n,onManualMappingChange:r,currencySymbol:a,defaultCostPerKg:s,defaultExpanded:o=!1}){const{t:l}=Dt(),c=on(),[u,d]=w.useState(!1),[m,p]=w.useState(o),{data:f}=nt({queryKey:["printer-status",t],queryFn:()=>ge.getPrinterStatus(t),enabled:!!t}),{data:y}=nt({queryKey:["spool-assignments",t],queryFn:()=>ge.getAssignments(t),enabled:!!t}),{loadedFilaments:v,filamentComparison:b,hasTypeMismatch:g,hasColorMismatch:_}=aie(e,f,n),N=w.useMemo(()=>{const z=new Map;for(const W of y||[]){const I=W.ams_id===255,ee=X0(W.ams_id,W.tray_id,I);z.set(ee,W.spool?.cost_per_kg??null)}return z},[y]),C=w.useMemo(()=>{const z=new Map;for(const W of y||[]){const I=W.ams_id===255,ee=X0(W.ams_id,W.tray_id,I),ie=W.spool;if(!ie){z.set(ee,null);continue}z.set(ee,Math.max(0,Math.round((ie.label_weight??0)-(ie.weight_used??0))))}return z},[y]),k=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]),T=e?.filaments&&e.filaments.length>0,D=e?.filaments?.some(z=>z.nozzle_id!=null)??!1;if(!T||!f)return null;const A=g?"#f97316":_?"#facc15":"#00ae42",R=(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 ge.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(y0,{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(Vl,{className:"w-4 h-4 ml-auto"}):i.jsx(In,{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} - ${Ld(z.color)}`,children:i.jsx(y0,{className:"w-3 h-3",fill:z.color,stroke:z.color})}),i.jsxs("span",{className:"text-white truncate flex items-center gap-1",children:[D&&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=>R(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 ee=C.get(I.globalTrayId),ie=ee!=null?l("printModal.slotRemainingShort",{grams:ee,defaultValue:` - ${ee}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(Zr,{className:"w-3 h-3 text-bambu-green"}):z.status==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(jn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(jn,{className:"w-3 h-3 text-orange-400"})})]},W)),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[l("printModal.totalCost")," ",i.jsx("span",{className:"text-white",children:k>0||P?`${a}${k.toFixed(2)}`:"N/A"})]}),g&&i.jsx("p",{className:"text-xs text-orange-400 mt-2",children:"Required filament type not found in printer."})]})]})}function Hqe({filamentReqs:t,availableFilaments:e,overrides:n,onChange:r,forceColorMatch:a,onForceColorMatchChange:s}){const{t:o}=Dt(),l=w.useMemo(()=>{const d={};for(const m of e){const p=eC(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[eC(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} - ${Ld(d.color)}`,children:i.jsx(y0,{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," (",Ld(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," (",Ld(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(Co,{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(vw,{className:"w-3 h-3"}),o("printModal.forceColorMatch")]})]},d.slot_id)})})]})}function $qe({plates:t,isMultiPlate:e,selectedPlate:n,onSelect:r,queueAll:a,onQueueAllChange:s}){const{t:o}=Dt();return!e||t.length<=1?null:i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx(Gi,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:"Select Plate to Print"}),!n&&!a&&i.jsxs("span",{className:"text-xs text-orange-400 flex items-center gap-1",children:[i.jsx(jn,{className:"w-3 h-3"}),"Selection required"]}),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(Gi,{className:"w-5 h-5 text-bambu-gray"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-sm text-white font-medium truncate",children: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?` • ${Us(l.print_time_seconds)}`:""]})]}),(a||n===l.index)&&i.jsx(Zr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]},l.index))})]})}const qqe=new Set(["IDLE","FINISH","FAILED"]);function Vqe({printerResult:t,filamentReqs:e,onUpdateConfig:n}){const r=on(),[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 ge.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=Fqe(u,t.loadedFilaments,v)}let y="mismatch";if(p){const v=p.type?.toUpperCase()===u.type?.toUpperCase(),b=Fi(p.color)===Fi(u.color)||bu(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} - ${Ld(u.color)}`,children:i.jsx(y0,{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 --"}),iie(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(Zr,{className:"w-3 h-3 text-bambu-green"}):m==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(jn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(jn,{className:"w-3 h-3 text-orange-400"})})]},f))]})}function Gqe({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),C=s?t:t.filter(se=>se.is_active),k=eg({queries:C.map(se=>({queryKey:["printerStatus",se.id],queryFn:()=>ge.getPrinterStatus(se.id),staleTime:5e3}))}),P=w.useMemo(()=>{const se=new Map;return C.forEach((le,fe)=>{const Te=k[fe];Te?.data&&se.set(le.id,Te.data)}),se},[C,k]),T=se=>{const le=P.get(se);return le?le.connected?!qqe.has(le.state??""):!0:!1},D=se=>{const le=P.get(se);if(!le)return null;if(!le.connected)return"Offline";const fe=le.state;return fe?fe==="RUNNING"?le.stg_cur_name||"Printing":fe==="PREPARE"?"Preparing":fe==="PAUSE"?"Paused":fe==="IDLE"?"Idle":fe==="FINISH"?"Finished":fe==="FAILED"?"Failed":fe:null},A=w.useMemo(()=>{if(m!=="printer"||!g||_)return C;const se=C.filter(le=>le.model===g);return se.length>0?se:C},[C,m,g,_]),R=C.length-A.length,B=w.useMemo(()=>{const se=C.map(le=>le.model).filter(le=>!!le);return[...new Set(se)].sort()},[C]),z=w.useMemo(()=>{if(!f)return[];const se=C.filter(le=>le.model===f&&le.location).map(le=>le.location).filter(le=>!!le);return[...new Set(se)].sort()},[C,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(ft,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(A.length===0)return i.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm mb-4",children:[i.jsx(Oi,{className:"w-4 h-4"}),"No ",s?"":"active ","printers available"]});const ee=se=>{o&&T(se)||(a?e.includes(se)?n(e.filter(le=>le!==se)):n([...e,se]):n([se]))},ie=()=>{const se=o?A.filter(le=>!T(le.id)):A;n(se.map(le=>le.id))},Z=()=>{n([])},ue=(se,le,fe)=>{fe.stopPropagation(),!(!u||!d)&&(le?u(se):d(se,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},me=se=>e.includes(se),he=e.length,Y=se=>l?.find(le=>le.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(ih,{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:he===0?"Select printers":`${he} printer${he!==1?"s":""} selected`}),i.jsxs("div",{className:"flex gap-2",children:[he0&&i.jsx("button",{type:"button",onClick:Z,className:"text-bambu-gray hover:text-white transition-colors",children:"Clear"})]})]}),m==="printer"&&A.map(se=>{const le=me(se.id),fe=Y(se.id),Te=fe&&!fe.config.useDefault,V=T(se.id),X=o&&V,j=D(se.id);return i.jsxs("div",{children:[i.jsxs("button",{type:"button",onClick:()=>ee(se.id),disabled:X,className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${X?"border-bambu-dark-tertiary bg-bambu-dark opacity-50 cursor-not-allowed":le?"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 ${X?"bg-bambu-dark-tertiary":le?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:i.jsx(_r,{className:`w-5 h-5 ${X?"text-bambu-gray/50":le?"text-bambu-green":"text-bambu-gray"}`})}),i.jsxs("div",{className:"text-left flex-1",children:[i.jsxs("p",{className:`font-medium ${X?"text-bambu-gray":"text-white"}`,children:[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 ${V?"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 ${X?"border-bambu-gray/30":le?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:le&&i.jsx(Zr,{className:"w-3 h-3 text-white"})})]}),le&&I&&fe&&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:Te,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 ${fe.matchStatus==="full"?"text-bambu-green":fe.matchStatus==="partial"?"text-yellow-400":"text-orange-400"}`,children:["(",fe.exactMatches,"/",fe.totalSlots," matched)"]}),fe.isLoading&&i.jsx(Sr,{className:"w-3 h-3 text-bambu-gray animate-spin"}),Te&&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(Rbe,{className:"w-3 h-3"}),"Auto"]})]}),Te&&i.jsx(Vqe,{printerResult:fe,filamentReqs:c.filaments,onUpdateConfig:E=>d(se.id,E)})]})]},se.id)}),m==="printer"&&R>0&&!_&&i.jsxs("button",{type:"button",onClick:()=>N(!0),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2 flex items-center gap-1",children:[i.jsx(jn,{className:"w-3 h-3 text-yellow-400"}),R," other printer",R>1?"s":""," hidden (different model) —",i.jsx("span",{className:"underline",children:"show all"})]}),m==="printer"&&_&&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"&&he===0&&i.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[i.jsx(Oi,{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(Oi,{className:"w-3 h-3"}),"Select a target printer model"]})]})}const Wqe=[{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 Kqe({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(lT,{className:"w-4 h-4"}),i.jsx("span",{children:"Print Options"}),r?i.jsx(Vl,{className:"w-4 h-4 ml-auto"}):i.jsx(In,{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:Wqe.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 Yqe({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 k;t.scheduledTime?(k=new Date(t.scheduledTime),isNaN(k.getTime())&&(k=new Date,k.setHours(k.getHours()+1,0,0,0))):(k=new Date,k.setHours(k.getHours()+1,0,0,0),e({...t,scheduledTime:P3(k)})),o(A3(k,n)),c(n6(k,r)),d(!0),p(!0)}},[t.scheduleType,t.scheduledTime,n,r,e,t]);const v=k=>{e({...t,scheduleType:k})},b=(k,P)=>{const T=rxe(k,n),D=ixe(P);d(!!T),p(!!D),T&&D&&(T.setHours(D.hours,D.minutes,0,0),T>new Date&&e({...t,scheduledTime:P3(T)}))},g=k=>{o(k),b(k,l)},_=k=>{c(k),b(s,k)},N=k=>{const P=k.target.value;if(P){const T=new Date(P);isNaN(T.getTime())||(o(A3(T,n)),c(n6(T,r)),d(!0),p(!0),e({...t,scheduledTime:P}))}},C=()=>{f.current?.showPicker()};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"When to print"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="asap"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("asap"),children:[i.jsx(Zn,{className:"w-4 h-4"}),"ASAP"]}),i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="scheduled"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("scheduled"),children:[i.jsx(Xr,{className:"w-4 h-4"}),"Scheduled"]}),i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="manual"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("manual"),children:[i.jsx(QX,{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:k=>g(k.target.value),placeholder:exe(n)}),i.jsx("button",{type:"button",onClick:C,className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",title:"Open calendar",children:i.jsx(Xr,{className:"w-4 h-4"})})]}),i.jsx("div",{className:"w-32",children:i.jsx("input",{type:"text",className:`w-full px-3 py-2 bg-bambu-dark border rounded-lg text-white focus:outline-none ${m?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:l,onChange:k=>_(k.target.value),placeholder:txe(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:k=>e({...t,requirePreviousSuccess:k.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("label",{htmlFor:"requirePrevious",className:"text-sm text-bambu-gray",children:"Only start if previous print succeeded"})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"checkbox",id:"autoOffAfter",checked:t.autoOffAfter,onChange:k=>e({...t,autoOffAfter:k.target.checked}),disabled:!a,className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green disabled:opacity-50"}),i.jsxs("label",{htmlFor:"autoOffAfter",className:`text-sm flex items-center gap-1 ${a?"text-bambu-gray":"text-bambu-gray/50"}`,children:[i.jsx(em,{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 _b={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1},Xqe={scheduleType:"asap",scheduledTime:"",requirePreviousSuccess:!1,autoOffAfter:!1};function xu({mode:t,archiveId:e,libraryFileId:n,archiveName:r,queueItem:a,initialSelectedPrinterIds:s,onClose:o,onSuccess:l}){const{t:c}=Dt(),u=on(),{showToast:d}=gn(),{hasPermission:m}=Ar(),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,C]=w.useState(()=>t==="edit-queue-item"&&a?{bed_levelling:a.bed_levelling??_b.bed_levelling,flow_cali:a.flow_cali??_b.flow_cali,vibration_cali:a.vibration_cali??_b.vibration_cali,layer_inspect:a.layer_inspect??_b.layer_inspect,timelapse:a.timelapse??_b.timelapse}:_b),[k,P]=w.useState(()=>{if(t==="edit-queue-item"&&a){let rt="asap";a.manual_start?rt="manual":a.scheduled_time&&!xW(a.scheduled_time)&&(rt="scheduled");let At="";if(a.scheduled_time&&!xW(a.scheduled_time)){const $t=Qn(a.scheduled_time)??new Date;At=P3($t)}return{scheduleType:rt,scheduledTime:At,requirePreviousSuccess:a.require_previous_success,autoOffAfter:a.auto_off_after}}return Xqe}),[T,D]=w.useState(()=>{if(t==="edit-queue-item"&&a?.ams_mapping&&Array.isArray(a.ams_mapping)){const rt={};return a.ams_mapping.forEach((At,$t)=>{At!==-1&&(rt[$t+1]=At)}),rt}return{}}),[A,R]=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),[ee,ie]=w.useState(()=>t==="edit-queue-item"&&a?.target_location?a.target_location:null),[Z,ue]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const rt={};for(const At of a.filament_overrides)rt[At.slot_id]={type:At.type,color:At.color};return rt}return{}}),[me,he]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const rt={};for(const At of a.filament_overrides)rt[At.slot_id]=At.force_color_match===!0;return rt}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),[le,fe]=w.useState(!1),[Te,V]=w.useState({current:0,total:0}),[X,j]=w.useState(null),[E,U]=w.useState(new Set),K=f.length,$=f.length>0?f[0]:null,{data:ne}=nt({queryKey:["settings"],queryFn:ge.getSettings}),O=Wo(ne?.currency||"USD"),q=ne?.default_filament_cost??0,{data:J,isLoading:G}=nt({queryKey:["printers"],queryFn:ge.getPrinters}),{data:re}=nt({queryKey:["spool-assignments"],queryFn:()=>ge.getAssignments(),staleTime:30*1e3,enabled:(t==="reprint"||t==="add-to-queue")&&B==="printer"||p&&t==="reprint"}),{data:ce}=nt({queryKey:["archive",e],queryFn:()=>ge.getArchive(e),enabled:!!e&&!p}),{data:be}=nt({queryKey:["library-file",n],queryFn:()=>ge.getLibraryFile(n),enabled:p&&!!n}),xe=ce?.sliced_for_model||be?.sliced_for_model||null,{data:ae,isError:L}=nt({queryKey:["archive-plates",e],queryFn:()=>ge.getArchivePlates(e),enabled:!!e&&!p,retry:!1}),{data:F}=nt({queryKey:["library-file-plates",n],queryFn:()=>ge.getLibraryFilePlates(n),enabled:p&&!!n}),te=p?F:ae,{data:ve,isError:pe}=nt({queryKey:["archive-filaments",e,v],queryFn:()=>ge.getArchiveFilamentRequirements(e,v??void 0),enabled:!!e&&!p&&(v!==null||!te?.is_multi_plate),retry:!1}),{data:de}=nt({queryKey:["library-file-filaments",n,v],queryFn:()=>ge.getLibraryFileFilamentRequirements(n,v??void 0),enabled:p&&!!n&&(v!==null||!te?.is_multi_plate)}),je=!p&&(L||pe),we=p?de:ve,Fe=w.useMemo(()=>{if(!(v===null||!te?.plates?.length))return te.plates.find(rt=>rt.index===v)?.name||void 0},[te,v]),{data:He}=nt({queryKey:["available-filaments",W,ee],queryFn:()=>ge.getAvailableFilaments(W,ee??void 0),enabled:B==="model"&&!!W}),{data:Ie}=nt({queryKey:["printer-status",$],queryFn:()=>ge.getPrinterStatus($),enabled:!!$}),{amsMapping:Ne}=aie(we,Ie,T),Ae=zqe(f,J,we,T,A,R);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 rt=J?.filter(At=>At.is_active)||[];rt.length===1&&f.length===0&&y([rt[0].id])},[t,J,f.length]),w.useEffect(()=>{t==="edit-queue-item"?(JSON.stringify(f.sort())!==JSON.stringify(Y.sort())||v!==se)&&(D({}),R({}),U(new Set)):(D({}),R({}),U(new Set))},[t,f,v,Y,se]);const[Be,Ee]=w.useState(W),[Xe,ye]=w.useState(v);w.useEffect(()=>{(W!==Be||v!==Xe)&&(Ee(W),ye(v),(t!=="edit-queue-item"||Be!==null)&&(ue({}),he({})))},[W,v,Be,Xe,t]),w.useEffect(()=>{if(!ne?.per_printer_mapping_expanded||f.length<=1)return;const rt=f.filter(At=>{if(E.has(At))return!1;const $t=Ae.printerResults.find(rn=>rn.printerId===At);return $t&&$t.status&&!$t.isLoading});rt.length>0&&(U(At=>{const $t=new Set(At);return rt.forEach(rn=>$t.add(rn)),$t}),rt.forEach(At=>{Ae.autoConfigurePrinter(At)}))},[ne?.per_printer_mapping_expanded,f,E,Ae]),w.useEffect(()=>{const rt=At=>{At.key==="Escape"&&!le&&o()};return window.addEventListener("keydown",rt),()=>window.removeEventListener("keydown",rt)},[o,le]);const We=te?.is_multi_plate??!1,Pe=te?.plates??[],Ke=w.useMemo(()=>{const rt=new Map;return re&&re.forEach(At=>{const $t=At.ams_id===255,rn=X0(At.ams_id,At.tray_id,$t),Vt=rt.get(At.printer_id)??new Map;Vt.set(rn,At),rt.set(At.printer_id,Vt)}),rt},[re]),Ve=w.useMemo(()=>{if(!X||X.length===0)return"";const rt=X.map(At=>c("printModal.insufficientFilamentLine",{printer:At.printerName,slot:At.slotLabel,required:Math.round(At.requiredGrams),remaining:Math.round(At.remainingGrams)}));return[c("printModal.insufficientFilamentMessage"),...rt].join(` +${o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})}`:g.type==="profile"&&(Z=o("inventory.assignProfileMismatchMessage",{spoolProfile:g.spoolProfile||o("common.unknown"),trayProfile:g.trayProfile||o("common.unknown"),location:s.location})),i.jsx(Nn,{title:o("inventory.assignMismatchTitle"),message:Z,confirmText:o("inventory.assignMismatchConfirm"),variant:"warning",isLoading:T.isPending,onConfirm:ie,onCancel:()=>{T.isPending||(b(!1),y(null),_(null))}})})()]})}function mW(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 M1(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 Qv=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function hW(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 Qv)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 Qv){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 Eqe(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const jqe={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"},pW=[{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"}],fW=[{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 gW(t){const e=t.toLowerCase().trim();return jqe[e]||null}function Dqe(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 tie({isOpen:t,onClose:e,printerId:n,slotInfo:r,nozzleDiameter:a="0.4",printerModel:s,onSuccess:o,fullScreen:l}){const{t:c}=Dt(),[u,d]=w.useState(""),[m,p]=w.useState(null),[f,y]=w.useState(""),[v,b]=w.useState(""),[g,_]=w.useState(""),[N,C]=w.useState(!1),[k,P]=w.useState(!1),T=w.useRef(""),{data:D,isLoading:A,isError:R}=nt({queryKey:["cloudSettings"],queryFn:()=>ge.getCloudSettings(),enabled:t,retry:!1}),{data:B,isLoading:z}=nt({queryKey:["localPresets"],queryFn:()=>ge.getLocalPresets(),enabled:t}),{data:W,isLoading:I}=nt({queryKey:["builtinFilaments"],queryFn:()=>ge.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:ee,isLoading:ie}=nt({queryKey:["kprofiles",n,a],queryFn:()=>ge.getKProfiles(n,a),enabled:t&&!!n}),{data:Z}=nt({queryKey:["colorCatalog"],queryFn:()=>ge.getColorCatalog(),enabled:t,staleTime:1/0}),ue=gt({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(Fe=>Fe.id===K):null,O=U?W?.find(Fe=>Fe.filament_id===$):null,q=!E&&!U?D?.filament.find(Fe=>Fe.setting_id===u):null;if(!E&&!U&&!q)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 J=E?ne.name:U?O.name:q.name,G=hW(J),re=m?.slot_id??-1,ce=f||r.trayColor?.slice(0,6)||"FFFFFF",be=J.replace(/@.+$/,"").trim();let xe,ae;const L=G.material.toUpperCase();if(E){const Fe=(Qv.includes(L)?L:ne?.filament_type||G.material||"").toUpperCase(),He={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=He[Fe]||He[Fe.replace(/[-\s]?CF$/,"")]||He[Fe.replace(/\+$/,"")]||He[Fe.split(/[-\s]/)[0]]||"",ae=""}else if(U)xe=$,ae="";else if(xe=M1(u),ae=u,!u.startsWith("GFS"))try{const Fe=await ge.getCloudSettingDetail(u);Fe.filament_id?xe=Fe.filament_id:Fe.base_id&&(xe=M1(Fe.base_id),console.log(`Derived tray_info_idx from base_id: ${Fe.base_id} -> ${xe}`))}catch(Fe){console.warn("Failed to fetch preset detail for filament_id:",Fe)}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 Fe=(E?Qv.includes(L)?L:ne?.filament_type||G.material||"":G.material).toUpperCase();Fe.includes("PLA")?(F=190,te=230):Fe.includes("PETG")?(F=220,te=260):Fe.includes("ABS")||Fe.includes("ASA")?(F=240,te=280):Fe.includes("TPU")?(F=200,te=240):Fe==="PCTG"?(F=220,te=260):Fe.includes("PC")?(F=260,te=300):(Fe.includes("PA")||Fe.includes("NYLON"))&&(F=250,te=290)}const ve=m?.k_value?parseFloat(m.k_value):0,pe=E?Qv.includes(L)?L:ne?.filament_type||G.material||"PLA":G.material||"PLA",de=await ge.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:xe,tray_type:pe,tray_sub_brands:be,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}),je=E?`local_${K}`:U?`builtin_${$}`:u,we=E?"local":U?"builtin":"cloud";try{await ge.saveSlotPreset(n,r.amsId,r.trayId,je,be,we)}catch(Fe){console.warn("Failed to save slot preset mapping:",Fe)}return de},onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),me=gt({mutationFn:async()=>ge.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),he=w.useMemo(()=>{const E=g.toLowerCase(),U=[],K=new Set,$=r.savedPresetId,ne=r.trayInfoIdx;if(D?.filament)for(const O of D.filament){K.add(O.setting_id);const J=$===O.setting_id||ne&&(O.setting_id===ne||M1(O.setting_id)===ne);if(!(E&&!O.name.toLowerCase().includes(E))){if(!J&&s){const G=Dqe(O.name);if(G&&G.toUpperCase()!==s.toUpperCase())continue}U.push({id:O.setting_id,name:O.name,source:"cloud",isUser:Eqe(O.setting_id)})}}if(B?.filament)for(const O of B.filament){const q=`local_${O.id}`;E&&!O.name.toLowerCase().includes(E)||U.push({id:q,name:O.name,source:"local",isUser:!1})}if(W)for(const O of W){if(K.has(O.filament_id))continue;const q=O.filament_id.startsWith("GF")?"GFS"+O.filament_id.slice(2):O.filament_id;K.has(q)||(!E||O.name.toLowerCase().includes(E))&&U.push({id:`builtin_${O.filament_id}`,name:O.name,source:"builtin",isUser:!1})}return U.sort((O,q)=>{const J={cloud:0,local:1,builtin:2};return O.source!==q.source?J[O.source]-J[q.source]:O.isUser&&!q.isUser?-1:!O.isUser&&q.isUser?1:O.name.localeCompare(q.name)})},[D?.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 D?.filament&&(E=D.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=hW(U);return{fullName:U,material:K.material,brand:K.brand}},[u,D?.filament,B?.filament,W]),se=Y?.fullName||"",le=w.useMemo(()=>{if(!Z||!Y)return[];const{fullName:E,brand:U}=Y,K=E.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return Z.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 J=U.toUpperCase();if(!O.includes(J)&&!J.includes(O))return!1}return!0})},[Z,Y]),fe=w.useMemo(()=>{if(!ee?.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 q=ee.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 be={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[ne]||[];for(const xe of be)if(re.includes(xe))return!0;return!1}),J=new Map;for(const G of q){const re=`${G.name}|${G.k_value}`,ce=J.get(re);ce?r.extruderId!==void 0&&G.extruder_id===r.extruderId&&ce.extruder_id!==r.extruderId&&J.set(re,G):J.set(re,G)}return Array.from(J.values())},[ee?.profiles,Y,r.extruderId]);w.useEffect(()=>{if(t){if(r.savedPresetId)d(r.savedPresetId);else if(r.trayInfoIdx&&D?.filament){let E=D.filament.find(U=>U.setting_id===r.trayInfoIdx);E||(E=D.filament.find(U=>M1(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(""),_(""),C(!1),T.current=""},[t,r.savedPresetId,r.trayInfoIdx,r.trayColor,D?.filament,W]),w.useEffect(()=>{if(fe.length>0){if(r.caliIdx!=null&&r.caliIdx>0){const E=fe.find(U=>U.slot_id===r.caliIdx);if(E){p(E);return}}p(fe[0])}else p(null)},[u,fe,r.caliIdx]);const Te=w.useCallback(E=>{E.key==="Escape"&&e()},[e]);w.useEffect(()=>{if(t)return document.addEventListener("keydown",Te),()=>document.removeEventListener("keydown",Te)},[t,Te]);const V=A&&!R||z||I||ie;if(w.useEffect(()=>{if(!V&&u&&u!==T.current){const E=requestAnimationFrame(()=>{const K=document.querySelector('[class*="fixed inset-0 z-50"]')?.querySelector(`[data-preset-id="${CSS.escape(u)}"]`);K&&(T.current=u,K.scrollIntoView({block:"nearest"}))});return()=>cancelAnimationFrame(E)}},[u,V]),!t)return null;const X=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(Bd,{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:mW(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(Bt,{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(wc,{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:mW(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&i.jsxs("span",{className:"text-bambu-gray",children:["(",r.traySubBrands,")"]})]})]}),V?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(ft,{className:"w-6 h-6 text-bambu-green animate-spin"})}):l?i.jsxs("div",{className:"flex gap-4 h-full",children:[i.jsxs("div",{className:"w-1/2 flex flex-col min-h-0",children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:g,onChange: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:he.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:D?.filament?.length===0&&!B?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):he.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})})]}),fe.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:E=>{const U=fe.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")}),fe.map(E=>i.jsxs("option",{value:E.name,children:[E.name," (K=",E.k_value,")"]},`${E.name}-${E.extruder_id}`))]}),i.jsx(In,{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")}),le.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:le.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:[pW.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(!k),className:"w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs",title:c(k?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:k?"−":"+"})]}),k&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:fW.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=gW(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:he.length===0?i.jsx("p",{className:"text-center py-4 text-bambu-gray",children:D?.filament?.length===0&&!B?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):he.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})})]}),fe.length>0?i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:m?.name||"",onChange:E=>{const U=fe.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")}),fe.map(E=>i.jsxs("option",{value:E.name,children:[E.name," (K=",E.k_value,")"]},`${E.name}-${E.extruder_id}`))]}),i.jsx(In,{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")}),le.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:le.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:[pW.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(!k),className:"w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs",title:c(k?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:k?"−":"+"})]}),k&&i.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:fW.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=gW(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(ze,{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(ft,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.resetting")]}):i.jsxs(i.Fragment,{children:[i.jsx(Co,{className:"w-4 h-4"}),c("configureAmsSlot.resetSlot")]})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(ze,{variant:"secondary",onClick:e,children:c("configureAmsSlot.cancel")}),i.jsx(ze,{onClick:()=>ue.mutate(),disabled:!X,children:ue.isPending?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.configuring")]}):i.jsxs(i.Fragment,{children:[i.jsx(Bd,{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 nie({folderId:t,onClose:e,onUploadComplete:n,onFileUploaded:r,autoUpload:a,validateFile:s,accept:o}){const{t:l}=Dt(),[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),[C,k]=w.useState(null),P=w.useRef(null),T=he=>{he.preventDefault(),m(!0)},D=he=>{he.preventDefault(),m(!1)},A=he=>{he.preventDefault(),m(!1),W(Array.from(he.dataTransfer.files))},R=he=>{he.target.files&&W(Array.from(he.target.files))},B=(he,Y)=>{u(se=>se.map(le=>le.file===he?{...le,...Y}:le))},z=async he=>{f(!0);for(const Y of he)if(Y.status==="pending"){B(Y.file,{status:"uploading"});try{if(Y.isZip){const se=await ge.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 ge.uploadLibraryFile(Y.file,t,_);B(Y.file,{status:"success"});const le=r?.(se);if(le){k(le),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=he=>{if(k(null),s)for(const se of he){const le=s(se);if(le){k(le);return}}const Y=he.map(se=>({file:se,status:"pending",isZip:se.name.toLowerCase().endsWith(".zip"),is3mf:se.name.toLowerCase().endsWith(".3mf")}));u(se=>[...se,...Y]),a&&he.length>0&&z(Y)},I=he=>{u(Y=>Y.filter((se,le)=>le!==he))},ee=c.some(he=>he.isZip&&he.status==="pending"),ie=c.some(he=>he.file.name.toLowerCase().endsWith(".stl")&&he.status==="pending"),Z=c.some(he=>he.is3mf&&he.status==="pending"),ue=c.filter(he=>he.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(Bt,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsxs("div",{onDragOver:T,onDragLeave:D,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:R}),ee&&i.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Vs,{className:"w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-blue-300 font-medium",children:l("fileManager.zipFilesDetected")}),i.jsx("p",{className:"text-xs text-blue-300/70 mt-1",children:l("fileManager.zipExtractOptions")}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:y,onChange:he=>v(he.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.preserveZipStructure")})]}),i.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:b,onChange:he=>g(he.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.createFolderFromZip")})]})]})]})}),Z&&i.jsx("div",{className:"p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(_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||ee)&&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(Ud,{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(ee&&!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:he=>N(he.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:l("fileManager.generateThumbnailsForStl")})]})]})]})}),c.length>0&&i.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:c.map((he,Y)=>i.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[he.isZip?i.jsx(Vs,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):i.jsx(tT,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-sm text-white truncate",children:he.file.name}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[(he.file.size/1024/1024).toFixed(2)," MB",he.isZip&&he.status==="pending"&&i.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",l("fileManager.willBeExtracted")]}),he.extractedCount!==void 0&&i.jsxs("span",{className:"text-green-400 ml-2",children:["• ",l("fileManager.filesExtracted",{count:he.extractedCount})]})]})]}),he.status==="pending"&&i.jsx("button",{onClick:()=>I(Y),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(Bt,{className:"w-4 h-4 text-bambu-gray"})}),he.status==="uploading"&&i.jsx(ft,{className:"w-4 h-4 text-bambu-green animate-spin"}),he.status==="success"&&i.jsx(pr,{className:"w-4 h-4 text-green-500"}),he.status==="error"&&i.jsx("span",{title:he.error,children:i.jsx(Vi,{className:"w-4 h-4 text-red-500"})})]},Y))}),C&&i.jsx("div",{className:"p-3 bg-red-500/10 border border-red-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Vi,{className:"w-5 h-5 text-red-400 mt-0.5 flex-shrink-0"}),i.jsx("p",{className:"text-sm text-red-300",children:C})]})})]}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2",children:[i.jsx(ze,{variant:"secondary",onClick:e,children:l("common.cancel")}),!me&&i.jsx(ze,{onClick:()=>z(c),disabled:ue===0||p,children:p?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-4 h-4 mr-2 animate-spin"}),l("fileManager.uploading")]}):i.jsxs(i.Fragment,{children:[i.jsx(vi,{className:"w-4 h-4 mr-2"}),l("common.upload")," ",ue>0?`(${ue})`:""]})})]})]})})}function bW(t){return t?`#${t.replace("#","").substring(0,6)}`:"#808080"}function Fi(t){return t?t.replace("#","").toLowerCase().substring(0,6):""}const Rqe=[["PA-CF","PA12-CF","PAHT-CF"]],rie={};for(const t of Rqe){const e=t[0];for(const n of t)rie[n.toUpperCase()]=e.toUpperCase()}function eC(t){if(!t)return"";const e=t.toUpperCase();return rie[e]??e}function X2(t,e){return eC(t)===eC(e)}function bu(t,e,n=40){const r=Fi(t),a=Fi(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 F4(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 X0(t,e,n){return n?254+e:t>=128?t:t*4+e}function xW(t){if(!t)return!1;const e=Date.now()+4320*60*60*1e3;return(Qn(t)?.getTime()??0)>e}function Fqe(t,e,n){const r=iie(e,t.nozzle_id),a=r.find(l=>!n.has(l.globalTrayId)&&X2(l.type,t.type)&&Fi(l.color)===Fi(t.color)),s=a?void 0:r.find(l=>!n.has(l.globalTrayId)&&X2(l.type,t.type)&&bu(l.color,t.color)),o=a||s?void 0:r.find(l=>!n.has(l.globalTrayId)&&X2(l.type,t.type));return a??s??o}function iie(t,e){return t.filter(n=>e==null||n.extruderId===e)}function Kw(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=bW(o.tray_color);e.push({type:o.tray_type,color:l,colorName:Ld(l),amsId:a.id,trayId:o.id,isHt:s,isExternal:!1,label:F4(a.id,o.id,s,!1),globalTrayId:X0(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=bW(a.tray_color),o=a.id??254,l=(t?.vt_tray?.length??0)>1;e.push({type:a.tray_type,color:s,colorName:Ld(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 yW(t,e){if(!t?.filaments||t.filaments.length===0)return;const n=Kw(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()&&Fi(b.color)===Fi(l.color)),m||(p=v.find(b=>b.type?.toUpperCase()===l.type?.toUpperCase()&&bu(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()&&Fi(v.color)===Fi(l.color)),m||(p=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&bu(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 Lqe(t){return w.useMemo(()=>Kw(t),[t])}function aie(t,e,n){const r=Lqe(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],T=r.find(D=>D.globalTrayId===P);if(T){const D=T.type?.toUpperCase()===u.type?.toUpperCase(),A=Fi(T.color)===Fi(u.color)||bu(T.color,u.color);let R;return D&&A?R="match":D?R="type_only":R="mismatch",{...u,loaded:T,hasFilament:!0,typeMatch:D,colorMatch:A,status:R,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(T=>T.trayInfoIdx===m);P.length===1?f=P[0]:P.length>1&&(y=P.find(T=>T.type?.toUpperCase()===u.type?.toUpperCase()&&Fi(T.color)===Fi(u.color)),y||(v=P.find(T=>T.type?.toUpperCase()===u.type?.toUpperCase()&&bu(T.color,u.color))),!y&&!v&&(b=P.find(T=>T.type?.toUpperCase()===u.type?.toUpperCase())))}!f&&!y&&!v&&!b&&(y=p.find(P=>P.type?.toUpperCase()===u.type?.toUpperCase()&&Fi(P.color)===Fi(u.color)),y||(v=p.find(P=>P.type?.toUpperCase()===u.type?.toUpperCase()&&bu(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=_,C=!!f||!!y||!!v;let k;return f||y||v?k="match":b?k="type_only":k="mismatch",{...u,loaded:g,hasFilament:_,typeMatch:N,colorMatch:C,status:k,isManual:!1}})},[t,r,n]),s=w.useMemo(()=>{if(a.length===0)return;const c=Math.max(...a.map(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 Oqe(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=Fi(g.color)===Fi(u.color)||bu(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()&&Fi(b.color)===Fi(u.color)),f=p?void 0:m.find(b=>b.type?.toUpperCase()===u.type?.toUpperCase()&&bu(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 Iqe(t,e,n){if(!t?.filaments||t.filaments.length===0)return;const r=Kw(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()&&Fi(v.color)===Fi(c.color)),p=m?void 0:d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&bu(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 vW={useDefault:!0,manualMappings:{},autoConfigured:!1};function zqe(t,e,n,r,a,s){const o=eg({queries:t.map(y=>({queryKey:["printer-status",y],queryFn:()=>ge.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(R=>R.id===y)?.name||`Printer ${y}`,C=Kw(g),k=a[y]||vW,P=yW(n,g),T=k.useDefault?r:k.manualMappings,D=Iqe(n,g,T),A=Oqe(n?.filaments,C,T);return{printerId:y,printerName:N,status:g,isLoading:b?.isLoading??!1,loadedFilaments:C,autoMapping:P,finalMapping:D,matchStatus:A.status,exactMatches:A.exactMatches,typeOnlyMatches:A.typeOnlyMatches,missingTypes:A.missingTypes,totalSlots:A.totalSlots,config:k}}),[t,o,e,n,a,r]),c=o.some(y=>y.isLoading),u=(y,v)=>{s(b=>({...b,[y]:{...b[y]||vW,...v}}))},d=y=>{const v=l.find(_=>_.printerId===y);if(!v||!v.status||!n?.filaments)return;const b=yW(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 sie={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 Wo(t){return sie[t.toUpperCase()]||t}const Uqe=Object.entries(sie).map(([t,e])=>({code:t,label:`${t} (${e})`}));function Bqe({printerId:t,filamentReqs:e,manualMappings:n,onManualMappingChange:r,currencySymbol:a,defaultCostPerKg:s,defaultExpanded:o=!1}){const{t:l}=Dt(),c=on(),[u,d]=w.useState(!1),[m,p]=w.useState(o),{data:f}=nt({queryKey:["printer-status",t],queryFn:()=>ge.getPrinterStatus(t),enabled:!!t}),{data:y}=nt({queryKey:["spool-assignments",t],queryFn:()=>ge.getAssignments(t),enabled:!!t}),{loadedFilaments:v,filamentComparison:b,hasTypeMismatch:g,hasColorMismatch:_}=aie(e,f,n),N=w.useMemo(()=>{const z=new Map;for(const W of y||[]){const I=W.ams_id===255,ee=X0(W.ams_id,W.tray_id,I);z.set(ee,W.spool?.cost_per_kg??null)}return z},[y]),C=w.useMemo(()=>{const z=new Map;for(const W of y||[]){const I=W.ams_id===255,ee=X0(W.ams_id,W.tray_id,I),ie=W.spool;if(!ie){z.set(ee,null);continue}z.set(ee,Math.max(0,Math.round((ie.label_weight??0)-(ie.weight_used??0))))}return z},[y]),k=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]),T=e?.filaments&&e.filaments.length>0,D=e?.filaments?.some(z=>z.nozzle_id!=null)??!1;if(!T||!f)return null;const A=g?"#f97316":_?"#facc15":"#00ae42",R=(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 ge.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(y0,{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(Vl,{className:"w-4 h-4 ml-auto"}):i.jsx(In,{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} - ${Ld(z.color)}`,children:i.jsx(y0,{className:"w-3 h-3",fill:z.color,stroke:z.color})}),i.jsxs("span",{className:"text-white truncate flex items-center gap-1",children:[D&&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=>R(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 ee=C.get(I.globalTrayId),ie=ee!=null?l("printModal.slotRemainingShort",{grams:ee,defaultValue:` - ${ee}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(Zr,{className:"w-3 h-3 text-bambu-green"}):z.status==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(jn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(jn,{className:"w-3 h-3 text-orange-400"})})]},W)),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[l("printModal.totalCost")," ",i.jsx("span",{className:"text-white",children:k>0||P?`${a}${k.toFixed(2)}`:"N/A"})]}),g&&i.jsx("p",{className:"text-xs text-orange-400 mt-2",children:"Required filament type not found in printer."})]})]})}function Hqe({filamentReqs:t,availableFilaments:e,overrides:n,onChange:r,forceColorMatch:a,onForceColorMatchChange:s}){const{t:o}=Dt(),l=w.useMemo(()=>{const d={};for(const m of e){const p=eC(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[eC(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} - ${Ld(d.color)}`,children:i.jsx(y0,{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," (",Ld(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," (",Ld(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(Co,{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(vw,{className:"w-3 h-3"}),o("printModal.forceColorMatch")]})]},d.slot_id)})})]})}function $qe({plates:t,isMultiPlate:e,selectedPlate:n,onSelect:r,queueAll:a,onQueueAllChange:s}){const{t:o}=Dt();return!e||t.length<=1?null:i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx(Gi,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:"Select Plate to Print"}),!n&&!a&&i.jsxs("span",{className:"text-xs text-orange-400 flex items-center gap-1",children:[i.jsx(jn,{className:"w-3 h-3"}),"Selection required"]}),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(Gi,{className:"w-5 h-5 text-bambu-gray"})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-sm text-white font-medium truncate",children: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?` • ${Us(l.print_time_seconds)}`:""]})]}),(a||n===l.index)&&i.jsx(Zr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]},l.index))})]})}const qqe=new Set(["IDLE","FINISH","FAILED"]);function Vqe({printerResult:t,filamentReqs:e,onUpdateConfig:n}){const r=on(),[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 ge.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=Fqe(u,t.loadedFilaments,v)}let y="mismatch";if(p){const v=p.type?.toUpperCase()===u.type?.toUpperCase(),b=Fi(p.color)===Fi(u.color)||bu(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} - ${Ld(u.color)}`,children:i.jsx(y0,{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 --"}),iie(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(Zr,{className:"w-3 h-3 text-bambu-green"}):m==="type_only"?i.jsx("span",{title:"Same type, different color",children:i.jsx(jn,{className:"w-3 h-3 text-yellow-400"})}):i.jsx("span",{title:"Filament type not loaded",children:i.jsx(jn,{className:"w-3 h-3 text-orange-400"})})]},f))]})}function Gqe({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),C=s?t:t.filter(se=>se.is_active),k=eg({queries:C.map(se=>({queryKey:["printerStatus",se.id],queryFn:()=>ge.getPrinterStatus(se.id),staleTime:5e3}))}),P=w.useMemo(()=>{const se=new Map;return C.forEach((le,fe)=>{const Te=k[fe];Te?.data&&se.set(le.id,Te.data)}),se},[C,k]),T=se=>{const le=P.get(se);return le?le.connected?!qqe.has(le.state??""):!0:!1},D=se=>{const le=P.get(se);if(!le)return null;if(!le.connected)return"Offline";const fe=le.state;return fe?fe==="RUNNING"?le.stg_cur_name||"Printing":fe==="PREPARE"?"Preparing":fe==="PAUSE"?"Paused":fe==="IDLE"?"Idle":fe==="FINISH"?"Finished":fe==="FAILED"?"Failed":fe:null},A=w.useMemo(()=>{if(m!=="printer"||!g||_)return C;const se=C.filter(le=>le.model===g);return se.length>0?se:C},[C,m,g,_]),R=C.length-A.length,B=w.useMemo(()=>{const se=C.map(le=>le.model).filter(le=>!!le);return[...new Set(se)].sort()},[C]),z=w.useMemo(()=>{if(!f)return[];const se=C.filter(le=>le.model===f&&le.location).map(le=>le.location).filter(le=>!!le);return[...new Set(se)].sort()},[C,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(ft,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(A.length===0)return i.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm mb-4",children:[i.jsx(Oi,{className:"w-4 h-4"}),"No ",s?"":"active ","printers available"]});const ee=se=>{o&&T(se)||(a?e.includes(se)?n(e.filter(le=>le!==se)):n([...e,se]):n([se]))},ie=()=>{const se=o?A.filter(le=>!T(le.id)):A;n(se.map(le=>le.id))},Z=()=>{n([])},ue=(se,le,fe)=>{fe.stopPropagation(),!(!u||!d)&&(le?u(se):d(se,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},me=se=>e.includes(se),he=e.length,Y=se=>l?.find(le=>le.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(ih,{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:he===0?"Select printers":`${he} printer${he!==1?"s":""} selected`}),i.jsxs("div",{className:"flex gap-2",children:[he0&&i.jsx("button",{type:"button",onClick:Z,className:"text-bambu-gray hover:text-white transition-colors",children:"Clear"})]})]}),m==="printer"&&A.map(se=>{const le=me(se.id),fe=Y(se.id),Te=fe&&!fe.config.useDefault,V=T(se.id),X=o&&V,j=D(se.id);return i.jsxs("div",{children:[i.jsxs("button",{type:"button",onClick:()=>ee(se.id),disabled:X,className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${X?"border-bambu-dark-tertiary bg-bambu-dark opacity-50 cursor-not-allowed":le?"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 ${X?"bg-bambu-dark-tertiary":le?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:i.jsx(_r,{className:`w-5 h-5 ${X?"text-bambu-gray/50":le?"text-bambu-green":"text-bambu-gray"}`})}),i.jsxs("div",{className:"text-left flex-1",children:[i.jsxs("p",{className:`font-medium ${X?"text-bambu-gray":"text-white"}`,children:[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 ${V?"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 ${X?"border-bambu-gray/30":le?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:le&&i.jsx(Zr,{className:"w-3 h-3 text-white"})})]}),le&&I&&fe&&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:Te,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 ${fe.matchStatus==="full"?"text-bambu-green":fe.matchStatus==="partial"?"text-yellow-400":"text-orange-400"}`,children:["(",fe.exactMatches,"/",fe.totalSlots," matched)"]}),fe.isLoading&&i.jsx(Sr,{className:"w-3 h-3 text-bambu-gray animate-spin"}),Te&&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(Rbe,{className:"w-3 h-3"}),"Auto"]})]}),Te&&i.jsx(Vqe,{printerResult:fe,filamentReqs:c.filaments,onUpdateConfig:E=>d(se.id,E)})]})]},se.id)}),m==="printer"&&R>0&&!_&&i.jsxs("button",{type:"button",onClick:()=>N(!0),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2 flex items-center gap-1",children:[i.jsx(jn,{className:"w-3 h-3 text-yellow-400"}),R," other printer",R>1?"s":""," hidden (different model) —",i.jsx("span",{className:"underline",children:"show all"})]}),m==="printer"&&_&&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"&&he===0&&i.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[i.jsx(Oi,{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(Oi,{className:"w-3 h-3"}),"Select a target printer model"]})]})}const Wqe=[{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 Kqe({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(lT,{className:"w-4 h-4"}),i.jsx("span",{children:"Print Options"}),r?i.jsx(Vl,{className:"w-4 h-4 ml-auto"}):i.jsx(In,{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:Wqe.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 Yqe({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 k;t.scheduledTime?(k=new Date(t.scheduledTime),isNaN(k.getTime())&&(k=new Date,k.setHours(k.getHours()+1,0,0,0))):(k=new Date,k.setHours(k.getHours()+1,0,0,0),e({...t,scheduledTime:P3(k)})),o(A3(k,n)),c(n6(k,r)),d(!0),p(!0)}},[t.scheduleType,t.scheduledTime,n,r,e,t]);const v=k=>{e({...t,scheduleType:k})},b=(k,P)=>{const T=rxe(k,n),D=ixe(P);d(!!T),p(!!D),T&&D&&(T.setHours(D.hours,D.minutes,0,0),T>new Date&&e({...t,scheduledTime:P3(T)}))},g=k=>{o(k),b(k,l)},_=k=>{c(k),b(s,k)},N=k=>{const P=k.target.value;if(P){const T=new Date(P);isNaN(T.getTime())||(o(A3(T,n)),c(n6(T,r)),d(!0),p(!0),e({...t,scheduledTime:P}))}},C=()=>{f.current?.showPicker()};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"When to print"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="asap"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("asap"),children:[i.jsx(Zn,{className:"w-4 h-4"}),"ASAP"]}),i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="scheduled"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("scheduled"),children:[i.jsx(Xr,{className:"w-4 h-4"}),"Scheduled"]}),i.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="manual"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>v("manual"),children:[i.jsx(QX,{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:k=>g(k.target.value),placeholder:exe(n)}),i.jsx("button",{type:"button",onClick:C,className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",title:"Open calendar",children:i.jsx(Xr,{className:"w-4 h-4"})})]}),i.jsx("div",{className:"w-32",children:i.jsx("input",{type:"text",className:`w-full px-3 py-2 bg-bambu-dark border rounded-lg text-white focus:outline-none ${m?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:l,onChange:k=>_(k.target.value),placeholder:txe(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:k=>e({...t,requirePreviousSuccess:k.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("label",{htmlFor:"requirePrevious",className:"text-sm text-bambu-gray",children:"Only start if previous print succeeded"})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"checkbox",id:"autoOffAfter",checked:t.autoOffAfter,onChange:k=>e({...t,autoOffAfter:k.target.checked}),disabled:!a,className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green disabled:opacity-50"}),i.jsxs("label",{htmlFor:"autoOffAfter",className:`text-sm flex items-center gap-1 ${a?"text-bambu-gray":"text-bambu-gray/50"}`,children:[i.jsx(em,{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 _b={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1},Xqe={scheduleType:"asap",scheduledTime:"",requirePreviousSuccess:!1,autoOffAfter:!1};function xu({mode:t,archiveId:e,libraryFileId:n,archiveName:r,queueItem:a,initialSelectedPrinterIds:s,onClose:o,onSuccess:l}){const{t:c}=Dt(),u=on(),{showToast:d}=gn(),{hasPermission:m}=Ar(),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,C]=w.useState(()=>t==="edit-queue-item"&&a?{bed_levelling:a.bed_levelling??_b.bed_levelling,flow_cali:a.flow_cali??_b.flow_cali,vibration_cali:a.vibration_cali??_b.vibration_cali,layer_inspect:a.layer_inspect??_b.layer_inspect,timelapse:a.timelapse??_b.timelapse}:_b),[k,P]=w.useState(()=>{if(t==="edit-queue-item"&&a){let rt="asap";a.manual_start?rt="manual":a.scheduled_time&&!xW(a.scheduled_time)&&(rt="scheduled");let At="";if(a.scheduled_time&&!xW(a.scheduled_time)){const $t=Qn(a.scheduled_time)??new Date;At=P3($t)}return{scheduleType:rt,scheduledTime:At,requirePreviousSuccess:a.require_previous_success,autoOffAfter:a.auto_off_after}}return Xqe}),[T,D]=w.useState(()=>{if(t==="edit-queue-item"&&a?.ams_mapping&&Array.isArray(a.ams_mapping)){const rt={};return a.ams_mapping.forEach((At,$t)=>{At!==-1&&(rt[$t+1]=At)}),rt}return{}}),[A,R]=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),[ee,ie]=w.useState(()=>t==="edit-queue-item"&&a?.target_location?a.target_location:null),[Z,ue]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const rt={};for(const At of a.filament_overrides)rt[At.slot_id]={type:At.type,color:At.color};return rt}return{}}),[me,he]=w.useState(()=>{if(t==="edit-queue-item"&&a?.filament_overrides){const rt={};for(const At of a.filament_overrides)rt[At.slot_id]=At.force_color_match===!0;return rt}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),[le,fe]=w.useState(!1),[Te,V]=w.useState({current:0,total:0}),[X,j]=w.useState(null),[E,U]=w.useState(new Set),K=f.length,$=f.length>0?f[0]:null,{data:ne}=nt({queryKey:["settings"],queryFn:ge.getSettings}),O=Wo(ne?.currency||"USD"),q=ne?.default_filament_cost??0,{data:J,isLoading:G}=nt({queryKey:["printers"],queryFn:ge.getPrinters}),{data:re}=nt({queryKey:["spool-assignments"],queryFn:()=>ge.getAssignments(),staleTime:30*1e3,enabled:(t==="reprint"||t==="add-to-queue")&&B==="printer"||p&&t==="reprint"}),{data:ce}=nt({queryKey:["archive",e],queryFn:()=>ge.getArchive(e),enabled:!!e&&!p}),{data:be}=nt({queryKey:["library-file",n],queryFn:()=>ge.getLibraryFile(n),enabled:p&&!!n}),xe=ce?.sliced_for_model||be?.sliced_for_model||null,{data:ae,isError:L}=nt({queryKey:["archive-plates",e],queryFn:()=>ge.getArchivePlates(e),enabled:!!e&&!p,retry:!1}),{data:F}=nt({queryKey:["library-file-plates",n],queryFn:()=>ge.getLibraryFilePlates(n),enabled:p&&!!n}),te=p?F:ae,{data:ve,isError:pe}=nt({queryKey:["archive-filaments",e,v],queryFn:()=>ge.getArchiveFilamentRequirements(e,v??void 0),enabled:!!e&&!p&&(v!==null||!te?.is_multi_plate),retry:!1}),{data:de}=nt({queryKey:["library-file-filaments",n,v],queryFn:()=>ge.getLibraryFileFilamentRequirements(n,v??void 0),enabled:p&&!!n&&(v!==null||!te?.is_multi_plate)}),je=!p&&(L||pe),we=p?de:ve,Fe=w.useMemo(()=>{if(!(v===null||!te?.plates?.length))return te.plates.find(rt=>rt.index===v)?.name||void 0},[te,v]),{data:He}=nt({queryKey:["available-filaments",W,ee],queryFn:()=>ge.getAvailableFilaments(W,ee??void 0),enabled:B==="model"&&!!W}),{data:Ie}=nt({queryKey:["printer-status",$],queryFn:()=>ge.getPrinterStatus($),enabled:!!$}),{amsMapping:Ne}=aie(we,Ie,T),Ae=zqe(f,J,we,T,A,R);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 rt=J?.filter(At=>At.is_active)||[];rt.length===1&&f.length===0&&y([rt[0].id])},[t,J,f.length]),w.useEffect(()=>{t==="edit-queue-item"?(JSON.stringify(f.sort())!==JSON.stringify(Y.sort())||v!==se)&&(D({}),R({}),U(new Set)):(D({}),R({}),U(new Set))},[t,f,v,Y,se]);const[Be,Ee]=w.useState(W),[Xe,ye]=w.useState(v);w.useEffect(()=>{(W!==Be||v!==Xe)&&(Ee(W),ye(v),(t!=="edit-queue-item"||Be!==null)&&(ue({}),he({})))},[W,v,Be,Xe,t]),w.useEffect(()=>{if(!ne?.per_printer_mapping_expanded||f.length<=1)return;const rt=f.filter(At=>{if(E.has(At))return!1;const $t=Ae.printerResults.find(rn=>rn.printerId===At);return $t&&$t.status&&!$t.isLoading});rt.length>0&&(U(At=>{const $t=new Set(At);return rt.forEach(rn=>$t.add(rn)),$t}),rt.forEach(At=>{Ae.autoConfigurePrinter(At)}))},[ne?.per_printer_mapping_expanded,f,E,Ae]),w.useEffect(()=>{const rt=At=>{At.key==="Escape"&&!le&&o()};return window.addEventListener("keydown",rt),()=>window.removeEventListener("keydown",rt)},[o,le]);const We=te?.is_multi_plate??!1,Pe=te?.plates??[],Ke=w.useMemo(()=>{const rt=new Map;return re&&re.forEach(At=>{const $t=At.ams_id===255,rn=X0(At.ams_id,At.tray_id,$t),Vt=rt.get(At.printer_id)??new Map;Vt.set(rn,At),rt.set(At.printer_id,Vt)}),rt},[re]),Ve=w.useMemo(()=>{if(!X||X.length===0)return"";const rt=X.map(At=>c("printModal.insufficientFilamentLine",{printer:At.printerName,slot:At.slotLabel,required:Math.round(At.requiredGrams),remaining:Math.round(At.remainingGrams)}));return[c("printModal.insufficientFilamentMessage"),...rt].join(` `)},[X,c]),ke=gt({mutationFn:rt=>ge.addToQueue(rt)}),Ce=gt({mutationFn:rt=>ge.updateQueueItem(a.id,rt),onSuccess:()=>{u.invalidateQueries({queryKey:["queue"]}),d("Queue item updated"),l?.(),o()},onError:rt=>{d(rt.message||"Failed to update queue item","error")}}),$e=async(rt,At)=>{if(rt?.preventDefault(),!At?.skipFilamentCheck&&!ne?.disable_filament_warnings&&(t==="reprint"||t==="add-to-queue")&&B==="printer"){const Re=[],it=we?.filaments??[];if(it.length>0&&Ke.size>0){const dt=(Qe,Me)=>!Number.isFinite(Qe)||Qe<=0||!Number.isFinite(Me)||Me<0?null:Math.max(0,Qe-Me);for(const Qe of f){const Me=f.length>1?Ae.getFinalMapping(Qe):Ne;if(!Me)continue;const st=f.length>1?Ae.printerResults.find(Oe=>Oe.printerId===Qe)?.status:Ie,oe=Kw(st),Le=new Map(oe.map(Oe=>[Oe.globalTrayId,Oe.label])),Ye=Ke.get(Qe),Ge=J?.find(Oe=>Oe.id===Qe)?.name??`Printer ${Qe}`;Ye&&it.forEach(Oe=>{if(!Oe.slot_id||Oe.slot_id<=0)return;const ht=Me[Oe.slot_id-1];if(!Number.isFinite(ht)||ht<0)return;const Ze=Ye.get(ht)?.spool;if(!Ze)return;const Nt=dt(Ze.label_weight,Ze.weight_used);Nt!==null&&(Nt>=Oe.used_grams||Re.push({printerName:Ge,slotLabel:Le.get(ht)??`Slot ${Oe.slot_id}`,requiredGrams:Oe.used_grams,remainingGrams:Nt}))})}}if(Re.length>0){j(Re);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}fe(!0);const $t=g?Pe:[null],rn=B==="model"?$t.length:f.length*$t.length;V({current:0,total:rn});const Vt={success:0,failed:0,errors:[]},dn=Re=>{if(f.length>1){const it=A[Re];if(it&&!it.useDefault)return Ae.getFinalMapping(Re)}return Ne},Hn=(()=>{const Re=[];if(we?.filaments)for(const it of we.filaments){const dt=Z[it.slot_id],Qe=me[it.slot_id]??!1,Me=dt?.type??it.type,st=dt?.color??it.color;(dt||Qe)&&Re.push({slot_id:it.slot_id,type:Me,color:st,color_name:Ld(st),force_color_match:Qe})}else for(const[it,{type:dt,color:Qe}]of Object.entries(Z)){const Me=parseInt(it,10),st=me[Me]??!1;Re.push({slot_id:Me,type:dt,color:Qe,color_name:Ld(Qe),force_color_match:st})}return Re.length>0?Re:void 0})(),tt=(Re,it)=>({printer_id:B==="printer"?Re:null,target_model:B==="model"?W:null,target_location:B==="model"?ee:null,filament_overrides:B==="model"?Hn:void 0,archive_id:p?void 0:e,library_file_id:p?n:void 0,require_previous_success:k.requirePreviousSuccess,auto_off_after:k.autoOffAfter,manual_start:k.scheduleType==="manual",ams_mapping:Re?dn(Re):void 0,plate_id:it!==void 0?it:v,scheduled_time:k.scheduleType==="scheduled"&&k.scheduledTime?new Date(k.scheduledTime).toISOString():void 0,...N});if(B==="model"){if(t==="reprint"){d("Model-based assignment only works with queue mode","error"),fe(!1);return}let Re=0;for(const it of $t){Re++,V({current:Re,total:rn});const dt=it?it.index:v;try{if(t==="edit-queue-item"&&!it){const Qe={printer_id:null,target_model:W,target_location:ee,filament_overrides:Hn||null,require_previous_success:k.requirePreviousSuccess,auto_off_after:k.autoOffAfter,manual_start:k.scheduleType==="manual",ams_mapping:void 0,plate_id:dt,scheduled_time:k.scheduleType==="scheduled"&&k.scheduledTime?new Date(k.scheduledTime).toISOString():null,...N};await Ce.mutateAsync(Qe)}else await ke.mutateAsync(tt(null,dt));Vt.success++}catch(Qe){Vt.failed++;const Me=it?it.name||`Plate ${it.index}`:"";Vt.errors.push(Me?`${Me}: ${Qe.message}`:Qe.message)}}}else{let Re=0;for(const it of $t){const dt=it?it.index:v;for(let Qe=0;QeGe.id===Me)?.name||`Printer ${Me}`,Le=it?it.name||`Plate ${it.index}`:"",Ye=Le?`${oe} (${Le})`:oe;Vt.errors.push(`${Ye}: ${st.message}`)}}}}fe(!1),Vt.failed===0?(t!=="reprint"&&(t==="edit-queue-item"?d("Queue item updated"):Vt.success===1?d(B==="model"?`Queued for any ${W}`:c("queue.printQueued")):d(c("queue.itemsQueued",{count:Vt.success}))),u.invalidateQueries({queryKey:["queue"]}),l?.(),o()):Vt.success===0?d(`Failed: ${Vt.errors[0]}`,"error"):(d(`${Vt.success} succeeded, ${Vt.failed} failed`,"error"),u.invalidateQueries({queryKey:["queue"]}))},Je=le||Ce.isPending,bt=w.useMemo(()=>!(Je||B==="printer"&&f.length===0||B==="model"&&!W||B==="model"&&t==="reprint"||We&&!v&&!g),[f.length,B,W,t,We,v,g,Je]),ut=(()=>{const rt=f.length;if(t==="reprint")return{title:c(p?"queue.print":"queue.reprint"),icon:_r,submitText:rt>1?c("queue.printToPrinters",{count:rt}):c("queue.print"),submitIcon:_r,loadingText:Te.total>1?c("queue.sendingProgress",{current:Te.current,total:Te.total}):c("queue.sending")};if(t==="add-to-queue"){let At=c("queue.addToQueue");return g&&Pe.length>1?At=c("queue.queueAllPlates",{count:Pe.length}):rt>1&&(At=c("queue.queueToPrinters",{count:rt})),{title:c("queue.schedulePrint"),icon:Xr,submitText:At,submitIcon:Xr,loadingText:Te.total>1?c("queue.addingProgress",{current:Te.current,total:Te.total}):c("queue.adding")}}return{title:c("queue.editQueueItem"),icon:Yi,submitText:c("common.save"),submitIcon:Yi,loadingText:Te.total>1?c("queue.savingProgress",{current:Te.current,total:Te.total}):c("common.saving")}})(),qe=ut.icon,_t=ut.submitIcon,Ht=$&&!g&&(p||(We?v!==null:!0));return i.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:le?void 0:o,children:[i.jsx(Pt,{className:"w-full max-w-2xl max-h-[90vh] overflow-y-auto",onClick:rt=>rt.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:ut.title})]}),i.jsx(ze,{variant:"ghost",size:"sm",onClick:o,disabled:le,children:i.jsx(Bt,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:$e,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&&J?i.jsx("span",{className:"text-white",children:J.find(rt=>rt.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($qe,{plates:Pe,isMultiPlate:We,selectedPlate:v,onSelect:b,queueAll:g,onQueueAllChange:t==="add-to-queue"?_:void 0}),!s?.length&&i.jsx(Gqe,{printers:J||[],selectedPrinterIds:f,onMultiSelect:y,isLoading:G,allowMultiple:!0,showInactive:t==="edit-queue-item",disableBusy:t==="reprint",printerMappingResults:Ae.printerResults,filamentReqs:we,onAutoConfigurePrinter:Ae.autoConfigurePrinter,onUpdatePrinterConfig:Ae.updatePrinterConfig,assignmentMode:t==="reprint"?"printer":B,onAssignmentModeChange:t!=="reprint"?z:void 0,targetModel:W,onTargetModelChange:t!=="reprint"?I:void 0,targetLocation:ee,onTargetLocationChange:t!=="reprint"?ie:void 0,slicedForModel:xe}),B==="model"&&W&&we&&He&&He.length>0&&i.jsx(Hqe,{filamentReqs:we,availableFilaments:He,overrides:Z,onChange:ue,forceColorMatch:me,onForceColorMatchChange:(rt,At)=>he($t=>({...$t,[rt]:At}))}),xe&&B==="printer"&&f.length===1&&(()=>{const rt=J?.find(At=>At.id===f[0]);return rt&&rt.model&&xe!==rt.model?i.jsxs("div",{className:"p-3 mb-2 bg-yellow-500/10 border border-yellow-500/30 rounded-lg flex items-center gap-2",children:[i.jsx(jn,{className:"w-4 h-4 text-yellow-400 flex-shrink-0"}),i.jsxs("span",{className:"text-sm text-yellow-400",children:["File was sliced for ",xe,", but printing on ",rt.model]})]}):null})(),je&&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(Oi,{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."})]}),Ht&&!je&&f.length===1&&i.jsx(Bqe,{printerId:$,filamentReqs:we,manualMappings:T,onManualMappingChange:D,defaultExpanded:!!s?.length||(ne?.per_printer_mapping_expanded??!1),currencySymbol:O,defaultCostPerKg:q}),(t==="reprint"||K>0||B==="model"&&W)&&i.jsx(Kqe,{options:N,onChange:C,defaultExpanded:!!s?.length}),t!=="reprint"&&i.jsx(Yqe,{options:k,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(ze,{type:"button",variant:"secondary",onClick:o,className:"flex-1",disabled:le,children:"Cancel"}),i.jsx(ze,{type:"submit",disabled:!bt,className:"flex-1",children:Je?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-4 h-4 animate-spin"}),ut.loadingText]}):i.jsxs(i.Fragment,{children:[i.jsx(_t,{className:"w-4 h-4"}),ut.submitText]})})]})]})]})}),X&&X.length>0&&i.jsx(Nn,{title:c("printModal.insufficientFilamentTitle"),message:Ve,confirmText:c("printModal.printAnyway"),cancelText:c("common.cancel"),variant:"warning",onConfirm:()=>{j(null),$e(void 0,{skipFilamentCheck:!0})},onCancel:()=>j(null)})]})}function wW({value:t}){const{t:e}=Dt(),[n,r]=w.useState(!1),a=async()=>{try{await navigator.clipboard.writeText(t),r(!0),setTimeout(()=>r(!1),2e3)}catch{}};return i.jsx("button",{onClick:a,className:"ml-2 p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:e(n?"printers.copied":"printers.copyToClipboard"),children:n?i.jsx(Zr,{className:"w-3.5 h-3.5 text-bambu-green"}):i.jsx(No,{className:"w-3.5 h-3.5"})})}function Qqe({printer:t,status:e,totalPrintHours:n,onClose:r}){const{t:a}=Dt();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(wW,{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(wW,{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(VL,{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=zZ(e.wifi_signal);s.push({label:a("printers.wifiSignalLabel"),value:i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(nQ,{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:Ef(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(Bt,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsx("div",{className:"flex justify-center mb-4",children:i.jsx("img",{src:IZ(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 Zqe(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 Q2({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&&Zqe(t)?"#000":"#fff"},children:r})})}const SW={"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"},Jqe={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 Z2(t){if(!t)return null;if(SW[t])return SW[t];const e=t.split("-");if(e.length<2)return null;const n=e[1];return Jqe[n]||null}function J2(t){return(t??.02).toFixed(3)}function _W({side:t}){const{mode:e}=tg(),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 oie(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 lie(t,e){return t?t.startsWith("HH")?e("printers.nozzleHighFlow"):t.startsWith("HS")?e("printers.nozzleStandardFlow"):"":""}function cie({slot:t,index:e,activeStatus:n,filamentName:r,children:a}){const{t:s}=Dt(),[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 C=d.current.getBoundingClientRect(),k=m.current.offsetHeight,T=C.top-56,D=window.innerHeight-C.bottom;TT?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=R4(t.filament_color),_=oie(t.nozzle_type,s),N=lie(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 a82812e45..9000308c3 100644 --- a/static/index.html +++ b/static/index.html @@ -23,7 +23,7 @@ - +