diff --git a/CHANGELOG.md b/CHANGELOG.md index 61aa81dac..01d1da202 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ All notable changes to Bambuddy will be documented in this file. - **Updates Card Separates Firmware and Software Settings** — The Updates card on the Settings page mixed printer firmware and Bambuddy software update toggles with no visual grouping. Now splits the card into two labeled sections ("Printer Firmware" and "Bambuddy Software") separated by a divider, making it clear which toggles control what. - **SpoolBuddy Test Coverage** — Added integration tests for all 12 SpoolBuddy API endpoints (21 backend tests covering device registration/re-registration, heartbeat status and pending commands, NFC tag scan/match/removal, scale reading broadcast, spool weight calculation, and scale calibration including tare, set-factor, and zero-delta error handling) and component tests for the three main SpoolBuddy frontend components (20 frontend tests covering WeightDisplay weight formatting and status indicators, SpoolInfoCard spool info rendering and action callbacks, UnknownTagCard tag display, and TagDetectedModal open/close/escape behavior with known and unknown spool views). - **Cleanup Obsolete Settings** — The startup migration now deletes orphaned settings keys from the database that are no longer used by the application (e.g., `slicer_binary_path` from earlier slicer integration research). +- **Added HUF Currency** ([#579](https://github.com/maziggy/bambuddy/issues/579)) — Added Hungarian Forint (HUF, Ft) to the supported currencies list for filament cost tracking. ## [0.2.1] - 2026-02-27 diff --git a/frontend/src/__tests__/utils/currency.test.ts b/frontend/src/__tests__/utils/currency.test.ts index 2a5b0fc61..6bbab097b 100644 --- a/frontend/src/__tests__/utils/currency.test.ts +++ b/frontend/src/__tests__/utils/currency.test.ts @@ -37,7 +37,7 @@ describe('SUPPORTED_CURRENCIES', () => { expect(SUPPORTED_CURRENCIES.find((c) => c.code === 'INR')).toBeDefined(); }); - it('has 25 entries', () => { - expect(SUPPORTED_CURRENCIES).toHaveLength(25); + it('has 26 entries', () => { + expect(SUPPORTED_CURRENCIES).toHaveLength(26); }); }); diff --git a/frontend/src/utils/currency.ts b/frontend/src/utils/currency.ts index 6aee937a9..7f708c5ed 100644 --- a/frontend/src/utils/currency.ts +++ b/frontend/src/utils/currency.ts @@ -24,6 +24,7 @@ const CURRENCY_SYMBOLS: Record = { ZAR: 'R', TRY: '₺', RUB: '₽', + HUF: 'Ft', }; export function getCurrencySymbol(currencyCode: string): string { @@ -56,4 +57,5 @@ export const SUPPORTED_CURRENCIES = [ { code: 'ZAR', label: 'ZAR (R)' }, { code: 'TRY', label: 'TRY (₺)' }, { code: 'RUB', label: 'RUB (₽)' }, + { code: 'HUF', label: 'HUF (Ft)' }, ] as const; diff --git a/static/assets/index-BG0HaL1s.js b/static/assets/index-BYJvXySm.js similarity index 98% rename from static/assets/index-BG0HaL1s.js rename to static/assets/index-BYJvXySm.js index 85ea1fdf4..64b913186 100644 --- a/static/assets/index-BG0HaL1s.js +++ b/static/assets/index-BYJvXySm.js @@ -8482,7 +8482,7 @@ void main() { border-l-[5px] border-l-transparent border-r-[5px] border-r-transparent border-t-[5px] border-t-bambu-dark-tertiary - `})]})]})}function N$e({isOpen:t,onClose:e,tagUid:n,trayUuid:r,printerId:i,amsId:s,trayId:o}){const{t:l}=jt(),c=Jt(),{showToast:u}=mn(),[d,h]=w.useState(""),{data:f,isLoading:p}=Je({queryKey:["inventory-spools"],queryFn:()=>ge.getSpools(!1),enabled:t}),x=w.useMemo(()=>f?f.filter(g=>{if(g.tag_uid||g.tray_uuid)return!1;if(!d)return!0;const y=d.toLowerCase();return g.material.toLowerCase().includes(y)||g.brand&&g.brand.toLowerCase().includes(y)||g.color_name&&g.color_name.toLowerCase().includes(y)}):[],[f,d]),v=ut({mutationFn:g=>ge.linkTagToSpool(g,{tag_uid:n||void 0,tray_uuid:r||void 0,tag_type:r?"bambulab":"generic",data_origin:"nfc_link"}),onSuccess:()=>{c.invalidateQueries({queryKey:["inventory-spools"]}),c.invalidateQueries({queryKey:["inventory-assignments"]}),u(l("inventory.tagLinked"),"success"),e()},onError:g=>{u(g.message||l("inventory.tagLinkFailed"),"error")}});return t?a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[a.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),a.jsxs("div",{className:"relative bg-bambu-dark-secondary rounded-xl shadow-xl w-full max-w-md mx-4 max-h-[80vh] flex flex-col border border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[a.jsxs("div",{children:[a.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(sx,{className:"w-5 h-5 text-bambu-green"}),l("inventory.linkToSpool")]}),a.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["AMS ",s," T",o," · Printer #",i]})]}),a.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:a.jsx(Bt,{className:"w-5 h-5"})})]}),a.jsxs("div",{className:"p-4 border-b border-white/10",children:[a.jsxs("div",{className:"relative",children:[a.jsx(Mr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),a.jsx("input",{type:"text",value:d,onChange:g=>h(g.target.value),placeholder:l("inventory.searchSpools"),className:"w-full pl-9 pr-3 py-2 bg-bambu-dark rounded-lg border border-white/10 text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green"})]}),(n||r)&&a.jsxs("p",{className:"text-xs text-bambu-gray mt-2 font-mono truncate",title:n||r,children:["Tag: ",n||r]})]}),a.jsx("div",{className:"flex-1 overflow-y-auto p-2 min-h-0",children:p?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(lt,{className:"w-6 h-6 animate-spin text-bambu-green"})}):x.length===0?a.jsx("p",{className:"text-center text-bambu-gray py-8 text-sm",children:l("inventory.noSpoolsMatch")}):x.map(g=>a.jsxs("button",{onClick:()=>v.mutate(g.id),disabled:v.isPending,className:"w-full flex items-center gap-3 p-3 rounded-lg hover:bg-white/5 transition-colors text-left",children:[a.jsx("span",{className:"w-6 h-6 rounded-full border border-white/20 flex-shrink-0",style:{backgroundColor:g.rgba?`#${g.rgba.substring(0,6)}`:"#808080"}}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"text-sm text-white font-medium truncate",children:[g.brand?`${g.brand} `:"",g.material,g.subtype?` ${g.subtype}`:""]}),a.jsxs("div",{className:"text-xs text-bambu-gray truncate",children:[g.color_name||"No color"," · #",g.id]})]}),a.jsxs("span",{className:"text-xs text-bambu-gray",children:[Math.round(g.label_weight-g.weight_used),"g"]})]},g.id))}),a.jsx("div",{className:"p-4 border-t border-white/10 flex justify-end",children:a.jsx(Ie,{variant:"ghost",onClick:e,children:l("inventory.cancel")||"Cancel"})})]})]}):null}function C$e({isOpen:t,onClose:e,printerId:n,amsId:r,trayId:i,trayInfo:s}){const{t:o}=jt(),l=Jt(),{showToast:c}=mn(),[u,d]=w.useState(null),[h,f]=w.useState(""),{data:p,isLoading:x}=Je({queryKey:["inventory-spools"],queryFn:()=>ge.getSpools(),enabled:t}),{data:v}=Je({queryKey:["spool-assignments"],queryFn:()=>ge.getAssignments(),enabled:t}),g=ut({mutationFn:M=>ge.assignSpool({spool_id:M,printer_id:n,ams_id:r,tray_id:i}),onSuccess:M=>{l.setQueryData(["spool-assignments"],C=>{const R=(C||[]).filter(A=>!(A.printer_id===n&&A.ams_id===r&&A.tray_id===i));return R.push(M),R}),l.invalidateQueries({queryKey:["spool-assignments"]}),c(o("inventory.assignSuccess"),"success"),e()},onError:M=>{c(`${o("inventory.assignFailed")}: ${M.message}`,"error")}});if(!t)return null;const y=new Set((v||[]).filter(M=>!(M.printer_id===n&&M.ams_id===r&&M.tray_id===i)).map(M=>M.spool_id)),_=r===254||r===255,N=p?.filter(M=>!y.has(M.id)&&(_||!M.tag_uid&&!M.tray_uuid)),T=N?.filter(M=>{if(!h)return!0;const C=h.toLowerCase();return M.material.toLowerCase().includes(C)||(M.brand?.toLowerCase().includes(C)??!1)||(M.color_name?.toLowerCase().includes(C)??!1)||(M.subtype?.toLowerCase().includes(C)??!1)}),k=()=>{u&&g.mutate(u)};return a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[a.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),a.jsxs("div",{className:"relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ii,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:o("inventory.assignSpool")})]}),a.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:a.jsx(Bt,{className:"w-5 h-5"})})]}),a.jsxs("div",{className:"p-4 space-y-4",children:[s&&a.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsxs("p",{className:"text-xs text-bambu-gray mb-1",children:[o("inventory.selectSpool"),":"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[s.color&&a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20",style:{backgroundColor:`#${s.color}`}}),a.jsx("span",{className:"text-white font-medium",children:s.type||o("ams.emptySlot")}),a.jsxs("span",{className:"text-bambu-gray",children:["(",s.location,")"]})]})]}),a.jsxs("div",{className:"relative",children:[a.jsx(Mr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),a.jsx("input",{type:"text",value:h,onChange:M=>f(M.target.value),placeholder:o("inventory.searchSpools"),className:"w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green"})]}),a.jsx("div",{children:x?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):T&&T.length>0?a.jsx("div",{className:"max-h-64 overflow-y-auto space-y-2",children:T.map(M=>a.jsx("button",{onClick:()=>d(M.id),className:`w-full p-3 rounded-lg border text-left transition-colors ${u===M.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:a.jsxs("div",{className:"flex items-center gap-2",children:[M.rgba&&a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20 flex-shrink-0",style:{backgroundColor:`#${M.rgba.substring(0,6)}`}}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("p",{className:"text-white font-medium truncate",children:[M.brand?`${M.brand} `:"",M.material,M.subtype?` ${M.subtype}`:""]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[M.color_name||"",M.label_weight?` - ${M.label_weight}g`:"",M.label_weight?` (${Math.max(0,Math.round(M.label_weight-M.weight_used))}g ${o("ams.remainingUnit")})`:""]})]}),u===M.id&&a.jsx(Vr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]})},M.id))}):N&&N.length===0?a.jsx("div",{className:"text-center py-8 text-bambu-gray",children:a.jsx("p",{children:o("inventory.noManualSpools")})}):a.jsx("div",{className:"text-center py-8 text-bambu-gray",children:a.jsx("p",{children:o("inventory.noSpoolsMatch")})})})]}),a.jsxs("div",{className:"flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary",children:[a.jsx(Ie,{variant:"secondary",onClick:e,children:o("common.cancel")}),a.jsx(Ie,{onClick:k,disabled:!u||g.isPending,children:g.isPending?a.jsxs(a.Fragment,{children:[a.jsx(lt,{className:"w-4 h-4 animate-spin"}),o("inventory.assigning")]}):a.jsxs(a.Fragment,{children:[a.jsx(ii,{className:"w-4 h-4"}),o("inventory.assignSpool")]})})]}),g.isError&&a.jsx("div",{className:"mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:g.error.message})]})]})}function mG(t,e){if(t===255)return"External";let n,r=!1;t>=128&&t<=135?(n=t-128,r=!0):t>=0&&t<=3?(n=t,r=e===1):n=0,n=Math.max(0,Math.min(n,7));const i=String.fromCharCode(65+n);return r?`HT-${i}`:`AMS-${i}`}function L_(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 k$e=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function fG(t){const e=t.replace(/@.+$/,"").trim(),n=e.toUpperCase();for(const i of k$e){const s=new RegExp(`\\b${i}\\b`,"i");if(s.test(n)){const o=e.split(s),l=o[0]?.trim()||"",c=o[1]?.trim()||"";return{material:i,brand:l,variant:c}}}const r=e.split(/\s+/);return r.length>=2?{material:r[1],brand:r[0],variant:r.slice(2).join(" ")}:{material:e,brand:"",variant:""}}function T$e(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const A$e={white:"FFFFFF",black:"000000",red:"FF0000",green:"00FF00",blue:"0000FF",yellow:"FFFF00",cyan:"00FFFF",magenta:"FF00FF",orange:"FFA500",purple:"800080",pink:"FFC0CB",brown:"8B4513",gray:"808080",grey:"808080","jade white":"FFFEF2",ivory:"FFFFF0",beige:"F5F5DC",cream:"FFFDD0",silver:"C0C0C0",gold:"FFD700",bronze:"CD7F32",copper:"B87333",navy:"000080",teal:"008080",olive:"808000",maroon:"800000",coral:"FF7F50",salmon:"FA8072",lime:"32CD32",mint:"98FF98","forest green":"228B22","sky blue":"87CEEB","royal blue":"4169E1",turquoise:"40E0D0",lavender:"E6E6FA",violet:"EE82EE",plum:"DDA0DD",tan:"D2B48C",chocolate:"D2691E",charcoal:"36454F",slate:"708090",transparent:"000000",natural:"F5F5DC",wood:"DEB887"},pG=[{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"}],gG=[{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 bG(t){const e=t.toLowerCase().trim();return A$e[e]||null}function P$e(t){const e=t.indexOf("@");if(e<0)return null;const r=t.slice(e+1).trim().match(/^BBL\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);return r?r[1].trim():null}function Bne({isOpen:t,onClose:e,printerId:n,slotInfo:r,nozzleDiameter:i="0.4",printerModel:s,onSuccess:o,fullScreen:l}){const{t:c}=jt(),[u,d]=w.useState(""),[h,f]=w.useState(null),[p,x]=w.useState(""),[v,g]=w.useState(""),[y,_]=w.useState(""),[N,T]=w.useState(!1),[k,M]=w.useState(!1),{data:C,isLoading:R,isError:A}=Je({queryKey:["cloudSettings"],queryFn:()=>ge.getCloudSettings(),enabled:t,retry:!1}),{data:D,isLoading:V}=Je({queryKey:["localPresets"],queryFn:()=>ge.getLocalPresets(),enabled:t}),{data:U,isLoading:W}=Je({queryKey:["builtinFilaments"],queryFn:()=>ge.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:L,isLoading:te}=Je({queryKey:["kprofiles",n,i],queryFn:()=>ge.getKProfiles(n,i),enabled:t&&!!n}),{data:ie}=Je({queryKey:["colorCatalog"],queryFn:()=>ge.getColorCatalog(),enabled:t,staleTime:1/0}),X=ut({mutationFn:async()=>{if(!u)throw new Error("No filament preset selected");const P=u.startsWith("local_"),E=u.startsWith("builtin_"),O=P?parseInt(u.replace("local_",""),10):null,G=E?u.replace("builtin_",""):null,B=P?D?.filament.find(Ne=>Ne.id===O):null,re=E?U?.find(Ne=>Ne.filament_id===G):null,z=!P&&!E?C?.filament.find(Ne=>Ne.setting_id===u):null;if(!P&&!E&&!z)throw new Error("Selected preset not found");if(P&&!B)throw new Error("Selected local preset not found");if(E&&!re)throw new Error("Selected builtin preset not found");const q=P?B.name:E?re.name:z.name,ee=fG(q),J=h?.slot_id??-1,ne=p||r.trayColor?.slice(0,6)||"FFFFFF",ae=q.replace(/@.+$/,"").trim();let de,ye;if(P){const Ne=(B?.filament_type||ee.material||"").toUpperCase(),_e={PLA:"GFL99","PLA-CF":"GFL98","PLA SILK":"GFL96","PLA HIGH SPEED":"GFL95",PETG:"GFG99","PETG HF":"GFG96","PETG-CF":"GFG98",PCTG:"GFG97",ABS:"GFB99",ASA:"GFB98",PC:"GFC99",PA:"GFN99","PA-CF":"GFN98",NYLON:"GFN99",TPU:"GFU99",PVA:"GFS99",HIPS:"GFS98",PE:"GFP99",PP:"GFP97"};de=_e[Ne]||_e[Ne.replace(/[-\s]?CF$/,"")]||_e[Ne.replace(/\+$/,"")]||_e[Ne.split(/[-\s]/)[0]]||"",ye=""}else if(E)de=G,ye="";else if(de=L_(u),ye=u,!u.startsWith("GFS"))try{const Ne=await ge.getCloudSettingDetail(u);Ne.filament_id?de=Ne.filament_id:Ne.base_id&&(de=L_(Ne.base_id),console.log(`Derived tray_info_idx from base_id: ${Ne.base_id} -> ${de}`))}catch(Ne){console.warn("Failed to fetch preset detail for filament_id:",Ne)}let le=P&&B?.nozzle_temp_min?B.nozzle_temp_min:190,I=P&&B?.nozzle_temp_max?B.nozzle_temp_max:230;if(!P||E||!B?.nozzle_temp_min&&!B?.nozzle_temp_max){const Ne=(P&&B?.filament_type||ee.material).toUpperCase();Ne.includes("PLA")?(le=190,I=230):Ne.includes("PETG")?(le=220,I=260):Ne.includes("ABS")||Ne.includes("ASA")?(le=240,I=280):Ne.includes("TPU")?(le=200,I=240):Ne==="PCTG"?(le=220,I=260):Ne.includes("PC")?(le=260,I=300):(Ne.includes("PA")||Ne.includes("NYLON"))&&(le=250,I=290)}const F=h?.k_value?parseFloat(h.k_value):0,Z=P?B?.filament_type||ee.material||"PLA":ee.material||"PLA",xe=await ge.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:de,tray_type:Z,tray_sub_brands:ae,tray_color:ne+"FF",nozzle_temp_min:le,nozzle_temp_max:I,cali_idx:J,nozzle_diameter:i,setting_id:ye,kprofile_filament_id:h?.filament_id,kprofile_setting_id:h?.setting_id||void 0,k_value:F}),me=P?`local_${O}`:E?`builtin_${G}`:u,ce=P?"local":E?"builtin":"cloud";try{await ge.saveSlotPreset(n,r.amsId,r.trayId,me,ae,ce)}catch(Ne){console.warn("Failed to save slot preset mapping:",Ne)}return xe},onSuccess:()=>{T(!0),o?.(),setTimeout(()=>{T(!1),e()},1500)}}),se=ut({mutationFn:async()=>ge.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{T(!0),o?.(),setTimeout(()=>{T(!1),e()},1500)}}),ue=w.useMemo(()=>{const P=y.toLowerCase(),E=[],O=new Set,G=r.savedPresetId,B=r.trayInfoIdx;if(C?.filament)for(const re of C.filament){O.add(re.setting_id);const z=G===re.setting_id||B&&(re.setting_id===B||L_(re.setting_id)===B);if(!(!z&&P&&!re.name.toLowerCase().includes(P))){if(!z&&s){const q=P$e(re.name);if(q&&q.toUpperCase()!==s.toUpperCase())continue}E.push({id:re.setting_id,name:re.name,source:"cloud",isUser:T$e(re.setting_id)})}}if(D?.filament)for(const re of D.filament){const z=`local_${re.id}`,q=G===z;if(!(!q&&P&&!re.name.toLowerCase().includes(P))){if(!q&&s&&re.compatible_printers){const ee=re.compatible_printers.split(";").map(J=>{const ne=J.trim(),ae=ne.match(/^BBL\s+(.+)/i);return ae?ae[1].trim().toUpperCase():ne.toUpperCase()}).filter(Boolean);if(ee.length>0&&!ee.includes(s.toUpperCase()))continue}E.push({id:z,name:re.name,source:"local",isUser:!1})}}if(U)for(const re of U){if(O.has(re.filament_id))continue;const z=re.filament_id.startsWith("GF")?"GFS"+re.filament_id.slice(2):re.filament_id;O.has(z)||(!P||re.name.toLowerCase().includes(P))&&E.push({id:`builtin_${re.filament_id}`,name:re.name,source:"builtin",isUser:!1})}return E.sort((re,z)=>{const q={cloud:0,local:1,builtin:2};return re.source!==z.source?q[re.source]-q[z.source]:re.isUser&&!z.isUser?-1:!re.isUser&&z.isUser?1:re.name.localeCompare(z.name)})},[C?.filament,D?.filament,U,y,s,r.savedPresetId,r.trayInfoIdx]),he=w.useMemo(()=>{if(!u)return null;let P=null;if(u.startsWith("local_")){const G=parseInt(u.replace("local_",""),10);P=D?.filament.find(re=>re.id===G)?.name||null}else if(u.startsWith("builtin_")){const G=u.replace("builtin_","");P=U?.find(re=>re.filament_id===G)?.name||null}else C?.filament&&(P=C.filament.find(B=>B.setting_id===u)?.name||null);if(!P)return null;let E=P.replace(/@.+$/,"").trim();E.startsWith("# ")&&(E=E.slice(2).trim());const O=fG(E);return{fullName:E,material:O.material,brand:O.brand}},[u,C?.filament,D?.filament,U]),Q=he?.fullName||"",oe=w.useMemo(()=>{if(!ie||!he)return[];const{fullName:P,brand:E}=he,O=P.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return ie.filter(G=>{const B=(G.material||"").toUpperCase(),re=G.manufacturer.toUpperCase();if(!(B===O.toUpperCase()||B.includes(O.toUpperCase())||O.toUpperCase().includes(B)))return!1;if(E){const q=E.toUpperCase();if(!re.includes(q)&&!q.includes(re))return!1}return!0})},[ie,he]),fe=w.useMemo(()=>{if(!L?.profiles||!he)return[];const{fullName:P,material:E,brand:O}=he,G=P.toUpperCase(),B=E.toUpperCase(),re=O.toUpperCase();if(!B||B.length<2)return[];const z=L.profiles.filter(ee=>{const J=ee.name.toUpperCase();if(re)return!(!J.includes(re)||!J.includes(B));if(J.includes(G)||J.includes(B))return!0;const ae={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[B]||[];for(const de of ae)if(J.includes(de))return!0;return!1}),q=new Map;for(const ee of z){const J=`${ee.name}|${ee.k_value}`,ne=q.get(J);ne?r.extruderId!==void 0&&ee.extruder_id===r.extruderId&&ne.extruder_id!==r.extruderId&&q.set(J,ee):q.set(J,ee)}return Array.from(q.values())},[L?.profiles,he,r.extruderId]);w.useEffect(()=>{if(t){if(r.savedPresetId)d(r.savedPresetId);else if(r.trayInfoIdx&&C?.filament){let P=C.filament.find(E=>E.setting_id===r.trayInfoIdx);P||(P=C.filament.find(E=>L_(E.setting_id)===r.trayInfoIdx)),P&&d(P.setting_id)}if(r.trayColor){const P=r.trayColor.slice(0,6);P&&x(P)}}else d(""),f(null),x(""),g(""),_(""),T(!1)},[t,r.savedPresetId,r.trayInfoIdx,r.trayColor,C?.filament]),w.useEffect(()=>{if(fe.length>0){if(r.caliIdx!=null&&r.caliIdx>0){const P=fe.find(E=>E.slot_id===r.caliIdx);if(P){f(P);return}}f(fe[0])}else f(null)},[u,fe,r.caliIdx]);const be=w.useCallback(P=>{P.key==="Escape"&&e()},[e]);if(w.useEffect(()=>{if(t)return document.addEventListener("keydown",be),()=>document.removeEventListener("keydown",be)},[t,be]),!t)return null;const Re=R&&!A||V||W||te,$=u&&!X.isPending,K=p||r.trayColor?.slice(0,6)||"FFFFFF";return a.jsxs("div",{className:`fixed inset-0 z-50 flex ${l?"":"items-center justify-center"}`,children:[!l&&a.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),a.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:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(sd,{className:"w-5 h-5 text-bambu-blue"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.title")}),l&&a.jsxs("div",{className:"flex items-center gap-2 ml-4 text-sm text-bambu-gray",children:[a.jsx("span",{className:"text-white/30",children:"|"}),r.trayColor&&a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),a.jsx("span",{className:"text-white/70",children:c("configureAmsSlot.slotLabel",{ams:mG(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&a.jsxs("span",{children:["(",r.traySubBrands,")"]})]})]}),a.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:a.jsx(Bt,{className:"w-5 h-5"})})]}),a.jsxs("div",{className:`p-4 overflow-y-auto ${l?"flex-1 min-h-0":"space-y-4 max-h-[60vh]"}`,children:[N&&a.jsx("div",{className:"absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl",children:a.jsxs("div",{className:"text-center space-y-3",children:[a.jsx(kb,{className:"w-16 h-16 text-bambu-green mx-auto"}),a.jsx("p",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.slotConfigured")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:c("configureAmsSlot.settingsSentToPrinter")})]})}),!l&&a.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:c("configureAmsSlot.configuringSlot")}),a.jsxs("div",{className:"flex items-center gap-2",children:[r.trayColor&&a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),a.jsx("span",{className:"text-white font-medium",children:c("configureAmsSlot.slotLabel",{ams:mG(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&a.jsxs("span",{className:"text-bambu-gray",children:["(",r.traySubBrands,")"]})]})]}),Re?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):l?a.jsxs("div",{className:"flex gap-4 h-full",children:[a.jsxs("div",{className:"w-1/2 flex flex-col min-h-0",children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",a.jsx("span",{className:"text-red-400",children:"*"})]}),a.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:y,onChange:P=>_(P.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"}),a.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-1",children:ue.length===0?a.jsx("p",{className:"text-center py-4 text-bambu-gray",children:C?.filament?.length===0&&!D?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):ue.map(P=>a.jsx("button",{ref:u===P.id?E=>{E?.scrollIntoView({block:"nearest"})}:void 0,onClick:()=>d(P.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${u===P.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-white text-sm truncate",children:P.name}),a.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[P.source==="local"&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),P.source==="builtin"&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),P.isUser&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},P.id))})]}),a.jsxs("div",{className:"w-1/2 flex flex-col gap-4 min-h-0 overflow-y-auto",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),Q&&a.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:Q})})]}),fe.length>0?a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:h?.name||"",onChange:P=>{const E=fe.find(O=>O.name===P.target.value);f(E||null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10",children:[a.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),fe.map(P=>a.jsxs("option",{value:P.name,children:[P.name," (K=",P.k_value,")"]},`${P.name}-${P.extruder_id}`))]}),a.jsx(Fn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):u?a.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):a.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),h&&a.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:h.k_value})})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),oe.length>0&&a.jsxs("div",{className:"mb-3",children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:he?.fullName})}),a.jsx("div",{className:"flex flex-wrap gap-1.5",children:oe.map(P=>a.jsxs("button",{onClick:()=>{const E=P.hex_color.replace("#","").toUpperCase();x(E),g(P.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${p===P.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:P.color_name,children:[a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/30 flex-shrink-0",style:{backgroundColor:P.hex_color}}),a.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:P.color_name})]},P.id))})]}),a.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[pG.map(P=>a.jsx("button",{onClick:()=>{x(P.hex),g(P.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===P.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${P.hex}`},title:P.name},P.hex)),a.jsx("button",{onClick:()=>M(!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&&a.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:gG.map(P=>a.jsx("button",{onClick:()=>{x(P.hex),g(P.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===P.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${P.hex}`},title:P.name},P.hex))}),a.jsxs("div",{className:"flex gap-2 items-center",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${K}`}}),a.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:P=>{const E=P.target.value;g(E);const O=bG(E);if(O)x(O);else{const G=E.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();G.length===6?x(G):G.length===3&&x(G.split("").map(B=>B+B).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"}),p&&a.jsx("button",{onClick:()=>{x(""),g("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),p&&a.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:p})})]})]})]}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",a.jsx("span",{className:"text-red-400",children:"*"})]}),a.jsxs("div",{className:"relative",children:[a.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:y,onChange:P=>_(P.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2"}),a.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:ue.length===0?a.jsx("p",{className:"text-center py-4 text-bambu-gray",children:C?.filament?.length===0&&!D?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):ue.map(P=>a.jsx("button",{ref:u===P.id?E=>{E?.scrollIntoView({block:"nearest"})}:void 0,onClick:()=>d(P.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${u===P.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-white text-sm truncate",children:P.name}),a.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[P.source==="local"&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),P.source==="builtin"&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),P.isUser&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},P.id))})]})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),Q&&a.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:Q})})]}),fe.length>0?a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:h?.name||"",onChange:P=>{const E=fe.find(O=>O.name===P.target.value);f(E||null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10",children:[a.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),fe.map(P=>a.jsxs("option",{value:P.name,children:[P.name," (K=",P.k_value,")"]},`${P.name}-${P.extruder_id}`))]}),a.jsx(Fn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):u?a.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):a.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),h&&a.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:h.k_value})})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),oe.length>0&&a.jsxs("div",{className:"mb-3",children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:he?.fullName})}),a.jsx("div",{className:"flex flex-wrap gap-1.5",children:oe.map(P=>a.jsxs("button",{onClick:()=>{const E=P.hex_color.replace("#","").toUpperCase();x(E),g(P.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${p===P.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:P.color_name,children:[a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/30 flex-shrink-0",style:{backgroundColor:P.hex_color}}),a.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:P.color_name})]},P.id))})]}),a.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[pG.map(P=>a.jsx("button",{onClick:()=>{x(P.hex),g(P.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===P.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${P.hex}`},title:P.name},P.hex)),a.jsx("button",{onClick:()=>M(!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&&a.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:gG.map(P=>a.jsx("button",{onClick:()=>{x(P.hex),g(P.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===P.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${P.hex}`},title:P.name},P.hex))}),a.jsxs("div",{className:"flex gap-2 items-center",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${K}`}}),a.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:P=>{const E=P.target.value;g(E);const O=bG(E);if(O)x(O);else{const G=E.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();G.length===6?x(G):G.length===3&&x(G.split("").map(B=>B+B).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"}),p&&a.jsx("button",{onClick:()=>{x(""),g("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),p&&a.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:p})})]})]})]}),a.jsxs("div",{className:"flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[a.jsx(Ie,{variant:"secondary",onClick:()=>se.mutate(),disabled:se.isPending||X.isPending,className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:se.isPending?a.jsxs(a.Fragment,{children:[a.jsx(lt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.resetting")]}):a.jsxs(a.Fragment,{children:[a.jsx(lo,{className:"w-4 h-4"}),c("configureAmsSlot.resetSlot")]})}),a.jsxs("div",{className:"flex gap-2",children:[a.jsx(Ie,{variant:"secondary",onClick:e,children:c("configureAmsSlot.cancel")}),a.jsx(Ie,{onClick:()=>X.mutate(),disabled:!$,children:X.isPending?a.jsxs(a.Fragment,{children:[a.jsx(lt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.configuring")]}):a.jsxs(a.Fragment,{children:[a.jsx(sd,{className:"w-4 h-4"}),c("configureAmsSlot.configureSlot")]})})]})]}),(X.isError||se.isError)&&a.jsx("div",{className:"mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:X.error?.message||se.error?.message})]})]})}function Hne({folderId:t,onClose:e,onUploadComplete:n,onFileUploaded:r,autoUpload:i,validateFile:s,accept:o}){const{t:l}=jt(),[c,u]=w.useState([]),[d,h]=w.useState(!1),[f,p]=w.useState(!1),[x,v]=w.useState(!0),[g,y]=w.useState(!1),[_,N]=w.useState(!0),[T,k]=w.useState(null),M=w.useRef(null),C=he=>{he.preventDefault(),h(!0)},R=he=>{he.preventDefault(),h(!1)},A=he=>{he.preventDefault(),h(!1),W(Array.from(he.dataTransfer.files))},D=he=>{he.target.files&&W(Array.from(he.target.files))},V=(he,Q)=>{u(oe=>oe.map(fe=>fe.file===he?{...fe,...Q}:fe))},U=async he=>{p(!0);for(const Q of he)if(Q.status==="pending"){V(Q.file,{status:"uploading"});try{if(Q.isZip){const oe=await ge.extractZipFile(Q.file,t,x,g,_);V(Q.file,{status:oe.errors.length>0&&oe.extracted===0?"error":"success",extractedCount:oe.extracted,error:oe.errors.length>0?l("fileManager.zipFilesFailed","{{count}} files failed",{count:oe.errors.length}):void 0})}else{const oe=await ge.uploadLibraryFile(Q.file,t,_);V(Q.file,{status:"success"});const fe=r?.(oe);if(fe){k(fe),u([]),p(!1);return}}}catch(oe){V(Q.file,{status:"error",error:oe instanceof Error?oe.message:l("fileManager.uploadFailed","Upload failed")})}}p(!1),n(),e()},W=he=>{if(k(null),s)for(const oe of he){const fe=s(oe);if(fe){k(fe);return}}const Q=he.map(oe=>({file:oe,status:"pending",isZip:oe.name.toLowerCase().endsWith(".zip"),is3mf:oe.name.toLowerCase().endsWith(".3mf")}));u(oe=>[...oe,...Q]),i&&he.length>0&&U(Q)},L=he=>{u(Q=>Q.filter((oe,fe)=>fe!==he))},te=c.some(he=>he.isZip&&he.status==="pending"),ie=c.some(he=>he.file.name.toLowerCase().endsWith(".stl")&&he.status==="pending"),X=c.some(he=>he.is3mf&&he.status==="pending"),se=c.filter(he=>he.status==="pending").length,ue=c.length>0&&se===0&&!f;return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-lg border border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[a.jsx("h2",{className:"text-lg font-semibold text-white",children:l("fileManager.uploadFiles")}),a.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:a.jsx(Bt,{className:"w-5 h-5 text-bambu-gray"})})]}),a.jsxs("div",{className:"p-4 space-y-4",children:[a.jsxs("div",{onDragOver:C,onDragLeave:R,onDrop:A,onClick:()=>M.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:[a.jsx(Oa,{className:`w-10 h-10 mx-auto mb-3 ${d?"text-bambu-green":"text-bambu-gray"}`}),a.jsx("p",{className:"text-white font-medium",children:l(d?"fileManager.dropFilesHere":"fileManager.dragDropFiles")}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:l("fileManager.orClickToBrowse")}),a.jsx("p",{className:"text-xs text-bambu-gray/70 mt-2",children:l("fileManager.allFileTypesSupported")})]}),a.jsx("input",{ref:M,type:"file",multiple:!0,accept:o,className:"hidden",onChange:D}),te&&a.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(Ls,{className:"w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:"flex-1",children:[a.jsx("p",{className:"text-sm text-blue-300 font-medium",children:l("fileManager.zipFilesDetected")}),a.jsx("p",{className:"text-xs text-blue-300/70 mt-1",children:l("fileManager.zipExtractOptions")}),a.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:x,onChange:he=>v(he.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),a.jsx("span",{className:"text-sm text-white",children:l("fileManager.preserveZipStructure")})]}),a.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:g,onChange:he=>y(he.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),a.jsx("span",{className:"text-sm text-white",children:l("fileManager.createFolderFromZip")})]})]})]})}),X&&a.jsx("div",{className:"p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(wr,{className:"w-5 h-5 text-purple-400 mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:"flex-1",children:[a.jsx("p",{className:"text-sm text-purple-300 font-medium",children:l("fileManager.threemfDetected")}),a.jsx("p",{className:"text-xs text-purple-300/70 mt-1",children:l("fileManager.threemfExtractionInfo")})]})]})}),(ie||te)&&a.jsx("div",{className:"p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(id,{className:"w-5 h-5 text-bambu-green mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:"flex-1",children:[a.jsx("p",{className:"text-sm text-bambu-green font-medium",children:l("fileManager.stlThumbnailGeneration")}),a.jsx("p",{className:"text-xs text-bambu-green/70 mt-1",children:l(te&&!ie?"fileManager.zipMayContainStl":"fileManager.thumbnailsCanBeGenerated")}),a.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[a.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"}),a.jsx("span",{className:"text-sm text-white",children:l("fileManager.generateThumbnailsForStl")})]})]})]})}),c.length>0&&a.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:c.map((he,Q)=>a.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[he.isZip?a.jsx(Ls,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):a.jsx(ak,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("p",{className:"text-sm text-white truncate",children:he.file.name}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[(he.file.size/1024/1024).toFixed(2)," MB",he.isZip&&he.status==="pending"&&a.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",l("fileManager.willBeExtracted")]}),he.extractedCount!==void 0&&a.jsxs("span",{className:"text-green-400 ml-2",children:["• ",l("fileManager.filesExtracted",{count:he.extractedCount})]})]})]}),he.status==="pending"&&a.jsx("button",{onClick:()=>L(Q),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Bt,{className:"w-4 h-4 text-bambu-gray"})}),he.status==="uploading"&&a.jsx(lt,{className:"w-4 h-4 text-bambu-green animate-spin"}),he.status==="success"&&a.jsx(br,{className:"w-4 h-4 text-green-500"}),he.status==="error"&&a.jsx("span",{title:he.error,children:a.jsx(qa,{className:"w-4 h-4 text-red-500"})})]},Q))}),T&&a.jsx("div",{className:"p-3 bg-red-500/10 border border-red-500/30 rounded-lg",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(qa,{className:"w-5 h-5 text-red-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-sm text-red-300",children:T})]})})]}),a.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2",children:[a.jsx(Ie,{variant:"secondary",onClick:e,children:l("common.cancel")}),!ue&&a.jsx(Ie,{onClick:()=>U(c),disabled:se===0||f,children:f?a.jsxs(a.Fragment,{children:[a.jsx(lt,{className:"w-4 h-4 mr-2 animate-spin"}),l("fileManager.uploading")]}):a.jsxs(a.Fragment,{children:[a.jsx(Oa,{className:"w-4 h-4 mr-2"}),l("common.upload")," ",se>0?`(${se})`:""]})})]})]})})}const tC={"000000":"Black","001489":"Blue","002e96":"Blue","0047bb":"Blue","00482b":"Pine Green","004ea8":"Blue","0056b8":"Cobalt Blue","0069b1":"Lake Blue","0072ce":"Blue","0078bf":"Marine Blue","0085ad":"Light Blue","0086d6":"Cyan","008bda":"Blue","009639":"Green","009bd8":"Cyan","009fa1":"Teal","00a6a0":"Green","00ae42":"Bambu Green","00b1b7":"Turquoise","00bb31":"Green","018814":"Candy Green","042f56":"Dark Blue","0a2989":"Blue","0a2ca5":"Blue","0c2340":"Navy Blue","0c3b95":"Blue",101820:"Black","147bd1":"Blue","164b35":"Green","16b08e":"Malachite Green","1d7c6a":"Oxide Green Metallic","1f79e5":"Lake Blue","2140b4":"Blue","25282a":"Black","2842ad":"Royal Blue","2d2b28":"Onyx Black Sparkle",324585:"Indigo Blue",353533:"Gray","39541a":"Forest Green","39699e":"Cobalt Blue Metallic","3b665e":"Green","3f5443":"Alpine Green Sparkle","3f8e43":"Mistletoe Green",424379:"Nebulae","43403d":"Iron Gray Metallic",482960:"Indigo Purple","483d8b":"Royal Purple Sparkle","489fdf":"Azure","4c241c":"Rosewood","4ce4a0":"Green","4d3324":"Dark Chocolate","4d5054":"Lava Gray","4dafda":"Cyan","4f3f24":"Black Walnut",515151:"Dark Gray","515a6c":"Gray",545454:"Dark Gray",565656:"Titan Gray","56b7e6":"Sky Blue",583061:"Violet Purple","5898dd":"Blue",594177:"Purple","5b492f":"Brown","5b6579":"Blue Gray","5c9748":"Matcha Green","5e43b7":"Purple","5e4b3c":"Copper","5f6367":"Titan Gray","61b0ff":"Translucent Light Blue","61bf36":"Green","61c680":"Grass Green","6667ab":"Lavender Blue","684a43":"Brown",686865:"Black","68724d":"Dark Green",688197:"Blue Gray","69398e":"Iris Purple","6e88bc":"Jeans Blue","6ee53c":"Lime Green","6f5034":"Cocoa Brown","7248bd":"Lavender","748c45":"Translucent Olive",757575:"Nardo Gray","75aed8":"Blue","77edd7":"Translucent Teal","789d4a":"Olive","792b36":"Crimson Red Sparkle","7ac0e9":"Glow Blue","7ae1bf":"Mint","7cd82b":"Lime Green","7d6556":"Dark Brown","8344b0":"Purple","847d48":"Bronze","854ce4":"Purple","8671cb":"Purple",875718:"Peanut Brown","87909a":"Silver","898d8d":"Gray","8a949e":"Gray","8e8e8e":"Translucent Gray","8e9089":"Gray","90ff1a":"Neon Green",918669:"Classic Birch",939393:"Gray",950051:"Plum","951e23":"Burgundy Red",959698:"Silver","96d8af":"Light Jade","96dcb9":"Mint","995f11":"Clay Brown","999d9d":"Gray","9b9ea0":"Ash Gray","9d2235":"Maroon Red","9d432c":"Brown","9e007e":"Purple","9ea2a2":"Gray","9f332a":"Brick Red",a1ffac:"Glow Green",a3d8e1:"Ice Blue",a6a9aa:"Silver",a8a8aa:"Gray",a8c6ee:"Baby Blue",aa6443:"Copper Brown Metallic",ad4e38:"Red Granite",adb1b2:"Gray",ae835b:"Caramel",ae96d4:"Lilac Purple",af1685:"Purple",afb1ae:"Gray",b15533:"Terracotta",b28b33:"Gold",b39b84:"Iridium Gold Metallic",b50011:"Red",b8acd6:"Lavender",b8cde9:"Ice Blue",ba9594:"Rose Gold",bb3d43:"Dark Red",bc0900:"Red",becf00:"Bright Green",c0df16:"Green",c12e1f:"Red",c2e189:"Apple Green",c3e2d6:"Light Cyan",c5ed48:"Lime",c6001a:"Red",c6c6c6:"Gray",c8102e:"Red",c8c8c8:"Silver",c98935:"Ochre Yellow",c9a381:"Translucent Brown",cbc6b8:"Bone White",cdceca:"Gray",cea629:"Classic Gold Sparkle",d02727:"Candy Red",d1d3d5:"Light Gray",d32941:"Red",d3b7a7:"Latte Brown",d6001c:"Red",d6abff:"Translucent Purple",d6cca3:"White Oak",dc3a27:"Orange",dd3c22:"Vermilion Red",de4343:"Scarlet Red",dfd1a7:"Beige",e02928:"Red",e4bd68:"Gold",e5b03d:"Gold",e83100:"Red",e8afcf:"Sakura Pink",e8dbb7:"Desert Tan",eaeae4:"White",eaeceb:"Silver",ec008c:"Magenta",ed0000:"Red",eeb1c1:"Pink",efe255:"Yellow",f0f1a8:"Clear",f17b8f:"Glow Pink",f3cfb2:"Champagne",f3e600:"Yellow",f48438:"Orange",f4a925:"Gold",f4d53f:"Yellow",f4ee2a:"Yellow",f5547c:"Hot Pink",f55a74:"Pink",f5b6cd:"Cherry Pink",f5dbab:"Mellow Yellow",f5f1dd:"White",f68b1b:"Neon Orange",f74e02:"Orange",f75403:"Orange",f7ada6:"Pink",f7d959:"Lemon Yellow",f7e6de:"Beige",f7f3f0:"White Marble",f8ff80:"Glow Yellow",f99963:"Mandarin Orange",f9c1bd:"Translucent Pink",f9dfb9:"Cream",f9ef41:"Yellow",f9f7f2:"Nature",f9f7f4:"White",fce300:"Yellow",fce900:"Yellow",fec600:"Sunflower Yellow",fedb00:"Yellow",ff4800:"Orange",ff671f:"Orange",ff6a13:"Orange",ff7f41:"Orange",ff9016:"Pumpkin Orange",ff911a:"Translucent Orange",ff9d5b:"Glow Orange",ffb549:"Sunflower Yellow",ffc72c:"Tangerine Yellow",ffce00:"Yellow",ffd00b:"Yellow",ffe133:"Yellow",fffaf2:"White",ffffff:"White"};function M$e(t){if(!t||t.length<6)return"Unknown";const e=t.replace("#",""),n=parseInt(e.substring(0,2),16),r=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16),s=Math.max(n,r,i)/255,o=Math.min(n,r,i)/255,l=(s+o)/2;let c=0,u=0;if(s!==o){const d=s-o;u=l>.5?d/(2-s-o):d/(s+o);const h=n/255,f=r/255,p=i/255;s===h?c=((f-p)/d+(f.85?"White":u<.15?l<.4?"Dark Gray":l>.6?"Light Gray":"Gray":c<15||c>=345?"Red":c<45?"Orange":c<70?"Yellow":c<150?"Green":c<200?"Cyan":c<260?"Blue":c<290?"Purple":"Pink"}function Ff(t){const e=t.replace("#","").toLowerCase().substring(0,6);return tC[e]?tC[e]:M$e(t)}function PO(t,e){if(t&&!/^[A-Z]\d+-[A-Z]\d+$/.test(t))return t;if(e&&e.length>=6){const n=e.substring(0,6).toLowerCase();if(tC[n])return tC[n]}return null}function xG(t){return t?`#${t.replace("#","").substring(0,6)}`:"#808080"}function Fa(t){return t?t.replace("#","").toLowerCase().substring(0,6):""}function Bc(t,e,n=40){const r=Fa(t),i=Fa(e);if(!r||!i||r.length<6||i.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(i.substring(0,2),16),u=parseInt(i.substring(2,4),16),d=parseInt(i.substring(4,6),16);return Math.abs(s-c)<=n&&Math.abs(o-u)<=n&&Math.abs(l-d)<=n}function MO(t,e,n,r){if(r)return"External";const i=String.fromCharCode(65+(t>=128?t-128:t));return n?`HT-${i}`:`AMS-${i} Slot ${e+1}`}function nC(t,e,n){return n?254+e:t>=128?t:t*4+e}function yG(t){if(!t)return!1;const e=Date.now()+4320*60*60*1e3;return(er(t)?.getTime()??0)>e}function ST(t){const e=[],n=t?.ams_extruder_map,r=n&&Object.keys(n).length>0;t?.ams?.forEach(i=>{const s=i.tray.length===1;i.tray.forEach(o=>{if(o.tray_type){const l=xG(o.tray_color);e.push({type:o.tray_type,color:l,colorName:Ff(l),amsId:i.id,trayId:o.id,isHt:s,isExternal:!1,label:MO(i.id,o.id,s,!1),globalTrayId:nC(i.id,o.id,!1),trayInfoIdx:o.tray_info_idx||"",extruderId:n?.[String(i.id)]})}})});for(const i of t?.vt_tray??[])if(i.tray_type){const s=xG(i.tray_color),o=i.id??254,l=(t?.vt_tray?.length??0)>1;e.push({type:i.tray_type,color:s,colorName:Ff(s),amsId:-1,trayId:o-254,isHt:!1,isExternal:!0,label:l?o===254?"Ext-L":"Ext-R":"External",globalTrayId:o,trayInfoIdx:i.tray_info_idx||"",extruderId:r?255-o:void 0})}return e}function vG(t,e){if(!t?.filaments||t.filaments.length===0)return;const n=ST(e);if(n.length===0)return;const r=new Set,i=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,h,f,p;if(c){const v=u.filter(g=>g.trayInfoIdx===c);v.length===1?d=v[0]:v.length>1&&(h=v.find(g=>g.type?.toUpperCase()===l.type?.toUpperCase()&&Fa(g.color)===Fa(l.color)),h||(f=v.find(g=>g.type?.toUpperCase()===l.type?.toUpperCase()&&Bc(g.color,l.color))),!h&&!f&&(p=v.find(g=>g.type?.toUpperCase()===l.type?.toUpperCase())))}!d&&!h&&!f&&!p&&(h=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&Fa(v.color)===Fa(l.color)),h||(f=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&Bc(v.color,l.color))),!h&&!f&&(p=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase())));const x=d||h||f||p||void 0;return x&&r.add(x.globalTrayId),{slot_id:l.slot_id,globalTrayId:x?.globalTrayId??-1}}),s=Math.max(...i.map(l=>l.slot_id||0));if(s<=0)return;const o=new Array(s).fill(-1);return i.forEach(l=>{l.slot_id&&l.slot_id>0&&(o[l.slot_id-1]=l.globalTrayId)}),o}function j$e(t){return w.useMemo(()=>ST(t),[t])}function $ne(t,e,n){const r=j$e(e),i=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 M=n[d],C=r.find(R=>R.globalTrayId===M);if(C){const R=C.type?.toUpperCase()===u.type?.toUpperCase(),A=Fa(C.color)===Fa(u.color)||Bc(C.color,u.color);let D;return R&&A?D="match":R?D="type_only":D="mismatch",{...u,loaded:C,hasFilament:!0,typeMatch:R,colorMatch:A,status:D,isManual:!0}}}const h=u.tray_info_idx||"";let f=r.filter(M=>!c.has(M.globalTrayId));u.nozzle_id!=null&&(f=f.filter(M=>M.extruderId===u.nozzle_id));let p,x,v,g;if(h){const M=f.filter(C=>C.trayInfoIdx===h);M.length===1?p=M[0]:M.length>1&&(x=M.find(C=>C.type?.toUpperCase()===u.type?.toUpperCase()&&Fa(C.color)===Fa(u.color)),x||(v=M.find(C=>C.type?.toUpperCase()===u.type?.toUpperCase()&&Bc(C.color,u.color))),!x&&!v&&(g=M.find(C=>C.type?.toUpperCase()===u.type?.toUpperCase())))}!p&&!x&&!v&&!g&&(x=f.find(M=>M.type?.toUpperCase()===u.type?.toUpperCase()&&Fa(M.color)===Fa(u.color)),x||(v=f.find(M=>M.type?.toUpperCase()===u.type?.toUpperCase()&&Bc(M.color,u.color))),!x&&!v&&(g=f.find(M=>M.type?.toUpperCase()===u.type?.toUpperCase())));const y=p||x||v||g||void 0;y&&c.add(y.globalTrayId);const _=!!y,N=_,T=!!p||!!x||!!v;let k;return p||x||v?k="match":g?k="type_only":k="mismatch",{...u,loaded:y,hasFilament:_,typeMatch:N,colorMatch:T,status:k,isManual:!1}})},[t,r,n]),s=w.useMemo(()=>{if(i.length===0)return;const c=Math.max(...i.map(d=>d.slot_id||0));if(c<=0)return;const u=new Array(c).fill(-1);return i.forEach(d=>{d.slot_id&&d.slot_id>0&&(u[d.slot_id-1]=d.loaded?.globalTrayId??-1)}),u},[i]),o=i.some(c=>c.status==="mismatch"),l=i.some(c=>c.status==="type_only");return{loadedFilaments:r,filamentComparison:i,amsMapping:s,hasTypeMismatch:o,hasColorMismatch:l}}function E$e(t,e,n){if(!t||t.length===0)return{exactMatches:0,typeOnlyMatches:0,missingTypes:0,totalSlots:0,status:"full"};let r=0,i=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 g=n[d],y=e.find(_=>_.globalTrayId===g);if(y){const _=y.type?.toUpperCase()===u.type?.toUpperCase(),N=Fa(y.color)===Fa(u.color)||Bc(y.color,u.color);_&&N?r++:_?i++:s++;continue}}let h=e.filter(g=>!o.has(g.globalTrayId));if(u.nozzle_id!=null){const g=h.filter(y=>y.extruderId===u.nozzle_id);g.length>0&&(h=g)}const f=h.find(g=>g.type?.toUpperCase()===u.type?.toUpperCase()&&Fa(g.color)===Fa(u.color)),p=f?void 0:h.find(g=>g.type?.toUpperCase()===u.type?.toUpperCase()&&Bc(g.color,u.color)),x=f||p?void 0:h.find(g=>g.type?.toUpperCase()===u.type?.toUpperCase()),v=f??p??x;v&&o.add(v.globalTrayId),f||p?r++:x?i++:s++}const l=t.length;let c="full";return s>0?c="missing":i>0&&(c="partial"),{exactMatches:r,typeOnlyMatches:i,missingTypes:s,totalSlots:l,status:c}}function D$e(t,e,n){if(!t?.filaments||t.filaments.length===0)return;const r=ST(e);if(r.length===0)return;const i=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=>!i.has(v.globalTrayId));if(c.nozzle_id!=null){const v=d.filter(g=>g.extruderId===c.nozzle_id);v.length>0&&(d=v)}const h=d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&Fa(v.color)===Fa(c.color)),f=h?void 0:d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&Bc(v.color,c.color)),p=h||f?void 0:d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()),x=h??f??p;x&&i.add(x.globalTrayId),s.push({slot_id:u,globalTrayId:x?.globalTrayId??-1})}const o=Math.max(...s.map(c=>c.slot_id||0));if(o<=0)return;const l=new Array(o).fill(-1);return s.forEach(c=>{c.slot_id&&c.slot_id>0&&(l[c.slot_id-1]=c.globalTrayId)}),l}const wG={useDefault:!0,manualMappings:{},autoConfigured:!1};function R$e(t,e,n,r,i,s){const o=rx({queries:t.map(x=>({queryKey:["printer-status",x],queryFn:()=>ge.getPrinterStatus(x),enabled:t.length>0,staleTime:5e3}))}),l=w.useMemo(()=>t.map((x,v)=>{const g=o[v],y=g?.data,N=e?.find(D=>D.id===x)?.name||`Printer ${x}`,T=ST(y),k=i[x]||wG,M=vG(n,y),C=k.useDefault?r:k.manualMappings,R=D$e(n,y,C),A=E$e(n?.filaments,T,C);return{printerId:x,printerName:N,status:y,isLoading:g?.isLoading??!1,loadedFilaments:T,autoMapping:M,finalMapping:R,matchStatus:A.status,exactMatches:A.exactMatches,typeOnlyMatches:A.typeOnlyMatches,missingTypes:A.missingTypes,totalSlots:A.totalSlots,config:k}}),[t,o,e,n,i,r]),c=o.some(x=>x.isLoading),u=(x,v)=>{s(g=>({...g,[x]:{...g[x]||wG,...v}}))},d=x=>{const v=l.find(_=>_.printerId===x);if(!v||!v.status||!n?.filaments)return;const g=vG(n,v.status);if(!g)return;const y={};g.forEach((_,N)=>{_!==-1&&(y[N+1]=_)}),u(x,{useDefault:!1,manualMappings:y,autoConfigured:!0})},h=()=>{for(const x of t)d(x)},f=x=>l.find(g=>g.printerId===x)?.finalMapping,p=l.every(x=>x.matchStatus!=="missing");return{printerResults:l,isLoading:c,perPrinterConfigs:i,updatePrinterConfig:u,autoConfigureAll:h,autoConfigurePrinter:d,getFinalMapping:f,allPrintersReady:p}}const F$e={USD:"$",EUR:"€",GBP:"£",CHF:"Fr.",JPY:"¥",CNY:"¥",CAD:"$",AUD:"$",INR:"₹",HKD:"HK$",KRW:"₩",SEK:"kr",NOK:"kr",DKK:"kr",PLN:"zł",BRL:"R$",TWD:"NT$",SGD:"S$",NZD:"NZ$",MXN:"MX$",CZK:"Kč",THB:"฿",ZAR:"R",TRY:"₺",RUB:"₽"};function sl(t){return F$e[t.toUpperCase()]||t}const L$e=[{code:"USD",label:"USD ($)"},{code:"EUR",label:"EUR (€)"},{code:"GBP",label:"GBP (£)"},{code:"CHF",label:"CHF (Fr.)"},{code:"JPY",label:"JPY (¥)"},{code:"CNY",label:"CNY (¥)"},{code:"CAD",label:"CAD ($)"},{code:"AUD",label:"AUD ($)"},{code:"INR",label:"INR (₹)"},{code:"HKD",label:"HKD (HK$)"},{code:"KRW",label:"KRW (₩)"},{code:"SEK",label:"SEK (kr)"},{code:"NOK",label:"NOK (kr)"},{code:"DKK",label:"DKK (kr)"},{code:"PLN",label:"PLN (zł)"},{code:"BRL",label:"BRL (R$)"},{code:"TWD",label:"TWD (NT$)"},{code:"SGD",label:"SGD (S$)"},{code:"NZD",label:"NZD (NZ$)"},{code:"MXN",label:"MXN (MX$)"},{code:"CZK",label:"CZK (Kč)"},{code:"THB",label:"THB (฿)"},{code:"ZAR",label:"ZAR (R)"},{code:"TRY",label:"TRY (₺)"},{code:"RUB",label:"RUB (₽)"}];function O$e({printerId:t,filamentReqs:e,manualMappings:n,onManualMappingChange:r,currencySymbol:i,defaultCostPerKg:s,defaultExpanded:o=!1}){const{t:l}=jt(),c=Jt(),[u,d]=w.useState(!1),[h,f]=w.useState(o),{data:p}=Je({queryKey:["printer-status",t],queryFn:()=>ge.getPrinterStatus(t),enabled:!!t}),{data:x}=Je({queryKey:["spool-assignments",t],queryFn:()=>ge.getAssignments(t),enabled:!!t}),{loadedFilaments:v,filamentComparison:g,hasTypeMismatch:y,hasColorMismatch:_}=$ne(e,p,n),N=w.useMemo(()=>{const U=new Map;for(const W of x||[]){const L=W.ams_id===255,te=nC(W.ams_id,W.tray_id,L);U.set(te,W.spool?.cost_per_kg??null)}return U},[x]),T=w.useMemo(()=>{const U=new Map;for(const W of x||[]){const L=W.ams_id===255,te=nC(W.ams_id,W.tray_id,L),ie=W.spool;if(!ie){U.set(te,null);continue}U.set(te,Math.max(0,Math.round((ie.label_weight??0)-(ie.weight_used??0))))}return U},[x]),k=w.useMemo(()=>{let U=0;for(const W of g){const L=W.loaded?.globalTrayId;if(L==null)continue;const ie=N.get(L)??null??s;ie>0&&(U+=W.used_grams/1e3*ie)}return U},[g,N,s]),M=w.useMemo(()=>Array.from(N.values()).some(U=>U!=null&&U>0),[N]),C=e?.filaments&&e.filaments.length>0,R=e?.filaments?.some(U=>U.nozzle_id!=null)??!1;if(!C||!p)return null;const A=y?"#f97316":_?"#facc15":"#00ae42",D=(U,W)=>{if(U>0)if(W===""){const L={...n};delete L[U],r(L)}else r({...n,[U]:parseInt(W,10)})},V=async()=>{d(!0);try{await ge.refreshPrinterStatus(t),await new Promise(U=>setTimeout(U,500)),await c.refetchQueries({queryKey:["printer-status",t]})}finally{d(!1)}};return a.jsxs("div",{className:"mb-4",children:[a.jsxs("button",{type:"button",onClick:()=>f(!h),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[a.jsx(R1,{className:"w-4 h-4",fill:A,stroke:"none"}),a.jsx("span",{children:l("printModal.filamentMapping")}),y?a.jsx("span",{className:"text-xs text-orange-400",children:"(Type not found)"}):_?a.jsx("span",{className:"text-xs text-yellow-400",children:"(Color mismatch)"}):a.jsx("span",{className:"text-xs text-bambu-green",children:"(Ready)"}),h?a.jsx(Sl,{className:"w-4 h-4 ml-auto"}):a.jsx(Fn,{className:"w-4 h-4 ml-auto"})]}),h&&a.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Click to change slot assignment"}),a.jsxs("button",{type:"button",onClick:V,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:[a.jsx(vr,{className:`w-3 h-3 ${u?"animate-spin":""}`}),a.jsx("span",{children:"Re-read"})]})]}),g.map((U,W)=>a.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[a.jsx("span",{title:`Required: ${U.type} - ${Ff(U.color)}`,children:a.jsx(R1,{className:"w-3 h-3",fill:U.color,stroke:U.color})}),a.jsxs("span",{className:"text-white truncate flex items-center gap-1",children:[R&&U.nozzle_id!=null&&a.jsx("span",{className:"inline-flex items-center justify-center w-3.5 h-3.5 rounded text-[9px] font-bold leading-none bg-bambu-gray/20 text-bambu-gray shrink-0",title:U.nozzle_id===1?l("printModal.leftNozzleTooltip"):l("printModal.rightNozzleTooltip"),children:U.nozzle_id===1?l("printModal.leftNozzle"):l("printModal.rightNozzle")}),U.type," ",a.jsxs("span",{className:"text-bambu-gray",children:["(",U.used_grams,"g)"]})]}),a.jsx("span",{className:"text-bambu-gray",children:"→"}),a.jsxs("select",{value:U.loaded?.globalTrayId??"",onChange:L=>D(U.slot_id||0,L.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${U.status==="match"?"border-bambu-green/50 text-bambu-green":U.status==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${U.isManual?"ring-1 ring-blue-400/50":""}`,title:U.isManual?"Manually selected":"Auto-matched",children:[a.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),v.filter(L=>U.nozzle_id==null||L.extruderId===U.nozzle_id).map(L=>{const te=T.get(L.globalTrayId),ie=te!=null?l("printModal.slotRemainingShort",{grams:te,defaultValue:` - ${te}g left`}):"";return a.jsxs("option",{value:L.globalTrayId,className:"bg-bambu-dark text-white",children:[L.label,": ",L.type," (",L.colorName,")",ie]},L.globalTrayId)})]}),U.status==="match"?a.jsx(Vr,{className:"w-3 h-3 text-bambu-green"}):U.status==="type_only"?a.jsx("span",{title:"Same type, different color",children:a.jsx(Pn,{className:"w-3 h-3 text-yellow-400"})}):a.jsx("span",{title:"Filament type not loaded",children:a.jsx(Pn,{className:"w-3 h-3 text-orange-400"})})]},W)),a.jsxs("div",{className:"text-xs text-bambu-gray",children:[l("printModal.totalCost")," ",a.jsx("span",{className:"text-white",children:k>0||M?`${i}${k.toFixed(2)}`:"N/A"})]}),y&&a.jsx("p",{className:"text-xs text-orange-400 mt-2",children:"Required filament type not found in printer."})]})]})}function I$e({filamentReqs:t,availableFilaments:e,overrides:n,onChange:r}){const{t:i}=jt(),s=w.useMemo(()=>{const c={};for(const u of e){const d=u.type.toUpperCase();c[d]||(c[d]=[]),c[d].push(u)}return c},[e]),o=t?.filaments;if(!o||o.length===0||e.length===0)return null;const l=(c,u)=>{if(u===""){const d={...n};delete d[c],r(d)}else{const[d,h]=u.split("|");r({...n,[c]:{type:d,color:h}})}};return a.jsxs("div",{className:"mb-4",children:[a.jsx("div",{className:"flex items-center gap-2 text-sm text-bambu-gray mb-2",children:a.jsx("span",{children:i("printModal.filamentOverride")})}),a.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:i("printModal.filamentOverrideHint")}),a.jsx("div",{className:"bg-bambu-dark rounded-lg p-3 space-y-2",children:o.map(c=>{const u=n[c.slot_id],d=!!u,h=s[c.type.toUpperCase()]||[],f=c.nozzle_id!=null?h.filter(p=>p.extruder_id==null||p.extruder_id===c.nozzle_id):h;return a.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 20px"},children:[a.jsx("span",{title:`${i("printModal.originalFilament")}: ${c.type} - ${Ff(c.color)}`,children:a.jsx(R1,{className:"w-3 h-3",fill:c.color,stroke:c.color})}),a.jsxs("span",{className:"text-white truncate",children:[c.type," ",a.jsxs("span",{className:"text-bambu-gray",children:["(",c.used_grams,"g)"]})]}),a.jsx("span",{className:"text-bambu-gray",children:"→"}),a.jsxs("select",{value:d?`${u.type}|${u.color}`:"",onChange:p=>l(c.slot_id,p.target.value),disabled:f.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 ${d?"border-blue-400/50 text-blue-400":"border-bambu-gray/30 text-bambu-gray"}`,children:[a.jsxs("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:[i("printModal.originalFilament"),": ",c.type," (",Ff(c.color),")"]}),f.map((p,x)=>a.jsxs("option",{value:`${p.type}|${p.color}`,className:"bg-bambu-dark text-white",children:[p.type," (",Ff(p.color),")"]},`${p.type}-${p.color}-${x}`))]}),d?a.jsx("button",{type:"button",onClick:()=>l(c.slot_id,""),className:"text-bambu-gray hover:text-white transition-colors",title:i("printModal.resetToOriginal"),children:a.jsx(lo,{className:"w-3 h-3"})}):a.jsx("span",{className:"w-3"})]},c.slot_id)})})]})}function z$e({plates:t,isMultiPlate:e,selectedPlate:n,onSelect:r}){return!e||t.length<=1?null:a.jsxs("div",{className:"mb-4",children:[a.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[a.jsx(Va,{className:"w-4 h-4 text-bambu-gray"}),a.jsx("span",{className:"text-sm text-bambu-gray",children:"Select Plate to Print"}),!n&&a.jsxs("span",{className:"text-xs text-orange-400 flex items-center gap-1",children:[a.jsx(Pn,{className:"w-3 h-3"}),"Selection required"]})]}),a.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map(i=>a.jsxs("button",{type:"button",onClick:()=>r(i.index),className:`flex items-center gap-2 p-2 rounded-lg border transition-colors text-left ${n===i.index?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"}`,children:[i.has_thumbnail&&i.thumbnail_url!=null?a.jsx("img",{src:i.thumbnail_url,alt:`Plate ${i.index}`,className:"w-10 h-10 rounded object-cover bg-bambu-dark-tertiary"}):a.jsx("div",{className:"w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center",children:a.jsx(Va,{className:"w-5 h-5 text-bambu-gray"})}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("p",{className:"text-sm text-white font-medium truncate",children:i.name||`Plate ${i.index}`}),a.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[i.objects.length>0?i.objects.slice(0,3).join(", ")+(i.objects.length>3?"...":""):`${i.filaments.length} filament${i.filaments.length!==1?"s":""}`,i.print_time_seconds!=null?` • ${js(i.print_time_seconds)}`:""]})]}),n===i.index&&a.jsx(Vr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]},i.index))})]})}function U$e({printerResult:t,filamentReqs:e,onUpdateConfig:n}){const r=Jt(),[i,s]=w.useState(!1),o=(u,d)=>{if(u<=0)return;const h={...t.config.manualMappings};d===""?delete h[u]:h[u]=parseInt(d,10),n({useDefault:!1,manualMappings:h,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,h=t.config.manualMappings[d];let f,p=!1;if(h!==void 0)f=t.loadedFilaments.find(v=>v.globalTrayId===h),p=!0;else{const v=new Set(Object.values(t.config.manualMappings)),g=t.loadedFilaments.find(N=>!v.has(N.globalTrayId)&&N.type?.toUpperCase()===u.type?.toUpperCase()&&Fa(N.color)===Fa(u.color)),y=g?void 0:t.loadedFilaments.find(N=>!v.has(N.globalTrayId)&&N.type?.toUpperCase()===u.type?.toUpperCase()&&Bc(N.color,u.color)),_=g||y?void 0:t.loadedFilaments.find(N=>!v.has(N.globalTrayId)&&N.type?.toUpperCase()===u.type?.toUpperCase());f=g??y??_}let x="mismatch";if(f){const v=f.type?.toUpperCase()===u.type?.toUpperCase(),g=Fa(f.color)===Fa(u.color)||Bc(f.color,u.color);v&&g?x="match":v&&(x="type_only")}return{req:u,loaded:f,status:x,isManual:p}});return a.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom slot mapping"}),a.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:i,children:[a.jsx(vr,{className:`w-3 h-3 ${i?"animate-spin":""}`}),a.jsx("span",{children:"Re-read"})]})]}),c.map(({req:u,loaded:d,status:h,isManual:f},p)=>a.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[a.jsx("span",{title:`Required: ${u.type} - ${Ff(u.color)}`,children:a.jsx(R1,{className:"w-3 h-3",fill:u.color,stroke:u.color})}),a.jsxs("span",{className:"text-white truncate",children:[u.type," ",a.jsxs("span",{className:"text-bambu-gray",children:["(",u.used_grams,"g)"]})]}),a.jsx("span",{className:"text-bambu-gray",children:"→"}),a.jsxs("select",{value:d?.globalTrayId??"",onChange:x=>o(u.slot_id||0,x.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${h==="match"?"border-bambu-green/50 text-bambu-green":h==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${f?"ring-1 ring-blue-400/50":""}`,title:f?"Manually selected":"Auto-matched",children:[a.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),t.loadedFilaments.map(x=>a.jsxs("option",{value:x.globalTrayId,className:"bg-bambu-dark text-white",children:[x.label,": ",x.type," (",x.colorName,")"]},x.globalTrayId))]}),h==="match"?a.jsx(Vr,{className:"w-3 h-3 text-bambu-green"}):h==="type_only"?a.jsx("span",{title:"Same type, different color",children:a.jsx(Pn,{className:"w-3 h-3 text-yellow-400"})}):a.jsx("span",{title:"Filament type not loaded",children:a.jsx(Pn,{className:"w-3 h-3 text-orange-400"})})]},p))]})}function B$e({printers:t,selectedPrinterIds:e,onMultiSelect:n,isLoading:r=!1,allowMultiple:i=!1,showInactive:s=!1,printerMappingResults:o,filamentReqs:l,onAutoConfigurePrinter:c,onUpdatePrinterConfig:u,assignmentMode:d="printer",onAssignmentModeChange:h,targetModel:f,onTargetModelChange:p,targetLocation:x,onTargetLocationChange:v,slicedForModel:g}){const[y,_]=w.useState(!1),N=s?t:t.filter(X=>X.is_active),T=w.useMemo(()=>{if(d!=="printer"||!g||y)return N;const X=N.filter(se=>se.model===g);return X.length>0?X:N},[N,d,g,y]),k=N.length-T.length,M=w.useMemo(()=>{const X=N.map(se=>se.model).filter(se=>!!se);return[...new Set(X)].sort()},[N]),C=w.useMemo(()=>{if(!f)return[];const X=N.filter(se=>se.model===f&&se.location).map(se=>se.location).filter(se=>!!se);return[...new Set(X)].sort()},[N,f]),R=h&&p&&M.length>0,A=i&&e.length>1&&o&&l?.filaments&&l.filaments.length>0&&c&&u;if(r)return a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(T.length===0)return a.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm mb-4",children:[a.jsx($a,{className:"w-4 h-4"}),"No ",s?"":"active ","printers available"]});const D=X=>{i?e.includes(X)?n(e.filter(se=>se!==X)):n([...e,X]):n([X])},V=()=>{n(T.map(X=>X.id))},U=()=>{n([])},W=(X,se,ue)=>{ue.stopPropagation(),!(!c||!u)&&(se?c(X):u(X,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},L=X=>e.includes(X),te=e.length,ie=X=>o?.find(se=>se.printerId===X);return a.jsxs("div",{className:"space-y-2 mb-6",children:[R&&a.jsxs("div",{className:"flex gap-2 mb-4",children:[a.jsxs("button",{type:"button",onClick:()=>{h("printer"),p(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${d==="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:[a.jsx(wr,{className:"w-4 h-4"}),a.jsx("span",{className:"text-sm",children:"Specific Printer"})]}),a.jsxs("button",{type:"button",onClick:()=>{h("model"),n([]);const X=g&&M.includes(g)?g:M[0];p(X)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${d==="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:[a.jsx(vh,{className:"w-4 h-4"}),a.jsxs("span",{className:"text-sm",children:["Any ",g||"Model"]})]})]}),d==="model"&&R&&a.jsxs("div",{className:"space-y-3 mb-4",children:[!g&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Target Model"}),a.jsxs("select",{value:f||"",onChange:X=>{p(X.target.value||null),v&&v(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:[a.jsx("option",{value:"",children:"Select a model..."}),M.map(X=>a.jsx("option",{value:X,children:X},X))]})]}),f&&C.length>0&&v&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Location Filter (optional)"}),a.jsxs("select",{value:x||"",onChange:X=>v(X.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:[a.jsx("option",{value:"",children:"Any location"}),C.map(X=>a.jsx("option",{value:X,children:X},X))]})]}),f&&a.jsxs("p",{className:"text-xs text-bambu-gray",children:["Scheduler will assign to first available idle ",f," printer",x?` in ${x}`:""]})]}),d==="printer"&&i&&T.length>1&&a.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray mb-2",children:[a.jsx("span",{children:te===0?"Select printers":`${te} printer${te!==1?"s":""} selected`}),a.jsxs("div",{className:"flex gap-2",children:[te0&&a.jsx("button",{type:"button",onClick:U,className:"text-bambu-gray hover:text-white transition-colors",children:"Clear"})]})]}),d==="printer"&&T.map(X=>{const se=L(X.id),ue=ie(X.id),he=ue&&!ue.config.useDefault;return a.jsxs("div",{children:[a.jsxs("button",{type:"button",onClick:()=>D(X.id),className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${se?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"} ${X.is_active?"":"opacity-60"}`,children:[a.jsx("div",{className:`p-2 rounded-lg ${se?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:a.jsx(wr,{className:`w-5 h-5 ${se?"text-bambu-green":"text-bambu-gray"}`})}),a.jsxs("div",{className:"text-left flex-1",children:[a.jsxs("p",{className:"text-white font-medium",children:[X.name,!X.is_active&&a.jsx("span",{className:"text-bambu-gray text-xs ml-2",children:"(inactive)"})]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[X.model||"Unknown model"," • ",X.ip_address]})]}),i&&a.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${se?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:se&&a.jsx(Vr,{className:"w-3 h-3 text-white"})})]}),se&&A&&ue&&a.jsxs("div",{className:"ml-4 mt-2 mb-3",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",onClick:Q=>Q.stopPropagation(),children:[a.jsx("input",{type:"checkbox",checked:he,onChange:Q=>W(X.id,Q.target.checked,Q),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"}),a.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom mapping"})]}),a.jsxs("span",{className:`text-xs ml-2 ${ue.matchStatus==="full"?"text-bambu-green":ue.matchStatus==="partial"?"text-yellow-400":"text-orange-400"}`,children:["(",ue.exactMatches,"/",ue.totalSlots," matched)"]}),ue.isLoading&&a.jsx(vr,{className:"w-3 h-3 text-bambu-gray animate-spin"}),he&&a.jsxs("button",{type:"button",onClick:Q=>{Q.stopPropagation(),c(X.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:[a.jsx(Rge,{className:"w-3 h-3"}),"Auto"]})]}),he&&a.jsx(U$e,{printerResult:ue,filamentReqs:l.filaments,onUpdateConfig:Q=>u(X.id,Q)})]})]},X.id)}),d==="printer"&&k>0&&!y&&a.jsxs("button",{type:"button",onClick:()=>_(!0),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2 flex items-center gap-1",children:[a.jsx(Pn,{className:"w-3 h-3 text-yellow-400"}),k," other printer",k>1?"s":""," hidden (different model) —",a.jsx("span",{className:"underline",children:"show all"})]}),d==="printer"&&y&&g&&a.jsx("button",{type:"button",onClick:()=>_(!1),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2",children:a.jsxs("span",{className:"underline",children:["Show only ",g," printers"]})}),d==="printer"&&te===0&&a.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[a.jsx($a,{className:"w-3 h-3"}),"Select at least one printer"]}),d==="model"&&!f&&a.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[a.jsx($a,{className:"w-3 h-3"}),"Select a target printer model"]})]})}const H$e=[{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 $$e({options:t,onChange:e,defaultExpanded:n=!1}){const[r,i]=w.useState(n),s=o=>{e({...t,[o]:!t[o]})};return a.jsxs("div",{className:"mb-4",children:[a.jsxs("button",{type:"button",onClick:()=>i(!r),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[a.jsx(mk,{className:"w-4 h-4"}),a.jsx("span",{children:"Print Options"}),r?a.jsx(Sl,{className:"w-4 h-4 ml-auto"}):a.jsx(Fn,{className:"w-4 h-4 ml-auto"})]}),r&&a.jsx("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:H$e.map(({key:o,label:l,desc:c})=>a.jsxs("label",{className:"flex items-center justify-between cursor-pointer group",children:[a.jsxs("div",{children:[a.jsx("span",{className:"text-sm text-white",children:l}),a.jsx("p",{className:"text-xs text-bambu-gray",children:c})]}),a.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:a.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 q$e({options:t,onChange:e,dateFormat:n="system",timeFormat:r="system",canControlPrinter:i=!0}){const[s,o]=w.useState(""),[l,c]=w.useState(""),[u,d]=w.useState(!0),[h,f]=w.useState(!0),p=w.useRef(null),x=w.useRef(!1);w.useEffect(()=>{if(t.scheduleType!=="scheduled"){x.current=!1;return}if(!x.current){x.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:A3(k)})),o(T3(k,n)),c(a8(k,r)),d(!0),f(!0)}},[t.scheduleType,t.scheduledTime,n,r,e,t]);const v=k=>{e({...t,scheduleType:k})},g=(k,M)=>{const C=nbe(k,n),R=rbe(M);d(!!C),f(!!R),C&&R&&(C.setHours(R.hours,R.minutes,0,0),C>new Date&&e({...t,scheduledTime:A3(C)}))},y=k=>{o(k),g(k,l)},_=k=>{c(k),g(s,k)},N=k=>{const M=k.target.value;if(M){const C=new Date(M);isNaN(C.getTime())||(o(T3(C,n)),c(a8(C,r)),d(!0),f(!0),e({...t,scheduledTime:M}))}},T=()=>{p.current?.showPicker()};return a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"When to print"}),a.jsxs("div",{className:"flex gap-2",children:[a.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:[a.jsx(Qn,{className:"w-4 h-4"}),"ASAP"]}),a.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:[a.jsx(Xr,{className:"w-4 h-4"}),"Scheduled"]}),a.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:[a.jsx(HY,{className:"w-4 h-4"}),"Queue Only"]})]})]}),t.scheduleType==="scheduled"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date & Time"}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("div",{className:"flex-1 relative",children:[a.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=>y(k.target.value),placeholder:ebe(n)}),a.jsx("button",{type:"button",onClick:T,className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",title:"Open calendar",children:a.jsx(Xr,{className:"w-4 h-4"})})]}),a.jsx("div",{className:"w-32",children:a.jsx("input",{type:"text",className:`w-full px-3 py-2 bg-bambu-dark border rounded-lg text-white focus:outline-none ${h?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:l,onChange:k=>_(k.target.value),placeholder:tbe(r)})})]}),a.jsx("input",{ref:p,type:"datetime-local",className:"sr-only",value:t.scheduledTime,onChange:N,tabIndex:-1}),(!u||!h)&&a.jsx("p",{className:"mt-1 text-xs text-red-400",children:"Please enter a valid date and time"})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.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"}),a.jsx("label",{htmlFor:"requirePrevious",className:"text-sm text-bambu-gray",children:"Only start if previous print succeeded"})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"checkbox",id:"autoOffAfter",checked:t.autoOffAfter,onChange:k=>e({...t,autoOffAfter:k.target.checked}),disabled:!i,className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green disabled:opacity-50"}),a.jsxs("label",{htmlFor:"autoOffAfter",className:`text-sm flex items-center gap-1 ${i?"text-bambu-gray":"text-bambu-gray/50"}`,children:[a.jsx(yd,{className:"w-3.5 h-3.5"}),"Power off printer when done"]})]}),a.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 zg={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1},V$e={scheduleType:"asap",scheduledTime:"",requirePreviousSuccess:!1,autoOffAfter:!1};function Hc({mode:t,archiveId:e,libraryFileId:n,archiveName:r,queueItem:i,initialSelectedPrinterIds:s,onClose:o,onSuccess:l}){const{t:c}=jt(),u=Jt(),{showToast:d}=mn(),{hasPermission:h}=jr(),f=!!n&&!e,[p,x]=w.useState(()=>t==="edit-queue-item"&&i?.printer_id?[i.printer_id]:s?.length?s:[]),[v,g]=w.useState(()=>t==="edit-queue-item"&&i?i.plate_id:null),[y,_]=w.useState(()=>t==="edit-queue-item"&&i?{bed_levelling:i.bed_levelling??zg.bed_levelling,flow_cali:i.flow_cali??zg.flow_cali,vibration_cali:i.vibration_cali??zg.vibration_cali,layer_inspect:i.layer_inspect??zg.layer_inspect,timelapse:i.timelapse??zg.timelapse}:zg),[N,T]=w.useState(()=>{if(t==="edit-queue-item"&&i){let we="asap";i.manual_start?we="manual":i.scheduled_time&&!yG(i.scheduled_time)&&(we="scheduled");let Ge="";if(i.scheduled_time&&!yG(i.scheduled_time)){const nt=er(i.scheduled_time)??new Date;Ge=A3(nt)}return{scheduleType:we,scheduledTime:Ge,requirePreviousSuccess:i.require_previous_success,autoOffAfter:i.auto_off_after}}return V$e}),[k,M]=w.useState(()=>{if(t==="edit-queue-item"&&i?.ams_mapping&&Array.isArray(i.ams_mapping)){const we={};return i.ams_mapping.forEach((Ge,nt)=>{Ge!==-1&&(we[nt+1]=Ge)}),we}return{}}),[C,R]=w.useState({}),[A,D]=w.useState(()=>t==="edit-queue-item"&&i?.target_model?"model":"printer"),[V,U]=w.useState(()=>t==="edit-queue-item"&&i?.target_model?i.target_model:null),[W,L]=w.useState(()=>t==="edit-queue-item"&&i?.target_location?i.target_location:null),[te,ie]=w.useState(()=>{if(t==="edit-queue-item"&&i?.filament_overrides){const we={};for(const Ge of i.filament_overrides)we[Ge.slot_id]={type:Ge.type,color:Ge.color};return we}return{}}),[X]=w.useState(()=>t==="edit-queue-item"&&i?.printer_id?[i.printer_id]:[]),[se]=w.useState(()=>t==="edit-queue-item"&&i?i.plate_id:null),[ue,he]=w.useState(!1),[Q,oe]=w.useState({current:0,total:0}),[fe,be]=w.useState(new Set),Re=p.length,$=p.length>0?p[0]:null,{data:K}=Je({queryKey:["settings"],queryFn:ge.getSettings}),P=sl(K?.currency||"USD"),E=K?.default_filament_cost??0,{data:O,isLoading:G}=Je({queryKey:["printers"],queryFn:ge.getPrinters}),{data:B}=Je({queryKey:["archive",e],queryFn:()=>ge.getArchive(e),enabled:!!e&&!f}),{data:re}=Je({queryKey:["library-file",n],queryFn:()=>ge.getLibraryFile(n),enabled:f&&!!n}),z=B?.sliced_for_model||re?.sliced_for_model||null,{data:q,isError:ee}=Je({queryKey:["archive-plates",e],queryFn:()=>ge.getArchivePlates(e),enabled:!!e&&!f,retry:!1}),{data:J}=Je({queryKey:["library-file-plates",n],queryFn:()=>ge.getLibraryFilePlates(n),enabled:f&&!!n}),ne=f?J:q,{data:ae,isError:de}=Je({queryKey:["archive-filaments",e,v],queryFn:()=>ge.getArchiveFilamentRequirements(e,v??void 0),enabled:!!e&&!f&&(v!==null||!ne?.is_multi_plate),retry:!1}),{data:ye}=Je({queryKey:["library-file-filaments",n,v],queryFn:()=>ge.getLibraryFileFilamentRequirements(n,v??void 0),enabled:f&&!!n&&(v!==null||!ne?.is_multi_plate)}),le=!f&&(ee||de),I=f?ye:ae,F=w.useMemo(()=>{if(!(v===null||!ne?.plates?.length))return ne.plates.find(we=>we.index===v)?.name||void 0},[ne,v]),{data:Z}=Je({queryKey:["available-filaments",V,W],queryFn:()=>ge.getAvailableFilaments(V,W??void 0),enabled:A==="model"&&!!V}),{data:xe}=Je({queryKey:["printer-status",$],queryFn:()=>ge.getPrinterStatus($),enabled:!!$}),{amsMapping:me}=$ne(I,xe,k),ce=R$e(p,O,I,k,C,R);w.useEffect(()=>{ne?.plates&&ne.plates.length>=1&&!v&&g(ne.plates[0].index)},[ne,v]),w.useEffect(()=>{if(t==="edit-queue-item")return;const we=O?.filter(Ge=>Ge.is_active)||[];we.length===1&&p.length===0&&x([we[0].id])},[t,O,p.length]),w.useEffect(()=>{t==="edit-queue-item"?(JSON.stringify(p.sort())!==JSON.stringify(X.sort())||v!==se)&&(M({}),R({}),be(new Set)):(M({}),R({}),be(new Set))},[t,p,v,X,se]);const[Ne,_e]=w.useState(V),[He,$e]=w.useState(v);w.useEffect(()=>{(V!==Ne||v!==He)&&(_e(V),$e(v),(t!=="edit-queue-item"||Ne!==null)&&ie({}))},[V,v,Ne,He,t]),w.useEffect(()=>{if(!K?.per_printer_mapping_expanded||p.length<=1)return;const we=p.filter(Ge=>{if(fe.has(Ge))return!1;const nt=ce.printerResults.find(vt=>vt.printerId===Ge);return nt&&nt.status&&!nt.isLoading});we.length>0&&(be(Ge=>{const nt=new Set(Ge);return we.forEach(vt=>nt.add(vt)),nt}),we.forEach(Ge=>{ce.autoConfigurePrinter(Ge)}))},[K?.per_printer_mapping_expanded,p,fe,ce]),w.useEffect(()=>{const we=Ge=>{Ge.key==="Escape"&&!ue&&o()};return window.addEventListener("keydown",we),()=>window.removeEventListener("keydown",we)},[o,ue]);const Fe=ne?.is_multi_plate??!1,ke=ne?.plates??[],Me=ut({mutationFn:we=>ge.addToQueue(we)}),Ce=ut({mutationFn:we=>ge.updateQueueItem(i.id,we),onSuccess:()=>{u.invalidateQueries({queryKey:["queue"]}),d("Queue item updated"),l?.(),o()},onError:we=>{d(we.message||"Failed to update queue item","error")}}),Pe=async we=>{if(we?.preventDefault(),A==="printer"&&p.length===0){d("Please select at least one printer","error");return}if(A==="model"&&!V){d("Please select a target printer model","error");return}he(!0);const Ge=A==="model"?1:p.length;oe({current:0,total:Ge});const nt={success:0,failed:0,errors:[]},vt=qe=>{if(p.length>1){const mt=C[qe];if(mt&&!mt.useDefault)return ce.getFinalMapping(qe)}return me},_t=Object.keys(te).length>0?Object.entries(te).map(([qe,{type:mt,color:gt}])=>({slot_id:parseInt(qe,10),type:mt,color:gt})):void 0,Nt=qe=>({printer_id:A==="printer"?qe:null,target_model:A==="model"?V:null,target_location:A==="model"?W:null,filament_overrides:A==="model"?_t:void 0,archive_id:f?void 0:e,library_file_id:f?n:void 0,require_previous_success:N.requirePreviousSuccess,auto_off_after:N.autoOffAfter,manual_start:N.scheduleType==="manual",ams_mapping:qe?vt(qe):void 0,plate_id:v,scheduled_time:N.scheduleType==="scheduled"&&N.scheduledTime?new Date(N.scheduledTime).toISOString():void 0,...y});if(A==="model"){oe({current:1,total:1});try{if(t==="reprint"){d("Model-based assignment only works with queue mode","error"),he(!1);return}else if(t==="edit-queue-item"){const qe={printer_id:null,target_model:V,target_location:W,filament_overrides:_t||null,require_previous_success:N.requirePreviousSuccess,auto_off_after:N.autoOffAfter,manual_start:N.scheduleType==="manual",ams_mapping:void 0,plate_id:v,scheduled_time:N.scheduleType==="scheduled"&&N.scheduledTime?new Date(N.scheduledTime).toISOString():null,...y};await Ce.mutateAsync(qe)}else await Me.mutateAsync(Nt(null));nt.success++}catch(qe){nt.failed++,nt.errors.push(qe.message)}}else for(let qe=0;qeen.id===mt)?.name||`Printer ${mt}`;nt.errors.push(`${It}: ${gt.message}`)}}he(!1),nt.failed===0?(t!=="reprint"&&(A==="model"?d(t==="edit-queue-item"?"Queue item updated":`Queued for any ${V}`):t==="edit-queue-item"?d("Queue item updated"):nt.success===1?d("Print queued for printer"):d(`Print queued for ${nt.success} printers`)),u.invalidateQueries({queryKey:["queue"]}),l?.(),o()):nt.success===0?d(`Failed: ${nt.errors[0]}`,"error"):(d(`${nt.success} succeeded, ${nt.failed} failed`,"error"),u.invalidateQueries({queryKey:["queue"]}))},We=ue||Ce.isPending,pe=w.useMemo(()=>!(We||A==="printer"&&p.length===0||A==="model"&&!V||A==="model"&&t==="reprint"||Fe&&!v),[p.length,A,V,t,Fe,v,We]),Te=(()=>{const we=p.length;return t==="reprint"?{title:c(f?"queue.print":"queue.reprint"),icon:wr,submitText:we>1?c("queue.printToPrinters",{count:we}):c("queue.print"),submitIcon:wr,loadingText:Q.total>1?c("queue.sendingProgress",{current:Q.current,total:Q.total}):c("queue.sending")}:t==="add-to-queue"?{title:c("queue.schedulePrint"),icon:Xr,submitText:we>1?c("queue.queueToPrinters",{count:we}):c("queue.addToQueue"),submitIcon:Xr,loadingText:Q.total>1?c("queue.addingProgress",{current:Q.current,total:Q.total}):c("queue.adding")}:{title:c("queue.editQueueItem"),icon:Wa,submitText:c("common.save"),submitIcon:Wa,loadingText:Q.total>1?c("queue.savingProgress",{current:Q.current,total:Q.total}):c("common.saving")}})(),Ve=Te.icon,Ee=Te.submitIcon,De=$&&(f||(Fe?v!==null:!0));return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:ue?void 0:o,children:a.jsx(Tt,{className:"w-full max-w-lg max-h-[90vh] overflow-y-auto",onClick:we=>we.stopPropagation(),children:a.jsxs(At,{className:t==="reprint"?"":"p-0",children:[a.jsxs("div",{className:`flex items-center justify-between ${t==="reprint"?"mb-4":"p-4 border-b border-bambu-dark-tertiary"}`,children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ve,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:Te.title})]}),a.jsx(Ie,{variant:"ghost",size:"sm",onClick:o,disabled:ue,children:a.jsx(Bt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:Pe,className:t==="reprint"?"":"p-4 space-y-4",children:[a.jsx("p",{className:`text-sm text-bambu-gray ${t==="reprint"?"mb-4":""}`,children:t==="reprint"?a.jsxs(a.Fragment,{children:["Send ",a.jsx("span",{className:"text-white",children:r})," to"," ",s?.length===1&&O?a.jsx("span",{className:"text-white",children:O.find(we=>we.id===s[0])?.name??"printer(s)"}):"printer(s)"]}):a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"block text-bambu-gray mb-1",children:"Print Job"}),a.jsx("span",{className:"text-white font-medium truncate block",children:r})]})}),a.jsx(z$e,{plates:ke,isMultiPlate:Fe,selectedPlate:v,onSelect:g}),!s?.length&&a.jsx(B$e,{printers:O||[],selectedPrinterIds:p,onMultiSelect:x,isLoading:G,allowMultiple:!0,showInactive:t==="edit-queue-item",printerMappingResults:ce.printerResults,filamentReqs:I,onAutoConfigurePrinter:ce.autoConfigurePrinter,onUpdatePrinterConfig:ce.updatePrinterConfig,assignmentMode:t==="reprint"?"printer":A,onAssignmentModeChange:t!=="reprint"?D:void 0,targetModel:V,onTargetModelChange:t!=="reprint"?U:void 0,targetLocation:W,onTargetLocationChange:t!=="reprint"?L:void 0,slicedForModel:z}),A==="model"&&V&&I&&Z&&Z.length>0&&a.jsx(I$e,{filamentReqs:I,availableFilaments:Z,overrides:te,onChange:ie}),z&&A==="printer"&&p.length===1&&(()=>{const we=O?.find(Ge=>Ge.id===p[0]);return we&&we.model&&z!==we.model?a.jsxs("div",{className:"p-3 mb-2 bg-yellow-500/10 border border-yellow-500/30 rounded-lg flex items-center gap-2",children:[a.jsx(Pn,{className:"w-4 h-4 text-yellow-400 flex-shrink-0"}),a.jsxs("span",{className:"text-sm text-yellow-400",children:["File was sliced for ",z,", but printing on ",we.model]})]}):null})(),le&&a.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:[a.jsx($a,{className:"w-4 h-4 text-orange-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-orange-400",children:"Archive data unavailable. The source file may have been deleted. Filament mapping is disabled."})]}),De&&!le&&p.length===1&&a.jsx(O$e,{printerId:$,filamentReqs:I,manualMappings:k,onManualMappingChange:M,defaultExpanded:!!s?.length||(K?.per_printer_mapping_expanded??!1),currencySymbol:P,defaultCostPerKg:E}),(t==="reprint"||Re>0||A==="model"&&V)&&a.jsx($$e,{options:y,onChange:_,defaultExpanded:!!s?.length}),t!=="reprint"&&a.jsx(q$e,{options:N,onChange:T,dateFormat:K?.date_format||"system",timeFormat:K?.time_format||"system",canControlPrinter:h("printers:control")}),Ce.isError&&a.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"}),a.jsxs("div",{className:`flex gap-3 ${t==="reprint"?"":"pt-2"}`,children:[a.jsx(Ie,{type:"button",variant:"secondary",onClick:o,className:"flex-1",disabled:ue,children:"Cancel"}),a.jsx(Ie,{type:"submit",disabled:!pe,className:"flex-1",children:We?a.jsxs(a.Fragment,{children:[a.jsx(lt,{className:"w-4 h-4 animate-spin"}),Te.loadingText]}):a.jsxs(a.Fragment,{children:[a.jsx(Ee,{className:"w-4 h-4"}),Te.submitText]})})]})]})]})})})}function qne(t){if(!t)return"/img/printers/default.png";const e=t.toLowerCase().replace(/\s+/g,"");return e.includes("x1e")?"/img/printers/x1e.png":e.includes("x1c")||e.includes("x1carbon")||e.includes("x1")?"/img/printers/x1c.png":e.includes("h2dpro")||e.includes("h2d-pro")?"/img/printers/h2dpro.png":e.includes("h2d")?"/img/printers/h2d.png":e.includes("h2c")?"/img/printers/h2c.png":e.includes("h2s")?"/img/printers/h2d.png":e.includes("p2s")||e.includes("p1s")?"/img/printers/p1s.png":e.includes("p1p")?"/img/printers/p1p.png":e.includes("a1mini")?"/img/printers/a1mini.png":e.includes("a1")?"/img/printers/a1.png":"/img/printers/default.png"}function Vne(t){return t>=-50?{labelKey:"printers.wifiSignal.excellent",color:"text-bambu-green",bars:4}:t>=-60?{labelKey:"printers.wifiSignal.good",color:"text-bambu-green",bars:3}:t>=-70?{labelKey:"printers.wifiSignal.fair",color:"text-yellow-400",bars:2}:t>=-80?{labelKey:"printers.wifiSignal.weak",color:"text-orange-400",bars:1}:{labelKey:"printers.wifiSignal.veryWeak",color:"text-red-400",bars:1}}function SG({value:t}){const{t:e}=jt(),[n,r]=w.useState(!1),i=async()=>{try{await navigator.clipboard.writeText(t),r(!0),setTimeout(()=>r(!1),2e3)}catch{}};return a.jsx("button",{onClick:i,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?a.jsx(Vr,{className:"w-3.5 h-3.5 text-bambu-green"}):a.jsx(_l,{className:"w-3.5 h-3.5"})})}function G$e({printer:t,status:e,totalPrintHours:n,onClose:r}){const{t:i}=jt();w.useEffect(()=>{const o=l=>{l.key==="Escape"&&r()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[r]);const s=[];if(s.push({label:i("printers.model"),value:t.model??"—"}),s.push({label:i("common.status"),value:a.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:[a.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${e?.connected?"bg-bambu-green":"bg-red-400"}`}),e?.connected?i("printers.status.available"):i("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:i("printers.state"),value:i(o[e.state]??"printers.status.unknown")})}if(s.push({label:i("printers.ipAddress"),value:a.jsxs("span",{className:"flex items-center",children:[a.jsx("span",{className:"font-mono",children:t.ip_address}),a.jsx(SG,{value:t.ip_address})]})}),s.push({label:i("printers.serialNumber"),value:a.jsxs("span",{className:"flex items-center",children:[a.jsx("span",{className:"font-mono truncate",children:t.serial_number}),a.jsx(SG,{value:t.serial_number})]})}),e?.wifi_signal!=null){const o=Vne(e.wifi_signal);s.push({label:i("printers.wifiSignalLabel"),value:a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsx(WY,{className:`w-4 h-4 ${o.color}`}),a.jsx("span",{className:o.color,children:i(o.labelKey)}),a.jsxs("span",{className:"text-bambu-gray text-xs",children:["(",e.wifi_signal," dBm)"]})]})})}return s.push({label:i("printers.firmware"),value:e?.firmware_version??"—"}),e?.developer_mode!=null&&s.push({label:i("printers.developerMode"),value:a.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?i("printers.enabled"):i("printers.disabled")})}),s.push({label:i("printers.nozzleCount"),value:t.nozzle_count}),e?.sdcard!=null&&s.push({label:i("printers.sdCard"),value:a.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?i("printers.inserted"):i("printers.notInserted")})}),s.push({label:i("printers.autoArchive"),value:a.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?i("printers.enabled"):i("printers.disabled")})}),n!=null&&n>0&&s.push({label:i("printers.totalPrintHours"),value:`${Math.round(n)}h`}),t.location&&s.push({label:i("printers.sort.location"),value:t.location}),s.push({label:i("printers.addedOn"),value:Kf(t.created_at)}),a.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:a.jsx(Tt,{className:"w-full max-w-md",onClick:o=>o.stopPropagation(),children:a.jsxs(At,{children:[a.jsxs("div",{className:"flex items-center justify-between mb-4",children:[a.jsx("h2",{className:"text-lg font-semibold text-white",children:t.name}),a.jsx("button",{onClick:r,className:"p-1 hover:bg-bambu-dark rounded flex-shrink-0",children:a.jsx(Bt,{className:"w-5 h-5 text-bambu-gray"})})]}),a.jsx("div",{className:"flex justify-center mb-4",children:a.jsx("img",{src:qne(t.model),alt:t.model??t.name,className:"h-24 object-contain"})}),a.jsx("div",{className:"space-y-0",children:s.map((o,l)=>a.jsxs("div",{className:"flex items-center justify-between gap-4 py-2.5 border-b border-bambu-dark-tertiary last:border-0",children:[a.jsx("span",{className:"text-sm text-bambu-gray whitespace-nowrap",children:o.label}),a.jsx("span",{className:"text-sm text-white text-right",children:o.value})]},l))})]})})})}const _G={"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"},W$e={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 nE(t){if(!t)return null;if(_G[t])return _G[t];const e=t.split("-");if(e.length<2)return null;const n=e[1];return W$e[n]||null}function rE(t){if(!t||t.length<6)return"Unknown";const e=parseInt(t.substring(0,2),16),n=parseInt(t.substring(2,4),16),r=parseInt(t.substring(4,6),16),i=Math.max(e,n,r)/255,s=Math.min(e,n,r)/255,o=(i+s)/2;let l=0,c=0;if(i!==s){const u=i-s;c=o>.5?u/(2-i-s):u/(i+s);const d=e/255,h=n/255,f=r/255;i===d?l=((h-f)/u+(h.85?"White":c<.15?o<.4?"Dark Gray":o>.6?"Light Gray":"Gray":l>=15&&l<45&&o<.45||l>=45&&l<70&&o<.4?"Brown":l<15||l>=345?"Red":l<45?"Orange":l<70?"Yellow":l<150?"Green":l<200?"Cyan":l<260?"Blue":l<290?"Purple":"Pink"}function aE(t){return(t??.02).toFixed(3)}function NG({side:t}){const{mode:e}=bp(),n=e==="dark"?"#1a4d2e":"#e7f5e9";return a.jsx("span",{className:"inline-flex items-center justify-center w-4 h-4 text-[10px] font-bold rounded",style:{backgroundColor:n,color:"#00ae42"},children:t})}function jO(t){if(!t||t==="00000000"||t.length<6)return null;const e=t.slice(0,2),n=t.slice(2,4),r=t.slice(4,6),i=t.length>=8?parseInt(t.slice(6,8),16)/255:1;return i===0?null:`rgba(${parseInt(e,16)}, ${parseInt(n,16)}, ${parseInt(r,16)}, ${i})`}function K$e(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 Gne(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 Wne(t,e){return t?t.startsWith("HH")?e("printers.nozzleHighFlow"):t.startsWith("HS")?e("printers.nozzleStandardFlow"):"":""}function Kne({slot:t,index:e,activeStatus:n,filamentName:r,children:i}){const{t:s}=jt(),[o,l]=w.useState(!1),[c,u]=w.useState("top"),d=w.useRef(null),h=w.useRef(null),f=w.useRef(null),p=!t.nozzle_diameter&&!t.nozzle_type,x=t.stat===1;w.useEffect(()=>{if(o&&d.current&&h.current){const T=d.current.getBoundingClientRect(),k=h.current.offsetHeight,C=T.top-56,R=window.innerHeight-T.bottom;CC?u("bottom"):u("top")}},[o]);const v=()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>l(!0),80)},g=()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>l(!1),100)};w.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]);const y=jO(t.filament_color),_=Gne(t.nozzle_type,s),N=Wne(t.nozzle_type,s);return a.jsxs("div",{ref:d,className:"relative",onMouseEnter:v,onMouseLeave:g,children:[i,o&&a.jsxs("div",{ref:h,className:` + `})]})]})}function N$e({isOpen:t,onClose:e,tagUid:n,trayUuid:r,printerId:i,amsId:s,trayId:o}){const{t:l}=jt(),c=Jt(),{showToast:u}=mn(),[d,h]=w.useState(""),{data:f,isLoading:p}=Je({queryKey:["inventory-spools"],queryFn:()=>ge.getSpools(!1),enabled:t}),x=w.useMemo(()=>f?f.filter(g=>{if(g.tag_uid||g.tray_uuid)return!1;if(!d)return!0;const y=d.toLowerCase();return g.material.toLowerCase().includes(y)||g.brand&&g.brand.toLowerCase().includes(y)||g.color_name&&g.color_name.toLowerCase().includes(y)}):[],[f,d]),v=ut({mutationFn:g=>ge.linkTagToSpool(g,{tag_uid:n||void 0,tray_uuid:r||void 0,tag_type:r?"bambulab":"generic",data_origin:"nfc_link"}),onSuccess:()=>{c.invalidateQueries({queryKey:["inventory-spools"]}),c.invalidateQueries({queryKey:["inventory-assignments"]}),u(l("inventory.tagLinked"),"success"),e()},onError:g=>{u(g.message||l("inventory.tagLinkFailed"),"error")}});return t?a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[a.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),a.jsxs("div",{className:"relative bg-bambu-dark-secondary rounded-xl shadow-xl w-full max-w-md mx-4 max-h-[80vh] flex flex-col border border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[a.jsxs("div",{children:[a.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(sx,{className:"w-5 h-5 text-bambu-green"}),l("inventory.linkToSpool")]}),a.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["AMS ",s," T",o," · Printer #",i]})]}),a.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:a.jsx(Bt,{className:"w-5 h-5"})})]}),a.jsxs("div",{className:"p-4 border-b border-white/10",children:[a.jsxs("div",{className:"relative",children:[a.jsx(Mr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),a.jsx("input",{type:"text",value:d,onChange:g=>h(g.target.value),placeholder:l("inventory.searchSpools"),className:"w-full pl-9 pr-3 py-2 bg-bambu-dark rounded-lg border border-white/10 text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green"})]}),(n||r)&&a.jsxs("p",{className:"text-xs text-bambu-gray mt-2 font-mono truncate",title:n||r,children:["Tag: ",n||r]})]}),a.jsx("div",{className:"flex-1 overflow-y-auto p-2 min-h-0",children:p?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(lt,{className:"w-6 h-6 animate-spin text-bambu-green"})}):x.length===0?a.jsx("p",{className:"text-center text-bambu-gray py-8 text-sm",children:l("inventory.noSpoolsMatch")}):x.map(g=>a.jsxs("button",{onClick:()=>v.mutate(g.id),disabled:v.isPending,className:"w-full flex items-center gap-3 p-3 rounded-lg hover:bg-white/5 transition-colors text-left",children:[a.jsx("span",{className:"w-6 h-6 rounded-full border border-white/20 flex-shrink-0",style:{backgroundColor:g.rgba?`#${g.rgba.substring(0,6)}`:"#808080"}}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"text-sm text-white font-medium truncate",children:[g.brand?`${g.brand} `:"",g.material,g.subtype?` ${g.subtype}`:""]}),a.jsxs("div",{className:"text-xs text-bambu-gray truncate",children:[g.color_name||"No color"," · #",g.id]})]}),a.jsxs("span",{className:"text-xs text-bambu-gray",children:[Math.round(g.label_weight-g.weight_used),"g"]})]},g.id))}),a.jsx("div",{className:"p-4 border-t border-white/10 flex justify-end",children:a.jsx(Ie,{variant:"ghost",onClick:e,children:l("inventory.cancel")||"Cancel"})})]})]}):null}function C$e({isOpen:t,onClose:e,printerId:n,amsId:r,trayId:i,trayInfo:s}){const{t:o}=jt(),l=Jt(),{showToast:c}=mn(),[u,d]=w.useState(null),[h,f]=w.useState(""),{data:p,isLoading:x}=Je({queryKey:["inventory-spools"],queryFn:()=>ge.getSpools(),enabled:t}),{data:v}=Je({queryKey:["spool-assignments"],queryFn:()=>ge.getAssignments(),enabled:t}),g=ut({mutationFn:M=>ge.assignSpool({spool_id:M,printer_id:n,ams_id:r,tray_id:i}),onSuccess:M=>{l.setQueryData(["spool-assignments"],C=>{const R=(C||[]).filter(A=>!(A.printer_id===n&&A.ams_id===r&&A.tray_id===i));return R.push(M),R}),l.invalidateQueries({queryKey:["spool-assignments"]}),c(o("inventory.assignSuccess"),"success"),e()},onError:M=>{c(`${o("inventory.assignFailed")}: ${M.message}`,"error")}});if(!t)return null;const y=new Set((v||[]).filter(M=>!(M.printer_id===n&&M.ams_id===r&&M.tray_id===i)).map(M=>M.spool_id)),_=r===254||r===255,N=p?.filter(M=>!y.has(M.id)&&(_||!M.tag_uid&&!M.tray_uuid)),T=N?.filter(M=>{if(!h)return!0;const C=h.toLowerCase();return M.material.toLowerCase().includes(C)||(M.brand?.toLowerCase().includes(C)??!1)||(M.color_name?.toLowerCase().includes(C)??!1)||(M.subtype?.toLowerCase().includes(C)??!1)}),k=()=>{u&&g.mutate(u)};return a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[a.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),a.jsxs("div",{className:"relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ii,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:o("inventory.assignSpool")})]}),a.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:a.jsx(Bt,{className:"w-5 h-5"})})]}),a.jsxs("div",{className:"p-4 space-y-4",children:[s&&a.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsxs("p",{className:"text-xs text-bambu-gray mb-1",children:[o("inventory.selectSpool"),":"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[s.color&&a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20",style:{backgroundColor:`#${s.color}`}}),a.jsx("span",{className:"text-white font-medium",children:s.type||o("ams.emptySlot")}),a.jsxs("span",{className:"text-bambu-gray",children:["(",s.location,")"]})]})]}),a.jsxs("div",{className:"relative",children:[a.jsx(Mr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),a.jsx("input",{type:"text",value:h,onChange:M=>f(M.target.value),placeholder:o("inventory.searchSpools"),className:"w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green"})]}),a.jsx("div",{children:x?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):T&&T.length>0?a.jsx("div",{className:"max-h-64 overflow-y-auto space-y-2",children:T.map(M=>a.jsx("button",{onClick:()=>d(M.id),className:`w-full p-3 rounded-lg border text-left transition-colors ${u===M.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:a.jsxs("div",{className:"flex items-center gap-2",children:[M.rgba&&a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20 flex-shrink-0",style:{backgroundColor:`#${M.rgba.substring(0,6)}`}}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("p",{className:"text-white font-medium truncate",children:[M.brand?`${M.brand} `:"",M.material,M.subtype?` ${M.subtype}`:""]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[M.color_name||"",M.label_weight?` - ${M.label_weight}g`:"",M.label_weight?` (${Math.max(0,Math.round(M.label_weight-M.weight_used))}g ${o("ams.remainingUnit")})`:""]})]}),u===M.id&&a.jsx(Vr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]})},M.id))}):N&&N.length===0?a.jsx("div",{className:"text-center py-8 text-bambu-gray",children:a.jsx("p",{children:o("inventory.noManualSpools")})}):a.jsx("div",{className:"text-center py-8 text-bambu-gray",children:a.jsx("p",{children:o("inventory.noSpoolsMatch")})})})]}),a.jsxs("div",{className:"flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary",children:[a.jsx(Ie,{variant:"secondary",onClick:e,children:o("common.cancel")}),a.jsx(Ie,{onClick:k,disabled:!u||g.isPending,children:g.isPending?a.jsxs(a.Fragment,{children:[a.jsx(lt,{className:"w-4 h-4 animate-spin"}),o("inventory.assigning")]}):a.jsxs(a.Fragment,{children:[a.jsx(ii,{className:"w-4 h-4"}),o("inventory.assignSpool")]})})]}),g.isError&&a.jsx("div",{className:"mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:g.error.message})]})]})}function mG(t,e){if(t===255)return"External";let n,r=!1;t>=128&&t<=135?(n=t-128,r=!0):t>=0&&t<=3?(n=t,r=e===1):n=0,n=Math.max(0,Math.min(n,7));const i=String.fromCharCode(65+n);return r?`HT-${i}`:`AMS-${i}`}function L_(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 k$e=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function fG(t){const e=t.replace(/@.+$/,"").trim(),n=e.toUpperCase();for(const i of k$e){const s=new RegExp(`\\b${i}\\b`,"i");if(s.test(n)){const o=e.split(s),l=o[0]?.trim()||"",c=o[1]?.trim()||"";return{material:i,brand:l,variant:c}}}const r=e.split(/\s+/);return r.length>=2?{material:r[1],brand:r[0],variant:r.slice(2).join(" ")}:{material:e,brand:"",variant:""}}function T$e(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const A$e={white:"FFFFFF",black:"000000",red:"FF0000",green:"00FF00",blue:"0000FF",yellow:"FFFF00",cyan:"00FFFF",magenta:"FF00FF",orange:"FFA500",purple:"800080",pink:"FFC0CB",brown:"8B4513",gray:"808080",grey:"808080","jade white":"FFFEF2",ivory:"FFFFF0",beige:"F5F5DC",cream:"FFFDD0",silver:"C0C0C0",gold:"FFD700",bronze:"CD7F32",copper:"B87333",navy:"000080",teal:"008080",olive:"808000",maroon:"800000",coral:"FF7F50",salmon:"FA8072",lime:"32CD32",mint:"98FF98","forest green":"228B22","sky blue":"87CEEB","royal blue":"4169E1",turquoise:"40E0D0",lavender:"E6E6FA",violet:"EE82EE",plum:"DDA0DD",tan:"D2B48C",chocolate:"D2691E",charcoal:"36454F",slate:"708090",transparent:"000000",natural:"F5F5DC",wood:"DEB887"},pG=[{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"}],gG=[{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 bG(t){const e=t.toLowerCase().trim();return A$e[e]||null}function P$e(t){const e=t.indexOf("@");if(e<0)return null;const r=t.slice(e+1).trim().match(/^BBL\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);return r?r[1].trim():null}function Bne({isOpen:t,onClose:e,printerId:n,slotInfo:r,nozzleDiameter:i="0.4",printerModel:s,onSuccess:o,fullScreen:l}){const{t:c}=jt(),[u,d]=w.useState(""),[h,f]=w.useState(null),[p,x]=w.useState(""),[v,g]=w.useState(""),[y,_]=w.useState(""),[N,T]=w.useState(!1),[k,M]=w.useState(!1),{data:C,isLoading:R,isError:A}=Je({queryKey:["cloudSettings"],queryFn:()=>ge.getCloudSettings(),enabled:t,retry:!1}),{data:D,isLoading:V}=Je({queryKey:["localPresets"],queryFn:()=>ge.getLocalPresets(),enabled:t}),{data:U,isLoading:W}=Je({queryKey:["builtinFilaments"],queryFn:()=>ge.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:L,isLoading:te}=Je({queryKey:["kprofiles",n,i],queryFn:()=>ge.getKProfiles(n,i),enabled:t&&!!n}),{data:ie}=Je({queryKey:["colorCatalog"],queryFn:()=>ge.getColorCatalog(),enabled:t,staleTime:1/0}),X=ut({mutationFn:async()=>{if(!u)throw new Error("No filament preset selected");const P=u.startsWith("local_"),E=u.startsWith("builtin_"),O=P?parseInt(u.replace("local_",""),10):null,G=E?u.replace("builtin_",""):null,B=P?D?.filament.find(Ne=>Ne.id===O):null,re=E?U?.find(Ne=>Ne.filament_id===G):null,z=!P&&!E?C?.filament.find(Ne=>Ne.setting_id===u):null;if(!P&&!E&&!z)throw new Error("Selected preset not found");if(P&&!B)throw new Error("Selected local preset not found");if(E&&!re)throw new Error("Selected builtin preset not found");const q=P?B.name:E?re.name:z.name,ee=fG(q),J=h?.slot_id??-1,ne=p||r.trayColor?.slice(0,6)||"FFFFFF",ae=q.replace(/@.+$/,"").trim();let de,ye;if(P){const Ne=(B?.filament_type||ee.material||"").toUpperCase(),_e={PLA:"GFL99","PLA-CF":"GFL98","PLA SILK":"GFL96","PLA HIGH SPEED":"GFL95",PETG:"GFG99","PETG HF":"GFG96","PETG-CF":"GFG98",PCTG:"GFG97",ABS:"GFB99",ASA:"GFB98",PC:"GFC99",PA:"GFN99","PA-CF":"GFN98",NYLON:"GFN99",TPU:"GFU99",PVA:"GFS99",HIPS:"GFS98",PE:"GFP99",PP:"GFP97"};de=_e[Ne]||_e[Ne.replace(/[-\s]?CF$/,"")]||_e[Ne.replace(/\+$/,"")]||_e[Ne.split(/[-\s]/)[0]]||"",ye=""}else if(E)de=G,ye="";else if(de=L_(u),ye=u,!u.startsWith("GFS"))try{const Ne=await ge.getCloudSettingDetail(u);Ne.filament_id?de=Ne.filament_id:Ne.base_id&&(de=L_(Ne.base_id),console.log(`Derived tray_info_idx from base_id: ${Ne.base_id} -> ${de}`))}catch(Ne){console.warn("Failed to fetch preset detail for filament_id:",Ne)}let le=P&&B?.nozzle_temp_min?B.nozzle_temp_min:190,I=P&&B?.nozzle_temp_max?B.nozzle_temp_max:230;if(!P||E||!B?.nozzle_temp_min&&!B?.nozzle_temp_max){const Ne=(P&&B?.filament_type||ee.material).toUpperCase();Ne.includes("PLA")?(le=190,I=230):Ne.includes("PETG")?(le=220,I=260):Ne.includes("ABS")||Ne.includes("ASA")?(le=240,I=280):Ne.includes("TPU")?(le=200,I=240):Ne==="PCTG"?(le=220,I=260):Ne.includes("PC")?(le=260,I=300):(Ne.includes("PA")||Ne.includes("NYLON"))&&(le=250,I=290)}const F=h?.k_value?parseFloat(h.k_value):0,Z=P?B?.filament_type||ee.material||"PLA":ee.material||"PLA",xe=await ge.configureAmsSlot(n,r.amsId,r.trayId,{tray_info_idx:de,tray_type:Z,tray_sub_brands:ae,tray_color:ne+"FF",nozzle_temp_min:le,nozzle_temp_max:I,cali_idx:J,nozzle_diameter:i,setting_id:ye,kprofile_filament_id:h?.filament_id,kprofile_setting_id:h?.setting_id||void 0,k_value:F}),me=P?`local_${O}`:E?`builtin_${G}`:u,ce=P?"local":E?"builtin":"cloud";try{await ge.saveSlotPreset(n,r.amsId,r.trayId,me,ae,ce)}catch(Ne){console.warn("Failed to save slot preset mapping:",Ne)}return xe},onSuccess:()=>{T(!0),o?.(),setTimeout(()=>{T(!1),e()},1500)}}),se=ut({mutationFn:async()=>ge.resetAmsSlot(n,r.amsId,r.trayId),onSuccess:()=>{T(!0),o?.(),setTimeout(()=>{T(!1),e()},1500)}}),ue=w.useMemo(()=>{const P=y.toLowerCase(),E=[],O=new Set,G=r.savedPresetId,B=r.trayInfoIdx;if(C?.filament)for(const re of C.filament){O.add(re.setting_id);const z=G===re.setting_id||B&&(re.setting_id===B||L_(re.setting_id)===B);if(!(!z&&P&&!re.name.toLowerCase().includes(P))){if(!z&&s){const q=P$e(re.name);if(q&&q.toUpperCase()!==s.toUpperCase())continue}E.push({id:re.setting_id,name:re.name,source:"cloud",isUser:T$e(re.setting_id)})}}if(D?.filament)for(const re of D.filament){const z=`local_${re.id}`,q=G===z;if(!(!q&&P&&!re.name.toLowerCase().includes(P))){if(!q&&s&&re.compatible_printers){const ee=re.compatible_printers.split(";").map(J=>{const ne=J.trim(),ae=ne.match(/^BBL\s+(.+)/i);return ae?ae[1].trim().toUpperCase():ne.toUpperCase()}).filter(Boolean);if(ee.length>0&&!ee.includes(s.toUpperCase()))continue}E.push({id:z,name:re.name,source:"local",isUser:!1})}}if(U)for(const re of U){if(O.has(re.filament_id))continue;const z=re.filament_id.startsWith("GF")?"GFS"+re.filament_id.slice(2):re.filament_id;O.has(z)||(!P||re.name.toLowerCase().includes(P))&&E.push({id:`builtin_${re.filament_id}`,name:re.name,source:"builtin",isUser:!1})}return E.sort((re,z)=>{const q={cloud:0,local:1,builtin:2};return re.source!==z.source?q[re.source]-q[z.source]:re.isUser&&!z.isUser?-1:!re.isUser&&z.isUser?1:re.name.localeCompare(z.name)})},[C?.filament,D?.filament,U,y,s,r.savedPresetId,r.trayInfoIdx]),he=w.useMemo(()=>{if(!u)return null;let P=null;if(u.startsWith("local_")){const G=parseInt(u.replace("local_",""),10);P=D?.filament.find(re=>re.id===G)?.name||null}else if(u.startsWith("builtin_")){const G=u.replace("builtin_","");P=U?.find(re=>re.filament_id===G)?.name||null}else C?.filament&&(P=C.filament.find(B=>B.setting_id===u)?.name||null);if(!P)return null;let E=P.replace(/@.+$/,"").trim();E.startsWith("# ")&&(E=E.slice(2).trim());const O=fG(E);return{fullName:E,material:O.material,brand:O.brand}},[u,C?.filament,D?.filament,U]),Q=he?.fullName||"",oe=w.useMemo(()=>{if(!ie||!he)return[];const{fullName:P,brand:E}=he,O=P.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return ie.filter(G=>{const B=(G.material||"").toUpperCase(),re=G.manufacturer.toUpperCase();if(!(B===O.toUpperCase()||B.includes(O.toUpperCase())||O.toUpperCase().includes(B)))return!1;if(E){const q=E.toUpperCase();if(!re.includes(q)&&!q.includes(re))return!1}return!0})},[ie,he]),fe=w.useMemo(()=>{if(!L?.profiles||!he)return[];const{fullName:P,material:E,brand:O}=he,G=P.toUpperCase(),B=E.toUpperCase(),re=O.toUpperCase();if(!B||B.length<2)return[];const z=L.profiles.filter(ee=>{const J=ee.name.toUpperCase();if(re)return!(!J.includes(re)||!J.includes(B));if(J.includes(G)||J.includes(B))return!0;const ae={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[B]||[];for(const de of ae)if(J.includes(de))return!0;return!1}),q=new Map;for(const ee of z){const J=`${ee.name}|${ee.k_value}`,ne=q.get(J);ne?r.extruderId!==void 0&&ee.extruder_id===r.extruderId&&ne.extruder_id!==r.extruderId&&q.set(J,ee):q.set(J,ee)}return Array.from(q.values())},[L?.profiles,he,r.extruderId]);w.useEffect(()=>{if(t){if(r.savedPresetId)d(r.savedPresetId);else if(r.trayInfoIdx&&C?.filament){let P=C.filament.find(E=>E.setting_id===r.trayInfoIdx);P||(P=C.filament.find(E=>L_(E.setting_id)===r.trayInfoIdx)),P&&d(P.setting_id)}if(r.trayColor){const P=r.trayColor.slice(0,6);P&&x(P)}}else d(""),f(null),x(""),g(""),_(""),T(!1)},[t,r.savedPresetId,r.trayInfoIdx,r.trayColor,C?.filament]),w.useEffect(()=>{if(fe.length>0){if(r.caliIdx!=null&&r.caliIdx>0){const P=fe.find(E=>E.slot_id===r.caliIdx);if(P){f(P);return}}f(fe[0])}else f(null)},[u,fe,r.caliIdx]);const be=w.useCallback(P=>{P.key==="Escape"&&e()},[e]);if(w.useEffect(()=>{if(t)return document.addEventListener("keydown",be),()=>document.removeEventListener("keydown",be)},[t,be]),!t)return null;const Re=R&&!A||V||W||te,$=u&&!X.isPending,K=p||r.trayColor?.slice(0,6)||"FFFFFF";return a.jsxs("div",{className:`fixed inset-0 z-50 flex ${l?"":"items-center justify-center"}`,children:[!l&&a.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),a.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:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(sd,{className:"w-5 h-5 text-bambu-blue"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.title")}),l&&a.jsxs("div",{className:"flex items-center gap-2 ml-4 text-sm text-bambu-gray",children:[a.jsx("span",{className:"text-white/30",children:"|"}),r.trayColor&&a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),a.jsx("span",{className:"text-white/70",children:c("configureAmsSlot.slotLabel",{ams:mG(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&a.jsxs("span",{children:["(",r.traySubBrands,")"]})]})]}),a.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:a.jsx(Bt,{className:"w-5 h-5"})})]}),a.jsxs("div",{className:`p-4 overflow-y-auto ${l?"flex-1 min-h-0":"space-y-4 max-h-[60vh]"}`,children:[N&&a.jsx("div",{className:"absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl",children:a.jsxs("div",{className:"text-center space-y-3",children:[a.jsx(kb,{className:"w-16 h-16 text-bambu-green mx-auto"}),a.jsx("p",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.slotConfigured")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:c("configureAmsSlot.settingsSentToPrinter")})]})}),!l&&a.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:c("configureAmsSlot.configuringSlot")}),a.jsxs("div",{className:"flex items-center gap-2",children:[r.trayColor&&a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/20",style:{backgroundColor:`#${r.trayColor.slice(0,6)}`}}),a.jsx("span",{className:"text-white font-medium",children:c("configureAmsSlot.slotLabel",{ams:mG(r.amsId,r.trayCount),slot:r.trayId+1})}),r.traySubBrands&&a.jsxs("span",{className:"text-bambu-gray",children:["(",r.traySubBrands,")"]})]})]}),Re?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):l?a.jsxs("div",{className:"flex gap-4 h-full",children:[a.jsxs("div",{className:"w-1/2 flex flex-col min-h-0",children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",a.jsx("span",{className:"text-red-400",children:"*"})]}),a.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:y,onChange:P=>_(P.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"}),a.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-1",children:ue.length===0?a.jsx("p",{className:"text-center py-4 text-bambu-gray",children:C?.filament?.length===0&&!D?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):ue.map(P=>a.jsx("button",{ref:u===P.id?E=>{E?.scrollIntoView({block:"nearest"})}:void 0,onClick:()=>d(P.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${u===P.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-white text-sm truncate",children:P.name}),a.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[P.source==="local"&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),P.source==="builtin"&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),P.isUser&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},P.id))})]}),a.jsxs("div",{className:"w-1/2 flex flex-col gap-4 min-h-0 overflow-y-auto",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),Q&&a.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:Q})})]}),fe.length>0?a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:h?.name||"",onChange:P=>{const E=fe.find(O=>O.name===P.target.value);f(E||null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10",children:[a.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),fe.map(P=>a.jsxs("option",{value:P.name,children:[P.name," (K=",P.k_value,")"]},`${P.name}-${P.extruder_id}`))]}),a.jsx(Fn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):u?a.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):a.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),h&&a.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:h.k_value})})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),oe.length>0&&a.jsxs("div",{className:"mb-3",children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:he?.fullName})}),a.jsx("div",{className:"flex flex-wrap gap-1.5",children:oe.map(P=>a.jsxs("button",{onClick:()=>{const E=P.hex_color.replace("#","").toUpperCase();x(E),g(P.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${p===P.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:P.color_name,children:[a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/30 flex-shrink-0",style:{backgroundColor:P.hex_color}}),a.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:P.color_name})]},P.id))})]}),a.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[pG.map(P=>a.jsx("button",{onClick:()=>{x(P.hex),g(P.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===P.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${P.hex}`},title:P.name},P.hex)),a.jsx("button",{onClick:()=>M(!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&&a.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:gG.map(P=>a.jsx("button",{onClick:()=>{x(P.hex),g(P.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===P.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${P.hex}`},title:P.name},P.hex))}),a.jsxs("div",{className:"flex gap-2 items-center",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${K}`}}),a.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:P=>{const E=P.target.value;g(E);const O=bG(E);if(O)x(O);else{const G=E.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();G.length===6?x(G):G.length===3&&x(G.split("").map(B=>B+B).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"}),p&&a.jsx("button",{onClick:()=>{x(""),g("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),p&&a.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:p})})]})]})]}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",a.jsx("span",{className:"text-red-400",children:"*"})]}),a.jsxs("div",{className:"relative",children:[a.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:y,onChange:P=>_(P.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2"}),a.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:ue.length===0?a.jsx("p",{className:"text-center py-4 text-bambu-gray",children:C?.filament?.length===0&&!D?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):ue.map(P=>a.jsx("button",{ref:u===P.id?E=>{E?.scrollIntoView({block:"nearest"})}:void 0,onClick:()=>d(P.id),className:`w-full p-2 rounded-lg border text-left transition-colors ${u===P.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-white text-sm truncate",children:P.name}),a.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[P.source==="local"&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),P.source==="builtin"&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),P.isUser&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},P.id))})]})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),Q&&a.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:Q})})]}),fe.length>0?a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:h?.name||"",onChange:P=>{const E=fe.find(O=>O.name===P.target.value);f(E||null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10",children:[a.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),fe.map(P=>a.jsxs("option",{value:P.name,children:[P.name," (K=",P.k_value,")"]},`${P.name}-${P.extruder_id}`))]}),a.jsx(Fn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):u?a.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):a.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),h&&a.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:h.k_value})})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),oe.length>0&&a.jsxs("div",{className:"mb-3",children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:he?.fullName})}),a.jsx("div",{className:"flex flex-wrap gap-1.5",children:oe.map(P=>a.jsxs("button",{onClick:()=>{const E=P.hex_color.replace("#","").toUpperCase();x(E),g(P.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${p===P.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:P.color_name,children:[a.jsx("span",{className:"w-4 h-4 rounded-full border border-white/30 flex-shrink-0",style:{backgroundColor:P.hex_color}}),a.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:P.color_name})]},P.id))})]}),a.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[pG.map(P=>a.jsx("button",{onClick:()=>{x(P.hex),g(P.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===P.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${P.hex}`},title:P.name},P.hex)),a.jsx("button",{onClick:()=>M(!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&&a.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:gG.map(P=>a.jsx("button",{onClick:()=>{x(P.hex),g(P.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${p===P.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${P.hex}`},title:P.name},P.hex))}),a.jsxs("div",{className:"flex gap-2 items-center",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${K}`}}),a.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:P=>{const E=P.target.value;g(E);const O=bG(E);if(O)x(O);else{const G=E.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();G.length===6?x(G):G.length===3&&x(G.split("").map(B=>B+B).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"}),p&&a.jsx("button",{onClick:()=>{x(""),g("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),p&&a.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:p})})]})]})]}),a.jsxs("div",{className:"flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[a.jsx(Ie,{variant:"secondary",onClick:()=>se.mutate(),disabled:se.isPending||X.isPending,className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:se.isPending?a.jsxs(a.Fragment,{children:[a.jsx(lt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.resetting")]}):a.jsxs(a.Fragment,{children:[a.jsx(lo,{className:"w-4 h-4"}),c("configureAmsSlot.resetSlot")]})}),a.jsxs("div",{className:"flex gap-2",children:[a.jsx(Ie,{variant:"secondary",onClick:e,children:c("configureAmsSlot.cancel")}),a.jsx(Ie,{onClick:()=>X.mutate(),disabled:!$,children:X.isPending?a.jsxs(a.Fragment,{children:[a.jsx(lt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.configuring")]}):a.jsxs(a.Fragment,{children:[a.jsx(sd,{className:"w-4 h-4"}),c("configureAmsSlot.configureSlot")]})})]})]}),(X.isError||se.isError)&&a.jsx("div",{className:"mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:X.error?.message||se.error?.message})]})]})}function Hne({folderId:t,onClose:e,onUploadComplete:n,onFileUploaded:r,autoUpload:i,validateFile:s,accept:o}){const{t:l}=jt(),[c,u]=w.useState([]),[d,h]=w.useState(!1),[f,p]=w.useState(!1),[x,v]=w.useState(!0),[g,y]=w.useState(!1),[_,N]=w.useState(!0),[T,k]=w.useState(null),M=w.useRef(null),C=he=>{he.preventDefault(),h(!0)},R=he=>{he.preventDefault(),h(!1)},A=he=>{he.preventDefault(),h(!1),W(Array.from(he.dataTransfer.files))},D=he=>{he.target.files&&W(Array.from(he.target.files))},V=(he,Q)=>{u(oe=>oe.map(fe=>fe.file===he?{...fe,...Q}:fe))},U=async he=>{p(!0);for(const Q of he)if(Q.status==="pending"){V(Q.file,{status:"uploading"});try{if(Q.isZip){const oe=await ge.extractZipFile(Q.file,t,x,g,_);V(Q.file,{status:oe.errors.length>0&&oe.extracted===0?"error":"success",extractedCount:oe.extracted,error:oe.errors.length>0?l("fileManager.zipFilesFailed","{{count}} files failed",{count:oe.errors.length}):void 0})}else{const oe=await ge.uploadLibraryFile(Q.file,t,_);V(Q.file,{status:"success"});const fe=r?.(oe);if(fe){k(fe),u([]),p(!1);return}}}catch(oe){V(Q.file,{status:"error",error:oe instanceof Error?oe.message:l("fileManager.uploadFailed","Upload failed")})}}p(!1),n(),e()},W=he=>{if(k(null),s)for(const oe of he){const fe=s(oe);if(fe){k(fe);return}}const Q=he.map(oe=>({file:oe,status:"pending",isZip:oe.name.toLowerCase().endsWith(".zip"),is3mf:oe.name.toLowerCase().endsWith(".3mf")}));u(oe=>[...oe,...Q]),i&&he.length>0&&U(Q)},L=he=>{u(Q=>Q.filter((oe,fe)=>fe!==he))},te=c.some(he=>he.isZip&&he.status==="pending"),ie=c.some(he=>he.file.name.toLowerCase().endsWith(".stl")&&he.status==="pending"),X=c.some(he=>he.is3mf&&he.status==="pending"),se=c.filter(he=>he.status==="pending").length,ue=c.length>0&&se===0&&!f;return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-lg border border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[a.jsx("h2",{className:"text-lg font-semibold text-white",children:l("fileManager.uploadFiles")}),a.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:a.jsx(Bt,{className:"w-5 h-5 text-bambu-gray"})})]}),a.jsxs("div",{className:"p-4 space-y-4",children:[a.jsxs("div",{onDragOver:C,onDragLeave:R,onDrop:A,onClick:()=>M.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:[a.jsx(Oa,{className:`w-10 h-10 mx-auto mb-3 ${d?"text-bambu-green":"text-bambu-gray"}`}),a.jsx("p",{className:"text-white font-medium",children:l(d?"fileManager.dropFilesHere":"fileManager.dragDropFiles")}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:l("fileManager.orClickToBrowse")}),a.jsx("p",{className:"text-xs text-bambu-gray/70 mt-2",children:l("fileManager.allFileTypesSupported")})]}),a.jsx("input",{ref:M,type:"file",multiple:!0,accept:o,className:"hidden",onChange:D}),te&&a.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(Ls,{className:"w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:"flex-1",children:[a.jsx("p",{className:"text-sm text-blue-300 font-medium",children:l("fileManager.zipFilesDetected")}),a.jsx("p",{className:"text-xs text-blue-300/70 mt-1",children:l("fileManager.zipExtractOptions")}),a.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:x,onChange:he=>v(he.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),a.jsx("span",{className:"text-sm text-white",children:l("fileManager.preserveZipStructure")})]}),a.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:g,onChange:he=>y(he.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),a.jsx("span",{className:"text-sm text-white",children:l("fileManager.createFolderFromZip")})]})]})]})}),X&&a.jsx("div",{className:"p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(wr,{className:"w-5 h-5 text-purple-400 mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:"flex-1",children:[a.jsx("p",{className:"text-sm text-purple-300 font-medium",children:l("fileManager.threemfDetected")}),a.jsx("p",{className:"text-xs text-purple-300/70 mt-1",children:l("fileManager.threemfExtractionInfo")})]})]})}),(ie||te)&&a.jsx("div",{className:"p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(id,{className:"w-5 h-5 text-bambu-green mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:"flex-1",children:[a.jsx("p",{className:"text-sm text-bambu-green font-medium",children:l("fileManager.stlThumbnailGeneration")}),a.jsx("p",{className:"text-xs text-bambu-green/70 mt-1",children:l(te&&!ie?"fileManager.zipMayContainStl":"fileManager.thumbnailsCanBeGenerated")}),a.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[a.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"}),a.jsx("span",{className:"text-sm text-white",children:l("fileManager.generateThumbnailsForStl")})]})]})]})}),c.length>0&&a.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:c.map((he,Q)=>a.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[he.isZip?a.jsx(Ls,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):a.jsx(ak,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("p",{className:"text-sm text-white truncate",children:he.file.name}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[(he.file.size/1024/1024).toFixed(2)," MB",he.isZip&&he.status==="pending"&&a.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",l("fileManager.willBeExtracted")]}),he.extractedCount!==void 0&&a.jsxs("span",{className:"text-green-400 ml-2",children:["• ",l("fileManager.filesExtracted",{count:he.extractedCount})]})]})]}),he.status==="pending"&&a.jsx("button",{onClick:()=>L(Q),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Bt,{className:"w-4 h-4 text-bambu-gray"})}),he.status==="uploading"&&a.jsx(lt,{className:"w-4 h-4 text-bambu-green animate-spin"}),he.status==="success"&&a.jsx(br,{className:"w-4 h-4 text-green-500"}),he.status==="error"&&a.jsx("span",{title:he.error,children:a.jsx(qa,{className:"w-4 h-4 text-red-500"})})]},Q))}),T&&a.jsx("div",{className:"p-3 bg-red-500/10 border border-red-500/30 rounded-lg",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(qa,{className:"w-5 h-5 text-red-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-sm text-red-300",children:T})]})})]}),a.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2",children:[a.jsx(Ie,{variant:"secondary",onClick:e,children:l("common.cancel")}),!ue&&a.jsx(Ie,{onClick:()=>U(c),disabled:se===0||f,children:f?a.jsxs(a.Fragment,{children:[a.jsx(lt,{className:"w-4 h-4 mr-2 animate-spin"}),l("fileManager.uploading")]}):a.jsxs(a.Fragment,{children:[a.jsx(Oa,{className:"w-4 h-4 mr-2"}),l("common.upload")," ",se>0?`(${se})`:""]})})]})]})})}const tC={"000000":"Black","001489":"Blue","002e96":"Blue","0047bb":"Blue","00482b":"Pine Green","004ea8":"Blue","0056b8":"Cobalt Blue","0069b1":"Lake Blue","0072ce":"Blue","0078bf":"Marine Blue","0085ad":"Light Blue","0086d6":"Cyan","008bda":"Blue","009639":"Green","009bd8":"Cyan","009fa1":"Teal","00a6a0":"Green","00ae42":"Bambu Green","00b1b7":"Turquoise","00bb31":"Green","018814":"Candy Green","042f56":"Dark Blue","0a2989":"Blue","0a2ca5":"Blue","0c2340":"Navy Blue","0c3b95":"Blue",101820:"Black","147bd1":"Blue","164b35":"Green","16b08e":"Malachite Green","1d7c6a":"Oxide Green Metallic","1f79e5":"Lake Blue","2140b4":"Blue","25282a":"Black","2842ad":"Royal Blue","2d2b28":"Onyx Black Sparkle",324585:"Indigo Blue",353533:"Gray","39541a":"Forest Green","39699e":"Cobalt Blue Metallic","3b665e":"Green","3f5443":"Alpine Green Sparkle","3f8e43":"Mistletoe Green",424379:"Nebulae","43403d":"Iron Gray Metallic",482960:"Indigo Purple","483d8b":"Royal Purple Sparkle","489fdf":"Azure","4c241c":"Rosewood","4ce4a0":"Green","4d3324":"Dark Chocolate","4d5054":"Lava Gray","4dafda":"Cyan","4f3f24":"Black Walnut",515151:"Dark Gray","515a6c":"Gray",545454:"Dark Gray",565656:"Titan Gray","56b7e6":"Sky Blue",583061:"Violet Purple","5898dd":"Blue",594177:"Purple","5b492f":"Brown","5b6579":"Blue Gray","5c9748":"Matcha Green","5e43b7":"Purple","5e4b3c":"Copper","5f6367":"Titan Gray","61b0ff":"Translucent Light Blue","61bf36":"Green","61c680":"Grass Green","6667ab":"Lavender Blue","684a43":"Brown",686865:"Black","68724d":"Dark Green",688197:"Blue Gray","69398e":"Iris Purple","6e88bc":"Jeans Blue","6ee53c":"Lime Green","6f5034":"Cocoa Brown","7248bd":"Lavender","748c45":"Translucent Olive",757575:"Nardo Gray","75aed8":"Blue","77edd7":"Translucent Teal","789d4a":"Olive","792b36":"Crimson Red Sparkle","7ac0e9":"Glow Blue","7ae1bf":"Mint","7cd82b":"Lime Green","7d6556":"Dark Brown","8344b0":"Purple","847d48":"Bronze","854ce4":"Purple","8671cb":"Purple",875718:"Peanut Brown","87909a":"Silver","898d8d":"Gray","8a949e":"Gray","8e8e8e":"Translucent Gray","8e9089":"Gray","90ff1a":"Neon Green",918669:"Classic Birch",939393:"Gray",950051:"Plum","951e23":"Burgundy Red",959698:"Silver","96d8af":"Light Jade","96dcb9":"Mint","995f11":"Clay Brown","999d9d":"Gray","9b9ea0":"Ash Gray","9d2235":"Maroon Red","9d432c":"Brown","9e007e":"Purple","9ea2a2":"Gray","9f332a":"Brick Red",a1ffac:"Glow Green",a3d8e1:"Ice Blue",a6a9aa:"Silver",a8a8aa:"Gray",a8c6ee:"Baby Blue",aa6443:"Copper Brown Metallic",ad4e38:"Red Granite",adb1b2:"Gray",ae835b:"Caramel",ae96d4:"Lilac Purple",af1685:"Purple",afb1ae:"Gray",b15533:"Terracotta",b28b33:"Gold",b39b84:"Iridium Gold Metallic",b50011:"Red",b8acd6:"Lavender",b8cde9:"Ice Blue",ba9594:"Rose Gold",bb3d43:"Dark Red",bc0900:"Red",becf00:"Bright Green",c0df16:"Green",c12e1f:"Red",c2e189:"Apple Green",c3e2d6:"Light Cyan",c5ed48:"Lime",c6001a:"Red",c6c6c6:"Gray",c8102e:"Red",c8c8c8:"Silver",c98935:"Ochre Yellow",c9a381:"Translucent Brown",cbc6b8:"Bone White",cdceca:"Gray",cea629:"Classic Gold Sparkle",d02727:"Candy Red",d1d3d5:"Light Gray",d32941:"Red",d3b7a7:"Latte Brown",d6001c:"Red",d6abff:"Translucent Purple",d6cca3:"White Oak",dc3a27:"Orange",dd3c22:"Vermilion Red",de4343:"Scarlet Red",dfd1a7:"Beige",e02928:"Red",e4bd68:"Gold",e5b03d:"Gold",e83100:"Red",e8afcf:"Sakura Pink",e8dbb7:"Desert Tan",eaeae4:"White",eaeceb:"Silver",ec008c:"Magenta",ed0000:"Red",eeb1c1:"Pink",efe255:"Yellow",f0f1a8:"Clear",f17b8f:"Glow Pink",f3cfb2:"Champagne",f3e600:"Yellow",f48438:"Orange",f4a925:"Gold",f4d53f:"Yellow",f4ee2a:"Yellow",f5547c:"Hot Pink",f55a74:"Pink",f5b6cd:"Cherry Pink",f5dbab:"Mellow Yellow",f5f1dd:"White",f68b1b:"Neon Orange",f74e02:"Orange",f75403:"Orange",f7ada6:"Pink",f7d959:"Lemon Yellow",f7e6de:"Beige",f7f3f0:"White Marble",f8ff80:"Glow Yellow",f99963:"Mandarin Orange",f9c1bd:"Translucent Pink",f9dfb9:"Cream",f9ef41:"Yellow",f9f7f2:"Nature",f9f7f4:"White",fce300:"Yellow",fce900:"Yellow",fec600:"Sunflower Yellow",fedb00:"Yellow",ff4800:"Orange",ff671f:"Orange",ff6a13:"Orange",ff7f41:"Orange",ff9016:"Pumpkin Orange",ff911a:"Translucent Orange",ff9d5b:"Glow Orange",ffb549:"Sunflower Yellow",ffc72c:"Tangerine Yellow",ffce00:"Yellow",ffd00b:"Yellow",ffe133:"Yellow",fffaf2:"White",ffffff:"White"};function M$e(t){if(!t||t.length<6)return"Unknown";const e=t.replace("#",""),n=parseInt(e.substring(0,2),16),r=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16),s=Math.max(n,r,i)/255,o=Math.min(n,r,i)/255,l=(s+o)/2;let c=0,u=0;if(s!==o){const d=s-o;u=l>.5?d/(2-s-o):d/(s+o);const h=n/255,f=r/255,p=i/255;s===h?c=((f-p)/d+(f.85?"White":u<.15?l<.4?"Dark Gray":l>.6?"Light Gray":"Gray":c<15||c>=345?"Red":c<45?"Orange":c<70?"Yellow":c<150?"Green":c<200?"Cyan":c<260?"Blue":c<290?"Purple":"Pink"}function Ff(t){const e=t.replace("#","").toLowerCase().substring(0,6);return tC[e]?tC[e]:M$e(t)}function PO(t,e){if(t&&!/^[A-Z]\d+-[A-Z]\d+$/.test(t))return t;if(e&&e.length>=6){const n=e.substring(0,6).toLowerCase();if(tC[n])return tC[n]}return null}function xG(t){return t?`#${t.replace("#","").substring(0,6)}`:"#808080"}function Fa(t){return t?t.replace("#","").toLowerCase().substring(0,6):""}function Bc(t,e,n=40){const r=Fa(t),i=Fa(e);if(!r||!i||r.length<6||i.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(i.substring(0,2),16),u=parseInt(i.substring(2,4),16),d=parseInt(i.substring(4,6),16);return Math.abs(s-c)<=n&&Math.abs(o-u)<=n&&Math.abs(l-d)<=n}function MO(t,e,n,r){if(r)return"External";const i=String.fromCharCode(65+(t>=128?t-128:t));return n?`HT-${i}`:`AMS-${i} Slot ${e+1}`}function nC(t,e,n){return n?254+e:t>=128?t:t*4+e}function yG(t){if(!t)return!1;const e=Date.now()+4320*60*60*1e3;return(er(t)?.getTime()??0)>e}function ST(t){const e=[],n=t?.ams_extruder_map,r=n&&Object.keys(n).length>0;t?.ams?.forEach(i=>{const s=i.tray.length===1;i.tray.forEach(o=>{if(o.tray_type){const l=xG(o.tray_color);e.push({type:o.tray_type,color:l,colorName:Ff(l),amsId:i.id,trayId:o.id,isHt:s,isExternal:!1,label:MO(i.id,o.id,s,!1),globalTrayId:nC(i.id,o.id,!1),trayInfoIdx:o.tray_info_idx||"",extruderId:n?.[String(i.id)]})}})});for(const i of t?.vt_tray??[])if(i.tray_type){const s=xG(i.tray_color),o=i.id??254,l=(t?.vt_tray?.length??0)>1;e.push({type:i.tray_type,color:s,colorName:Ff(s),amsId:-1,trayId:o-254,isHt:!1,isExternal:!0,label:l?o===254?"Ext-L":"Ext-R":"External",globalTrayId:o,trayInfoIdx:i.tray_info_idx||"",extruderId:r?255-o:void 0})}return e}function vG(t,e){if(!t?.filaments||t.filaments.length===0)return;const n=ST(e);if(n.length===0)return;const r=new Set,i=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,h,f,p;if(c){const v=u.filter(g=>g.trayInfoIdx===c);v.length===1?d=v[0]:v.length>1&&(h=v.find(g=>g.type?.toUpperCase()===l.type?.toUpperCase()&&Fa(g.color)===Fa(l.color)),h||(f=v.find(g=>g.type?.toUpperCase()===l.type?.toUpperCase()&&Bc(g.color,l.color))),!h&&!f&&(p=v.find(g=>g.type?.toUpperCase()===l.type?.toUpperCase())))}!d&&!h&&!f&&!p&&(h=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&Fa(v.color)===Fa(l.color)),h||(f=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase()&&Bc(v.color,l.color))),!h&&!f&&(p=u.find(v=>v.type?.toUpperCase()===l.type?.toUpperCase())));const x=d||h||f||p||void 0;return x&&r.add(x.globalTrayId),{slot_id:l.slot_id,globalTrayId:x?.globalTrayId??-1}}),s=Math.max(...i.map(l=>l.slot_id||0));if(s<=0)return;const o=new Array(s).fill(-1);return i.forEach(l=>{l.slot_id&&l.slot_id>0&&(o[l.slot_id-1]=l.globalTrayId)}),o}function j$e(t){return w.useMemo(()=>ST(t),[t])}function $ne(t,e,n){const r=j$e(e),i=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 M=n[d],C=r.find(R=>R.globalTrayId===M);if(C){const R=C.type?.toUpperCase()===u.type?.toUpperCase(),A=Fa(C.color)===Fa(u.color)||Bc(C.color,u.color);let D;return R&&A?D="match":R?D="type_only":D="mismatch",{...u,loaded:C,hasFilament:!0,typeMatch:R,colorMatch:A,status:D,isManual:!0}}}const h=u.tray_info_idx||"";let f=r.filter(M=>!c.has(M.globalTrayId));u.nozzle_id!=null&&(f=f.filter(M=>M.extruderId===u.nozzle_id));let p,x,v,g;if(h){const M=f.filter(C=>C.trayInfoIdx===h);M.length===1?p=M[0]:M.length>1&&(x=M.find(C=>C.type?.toUpperCase()===u.type?.toUpperCase()&&Fa(C.color)===Fa(u.color)),x||(v=M.find(C=>C.type?.toUpperCase()===u.type?.toUpperCase()&&Bc(C.color,u.color))),!x&&!v&&(g=M.find(C=>C.type?.toUpperCase()===u.type?.toUpperCase())))}!p&&!x&&!v&&!g&&(x=f.find(M=>M.type?.toUpperCase()===u.type?.toUpperCase()&&Fa(M.color)===Fa(u.color)),x||(v=f.find(M=>M.type?.toUpperCase()===u.type?.toUpperCase()&&Bc(M.color,u.color))),!x&&!v&&(g=f.find(M=>M.type?.toUpperCase()===u.type?.toUpperCase())));const y=p||x||v||g||void 0;y&&c.add(y.globalTrayId);const _=!!y,N=_,T=!!p||!!x||!!v;let k;return p||x||v?k="match":g?k="type_only":k="mismatch",{...u,loaded:y,hasFilament:_,typeMatch:N,colorMatch:T,status:k,isManual:!1}})},[t,r,n]),s=w.useMemo(()=>{if(i.length===0)return;const c=Math.max(...i.map(d=>d.slot_id||0));if(c<=0)return;const u=new Array(c).fill(-1);return i.forEach(d=>{d.slot_id&&d.slot_id>0&&(u[d.slot_id-1]=d.loaded?.globalTrayId??-1)}),u},[i]),o=i.some(c=>c.status==="mismatch"),l=i.some(c=>c.status==="type_only");return{loadedFilaments:r,filamentComparison:i,amsMapping:s,hasTypeMismatch:o,hasColorMismatch:l}}function E$e(t,e,n){if(!t||t.length===0)return{exactMatches:0,typeOnlyMatches:0,missingTypes:0,totalSlots:0,status:"full"};let r=0,i=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 g=n[d],y=e.find(_=>_.globalTrayId===g);if(y){const _=y.type?.toUpperCase()===u.type?.toUpperCase(),N=Fa(y.color)===Fa(u.color)||Bc(y.color,u.color);_&&N?r++:_?i++:s++;continue}}let h=e.filter(g=>!o.has(g.globalTrayId));if(u.nozzle_id!=null){const g=h.filter(y=>y.extruderId===u.nozzle_id);g.length>0&&(h=g)}const f=h.find(g=>g.type?.toUpperCase()===u.type?.toUpperCase()&&Fa(g.color)===Fa(u.color)),p=f?void 0:h.find(g=>g.type?.toUpperCase()===u.type?.toUpperCase()&&Bc(g.color,u.color)),x=f||p?void 0:h.find(g=>g.type?.toUpperCase()===u.type?.toUpperCase()),v=f??p??x;v&&o.add(v.globalTrayId),f||p?r++:x?i++:s++}const l=t.length;let c="full";return s>0?c="missing":i>0&&(c="partial"),{exactMatches:r,typeOnlyMatches:i,missingTypes:s,totalSlots:l,status:c}}function D$e(t,e,n){if(!t?.filaments||t.filaments.length===0)return;const r=ST(e);if(r.length===0)return;const i=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=>!i.has(v.globalTrayId));if(c.nozzle_id!=null){const v=d.filter(g=>g.extruderId===c.nozzle_id);v.length>0&&(d=v)}const h=d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&Fa(v.color)===Fa(c.color)),f=h?void 0:d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()&&Bc(v.color,c.color)),p=h||f?void 0:d.find(v=>v.type?.toUpperCase()===c.type?.toUpperCase()),x=h??f??p;x&&i.add(x.globalTrayId),s.push({slot_id:u,globalTrayId:x?.globalTrayId??-1})}const o=Math.max(...s.map(c=>c.slot_id||0));if(o<=0)return;const l=new Array(o).fill(-1);return s.forEach(c=>{c.slot_id&&c.slot_id>0&&(l[c.slot_id-1]=c.globalTrayId)}),l}const wG={useDefault:!0,manualMappings:{},autoConfigured:!1};function R$e(t,e,n,r,i,s){const o=rx({queries:t.map(x=>({queryKey:["printer-status",x],queryFn:()=>ge.getPrinterStatus(x),enabled:t.length>0,staleTime:5e3}))}),l=w.useMemo(()=>t.map((x,v)=>{const g=o[v],y=g?.data,N=e?.find(D=>D.id===x)?.name||`Printer ${x}`,T=ST(y),k=i[x]||wG,M=vG(n,y),C=k.useDefault?r:k.manualMappings,R=D$e(n,y,C),A=E$e(n?.filaments,T,C);return{printerId:x,printerName:N,status:y,isLoading:g?.isLoading??!1,loadedFilaments:T,autoMapping:M,finalMapping:R,matchStatus:A.status,exactMatches:A.exactMatches,typeOnlyMatches:A.typeOnlyMatches,missingTypes:A.missingTypes,totalSlots:A.totalSlots,config:k}}),[t,o,e,n,i,r]),c=o.some(x=>x.isLoading),u=(x,v)=>{s(g=>({...g,[x]:{...g[x]||wG,...v}}))},d=x=>{const v=l.find(_=>_.printerId===x);if(!v||!v.status||!n?.filaments)return;const g=vG(n,v.status);if(!g)return;const y={};g.forEach((_,N)=>{_!==-1&&(y[N+1]=_)}),u(x,{useDefault:!1,manualMappings:y,autoConfigured:!0})},h=()=>{for(const x of t)d(x)},f=x=>l.find(g=>g.printerId===x)?.finalMapping,p=l.every(x=>x.matchStatus!=="missing");return{printerResults:l,isLoading:c,perPrinterConfigs:i,updatePrinterConfig:u,autoConfigureAll:h,autoConfigurePrinter:d,getFinalMapping:f,allPrintersReady:p}}const F$e={USD:"$",EUR:"€",GBP:"£",CHF:"Fr.",JPY:"¥",CNY:"¥",CAD:"$",AUD:"$",INR:"₹",HKD:"HK$",KRW:"₩",SEK:"kr",NOK:"kr",DKK:"kr",PLN:"zł",BRL:"R$",TWD:"NT$",SGD:"S$",NZD:"NZ$",MXN:"MX$",CZK:"Kč",THB:"฿",ZAR:"R",TRY:"₺",RUB:"₽",HUF:"Ft"};function sl(t){return F$e[t.toUpperCase()]||t}const L$e=[{code:"USD",label:"USD ($)"},{code:"EUR",label:"EUR (€)"},{code:"GBP",label:"GBP (£)"},{code:"CHF",label:"CHF (Fr.)"},{code:"JPY",label:"JPY (¥)"},{code:"CNY",label:"CNY (¥)"},{code:"CAD",label:"CAD ($)"},{code:"AUD",label:"AUD ($)"},{code:"INR",label:"INR (₹)"},{code:"HKD",label:"HKD (HK$)"},{code:"KRW",label:"KRW (₩)"},{code:"SEK",label:"SEK (kr)"},{code:"NOK",label:"NOK (kr)"},{code:"DKK",label:"DKK (kr)"},{code:"PLN",label:"PLN (zł)"},{code:"BRL",label:"BRL (R$)"},{code:"TWD",label:"TWD (NT$)"},{code:"SGD",label:"SGD (S$)"},{code:"NZD",label:"NZD (NZ$)"},{code:"MXN",label:"MXN (MX$)"},{code:"CZK",label:"CZK (Kč)"},{code:"THB",label:"THB (฿)"},{code:"ZAR",label:"ZAR (R)"},{code:"TRY",label:"TRY (₺)"},{code:"RUB",label:"RUB (₽)"},{code:"HUF",label:"HUF (Ft)"}];function O$e({printerId:t,filamentReqs:e,manualMappings:n,onManualMappingChange:r,currencySymbol:i,defaultCostPerKg:s,defaultExpanded:o=!1}){const{t:l}=jt(),c=Jt(),[u,d]=w.useState(!1),[h,f]=w.useState(o),{data:p}=Je({queryKey:["printer-status",t],queryFn:()=>ge.getPrinterStatus(t),enabled:!!t}),{data:x}=Je({queryKey:["spool-assignments",t],queryFn:()=>ge.getAssignments(t),enabled:!!t}),{loadedFilaments:v,filamentComparison:g,hasTypeMismatch:y,hasColorMismatch:_}=$ne(e,p,n),N=w.useMemo(()=>{const U=new Map;for(const W of x||[]){const L=W.ams_id===255,te=nC(W.ams_id,W.tray_id,L);U.set(te,W.spool?.cost_per_kg??null)}return U},[x]),T=w.useMemo(()=>{const U=new Map;for(const W of x||[]){const L=W.ams_id===255,te=nC(W.ams_id,W.tray_id,L),ie=W.spool;if(!ie){U.set(te,null);continue}U.set(te,Math.max(0,Math.round((ie.label_weight??0)-(ie.weight_used??0))))}return U},[x]),k=w.useMemo(()=>{let U=0;for(const W of g){const L=W.loaded?.globalTrayId;if(L==null)continue;const ie=N.get(L)??null??s;ie>0&&(U+=W.used_grams/1e3*ie)}return U},[g,N,s]),M=w.useMemo(()=>Array.from(N.values()).some(U=>U!=null&&U>0),[N]),C=e?.filaments&&e.filaments.length>0,R=e?.filaments?.some(U=>U.nozzle_id!=null)??!1;if(!C||!p)return null;const A=y?"#f97316":_?"#facc15":"#00ae42",D=(U,W)=>{if(U>0)if(W===""){const L={...n};delete L[U],r(L)}else r({...n,[U]:parseInt(W,10)})},V=async()=>{d(!0);try{await ge.refreshPrinterStatus(t),await new Promise(U=>setTimeout(U,500)),await c.refetchQueries({queryKey:["printer-status",t]})}finally{d(!1)}};return a.jsxs("div",{className:"mb-4",children:[a.jsxs("button",{type:"button",onClick:()=>f(!h),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[a.jsx(R1,{className:"w-4 h-4",fill:A,stroke:"none"}),a.jsx("span",{children:l("printModal.filamentMapping")}),y?a.jsx("span",{className:"text-xs text-orange-400",children:"(Type not found)"}):_?a.jsx("span",{className:"text-xs text-yellow-400",children:"(Color mismatch)"}):a.jsx("span",{className:"text-xs text-bambu-green",children:"(Ready)"}),h?a.jsx(Sl,{className:"w-4 h-4 ml-auto"}):a.jsx(Fn,{className:"w-4 h-4 ml-auto"})]}),h&&a.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Click to change slot assignment"}),a.jsxs("button",{type:"button",onClick:V,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:[a.jsx(vr,{className:`w-3 h-3 ${u?"animate-spin":""}`}),a.jsx("span",{children:"Re-read"})]})]}),g.map((U,W)=>a.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[a.jsx("span",{title:`Required: ${U.type} - ${Ff(U.color)}`,children:a.jsx(R1,{className:"w-3 h-3",fill:U.color,stroke:U.color})}),a.jsxs("span",{className:"text-white truncate flex items-center gap-1",children:[R&&U.nozzle_id!=null&&a.jsx("span",{className:"inline-flex items-center justify-center w-3.5 h-3.5 rounded text-[9px] font-bold leading-none bg-bambu-gray/20 text-bambu-gray shrink-0",title:U.nozzle_id===1?l("printModal.leftNozzleTooltip"):l("printModal.rightNozzleTooltip"),children:U.nozzle_id===1?l("printModal.leftNozzle"):l("printModal.rightNozzle")}),U.type," ",a.jsxs("span",{className:"text-bambu-gray",children:["(",U.used_grams,"g)"]})]}),a.jsx("span",{className:"text-bambu-gray",children:"→"}),a.jsxs("select",{value:U.loaded?.globalTrayId??"",onChange:L=>D(U.slot_id||0,L.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${U.status==="match"?"border-bambu-green/50 text-bambu-green":U.status==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${U.isManual?"ring-1 ring-blue-400/50":""}`,title:U.isManual?"Manually selected":"Auto-matched",children:[a.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),v.filter(L=>U.nozzle_id==null||L.extruderId===U.nozzle_id).map(L=>{const te=T.get(L.globalTrayId),ie=te!=null?l("printModal.slotRemainingShort",{grams:te,defaultValue:` - ${te}g left`}):"";return a.jsxs("option",{value:L.globalTrayId,className:"bg-bambu-dark text-white",children:[L.label,": ",L.type," (",L.colorName,")",ie]},L.globalTrayId)})]}),U.status==="match"?a.jsx(Vr,{className:"w-3 h-3 text-bambu-green"}):U.status==="type_only"?a.jsx("span",{title:"Same type, different color",children:a.jsx(Pn,{className:"w-3 h-3 text-yellow-400"})}):a.jsx("span",{title:"Filament type not loaded",children:a.jsx(Pn,{className:"w-3 h-3 text-orange-400"})})]},W)),a.jsxs("div",{className:"text-xs text-bambu-gray",children:[l("printModal.totalCost")," ",a.jsx("span",{className:"text-white",children:k>0||M?`${i}${k.toFixed(2)}`:"N/A"})]}),y&&a.jsx("p",{className:"text-xs text-orange-400 mt-2",children:"Required filament type not found in printer."})]})]})}function I$e({filamentReqs:t,availableFilaments:e,overrides:n,onChange:r}){const{t:i}=jt(),s=w.useMemo(()=>{const c={};for(const u of e){const d=u.type.toUpperCase();c[d]||(c[d]=[]),c[d].push(u)}return c},[e]),o=t?.filaments;if(!o||o.length===0||e.length===0)return null;const l=(c,u)=>{if(u===""){const d={...n};delete d[c],r(d)}else{const[d,h]=u.split("|");r({...n,[c]:{type:d,color:h}})}};return a.jsxs("div",{className:"mb-4",children:[a.jsx("div",{className:"flex items-center gap-2 text-sm text-bambu-gray mb-2",children:a.jsx("span",{children:i("printModal.filamentOverride")})}),a.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:i("printModal.filamentOverrideHint")}),a.jsx("div",{className:"bg-bambu-dark rounded-lg p-3 space-y-2",children:o.map(c=>{const u=n[c.slot_id],d=!!u,h=s[c.type.toUpperCase()]||[],f=c.nozzle_id!=null?h.filter(p=>p.extruder_id==null||p.extruder_id===c.nozzle_id):h;return a.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 20px"},children:[a.jsx("span",{title:`${i("printModal.originalFilament")}: ${c.type} - ${Ff(c.color)}`,children:a.jsx(R1,{className:"w-3 h-3",fill:c.color,stroke:c.color})}),a.jsxs("span",{className:"text-white truncate",children:[c.type," ",a.jsxs("span",{className:"text-bambu-gray",children:["(",c.used_grams,"g)"]})]}),a.jsx("span",{className:"text-bambu-gray",children:"→"}),a.jsxs("select",{value:d?`${u.type}|${u.color}`:"",onChange:p=>l(c.slot_id,p.target.value),disabled:f.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 ${d?"border-blue-400/50 text-blue-400":"border-bambu-gray/30 text-bambu-gray"}`,children:[a.jsxs("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:[i("printModal.originalFilament"),": ",c.type," (",Ff(c.color),")"]}),f.map((p,x)=>a.jsxs("option",{value:`${p.type}|${p.color}`,className:"bg-bambu-dark text-white",children:[p.type," (",Ff(p.color),")"]},`${p.type}-${p.color}-${x}`))]}),d?a.jsx("button",{type:"button",onClick:()=>l(c.slot_id,""),className:"text-bambu-gray hover:text-white transition-colors",title:i("printModal.resetToOriginal"),children:a.jsx(lo,{className:"w-3 h-3"})}):a.jsx("span",{className:"w-3"})]},c.slot_id)})})]})}function z$e({plates:t,isMultiPlate:e,selectedPlate:n,onSelect:r}){return!e||t.length<=1?null:a.jsxs("div",{className:"mb-4",children:[a.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[a.jsx(Va,{className:"w-4 h-4 text-bambu-gray"}),a.jsx("span",{className:"text-sm text-bambu-gray",children:"Select Plate to Print"}),!n&&a.jsxs("span",{className:"text-xs text-orange-400 flex items-center gap-1",children:[a.jsx(Pn,{className:"w-3 h-3"}),"Selection required"]})]}),a.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map(i=>a.jsxs("button",{type:"button",onClick:()=>r(i.index),className:`flex items-center gap-2 p-2 rounded-lg border transition-colors text-left ${n===i.index?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"}`,children:[i.has_thumbnail&&i.thumbnail_url!=null?a.jsx("img",{src:i.thumbnail_url,alt:`Plate ${i.index}`,className:"w-10 h-10 rounded object-cover bg-bambu-dark-tertiary"}):a.jsx("div",{className:"w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center",children:a.jsx(Va,{className:"w-5 h-5 text-bambu-gray"})}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("p",{className:"text-sm text-white font-medium truncate",children:i.name||`Plate ${i.index}`}),a.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[i.objects.length>0?i.objects.slice(0,3).join(", ")+(i.objects.length>3?"...":""):`${i.filaments.length} filament${i.filaments.length!==1?"s":""}`,i.print_time_seconds!=null?` • ${js(i.print_time_seconds)}`:""]})]}),n===i.index&&a.jsx(Vr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]},i.index))})]})}function U$e({printerResult:t,filamentReqs:e,onUpdateConfig:n}){const r=Jt(),[i,s]=w.useState(!1),o=(u,d)=>{if(u<=0)return;const h={...t.config.manualMappings};d===""?delete h[u]:h[u]=parseInt(d,10),n({useDefault:!1,manualMappings:h,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,h=t.config.manualMappings[d];let f,p=!1;if(h!==void 0)f=t.loadedFilaments.find(v=>v.globalTrayId===h),p=!0;else{const v=new Set(Object.values(t.config.manualMappings)),g=t.loadedFilaments.find(N=>!v.has(N.globalTrayId)&&N.type?.toUpperCase()===u.type?.toUpperCase()&&Fa(N.color)===Fa(u.color)),y=g?void 0:t.loadedFilaments.find(N=>!v.has(N.globalTrayId)&&N.type?.toUpperCase()===u.type?.toUpperCase()&&Bc(N.color,u.color)),_=g||y?void 0:t.loadedFilaments.find(N=>!v.has(N.globalTrayId)&&N.type?.toUpperCase()===u.type?.toUpperCase());f=g??y??_}let x="mismatch";if(f){const v=f.type?.toUpperCase()===u.type?.toUpperCase(),g=Fa(f.color)===Fa(u.color)||Bc(f.color,u.color);v&&g?x="match":v&&(x="type_only")}return{req:u,loaded:f,status:x,isManual:p}});return a.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom slot mapping"}),a.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:i,children:[a.jsx(vr,{className:`w-3 h-3 ${i?"animate-spin":""}`}),a.jsx("span",{children:"Re-read"})]})]}),c.map(({req:u,loaded:d,status:h,isManual:f},p)=>a.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[a.jsx("span",{title:`Required: ${u.type} - ${Ff(u.color)}`,children:a.jsx(R1,{className:"w-3 h-3",fill:u.color,stroke:u.color})}),a.jsxs("span",{className:"text-white truncate",children:[u.type," ",a.jsxs("span",{className:"text-bambu-gray",children:["(",u.used_grams,"g)"]})]}),a.jsx("span",{className:"text-bambu-gray",children:"→"}),a.jsxs("select",{value:d?.globalTrayId??"",onChange:x=>o(u.slot_id||0,x.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${h==="match"?"border-bambu-green/50 text-bambu-green":h==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${f?"ring-1 ring-blue-400/50":""}`,title:f?"Manually selected":"Auto-matched",children:[a.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),t.loadedFilaments.map(x=>a.jsxs("option",{value:x.globalTrayId,className:"bg-bambu-dark text-white",children:[x.label,": ",x.type," (",x.colorName,")"]},x.globalTrayId))]}),h==="match"?a.jsx(Vr,{className:"w-3 h-3 text-bambu-green"}):h==="type_only"?a.jsx("span",{title:"Same type, different color",children:a.jsx(Pn,{className:"w-3 h-3 text-yellow-400"})}):a.jsx("span",{title:"Filament type not loaded",children:a.jsx(Pn,{className:"w-3 h-3 text-orange-400"})})]},p))]})}function B$e({printers:t,selectedPrinterIds:e,onMultiSelect:n,isLoading:r=!1,allowMultiple:i=!1,showInactive:s=!1,printerMappingResults:o,filamentReqs:l,onAutoConfigurePrinter:c,onUpdatePrinterConfig:u,assignmentMode:d="printer",onAssignmentModeChange:h,targetModel:f,onTargetModelChange:p,targetLocation:x,onTargetLocationChange:v,slicedForModel:g}){const[y,_]=w.useState(!1),N=s?t:t.filter(X=>X.is_active),T=w.useMemo(()=>{if(d!=="printer"||!g||y)return N;const X=N.filter(se=>se.model===g);return X.length>0?X:N},[N,d,g,y]),k=N.length-T.length,M=w.useMemo(()=>{const X=N.map(se=>se.model).filter(se=>!!se);return[...new Set(X)].sort()},[N]),C=w.useMemo(()=>{if(!f)return[];const X=N.filter(se=>se.model===f&&se.location).map(se=>se.location).filter(se=>!!se);return[...new Set(X)].sort()},[N,f]),R=h&&p&&M.length>0,A=i&&e.length>1&&o&&l?.filaments&&l.filaments.length>0&&c&&u;if(r)return a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(T.length===0)return a.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm mb-4",children:[a.jsx($a,{className:"w-4 h-4"}),"No ",s?"":"active ","printers available"]});const D=X=>{i?e.includes(X)?n(e.filter(se=>se!==X)):n([...e,X]):n([X])},V=()=>{n(T.map(X=>X.id))},U=()=>{n([])},W=(X,se,ue)=>{ue.stopPropagation(),!(!c||!u)&&(se?c(X):u(X,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},L=X=>e.includes(X),te=e.length,ie=X=>o?.find(se=>se.printerId===X);return a.jsxs("div",{className:"space-y-2 mb-6",children:[R&&a.jsxs("div",{className:"flex gap-2 mb-4",children:[a.jsxs("button",{type:"button",onClick:()=>{h("printer"),p(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${d==="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:[a.jsx(wr,{className:"w-4 h-4"}),a.jsx("span",{className:"text-sm",children:"Specific Printer"})]}),a.jsxs("button",{type:"button",onClick:()=>{h("model"),n([]);const X=g&&M.includes(g)?g:M[0];p(X)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${d==="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:[a.jsx(vh,{className:"w-4 h-4"}),a.jsxs("span",{className:"text-sm",children:["Any ",g||"Model"]})]})]}),d==="model"&&R&&a.jsxs("div",{className:"space-y-3 mb-4",children:[!g&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Target Model"}),a.jsxs("select",{value:f||"",onChange:X=>{p(X.target.value||null),v&&v(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:[a.jsx("option",{value:"",children:"Select a model..."}),M.map(X=>a.jsx("option",{value:X,children:X},X))]})]}),f&&C.length>0&&v&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Location Filter (optional)"}),a.jsxs("select",{value:x||"",onChange:X=>v(X.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:[a.jsx("option",{value:"",children:"Any location"}),C.map(X=>a.jsx("option",{value:X,children:X},X))]})]}),f&&a.jsxs("p",{className:"text-xs text-bambu-gray",children:["Scheduler will assign to first available idle ",f," printer",x?` in ${x}`:""]})]}),d==="printer"&&i&&T.length>1&&a.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray mb-2",children:[a.jsx("span",{children:te===0?"Select printers":`${te} printer${te!==1?"s":""} selected`}),a.jsxs("div",{className:"flex gap-2",children:[te0&&a.jsx("button",{type:"button",onClick:U,className:"text-bambu-gray hover:text-white transition-colors",children:"Clear"})]})]}),d==="printer"&&T.map(X=>{const se=L(X.id),ue=ie(X.id),he=ue&&!ue.config.useDefault;return a.jsxs("div",{children:[a.jsxs("button",{type:"button",onClick:()=>D(X.id),className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${se?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"} ${X.is_active?"":"opacity-60"}`,children:[a.jsx("div",{className:`p-2 rounded-lg ${se?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:a.jsx(wr,{className:`w-5 h-5 ${se?"text-bambu-green":"text-bambu-gray"}`})}),a.jsxs("div",{className:"text-left flex-1",children:[a.jsxs("p",{className:"text-white font-medium",children:[X.name,!X.is_active&&a.jsx("span",{className:"text-bambu-gray text-xs ml-2",children:"(inactive)"})]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[X.model||"Unknown model"," • ",X.ip_address]})]}),i&&a.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${se?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:se&&a.jsx(Vr,{className:"w-3 h-3 text-white"})})]}),se&&A&&ue&&a.jsxs("div",{className:"ml-4 mt-2 mb-3",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",onClick:Q=>Q.stopPropagation(),children:[a.jsx("input",{type:"checkbox",checked:he,onChange:Q=>W(X.id,Q.target.checked,Q),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"}),a.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom mapping"})]}),a.jsxs("span",{className:`text-xs ml-2 ${ue.matchStatus==="full"?"text-bambu-green":ue.matchStatus==="partial"?"text-yellow-400":"text-orange-400"}`,children:["(",ue.exactMatches,"/",ue.totalSlots," matched)"]}),ue.isLoading&&a.jsx(vr,{className:"w-3 h-3 text-bambu-gray animate-spin"}),he&&a.jsxs("button",{type:"button",onClick:Q=>{Q.stopPropagation(),c(X.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:[a.jsx(Rge,{className:"w-3 h-3"}),"Auto"]})]}),he&&a.jsx(U$e,{printerResult:ue,filamentReqs:l.filaments,onUpdateConfig:Q=>u(X.id,Q)})]})]},X.id)}),d==="printer"&&k>0&&!y&&a.jsxs("button",{type:"button",onClick:()=>_(!0),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2 flex items-center gap-1",children:[a.jsx(Pn,{className:"w-3 h-3 text-yellow-400"}),k," other printer",k>1?"s":""," hidden (different model) —",a.jsx("span",{className:"underline",children:"show all"})]}),d==="printer"&&y&&g&&a.jsx("button",{type:"button",onClick:()=>_(!1),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2",children:a.jsxs("span",{className:"underline",children:["Show only ",g," printers"]})}),d==="printer"&&te===0&&a.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[a.jsx($a,{className:"w-3 h-3"}),"Select at least one printer"]}),d==="model"&&!f&&a.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[a.jsx($a,{className:"w-3 h-3"}),"Select a target printer model"]})]})}const H$e=[{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 $$e({options:t,onChange:e,defaultExpanded:n=!1}){const[r,i]=w.useState(n),s=o=>{e({...t,[o]:!t[o]})};return a.jsxs("div",{className:"mb-4",children:[a.jsxs("button",{type:"button",onClick:()=>i(!r),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[a.jsx(mk,{className:"w-4 h-4"}),a.jsx("span",{children:"Print Options"}),r?a.jsx(Sl,{className:"w-4 h-4 ml-auto"}):a.jsx(Fn,{className:"w-4 h-4 ml-auto"})]}),r&&a.jsx("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:H$e.map(({key:o,label:l,desc:c})=>a.jsxs("label",{className:"flex items-center justify-between cursor-pointer group",children:[a.jsxs("div",{children:[a.jsx("span",{className:"text-sm text-white",children:l}),a.jsx("p",{className:"text-xs text-bambu-gray",children:c})]}),a.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:a.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 q$e({options:t,onChange:e,dateFormat:n="system",timeFormat:r="system",canControlPrinter:i=!0}){const[s,o]=w.useState(""),[l,c]=w.useState(""),[u,d]=w.useState(!0),[h,f]=w.useState(!0),p=w.useRef(null),x=w.useRef(!1);w.useEffect(()=>{if(t.scheduleType!=="scheduled"){x.current=!1;return}if(!x.current){x.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:A3(k)})),o(T3(k,n)),c(a8(k,r)),d(!0),f(!0)}},[t.scheduleType,t.scheduledTime,n,r,e,t]);const v=k=>{e({...t,scheduleType:k})},g=(k,M)=>{const C=nbe(k,n),R=rbe(M);d(!!C),f(!!R),C&&R&&(C.setHours(R.hours,R.minutes,0,0),C>new Date&&e({...t,scheduledTime:A3(C)}))},y=k=>{o(k),g(k,l)},_=k=>{c(k),g(s,k)},N=k=>{const M=k.target.value;if(M){const C=new Date(M);isNaN(C.getTime())||(o(T3(C,n)),c(a8(C,r)),d(!0),f(!0),e({...t,scheduledTime:M}))}},T=()=>{p.current?.showPicker()};return a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"When to print"}),a.jsxs("div",{className:"flex gap-2",children:[a.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:[a.jsx(Qn,{className:"w-4 h-4"}),"ASAP"]}),a.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:[a.jsx(Xr,{className:"w-4 h-4"}),"Scheduled"]}),a.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:[a.jsx(HY,{className:"w-4 h-4"}),"Queue Only"]})]})]}),t.scheduleType==="scheduled"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date & Time"}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("div",{className:"flex-1 relative",children:[a.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=>y(k.target.value),placeholder:ebe(n)}),a.jsx("button",{type:"button",onClick:T,className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",title:"Open calendar",children:a.jsx(Xr,{className:"w-4 h-4"})})]}),a.jsx("div",{className:"w-32",children:a.jsx("input",{type:"text",className:`w-full px-3 py-2 bg-bambu-dark border rounded-lg text-white focus:outline-none ${h?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:l,onChange:k=>_(k.target.value),placeholder:tbe(r)})})]}),a.jsx("input",{ref:p,type:"datetime-local",className:"sr-only",value:t.scheduledTime,onChange:N,tabIndex:-1}),(!u||!h)&&a.jsx("p",{className:"mt-1 text-xs text-red-400",children:"Please enter a valid date and time"})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.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"}),a.jsx("label",{htmlFor:"requirePrevious",className:"text-sm text-bambu-gray",children:"Only start if previous print succeeded"})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"checkbox",id:"autoOffAfter",checked:t.autoOffAfter,onChange:k=>e({...t,autoOffAfter:k.target.checked}),disabled:!i,className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green disabled:opacity-50"}),a.jsxs("label",{htmlFor:"autoOffAfter",className:`text-sm flex items-center gap-1 ${i?"text-bambu-gray":"text-bambu-gray/50"}`,children:[a.jsx(yd,{className:"w-3.5 h-3.5"}),"Power off printer when done"]})]}),a.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 zg={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1},V$e={scheduleType:"asap",scheduledTime:"",requirePreviousSuccess:!1,autoOffAfter:!1};function Hc({mode:t,archiveId:e,libraryFileId:n,archiveName:r,queueItem:i,initialSelectedPrinterIds:s,onClose:o,onSuccess:l}){const{t:c}=jt(),u=Jt(),{showToast:d}=mn(),{hasPermission:h}=jr(),f=!!n&&!e,[p,x]=w.useState(()=>t==="edit-queue-item"&&i?.printer_id?[i.printer_id]:s?.length?s:[]),[v,g]=w.useState(()=>t==="edit-queue-item"&&i?i.plate_id:null),[y,_]=w.useState(()=>t==="edit-queue-item"&&i?{bed_levelling:i.bed_levelling??zg.bed_levelling,flow_cali:i.flow_cali??zg.flow_cali,vibration_cali:i.vibration_cali??zg.vibration_cali,layer_inspect:i.layer_inspect??zg.layer_inspect,timelapse:i.timelapse??zg.timelapse}:zg),[N,T]=w.useState(()=>{if(t==="edit-queue-item"&&i){let we="asap";i.manual_start?we="manual":i.scheduled_time&&!yG(i.scheduled_time)&&(we="scheduled");let Ge="";if(i.scheduled_time&&!yG(i.scheduled_time)){const nt=er(i.scheduled_time)??new Date;Ge=A3(nt)}return{scheduleType:we,scheduledTime:Ge,requirePreviousSuccess:i.require_previous_success,autoOffAfter:i.auto_off_after}}return V$e}),[k,M]=w.useState(()=>{if(t==="edit-queue-item"&&i?.ams_mapping&&Array.isArray(i.ams_mapping)){const we={};return i.ams_mapping.forEach((Ge,nt)=>{Ge!==-1&&(we[nt+1]=Ge)}),we}return{}}),[C,R]=w.useState({}),[A,D]=w.useState(()=>t==="edit-queue-item"&&i?.target_model?"model":"printer"),[V,U]=w.useState(()=>t==="edit-queue-item"&&i?.target_model?i.target_model:null),[W,L]=w.useState(()=>t==="edit-queue-item"&&i?.target_location?i.target_location:null),[te,ie]=w.useState(()=>{if(t==="edit-queue-item"&&i?.filament_overrides){const we={};for(const Ge of i.filament_overrides)we[Ge.slot_id]={type:Ge.type,color:Ge.color};return we}return{}}),[X]=w.useState(()=>t==="edit-queue-item"&&i?.printer_id?[i.printer_id]:[]),[se]=w.useState(()=>t==="edit-queue-item"&&i?i.plate_id:null),[ue,he]=w.useState(!1),[Q,oe]=w.useState({current:0,total:0}),[fe,be]=w.useState(new Set),Re=p.length,$=p.length>0?p[0]:null,{data:K}=Je({queryKey:["settings"],queryFn:ge.getSettings}),P=sl(K?.currency||"USD"),E=K?.default_filament_cost??0,{data:O,isLoading:G}=Je({queryKey:["printers"],queryFn:ge.getPrinters}),{data:B}=Je({queryKey:["archive",e],queryFn:()=>ge.getArchive(e),enabled:!!e&&!f}),{data:re}=Je({queryKey:["library-file",n],queryFn:()=>ge.getLibraryFile(n),enabled:f&&!!n}),z=B?.sliced_for_model||re?.sliced_for_model||null,{data:q,isError:ee}=Je({queryKey:["archive-plates",e],queryFn:()=>ge.getArchivePlates(e),enabled:!!e&&!f,retry:!1}),{data:J}=Je({queryKey:["library-file-plates",n],queryFn:()=>ge.getLibraryFilePlates(n),enabled:f&&!!n}),ne=f?J:q,{data:ae,isError:de}=Je({queryKey:["archive-filaments",e,v],queryFn:()=>ge.getArchiveFilamentRequirements(e,v??void 0),enabled:!!e&&!f&&(v!==null||!ne?.is_multi_plate),retry:!1}),{data:ye}=Je({queryKey:["library-file-filaments",n,v],queryFn:()=>ge.getLibraryFileFilamentRequirements(n,v??void 0),enabled:f&&!!n&&(v!==null||!ne?.is_multi_plate)}),le=!f&&(ee||de),I=f?ye:ae,F=w.useMemo(()=>{if(!(v===null||!ne?.plates?.length))return ne.plates.find(we=>we.index===v)?.name||void 0},[ne,v]),{data:Z}=Je({queryKey:["available-filaments",V,W],queryFn:()=>ge.getAvailableFilaments(V,W??void 0),enabled:A==="model"&&!!V}),{data:xe}=Je({queryKey:["printer-status",$],queryFn:()=>ge.getPrinterStatus($),enabled:!!$}),{amsMapping:me}=$ne(I,xe,k),ce=R$e(p,O,I,k,C,R);w.useEffect(()=>{ne?.plates&&ne.plates.length>=1&&!v&&g(ne.plates[0].index)},[ne,v]),w.useEffect(()=>{if(t==="edit-queue-item")return;const we=O?.filter(Ge=>Ge.is_active)||[];we.length===1&&p.length===0&&x([we[0].id])},[t,O,p.length]),w.useEffect(()=>{t==="edit-queue-item"?(JSON.stringify(p.sort())!==JSON.stringify(X.sort())||v!==se)&&(M({}),R({}),be(new Set)):(M({}),R({}),be(new Set))},[t,p,v,X,se]);const[Ne,_e]=w.useState(V),[He,$e]=w.useState(v);w.useEffect(()=>{(V!==Ne||v!==He)&&(_e(V),$e(v),(t!=="edit-queue-item"||Ne!==null)&&ie({}))},[V,v,Ne,He,t]),w.useEffect(()=>{if(!K?.per_printer_mapping_expanded||p.length<=1)return;const we=p.filter(Ge=>{if(fe.has(Ge))return!1;const nt=ce.printerResults.find(vt=>vt.printerId===Ge);return nt&&nt.status&&!nt.isLoading});we.length>0&&(be(Ge=>{const nt=new Set(Ge);return we.forEach(vt=>nt.add(vt)),nt}),we.forEach(Ge=>{ce.autoConfigurePrinter(Ge)}))},[K?.per_printer_mapping_expanded,p,fe,ce]),w.useEffect(()=>{const we=Ge=>{Ge.key==="Escape"&&!ue&&o()};return window.addEventListener("keydown",we),()=>window.removeEventListener("keydown",we)},[o,ue]);const Fe=ne?.is_multi_plate??!1,ke=ne?.plates??[],Me=ut({mutationFn:we=>ge.addToQueue(we)}),Ce=ut({mutationFn:we=>ge.updateQueueItem(i.id,we),onSuccess:()=>{u.invalidateQueries({queryKey:["queue"]}),d("Queue item updated"),l?.(),o()},onError:we=>{d(we.message||"Failed to update queue item","error")}}),Pe=async we=>{if(we?.preventDefault(),A==="printer"&&p.length===0){d("Please select at least one printer","error");return}if(A==="model"&&!V){d("Please select a target printer model","error");return}he(!0);const Ge=A==="model"?1:p.length;oe({current:0,total:Ge});const nt={success:0,failed:0,errors:[]},vt=qe=>{if(p.length>1){const mt=C[qe];if(mt&&!mt.useDefault)return ce.getFinalMapping(qe)}return me},_t=Object.keys(te).length>0?Object.entries(te).map(([qe,{type:mt,color:gt}])=>({slot_id:parseInt(qe,10),type:mt,color:gt})):void 0,Nt=qe=>({printer_id:A==="printer"?qe:null,target_model:A==="model"?V:null,target_location:A==="model"?W:null,filament_overrides:A==="model"?_t:void 0,archive_id:f?void 0:e,library_file_id:f?n:void 0,require_previous_success:N.requirePreviousSuccess,auto_off_after:N.autoOffAfter,manual_start:N.scheduleType==="manual",ams_mapping:qe?vt(qe):void 0,plate_id:v,scheduled_time:N.scheduleType==="scheduled"&&N.scheduledTime?new Date(N.scheduledTime).toISOString():void 0,...y});if(A==="model"){oe({current:1,total:1});try{if(t==="reprint"){d("Model-based assignment only works with queue mode","error"),he(!1);return}else if(t==="edit-queue-item"){const qe={printer_id:null,target_model:V,target_location:W,filament_overrides:_t||null,require_previous_success:N.requirePreviousSuccess,auto_off_after:N.autoOffAfter,manual_start:N.scheduleType==="manual",ams_mapping:void 0,plate_id:v,scheduled_time:N.scheduleType==="scheduled"&&N.scheduledTime?new Date(N.scheduledTime).toISOString():null,...y};await Ce.mutateAsync(qe)}else await Me.mutateAsync(Nt(null));nt.success++}catch(qe){nt.failed++,nt.errors.push(qe.message)}}else for(let qe=0;qeen.id===mt)?.name||`Printer ${mt}`;nt.errors.push(`${It}: ${gt.message}`)}}he(!1),nt.failed===0?(t!=="reprint"&&(A==="model"?d(t==="edit-queue-item"?"Queue item updated":`Queued for any ${V}`):t==="edit-queue-item"?d("Queue item updated"):nt.success===1?d("Print queued for printer"):d(`Print queued for ${nt.success} printers`)),u.invalidateQueries({queryKey:["queue"]}),l?.(),o()):nt.success===0?d(`Failed: ${nt.errors[0]}`,"error"):(d(`${nt.success} succeeded, ${nt.failed} failed`,"error"),u.invalidateQueries({queryKey:["queue"]}))},We=ue||Ce.isPending,pe=w.useMemo(()=>!(We||A==="printer"&&p.length===0||A==="model"&&!V||A==="model"&&t==="reprint"||Fe&&!v),[p.length,A,V,t,Fe,v,We]),Te=(()=>{const we=p.length;return t==="reprint"?{title:c(f?"queue.print":"queue.reprint"),icon:wr,submitText:we>1?c("queue.printToPrinters",{count:we}):c("queue.print"),submitIcon:wr,loadingText:Q.total>1?c("queue.sendingProgress",{current:Q.current,total:Q.total}):c("queue.sending")}:t==="add-to-queue"?{title:c("queue.schedulePrint"),icon:Xr,submitText:we>1?c("queue.queueToPrinters",{count:we}):c("queue.addToQueue"),submitIcon:Xr,loadingText:Q.total>1?c("queue.addingProgress",{current:Q.current,total:Q.total}):c("queue.adding")}:{title:c("queue.editQueueItem"),icon:Wa,submitText:c("common.save"),submitIcon:Wa,loadingText:Q.total>1?c("queue.savingProgress",{current:Q.current,total:Q.total}):c("common.saving")}})(),Ve=Te.icon,Ee=Te.submitIcon,De=$&&(f||(Fe?v!==null:!0));return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:ue?void 0:o,children:a.jsx(Tt,{className:"w-full max-w-lg max-h-[90vh] overflow-y-auto",onClick:we=>we.stopPropagation(),children:a.jsxs(At,{className:t==="reprint"?"":"p-0",children:[a.jsxs("div",{className:`flex items-center justify-between ${t==="reprint"?"mb-4":"p-4 border-b border-bambu-dark-tertiary"}`,children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ve,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:Te.title})]}),a.jsx(Ie,{variant:"ghost",size:"sm",onClick:o,disabled:ue,children:a.jsx(Bt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:Pe,className:t==="reprint"?"":"p-4 space-y-4",children:[a.jsx("p",{className:`text-sm text-bambu-gray ${t==="reprint"?"mb-4":""}`,children:t==="reprint"?a.jsxs(a.Fragment,{children:["Send ",a.jsx("span",{className:"text-white",children:r})," to"," ",s?.length===1&&O?a.jsx("span",{className:"text-white",children:O.find(we=>we.id===s[0])?.name??"printer(s)"}):"printer(s)"]}):a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"block text-bambu-gray mb-1",children:"Print Job"}),a.jsx("span",{className:"text-white font-medium truncate block",children:r})]})}),a.jsx(z$e,{plates:ke,isMultiPlate:Fe,selectedPlate:v,onSelect:g}),!s?.length&&a.jsx(B$e,{printers:O||[],selectedPrinterIds:p,onMultiSelect:x,isLoading:G,allowMultiple:!0,showInactive:t==="edit-queue-item",printerMappingResults:ce.printerResults,filamentReqs:I,onAutoConfigurePrinter:ce.autoConfigurePrinter,onUpdatePrinterConfig:ce.updatePrinterConfig,assignmentMode:t==="reprint"?"printer":A,onAssignmentModeChange:t!=="reprint"?D:void 0,targetModel:V,onTargetModelChange:t!=="reprint"?U:void 0,targetLocation:W,onTargetLocationChange:t!=="reprint"?L:void 0,slicedForModel:z}),A==="model"&&V&&I&&Z&&Z.length>0&&a.jsx(I$e,{filamentReqs:I,availableFilaments:Z,overrides:te,onChange:ie}),z&&A==="printer"&&p.length===1&&(()=>{const we=O?.find(Ge=>Ge.id===p[0]);return we&&we.model&&z!==we.model?a.jsxs("div",{className:"p-3 mb-2 bg-yellow-500/10 border border-yellow-500/30 rounded-lg flex items-center gap-2",children:[a.jsx(Pn,{className:"w-4 h-4 text-yellow-400 flex-shrink-0"}),a.jsxs("span",{className:"text-sm text-yellow-400",children:["File was sliced for ",z,", but printing on ",we.model]})]}):null})(),le&&a.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:[a.jsx($a,{className:"w-4 h-4 text-orange-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-orange-400",children:"Archive data unavailable. The source file may have been deleted. Filament mapping is disabled."})]}),De&&!le&&p.length===1&&a.jsx(O$e,{printerId:$,filamentReqs:I,manualMappings:k,onManualMappingChange:M,defaultExpanded:!!s?.length||(K?.per_printer_mapping_expanded??!1),currencySymbol:P,defaultCostPerKg:E}),(t==="reprint"||Re>0||A==="model"&&V)&&a.jsx($$e,{options:y,onChange:_,defaultExpanded:!!s?.length}),t!=="reprint"&&a.jsx(q$e,{options:N,onChange:T,dateFormat:K?.date_format||"system",timeFormat:K?.time_format||"system",canControlPrinter:h("printers:control")}),Ce.isError&&a.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"}),a.jsxs("div",{className:`flex gap-3 ${t==="reprint"?"":"pt-2"}`,children:[a.jsx(Ie,{type:"button",variant:"secondary",onClick:o,className:"flex-1",disabled:ue,children:"Cancel"}),a.jsx(Ie,{type:"submit",disabled:!pe,className:"flex-1",children:We?a.jsxs(a.Fragment,{children:[a.jsx(lt,{className:"w-4 h-4 animate-spin"}),Te.loadingText]}):a.jsxs(a.Fragment,{children:[a.jsx(Ee,{className:"w-4 h-4"}),Te.submitText]})})]})]})]})})})}function qne(t){if(!t)return"/img/printers/default.png";const e=t.toLowerCase().replace(/\s+/g,"");return e.includes("x1e")?"/img/printers/x1e.png":e.includes("x1c")||e.includes("x1carbon")||e.includes("x1")?"/img/printers/x1c.png":e.includes("h2dpro")||e.includes("h2d-pro")?"/img/printers/h2dpro.png":e.includes("h2d")?"/img/printers/h2d.png":e.includes("h2c")?"/img/printers/h2c.png":e.includes("h2s")?"/img/printers/h2d.png":e.includes("p2s")||e.includes("p1s")?"/img/printers/p1s.png":e.includes("p1p")?"/img/printers/p1p.png":e.includes("a1mini")?"/img/printers/a1mini.png":e.includes("a1")?"/img/printers/a1.png":"/img/printers/default.png"}function Vne(t){return t>=-50?{labelKey:"printers.wifiSignal.excellent",color:"text-bambu-green",bars:4}:t>=-60?{labelKey:"printers.wifiSignal.good",color:"text-bambu-green",bars:3}:t>=-70?{labelKey:"printers.wifiSignal.fair",color:"text-yellow-400",bars:2}:t>=-80?{labelKey:"printers.wifiSignal.weak",color:"text-orange-400",bars:1}:{labelKey:"printers.wifiSignal.veryWeak",color:"text-red-400",bars:1}}function SG({value:t}){const{t:e}=jt(),[n,r]=w.useState(!1),i=async()=>{try{await navigator.clipboard.writeText(t),r(!0),setTimeout(()=>r(!1),2e3)}catch{}};return a.jsx("button",{onClick:i,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?a.jsx(Vr,{className:"w-3.5 h-3.5 text-bambu-green"}):a.jsx(_l,{className:"w-3.5 h-3.5"})})}function G$e({printer:t,status:e,totalPrintHours:n,onClose:r}){const{t:i}=jt();w.useEffect(()=>{const o=l=>{l.key==="Escape"&&r()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[r]);const s=[];if(s.push({label:i("printers.model"),value:t.model??"—"}),s.push({label:i("common.status"),value:a.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:[a.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${e?.connected?"bg-bambu-green":"bg-red-400"}`}),e?.connected?i("printers.status.available"):i("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:i("printers.state"),value:i(o[e.state]??"printers.status.unknown")})}if(s.push({label:i("printers.ipAddress"),value:a.jsxs("span",{className:"flex items-center",children:[a.jsx("span",{className:"font-mono",children:t.ip_address}),a.jsx(SG,{value:t.ip_address})]})}),s.push({label:i("printers.serialNumber"),value:a.jsxs("span",{className:"flex items-center",children:[a.jsx("span",{className:"font-mono truncate",children:t.serial_number}),a.jsx(SG,{value:t.serial_number})]})}),e?.wifi_signal!=null){const o=Vne(e.wifi_signal);s.push({label:i("printers.wifiSignalLabel"),value:a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsx(WY,{className:`w-4 h-4 ${o.color}`}),a.jsx("span",{className:o.color,children:i(o.labelKey)}),a.jsxs("span",{className:"text-bambu-gray text-xs",children:["(",e.wifi_signal," dBm)"]})]})})}return s.push({label:i("printers.firmware"),value:e?.firmware_version??"—"}),e?.developer_mode!=null&&s.push({label:i("printers.developerMode"),value:a.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?i("printers.enabled"):i("printers.disabled")})}),s.push({label:i("printers.nozzleCount"),value:t.nozzle_count}),e?.sdcard!=null&&s.push({label:i("printers.sdCard"),value:a.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?i("printers.inserted"):i("printers.notInserted")})}),s.push({label:i("printers.autoArchive"),value:a.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?i("printers.enabled"):i("printers.disabled")})}),n!=null&&n>0&&s.push({label:i("printers.totalPrintHours"),value:`${Math.round(n)}h`}),t.location&&s.push({label:i("printers.sort.location"),value:t.location}),s.push({label:i("printers.addedOn"),value:Kf(t.created_at)}),a.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:a.jsx(Tt,{className:"w-full max-w-md",onClick:o=>o.stopPropagation(),children:a.jsxs(At,{children:[a.jsxs("div",{className:"flex items-center justify-between mb-4",children:[a.jsx("h2",{className:"text-lg font-semibold text-white",children:t.name}),a.jsx("button",{onClick:r,className:"p-1 hover:bg-bambu-dark rounded flex-shrink-0",children:a.jsx(Bt,{className:"w-5 h-5 text-bambu-gray"})})]}),a.jsx("div",{className:"flex justify-center mb-4",children:a.jsx("img",{src:qne(t.model),alt:t.model??t.name,className:"h-24 object-contain"})}),a.jsx("div",{className:"space-y-0",children:s.map((o,l)=>a.jsxs("div",{className:"flex items-center justify-between gap-4 py-2.5 border-b border-bambu-dark-tertiary last:border-0",children:[a.jsx("span",{className:"text-sm text-bambu-gray whitespace-nowrap",children:o.label}),a.jsx("span",{className:"text-sm text-white text-right",children:o.value})]},l))})]})})})}const _G={"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"},W$e={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 nE(t){if(!t)return null;if(_G[t])return _G[t];const e=t.split("-");if(e.length<2)return null;const n=e[1];return W$e[n]||null}function rE(t){if(!t||t.length<6)return"Unknown";const e=parseInt(t.substring(0,2),16),n=parseInt(t.substring(2,4),16),r=parseInt(t.substring(4,6),16),i=Math.max(e,n,r)/255,s=Math.min(e,n,r)/255,o=(i+s)/2;let l=0,c=0;if(i!==s){const u=i-s;c=o>.5?u/(2-i-s):u/(i+s);const d=e/255,h=n/255,f=r/255;i===d?l=((h-f)/u+(h.85?"White":c<.15?o<.4?"Dark Gray":o>.6?"Light Gray":"Gray":l>=15&&l<45&&o<.45||l>=45&&l<70&&o<.4?"Brown":l<15||l>=345?"Red":l<45?"Orange":l<70?"Yellow":l<150?"Green":l<200?"Cyan":l<260?"Blue":l<290?"Purple":"Pink"}function aE(t){return(t??.02).toFixed(3)}function NG({side:t}){const{mode:e}=bp(),n=e==="dark"?"#1a4d2e":"#e7f5e9";return a.jsx("span",{className:"inline-flex items-center justify-center w-4 h-4 text-[10px] font-bold rounded",style:{backgroundColor:n,color:"#00ae42"},children:t})}function jO(t){if(!t||t==="00000000"||t.length<6)return null;const e=t.slice(0,2),n=t.slice(2,4),r=t.slice(4,6),i=t.length>=8?parseInt(t.slice(6,8),16)/255:1;return i===0?null:`rgba(${parseInt(e,16)}, ${parseInt(n,16)}, ${parseInt(r,16)}, ${i})`}function K$e(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 Gne(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 Wne(t,e){return t?t.startsWith("HH")?e("printers.nozzleHighFlow"):t.startsWith("HS")?e("printers.nozzleStandardFlow"):"":""}function Kne({slot:t,index:e,activeStatus:n,filamentName:r,children:i}){const{t:s}=jt(),[o,l]=w.useState(!1),[c,u]=w.useState("top"),d=w.useRef(null),h=w.useRef(null),f=w.useRef(null),p=!t.nozzle_diameter&&!t.nozzle_type,x=t.stat===1;w.useEffect(()=>{if(o&&d.current&&h.current){const T=d.current.getBoundingClientRect(),k=h.current.offsetHeight,C=T.top-56,R=window.innerHeight-T.bottom;CC?u("bottom"):u("top")}},[o]);const v=()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>l(!0),80)},g=()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>l(!1),100)};w.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]);const y=jO(t.filament_color),_=Gne(t.nozzle_type,s),N=Wne(t.nozzle_type,s);return a.jsxs("div",{ref:d,className:"relative",onMouseEnter:v,onMouseLeave:g,children:[i,o&&a.jsxs("div",{ref:h,className:` absolute left-1/2 -translate-x-1/2 z-50 ${c==="top"?"bottom-full mb-2":"top-full mt-2"} animate-in fade-in-0 zoom-in-95 duration-150 diff --git a/static/index.html b/static/index.html index 3097a9966..5b0e47313 100644 --- a/static/index.html +++ b/static/index.html @@ -23,7 +23,7 @@ - +