diff --git a/static/assets/index-kl_IYtg7.js b/static/assets/index-BfIGXFHd.js similarity index 99% rename from static/assets/index-kl_IYtg7.js rename to static/assets/index-BfIGXFHd.js index 29497ebe7..dbc136c6b 100644 --- a/static/assets/index-kl_IYtg7.js +++ b/static/assets/index-BfIGXFHd.js @@ -8660,6 +8660,6 @@ Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${t0(t. `+n+"]";if(typeof t=="object"){const r=Object.entries(t);return r.length===0?"{}":`{ `+r.map(([a,o])=>n+" "+JSON.stringify(a)+": "+dR(o,e+1)).join(`, `)+` -`+n+"}"}return String(t)}function UKe({setting:t,onClose:e,onDeleted:n,onDuplicate:r,onEdit:i,hasPermission:a,t:o}){const{showToast:l}=Vn(),c=ln(),[u,d]=_.useState(!1),{data:f,isLoading:p}=ot({queryKey:["cloudSettingDetail",t.setting_id],queryFn:()=>ce.getCloudSettingDetail(t.setting_id)}),m=gt({mutationFn:()=>ce.deleteCloudSetting(t.setting_id),onSuccess:()=>{l(o("profiles.presets.toast.deleted")),c.invalidateQueries({queryKey:["cloudSettings"]}),n()},onError:v=>l(v.message,"error")}),x=Ry(t.setting_id),b=cF(t.name,f?.setting?.inherits);return s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:s.jsx(Nt,{className:"w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden",children:s.jsxs(Mt,{className:"p-0 flex flex-col min-h-0 flex-1",children:[s.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h2",{className:"text-xl font-semibold text-white truncate",children:t.name}),x&&s.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full",children:o("profiles.presets.editable")})]}),s.jsxs("div",{className:"flex items-center gap-2 mt-1 text-sm text-bambu-gray",children:[s.jsx("span",{className:"capitalize",children:o(`profiles.presets.types.${t.type}`)}),b.printer&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"•"}),s.jsx("span",{children:b.printer})]})]})]}),s.jsx("button",{onClick:e,className:"p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:s.jsx(Lt,{className:"w-5 h-5"})})]}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto p-4",children:p?s.jsx("div",{className:"flex items-center justify-center py-16",children:s.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):f?s.jsx("pre",{className:"text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full",children:dR(f)}):s.jsx("div",{className:"text-center py-16 text-bambu-gray",children:o("profiles.presets.failedToLoadDetails")})}),u?s.jsxs("div",{className:"flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-3 text-red-400",children:[s.jsx(Sn,{className:"w-5 h-5"}),s.jsx("span",{className:"font-medium",children:o("profiles.presets.deleteConfirm")})]}),s.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:o("profiles.presets.deleteWarning",{name:t.name})}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Te,{variant:"secondary",onClick:()=>d(!1),disabled:m.isPending,className:"flex-1",children:o("common.cancel")}),s.jsxs(Te,{variant:"danger",onClick:()=>m.mutate(),disabled:m.isPending,className:"flex-1",children:[m.isPending?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):s.jsx(on,{className:"w-4 h-4"}),o("common.delete")]})]})]}):s.jsx("div",{className:"flex-shrink-0 p-4 border-t border-bambu-dark-tertiary",children:s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Te,{variant:"secondary",onClick:e,className:"flex-1",children:o("common.close")}),s.jsxs(Te,{variant:"secondary",onClick:r,disabled:!a("cloud:auth"),title:a("cloud:auth")?void 0:o("profiles.presets.noDuplicatePermission"),children:[s.jsx(Fl,{className:"w-4 h-4"}),o("profiles.presets.duplicate")]}),x&&s.jsxs(s.Fragment,{children:[s.jsxs(Te,{variant:"secondary",onClick:i,disabled:p||!f||!a("cloud:auth"),title:a("cloud:auth")?void 0:o("profiles.presets.noEditPermission"),children:[s.jsx(Zi,{className:"w-4 h-4"}),o("common.edit")]}),s.jsx(Te,{variant:"danger",onClick:()=>d(!0),disabled:!a("cloud:auth"),title:a("cloud:auth")?void 0:o("profiles.presets.noDeletePermission"),children:s.jsx(on,{className:"w-4 h-4"})})]})]})})]})})})}function zre(){try{const t=localStorage.getItem("bambusy_preset_templates");return t?JSON.parse(t):[]}catch{return[]}}function Bre(t){localStorage.setItem("bambusy_preset_templates",JSON.stringify(t))}function zKe({onClose:t,onApply:e,t:n}){const{showToast:r}=Vn(),[i,a]=_.useState(zre),[o,l]=_.useState("all"),[c,u]=_.useState(null),[d,f]=_.useState(""),[p,m]=_.useState(""),[x,b]=_.useState("{}"),[v,y]=_.useState(null),[S,M]=_.useState(null),T=o==="all"?i:i.filter(H=>H.type===o),k=H=>{a(H),Bre(H)},C=H=>{const R=i.filter(z=>z.id!==H);k(R),M(null),r(n("profiles.templates.toast.deleted"))},E=H=>{u(H.id),f(H.name),m(H.description),b(JSON.stringify(H.settings,null,2)),y(null)},D=()=>{if(!(!c||!d.trim()))try{const H=JSON.parse(x),R=i.map(z=>z.id===c?{...z,name:d.trim(),description:p.trim(),settings:H}:z);k(R),u(null),r(n("profiles.templates.toast.updated"))}catch(H){y(H.message)}},A=()=>{u(null),f(""),m(""),b("{}"),y(null)},j=H=>{const R=i.map(z=>z.id===H?{...z,showInModal:!z.showInModal}:z);k(R)},I={filament:{label:n("profiles.presets.types.filament"),icon:TR,color:"text-amber-400"},print:{label:n("profiles.presets.types.process"),icon:vh,color:"text-blue-400"},printer:{label:n("profiles.presets.types.printer"),icon:Pr,color:"text-purple-400"}},F=S?i.find(H=>H.id===S):null;return _.useEffect(()=>{const H=R=>{R.key==="Escape"&&(S?M(null):c?A():t())};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[S,c,t]),s.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:[F&&s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-60",children:s.jsx(Nt,{className:"w-full max-w-md",children:s.jsxs(Mt,{className:"p-6",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[s.jsx("div",{className:"p-2 bg-red-500/20 rounded-lg",children:s.jsx(Sn,{className:"w-6 h-6 text-red-400"})}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-lg font-semibold text-white",children:n("profiles.templates.deleteTitle")}),s.jsx("p",{className:"text-sm text-bambu-gray",children:n("profiles.templates.deleteWarning")})]})]}),s.jsx("p",{className:"text-white mb-6",children:n("profiles.templates.deleteConfirm",{name:F.name})}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Te,{variant:"secondary",onClick:()=>M(null),className:"flex-1",children:n("common.cancel")}),s.jsxs(Te,{onClick:()=>C(S),className:"flex-1 bg-red-500 hover:bg-red-600",children:[s.jsx(on,{className:"w-4 h-4"}),n("common.delete")]})]})]})})}),s.jsx(Nt,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",children:s.jsxs(Mt,{className:"p-0 flex flex-col h-full",children:[s.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(W0,{className:"w-5 h-5 text-amber-400"}),n("profiles.templates.title")]}),s.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white",children:s.jsx(Lt,{className:"w-5 h-5"})})]}),s.jsxs("div",{className:"flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary",children:[s.jsx("span",{className:"text-sm text-bambu-gray",children:n("profiles.templates.typeFilter")}),["all","filament","print","printer"].map(H=>s.jsx("button",{onClick:()=>l(H),className:`px-3 py-1 text-sm rounded-lg transition-colors ${o===H?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:H==="all"?n("common.all"):I[H].label},H))]}),s.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:T.length===0?s.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[s.jsx(W0,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),s.jsx("p",{children:n("profiles.templates.noTemplates")}),s.jsx("p",{className:"text-sm mt-1",children:n("profiles.templates.createFirst")})]}):s.jsx("div",{className:"space-y-2",children:T.map(H=>{const R=I[H.type],z=R.icon;return c===H.id?s.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-green",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-3 mb-3",children:[s.jsx("input",{type:"text",value:d,onChange:W=>f(W.target.value),placeholder:n("profiles.templates.namePlaceholder"),className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",autoFocus:!0}),s.jsx("input",{type:"text",value:p,onChange:W=>m(W.target.value),placeholder:n("profiles.templates.descriptionPlaceholder"),className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]}),s.jsxs("div",{className:"mb-3",children:[s.jsx("label",{className:"text-xs text-bambu-gray mb-1 block",children:n("profiles.templates.settingsJson")}),s.jsx("textarea",{value:x,onChange:W=>{b(W.target.value),y(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${v?"border-red-500":"border-bambu-dark-tertiary focus:border-bambu-green"}`}),v&&s.jsx("p",{className:"text-xs text-red-400 mt-1",children:v})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(Te,{size:"sm",onClick:D,disabled:!d.trim(),children:[s.jsx(hs,{className:"w-4 h-4"}),"Save"]}),s.jsx(Te,{size:"sm",variant:"secondary",onClick:A,children:"Cancel"})]})]},H.id):s.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors",children:[s.jsx(z,{className:`w-5 h-5 ${R.color} flex-shrink-0`}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm font-medium text-white",children:H.name}),s.jsx("p",{className:"text-xs text-bambu-gray truncate",children:H.description})]}),s.jsx("span",{className:"text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded",children:n("profiles.templates.fieldsCount",{count:Object.keys(H.settings).length})}),s.jsx("button",{onClick:()=>j(H.id),className:`p-1 transition-colors ${H.showInModal?"text-bambu-green hover:text-bambu-green/70":"text-bambu-gray hover:text-white"}`,title:H.showInModal?n("profiles.templates.shownInModals"):n("profiles.templates.hiddenInModals"),children:H.showInModal?s.jsx(mc,{className:"w-4 h-4"}):s.jsx(cM,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>e(H),className:"px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors",children:n("profiles.templates.apply")}),s.jsx("button",{onClick:()=>E(H),className:"p-1 text-bambu-gray hover:text-white",title:n("common.edit"),children:s.jsx(Zi,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>M(H.id),className:"p-1 text-bambu-gray hover:text-red-400",title:n("common.delete"),children:s.jsx(on,{className:"w-4 h-4"})})]},H.id)})})})]})})]})}function Hre({onClose:t,leftPreset:e,rightPreset:n,leftLabel:r,rightLabel:i,t:a}){const[o,l]=_.useState("changes"),[c,u]=_.useState(""),d=_.useMemo(()=>{const x=new Set([...Object.keys(e),...Object.keys(n)]),b=[];for(const v of x){if(v==="inherits"||v==="version")continue;const y=e[v],S=n[v],M=v in e,T=v in n;let k;!M&&T?k="added":M&&!T?k="removed":JSON.stringify(y)!==JSON.stringify(S)?k="changed":k="same",b.push({key:v,left:y,right:S,status:k})}return b.sort((v,y)=>{const S={changed:0,added:1,removed:2,same:3};return S[v.status]!==S[y.status]?S[v.status]-S[y.status]:v.key.localeCompare(y.key)})},[e,n]),f=_.useMemo(()=>{let x=[...d];if(o==="changes"&&(x=x.filter(b=>b.status!=="same")),c){const b=c.toLowerCase();x=x.filter(v=>v.key.toLowerCase().includes(b)||String(v.left).toLowerCase().includes(b)||String(v.right).toLowerCase().includes(b))}return x},[d,o,c]),p=_.useMemo(()=>({added:d.filter(x=>x.status==="added").length,removed:d.filter(x=>x.status==="removed").length,changed:d.filter(x=>x.status==="changed").length,same:d.filter(x=>x.status==="same").length}),[d]),m=x=>{if(x===void 0)return"—";if(x===null)return"null";if(Array.isArray(x))return x.length===0?"[]":x.length===1?String(x[0]):x.join(", ");if(typeof x=="object")return JSON.stringify(x);const b=String(x);if(b.includes("\\n")||b.length>100){const v=b.split("\\n").length;if(v>1)return`[${v} lines of G-code/script]`;if(b.length>100)return b.substring(0,100)+"…"}return b};return _.useEffect(()=>{const x=b=>{b.key==="Escape"&&t()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[t]),s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:s.jsx(Nt,{className:"w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden",children:s.jsxs(Mt,{className:"p-0 flex flex-col min-h-0 flex-1",children:[s.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(_g,{className:"w-5 h-5 text-blue-400"}),a("profiles.diff.title")]}),s.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white",children:s.jsx(Lt,{className:"w-5 h-5"})})]}),s.jsxs("div",{className:"flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark",children:[s.jsxs("div",{className:"text-center",children:[s.jsx("span",{className:"text-sm text-bambu-gray",children:a("profiles.diff.left")}),s.jsx("p",{className:"text-white font-medium truncate",children:r})]}),s.jsxs("div",{className:"text-center",children:[s.jsx("span",{className:"text-sm text-bambu-gray",children:a("profiles.diff.right")}),s.jsx("p",{className:"text-white font-medium truncate",children:i})]})]}),s.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[s.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[s.jsx(fr,{className:"w-3.5 h-3.5"}),p.added," ",a("profiles.diff.added")]}),s.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[s.jsx(xj,{className:"w-3.5 h-3.5"}),p.removed," ",a("profiles.diff.removed")]}),s.jsxs("span",{className:"flex items-center gap-1 text-amber-400",children:[s.jsx(uj,{className:"w-3.5 h-3.5"}),p.changed," ",a("profiles.diff.changed")]}),s.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray",children:[s.jsx(eT,{className:"w-3.5 h-3.5"}),p.same," ",a("profiles.diff.same")]})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs("div",{className:"relative",children:[s.jsx(ya,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),s.jsx("input",{type:"text",value:c,onChange:x=>u(x.target.value),placeholder:a("profiles.diff.searchFields"),className:"pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48"})]}),p.same>0&&s.jsxs("div",{className:"flex rounded overflow-hidden border border-bambu-dark-tertiary",children:[s.jsx("button",{onClick:()=>l("changes"),className:`px-3 py-1.5 text-sm transition-colors ${o==="changes"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:a("profiles.diff.changes")}),s.jsx("button",{onClick:()=>l("all"),className:`px-3 py-1.5 text-sm transition-colors ${o==="all"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:a("common.all")})]})]})]}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:f.length===0?s.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[s.jsx(eT,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),s.jsx("p",{children:a(o==="changes"?"profiles.diff.noDifferences":"profiles.diff.noFieldsMatch")})]}):s.jsxs("table",{className:"w-full",children:[s.jsx("thead",{className:"sticky top-0 bg-bambu-dark-secondary",children:s.jsxs("tr",{className:"text-sm text-bambu-gray border-b border-bambu-dark-tertiary",children:[s.jsx("th",{className:"text-left p-3 w-1/3",children:a("profiles.diff.field")}),s.jsx("th",{className:"text-left p-3 w-1/3",children:r}),s.jsx("th",{className:"text-left p-3 w-1/3",children:i})]})}),s.jsx("tbody",{children:f.map(x=>{const b={added:"bg-green-500/10",removed:"bg-red-500/10",changed:"bg-amber-500/10",same:""}[x.status],v={added:s.jsx(fr,{className:"w-3.5 h-3.5 text-green-400"}),removed:s.jsx(xj,{className:"w-3.5 h-3.5 text-red-400"}),changed:s.jsx(uj,{className:"w-3.5 h-3.5 text-amber-400"}),same:s.jsx(eT,{className:"w-3.5 h-3.5 text-bambu-gray-dark"})}[x.status];return s.jsxs("tr",{className:`border-b border-bambu-dark-tertiary ${b}`,children:[s.jsx("td",{className:"p-3",children:s.jsxs("div",{className:"flex items-center gap-2",children:[v,s.jsx("span",{className:"text-sm text-white font-mono",children:x.key})]})}),s.jsx("td",{className:"p-3",children:s.jsx("span",{className:`text-sm font-mono break-all ${x.status==="removed"?"text-red-300":x.status==="changed"?"text-white":"text-bambu-gray"}`,children:m(x.left)})}),s.jsx("td",{className:"p-3",children:s.jsx("span",{className:`text-sm font-mono break-all ${x.status==="added"?"text-green-300":x.status==="changed"?"text-white":"text-bambu-gray"}`,children:m(x.right)})})]},x.key)})})]})})]})})})}function BKe({onClose:t,initialData:e,allPresets:n,t:r}){const{showToast:i}=Vn(),a=ln(),o=!!e?.setting_id,[l,c]=_.useState("common"),[u,d]=_.useState(e?.type||"filament"),[f,p]=_.useState(e?.name?o?e.name:`${e.name} (Copy)`:""),[m,x]=_.useState(e?.base_id||""),[b,v]=_.useState(""),[y,S]=_.useState(e?.setting||{inherits:""}),[M,T]=_.useState(JSON.stringify(e?.setting||{inherits:""},null,2)),[k,C]=_.useState(null),[E,D]=_.useState(""),[A,j]=_.useState(!1),[I,F]=_.useState(""),[H,R]=_.useState(!1),[z,W]=_.useState(zre),[V,X]=_.useState(!1),[Q,ae]=_.useState(""),[$,K]=_.useState(""),[ie,re]=_.useState(!0),[xe,pe]=_.useState(null),[ue,Pe]=_.useState(!1),te=_.useMemo(()=>({filament:n.filament,print:n.process,printer:n.printer})[u]||[],[n,u]),Ee=_.useMemo(()=>te.filter(Ae=>Ry(Ae.setting_id)),[te]),{data:Oe}=ot({queryKey:["cloudFields",u],queryFn:()=>ce.getCloudFields(u==="print"?"process":u),staleTime:1e3*60*60}),{data:me}=ot({queryKey:["allPresetDetails",u,Ee.map(Ae=>Ae.setting_id).join(",")],queryFn:async()=>{const Ae={};for(let Me=0;Me{try{const ke=await ce.getCloudSettingDetail(nt.setting_id);return{id:nt.setting_id,detail:ke}}catch{return null}}))).forEach(nt=>{nt&&(Ae[nt.id]=nt.detail)})}return Ae},enabled:Ee.length>0,staleTime:1e3*60*10}),{data:Xe,isLoading:G}=ot({queryKey:["cloudSettingDetail",m],queryFn:()=>ce.getCloudSettingDetail(m),enabled:!!m});_.useEffect(()=>{l!=="json"&&T(JSON.stringify(y,null,2))},[y,l]);const Y=_.useMemo(()=>({filament:n.filament,print:n.process,printer:n.printer}[u]||[]).filter(Ue=>!Ry(Ue.setting_id)).sort((Ue,Me)=>Ue.name.localeCompare(Me.name)),[n,u]);_.useEffect(()=>{if(!m)return;const Ae=Y.find(Ue=>Ue.setting_id===m);Ae&&(v(Ae.name),o||(S({inherits:Ae.name}),T(JSON.stringify({inherits:Ae.name},null,2))))},[m,Y,o]);const de=_.useMemo(()=>{const Ae=Oe?.fields||[],Ue=new Set(Ae.map(nt=>nt.key)),Me=new Set,Ge=new Set(["inherits","updated_time","compatible_printers","compatible_prints"]);me&&Object.values(me).forEach(nt=>{nt?.setting&&Object.keys(nt.setting).forEach(ke=>{!Ue.has(ke)&&!Ge.has(ke)&&Me.add(ke)})}),Object.keys(y).forEach(nt=>{!Ue.has(nt)&&!Ge.has(nt)&&Me.add(nt)});const Ne=Array.from(Me).sort().map(nt=>({key:nt,label:nt.replace(/_/g," ").replace(/\b\w/g,ke=>ke.toUpperCase()),type:"text",category:"discovered",description:r("profiles.presets.discoveredFromPresets")}));return[...Ae,...Ne]},[Oe,me,y,r]),q=de.filter(Ae=>Ae.label.toLowerCase().includes(E.toLowerCase())||Ae.key.toLowerCase().includes(E.toLowerCase())),ee=()=>{if(I.trim()){const Ae=I.trim().toLowerCase().replace(/\s+/g,"_");U(Ae,""),F(""),R(!1),i(r("profiles.presets.toast.fieldAdded",{key:Ae}))}},U=(Ae,Ue)=>{S(Me=>{const Ge={...Me};return Ue===""||Ue===void 0?delete Ge[Ae]:Ge[Ae]=Ue,Ge})},fe=Ae=>{S(Ue=>({...Ue,...Ae.settings})),pe(Ae.name),i(r("profiles.templates.toast.applied"))},we=()=>{if(!Q.trim())return;const Ae={...y};if(delete Ae.inherits,Object.keys(Ae).length===0){i(r("profiles.presets.noOverridesToSave"),"error");return}const Ue={id:Date.now().toString(),name:Q.trim(),description:$.trim()||r("profiles.presets.customTemplate"),type:u,settings:Ae,showInModal:ie},Me=[...z,Ue];W(Me),Bre(Me),X(!1),ae(""),K(""),re(!0),i(r("profiles.templates.toast.created"))},ge=_.useMemo(()=>z.filter(Ae=>Ae.type===u&&Ae.showInModal),[u,z]),B=Ae=>{T(Ae);try{const Ue=JSON.parse(Ae);S(Ue),C(null)}catch(Ue){C(Ue.message)}},O=Ae=>{Ae.preventDefault(),j(!1);const Ue=Ae.dataTransfer.files[0];if(Ue&&Ue.name.endsWith(".json")){const Me=new FileReader;Me.onload=Ge=>{try{const Ne=Ge.target?.result,nt=JSON.parse(Ne),ke=nt.setting||nt;S(Ke=>({...Ke,...ke})),T(JSON.stringify({...y,...ke},null,2)),i(r("profiles.presets.fileImported"))}catch{i(r("profiles.presets.invalidJsonFile"),"error")}},Me.readAsText(Ue)}},J=gt({mutationFn:()=>{const Ae={...y},Ue=u==="filament"?"filament_settings_id":u==="print"?"print_settings_id":"printer_settings_id";Ae[Ue]=`"${f}"`;const Me={type:u,name:f,base_id:m,setting:Ae};return ce.createCloudSetting(Me)},onSuccess:async()=>{i(r("profiles.presets.toast.created")),await a.refetchQueries({queryKey:["cloudSettings"]}),t()},onError:Ae=>i(Ae.message,"error")}),se=gt({mutationFn:()=>{if(!e?.setting_id)throw new Error(r("profiles.presets.noSettingId"));return ce.updateCloudSetting(e.setting_id,{name:f,setting:y})},onSuccess:async()=>{i(r("profiles.presets.toast.updated")),a.removeQueries({queryKey:["cloudSettingDetail"]}),await a.refetchQueries({queryKey:["cloudSettings"]}),t()},onError:Ae=>i(Ae.message,"error")}),ve=o?se:J,_e=Xe?.setting?.inherits,ne=_e?Y.find(Ae=>Ae.name===_e):void 0,{data:Fe}=ot({queryKey:["cloudSettingDetail",ne?.setting_id],queryFn:()=>ce.getCloudSettingDetail(ne.setting_id),enabled:!!ne?.setting_id}),He=_.useMemo(()=>{const Ae=Fe?.setting||{},Ue=Xe?.setting||{},Me=m&&me?.[m]?.setting?me[m].setting:{};return{...Ae,...Ue,...Me}},[m,Xe,Fe,me]),rt=Ae=>{if(Ae==null)return"";if(Array.isArray(Ae)){const Ue=[...new Set(Ae.map(Me=>String(Me)))];return Ue.length===1?Ue[0]:Ae.join(", ")}return String(Ae)},Ie=Ae=>{const Ue=y[Ae.key],Me=He[Ae.key],Ge=rt(Me),Ne=G?r("common.loading"):Ge||"",nt="w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none";if(Ae.type==="boolean"){const ke=Ue==="1"||Ue===void 0&&Me==="1";return s.jsx("button",{type:"button",onClick:()=>U(Ae.key,Ue==="1"?"0":"1"),className:`w-8 h-5 rounded-full transition-colors ${ke?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:s.jsx("div",{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${ke?"translate-x-3.5":"translate-x-0.5"}`})})}return Ae.type==="select"?s.jsxs("select",{value:Ue||"",onChange:ke=>U(Ae.key,ke.target.value),className:nt,children:[s.jsx("option",{value:"",children:Ne}),Ae.options?.map(ke=>s.jsx("option",{value:ke.value,children:ke.label},ke.value))]}):s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:Ae.type==="number"?"number":"text",value:Ue!==void 0?String(Ue):"",onChange:ke=>U(Ae.key,ke.target.value),step:Ae.step,min:Ae.min,max:Ae.max,placeholder:Ne,className:nt}),Ae.unit&&s.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:Ae.unit})]})},be=_.useMemo(()=>Xe?.setting?Xe.setting:{},[Xe]);return s.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onDragOver:Ae=>{Ae.preventDefault(),j(!0)},onDragLeave:()=>j(!1),onDrop:O,children:[ue&&m&&s.jsx(Hre,{onClose:()=>Pe(!1),leftPreset:be,rightPreset:y,leftLabel:r("profiles.presets.baseLabel",{name:b||m}),rightLabel:r("profiles.presets.currentLabel",{name:f||r("profiles.presets.newPreset")}),t:r}),s.jsx(Nt,{className:"w-full max-w-6xl max-h-[90vh] flex flex-col",children:s.jsxs(Mt,{className:"p-0 flex flex-col h-full",children:[s.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("div",{children:[s.jsx("h2",{className:"text-xl font-semibold text-white",children:r(o?"profiles.presets.editPreset":e?"profiles.presets.duplicatePreset":"profiles.presets.createNewPreset")}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:r("profiles.presets.customizeSettings")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[m&&s.jsxs("button",{onClick:()=>Pe(!0),className:"flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",title:r("profiles.presets.compareWithBase"),children:[s.jsx(_g,{className:"w-4 h-4"}),r("profiles.presets.compare")]}),s.jsx("button",{onClick:t,className:"p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:s.jsx(Lt,{className:"w-5 h-5"})})]})]}),A&&s.jsx("div",{className:"absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10",children:s.jsxs("div",{className:"text-center",children:[s.jsx(za,{className:"w-12 h-12 text-bambu-green mx-auto mb-2"}),s.jsx("p",{className:"text-bambu-green font-medium",children:r("profiles.presets.dropJsonToImport")})]})}),s.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("common.type")}),s.jsxs("select",{value:u,onChange:Ae=>{d(Ae.target.value),x("")},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",children:[s.jsx("option",{value:"filament",children:r("profiles.presets.types.filament")}),s.jsx("option",{value:"print",children:r("profiles.presets.types.process")}),s.jsx("option",{value:"printer",children:r("profiles.presets.types.printer")})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("profiles.presets.basePreset")}),s.jsxs("select",{value:m,onChange:Ae=>x(Ae.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",children:[s.jsx("option",{value:"",children:r("profiles.presets.selectBasePreset")}),Y.map(Ae=>s.jsx("option",{value:Ae.setting_id,children:Ae.name},Ae.setting_id))]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("profiles.presets.presetName")}),s.jsx("input",{type:"text",value:f,onChange:Ae=>p(Ae.target.value),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",placeholder:r("profiles.presets.myCustomPreset")})]})]}),b&&s.jsx("div",{className:"text-xs text-bambu-gray",children:s.jsxs("p",{className:"flex items-center gap-1",children:[s.jsx(Na,{className:"w-3 h-3 text-bambu-green"}),r("profiles.presets.inheritsFrom")," ",s.jsx("span",{className:"text-white",children:b}),G&&s.jsx(pt,{className:"w-3 h-3 animate-spin ml-1"})]})})]}),s.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary",children:[s.jsxs("button",{onClick:()=>c("common"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="common"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[s.jsx(Oz,{className:"w-4 h-4"}),r("profiles.presets.tabs.common")]}),s.jsxs("button",{onClick:()=>c("fields"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="fields"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[s.jsx(pM,{className:"w-4 h-4"}),r("profiles.presets.tabs.allFields")]}),s.jsxs("button",{onClick:()=>c("json"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="json"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[s.jsx(yW,{className:"w-4 h-4"}),"JSON",k&&s.jsx($i,{className:"w-3 h-3 text-red-400"})]}),s.jsx("div",{className:"flex-1"}),s.jsxs("button",{onClick:()=>{const Ae={name:f,type:u,base_id:m,setting:y},Ue=new Blob([JSON.stringify(Ae,null,2)],{type:"application/json"}),Me=URL.createObjectURL(Ue),Ge=document.createElement("a");Ge.href=Me,Ge.download=`${f||"preset"}.json`,document.body.appendChild(Ge),Ge.click(),document.body.removeChild(Ge),URL.revokeObjectURL(Me),i(r("profiles.presets.toast.exported"))},className:"flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors",title:r("profiles.presets.exportToJson"),children:[s.jsx(wi,{className:"w-4 h-4"}),r("common.download")]}),s.jsxs("button",{onClick:()=>document.getElementById("file-import")?.click(),className:"flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors",title:r("profiles.presets.importFromJson"),children:[s.jsx(za,{className:"w-4 h-4"}),r("common.upload")]}),s.jsx("input",{id:"file-import",type:"file",accept:".json",className:"hidden",onChange:Ae=>{const Ue=Ae.target.files?.[0];if(Ue){const Me=new FileReader;Me.onload=Ge=>{try{const Ne=JSON.parse(Ge.target?.result),nt=Ne.setting||Ne;S(ke=>({...ke,...nt})),i(r("profiles.presets.fileImported"))}catch{i(r("profiles.presets.invalidJson"),"error")}},Me.readAsText(Ue)}}})]}),s.jsxs("div",{className:"flex-1 overflow-y-auto p-4",children:[l==="common"&&s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[s.jsx(W0,{className:"w-4 h-4 text-amber-400"}),r("profiles.templates.title")]}),Object.keys(y).filter(Ae=>Ae!=="inherits").length>0&&s.jsxs("button",{onClick:()=>X(!V),className:"text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors",children:[s.jsx(hs,{className:"w-3 h-3"}),r("profiles.presets.saveAsTemplate")]})]}),V&&s.jsxs("div",{className:"mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-2",children:[s.jsx("input",{type:"text",value:Q,onChange:Ae=>ae(Ae.target.value),placeholder:r("profiles.templates.namePlaceholder"),className:"px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",autoFocus:!0}),s.jsx("input",{type:"text",value:$,onChange:Ae=>K(Ae.target.value),placeholder:r("profiles.templates.descriptionPlaceholder"),className:"px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(Te,{size:"sm",onClick:we,disabled:!Q.trim(),children:[s.jsx(hs,{className:"w-3 h-3"}),r("common.save")]}),s.jsx(Te,{size:"sm",variant:"secondary",onClick:()=>X(!1),children:r("common.cancel")})]}),s.jsxs("button",{onClick:()=>re(!ie),className:`flex items-center gap-1.5 text-xs transition-colors ${ie?"text-bambu-green":"text-bambu-gray hover:text-white"}`,children:[ie?s.jsx(mc,{className:"w-3.5 h-3.5"}):s.jsx(cM,{className:"w-3.5 h-3.5"}),r(ie?"profiles.templates.shownInModals":"profiles.templates.hiddenInModals")]})]})]}),xe&&s.jsxs("div",{className:"mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2",children:[s.jsx(Na,{className:"w-4 h-4 text-bambu-green"}),s.jsxs("span",{className:"text-sm text-bambu-green",children:[r("profiles.presets.templateApplied")," ",s.jsx("span",{className:"font-medium",children:xe})]}),s.jsx("button",{onClick:()=>pe(null),className:"ml-auto text-bambu-green/70 hover:text-bambu-green",children:s.jsx(Lt,{className:"w-4 h-4"})})]}),s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[ge.map(Ae=>s.jsxs("button",{onClick:()=>fe(Ae),className:"p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors",children:[s.jsx("p",{className:"text-sm font-medium text-white",children:Ae.name}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:Ae.description})]},Ae.id)),ge.length===0&&s.jsx("p",{className:"col-span-3 text-center text-bambu-gray text-sm py-4",children:r("profiles.presets.noTemplatesSelected")})]}),s.jsx("p",{className:"text-xs text-bambu-gray-dark mt-2 text-center",children:r("profiles.presets.manageTemplatesHint")})]}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:r("profiles.presets.commonSettings")}),s.jsx("div",{className:"grid grid-cols-2 gap-x-6 gap-y-3",children:de.slice(0,10).map(Ae=>s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("label",{className:"text-sm text-bambu-gray flex-shrink-0",children:Ae.label}),s.jsx("div",{className:"w-48",children:Ie(Ae)})]},Ae.key))})]}),Object.keys(y).length>1&&s.jsxs("div",{children:[s.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:r("profiles.presets.currentOverrides")}),s.jsx("div",{className:"flex flex-wrap gap-2",children:Object.entries(y).filter(([Ae])=>Ae!=="inherits").map(([Ae,Ue])=>s.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded",children:[Ae,": ",String(Ue).slice(0,20),s.jsx("button",{onClick:()=>U(Ae,void 0),className:"hover:text-white",children:s.jsx(Lt,{className:"w-3 h-3"})})]},Ae))})]})]}),l==="fields"&&s.jsxs("div",{className:"grid grid-cols-2 gap-6",style:{height:"400px"},children:[s.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[s.jsx("h3",{className:"text-sm font-medium text-white",children:r("profiles.presets.availableFields")}),s.jsx("span",{className:"text-xs text-bambu-gray",children:me?r("profiles.templates.fieldsCount",{count:de.length}):r("common.loading")})]}),s.jsxs("div",{className:"relative mb-3 flex-shrink-0",children:[s.jsx(ya,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),s.jsx("input",{type:"text",value:E,onChange:Ae=>D(Ae.target.value),placeholder:r("profiles.presets.searchFieldsPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none"})]}),s.jsxs("div",{className:"flex-1 overflow-y-auto space-y-1 pr-2 min-h-0",children:[q.filter(Ae=>!(Ae.key in y)).map(Ae=>{const Ue=He[Ae.key],Me=rt(Ue);return s.jsxs("div",{onClick:()=>{S(Ge=>({...Ge,[Ae.key]:Me||""}))},className:"flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"text-sm text-white truncate",children:Ae.label}),s.jsx("p",{className:"text-xs text-bambu-gray-dark truncate",children:Ae.key})]}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[Me&&s.jsxs("span",{className:"text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate",title:Me,children:[Me.slice(0,20),Me.length>20?"...":""]}),s.jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors",children:s.jsx(fr,{className:"w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors"})})]})]},Ae.key)}),q.filter(Ae=>!(Ae.key in y)).length===0&&s.jsx("p",{className:"text-center text-bambu-gray py-4 text-sm",children:r(E?"profiles.presets.noMatchingFields":"profiles.presets.allFieldsAdded")})]}),s.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0",children:H?s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{type:"text",value:I,onChange:Ae=>F(Ae.target.value),onKeyDown:Ae=>Ae.key==="Enter"&&ee(),placeholder:"custom_field_name",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",autoFocus:!0}),s.jsx(Te,{size:"sm",onClick:ee,disabled:!I.trim(),children:s.jsx(fr,{className:"w-4 h-4"})}),s.jsx(Te,{size:"sm",variant:"secondary",onClick:()=>{R(!1),F("")},children:s.jsx(Lt,{className:"w-4 h-4"})})]}):s.jsxs("button",{onClick:()=>R(!0),className:"w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors",children:[s.jsx(fr,{className:"w-4 h-4"}),r("profiles.presets.addCustomField")]})})]}),s.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[s.jsx("h3",{className:"text-sm font-medium text-white",children:r("profiles.presets.yourOverrides")}),s.jsx("span",{className:"text-xs text-bambu-gray",children:r("profiles.templates.fieldsCount",{count:Object.keys(y).filter(Ae=>Ae!=="inherits").length})})]}),s.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2 pr-2 min-h-0",children:[Object.entries(y).filter(([Ae])=>Ae!=="inherits").map(([Ae,Ue])=>{const Me=de.find(Ge=>Ge.key===Ae);return s.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm font-medium text-white",children:Me?.label||Ae}),s.jsx("p",{className:"text-xs text-bambu-gray-dark",children:Ae})]}),s.jsx("button",{onClick:()=>U(Ae,void 0),className:"p-1 text-bambu-gray hover:text-red-400 transition-colors",children:s.jsx(Lt,{className:"w-4 h-4"})})]}),Me?Ie(Me):s.jsx("input",{type:"text",value:String(Ue),onChange:Ge=>U(Ae,Ge.target.value),className:"w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]},Ae)}),Object.keys(y).filter(Ae=>Ae!=="inherits").length===0&&s.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[s.jsx(Oz,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),s.jsx("p",{className:"text-sm",children:r("profiles.presets.noOverridesYet")}),s.jsx("p",{className:"text-xs mt-1",children:r("profiles.presets.clickFieldsToAdd")})]})]}),Object.keys(y).filter(Ae=>Ae!=="inherits").length>0&&s.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0",children:s.jsxs("button",{onClick:()=>{X(!0),c("common")},className:"w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors",children:[s.jsx(hs,{className:"w-4 h-4"}),r("profiles.presets.saveAsTemplate")]})})]})]}),l==="json"&&s.jsxs("div",{className:"space-y-2",children:[k&&s.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm",children:[s.jsx($i,{className:"w-4 h-4"}),k]}),s.jsx("textarea",{value:M,onChange:Ae=>B(Ae.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${k?"border-red-500 focus:border-red-500":"border-bambu-dark-tertiary focus:border-bambu-green"}`,spellCheck:!1}),s.jsx("p",{className:"text-xs text-bambu-gray",children:r("profiles.presets.jsonTip")})]})]}),s.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex gap-2",children:[s.jsx(Te,{variant:"secondary",onClick:t,className:"flex-1",children:r("common.cancel")}),s.jsxs(Te,{onClick:()=>ve.mutate(),disabled:ve.isPending||!f.trim()||!o&&!m||!!k,className:"flex-1",children:[ve.isPending?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):o?s.jsx(hs,{className:"w-4 h-4"}):s.jsx(fr,{className:"w-4 h-4"}),r(o?"common.save":e?"common.duplicate":"common.create")]})]})]})})]})}function HKe({settings:t,lastSyncTime:e,onRefresh:n,isRefreshing:r,printers:i,hasPermission:a,t:o}){const[l,c]=_.useState(""),[u,d]=_.useState("all"),[f,p]=_.useState("all"),[m,x]=_.useState("all"),[b,v]=_.useState("all"),[y,S]=_.useState("all"),[M,T]=_.useState("all"),[k,C]=_.useState(null),[E,D]=_.useState(!1),[A,j]=_.useState(!1),[I,F]=_.useState(null),[H,R]=_.useState(null),[z,W]=_.useState(null),[V,X]=_.useState(!1),[Q,ae]=_.useState([null,null]),[$,K]=_.useState(!1),[ie,re]=_.useState(null),xe=ln(),pe=_.useMemo(()=>[...t.filament.map(ee=>({...ee,type:"filament"})),...t.printer.map(ee=>({...ee,type:"printer"})),...t.process.map(ee=>({...ee,type:"process"}))].map(ee=>({...ee,meta:cF(ee.name)})),[t]),ue=_.useMemo(()=>{const q=new Set,ee=new Set,U=new Set;return pe.forEach(fe=>{fe.meta.nozzle&&q.add(fe.meta.nozzle),fe.meta.filamentType&&ee.add(fe.meta.filamentType),fe.meta.layerHeight&&U.add(fe.meta.layerHeight)}),{printers:i.map(fe=>({id:fe.id.toString(),name:fe.name})),nozzles:Array.from(q).sort((fe,we)=>parseFloat(fe)-parseFloat(we)),filaments:Array.from(ee).sort(),layerHeights:Array.from(U).sort((fe,we)=>parseFloat(fe)-parseFloat(we))}},[pe,i]),Pe=_.useMemo(()=>m==="all"?null:i.find(ee=>ee.id.toString()===m)?.model||null,[m,i]),te=_.useMemo(()=>pe.filter(q=>u==="all"||q.type===u).filter(q=>{if(f==="all")return!0;const ee=Ry(q.setting_id);return f==="custom"?ee:!ee}).filter(q=>{if(m==="all"||!Pe)return!0;const ee=q.meta.printer?.toLowerCase()||"",U=Pe.toLowerCase();return ee.includes(U)||U.includes(ee)}).filter(q=>b==="all"||q.meta.nozzle===b).filter(q=>y==="all"||q.meta.filamentType===y).filter(q=>M==="all"||q.meta.layerHeight===M).filter(q=>l===""||q.name.toLowerCase().includes(l.toLowerCase())).sort((q,ee)=>q.name.localeCompare(ee.name)),[pe,u,f,m,Pe,b,y,M,l]),Ee=q=>{if(V){const ee=Q[0]?.setting_id===q.setting_id,U=Q[1]?.setting_id===q.setting_id;if(ee)ae([Q[1],null]);else if(U)ae([Q[0],null]);else if(!Q[0])ae([q,null]);else if(Q[1]){if(Q[0].type!==q.type)return;ae([Q[0],q])}else{if(Q[0].type!==q.type)return;ae([Q[0],q])}}else C(q)},Oe=q=>{if(Q[0]?.setting_id===q.setting_id)return 0;if(Q[1]?.setting_id===q.setting_id)return 1},me=async q=>{try{const ee=await ce.getCloudSettingDetail(q.setting_id),U=q.type==="process"?"print":q.type;F({type:U,name:q.name,base_id:ee.base_id||"GFSA00",setting:ee.setting||{}}),C(null)}catch(ee){console.error("Failed to fetch preset details for duplication:",ee)}},Xe=async q=>{try{xe.removeQueries({queryKey:["cloudSettingDetail",q.setting_id]});const ee=await ce.getCloudSettingDetail(q.setting_id),U=q.type==="process"?"print":q.type;R({type:U,name:q.name,base_id:ee.base_id||"GFSA00",setting:ee.setting||{},setting_id:q.setting_id}),C(null)}catch(ee){console.error("Failed to fetch preset details for editing:",ee)}},G=()=>{d("all"),p("all"),x("all"),v("all"),S("all"),T("all"),c("")},Y=u!=="all"||f!=="all"||m!=="all"||b!=="all"||y!=="all"||M!=="all"||l!=="",de=t.filament.length+t.printer.length+t.process.length;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"space-y-4 mb-6",children:[s.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[s.jsxs("div",{className:"relative flex-1",children:[s.jsx(ya,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),s.jsx("input",{type:"text",value:l,onChange:q=>c(q.target.value),placeholder:o("profiles.cloudView.searchPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none"})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(Te,{variant:V?"primary":"secondary",onClick:()=>{V?(X(!1),ae([null,null])):X(!0)},children:[s.jsx(_g,{className:"w-4 h-4"}),o(V?"common.cancel":"profiles.presets.compare")]}),s.jsxs(Te,{variant:"secondary",onClick:()=>j(!0),disabled:!a("cloud:auth"),title:a("cloud:auth")?void 0:o("profiles.cloudView.noTemplatesPermission"),children:[s.jsx(W0,{className:"w-4 h-4"}),o("profiles.cloudView.templates")]}),s.jsxs(Te,{variant:"secondary",onClick:n,disabled:r||!a("cloud:auth"),title:a("cloud:auth")?void 0:o("profiles.cloudView.noRefreshPermission"),children:[s.jsx(Rr,{className:`w-4 h-4 ${r?"animate-spin":""}`}),o("profiles.cloudView.refresh")]}),s.jsxs(Te,{onClick:()=>D(!0),disabled:!a("cloud:auth"),title:a("cloud:auth")?void 0:o("profiles.cloudView.noCreatePermission"),children:[s.jsx(fr,{className:"w-4 h-4"}),o("profiles.cloudView.newPreset")]})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(dM,{className:"w-4 h-4 text-bambu-gray"}),s.jsx(rg,{label:o("profiles.cloudView.filters.type"),value:u,options:[{value:"all",label:o("profiles.cloudView.filters.all"),count:de},{value:"filament",label:o("profiles.cloudView.filters.filament"),count:t.filament.length},{value:"printer",label:o("profiles.cloudView.filters.printer"),count:t.printer.length},{value:"process",label:o("profiles.cloudView.filters.process"),count:t.process.length}],onChange:q=>d(q)}),s.jsx(rg,{label:o("profiles.cloudView.filters.owner"),value:f,options:[{value:"all",label:o("profiles.cloudView.filters.all")},{value:"custom",label:o("profiles.cloudView.filters.myPresets")},{value:"builtin",label:o("profiles.cloudView.filters.builtIn")}],onChange:q=>p(q)}),ue.printers.length>0&&s.jsx(rg,{label:o("profiles.cloudView.filters.printer"),value:m,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...ue.printers.map(q=>({value:q.id,label:q.name}))],onChange:x}),ue.nozzles.length>0&&s.jsx(rg,{label:o("profiles.cloudView.filters.nozzle"),value:b,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...ue.nozzles.map(q=>({value:q,label:q}))],onChange:v}),ue.filaments.length>0&&(u==="all"||u==="filament")&&s.jsx(rg,{label:o("profiles.cloudView.filters.filament"),value:y,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...ue.filaments.map(q=>({value:q,label:q}))],onChange:S}),ue.layerHeights.length>0&&(u==="all"||u==="process")&&s.jsx(rg,{label:o("profiles.cloudView.filters.layer"),value:M,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...ue.layerHeights.map(q=>({value:q,label:q}))],onChange:T}),Y&&s.jsx("button",{onClick:G,className:"px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:o("profiles.cloudView.clearFilters")})]})]}),V&&s.jsx("div",{className:"mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsx(_g,{className:"w-5 h-5 text-blue-400"}),s.jsx("span",{className:"text-white font-medium",children:o("profiles.cloudView.compareMode")}),s.jsx("span",{className:"text-bambu-gray",children:Q[0]?o("profiles.cloudView.selectAnotherPreset",{type:Q[0].type}):o("profiles.cloudView.clickTwoPresets")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${Q[0]?"bg-blue-500/30 text-blue-700 dark:text-blue-300":"bg-bambu-dark text-bambu-gray"}`,children:Q[0]?Q[0].name:o("profiles.cloudView.selectFirst")}),s.jsx(uj,{className:"w-4 h-4 text-bambu-gray"}),s.jsx("span",{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${Q[1]?"bg-blue-500/30 text-blue-700 dark:text-blue-300":"bg-bambu-dark text-bambu-gray"}`,children:Q[1]?Q[1].name:o("profiles.cloudView.selectSecond")})]}),Q[0]&&Q[1]&&s.jsxs(Te,{size:"sm",onClick:async()=>{try{const[q,ee]=await Promise.all([ce.getCloudSettingDetail(Q[0].setting_id),ce.getCloudSettingDetail(Q[1].setting_id)]);re([q.setting||{},ee.setting||{}]),K(!0)}catch{}},children:[s.jsx(_g,{className:"w-4 h-4"}),o("profiles.cloudView.compareNow")]})]})]})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray",children:[e&&s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(nr,{className:"w-3 h-3"}),o("profiles.cloudView.lastSynced")," ",LKe(e.toISOString(),o)]}),s.jsx("span",{children:o("profiles.cloudView.showingCount",{showing:te.length,total:de})}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-bambu-green"}),s.jsxs("span",{children:["= ",o("profiles.presets.myPreset")]})]})]}),te.length===0?s.jsxs("div",{className:"text-center py-16",children:[s.jsx(sl,{className:"w-12 h-12 text-bambu-gray-dark mx-auto mb-4"}),s.jsx("p",{className:"text-bambu-gray",children:o("profiles.cloudView.noPresetsFound")}),Y&&s.jsx("button",{onClick:G,className:"mt-2 text-sm text-bambu-green hover:text-bambu-green-light",children:o("profiles.cloudView.clearFilters")})]}):s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[s.jsx(TR,{className:"w-4 h-4 text-amber-400"}),s.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.filament")}),s.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",te.filter(q=>q.type==="filament").length,")"]})]}),s.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[te.filter(q=>q.type==="filament").map(q=>s.jsx(GP,{setting:q,onClick:()=>Ee(q),onDuplicate:()=>me(q),compareMode:V,isCompareSelected:Oe(q)!==void 0,compareIndex:Oe(q),compareDisabled:V&&!!Q[0]&&Q[0].type!==q.type,t:o},q.setting_id)),te.filter(q=>q.type==="filament").length===0&&s.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noFilamentPresets")})]})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[s.jsx(vh,{className:"w-4 h-4 text-blue-400"}),s.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.process")}),s.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",te.filter(q=>q.type==="process").length,")"]})]}),s.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[te.filter(q=>q.type==="process").map(q=>s.jsx(GP,{setting:q,onClick:()=>Ee(q),onDuplicate:()=>me(q),compareMode:V,isCompareSelected:Oe(q)!==void 0,compareIndex:Oe(q),compareDisabled:V&&!!Q[0]&&Q[0].type!==q.type,t:o},q.setting_id)),te.filter(q=>q.type==="process").length===0&&s.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noProcessPresets")})]})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[s.jsx(Pr,{className:"w-4 h-4 text-purple-400"}),s.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.printer")}),s.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",te.filter(q=>q.type==="printer").length,")"]})]}),s.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[te.filter(q=>q.type==="printer").map(q=>s.jsx(GP,{setting:q,onClick:()=>Ee(q),onDuplicate:()=>me(q),compareMode:V,isCompareSelected:Oe(q)!==void 0,compareIndex:Oe(q),compareDisabled:V&&!!Q[0]&&Q[0].type!==q.type,t:o},q.setting_id)),te.filter(q=>q.type==="printer").length===0&&s.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noPrinterPresets")})]})]})]}),k&&s.jsx(UKe,{setting:k,onClose:()=>C(null),onDeleted:()=>C(null),onDuplicate:()=>me(k),onEdit:()=>Xe(k),hasPermission:a,t:o}),(E||I||H||z)&&s.jsx(BKe,{onClose:()=>{D(!1),F(null),R(null),W(null)},initialData:H||I||(z?{type:z.type,name:"",base_id:"",setting:z.setting}:void 0),allPresets:t,t:o}),A&&s.jsx(zKe,{onClose:()=>j(!1),onApply:q=>{W({type:q.type,setting:q.settings}),j(!1)},t:o}),$&&ie&&Q[0]&&Q[1]&&s.jsx(Hre,{onClose:()=>{K(!1),re(null)},leftPreset:ie[0],rightPreset:ie[1],leftLabel:Q[0].name,rightLabel:Q[1].name,t:o})]})}function $Ke(){const{t}=On(),e=ln(),{showToast:n}=Vn(),{hasPermission:r}=Ci(),[i,a]=_.useState("cloud"),[o,l]=_.useState(),{data:c,isLoading:u}=ot({queryKey:["cloudStatus"],queryFn:ce.getCloudStatus}),{data:d=[]}=ot({queryKey:["printers"],queryFn:ce.getPrinters}),{data:f,isLoading:p,refetch:m,dataUpdatedAt:x}=ot({queryKey:["cloudSettings"],queryFn:()=>ce.getCloudSettings(),enabled:!!c?.is_authenticated,retry:!1,staleTime:1e3*60*5});_.useEffect(()=>{x&&l(new Date(x))},[x]);const b=gt({mutationFn:ce.cloudLogout,onSuccess:()=>{e.invalidateQueries({queryKey:["cloudStatus"]}),e.removeQueries({queryKey:["cloudSettings"]}),n(t("profiles.toast.loggedOut"))}}),v=()=>{e.invalidateQueries({queryKey:["cloudStatus"]})};return u?s.jsx("div",{className:"p-4 md:p-8 flex items-center justify-center min-h-[400px]",children:s.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):s.jsxs("div",{className:"p-6 lg:p-8",children:[s.jsxs("div",{className:"mb-6",children:[s.jsx("h1",{className:"text-2xl font-bold text-white",children:t("profiles.title")}),s.jsx("p",{className:"text-bambu-gray",children:t("profiles.subtitle")})]}),s.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary mb-6",children:[s.jsxs("button",{onClick:()=>a("cloud"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i==="cloud"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[s.jsx(lM,{className:"w-4 h-4"}),t("profiles.tabs.cloud")]}),s.jsxs("button",{onClick:()=>a("kprofiles"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i==="kprofiles"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[s.jsx(hM,{className:"w-4 h-4"}),t("profiles.tabs.kprofiles")]})]}),i==="cloud"&&s.jsxs(s.Fragment,{children:[c?.is_authenticated&&s.jsxs("div",{className:"flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-2 h-2 rounded-full bg-bambu-green animate-pulse"}),s.jsxs("span",{className:"text-sm text-bambu-gray",children:[t("profiles.connectedAs")," ",s.jsx("span",{className:"text-white",children:c.email})]})]}),s.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>b.mutate(),disabled:b.isPending||!r("cloud:auth"),title:r("cloud:auth")?void 0:t("profiles.noLogoutPermission"),children:[s.jsx(gj,{className:"w-4 h-4"}),t("profiles.logout")]})]}),c?.is_authenticated?p?s.jsx("div",{className:"flex items-center justify-center py-16",children:s.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):f?s.jsx(HKe,{settings:f,lastSyncTime:o,onRefresh:()=>m(),isRefreshing:p,printers:d,hasPermission:r,t}):s.jsxs("div",{className:"text-center py-16",children:[s.jsx("p",{className:"text-bambu-gray mb-4",children:t("profiles.failedToLoad")}),s.jsx(Te,{onClick:()=>m(),children:t("profiles.retry")})]}):s.jsx(FKe,{onSuccess:v,t})]}),i==="kprofiles"&&s.jsx(OKe,{}),s.jsx(IKe,{})]})}const g0={Droplet:TR,Flame:Iue,Ruler:xhe,Sparkles:W0,Square:ll,Cable:Pce,Wrench:om,Calendar:ti,Timer:bu,Cog:due,Fan:vW,Zap:_h,Wind:RW,Thermometer:bM,Layers:sl,Box:oo,Target:PW,RefreshCw:Rr,Settings:xM,Filter:dM,CircleDot:Yce};function z0(t){return t&&g0[t]||om}function ig(t,e,n){if(e==="days"){if(t<1)return n?n("common.today"):"Today";if(t===1)return n?n("maintenance.day"):"1 day";if(t<7){const i=Math.round(t);return n?n("maintenance.days",{count:i}):`${i} days`}if(t<180){const i=Math.round(t/7);return i===1?n?n("maintenance.week"):"1 week":n?n("maintenance.weeks",{count:i}):`${i} weeks`}const r=Math.round(t/30);return r===1?n?n("maintenance.month"):"1 month":n?n("maintenance.months",{count:r}):`${r} months`}else{if(t<1)return`${Math.round(t*60)}m`;if(t<24)return`${t<10?t.toFixed(1):Math.round(t)}h`;const r=t/24;if(r<7)return`${r<2?r.toFixed(1):Math.round(r)}d`;const i=r/7;return i<12?`${i<2?i.toFixed(1):Math.round(i)}w`:`${Math.round(i/4)}mo`}}function qP(t,e,n){return e==="days"?t===1?n?n("maintenance.day"):"1 day":t===7?n?n("maintenance.week"):"1 week":t===14?n?n("maintenance.weeks",{count:2}):"2 weeks":t===30?n?n("maintenance.month"):"1 month":t===60?n?n("maintenance.months",{count:2}):"2 months":t===90?n?n("maintenance.months",{count:3}):"3 months":t===180?n?n("maintenance.months",{count:6}):"6 months":t===365?n?n("maintenance.year"):"1 year":n?n("maintenance.days",{count:t}):`${t} days`:`${t}h`}function VKe(t,e){const n=(e||"").toUpperCase().replace(/[- ]/g,""),r=n.includes("X1"),i=n.includes("P1"),a=n.includes("A1MINI"),o=n.includes("A1")&&!a,l=n.includes("H2D"),c=n.includes("H2C"),u=n.includes("H2S"),d=l||c||u,f=n.includes("P2S");switch(t){case"Lubricate Linear Rails":return r?"https://wiki.bambulab.com/en/x1/maintenance/basic-maintenance":i?"https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance":a?"https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis":o?"https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis":d?"https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication":f?"https://wiki.bambulab.com/en/p2s/maintenance/belt-tension":"https://wiki.bambulab.com/en/general/lead-screws-lubrication";case"Clean Nozzle/Hotend":return r||i?"https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog":a||o?"https://wiki.bambulab.com/en/a1-mini/troubleshooting/nozzle-clog":d?"https://wiki.bambulab.com/en/h2/maintenance/nozzl-cold-pull-maintenance-and-cleaning":f?"https://wiki.bambulab.com/en/p2s/maintenance/cold-pull-maintenance-hotend":"https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog";case"Check Belt Tension":return r?"https://wiki.bambulab.com/en/x1/maintenance/belt-tension":i?"https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance":a?"https://wiki.bambulab.com/en/a1-mini/maintenance/belt_tension":o?"https://wiki.bambulab.com/en/a1/maintenance/belt_tension":l?"https://wiki.bambulab.com/en/h2/maintenance/belt-tension":c?"https://wiki.bambulab.com/en/h2c/maintenance/belt-tension":u?"https://wiki.bambulab.com/en/h2s/maintenance/belt-tension":f?"https://wiki.bambulab.com/en/p2s/maintenance/belt-tension":"https://wiki.bambulab.com/en/x1/maintenance/belt-tension";case"Clean Carbon Rods":return r||i?"https://wiki.bambulab.com/en/general/carbon-rods-clearance":a||o||d||f?null:"https://wiki.bambulab.com/en/general/carbon-rods-clearance";case"Clean Build Plate":return"https://wiki.bambulab.com/en/filament-acc/acc/pei-plate-clean-guide";case"Check PTFE Tube":return r||i?"https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube":a||o?"https://wiki.bambulab.com/en/a1-mini/maintenance/ptfe-tube":l?"https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer":u?"https://wiki.bambulab.com/en/h2s/maintenance/replace-ptfe-tube-on-h2s-printer":c?"https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer":"https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube";case"Replace HEPA Filter":case"HEPA Filter":case"Replace Carbon Filter":case"Carbon Filter":return d?"https://wiki.bambulab.com/en/h2/maintenance/replace-smoke-purifier-air-filte":"https://wiki.bambulab.com/en/x1/maintenance/replace-carbon-filter";case"Lubricate Left Nozzle Rail":case"Left Nozzle Rail":return d?"https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication":null;default:return null}}function GKe({item:t,onPerform:e,onToggle:n,hasPermission:r,t:i}){const a=z0(t.maintenance_type_icon),o=t.interval_type||"hours",c=(()=>{if(o==="days"){const m=t.days_since_maintenance??0;return Math.max(0,Math.min(100,m/t.interval_hours*100))}return Math.max(0,Math.min(100,(t.interval_hours-t.hours_until_due)/t.interval_hours*100))})(),u=()=>t.enabled?t.is_due?"text-red-400":t.is_warning?"text-amber-400":"text-bambu-green":"text-bambu-gray",d=()=>t.enabled?t.is_due?"bg-red-500":t.is_warning?"bg-amber-500":"bg-bambu-green":"bg-bambu-gray/30",f=()=>t.enabled?t.is_due?"bg-red-500/5 border-red-500/20":t.is_warning?"bg-amber-500/5 border-amber-500/20":"bg-bambu-dark-secondary border-bambu-dark-tertiary":"bg-bambu-dark-secondary/50",p=()=>{if(!t.enabled)return i("common.disabled");if(o==="days"){const m=t.days_until_due??0;return t.is_due?i("maintenance.overdueBy",{duration:ig(Math.abs(m),"days",i)}):t.is_warning?i("maintenance.dueIn",{duration:ig(m,"days",i)}):i("maintenance.timeLeft",{duration:ig(m,"days",i)})}else return t.is_due?i("maintenance.overdueBy",{duration:ig(Math.abs(t.hours_until_due),"hours",i)}):t.is_warning?i("maintenance.dueIn",{duration:ig(t.hours_until_due,"hours",i)}):i("maintenance.timeLeft",{duration:ig(t.hours_until_due,"hours",i)})};return s.jsx("div",{className:`rounded-xl border p-4 transition-all ${f()}`,children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsxs("div",{className:`relative p-2.5 rounded-lg ${t.is_due?"bg-red-500/20":t.is_warning?"bg-amber-500/20":t.enabled?"bg-bambu-dark":"bg-bambu-dark/50"}`,children:[s.jsx(a,{className:`w-5 h-5 ${u()}`}),t.enabled&&(t.is_due||t.is_warning)&&s.jsx("span",{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${t.is_due?"bg-red-500":"bg-amber-500"} animate-pulse`})]}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:`font-medium truncate ${t.enabled?"text-white":"text-bambu-gray"}`,children:t.maintenance_type_name}),o==="days"&&s.jsx("span",{title:i("maintenance.timeBasedInterval"),children:s.jsx(ti,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"})}),(()=>{const m=t.maintenance_type_wiki_url||VKe(t.maintenance_type_name,t.printer_model);return m?s.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-bambu-green transition-colors shrink-0",title:i("maintenance.viewDocumentation"),onClick:x=>x.stopPropagation(),children:s.jsx(Xr,{className:"w-3.5 h-3.5"})}):null})()]}),s.jsx("div",{className:"mt-2 mb-1.5",children:s.jsx("div",{className:"w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden",children:s.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${d()}`,style:{width:`${c}%`}})})}),s.jsxs("div",{className:`text-xs flex items-center gap-1 ${u()}`,children:[t.is_due&&s.jsx(Sn,{className:"w-3 h-3"}),t.is_warning&&!t.is_due&&s.jsx(nr,{className:"w-3 h-3"}),!t.is_due&&!t.is_warning&&t.enabled&&s.jsx(Na,{className:"w-3 h-3"}),p()]})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsx("span",{title:r("maintenance:update")?void 0:i("maintenance.noPermissionUpdate"),children:s.jsx(In,{checked:t.enabled,onChange:m=>n(t.id,m),disabled:!r("maintenance:update")})}),s.jsxs(Te,{size:"sm",variant:t.is_due?"primary":"secondary",onClick:()=>e(t.id),disabled:!t.enabled||!r("maintenance:update"),title:r("maintenance:update")?void 0:i("maintenance.noPermissionPerform"),className:"!px-3",children:[s.jsx(Oh,{className:"w-3.5 h-3.5"}),i("common.reset")]})]})]})})}function qKe({overview:t,onPerform:e,onToggle:n,onSetHours:r,hasPermission:i,t:a}){const[o,l]=_.useState(!0),[c,u]=_.useState(!1),[d,f]=_.useState(t.total_print_hours.toFixed(1)),p=[...t.maintenance_items].sort((b,v)=>b.is_due&&!v.is_due?-1:!b.is_due&&v.is_due?1:b.is_warning&&!v.is_warning?-1:!b.is_warning&&v.is_warning?1:b.maintenance_type_id-v.maintenance_type_id),m=p.find(b=>b.enabled&&(b.is_due||b.is_warning)),x=()=>{const b=parseFloat(d);!isNaN(b)&&b>=0&&(r(t.printer_id,b),u(!1))};return s.jsxs(Nt,{className:"overflow-hidden",children:[s.jsxs("div",{className:"p-5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsx("h2",{className:"text-xl font-semibold text-white",children:t.printer_name}),s.jsxs("div",{className:"flex items-center gap-2",children:[t.due_count>0&&s.jsxs("span",{className:"px-2.5 py-1 bg-red-500/20 text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5",children:[s.jsx(Sn,{className:"w-3 h-3"}),a("maintenance.overdueCount",{count:t.due_count})]}),t.warning_count>0&&s.jsxs("span",{className:"px-2.5 py-1 bg-amber-500/20 text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5",children:[s.jsx(nr,{className:"w-3 h-3"}),a("maintenance.dueSoonCount",{count:t.warning_count})]}),t.due_count===0&&t.warning_count===0&&s.jsxs("span",{className:"px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5",children:[s.jsx(Na,{className:"w-3 h-3"}),a("maintenance.allGood")]})]})]}),s.jsxs("button",{onClick:()=>l(!o),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors",children:[o?s.jsx(yh,{className:"w-4 h-4"}):s.jsx(Kr,{className:"w-4 h-4"}),a(o?"common.collapse":"common.expand")]})]}),s.jsxs("div",{className:"flex items-center gap-6 mt-4",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"p-2 bg-bambu-dark/50 rounded-lg",children:s.jsx(bu,{className:"w-4 h-4 text-bambu-gray"})}),c?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",value:d,onChange:b=>f(b.target.value),onKeyDown:b=>{b.key==="Enter"&&x(),b.key==="Escape"&&u(!1)},className:"w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm",min:"0",step:"1",autoFocus:!0}),s.jsx("span",{className:"text-xs text-bambu-gray",children:a("common.hours")}),s.jsx(Te,{size:"sm",onClick:x,children:a("common.save")}),s.jsx(Te,{size:"sm",variant:"secondary",onClick:()=>u(!1),children:a("common.cancel")})]}):s.jsxs("button",{onClick:()=>{i("maintenance:update")&&(f(Math.round(t.total_print_hours).toString()),u(!0))},className:`group ${i("maintenance:update")?"":"cursor-not-allowed opacity-60"}`,title:i("maintenance:update")?void 0:a("maintenance.noPermissionEditHours"),children:[s.jsxs("div",{className:`text-sm font-medium text-white ${i("maintenance:update")?"group-hover:text-bambu-green":""} transition-colors flex items-center gap-1`,children:[Math.round(t.total_print_hours)," ",a("common.hours"),s.jsx(im,{className:`w-3 h-3 text-bambu-gray ${i("maintenance:update")?"group-hover:text-bambu-green":""}`})]}),s.jsx("div",{className:"text-xs text-bambu-gray",children:a("maintenance.totalPrintTime")})]})]}),s.jsx("div",{className:"w-px h-10 bg-bambu-dark-tertiary"}),m&&s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:`p-2 rounded-lg ${m.is_due?"bg-red-500/20":"bg-amber-500/20"}`,children:(()=>{const b=z0(m.maintenance_type_icon);return s.jsx(b,{className:`w-4 h-4 ${m.is_due?"text-red-400":"text-amber-400"}`})})()}),s.jsxs("div",{children:[s.jsx("div",{className:`text-sm font-medium ${m.is_due?"text-red-400":"text-amber-400"}`,children:m.maintenance_type_name}),s.jsx("div",{className:`text-xs ${m.is_due?"text-red-400/70":"text-amber-400/70"}`,children:m.is_due?a("common.overdue"):a("maintenance.dueSoon")})]})]})]})]}),o&&s.jsx(Mt,{className:"pt-0 border-t border-bambu-dark-tertiary",children:s.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4",children:p.map(b=>s.jsx(GKe,{item:b,onPerform:e,onToggle:n,hasPermission:i,t:a},b.id))})})]})}function WKe({overview:t,types:e,onUpdateInterval:n,onAddType:r,onUpdateType:i,onDeleteType:a,onAssignType:o,onRemoveItem:l,hasPermission:c,t:u}){const[d,f]=_.useState(null),[p,m]=_.useState(""),[x,b]=_.useState("hours"),[v,y]=_.useState(!1),[S,M]=_.useState(""),[T,k]=_.useState("100"),[C,E]=_.useState("hours"),[D,A]=_.useState("Wrench"),[j,I]=_.useState(""),[F,H]=_.useState(new Set),[R,z]=_.useState(null),W=_.useMemo(()=>t?t.map(U=>({id:U.printer_id,name:U.printer_name})):[],[t]),V=U=>t?t.filter(fe=>fe.maintenance_items.some(we=>we.maintenance_type_id===U)).map(fe=>({printerId:fe.printer_id,printerName:fe.printer_name,itemId:fe.maintenance_items.find(we=>we.maintenance_type_id===U)?.id})):[],X=U=>{if(!t)return[];const fe=new Set(V(U).map(we=>we.printerId));return W.filter(we=>!fe.has(we.id))},[Q,ae]=_.useState(null),[$,K]=_.useState(""),[ie,re]=_.useState(""),[xe,pe]=_.useState("hours"),[ue,Pe]=_.useState("Wrench"),[te,Ee]=_.useState(""),Oe=U=>{ae(U),K(U.name),re(U.default_interval_hours.toString()),pe(U.interval_type||"hours"),Pe(U.icon||"Wrench"),Ee(U.wiki_url||"")},me=()=>{Q&&$.trim()&&parseFloat(ie)>0&&(i(Q.id,{name:$.trim(),default_interval_hours:parseFloat(ie),interval_type:xe,icon:ue,wiki_url:te.trim()||null}),ae(null))},Xe=(U,fe,we)=>{const ge=parseFloat(p);if(!isNaN(ge)&&ge>0){const B=Math.abs(ge-fe)<.01?null:ge;n(U,{custom_interval_hours:B,custom_interval_type:x!==we?x:null})}f(null)},G=U=>{U.preventDefault(),S.trim()&&parseFloat(T)>0&&F.size>0&&(r({name:S.trim(),default_interval_hours:parseFloat(T),interval_type:C,icon:D,wiki_url:j.trim()||null},Array.from(F)),M(""),k("100"),E("hours"),I(""),H(new Set),y(!1))},Y=U=>{H(fe=>{const we=new Set(fe);return we.has(U)?we.delete(U):we.add(U),we})},de=t?.map(U=>({printerId:U.printer_id,printerName:U.printer_name,items:U.maintenance_items.sort((fe,we)=>fe.maintenance_type_id-we.maintenance_type_id)})).sort((U,fe)=>U.printerName.localeCompare(fe.printerName))||[],q=e.filter(U=>U.is_system),ee=e.filter(U=>!U.is_system);return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-4",children:[s.jsxs("div",{children:[s.jsx("h2",{className:"text-lg font-semibold text-white",children:u("maintenance.maintenanceTypes")}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:u("maintenance.maintenanceTypesDescription")})]}),s.jsxs(Te,{onClick:()=>y(!v),disabled:!c("maintenance:create"),title:c("maintenance:create")?void 0:u("maintenance.noPermissionEditTypes"),children:[s.jsx(fr,{className:"w-4 h-4"}),u("maintenance.addCustomType")]})]}),v&&s.jsx(Nt,{className:"mb-6",children:s.jsx(Mt,{className:"py-4",children:s.jsxs("form",{onSubmit:G,children:[s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[s.jsxs("div",{className:"lg:col-span-2",children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:u("common.name")}),s.jsx("input",{type:"text",value:S,onChange:U=>M(U.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",placeholder:u("maintenance.exampleName"),autoFocus:!0})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:u("maintenance.intervalType")}),s.jsxs("select",{value:C,onChange:U=>{E(U.target.value),U.target.value==="days"?k("30"):k("100")},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",children:[s.jsx("option",{value:"hours",children:u("maintenance.printHours")}),s.jsx("option",{value:"days",children:u("maintenance.calendarDays")})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:u("maintenance.intervalValue",{type:C==="days"?u("maintenance.calendarDays").toLowerCase():u("common.hours")})}),s.jsx("input",{type:"number",value:T,onChange:U=>k(U.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",min:"1"})]})]}),s.jsx("div",{className:"mt-4 flex items-end justify-between",children:s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:u("maintenance.icon")}),s.jsx("div",{className:"flex gap-1",children:Object.keys(g0).map(U=>{const fe=g0[U];return s.jsx("button",{type:"button",onClick:()=>A(U),className:`p-2 rounded-lg transition-colors ${D===U?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:s.jsx(fe,{className:"w-4 h-4"})},U)})})]})}),s.jsxs("div",{className:"mt-4",children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:u("maintenance.documentationLink")}),s.jsx("input",{type:"url",value:j,onChange:U=>I(U.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",placeholder:"https://wiki.bambulab.com/..."})]}),s.jsxs("div",{className:"mt-4",children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:u("maintenance.assignToPrinters")}),s.jsx("div",{className:"flex flex-wrap gap-2",children:W.map(U=>s.jsx("button",{type:"button",onClick:()=>Y(U.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${F.has(U.id)?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:U.name},U.id))}),F.size===0&&s.jsx("p",{className:"text-xs text-orange-400 mt-1",children:u("maintenance.selectAtLeastOnePrinter")})]}),s.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[s.jsx(Te,{type:"button",variant:"secondary",onClick:()=>{y(!1),H(new Set)},children:u("common.cancel")}),s.jsx(Te,{type:"submit",disabled:!S.trim()||F.size===0,children:u("maintenance.addType")})]})]})})}),s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:[q.map(U=>{const fe=z0(U.icon),we=U.interval_type||"hours";return s.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"p-2.5 bg-bambu-dark rounded-lg",children:s.jsx(fe,{className:"w-5 h-5 text-bambu-gray"})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("div",{className:"text-sm font-medium text-white truncate",children:U.name}),s.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 flex items-center gap-1",children:[we==="days"?s.jsx(ti,{className:"w-3 h-3"}):s.jsx(bu,{className:"w-3 h-3"}),qP(U.default_interval_hours,we,u)]})]})]})},U.id)}),ee.map(U=>{const fe=z0(U.icon),we=U.interval_type||"hours";if(Q?.id===U.id)return s.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green",children:s.jsxs("div",{className:"space-y-3",children:[s.jsx("input",{type:"text",value:$,onChange:se=>K(se.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",placeholder:u("common.name"),autoFocus:!0}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs("select",{value:xe,onChange:se=>pe(se.target.value),className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",children:[s.jsx("option",{value:"hours",children:u("maintenance.printHours")}),s.jsx("option",{value:"days",children:u("maintenance.calendarDays")})]}),s.jsx("input",{type:"number",value:ie,onChange:se=>re(se.target.value),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",min:"1"})]}),s.jsx("div",{className:"flex flex-wrap gap-1",children:Object.keys(g0).map(se=>{const ve=g0[se];return s.jsx("button",{type:"button",onClick:()=>Pe(se),className:`p-1.5 rounded transition-colors ${ue===se?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:s.jsx(ve,{className:"w-3.5 h-3.5"})},se)})}),s.jsx("input",{type:"url",value:te,onChange:se=>Ee(se.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",placeholder:u("maintenance.documentationLink")}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Te,{size:"sm",onClick:me,disabled:!$.trim(),children:u("common.save")}),s.jsx(Te,{size:"sm",variant:"secondary",onClick:()=>ae(null),children:u("common.cancel")})]})]})},U.id);const B=V(U.id),O=X(U.id),J=R===U.id;return s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"p-2.5 bg-bambu-green/20 rounded-lg",children:s.jsx(fe,{className:"w-5 h-5 text-bambu-green"})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-sm font-medium text-white truncate",children:U.name}),s.jsx("span",{className:"px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded",children:u("maintenance.custom")})]}),s.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 flex items-center gap-1",children:[we==="days"?s.jsx(ti,{className:"w-3 h-3"}):s.jsx(bu,{className:"w-3 h-3"}),qP(U.default_interval_hours,we,u)]})]}),s.jsxs("button",{onClick:()=>z(J?null:U.id),className:`px-2 py-1 rounded-lg border transition-colors flex items-center gap-1 ${B.length>0?"border-bambu-green/50 bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20":"border-orange-400/50 bg-orange-400/10 text-orange-400 hover:bg-orange-400/20"}`,title:u("maintenance.printersAssignedClick",{count:B.length}),children:[s.jsx(Pr,{className:"w-3 h-3"}),s.jsx("span",{className:"text-xs font-medium",children:B.length}),s.jsx(Kr,{className:`w-3 h-3 transition-transform ${J?"rotate-180":""}`})]}),s.jsx("button",{onClick:()=>Oe(U),disabled:!c("maintenance:update"),title:c("maintenance:update")?void 0:u("maintenance.noPermissionEditTypes"),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors ${c("maintenance:update")?"":"opacity-50 cursor-not-allowed"}`,children:s.jsx(im,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>{confirm(u("maintenance.deleteTypeConfirm",{name:U.name}))&&a(U.id)},disabled:!c("maintenance:delete"),title:c("maintenance:delete")?void 0:u("maintenance.noPermissionDeleteTypes"),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors ${c("maintenance:delete")?"":"opacity-50 cursor-not-allowed"}`,children:s.jsx(on,{className:"w-4 h-4"})})]}),J&&s.jsxs("div",{className:"mt-3 pt-3 border-t border-bambu-dark-tertiary",children:[s.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:u("maintenance.assignedToPrinters")}),B.length===0?s.jsx("p",{className:"text-xs text-orange-400",children:u("maintenance.noPrintersAssigned")}):s.jsx("div",{className:"flex flex-wrap gap-1 mb-2",children:B.map(se=>s.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark rounded text-xs text-white",children:[se.printerName,s.jsx("button",{onClick:()=>se.itemId&&l(se.itemId),disabled:!c("maintenance:delete"),title:c("maintenance:delete")?u("maintenance.removeFromPrinter"):u("maintenance.noPermissionRemovePrinter"),className:`ml-1 ${c("maintenance:delete")?"hover:text-red-400":"opacity-50 cursor-not-allowed"}`,children:"×"})]},se.printerId))}),O.length>0&&s.jsxs("div",{className:"flex flex-wrap gap-1",children:[s.jsx("span",{className:"text-xs text-bambu-gray mr-1",children:u("maintenance.addPrinterShort")}),O.map(se=>s.jsxs("button",{onClick:()=>o(se.id,U.id),disabled:!c("maintenance:create"),title:c("maintenance:create")?void 0:u("maintenance.noPermissionAssignPrinter"),className:`px-2 py-1 bg-bambu-dark rounded text-xs transition-colors ${c("maintenance:create")?"hover:bg-bambu-green/20 text-bambu-gray hover:text-bambu-green":"opacity-50 cursor-not-allowed text-bambu-gray"}`,children:["+ ",se.name]},se.id))]})]})]},U.id)})]})]}),de.length>0&&s.jsxs("div",{children:[s.jsxs("div",{className:"mb-4",children:[s.jsx("h2",{className:"text-lg font-semibold text-white",children:u("maintenance.intervalOverrides")}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:u("maintenance.intervalOverridesDescription")})]}),s.jsx("div",{className:"space-y-4",children:de.map(U=>s.jsx(Nt,{children:s.jsxs(Mt,{className:"py-4",children:[s.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:U.printerName}),s.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2",children:U.items.map(fe=>{const we=z0(fe.maintenance_type_icon),ge=e.find(ve=>ve.id===fe.maintenance_type_id),B=ge?.default_interval_hours||fe.interval_hours,O=ge?.interval_type||"hours",J=fe.interval_type||"hours",se=d===fe.id;return s.jsxs("div",{className:"flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg",children:[s.jsx(we,{className:"w-4 h-4 text-bambu-gray shrink-0"}),s.jsx("span",{className:"text-xs text-bambu-gray flex-1 truncate",children:fe.maintenance_type_name}),se?s.jsxs("div",{className:"flex items-center gap-1",children:[x==="days"?s.jsx(ti,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"}):s.jsx(bu,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"}),s.jsxs("select",{value:x,onChange:ve=>b(ve.target.value),className:"px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",children:[s.jsx("option",{value:"hours",children:u("maintenance.printHours")}),s.jsx("option",{value:"days",children:u("maintenance.calendarDays")})]}),s.jsx("input",{type:"number",value:p,onChange:ve=>m(ve.target.value),onKeyDown:ve=>{ve.key==="Enter"&&Xe(fe.id,B,O),ve.key==="Escape"&&f(null)},className:"w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",min:"1"}),s.jsx(Te,{size:"sm",onClick:()=>Xe(fe.id,B,O),children:"OK"})]}):s.jsxs("button",{onClick:()=>{c("maintenance:update")&&(f(fe.id),m(fe.interval_hours.toString()),b(J))},disabled:!c("maintenance:update"),title:c("maintenance:update")?void 0:u("maintenance.noPermissionEditIntervals"),className:`px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs font-medium text-white transition-colors flex items-center gap-1 ${c("maintenance:update")?"hover:bg-bambu-dark-secondary hover:border-bambu-green":"opacity-50 cursor-not-allowed"}`,children:[J==="days"?s.jsx(ti,{className:"w-3 h-3"}):s.jsx(bu,{className:"w-3 h-3"}),qP(fe.interval_hours,J,u),s.jsx(im,{className:"w-3 h-3 text-bambu-gray"})]})]},fe.id)})})]})},U.printerId))})]}),de.length===0&&s.jsx(Nt,{children:s.jsxs(Mt,{className:"text-center py-12",children:[s.jsx(nr,{className:"w-12 h-12 mx-auto mb-4 text-bambu-gray/30"}),s.jsx("p",{className:"text-bambu-gray",children:u("common.noPrinters")}),s.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1",children:u("maintenance.intervalOverridesDescription")})]})})]})}function KKe(){const{t}=On(),e=ln(),{showToast:n}=Vn(),{hasPermission:r}=Ci(),[i,a]=_.useState("status"),{data:o,isLoading:l}=ot({queryKey:["maintenanceOverview"],queryFn:ce.getMaintenanceOverview}),{data:c}=ot({queryKey:["maintenanceTypes"],queryFn:ce.getMaintenanceTypes}),u=gt({mutationFn:({id:k,notes:C})=>ce.performMaintenance(k,C),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),e.invalidateQueries({queryKey:["maintenanceSummary"]}),n(t("maintenance.maintenanceComplete"))},onError:k=>{n(k.message,"error")}}),d=gt({mutationFn:({id:k,data:C})=>ce.updateMaintenanceItem(k,C),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]})},onError:k=>{n(k.message,"error")}}),f=gt({mutationFn:({id:k,data:C})=>ce.updateMaintenanceType(k,C),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeUpdated"))},onError:k=>{n(k.message,"error")}}),p=gt({mutationFn:ce.deleteMaintenanceType,onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeDeleted"))},onError:k=>{n(k.message,"error")}}),m=gt({mutationFn:({printerId:k,hours:C})=>ce.setPrinterHours(k,C),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),e.invalidateQueries({queryKey:["maintenanceSummary"]}),n(t("maintenance.printHoursUpdated"))},onError:k=>{n(k.message,"error")}}),x=gt({mutationFn:({printerId:k,typeId:C})=>ce.assignMaintenanceType(k,C),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.printerAssigned"))},onError:k=>{n(k.message,"error")}}),b=gt({mutationFn:ce.removeMaintenanceItem,onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.printerRemoved"))},onError:k=>{n(k.message,"error")}}),v=k=>{u.mutate({id:k})},y=(k,C)=>{d.mutate({id:k,data:{enabled:C}})},S=(k,C)=>{m.mutate({printerId:k,hours:C})};if(l)return s.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:s.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})});const M=o?.reduce((k,C)=>k+C.due_count,0)||0,T=o?.reduce((k,C)=>k+C.warning_count,0)||0;return s.jsxs("div",{className:"p-4 md:p-8",children:[s.jsxs("div",{className:"mb-6",children:[s.jsx("h1",{className:"text-2xl font-bold text-white",children:t("maintenance.title")}),s.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:i==="status"?s.jsxs(s.Fragment,{children:[M>0&&s.jsx("span",{className:"text-red-400",children:t("maintenance.dueCount",{count:M})}),M>0&&T>0&&" · ",T>0&&s.jsx("span",{className:"text-amber-400",children:t("maintenance.warningCount",{count:T})}),M===0&&T===0&&s.jsx("span",{className:"text-bambu-green",children:t("maintenance.allOk")})]}):t("maintenance.configureSettings")})]}),s.jsxs("div",{className:"flex gap-1 mb-6 border-b border-bambu-dark-tertiary",children:[s.jsx("button",{onClick:()=>a("status"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i==="status"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:t("maintenance.statusTab")}),s.jsx("button",{onClick:()=>a("settings"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i==="settings"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:t("maintenance.settingsTab")})]}),i==="status"?s.jsx("div",{className:"space-y-6",children:o&&o.length>0?[...o].sort((k,C)=>{const E=k.due_count*10+k.warning_count,D=C.due_count*10+C.warning_count;return E!==D?D-E:k.printer_name.localeCompare(C.printer_name)}).map(k=>s.jsx(qKe,{overview:k,onPerform:v,onToggle:y,onSetHours:S,hasPermission:r,t},k.printer_id)):s.jsx(Nt,{children:s.jsxs(Mt,{className:"text-center py-16",children:[s.jsx(om,{className:"w-16 h-16 mx-auto mb-4 text-bambu-gray/30"}),s.jsx("p",{className:"text-lg font-medium text-white mb-2",children:t("common.noPrinters")}),s.jsx("p",{className:"text-bambu-gray",children:t("maintenance.configureSettings")})]})})}):s.jsx(WKe,{overview:o,types:c||[],onUpdateInterval:(k,C)=>d.mutate({id:k,data:C}),onAddType:async(k,C)=>{const E=await ce.createMaintenanceType(k);for(const D of C)await ce.assignMaintenanceType(D,E.id);e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeUpdated"))},onUpdateType:(k,C)=>f.mutate({id:k,data:C}),onDeleteType:k=>p.mutate(k),onAssignType:(k,C)=>x.mutate({printerId:k,typeId:C}),onRemoveItem:k=>b.mutate(k),hasPermission:r,t})]})}const yq=["#ef4444","#f97316","#eab308","#22c55e","#06b6d4","#3b82f6","#8b5cf6","#ec4899","#6b7280"];function $re({project:t,onClose:e,onSave:n,isLoading:r,t:i}){const[a,o]=_.useState(t?.name||""),[l,c]=_.useState(t?.description||""),[u,d]=_.useState(t?.color||yq[0]),[f,p]=_.useState(t?.target_count?.toString()||""),[m,x]=_.useState(t?.target_parts_count?.toString()||""),[b,v]=_.useState(t?.status||"active"),[y,S]=_.useState(t?.tags||""),[M,T]=_.useState(t?.due_date?.split("T")[0]||""),[k,C]=_.useState(t?.priority||"normal"),E=D=>{D.preventDefault(),n({name:a.trim(),description:l.trim()||void 0,color:u,target_count:f?parseInt(f,10):void 0,target_parts_count:m?parseInt(m,10):void 0,tags:y.trim()||void 0,due_date:M||void 0,priority:k,...t&&{status:b}})};return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary",children:[s.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:i(t?"projects.editProject":"projects.newProject")})}),s.jsxs("form",{onSubmit:E,className:"p-4 space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("common.name")}),s.jsx("input",{type:"text",value:a,onChange:D=>o(D.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:i("projects.namePlaceholder"),required:!0})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("common.description")}),s.jsx("textarea",{value:l,onChange:D=>c(D.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none",placeholder:i("projects.descriptionPlaceholder"),rows:2})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("projects.color")}),s.jsx("div",{className:"flex gap-2 flex-wrap",children:yq.map(D=>s.jsx("button",{type:"button",onClick:()=>d(D),className:`w-8 h-8 rounded-full transition-transform ${u===D?"ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110":""}`,style:{backgroundColor:D}},D))})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("projects.targetPlates")}),s.jsx("input",{type:"number",value:f,onChange:D=>p(D.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:i("projects.targetPlatesPlaceholder"),min:"1"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("projects.targetPlatesHelp")})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("projects.targetParts")}),s.jsx("input",{type:"number",value:m,onChange:D=>x(D.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:i("projects.targetPartsPlaceholder"),min:"1"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("projects.targetPartsHelp")})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("projects.tagsLabel")}),s.jsx("input",{type:"text",value:y,onChange:D=>S(D.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:i("projects.tagsPlaceholder")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("projects.dueDate")}),s.jsx("input",{type:"date",value:M,onChange:D=>T(D.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("projects.priority")}),s.jsxs("select",{value:k,onChange:D=>C(D.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green",children:[s.jsx("option",{value:"low",children:i("projects.priorityLow")}),s.jsx("option",{value:"normal",children:i("projects.priorityNormal")}),s.jsx("option",{value:"high",children:i("projects.priorityHigh")}),s.jsx("option",{value:"urgent",children:i("projects.priorityUrgent")})]})]})]}),t&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("common.status")}),s.jsxs("select",{value:b,onChange:D=>v(D.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green",children:[s.jsx("option",{value:"active",children:i("projects.statusActive")}),s.jsx("option",{value:"completed",children:i("projects.statusCompleted")}),s.jsx("option",{value:"archived",children:i("projects.statusArchived")})]})]}),s.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[s.jsx(Te,{type:"button",variant:"secondary",onClick:e,children:i("common.cancel")}),s.jsx(Te,{type:"submit",disabled:!a.trim()||r,children:r?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):i(t?"common.save":"projects.create")})]})]})]})})}function XKe({project:t,onClick:e,onEdit:n,onDelete:r,hasPermission:i,t:a}){const o=t.target_count?Math.round(t.archive_count/t.target_count*100):0,l=t.target_parts_count?Math.round(t.completed_count/t.target_parts_count*100):0,c=t.status==="completed",u=t.status==="archived",[d,f]=_.useState(!1),m=c?{icon:oM,color:"text-bambu-green",bg:"bg-bambu-green/10"}:u?{icon:ho,color:"text-bambu-gray",bg:"bg-bambu-gray/10"}:t.queue_count>0?{icon:nr,color:"text-blue-400",bg:"bg-blue-400/10"}:{icon:Ja,color:"text-bambu-gray",bg:"bg-bambu-gray/10"};return s.jsxs("div",{className:"group relative bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary hover:border-bambu-green/50 hover:shadow-lg hover:shadow-bambu-green/5 transition-all duration-300 cursor-pointer overflow-hidden",onClick:e,children:[s.jsx("div",{className:"absolute top-0 left-0 w-1.5 h-full",style:{backgroundColor:t.color||"#6b7280",boxShadow:`0 0 12px ${t.color||"#6b7280"}40`}}),s.jsxs("div",{className:"p-5 pl-6",children:[s.jsxs("div",{className:"flex items-start justify-between mb-4",children:[s.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[s.jsx("div",{className:`p-2 rounded-lg ${m.bg} flex-shrink-0`,children:s.jsx(m.icon,{className:`w-5 h-5 ${m.color}`})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s.jsx("h3",{className:"font-semibold text-white truncate",children:t.name}),t.target_parts_count?s.jsxs("span",{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${l>=100?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray"}`,children:[t.completed_count,"/",t.target_parts_count," ",a("projects.parts")]}):t.target_count?s.jsxs("span",{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${o>=100?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray"}`,children:[t.archive_count,"/",t.target_count," ",a("projects.plates")]}):t.completed_count>0?s.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium bg-bambu-dark text-bambu-gray",children:[t.completed_count," ",a("projects.parts")]}):null,c&&s.jsx("span",{className:"text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap",children:a("projects.done")}),u&&s.jsx("span",{className:"text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap",children:a("projects.statusArchived")})]}),t.description&&s.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1 line-clamp-1",children:t.description}),t.archives&&t.archives.length>0&&(()=>{const x=t.archives.map(S=>S.filament_type).filter(Boolean).flatMap(S=>S.split(",").map(M=>M.trim())).filter(Boolean),b=[...new Set(x)],v=t.archives.map(S=>S.filament_color).filter(Boolean).flatMap(S=>S.split(",").map(M=>M.trim())).filter(S=>S.startsWith("#")||/^[0-9A-Fa-f]{6}$/.test(S)),y=[...new Set(v)];return b.length===0&&y.length===0?null:s.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[b.slice(0,3).map(S=>s.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-bambu-dark text-bambu-gray rounded",children:S},S)),y.length>0&&s.jsxs("div",{className:"flex items-center gap-0.5",children:[y.slice(0,5).map(S=>s.jsx("div",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:S.startsWith("#")?S:`#${S}`},title:S},S)),y.length>5&&s.jsxs("span",{className:"text-[10px] text-bambu-gray ml-0.5",children:["+",y.length-5]})]})]})})()]})]}),s.jsxs("div",{className:"relative",onClick:x=>x.stopPropagation(),children:[s.jsx("button",{className:"p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors opacity-0 group-hover:opacity-100",onClick:()=>f(!d),children:s.jsx(sh,{className:"w-4 h-4"})}),d&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>f(!1)}),s.jsxs("div",{className:"absolute right-0 top-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]",children:[s.jsxs("button",{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${i("projects:update")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{i("projects:update")&&(n(),f(!1))},disabled:!i("projects:update"),title:i("projects:update")?void 0:a("projects.noEditPermission"),children:[s.jsx(im,{className:"w-4 h-4"}),a("common.edit")]}),s.jsxs("button",{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${i("projects:delete")?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{i("projects:delete")&&(r(),f(!1))},disabled:!i("projects:delete"),title:i("projects:delete")?void 0:a("projects.noDeletePermission"),children:[s.jsx(on,{className:"w-4 h-4"}),a("common.delete")]})]})]})]})]}),s.jsx("div",{className:"mb-4",children:t.target_count||t.target_parts_count?s.jsxs("div",{className:"space-y-3",children:[t.target_count&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[s.jsx("span",{className:"text-bambu-gray",children:a("projects.plates")}),s.jsxs("span",{className:o>=100?"text-bambu-green font-medium":"text-white",children:[t.archive_count," / ",t.target_count]})]}),s.jsx("div",{className:"h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm",children:s.jsx("div",{className:"h-full transition-all duration-500 ease-out rounded-full relative",style:{width:`${Math.min(o,100)}%`,background:o>=100?"linear-gradient(90deg, #22c55e, #4ade80)":`linear-gradient(90deg, ${t.color||"#6b7280"}, ${t.color||"#6b7280"}cc)`,boxShadow:`0 0 8px ${o>=100?"#22c55e":t.color||"#6b7280"}60`}})})]}),t.target_parts_count&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[s.jsx("span",{className:"text-bambu-gray",children:a("projects.parts")}),s.jsxs("span",{className:l>=100?"text-bambu-green font-medium":"text-white",children:[t.completed_count," / ",t.target_parts_count]})]}),s.jsx("div",{className:"h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm",children:s.jsx("div",{className:"h-full transition-all duration-500 ease-out rounded-full relative",style:{width:`${Math.min(l,100)}%`,background:l>=100?"linear-gradient(90deg, #22c55e, #4ade80)":`linear-gradient(90deg, ${t.color||"#6b7280"}, ${t.color||"#6b7280"}cc)`,boxShadow:`0 0 8px ${l>=100?"#22c55e":t.color||"#6b7280"}60`}})})]}),t.failed_count>0&&s.jsxs("div",{className:"text-xs text-red-400",children:[t.failed_count," ",a("projects.failed")]})]}):t.completed_count>0||t.failed_count>0?s.jsxs("div",{className:"flex items-center gap-4 text-xs",children:[t.completed_count>0&&s.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",children:[s.jsx(ho,{className:"w-3.5 h-3.5"}),s.jsxs("span",{children:[t.completed_count," ",a("projects.completed")]})]}),t.failed_count>0&&s.jsxs("div",{className:"flex items-center gap-1.5 text-red-400",children:[s.jsx(Sn,{className:"w-3.5 h-3.5"}),s.jsxs("span",{children:[t.failed_count," ",a("projects.failed")]})]}),t.queue_count>0&&s.jsxs("div",{className:"flex items-center gap-1.5 text-blue-400",children:[s.jsx(nr,{className:"w-3.5 h-3.5"}),s.jsxs("span",{children:[t.queue_count," ",a("projects.inQueue")]})]})]}):s.jsx("div",{className:"text-xs text-bambu-gray/60 italic",children:a("projects.noPrintsYet")})}),t.archives&&t.archives.length>0&&s.jsxs("div",{className:"mb-4",children:[s.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:t.archives.slice(0,4).map(x=>s.jsxs("div",{className:"relative aspect-square rounded-lg bg-bambu-dark overflow-hidden border border-bambu-dark-tertiary",title:x.print_name||"Unknown",children:[x.thumbnail_path?s.jsx("img",{src:ce.getArchiveThumbnail(x.id),alt:x.print_name||"",className:"w-full h-full object-cover"}):s.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray/50",children:s.jsx(pc,{className:"w-6 h-6"})}),x.status==="failed"&&s.jsx("div",{className:"absolute inset-0 bg-red-500/40 flex items-center justify-center",children:s.jsx(Sn,{className:"w-4 h-4 text-white"})})]},x.id))}),t.archive_count>4&&s.jsx("p",{className:"text-xs text-bambu-gray mt-1.5 text-center",children:a("common.more",{count:t.archive_count-4})})]}),s.jsxs("div",{className:"flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-4 text-xs text-bambu-gray",children:[s.jsxs("div",{className:"flex items-center gap-1.5",title:a("projects.printJobs"),children:[s.jsx(sl,{className:"w-3.5 h-3.5 text-blue-400"}),s.jsxs("span",{children:[t.archive_count," ",a("projects.plates")]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",title:a("projects.partsPrinted"),children:[s.jsx(pc,{className:"w-3.5 h-3.5 text-bambu-green"}),s.jsxs("span",{children:[t.completed_count," ",a("projects.parts")]})]}),t.failed_count>0&&s.jsxs("div",{className:"flex items-center gap-1.5 text-red-400",title:a("projects.failedParts"),children:[s.jsx(Sn,{className:"w-3.5 h-3.5"}),s.jsx("span",{children:t.failed_count})]}),t.queue_count>0&&s.jsxs("div",{className:"flex items-center gap-1.5 text-yellow-400",title:a("projects.inQueue"),children:[s.jsx(pj,{className:"w-3.5 h-3.5"}),s.jsx("span",{children:t.queue_count})]})]}),s.jsx(gs,{className:"w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors"})]})]})]})}function YKe(){const{t}=On(),e=kc(),n=ln(),{showToast:r}=Vn(),{hasPermission:i}=Ci(),[a,o]=_.useState(!1),[l,c]=_.useState(),[u,d]=_.useState("active"),[f,p]=_.useState(null),{data:m,isLoading:x}=ot({queryKey:["projects",u==="all"?void 0:u],queryFn:()=>ce.getProjects(u==="all"?void 0:u)}),b=gt({mutationFn:H=>ce.createProject(H),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),o(!1),r(t("projects.toast.created"),"success")},onError:H=>{r(H.message,"error")}}),v=gt({mutationFn:({id:H,data:R})=>ce.updateProject(H,R),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),o(!1),c(void 0),r(t("projects.toast.updated"),"success")},onError:H=>{r(H.message,"error")}}),y=gt({mutationFn:H=>ce.deleteProject(H),onSuccess:()=>{p(null),r(t("projects.toast.deleted"),"success"),setTimeout(()=>window.location.reload(),100)},onError:H=>{p(null),r(H.message,"error")}}),S=gt({mutationFn:H=>ce.importProject(H),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),r(t("projects.toast.imported"),"success")},onError:H=>{r(H.message,"error")}}),M=_.useRef(null),T=async()=>{try{const H=await ce.getProjects(),R=await Promise.all(H.map(async X=>await ce.exportProjectJson(X.id))),z=new Blob([JSON.stringify(R,null,2)],{type:"application/json"}),W=URL.createObjectURL(z),V=document.createElement("a");V.href=W,V.download=`bambuddy_projects_${new Date().toISOString().split("T")[0]}.json`,V.click(),URL.revokeObjectURL(W),r(t("projects.toast.exported"),"success")}catch(H){r(H.message,"error")}},k=()=>{M.current?.click()},C=async H=>{const R=H.target.files?.[0];if(R){try{if(R.name.toLowerCase().endsWith(".zip"))await ce.importProjectFile(R),n.invalidateQueries({queryKey:["projects"]}),r(t("projects.toast.imported"),"success");else{const W=await R.text(),V=JSON.parse(W),X=Array.isArray(V)?V:[V];for(const Q of X)await S.mutateAsync(Q);X.length>1&&r(t("projects.toast.multipleImported",{count:X.length}),"success")}}catch(z){r(`${t("projects.toast.importFailed")}: ${z.message}`,"error")}H.target.value=""}},E=H=>{l?v.mutate({id:l.id,data:H}):b.mutate(H)},D=H=>{c(H),o(!0)},A=H=>{e(`/projects/${H.id}`)},j=H=>{p(H)},I=()=>{f!==null&&y.mutate(f)},F=m?.reduce((H,R)=>(H[R.status]=(H[R.status]||0)+1,H.all=(H.all||0)+1,H),{})||{};return s.jsxs("div",{className:"p-4 md:p-8 space-y-8",children:[s.jsx("input",{ref:M,type:"file",accept:".json,.zip",onChange:C,className:"hidden"}),s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[s.jsxs("div",{children:[s.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[s.jsx("div",{className:"p-2.5 bg-bambu-green/10 rounded-xl",children:s.jsx(Ja,{className:"w-6 h-6 text-bambu-green"})}),t("projects.title")]}),s.jsx("p",{className:"text-sm text-bambu-gray mt-2 ml-14",children:t("projects.subtitle")})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(Te,{variant:"secondary",onClick:k,disabled:!i("projects:create"),title:i("projects:create")?t("projects.importProject"):t("projects.noImportPermission"),children:[s.jsx(za,{className:"w-4 h-4 mr-2"}),t("projects.import")]}),s.jsxs(Te,{variant:"secondary",onClick:T,disabled:!i("projects:read"),title:i("projects:read")?t("projects.exportAll"):t("projects.noExportPermission"),children:[s.jsx(wi,{className:"w-4 h-4 mr-2"}),t("projects.export")]}),s.jsxs(Te,{onClick:()=>o(!0),className:"sm:w-auto w-full",disabled:!i("projects:create"),title:i("projects:create")?void 0:t("projects.noCreatePermission"),children:[s.jsx(fr,{className:"w-4 h-4 mr-2"}),t("projects.newProject")]})]})]}),s.jsx("div",{className:"flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit",children:[{key:"active",label:t("projects.statusActive"),icon:nr},{key:"completed",label:t("projects.statusCompleted"),icon:oM},{key:"archived",label:t("projects.statusArchived"),icon:ho},{key:"all",label:t("common.all"),icon:Ja}].map(({key:H,label:R,icon:z})=>s.jsxs("button",{onClick:()=>d(H),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${u===H?"bg-bambu-card text-white shadow-sm":"text-bambu-gray hover:text-white"}`,children:[s.jsx(z,{className:"w-4 h-4"}),s.jsx("span",{children:R}),F[H]>0&&s.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded-full ${u===H?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary"}`,children:F[H]})]},H))}),x?s.jsx("div",{className:"flex items-center justify-center py-20",children:s.jsxs("div",{className:"flex flex-col items-center gap-3",children:[s.jsx(pt,{className:"w-8 h-8 animate-spin text-bambu-green"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:t("projects.loading")})]})}):m?.length===0?s.jsxs("div",{className:"flex flex-col items-center justify-center py-20 px-4",children:[s.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:s.jsx(Ja,{className:"w-12 h-12 text-bambu-gray/50"})}),s.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:u==="all"?t("projects.noProjects"):t("projects.noProjectsFiltered",{status:u})}),s.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:u==="all"?t("projects.createFirst"):t("projects.noProjectsFilteredHelp",{status:u})}),u==="all"&&s.jsxs(Te,{onClick:()=>o(!0),disabled:!i("projects:create"),title:i("projects:create")?void 0:t("projects.noCreatePermission"),children:[s.jsx(fr,{className:"w-4 h-4 mr-2"}),t("projects.createFirstButton")]})]}):s.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8",children:m?.map(H=>s.jsx(XKe,{project:H,onClick:()=>A(H),onEdit:()=>D(H),onDelete:()=>j(H.id),hasPermission:i,t},H.id))}),f!==null&&s.jsx(Jn,{title:t("projects.deleteProject"),message:t("projects.deleteConfirm"),confirmText:t("projects.deleteProject"),variant:"danger",onConfirm:I,onCancel:()=>p(null)}),a&&s.jsx($re,{project:l,onClose:()=>{o(!1),c(void 0)},onSave:E,isLoading:b.isPending||v.isPending,t})]})}function QKe(t){if(t<1)return`${Math.round(t*60)}m`;const e=Math.floor(t),n=Math.round((t-e)*60);return n>0?`${e}h ${n}m`:`${e}h`}function ZKe(t){return t>=1e3?`${(t/1e3).toFixed(2)}kg`:`${Math.round(t)}g`}function JKe({status:t,t:e}){const n={active:"bg-bambu-green/20 text-bambu-green",completed:"bg-blue-500/20 text-blue-400",archived:"bg-bambu-gray/20 text-bambu-gray"},r=n[t]||n.active,i={active:e("projectDetail.status.active"),completed:e("projectDetail.status.completed"),archived:e("projectDetail.status.archived")};return s.jsx("span",{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:i[t]||t.charAt(0).toUpperCase()+t.slice(1)})}function vq({icon:t,label:e,value:n,subValue:r,hint:i,color:a="text-bambu-gray"}){return s.jsx(Nt,{children:s.jsx(Mt,{className:"p-4",children:s.jsxs("div",{className:"flex items-center gap-3",title:i,children:[s.jsx("div",{className:`p-2 rounded-lg bg-bambu-dark ${a}`,children:s.jsx(t,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:e}),s.jsx("p",{className:"text-xl font-semibold text-white",children:n}),r&&s.jsx("p",{className:"text-xs text-bambu-gray/70",children:r})]})]})})})}function eXe({archives:t,t:e}){return t.length===0?s.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[s.jsx(pc,{className:"w-12 h-12 mx-auto mb-2 opacity-50"}),s.jsx("p",{children:e("projectDetail.noPrints")})]}):s.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3",children:t.map(n=>s.jsxs(Ds,{to:`/archives?search=${encodeURIComponent(n.print_name||"")}`,className:"group relative aspect-square rounded-lg bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden hover:border-bambu-green transition-colors",children:[n.thumbnail_path?s.jsx("img",{src:ce.getArchiveThumbnail(n.id),alt:n.print_name||"Print",className:"w-full h-full object-cover"}):s.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:s.jsx(pc,{className:"w-8 h-8"})}),n.status==="failed"&&s.jsx("div",{className:"absolute inset-0 bg-red-500/30 flex items-center justify-center",children:s.jsx(Qi,{className:"w-8 h-8 text-white"})}),n.status==="completed"&&s.jsx("div",{className:"absolute top-1 right-1",children:s.jsx(Ar,{className:"w-4 h-4 text-bambu-green"})}),s.jsx("div",{className:"absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity",children:s.jsx("p",{className:"text-xs text-white truncate",children:n.print_name||"Unknown"})})]},n.id))})}function tXe({priority:t,t:e}){const n={low:{color:"bg-gray-500/20 text-gray-400",label:e("projectDetail.priority.low")},normal:{color:"bg-blue-500/20 text-blue-400",label:e("projectDetail.priority.normal")},high:{color:"bg-orange-500/20 text-orange-400",label:e("projectDetail.priority.high")},urgent:{color:"bg-red-500/20 text-red-400",label:e("projectDetail.priority.urgent")}},{color:r,label:i}=n[t]||n.normal;return s.jsxs("span",{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[t==="urgent"&&s.jsx(Sn,{className:"w-3 h-3"}),i]})}function nXe(t){return t?Bg(t,{year:"numeric",month:"short",day:"numeric"}):""}function WP(t,e){if(!t)return null;const n=Ui(t);if(!n)return null;const r=new Date,i=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return i<0?{color:"text-red-400",label:e("projectDetail.dueDate.overdue")}:i===0?{color:"text-orange-400",label:e("projectDetail.dueDate.today")}:i<=3?{color:"text-yellow-400",label:e("projectDetail.dueDate.daysLeft",{count:i})}:{color:"text-bambu-gray",label:e("projectDetail.dueDate.daysLeft",{count:i})}}function rXe(){const{id:t}=iM(),e=kc(),{t:n}=On(),r=ln(),{showToast:i}=Vn(),{hasPermission:a}=Ci(),[o,l]=_.useState(!1),[c,u]=_.useState(!1),[d,f]=_.useState(""),p=parseInt(t||"0",10),{data:m,isLoading:x,error:b}=ot({queryKey:["project",p],queryFn:()=>ce.getProject(p),enabled:p>0}),{data:v,isLoading:y}=ot({queryKey:["project-archives",p],queryFn:()=>ce.getProjectArchives(p),enabled:p>0}),{data:S,isLoading:M}=ot({queryKey:["project-bom",p],queryFn:()=>ce.getProjectBOM(p),enabled:p>0}),{data:T,isLoading:k}=ot({queryKey:["project-timeline",p],queryFn:()=>ce.getProjectTimeline(p,20),enabled:p>0}),{data:C}=ot({queryKey:["settings"],queryFn:ce.getSettings}),{data:E}=ot({queryKey:["project-folders",p],queryFn:()=>ce.getLibraryFoldersByProject(p),enabled:p>0}),D=C?.currency||"$",A=C?.time_format||"system",j=gt({mutationFn:Me=>ce.updateProject(p,Me),onSuccess:()=>{r.invalidateQueries({queryKey:["project",p]}),r.invalidateQueries({queryKey:["projects"]}),l(!1),u(!1),i(n("projectDetail.toast.projectUpdated"),"success")},onError:Me=>{i(Me.message,"error")}}),I=()=>{f(m?.notes||""),u(!0)},F=()=>{j.mutate({notes:d})},H=()=>{u(!1),f("")},[R,z]=_.useState(""),[W,V]=_.useState(1),[X,Q]=_.useState(""),[ae,$]=_.useState(""),[K,ie]=_.useState(""),[re,xe]=_.useState(!1),[pe,ue]=_.useState(!1),[Pe,te]=_.useState(null),[Ee,Oe]=_.useState(""),[me,Xe]=_.useState(1),[G,Y]=_.useState(""),[de,q]=_.useState(""),[ee,U]=_.useState(""),[fe,we]=_.useState({isOpen:!1,title:"",message:"",onConfirm:()=>{}}),ge=gt({mutationFn:Me=>ce.createBOMItem(p,Me),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),z(""),V(1),Q(""),$(""),ie(""),xe(!1),i(n("projectDetail.toast.partAdded"),"success")},onError:Me=>i(Me.message,"error")}),B=gt({mutationFn:({itemId:Me,data:Ge})=>ce.updateBOMItem(p,Me,Ge),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),te(null)},onError:Me=>i(Me.message,"error")}),O=gt({mutationFn:Me=>ce.deleteBOMItem(p,Me),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),i(n("projectDetail.toast.partRemoved"),"success")},onError:Me=>i(Me.message,"error")}),J=Me=>{Me.preventDefault(),R.trim()&&ge.mutate({name:R.trim(),quantity_needed:W,unit_price:X?parseFloat(X):void 0,sourcing_url:ae.trim()||void 0,remarks:K.trim()||void 0})},se=Me=>{const Ge=Me.is_complete?0:Me.quantity_needed;B.mutate({itemId:Me.id,data:{quantity_acquired:Ge}})},ve=(Me,Ge)=>{we({isOpen:!0,title:n("projectDetail.bom.deletePart"),message:n("projectDetail.bom.deleteConfirm",{name:Ge}),onConfirm:()=>{we(Ne=>({...Ne,isOpen:!1})),O.mutate(Me)}})},_e=Me=>{te(Me),Oe(Me.name),Xe(Me.quantity_needed),Y(Me.unit_price?.toString()||""),q(Me.sourcing_url||""),U(Me.remarks||"")},ne=Me=>{Me.preventDefault(),!(!Pe||!Ee.trim())&&B.mutate({itemId:Pe.id,data:{name:Ee.trim(),quantity_needed:me,unit_price:G?parseFloat(G):void 0,sourcing_url:de.trim()||void 0,remarks:ee.trim()||void 0}})},Fe=()=>{te(null)},He=async()=>{try{const{blob:Me,filename:Ge}=await ce.exportProjectZip(Number(p)),Ne=URL.createObjectURL(Me),nt=document.createElement("a");nt.href=Ne,nt.download=Ge||`${m?.name||"project"}_${new Date().toISOString().split("T")[0]}.zip`,nt.click(),URL.revokeObjectURL(Ne),i(n("projectDetail.toast.projectExported"),"success")}catch(Me){i(Me.message,"error")}},rt=gt({mutationFn:()=>ce.createTemplateFromProject(p),onSuccess:()=>{r.invalidateQueries({queryKey:["projects"]}),i(n("projectDetail.toast.templateCreated"),"success")},onError:Me=>i(Me.message,"error")}),Ie=Me=>Hg(Me,A,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"});if(x)return s.jsx("div",{className:"flex items-center justify-center py-24",children:s.jsx(pt,{className:"w-8 h-8 animate-spin text-bambu-green"})});if(b||!m)return s.jsxs("div",{className:"text-center py-24",children:[s.jsx("p",{className:"text-bambu-gray",children:b?`${n("common.error")}: ${b.message}`:n("projectDetail.notFound")}),s.jsx(Te,{variant:"secondary",className:"mt-4",onClick:()=>e("/projects"),children:n("projectDetail.backToProjects")})]});const be=m.stats,Ae=be?.progress_percent??0,Ue=be?.parts_progress_percent??0;return s.jsxs("div",{className:"p-4 md:p-8 space-y-8",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[s.jsx(Ds,{to:"/projects",className:"hover:text-white transition-colors",children:n("navigation.projects")}),s.jsx(gs,{className:"w-4 h-4"}),s.jsx("span",{className:"text-white",children:m.name})]}),s.jsxs("div",{className:"flex items-start justify-between",children:[s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsx("button",{onClick:()=>e("/projects"),className:"p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors",children:s.jsx(fce,{className:"w-5 h-5 text-bambu-gray"})}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-4 h-4 rounded-full flex-shrink-0",style:{backgroundColor:m.color||"#6b7280"}}),s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold text-white",children:m.name}),m.description&&s.jsx("p",{className:"text-bambu-gray mt-1",children:m.description})]})]}),s.jsx(JKe,{status:m.status,t:n})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(Te,{variant:"secondary",onClick:He,disabled:!a("projects:read"),title:a("projects:read")?n("projectDetail.exportProject"):n("projectDetail.noExportPermission"),children:[s.jsx(wi,{className:"w-4 h-4 mr-2"}),n("projectDetail.export")]}),s.jsxs(Te,{onClick:()=>l(!0),disabled:!a("projects:update"),title:a("projects:update")?void 0:n("projectDetail.noEditPermission"),children:[s.jsx(im,{className:"w-4 h-4 mr-2"}),n("common.edit")]})]})]}),(m.target_count||m.target_parts_count)&&s.jsx(Nt,{children:s.jsxs(Mt,{className:"p-4 space-y-4",children:[m.target_count&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsx("span",{className:"text-sm text-bambu-gray",children:n("projectDetail.progress.platesProgress")}),s.jsxs("span",{className:"text-sm font-medium text-white",children:[be?.total_archives||0," / ",m.target_count," ",n("projectDetail.progress.printJobs")]})]}),s.jsx("div",{className:"h-3 bg-bambu-dark rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${Math.min(Ae,100)}%`,backgroundColor:Ae>=100?"#22c55e":m.color||"#6b7280"}})}),s.jsxs("div",{className:"flex justify-between mt-1",children:[s.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.percentComplete",{percent:Ae.toFixed(0)})}),be?.remaining_prints!=null&&be.remaining_prints>0&&s.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.remaining",{count:be.remaining_prints})})]})]}),m.target_parts_count&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsx("span",{className:"text-sm text-bambu-gray",children:n("projectDetail.progress.partsProgress")}),s.jsxs("span",{className:"text-sm font-medium text-white",children:[be?.completed_prints||0," / ",m.target_parts_count," ",n("projectDetail.progress.parts")]})]}),s.jsx("div",{className:"h-3 bg-bambu-dark rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${Math.min(Ue,100)}%`,backgroundColor:Ue>=100?"#22c55e":m.color||"#6b7280"}})}),s.jsxs("div",{className:"flex justify-between mt-1",children:[s.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.percentComplete",{percent:Ue.toFixed(0)})}),be?.remaining_parts!=null&&be.remaining_parts>0&&s.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.remaining",{count:be.remaining_parts})})]})]})]})}),be&&s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[s.jsx(Nt,{children:s.jsx(Mt,{className:"p-4",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:s.jsx(pc,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:n("projectDetail.stats.printJobs")}),s.jsxs("p",{className:"text-xl font-semibold text-white",children:[be.total_archives," ",s.jsx("span",{className:"text-sm font-normal text-bambu-gray",children:n("projectDetail.stats.total")})]}),be.failed_prints>0&&s.jsx("p",{className:"text-sm text-status-error",children:n("projectDetail.stats.failed",{count:be.failed_prints})}),s.jsx("p",{className:"text-sm text-bambu-gray",children:n("projectDetail.stats.partsPrinted",{count:be.completed_prints})})]})]})})}),s.jsx(vq,{icon:nr,label:n("projectDetail.stats.printTime"),value:QKe(be.total_print_time_hours),color:"text-yellow-400"}),s.jsx(vq,{icon:Pr,label:n("projectDetail.stats.filamentUsed"),value:ZKe(be.total_filament_grams),color:"text-purple-400"})]}),be&&(be.estimated_cost>0||m.budget)&&s.jsx(Nt,{children:s.jsxs(Mt,{className:"p-4",children:[s.jsx("h2",{className:"text-lg font-semibold text-white mb-3",children:n("projectDetail.cost.title")}),s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.filamentCost")}),s.jsxs("p",{className:"text-lg font-semibold text-white",children:[D,be.estimated_cost.toFixed(2)]})]}),be.total_energy_kwh>0&&s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.energy")}),s.jsxs("p",{className:"text-lg font-semibold text-white",children:[be.total_energy_kwh.toFixed(2)," kWh",be.total_energy_cost>0&&s.jsxs("span",{className:"text-sm text-bambu-gray ml-1",children:["(",D,be.total_energy_cost.toFixed(2),")"]})]})]}),m.budget&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.budget")}),s.jsxs("p",{className:"text-lg font-semibold text-white",children:[D,m.budget.toFixed(2)]})]}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.remaining")}),s.jsxs("p",{className:`text-lg font-semibold ${m.budget-be.estimated_cost>=0?"text-bambu-green":"text-red-400"}`,children:[D,(m.budget-be.estimated_cost).toFixed(2)]})]})]})]})]})}),m.children&&m.children.length>0&&s.jsx(Nt,{children:s.jsxs(Mt,{className:"p-4",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-3",children:[s.jsx(Vue,{className:"w-5 h-5"}),n("projectDetail.subProjects.title",{count:m.children.length})]}),s.jsx("div",{className:"space-y-2",children:m.children.map(Me=>s.jsxs(Ds,{to:`/projects/${Me.id}`,className:"flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:Me.color||"#6b7280"}}),s.jsx("span",{className:"text-white",children:Me.name}),s.jsx("span",{className:`text-xs px-2 py-0.5 rounded ${Me.status==="completed"?"bg-status-ok/20 text-status-ok":Me.status==="archived"?"bg-bambu-gray/20 text-bambu-gray":"bg-blue-500/20 text-blue-400"}`,children:Me.status})]}),Me.progress_percent!==null&&s.jsxs("span",{className:"text-sm text-bambu-gray",children:[Me.progress_percent.toFixed(0),"%"]})]},Me.id))})]})}),m.parent_id&&m.parent_name&&s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsx(sl,{className:"w-4 h-4 text-bambu-gray"}),s.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.partOf")}),s.jsx(Ds,{to:`/projects/${m.parent_id}`,className:"text-bambu-green hover:underline",children:m.parent_name})]}),(m.tags||m.due_date||m.priority!=="normal")&&s.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[m.priority&&m.priority!=="normal"&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.priorityLabel")}),s.jsx(tXe,{priority:m.priority,t:n})]}),m.due_date&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ti,{className:"w-4 h-4 text-bambu-gray"}),s.jsx("span",{className:"text-sm text-white",children:nXe(m.due_date)}),WP(m.due_date,n)&&s.jsxs("span",{className:`text-xs ${WP(m.due_date,n).color}`,children:["(",WP(m.due_date,n).label,")"]})]}),m.tags&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(wh,{className:"w-4 h-4 text-bambu-gray"}),s.jsx("div",{className:"flex flex-wrap gap-1",children:m.tags.split(",").map((Me,Ge)=>s.jsx("span",{className:"px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded",children:Me.trim()},Ge))})]})]}),s.jsx(Nt,{children:s.jsxs(Mt,{className:"p-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Ls,{className:"w-5 h-5"}),n("projectDetail.notes.title")]}),c?s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(Te,{variant:"secondary",size:"sm",onClick:H,disabled:j.isPending,children:[s.jsx(Lt,{className:"w-4 h-4 mr-1"}),n("common.cancel")]}),s.jsxs(Te,{size:"sm",onClick:F,disabled:j.isPending,children:[j.isPending?s.jsx(pt,{className:"w-4 h-4 animate-spin mr-1"}):s.jsx(hs,{className:"w-4 h-4 mr-1"}),n("common.save")]})]}):s.jsxs(Te,{variant:"secondary",size:"sm",onClick:I,disabled:!a("projects:update"),title:a("projects:update")?void 0:n("projectDetail.notes.noEditPermission"),children:[s.jsx(im,{className:"w-4 h-4 mr-1"}),n("common.edit")]})]}),c?s.jsx(iR,{content:d,onChange:f,placeholder:n("projectDetail.notes.placeholder")}):m.notes?s.jsx("div",{className:"prose prose-invert prose-sm max-w-none",dangerouslySetInnerHTML:{__html:m.notes}}):s.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.notes.empty")})]})}),s.jsx(Nt,{children:s.jsxs(Mt,{className:"p-4",children:[s.jsx("div",{className:"flex items-center justify-between mb-3",children:s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Il,{className:"w-5 h-5"}),n("projectDetail.files.title")]})}),s.jsxs("p",{className:"text-xs text-bambu-gray mb-3",children:[s.jsx(Ds,{to:"/files",className:"text-bambu-green hover:underline",children:n("projectDetail.files.linkFolders")})," ",n("projectDetail.files.forQuickAccess")]}),E&&E.length>0?s.jsx("div",{className:"space-y-2",children:E.map(Me=>s.jsxs(Ds,{to:`/files?folder=${Me.id}`,className:"flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[s.jsx(Il,{className:"w-5 h-5 text-bambu-green flex-shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"text-sm text-white truncate",children:Me.name}),s.jsx("p",{className:"text-xs text-bambu-gray",children:n("projectDetail.files.fileCount",{count:Me.file_count})})]})]}),s.jsx(gs,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"})]},Me.id))}):s.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.files.empty")})]})}),s.jsx(Nt,{children:s.jsxs(Mt,{className:"p-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-4",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(AW,{className:"w-5 h-5"}),n("projectDetail.bom.title"),be&&be.bom_total_items>0&&s.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",n("projectDetail.bom.acquired",{completed:be.bom_completed_items,total:be.bom_total_items}),")"]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[S&&S.some(Me=>Me.is_complete)&&s.jsx("button",{onClick:()=>ue(!pe),className:`text-xs px-2 py-1 rounded transition-colors ${pe?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:n(pe?"projectDetail.bom.showAll":"projectDetail.bom.hideDone")}),!re&&s.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>xe(!0),disabled:!a("projects:update"),title:a("projects:update")?void 0:n("projectDetail.bom.noAddPermission"),children:[s.jsx(fr,{className:"w-4 h-4 mr-1"}),n("projectDetail.bom.addPart")]})]})]}),re&&s.jsxs("form",{onSubmit:J,className:"bg-bambu-dark rounded-lg p-4 mb-4 space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[s.jsx("input",{type:"text",value:R,onChange:Me=>z(Me.target.value),className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.partNamePlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{type:"number",value:W,onChange:Me=>V(parseInt(Me.target.value)||1),className:"w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green",min:"1",placeholder:n("projectDetail.bom.qty")}),s.jsx("input",{type:"number",step:"0.01",value:X,onChange:Me=>Q(Me.target.value),className:"flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.price",{currency:D})})]})]}),s.jsx("input",{type:"url",value:ae,onChange:Me=>$(Me.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.sourcingUrlPlaceholder")}),s.jsx("input",{type:"text",value:K,onChange:Me=>ie(Me.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.remarksPlaceholder")}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(Te,{type:"button",variant:"secondary",size:"sm",onClick:()=>xe(!1),children:n("common.cancel")}),s.jsx(Te,{type:"submit",size:"sm",disabled:!R.trim()||ge.isPending,children:ge.isPending?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):n("projectDetail.bom.addPart")})]})]}),M?s.jsx("div",{className:"flex items-center justify-center py-4",children:s.jsx(pt,{className:"w-6 h-6 animate-spin text-bambu-green"})}):S&&S.length>0?s.jsxs("div",{className:"space-y-2",children:[S.filter(Me=>!pe||!Me.is_complete).map(Me=>s.jsx("div",{className:`p-3 rounded-lg transition-colors ${Me.is_complete?"bg-status-ok/10":"bg-bambu-dark"}`,children:Pe?.id===Me.id?s.jsxs("form",{onSubmit:ne,className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[s.jsx("input",{type:"text",value:Ee,onChange:Ge=>Oe(Ge.target.value),className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.partName"),autoFocus:!0}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{type:"number",value:me,onChange:Ge=>Xe(parseInt(Ge.target.value)||1),className:"w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green",min:"1",placeholder:n("projectDetail.bom.qty")}),s.jsx("input",{type:"number",step:"0.01",value:G,onChange:Ge=>Y(Ge.target.value),className:"flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.price",{currency:D})})]})]}),s.jsx("input",{type:"url",value:de,onChange:Ge=>q(Ge.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.sourcingUrlPlaceholder")}),s.jsx("input",{type:"text",value:ee,onChange:Ge=>U(Ge.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.remarksPlaceholder")}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(Te,{type:"button",variant:"secondary",size:"sm",onClick:Fe,children:n("common.cancel")}),s.jsx(Te,{type:"submit",size:"sm",disabled:!Ee.trim()||B.isPending,children:B.isPending?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):n("common.save")})]})]}):s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("button",{onClick:()=>a("projects:update")&&se(Me),disabled:B.isPending||!a("projects:update"),title:a("projects:update")?void 0:n("projectDetail.bom.noUpdatePermission"),className:`w-5 h-5 mt-0.5 rounded border-2 flex items-center justify-center transition-colors flex-shrink-0 ${Me.is_complete?"bg-status-ok border-status-ok text-white":a("projects:update")?"border-bambu-gray hover:border-bambu-green":"border-bambu-gray/50 cursor-not-allowed"}`,children:Me.is_complete&&s.jsx(Ar,{className:"w-3 h-3"})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsxs("p",{className:`text-sm font-medium ${Me.is_complete?"text-bambu-gray line-through":"text-white"}`,children:[Me.name,s.jsxs("span",{className:"text-bambu-gray font-normal ml-2",children:["x",Me.quantity_needed]})]}),Me.unit_price!==null&&s.jsxs("span",{className:"text-xs text-bambu-green whitespace-nowrap",children:[D,(Me.unit_price*Me.quantity_needed).toFixed(2)]})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("button",{onClick:()=>a("projects:update")&&_e(Me),disabled:!a("projects:update"),className:`p-1 rounded transition-colors flex-shrink-0 ${a("projects:update")?"hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:a("projects:update")?n("common.edit"):n("projectDetail.bom.noEditPermission"),children:s.jsx(Zi,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>a("projects:update")&&ve(Me.id,Me.name),disabled:!a("projects:update"),className:`p-1 rounded transition-colors flex-shrink-0 ${a("projects:update")?"hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400":"text-bambu-gray/50 cursor-not-allowed"}`,title:a("projects:update")?n("common.delete"):n("projectDetail.bom.noDeletePermission"),children:s.jsx(on,{className:"w-4 h-4"})})]})]}),Me.sourcing_url&&s.jsxs("a",{href:Me.sourcing_url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 mt-1 text-xs text-blue-400 hover:text-blue-300 transition-colors",onClick:Ge=>Ge.stopPropagation(),children:[s.jsx(Xr,{className:"w-3 h-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:(()=>{try{return new URL(Me.sourcing_url).hostname.replace("www.","")}catch{return Me.sourcing_url}})()})]}),Me.remarks&&s.jsx("p",{className:"mt-1 text-xs text-bambu-gray/80 italic",children:Me.remarks})]})]})},Me.id)),S.some(Me=>Me.unit_price!==null)&&s.jsxs("div",{className:"pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm",children:[s.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.bom.totalCost")}),s.jsxs("span",{className:"text-white font-medium",children:[D,S.reduce((Me,Ge)=>Me+(Ge.unit_price||0)*Ge.quantity_needed,0).toFixed(2)]})]})]}):s.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.bom.empty")})]})}),s.jsx(Nt,{children:s.jsxs(Mt,{className:"p-4",children:[s.jsx("div",{className:"flex items-center justify-between mb-3",children:s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(q0,{className:"w-5 h-5"}),n("projectDetail.timeline.title")]})}),k?s.jsx("div",{className:"flex items-center justify-center py-4",children:s.jsx(pt,{className:"w-6 h-6 animate-spin text-bambu-green"})}):T&&T.length>0?s.jsx("div",{className:"space-y-3",children:T.slice(0,10).map((Me,Ge)=>s.jsxs("div",{className:"flex gap-3",children:[s.jsxs("div",{className:`w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0 ${Me.event_type==="print_completed"?"bg-status-ok/20 text-status-ok":Me.event_type==="print_failed"?"bg-status-error/20 text-status-error":Me.event_type==="print_started"?"bg-yellow-500/20 text-yellow-400":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:[Me.event_type==="print_completed"&&s.jsx(Ar,{className:"w-4 h-4"}),Me.event_type==="print_failed"&&s.jsx(Qi,{className:"w-4 h-4"}),Me.event_type==="print_started"&&s.jsx(Pr,{className:"w-4 h-4"}),Me.event_type==="queued"&&s.jsx(pj,{className:"w-4 h-4"}),Me.event_type==="project_created"&&s.jsx(fr,{className:"w-4 h-4"})]}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm text-white",children:Me.title}),Me.description&&s.jsx("p",{className:"text-xs text-bambu-gray truncate",children:Me.description}),s.jsx("p",{className:"text-xs text-bambu-gray/70",children:Ie(Me.timestamp)})]})]},Ge))}):s.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.timeline.empty")})]})}),!m.is_template&&s.jsx("div",{className:"flex justify-end",children:s.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>rt.mutate(),disabled:rt.isPending||!a("projects:create"),title:a("projects:create")?void 0:n("projectDetail.template.noCreatePermission"),children:[rt.isPending?s.jsx(pt,{className:"w-4 h-4 animate-spin mr-2"}):s.jsx(Fl,{className:"w-4 h-4 mr-2"}),n("projectDetail.template.saveAsTemplate")]})}),be&&(be.queued_prints>0||be.in_progress_prints>0)&&s.jsx(Nt,{children:s.jsxs(Mt,{className:"p-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(pj,{className:"w-5 h-5"}),n("projectDetail.queue.title")]}),s.jsx(Ds,{to:`/queue?project=${p}`,className:"text-sm text-bambu-green hover:underline",children:n("projectDetail.queue.viewAll")})]}),s.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[be.in_progress_prints>0&&s.jsx("span",{className:"text-yellow-400",children:n("projectDetail.queue.printing",{count:be.in_progress_prints})}),be.queued_prints>0&&s.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.queue.queued",{count:be.queued_prints})})]})]})}),s.jsxs("div",{children:[s.jsx("div",{className:"flex items-center justify-between mb-4",children:s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(pc,{className:"w-5 h-5"}),n("projectDetail.prints.title",{count:v?.length||0})]})}),y?s.jsx("div",{className:"flex items-center justify-center py-8",children:s.jsx(pt,{className:"w-6 h-6 animate-spin text-bambu-green"})}):s.jsx(eXe,{archives:v||[],t:n})]}),o&&s.jsx($re,{t:n,project:{...m,archive_count:be?.total_archives||0,total_items:be?.total_items||0,completed_count:be?.completed_prints||0,failed_count:be?.failed_prints||0,queue_count:be?.queued_prints||0,progress_percent:be?.progress_percent||null,archives:[]},onClose:()=>l(!1),onSave:Me=>j.mutate(Me),isLoading:j.isPending}),fe.isOpen&&s.jsx(Jn,{title:fe.title,message:fe.message,confirmText:n("common.delete"),variant:"danger",onConfirm:fe.onConfirm,onCancel:()=>we(Me=>({...Me,isOpen:!1}))})]})}function hg(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:`${(t/(1024*1024*1024)).toFixed(2)} GB`}function iXe(t){if(!t)return"-";const e=Math.floor(t/3600),n=Math.floor(t%3600/60);return e>0?`${e}h ${n}m`:`${n}m`}function aXe({parentId:t,onClose:e,onSave:n,isLoading:r,t:i}){const[a,o]=_.useState(""),l=c=>{c.preventDefault(),n({name:a.trim(),parent_id:t})};return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[s.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:i("fileManager.newFolder")})}),s.jsxs("form",{onSubmit:l,className:"p-4 space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("fileManager.folderName")}),s.jsx("input",{type:"text",value:a,onChange:c=>o(c.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:i("fileManager.folderNamePlaceholder"),autoFocus:!0,required:!0})]}),s.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[s.jsx(Te,{type:"button",variant:"secondary",onClick:e,children:i("common.cancel")}),s.jsx(Te,{type:"submit",disabled:!a.trim()||r,children:r?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):i("common.create")})]})]})]})})}function sXe({type:t,currentName:e,onClose:n,onSave:r,isLoading:i,t:a}){const[o,l]=_.useState(e),c=u=>{u.preventDefault(),o.trim()&&o.trim()!==e&&r(o.trim())};return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[s.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:a(t==="file"?"fileManager.renameFile":"fileManager.renameFolder")})}),s.jsxs("form",{onSubmit:c,className:"p-4 space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("common.name")}),s.jsx("input",{type:"text",value:o,onChange:u=>l(u.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",autoFocus:!0,required:!0})]}),s.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[s.jsx(Te,{type:"button",variant:"secondary",onClick:n,children:a("common.cancel")}),s.jsx(Te,{type:"submit",disabled:!o.trim()||o.trim()===e||i,children:i?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):a("common.rename")})]})]})]})})}function oXe({folders:t,selectedFiles:e,currentFolderId:n,onClose:r,onMove:i,isLoading:a,t:o}){const[l,c]=_.useState(null),u=(f,p=0)=>{const m=[];for(const x of f)m.push({id:x.id,name:x.name,depth:p}),x.children.length>0&&m.push(...u(x.children,p+1));return m},d=[{id:null,name:o("fileManager.rootNoFolder"),depth:0},...u(t)];return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[s.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:o("fileManager.moveFiles",{count:e.length})})}),s.jsxs("div",{className:"p-4 space-y-4",children:[s.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1",children:d.map(f=>s.jsxs("button",{onClick:()=>c(f.id),disabled:f.id===n,className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===f.id?"bg-bambu-green/20 text-bambu-green":f.id===n?"opacity-50 cursor-not-allowed text-bambu-gray":"hover:bg-bambu-dark text-white"}`,style:{paddingLeft:`${12+f.depth*16}px`},children:[s.jsx(Il,{className:"w-4 h-4"}),f.name,f.id===n&&s.jsxs("span",{className:"text-xs text-bambu-gray ml-auto",children:["(",o("fileManager.current"),")"]})]},f.id??"root"))}),s.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[s.jsx(Te,{type:"button",variant:"secondary",onClick:r,children:o("common.cancel")}),s.jsx(Te,{onClick:()=>i(l),disabled:a,children:a?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):o("common.move")})]})]})]})})}function lXe({folder:t,onClose:e,onLink:n,isLoading:r,t:i}){const[a,o]=_.useState("project"),[l,c]=_.useState(t.project_id||t.archive_id||null);_.useState(()=>{t.archive_id&&o("archive")});const{data:u}=ot({queryKey:["projects"],queryFn:()=>ce.getProjects()}),{data:d}=ot({queryKey:["archives-for-link"],queryFn:()=>ce.getArchives(void 0,void 0,100)}),f=()=>{n(a==="project"?{project_id:l,archive_id:0}:{project_id:0,archive_id:l})},p=()=>{n({project_id:0,archive_id:0})},m=t.project_id||t.archive_id;return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(uc,{className:"w-5 h-5 text-bambu-green"}),i("fileManager.linkFolder")]}),s.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:s.jsx(Lt,{className:"w-5 h-5 text-bambu-gray"})})]}),s.jsxs("div",{className:"p-4 space-y-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:i("fileManager.linkFolderDescription",{name:t.name})}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs("button",{onClick:()=>{o("project"),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a==="project"?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,children:[s.jsx(bW,{className:"w-4 h-4"}),i("fileManager.project")]}),s.jsxs("button",{onClick:()=>{o("archive"),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a==="archive"?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,children:[s.jsx(ho,{className:"w-4 h-4"}),i("fileManager.archive")]})]}),s.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2",children:a==="project"?u&&u.length>0?u.map(x=>s.jsxs("button",{onClick:()=>c(x.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===x.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark-tertiary text-white"}`,children:[s.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:x.color||"#00ae42"}}),s.jsx("span",{className:"truncate",children:x.name})]},x.id)):s.jsx("p",{className:"text-sm text-bambu-gray text-center py-4",children:i("fileManager.noProjectsFound")}):d&&d.length>0?d.map(x=>s.jsxs("button",{onClick:()=>c(x.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===x.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark-tertiary text-white"}`,children:[s.jsx(Bf,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),s.jsx("span",{className:"truncate",children:x.print_name||x.filename})]},x.id)):s.jsx("p",{className:"text-sm text-bambu-gray text-center py-4",children:i("fileManager.noArchivesFound")})})]}),s.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-between",children:[m&&s.jsxs(Te,{variant:"danger",onClick:p,disabled:r,children:[s.jsx(RR,{className:"w-4 h-4 mr-2"}),i("fileManager.unlink")]}),s.jsxs("div",{className:`flex gap-2 ${m?"":"ml-auto"}`,children:[s.jsx(Te,{variant:"secondary",onClick:e,children:i("common.cancel")}),s.jsx(Te,{onClick:f,disabled:!l||r,children:r?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):i("fileManager.link")})]})]})]})})}function cXe({folderId:t,onClose:e,onUploadComplete:n,t:r}){const[i,a]=_.useState([]),[o,l]=_.useState(!1),[c,u]=_.useState(!1),[d,f]=_.useState(!0),[p,m]=_.useState(!1),[x,b]=_.useState(!0),v=_.useRef(null),y=z=>{z.preventDefault(),l(!0)},S=z=>{z.preventDefault(),l(!1)},M=z=>{z.preventDefault(),l(!1);const W=Array.from(z.dataTransfer.files);k(W)},T=z=>{z.target.files&&k(Array.from(z.target.files))},k=z=>{const W=z.map(V=>({file:V,status:"pending",isZip:V.name.toLowerCase().endsWith(".zip"),is3mf:V.name.toLowerCase().endsWith(".3mf")}));a(V=>[...V,...W])},C=z=>{a(W=>W.filter((V,X)=>X!==z))},E=i.some(z=>z.isZip&&z.status==="pending"),D=i.some(z=>z.file.name.toLowerCase().endsWith(".stl")&&z.status==="pending"),A=i.some(z=>z.is3mf&&z.status==="pending"),j=async()=>{if(i.length!==0){u(!0);for(let z=0;zW.map((V,X)=>X===z?{...V,status:"uploading"}:V));try{if(i[z].isZip){const W=await ce.extractZipFile(i[z].file,t,d,p,x);a(V=>V.map((X,Q)=>Q===z?{...X,status:W.errors.length>0&&W.extracted===0?"error":"success",extractedCount:W.extracted,error:W.errors.length>0?`${W.errors.length} files failed`:void 0}:X))}else await ce.uploadLibraryFile(i[z].file,t,x),a(W=>W.map((V,X)=>X===z?{...V,status:"success"}:V))}catch(W){a(V=>V.map((X,Q)=>Q===z?{...X,status:"error",error:W instanceof Error?W.message:"Upload failed"}:X))}}u(!1),n(),e()}},I=i.filter(z=>z.status==="pending").length,F=i.filter(z=>z.status==="success").length,H=i.filter(z=>z.status==="error").length,R=i.length>0&&I===0&&!c;return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-lg border border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[s.jsx("h2",{className:"text-lg font-semibold text-white",children:r("fileManager.uploadFiles")}),s.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:s.jsx(Lt,{className:"w-5 h-5 text-bambu-gray"})})]}),s.jsxs("div",{className:"p-4 space-y-4",children:[s.jsxs("div",{onDragOver:y,onDragLeave:S,onDrop:M,onClick:()=>v.current?.click(),className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${o?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,children:[s.jsx(za,{className:`w-10 h-10 mx-auto mb-3 ${o?"text-bambu-green":"text-bambu-gray"}`}),s.jsx("p",{className:"text-white font-medium",children:r(o?"fileManager.dropFilesHere":"fileManager.dragDropFiles")}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:r("fileManager.orClickToBrowse")}),s.jsx("p",{className:"text-xs text-bambu-gray/70 mt-2",children:r("fileManager.allFileTypesSupported")})]}),s.jsx("input",{ref:v,type:"file",multiple:!0,className:"hidden",onChange:T}),E&&s.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(ho,{className:"w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"text-sm text-blue-300 font-medium",children:r("fileManager.zipFilesDetected")}),s.jsx("p",{className:"text-xs text-blue-300/70 mt-1",children:r("fileManager.zipExtractOptions")}),s.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:d,onChange:z=>f(z.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),s.jsx("span",{className:"text-sm text-white",children:r("fileManager.preserveZipStructure")})]}),s.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:p,onChange:z=>m(z.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),s.jsx("span",{className:"text-sm text-white",children:r("fileManager.createFolderFromZip")})]})]})]})}),A&&s.jsx("div",{className:"p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg",children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(Pr,{className:"w-5 h-5 text-purple-400 mt-0.5 flex-shrink-0"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"text-sm text-purple-300 font-medium",children:r("fileManager.threemfDetected")}),s.jsx("p",{className:"text-xs text-purple-300/70 mt-1",children:r("fileManager.threemfExtractionInfo")})]})]})}),(D||E)&&s.jsx("div",{className:"p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(Lu,{className:"w-5 h-5 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"text-sm text-bambu-green font-medium",children:r("fileManager.stlThumbnailGeneration")}),s.jsx("p",{className:"text-xs text-bambu-green/70 mt-1",children:r(E&&!D?"fileManager.zipMayContainStl":"fileManager.thumbnailsCanBeGenerated")}),s.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:x,onChange:z=>b(z.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),s.jsx("span",{className:"text-sm text-white",children:r("fileManager.generateThumbnailsForStl")})]})]})]})}),i.length>0&&s.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:i.map((z,W)=>s.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[z.isZip?s.jsx(ho,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):s.jsx(uM,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm text-white truncate",children:z.file.name}),s.jsxs("p",{className:"text-xs text-bambu-gray",children:[(z.file.size/1024/1024).toFixed(2)," MB",z.isZip&&z.status==="pending"&&s.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",r("fileManager.willBeExtracted")]}),z.extractedCount!==void 0&&s.jsxs("span",{className:"text-green-400 ml-2",children:["• ",r("fileManager.filesExtracted",{count:z.extractedCount})]})]})]}),z.status==="pending"&&s.jsx("button",{onClick:()=>C(W),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:s.jsx(Lt,{className:"w-4 h-4 text-bambu-gray"})}),z.status==="uploading"&&s.jsx(pt,{className:"w-4 h-4 text-bambu-green animate-spin"}),z.status==="success"&&s.jsx(Ar,{className:"w-4 h-4 text-green-500"}),z.status==="error"&&s.jsx("span",{title:z.error,children:s.jsx(Qi,{className:"w-4 h-4 text-red-500"})})]},W))}),R&&s.jsx("div",{className:"p-3 bg-bambu-dark rounded-lg",children:s.jsxs("p",{className:"text-sm text-white",children:[r("fileManager.uploadComplete",{succeeded:F}),H>0&&s.jsxs("span",{className:"text-red-400",children:[", ",r("fileManager.uploadFailed",{count:H})]})]})})]}),s.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2",children:[s.jsx(Te,{variant:"secondary",onClick:e,children:r(R?"common.close":"common.cancel")}),!R&&s.jsx(Te,{onClick:j,disabled:I===0||c,children:c?s.jsxs(s.Fragment,{children:[s.jsx(pt,{className:"w-4 h-4 mr-2 animate-spin"}),r("fileManager.uploading")]}):s.jsxs(s.Fragment,{children:[s.jsx(za,{className:"w-4 h-4 mr-2"}),r("common.upload")," ",I>0?`(${I})`:""]})})]})]})})}function Vre({folder:t,selectedFolderId:e,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o=0,wrapNames:l=!1,hasPermission:c,t:u}){const[d,f]=_.useState(!0),[p,m]=_.useState(!1),x=t.children.length>0,b=t.project_id||t.archive_id;return s.jsxs("div",{children:[s.jsxs("div",{className:`group flex items-center gap-1 px-2 py-1.5 rounded cursor-pointer transition-colors ${e===t.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark text-white"}`,style:{paddingLeft:`${8+o*12}px`},onClick:()=>n(t.id),children:[x?s.jsx("button",{onClick:v=>{v.stopPropagation(),f(!d)},className:"p-0.5 hover:bg-bambu-dark-tertiary rounded",children:s.jsx(gs,{className:`w-3.5 h-3.5 transition-transform ${d?"rotate-90":""}`})}):s.jsx("div",{className:"w-4.5"}),s.jsx(Il,{className:"w-4 h-4 text-bambu-green flex-shrink-0"}),s.jsx("span",{className:`text-sm flex-1 min-w-0 ${l?"break-all":"truncate"}`,title:t.name,children:t.name}),b&&s.jsxs("button",{onClick:v=>{v.stopPropagation(),i(t)},className:"flex-shrink-0 flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400 hover:bg-blue-500/30 transition-colors",title:`${t.project_name?`Project: ${t.project_name}`:`Archive: ${t.archive_name}`} (click to change)`,children:[s.jsx(uc,{className:"w-3 h-3"}),t.project_name?s.jsx(bW,{className:"w-3 h-3"}):s.jsx(ho,{className:"w-3 h-3"})]}),t.file_count>0&&s.jsx("span",{className:"flex-shrink-0 text-xs text-bambu-gray",children:t.file_count}),!b&&s.jsx("button",{onClick:v=>{v.stopPropagation(),i(t)},className:"flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary",title:u("fileManager.linkToProjectOrArchive"),children:s.jsx(uc,{className:"w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green"})}),s.jsx("div",{className:`flex-shrink-0 flex items-center gap-0.5 transition-opacity ${l?"":"opacity-0 group-hover:opacity-100"}`,onClick:v=>v.stopPropagation(),children:s.jsxs("div",{className:"relative",children:[s.jsx("button",{onClick:()=>m(!p),className:"p-1 rounded hover:bg-bambu-dark-tertiary",children:s.jsx(sh,{className:"w-3.5 h-3.5 text-bambu-gray"})}),p&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>m(!1)}),s.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]",children:[s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:update_all")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:update_all")&&(a(t),m(!1))},disabled:!c("library:update_all"),title:c("library:update_all")?void 0:u("fileManager.noPermissionRenameFolder"),children:[s.jsx(Zi,{className:"w-3.5 h-3.5"}),u("common.rename")]}),s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:update_all")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:update_all")&&(i(t),m(!1))},disabled:!c("library:update_all"),title:c("library:update_all")?void 0:u("fileManager.noPermissionLinkFolder"),children:[s.jsx(uc,{className:"w-3.5 h-3.5"}),u(b?"fileManager.changeLink":"fileManager.linkTo")]}),s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:delete_all")?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:delete_all")&&(r(t.id),m(!1))},disabled:!c("library:delete_all"),title:c("library:delete_all")?void 0:u("fileManager.noPermissionDeleteFolder"),children:[s.jsx(on,{className:"w-3.5 h-3.5"}),u("common.delete")]})]})]})]})})]}),x&&d&&s.jsx("div",{children:t.children.map(v=>s.jsx(Vre,{folder:v,selectedFolderId:e,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o+1,wrapNames:l,hasPermission:c,t:u},v.id))})]})}function hR(t){const e=t.toLowerCase();return e.endsWith(".gcode")||e.includes(".gcode.")}function uXe({file:t,isSelected:e,isMobile:n,onSelect:r,onDelete:i,onDownload:a,onAddToQueue:o,onPrint:l,onRename:c,onGenerateThumbnail:u,thumbnailVersion:d,hasPermission:f,canModify:p,authEnabled:m,t:x}){const[b,v]=_.useState(!1);return s.jsxs("div",{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer overflow-hidden ${e?"border-bambu-green ring-1 ring-bambu-green":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,onClick:()=>r(t.id),children:[s.jsxs("div",{className:"aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden",children:[t.thumbnail_path?s.jsx("img",{src:`${ce.getLibraryFileThumbnailUrl(t.id)}${d?`?v=${d}`:""}`,alt:t.filename,className:"w-full h-full object-cover"}):s.jsx(Bf,{className:"w-12 h-12 text-bambu-gray/30"}),s.jsx("div",{className:`absolute top-2 right-2 text-xs px-1.5 py-0.5 rounded font-medium ${t.file_type==="3mf"?"bg-bambu-green/90 text-white":t.file_type==="gcode"?"bg-blue-500/90 text-white":t.file_type==="stl"?"bg-purple-500/90 text-white":"bg-bambu-gray/90 text-white"}`,children:t.file_type.toUpperCase()})]}),s.jsxs("div",{className:"p-3",children:[s.jsx("h3",{className:"text-sm font-medium text-white truncate",title:t.print_name||t.filename,children:t.print_name||t.filename}),s.jsxs("div",{className:"flex items-center gap-3 mt-1 text-xs text-bambu-gray",children:[s.jsx("span",{children:hg(t.file_size)}),t.print_time_seconds&&s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(nr,{className:"w-3 h-3"}),iXe(t.print_time_seconds)]})]}),t.sliced_for_model&&s.jsxs("div",{className:"mt-1 text-xs text-bambu-gray flex items-center gap-1",children:[s.jsx(Pr,{className:"w-3 h-3"}),t.sliced_for_model]}),t.print_count>0&&s.jsx("div",{className:"mt-1 text-xs text-bambu-green",children:x("fileManager.printedCount",{count:t.print_count})}),m&&t.created_by_username&&s.jsxs("div",{className:"mt-1 text-xs text-bambu-gray flex items-center gap-1",children:[s.jsx(Fu,{className:"w-3 h-3"}),t.created_by_username]})]}),s.jsxs("div",{className:`absolute bottom-2 right-2 transition-opacity ${n?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:y=>y.stopPropagation(),children:[s.jsx("button",{onClick:()=>v(!b),className:"p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary",children:s.jsx(sh,{className:"w-4 h-4 text-bambu-gray"})}),b&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>v(!1)}),s.jsxs("div",{className:"absolute right-0 bottom-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[140px]",children:[l&&hR(t.filename)&&s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("printers:control")?"text-bambu-green hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("printers:control")&&(l(t),v(!1))},disabled:!f("printers:control"),title:f("printers:control")?void 0:x("fileManager.noPermissionPrint"),children:[s.jsx(Pr,{className:"w-3.5 h-3.5"}),x("common.print")]}),o&&hR(t.filename)&&s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("queue:create")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("queue:create")&&(o(t.id),v(!1))},disabled:!f("queue:create"),title:f("queue:create")?void 0:x("fileManager.noPermissionAddToQueue"),children:[s.jsx(nr,{className:"w-3.5 h-3.5"}),x("fileManager.schedulePrint")]}),s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("library:read")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("library:read")&&(a(t.id),v(!1))},disabled:!f("library:read"),title:f("library:read")?void 0:x("fileManager.noPermissionDownload"),children:[s.jsx(wi,{className:"w-3.5 h-3.5"}),x("common.download")]}),c&&s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("library","update",t.created_by_id)?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("library","update",t.created_by_id)&&(c(t),v(!1))},disabled:!p("library","update",t.created_by_id),title:p("library","update",t.created_by_id)?void 0:x("fileManager.noPermissionRenameFile"),children:[s.jsx(Zi,{className:"w-3.5 h-3.5"}),x("common.rename")]}),u&&t.file_type==="stl"&&s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("library","update",t.created_by_id)?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("library","update",t.created_by_id)&&(u(t),v(!1))},disabled:!p("library","update",t.created_by_id),title:p("library","update",t.created_by_id)?void 0:x("fileManager.noPermissionGenerateThumbnail"),children:[s.jsx(Lu,{className:"w-3.5 h-3.5"}),x("fileManager.generateThumbnail")]}),s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("library","delete",t.created_by_id)?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("library","delete",t.created_by_id)&&(i(t.id),v(!1))},disabled:!p("library","delete",t.created_by_id),title:p("library","delete",t.created_by_id)?void 0:x("fileManager.noPermissionDeleteFile"),children:[s.jsx(on,{className:"w-3.5 h-3.5"}),x("common.delete")]})]})]})]}),s.jsx("div",{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${e?"bg-bambu-green border-bambu-green":`border-white/30 bg-black/30 ${n?"opacity-100":"opacity-0 group-hover:opacity-100"}`}`,children:e&&s.jsx("div",{className:"w-2 h-2 bg-white rounded-sm"})})]})}function dXe(){const{t}=On(),e=ln(),{showToast:n}=Vn(),{hasPermission:r,hasAnyPermission:i,canModify:a,authEnabled:o}=Ci(),[l]=wR(),c=l.get("folder"),u=c?parseInt(c,10):null,[d,f]=_.useState(u),[p,m]=_.useState([]),[x,b]=_.useState(!1),[v,y]=_.useState(!1),[S,M]=_.useState(!1),[T,k]=_.useState(null),[C,E]=_.useState(null),[D,A]=_.useState(null),[j,I]=_.useState(null),[F,H]=_.useState(null),[R,z]=_.useState(null),[W,V]=_.useState({}),[X,Q]=_.useState(()=>localStorage.getItem("library-view-mode")||"grid"),[ae,$]=_.useState(()=>localStorage.getItem("library-wrap-folders")==="true"),[K,ie]=_.useState(()=>{const Re=localStorage.getItem("library-sidebar-width");return Re?parseInt(Re,10):256}),[re,xe]=_.useState(!1),pe=_.useRef(null);_.useEffect(()=>{if(!re)return;document.body.style.userSelect="none",document.body.style.cursor="col-resize";const Re=It=>{if(!pe.current)return;const Ht=pe.current.parentElement?.getBoundingClientRect();if(!Ht)return;const Nn=It.clientX-Ht.left,Ln=Math.min(500,Math.max(200,Nn));ie(Ln)},ct=()=>{xe(!1),document.body.style.userSelect="",document.body.style.cursor="",localStorage.setItem("library-sidebar-width",String(K))};return document.addEventListener("mousemove",Re),document.addEventListener("mouseup",ct),()=>{document.removeEventListener("mousemove",Re),document.removeEventListener("mouseup",ct),document.body.style.userSelect="",document.body.style.cursor=""}},[re,K]);const[ue,Pe]=_.useState(""),[te,Ee]=_.useState("all"),[Oe,me]=_.useState(""),[Xe,G]=_.useState(()=>localStorage.getItem("library-sort-field")||"name"),[Y,de]=_.useState(()=>localStorage.getItem("library-sort-direction")||"asc"),q=IR();_.useEffect(()=>{const Re=l.get("folder");if(Re){const ct=parseInt(Re,10);f(ct)}},[l]);const{data:ee}=ot({queryKey:["settings"],queryFn:()=>ce.getSettings()}),{data:U,isLoading:fe}=ot({queryKey:["library-folders"],queryFn:()=>ce.getLibraryFolders()}),{data:we,isLoading:ge}=ot({queryKey:["library-files",d],queryFn:()=>ce.getLibraryFiles(d,d===null)}),{data:B}=ot({queryKey:["library-stats"],queryFn:()=>ce.getLibraryStats()}),{data:O}=ot({queryKey:["users"],queryFn:()=>ce.getUsers()}),J=_.useMemo(()=>{if(!we)return[];const Re=new Set(we.map(ct=>ct.file_type));return Array.from(Re).sort()},[we]),se=_.useMemo(()=>{if(!we)return[];let Re=[...we];if(ue.trim()){const ct=ue.toLowerCase();Re=Re.filter(It=>It.filename.toLowerCase().includes(ct)||It.print_name&&It.print_name.toLowerCase().includes(ct))}if(te!=="all"&&(Re=Re.filter(ct=>ct.file_type===te)),Oe.trim()){const ct=Oe.toLowerCase();Re=Re.filter(It=>It.created_by_username&&It.created_by_username.toLowerCase().includes(ct))}return Re.sort((ct,It)=>{let Ht=0;switch(Xe){case"name":Ht=(ct.print_name||ct.filename).localeCompare(It.print_name||It.filename);break;case"date":Ht=new Date(ct.created_at).getTime()-new Date(It.created_at).getTime();break;case"size":Ht=ct.file_size-It.file_size;break;case"type":Ht=ct.file_type.localeCompare(It.file_type);break;case"prints":Ht=ct.print_count-It.print_count;break}return Y==="asc"?Ht:-Ht}),Re},[we,ue,te,Oe,Xe,Y]),ve=_.useMemo(()=>{if(!B||!ee)return!1;const Re=(ee.library_disk_warning_gb||5)*1024*1024*1024;return B.disk_free_bytesce.createLibraryFolder(Re),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),b(!1),n(t("fileManager.toast.folderCreated"),"success")},onError:Re=>n(Re.message,"error")}),ne=gt({mutationFn:Re=>ce.deleteLibraryFolder(Re),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-stats"]}),d===C?.id&&f(null),E(null),n(t("fileManager.toast.folderDeleted"),"success")},onError:Re=>{E(null),n(Re.message,"error")}}),Fe=gt({mutationFn:Re=>ce.deleteLibraryFile(Re),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]}),m(Re=>Re.filter(ct=>ct!==C?.id)),E(null),n(t("fileManager.toast.fileDeleted"),"success")},onError:Re=>{E(null),n(Re.message,"error")}}),He=gt({mutationFn:Re=>ce.bulkDeleteLibrary(Re,[]),onSuccess:(Re,ct)=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]}),n(t("fileManager.toast.filesDeleted",{count:ct.length}),"success"),m([]),E(null)},onError:Re=>{E(null),n(Re.message,"error")}}),rt=gt({mutationFn:({fileIds:Re,folderId:ct})=>ce.moveLibraryFiles(Re,ct),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),m([]),y(!1),n(t("fileManager.toast.filesMoved"),"success")},onError:Re=>n(Re.message,"error")}),Ie=gt({mutationFn:({id:Re,data:ct})=>ce.updateLibraryFolder(Re,ct),onSuccess:(Re,ct)=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["project-folders"]}),e.invalidateQueries({queryKey:["archive-folders"]}),k(null);const It=ct.data.project_id===0&&ct.data.archive_id===0;n(t(It?"fileManager.toast.folderUnlinked":"fileManager.toast.folderLinked"),"success")},onError:Re=>n(Re.message,"error")}),be=gt({mutationFn:({id:Re,filename:ct})=>ce.updateLibraryFile(Re,{filename:ct}),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),z(null),n(t("fileManager.toast.fileRenamed"),"success")},onError:Re=>{z(null),n(Re.message,"error")}}),Ae=gt({mutationFn:({id:Re,name:ct})=>ce.updateLibraryFolder(Re,{name:ct}),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-files"]}),z(null),n(t("fileManager.toast.folderRenamed"),"success")},onError:Re=>{z(null),n(Re.message,"error")}}),Ue=gt({mutationFn:()=>ce.batchGenerateStlThumbnails({all_missing:!0}),onSuccess:Re=>{if(e.invalidateQueries({queryKey:["library-files"]}),Re.succeeded>0){const ct=Date.now(),It={};Re.results.forEach(Ht=>{Ht.success&&(It[Ht.file_id]=ct)}),V(Ht=>({...Ht,...It}))}Re.succeeded>0&&Re.failed===0?n(t("fileManager.toast.thumbnailsGenerated",{count:Re.succeeded}),"success"):Re.succeeded>0&&Re.failed>0?n(t("fileManager.toast.thumbnailsGeneratedPartial",{succeeded:Re.succeeded,failed:Re.failed}),"success"):Re.processed===0?n(t("fileManager.toast.noStlMissingThumbnails"),"info"):n(t("fileManager.toast.failedToGenerateThumbnails",{error:Re.results[0]?.error||"Unknown error"}),"error")},onError:Re=>n(Re.message,"error")}),Me=gt({mutationFn:Re=>ce.batchGenerateStlThumbnails({file_ids:[Re]}),onSuccess:Re=>{if(e.invalidateQueries({queryKey:["library-files"]}),Re.succeeded>0){const ct=Re.results[0]?.file_id;ct&&V(It=>({...It,[ct]:Date.now()})),n(t("fileManager.toast.thumbnailGenerated"),"success")}else n(t("fileManager.toast.failedToGenerateThumbnail",{error:Re.results[0]?.error||"Unknown error"}),"error")},onError:Re=>n(Re.message,"error")}),Ge=_.useCallback(Re=>{const ct=Re.toLowerCase();return ct.endsWith(".gcode")||ct.includes(".gcode.")},[]),Ne=_.useMemo(()=>we?we.filter(Re=>p.includes(Re.id)&&Ge(Re.filename)):[],[we,p,Ge]),nt=_.useCallback(Re=>{m(ct=>ct.includes(Re)?ct.filter(It=>It!==Re):[...ct,Re])},[]),ke=_.useCallback(()=>{se.length>0&&m(se.map(Re=>Re.id))},[se]),Ke=_.useCallback(()=>{m([])},[]),Be=()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]})},le=Re=>{ce.downloadLibraryFile(Re).catch(ct=>{console.error("Library file download failed:",ct)})},$e=()=>{C&&(C.type==="file"?Fe.mutate(C.id):C.type==="folder"?ne.mutate(C.id):C.type==="bulk"&&He.mutate(p))},it=ne.isPending||Fe.isPending||He.isPending,kt=Re=>{Q(Re),localStorage.setItem("library-view-mode",Re)},bt=fe||ge;return s.jsxs("div",{className:"p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-[calc(100vh-64px)] flex flex-col",children:[s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6",children:[s.jsxs("div",{children:[s.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[s.jsx("div",{className:"p-2.5 bg-bambu-green/10 rounded-xl",children:s.jsx(Il,{className:"w-6 h-6 text-bambu-green"})}),t("fileManager.title")]}),s.jsx("p",{className:"text-sm text-bambu-gray mt-2 ml-14",children:t("fileManager.subtitle")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"flex items-center bg-bambu-dark rounded-lg p-1",children:[s.jsx("button",{onClick:()=>kt("grid"),className:`p-1.5 rounded transition-colors ${X==="grid"?"bg-bambu-dark-secondary text-white":"text-bambu-gray hover:text-white"}`,title:t("fileManager.gridView"),children:s.jsx(mM,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>kt("list"),className:`p-1.5 rounded transition-colors ${X==="list"?"bg-bambu-dark-secondary text-white":"text-bambu-gray hover:text-white"}`,title:t("fileManager.listView"),children:s.jsx(pM,{className:"w-4 h-4"})})]}),s.jsxs(Te,{variant:"secondary",onClick:()=>Ue.mutate(),disabled:Ue.isPending||!i("library:update_own","library:update_all"),title:i("library:update_own","library:update_all")?t("fileManager.generateThumbnailsForMissing"):t("fileManager.noPermissionGenerateThumbnail"),children:[Ue.isPending?s.jsx(pt,{className:"w-4 h-4 mr-2 animate-spin"}):s.jsx(Lu,{className:"w-4 h-4 mr-2"}),t("fileManager.generateThumbnails")]}),s.jsxs(Te,{variant:"secondary",onClick:()=>b(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionCreateFolder"),children:[s.jsx(Hue,{className:"w-4 h-4 mr-2"}),t("fileManager.newFolder")]}),s.jsxs(Te,{onClick:()=>M(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionUpload"),children:[s.jsx(za,{className:"w-4 h-4 mr-2"}),t("common.upload")]})]})]}),ve&&B&&ee&&s.jsxs("div",{className:"flex items-center gap-3 mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg",children:[s.jsx(Sn,{className:"w-5 h-5 text-amber-500 flex-shrink-0"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"text-sm text-amber-500 font-medium",children:t("fileManager.lowDiskSpaceWarning")}),s.jsx("p",{className:"text-xs text-amber-500/80",children:t("fileManager.lowDiskSpaceDetails",{free:hg(B.disk_free_bytes),total:hg(B.disk_total_bytes),threshold:ee.library_disk_warning_gb})})]})]}),B&&s.jsxs("div",{className:"flex flex-wrap items-center gap-3 sm:gap-6 mb-6 p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsx(uM,{className:"w-4 h-4 text-bambu-green"}),s.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.files"),":"]}),s.jsx("span",{className:"text-white font-medium",children:B.total_files})]}),s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsx(Il,{className:"w-4 h-4 text-blue-400"}),s.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.folders"),":"]}),s.jsx("span",{className:"text-white font-medium",children:B.total_folders})]}),s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsx(fM,{className:"w-4 h-4 text-amber-400"}),s.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.size"),":"]}),s.jsx("span",{className:"text-white font-medium",children:hg(B.total_size_bytes)})]}),s.jsxs("div",{className:"flex items-center gap-2 text-sm sm:ml-auto",children:[s.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.free"),":"]}),s.jsx("span",{className:`font-medium ${ve?"text-amber-500":"text-white"}`,children:hg(B.disk_free_bytes)})]})]}),s.jsxs("div",{className:"flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0",children:[s.jsx("div",{className:"lg:hidden",children:s.jsxs("select",{value:d??"",onChange:Re=>f(Re.target.value?parseInt(Re.target.value,10):null),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg px-3 py-2.5 text-white focus:outline-none focus:border-bambu-green",children:[s.jsxs("option",{value:"",children:["📁 ",t("fileManager.allFiles")]}),U&&(()=>{const Re=(ct,It=0)=>{const Ht=[];for(const Nn of ct)Ht.push({id:Nn.id,name:Nn.name,fileCount:Nn.file_count,depth:It}),Nn.children.length>0&&Ht.push(...Re(Nn.children,It+1));return Ht};return Re(U).map(ct=>s.jsxs("option",{value:ct.id,children:["│ ".repeat(ct.depth),"📂 ",ct.name," ",ct.fileCount>0?`(${ct.fileCount})`:""]},ct.id))})()]})}),s.jsxs("div",{ref:pe,className:"hidden lg:flex flex-shrink-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden flex-col relative",style:{width:`${K}px`},children:[s.jsx("div",{className:`absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group/resize flex items-center justify-center transition-colors ${re?"bg-bambu-green":"hover:bg-bambu-green/50"}`,onMouseDown:Re=>{Re.preventDefault(),xe(!0)},onDoubleClick:()=>{ie(256),localStorage.setItem("library-sidebar-width","256")},title:t("fileManager.dragToResizeTooltip"),children:s.jsxs("div",{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${re?"opacity-100":""}`,children:[s.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"}),s.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"}),s.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"})]})}),s.jsxs("div",{className:"p-3 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[s.jsx("h2",{className:"text-sm font-medium text-white",children:t("fileManager.folders")}),s.jsx("button",{onClick:()=>{const Re=!ae;$(Re),localStorage.setItem("library-wrap-folders",String(Re))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${ae?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:text-white hover:bg-bambu-dark"}`,title:t(ae?"fileManager.disableTextWrapping":"fileManager.enableTextWrapping"),children:t("fileManager.wrap")})]}),s.jsxs("div",{className:"flex-1 overflow-y-auto p-2",children:[s.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${d===null?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark text-white"}`,onClick:()=>f(null),children:[s.jsx(Bf,{className:"w-4 h-4"}),s.jsx("span",{className:"text-sm",children:t("fileManager.allFiles")})]}),U?.map(Re=>s.jsx(Vre,{folder:Re,selectedFolderId:d,onSelect:f,onDelete:ct=>E({type:"folder",id:ct}),onLink:k,onRename:ct=>z({type:"folder",id:ct.id,name:ct.name}),wrapNames:ae,hasPermission:r,t},Re.id))]})]}),s.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[we&&we.length>0&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3 mb-4 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-0 z-10 lg:static",children:[s.jsxs("div",{className:"relative w-full sm:w-auto sm:flex-1 sm:max-w-xs",children:[s.jsx(ya,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),s.jsx("input",{type:"text",placeholder:t("fileManager.searchFiles"),value:ue,onChange:Re=>Pe(Re.target.value),className:"w-full pl-9 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(dM,{className:"w-4 h-4 text-bambu-gray hidden sm:block"}),s.jsxs("select",{value:te,onChange:Re=>Ee(Re.target.value),className:"bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green",children:[s.jsx("option",{value:"all",children:t("fileManager.allTypes")}),J.map(Re=>s.jsx("option",{value:Re,children:Re.toUpperCase()},Re))]})]}),o&&s.jsxs("div",{className:"relative",children:[s.jsx("input",{type:"text",placeholder:t("fileManager.filterByUser",{defaultValue:"Filter by user"}),value:Oe,onChange:Re=>me(Re.target.value),list:"usernames-list",className:`w-32 sm:w-40 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green ${Oe?"pr-7":""}`,style:Oe?{WebkitAppearance:"none",MozAppearance:"textfield"}:void 0}),Oe&&s.jsx("button",{onClick:()=>me(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10",children:s.jsx(Lt,{className:"w-3 h-3"})}),s.jsx("datalist",{id:"usernames-list",children:O?.map(Re=>s.jsx("option",{value:Re.username},Re.id))})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("select",{value:Xe,onChange:Re=>{const ct=Re.target.value;G(ct),localStorage.setItem("library-sort-field",ct)},className:"bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green",children:[s.jsx("option",{value:"name",children:t("common.name")}),s.jsx("option",{value:"date",children:t("common.date")}),s.jsx("option",{value:"size",children:t("fileManager.size")}),s.jsx("option",{value:"type",children:t("common.type")}),s.jsx("option",{value:"prints",children:t("fileManager.prints")})]}),s.jsx("button",{onClick:()=>de(Re=>{const ct=Re==="asc"?"desc":"asc";return localStorage.setItem("library-sort-direction",ct),ct}),className:"p-1.5 rounded bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors",title:t(Y==="asc"?"fileManager.ascending":"fileManager.descending"),children:Y==="asc"?s.jsx(bce,{className:"w-4 h-4 text-white"}):s.jsx(uce,{className:"w-4 h-4 text-white"})})]}),(ue||te!=="all"||Oe)&&s.jsx("span",{className:"text-sm text-bambu-gray hidden sm:inline",children:t("fileManager.resultsCount",{showing:se.length,total:we.length})})]}),se.length>0&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4 p-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-[52px] z-10 lg:static",children:[p.length===se.length&&p.length>0?s.jsxs(Te,{variant:"secondary",size:"sm",onClick:Ke,children:[s.jsx(ll,{className:"w-4 h-4 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:t("fileManager.deselectAll")})]}):s.jsxs(Te,{variant:"secondary",size:"sm",onClick:ke,children:[s.jsx(ol,{className:"w-4 h-4 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:t("fileManager.selectAll")})]}),p.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-sm text-bambu-gray ml-2",children:t("fileManager.selected",{count:p.length})}),s.jsx("div",{className:"hidden sm:block flex-1"}),s.jsxs("div",{className:"w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0",children:[Ne.length===1&&s.jsxs(Te,{variant:"primary",size:"sm",onClick:()=>I(Ne[0]),disabled:!r("printers:control"),title:r("printers:control")?void 0:t("fileManager.noPermissionPrint"),children:[s.jsx(bo,{className:"w-4 h-4 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:t("common.print")})]}),Ne.length>0&&s.jsxs(Te,{variant:Ne.length===1?"secondary":"primary",size:"sm",onClick:()=>H(Ne[0]),disabled:!r("queue:create"),title:r("queue:create")?void 0:t("fileManager.noPermissionAddToQueue"),children:[s.jsx(nr,{className:"w-4 h-4 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:`${t("fileManager.schedulePrint")}${Ne.lengthy(!0),disabled:!i("library:update_own","library:update_all"),title:i("library:update_own","library:update_all")?void 0:t("fileManager.noPermissionMoveFiles"),children:[s.jsx(Yde,{className:"w-4 h-4 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:t("common.move")})]}),s.jsxs(Te,{variant:"danger",size:"sm",onClick:()=>{p.length===1?E({type:"file",id:p[0]}):E({type:"bulk",id:0,count:p.length})},disabled:!i("library:delete_own","library:delete_all"),title:i("library:delete_own","library:delete_all")?void 0:t("fileManager.noPermissionDeleteFiles"),children:[s.jsx(on,{className:"w-4 h-4 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:t("common.delete")})]}),s.jsxs(Te,{variant:"secondary",size:"sm",onClick:Ke,children:[s.jsx(Lt,{className:"w-4 h-4 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:t("common.clear")})]})]})]})]}),bt?s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsxs("div",{className:"flex flex-col items-center gap-3",children:[s.jsx(pt,{className:"w-8 h-8 animate-spin text-bambu-green"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:t("fileManager.loadingFiles")})]})}):we?.length===0?s.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center",children:[s.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:s.jsx(Bf,{className:"w-12 h-12 text-bambu-gray/50"})}),s.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:t(d!==null?"fileManager.folderIsEmpty":"fileManager.noFilesYet")}),s.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:t(d!==null?"fileManager.folderEmptyDescription":"fileManager.noFilesDescription")}),s.jsxs(Te,{onClick:()=>M(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionUpload"),children:[s.jsx(fr,{className:"w-4 h-4 mr-2"}),t("fileManager.uploadFiles")]})]}):se.length===0?s.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center",children:[s.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:s.jsx(ya,{className:"w-12 h-12 text-bambu-gray/50"})}),s.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:t("fileManager.noMatchingFiles")}),s.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:t("fileManager.noMatchingFilesDescription")}),s.jsx(Te,{variant:"secondary",onClick:()=>{Pe(""),Ee("all")},children:t("fileManager.clearFilters")})]}):X==="grid"?s.jsx("div",{className:"flex-1 lg:overflow-y-auto",children:s.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4",children:se.map(Re=>s.jsx(uXe,{file:Re,isSelected:p.includes(Re.id),isMobile:q,t,onSelect:nt,onDelete:ct=>E({type:"file",id:ct}),onDownload:le,onAddToQueue:ct=>{const It=we?.find(Ht=>Ht.id===ct);It&&H(It)},onPrint:A,onRename:ct=>z({type:"file",id:ct.id,name:ct.filename}),onGenerateThumbnail:ct=>Me.mutate(ct.id),thumbnailVersion:W[Re.id],hasPermission:r,canModify:a,authEnabled:o},Re.id))})}):s.jsx("div",{className:"flex-1 lg:overflow-y-auto",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden",children:[s.jsxs("div",{className:`hidden sm:grid ${o?"grid-cols-[auto_1fr_120px_100px_100px_100px_80px]":"grid-cols-[auto_1fr_100px_100px_100px_80px]"} gap-4 px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary text-xs text-bambu-gray font-medium`,children:[s.jsx("div",{className:"w-6"}),s.jsx("div",{children:t("common.name")}),o&&s.jsx("div",{children:t("fileManager.uploadedBy",{defaultValue:"Uploaded By"})}),s.jsx("div",{children:t("common.type")}),s.jsx("div",{children:t("fileManager.size")}),s.jsx("div",{children:t("fileManager.prints")}),s.jsx("div",{})]}),se.map(Re=>s.jsxs("div",{className:`grid ${o?"grid-cols-[auto_1fr_120px_100px_100px_100px_80px]":"grid-cols-[auto_1fr_100px_100px_100px_80px]"} gap-4 px-4 py-3 items-center border-b border-bambu-dark-tertiary last:border-b-0 cursor-pointer hover:bg-bambu-dark/50 transition-colors ${p.includes(Re.id)?"bg-bambu-green/10":""}`,onClick:()=>nt(Re.id),children:[s.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${p.includes(Re.id)?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:p.includes(Re.id)&&s.jsx("div",{className:"w-2 h-2 bg-white rounded-sm"})}),s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[s.jsxs("div",{className:"relative group/thumb",children:[s.jsx("div",{className:"w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden",children:Re.thumbnail_path?s.jsx("img",{src:`${ce.getLibraryFileThumbnailUrl(Re.id)}${W[Re.id]?`?v=${W[Re.id]}`:""}`,alt:"",className:"w-full h-full object-cover"}):s.jsx("div",{className:"w-full h-full flex items-center justify-center",children:s.jsx(Bf,{className:"w-5 h-5 text-bambu-gray/50"})})}),Re.thumbnail_path&&s.jsx("div",{className:"absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block",children:s.jsx("div",{className:"w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden",children:s.jsx("img",{src:`${ce.getLibraryFileThumbnailUrl(Re.id)}${W[Re.id]?`?v=${W[Re.id]}`:""}`,alt:Re.filename,className:"w-full h-full object-contain"})})})]}),s.jsx("div",{className:"min-w-0",children:s.jsx("div",{className:"text-sm text-white truncate",children:Re.print_name||Re.filename})})]}),o&&s.jsx("div",{className:"text-sm text-bambu-gray flex items-center gap-1",children:Re.created_by_username?s.jsxs(s.Fragment,{children:[s.jsx(Fu,{className:"w-3 h-3"}),s.jsx("span",{className:"truncate",children:Re.created_by_username})]}):"-"}),s.jsx("div",{children:s.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded font-medium ${Re.file_type==="3mf"?"bg-bambu-green/20 text-bambu-green":Re.file_type==="gcode"?"bg-blue-500/20 text-blue-400":Re.file_type==="stl"?"bg-purple-500/20 text-purple-400":"bg-bambu-gray/20 text-bambu-gray"}`,children:Re.file_type.toUpperCase()})}),s.jsx("div",{className:"text-sm text-bambu-gray",children:hg(Re.file_size)}),s.jsx("div",{className:"text-sm text-bambu-gray",children:Re.print_count>0?`${Re.print_count}x`:"-"}),s.jsxs("div",{className:"flex items-center gap-1",onClick:ct=>ct.stopPropagation(),children:[hR(Re.filename)&&s.jsxs(s.Fragment,{children:[s.jsx("button",{onClick:()=>r("printers:control")&&A(Re),className:`p-1.5 rounded transition-colors ${r("printers:control")?"hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("printers:control")?t("common.print"):t("fileManager.noPermissionPrint"),disabled:!r("printers:control"),children:s.jsx(Pr,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>{r("queue:create")&&H(Re)},className:`p-1.5 rounded transition-colors ${r("queue:create")?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("queue:create")?t("fileManager.schedulePrint"):t("fileManager.noPermissionAddToQueue"),disabled:!r("queue:create"),children:s.jsx(nr,{className:"w-4 h-4"})})]}),s.jsx("button",{onClick:()=>r("library:read")&&le(Re.id),className:`p-1.5 rounded transition-colors ${r("library:read")?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("library:read")?t("common.download"):t("fileManager.noPermissionDownload"),disabled:!r("library:read"),children:s.jsx(wi,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>a("library","update",Re.created_by_id)&&z({type:"file",id:Re.id,name:Re.filename}),className:`p-1.5 rounded transition-colors ${a("library","update",Re.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:a("library","update",Re.created_by_id)?t("common.rename"):t("fileManager.noPermissionRenameFile"),disabled:!a("library","update",Re.created_by_id),children:s.jsx(Zi,{className:"w-4 h-4"})}),Re.file_type==="stl"&&s.jsx("button",{onClick:()=>a("library","update",Re.created_by_id)&&Me.mutate(Re.id),className:`p-1.5 rounded transition-colors ${a("library","update",Re.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green":"text-bambu-gray/50 cursor-not-allowed"}`,title:a("library","update",Re.created_by_id)?t("fileManager.generateThumbnail"):t("fileManager.noPermissionGenerateThumbnail"),disabled:Me.isPending||!a("library","update",Re.created_by_id),children:s.jsx(Lu,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>a("library","delete",Re.created_by_id)&&E({type:"file",id:Re.id}),className:`p-1.5 rounded transition-colors ${a("library","delete",Re.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-red-400":"text-bambu-gray/50 cursor-not-allowed"}`,title:a("library","delete",Re.created_by_id)?t("common.delete"):t("fileManager.noPermissionDeleteFile"),disabled:!a("library","delete",Re.created_by_id),children:s.jsx(on,{className:"w-4 h-4"})})]})]},Re.id))]})})]})]}),x&&s.jsx(aXe,{parentId:d,onClose:()=>b(!1),onSave:Re=>_e.mutate(Re),isLoading:_e.isPending,t}),v&&U&&s.jsx(oXe,{folders:U,selectedFiles:p,currentFolderId:d,onClose:()=>y(!1),onMove:Re=>rt.mutate({fileIds:p,folderId:Re}),isLoading:rt.isPending,t}),S&&s.jsx(cXe,{folderId:d,onClose:()=>M(!1),onUploadComplete:Be,t}),T&&s.jsx(lXe,{folder:T,onClose:()=>k(null),onLink:Re=>Ie.mutate({id:T.id,data:Re}),isLoading:Ie.isPending,t}),C&&s.jsx(Jn,{title:C.type==="folder"?t("fileManager.deleteFolder"):C.type==="bulk"?t("fileManager.deleteFilesCount",{count:C.count}):t("fileManager.deleteFile"),message:C.type==="folder"?t("fileManager.deleteFolderConfirm"):C.type==="bulk"?t("fileManager.deleteFilesConfirm",{count:C.count}):t("fileManager.deleteFileConfirm"),confirmText:t("common.delete"),variant:"danger",isLoading:it,loadingText:t("fileManager.deleting"),onConfirm:$e,onCancel:()=>E(null)}),D&&s.jsx(ju,{mode:"reprint",libraryFileId:D.id,archiveName:D.print_name||D.filename,onClose:()=>A(null),onSuccess:()=>{A(null),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["archives"]})}}),j&&s.jsx(ju,{mode:"reprint",libraryFileId:j.id,archiveName:j.print_name||j.filename,onClose:()=>I(null),onSuccess:()=>{I(null),m([]),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["archives"]})}}),F&&s.jsx(ju,{mode:"add-to-queue",libraryFileId:F.id,archiveName:F.print_name||F.filename,onClose:()=>H(null),onSuccess:()=>{H(null),m([]),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["queue"]}),e.invalidateQueries({queryKey:["archives"]})}}),R&&s.jsx(sXe,{type:R.type,currentName:R.name,onClose:()=>z(null),onSave:Re=>{R.type==="file"?be.mutate({id:R.id,filename:Re}):Ae.mutate({id:R.id,name:Re})},isLoading:be.isPending||Ae.isPending,t})]})}const KP=5,hXe=2e3,fXe=3e4,mXe=5e3;function pXe(){const{t}=On(),{printerId:e}=iM(),n=parseInt(e||"0",10),[r,i]=_.useState("stream"),[a,o]=_.useState(!1),[l,c]=_.useState(!0),[u,d]=_.useState(Date.now()),[f,p]=_.useState(!1),[m,x]=_.useState(!1),[b,v]=_.useState(0),[y,S]=_.useState(!1),[M,T]=_.useState(0),[k,C]=_.useState(1),[E,D]=_.useState({x:0,y:0}),[A,j]=_.useState(!1),[I,F]=_.useState({x:0,y:0}),[H,R]=_.useState(null),[z,W]=_.useState(null),V=_.useRef(null),X=_.useRef(null),Q=_.useRef(null),ae=_.useRef(null),$=_.useRef(null),{data:K}=ot({queryKey:["printer",n],queryFn:()=>ce.getPrinter(n),enabled:n>0});_.useEffect(()=>(K&&(document.title=`${K.name} - Camera`),()=>{document.title="Bambuddy"}),[K]);const ie=_.useRef(!1);_.useEffect(()=>{const se=`/api/v1/printers/${n}/camera/stop`;ie.current=!1;const ve=()=>{n>0&&!ie.current&&(ie.current=!0,navigator.sendBeacon(se))},_e=()=>{ve()};window.addEventListener("beforeunload",_e);const ne=V.current;return()=>{window.removeEventListener("beforeunload",_e),ne&&(ne.src=""),ve()}},[n]),_.useEffect(()=>{if(l&&!f){const ve=setTimeout(()=>{c(!1)},r==="stream"?3e3:2e4);return()=>clearTimeout(ve)}},[r,l,u,f]),_.useEffect(()=>{const se=()=>{const ve=!!document.fullscreenElement;x(ve),C(1),D({x:0,y:0}),r==="stream"&&!f&&(V.current&&(V.current.src=""),setTimeout(()=>{c(!0),d(Date.now())},200))};return document.addEventListener("fullscreenchange",se),()=>document.removeEventListener("fullscreenchange",se)},[r,f]),_.useEffect(()=>{let se;const ve=()=>{clearTimeout(se),se=setTimeout(()=>{localStorage.setItem("cameraWindowState",JSON.stringify({width:window.outerWidth,height:window.outerHeight,left:window.screenX,top:window.screenY}))},500)};return window.addEventListener("resize",ve),()=>{clearTimeout(se),window.removeEventListener("resize",ve)}},[]),_.useEffect(()=>()=>{Q.current&&clearTimeout(Q.current),ae.current&&clearInterval(ae.current),$.current&&clearInterval($.current)},[]);const re=_.useCallback(()=>{if(b>=KP){S(!1),o(!0);return}const se=Math.min(hXe*Math.pow(2,b),fXe);S(!0),T(Math.ceil(se/1e3)),ae.current=setInterval(()=>{T(ve=>ve<=1?(ae.current&&clearInterval(ae.current),0):ve-1)},1e3),Q.current=setTimeout(()=>{v(ve=>ve+1),S(!1),c(!0),o(!1),V.current&&(V.current.src=""),d(Date.now())},se)},[b]);_.useEffect(()=>{if(r!=="stream"||l||y||f){$.current&&(clearInterval($.current),$.current=null);return}return $.current=setInterval(async()=>{try{const se=await ce.getCameraStatus(n);(se.stalled||!se.active&&!a)&&(console.log(`Stream issue detected: stalled=${se.stalled}, active=${se.active}, reconnecting...`),$.current&&(clearInterval($.current),$.current=null),c(!1),re())}catch{}},mXe),()=>{$.current&&(clearInterval($.current),$.current=null)}},[r,l,a,y,f,n,re]);const xe=()=>{c(!1),r==="stream"&&b{if(c(!1),o(!1),v(0),S(!1),Q.current&&clearTimeout(Q.current),ae.current&&clearInterval(ae.current),V.current&&!localStorage.getItem("cameraWindowState")){const se=V.current,ve=se.naturalWidth,_e=se.naturalHeight;if(ve>0&&_e>0){const He=window.outerWidth-window.innerWidth,rt=window.outerHeight-window.innerHeight,Ie=ve+16+He,be=_e+45+16+rt;try{window.resizeTo(Ie,be)}catch{}}}},ue=()=>{n>0&&fetch(`/api/v1/printers/${n}/camera/stop`).catch(()=>{})},Pe=se=>{r===se||f||(p(!0),c(!0),o(!1),v(0),S(!1),C(1),D({x:0,y:0}),Q.current&&clearTimeout(Q.current),ae.current&&clearInterval(ae.current),V.current&&(V.current.src=""),r==="stream"&&ue(),setTimeout(()=>{i(se),d(Date.now()),p(!1)},100))},te=()=>{f||(p(!0),c(!0),o(!1),v(0),S(!1),Q.current&&clearTimeout(Q.current),ae.current&&clearInterval(ae.current),V.current&&(V.current.src=""),r==="stream"&&ue(),setTimeout(()=>{d(Date.now()),p(!1)},100))},Ee=()=>{X.current&&(document.fullscreenElement?document.exitFullscreen():X.current.requestFullscreen())},Oe=()=>{C(se=>Math.min(se+.5,4))},me=()=>{C(se=>{const ve=Math.max(se-.5,1);return ve===1&&D({x:0,y:0}),ve})},Xe=se=>{se.preventDefault(),se.deltaY<0?Oe():me()},G=se=>{k>1&&(se.preventDefault(),j(!0),F({x:se.clientX-E.x,y:se.clientY-E.y}))},Y=_.useCallback(()=>{if(!X.current)return{x:300,y:200};const se=X.current.getBoundingClientRect(),ve=se.width*(k-1)/2,_e=se.height*(k-1)/2;return{x:Math.max(50,ve),y:Math.max(50,_e)}},[k]),de=se=>{if(A&&k>1){const ve=se.clientX-I.x,_e=se.clientY-I.y,ne=Y();D({x:Math.max(-ne.x,Math.min(ne.x,ve)),y:Math.max(-ne.y,Math.min(ne.y,_e))})}},q=()=>{j(!1)},ee=se=>{if(se.length<2)return 0;const ve=se[0].clientX-se[1].clientX,_e=se[0].clientY-se[1].clientY;return Math.sqrt(ve*ve+_e*_e)},U=se=>se.length<2?{x:se[0].clientX,y:se[0].clientY}:{x:(se[0].clientX+se[1].clientX)/2,y:(se[0].clientY+se[1].clientY)/2},fe=se=>{se.touches.length===2?(se.preventDefault(),R(ee(se.touches)),W(U(se.touches))):se.touches.length===1&&k>1&&(se.preventDefault(),j(!0),F({x:se.touches[0].clientX-E.x,y:se.touches[0].clientY-E.y}))},we=se=>{if(se.touches.length===2&&H!==null){se.preventDefault();const ve=ee(se.touches),_e=ve/H;C(Fe=>{const He=Math.max(1,Math.min(4,Fe*_e));return He===1&&D({x:0,y:0}),He}),R(ve);const ne=U(se.touches);if(z){const Fe=Y();D(He=>({x:Math.max(-Fe.x,Math.min(Fe.x,He.x+(ne.x-z.x))),y:Math.max(-Fe.y,Math.min(Fe.y,He.y+(ne.y-z.y)))}))}W(ne)}else if(se.touches.length===1&&A&&k>1){se.preventDefault();const ve=se.touches[0].clientX-I.x,_e=se.touches[0].clientY-I.y,ne=Y();D({x:Math.max(-ne.x,Math.min(ne.x,ve)),y:Math.max(-ne.y,Math.min(ne.y,_e))})}},ge=se=>{se.touches.length<2&&(R(null),W(null)),se.touches.length===0&&j(!1)},B=()=>{C(1),D({x:0,y:0})},O=f?"":r==="stream"?`/api/v1/printers/${n}/camera/stream?fps=15&t=${u}`:`/api/v1/printers/${n}/camera/snapshot?t=${u}`,J=l||f||y;return n?s.jsxs("div",{ref:X,className:"min-h-screen bg-black flex flex-col",children:[s.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary",children:[s.jsxs("h1",{className:"text-sm font-medium text-white flex items-center gap-2",children:[s.jsx(Ug,{className:"w-4 h-4"}),K?.name||`Printer ${n}`]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"flex bg-bambu-dark rounded p-0.5",children:[s.jsx("button",{onClick:()=>Pe("stream"),disabled:J,className:`px-3 py-1 text-xs rounded transition-colors ${r==="stream"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white disabled:opacity-50"}`,children:t("camera.live")}),s.jsx("button",{onClick:()=>Pe("snapshot"),disabled:J,className:`px-3 py-1 text-xs rounded transition-colors ${r==="snapshot"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white disabled:opacity-50"}`,children:t("camera.snapshot")})]}),s.jsx("button",{onClick:te,disabled:J,className:"p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50",title:t(r==="stream"?"camera.restartStream":"camera.refreshSnapshot"),children:s.jsx(Rr,{className:`w-4 h-4 text-bambu-gray ${J?"animate-spin":""}`})}),s.jsx("button",{onClick:Ee,className:"p-1.5 hover:bg-bambu-dark-tertiary rounded",title:t(m?"camera.exitFullscreen":"camera.fullscreen"),children:m?s.jsx(kW,{className:"w-4 h-4 text-bambu-gray"}):s.jsx(Ide,{className:"w-4 h-4 text-bambu-gray"})})]})]}),s.jsx("div",{className:"flex-1 flex items-center justify-center p-2 overflow-hidden",onWheel:Xe,onMouseMove:de,onMouseUp:q,onMouseLeave:q,onTouchStart:fe,onTouchMove:we,onTouchEnd:ge,style:{touchAction:"none"},children:s.jsxs("div",{className:"relative w-full h-full flex items-center justify-center",children:[(l||f)&&!y&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 z-10",children:s.jsxs("div",{className:"text-center",children:[s.jsx(Rr,{className:"w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:t(r==="stream"?"camera.connectingToCamera":"camera.capturingSnapshot")})]})}),y&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/80 z-10",children:s.jsxs("div",{className:"text-center p-4",children:[s.jsx(sm,{className:"w-10 h-10 text-orange-400 mx-auto mb-3"}),s.jsx("p",{className:"text-white mb-2",children:t("camera.connectionLost")}),s.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:t("camera.reconnecting",{countdown:M,attempt:b+1,max:KP})}),s.jsx("button",{onClick:te,className:"px-4 py-2 bg-bambu-green text-white text-sm rounded hover:bg-bambu-green/80 transition-colors",children:t("camera.reconnectNow")})]})}),a&&!y&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black z-10",children:s.jsxs("div",{className:"text-center p-4",children:[s.jsx(Sn,{className:"w-12 h-12 text-orange-400 mx-auto mb-3"}),s.jsx("p",{className:"text-white mb-2",children:t("camera.cameraUnavailable")}),s.jsx("p",{className:"text-xs text-bambu-gray mb-4 max-w-md",children:t("camera.cameraUnavailableDesc")}),s.jsx("button",{onClick:te,className:"px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors",children:t("camera.retry")})]})}),s.jsx("img",{ref:V,src:O,alt:t("camera.cameraStream"),className:"max-w-full max-h-full object-contain select-none",style:{transform:`scale(${k}) translate(${E.x/k}px, ${E.y/k}px)`,cursor:k>1?A?"grabbing":"grab":"default"},onError:O?xe:void 0,onLoad:O?pe:void 0,onMouseDown:G,draggable:!1},u),s.jsxs("div",{className:"absolute bottom-4 left-4 flex items-center gap-1.5 bg-black/60 rounded-lg px-2 py-1.5",children:[s.jsx("button",{onClick:me,disabled:k<=1,className:"p-1.5 hover:bg-white/10 rounded disabled:opacity-30",title:t("camera.zoomOut"),children:s.jsx(FR,{className:"w-4 h-4 text-white"})}),s.jsxs("button",{onClick:B,className:"px-2 py-1 text-sm text-white hover:bg-white/10 rounded min-w-[48px]",title:t("camera.resetZoom"),children:[Math.round(k*100),"%"]}),s.jsx("button",{onClick:Oe,disabled:k>=4,className:"p-1.5 hover:bg-white/10 rounded disabled:opacity-30",title:t("camera.zoomIn"),children:s.jsx(LR,{className:"w-4 h-4 text-white"})})]})]})})]}):s.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:s.jsx("p",{className:"text-white",children:t("camera.invalidPrinterId")})})}function gXe(t){const e=t.get("show")?.split(",")||["progress","layers","eta","filename","status"],n=parseInt(t.get("fps")||"15",10),r=Math.min(Math.max(isNaN(n)?15:n,1),30),i=t.get("camera"),a=i!=="false"&&i!=="0";return{size:t.get("size")||"medium",fps:r,showCamera:a,showProgress:e.includes("progress"),showLayers:e.includes("layers"),showEta:e.includes("eta"),showFilename:e.includes("filename"),showStatus:e.includes("status"),showPrinter:e.includes("printer")}}function xXe(t){const e=Math.floor(t/3600),n=Math.floor(t%3600/60);return e>0?`${e}h ${n}m`:`${n}m`}function bXe(t,e){const n=new Date,r=new Date(n.getTime()+t*60*1e3),i=new Date;i.setHours(0,0,0,0);const a=new Date(r);a.setHours(0,0,0,0);const o=r.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return a.getTime()===i.getTime()?o:a.getTime()===i.getTime()+864e5?`${e("streamOverlay.tomorrow")} ${o}`:r.toLocaleDateString([],{weekday:"short"})+" "+o}function yXe(t,e){if(t.stg_cur_name)return t.stg_cur_name;switch(t.state){case"RUNNING":return e("streamOverlay.status.printing");case"PAUSE":return e("streamOverlay.status.paused");case"FINISH":return e("streamOverlay.status.finished");case"FAILED":return e("streamOverlay.status.failed");case"IDLE":return e("streamOverlay.status.idle");default:return t.state||e("streamOverlay.status.unknown")}}function vXe(t){switch(t){case"small":return{container:"p-3",text:"text-sm",textLarge:"text-lg",progressHeight:"h-2",icon:"w-3 h-3",gap:"gap-2",logoHeight:"h-12"};case"large":return{container:"p-6",text:"text-xl",textLarge:"text-3xl",progressHeight:"h-4",icon:"w-6 h-6",gap:"gap-4",logoHeight:"h-24"};case"medium":default:return{container:"p-4",text:"text-base",textLarge:"text-xl",progressHeight:"h-3",icon:"w-4 h-4",gap:"gap-3",logoHeight:"h-16"}}}function wXe(){const{printerId:t}=iM(),[e]=wR(),{t:n}=On(),r=ln(),i=parseInt(t||"0",10),[a,o]=_.useState(Date.now()),l=_.useMemo(()=>gXe(e),[e]),c=vXe(l.size),{data:u}=ot({queryKey:["printer",i],queryFn:()=>ce.getPrinter(i),enabled:i>0}),{data:d}=ot({queryKey:["printerStatus",i],queryFn:()=>ce.getPrinterStatus(i),enabled:i>0,refetchInterval:2e3});_.useEffect(()=>{if(!i)return;const v=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/v1/ws`,y=new WebSocket(v);return y.onmessage=S=>{try{const M=JSON.parse(S.data);M.type==="printer_status"&&M.printer_id===i&&r.setQueryData(["printerStatus",i],M.status)}catch{}},y.onerror=()=>{},()=>{y.close()}},[i,r]),_.useEffect(()=>(document.title=u?`${u.name} - ${n("streamOverlay.title")}`:n("streamOverlay.title"),()=>{document.title="Bambuddy"}),[u,n]);const f=()=>{setTimeout(()=>{o(Date.now())},3e3)};if(!i)return s.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:s.jsx("p",{className:"text-white",children:n("streamOverlay.invalidPrinterId")})});if(!d)return s.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:s.jsx("p",{className:"text-gray-400",children:n("common.loading")})});const p=d.state==="RUNNING"||d.state==="PAUSE",m=d.progress||0,x=`/api/v1/printers/${i}/camera/stream?fps=${l.fps}&t=${a}`;return s.jsxs("div",{className:"min-h-screen bg-black relative overflow-hidden",children:[l.showCamera&&s.jsx("img",{src:x,alt:n("streamOverlay.cameraStream"),className:"absolute inset-0 w-full h-full object-contain",onError:f},a),s.jsx("a",{href:"https://github.com/maziggy/bambuddy",target:"_blank",rel:"noopener noreferrer",className:"absolute top-4 right-4 z-10",children:s.jsx("img",{src:"/img/bambuddy_logo_dark_transparent.png",alt:"Bambuddy",className:`${c.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})}),s.jsx("div",{className:"absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/60 to-transparent",children:s.jsxs("div",{className:`${c.container}`,children:[l.showPrinter&&u&&s.jsxs("div",{className:`flex items-center ${c.gap} mb-2`,children:[s.jsx(Pr,{className:`${c.icon} text-white/70`}),s.jsx("span",{className:`${c.text} text-white font-medium`,children:u.name})]}),l.showFilename&&d.current_print&&s.jsx("div",{className:`${c.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:d.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,"")}),l.showStatus&&s.jsx("div",{className:`${c.text} text-white/70 mb-2`,children:yXe(d,n)}),l.showProgress&&p&&s.jsxs("div",{className:"mb-3",children:[s.jsxs("div",{className:`flex items-center justify-between mb-1 ${c.text}`,children:[s.jsx("span",{className:"text-white/70",children:n("streamOverlay.progress")}),s.jsxs("span",{className:"text-white font-bold",children:[Math.round(m),"%"]})]}),s.jsx("div",{className:`w-full bg-white/20 rounded-full ${c.progressHeight}`,children:s.jsx("div",{className:`bg-bambu-green ${c.progressHeight} rounded-full transition-all duration-500`,style:{width:`${m}%`}})})]}),p&&(l.showLayers||l.showEta)&&s.jsxs("div",{className:`flex items-center ${c.gap} flex-wrap`,children:[l.showLayers&&d.layer_num!=null&&d.total_layers!=null&&d.total_layers>0&&s.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[s.jsx(sl,{className:c.icon}),s.jsxs("span",{className:c.text,children:[s.jsx("span",{className:"text-white",children:d.layer_num}),s.jsx("span",{className:"mx-1",children:"/"}),s.jsx("span",{children:d.total_layers})]})]}),l.showEta&&d.remaining_time!=null&&d.remaining_time>0&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[s.jsx(bu,{className:c.icon}),s.jsx("span",{className:`${c.text} text-white`,children:xXe(d.remaining_time*60)})]}),s.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[s.jsx(nr,{className:c.icon}),s.jsxs("span",{className:`${c.text} text-white`,children:[n("streamOverlay.eta")," ",bXe(d.remaining_time,n)]})]})]})]}),!p&&s.jsx("div",{className:`${c.text} text-white/70 py-2`,children:d.connected?n("streamOverlay.printerIdle"):n("streamOverlay.printerOffline")})]})})]})}function _Xe(){const{t}=On(),{id:e}=iM(),{mode:n}=Lh(),{data:r,isLoading:i,error:a}=ot({queryKey:["external-link",e],queryFn:()=>ce.getExternalLink(Number(e)),enabled:!!e});return i?s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):a||!r?s.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 text-bambu-gray",children:[s.jsx(Sn,{className:"w-12 h-12"}),s.jsx("p",{children:t("common.linkNotFound")})]}):s.jsx("iframe",{src:r.url,className:"h-full w-full border-0",style:{colorScheme:n},title:r.name,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox"})}const wq=["DEBUG","INFO","WARNING","ERROR"],XP={DEBUG:"text-gray-400",INFO:"text-blue-400",WARNING:"text-yellow-400",ERROR:"text-red-400"},SXe={DEBUG:sM,INFO:Zo,WARNING:Sn,ERROR:$i};function NXe(){const t=ln(),[e,n]=_.useState(!0),[r,i]=_.useState(new Set),[a,o]=_.useState(""),[l,c]=_.useState("ALL"),[u,d]=_.useState(!1),[f,p]=_.useState(!1),m=_.useRef(null),{data:x,isLoading:b,refetch:v}=ot({queryKey:["application-logs",l,a],queryFn:()=>Ng.getLogs({limit:200,level:l==="ALL"?void 0:l,search:a||void 0}),refetchInterval:f?2e3:!1,enabled:u});_.useEffect(()=>{u||p(!1)},[u]);const y=gt({mutationFn:()=>Ng.clearLogs(),onSuccess:()=>{t.invalidateQueries({queryKey:["application-logs"]})}});_.useEffect(()=>{e&&m.current&&x?.entries&&(m.current.scrollTop=m.current.scrollHeight)},[x?.entries,e]);const S=E=>{i(D=>{const A=new Set(D);return A.has(E)?A.delete(E):A.add(E),A})},M=E=>{const D=E.split(" ");return D.length>=2?D[1]:E},T=_.useMemo(()=>x?.entries??[],[x?.entries]),k=_.useMemo(()=>[...T].reverse(),[T]),C=({level:E})=>{const D=SXe[E]||Zo;return s.jsx(D,{className:`w-3.5 h-3.5 ${XP[E]||"text-gray-400"}`})};return s.jsxs("div",{className:"bg-bambu-dark rounded-lg overflow-hidden",children:[s.jsxs("button",{onClick:()=>d(!u),className:"w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/50 transition-colors",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:`p-2 rounded-lg ${f?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:s.jsx(sM,{className:"w-5 h-5"})}),s.jsxs("div",{className:"text-left",children:[s.jsx("p",{className:"font-medium text-white",children:"Application Logs"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:f?`Live streaming - ${x?.filtered_count??0} entries`:"View and filter application logs"})]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[f&&s.jsxs("span",{className:"flex items-center gap-1.5 px-2 py-1 bg-bambu-green/20 rounded text-bambu-green text-xs",children:[s.jsx("span",{className:"w-1.5 h-1.5 bg-bambu-green rounded-full animate-pulse"}),"Live"]}),u?s.jsx(yh,{className:"w-5 h-5 text-bambu-gray"}):s.jsx(Kr,{className:"w-5 h-5 text-bambu-gray"})]})]}),u&&s.jsxs("div",{className:"border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[f?s.jsxs("button",{onClick:E=>{E.stopPropagation(),p(!1)},className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-red-500/20 text-red-400 hover:bg-red-500/30 rounded transition-colors",children:[s.jsx(ll,{className:"w-4 h-4"}),"Stop"]}):s.jsxs("button",{onClick:E=>{E.stopPropagation(),p(!0),v()},className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 rounded transition-colors",children:[s.jsx(bo,{className:"w-4 h-4"}),"Start"]}),s.jsxs("button",{onClick:()=>y.mutate(),disabled:y.isPending||T.length===0,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50",children:[s.jsx(on,{className:"w-4 h-4"}),"Clear"]}),s.jsx("button",{onClick:()=>v(),disabled:b,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50",children:s.jsx(Rr,{className:`w-4 h-4 ${b?"animate-spin":""}`})}),s.jsx("div",{className:"flex-1"}),s.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:e,onChange:E=>n(E.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark-tertiary"}),"Auto-scroll"]}),s.jsxs("span",{className:"text-sm text-bambu-gray",children:[x?.filtered_count??0,"/",x?.total_in_file??0]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1",children:[s.jsx(ya,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),s.jsx("input",{type:"text",placeholder:"Search message or logger name...",value:a,onChange:E=>o(E.target.value),className:"w-full pl-8 pr-8 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),a&&s.jsx("button",{onClick:()=>o(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:s.jsx(Lt,{className:"w-4 h-4"})})]}),s.jsxs("div",{className:"flex items-center gap-1 bg-bambu-dark-secondary rounded border border-bambu-dark-tertiary",children:[s.jsx("button",{onClick:()=>c("ALL"),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${l==="ALL"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white"}`,children:"All"}),wq.map((E,D)=>s.jsx("button",{onClick:()=>c(E),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${D===wq.length-1?"rounded-r":""} ${l===E?`${XP[E]} bg-bambu-dark-tertiary`:"text-bambu-gray hover:text-white"}`,children:E},E))]})]})]}),s.jsx("div",{ref:m,className:"overflow-auto font-mono text-xs bg-black min-h-[300px] max-h-[500px]",children:T.length===0?s.jsxs("div",{className:"flex flex-col items-center justify-center h-[300px] text-bambu-gray",children:[s.jsx("p",{className:"mb-2",children:"No log entries found"}),s.jsx("p",{className:"text-sm",children:"Log file may be empty or cleared"})]}):s.jsx("div",{className:"divide-y divide-bambu-dark-tertiary/30",children:k.map((E,D)=>{const A=r.has(D),j=E.message.includes(` +`+n+"}"}return String(t)}function UKe({setting:t,onClose:e,onDeleted:n,onDuplicate:r,onEdit:i,hasPermission:a,t:o}){const{showToast:l}=Vn(),c=ln(),[u,d]=_.useState(!1),{data:f,isLoading:p}=ot({queryKey:["cloudSettingDetail",t.setting_id],queryFn:()=>ce.getCloudSettingDetail(t.setting_id)}),m=gt({mutationFn:()=>ce.deleteCloudSetting(t.setting_id),onSuccess:()=>{l(o("profiles.presets.toast.deleted")),c.invalidateQueries({queryKey:["cloudSettings"]}),n()},onError:v=>l(v.message,"error")}),x=Ry(t.setting_id),b=cF(t.name,f?.setting?.inherits);return s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:s.jsx(Nt,{className:"w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden",children:s.jsxs(Mt,{className:"p-0 flex flex-col min-h-0 flex-1",children:[s.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h2",{className:"text-xl font-semibold text-white truncate",children:t.name}),x&&s.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full",children:o("profiles.presets.editable")})]}),s.jsxs("div",{className:"flex items-center gap-2 mt-1 text-sm text-bambu-gray",children:[s.jsx("span",{className:"capitalize",children:o(`profiles.presets.types.${t.type}`)}),b.printer&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"•"}),s.jsx("span",{children:b.printer})]})]})]}),s.jsx("button",{onClick:e,className:"p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:s.jsx(Lt,{className:"w-5 h-5"})})]}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto p-4",children:p?s.jsx("div",{className:"flex items-center justify-center py-16",children:s.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):f?s.jsx("pre",{className:"text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full",children:dR(f)}):s.jsx("div",{className:"text-center py-16 text-bambu-gray",children:o("profiles.presets.failedToLoadDetails")})}),u?s.jsxs("div",{className:"flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-3 text-red-400",children:[s.jsx(Sn,{className:"w-5 h-5"}),s.jsx("span",{className:"font-medium",children:o("profiles.presets.deleteConfirm")})]}),s.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:o("profiles.presets.deleteWarning",{name:t.name})}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Te,{variant:"secondary",onClick:()=>d(!1),disabled:m.isPending,className:"flex-1",children:o("common.cancel")}),s.jsxs(Te,{variant:"danger",onClick:()=>m.mutate(),disabled:m.isPending,className:"flex-1",children:[m.isPending?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):s.jsx(on,{className:"w-4 h-4"}),o("common.delete")]})]})]}):s.jsx("div",{className:"flex-shrink-0 p-4 border-t border-bambu-dark-tertiary",children:s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Te,{variant:"secondary",onClick:e,className:"flex-1",children:o("common.close")}),s.jsxs(Te,{variant:"secondary",onClick:r,disabled:!a("cloud:auth"),title:a("cloud:auth")?void 0:o("profiles.presets.noDuplicatePermission"),children:[s.jsx(Fl,{className:"w-4 h-4"}),o("profiles.presets.duplicate")]}),x&&s.jsxs(s.Fragment,{children:[s.jsxs(Te,{variant:"secondary",onClick:i,disabled:p||!f||!a("cloud:auth"),title:a("cloud:auth")?void 0:o("profiles.presets.noEditPermission"),children:[s.jsx(Zi,{className:"w-4 h-4"}),o("common.edit")]}),s.jsx(Te,{variant:"danger",onClick:()=>d(!0),disabled:!a("cloud:auth"),title:a("cloud:auth")?void 0:o("profiles.presets.noDeletePermission"),children:s.jsx(on,{className:"w-4 h-4"})})]})]})})]})})})}function zre(){try{const t=localStorage.getItem("bambusy_preset_templates");return t?JSON.parse(t):[]}catch{return[]}}function Bre(t){localStorage.setItem("bambusy_preset_templates",JSON.stringify(t))}function zKe({onClose:t,onApply:e,t:n}){const{showToast:r}=Vn(),[i,a]=_.useState(zre),[o,l]=_.useState("all"),[c,u]=_.useState(null),[d,f]=_.useState(""),[p,m]=_.useState(""),[x,b]=_.useState("{}"),[v,y]=_.useState(null),[S,M]=_.useState(null),T=o==="all"?i:i.filter(H=>H.type===o),k=H=>{a(H),Bre(H)},C=H=>{const R=i.filter(z=>z.id!==H);k(R),M(null),r(n("profiles.templates.toast.deleted"))},E=H=>{u(H.id),f(H.name),m(H.description),b(JSON.stringify(H.settings,null,2)),y(null)},D=()=>{if(!(!c||!d.trim()))try{const H=JSON.parse(x),R=i.map(z=>z.id===c?{...z,name:d.trim(),description:p.trim(),settings:H}:z);k(R),u(null),r(n("profiles.templates.toast.updated"))}catch(H){y(H.message)}},A=()=>{u(null),f(""),m(""),b("{}"),y(null)},j=H=>{const R=i.map(z=>z.id===H?{...z,showInModal:!z.showInModal}:z);k(R)},I={filament:{label:n("profiles.presets.types.filament"),icon:TR,color:"text-amber-400"},print:{label:n("profiles.presets.types.process"),icon:vh,color:"text-blue-400"},printer:{label:n("profiles.presets.types.printer"),icon:Pr,color:"text-purple-400"}},F=S?i.find(H=>H.id===S):null;return _.useEffect(()=>{const H=R=>{R.key==="Escape"&&(S?M(null):c?A():t())};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[S,c,t]),s.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:[F&&s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-60",children:s.jsx(Nt,{className:"w-full max-w-md",children:s.jsxs(Mt,{className:"p-6",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[s.jsx("div",{className:"p-2 bg-red-500/20 rounded-lg",children:s.jsx(Sn,{className:"w-6 h-6 text-red-400"})}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-lg font-semibold text-white",children:n("profiles.templates.deleteTitle")}),s.jsx("p",{className:"text-sm text-bambu-gray",children:n("profiles.templates.deleteWarning")})]})]}),s.jsx("p",{className:"text-white mb-6",children:n("profiles.templates.deleteConfirm",{name:F.name})}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Te,{variant:"secondary",onClick:()=>M(null),className:"flex-1",children:n("common.cancel")}),s.jsxs(Te,{onClick:()=>C(S),className:"flex-1 bg-red-500 hover:bg-red-600",children:[s.jsx(on,{className:"w-4 h-4"}),n("common.delete")]})]})]})})}),s.jsx(Nt,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",children:s.jsxs(Mt,{className:"p-0 flex flex-col h-full",children:[s.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(W0,{className:"w-5 h-5 text-amber-400"}),n("profiles.templates.title")]}),s.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white",children:s.jsx(Lt,{className:"w-5 h-5"})})]}),s.jsxs("div",{className:"flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary",children:[s.jsx("span",{className:"text-sm text-bambu-gray",children:n("profiles.templates.typeFilter")}),["all","filament","print","printer"].map(H=>s.jsx("button",{onClick:()=>l(H),className:`px-3 py-1 text-sm rounded-lg transition-colors ${o===H?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:H==="all"?n("common.all"):I[H].label},H))]}),s.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:T.length===0?s.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[s.jsx(W0,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),s.jsx("p",{children:n("profiles.templates.noTemplates")}),s.jsx("p",{className:"text-sm mt-1",children:n("profiles.templates.createFirst")})]}):s.jsx("div",{className:"space-y-2",children:T.map(H=>{const R=I[H.type],z=R.icon;return c===H.id?s.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-green",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-3 mb-3",children:[s.jsx("input",{type:"text",value:d,onChange:W=>f(W.target.value),placeholder:n("profiles.templates.namePlaceholder"),className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",autoFocus:!0}),s.jsx("input",{type:"text",value:p,onChange:W=>m(W.target.value),placeholder:n("profiles.templates.descriptionPlaceholder"),className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]}),s.jsxs("div",{className:"mb-3",children:[s.jsx("label",{className:"text-xs text-bambu-gray mb-1 block",children:n("profiles.templates.settingsJson")}),s.jsx("textarea",{value:x,onChange:W=>{b(W.target.value),y(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${v?"border-red-500":"border-bambu-dark-tertiary focus:border-bambu-green"}`}),v&&s.jsx("p",{className:"text-xs text-red-400 mt-1",children:v})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(Te,{size:"sm",onClick:D,disabled:!d.trim(),children:[s.jsx(hs,{className:"w-4 h-4"}),"Save"]}),s.jsx(Te,{size:"sm",variant:"secondary",onClick:A,children:"Cancel"})]})]},H.id):s.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors",children:[s.jsx(z,{className:`w-5 h-5 ${R.color} flex-shrink-0`}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm font-medium text-white",children:H.name}),s.jsx("p",{className:"text-xs text-bambu-gray truncate",children:H.description})]}),s.jsx("span",{className:"text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded",children:n("profiles.templates.fieldsCount",{count:Object.keys(H.settings).length})}),s.jsx("button",{onClick:()=>j(H.id),className:`p-1 transition-colors ${H.showInModal?"text-bambu-green hover:text-bambu-green/70":"text-bambu-gray hover:text-white"}`,title:H.showInModal?n("profiles.templates.shownInModals"):n("profiles.templates.hiddenInModals"),children:H.showInModal?s.jsx(mc,{className:"w-4 h-4"}):s.jsx(cM,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>e(H),className:"px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors",children:n("profiles.templates.apply")}),s.jsx("button",{onClick:()=>E(H),className:"p-1 text-bambu-gray hover:text-white",title:n("common.edit"),children:s.jsx(Zi,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>M(H.id),className:"p-1 text-bambu-gray hover:text-red-400",title:n("common.delete"),children:s.jsx(on,{className:"w-4 h-4"})})]},H.id)})})})]})})]})}function Hre({onClose:t,leftPreset:e,rightPreset:n,leftLabel:r,rightLabel:i,t:a}){const[o,l]=_.useState("changes"),[c,u]=_.useState(""),d=_.useMemo(()=>{const x=new Set([...Object.keys(e),...Object.keys(n)]),b=[];for(const v of x){if(v==="inherits"||v==="version")continue;const y=e[v],S=n[v],M=v in e,T=v in n;let k;!M&&T?k="added":M&&!T?k="removed":JSON.stringify(y)!==JSON.stringify(S)?k="changed":k="same",b.push({key:v,left:y,right:S,status:k})}return b.sort((v,y)=>{const S={changed:0,added:1,removed:2,same:3};return S[v.status]!==S[y.status]?S[v.status]-S[y.status]:v.key.localeCompare(y.key)})},[e,n]),f=_.useMemo(()=>{let x=[...d];if(o==="changes"&&(x=x.filter(b=>b.status!=="same")),c){const b=c.toLowerCase();x=x.filter(v=>v.key.toLowerCase().includes(b)||String(v.left).toLowerCase().includes(b)||String(v.right).toLowerCase().includes(b))}return x},[d,o,c]),p=_.useMemo(()=>({added:d.filter(x=>x.status==="added").length,removed:d.filter(x=>x.status==="removed").length,changed:d.filter(x=>x.status==="changed").length,same:d.filter(x=>x.status==="same").length}),[d]),m=x=>{if(x===void 0)return"—";if(x===null)return"null";if(Array.isArray(x))return x.length===0?"[]":x.length===1?String(x[0]):x.join(", ");if(typeof x=="object")return JSON.stringify(x);const b=String(x);if(b.includes("\\n")||b.length>100){const v=b.split("\\n").length;if(v>1)return`[${v} lines of G-code/script]`;if(b.length>100)return b.substring(0,100)+"…"}return b};return _.useEffect(()=>{const x=b=>{b.key==="Escape"&&t()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[t]),s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:s.jsx(Nt,{className:"w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden",children:s.jsxs(Mt,{className:"p-0 flex flex-col min-h-0 flex-1",children:[s.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(_g,{className:"w-5 h-5 text-blue-400"}),a("profiles.diff.title")]}),s.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white",children:s.jsx(Lt,{className:"w-5 h-5"})})]}),s.jsxs("div",{className:"flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark",children:[s.jsxs("div",{className:"text-center",children:[s.jsx("span",{className:"text-sm text-bambu-gray",children:a("profiles.diff.left")}),s.jsx("p",{className:"text-white font-medium truncate",children:r})]}),s.jsxs("div",{className:"text-center",children:[s.jsx("span",{className:"text-sm text-bambu-gray",children:a("profiles.diff.right")}),s.jsx("p",{className:"text-white font-medium truncate",children:i})]})]}),s.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[s.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[s.jsx(fr,{className:"w-3.5 h-3.5"}),p.added," ",a("profiles.diff.added")]}),s.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[s.jsx(xj,{className:"w-3.5 h-3.5"}),p.removed," ",a("profiles.diff.removed")]}),s.jsxs("span",{className:"flex items-center gap-1 text-amber-400",children:[s.jsx(uj,{className:"w-3.5 h-3.5"}),p.changed," ",a("profiles.diff.changed")]}),s.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray",children:[s.jsx(eT,{className:"w-3.5 h-3.5"}),p.same," ",a("profiles.diff.same")]})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs("div",{className:"relative",children:[s.jsx(ya,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),s.jsx("input",{type:"text",value:c,onChange:x=>u(x.target.value),placeholder:a("profiles.diff.searchFields"),className:"pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48"})]}),p.same>0&&s.jsxs("div",{className:"flex rounded overflow-hidden border border-bambu-dark-tertiary",children:[s.jsx("button",{onClick:()=>l("changes"),className:`px-3 py-1.5 text-sm transition-colors ${o==="changes"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:a("profiles.diff.changes")}),s.jsx("button",{onClick:()=>l("all"),className:`px-3 py-1.5 text-sm transition-colors ${o==="all"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:a("common.all")})]})]})]}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:f.length===0?s.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[s.jsx(eT,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),s.jsx("p",{children:a(o==="changes"?"profiles.diff.noDifferences":"profiles.diff.noFieldsMatch")})]}):s.jsxs("table",{className:"w-full",children:[s.jsx("thead",{className:"sticky top-0 bg-bambu-dark-secondary",children:s.jsxs("tr",{className:"text-sm text-bambu-gray border-b border-bambu-dark-tertiary",children:[s.jsx("th",{className:"text-left p-3 w-1/3",children:a("profiles.diff.field")}),s.jsx("th",{className:"text-left p-3 w-1/3",children:r}),s.jsx("th",{className:"text-left p-3 w-1/3",children:i})]})}),s.jsx("tbody",{children:f.map(x=>{const b={added:"bg-green-500/10",removed:"bg-red-500/10",changed:"bg-amber-500/10",same:""}[x.status],v={added:s.jsx(fr,{className:"w-3.5 h-3.5 text-green-400"}),removed:s.jsx(xj,{className:"w-3.5 h-3.5 text-red-400"}),changed:s.jsx(uj,{className:"w-3.5 h-3.5 text-amber-400"}),same:s.jsx(eT,{className:"w-3.5 h-3.5 text-bambu-gray-dark"})}[x.status];return s.jsxs("tr",{className:`border-b border-bambu-dark-tertiary ${b}`,children:[s.jsx("td",{className:"p-3",children:s.jsxs("div",{className:"flex items-center gap-2",children:[v,s.jsx("span",{className:"text-sm text-white font-mono",children:x.key})]})}),s.jsx("td",{className:"p-3",children:s.jsx("span",{className:`text-sm font-mono break-all ${x.status==="removed"?"text-red-300":x.status==="changed"?"text-white":"text-bambu-gray"}`,children:m(x.left)})}),s.jsx("td",{className:"p-3",children:s.jsx("span",{className:`text-sm font-mono break-all ${x.status==="added"?"text-green-300":x.status==="changed"?"text-white":"text-bambu-gray"}`,children:m(x.right)})})]},x.key)})})]})})]})})})}function BKe({onClose:t,initialData:e,allPresets:n,t:r}){const{showToast:i}=Vn(),a=ln(),o=!!e?.setting_id,[l,c]=_.useState("common"),[u,d]=_.useState(e?.type||"filament"),[f,p]=_.useState(e?.name?o?e.name:`${e.name} (Copy)`:""),[m,x]=_.useState(e?.base_id||""),[b,v]=_.useState(""),[y,S]=_.useState(e?.setting||{inherits:""}),[M,T]=_.useState(JSON.stringify(e?.setting||{inherits:""},null,2)),[k,C]=_.useState(null),[E,D]=_.useState(""),[A,j]=_.useState(!1),[I,F]=_.useState(""),[H,R]=_.useState(!1),[z,W]=_.useState(zre),[V,X]=_.useState(!1),[Q,ae]=_.useState(""),[$,K]=_.useState(""),[ie,re]=_.useState(!0),[xe,pe]=_.useState(null),[ue,Pe]=_.useState(!1),te=_.useMemo(()=>({filament:n.filament,print:n.process,printer:n.printer})[u]||[],[n,u]),Ee=_.useMemo(()=>te.filter(Ae=>Ry(Ae.setting_id)),[te]),{data:Oe}=ot({queryKey:["cloudFields",u],queryFn:()=>ce.getCloudFields(u==="print"?"process":u),staleTime:1e3*60*60}),{data:me}=ot({queryKey:["allPresetDetails",u,Ee.map(Ae=>Ae.setting_id).join(",")],queryFn:async()=>{const Ae={};for(let Me=0;Me{try{const ke=await ce.getCloudSettingDetail(nt.setting_id);return{id:nt.setting_id,detail:ke}}catch{return null}}))).forEach(nt=>{nt&&(Ae[nt.id]=nt.detail)})}return Ae},enabled:Ee.length>0,staleTime:1e3*60*10}),{data:Xe,isLoading:G}=ot({queryKey:["cloudSettingDetail",m],queryFn:()=>ce.getCloudSettingDetail(m),enabled:!!m});_.useEffect(()=>{l!=="json"&&T(JSON.stringify(y,null,2))},[y,l]);const Y=_.useMemo(()=>({filament:n.filament,print:n.process,printer:n.printer}[u]||[]).filter(Ue=>!Ry(Ue.setting_id)).sort((Ue,Me)=>Ue.name.localeCompare(Me.name)),[n,u]);_.useEffect(()=>{if(!m)return;const Ae=Y.find(Ue=>Ue.setting_id===m);Ae&&(v(Ae.name),o||(S({inherits:Ae.name}),T(JSON.stringify({inherits:Ae.name},null,2))))},[m,Y,o]);const de=_.useMemo(()=>{const Ae=Oe?.fields||[],Ue=new Set(Ae.map(nt=>nt.key)),Me=new Set,Ge=new Set(["inherits","updated_time","compatible_printers","compatible_prints"]);me&&Object.values(me).forEach(nt=>{nt?.setting&&Object.keys(nt.setting).forEach(ke=>{!Ue.has(ke)&&!Ge.has(ke)&&Me.add(ke)})}),Object.keys(y).forEach(nt=>{!Ue.has(nt)&&!Ge.has(nt)&&Me.add(nt)});const Ne=Array.from(Me).sort().map(nt=>({key:nt,label:nt.replace(/_/g," ").replace(/\b\w/g,ke=>ke.toUpperCase()),type:"text",category:"discovered",description:r("profiles.presets.discoveredFromPresets")}));return[...Ae,...Ne]},[Oe,me,y,r]),q=de.filter(Ae=>Ae.label.toLowerCase().includes(E.toLowerCase())||Ae.key.toLowerCase().includes(E.toLowerCase())),ee=()=>{if(I.trim()){const Ae=I.trim().toLowerCase().replace(/\s+/g,"_");U(Ae,""),F(""),R(!1),i(r("profiles.presets.toast.fieldAdded",{key:Ae}))}},U=(Ae,Ue)=>{S(Me=>{const Ge={...Me};return Ue===""||Ue===void 0?delete Ge[Ae]:Ge[Ae]=Ue,Ge})},fe=Ae=>{S(Ue=>({...Ue,...Ae.settings})),pe(Ae.name),i(r("profiles.templates.toast.applied"))},we=()=>{if(!Q.trim())return;const Ae={...y};if(delete Ae.inherits,Object.keys(Ae).length===0){i(r("profiles.presets.noOverridesToSave"),"error");return}const Ue={id:Date.now().toString(),name:Q.trim(),description:$.trim()||r("profiles.presets.customTemplate"),type:u,settings:Ae,showInModal:ie},Me=[...z,Ue];W(Me),Bre(Me),X(!1),ae(""),K(""),re(!0),i(r("profiles.templates.toast.created"))},ge=_.useMemo(()=>z.filter(Ae=>Ae.type===u&&Ae.showInModal),[u,z]),B=Ae=>{T(Ae);try{const Ue=JSON.parse(Ae);S(Ue),C(null)}catch(Ue){C(Ue.message)}},O=Ae=>{Ae.preventDefault(),j(!1);const Ue=Ae.dataTransfer.files[0];if(Ue&&Ue.name.endsWith(".json")){const Me=new FileReader;Me.onload=Ge=>{try{const Ne=Ge.target?.result,nt=JSON.parse(Ne),ke=nt.setting||nt;S(Ke=>({...Ke,...ke})),T(JSON.stringify({...y,...ke},null,2)),i(r("profiles.presets.fileImported"))}catch{i(r("profiles.presets.invalidJsonFile"),"error")}},Me.readAsText(Ue)}},J=gt({mutationFn:()=>{const Ae={...y},Ue=u==="filament"?"filament_settings_id":u==="print"?"print_settings_id":"printer_settings_id";Ae[Ue]=`"${f}"`;const Me={type:u,name:f,base_id:m,setting:Ae};return ce.createCloudSetting(Me)},onSuccess:async()=>{i(r("profiles.presets.toast.created")),await a.refetchQueries({queryKey:["cloudSettings"]}),t()},onError:Ae=>i(Ae.message,"error")}),se=gt({mutationFn:()=>{if(!e?.setting_id)throw new Error(r("profiles.presets.noSettingId"));return ce.updateCloudSetting(e.setting_id,{name:f,setting:y})},onSuccess:async()=>{i(r("profiles.presets.toast.updated")),a.removeQueries({queryKey:["cloudSettingDetail"]}),await a.refetchQueries({queryKey:["cloudSettings"]}),t()},onError:Ae=>i(Ae.message,"error")}),ve=o?se:J,_e=Xe?.setting?.inherits,ne=_e?Y.find(Ae=>Ae.name===_e):void 0,{data:Fe}=ot({queryKey:["cloudSettingDetail",ne?.setting_id],queryFn:()=>ce.getCloudSettingDetail(ne.setting_id),enabled:!!ne?.setting_id}),He=_.useMemo(()=>{const Ae=Fe?.setting||{},Ue=Xe?.setting||{},Me=m&&me?.[m]?.setting?me[m].setting:{};return{...Ae,...Ue,...Me}},[m,Xe,Fe,me]),rt=Ae=>{if(Ae==null)return"";if(Array.isArray(Ae)){const Ue=[...new Set(Ae.map(Me=>String(Me)))];return Ue.length===1?Ue[0]:Ae.join(", ")}return String(Ae)},Ie=Ae=>{const Ue=y[Ae.key],Me=He[Ae.key],Ge=rt(Me),Ne=G?r("common.loading"):Ge||"",nt="w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none";if(Ae.type==="boolean"){const ke=Ue==="1"||Ue===void 0&&Me==="1";return s.jsx("button",{type:"button",onClick:()=>U(Ae.key,Ue==="1"?"0":"1"),className:`w-8 h-5 rounded-full transition-colors ${ke?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:s.jsx("div",{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${ke?"translate-x-3.5":"translate-x-0.5"}`})})}return Ae.type==="select"?s.jsxs("select",{value:Ue||"",onChange:ke=>U(Ae.key,ke.target.value),className:nt,children:[s.jsx("option",{value:"",children:Ne}),Ae.options?.map(ke=>s.jsx("option",{value:ke.value,children:ke.label},ke.value))]}):s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:Ae.type==="number"?"number":"text",value:Ue!==void 0?String(Ue):"",onChange:ke=>U(Ae.key,ke.target.value),step:Ae.step,min:Ae.min,max:Ae.max,placeholder:Ne,className:nt}),Ae.unit&&s.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:Ae.unit})]})},be=_.useMemo(()=>Xe?.setting?Xe.setting:{},[Xe]);return s.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onDragOver:Ae=>{Ae.preventDefault(),j(!0)},onDragLeave:()=>j(!1),onDrop:O,children:[ue&&m&&s.jsx(Hre,{onClose:()=>Pe(!1),leftPreset:be,rightPreset:y,leftLabel:r("profiles.presets.baseLabel",{name:b||m}),rightLabel:r("profiles.presets.currentLabel",{name:f||r("profiles.presets.newPreset")}),t:r}),s.jsx(Nt,{className:"w-full max-w-6xl max-h-[90vh] flex flex-col",children:s.jsxs(Mt,{className:"p-0 flex flex-col h-full",children:[s.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("div",{children:[s.jsx("h2",{className:"text-xl font-semibold text-white",children:r(o?"profiles.presets.editPreset":e?"profiles.presets.duplicatePreset":"profiles.presets.createNewPreset")}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:r("profiles.presets.customizeSettings")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[m&&s.jsxs("button",{onClick:()=>Pe(!0),className:"flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",title:r("profiles.presets.compareWithBase"),children:[s.jsx(_g,{className:"w-4 h-4"}),r("profiles.presets.compare")]}),s.jsx("button",{onClick:t,className:"p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:s.jsx(Lt,{className:"w-5 h-5"})})]})]}),A&&s.jsx("div",{className:"absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10",children:s.jsxs("div",{className:"text-center",children:[s.jsx(za,{className:"w-12 h-12 text-bambu-green mx-auto mb-2"}),s.jsx("p",{className:"text-bambu-green font-medium",children:r("profiles.presets.dropJsonToImport")})]})}),s.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("common.type")}),s.jsxs("select",{value:u,onChange:Ae=>{d(Ae.target.value),x("")},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",children:[s.jsx("option",{value:"filament",children:r("profiles.presets.types.filament")}),s.jsx("option",{value:"print",children:r("profiles.presets.types.process")}),s.jsx("option",{value:"printer",children:r("profiles.presets.types.printer")})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("profiles.presets.basePreset")}),s.jsxs("select",{value:m,onChange:Ae=>x(Ae.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",children:[s.jsx("option",{value:"",children:r("profiles.presets.selectBasePreset")}),Y.map(Ae=>s.jsx("option",{value:Ae.setting_id,children:Ae.name},Ae.setting_id))]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("profiles.presets.presetName")}),s.jsx("input",{type:"text",value:f,onChange:Ae=>p(Ae.target.value),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",placeholder:r("profiles.presets.myCustomPreset")})]})]}),b&&s.jsx("div",{className:"text-xs text-bambu-gray",children:s.jsxs("p",{className:"flex items-center gap-1",children:[s.jsx(Na,{className:"w-3 h-3 text-bambu-green"}),r("profiles.presets.inheritsFrom")," ",s.jsx("span",{className:"text-white",children:b}),G&&s.jsx(pt,{className:"w-3 h-3 animate-spin ml-1"})]})})]}),s.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary",children:[s.jsxs("button",{onClick:()=>c("common"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="common"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[s.jsx(Oz,{className:"w-4 h-4"}),r("profiles.presets.tabs.common")]}),s.jsxs("button",{onClick:()=>c("fields"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="fields"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[s.jsx(pM,{className:"w-4 h-4"}),r("profiles.presets.tabs.allFields")]}),s.jsxs("button",{onClick:()=>c("json"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="json"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[s.jsx(yW,{className:"w-4 h-4"}),"JSON",k&&s.jsx($i,{className:"w-3 h-3 text-red-400"})]}),s.jsx("div",{className:"flex-1"}),s.jsxs("button",{onClick:()=>{const Ae={name:f,type:u,base_id:m,setting:y},Ue=new Blob([JSON.stringify(Ae,null,2)],{type:"application/json"}),Me=URL.createObjectURL(Ue),Ge=document.createElement("a");Ge.href=Me,Ge.download=`${f||"preset"}.json`,document.body.appendChild(Ge),Ge.click(),document.body.removeChild(Ge),URL.revokeObjectURL(Me),i(r("profiles.presets.toast.exported"))},className:"flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors",title:r("profiles.presets.exportToJson"),children:[s.jsx(wi,{className:"w-4 h-4"}),r("common.download")]}),s.jsxs("button",{onClick:()=>document.getElementById("file-import")?.click(),className:"flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors",title:r("profiles.presets.importFromJson"),children:[s.jsx(za,{className:"w-4 h-4"}),r("common.upload")]}),s.jsx("input",{id:"file-import",type:"file",accept:".json",className:"hidden",onChange:Ae=>{const Ue=Ae.target.files?.[0];if(Ue){const Me=new FileReader;Me.onload=Ge=>{try{const Ne=JSON.parse(Ge.target?.result),nt=Ne.setting||Ne;S(ke=>({...ke,...nt})),i(r("profiles.presets.fileImported"))}catch{i(r("profiles.presets.invalidJson"),"error")}},Me.readAsText(Ue)}}})]}),s.jsxs("div",{className:"flex-1 overflow-y-auto p-4",children:[l==="common"&&s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[s.jsx(W0,{className:"w-4 h-4 text-amber-400"}),r("profiles.templates.title")]}),Object.keys(y).filter(Ae=>Ae!=="inherits").length>0&&s.jsxs("button",{onClick:()=>X(!V),className:"text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors",children:[s.jsx(hs,{className:"w-3 h-3"}),r("profiles.presets.saveAsTemplate")]})]}),V&&s.jsxs("div",{className:"mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-2",children:[s.jsx("input",{type:"text",value:Q,onChange:Ae=>ae(Ae.target.value),placeholder:r("profiles.templates.namePlaceholder"),className:"px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",autoFocus:!0}),s.jsx("input",{type:"text",value:$,onChange:Ae=>K(Ae.target.value),placeholder:r("profiles.templates.descriptionPlaceholder"),className:"px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(Te,{size:"sm",onClick:we,disabled:!Q.trim(),children:[s.jsx(hs,{className:"w-3 h-3"}),r("common.save")]}),s.jsx(Te,{size:"sm",variant:"secondary",onClick:()=>X(!1),children:r("common.cancel")})]}),s.jsxs("button",{onClick:()=>re(!ie),className:`flex items-center gap-1.5 text-xs transition-colors ${ie?"text-bambu-green":"text-bambu-gray hover:text-white"}`,children:[ie?s.jsx(mc,{className:"w-3.5 h-3.5"}):s.jsx(cM,{className:"w-3.5 h-3.5"}),r(ie?"profiles.templates.shownInModals":"profiles.templates.hiddenInModals")]})]})]}),xe&&s.jsxs("div",{className:"mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2",children:[s.jsx(Na,{className:"w-4 h-4 text-bambu-green"}),s.jsxs("span",{className:"text-sm text-bambu-green",children:[r("profiles.presets.templateApplied")," ",s.jsx("span",{className:"font-medium",children:xe})]}),s.jsx("button",{onClick:()=>pe(null),className:"ml-auto text-bambu-green/70 hover:text-bambu-green",children:s.jsx(Lt,{className:"w-4 h-4"})})]}),s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[ge.map(Ae=>s.jsxs("button",{onClick:()=>fe(Ae),className:"p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors",children:[s.jsx("p",{className:"text-sm font-medium text-white",children:Ae.name}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:Ae.description})]},Ae.id)),ge.length===0&&s.jsx("p",{className:"col-span-3 text-center text-bambu-gray text-sm py-4",children:r("profiles.presets.noTemplatesSelected")})]}),s.jsx("p",{className:"text-xs text-bambu-gray-dark mt-2 text-center",children:r("profiles.presets.manageTemplatesHint")})]}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:r("profiles.presets.commonSettings")}),s.jsx("div",{className:"grid grid-cols-2 gap-x-6 gap-y-3",children:de.slice(0,10).map(Ae=>s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("label",{className:"text-sm text-bambu-gray flex-shrink-0",children:Ae.label}),s.jsx("div",{className:"w-48",children:Ie(Ae)})]},Ae.key))})]}),Object.keys(y).length>1&&s.jsxs("div",{children:[s.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:r("profiles.presets.currentOverrides")}),s.jsx("div",{className:"flex flex-wrap gap-2",children:Object.entries(y).filter(([Ae])=>Ae!=="inherits").map(([Ae,Ue])=>s.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded",children:[Ae,": ",String(Ue).slice(0,20),s.jsx("button",{onClick:()=>U(Ae,void 0),className:"hover:text-white",children:s.jsx(Lt,{className:"w-3 h-3"})})]},Ae))})]})]}),l==="fields"&&s.jsxs("div",{className:"grid grid-cols-2 gap-6",style:{height:"400px"},children:[s.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[s.jsx("h3",{className:"text-sm font-medium text-white",children:r("profiles.presets.availableFields")}),s.jsx("span",{className:"text-xs text-bambu-gray",children:me?r("profiles.templates.fieldsCount",{count:de.length}):r("common.loading")})]}),s.jsxs("div",{className:"relative mb-3 flex-shrink-0",children:[s.jsx(ya,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),s.jsx("input",{type:"text",value:E,onChange:Ae=>D(Ae.target.value),placeholder:r("profiles.presets.searchFieldsPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none"})]}),s.jsxs("div",{className:"flex-1 overflow-y-auto space-y-1 pr-2 min-h-0",children:[q.filter(Ae=>!(Ae.key in y)).map(Ae=>{const Ue=He[Ae.key],Me=rt(Ue);return s.jsxs("div",{onClick:()=>{S(Ge=>({...Ge,[Ae.key]:Me||""}))},className:"flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"text-sm text-white truncate",children:Ae.label}),s.jsx("p",{className:"text-xs text-bambu-gray-dark truncate",children:Ae.key})]}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[Me&&s.jsxs("span",{className:"text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate",title:Me,children:[Me.slice(0,20),Me.length>20?"...":""]}),s.jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors",children:s.jsx(fr,{className:"w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors"})})]})]},Ae.key)}),q.filter(Ae=>!(Ae.key in y)).length===0&&s.jsx("p",{className:"text-center text-bambu-gray py-4 text-sm",children:r(E?"profiles.presets.noMatchingFields":"profiles.presets.allFieldsAdded")})]}),s.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0",children:H?s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{type:"text",value:I,onChange:Ae=>F(Ae.target.value),onKeyDown:Ae=>Ae.key==="Enter"&&ee(),placeholder:"custom_field_name",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",autoFocus:!0}),s.jsx(Te,{size:"sm",onClick:ee,disabled:!I.trim(),children:s.jsx(fr,{className:"w-4 h-4"})}),s.jsx(Te,{size:"sm",variant:"secondary",onClick:()=>{R(!1),F("")},children:s.jsx(Lt,{className:"w-4 h-4"})})]}):s.jsxs("button",{onClick:()=>R(!0),className:"w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors",children:[s.jsx(fr,{className:"w-4 h-4"}),r("profiles.presets.addCustomField")]})})]}),s.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[s.jsx("h3",{className:"text-sm font-medium text-white",children:r("profiles.presets.yourOverrides")}),s.jsx("span",{className:"text-xs text-bambu-gray",children:r("profiles.templates.fieldsCount",{count:Object.keys(y).filter(Ae=>Ae!=="inherits").length})})]}),s.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2 pr-2 min-h-0",children:[Object.entries(y).filter(([Ae])=>Ae!=="inherits").map(([Ae,Ue])=>{const Me=de.find(Ge=>Ge.key===Ae);return s.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm font-medium text-white",children:Me?.label||Ae}),s.jsx("p",{className:"text-xs text-bambu-gray-dark",children:Ae})]}),s.jsx("button",{onClick:()=>U(Ae,void 0),className:"p-1 text-bambu-gray hover:text-red-400 transition-colors",children:s.jsx(Lt,{className:"w-4 h-4"})})]}),Me?Ie(Me):s.jsx("input",{type:"text",value:String(Ue),onChange:Ge=>U(Ae,Ge.target.value),className:"w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]},Ae)}),Object.keys(y).filter(Ae=>Ae!=="inherits").length===0&&s.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[s.jsx(Oz,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),s.jsx("p",{className:"text-sm",children:r("profiles.presets.noOverridesYet")}),s.jsx("p",{className:"text-xs mt-1",children:r("profiles.presets.clickFieldsToAdd")})]})]}),Object.keys(y).filter(Ae=>Ae!=="inherits").length>0&&s.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0",children:s.jsxs("button",{onClick:()=>{X(!0),c("common")},className:"w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors",children:[s.jsx(hs,{className:"w-4 h-4"}),r("profiles.presets.saveAsTemplate")]})})]})]}),l==="json"&&s.jsxs("div",{className:"space-y-2",children:[k&&s.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm",children:[s.jsx($i,{className:"w-4 h-4"}),k]}),s.jsx("textarea",{value:M,onChange:Ae=>B(Ae.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${k?"border-red-500 focus:border-red-500":"border-bambu-dark-tertiary focus:border-bambu-green"}`,spellCheck:!1}),s.jsx("p",{className:"text-xs text-bambu-gray",children:r("profiles.presets.jsonTip")})]})]}),s.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex gap-2",children:[s.jsx(Te,{variant:"secondary",onClick:t,className:"flex-1",children:r("common.cancel")}),s.jsxs(Te,{onClick:()=>ve.mutate(),disabled:ve.isPending||!f.trim()||!o&&!m||!!k,className:"flex-1",children:[ve.isPending?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):o?s.jsx(hs,{className:"w-4 h-4"}):s.jsx(fr,{className:"w-4 h-4"}),r(o?"common.save":e?"common.duplicate":"common.create")]})]})]})})]})}function HKe({settings:t,lastSyncTime:e,onRefresh:n,isRefreshing:r,printers:i,hasPermission:a,t:o}){const[l,c]=_.useState(""),[u,d]=_.useState("all"),[f,p]=_.useState("all"),[m,x]=_.useState("all"),[b,v]=_.useState("all"),[y,S]=_.useState("all"),[M,T]=_.useState("all"),[k,C]=_.useState(null),[E,D]=_.useState(!1),[A,j]=_.useState(!1),[I,F]=_.useState(null),[H,R]=_.useState(null),[z,W]=_.useState(null),[V,X]=_.useState(!1),[Q,ae]=_.useState([null,null]),[$,K]=_.useState(!1),[ie,re]=_.useState(null),xe=ln(),pe=_.useMemo(()=>[...t.filament.map(ee=>({...ee,type:"filament"})),...t.printer.map(ee=>({...ee,type:"printer"})),...t.process.map(ee=>({...ee,type:"process"}))].map(ee=>({...ee,meta:cF(ee.name)})),[t]),ue=_.useMemo(()=>{const q=new Set,ee=new Set,U=new Set;return pe.forEach(fe=>{fe.meta.nozzle&&q.add(fe.meta.nozzle),fe.meta.filamentType&&ee.add(fe.meta.filamentType),fe.meta.layerHeight&&U.add(fe.meta.layerHeight)}),{printers:i.map(fe=>({id:fe.id.toString(),name:fe.name})),nozzles:Array.from(q).sort((fe,we)=>parseFloat(fe)-parseFloat(we)),filaments:Array.from(ee).sort(),layerHeights:Array.from(U).sort((fe,we)=>parseFloat(fe)-parseFloat(we))}},[pe,i]),Pe=_.useMemo(()=>m==="all"?null:i.find(ee=>ee.id.toString()===m)?.model||null,[m,i]),te=_.useMemo(()=>pe.filter(q=>u==="all"||q.type===u).filter(q=>{if(f==="all")return!0;const ee=Ry(q.setting_id);return f==="custom"?ee:!ee}).filter(q=>{if(m==="all"||!Pe)return!0;const ee=q.meta.printer?.toLowerCase()||"",U=Pe.toLowerCase();return ee.includes(U)||U.includes(ee)}).filter(q=>b==="all"||q.meta.nozzle===b).filter(q=>y==="all"||q.meta.filamentType===y).filter(q=>M==="all"||q.meta.layerHeight===M).filter(q=>l===""||q.name.toLowerCase().includes(l.toLowerCase())).sort((q,ee)=>q.name.localeCompare(ee.name)),[pe,u,f,m,Pe,b,y,M,l]),Ee=q=>{if(V){const ee=Q[0]?.setting_id===q.setting_id,U=Q[1]?.setting_id===q.setting_id;if(ee)ae([Q[1],null]);else if(U)ae([Q[0],null]);else if(!Q[0])ae([q,null]);else if(Q[1]){if(Q[0].type!==q.type)return;ae([Q[0],q])}else{if(Q[0].type!==q.type)return;ae([Q[0],q])}}else C(q)},Oe=q=>{if(Q[0]?.setting_id===q.setting_id)return 0;if(Q[1]?.setting_id===q.setting_id)return 1},me=async q=>{try{const ee=await ce.getCloudSettingDetail(q.setting_id),U=q.type==="process"?"print":q.type;F({type:U,name:q.name,base_id:ee.base_id||"GFSA00",setting:ee.setting||{}}),C(null)}catch(ee){console.error("Failed to fetch preset details for duplication:",ee)}},Xe=async q=>{try{xe.removeQueries({queryKey:["cloudSettingDetail",q.setting_id]});const ee=await ce.getCloudSettingDetail(q.setting_id),U=q.type==="process"?"print":q.type;R({type:U,name:q.name,base_id:ee.base_id||"GFSA00",setting:ee.setting||{},setting_id:q.setting_id}),C(null)}catch(ee){console.error("Failed to fetch preset details for editing:",ee)}},G=()=>{d("all"),p("all"),x("all"),v("all"),S("all"),T("all"),c("")},Y=u!=="all"||f!=="all"||m!=="all"||b!=="all"||y!=="all"||M!=="all"||l!=="",de=t.filament.length+t.printer.length+t.process.length;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"space-y-4 mb-6",children:[s.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[s.jsxs("div",{className:"relative flex-1",children:[s.jsx(ya,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),s.jsx("input",{type:"text",value:l,onChange:q=>c(q.target.value),placeholder:o("profiles.cloudView.searchPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none"})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(Te,{variant:V?"primary":"secondary",onClick:()=>{V?(X(!1),ae([null,null])):X(!0)},children:[s.jsx(_g,{className:"w-4 h-4"}),o(V?"common.cancel":"profiles.presets.compare")]}),s.jsxs(Te,{variant:"secondary",onClick:()=>j(!0),disabled:!a("cloud:auth"),title:a("cloud:auth")?void 0:o("profiles.cloudView.noTemplatesPermission"),children:[s.jsx(W0,{className:"w-4 h-4"}),o("profiles.cloudView.templates")]}),s.jsxs(Te,{variant:"secondary",onClick:n,disabled:r||!a("cloud:auth"),title:a("cloud:auth")?void 0:o("profiles.cloudView.noRefreshPermission"),children:[s.jsx(Rr,{className:`w-4 h-4 ${r?"animate-spin":""}`}),o("profiles.cloudView.refresh")]}),s.jsxs(Te,{onClick:()=>D(!0),disabled:!a("cloud:auth"),title:a("cloud:auth")?void 0:o("profiles.cloudView.noCreatePermission"),children:[s.jsx(fr,{className:"w-4 h-4"}),o("profiles.cloudView.newPreset")]})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(dM,{className:"w-4 h-4 text-bambu-gray"}),s.jsx(rg,{label:o("profiles.cloudView.filters.type"),value:u,options:[{value:"all",label:o("profiles.cloudView.filters.all"),count:de},{value:"filament",label:o("profiles.cloudView.filters.filament"),count:t.filament.length},{value:"printer",label:o("profiles.cloudView.filters.printer"),count:t.printer.length},{value:"process",label:o("profiles.cloudView.filters.process"),count:t.process.length}],onChange:q=>d(q)}),s.jsx(rg,{label:o("profiles.cloudView.filters.owner"),value:f,options:[{value:"all",label:o("profiles.cloudView.filters.all")},{value:"custom",label:o("profiles.cloudView.filters.myPresets")},{value:"builtin",label:o("profiles.cloudView.filters.builtIn")}],onChange:q=>p(q)}),ue.printers.length>0&&s.jsx(rg,{label:o("profiles.cloudView.filters.printer"),value:m,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...ue.printers.map(q=>({value:q.id,label:q.name}))],onChange:x}),ue.nozzles.length>0&&s.jsx(rg,{label:o("profiles.cloudView.filters.nozzle"),value:b,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...ue.nozzles.map(q=>({value:q,label:q}))],onChange:v}),ue.filaments.length>0&&(u==="all"||u==="filament")&&s.jsx(rg,{label:o("profiles.cloudView.filters.filament"),value:y,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...ue.filaments.map(q=>({value:q,label:q}))],onChange:S}),ue.layerHeights.length>0&&(u==="all"||u==="process")&&s.jsx(rg,{label:o("profiles.cloudView.filters.layer"),value:M,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...ue.layerHeights.map(q=>({value:q,label:q}))],onChange:T}),Y&&s.jsx("button",{onClick:G,className:"px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:o("profiles.cloudView.clearFilters")})]})]}),V&&s.jsx("div",{className:"mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsx(_g,{className:"w-5 h-5 text-blue-400"}),s.jsx("span",{className:"text-white font-medium",children:o("profiles.cloudView.compareMode")}),s.jsx("span",{className:"text-bambu-gray",children:Q[0]?o("profiles.cloudView.selectAnotherPreset",{type:Q[0].type}):o("profiles.cloudView.clickTwoPresets")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${Q[0]?"bg-blue-500/30 text-blue-700 dark:text-blue-300":"bg-bambu-dark text-bambu-gray"}`,children:Q[0]?Q[0].name:o("profiles.cloudView.selectFirst")}),s.jsx(uj,{className:"w-4 h-4 text-bambu-gray"}),s.jsx("span",{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${Q[1]?"bg-blue-500/30 text-blue-700 dark:text-blue-300":"bg-bambu-dark text-bambu-gray"}`,children:Q[1]?Q[1].name:o("profiles.cloudView.selectSecond")})]}),Q[0]&&Q[1]&&s.jsxs(Te,{size:"sm",onClick:async()=>{try{const[q,ee]=await Promise.all([ce.getCloudSettingDetail(Q[0].setting_id),ce.getCloudSettingDetail(Q[1].setting_id)]);re([q.setting||{},ee.setting||{}]),K(!0)}catch{}},children:[s.jsx(_g,{className:"w-4 h-4"}),o("profiles.cloudView.compareNow")]})]})]})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray",children:[e&&s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(nr,{className:"w-3 h-3"}),o("profiles.cloudView.lastSynced")," ",LKe(e.toISOString(),o)]}),s.jsx("span",{children:o("profiles.cloudView.showingCount",{showing:te.length,total:de})}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-bambu-green"}),s.jsxs("span",{children:["= ",o("profiles.presets.myPreset")]})]})]}),te.length===0?s.jsxs("div",{className:"text-center py-16",children:[s.jsx(sl,{className:"w-12 h-12 text-bambu-gray-dark mx-auto mb-4"}),s.jsx("p",{className:"text-bambu-gray",children:o("profiles.cloudView.noPresetsFound")}),Y&&s.jsx("button",{onClick:G,className:"mt-2 text-sm text-bambu-green hover:text-bambu-green-light",children:o("profiles.cloudView.clearFilters")})]}):s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[s.jsx(TR,{className:"w-4 h-4 text-amber-400"}),s.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.filament")}),s.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",te.filter(q=>q.type==="filament").length,")"]})]}),s.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[te.filter(q=>q.type==="filament").map(q=>s.jsx(GP,{setting:q,onClick:()=>Ee(q),onDuplicate:()=>me(q),compareMode:V,isCompareSelected:Oe(q)!==void 0,compareIndex:Oe(q),compareDisabled:V&&!!Q[0]&&Q[0].type!==q.type,t:o},q.setting_id)),te.filter(q=>q.type==="filament").length===0&&s.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noFilamentPresets")})]})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[s.jsx(vh,{className:"w-4 h-4 text-blue-400"}),s.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.process")}),s.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",te.filter(q=>q.type==="process").length,")"]})]}),s.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[te.filter(q=>q.type==="process").map(q=>s.jsx(GP,{setting:q,onClick:()=>Ee(q),onDuplicate:()=>me(q),compareMode:V,isCompareSelected:Oe(q)!==void 0,compareIndex:Oe(q),compareDisabled:V&&!!Q[0]&&Q[0].type!==q.type,t:o},q.setting_id)),te.filter(q=>q.type==="process").length===0&&s.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noProcessPresets")})]})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[s.jsx(Pr,{className:"w-4 h-4 text-purple-400"}),s.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.printer")}),s.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",te.filter(q=>q.type==="printer").length,")"]})]}),s.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[te.filter(q=>q.type==="printer").map(q=>s.jsx(GP,{setting:q,onClick:()=>Ee(q),onDuplicate:()=>me(q),compareMode:V,isCompareSelected:Oe(q)!==void 0,compareIndex:Oe(q),compareDisabled:V&&!!Q[0]&&Q[0].type!==q.type,t:o},q.setting_id)),te.filter(q=>q.type==="printer").length===0&&s.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noPrinterPresets")})]})]})]}),k&&s.jsx(UKe,{setting:k,onClose:()=>C(null),onDeleted:()=>C(null),onDuplicate:()=>me(k),onEdit:()=>Xe(k),hasPermission:a,t:o}),(E||I||H||z)&&s.jsx(BKe,{onClose:()=>{D(!1),F(null),R(null),W(null)},initialData:H||I||(z?{type:z.type,name:"",base_id:"",setting:z.setting}:void 0),allPresets:t,t:o}),A&&s.jsx(zKe,{onClose:()=>j(!1),onApply:q=>{W({type:q.type,setting:q.settings}),j(!1)},t:o}),$&&ie&&Q[0]&&Q[1]&&s.jsx(Hre,{onClose:()=>{K(!1),re(null)},leftPreset:ie[0],rightPreset:ie[1],leftLabel:Q[0].name,rightLabel:Q[1].name,t:o})]})}function $Ke(){const{t}=On(),e=ln(),{showToast:n}=Vn(),{hasPermission:r}=Ci(),[i,a]=_.useState("cloud"),[o,l]=_.useState(),{data:c,isLoading:u}=ot({queryKey:["cloudStatus"],queryFn:ce.getCloudStatus}),{data:d=[]}=ot({queryKey:["printers"],queryFn:ce.getPrinters}),{data:f,isLoading:p,refetch:m,dataUpdatedAt:x}=ot({queryKey:["cloudSettings"],queryFn:()=>ce.getCloudSettings(),enabled:!!c?.is_authenticated,retry:!1,staleTime:1e3*60*5});_.useEffect(()=>{x&&l(new Date(x))},[x]);const b=gt({mutationFn:ce.cloudLogout,onSuccess:()=>{e.invalidateQueries({queryKey:["cloudStatus"]}),e.removeQueries({queryKey:["cloudSettings"]}),n(t("profiles.toast.loggedOut"))}}),v=()=>{e.invalidateQueries({queryKey:["cloudStatus"]})};return u?s.jsx("div",{className:"p-4 md:p-8 flex items-center justify-center min-h-[400px]",children:s.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):s.jsxs("div",{className:"p-6 lg:p-8",children:[s.jsxs("div",{className:"mb-6",children:[s.jsx("h1",{className:"text-2xl font-bold text-white",children:t("profiles.title")}),s.jsx("p",{className:"text-bambu-gray",children:t("profiles.subtitle")})]}),s.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary mb-6",children:[s.jsxs("button",{onClick:()=>a("cloud"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i==="cloud"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[s.jsx(lM,{className:"w-4 h-4"}),t("profiles.tabs.cloud")]}),s.jsxs("button",{onClick:()=>a("kprofiles"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i==="kprofiles"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[s.jsx(hM,{className:"w-4 h-4"}),t("profiles.tabs.kprofiles")]})]}),i==="cloud"&&s.jsxs(s.Fragment,{children:[c?.is_authenticated&&s.jsxs("div",{className:"flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-2 h-2 rounded-full bg-bambu-green animate-pulse"}),s.jsxs("span",{className:"text-sm text-bambu-gray",children:[t("profiles.connectedAs")," ",s.jsx("span",{className:"text-white",children:c.email})]})]}),s.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>b.mutate(),disabled:b.isPending||!r("cloud:auth"),title:r("cloud:auth")?void 0:t("profiles.noLogoutPermission"),children:[s.jsx(gj,{className:"w-4 h-4"}),t("profiles.logout")]})]}),c?.is_authenticated?p?s.jsx("div",{className:"flex items-center justify-center py-16",children:s.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):f?s.jsx(HKe,{settings:f,lastSyncTime:o,onRefresh:()=>m(),isRefreshing:p,printers:d,hasPermission:r,t}):s.jsxs("div",{className:"text-center py-16",children:[s.jsx("p",{className:"text-bambu-gray mb-4",children:t("profiles.failedToLoad")}),s.jsx(Te,{onClick:()=>m(),children:t("profiles.retry")})]}):s.jsx(FKe,{onSuccess:v,t})]}),i==="kprofiles"&&s.jsx(OKe,{}),s.jsx(IKe,{})]})}const g0={Droplet:TR,Flame:Iue,Ruler:xhe,Sparkles:W0,Square:ll,Cable:Pce,Wrench:om,Calendar:ti,Timer:bu,Cog:due,Fan:vW,Zap:_h,Wind:RW,Thermometer:bM,Layers:sl,Box:oo,Target:PW,RefreshCw:Rr,Settings:xM,Filter:dM,CircleDot:Yce};function z0(t){return t&&g0[t]||om}function ig(t,e,n){if(e==="days"){if(t<1)return n?n("common.today"):"Today";if(t===1)return n?n("maintenance.day"):"1 day";if(t<7){const i=Math.round(t);return n?n("maintenance.days",{count:i}):`${i} days`}if(t<180){const i=Math.round(t/7);return i===1?n?n("maintenance.week"):"1 week":n?n("maintenance.weeks",{count:i}):`${i} weeks`}const r=Math.round(t/30);return r===1?n?n("maintenance.month"):"1 month":n?n("maintenance.months",{count:r}):`${r} months`}else{if(t<1)return`${Math.round(t*60)}m`;if(t<24)return`${t<10?t.toFixed(1):Math.round(t)}h`;const r=t/24;if(r<7)return`${r<2?r.toFixed(1):Math.round(r)}d`;const i=r/7;return i<12?`${i<2?i.toFixed(1):Math.round(i)}w`:`${Math.round(i/4)}mo`}}function qP(t,e,n){return e==="days"?t===1?n?n("maintenance.day"):"1 day":t===7?n?n("maintenance.week"):"1 week":t===14?n?n("maintenance.weeks",{count:2}):"2 weeks":t===30?n?n("maintenance.month"):"1 month":t===60?n?n("maintenance.months",{count:2}):"2 months":t===90?n?n("maintenance.months",{count:3}):"3 months":t===180?n?n("maintenance.months",{count:6}):"6 months":t===365?n?n("maintenance.year"):"1 year":n?n("maintenance.days",{count:t}):`${t} days`:`${t}h`}function VKe(t,e){const n=(e||"").toUpperCase().replace(/[- ]/g,""),r=n.includes("X1"),i=n.includes("P1"),a=n.includes("A1MINI"),o=n.includes("A1")&&!a,l=n.includes("H2D"),c=n.includes("H2C"),u=n.includes("H2S"),d=l||c||u,f=n.includes("P2S");switch(t){case"Lubricate Linear Rails":return r?"https://wiki.bambulab.com/en/x1/maintenance/basic-maintenance":i?"https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance":a?"https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis":o?"https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis":d?"https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication":f?"https://wiki.bambulab.com/en/p2s/maintenance/belt-tension":"https://wiki.bambulab.com/en/general/lead-screws-lubrication";case"Clean Nozzle/Hotend":return r||i?"https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog":a||o?"https://wiki.bambulab.com/en/a1-mini/troubleshooting/nozzle-clog":d?"https://wiki.bambulab.com/en/h2/maintenance/nozzl-cold-pull-maintenance-and-cleaning":f?"https://wiki.bambulab.com/en/p2s/maintenance/cold-pull-maintenance-hotend":"https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog";case"Check Belt Tension":return r?"https://wiki.bambulab.com/en/x1/maintenance/belt-tension":i?"https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance":a?"https://wiki.bambulab.com/en/a1-mini/maintenance/belt_tension":o?"https://wiki.bambulab.com/en/a1/maintenance/belt_tension":l?"https://wiki.bambulab.com/en/h2/maintenance/belt-tension":c?"https://wiki.bambulab.com/en/h2c/maintenance/belt-tension":u?"https://wiki.bambulab.com/en/h2s/maintenance/belt-tension":f?"https://wiki.bambulab.com/en/p2s/maintenance/belt-tension":"https://wiki.bambulab.com/en/x1/maintenance/belt-tension";case"Clean Carbon Rods":return r||i?"https://wiki.bambulab.com/en/general/carbon-rods-clearance":a||o||d||f?null:"https://wiki.bambulab.com/en/general/carbon-rods-clearance";case"Clean Build Plate":return"https://wiki.bambulab.com/en/filament-acc/acc/pei-plate-clean-guide";case"Check PTFE Tube":return r||i?"https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube":a||o?"https://wiki.bambulab.com/en/a1-mini/maintenance/ptfe-tube":l?"https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer":u?"https://wiki.bambulab.com/en/h2s/maintenance/replace-ptfe-tube-on-h2s-printer":c?"https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer":"https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube";case"Replace HEPA Filter":case"HEPA Filter":case"Replace Carbon Filter":case"Carbon Filter":return d?"https://wiki.bambulab.com/en/h2/maintenance/replace-smoke-purifier-air-filte":"https://wiki.bambulab.com/en/x1/maintenance/replace-carbon-filter";case"Lubricate Left Nozzle Rail":case"Left Nozzle Rail":return d?"https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication":null;default:return null}}function GKe({item:t,onPerform:e,onToggle:n,hasPermission:r,t:i}){const a=z0(t.maintenance_type_icon),o=t.interval_type||"hours",c=(()=>{if(o==="days"){const m=t.days_since_maintenance??0;return Math.max(0,Math.min(100,m/t.interval_hours*100))}return Math.max(0,Math.min(100,(t.interval_hours-t.hours_until_due)/t.interval_hours*100))})(),u=()=>t.enabled?t.is_due?"text-red-400":t.is_warning?"text-amber-400":"text-bambu-green":"text-bambu-gray",d=()=>t.enabled?t.is_due?"bg-red-500":t.is_warning?"bg-amber-500":"bg-bambu-green":"bg-bambu-gray/30",f=()=>t.enabled?t.is_due?"bg-red-500/5 border-red-500/20":t.is_warning?"bg-amber-500/5 border-amber-500/20":"bg-bambu-dark-secondary border-bambu-dark-tertiary":"bg-bambu-dark-secondary/50",p=()=>{if(!t.enabled)return i("common.disabled");if(o==="days"){const m=t.days_until_due??0;return t.is_due?i("maintenance.overdueBy",{duration:ig(Math.abs(m),"days",i)}):t.is_warning?i("maintenance.dueIn",{duration:ig(m,"days",i)}):i("maintenance.timeLeft",{duration:ig(m,"days",i)})}else return t.is_due?i("maintenance.overdueBy",{duration:ig(Math.abs(t.hours_until_due),"hours",i)}):t.is_warning?i("maintenance.dueIn",{duration:ig(t.hours_until_due,"hours",i)}):i("maintenance.timeLeft",{duration:ig(t.hours_until_due,"hours",i)})};return s.jsx("div",{className:`rounded-xl border p-4 transition-all ${f()}`,children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsxs("div",{className:`relative p-2.5 rounded-lg ${t.is_due?"bg-red-500/20":t.is_warning?"bg-amber-500/20":t.enabled?"bg-bambu-dark":"bg-bambu-dark/50"}`,children:[s.jsx(a,{className:`w-5 h-5 ${u()}`}),t.enabled&&(t.is_due||t.is_warning)&&s.jsx("span",{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${t.is_due?"bg-red-500":"bg-amber-500"} animate-pulse`})]}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:`font-medium truncate ${t.enabled?"text-white":"text-bambu-gray"}`,children:t.maintenance_type_name}),o==="days"&&s.jsx("span",{title:i("maintenance.timeBasedInterval"),children:s.jsx(ti,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"})}),(()=>{const m=t.maintenance_type_wiki_url||VKe(t.maintenance_type_name,t.printer_model);return m?s.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-bambu-green transition-colors shrink-0",title:i("maintenance.viewDocumentation"),onClick:x=>x.stopPropagation(),children:s.jsx(Xr,{className:"w-3.5 h-3.5"})}):null})()]}),s.jsx("div",{className:"mt-2 mb-1.5",children:s.jsx("div",{className:"w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden",children:s.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${d()}`,style:{width:`${c}%`}})})}),s.jsxs("div",{className:`text-xs flex items-center gap-1 ${u()}`,children:[t.is_due&&s.jsx(Sn,{className:"w-3 h-3"}),t.is_warning&&!t.is_due&&s.jsx(nr,{className:"w-3 h-3"}),!t.is_due&&!t.is_warning&&t.enabled&&s.jsx(Na,{className:"w-3 h-3"}),p()]})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsx("span",{title:r("maintenance:update")?void 0:i("maintenance.noPermissionUpdate"),children:s.jsx(In,{checked:t.enabled,onChange:m=>n(t.id,m),disabled:!r("maintenance:update")})}),s.jsxs(Te,{size:"sm",variant:t.is_due?"primary":"secondary",onClick:()=>e(t.id),disabled:!t.enabled||!r("maintenance:update"),title:r("maintenance:update")?void 0:i("maintenance.noPermissionPerform"),className:"!px-3",children:[s.jsx(Oh,{className:"w-3.5 h-3.5"}),i("common.reset")]})]})]})})}function qKe({overview:t,onPerform:e,onToggle:n,onSetHours:r,hasPermission:i,t:a}){const[o,l]=_.useState(!0),[c,u]=_.useState(!1),[d,f]=_.useState(t.total_print_hours.toFixed(1)),p=[...t.maintenance_items].sort((b,v)=>b.is_due&&!v.is_due?-1:!b.is_due&&v.is_due?1:b.is_warning&&!v.is_warning?-1:!b.is_warning&&v.is_warning?1:b.maintenance_type_id-v.maintenance_type_id),m=p.find(b=>b.enabled&&(b.is_due||b.is_warning)),x=()=>{const b=parseFloat(d);!isNaN(b)&&b>=0&&(r(t.printer_id,b),u(!1))};return s.jsxs(Nt,{className:"overflow-hidden",children:[s.jsxs("div",{className:"p-5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsx("h2",{className:"text-xl font-semibold text-white",children:t.printer_name}),s.jsxs("div",{className:"flex items-center gap-2",children:[t.due_count>0&&s.jsxs("span",{className:"px-2.5 py-1 bg-red-500/20 text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5",children:[s.jsx(Sn,{className:"w-3 h-3"}),a("maintenance.overdueCount",{count:t.due_count})]}),t.warning_count>0&&s.jsxs("span",{className:"px-2.5 py-1 bg-amber-500/20 text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5",children:[s.jsx(nr,{className:"w-3 h-3"}),a("maintenance.dueSoonCount",{count:t.warning_count})]}),t.due_count===0&&t.warning_count===0&&s.jsxs("span",{className:"px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5",children:[s.jsx(Na,{className:"w-3 h-3"}),a("maintenance.allGood")]})]})]}),s.jsxs("button",{onClick:()=>l(!o),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors",children:[o?s.jsx(yh,{className:"w-4 h-4"}):s.jsx(Kr,{className:"w-4 h-4"}),a(o?"common.collapse":"common.expand")]})]}),s.jsxs("div",{className:"flex items-center gap-6 mt-4",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"p-2 bg-bambu-dark/50 rounded-lg",children:s.jsx(bu,{className:"w-4 h-4 text-bambu-gray"})}),c?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",value:d,onChange:b=>f(b.target.value),onKeyDown:b=>{b.key==="Enter"&&x(),b.key==="Escape"&&u(!1)},className:"w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm",min:"0",step:"1",autoFocus:!0}),s.jsx("span",{className:"text-xs text-bambu-gray",children:a("common.hours")}),s.jsx(Te,{size:"sm",onClick:x,children:a("common.save")}),s.jsx(Te,{size:"sm",variant:"secondary",onClick:()=>u(!1),children:a("common.cancel")})]}):s.jsxs("button",{onClick:()=>{i("maintenance:update")&&(f(Math.round(t.total_print_hours).toString()),u(!0))},className:`group ${i("maintenance:update")?"":"cursor-not-allowed opacity-60"}`,title:i("maintenance:update")?void 0:a("maintenance.noPermissionEditHours"),children:[s.jsxs("div",{className:`text-sm font-medium text-white ${i("maintenance:update")?"group-hover:text-bambu-green":""} transition-colors flex items-center gap-1`,children:[Math.round(t.total_print_hours)," ",a("common.hours"),s.jsx(im,{className:`w-3 h-3 text-bambu-gray ${i("maintenance:update")?"group-hover:text-bambu-green":""}`})]}),s.jsx("div",{className:"text-xs text-bambu-gray",children:a("maintenance.totalPrintTime")})]})]}),s.jsx("div",{className:"w-px h-10 bg-bambu-dark-tertiary"}),m&&s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:`p-2 rounded-lg ${m.is_due?"bg-red-500/20":"bg-amber-500/20"}`,children:(()=>{const b=z0(m.maintenance_type_icon);return s.jsx(b,{className:`w-4 h-4 ${m.is_due?"text-red-400":"text-amber-400"}`})})()}),s.jsxs("div",{children:[s.jsx("div",{className:`text-sm font-medium ${m.is_due?"text-red-400":"text-amber-400"}`,children:m.maintenance_type_name}),s.jsx("div",{className:`text-xs ${m.is_due?"text-red-400/70":"text-amber-400/70"}`,children:m.is_due?a("common.overdue"):a("maintenance.dueSoon")})]})]})]})]}),o&&s.jsx(Mt,{className:"pt-0 border-t border-bambu-dark-tertiary",children:s.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4",children:p.map(b=>s.jsx(GKe,{item:b,onPerform:e,onToggle:n,hasPermission:i,t:a},b.id))})})]})}function WKe({overview:t,types:e,onUpdateInterval:n,onAddType:r,onUpdateType:i,onDeleteType:a,onAssignType:o,onRemoveItem:l,hasPermission:c,t:u}){const[d,f]=_.useState(null),[p,m]=_.useState(""),[x,b]=_.useState("hours"),[v,y]=_.useState(!1),[S,M]=_.useState(""),[T,k]=_.useState("100"),[C,E]=_.useState("hours"),[D,A]=_.useState("Wrench"),[j,I]=_.useState(""),[F,H]=_.useState(new Set),[R,z]=_.useState(null),W=_.useMemo(()=>t?t.map(U=>({id:U.printer_id,name:U.printer_name})):[],[t]),V=U=>t?t.filter(fe=>fe.maintenance_items.some(we=>we.maintenance_type_id===U)).map(fe=>({printerId:fe.printer_id,printerName:fe.printer_name,itemId:fe.maintenance_items.find(we=>we.maintenance_type_id===U)?.id})):[],X=U=>{if(!t)return[];const fe=new Set(V(U).map(we=>we.printerId));return W.filter(we=>!fe.has(we.id))},[Q,ae]=_.useState(null),[$,K]=_.useState(""),[ie,re]=_.useState(""),[xe,pe]=_.useState("hours"),[ue,Pe]=_.useState("Wrench"),[te,Ee]=_.useState(""),Oe=U=>{ae(U),K(U.name),re(U.default_interval_hours.toString()),pe(U.interval_type||"hours"),Pe(U.icon||"Wrench"),Ee(U.wiki_url||"")},me=()=>{Q&&$.trim()&&parseFloat(ie)>0&&(i(Q.id,{name:$.trim(),default_interval_hours:parseFloat(ie),interval_type:xe,icon:ue,wiki_url:te.trim()||null}),ae(null))},Xe=(U,fe,we)=>{const ge=parseFloat(p);if(!isNaN(ge)&&ge>0){const B=Math.abs(ge-fe)<.01?null:ge;n(U,{custom_interval_hours:B,custom_interval_type:x!==we?x:null})}f(null)},G=U=>{U.preventDefault(),S.trim()&&parseFloat(T)>0&&F.size>0&&(r({name:S.trim(),default_interval_hours:parseFloat(T),interval_type:C,icon:D,wiki_url:j.trim()||null},Array.from(F)),M(""),k("100"),E("hours"),I(""),H(new Set),y(!1))},Y=U=>{H(fe=>{const we=new Set(fe);return we.has(U)?we.delete(U):we.add(U),we})},de=t?.map(U=>({printerId:U.printer_id,printerName:U.printer_name,items:U.maintenance_items.sort((fe,we)=>fe.maintenance_type_id-we.maintenance_type_id)})).sort((U,fe)=>U.printerName.localeCompare(fe.printerName))||[],q=e.filter(U=>U.is_system),ee=e.filter(U=>!U.is_system);return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-4",children:[s.jsxs("div",{children:[s.jsx("h2",{className:"text-lg font-semibold text-white",children:u("maintenance.maintenanceTypes")}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:u("maintenance.maintenanceTypesDescription")})]}),s.jsxs(Te,{onClick:()=>y(!v),disabled:!c("maintenance:create"),title:c("maintenance:create")?void 0:u("maintenance.noPermissionEditTypes"),children:[s.jsx(fr,{className:"w-4 h-4"}),u("maintenance.addCustomType")]})]}),v&&s.jsx(Nt,{className:"mb-6",children:s.jsx(Mt,{className:"py-4",children:s.jsxs("form",{onSubmit:G,children:[s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[s.jsxs("div",{className:"lg:col-span-2",children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:u("common.name")}),s.jsx("input",{type:"text",value:S,onChange:U=>M(U.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",placeholder:u("maintenance.exampleName"),autoFocus:!0})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:u("maintenance.intervalType")}),s.jsxs("select",{value:C,onChange:U=>{E(U.target.value),U.target.value==="days"?k("30"):k("100")},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",children:[s.jsx("option",{value:"hours",children:u("maintenance.printHours")}),s.jsx("option",{value:"days",children:u("maintenance.calendarDays")})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:u("maintenance.intervalValue",{type:C==="days"?u("maintenance.calendarDays").toLowerCase():u("common.hours")})}),s.jsx("input",{type:"number",value:T,onChange:U=>k(U.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",min:"1"})]})]}),s.jsx("div",{className:"mt-4 flex items-end justify-between",children:s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:u("maintenance.icon")}),s.jsx("div",{className:"flex gap-1",children:Object.keys(g0).map(U=>{const fe=g0[U];return s.jsx("button",{type:"button",onClick:()=>A(U),className:`p-2 rounded-lg transition-colors ${D===U?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:s.jsx(fe,{className:"w-4 h-4"})},U)})})]})}),s.jsxs("div",{className:"mt-4",children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:u("maintenance.documentationLink")}),s.jsx("input",{type:"url",value:j,onChange:U=>I(U.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",placeholder:"https://wiki.bambulab.com/..."})]}),s.jsxs("div",{className:"mt-4",children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:u("maintenance.assignToPrinters")}),s.jsx("div",{className:"flex flex-wrap gap-2",children:W.map(U=>s.jsx("button",{type:"button",onClick:()=>Y(U.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${F.has(U.id)?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:U.name},U.id))}),F.size===0&&s.jsx("p",{className:"text-xs text-orange-400 mt-1",children:u("maintenance.selectAtLeastOnePrinter")})]}),s.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[s.jsx(Te,{type:"button",variant:"secondary",onClick:()=>{y(!1),H(new Set)},children:u("common.cancel")}),s.jsx(Te,{type:"submit",disabled:!S.trim()||F.size===0,children:u("maintenance.addType")})]})]})})}),s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:[q.map(U=>{const fe=z0(U.icon),we=U.interval_type||"hours";return s.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"p-2.5 bg-bambu-dark rounded-lg",children:s.jsx(fe,{className:"w-5 h-5 text-bambu-gray"})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("div",{className:"text-sm font-medium text-white truncate",children:U.name}),s.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 flex items-center gap-1",children:[we==="days"?s.jsx(ti,{className:"w-3 h-3"}):s.jsx(bu,{className:"w-3 h-3"}),qP(U.default_interval_hours,we,u)]})]})]})},U.id)}),ee.map(U=>{const fe=z0(U.icon),we=U.interval_type||"hours";if(Q?.id===U.id)return s.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green",children:s.jsxs("div",{className:"space-y-3",children:[s.jsx("input",{type:"text",value:$,onChange:se=>K(se.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",placeholder:u("common.name"),autoFocus:!0}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs("select",{value:xe,onChange:se=>pe(se.target.value),className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",children:[s.jsx("option",{value:"hours",children:u("maintenance.printHours")}),s.jsx("option",{value:"days",children:u("maintenance.calendarDays")})]}),s.jsx("input",{type:"number",value:ie,onChange:se=>re(se.target.value),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",min:"1"})]}),s.jsx("div",{className:"flex flex-wrap gap-1",children:Object.keys(g0).map(se=>{const ve=g0[se];return s.jsx("button",{type:"button",onClick:()=>Pe(se),className:`p-1.5 rounded transition-colors ${ue===se?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:s.jsx(ve,{className:"w-3.5 h-3.5"})},se)})}),s.jsx("input",{type:"url",value:te,onChange:se=>Ee(se.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",placeholder:u("maintenance.documentationLink")}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Te,{size:"sm",onClick:me,disabled:!$.trim(),children:u("common.save")}),s.jsx(Te,{size:"sm",variant:"secondary",onClick:()=>ae(null),children:u("common.cancel")})]})]})},U.id);const B=V(U.id),O=X(U.id),J=R===U.id;return s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"p-2.5 bg-bambu-green/20 rounded-lg",children:s.jsx(fe,{className:"w-5 h-5 text-bambu-green"})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-sm font-medium text-white truncate",children:U.name}),s.jsx("span",{className:"px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded",children:u("maintenance.custom")})]}),s.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 flex items-center gap-1",children:[we==="days"?s.jsx(ti,{className:"w-3 h-3"}):s.jsx(bu,{className:"w-3 h-3"}),qP(U.default_interval_hours,we,u)]})]}),s.jsxs("button",{onClick:()=>z(J?null:U.id),className:`px-2 py-1 rounded-lg border transition-colors flex items-center gap-1 ${B.length>0?"border-bambu-green/50 bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20":"border-orange-400/50 bg-orange-400/10 text-orange-400 hover:bg-orange-400/20"}`,title:u("maintenance.printersAssignedClick",{count:B.length}),children:[s.jsx(Pr,{className:"w-3 h-3"}),s.jsx("span",{className:"text-xs font-medium",children:B.length}),s.jsx(Kr,{className:`w-3 h-3 transition-transform ${J?"rotate-180":""}`})]}),s.jsx("button",{onClick:()=>Oe(U),disabled:!c("maintenance:update"),title:c("maintenance:update")?void 0:u("maintenance.noPermissionEditTypes"),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors ${c("maintenance:update")?"":"opacity-50 cursor-not-allowed"}`,children:s.jsx(im,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>{confirm(u("maintenance.deleteTypeConfirm",{name:U.name}))&&a(U.id)},disabled:!c("maintenance:delete"),title:c("maintenance:delete")?void 0:u("maintenance.noPermissionDeleteTypes"),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors ${c("maintenance:delete")?"":"opacity-50 cursor-not-allowed"}`,children:s.jsx(on,{className:"w-4 h-4"})})]}),J&&s.jsxs("div",{className:"mt-3 pt-3 border-t border-bambu-dark-tertiary",children:[s.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:u("maintenance.assignedToPrinters")}),B.length===0?s.jsx("p",{className:"text-xs text-orange-400",children:u("maintenance.noPrintersAssigned")}):s.jsx("div",{className:"flex flex-wrap gap-1 mb-2",children:B.map(se=>s.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark rounded text-xs text-white",children:[se.printerName,s.jsx("button",{onClick:()=>se.itemId&&l(se.itemId),disabled:!c("maintenance:delete"),title:c("maintenance:delete")?u("maintenance.removeFromPrinter"):u("maintenance.noPermissionRemovePrinter"),className:`ml-1 ${c("maintenance:delete")?"hover:text-red-400":"opacity-50 cursor-not-allowed"}`,children:"×"})]},se.printerId))}),O.length>0&&s.jsxs("div",{className:"flex flex-wrap gap-1",children:[s.jsx("span",{className:"text-xs text-bambu-gray mr-1",children:u("maintenance.addPrinterShort")}),O.map(se=>s.jsxs("button",{onClick:()=>o(se.id,U.id),disabled:!c("maintenance:create"),title:c("maintenance:create")?void 0:u("maintenance.noPermissionAssignPrinter"),className:`px-2 py-1 bg-bambu-dark rounded text-xs transition-colors ${c("maintenance:create")?"hover:bg-bambu-green/20 text-bambu-gray hover:text-bambu-green":"opacity-50 cursor-not-allowed text-bambu-gray"}`,children:["+ ",se.name]},se.id))]})]})]},U.id)})]})]}),de.length>0&&s.jsxs("div",{children:[s.jsxs("div",{className:"mb-4",children:[s.jsx("h2",{className:"text-lg font-semibold text-white",children:u("maintenance.intervalOverrides")}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:u("maintenance.intervalOverridesDescription")})]}),s.jsx("div",{className:"space-y-4",children:de.map(U=>s.jsx(Nt,{children:s.jsxs(Mt,{className:"py-4",children:[s.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:U.printerName}),s.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2",children:U.items.map(fe=>{const we=z0(fe.maintenance_type_icon),ge=e.find(ve=>ve.id===fe.maintenance_type_id),B=ge?.default_interval_hours||fe.interval_hours,O=ge?.interval_type||"hours",J=fe.interval_type||"hours",se=d===fe.id;return s.jsxs("div",{className:"flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg",children:[s.jsx(we,{className:"w-4 h-4 text-bambu-gray shrink-0"}),s.jsx("span",{className:"text-xs text-bambu-gray flex-1 truncate",children:fe.maintenance_type_name}),se?s.jsxs("div",{className:"flex items-center gap-1",children:[x==="days"?s.jsx(ti,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"}):s.jsx(bu,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"}),s.jsxs("select",{value:x,onChange:ve=>b(ve.target.value),className:"px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",children:[s.jsx("option",{value:"hours",children:u("maintenance.printHours")}),s.jsx("option",{value:"days",children:u("maintenance.calendarDays")})]}),s.jsx("input",{type:"number",value:p,onChange:ve=>m(ve.target.value),onKeyDown:ve=>{ve.key==="Enter"&&Xe(fe.id,B,O),ve.key==="Escape"&&f(null)},className:"w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",min:"1"}),s.jsx(Te,{size:"sm",onClick:()=>Xe(fe.id,B,O),children:"OK"})]}):s.jsxs("button",{onClick:()=>{c("maintenance:update")&&(f(fe.id),m(fe.interval_hours.toString()),b(J))},disabled:!c("maintenance:update"),title:c("maintenance:update")?void 0:u("maintenance.noPermissionEditIntervals"),className:`px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs font-medium text-white transition-colors flex items-center gap-1 ${c("maintenance:update")?"hover:bg-bambu-dark-secondary hover:border-bambu-green":"opacity-50 cursor-not-allowed"}`,children:[J==="days"?s.jsx(ti,{className:"w-3 h-3"}):s.jsx(bu,{className:"w-3 h-3"}),qP(fe.interval_hours,J,u),s.jsx(im,{className:"w-3 h-3 text-bambu-gray"})]})]},fe.id)})})]})},U.printerId))})]}),de.length===0&&s.jsx(Nt,{children:s.jsxs(Mt,{className:"text-center py-12",children:[s.jsx(nr,{className:"w-12 h-12 mx-auto mb-4 text-bambu-gray/30"}),s.jsx("p",{className:"text-bambu-gray",children:u("common.noPrinters")}),s.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1",children:u("maintenance.intervalOverridesDescription")})]})})]})}function KKe(){const{t}=On(),e=ln(),{showToast:n}=Vn(),{hasPermission:r}=Ci(),[i,a]=_.useState("status"),{data:o,isLoading:l}=ot({queryKey:["maintenanceOverview"],queryFn:ce.getMaintenanceOverview}),{data:c}=ot({queryKey:["maintenanceTypes"],queryFn:ce.getMaintenanceTypes}),u=gt({mutationFn:({id:k,notes:C})=>ce.performMaintenance(k,C),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),e.invalidateQueries({queryKey:["maintenanceSummary"]}),n(t("maintenance.maintenanceComplete"))},onError:k=>{n(k.message,"error")}}),d=gt({mutationFn:({id:k,data:C})=>ce.updateMaintenanceItem(k,C),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]})},onError:k=>{n(k.message,"error")}}),f=gt({mutationFn:({id:k,data:C})=>ce.updateMaintenanceType(k,C),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeUpdated"))},onError:k=>{n(k.message,"error")}}),p=gt({mutationFn:ce.deleteMaintenanceType,onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeDeleted"))},onError:k=>{n(k.message,"error")}}),m=gt({mutationFn:({printerId:k,hours:C})=>ce.setPrinterHours(k,C),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),e.invalidateQueries({queryKey:["maintenanceSummary"]}),n(t("maintenance.printHoursUpdated"))},onError:k=>{n(k.message,"error")}}),x=gt({mutationFn:({printerId:k,typeId:C})=>ce.assignMaintenanceType(k,C),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.printerAssigned"))},onError:k=>{n(k.message,"error")}}),b=gt({mutationFn:ce.removeMaintenanceItem,onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.printerRemoved"))},onError:k=>{n(k.message,"error")}}),v=k=>{u.mutate({id:k})},y=(k,C)=>{d.mutate({id:k,data:{enabled:C}})},S=(k,C)=>{m.mutate({printerId:k,hours:C})};if(l)return s.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:s.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})});const M=o?.reduce((k,C)=>k+C.due_count,0)||0,T=o?.reduce((k,C)=>k+C.warning_count,0)||0;return s.jsxs("div",{className:"p-4 md:p-8",children:[s.jsxs("div",{className:"mb-6",children:[s.jsx("h1",{className:"text-2xl font-bold text-white",children:t("maintenance.title")}),s.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:i==="status"?s.jsxs(s.Fragment,{children:[M>0&&s.jsx("span",{className:"text-red-400",children:t("maintenance.dueCount",{count:M})}),M>0&&T>0&&" · ",T>0&&s.jsx("span",{className:"text-amber-400",children:t("maintenance.warningCount",{count:T})}),M===0&&T===0&&s.jsx("span",{className:"text-bambu-green",children:t("maintenance.allOk")})]}):t("maintenance.configureSettings")})]}),s.jsxs("div",{className:"flex gap-1 mb-6 border-b border-bambu-dark-tertiary",children:[s.jsx("button",{onClick:()=>a("status"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i==="status"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:t("maintenance.statusTab")}),s.jsx("button",{onClick:()=>a("settings"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i==="settings"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:t("maintenance.settingsTab")})]}),i==="status"?s.jsx("div",{className:"space-y-6",children:o&&o.length>0?[...o].sort((k,C)=>{const E=k.due_count*10+k.warning_count,D=C.due_count*10+C.warning_count;return E!==D?D-E:k.printer_name.localeCompare(C.printer_name)}).map(k=>s.jsx(qKe,{overview:k,onPerform:v,onToggle:y,onSetHours:S,hasPermission:r,t},k.printer_id)):s.jsx(Nt,{children:s.jsxs(Mt,{className:"text-center py-16",children:[s.jsx(om,{className:"w-16 h-16 mx-auto mb-4 text-bambu-gray/30"}),s.jsx("p",{className:"text-lg font-medium text-white mb-2",children:t("common.noPrinters")}),s.jsx("p",{className:"text-bambu-gray",children:t("maintenance.configureSettings")})]})})}):s.jsx(WKe,{overview:o,types:c||[],onUpdateInterval:(k,C)=>d.mutate({id:k,data:C}),onAddType:async(k,C)=>{const E=await ce.createMaintenanceType(k);for(const D of C)await ce.assignMaintenanceType(D,E.id);e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeUpdated"))},onUpdateType:(k,C)=>f.mutate({id:k,data:C}),onDeleteType:k=>p.mutate(k),onAssignType:(k,C)=>x.mutate({printerId:k,typeId:C}),onRemoveItem:k=>b.mutate(k),hasPermission:r,t})]})}const yq=["#ef4444","#f97316","#eab308","#22c55e","#06b6d4","#3b82f6","#8b5cf6","#ec4899","#6b7280"];function $re({project:t,onClose:e,onSave:n,isLoading:r,t:i}){const[a,o]=_.useState(t?.name||""),[l,c]=_.useState(t?.description||""),[u,d]=_.useState(t?.color||yq[0]),[f,p]=_.useState(t?.target_count?.toString()||""),[m,x]=_.useState(t?.target_parts_count?.toString()||""),[b,v]=_.useState(t?.status||"active"),[y,S]=_.useState(t?.tags||""),[M,T]=_.useState(t?.due_date?.split("T")[0]||""),[k,C]=_.useState(t?.priority||"normal"),E=D=>{D.preventDefault(),n({name:a.trim(),description:l.trim()||void 0,color:u,target_count:f?parseInt(f,10):void 0,target_parts_count:m?parseInt(m,10):void 0,tags:y.trim()||void 0,due_date:M||void 0,priority:k,...t&&{status:b}})};return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary",children:[s.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:i(t?"projects.editProject":"projects.newProject")})}),s.jsxs("form",{onSubmit:E,className:"p-4 space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("common.name")}),s.jsx("input",{type:"text",value:a,onChange:D=>o(D.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:i("projects.namePlaceholder"),required:!0})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("common.description")}),s.jsx("textarea",{value:l,onChange:D=>c(D.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none",placeholder:i("projects.descriptionPlaceholder"),rows:2})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("projects.color")}),s.jsx("div",{className:"flex gap-2 flex-wrap",children:yq.map(D=>s.jsx("button",{type:"button",onClick:()=>d(D),className:`w-8 h-8 rounded-full transition-transform ${u===D?"ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110":""}`,style:{backgroundColor:D}},D))})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("projects.targetPlates")}),s.jsx("input",{type:"number",value:f,onChange:D=>p(D.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:i("projects.targetPlatesPlaceholder"),min:"1"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("projects.targetPlatesHelp")})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("projects.targetParts")}),s.jsx("input",{type:"number",value:m,onChange:D=>x(D.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:i("projects.targetPartsPlaceholder"),min:"1"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("projects.targetPartsHelp")})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("projects.tagsLabel")}),s.jsx("input",{type:"text",value:y,onChange:D=>S(D.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:i("projects.tagsPlaceholder")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("projects.dueDate")}),s.jsx("input",{type:"date",value:M,onChange:D=>T(D.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("projects.priority")}),s.jsxs("select",{value:k,onChange:D=>C(D.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green",children:[s.jsx("option",{value:"low",children:i("projects.priorityLow")}),s.jsx("option",{value:"normal",children:i("projects.priorityNormal")}),s.jsx("option",{value:"high",children:i("projects.priorityHigh")}),s.jsx("option",{value:"urgent",children:i("projects.priorityUrgent")})]})]})]}),t&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("common.status")}),s.jsxs("select",{value:b,onChange:D=>v(D.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green",children:[s.jsx("option",{value:"active",children:i("projects.statusActive")}),s.jsx("option",{value:"completed",children:i("projects.statusCompleted")}),s.jsx("option",{value:"archived",children:i("projects.statusArchived")})]})]}),s.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[s.jsx(Te,{type:"button",variant:"secondary",onClick:e,children:i("common.cancel")}),s.jsx(Te,{type:"submit",disabled:!a.trim()||r,children:r?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):i(t?"common.save":"projects.create")})]})]})]})})}function XKe({project:t,onClick:e,onEdit:n,onDelete:r,hasPermission:i,t:a}){const o=t.target_count?Math.round(t.archive_count/t.target_count*100):0,l=t.target_parts_count?Math.round(t.completed_count/t.target_parts_count*100):0,c=t.status==="completed",u=t.status==="archived",[d,f]=_.useState(!1),m=c?{icon:oM,color:"text-bambu-green",bg:"bg-bambu-green/10"}:u?{icon:ho,color:"text-bambu-gray",bg:"bg-bambu-gray/10"}:t.queue_count>0?{icon:nr,color:"text-blue-400",bg:"bg-blue-400/10"}:{icon:Ja,color:"text-bambu-gray",bg:"bg-bambu-gray/10"};return s.jsxs("div",{className:"group relative bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary hover:border-bambu-green/50 hover:shadow-lg hover:shadow-bambu-green/5 transition-all duration-300 cursor-pointer overflow-hidden",onClick:e,children:[s.jsx("div",{className:"absolute top-0 left-0 w-1.5 h-full",style:{backgroundColor:t.color||"#6b7280",boxShadow:`0 0 12px ${t.color||"#6b7280"}40`}}),s.jsxs("div",{className:"p-5 pl-6",children:[s.jsxs("div",{className:"flex items-start justify-between mb-4",children:[s.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[s.jsx("div",{className:`p-2 rounded-lg ${m.bg} flex-shrink-0`,children:s.jsx(m.icon,{className:`w-5 h-5 ${m.color}`})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s.jsx("h3",{className:"font-semibold text-white truncate",children:t.name}),t.target_parts_count?s.jsxs("span",{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${l>=100?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray"}`,children:[t.completed_count,"/",t.target_parts_count," ",a("projects.parts")]}):t.target_count?s.jsxs("span",{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${o>=100?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray"}`,children:[t.archive_count,"/",t.target_count," ",a("projects.plates")]}):t.completed_count>0?s.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium bg-bambu-dark text-bambu-gray",children:[t.completed_count," ",a("projects.parts")]}):null,c&&s.jsx("span",{className:"text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap",children:a("projects.done")}),u&&s.jsx("span",{className:"text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap",children:a("projects.statusArchived")})]}),t.description&&s.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1 line-clamp-1",children:t.description}),t.archives&&t.archives.length>0&&(()=>{const x=t.archives.map(S=>S.filament_type).filter(Boolean).flatMap(S=>S.split(",").map(M=>M.trim())).filter(Boolean),b=[...new Set(x)],v=t.archives.map(S=>S.filament_color).filter(Boolean).flatMap(S=>S.split(",").map(M=>M.trim())).filter(S=>S.startsWith("#")||/^[0-9A-Fa-f]{6}$/.test(S)),y=[...new Set(v)];return b.length===0&&y.length===0?null:s.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[b.slice(0,3).map(S=>s.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-bambu-dark text-bambu-gray rounded",children:S},S)),y.length>0&&s.jsxs("div",{className:"flex items-center gap-0.5",children:[y.slice(0,5).map(S=>s.jsx("div",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:S.startsWith("#")?S:`#${S}`},title:S},S)),y.length>5&&s.jsxs("span",{className:"text-[10px] text-bambu-gray ml-0.5",children:["+",y.length-5]})]})]})})()]})]}),s.jsxs("div",{className:"relative",onClick:x=>x.stopPropagation(),children:[s.jsx("button",{className:"p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors opacity-0 group-hover:opacity-100",onClick:()=>f(!d),children:s.jsx(sh,{className:"w-4 h-4"})}),d&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>f(!1)}),s.jsxs("div",{className:"absolute right-0 top-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]",children:[s.jsxs("button",{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${i("projects:update")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{i("projects:update")&&(n(),f(!1))},disabled:!i("projects:update"),title:i("projects:update")?void 0:a("projects.noEditPermission"),children:[s.jsx(im,{className:"w-4 h-4"}),a("common.edit")]}),s.jsxs("button",{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${i("projects:delete")?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{i("projects:delete")&&(r(),f(!1))},disabled:!i("projects:delete"),title:i("projects:delete")?void 0:a("projects.noDeletePermission"),children:[s.jsx(on,{className:"w-4 h-4"}),a("common.delete")]})]})]})]})]}),s.jsx("div",{className:"mb-4",children:t.target_count||t.target_parts_count?s.jsxs("div",{className:"space-y-3",children:[t.target_count&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[s.jsx("span",{className:"text-bambu-gray",children:a("projects.plates")}),s.jsxs("span",{className:o>=100?"text-bambu-green font-medium":"text-white",children:[t.archive_count," / ",t.target_count]})]}),s.jsx("div",{className:"h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm",children:s.jsx("div",{className:"h-full transition-all duration-500 ease-out rounded-full relative",style:{width:`${Math.min(o,100)}%`,background:o>=100?"linear-gradient(90deg, #22c55e, #4ade80)":`linear-gradient(90deg, ${t.color||"#6b7280"}, ${t.color||"#6b7280"}cc)`,boxShadow:`0 0 8px ${o>=100?"#22c55e":t.color||"#6b7280"}60`}})})]}),t.target_parts_count&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[s.jsx("span",{className:"text-bambu-gray",children:a("projects.parts")}),s.jsxs("span",{className:l>=100?"text-bambu-green font-medium":"text-white",children:[t.completed_count," / ",t.target_parts_count]})]}),s.jsx("div",{className:"h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm",children:s.jsx("div",{className:"h-full transition-all duration-500 ease-out rounded-full relative",style:{width:`${Math.min(l,100)}%`,background:l>=100?"linear-gradient(90deg, #22c55e, #4ade80)":`linear-gradient(90deg, ${t.color||"#6b7280"}, ${t.color||"#6b7280"}cc)`,boxShadow:`0 0 8px ${l>=100?"#22c55e":t.color||"#6b7280"}60`}})})]}),t.failed_count>0&&s.jsxs("div",{className:"text-xs text-red-400",children:[t.failed_count," ",a("projects.failed")]})]}):t.completed_count>0||t.failed_count>0?s.jsxs("div",{className:"flex items-center gap-4 text-xs",children:[t.completed_count>0&&s.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",children:[s.jsx(ho,{className:"w-3.5 h-3.5"}),s.jsxs("span",{children:[t.completed_count," ",a("projects.completed")]})]}),t.failed_count>0&&s.jsxs("div",{className:"flex items-center gap-1.5 text-red-400",children:[s.jsx(Sn,{className:"w-3.5 h-3.5"}),s.jsxs("span",{children:[t.failed_count," ",a("projects.failed")]})]}),t.queue_count>0&&s.jsxs("div",{className:"flex items-center gap-1.5 text-blue-400",children:[s.jsx(nr,{className:"w-3.5 h-3.5"}),s.jsxs("span",{children:[t.queue_count," ",a("projects.inQueue")]})]})]}):s.jsx("div",{className:"text-xs text-bambu-gray/60 italic",children:a("projects.noPrintsYet")})}),t.archives&&t.archives.length>0&&s.jsxs("div",{className:"mb-4",children:[s.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:t.archives.slice(0,4).map(x=>s.jsxs("div",{className:"relative aspect-square rounded-lg bg-bambu-dark overflow-hidden border border-bambu-dark-tertiary",title:x.print_name||"Unknown",children:[x.thumbnail_path?s.jsx("img",{src:ce.getArchiveThumbnail(x.id),alt:x.print_name||"",className:"w-full h-full object-cover"}):s.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray/50",children:s.jsx(pc,{className:"w-6 h-6"})}),x.status==="failed"&&s.jsx("div",{className:"absolute inset-0 bg-red-500/40 flex items-center justify-center",children:s.jsx(Sn,{className:"w-4 h-4 text-white"})})]},x.id))}),t.archive_count>4&&s.jsx("p",{className:"text-xs text-bambu-gray mt-1.5 text-center",children:a("common.more",{count:t.archive_count-4})})]}),s.jsxs("div",{className:"flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-4 text-xs text-bambu-gray",children:[s.jsxs("div",{className:"flex items-center gap-1.5",title:a("projects.printJobs"),children:[s.jsx(sl,{className:"w-3.5 h-3.5 text-blue-400"}),s.jsxs("span",{children:[t.archive_count," ",a("projects.plates")]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",title:a("projects.partsPrinted"),children:[s.jsx(pc,{className:"w-3.5 h-3.5 text-bambu-green"}),s.jsxs("span",{children:[t.completed_count," ",a("projects.parts")]})]}),t.failed_count>0&&s.jsxs("div",{className:"flex items-center gap-1.5 text-red-400",title:a("projects.failedParts"),children:[s.jsx(Sn,{className:"w-3.5 h-3.5"}),s.jsx("span",{children:t.failed_count})]}),t.queue_count>0&&s.jsxs("div",{className:"flex items-center gap-1.5 text-yellow-400",title:a("projects.inQueue"),children:[s.jsx(pj,{className:"w-3.5 h-3.5"}),s.jsx("span",{children:t.queue_count})]})]}),s.jsx(gs,{className:"w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors"})]})]})]})}function YKe(){const{t}=On(),e=kc(),n=ln(),{showToast:r}=Vn(),{hasPermission:i}=Ci(),[a,o]=_.useState(!1),[l,c]=_.useState(),[u,d]=_.useState("active"),[f,p]=_.useState(null),{data:m,isLoading:x}=ot({queryKey:["projects",u==="all"?void 0:u],queryFn:()=>ce.getProjects(u==="all"?void 0:u)}),b=gt({mutationFn:H=>ce.createProject(H),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),o(!1),r(t("projects.toast.created"),"success")},onError:H=>{r(H.message,"error")}}),v=gt({mutationFn:({id:H,data:R})=>ce.updateProject(H,R),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),o(!1),c(void 0),r(t("projects.toast.updated"),"success")},onError:H=>{r(H.message,"error")}}),y=gt({mutationFn:H=>ce.deleteProject(H),onSuccess:()=>{p(null),r(t("projects.toast.deleted"),"success"),setTimeout(()=>window.location.reload(),100)},onError:H=>{p(null),r(H.message,"error")}}),S=gt({mutationFn:H=>ce.importProject(H),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),r(t("projects.toast.imported"),"success")},onError:H=>{r(H.message,"error")}}),M=_.useRef(null),T=async()=>{try{const H=await ce.getProjects(),R=await Promise.all(H.map(async X=>await ce.exportProjectJson(X.id))),z=new Blob([JSON.stringify(R,null,2)],{type:"application/json"}),W=URL.createObjectURL(z),V=document.createElement("a");V.href=W,V.download=`bambuddy_projects_${new Date().toISOString().split("T")[0]}.json`,V.click(),URL.revokeObjectURL(W),r(t("projects.toast.exported"),"success")}catch(H){r(H.message,"error")}},k=()=>{M.current?.click()},C=async H=>{const R=H.target.files?.[0];if(R){try{if(R.name.toLowerCase().endsWith(".zip"))await ce.importProjectFile(R),n.invalidateQueries({queryKey:["projects"]}),r(t("projects.toast.imported"),"success");else{const W=await R.text(),V=JSON.parse(W),X=Array.isArray(V)?V:[V];for(const Q of X)await S.mutateAsync(Q);X.length>1&&r(t("projects.toast.multipleImported",{count:X.length}),"success")}}catch(z){r(`${t("projects.toast.importFailed")}: ${z.message}`,"error")}H.target.value=""}},E=H=>{l?v.mutate({id:l.id,data:H}):b.mutate(H)},D=H=>{c(H),o(!0)},A=H=>{e(`/projects/${H.id}`)},j=H=>{p(H)},I=()=>{f!==null&&y.mutate(f)},F=m?.reduce((H,R)=>(H[R.status]=(H[R.status]||0)+1,H.all=(H.all||0)+1,H),{})||{};return s.jsxs("div",{className:"p-4 md:p-8 space-y-8",children:[s.jsx("input",{ref:M,type:"file",accept:".json,.zip",onChange:C,className:"hidden"}),s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[s.jsxs("div",{children:[s.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[s.jsx("div",{className:"p-2.5 bg-bambu-green/10 rounded-xl",children:s.jsx(Ja,{className:"w-6 h-6 text-bambu-green"})}),t("projects.title")]}),s.jsx("p",{className:"text-sm text-bambu-gray mt-2 ml-14",children:t("projects.subtitle")})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(Te,{variant:"secondary",onClick:k,disabled:!i("projects:create"),title:i("projects:create")?t("projects.importProject"):t("projects.noImportPermission"),children:[s.jsx(za,{className:"w-4 h-4 mr-2"}),t("projects.import")]}),s.jsxs(Te,{variant:"secondary",onClick:T,disabled:!i("projects:read"),title:i("projects:read")?t("projects.exportAll"):t("projects.noExportPermission"),children:[s.jsx(wi,{className:"w-4 h-4 mr-2"}),t("projects.export")]}),s.jsxs(Te,{onClick:()=>o(!0),className:"sm:w-auto w-full",disabled:!i("projects:create"),title:i("projects:create")?void 0:t("projects.noCreatePermission"),children:[s.jsx(fr,{className:"w-4 h-4 mr-2"}),t("projects.newProject")]})]})]}),s.jsx("div",{className:"flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit",children:[{key:"active",label:t("projects.statusActive"),icon:nr},{key:"completed",label:t("projects.statusCompleted"),icon:oM},{key:"archived",label:t("projects.statusArchived"),icon:ho},{key:"all",label:t("common.all"),icon:Ja}].map(({key:H,label:R,icon:z})=>s.jsxs("button",{onClick:()=>d(H),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${u===H?"bg-bambu-card text-white shadow-sm":"text-bambu-gray hover:text-white"}`,children:[s.jsx(z,{className:"w-4 h-4"}),s.jsx("span",{children:R}),F[H]>0&&s.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded-full ${u===H?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary"}`,children:F[H]})]},H))}),x?s.jsx("div",{className:"flex items-center justify-center py-20",children:s.jsxs("div",{className:"flex flex-col items-center gap-3",children:[s.jsx(pt,{className:"w-8 h-8 animate-spin text-bambu-green"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:t("projects.loading")})]})}):m?.length===0?s.jsxs("div",{className:"flex flex-col items-center justify-center py-20 px-4",children:[s.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:s.jsx(Ja,{className:"w-12 h-12 text-bambu-gray/50"})}),s.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:u==="all"?t("projects.noProjects"):t("projects.noProjectsFiltered",{status:u})}),s.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:u==="all"?t("projects.createFirst"):t("projects.noProjectsFilteredHelp",{status:u})}),u==="all"&&s.jsxs(Te,{onClick:()=>o(!0),disabled:!i("projects:create"),title:i("projects:create")?void 0:t("projects.noCreatePermission"),children:[s.jsx(fr,{className:"w-4 h-4 mr-2"}),t("projects.createFirstButton")]})]}):s.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8",children:m?.map(H=>s.jsx(XKe,{project:H,onClick:()=>A(H),onEdit:()=>D(H),onDelete:()=>j(H.id),hasPermission:i,t},H.id))}),f!==null&&s.jsx(Jn,{title:t("projects.deleteProject"),message:t("projects.deleteConfirm"),confirmText:t("projects.deleteProject"),variant:"danger",onConfirm:I,onCancel:()=>p(null)}),a&&s.jsx($re,{project:l,onClose:()=>{o(!1),c(void 0)},onSave:E,isLoading:b.isPending||v.isPending,t})]})}function QKe(t){if(t<1)return`${Math.round(t*60)}m`;const e=Math.floor(t),n=Math.round((t-e)*60);return n>0?`${e}h ${n}m`:`${e}h`}function ZKe(t){return t>=1e3?`${(t/1e3).toFixed(2)}kg`:`${Math.round(t)}g`}function JKe({status:t,t:e}){const n={active:"bg-bambu-green/20 text-bambu-green",completed:"bg-blue-500/20 text-blue-400",archived:"bg-bambu-gray/20 text-bambu-gray"},r=n[t]||n.active,i={active:e("projectDetail.status.active"),completed:e("projectDetail.status.completed"),archived:e("projectDetail.status.archived")};return s.jsx("span",{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:i[t]||t.charAt(0).toUpperCase()+t.slice(1)})}function vq({icon:t,label:e,value:n,subValue:r,hint:i,color:a="text-bambu-gray"}){return s.jsx(Nt,{children:s.jsx(Mt,{className:"p-4",children:s.jsxs("div",{className:"flex items-center gap-3",title:i,children:[s.jsx("div",{className:`p-2 rounded-lg bg-bambu-dark ${a}`,children:s.jsx(t,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:e}),s.jsx("p",{className:"text-xl font-semibold text-white",children:n}),r&&s.jsx("p",{className:"text-xs text-bambu-gray/70",children:r})]})]})})})}function eXe({archives:t,t:e}){return t.length===0?s.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[s.jsx(pc,{className:"w-12 h-12 mx-auto mb-2 opacity-50"}),s.jsx("p",{children:e("projectDetail.noPrints")})]}):s.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3",children:t.map(n=>s.jsxs(Ds,{to:`/archives?search=${encodeURIComponent(n.print_name||"")}`,className:"group relative aspect-square rounded-lg bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden hover:border-bambu-green transition-colors",children:[n.thumbnail_path?s.jsx("img",{src:ce.getArchiveThumbnail(n.id),alt:n.print_name||"Print",className:"w-full h-full object-cover"}):s.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:s.jsx(pc,{className:"w-8 h-8"})}),n.status==="failed"&&s.jsx("div",{className:"absolute inset-0 bg-red-500/30 flex items-center justify-center",children:s.jsx(Qi,{className:"w-8 h-8 text-white"})}),n.status==="completed"&&s.jsx("div",{className:"absolute top-1 right-1",children:s.jsx(Ar,{className:"w-4 h-4 text-bambu-green"})}),s.jsx("div",{className:"absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity",children:s.jsx("p",{className:"text-xs text-white truncate",children:n.print_name||"Unknown"})})]},n.id))})}function tXe({priority:t,t:e}){const n={low:{color:"bg-gray-500/20 text-gray-400",label:e("projectDetail.priority.low")},normal:{color:"bg-blue-500/20 text-blue-400",label:e("projectDetail.priority.normal")},high:{color:"bg-orange-500/20 text-orange-400",label:e("projectDetail.priority.high")},urgent:{color:"bg-red-500/20 text-red-400",label:e("projectDetail.priority.urgent")}},{color:r,label:i}=n[t]||n.normal;return s.jsxs("span",{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[t==="urgent"&&s.jsx(Sn,{className:"w-3 h-3"}),i]})}function nXe(t){return t?Bg(t,{year:"numeric",month:"short",day:"numeric"}):""}function WP(t,e){if(!t)return null;const n=Ui(t);if(!n)return null;const r=new Date,i=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return i<0?{color:"text-red-400",label:e("projectDetail.dueDate.overdue")}:i===0?{color:"text-orange-400",label:e("projectDetail.dueDate.today")}:i<=3?{color:"text-yellow-400",label:e("projectDetail.dueDate.daysLeft",{count:i})}:{color:"text-bambu-gray",label:e("projectDetail.dueDate.daysLeft",{count:i})}}function rXe(){const{id:t}=iM(),e=kc(),{t:n}=On(),r=ln(),{showToast:i}=Vn(),{hasPermission:a}=Ci(),[o,l]=_.useState(!1),[c,u]=_.useState(!1),[d,f]=_.useState(""),p=parseInt(t||"0",10),{data:m,isLoading:x,error:b}=ot({queryKey:["project",p],queryFn:()=>ce.getProject(p),enabled:p>0}),{data:v,isLoading:y}=ot({queryKey:["project-archives",p],queryFn:()=>ce.getProjectArchives(p),enabled:p>0}),{data:S,isLoading:M}=ot({queryKey:["project-bom",p],queryFn:()=>ce.getProjectBOM(p),enabled:p>0}),{data:T,isLoading:k}=ot({queryKey:["project-timeline",p],queryFn:()=>ce.getProjectTimeline(p,20),enabled:p>0}),{data:C}=ot({queryKey:["settings"],queryFn:ce.getSettings}),{data:E}=ot({queryKey:["project-folders",p],queryFn:()=>ce.getLibraryFoldersByProject(p),enabled:p>0}),D=C?.currency||"$",A=C?.time_format||"system",j=gt({mutationFn:Me=>ce.updateProject(p,Me),onSuccess:()=>{r.invalidateQueries({queryKey:["project",p]}),r.invalidateQueries({queryKey:["projects"]}),l(!1),u(!1),i(n("projectDetail.toast.projectUpdated"),"success")},onError:Me=>{i(Me.message,"error")}}),I=()=>{f(m?.notes||""),u(!0)},F=()=>{j.mutate({notes:d})},H=()=>{u(!1),f("")},[R,z]=_.useState(""),[W,V]=_.useState(1),[X,Q]=_.useState(""),[ae,$]=_.useState(""),[K,ie]=_.useState(""),[re,xe]=_.useState(!1),[pe,ue]=_.useState(!1),[Pe,te]=_.useState(null),[Ee,Oe]=_.useState(""),[me,Xe]=_.useState(1),[G,Y]=_.useState(""),[de,q]=_.useState(""),[ee,U]=_.useState(""),[fe,we]=_.useState({isOpen:!1,title:"",message:"",onConfirm:()=>{}}),ge=gt({mutationFn:Me=>ce.createBOMItem(p,Me),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),z(""),V(1),Q(""),$(""),ie(""),xe(!1),i(n("projectDetail.toast.partAdded"),"success")},onError:Me=>i(Me.message,"error")}),B=gt({mutationFn:({itemId:Me,data:Ge})=>ce.updateBOMItem(p,Me,Ge),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),te(null)},onError:Me=>i(Me.message,"error")}),O=gt({mutationFn:Me=>ce.deleteBOMItem(p,Me),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),i(n("projectDetail.toast.partRemoved"),"success")},onError:Me=>i(Me.message,"error")}),J=Me=>{Me.preventDefault(),R.trim()&&ge.mutate({name:R.trim(),quantity_needed:W,unit_price:X?parseFloat(X):void 0,sourcing_url:ae.trim()||void 0,remarks:K.trim()||void 0})},se=Me=>{const Ge=Me.is_complete?0:Me.quantity_needed;B.mutate({itemId:Me.id,data:{quantity_acquired:Ge}})},ve=(Me,Ge)=>{we({isOpen:!0,title:n("projectDetail.bom.deletePart"),message:n("projectDetail.bom.deleteConfirm",{name:Ge}),onConfirm:()=>{we(Ne=>({...Ne,isOpen:!1})),O.mutate(Me)}})},_e=Me=>{te(Me),Oe(Me.name),Xe(Me.quantity_needed),Y(Me.unit_price?.toString()||""),q(Me.sourcing_url||""),U(Me.remarks||"")},ne=Me=>{Me.preventDefault(),!(!Pe||!Ee.trim())&&B.mutate({itemId:Pe.id,data:{name:Ee.trim(),quantity_needed:me,unit_price:G?parseFloat(G):void 0,sourcing_url:de.trim()||void 0,remarks:ee.trim()||void 0}})},Fe=()=>{te(null)},He=async()=>{try{const{blob:Me,filename:Ge}=await ce.exportProjectZip(Number(p)),Ne=URL.createObjectURL(Me),nt=document.createElement("a");nt.href=Ne,nt.download=Ge||`${m?.name||"project"}_${new Date().toISOString().split("T")[0]}.zip`,nt.click(),URL.revokeObjectURL(Ne),i(n("projectDetail.toast.projectExported"),"success")}catch(Me){i(Me.message,"error")}},rt=gt({mutationFn:()=>ce.createTemplateFromProject(p),onSuccess:()=>{r.invalidateQueries({queryKey:["projects"]}),i(n("projectDetail.toast.templateCreated"),"success")},onError:Me=>i(Me.message,"error")}),Ie=Me=>Hg(Me,A,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"});if(x)return s.jsx("div",{className:"flex items-center justify-center py-24",children:s.jsx(pt,{className:"w-8 h-8 animate-spin text-bambu-green"})});if(b||!m)return s.jsxs("div",{className:"text-center py-24",children:[s.jsx("p",{className:"text-bambu-gray",children:b?`${n("common.error")}: ${b.message}`:n("projectDetail.notFound")}),s.jsx(Te,{variant:"secondary",className:"mt-4",onClick:()=>e("/projects"),children:n("projectDetail.backToProjects")})]});const be=m.stats,Ae=be?.progress_percent??0,Ue=be?.parts_progress_percent??0;return s.jsxs("div",{className:"p-4 md:p-8 space-y-8",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[s.jsx(Ds,{to:"/projects",className:"hover:text-white transition-colors",children:n("navigation.projects")}),s.jsx(gs,{className:"w-4 h-4"}),s.jsx("span",{className:"text-white",children:m.name})]}),s.jsxs("div",{className:"flex items-start justify-between",children:[s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsx("button",{onClick:()=>e("/projects"),className:"p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors",children:s.jsx(fce,{className:"w-5 h-5 text-bambu-gray"})}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-4 h-4 rounded-full flex-shrink-0",style:{backgroundColor:m.color||"#6b7280"}}),s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold text-white",children:m.name}),m.description&&s.jsx("p",{className:"text-bambu-gray mt-1",children:m.description})]})]}),s.jsx(JKe,{status:m.status,t:n})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(Te,{variant:"secondary",onClick:He,disabled:!a("projects:read"),title:a("projects:read")?n("projectDetail.exportProject"):n("projectDetail.noExportPermission"),children:[s.jsx(wi,{className:"w-4 h-4 mr-2"}),n("projectDetail.export")]}),s.jsxs(Te,{onClick:()=>l(!0),disabled:!a("projects:update"),title:a("projects:update")?void 0:n("projectDetail.noEditPermission"),children:[s.jsx(im,{className:"w-4 h-4 mr-2"}),n("common.edit")]})]})]}),(m.target_count||m.target_parts_count)&&s.jsx(Nt,{children:s.jsxs(Mt,{className:"p-4 space-y-4",children:[m.target_count&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsx("span",{className:"text-sm text-bambu-gray",children:n("projectDetail.progress.platesProgress")}),s.jsxs("span",{className:"text-sm font-medium text-white",children:[be?.total_archives||0," / ",m.target_count," ",n("projectDetail.progress.printJobs")]})]}),s.jsx("div",{className:"h-3 bg-bambu-dark rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${Math.min(Ae,100)}%`,backgroundColor:Ae>=100?"#22c55e":m.color||"#6b7280"}})}),s.jsxs("div",{className:"flex justify-between mt-1",children:[s.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.percentComplete",{percent:Ae.toFixed(0)})}),be?.remaining_prints!=null&&be.remaining_prints>0&&s.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.remaining",{count:be.remaining_prints})})]})]}),m.target_parts_count&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsx("span",{className:"text-sm text-bambu-gray",children:n("projectDetail.progress.partsProgress")}),s.jsxs("span",{className:"text-sm font-medium text-white",children:[be?.completed_prints||0," / ",m.target_parts_count," ",n("projectDetail.progress.parts")]})]}),s.jsx("div",{className:"h-3 bg-bambu-dark rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${Math.min(Ue,100)}%`,backgroundColor:Ue>=100?"#22c55e":m.color||"#6b7280"}})}),s.jsxs("div",{className:"flex justify-between mt-1",children:[s.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.percentComplete",{percent:Ue.toFixed(0)})}),be?.remaining_parts!=null&&be.remaining_parts>0&&s.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.remaining",{count:be.remaining_parts})})]})]})]})}),be&&s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[s.jsx(Nt,{children:s.jsx(Mt,{className:"p-4",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:s.jsx(pc,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:n("projectDetail.stats.printJobs")}),s.jsxs("p",{className:"text-xl font-semibold text-white",children:[be.total_archives," ",s.jsx("span",{className:"text-sm font-normal text-bambu-gray",children:n("projectDetail.stats.total")})]}),be.failed_prints>0&&s.jsx("p",{className:"text-sm text-status-error",children:n("projectDetail.stats.failed",{count:be.failed_prints})}),s.jsx("p",{className:"text-sm text-bambu-gray",children:n("projectDetail.stats.partsPrinted",{count:be.completed_prints})})]})]})})}),s.jsx(vq,{icon:nr,label:n("projectDetail.stats.printTime"),value:QKe(be.total_print_time_hours),color:"text-yellow-400"}),s.jsx(vq,{icon:Pr,label:n("projectDetail.stats.filamentUsed"),value:ZKe(be.total_filament_grams),color:"text-purple-400"})]}),be&&(be.estimated_cost>0||m.budget)&&s.jsx(Nt,{children:s.jsxs(Mt,{className:"p-4",children:[s.jsx("h2",{className:"text-lg font-semibold text-white mb-3",children:n("projectDetail.cost.title")}),s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.filamentCost")}),s.jsxs("p",{className:"text-lg font-semibold text-white",children:[D,be.estimated_cost.toFixed(2)]})]}),be.total_energy_kwh>0&&s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.energy")}),s.jsxs("p",{className:"text-lg font-semibold text-white",children:[be.total_energy_kwh.toFixed(2)," kWh",be.total_energy_cost>0&&s.jsxs("span",{className:"text-sm text-bambu-gray ml-1",children:["(",D,be.total_energy_cost.toFixed(2),")"]})]})]}),m.budget&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.budget")}),s.jsxs("p",{className:"text-lg font-semibold text-white",children:[D,m.budget.toFixed(2)]})]}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.remaining")}),s.jsxs("p",{className:`text-lg font-semibold ${m.budget-be.estimated_cost>=0?"text-bambu-green":"text-red-400"}`,children:[D,(m.budget-be.estimated_cost).toFixed(2)]})]})]})]})]})}),m.children&&m.children.length>0&&s.jsx(Nt,{children:s.jsxs(Mt,{className:"p-4",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-3",children:[s.jsx(Vue,{className:"w-5 h-5"}),n("projectDetail.subProjects.title",{count:m.children.length})]}),s.jsx("div",{className:"space-y-2",children:m.children.map(Me=>s.jsxs(Ds,{to:`/projects/${Me.id}`,className:"flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:Me.color||"#6b7280"}}),s.jsx("span",{className:"text-white",children:Me.name}),s.jsx("span",{className:`text-xs px-2 py-0.5 rounded ${Me.status==="completed"?"bg-status-ok/20 text-status-ok":Me.status==="archived"?"bg-bambu-gray/20 text-bambu-gray":"bg-blue-500/20 text-blue-400"}`,children:Me.status})]}),Me.progress_percent!==null&&s.jsxs("span",{className:"text-sm text-bambu-gray",children:[Me.progress_percent.toFixed(0),"%"]})]},Me.id))})]})}),m.parent_id&&m.parent_name&&s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsx(sl,{className:"w-4 h-4 text-bambu-gray"}),s.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.partOf")}),s.jsx(Ds,{to:`/projects/${m.parent_id}`,className:"text-bambu-green hover:underline",children:m.parent_name})]}),(m.tags||m.due_date||m.priority!=="normal")&&s.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[m.priority&&m.priority!=="normal"&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.priorityLabel")}),s.jsx(tXe,{priority:m.priority,t:n})]}),m.due_date&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ti,{className:"w-4 h-4 text-bambu-gray"}),s.jsx("span",{className:"text-sm text-white",children:nXe(m.due_date)}),WP(m.due_date,n)&&s.jsxs("span",{className:`text-xs ${WP(m.due_date,n).color}`,children:["(",WP(m.due_date,n).label,")"]})]}),m.tags&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(wh,{className:"w-4 h-4 text-bambu-gray"}),s.jsx("div",{className:"flex flex-wrap gap-1",children:m.tags.split(",").map((Me,Ge)=>s.jsx("span",{className:"px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded",children:Me.trim()},Ge))})]})]}),s.jsx(Nt,{children:s.jsxs(Mt,{className:"p-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Ls,{className:"w-5 h-5"}),n("projectDetail.notes.title")]}),c?s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(Te,{variant:"secondary",size:"sm",onClick:H,disabled:j.isPending,children:[s.jsx(Lt,{className:"w-4 h-4 mr-1"}),n("common.cancel")]}),s.jsxs(Te,{size:"sm",onClick:F,disabled:j.isPending,children:[j.isPending?s.jsx(pt,{className:"w-4 h-4 animate-spin mr-1"}):s.jsx(hs,{className:"w-4 h-4 mr-1"}),n("common.save")]})]}):s.jsxs(Te,{variant:"secondary",size:"sm",onClick:I,disabled:!a("projects:update"),title:a("projects:update")?void 0:n("projectDetail.notes.noEditPermission"),children:[s.jsx(im,{className:"w-4 h-4 mr-1"}),n("common.edit")]})]}),c?s.jsx(iR,{content:d,onChange:f,placeholder:n("projectDetail.notes.placeholder")}):m.notes?s.jsx("div",{className:"prose prose-invert prose-sm max-w-none",dangerouslySetInnerHTML:{__html:m.notes}}):s.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.notes.empty")})]})}),s.jsx(Nt,{children:s.jsxs(Mt,{className:"p-4",children:[s.jsx("div",{className:"flex items-center justify-between mb-3",children:s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Il,{className:"w-5 h-5"}),n("projectDetail.files.title")]})}),s.jsxs("p",{className:"text-xs text-bambu-gray mb-3",children:[s.jsx(Ds,{to:"/files",className:"text-bambu-green hover:underline",children:n("projectDetail.files.linkFolders")})," ",n("projectDetail.files.forQuickAccess")]}),E&&E.length>0?s.jsx("div",{className:"space-y-2",children:E.map(Me=>s.jsxs(Ds,{to:`/files?folder=${Me.id}`,className:"flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[s.jsx(Il,{className:"w-5 h-5 text-bambu-green flex-shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"text-sm text-white truncate",children:Me.name}),s.jsx("p",{className:"text-xs text-bambu-gray",children:n("projectDetail.files.fileCount",{count:Me.file_count})})]})]}),s.jsx(gs,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"})]},Me.id))}):s.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.files.empty")})]})}),s.jsx(Nt,{children:s.jsxs(Mt,{className:"p-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-4",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(AW,{className:"w-5 h-5"}),n("projectDetail.bom.title"),be&&be.bom_total_items>0&&s.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",n("projectDetail.bom.acquired",{completed:be.bom_completed_items,total:be.bom_total_items}),")"]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[S&&S.some(Me=>Me.is_complete)&&s.jsx("button",{onClick:()=>ue(!pe),className:`text-xs px-2 py-1 rounded transition-colors ${pe?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:n(pe?"projectDetail.bom.showAll":"projectDetail.bom.hideDone")}),!re&&s.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>xe(!0),disabled:!a("projects:update"),title:a("projects:update")?void 0:n("projectDetail.bom.noAddPermission"),children:[s.jsx(fr,{className:"w-4 h-4 mr-1"}),n("projectDetail.bom.addPart")]})]})]}),re&&s.jsxs("form",{onSubmit:J,className:"bg-bambu-dark rounded-lg p-4 mb-4 space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[s.jsx("input",{type:"text",value:R,onChange:Me=>z(Me.target.value),className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.partNamePlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{type:"number",value:W,onChange:Me=>V(parseInt(Me.target.value)||1),className:"w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green",min:"1",placeholder:n("projectDetail.bom.qty")}),s.jsx("input",{type:"number",step:"0.01",value:X,onChange:Me=>Q(Me.target.value),className:"flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.price",{currency:D})})]})]}),s.jsx("input",{type:"url",value:ae,onChange:Me=>$(Me.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.sourcingUrlPlaceholder")}),s.jsx("input",{type:"text",value:K,onChange:Me=>ie(Me.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.remarksPlaceholder")}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(Te,{type:"button",variant:"secondary",size:"sm",onClick:()=>xe(!1),children:n("common.cancel")}),s.jsx(Te,{type:"submit",size:"sm",disabled:!R.trim()||ge.isPending,children:ge.isPending?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):n("projectDetail.bom.addPart")})]})]}),M?s.jsx("div",{className:"flex items-center justify-center py-4",children:s.jsx(pt,{className:"w-6 h-6 animate-spin text-bambu-green"})}):S&&S.length>0?s.jsxs("div",{className:"space-y-2",children:[S.filter(Me=>!pe||!Me.is_complete).map(Me=>s.jsx("div",{className:`p-3 rounded-lg transition-colors ${Me.is_complete?"bg-status-ok/10":"bg-bambu-dark"}`,children:Pe?.id===Me.id?s.jsxs("form",{onSubmit:ne,className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[s.jsx("input",{type:"text",value:Ee,onChange:Ge=>Oe(Ge.target.value),className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.partName"),autoFocus:!0}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{type:"number",value:me,onChange:Ge=>Xe(parseInt(Ge.target.value)||1),className:"w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green",min:"1",placeholder:n("projectDetail.bom.qty")}),s.jsx("input",{type:"number",step:"0.01",value:G,onChange:Ge=>Y(Ge.target.value),className:"flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.price",{currency:D})})]})]}),s.jsx("input",{type:"url",value:de,onChange:Ge=>q(Ge.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.sourcingUrlPlaceholder")}),s.jsx("input",{type:"text",value:ee,onChange:Ge=>U(Ge.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.remarksPlaceholder")}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(Te,{type:"button",variant:"secondary",size:"sm",onClick:Fe,children:n("common.cancel")}),s.jsx(Te,{type:"submit",size:"sm",disabled:!Ee.trim()||B.isPending,children:B.isPending?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):n("common.save")})]})]}):s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("button",{onClick:()=>a("projects:update")&&se(Me),disabled:B.isPending||!a("projects:update"),title:a("projects:update")?void 0:n("projectDetail.bom.noUpdatePermission"),className:`w-5 h-5 mt-0.5 rounded border-2 flex items-center justify-center transition-colors flex-shrink-0 ${Me.is_complete?"bg-status-ok border-status-ok text-white":a("projects:update")?"border-bambu-gray hover:border-bambu-green":"border-bambu-gray/50 cursor-not-allowed"}`,children:Me.is_complete&&s.jsx(Ar,{className:"w-3 h-3"})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsxs("p",{className:`text-sm font-medium ${Me.is_complete?"text-bambu-gray line-through":"text-white"}`,children:[Me.name,s.jsxs("span",{className:"text-bambu-gray font-normal ml-2",children:["x",Me.quantity_needed]})]}),Me.unit_price!==null&&s.jsxs("span",{className:"text-xs text-bambu-green whitespace-nowrap",children:[D,(Me.unit_price*Me.quantity_needed).toFixed(2)]})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("button",{onClick:()=>a("projects:update")&&_e(Me),disabled:!a("projects:update"),className:`p-1 rounded transition-colors flex-shrink-0 ${a("projects:update")?"hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:a("projects:update")?n("common.edit"):n("projectDetail.bom.noEditPermission"),children:s.jsx(Zi,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>a("projects:update")&&ve(Me.id,Me.name),disabled:!a("projects:update"),className:`p-1 rounded transition-colors flex-shrink-0 ${a("projects:update")?"hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400":"text-bambu-gray/50 cursor-not-allowed"}`,title:a("projects:update")?n("common.delete"):n("projectDetail.bom.noDeletePermission"),children:s.jsx(on,{className:"w-4 h-4"})})]})]}),Me.sourcing_url&&s.jsxs("a",{href:Me.sourcing_url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 mt-1 text-xs text-blue-400 hover:text-blue-300 transition-colors",onClick:Ge=>Ge.stopPropagation(),children:[s.jsx(Xr,{className:"w-3 h-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:(()=>{try{return new URL(Me.sourcing_url).hostname.replace("www.","")}catch{return Me.sourcing_url}})()})]}),Me.remarks&&s.jsx("p",{className:"mt-1 text-xs text-bambu-gray/80 italic",children:Me.remarks})]})]})},Me.id)),S.some(Me=>Me.unit_price!==null)&&s.jsxs("div",{className:"pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm",children:[s.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.bom.totalCost")}),s.jsxs("span",{className:"text-white font-medium",children:[D,S.reduce((Me,Ge)=>Me+(Ge.unit_price||0)*Ge.quantity_needed,0).toFixed(2)]})]})]}):s.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.bom.empty")})]})}),s.jsx(Nt,{children:s.jsxs(Mt,{className:"p-4",children:[s.jsx("div",{className:"flex items-center justify-between mb-3",children:s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(q0,{className:"w-5 h-5"}),n("projectDetail.timeline.title")]})}),k?s.jsx("div",{className:"flex items-center justify-center py-4",children:s.jsx(pt,{className:"w-6 h-6 animate-spin text-bambu-green"})}):T&&T.length>0?s.jsx("div",{className:"space-y-3",children:T.slice(0,10).map((Me,Ge)=>s.jsxs("div",{className:"flex gap-3",children:[s.jsxs("div",{className:`w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0 ${Me.event_type==="print_completed"?"bg-status-ok/20 text-status-ok":Me.event_type==="print_failed"?"bg-status-error/20 text-status-error":Me.event_type==="print_started"?"bg-yellow-500/20 text-yellow-400":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:[Me.event_type==="print_completed"&&s.jsx(Ar,{className:"w-4 h-4"}),Me.event_type==="print_failed"&&s.jsx(Qi,{className:"w-4 h-4"}),Me.event_type==="print_started"&&s.jsx(Pr,{className:"w-4 h-4"}),Me.event_type==="queued"&&s.jsx(pj,{className:"w-4 h-4"}),Me.event_type==="project_created"&&s.jsx(fr,{className:"w-4 h-4"})]}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm text-white",children:Me.title}),Me.description&&s.jsx("p",{className:"text-xs text-bambu-gray truncate",children:Me.description}),s.jsx("p",{className:"text-xs text-bambu-gray/70",children:Ie(Me.timestamp)})]})]},Ge))}):s.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.timeline.empty")})]})}),!m.is_template&&s.jsx("div",{className:"flex justify-end",children:s.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>rt.mutate(),disabled:rt.isPending||!a("projects:create"),title:a("projects:create")?void 0:n("projectDetail.template.noCreatePermission"),children:[rt.isPending?s.jsx(pt,{className:"w-4 h-4 animate-spin mr-2"}):s.jsx(Fl,{className:"w-4 h-4 mr-2"}),n("projectDetail.template.saveAsTemplate")]})}),be&&(be.queued_prints>0||be.in_progress_prints>0)&&s.jsx(Nt,{children:s.jsxs(Mt,{className:"p-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(pj,{className:"w-5 h-5"}),n("projectDetail.queue.title")]}),s.jsx(Ds,{to:`/queue?project=${p}`,className:"text-sm text-bambu-green hover:underline",children:n("projectDetail.queue.viewAll")})]}),s.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[be.in_progress_prints>0&&s.jsx("span",{className:"text-yellow-400",children:n("projectDetail.queue.printing",{count:be.in_progress_prints})}),be.queued_prints>0&&s.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.queue.queued",{count:be.queued_prints})})]})]})}),s.jsxs("div",{children:[s.jsx("div",{className:"flex items-center justify-between mb-4",children:s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(pc,{className:"w-5 h-5"}),n("projectDetail.prints.title",{count:v?.length||0})]})}),y?s.jsx("div",{className:"flex items-center justify-center py-8",children:s.jsx(pt,{className:"w-6 h-6 animate-spin text-bambu-green"})}):s.jsx(eXe,{archives:v||[],t:n})]}),o&&s.jsx($re,{t:n,project:{...m,archive_count:be?.total_archives||0,total_items:be?.total_items||0,completed_count:be?.completed_prints||0,failed_count:be?.failed_prints||0,queue_count:be?.queued_prints||0,progress_percent:be?.progress_percent||null,archives:[]},onClose:()=>l(!1),onSave:Me=>j.mutate(Me),isLoading:j.isPending}),fe.isOpen&&s.jsx(Jn,{title:fe.title,message:fe.message,confirmText:n("common.delete"),variant:"danger",onConfirm:fe.onConfirm,onCancel:()=>we(Me=>({...Me,isOpen:!1}))})]})}function hg(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:`${(t/(1024*1024*1024)).toFixed(2)} GB`}function iXe(t){if(!t)return"-";const e=Math.floor(t/3600),n=Math.floor(t%3600/60);return e>0?`${e}h ${n}m`:`${n}m`}function aXe({parentId:t,onClose:e,onSave:n,isLoading:r,t:i}){const[a,o]=_.useState(""),l=c=>{c.preventDefault(),n({name:a.trim(),parent_id:t})};return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[s.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:i("fileManager.newFolder")})}),s.jsxs("form",{onSubmit:l,className:"p-4 space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:i("fileManager.folderName")}),s.jsx("input",{type:"text",value:a,onChange:c=>o(c.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:i("fileManager.folderNamePlaceholder"),autoFocus:!0,required:!0})]}),s.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[s.jsx(Te,{type:"button",variant:"secondary",onClick:e,children:i("common.cancel")}),s.jsx(Te,{type:"submit",disabled:!a.trim()||r,children:r?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):i("common.create")})]})]})]})})}function sXe({type:t,currentName:e,onClose:n,onSave:r,isLoading:i,t:a}){const[o,l]=_.useState(e),c=u=>{u.preventDefault(),o.trim()&&o.trim()!==e&&r(o.trim())};return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[s.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:a(t==="file"?"fileManager.renameFile":"fileManager.renameFolder")})}),s.jsxs("form",{onSubmit:c,className:"p-4 space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("common.name")}),s.jsx("input",{type:"text",value:o,onChange:u=>l(u.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",autoFocus:!0,required:!0})]}),s.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[s.jsx(Te,{type:"button",variant:"secondary",onClick:n,children:a("common.cancel")}),s.jsx(Te,{type:"submit",disabled:!o.trim()||o.trim()===e||i,children:i?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):a("common.rename")})]})]})]})})}function oXe({folders:t,selectedFiles:e,currentFolderId:n,onClose:r,onMove:i,isLoading:a,t:o}){const[l,c]=_.useState(null),u=(f,p=0)=>{const m=[];for(const x of f)m.push({id:x.id,name:x.name,depth:p}),x.children.length>0&&m.push(...u(x.children,p+1));return m},d=[{id:null,name:o("fileManager.rootNoFolder"),depth:0},...u(t)];return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[s.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:o("fileManager.moveFiles",{count:e.length})})}),s.jsxs("div",{className:"p-4 space-y-4",children:[s.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1",children:d.map(f=>s.jsxs("button",{onClick:()=>c(f.id),disabled:f.id===n,className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===f.id?"bg-bambu-green/20 text-bambu-green":f.id===n?"opacity-50 cursor-not-allowed text-bambu-gray":"hover:bg-bambu-dark text-white"}`,style:{paddingLeft:`${12+f.depth*16}px`},children:[s.jsx(Il,{className:"w-4 h-4"}),f.name,f.id===n&&s.jsxs("span",{className:"text-xs text-bambu-gray ml-auto",children:["(",o("fileManager.current"),")"]})]},f.id??"root"))}),s.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[s.jsx(Te,{type:"button",variant:"secondary",onClick:r,children:o("common.cancel")}),s.jsx(Te,{onClick:()=>i(l),disabled:a,children:a?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):o("common.move")})]})]})]})})}function lXe({folder:t,onClose:e,onLink:n,isLoading:r,t:i}){const[a,o]=_.useState("project"),[l,c]=_.useState(t.project_id||t.archive_id||null);_.useState(()=>{t.archive_id&&o("archive")});const{data:u}=ot({queryKey:["projects"],queryFn:()=>ce.getProjects()}),{data:d}=ot({queryKey:["archives-for-link"],queryFn:()=>ce.getArchives(void 0,void 0,100)}),f=()=>{n(a==="project"?{project_id:l,archive_id:0}:{project_id:0,archive_id:l})},p=()=>{n({project_id:0,archive_id:0})},m=t.project_id||t.archive_id;return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(uc,{className:"w-5 h-5 text-bambu-green"}),i("fileManager.linkFolder")]}),s.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:s.jsx(Lt,{className:"w-5 h-5 text-bambu-gray"})})]}),s.jsxs("div",{className:"p-4 space-y-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:i("fileManager.linkFolderDescription",{name:t.name})}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs("button",{onClick:()=>{o("project"),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a==="project"?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,children:[s.jsx(bW,{className:"w-4 h-4"}),i("fileManager.project")]}),s.jsxs("button",{onClick:()=>{o("archive"),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a==="archive"?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,children:[s.jsx(ho,{className:"w-4 h-4"}),i("fileManager.archive")]})]}),s.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2",children:a==="project"?u&&u.length>0?u.map(x=>s.jsxs("button",{onClick:()=>c(x.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===x.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark-tertiary text-white"}`,children:[s.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:x.color||"#00ae42"}}),s.jsx("span",{className:"truncate",children:x.name})]},x.id)):s.jsx("p",{className:"text-sm text-bambu-gray text-center py-4",children:i("fileManager.noProjectsFound")}):d&&d.length>0?d.map(x=>s.jsxs("button",{onClick:()=>c(x.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===x.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark-tertiary text-white"}`,children:[s.jsx(Bf,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),s.jsx("span",{className:"truncate",children:x.print_name||x.filename})]},x.id)):s.jsx("p",{className:"text-sm text-bambu-gray text-center py-4",children:i("fileManager.noArchivesFound")})})]}),s.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-between",children:[m&&s.jsxs(Te,{variant:"danger",onClick:p,disabled:r,children:[s.jsx(RR,{className:"w-4 h-4 mr-2"}),i("fileManager.unlink")]}),s.jsxs("div",{className:`flex gap-2 ${m?"":"ml-auto"}`,children:[s.jsx(Te,{variant:"secondary",onClick:e,children:i("common.cancel")}),s.jsx(Te,{onClick:f,disabled:!l||r,children:r?s.jsx(pt,{className:"w-4 h-4 animate-spin"}):i("fileManager.link")})]})]})]})})}function cXe({folderId:t,onClose:e,onUploadComplete:n,t:r}){const[i,a]=_.useState([]),[o,l]=_.useState(!1),[c,u]=_.useState(!1),[d,f]=_.useState(!0),[p,m]=_.useState(!1),[x,b]=_.useState(!0),v=_.useRef(null),y=z=>{z.preventDefault(),l(!0)},S=z=>{z.preventDefault(),l(!1)},M=z=>{z.preventDefault(),l(!1);const W=Array.from(z.dataTransfer.files);k(W)},T=z=>{z.target.files&&k(Array.from(z.target.files))},k=z=>{const W=z.map(V=>({file:V,status:"pending",isZip:V.name.toLowerCase().endsWith(".zip"),is3mf:V.name.toLowerCase().endsWith(".3mf")}));a(V=>[...V,...W])},C=z=>{a(W=>W.filter((V,X)=>X!==z))},E=i.some(z=>z.isZip&&z.status==="pending"),D=i.some(z=>z.file.name.toLowerCase().endsWith(".stl")&&z.status==="pending"),A=i.some(z=>z.is3mf&&z.status==="pending"),j=async()=>{if(i.length!==0){u(!0);for(let z=0;zW.map((V,X)=>X===z?{...V,status:"uploading"}:V));try{if(i[z].isZip){const W=await ce.extractZipFile(i[z].file,t,d,p,x);a(V=>V.map((X,Q)=>Q===z?{...X,status:W.errors.length>0&&W.extracted===0?"error":"success",extractedCount:W.extracted,error:W.errors.length>0?`${W.errors.length} files failed`:void 0}:X))}else await ce.uploadLibraryFile(i[z].file,t,x),a(W=>W.map((V,X)=>X===z?{...V,status:"success"}:V))}catch(W){a(V=>V.map((X,Q)=>Q===z?{...X,status:"error",error:W instanceof Error?W.message:"Upload failed"}:X))}}u(!1),n(),e()}},I=i.filter(z=>z.status==="pending").length,F=i.filter(z=>z.status==="success").length,H=i.filter(z=>z.status==="error").length,R=i.length>0&&I===0&&!c;return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-lg border border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[s.jsx("h2",{className:"text-lg font-semibold text-white",children:r("fileManager.uploadFiles")}),s.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:s.jsx(Lt,{className:"w-5 h-5 text-bambu-gray"})})]}),s.jsxs("div",{className:"p-4 space-y-4",children:[s.jsxs("div",{onDragOver:y,onDragLeave:S,onDrop:M,onClick:()=>v.current?.click(),className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${o?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,children:[s.jsx(za,{className:`w-10 h-10 mx-auto mb-3 ${o?"text-bambu-green":"text-bambu-gray"}`}),s.jsx("p",{className:"text-white font-medium",children:r(o?"fileManager.dropFilesHere":"fileManager.dragDropFiles")}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:r("fileManager.orClickToBrowse")}),s.jsx("p",{className:"text-xs text-bambu-gray/70 mt-2",children:r("fileManager.allFileTypesSupported")})]}),s.jsx("input",{ref:v,type:"file",multiple:!0,className:"hidden",onChange:T}),E&&s.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(ho,{className:"w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"text-sm text-blue-300 font-medium",children:r("fileManager.zipFilesDetected")}),s.jsx("p",{className:"text-xs text-blue-300/70 mt-1",children:r("fileManager.zipExtractOptions")}),s.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:d,onChange:z=>f(z.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),s.jsx("span",{className:"text-sm text-white",children:r("fileManager.preserveZipStructure")})]}),s.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:p,onChange:z=>m(z.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),s.jsx("span",{className:"text-sm text-white",children:r("fileManager.createFolderFromZip")})]})]})]})}),A&&s.jsx("div",{className:"p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg",children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(Pr,{className:"w-5 h-5 text-purple-400 mt-0.5 flex-shrink-0"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"text-sm text-purple-300 font-medium",children:r("fileManager.threemfDetected")}),s.jsx("p",{className:"text-xs text-purple-300/70 mt-1",children:r("fileManager.threemfExtractionInfo")})]})]})}),(D||E)&&s.jsx("div",{className:"p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(Lu,{className:"w-5 h-5 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"text-sm text-bambu-green font-medium",children:r("fileManager.stlThumbnailGeneration")}),s.jsx("p",{className:"text-xs text-bambu-green/70 mt-1",children:r(E&&!D?"fileManager.zipMayContainStl":"fileManager.thumbnailsCanBeGenerated")}),s.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:x,onChange:z=>b(z.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),s.jsx("span",{className:"text-sm text-white",children:r("fileManager.generateThumbnailsForStl")})]})]})]})}),i.length>0&&s.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:i.map((z,W)=>s.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[z.isZip?s.jsx(ho,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):s.jsx(uM,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm text-white truncate",children:z.file.name}),s.jsxs("p",{className:"text-xs text-bambu-gray",children:[(z.file.size/1024/1024).toFixed(2)," MB",z.isZip&&z.status==="pending"&&s.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",r("fileManager.willBeExtracted")]}),z.extractedCount!==void 0&&s.jsxs("span",{className:"text-green-400 ml-2",children:["• ",r("fileManager.filesExtracted",{count:z.extractedCount})]})]})]}),z.status==="pending"&&s.jsx("button",{onClick:()=>C(W),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:s.jsx(Lt,{className:"w-4 h-4 text-bambu-gray"})}),z.status==="uploading"&&s.jsx(pt,{className:"w-4 h-4 text-bambu-green animate-spin"}),z.status==="success"&&s.jsx(Ar,{className:"w-4 h-4 text-green-500"}),z.status==="error"&&s.jsx("span",{title:z.error,children:s.jsx(Qi,{className:"w-4 h-4 text-red-500"})})]},W))}),R&&s.jsx("div",{className:"p-3 bg-bambu-dark rounded-lg",children:s.jsxs("p",{className:"text-sm text-white",children:[r("fileManager.uploadComplete",{succeeded:F}),H>0&&s.jsxs("span",{className:"text-red-400",children:[", ",r("fileManager.uploadFailed",{count:H})]})]})})]}),s.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2",children:[s.jsx(Te,{variant:"secondary",onClick:e,children:r(R?"common.close":"common.cancel")}),!R&&s.jsx(Te,{onClick:j,disabled:I===0||c,children:c?s.jsxs(s.Fragment,{children:[s.jsx(pt,{className:"w-4 h-4 mr-2 animate-spin"}),r("fileManager.uploading")]}):s.jsxs(s.Fragment,{children:[s.jsx(za,{className:"w-4 h-4 mr-2"}),r("common.upload")," ",I>0?`(${I})`:""]})})]})]})})}function Vre({folder:t,selectedFolderId:e,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o=0,wrapNames:l=!1,hasPermission:c,t:u}){const[d,f]=_.useState(!0),[p,m]=_.useState(!1),x=t.children.length>0,b=t.project_id||t.archive_id;return s.jsxs("div",{children:[s.jsxs("div",{className:`group flex items-center gap-1 px-2 py-1.5 rounded cursor-pointer transition-colors ${e===t.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark text-white"}`,style:{paddingLeft:`${8+o*12}px`},onClick:()=>n(t.id),children:[x?s.jsx("button",{onClick:v=>{v.stopPropagation(),f(!d)},className:"p-0.5 hover:bg-bambu-dark-tertiary rounded",children:s.jsx(gs,{className:`w-3.5 h-3.5 transition-transform ${d?"rotate-90":""}`})}):s.jsx("div",{className:"w-4.5"}),s.jsx(Il,{className:"w-4 h-4 text-bambu-green flex-shrink-0"}),s.jsx("span",{className:`text-sm flex-1 min-w-0 ${l?"break-all":"truncate"}`,title:t.name,children:t.name}),b&&s.jsxs("button",{onClick:v=>{v.stopPropagation(),i(t)},className:"flex-shrink-0 flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400 hover:bg-blue-500/30 transition-colors",title:`${t.project_name?`Project: ${t.project_name}`:`Archive: ${t.archive_name}`} (click to change)`,children:[s.jsx(uc,{className:"w-3 h-3"}),t.project_name?s.jsx(bW,{className:"w-3 h-3"}):s.jsx(ho,{className:"w-3 h-3"})]}),t.file_count>0&&s.jsx("span",{className:"flex-shrink-0 text-xs text-bambu-gray",children:t.file_count}),!b&&s.jsx("button",{onClick:v=>{v.stopPropagation(),i(t)},className:"flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary",title:u("fileManager.linkToProjectOrArchive"),children:s.jsx(uc,{className:"w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green"})}),s.jsx("div",{className:`flex-shrink-0 flex items-center gap-0.5 transition-opacity ${l?"":"opacity-0 group-hover:opacity-100"}`,onClick:v=>v.stopPropagation(),children:s.jsxs("div",{className:"relative",children:[s.jsx("button",{onClick:()=>m(!p),className:"p-1 rounded hover:bg-bambu-dark-tertiary",children:s.jsx(sh,{className:"w-3.5 h-3.5 text-bambu-gray"})}),p&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>m(!1)}),s.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]",children:[s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:update_all")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:update_all")&&(a(t),m(!1))},disabled:!c("library:update_all"),title:c("library:update_all")?void 0:u("fileManager.noPermissionRenameFolder"),children:[s.jsx(Zi,{className:"w-3.5 h-3.5"}),u("common.rename")]}),s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:update_all")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:update_all")&&(i(t),m(!1))},disabled:!c("library:update_all"),title:c("library:update_all")?void 0:u("fileManager.noPermissionLinkFolder"),children:[s.jsx(uc,{className:"w-3.5 h-3.5"}),u(b?"fileManager.changeLink":"fileManager.linkTo")]}),s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:delete_all")?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:delete_all")&&(r(t.id),m(!1))},disabled:!c("library:delete_all"),title:c("library:delete_all")?void 0:u("fileManager.noPermissionDeleteFolder"),children:[s.jsx(on,{className:"w-3.5 h-3.5"}),u("common.delete")]})]})]})]})})]}),x&&d&&s.jsx("div",{children:t.children.map(v=>s.jsx(Vre,{folder:v,selectedFolderId:e,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o+1,wrapNames:l,hasPermission:c,t:u},v.id))})]})}function hR(t){const e=t.toLowerCase();return e.endsWith(".gcode")||e.includes(".gcode.")}function uXe({file:t,isSelected:e,isMobile:n,onSelect:r,onDelete:i,onDownload:a,onAddToQueue:o,onPrint:l,onRename:c,onGenerateThumbnail:u,thumbnailVersion:d,hasPermission:f,canModify:p,authEnabled:m,t:x}){const[b,v]=_.useState(!1);return s.jsxs("div",{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer overflow-hidden ${e?"border-bambu-green ring-1 ring-bambu-green":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,onClick:()=>r(t.id),children:[s.jsxs("div",{className:"aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden",children:[t.thumbnail_path?s.jsx("img",{src:`${ce.getLibraryFileThumbnailUrl(t.id)}${d?`?v=${d}`:""}`,alt:t.filename,className:"w-full h-full object-cover"}):s.jsx(Bf,{className:"w-12 h-12 text-bambu-gray/30"}),s.jsx("div",{className:`absolute top-2 right-2 text-xs px-1.5 py-0.5 rounded font-medium ${t.file_type==="3mf"?"bg-bambu-green/90 text-white":t.file_type==="gcode"?"bg-blue-500/90 text-white":t.file_type==="stl"?"bg-purple-500/90 text-white":"bg-bambu-gray/90 text-white"}`,children:t.file_type.toUpperCase()})]}),s.jsxs("div",{className:"p-3",children:[s.jsx("h3",{className:"text-sm font-medium text-white truncate",title:t.print_name||t.filename,children:t.print_name||t.filename}),s.jsxs("div",{className:"flex items-center gap-3 mt-1 text-xs text-bambu-gray",children:[s.jsx("span",{children:hg(t.file_size)}),t.print_time_seconds&&s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(nr,{className:"w-3 h-3"}),iXe(t.print_time_seconds)]})]}),t.sliced_for_model&&s.jsxs("div",{className:"mt-1 text-xs text-bambu-gray flex items-center gap-1",children:[s.jsx(Pr,{className:"w-3 h-3"}),t.sliced_for_model]}),t.print_count>0&&s.jsx("div",{className:"mt-1 text-xs text-bambu-green",children:x("fileManager.printedCount",{count:t.print_count})}),m&&t.created_by_username&&s.jsxs("div",{className:"mt-1 text-xs text-bambu-gray flex items-center gap-1",children:[s.jsx(Fu,{className:"w-3 h-3"}),t.created_by_username]})]}),s.jsxs("div",{className:`absolute bottom-2 right-2 transition-opacity ${n?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:y=>y.stopPropagation(),children:[s.jsx("button",{onClick:()=>v(!b),className:"p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary",children:s.jsx(sh,{className:"w-4 h-4 text-bambu-gray"})}),b&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>v(!1)}),s.jsxs("div",{className:"absolute right-0 bottom-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[140px]",children:[l&&hR(t.filename)&&s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("printers:control")?"text-bambu-green hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("printers:control")&&(l(t),v(!1))},disabled:!f("printers:control"),title:f("printers:control")?void 0:x("fileManager.noPermissionPrint"),children:[s.jsx(Pr,{className:"w-3.5 h-3.5"}),x("common.print")]}),o&&hR(t.filename)&&s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("queue:create")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("queue:create")&&(o(t.id),v(!1))},disabled:!f("queue:create"),title:f("queue:create")?void 0:x("fileManager.noPermissionAddToQueue"),children:[s.jsx(nr,{className:"w-3.5 h-3.5"}),x("fileManager.schedulePrint")]}),s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("library:read")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("library:read")&&(a(t.id),v(!1))},disabled:!f("library:read"),title:f("library:read")?void 0:x("fileManager.noPermissionDownload"),children:[s.jsx(wi,{className:"w-3.5 h-3.5"}),x("common.download")]}),c&&s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("library","update",t.created_by_id)?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("library","update",t.created_by_id)&&(c(t),v(!1))},disabled:!p("library","update",t.created_by_id),title:p("library","update",t.created_by_id)?void 0:x("fileManager.noPermissionRenameFile"),children:[s.jsx(Zi,{className:"w-3.5 h-3.5"}),x("common.rename")]}),u&&t.file_type==="stl"&&s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("library","update",t.created_by_id)?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("library","update",t.created_by_id)&&(u(t),v(!1))},disabled:!p("library","update",t.created_by_id),title:p("library","update",t.created_by_id)?void 0:x("fileManager.noPermissionGenerateThumbnail"),children:[s.jsx(Lu,{className:"w-3.5 h-3.5"}),x("fileManager.generateThumbnail")]}),s.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("library","delete",t.created_by_id)?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("library","delete",t.created_by_id)&&(i(t.id),v(!1))},disabled:!p("library","delete",t.created_by_id),title:p("library","delete",t.created_by_id)?void 0:x("fileManager.noPermissionDeleteFile"),children:[s.jsx(on,{className:"w-3.5 h-3.5"}),x("common.delete")]})]})]})]}),s.jsx("div",{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${e?"bg-bambu-green border-bambu-green":`border-white/30 bg-black/30 ${n?"opacity-100":"opacity-0 group-hover:opacity-100"}`}`,children:e&&s.jsx("div",{className:"w-2 h-2 bg-white rounded-sm"})})]})}function dXe(){const{t}=On(),e=ln(),{showToast:n}=Vn(),{hasPermission:r,hasAnyPermission:i,canModify:a,authEnabled:o}=Ci(),[l]=wR(),c=l.get("folder"),u=c?parseInt(c,10):null,[d,f]=_.useState(u),[p,m]=_.useState([]),[x,b]=_.useState(!1),[v,y]=_.useState(!1),[S,M]=_.useState(!1),[T,k]=_.useState(null),[C,E]=_.useState(null),[D,A]=_.useState(null),[j,I]=_.useState(null),[F,H]=_.useState(null),[R,z]=_.useState(null),[W,V]=_.useState({}),[X,Q]=_.useState(()=>localStorage.getItem("library-view-mode")||"grid"),[ae,$]=_.useState(()=>localStorage.getItem("library-wrap-folders")==="true"),[K,ie]=_.useState(()=>{const Re=localStorage.getItem("library-sidebar-width");return Re?parseInt(Re,10):256}),[re,xe]=_.useState(!1),pe=_.useRef(null);_.useEffect(()=>{if(!re)return;document.body.style.userSelect="none",document.body.style.cursor="col-resize";const Re=It=>{if(!pe.current)return;const Ht=pe.current.parentElement?.getBoundingClientRect();if(!Ht)return;const Nn=It.clientX-Ht.left,Ln=Math.min(500,Math.max(200,Nn));ie(Ln)},ct=()=>{xe(!1),document.body.style.userSelect="",document.body.style.cursor="",localStorage.setItem("library-sidebar-width",String(K))};return document.addEventListener("mousemove",Re),document.addEventListener("mouseup",ct),()=>{document.removeEventListener("mousemove",Re),document.removeEventListener("mouseup",ct),document.body.style.userSelect="",document.body.style.cursor=""}},[re,K]);const[ue,Pe]=_.useState(""),[te,Ee]=_.useState("all"),[Oe,me]=_.useState(""),[Xe,G]=_.useState(()=>localStorage.getItem("library-sort-field")||"name"),[Y,de]=_.useState(()=>localStorage.getItem("library-sort-direction")||"asc"),q=IR();_.useEffect(()=>{const Re=l.get("folder");if(Re){const ct=parseInt(Re,10);f(ct)}},[l]);const{data:ee}=ot({queryKey:["settings"],queryFn:()=>ce.getSettings()}),{data:U,isLoading:fe}=ot({queryKey:["library-folders"],queryFn:()=>ce.getLibraryFolders()}),{data:we,isLoading:ge}=ot({queryKey:["library-files",d],queryFn:()=>ce.getLibraryFiles(d,d===null)}),{data:B}=ot({queryKey:["library-stats"],queryFn:()=>ce.getLibraryStats()}),{data:O}=ot({queryKey:["users"],queryFn:()=>ce.getUsers()}),J=_.useMemo(()=>{if(!we)return[];const Re=new Set(we.map(ct=>ct.file_type));return Array.from(Re).sort()},[we]),se=_.useMemo(()=>{if(!we)return[];let Re=[...we];if(ue.trim()){const ct=ue.toLowerCase();Re=Re.filter(It=>It.filename.toLowerCase().includes(ct)||It.print_name&&It.print_name.toLowerCase().includes(ct))}if(te!=="all"&&(Re=Re.filter(ct=>ct.file_type===te)),Oe.trim()){const ct=Oe.toLowerCase();Re=Re.filter(It=>It.created_by_username&&It.created_by_username.toLowerCase().includes(ct))}return Re.sort((ct,It)=>{let Ht=0;switch(Xe){case"name":Ht=(ct.print_name||ct.filename).localeCompare(It.print_name||It.filename);break;case"date":Ht=new Date(ct.created_at).getTime()-new Date(It.created_at).getTime();break;case"size":Ht=ct.file_size-It.file_size;break;case"type":Ht=ct.file_type.localeCompare(It.file_type);break;case"prints":Ht=ct.print_count-It.print_count;break}return Y==="asc"?Ht:-Ht}),Re},[we,ue,te,Oe,Xe,Y]),ve=_.useMemo(()=>{if(!B||!ee)return!1;const Re=(ee.library_disk_warning_gb||5)*1024*1024*1024;return B.disk_free_bytesce.createLibraryFolder(Re),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),b(!1),n(t("fileManager.toast.folderCreated"),"success")},onError:Re=>n(Re.message,"error")}),ne=gt({mutationFn:Re=>ce.deleteLibraryFolder(Re),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-stats"]}),d===C?.id&&f(null),E(null),n(t("fileManager.toast.folderDeleted"),"success")},onError:Re=>{E(null),n(Re.message,"error")}}),Fe=gt({mutationFn:Re=>ce.deleteLibraryFile(Re),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]}),m(Re=>Re.filter(ct=>ct!==C?.id)),E(null),n(t("fileManager.toast.fileDeleted"),"success")},onError:Re=>{E(null),n(Re.message,"error")}}),He=gt({mutationFn:Re=>ce.bulkDeleteLibrary(Re,[]),onSuccess:(Re,ct)=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]}),n(t("fileManager.toast.filesDeleted",{count:ct.length}),"success"),m([]),E(null)},onError:Re=>{E(null),n(Re.message,"error")}}),rt=gt({mutationFn:({fileIds:Re,folderId:ct})=>ce.moveLibraryFiles(Re,ct),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),m([]),y(!1),n(t("fileManager.toast.filesMoved"),"success")},onError:Re=>n(Re.message,"error")}),Ie=gt({mutationFn:({id:Re,data:ct})=>ce.updateLibraryFolder(Re,ct),onSuccess:(Re,ct)=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["project-folders"]}),e.invalidateQueries({queryKey:["archive-folders"]}),k(null);const It=ct.data.project_id===0&&ct.data.archive_id===0;n(t(It?"fileManager.toast.folderUnlinked":"fileManager.toast.folderLinked"),"success")},onError:Re=>n(Re.message,"error")}),be=gt({mutationFn:({id:Re,filename:ct})=>ce.updateLibraryFile(Re,{filename:ct}),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),z(null),n(t("fileManager.toast.fileRenamed"),"success")},onError:Re=>{z(null),n(Re.message,"error")}}),Ae=gt({mutationFn:({id:Re,name:ct})=>ce.updateLibraryFolder(Re,{name:ct}),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-files"]}),z(null),n(t("fileManager.toast.folderRenamed"),"success")},onError:Re=>{z(null),n(Re.message,"error")}}),Ue=gt({mutationFn:()=>ce.batchGenerateStlThumbnails({all_missing:!0}),onSuccess:Re=>{if(e.invalidateQueries({queryKey:["library-files"]}),Re.succeeded>0){const ct=Date.now(),It={};Re.results.forEach(Ht=>{Ht.success&&(It[Ht.file_id]=ct)}),V(Ht=>({...Ht,...It}))}Re.succeeded>0&&Re.failed===0?n(t("fileManager.toast.thumbnailsGenerated",{count:Re.succeeded}),"success"):Re.succeeded>0&&Re.failed>0?n(t("fileManager.toast.thumbnailsGeneratedPartial",{succeeded:Re.succeeded,failed:Re.failed}),"success"):Re.processed===0?n(t("fileManager.toast.noStlMissingThumbnails"),"info"):n(t("fileManager.toast.failedToGenerateThumbnails",{error:Re.results[0]?.error||"Unknown error"}),"error")},onError:Re=>n(Re.message,"error")}),Me=gt({mutationFn:Re=>ce.batchGenerateStlThumbnails({file_ids:[Re]}),onSuccess:Re=>{if(e.invalidateQueries({queryKey:["library-files"]}),Re.succeeded>0){const ct=Re.results[0]?.file_id;ct&&V(It=>({...It,[ct]:Date.now()})),n(t("fileManager.toast.thumbnailGenerated"),"success")}else n(t("fileManager.toast.failedToGenerateThumbnail",{error:Re.results[0]?.error||"Unknown error"}),"error")},onError:Re=>n(Re.message,"error")}),Ge=_.useCallback(Re=>{const ct=Re.toLowerCase();return ct.endsWith(".gcode")||ct.includes(".gcode.")},[]),Ne=_.useMemo(()=>we?we.filter(Re=>p.includes(Re.id)&&Ge(Re.filename)):[],[we,p,Ge]),nt=_.useCallback(Re=>{m(ct=>ct.includes(Re)?ct.filter(It=>It!==Re):[...ct,Re])},[]),ke=_.useCallback(()=>{se.length>0&&m(se.map(Re=>Re.id))},[se]),Ke=_.useCallback(()=>{m([])},[]),Be=()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]})},le=Re=>{ce.downloadLibraryFile(Re).catch(ct=>{console.error("Library file download failed:",ct)})},$e=()=>{C&&(C.type==="file"?Fe.mutate(C.id):C.type==="folder"?ne.mutate(C.id):C.type==="bulk"&&He.mutate(p))},it=ne.isPending||Fe.isPending||He.isPending,kt=Re=>{Q(Re),localStorage.setItem("library-view-mode",Re)},bt=fe||ge;return s.jsxs("div",{className:"p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-[calc(100vh-64px)] flex flex-col",children:[s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6",children:[s.jsxs("div",{children:[s.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[s.jsx("div",{className:"p-2.5 bg-bambu-green/10 rounded-xl",children:s.jsx(Il,{className:"w-6 h-6 text-bambu-green"})}),t("fileManager.title")]}),s.jsx("p",{className:"text-sm text-bambu-gray mt-2 ml-14",children:t("fileManager.subtitle")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"flex items-center bg-bambu-dark rounded-lg p-1",children:[s.jsx("button",{onClick:()=>kt("grid"),className:`p-1.5 rounded transition-colors ${X==="grid"?"bg-bambu-dark-secondary text-white":"text-bambu-gray hover:text-white"}`,title:t("fileManager.gridView"),children:s.jsx(mM,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>kt("list"),className:`p-1.5 rounded transition-colors ${X==="list"?"bg-bambu-dark-secondary text-white":"text-bambu-gray hover:text-white"}`,title:t("fileManager.listView"),children:s.jsx(pM,{className:"w-4 h-4"})})]}),s.jsxs(Te,{variant:"secondary",onClick:()=>Ue.mutate(),disabled:Ue.isPending||!i("library:update_own","library:update_all"),title:i("library:update_own","library:update_all")?t("fileManager.generateThumbnailsForMissing"):t("fileManager.noPermissionGenerateThumbnail"),children:[Ue.isPending?s.jsx(pt,{className:"w-4 h-4 mr-2 animate-spin"}):s.jsx(Lu,{className:"w-4 h-4 mr-2"}),t("fileManager.generateThumbnails")]}),s.jsxs(Te,{variant:"secondary",onClick:()=>b(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionCreateFolder"),children:[s.jsx(Hue,{className:"w-4 h-4 mr-2"}),t("fileManager.newFolder")]}),s.jsxs(Te,{onClick:()=>M(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionUpload"),children:[s.jsx(za,{className:"w-4 h-4 mr-2"}),t("common.upload")]})]})]}),ve&&B&&ee&&s.jsxs("div",{className:"flex items-center gap-3 mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg",children:[s.jsx(Sn,{className:"w-5 h-5 text-amber-500 flex-shrink-0"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"text-sm text-amber-500 font-medium",children:t("fileManager.lowDiskSpaceWarning")}),s.jsx("p",{className:"text-xs text-amber-500/80",children:t("fileManager.lowDiskSpaceDetails",{free:hg(B.disk_free_bytes),total:hg(B.disk_total_bytes),threshold:ee.library_disk_warning_gb})})]})]}),B&&s.jsxs("div",{className:"flex flex-wrap items-center gap-3 sm:gap-6 mb-6 p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsx(uM,{className:"w-4 h-4 text-bambu-green"}),s.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.files"),":"]}),s.jsx("span",{className:"text-white font-medium",children:B.total_files})]}),s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsx(Il,{className:"w-4 h-4 text-blue-400"}),s.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.folders"),":"]}),s.jsx("span",{className:"text-white font-medium",children:B.total_folders})]}),s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsx(fM,{className:"w-4 h-4 text-amber-400"}),s.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.size"),":"]}),s.jsx("span",{className:"text-white font-medium",children:hg(B.total_size_bytes)})]}),s.jsxs("div",{className:"flex items-center gap-2 text-sm sm:ml-auto",children:[s.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.free"),":"]}),s.jsx("span",{className:`font-medium ${ve?"text-amber-500":"text-white"}`,children:hg(B.disk_free_bytes)})]})]}),s.jsxs("div",{className:"flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0",children:[s.jsx("div",{className:"lg:hidden",children:s.jsxs("select",{value:d??"",onChange:Re=>f(Re.target.value?parseInt(Re.target.value,10):null),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg px-3 py-2.5 text-white focus:outline-none focus:border-bambu-green",children:[s.jsxs("option",{value:"",children:["📁 ",t("fileManager.allFiles")]}),U&&(()=>{const Re=(ct,It=0)=>{const Ht=[];for(const Nn of ct)Ht.push({id:Nn.id,name:Nn.name,fileCount:Nn.file_count,depth:It}),Nn.children.length>0&&Ht.push(...Re(Nn.children,It+1));return Ht};return Re(U).map(ct=>s.jsxs("option",{value:ct.id,children:["│ ".repeat(ct.depth),"📂 ",ct.name," ",ct.fileCount>0?`(${ct.fileCount})`:""]},ct.id))})()]})}),s.jsxs("div",{ref:pe,className:"hidden lg:flex flex-shrink-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden flex-col relative",style:{width:`${K}px`},children:[s.jsx("div",{className:`absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group/resize flex items-center justify-center transition-colors ${re?"bg-bambu-green":"hover:bg-bambu-green/50"}`,onMouseDown:Re=>{Re.preventDefault(),xe(!0)},onDoubleClick:()=>{ie(256),localStorage.setItem("library-sidebar-width","256")},title:t("fileManager.dragToResizeTooltip"),children:s.jsxs("div",{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${re?"opacity-100":""}`,children:[s.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"}),s.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"}),s.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"})]})}),s.jsxs("div",{className:"p-3 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[s.jsx("h2",{className:"text-sm font-medium text-white",children:t("fileManager.folders")}),s.jsx("button",{onClick:()=>{const Re=!ae;$(Re),localStorage.setItem("library-wrap-folders",String(Re))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${ae?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:text-white hover:bg-bambu-dark"}`,title:t(ae?"fileManager.disableTextWrapping":"fileManager.enableTextWrapping"),children:t("fileManager.wrap")})]}),s.jsxs("div",{className:"flex-1 overflow-y-auto p-2",children:[s.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${d===null?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark text-white"}`,onClick:()=>f(null),children:[s.jsx(Bf,{className:"w-4 h-4"}),s.jsx("span",{className:"text-sm",children:t("fileManager.allFiles")})]}),U?.map(Re=>s.jsx(Vre,{folder:Re,selectedFolderId:d,onSelect:f,onDelete:ct=>E({type:"folder",id:ct}),onLink:k,onRename:ct=>z({type:"folder",id:ct.id,name:ct.name}),wrapNames:ae,hasPermission:r,t},Re.id))]})]}),s.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[we&&we.length>0&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3 mb-4 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-0 z-10 lg:static",children:[s.jsxs("div",{className:"relative w-full sm:w-auto sm:flex-1 sm:max-w-xs",children:[s.jsx(ya,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),s.jsx("input",{type:"text",placeholder:t("fileManager.searchFiles"),value:ue,onChange:Re=>Pe(Re.target.value),className:"w-full pl-9 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(dM,{className:"w-4 h-4 text-bambu-gray hidden sm:block"}),s.jsxs("select",{value:te,onChange:Re=>Ee(Re.target.value),className:"bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green",children:[s.jsx("option",{value:"all",children:t("fileManager.allTypes")}),J.map(Re=>s.jsx("option",{value:Re,children:Re.toUpperCase()},Re))]})]}),o&&s.jsxs("div",{className:"relative",children:[s.jsx("input",{type:"text",placeholder:t("fileManager.filterByUser",{defaultValue:"Filter by user"}),value:Oe,onChange:Re=>me(Re.target.value),list:"usernames-list",className:`w-32 sm:w-40 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green ${Oe?"pr-7":""}`,style:Oe?{WebkitAppearance:"none",MozAppearance:"textfield"}:void 0}),Oe&&s.jsx("button",{onClick:()=>me(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10",children:s.jsx(Lt,{className:"w-3 h-3"})}),s.jsx("datalist",{id:"usernames-list",children:O?.map(Re=>s.jsx("option",{value:Re.username},Re.id))})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("select",{value:Xe,onChange:Re=>{const ct=Re.target.value;G(ct),localStorage.setItem("library-sort-field",ct)},className:"bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green",children:[s.jsx("option",{value:"name",children:t("common.name")}),s.jsx("option",{value:"date",children:t("common.date")}),s.jsx("option",{value:"size",children:t("fileManager.size")}),s.jsx("option",{value:"type",children:t("common.type")}),s.jsx("option",{value:"prints",children:t("fileManager.prints")})]}),s.jsx("button",{onClick:()=>de(Re=>{const ct=Re==="asc"?"desc":"asc";return localStorage.setItem("library-sort-direction",ct),ct}),className:"p-1.5 rounded bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors",title:t(Y==="asc"?"fileManager.ascending":"fileManager.descending"),children:Y==="asc"?s.jsx(bce,{className:"w-4 h-4 text-white"}):s.jsx(uce,{className:"w-4 h-4 text-white"})})]}),(ue||te!=="all"||Oe)&&s.jsx("span",{className:"text-sm text-bambu-gray hidden sm:inline",children:t("fileManager.resultsCount",{showing:se.length,total:we.length})})]}),se.length>0&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4 p-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-[52px] z-10 lg:static",children:[p.length===se.length&&p.length>0?s.jsxs(Te,{variant:"secondary",size:"sm",onClick:Ke,children:[s.jsx(ll,{className:"w-4 h-4 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:t("fileManager.deselectAll")})]}):s.jsxs(Te,{variant:"secondary",size:"sm",onClick:ke,children:[s.jsx(ol,{className:"w-4 h-4 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:t("fileManager.selectAll")})]}),p.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-sm text-bambu-gray ml-2",children:t("fileManager.selected",{count:p.length})}),s.jsx("div",{className:"hidden sm:block flex-1"}),s.jsxs("div",{className:"w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0",children:[Ne.length===1&&s.jsxs(Te,{variant:"primary",size:"sm",onClick:()=>I(Ne[0]),disabled:!r("printers:control"),title:r("printers:control")?void 0:t("fileManager.noPermissionPrint"),children:[s.jsx(bo,{className:"w-4 h-4 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:t("common.print")})]}),Ne.length===1&&s.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>H(Ne[0]),disabled:!r("queue:create"),title:r("queue:create")?void 0:t("fileManager.noPermissionAddToQueue"),children:[s.jsx(nr,{className:"w-4 h-4 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:t("fileManager.schedulePrint")})]}),s.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>y(!0),disabled:!i("library:update_own","library:update_all"),title:i("library:update_own","library:update_all")?void 0:t("fileManager.noPermissionMoveFiles"),children:[s.jsx(Yde,{className:"w-4 h-4 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:t("common.move")})]}),s.jsxs(Te,{variant:"danger",size:"sm",onClick:()=>{p.length===1?E({type:"file",id:p[0]}):E({type:"bulk",id:0,count:p.length})},disabled:!i("library:delete_own","library:delete_all"),title:i("library:delete_own","library:delete_all")?void 0:t("fileManager.noPermissionDeleteFiles"),children:[s.jsx(on,{className:"w-4 h-4 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:t("common.delete")})]}),s.jsxs(Te,{variant:"secondary",size:"sm",onClick:Ke,children:[s.jsx(Lt,{className:"w-4 h-4 sm:mr-1"}),s.jsx("span",{className:"hidden sm:inline",children:t("common.clear")})]})]})]})]}),bt?s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsxs("div",{className:"flex flex-col items-center gap-3",children:[s.jsx(pt,{className:"w-8 h-8 animate-spin text-bambu-green"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:t("fileManager.loadingFiles")})]})}):we?.length===0?s.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center",children:[s.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:s.jsx(Bf,{className:"w-12 h-12 text-bambu-gray/50"})}),s.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:t(d!==null?"fileManager.folderIsEmpty":"fileManager.noFilesYet")}),s.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:t(d!==null?"fileManager.folderEmptyDescription":"fileManager.noFilesDescription")}),s.jsxs(Te,{onClick:()=>M(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionUpload"),children:[s.jsx(fr,{className:"w-4 h-4 mr-2"}),t("fileManager.uploadFiles")]})]}):se.length===0?s.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center",children:[s.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:s.jsx(ya,{className:"w-12 h-12 text-bambu-gray/50"})}),s.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:t("fileManager.noMatchingFiles")}),s.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:t("fileManager.noMatchingFilesDescription")}),s.jsx(Te,{variant:"secondary",onClick:()=>{Pe(""),Ee("all")},children:t("fileManager.clearFilters")})]}):X==="grid"?s.jsx("div",{className:"flex-1 lg:overflow-y-auto",children:s.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4",children:se.map(Re=>s.jsx(uXe,{file:Re,isSelected:p.includes(Re.id),isMobile:q,t,onSelect:nt,onDelete:ct=>E({type:"file",id:ct}),onDownload:le,onAddToQueue:ct=>{const It=we?.find(Ht=>Ht.id===ct);It&&H(It)},onPrint:A,onRename:ct=>z({type:"file",id:ct.id,name:ct.filename}),onGenerateThumbnail:ct=>Me.mutate(ct.id),thumbnailVersion:W[Re.id],hasPermission:r,canModify:a,authEnabled:o},Re.id))})}):s.jsx("div",{className:"flex-1 lg:overflow-y-auto",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden",children:[s.jsxs("div",{className:`hidden sm:grid ${o?"grid-cols-[auto_1fr_120px_100px_100px_100px_80px]":"grid-cols-[auto_1fr_100px_100px_100px_80px]"} gap-4 px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary text-xs text-bambu-gray font-medium`,children:[s.jsx("div",{className:"w-6"}),s.jsx("div",{children:t("common.name")}),o&&s.jsx("div",{children:t("fileManager.uploadedBy",{defaultValue:"Uploaded By"})}),s.jsx("div",{children:t("common.type")}),s.jsx("div",{children:t("fileManager.size")}),s.jsx("div",{children:t("fileManager.prints")}),s.jsx("div",{})]}),se.map(Re=>s.jsxs("div",{className:`grid ${o?"grid-cols-[auto_1fr_120px_100px_100px_100px_80px]":"grid-cols-[auto_1fr_100px_100px_100px_80px]"} gap-4 px-4 py-3 items-center border-b border-bambu-dark-tertiary last:border-b-0 cursor-pointer hover:bg-bambu-dark/50 transition-colors ${p.includes(Re.id)?"bg-bambu-green/10":""}`,onClick:()=>nt(Re.id),children:[s.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${p.includes(Re.id)?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:p.includes(Re.id)&&s.jsx("div",{className:"w-2 h-2 bg-white rounded-sm"})}),s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[s.jsxs("div",{className:"relative group/thumb",children:[s.jsx("div",{className:"w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden",children:Re.thumbnail_path?s.jsx("img",{src:`${ce.getLibraryFileThumbnailUrl(Re.id)}${W[Re.id]?`?v=${W[Re.id]}`:""}`,alt:"",className:"w-full h-full object-cover"}):s.jsx("div",{className:"w-full h-full flex items-center justify-center",children:s.jsx(Bf,{className:"w-5 h-5 text-bambu-gray/50"})})}),Re.thumbnail_path&&s.jsx("div",{className:"absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block",children:s.jsx("div",{className:"w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden",children:s.jsx("img",{src:`${ce.getLibraryFileThumbnailUrl(Re.id)}${W[Re.id]?`?v=${W[Re.id]}`:""}`,alt:Re.filename,className:"w-full h-full object-contain"})})})]}),s.jsx("div",{className:"min-w-0",children:s.jsx("div",{className:"text-sm text-white truncate",children:Re.print_name||Re.filename})})]}),o&&s.jsx("div",{className:"text-sm text-bambu-gray flex items-center gap-1",children:Re.created_by_username?s.jsxs(s.Fragment,{children:[s.jsx(Fu,{className:"w-3 h-3"}),s.jsx("span",{className:"truncate",children:Re.created_by_username})]}):"-"}),s.jsx("div",{children:s.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded font-medium ${Re.file_type==="3mf"?"bg-bambu-green/20 text-bambu-green":Re.file_type==="gcode"?"bg-blue-500/20 text-blue-400":Re.file_type==="stl"?"bg-purple-500/20 text-purple-400":"bg-bambu-gray/20 text-bambu-gray"}`,children:Re.file_type.toUpperCase()})}),s.jsx("div",{className:"text-sm text-bambu-gray",children:hg(Re.file_size)}),s.jsx("div",{className:"text-sm text-bambu-gray",children:Re.print_count>0?`${Re.print_count}x`:"-"}),s.jsxs("div",{className:"flex items-center gap-1",onClick:ct=>ct.stopPropagation(),children:[hR(Re.filename)&&s.jsxs(s.Fragment,{children:[s.jsx("button",{onClick:()=>r("printers:control")&&A(Re),className:`p-1.5 rounded transition-colors ${r("printers:control")?"hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("printers:control")?t("common.print"):t("fileManager.noPermissionPrint"),disabled:!r("printers:control"),children:s.jsx(Pr,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>{r("queue:create")&&H(Re)},className:`p-1.5 rounded transition-colors ${r("queue:create")?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("queue:create")?t("fileManager.schedulePrint"):t("fileManager.noPermissionAddToQueue"),disabled:!r("queue:create"),children:s.jsx(nr,{className:"w-4 h-4"})})]}),s.jsx("button",{onClick:()=>r("library:read")&&le(Re.id),className:`p-1.5 rounded transition-colors ${r("library:read")?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("library:read")?t("common.download"):t("fileManager.noPermissionDownload"),disabled:!r("library:read"),children:s.jsx(wi,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>a("library","update",Re.created_by_id)&&z({type:"file",id:Re.id,name:Re.filename}),className:`p-1.5 rounded transition-colors ${a("library","update",Re.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:a("library","update",Re.created_by_id)?t("common.rename"):t("fileManager.noPermissionRenameFile"),disabled:!a("library","update",Re.created_by_id),children:s.jsx(Zi,{className:"w-4 h-4"})}),Re.file_type==="stl"&&s.jsx("button",{onClick:()=>a("library","update",Re.created_by_id)&&Me.mutate(Re.id),className:`p-1.5 rounded transition-colors ${a("library","update",Re.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green":"text-bambu-gray/50 cursor-not-allowed"}`,title:a("library","update",Re.created_by_id)?t("fileManager.generateThumbnail"):t("fileManager.noPermissionGenerateThumbnail"),disabled:Me.isPending||!a("library","update",Re.created_by_id),children:s.jsx(Lu,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>a("library","delete",Re.created_by_id)&&E({type:"file",id:Re.id}),className:`p-1.5 rounded transition-colors ${a("library","delete",Re.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-red-400":"text-bambu-gray/50 cursor-not-allowed"}`,title:a("library","delete",Re.created_by_id)?t("common.delete"):t("fileManager.noPermissionDeleteFile"),disabled:!a("library","delete",Re.created_by_id),children:s.jsx(on,{className:"w-4 h-4"})})]})]},Re.id))]})})]})]}),x&&s.jsx(aXe,{parentId:d,onClose:()=>b(!1),onSave:Re=>_e.mutate(Re),isLoading:_e.isPending,t}),v&&U&&s.jsx(oXe,{folders:U,selectedFiles:p,currentFolderId:d,onClose:()=>y(!1),onMove:Re=>rt.mutate({fileIds:p,folderId:Re}),isLoading:rt.isPending,t}),S&&s.jsx(cXe,{folderId:d,onClose:()=>M(!1),onUploadComplete:Be,t}),T&&s.jsx(lXe,{folder:T,onClose:()=>k(null),onLink:Re=>Ie.mutate({id:T.id,data:Re}),isLoading:Ie.isPending,t}),C&&s.jsx(Jn,{title:C.type==="folder"?t("fileManager.deleteFolder"):C.type==="bulk"?t("fileManager.deleteFilesCount",{count:C.count}):t("fileManager.deleteFile"),message:C.type==="folder"?t("fileManager.deleteFolderConfirm"):C.type==="bulk"?t("fileManager.deleteFilesConfirm",{count:C.count}):t("fileManager.deleteFileConfirm"),confirmText:t("common.delete"),variant:"danger",isLoading:it,loadingText:t("fileManager.deleting"),onConfirm:$e,onCancel:()=>E(null)}),D&&s.jsx(ju,{mode:"reprint",libraryFileId:D.id,archiveName:D.print_name||D.filename,onClose:()=>A(null),onSuccess:()=>{A(null),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["archives"]})}}),j&&s.jsx(ju,{mode:"reprint",libraryFileId:j.id,archiveName:j.print_name||j.filename,onClose:()=>I(null),onSuccess:()=>{I(null),m([]),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["archives"]})}}),F&&s.jsx(ju,{mode:"add-to-queue",libraryFileId:F.id,archiveName:F.print_name||F.filename,onClose:()=>H(null),onSuccess:()=>{H(null),m([]),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["queue"]}),e.invalidateQueries({queryKey:["archives"]})}}),R&&s.jsx(sXe,{type:R.type,currentName:R.name,onClose:()=>z(null),onSave:Re=>{R.type==="file"?be.mutate({id:R.id,filename:Re}):Ae.mutate({id:R.id,name:Re})},isLoading:be.isPending||Ae.isPending,t})]})}const KP=5,hXe=2e3,fXe=3e4,mXe=5e3;function pXe(){const{t}=On(),{printerId:e}=iM(),n=parseInt(e||"0",10),[r,i]=_.useState("stream"),[a,o]=_.useState(!1),[l,c]=_.useState(!0),[u,d]=_.useState(Date.now()),[f,p]=_.useState(!1),[m,x]=_.useState(!1),[b,v]=_.useState(0),[y,S]=_.useState(!1),[M,T]=_.useState(0),[k,C]=_.useState(1),[E,D]=_.useState({x:0,y:0}),[A,j]=_.useState(!1),[I,F]=_.useState({x:0,y:0}),[H,R]=_.useState(null),[z,W]=_.useState(null),V=_.useRef(null),X=_.useRef(null),Q=_.useRef(null),ae=_.useRef(null),$=_.useRef(null),{data:K}=ot({queryKey:["printer",n],queryFn:()=>ce.getPrinter(n),enabled:n>0});_.useEffect(()=>(K&&(document.title=`${K.name} - Camera`),()=>{document.title="Bambuddy"}),[K]);const ie=_.useRef(!1);_.useEffect(()=>{const se=`/api/v1/printers/${n}/camera/stop`;ie.current=!1;const ve=()=>{n>0&&!ie.current&&(ie.current=!0,navigator.sendBeacon(se))},_e=()=>{ve()};window.addEventListener("beforeunload",_e);const ne=V.current;return()=>{window.removeEventListener("beforeunload",_e),ne&&(ne.src=""),ve()}},[n]),_.useEffect(()=>{if(l&&!f){const ve=setTimeout(()=>{c(!1)},r==="stream"?3e3:2e4);return()=>clearTimeout(ve)}},[r,l,u,f]),_.useEffect(()=>{const se=()=>{const ve=!!document.fullscreenElement;x(ve),C(1),D({x:0,y:0}),r==="stream"&&!f&&(V.current&&(V.current.src=""),setTimeout(()=>{c(!0),d(Date.now())},200))};return document.addEventListener("fullscreenchange",se),()=>document.removeEventListener("fullscreenchange",se)},[r,f]),_.useEffect(()=>{let se;const ve=()=>{clearTimeout(se),se=setTimeout(()=>{localStorage.setItem("cameraWindowState",JSON.stringify({width:window.outerWidth,height:window.outerHeight,left:window.screenX,top:window.screenY}))},500)};return window.addEventListener("resize",ve),()=>{clearTimeout(se),window.removeEventListener("resize",ve)}},[]),_.useEffect(()=>()=>{Q.current&&clearTimeout(Q.current),ae.current&&clearInterval(ae.current),$.current&&clearInterval($.current)},[]);const re=_.useCallback(()=>{if(b>=KP){S(!1),o(!0);return}const se=Math.min(hXe*Math.pow(2,b),fXe);S(!0),T(Math.ceil(se/1e3)),ae.current=setInterval(()=>{T(ve=>ve<=1?(ae.current&&clearInterval(ae.current),0):ve-1)},1e3),Q.current=setTimeout(()=>{v(ve=>ve+1),S(!1),c(!0),o(!1),V.current&&(V.current.src=""),d(Date.now())},se)},[b]);_.useEffect(()=>{if(r!=="stream"||l||y||f){$.current&&(clearInterval($.current),$.current=null);return}return $.current=setInterval(async()=>{try{const se=await ce.getCameraStatus(n);(se.stalled||!se.active&&!a)&&(console.log(`Stream issue detected: stalled=${se.stalled}, active=${se.active}, reconnecting...`),$.current&&(clearInterval($.current),$.current=null),c(!1),re())}catch{}},mXe),()=>{$.current&&(clearInterval($.current),$.current=null)}},[r,l,a,y,f,n,re]);const xe=()=>{c(!1),r==="stream"&&b{if(c(!1),o(!1),v(0),S(!1),Q.current&&clearTimeout(Q.current),ae.current&&clearInterval(ae.current),V.current&&!localStorage.getItem("cameraWindowState")){const se=V.current,ve=se.naturalWidth,_e=se.naturalHeight;if(ve>0&&_e>0){const He=window.outerWidth-window.innerWidth,rt=window.outerHeight-window.innerHeight,Ie=ve+16+He,be=_e+45+16+rt;try{window.resizeTo(Ie,be)}catch{}}}},ue=()=>{n>0&&fetch(`/api/v1/printers/${n}/camera/stop`).catch(()=>{})},Pe=se=>{r===se||f||(p(!0),c(!0),o(!1),v(0),S(!1),C(1),D({x:0,y:0}),Q.current&&clearTimeout(Q.current),ae.current&&clearInterval(ae.current),V.current&&(V.current.src=""),r==="stream"&&ue(),setTimeout(()=>{i(se),d(Date.now()),p(!1)},100))},te=()=>{f||(p(!0),c(!0),o(!1),v(0),S(!1),Q.current&&clearTimeout(Q.current),ae.current&&clearInterval(ae.current),V.current&&(V.current.src=""),r==="stream"&&ue(),setTimeout(()=>{d(Date.now()),p(!1)},100))},Ee=()=>{X.current&&(document.fullscreenElement?document.exitFullscreen():X.current.requestFullscreen())},Oe=()=>{C(se=>Math.min(se+.5,4))},me=()=>{C(se=>{const ve=Math.max(se-.5,1);return ve===1&&D({x:0,y:0}),ve})},Xe=se=>{se.preventDefault(),se.deltaY<0?Oe():me()},G=se=>{k>1&&(se.preventDefault(),j(!0),F({x:se.clientX-E.x,y:se.clientY-E.y}))},Y=_.useCallback(()=>{if(!X.current)return{x:300,y:200};const se=X.current.getBoundingClientRect(),ve=se.width*(k-1)/2,_e=se.height*(k-1)/2;return{x:Math.max(50,ve),y:Math.max(50,_e)}},[k]),de=se=>{if(A&&k>1){const ve=se.clientX-I.x,_e=se.clientY-I.y,ne=Y();D({x:Math.max(-ne.x,Math.min(ne.x,ve)),y:Math.max(-ne.y,Math.min(ne.y,_e))})}},q=()=>{j(!1)},ee=se=>{if(se.length<2)return 0;const ve=se[0].clientX-se[1].clientX,_e=se[0].clientY-se[1].clientY;return Math.sqrt(ve*ve+_e*_e)},U=se=>se.length<2?{x:se[0].clientX,y:se[0].clientY}:{x:(se[0].clientX+se[1].clientX)/2,y:(se[0].clientY+se[1].clientY)/2},fe=se=>{se.touches.length===2?(se.preventDefault(),R(ee(se.touches)),W(U(se.touches))):se.touches.length===1&&k>1&&(se.preventDefault(),j(!0),F({x:se.touches[0].clientX-E.x,y:se.touches[0].clientY-E.y}))},we=se=>{if(se.touches.length===2&&H!==null){se.preventDefault();const ve=ee(se.touches),_e=ve/H;C(Fe=>{const He=Math.max(1,Math.min(4,Fe*_e));return He===1&&D({x:0,y:0}),He}),R(ve);const ne=U(se.touches);if(z){const Fe=Y();D(He=>({x:Math.max(-Fe.x,Math.min(Fe.x,He.x+(ne.x-z.x))),y:Math.max(-Fe.y,Math.min(Fe.y,He.y+(ne.y-z.y)))}))}W(ne)}else if(se.touches.length===1&&A&&k>1){se.preventDefault();const ve=se.touches[0].clientX-I.x,_e=se.touches[0].clientY-I.y,ne=Y();D({x:Math.max(-ne.x,Math.min(ne.x,ve)),y:Math.max(-ne.y,Math.min(ne.y,_e))})}},ge=se=>{se.touches.length<2&&(R(null),W(null)),se.touches.length===0&&j(!1)},B=()=>{C(1),D({x:0,y:0})},O=f?"":r==="stream"?`/api/v1/printers/${n}/camera/stream?fps=15&t=${u}`:`/api/v1/printers/${n}/camera/snapshot?t=${u}`,J=l||f||y;return n?s.jsxs("div",{ref:X,className:"min-h-screen bg-black flex flex-col",children:[s.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary",children:[s.jsxs("h1",{className:"text-sm font-medium text-white flex items-center gap-2",children:[s.jsx(Ug,{className:"w-4 h-4"}),K?.name||`Printer ${n}`]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"flex bg-bambu-dark rounded p-0.5",children:[s.jsx("button",{onClick:()=>Pe("stream"),disabled:J,className:`px-3 py-1 text-xs rounded transition-colors ${r==="stream"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white disabled:opacity-50"}`,children:t("camera.live")}),s.jsx("button",{onClick:()=>Pe("snapshot"),disabled:J,className:`px-3 py-1 text-xs rounded transition-colors ${r==="snapshot"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white disabled:opacity-50"}`,children:t("camera.snapshot")})]}),s.jsx("button",{onClick:te,disabled:J,className:"p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50",title:t(r==="stream"?"camera.restartStream":"camera.refreshSnapshot"),children:s.jsx(Rr,{className:`w-4 h-4 text-bambu-gray ${J?"animate-spin":""}`})}),s.jsx("button",{onClick:Ee,className:"p-1.5 hover:bg-bambu-dark-tertiary rounded",title:t(m?"camera.exitFullscreen":"camera.fullscreen"),children:m?s.jsx(kW,{className:"w-4 h-4 text-bambu-gray"}):s.jsx(Ide,{className:"w-4 h-4 text-bambu-gray"})})]})]}),s.jsx("div",{className:"flex-1 flex items-center justify-center p-2 overflow-hidden",onWheel:Xe,onMouseMove:de,onMouseUp:q,onMouseLeave:q,onTouchStart:fe,onTouchMove:we,onTouchEnd:ge,style:{touchAction:"none"},children:s.jsxs("div",{className:"relative w-full h-full flex items-center justify-center",children:[(l||f)&&!y&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 z-10",children:s.jsxs("div",{className:"text-center",children:[s.jsx(Rr,{className:"w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:t(r==="stream"?"camera.connectingToCamera":"camera.capturingSnapshot")})]})}),y&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/80 z-10",children:s.jsxs("div",{className:"text-center p-4",children:[s.jsx(sm,{className:"w-10 h-10 text-orange-400 mx-auto mb-3"}),s.jsx("p",{className:"text-white mb-2",children:t("camera.connectionLost")}),s.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:t("camera.reconnecting",{countdown:M,attempt:b+1,max:KP})}),s.jsx("button",{onClick:te,className:"px-4 py-2 bg-bambu-green text-white text-sm rounded hover:bg-bambu-green/80 transition-colors",children:t("camera.reconnectNow")})]})}),a&&!y&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black z-10",children:s.jsxs("div",{className:"text-center p-4",children:[s.jsx(Sn,{className:"w-12 h-12 text-orange-400 mx-auto mb-3"}),s.jsx("p",{className:"text-white mb-2",children:t("camera.cameraUnavailable")}),s.jsx("p",{className:"text-xs text-bambu-gray mb-4 max-w-md",children:t("camera.cameraUnavailableDesc")}),s.jsx("button",{onClick:te,className:"px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors",children:t("camera.retry")})]})}),s.jsx("img",{ref:V,src:O,alt:t("camera.cameraStream"),className:"max-w-full max-h-full object-contain select-none",style:{transform:`scale(${k}) translate(${E.x/k}px, ${E.y/k}px)`,cursor:k>1?A?"grabbing":"grab":"default"},onError:O?xe:void 0,onLoad:O?pe:void 0,onMouseDown:G,draggable:!1},u),s.jsxs("div",{className:"absolute bottom-4 left-4 flex items-center gap-1.5 bg-black/60 rounded-lg px-2 py-1.5",children:[s.jsx("button",{onClick:me,disabled:k<=1,className:"p-1.5 hover:bg-white/10 rounded disabled:opacity-30",title:t("camera.zoomOut"),children:s.jsx(FR,{className:"w-4 h-4 text-white"})}),s.jsxs("button",{onClick:B,className:"px-2 py-1 text-sm text-white hover:bg-white/10 rounded min-w-[48px]",title:t("camera.resetZoom"),children:[Math.round(k*100),"%"]}),s.jsx("button",{onClick:Oe,disabled:k>=4,className:"p-1.5 hover:bg-white/10 rounded disabled:opacity-30",title:t("camera.zoomIn"),children:s.jsx(LR,{className:"w-4 h-4 text-white"})})]})]})})]}):s.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:s.jsx("p",{className:"text-white",children:t("camera.invalidPrinterId")})})}function gXe(t){const e=t.get("show")?.split(",")||["progress","layers","eta","filename","status"],n=parseInt(t.get("fps")||"15",10),r=Math.min(Math.max(isNaN(n)?15:n,1),30),i=t.get("camera"),a=i!=="false"&&i!=="0";return{size:t.get("size")||"medium",fps:r,showCamera:a,showProgress:e.includes("progress"),showLayers:e.includes("layers"),showEta:e.includes("eta"),showFilename:e.includes("filename"),showStatus:e.includes("status"),showPrinter:e.includes("printer")}}function xXe(t){const e=Math.floor(t/3600),n=Math.floor(t%3600/60);return e>0?`${e}h ${n}m`:`${n}m`}function bXe(t,e){const n=new Date,r=new Date(n.getTime()+t*60*1e3),i=new Date;i.setHours(0,0,0,0);const a=new Date(r);a.setHours(0,0,0,0);const o=r.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return a.getTime()===i.getTime()?o:a.getTime()===i.getTime()+864e5?`${e("streamOverlay.tomorrow")} ${o}`:r.toLocaleDateString([],{weekday:"short"})+" "+o}function yXe(t,e){if(t.stg_cur_name)return t.stg_cur_name;switch(t.state){case"RUNNING":return e("streamOverlay.status.printing");case"PAUSE":return e("streamOverlay.status.paused");case"FINISH":return e("streamOverlay.status.finished");case"FAILED":return e("streamOverlay.status.failed");case"IDLE":return e("streamOverlay.status.idle");default:return t.state||e("streamOverlay.status.unknown")}}function vXe(t){switch(t){case"small":return{container:"p-3",text:"text-sm",textLarge:"text-lg",progressHeight:"h-2",icon:"w-3 h-3",gap:"gap-2",logoHeight:"h-12"};case"large":return{container:"p-6",text:"text-xl",textLarge:"text-3xl",progressHeight:"h-4",icon:"w-6 h-6",gap:"gap-4",logoHeight:"h-24"};case"medium":default:return{container:"p-4",text:"text-base",textLarge:"text-xl",progressHeight:"h-3",icon:"w-4 h-4",gap:"gap-3",logoHeight:"h-16"}}}function wXe(){const{printerId:t}=iM(),[e]=wR(),{t:n}=On(),r=ln(),i=parseInt(t||"0",10),[a,o]=_.useState(Date.now()),l=_.useMemo(()=>gXe(e),[e]),c=vXe(l.size),{data:u}=ot({queryKey:["printer",i],queryFn:()=>ce.getPrinter(i),enabled:i>0}),{data:d}=ot({queryKey:["printerStatus",i],queryFn:()=>ce.getPrinterStatus(i),enabled:i>0,refetchInterval:2e3});_.useEffect(()=>{if(!i)return;const v=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/v1/ws`,y=new WebSocket(v);return y.onmessage=S=>{try{const M=JSON.parse(S.data);M.type==="printer_status"&&M.printer_id===i&&r.setQueryData(["printerStatus",i],M.status)}catch{}},y.onerror=()=>{},()=>{y.close()}},[i,r]),_.useEffect(()=>(document.title=u?`${u.name} - ${n("streamOverlay.title")}`:n("streamOverlay.title"),()=>{document.title="Bambuddy"}),[u,n]);const f=()=>{setTimeout(()=>{o(Date.now())},3e3)};if(!i)return s.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:s.jsx("p",{className:"text-white",children:n("streamOverlay.invalidPrinterId")})});if(!d)return s.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:s.jsx("p",{className:"text-gray-400",children:n("common.loading")})});const p=d.state==="RUNNING"||d.state==="PAUSE",m=d.progress||0,x=`/api/v1/printers/${i}/camera/stream?fps=${l.fps}&t=${a}`;return s.jsxs("div",{className:"min-h-screen bg-black relative overflow-hidden",children:[l.showCamera&&s.jsx("img",{src:x,alt:n("streamOverlay.cameraStream"),className:"absolute inset-0 w-full h-full object-contain",onError:f},a),s.jsx("a",{href:"https://github.com/maziggy/bambuddy",target:"_blank",rel:"noopener noreferrer",className:"absolute top-4 right-4 z-10",children:s.jsx("img",{src:"/img/bambuddy_logo_dark_transparent.png",alt:"Bambuddy",className:`${c.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})}),s.jsx("div",{className:"absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/60 to-transparent",children:s.jsxs("div",{className:`${c.container}`,children:[l.showPrinter&&u&&s.jsxs("div",{className:`flex items-center ${c.gap} mb-2`,children:[s.jsx(Pr,{className:`${c.icon} text-white/70`}),s.jsx("span",{className:`${c.text} text-white font-medium`,children:u.name})]}),l.showFilename&&d.current_print&&s.jsx("div",{className:`${c.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:d.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,"")}),l.showStatus&&s.jsx("div",{className:`${c.text} text-white/70 mb-2`,children:yXe(d,n)}),l.showProgress&&p&&s.jsxs("div",{className:"mb-3",children:[s.jsxs("div",{className:`flex items-center justify-between mb-1 ${c.text}`,children:[s.jsx("span",{className:"text-white/70",children:n("streamOverlay.progress")}),s.jsxs("span",{className:"text-white font-bold",children:[Math.round(m),"%"]})]}),s.jsx("div",{className:`w-full bg-white/20 rounded-full ${c.progressHeight}`,children:s.jsx("div",{className:`bg-bambu-green ${c.progressHeight} rounded-full transition-all duration-500`,style:{width:`${m}%`}})})]}),p&&(l.showLayers||l.showEta)&&s.jsxs("div",{className:`flex items-center ${c.gap} flex-wrap`,children:[l.showLayers&&d.layer_num!=null&&d.total_layers!=null&&d.total_layers>0&&s.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[s.jsx(sl,{className:c.icon}),s.jsxs("span",{className:c.text,children:[s.jsx("span",{className:"text-white",children:d.layer_num}),s.jsx("span",{className:"mx-1",children:"/"}),s.jsx("span",{children:d.total_layers})]})]}),l.showEta&&d.remaining_time!=null&&d.remaining_time>0&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[s.jsx(bu,{className:c.icon}),s.jsx("span",{className:`${c.text} text-white`,children:xXe(d.remaining_time*60)})]}),s.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[s.jsx(nr,{className:c.icon}),s.jsxs("span",{className:`${c.text} text-white`,children:[n("streamOverlay.eta")," ",bXe(d.remaining_time,n)]})]})]})]}),!p&&s.jsx("div",{className:`${c.text} text-white/70 py-2`,children:d.connected?n("streamOverlay.printerIdle"):n("streamOverlay.printerOffline")})]})})]})}function _Xe(){const{t}=On(),{id:e}=iM(),{mode:n}=Lh(),{data:r,isLoading:i,error:a}=ot({queryKey:["external-link",e],queryFn:()=>ce.getExternalLink(Number(e)),enabled:!!e});return i?s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):a||!r?s.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 text-bambu-gray",children:[s.jsx(Sn,{className:"w-12 h-12"}),s.jsx("p",{children:t("common.linkNotFound")})]}):s.jsx("iframe",{src:r.url,className:"h-full w-full border-0",style:{colorScheme:n},title:r.name,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox"})}const wq=["DEBUG","INFO","WARNING","ERROR"],XP={DEBUG:"text-gray-400",INFO:"text-blue-400",WARNING:"text-yellow-400",ERROR:"text-red-400"},SXe={DEBUG:sM,INFO:Zo,WARNING:Sn,ERROR:$i};function NXe(){const t=ln(),[e,n]=_.useState(!0),[r,i]=_.useState(new Set),[a,o]=_.useState(""),[l,c]=_.useState("ALL"),[u,d]=_.useState(!1),[f,p]=_.useState(!1),m=_.useRef(null),{data:x,isLoading:b,refetch:v}=ot({queryKey:["application-logs",l,a],queryFn:()=>Ng.getLogs({limit:200,level:l==="ALL"?void 0:l,search:a||void 0}),refetchInterval:f?2e3:!1,enabled:u});_.useEffect(()=>{u||p(!1)},[u]);const y=gt({mutationFn:()=>Ng.clearLogs(),onSuccess:()=>{t.invalidateQueries({queryKey:["application-logs"]})}});_.useEffect(()=>{e&&m.current&&x?.entries&&(m.current.scrollTop=m.current.scrollHeight)},[x?.entries,e]);const S=E=>{i(D=>{const A=new Set(D);return A.has(E)?A.delete(E):A.add(E),A})},M=E=>{const D=E.split(" ");return D.length>=2?D[1]:E},T=_.useMemo(()=>x?.entries??[],[x?.entries]),k=_.useMemo(()=>[...T].reverse(),[T]),C=({level:E})=>{const D=SXe[E]||Zo;return s.jsx(D,{className:`w-3.5 h-3.5 ${XP[E]||"text-gray-400"}`})};return s.jsxs("div",{className:"bg-bambu-dark rounded-lg overflow-hidden",children:[s.jsxs("button",{onClick:()=>d(!u),className:"w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/50 transition-colors",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:`p-2 rounded-lg ${f?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:s.jsx(sM,{className:"w-5 h-5"})}),s.jsxs("div",{className:"text-left",children:[s.jsx("p",{className:"font-medium text-white",children:"Application Logs"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:f?`Live streaming - ${x?.filtered_count??0} entries`:"View and filter application logs"})]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[f&&s.jsxs("span",{className:"flex items-center gap-1.5 px-2 py-1 bg-bambu-green/20 rounded text-bambu-green text-xs",children:[s.jsx("span",{className:"w-1.5 h-1.5 bg-bambu-green rounded-full animate-pulse"}),"Live"]}),u?s.jsx(yh,{className:"w-5 h-5 text-bambu-gray"}):s.jsx(Kr,{className:"w-5 h-5 text-bambu-gray"})]})]}),u&&s.jsxs("div",{className:"border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[f?s.jsxs("button",{onClick:E=>{E.stopPropagation(),p(!1)},className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-red-500/20 text-red-400 hover:bg-red-500/30 rounded transition-colors",children:[s.jsx(ll,{className:"w-4 h-4"}),"Stop"]}):s.jsxs("button",{onClick:E=>{E.stopPropagation(),p(!0),v()},className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 rounded transition-colors",children:[s.jsx(bo,{className:"w-4 h-4"}),"Start"]}),s.jsxs("button",{onClick:()=>y.mutate(),disabled:y.isPending||T.length===0,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50",children:[s.jsx(on,{className:"w-4 h-4"}),"Clear"]}),s.jsx("button",{onClick:()=>v(),disabled:b,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50",children:s.jsx(Rr,{className:`w-4 h-4 ${b?"animate-spin":""}`})}),s.jsx("div",{className:"flex-1"}),s.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:e,onChange:E=>n(E.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark-tertiary"}),"Auto-scroll"]}),s.jsxs("span",{className:"text-sm text-bambu-gray",children:[x?.filtered_count??0,"/",x?.total_in_file??0]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1",children:[s.jsx(ya,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),s.jsx("input",{type:"text",placeholder:"Search message or logger name...",value:a,onChange:E=>o(E.target.value),className:"w-full pl-8 pr-8 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),a&&s.jsx("button",{onClick:()=>o(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:s.jsx(Lt,{className:"w-4 h-4"})})]}),s.jsxs("div",{className:"flex items-center gap-1 bg-bambu-dark-secondary rounded border border-bambu-dark-tertiary",children:[s.jsx("button",{onClick:()=>c("ALL"),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${l==="ALL"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white"}`,children:"All"}),wq.map((E,D)=>s.jsx("button",{onClick:()=>c(E),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${D===wq.length-1?"rounded-r":""} ${l===E?`${XP[E]} bg-bambu-dark-tertiary`:"text-bambu-gray hover:text-white"}`,children:E},E))]})]})]}),s.jsx("div",{ref:m,className:"overflow-auto font-mono text-xs bg-black min-h-[300px] max-h-[500px]",children:T.length===0?s.jsxs("div",{className:"flex flex-col items-center justify-center h-[300px] text-bambu-gray",children:[s.jsx("p",{className:"mb-2",children:"No log entries found"}),s.jsx("p",{className:"text-sm",children:"Log file may be empty or cleared"})]}):s.jsx("div",{className:"divide-y divide-bambu-dark-tertiary/30",children:k.map((E,D)=>{const A=r.has(D),j=E.message.includes(` `);return s.jsx("div",{className:`p-2 cursor-pointer hover:bg-bambu-dark-secondary/50 transition-colors ${A?"bg-bambu-dark-secondary/30":""}`,onClick:()=>j&&S(D),children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("span",{className:"text-bambu-gray/70 shrink-0 w-20",children:M(E.timestamp)}),s.jsx("span",{className:"shrink-0",children:s.jsx(C,{level:E.level})}),s.jsxs("span",{className:"text-purple-400/80 shrink-0 max-w-[200px] truncate",title:E.logger_name,children:["[",E.logger_name,"]"]}),s.jsx("span",{className:`flex-1 ${XP[E.level]||"text-white/80"} ${!A&&j?"truncate":""}`,children:A?s.jsx("pre",{className:"whitespace-pre-wrap break-all",children:E.message}):E.message.split(` `)[0]}),j&&s.jsx("span",{className:"text-bambu-gray/50 shrink-0",children:A?s.jsx(yh,{className:"w-3.5 h-3.5"}):s.jsx(Kr,{className:"w-3.5 h-3.5"})})]})},D)})})}),s.jsx("div",{className:"flex items-center justify-between p-3 border-t border-bambu-dark-tertiary text-sm text-bambu-gray",children:f?s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"w-2 h-2 bg-green-500 rounded-full animate-pulse"}),"Auto-refreshing every 2 seconds"]}):s.jsx("span",{children:"Click Start to enable live log streaming"})})]})]})}function MXe(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:`${(t/(1024*1024*1024)).toFixed(2)} GB`}function gi({icon:t,label:e,value:n,subValue:r,color:i="text-bambu-green"}){return s.jsxs("div",{className:"flex items-start gap-3 p-4 bg-bambu-dark rounded-lg",children:[s.jsx("div",{className:`p-2 rounded-lg bg-bambu-dark-tertiary ${i}`,children:s.jsx(t,{className:"w-5 h-5"})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:e}),s.jsx("p",{className:"text-lg font-semibold text-white truncate",children:n}),r&&s.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:r})]})]})}function _q({percent:t,color:e="bg-bambu-green"}){return s.jsx("div",{className:"w-full h-2 bg-bambu-dark rounded-full overflow-hidden",children:s.jsx("div",{className:`h-full ${e} transition-all duration-300`,style:{width:`${Math.min(100,t)}%`}})})}function Ud({title:t,icon:e,children:n}){return s.jsxs(Nt,{className:"p-6",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[s.jsx(e,{className:"w-5 h-5 text-bambu-green"}),s.jsx("h2",{className:"text-lg font-semibold text-white",children:t})]}),n]})}function kXe(){const{t}=On(),e=ln(),[n,r]=_.useState(null),[i,a]=_.useState(!1),[o,l]=_.useState(!1),{data:c,isLoading:u,refetch:d,isFetching:f}=ot({queryKey:["systemInfo"],queryFn:ce.getSystemInfo,refetchInterval:3e4}),{data:p}=ot({queryKey:["debugLogging"],queryFn:Ng.getDebugLoggingState,staleTime:10*1e3,refetchInterval:10*1e3}),{data:m}=ot({queryKey:["settings"],queryFn:ce.getSettings}),{data:x}=ot({queryKey:["library-stats"],queryFn:ce.getLibraryStats}),b=m?.time_format||"system",v=async()=>{l(!0);try{const T=await Ng.setDebugLogging(!p?.enabled);e.setQueryData(["debugLogging"],T)}catch(T){console.error("Failed to toggle debug logging:",T)}finally{l(!1)}},y=async()=>{r(null),a(!0);try{await Ng.downloadSupportBundle()}catch(T){r(T instanceof Error?T.message:"Failed to download support bundle")}finally{a(!1)}};if(u)return s.jsx("div",{className:"flex items-center justify-center h-64",children:s.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})});if(!c)return s.jsx("div",{className:"p-6 text-center text-bambu-gray",children:t("system.failedToLoad","Failed to load system information")});const S=c.storage.disk_percent_used>90?"bg-red-500":c.storage.disk_percent_used>75?"bg-yellow-500":"bg-bambu-green",M=c.memory.percent_used>90?"bg-red-500":c.memory.percent_used>75?"bg-yellow-500":"bg-bambu-green";return s.jsxs("div",{className:"p-6 space-y-6",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold text-white",children:t("system.title","System Information")}),s.jsx("p",{className:"text-bambu-gray mt-1",children:t("system.subtitle","Monitor system resources and database statistics")})]}),s.jsxs("button",{onClick:()=>d(),disabled:f,className:"flex items-center gap-2 px-4 py-2 bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary rounded-lg transition-colors disabled:opacity-50",children:[s.jsx(Rr,{className:`w-4 h-4 ${f?"animate-spin":""}`}),t("common.refresh","Refresh")]})]}),s.jsx(Ud,{title:t("system.application","Application"),icon:vf,children:s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[s.jsx(gi,{icon:vf,label:t("system.version","Version"),value:`v${c.app.version}`}),s.jsx(gi,{icon:nr,label:t("system.uptime","System Uptime"),value:c.system.uptime_formatted}),s.jsx(gi,{icon:vf,label:t("system.hostname","Hostname"),value:c.system.hostname})]})}),s.jsx(Ud,{title:t("support.title","Support & Troubleshooting"),icon:ode,children:s.jsxs("div",{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:t("support.description","Enable debug logging to capture detailed information, then download a support bundle to share when reporting issues.")}),s.jsxs("div",{className:"flex items-center justify-between p-4 bg-bambu-dark rounded-lg",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:`p-2 rounded-lg ${p?.enabled?"bg-amber-500/20 text-amber-500":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:s.jsx(sM,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"font-medium text-white",children:t("support.debugLogging","Debug Logging")}),s.jsxs("p",{className:"text-sm text-bambu-gray",children:[p?.enabled?t("support.debugLoggingEnabled","Capturing detailed logs"):t("support.debugLoggingDisabled","Normal logging level"),p?.enabled&&p.duration_seconds!==null&&s.jsxs("span",{className:"text-amber-400 ml-2",children:["(",Math.floor(p.duration_seconds/60),"m ",p.duration_seconds%60,"s)"]})]})]})]}),s.jsxs("button",{onClick:v,disabled:o,className:`px-4 py-2 rounded-lg font-medium transition-colors flex items-center gap-2 ${p?.enabled?"bg-amber-500/20 text-amber-400 hover:bg-amber-500/30":"bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30"} disabled:opacity-50`,children:[o&&s.jsx(pt,{className:"w-4 h-4 animate-spin"}),p?.enabled?t("support.disableDebug","Disable"):t("support.enableDebug","Enable")]})]}),s.jsxs("div",{className:"flex items-center justify-between p-4 bg-bambu-dark rounded-lg",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-green",children:s.jsx(wi,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"font-medium text-white",children:t("support.supportBundle","Support Bundle")}),s.jsx("p",{className:"text-sm text-bambu-gray",children:t("support.supportBundleDescription","Download system info and logs as a ZIP file")})]})]}),s.jsxs("button",{onClick:y,disabled:i||!p?.enabled,className:"px-4 py-2 rounded-lg font-medium bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 transition-colors flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",title:p?.enabled?void 0:t("support.enableDebugFirst","Enable debug logging first"),children:[i&&s.jsx(pt,{className:"w-4 h-4 animate-spin"}),t("common.download","Download")]})]}),n&&s.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/30 rounded-lg text-red-400 text-sm",children:n}),!p?.enabled&&s.jsx("div",{className:"p-4 bg-bambu-dark-tertiary/50 rounded-lg",children:s.jsxs("p",{className:"text-sm text-bambu-gray",children:[s.jsx("span",{className:"text-amber-400 font-medium",children:t("support.instructions","To report an issue:")}),s.jsx("br",{}),"1. ",t("support.step1","Enable debug logging"),s.jsx("br",{}),"2. ",t("support.step2","Reproduce the issue"),s.jsx("br",{}),"3. ",t("support.step3","Download the support bundle"),s.jsx("br",{}),"4. ",t("support.step4","Attach the ZIP file to your issue report")]})}),s.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg space-y-3",children:[s.jsx("p",{className:"text-sm font-medium text-white",children:t("support.privacyTitle","What's in the support bundle?")}),s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 text-sm",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-bambu-green font-medium mb-1",children:t("support.collected","Collected:")}),s.jsxs("ul",{className:"text-bambu-gray space-y-0.5",children:[s.jsxs("li",{children:["• ",t("support.collectItem1","App version and debug mode")]}),s.jsxs("li",{children:["• ",t("support.collectItem2","OS, architecture, Python version")]}),s.jsxs("li",{children:["• ",t("support.collectItem3","Database statistics (counts only)")]}),s.jsxs("li",{children:["• ",t("support.collectItem4","Printer models and nozzle counts")]}),s.jsxs("li",{children:["• ",t("support.collectItem5","Non-sensitive settings (themes, formats)")]}),s.jsxs("li",{children:["• ",t("support.collectItem6","Debug logs (sanitized)")]})]})]}),s.jsxs("div",{children:[s.jsx("p",{className:"text-red-400 font-medium mb-1",children:t("support.notCollected","NOT collected:")}),s.jsxs("ul",{className:"text-bambu-gray space-y-0.5",children:[s.jsxs("li",{children:["• ",t("support.notItem1","Printer names, IPs, serial numbers")]}),s.jsxs("li",{children:["• ",t("support.notItem2","Access codes and passwords")]}),s.jsxs("li",{children:["• ",t("support.notItem3","Email addresses")]}),s.jsxs("li",{children:["• ",t("support.notItem4","API keys and tokens")]}),s.jsxs("li",{children:["• ",t("support.notItem5","Webhook URLs")]}),s.jsxs("li",{children:["• ",t("support.notItem6","Your hostname or username")]})]})]})]}),s.jsx("p",{className:"text-xs text-bambu-gray/70",children:t("support.privacyNote","IP addresses in logs are replaced with [IP] and email addresses with [EMAIL].")})]}),s.jsx(NXe,{})]})}),s.jsxs(Ud,{title:t("system.database","Database"),icon:ku,children:[s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-4",children:[s.jsx(gi,{icon:ho,label:t("system.totalArchives","Total Archives"),value:c.database.archives}),s.jsx(gi,{icon:oM,label:t("system.completed","Completed"),value:c.database.archives_completed,color:"text-green-500"}),s.jsx(gi,{icon:Qi,label:t("system.failed","Failed"),value:c.database.archives_failed,color:"text-red-500"}),s.jsx(gi,{icon:pt,label:t("system.printing","Printing"),value:c.database.archives_printing,color:"text-yellow-500"})]}),s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[s.jsx(gi,{icon:Pr,label:t("system.printers","Printers"),value:c.database.printers}),s.jsx(gi,{icon:EW,label:t("system.filaments","Filaments"),value:c.database.filaments}),s.jsx(gi,{icon:Ja,label:t("system.projects","Projects"),value:c.database.projects}),s.jsx(gi,{icon:tl,label:t("system.smartPlugs","Smart Plugs"),value:c.database.smart_plugs})]}),s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mt-4",children:[s.jsx(gi,{icon:nr,label:t("system.totalPrintTime","Total Print Time"),value:c.database.total_print_time_formatted}),s.jsx(gi,{icon:ho,label:t("system.totalFilament","Total Filament Used"),value:`${c.database.total_filament_kg} kg`,subValue:`${c.database.total_filament_grams.toLocaleString()} g`})]})]}),s.jsxs(Ud,{title:t("system.connectedPrinters","Connected Printers"),icon:Pr,children:[s.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[s.jsx("div",{className:"text-3xl font-bold text-bambu-green",children:c.printers.connected}),s.jsx("div",{className:"text-bambu-gray",children:t("system.ofTotal","of {{total}} printers connected",{total:c.printers.total})})]}),c.printers.connected_list.length>0?s.jsx("div",{className:"space-y-2",children:c.printers.connected_list.map(T=>s.jsxs("div",{className:"flex items-center justify-between p-3 bg-bambu-dark rounded-lg",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-2 h-2 rounded-full bg-bambu-green"}),s.jsx("span",{className:"font-medium text-white",children:T.name})]}),s.jsxs("div",{className:"flex items-center gap-4 text-sm text-bambu-gray",children:[s.jsx("span",{children:T.model}),s.jsx("span",{className:`px-2 py-0.5 rounded ${T.state==="RUNNING"?"bg-bambu-green/20 text-bambu-green":T.state==="IDLE"?"bg-blue-500/20 text-blue-400":"bg-bambu-dark-tertiary"}`,children:T.state})]})]},T.id))}):s.jsx("p",{className:"text-bambu-gray",children:t("system.noPrintersConnected","No printers connected")})]}),s.jsx(Ud,{title:t("system.storage","Storage"),icon:fM,children:s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[s.jsx("span",{className:"text-bambu-gray",children:t("system.diskUsage","Disk Usage")}),s.jsxs("span",{className:"text-white",children:[c.storage.disk_used_formatted," / ",c.storage.disk_total_formatted]})]}),s.jsx(_q,{percent:c.storage.disk_percent_used,color:S}),s.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:[c.storage.disk_free_formatted," ",t("system.free","free")," (",(100-c.storage.disk_percent_used).toFixed(1),"%)"]})]}),s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[s.jsx(gi,{icon:ho,label:t("system.archiveStorage","Archive Storage"),value:c.storage.archive_size_formatted}),s.jsx(gi,{icon:ku,label:t("system.databaseSize","Database Size"),value:c.storage.database_size_formatted}),x&&s.jsx(gi,{icon:Il,label:t("system.fileManagerStorage","File Manager"),value:MXe(x.total_size_bytes),subValue:`${x.total_files} files, ${x.total_folders} folders`})]})]})}),s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[s.jsx(Ud,{title:t("system.memory","Memory"),icon:zde,children:s.jsx("div",{className:"space-y-4",children:s.jsxs("div",{children:[s.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[s.jsx("span",{className:"text-bambu-gray",children:t("system.memoryUsage","Memory Usage")}),s.jsxs("span",{className:"text-white",children:[c.memory.used_formatted," / ",c.memory.total_formatted]})]}),s.jsx(_q,{percent:c.memory.percent_used,color:M}),s.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:[c.memory.available_formatted," ",t("system.available","available")]})]})})}),s.jsx(Ud,{title:t("system.cpu","CPU"),icon:Rw,children:s.jsx("div",{className:"space-y-4",children:s.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[s.jsx(gi,{icon:Rw,label:t("system.cores","Cores"),value:c.cpu.count,subValue:`${c.cpu.count_logical} logical`}),s.jsx(gi,{icon:Rw,label:t("system.usage","Usage"),value:`${c.cpu.percent}%`})]})})})]}),s.jsx(Ud,{title:t("system.systemDetails","System Details"),icon:vf,children:s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[s.jsx(gi,{icon:vf,label:t("system.os","Operating System"),value:c.system.platform,subValue:c.system.platform_release}),s.jsx(gi,{icon:Rw,label:t("system.architecture","Architecture"),value:c.system.architecture}),s.jsx(gi,{icon:vf,label:t("system.python","Python"),value:c.system.python_version}),s.jsx(gi,{icon:nr,label:t("system.bootTime","Boot Time"),value:Hg(c.system.boot_time,b)})]})})]})}function EXe(){const t=kc(),{t:e}=On(),{login:n}=Ci(),{showToast:r}=Vn(),{mode:i}=Lh(),[a,o]=_.useState(""),[l,c]=_.useState(""),[u,d]=_.useState(!1),f=gt({mutationFn:()=>n(a,l),onSuccess:()=>{r(e("login.loginSuccess")),t("/")},onError:m=>{r(m.message||e("login.loginFailed"),"error")}}),p=m=>{if(m.preventDefault(),!a||!l){r(e("login.enterCredentials"),"error");return}f.mutate()};return s.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-bambu-dark p-4",children:[s.jsxs("div",{className:"max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg",children:[s.jsxs("div",{className:"text-center",children:[s.jsx("div",{className:"flex items-center justify-center mb-6",children:s.jsx("img",{src:i==="dark"?"/img/bambuddy_logo_dark_transparent.png":"/img/bambuddy_logo_light.png",alt:"Bambuddy",className:"h-16"})}),s.jsx("h2",{className:"text-3xl font-bold text-white",children:e("login.title")}),s.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:e("login.subtitle")})]}),s.jsxs("form",{className:"mt-8 space-y-6",onSubmit:p,children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{htmlFor:"username",className:"block text-sm font-medium text-white mb-2",children:e("login.username")}),s.jsx("input",{id:"username",type:"text",required:!0,value:a,onChange:m=>o(m.target.value),className:"block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:e("login.usernamePlaceholder"),autoComplete:"username"})]}),s.jsxs("div",{children:[s.jsx("label",{htmlFor:"password",className:"block text-sm font-medium text-white mb-2",children:e("login.password")}),s.jsx("input",{id:"password",type:"password",required:!0,value:l,onChange:m=>c(m.target.value),className:"block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:e("login.passwordPlaceholder"),autoComplete:"current-password"})]})]}),s.jsx("div",{children:s.jsx("button",{type:"submit",disabled:f.isPending,className:"w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green",children:f.isPending?e("login.signingIn"):e("login.signIn")})}),s.jsx("div",{className:"text-center",children:s.jsx("button",{type:"button",onClick:()=>d(!0),className:"text-sm text-bambu-gray hover:text-bambu-green transition-colors",children:e("login.forgotPassword")})})]})]}),u&&s.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>d(!1),children:s.jsxs("div",{className:"w-full max-w-md bg-bambu-card rounded-xl border border-bambu-dark-tertiary shadow-lg p-6",onClick:m=>m.stopPropagation(),children:[s.jsxs("div",{className:"flex items-center justify-between mb-4",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Zce,{className:"w-5 h-5 text-bambu-green"}),s.jsx("h2",{className:"text-lg font-semibold text-white",children:e("login.forgotPasswordTitle")})]}),s.jsx("button",{onClick:()=>d(!1),className:"p-1 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",children:s.jsx(Lt,{className:"w-5 h-5"})})]}),s.jsxs("div",{className:"space-y-4",children:[s.jsx("p",{className:"text-bambu-gray",children:e("login.forgotPasswordMessage")}),s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4 space-y-2",children:[s.jsx("p",{className:"text-sm text-white font-medium",children:e("login.howToReset")}),s.jsxs("ol",{className:"text-sm text-bambu-gray space-y-1 list-decimal list-inside",children:[s.jsx("li",{children:e("login.resetStep1")}),s.jsx("li",{children:e("login.resetStep2")}),s.jsx("li",{children:e("login.resetStep3")}),s.jsx("li",{children:e("login.resetStep4")})]})]}),s.jsx("button",{onClick:()=>d(!1),className:"w-full py-2 px-4 bg-bambu-dark-tertiary hover:bg-bambu-dark text-white rounded-lg transition-colors",children:e("login.gotIt")})]})]})})]})}function TXe(){const t=kc(),{t:e}=On(),{showToast:n}=Vn(),{mode:r}=Lh(),{refreshAuth:i}=Ci(),[a,o]=_.useState(!1),[l,c]=_.useState(""),[u,d]=_.useState(""),[f,p]=_.useState(""),m=gt({mutationFn:()=>ce.setupAuth({auth_enabled:a,admin_username:a?l:void 0,admin_password:a?u:void 0}),onSuccess:async b=>{await i(),b.auth_enabled?b.admin_created?(n(e("setup.toast.authEnabledAdminCreated")),t("/login")):(n(e("setup.toast.authEnabledExistingAdmins")),t("/login")):(n(e("setup.toast.setupCompleted")),t("/"))},onError:b=>{n(b.message,"error")}}),x=b=>{if(b.preventDefault(),a&&(l||u)){if(!l||!u){n(e("setup.toast.enterBothCredentials"),"error");return}if(u!==f){n(e("setup.toast.passwordsDoNotMatch"),"error");return}if(u.length<6){n(e("setup.toast.passwordTooShort"),"error");return}}m.mutate()};return s.jsx("div",{className:"min-h-screen flex items-center justify-center bg-bambu-dark p-4",children:s.jsxs("div",{className:"max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg",children:[s.jsxs("div",{className:"text-center",children:[s.jsx("div",{className:"flex items-center justify-center mb-6",children:s.jsx("img",{src:r==="dark"?"/img/bambuddy_logo_dark_transparent.png":"/img/bambuddy_logo_light.png",alt:"Bambuddy",className:"h-16"})}),s.jsx("h2",{className:"text-3xl font-bold text-white",children:e("setup.title")}),s.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:e("setup.subtitle")})]}),s.jsxs("form",{className:"mt-8 space-y-6",onSubmit:x,children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center p-4 bg-bambu-dark-secondary/50 rounded-lg border border-bambu-dark-tertiary",children:[s.jsx("input",{id:"auth-enabled",type:"checkbox",checked:a,onChange:b=>o(b.target.checked),className:"h-4 w-4 text-bambu-green focus:ring-bambu-green border-bambu-dark-tertiary rounded bg-bambu-dark-secondary"}),s.jsx("label",{htmlFor:"auth-enabled",className:"ml-3 block text-sm font-medium text-white",children:e("setup.enableAuth")})]}),a&&s.jsxs("div",{className:"space-y-4 mt-4",children:[s.jsx("div",{className:"p-3 bg-bambu-dark-secondary/50 border border-bambu-dark-tertiary rounded-lg",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(Zo,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsxs("div",{className:"text-sm text-bambu-gray",children:[s.jsx("p",{className:"text-white font-medium mb-1",children:e("setup.adminAccount")}),s.jsx("p",{children:e("setup.adminAccountDesc")})]})]})}),s.jsxs("div",{children:[s.jsxs("label",{htmlFor:"admin-username",className:"block text-sm font-medium text-white mb-2",children:[e("setup.adminUsername")," ",s.jsx("span",{className:"text-bambu-gray text-xs",children:e("setup.optionalIfAdminExists")})]}),s.jsx("input",{id:"admin-username",type:"text",value:l,onChange:b=>c(b.target.value),className:"block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:e("setup.adminUsernamePlaceholder"),autoComplete:"username"})]}),s.jsxs("div",{children:[s.jsxs("label",{htmlFor:"admin-password",className:"block text-sm font-medium text-white mb-2",children:[e("setup.adminPassword")," ",s.jsx("span",{className:"text-bambu-gray text-xs",children:e("setup.optionalIfAdminExists")})]}),s.jsx("input",{id:"admin-password",type:"password",value:u,onChange:b=>d(b.target.value),className:"block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:e("setup.adminPasswordPlaceholder"),minLength:6,autoComplete:"new-password"})]}),u&&s.jsxs("div",{children:[s.jsx("label",{htmlFor:"confirm-password",className:"block text-sm font-medium text-white mb-2",children:e("setup.confirmPassword")}),s.jsx("input",{id:"confirm-password",type:"password",value:f,onChange:b=>p(b.target.value),className:"block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:e("setup.confirmPasswordPlaceholder"),minLength:6,autoComplete:"new-password"})]})]})]}),s.jsx("div",{children:s.jsx("button",{type:"submit",disabled:m.isPending,className:"w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green",children:m.isPending?e("setup.settingUp"):e("setup.completeSetup")})})]})]})})}function AXe(){const t=_.useRef(null),e=_.useRef(null),n=ln(),[r,i]=_.useState(!1),a=_.useRef(new Set),o=_.useRef(null),l=_.useRef(new Map),c=_.useRef(null),u=_.useRef([]),d=_.useRef(!1),f=_.useRef(()=>{}),p=_.useCallback(()=>{if(d.current||u.current.length===0)return;d.current=!0;const S=()=>{const M=u.current.shift();M?requestAnimationFrame(()=>{f.current(M),u.current.length>0?setTimeout(S,16):d.current=!1}):d.current=!1};S()},[]),m=_.useCallback(()=>{if(t.current?.readyState===WebSocket.OPEN)return;const M=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/v1/ws`,T=new WebSocket(M);let k=null;T.onopen=()=>{console.log("[WebSocket] Connected"),i(!0),k=window.setInterval(()=>{T.readyState===WebSocket.OPEN&&T.send(JSON.stringify({type:"ping"}))},3e4)},T.onmessage=C=>{try{const E=JSON.parse(C.data);E.type==="printer_status"&&E.printer_id!==void 0&&E.data?f.current(E):(u.current.push(E),p())}catch{}},T.onclose=C=>{console.log("[WebSocket] Closed",C.code,C.reason),k&&(clearInterval(k),k=null),i(!1),t.current=null,e.current=window.setTimeout(()=>{m()},3e3)},T.onerror=C=>{console.error("[WebSocket] Error",C),T.close()},t.current=T},[p]),x=_.useCallback((S,M)=>{const T=l.current.get(S)||{};l.current.set(S,{...T,...M}),c.current||(c.current=window.setTimeout(()=>{const k=new Map(l.current);l.current.clear(),c.current=null,requestAnimationFrame(()=>{k.forEach((C,E)=>{n.setQueryData(["printerStatus",E],D=>{const A={...D,...C};return A.wifi_signal==null&&D?.wifi_signal!=null&&(A.wifi_signal=D.wifi_signal),A})})})},100))},[n]),b=_.useCallback(S=>{a.current.add(S),o.current&&clearTimeout(o.current),o.current=window.setTimeout(()=>{const M=Array.from(a.current);a.current.clear(),o.current=null;let T=0;M.forEach(k=>{setTimeout(()=>{requestAnimationFrame(()=>{n.invalidateQueries({queryKey:[k]})})},T),T+=500})},3e3)},[n]),v=_.useCallback(S=>{switch(S.type){case"printer_status":S.printer_id!==void 0&&S.data&&x(S.printer_id,S.data);break;case"print_start":S.printer_id!==void 0&&n.invalidateQueries({queryKey:["printerStatus",S.printer_id]});break;case"print_complete":b("archives"),b("archiveStats");break;case"archive_created":b("archives"),b("archiveStats");break;case"archive_updated":b("archives");break;case"pong":break;case"plate_not_empty":window.dispatchEvent(new CustomEvent("plate-not-empty",{detail:{printer_id:S.printer_id,printer_name:S.printer_name,message:S.message}}));break}},[n,b,x]);_.useEffect(()=>{f.current=v},[v]),_.useEffect(()=>(m(),()=>{e.current&&clearTimeout(e.current),o.current&&clearTimeout(o.current),c.current&&clearTimeout(c.current),t.current&&t.current.close()}),[m]);const y=_.useCallback(S=>{t.current?.readyState===WebSocket.OPEN&&t.current.send(JSON.stringify(S))},[]);return{isConnected:r,sendMessage:y}}const CXe=new Yle({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function PXe({children:t}){return AXe(),s.jsx(s.Fragment,{children:t})}function jXe({children:t}){const{authEnabled:e,loading:n,user:r}=Ci();return n?s.jsx("div",{className:"min-h-screen flex items-center justify-center",children:"Loading..."}):e&&!r?s.jsx(Fg,{to:"/login",replace:!0}):s.jsx(s.Fragment,{children:t})}function DXe({children:t}){const{authEnabled:e,loading:n,user:r,isAdmin:i}=Ci();return n?s.jsx("div",{className:"min-h-screen flex items-center justify-center",children:"Loading..."}):e?r?i?s.jsx(s.Fragment,{children:t}):s.jsx(Fg,{to:"/",replace:!0}):s.jsx(Fg,{to:"/login",replace:!0}):s.jsx(s.Fragment,{children:t})}function RXe({children:t}){const{authEnabled:e,loading:n}=Ci();return n?s.jsx("div",{className:"min-h-screen flex items-center justify-center",children:"Loading..."}):e?s.jsx(Fg,{to:"/login",replace:!0}):s.jsx(s.Fragment,{children:t})}function OXe(){return s.jsx(Mfe,{children:s.jsx(Dfe,{children:s.jsx(Qle,{client:CXe,children:s.jsx(Cfe,{children:s.jsx(xle,{children:s.jsxs(qoe,{children:[s.jsx(Fi,{path:"/setup",element:s.jsx(RXe,{children:s.jsx(TXe,{})})}),s.jsx(Fi,{path:"/login",element:s.jsx(EXe,{})}),s.jsx(Fi,{path:"/camera/:printerId",element:s.jsx(pXe,{})}),s.jsx(Fi,{path:"/overlay/:printerId",element:s.jsx(wXe,{})}),s.jsxs(Fi,{element:s.jsx(jXe,{children:s.jsx(PXe,{children:s.jsx(Ffe,{})})}),children:[s.jsx(Fi,{index:!0,element:s.jsx(SPe,{})}),s.jsx(Fi,{path:"archives",element:s.jsx(dqe,{})}),s.jsx(Fi,{path:"queue",element:s.jsx(YWe,{})}),s.jsx(Fi,{path:"stats",element:s.jsx(uKe,{})}),s.jsx(Fi,{path:"profiles",element:s.jsx($Ke,{})}),s.jsx(Fi,{path:"maintenance",element:s.jsx(KKe,{})}),s.jsx(Fi,{path:"projects",element:s.jsx(YKe,{})}),s.jsx(Fi,{path:"projects/:id",element:s.jsx(rXe,{})}),s.jsx(Fi,{path:"files",element:s.jsx(dXe,{})}),s.jsx(Fi,{path:"settings",element:s.jsx(DXe,{children:s.jsx(jKe,{})})}),s.jsx(Fi,{path:"users",element:s.jsx(Fg,{to:"/settings?tab=users",replace:!0})}),s.jsx(Fi,{path:"groups",element:s.jsx(Fg,{to:"/settings?tab=users",replace:!0})}),s.jsx(Fi,{path:"system",element:s.jsx(kXe,{})}),s.jsx(Fi,{path:"external/:id",element:s.jsx(_Xe,{})})]})]})})})})})})}$ae.createRoot(document.getElementById("root")).render(s.jsx(_.StrictMode,{children:s.jsx(OXe,{})})); diff --git a/static/index.html b/static/index.html index bf73f2a14..86ae3a9fc 100644 --- a/static/index.html +++ b/static/index.html @@ -23,7 +23,7 @@ - +